2727
2828import com .mojang .blaze3d .ProjectionType ;
2929import com .mojang .blaze3d .buffers .GpuBufferSlice ;
30- import com .mojang .blaze3d .opengl .GlStateManager ;
31- import com .mojang .blaze3d .opengl .GlTexture ;
32- import com .mojang .blaze3d .opengl .GlTextureView ;
3330import com .mojang .blaze3d .pipeline .BlendFunction ;
3431import com .mojang .blaze3d .pipeline .RenderPipeline ;
3532import com .mojang .blaze3d .pipeline .RenderTarget ;
3633import com .mojang .blaze3d .platform .DestFactor ;
3734import com .mojang .blaze3d .platform .SourceFactor ;
38- import com .mojang .blaze3d .systems .GpuDevice ;
3935import com .mojang .blaze3d .systems .RenderSystem ;
40- import com .mojang .blaze3d .textures .GpuTexture ;
4136import com .mojang .blaze3d .textures .GpuTextureView ;
42- import com .mojang .blaze3d .textures .TextureFormat ;
4337import com .mojang .blaze3d .vertex .*;
4438import lombok .experimental .UtilityClass ;
4539import net .minecraft .client .Minecraft ;
5650import org .jetbrains .annotations .Nullable ;
5751import org .joml .Matrix3x2f ;
5852import org .joml .Matrix4fStack ;
59- import org .joml .Vector4i ;
60- import org .lwjgl .opengl .GL11 ;
6153import org .visuals .legacy .animatium .Animatium ;
6254
6355@ UtilityClass
@@ -78,18 +70,6 @@ public class PanoramaRendererUtility {
7870 .withVertexFormat (DefaultVertexFormat .POSITION_TEX_COLOR , VertexFormat .Mode .QUADS )
7971 .build ();
8072
81- private final RenderPipeline PANORAMA_BLUR =
82- RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
83- .withLocation (Animatium .location ("pipeline/panorama_blur" ))
84- .withBlend (PANORAMA_BLEND )
85- .withColorWrite (true , false )
86- .build ();
87-
88- private final RenderPipeline SIMPLE_TEXTURE =
89- RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
90- .withLocation (Animatium .location ("pipeline/blit_texture" ))
91- .build ();
92-
9373 private final ResourceLocation [] PANORAMA_LOCATIONS = new ResourceLocation []{
9474 ResourceLocation .withDefaultNamespace ("textures/gui/title/background/panorama_0.png" ),
9575 ResourceLocation .withDefaultNamespace ("textures/gui/title/background/panorama_1.png" ),
@@ -100,50 +80,33 @@ public class PanoramaRendererUtility {
10080 };
10181
10282 private CachedPerspectiveProjectionMatrixBuffer projectionMatrixBuffer = null ;
103- private GlTexture backgroundTexture = null ;
104- private GlTextureView backgroundTextureView = null ;
83+ private PanoramaTarget panoramaTarget = null ;
10584 private float spin = 0.0F ;
10685
10786 static {
10887 setup ();
10988 }
11089
11190 private void setup () {
112- final int width = 256 ;
113- final int height = 256 ;
114-
115- final GpuDevice device = RenderSystem .getDevice ();
116- if (backgroundTexture == null ) {
117- final int flags = GpuTexture .USAGE_RENDER_ATTACHMENT | GpuTexture .USAGE_TEXTURE_BINDING | GpuTexture .USAGE_COPY_SRC ;
118- backgroundTexture = (GlTexture ) device .createTexture (() -> "Background texture" , flags , TextureFormat .RGBA8 , width , height , 1 , 1 );
119- }
120-
121- if (backgroundTextureView == null ) {
122- backgroundTextureView = (GlTextureView ) device .createTextureView (backgroundTexture );
91+ if (panoramaTarget == null ) {
92+ panoramaTarget = new PanoramaTarget ();
12393 }
12494
12595 if (projectionMatrixBuffer == null ) {
12696 projectionMatrixBuffer = new CachedPerspectiveProjectionMatrixBuffer ("panorama" , 0.05F , 10.0F );
12797 }
12898 }
12999
130- public void render (final GuiGraphics guiGraphics , final RenderTarget renderTarget , final int width , final int height ) {
131- final RenderUtils .RenderOverrides properties = new RenderUtils .RenderOverrides (new Vector4i (0 , 0 , 256 , 256 ), 0 );
132- renderPanorama (PANORAMA , renderTarget , width , height , properties );
100+ public void render (final GuiGraphics guiGraphics , final int width , final int height ) {
101+ renderPanorama (PANORAMA , panoramaTarget , width , height );
133102 for (int layer = 0 ; layer < 7 ; ++layer ) {
134- final int prevTex = GlStateManager ._getInteger (GL11 .GL_TEXTURE_BINDING_2D );
135- GlStateManager ._bindTexture (backgroundTexture .glId ());
136- GlStateManager ._texParameter (GL11 .GL_TEXTURE_2D , GL11 .GL_TEXTURE_MIN_FILTER , GL11 .GL_LINEAR );
137- GlStateManager ._texParameter (GL11 .GL_TEXTURE_2D , GL11 .GL_TEXTURE_MAG_FILTER , GL11 .GL_LINEAR );
138- GL11 .glCopyTexSubImage2D (GL11 .GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , 256 , 256 );
139- GlStateManager ._bindTexture (prevTex );
140- RenderUtils .drawInGui (renderTarget , new BlitBlurTexture (guiGraphics .pose (), backgroundTextureView , width , height ), RenderUtils .RenderOverrides .DEFAULT );
103+ RenderUtils .drawInGui (panoramaTarget , new BlitBlurTexture (guiGraphics .pose (), panoramaTarget .getColorTextureView (), width , height ));
141104 }
142105
143- // RenderUtils.renderInGui(renderTarget, new BlitFinalTexture(guiGraphics.pose(), backgroundTextureView , width, height), RenderUtils.RenderProperties.DEFAULT );
106+ guiGraphics . guiRenderState . submitGuiElement ( new BlitFinalTexture (guiGraphics .pose (), panoramaTarget . getColorTextureView () , width , height , ARGB . white ( 1.0F )) );
144107 }
145108
146- private void renderPanorama (final RenderPipeline pipeline , final RenderTarget renderTarget , final int width , final int height , final RenderUtils . RenderOverrides renderOverrides ) {
109+ private void renderPanorama (final RenderPipeline pipeline , final RenderTarget renderTarget , final int width , final int height ) {
147110 RenderSystem .setProjectionMatrix (projectionMatrixBuffer .getBuffer (width , height , 120.0F ), ProjectionType .PERSPECTIVE );
148111 final Matrix4fStack modelViewStack = RenderSystem .getModelViewStack ();
149112 modelViewStack .pushMatrix ();
@@ -180,7 +143,7 @@ private void renderPanorama(final RenderPipeline pipeline, final RenderTarget re
180143 builder .addVertex (1.0F , 1.0F , 1.0F ).setUv (1.0F , 1.0F ).setColor (color );
181144 builder .addVertex (-1.0F , 1.0F , 1.0F ).setUv (0.0F , 1.0F ).setColor (color );
182145 final GpuBufferSlice dynamicTransforms = DynamicTransformsBuilder .of ().withModelViewMatrix (modelViewStack ).build ();
183- RenderUtils .drawWithPipeline (renderTarget , pipeline , builder .buildOrThrow (), renderOverrides , (pass ) -> {
146+ RenderUtils .drawWithPipeline (renderTarget , pipeline , builder .buildOrThrow (), (pass ) -> {
184147 pass .setUniform ("DynamicTransforms" , dynamicTransforms );
185148 pass .bindSampler ("Sampler0" , panoramaTexture );
186149 });
@@ -193,7 +156,6 @@ private void renderPanorama(final RenderPipeline pipeline, final RenderTarget re
193156 }
194157
195158 modelViewStack .popMatrix ();
196-
197159 }
198160
199161 public void update (float tickDelta ) {
@@ -208,23 +170,26 @@ private float getYRot() {
208170 return -spin * 0.1F ;
209171 }
210172
211- private record BlitBlurTexture (Matrix3x2f pose , GpuTextureView texture , int width ,
212- int height ) implements GuiElementRenderState {
173+ private record BlitBlurTexture (Matrix3x2f pose , GpuTextureView texture , int width , int height ) implements GuiElementRenderState {
213174 @ Override
214175 public void buildVertices (VertexConsumer consumer ) {
215176 for (int cycle = 0 ; cycle < 3 ; cycle ++) {
216177 final int color = ARGB .white (1.0F / (cycle + 1 ));
217178 final float growth = (cycle - 1 ) / 256.0F ;
218- consumer .addVertex (this .width , this .height , 0.0F ).setUv (0.0F + growth , 1.0F ).setColor (color );
219- consumer .addVertex (this .width , 0.0F , 0.0F ).setUv (1.0F + growth , 1.0F ).setColor (color );
220- consumer .addVertex ( 0.0F , 0.0F , 0.0F ).setUv (1.0F + growth , 0.0F ).setColor (color );
221- consumer .addVertex ( 0.0F , this .height , 0.0F ).setUv (0.0F + growth , 0.0F ).setColor (color );
179+ consumer .addVertexWith2DPose (this .pose , this .width , this . height ).setUv (0.0F + growth , 1.0F ).setColor (color );
180+ consumer .addVertexWith2DPose (this .pose , this . width , 0.0F ).setUv (1.0F + growth , 1.0F ).setColor (color );
181+ consumer .addVertexWith2DPose ( this . pose , 0.0F , 0.0F ).setUv (1.0F + growth , 0.0F ).setColor (color );
182+ consumer .addVertexWith2DPose ( this . pose , 0.0F , this .height ).setUv (0.0F + growth , 0.0F ).setColor (color );
222183 }
223184 }
224185
225186 @ Override
226187 public @ NotNull RenderPipeline pipeline () {
227- return PANORAMA_BLUR ;
188+ return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
189+ .withLocation (Animatium .location ("pipeline/panorama_blur" ))
190+ .withBlend (PANORAMA_BLEND )
191+ .withColorWrite (true , false )
192+ .build ();
228193 }
229194
230195 @ Override
@@ -243,28 +208,26 @@ public void buildVertices(VertexConsumer consumer) {
243208 }
244209 }
245210
246- private record BlitFinalTexture (Matrix3x2f pose , GpuTextureView texture , int width ,
247- int height ) implements GuiElementRenderState {
211+ public record BlitFinalTexture (Matrix3x2f pose , GpuTextureView texture , int width , int height , int color ) implements GuiElementRenderState {
248212 @ Override
249213 public void buildVertices (VertexConsumer consumer ) {
250- float aspect = 120.0F / (Math .max (this .width , this .height ));
251- float sw = this .width * aspect / 256.0F ;
252- float sh = this .height * aspect / 256.0F ;
253- final int color = ARGB .white (1.0F );
254- consumer .addVertexWith2DPose (this .pose , 0.0F , this .height ).setUv (0.5F - sh , 0.5F + sw ).setColor (color );
255- consumer .addVertexWith2DPose (this .pose , this .width , this .height ).setUv (0.5F - sh , 0.5F - sw ).setColor (color );
256- consumer .addVertexWith2DPose (this .pose , this .width , 0.0F ).setUv (0.5F + sh , 0.5F - sw ).setColor (color );
257- consumer .addVertexWith2DPose (this .pose , 0.0F , 0.0F ).setUv (0.5F + sh , 0.5F + sw ).setColor (color );
214+ final float aspect = 120.0F / (Math .max (this .width , this .height ));
215+ final float sw = this .width * aspect / panoramaTarget .width ;
216+ final float sh = this .height * aspect / panoramaTarget .height ;
217+ consumer .addVertexWith2DPose (this .pose , 0.0F , this .height ).setUv (0.5F - sh , 0.5F + sw ).setColor (this .color );
218+ consumer .addVertexWith2DPose (this .pose , this .width , this .height ).setUv (0.5F - sh , 0.5F - sw ).setColor (this .color );
219+ consumer .addVertexWith2DPose (this .pose , this .width , 0.0F ).setUv (0.5F + sh , 0.5F - sw ).setColor (this .color );
220+ consumer .addVertexWith2DPose (this .pose , 0.0F , 0.0F ).setUv (0.5F + sh , 0.5F + sw ).setColor (this .color );
258221 }
259222
260223 @ Override
261224 public @ NotNull RenderPipeline pipeline () {
262- return SIMPLE_TEXTURE ;
225+ return RenderPipelines . GUI_TEXTURED ;
263226 }
264227
265228 @ Override
266229 public @ NotNull TextureSetup textureSetup () {
267- return TextureSetup .singleTexture (texture );
230+ return TextureSetup .singleTexture (this . texture );
268231 }
269232
270233 @ Override
0 commit comments