PictureInPictureRenderer.java
net.minecraft.client.gui.render.pip.PictureInPictureRenderer
信息
- 全限定名:net.minecraft.client.gui.render.pip.PictureInPictureRenderer
- 类型:public abstract class
- 包:net.minecraft.client.gui.render.pip
- 源码路径:src/main/java/net/minecraft/client/gui/render/pip/PictureInPictureRenderer.java
- 起始行号:L24
- 实现:AutoCloseable
- 职责:
TODO
字段/常量
-
bufferSource- 类型:
MultiBufferSource.BufferSource - 修饰符:
protected final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
texture- 类型:
GpuTexture - 修饰符:
private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
textureView- 类型:
GpuTextureView - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
depthTexture- 类型:
GpuTexture - 修饰符:
private - 源码定位:
L28 - 说明:
TODO
- 类型:
-
depthTextureView- 类型:
GpuTextureView - 修饰符:
private - 源码定位:
L29 - 说明:
TODO
- 类型:
-
projection- 类型:
Projection - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
projectionMatrixBuffer- 类型:
ProjectionMatrixBuffer - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
protected PictureInPictureRenderer(MultiBufferSource.BufferSource bufferSource) @ L33
- 构造器名:PictureInPictureRenderer
- 源码定位:L33
- 修饰符:protected
参数:
- bufferSource: MultiBufferSource.BufferSource
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void prepare(T renderState, GuiRenderState guiRenderState, int guiScale) @ L37
- 方法名:prepare
- 源码定位:L37
- 返回类型:void
- 修饰符:public
参数:
- renderState: T
- guiRenderState: GuiRenderState
- guiScale: int
说明:
TODO
protected void blitTexture(T renderState, GuiRenderState guiRenderState) @ L59
- 方法名:blitTexture
- 源码定位:L59
- 返回类型:void
- 修饰符:protected
参数:
- renderState: T
- guiRenderState: GuiRenderState
说明:
TODO
private void prepareTexturesAndProjection(boolean needsAResize, int width, int height) @ L80
- 方法名:prepareTexturesAndProjection
- 源码定位:L80
- 返回类型:void
- 修饰符:private
参数:
- needsAResize: boolean
- width: int
- height: int
说明:
TODO
protected boolean textureIsReadyToBlit(T renderState) @ L105
- 方法名:textureIsReadyToBlit
- 源码定位:L105
- 返回类型:boolean
- 修饰符:protected
参数:
- renderState: T
说明:
TODO
protected float getTranslateY(int height, int guiScale) @ L109
- 方法名:getTranslateY
- 源码定位:L109
- 返回类型:float
- 修饰符:protected
参数:
- height: int
- guiScale: int
说明:
TODO
public void close() @ L113
- 方法名:close
- 源码定位:L113
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public abstract Class<T> getRenderStateClass() @ L134
- 方法名:getRenderStateClass
- 源码定位:L134
- 返回类型:Class
- 修饰符:public abstract
参数:
- 无
说明:
TODO
protected abstract void renderToTexture(T renderState, PoseStack poseStack) @ L136
- 方法名:renderToTexture
- 源码定位:L136
- 返回类型:void
- 修饰符:protected abstract
参数:
- renderState: T
- poseStack: PoseStack
说明:
TODO
protected abstract String getTextureLabel() @ L138
- 方法名:getTextureLabel
- 源码定位:L138
- 返回类型:String
- 修饰符:protected abstract
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public abstract class PictureInPictureRenderer<T extends PictureInPictureRenderState> implements AutoCloseable {
protected final MultiBufferSource.BufferSource bufferSource;
private @Nullable GpuTexture texture;
private @Nullable GpuTextureView textureView;
private @Nullable GpuTexture depthTexture;
private @Nullable GpuTextureView depthTextureView;
private final Projection projection = new Projection();
private final ProjectionMatrixBuffer projectionMatrixBuffer = new ProjectionMatrixBuffer("PIP - " + this.getClass().getSimpleName());
protected PictureInPictureRenderer(MultiBufferSource.BufferSource bufferSource) {
this.bufferSource = bufferSource;
}
public void prepare(T renderState, GuiRenderState guiRenderState, int guiScale) {
int width = (renderState.x1() - renderState.x0()) * guiScale;
int height = (renderState.y1() - renderState.y0()) * guiScale;
boolean needsAResize = this.texture == null || this.texture.getWidth(0) != width || this.texture.getHeight(0) != height;
if (!needsAResize && this.textureIsReadyToBlit(renderState)) {
this.blitTexture(renderState, guiRenderState);
} else {
this.prepareTexturesAndProjection(needsAResize, width, height);
RenderSystem.outputColorTextureOverride = this.textureView;
RenderSystem.outputDepthTextureOverride = this.depthTextureView;
PoseStack poseStack = new PoseStack();
poseStack.translate(width / 2.0F, this.getTranslateY(height, guiScale), 0.0F);
float scale = guiScale * renderState.scale();
poseStack.scale(scale, scale, -scale);
this.renderToTexture(renderState, poseStack);
this.bufferSource.endBatch();
RenderSystem.outputColorTextureOverride = null;
RenderSystem.outputDepthTextureOverride = null;
this.blitTexture(renderState, guiRenderState);
}
}
protected void blitTexture(T renderState, GuiRenderState guiRenderState) {
guiRenderState.addBlitToCurrentLayer(
new BlitRenderState(
RenderPipelines.GUI_TEXTURED_PREMULTIPLIED_ALPHA,
TextureSetup.singleTexture(this.textureView, RenderSystem.getSamplerCache().getRepeat(FilterMode.NEAREST)),
renderState.pose(),
renderState.x0(),
renderState.y0(),
renderState.x1(),
renderState.y1(),
0.0F,
1.0F,
1.0F,
0.0F,
-1,
renderState.scissorArea(),
null
)
);
}
private void prepareTexturesAndProjection(boolean needsAResize, int width, int height) {
if (this.texture != null && needsAResize) {
this.texture.close();
this.texture = null;
this.textureView.close();
this.textureView = null;
this.depthTexture.close();
this.depthTexture = null;
this.depthTextureView.close();
this.depthTextureView = null;
}
GpuDevice device = RenderSystem.getDevice();
if (this.texture == null) {
this.texture = device.createTexture(() -> "UI " + this.getTextureLabel() + " texture", 13, TextureFormat.RGBA8, width, height, 1, 1);
this.textureView = device.createTextureView(this.texture);
this.depthTexture = device.createTexture(() -> "UI " + this.getTextureLabel() + " depth texture", 9, TextureFormat.DEPTH32, width, height, 1, 1);
this.depthTextureView = device.createTextureView(this.depthTexture);
}
device.createCommandEncoder().clearColorAndDepthTextures(this.texture, 0, this.depthTexture, 1.0);
this.projection.setupOrtho(-1000.0F, 1000.0F, width, height, true);
RenderSystem.setProjectionMatrix(this.projectionMatrixBuffer.getBuffer(this.projection), ProjectionType.ORTHOGRAPHIC);
}
protected boolean textureIsReadyToBlit(T renderState) {
return false;
}
protected float getTranslateY(int height, int guiScale) {
return height;
}
@Override
public void close() {
if (this.texture != null) {
this.texture.close();
}
if (this.textureView != null) {
this.textureView.close();
}
if (this.depthTexture != null) {
this.depthTexture.close();
}
if (this.depthTextureView != null) {
this.depthTextureView.close();
}
this.projectionMatrixBuffer.close();
}
public abstract Class<T> getRenderStateClass();
protected abstract void renderToTexture(final T renderState, final PoseStack poseStack);
protected abstract String getTextureLabel();
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
RenderSystem.getDevice(), RenderSystem.getSamplerCache(), RenderSystem.setProjectionMatrix()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
PoseStack()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
TextureSetup.singleTexture()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
Projection()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
ProjectionMatrixBuffer()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BlitRenderState()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: