RenderPipeline.java
com.mojang.blaze3d.pipeline.RenderPipeline
信息
- 全限定名:com.mojang.blaze3d.pipeline.RenderPipeline
- 类型:public class
- 包:com.mojang.blaze3d.pipeline
- 源码路径:src/main/java/com/mojang/blaze3d/pipeline/RenderPipeline.java
- 起始行号:L20
- 职责:
TODO
字段/常量
-
location- 类型:
Identifier - 修饰符:
private final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
vertexShader- 类型:
Identifier - 修饰符:
private final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
fragmentShader- 类型:
Identifier - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
shaderDefines- 类型:
ShaderDefines - 修饰符:
private final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
samplers- 类型:
List<String> - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
uniforms- 类型:
List<RenderPipeline.UniformDescription> - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
depthStencilState- 类型:
DepthStencilState - 修饰符:
private final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
polygonMode- 类型:
PolygonMode - 修饰符:
private final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
cull- 类型:
boolean - 修饰符:
private final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
colorTargetState- 类型:
ColorTargetState - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
vertexFormat- 类型:
VertexFormat - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
vertexFormatMode- 类型:
VertexFormat.Mode - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
sortKey- 类型:
int - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
sortKeySeed- 类型:
int - 修饰符:
private static - 源码定位:
L34 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
com.mojang.blaze3d.pipeline.RenderPipeline.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L142 - 说明:
TODO
- 类型:
-
com.mojang.blaze3d.pipeline.RenderPipeline.Snippet- 类型:
record - 修饰符:
public - 源码定位:
L395 - 说明:
TODO
- 类型:
-
com.mojang.blaze3d.pipeline.RenderPipeline.UniformDescription- 类型:
record - 修饰符:
public - 源码定位:
L411 - 说明:
TODO
- 类型:
构造器
protected RenderPipeline(Identifier location, Identifier vertexShader, Identifier fragmentShader, ShaderDefines shaderDefines, List<String> samplers, List<RenderPipeline.UniformDescription> uniforms, ColorTargetState colorTargetState, DepthStencilState depthStencilState, PolygonMode polygonMode, boolean cull, VertexFormat vertexFormat, VertexFormat.Mode vertexFormatMode, int sortKey) @ L36
- 构造器名:RenderPipeline
- 源码定位:L36
- 修饰符:protected
参数:
- location: Identifier
- vertexShader: Identifier
- fragmentShader: Identifier
- shaderDefines: ShaderDefines
- samplers: List
- uniforms: List<RenderPipeline.UniformDescription>
- colorTargetState: ColorTargetState
- depthStencilState: DepthStencilState
- polygonMode: PolygonMode
- cull: boolean
- vertexFormat: VertexFormat
- vertexFormatMode: VertexFormat.Mode
- sortKey: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public int getSortKey() @ L66
- 方法名:getSortKey
- 源码定位:L66
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public static void updateSortKeySeed() @ L70
- 方法名:updateSortKeySeed
- 源码定位:L70
- 返回类型:void
- 修饰符:public static
参数:
- 无
说明:
TODO
public String toString() @ L74
- 方法名:toString
- 源码定位:L74
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public PolygonMode getPolygonMode() @ L79
- 方法名:getPolygonMode
- 源码定位:L79
- 返回类型:PolygonMode
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isCull() @ L83
- 方法名:isCull
- 源码定位:L83
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public ColorTargetState getColorTargetState() @ L87
- 方法名:getColorTargetState
- 源码定位:L87
- 返回类型:ColorTargetState
- 修饰符:public
参数:
- 无
说明:
TODO
public DepthStencilState getDepthStencilState() @ L91
- 方法名:getDepthStencilState
- 源码定位:L91
- 返回类型:DepthStencilState
- 修饰符:public
参数:
- 无
说明:
TODO
public Identifier getLocation() @ L95
- 方法名:getLocation
- 源码定位:L95
- 返回类型:Identifier
- 修饰符:public
参数:
- 无
说明:
TODO
public VertexFormat getVertexFormat() @ L99
- 方法名:getVertexFormat
- 源码定位:L99
- 返回类型:VertexFormat
- 修饰符:public
参数:
- 无
说明:
TODO
public VertexFormat.Mode getVertexFormatMode() @ L103
- 方法名:getVertexFormatMode
- 源码定位:L103
- 返回类型:VertexFormat.Mode
- 修饰符:public
参数:
- 无
说明:
TODO
public Identifier getVertexShader() @ L107
- 方法名:getVertexShader
- 源码定位:L107
- 返回类型:Identifier
- 修饰符:public
参数:
- 无
说明:
TODO
public Identifier getFragmentShader() @ L111
- 方法名:getFragmentShader
- 源码定位:L111
- 返回类型:Identifier
- 修饰符:public
参数:
- 无
说明:
TODO
public ShaderDefines getShaderDefines() @ L115
- 方法名:getShaderDefines
- 源码定位:L115
- 返回类型:ShaderDefines
- 修饰符:public
参数:
- 无
说明:
TODO
public List<String> getSamplers() @ L119
- 方法名:getSamplers
- 源码定位:L119
- 返回类型:List
- 修饰符:public
参数:
- 无
说明:
TODO
public List<RenderPipeline.UniformDescription> getUniforms() @ L123
- 方法名:getUniforms
- 源码定位:L123
- 返回类型:List<RenderPipeline.UniformDescription>
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean wantsDepthTexture() @ L127
- 方法名:wantsDepthTexture
- 源码定位:L127
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public static RenderPipeline.Builder builder(RenderPipeline.Snippet... snippets) @ L131
- 方法名:builder
- 源码定位:L131
- 返回类型:RenderPipeline.Builder
- 修饰符:public static
参数:
- snippets: RenderPipeline.Snippet…
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RenderPipeline {
private final Identifier location;
private final Identifier vertexShader;
private final Identifier fragmentShader;
private final ShaderDefines shaderDefines;
private final List<String> samplers;
private final List<RenderPipeline.UniformDescription> uniforms;
private final @Nullable DepthStencilState depthStencilState;
private final PolygonMode polygonMode;
private final boolean cull;
private final ColorTargetState colorTargetState;
private final VertexFormat vertexFormat;
private final VertexFormat.Mode vertexFormatMode;
private final int sortKey;
private static int sortKeySeed;
protected RenderPipeline(
Identifier location,
Identifier vertexShader,
Identifier fragmentShader,
ShaderDefines shaderDefines,
List<String> samplers,
List<RenderPipeline.UniformDescription> uniforms,
ColorTargetState colorTargetState,
@Nullable DepthStencilState depthStencilState,
PolygonMode polygonMode,
boolean cull,
VertexFormat vertexFormat,
VertexFormat.Mode vertexFormatMode,
int sortKey
) {
this.location = location;
this.vertexShader = vertexShader;
this.fragmentShader = fragmentShader;
this.shaderDefines = shaderDefines;
this.samplers = samplers;
this.uniforms = uniforms;
this.depthStencilState = depthStencilState;
this.polygonMode = polygonMode;
this.cull = cull;
this.colorTargetState = colorTargetState;
this.vertexFormat = vertexFormat;
this.vertexFormatMode = vertexFormatMode;
this.sortKey = sortKey;
}
public int getSortKey() {
return SharedConstants.DEBUG_SHUFFLE_UI_RENDERING_ORDER ? super.hashCode() * (sortKeySeed + 1) : this.sortKey;
}
public static void updateSortKeySeed() {
sortKeySeed = Math.round(100000.0F * (float)Math.random());
}
@Override
public String toString() {
return this.location.toString();
}
public PolygonMode getPolygonMode() {
return this.polygonMode;
}
public boolean isCull() {
return this.cull;
}
public ColorTargetState getColorTargetState() {
return this.colorTargetState;
}
public @Nullable DepthStencilState getDepthStencilState() {
return this.depthStencilState;
}
public Identifier getLocation() {
return this.location;
}
public VertexFormat getVertexFormat() {
return this.vertexFormat;
}
public VertexFormat.Mode getVertexFormatMode() {
return this.vertexFormatMode;
}
public Identifier getVertexShader() {
return this.vertexShader;
}
public Identifier getFragmentShader() {
return this.fragmentShader;
}
public ShaderDefines getShaderDefines() {
return this.shaderDefines;
}
public List<String> getSamplers() {
return this.samplers;
}
public List<RenderPipeline.UniformDescription> getUniforms() {
return this.uniforms;
}
public boolean wantsDepthTexture() {
return this.depthStencilState != null;
}
public static RenderPipeline.Builder builder(RenderPipeline.Snippet... snippets) {
RenderPipeline.Builder builder = new RenderPipeline.Builder();
for (RenderPipeline.Snippet snippet : snippets) {
builder.withSnippet(snippet);
}
return builder;
}
@OnlyIn(Dist.CLIENT)
public static class Builder {
private static int nextPipelineSortKey;
private Optional<Identifier> location = Optional.empty();
private Optional<Identifier> fragmentShader = Optional.empty();
private Optional<Identifier> vertexShader = Optional.empty();
private Optional<ShaderDefines.Builder> definesBuilder = Optional.empty();
private Optional<List<String>> samplers = Optional.empty();
private Optional<List<RenderPipeline.UniformDescription>> uniforms = Optional.empty();
private Optional<DepthStencilState> depthStencilState = Optional.empty();
private Optional<PolygonMode> polygonMode = Optional.empty();
private Optional<Boolean> cull = Optional.empty();
private Optional<ColorTargetState> colorTargetState = Optional.empty();
private Optional<VertexFormat> vertexFormat = Optional.empty();
private Optional<VertexFormat.Mode> vertexFormatMode = Optional.empty();
private Builder() {
}
public RenderPipeline.Builder withLocation(String location) {
this.location = Optional.of(Identifier.withDefaultNamespace(location));
return this;
}
public RenderPipeline.Builder withLocation(Identifier location) {
this.location = Optional.of(location);
return this;
}
public RenderPipeline.Builder withFragmentShader(String fragmentShader) {
this.fragmentShader = Optional.of(Identifier.withDefaultNamespace(fragmentShader));
return this;
}
public RenderPipeline.Builder withFragmentShader(Identifier fragmentShader) {
this.fragmentShader = Optional.of(fragmentShader);
return this;
}
public RenderPipeline.Builder withVertexShader(String vertexShader) {
this.vertexShader = Optional.of(Identifier.withDefaultNamespace(vertexShader));
return this;
}
public RenderPipeline.Builder withVertexShader(Identifier vertexShader) {
this.vertexShader = Optional.of(vertexShader);
return this;
}
public RenderPipeline.Builder withShaderDefine(String key) {
if (this.definesBuilder.isEmpty()) {
this.definesBuilder = Optional.of(ShaderDefines.builder());
}
this.definesBuilder.get().define(key);
return this;
}
public RenderPipeline.Builder withShaderDefine(String key, int value) {
if (this.definesBuilder.isEmpty()) {
this.definesBuilder = Optional.of(ShaderDefines.builder());
}
this.definesBuilder.get().define(key, value);
return this;
}
public RenderPipeline.Builder withShaderDefine(String key, float value) {
if (this.definesBuilder.isEmpty()) {
this.definesBuilder = Optional.of(ShaderDefines.builder());
}
this.definesBuilder.get().define(key, value);
return this;
}
public RenderPipeline.Builder withSampler(String sampler) {
if (this.samplers.isEmpty()) {
this.samplers = Optional.of(new ArrayList<>());
}
this.samplers.get().add(sampler);
return this;
}
public RenderPipeline.Builder withUniform(String name, UniformType type) {
if (this.uniforms.isEmpty()) {
this.uniforms = Optional.of(new ArrayList<>());
}
if (type == UniformType.TEXEL_BUFFER) {
throw new IllegalArgumentException("Cannot use texel buffer without specifying texture format");
} else {
this.uniforms.get().add(new RenderPipeline.UniformDescription(name, type));
return this;
}
}
public RenderPipeline.Builder withUniform(String name, UniformType type, TextureFormat format) {
if (this.uniforms.isEmpty()) {
this.uniforms = Optional.of(new ArrayList<>());
}
if (type != UniformType.TEXEL_BUFFER) {
throw new IllegalArgumentException("Only texel buffer can specify texture format");
} else {
this.uniforms.get().add(new RenderPipeline.UniformDescription(name, format));
return this;
}
}
public RenderPipeline.Builder withPolygonMode(PolygonMode polygonMode) {
this.polygonMode = Optional.of(polygonMode);
return this;
}
public RenderPipeline.Builder withCull(boolean cull) {
this.cull = Optional.of(cull);
return this;
}
public RenderPipeline.Builder withColorTargetState(ColorTargetState colorTargetState) {
this.colorTargetState = Optional.of(colorTargetState);
return this;
}
public RenderPipeline.Builder withDepthStencilState(DepthStencilState depthStencilState) {
this.depthStencilState = Optional.of(depthStencilState);
return this;
}
public RenderPipeline.Builder withDepthStencilState(Optional<DepthStencilState> depthStencilState) {
this.depthStencilState = depthStencilState;
return this;
}
public RenderPipeline.Builder withVertexFormat(VertexFormat vertexFormat, VertexFormat.Mode vertexFormatMode) {
this.vertexFormat = Optional.of(vertexFormat);
this.vertexFormatMode = Optional.of(vertexFormatMode);
return this;
}
private void withSnippet(RenderPipeline.Snippet snippet) {
if (snippet.vertexShader.isPresent()) {
this.vertexShader = snippet.vertexShader;
}
if (snippet.fragmentShader.isPresent()) {
this.fragmentShader = snippet.fragmentShader;
}
if (snippet.shaderDefines.isPresent()) {
if (this.definesBuilder.isEmpty()) {
this.definesBuilder = Optional.of(ShaderDefines.builder());
}
ShaderDefines snippetDefines = snippet.shaderDefines.get();
for (Entry<String, String> snippetValue : snippetDefines.values().entrySet()) {
this.definesBuilder.get().define(snippetValue.getKey(), snippetValue.getValue());
}
for (String flag : snippetDefines.flags()) {
this.definesBuilder.get().define(flag);
}
}
snippet.samplers.ifPresent(builderSamplers -> {
if (this.samplers.isPresent()) {
this.samplers.get().addAll(builderSamplers);
} else {
this.samplers = Optional.of(new ArrayList<>(builderSamplers));
}
});
snippet.uniforms.ifPresent(builderUniforms -> {
if (this.uniforms.isPresent()) {
this.uniforms.get().addAll(builderUniforms);
} else {
this.uniforms = Optional.of(new ArrayList<>(builderUniforms));
}
});
if (snippet.depthStencilState.isPresent()) {
this.depthStencilState = snippet.depthStencilState;
}
if (snippet.cull.isPresent()) {
this.cull = snippet.cull;
}
if (snippet.colorTargetState.isPresent()) {
this.colorTargetState = snippet.colorTargetState;
}
if (snippet.vertexFormat.isPresent()) {
this.vertexFormat = snippet.vertexFormat;
}
if (snippet.vertexFormatMode.isPresent()) {
this.vertexFormatMode = snippet.vertexFormatMode;
}
if (snippet.polygonMode.isPresent()) {
this.polygonMode = snippet.polygonMode;
}
}
public RenderPipeline.Snippet buildSnippet() {
return new RenderPipeline.Snippet(
this.vertexShader,
this.fragmentShader,
this.definesBuilder.map(ShaderDefines.Builder::build),
this.samplers.map(Collections::unmodifiableList),
this.uniforms.map(Collections::unmodifiableList),
this.colorTargetState,
this.depthStencilState,
this.polygonMode,
this.cull,
this.vertexFormat,
this.vertexFormatMode
);
}
public RenderPipeline build() {
if (this.location.isEmpty()) {
throw new IllegalStateException("Missing location");
} else if (this.vertexShader.isEmpty()) {
throw new IllegalStateException("Missing vertex shader");
} else if (this.fragmentShader.isEmpty()) {
throw new IllegalStateException("Missing fragment shader");
} else if (this.vertexFormat.isEmpty()) {
throw new IllegalStateException("Missing vertex buffer format");
} else if (this.vertexFormatMode.isEmpty()) {
throw new IllegalStateException("Missing vertex mode");
} else {
return new RenderPipeline(
this.location.get(),
this.vertexShader.get(),
this.fragmentShader.get(),
this.definesBuilder.orElse(ShaderDefines.builder()).build(),
List.copyOf(this.samplers.orElse(new ArrayList<>())),
this.uniforms.orElse(Collections.emptyList()),
this.colorTargetState.orElse(ColorTargetState.DEFAULT),
this.depthStencilState.orElse(null),
this.polygonMode.orElse(PolygonMode.FILL),
this.cull.orElse(true),
this.vertexFormat.get(),
this.vertexFormatMode.get(),
nextPipelineSortKey++
);
}
}
}
@OnlyIn(Dist.CLIENT)
public record Snippet(
Optional<Identifier> vertexShader,
Optional<Identifier> fragmentShader,
Optional<ShaderDefines> shaderDefines,
Optional<List<String>> samplers,
Optional<List<RenderPipeline.UniformDescription>> uniforms,
Optional<ColorTargetState> colorTargetState,
Optional<DepthStencilState> depthStencilState,
Optional<PolygonMode> polygonMode,
Optional<Boolean> cull,
Optional<VertexFormat> vertexFormat,
Optional<VertexFormat.Mode> vertexFormatMode
) {
}
@OnlyIn(Dist.CLIENT)
public record UniformDescription(String name, UniformType type, @Nullable TextureFormat textureFormat) {
public UniformDescription(String name, UniformType type) {
this(name, type, null);
if (type == UniformType.TEXEL_BUFFER) {
throw new IllegalArgumentException("Texel buffer needs a texture format");
}
}
public UniformDescription(String name, TextureFormat textureFormat) {
this(name, UniformType.TEXEL_BUFFER, textureFormat);
}
}
}引用的其他类
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
ShaderDefines.builder()
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置: