RenderTarget.java

com.mojang.blaze3d.pipeline.RenderTarget

信息

  • 全限定名:com.mojang.blaze3d.pipeline.RenderTarget
  • 类型:public abstract class
  • 包:com.mojang.blaze3d.pipeline
  • 源码路径:src/main/java/com/mojang/blaze3d/pipeline/RenderTarget.java
  • 起始行号:L17
  • 职责:

    TODO

字段/常量

  • UNNAMED_RENDER_TARGETS

    • 类型: int
    • 修饰符: private static
    • 源码定位: L18
    • 说明:

      TODO

  • width

    • 类型: int
    • 修饰符: public
    • 源码定位: L19
    • 说明:

      TODO

  • height

    • 类型: int
    • 修饰符: public
    • 源码定位: L20
    • 说明:

      TODO

  • label

    • 类型: String
    • 修饰符: protected final
    • 源码定位: L21
    • 说明:

      TODO

  • useDepth

    • 类型: boolean
    • 修饰符: public final
    • 源码定位: L22
    • 说明:

      TODO

  • colorTexture

    • 类型: GpuTexture
    • 修饰符: protected
    • 源码定位: L23
    • 说明:

      TODO

  • colorTextureView

    • 类型: GpuTextureView
    • 修饰符: protected
    • 源码定位: L24
    • 说明:

      TODO

  • depthTexture

    • 类型: GpuTexture
    • 修饰符: protected
    • 源码定位: L25
    • 说明:

      TODO

  • depthTextureView

    • 类型: GpuTextureView
    • 修饰符: protected
    • 源码定位: L26
    • 说明:

      TODO

内部类/嵌套类型

构造器

public RenderTarget(String label, boolean useDepth) @ L28

  • 构造器名:RenderTarget
  • 源码定位:L28
  • 修饰符:public

参数:

  • label: String
  • useDepth: boolean

说明:

TODO

方法

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

public void resize(int width, int height) @ L33

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

参数:

  • width: int
  • height: int

说明:

TODO

public void destroyBuffers() @ L39

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

参数:

说明:

TODO

public void copyDepthFrom(RenderTarget source) @ L62

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

参数:

  • source: RenderTarget

说明:

TODO

public void createBuffers(int width, int height) @ L75

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

参数:

  • width: int
  • height: int

说明:

TODO

public void blitToScreen() @ L94

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

参数:

说明:

TODO

public void blitAndBlendToTexture(GpuTextureView output) @ L102

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

参数:

  • output: GpuTextureView

说明:

TODO

public GpuTexture getColorTexture() @ L113

  • 方法名:getColorTexture
  • 源码定位:L113
  • 返回类型:GpuTexture
  • 修饰符:public

参数:

说明:

TODO

public GpuTextureView getColorTextureView() @ L117

  • 方法名:getColorTextureView
  • 源码定位:L117
  • 返回类型:GpuTextureView
  • 修饰符:public

参数:

说明:

TODO

public GpuTexture getDepthTexture() @ L121

  • 方法名:getDepthTexture
  • 源码定位:L121
  • 返回类型:GpuTexture
  • 修饰符:public

参数:

说明:

TODO

