2626package org .visuals .legacy .animatium .util ;
2727
2828import com .mojang .blaze3d .opengl .GlStateManager ;
29+ import com .mojang .blaze3d .opengl .GlTexture ;
30+ import com .mojang .blaze3d .opengl .GlTextureView ;
2931import com .mojang .blaze3d .pipeline .BlendFunction ;
3032import com .mojang .blaze3d .pipeline .RenderPipeline ;
3133import com .mojang .blaze3d .pipeline .RenderTarget ;
3739import com .mojang .blaze3d .textures .GpuTexture ;
3840import com .mojang .blaze3d .textures .GpuTextureView ;
3941import com .mojang .blaze3d .textures .TextureFormat ;
40- import com .mojang .blaze3d .vertex .* ;
42+ import com .mojang .blaze3d .vertex .VertexConsumer ;
4143import lombok .experimental .UtilityClass ;
4244import net .minecraft .client .Minecraft ;
4345import net .minecraft .client .gui .GuiGraphics ;
5052import org .jetbrains .annotations .NotNull ;
5153import org .jetbrains .annotations .Nullable ;
5254import org .joml .Matrix3x2f ;
55+ import org .lwjgl .opengl .GL11 ;
56+ import org .lwjgl .opengl .GL30C ;
5357import org .visuals .legacy .animatium .Animatium ;
5458
5559@ UtilityClass
5660// Ported code of the old <=1.12.2 panorama renderer (w/ blur)
5761public class PanoramaRendererUtility {
58- private final RenderPipeline .Snippet TEXTURE_SNIPPET =
59- RenderPipeline .builder (RenderPipelines .MATRICES_PROJECTION_SNIPPET )
60- .withVertexShader ("core/position_tex" )
61- .withFragmentShader ("core/position_tex" )
62- .withSampler ("Sampler0" )
63- .withVertexFormat (DefaultVertexFormat .POSITION_TEX_COLOR , VertexFormat .Mode .QUADS )
64- .buildSnippet ();
65-
6662 private GpuTextureView backgroundTextureView = null ;
6763 private float spin = 0.0F ;
6864
@@ -89,32 +85,11 @@ public void setup() {
8985 public void render (GuiGraphics guiGraphics , int width , int height ) {
9086 final RenderTarget renderTarget = Minecraft .getInstance ().getMainRenderTarget ();
9187 for (int i = 0 ; i < 7 ; ++i ) {
92- final BlurTextureBlit blurTextureBlit = new BlurTextureBlit (guiGraphics .pose (), renderTarget , backgroundTextureView , width , height );
93- try (ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder (blurTextureBlit .pipeline ().getVertexFormat ().getVertexSize () * 12 )) {
94- final BufferBuilder builder = new BufferBuilder (byteBufferBuilder , blurTextureBlit .pipeline ().getVertexFormatMode (), blurTextureBlit .pipeline ().getVertexFormat ());
95- blurTextureBlit .buildVertices (builder );
96- RenderUtils .drawBuffer (
97- blurTextureBlit .pipeline (),
98- renderTarget ,
99- builder .buildOrThrow (),
100- DynamicTransformsBuilder .of ().build (),
101- (pass ) -> pass .bindSampler ("Sampler0" , blurTextureBlit .textureSetup ().texure0 ())
102- );
103- }
88+ guiGraphics .guiRenderState .submitGuiElement (new BlurTextureBlit (guiGraphics .pose (), renderTarget , backgroundTextureView , width , height ));
10489 }
10590
106- final FinalTextureBlit finalTextureBlit = new FinalTextureBlit (guiGraphics .pose (), backgroundTextureView , width , height , 120.0F / (float ) (Math .max (width , height )));
107- try (ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder (finalTextureBlit .pipeline ().getVertexFormat ().getVertexSize () * 4 )) {
108- final BufferBuilder builder = new BufferBuilder (byteBufferBuilder , finalTextureBlit .pipeline ().getVertexFormatMode (), finalTextureBlit .pipeline ().getVertexFormat ());
109- finalTextureBlit .buildVertices (builder );
110- RenderUtils .drawBuffer (
111- finalTextureBlit .pipeline (),
112- renderTarget ,
113- builder .buildOrThrow (),
114- DynamicTransformsBuilder .of ().build (),
115- (pass ) -> pass .bindSampler ("Sampler0" , finalTextureBlit .textureSetup ().texure0 ())
116- );
117- }
91+ GlStateManager ._bindTexture (((GlTexture ) renderTarget .getColorTexture ()).glId ());
92+ guiGraphics .guiRenderState .submitGuiElement (new FinalTextureBlit (guiGraphics .pose (), backgroundTextureView , width , height , 120.0F / (float ) (Math .max (width , height ))));
11893 }
11994
12095 /**
@@ -135,26 +110,10 @@ public float getYRot() {
135110 }
136111
137112 private record BlurTextureBlit (Matrix3x2f pose , RenderTarget renderTarget , GpuTextureView textureView , int width , int height ) implements GuiElementRenderState {
138- private static final RenderPipeline BLUR_TEXTURED_PIPELINE =
139- RenderPipeline .builder (TEXTURE_SNIPPET )
140- .withLocation (Animatium .location ("pipeline/blur_texture" ))
141- .withColorWrite (true , false )
142- .withBlend (new BlendFunction (SourceFactor .SRC_ALPHA , DestFactor .ONE_MINUS_SRC_ALPHA , SourceFactor .ONE , DestFactor .ZERO ))
143- .build ();
144-
145113 public BlurTextureBlit {
146114 textureView .texture ().setTextureFilter (FilterMode .LINEAR , FilterMode .LINEAR , false );
147- // Ensures enough width/height for it to not crash when window is resized
148- if (renderTarget .width >= 256 && renderTarget .height >= 256 ) {
149- RenderSystem .getDevice ().createCommandEncoder ().copyTextureToTexture (
150- renderTarget .getColorTexture (),
151- textureView .texture (),
152- 0 , // mips?
153- 0 , 0 , // srcXY
154- 0 , 0 , // dstXY
155- 256 , 256 // w/h
156- );
157- }
115+ GlStateManager ._bindTexture (((GlTextureView ) textureView ).texture ().glId ());
116+ GL30C .glCopyTexSubImage2D (GL11 .GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , 256 , 256 );
158117 }
159118
160119 @ Override
@@ -171,7 +130,11 @@ public void buildVertices(VertexConsumer consumer) {
171130
172131 @ Override
173132 public @ NotNull RenderPipeline pipeline () {
174- return BLUR_TEXTURED_PIPELINE ;
133+ return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
134+ .withLocation (Animatium .location ("pipeline/blur_texture" ))
135+ .withColorWrite (true , false )
136+ .withBlend (new BlendFunction (SourceFactor .SRC_ALPHA , DestFactor .ONE_MINUS_SRC_ALPHA , SourceFactor .ONE , DestFactor .ZERO ))
137+ .build ();
175138 }
176139
177140 @ Override
@@ -191,11 +154,6 @@ public void buildVertices(VertexConsumer consumer) {
191154 }
192155
193156 private record FinalTextureBlit (Matrix3x2f pose , GpuTextureView textureView , int width , int height , float aspect ) implements GuiElementRenderState {
194- private static final RenderPipeline BASIC_TEXTURED_PIPELINE =
195- RenderPipeline .builder (TEXTURE_SNIPPET )
196- .withLocation (Animatium .location ("pipeline/basic_texture" ))
197- .build ();
198-
199157 @ Override
200158 public void buildVertices (VertexConsumer consumer ) {
201159 final int color = ARGB .white (1.0F );
@@ -209,7 +167,9 @@ public void buildVertices(VertexConsumer consumer) {
209167
210168 @ Override
211169 public @ NotNull RenderPipeline pipeline () {
212- return BASIC_TEXTURED_PIPELINE ;
170+ return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
171+ .withLocation (Animatium .location ("pipeline/basic_texture" ))
172+ .build ();
213173 }
214174
215175 @ Override
0 commit comments