ProjectionMatrixBuffer.java

net.minecraft.client.renderer.ProjectionMatrixBuffer

信息

  • 全限定名:net.minecraft.client.renderer.ProjectionMatrixBuffer
  • 类型:public class
  • 包:net.minecraft.client.renderer
  • 源码路径:src/main/java/net/minecraft/client/renderer/ProjectionMatrixBuffer.java
  • 起始行号:L16
  • 实现:AutoCloseable
  • 职责:

    TODO

字段/常量

  • buffer

    • 类型: GpuBuffer
    • 修饰符: package-private
    • 源码定位: L17
    • 说明:

      TODO

  • bufferSlice

    • 类型: GpuBufferSlice
    • 修饰符: package-private
    • 源码定位: L18
    • 说明:

      TODO

  • lastUploadedProjection

    • 类型: Projection
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • projectionMatrixVersion

    • 类型: long
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • tempMatrix

    • 类型: Matrix4f
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ProjectionMatrixBuffer(String name) @ L23

  • 构造器名:ProjectionMatrixBuffer
  • 源码定位:L23
  • 修饰符:public

参数:

  • name: String

说明:

TODO

方法

下面的方法块按源码顺序生成。

public GpuBufferSlice getBuffer(Projection projection) @ L31

  • 方法名:getBuffer
  • 源码定位:L31
  • 返回类型:GpuBufferSlice
  • 修饰符:public

参数:

  • projection: Projection

说明:

TODO

public GpuBufferSlice getBuffer(Matrix4f projectionMatrix) @ L43

  • 方法名:getBuffer
  • 源码定位:L43
  • 返回类型:GpuBufferSlice
  • 修饰符:public

参数:

  • projectionMatrix: Matrix4f

说明:

TODO

private GpuBufferSlice writeBuffer(Matrix4f projectionMatrix) @ L49

  • 方法名:writeBuffer
  • 源码定位:L49
  • 返回类型:GpuBufferSlice
  • 修饰符:private

参数:

  • projectionMatrix: Matrix4f

说明:

TODO

public void close() @ L58

  • 方法名:close
  • 源码定位:L58
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ProjectionMatrixBuffer implements AutoCloseable {
    GpuBuffer buffer;
    GpuBufferSlice bufferSlice;
    private @Nullable Projection lastUploadedProjection;
    private long projectionMatrixVersion;
    private final Matrix4f tempMatrix = new Matrix4f();
 
    public ProjectionMatrixBuffer(String name) {
        this.lastUploadedProjection = null;
        this.projectionMatrixVersion = -1L;
        GpuDevice device = RenderSystem.getDevice();
        this.buffer = device.createBuffer(() -> "Camera projection matrix UBO " + name, 136, RenderSystem.PROJECTION_MATRIX_UBO_SIZE);
        this.bufferSlice = this.buffer.slice(0L, RenderSystem.PROJECTION_MATRIX_UBO_SIZE);
    }
 
    public GpuBufferSlice getBuffer(Projection projection) {
        assert projection.getMatrixVersion() != -1L;
 
        if (this.lastUploadedProjection == projection && projection.getMatrixVersion() == this.projectionMatrixVersion) {
            return this.bufferSlice;
        } else {
            this.lastUploadedProjection = projection;
            this.projectionMatrixVersion = projection.getMatrixVersion();
            return this.writeBuffer(projection.getMatrix(this.tempMatrix));
        }
    }
 
    public GpuBufferSlice getBuffer(Matrix4f projectionMatrix) {
        this.lastUploadedProjection = null;
        this.projectionMatrixVersion = -1L;
        return this.writeBuffer(projectionMatrix);
    }
 
    private GpuBufferSlice writeBuffer(Matrix4f projectionMatrix) {
        try (MemoryStack stack = MemoryStack.stackPush()) {
            ByteBuffer byteBuffer = Std140Builder.onStack(stack, RenderSystem.PROJECTION_MATRIX_UBO_SIZE).putMat4f(projectionMatrix).get();
            RenderSystem.getDevice().createCommandEncoder().writeToBuffer(this.buffer.slice(), byteBuffer);
        }
 
        return this.bufferSlice;
    }
 
    @Override
    public void close() {
        this.buffer.close();
    }
}

引用的其他类