public GpuTextureView getDepthTextureView() @ L125

  • 方法名:getDepthTextureView
  • 源码定位:L125
  • 返回类型:GpuTextureView
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public abstract class RenderTarget {
    private static int UNNAMED_RENDER_TARGETS = 0;
    public int width;
    public int height;
    protected final String label;
    public final boolean useDepth;
    protected @Nullable GpuTexture colorTexture;
    protected @Nullable GpuTextureView colorTextureView;
    protected @Nullable GpuTexture depthTexture;
    protected @Nullable GpuTextureView depthTextureView;
 
    public RenderTarget(@Nullable String label, boolean useDepth) {
        this.label = label == null ? "FBO " + UNNAMED_RENDER_TARGETS++ : label;
        this.useDepth = useDepth;
    }
 
    public void resize(int width, int height) {
        RenderSystem.assertOnRenderThread();
        this.destroyBuffers();
        this.createBuffers(width, height);
    }
 
    public void destroyBuffers() {
        RenderSystem.assertOnRenderThread();
        if (this.depthTexture != null) {
            this.depthTexture.close();
            this.depthTexture = null;
        }
 
        if (this.depthTextureView != null) {
            this.depthTextureView.close();
            this.depthTextureView = null;
        }
 
        if (this.colorTexture != null) {
            this.colorTexture.close();
            this.colorTexture = null;
        }
 
        if (this.colorTextureView != null) {
            this.colorTextureView.close();
            this.colorTextureView = null;
        }
    }
 
    public void copyDepthFrom(RenderTarget source) {
        RenderSystem.assertOnRenderThread();
        if (this.depthTexture == null) {
            throw new IllegalStateException("Trying to copy depth texture to a RenderTarget without a depth texture");
        } else if (source.depthTexture == null) {
            throw new IllegalStateException("Trying to copy depth texture from a RenderTarget without a depth texture");
        } else {
            RenderSystem.getDevice()
                .createCommandEncoder()
                .copyTextureToTexture(source.depthTexture, this.depthTexture, 0, 0, 0, 0, 0, this.width, this.height);
        }
    }
 
    public void createBuffers(int width, int height) {
        RenderSystem.assertOnRenderThread();
        GpuDevice device = RenderSystem.getDevice();
        int maxTextureSize = device.getMaxTextureSize();
        if (width > 0 && width <= maxTextureSize && height > 0 && height <= maxTextureSize) {
            this.width = width;
            this.height = height;
            if (this.useDepth) {
                this.depthTexture = device.createTexture(() -> this.label + " / Depth", 15, TextureFormat.DEPTH32, width, height, 1, 1);
                this.depthTextureView = device.createTextureView(this.depthTexture);
            }
 
            this.colorTexture = device.createTexture(() -> this.label + " / Color", 15, TextureFormat.RGBA8, width, height, 1, 1);
            this.colorTextureView = device.createTextureView(this.colorTexture);
        } else {
            throw new IllegalArgumentException("Window " + width + "x" + height + " size out of bounds (max. size: " + maxTextureSize + ")");
        }
    }
 
    public void blitToScreen() {
        if (this.colorTexture == null) {
            throw new IllegalStateException("Can't blit to screen, color texture doesn't exist yet");
        } else {
            RenderSystem.getDevice().createCommandEncoder().presentTexture(this.colorTextureView);
        }
    }
 
    public void blitAndBlendToTexture(GpuTextureView output) {
        RenderSystem.assertOnRenderThread();
 
        try (RenderPass renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(() -> "Blit render target", output, OptionalInt.empty())) {
            renderPass.setPipeline(RenderPipelines.ENTITY_OUTLINE_BLIT);
            RenderSystem.bindDefaultUniforms(renderPass);
            renderPass.bindTexture("InSampler", this.colorTextureView, RenderSystem.getSamplerCache().getClampToEdge(FilterMode.NEAREST));
            renderPass.draw(0, 3);
        }
    }
 
    public @Nullable GpuTexture getColorTexture() {
        return this.colorTexture;
    }
 
    public @Nullable GpuTextureView getColorTextureView() {
        return this.colorTextureView;
    }
 
    public @Nullable GpuTexture getDepthTexture() {
        return this.depthTexture;
    }
 
    public @Nullable GpuTextureView getDepthTextureView() {
        return this.depthTextureView;
    }
}

引用的其他类

  • RenderSystem

    • 引用位置: 方法调用
    • 关联成员: RenderSystem.assertOnRenderThread(), RenderSystem.bindDefaultUniforms(), RenderSystem.getDevice(), RenderSystem.getSamplerCache()
  • GpuTexture

    • 引用位置: 字段/返回值
  • GpuTextureView

    • 引用位置: 参数/字段/返回值