MainTarget.java
com.mojang.blaze3d.pipeline.MainTarget
信息
- 全限定名:com.mojang.blaze3d.pipeline.MainTarget
- 类型:public class
- 包:com.mojang.blaze3d.pipeline
- 源码路径:src/main/java/com/mojang/blaze3d/pipeline/MainTarget.java
- 起始行号:L15
- 继承:RenderTarget
- 职责:
TODO
字段/常量
-
DEFAULT_WIDTH- 类型:
int - 修饰符:
public static final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
DEFAULT_HEIGHT- 类型:
int - 修饰符:
public static final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
DEFAULT_DIMENSIONS- 类型:
MainTarget.Dimension - 修饰符:
private static final - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
com.mojang.blaze3d.pipeline.MainTarget.Dimension- 类型:
class - 修饰符:
private static - 源码定位:
L94 - 说明:
TODO
- 类型:
构造器
public MainTarget(int desiredWidth, int desiredHeight) @ L20
- 构造器名:MainTarget
- 源码定位:L20
- 修饰符:public
参数:
- desiredWidth: int
- desiredHeight: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
private void createFrameBuffer(int desiredWidth, int desiredHeight) @ L25
- 方法名:createFrameBuffer
- 源码定位:L25
- 返回类型:void
- 修饰符:private
参数:
- desiredWidth: int
- desiredHeight: int
说明:
TODO
private MainTarget.Dimension allocateAttachments(int width, int height) @ L35
- 方法名:allocateAttachments
- 源码定位:L35
- 返回类型:MainTarget.Dimension
- 修饰符:private
参数:
- width: int
- height: int
说明:
TODO
private GpuTexture allocateColorAttachment(MainTarget.Dimension dimension) @ L77
- 方法名:allocateColorAttachment
- 源码定位:L77
- 返回类型:GpuTexture
- 修饰符:private
参数:
- dimension: MainTarget.Dimension
说明:
TODO
private GpuTexture allocateDepthAttachment(MainTarget.Dimension dimension) @ L85
- 方法名:allocateDepthAttachment
- 源码定位:L85
- 返回类型:GpuTexture
- 修饰符:private
参数:
- dimension: MainTarget.Dimension
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class MainTarget extends RenderTarget {
public static final int DEFAULT_WIDTH = 854;
public static final int DEFAULT_HEIGHT = 480;
private static final MainTarget.Dimension DEFAULT_DIMENSIONS = new MainTarget.Dimension(854, 480);
public MainTarget(int desiredWidth, int desiredHeight) {
super("Main", true);
this.createFrameBuffer(desiredWidth, desiredHeight);
}
private void createFrameBuffer(int desiredWidth, int desiredHeight) {
MainTarget.Dimension allocatedDimensions = this.allocateAttachments(desiredWidth, desiredHeight);
if (this.colorTexture != null && this.depthTexture != null) {
this.width = allocatedDimensions.width;
this.height = allocatedDimensions.height;
} else {
throw new IllegalStateException("Missing color and/or depth textures");
}
}
private MainTarget.Dimension allocateAttachments(int width, int height) {
RenderSystem.assertOnRenderThread();
for (MainTarget.Dimension dimension : MainTarget.Dimension.listWithFallback(width, height)) {
if (this.colorTexture != null) {
this.colorTexture.close();
this.colorTexture = null;
}
if (this.colorTextureView != null) {
this.colorTextureView.close();
this.colorTextureView = null;
}
if (this.depthTexture != null) {
this.depthTexture.close();
this.depthTexture = null;
}
if (this.depthTextureView != null) {
this.depthTextureView.close();
this.depthTextureView = null;
}
this.colorTexture = this.allocateColorAttachment(dimension);
this.depthTexture = this.allocateDepthAttachment(dimension);
if (this.colorTexture != null && this.depthTexture != null) {
this.colorTextureView = RenderSystem.getDevice().createTextureView(this.colorTexture);
this.depthTextureView = RenderSystem.getDevice().createTextureView(this.depthTexture);
return dimension;
}
}
throw new RuntimeException(
"Unrecoverable GL_OUT_OF_MEMORY ("
+ (this.colorTexture == null ? "missing color" : "have color")
+ ", "
+ (this.depthTexture == null ? "missing depth" : "have depth")
+ ")"
);
}
private @Nullable GpuTexture allocateColorAttachment(MainTarget.Dimension dimension) {
try {
return RenderSystem.getDevice().createTexture(() -> this.label + " / Color", 15, TextureFormat.RGBA8, dimension.width, dimension.height, 1, 1);
} catch (GpuOutOfMemoryException var3) {
return null;
}
}
private @Nullable GpuTexture allocateDepthAttachment(MainTarget.Dimension dimension) {
try {
return RenderSystem.getDevice().createTexture(() -> this.label + " / Depth", 15, TextureFormat.DEPTH32, dimension.width, dimension.height, 1, 1);
} catch (GpuOutOfMemoryException var3) {
return null;
}
}
@OnlyIn(Dist.CLIENT)
private static class Dimension {
public final int width;
public final int height;
private Dimension(int width, int height) {
this.width = width;
this.height = height;
}
private static List<MainTarget.Dimension> listWithFallback(int width, int height) {
RenderSystem.assertOnRenderThread();
int maxTextureSize = RenderSystem.getDevice().getMaxTextureSize();
return width > 0 && width <= maxTextureSize && height > 0 && height <= maxTextureSize
? ImmutableList.of(new MainTarget.Dimension(width, height), MainTarget.DEFAULT_DIMENSIONS)
: ImmutableList.of(MainTarget.DEFAULT_DIMENSIONS);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other != null && this.getClass() == other.getClass()) {
MainTarget.Dimension that = (MainTarget.Dimension)other;
return this.width == that.width && this.height == that.height;
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hash(this.width, this.height);
}
@Override
public String toString() {
return this.width + "x" + this.height;
}
}
}引用的其他类
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderSystem.assertOnRenderThread(), RenderSystem.getDevice()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置: