66import btw .lowercase .optiboxes .utils .IrisUtil ;
77import btw .lowercase .optiboxes .utils .UVRange ;
88import com .mojang .blaze3d .buffers .GpuBuffer ;
9- import com .mojang .blaze3d .pipeline .BlendFunction ;
10- import com .mojang .blaze3d .pipeline .RenderPipeline ;
119import com .mojang .blaze3d .pipeline .RenderTarget ;
1210import com .mojang .blaze3d .systems .RenderPass ;
1311import com .mojang .blaze3d .systems .RenderSystem ;
14- import com .mojang .blaze3d .textures .GpuTextureView ;
1512import com .mojang .blaze3d .vertex .*;
1613import net .minecraft .client .Minecraft ;
14+ import net .minecraft .client .renderer .texture .AbstractTexture ;
1715import net .minecraft .resources .ResourceLocation ;
1816import net .minecraft .util .Mth ;
1917import net .minecraft .world .level .Level ;
@@ -32,7 +30,6 @@ public final class OptiFineSkyRenderer {
3230 private GpuBuffer skyBuffer ;
3331 private RenderSystem .AutoStorageIndexBuffer skyBufferIndices ;
3432 private int skyBufferIndexCount ;
35- private final Map <ResourceLocation , RenderPipeline > renderPipelineCache = new HashMap <>();
3633
3734 private OptiFineSkyRenderer () {
3835 Minecraft .getInstance ().schedule (this ::buildSky );
@@ -57,12 +54,22 @@ private void buildSky() {
5754 skyBufferIndices = RenderSystem .getSequentialBuffer (vertexFormatMode );
5855 try (MeshData meshData = builder .buildOrThrow ()) {
5956 skyBufferIndexCount = meshData .drawState ().indexCount ();
60- skyBuffer = RenderSystem .getDevice ().createBuffer (() -> "OptiFine Skybox" , GpuBuffer .USAGE_COPY_DST , meshData .vertexBuffer ());
57+ skyBuffer = RenderSystem .getDevice ().createBuffer (
58+ () -> "OptiFine Skybox" ,
59+ //? >=1.21.6
60+ /*GpuBuffer.USAGE_COPY_DST,*/
61+ //? =1.21.5
62+ com .mojang .blaze3d .buffers .BufferType .VERTICES , com .mojang .blaze3d .buffers .BufferUsage .STATIC_WRITE ,
63+ meshData .vertexBuffer ()
64+ );
6165 }
6266 }
6367
64- public static RenderPipeline getSkyboxPipeline (@ Nullable BlendFunction blendFunction ) {
65- RenderPipeline .Builder builder = RenderPipeline .builder (RenderPipelinesAccessor .optiboxes$getMatricesProjectionSnippet ());
68+ //? >=1.21.5 {
69+ private final Map <ResourceLocation , com .mojang .blaze3d .pipeline .RenderPipeline > renderPipelineCache = new HashMap <>();
70+
71+ public static com .mojang .blaze3d .pipeline .RenderPipeline getSkyboxPipeline (@ Nullable com .mojang .blaze3d .pipeline .BlendFunction blendFunction ) {
72+ com .mojang .blaze3d .pipeline .RenderPipeline .Builder builder = com .mojang .blaze3d .pipeline .RenderPipeline .builder (RenderPipelinesAccessor .optiboxes$getMatricesProjectionSnippet ());
6673 builder .withLocation (OptiBoxesClient .id ("pipeline/custom_skybox" ));
6774 builder .withVertexShader (OptiBoxesClient .id ("core/custom_skybox" ));
6875 builder .withFragmentShader (OptiBoxesClient .id ("core/custom_skybox" ));
@@ -75,6 +82,7 @@ public static RenderPipeline getSkyboxPipeline(@Nullable BlendFunction blendFunc
7582 builder .withVertexFormat (DefaultVertexFormat .POSITION_TEX , VertexFormat .Mode .QUADS );
7683 return builder .build ();
7784 }
85+ //?}
7886
7987 public void renderSkybox (OptiFineSkybox optiFineSkybox , Matrix4fStack modelViewStack , Level level , float tickDelta ) {
8088 long dayTime = level .getDayTime ();
@@ -103,39 +111,62 @@ public void renderSkyLayer(OptiFineSkyLayer optiFineSkyLayer, Matrix4fStack mode
103111 }
104112
105113 Vector4f shaderColor = optiFineSkyLayer .blend ().getShaderColor (finalAlpha );
114+ AbstractTexture skyTexture = Minecraft .getInstance ().getTextureManager ().getTexture (optiFineSkyLayer .source ());
106115
107- //? >=1.21.5 {
108116 //? >=1.21.6 {
109- com .mojang .blaze3d .buffers .GpuBufferSlice transforms = btw .lowercase .optiboxes .utils .DynamicTransformsBuilder .of ()
117+ /* com.mojang.blaze3d.buffers.GpuBufferSlice transforms = btw.lowercase.optiboxes.utils.DynamicTransformsBuilder.of()
110118 .withModelViewMatrix(modelViewStack)
111119 .withShaderColor(shaderColor)
112120 .build();
113- //?} else {
114- /* RenderSystem.setShaderColor(shaderColor.x, shaderColor.y, shaderColor.z, shaderColor.w);
115- */ //?}
121+ */ //?} else {
122+ RenderSystem .setShaderColor (shaderColor .x , shaderColor .y , shaderColor .z , shaderColor .w );
123+ //?}
116124
117- RenderPipeline renderPipeline = this .renderPipelineCache .computeIfAbsent (optiFineSkyLayer .source (), (resourceLocation ) -> {
118- RenderPipeline pipeline = getSkyboxPipeline (optiFineSkyLayer .blend ().getBlendFunction ().toNative ());
125+ //? >=1.21.5 {
126+ com .mojang .blaze3d .pipeline .RenderPipeline renderPipeline = this .renderPipelineCache .computeIfAbsent (optiFineSkyLayer .source (), (resourceLocation ) -> {
127+ com .mojang .blaze3d .pipeline .RenderPipeline pipeline = getSkyboxPipeline (optiFineSkyLayer .blend ().getBlendFunction ().toNative ());
119128 IrisUtil .assignPipeline (pipeline , IrisUtil .skyTextured ());
120129 return pipeline ;
121130 });
122131
123132 RenderTarget renderTarget = Minecraft .getInstance ().getMainRenderTarget ();
133+
134+ //? >=1.21.6 {
135+ /*com.mojang.blaze3d.textures.GpuTextureView texture = skyTexture.getTextureView();
136+ com.mojang.blaze3d.textures.GpuTextureView colorTexture = renderTarget.getColorTextureView();
137+ com.mojang.blaze3d.textures.GpuTextureView depthTexture = renderTarget.useDepth ? renderTarget.getDepthTextureView() : null;
138+ */ //?} else {
139+ com .mojang .blaze3d .textures .GpuTexture texture = skyTexture .getTexture ();
140+ com .mojang .blaze3d .textures .GpuTexture colorTexture = renderTarget .getColorTexture ();
141+ com .mojang .blaze3d .textures .GpuTexture depthTexture = renderTarget .useDepth ? renderTarget .getDepthTexture () : null ;
142+ //?}
143+
124144 GpuBuffer indexBuffer = this .skyBufferIndices .getBuffer (this .skyBufferIndexCount );
125- GpuTextureView texture = Minecraft .getInstance ().getTextureManager ().getTexture (optiFineSkyLayer .source ()).getTextureView ();
126145 try (RenderPass renderPass = RenderSystem .getDevice ()
127146 .createCommandEncoder ()
128- .createRenderPass (() -> "Custom Sky Rendering" , renderTarget .getColorTextureView (), OptionalInt .empty (), renderTarget .getDepthTextureView (), OptionalDouble .empty ())) {
147+ .createRenderPass (
148+ //? >=1.21.6
149+ /*() -> "Custom Sky Rendering",*/
150+ colorTexture ,
151+ OptionalInt .empty (),
152+ depthTexture ,
153+ OptionalDouble .empty ()
154+ )) {
129155 renderPass .setPipeline (renderPipeline );
130156 renderPass .setVertexBuffer (0 , this .skyBuffer );
131157 renderPass .setIndexBuffer (indexBuffer , this .skyBufferIndices .type ());
132158 //? >=1.21.6 {
133- RenderSystem .bindDefaultUniforms (renderPass );
159+ /* RenderSystem.bindDefaultUniforms(renderPass);
134160 renderPass.setUniform("DynamicTransforms", transforms);
135- //?}
161+ */ //?}
136162 renderPass .bindSampler ("Sampler0" , texture );
137- renderPass .drawIndexed (0 , 0 , this .skyBufferIndexCount , 1 );
163+ //? >=1.21.6 {
164+ /*renderPass.drawIndexed(0, 0, this.skyBufferIndexCount, 1);
165+ */ //?} else {
166+ renderPass .drawIndexed (0 , this .skyBufferIndexCount );
167+ //?}
138168 }
169+ //?} else {
139170 //?}
140171
141172 modelViewStack .popMatrix ();
0 commit comments