--- a/com/mojang/blaze3d/pipeline/RenderPipeline.java +++ b/com/mojang/blaze3d/pipeline/RenderPipeline.java @@ -30,21 +_,42 @@ private final @Nullable ColorTargetState[] colorTargetStates; private final @Nullable VertexFormat[] vertexFormatPerBuffer = new VertexFormat[16]; private final PrimitiveTopology primitiveTopology; + private final Optional stencilTest; private final int sortKey; private static int sortKeySeed; - protected RenderPipeline( - Identifier location, - Identifier vertexShader, - Identifier fragmentShader, - ShaderDefines shaderDefines, - List bindGroupLayouts, - @Nullable ColorTargetState[] colorTargetStates, - @Nullable DepthStencilState depthStencilState, - PolygonMode polygonMode, - boolean cull, - @Nullable VertexFormat[] vertexFormatPerBuffer, - PrimitiveTopology primitiveTopology, + /// @deprecated Neo: use [#RenderPipeline(Identifier, Identifier, Identifier, ShaderDefines, List, ColorTargetState\[\], DepthStencilState, PolygonMode, boolean, VertexFormat\[\], PrimitiveTopology, Optional, int)] instead + @Deprecated + protected RenderPipeline( + Identifier location, + Identifier vertexShader, + Identifier fragmentShader, + ShaderDefines shaderDefines, + List bindGroupLayouts, + @Nullable ColorTargetState[] colorTargetStates, + @Nullable DepthStencilState depthStencilState, + PolygonMode polygonMode, + boolean cull, + @Nullable VertexFormat[] vertexFormatPerBuffer, + PrimitiveTopology primitiveTopology, + int sortKey + ) { + this(location, vertexShader, fragmentShader, shaderDefines, bindGroupLayouts, colorTargetStates, depthStencilState, polygonMode, cull, vertexFormatPerBuffer, primitiveTopology, Optional.empty(), sortKey); + } + + protected RenderPipeline( + Identifier location, + Identifier vertexShader, + Identifier fragmentShader, + ShaderDefines shaderDefines, + List bindGroupLayouts, + @Nullable ColorTargetState[] colorTargetStates, + @Nullable DepthStencilState depthStencilState, + PolygonMode polygonMode, + boolean cull, + @Nullable VertexFormat[] vertexFormatPerBuffer, + PrimitiveTopology primitiveTopology, + Optional stencilTest, int sortKey ) { this.location = location; @@ -57,6 +_,7 @@ this.cull = cull; this.colorTargetStates = colorTargetStates; this.primitiveTopology = primitiveTopology; + this.stencilTest = stencilTest; this.sortKey = sortKey; System.arraycopy(vertexFormatPerBuffer, 0, this.vertexFormatPerBuffer, 0, this.vertexFormatPerBuffer.length); } @@ -130,6 +_,48 @@ return this.depthStencilState != null; } + public Optional getStencilTest() { + return stencilTest; + } + + /** + * Neo: Create a {@link RenderPipeline.Builder} from this {@link RenderPipeline} to adjust its configuration and + * build a new, modified {@link RenderPipeline} from it + */ + public RenderPipeline.Builder toBuilder() { + RenderPipeline.Builder builder = new RenderPipeline.Builder(); + builder.location = Optional.of(this.location); + builder.fragmentShader = Optional.of(this.fragmentShader); + builder.vertexShader = Optional.of(this.vertexShader); + if (!this.shaderDefines.isEmpty()) { + ShaderDefines.Builder defBuilder = ShaderDefines.builder(); + for (Entry entry : this.shaderDefines.values().entrySet()) { + defBuilder.define(entry.getKey(), entry.getValue()); + } + for (String flag : this.shaderDefines.flags()) { + defBuilder.define(flag); + } + builder.definesBuilder = Optional.of(defBuilder); + } + if (!this.bindGroupLayouts.isEmpty()) { + builder.bindGroupLayouts = Optional.of(new ArrayList<>(this.bindGroupLayouts)); + } + builder.depthStencilState = Optional.ofNullable(this.depthStencilState); + builder.polygonMode = Optional.of(this.polygonMode); + builder.cull = Optional.of(this.cull); + System.arraycopy(this.colorTargetStates, 0, builder.colorTargetStates, 0, this.colorTargetStates.length); + int activeColorTargetStateCount = 0; + for (int i = 0; i < this.colorTargetStates.length; i++) { + if (this.colorTargetStates[i] != null) { + activeColorTargetStateCount = i + 1; + } + } + System.arraycopy(this.vertexFormatPerBuffer, 0, builder.vertexFormatPerBuffer, 0, this.vertexFormatPerBuffer.length); + builder.primitiveTopology = Optional.of(this.primitiveTopology); + builder.stencilTest = this.stencilTest; + return builder; + } + public static RenderPipeline.Builder builder(RenderPipeline.Snippet... snippets) { RenderPipeline.Builder builder = new RenderPipeline.Builder(); @@ -154,6 +_,7 @@ private int activeColorTargetStateCount; private final @Nullable VertexFormat[] vertexFormatPerBuffer = new VertexFormat[16]; private Optional primitiveTopology = Optional.empty(); + private Optional stencilTest = Optional.empty(); private Builder() { } @@ -270,6 +_,16 @@ return this; } + public RenderPipeline.Builder withStencilTest(net.neoforged.neoforge.client.stencil.StencilTest stencilTest) { + this.stencilTest = Optional.of(stencilTest); + return this; + } + + public RenderPipeline.Builder withoutStencilTest(){ + this.stencilTest = Optional.empty(); + return this; + } + private void withSnippet(RenderPipeline.Snippet snippet) { if (snippet.vertexShader.isPresent()) { this.vertexShader = snippet.vertexShader; @@ -332,6 +_,10 @@ if (snippet.polygonMode.isPresent()) { this.polygonMode = snippet.polygonMode; } + + if (snippet.stencilTest.isPresent()) { + this.stencilTest = snippet.stencilTest; + } } public RenderPipeline.Snippet buildSnippet() { @@ -346,7 +_,8 @@ this.polygonMode, this.cull, this.vertexFormatPerBuffer, - this.primitiveTopology + this.primitiveTopology, + this.stencilTest ); } @@ -411,6 +_,7 @@ this.cull.orElse(true), this.vertexFormatPerBuffer, this.primitiveTopology.get(), + this.stencilTest, nextPipelineSortKey++ ); } @@ -428,7 +_,25 @@ Optional polygonMode, Optional cull, @Nullable VertexFormat[] vertexFormatPerBuffer, - Optional vertexFormatMode + Optional vertexFormatMode, + Optional stencilTest ) { + /// @deprecated Neo: use [#Snippet(Optional, Optional, Optional, Optional, ColorTargetState\[\], int, Optional, Optional, Optional, VertexFormat\[\], Optional, Optional)] instead + @Deprecated + public Snippet( + Optional vertexShader, + Optional fragmentShader, + Optional shaderDefines, + Optional> bindGroupLayouts, + @Nullable ColorTargetState[] colorTargetStates, + int activeColorTargetStateCount, + Optional depthStencilState, + Optional polygonMode, + Optional cull, + @Nullable VertexFormat[] vertexFormatPerBuffer, + Optional vertexFormatMode + ) { + this(vertexShader, fragmentShader, shaderDefines, bindGroupLayouts, colorTargetStates, activeColorTargetStateCount, depthStencilState, polygonMode, cull, vertexFormatPerBuffer, vertexFormatMode, Optional.empty()); + } } }