2727
2828import com .mojang .blaze3d .ProjectionType ;
2929import com .mojang .blaze3d .buffers .GpuBufferSlice ;
30- import com .mojang .blaze3d .opengl .GlDevice ;
3130import com .mojang .blaze3d .opengl .GlStateManager ;
3231import com .mojang .blaze3d .opengl .GlTexture ;
32+ import com .mojang .blaze3d .opengl .GlTextureView ;
3333import com .mojang .blaze3d .pipeline .BlendFunction ;
3434import com .mojang .blaze3d .pipeline .RenderPipeline ;
3535import com .mojang .blaze3d .pipeline .RenderTarget ;
5656import org .jetbrains .annotations .Nullable ;
5757import org .joml .Matrix3x2f ;
5858import org .joml .Matrix4fStack ;
59+ import org .joml .Vector4i ;
5960import org .lwjgl .opengl .GL11 ;
60- import org .lwjgl .opengl .GL30C ;
6161import org .visuals .legacy .animatium .Animatium ;
6262
6363@ UtilityClass
@@ -78,6 +78,18 @@ public class PanoramaRendererUtility {
7878 .withVertexFormat (DefaultVertexFormat .POSITION_TEX_COLOR , VertexFormat .Mode .QUADS )
7979 .build ();
8080
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+
8193 private final ResourceLocation [] PANORAMA_LOCATIONS = new ResourceLocation []{
8294 ResourceLocation .withDefaultNamespace ("textures/gui/title/background/panorama_0.png" ),
8395 ResourceLocation .withDefaultNamespace ("textures/gui/title/background/panorama_1.png" ),
@@ -88,7 +100,8 @@ public class PanoramaRendererUtility {
88100 };
89101
90102 private CachedPerspectiveProjectionMatrixBuffer projectionMatrixBuffer = null ;
91- private GpuTextureView backgroundTextureView = null ;
103+ private GlTexture backgroundTexture = null ;
104+ private GlTextureView backgroundTextureView = null ;
92105 private float spin = 0.0F ;
93106
94107 static {
@@ -98,10 +111,15 @@ public class PanoramaRendererUtility {
98111 private void setup () {
99112 final int width = 256 ;
100113 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+
101121 if (backgroundTextureView == null ) {
102- final GpuDevice device = RenderSystem .getDevice ();
103- final GpuTexture backgroundTexture = device .createTexture (() -> "Background texture" , 15 , TextureFormat .RGBA8 , width , height , 1 , 1 );
104- backgroundTextureView = device .createTextureView (backgroundTexture );
122+ backgroundTextureView = (GlTextureView ) device .createTextureView (backgroundTexture );
105123 }
106124
107125 if (projectionMatrixBuffer == null ) {
@@ -110,27 +128,22 @@ private void setup() {
110128 }
111129
112130 public void render (final GuiGraphics guiGraphics , final RenderTarget renderTarget , final int width , final int height ) {
113- renderPanorama (renderTarget , width , height );
131+ final RenderUtils .RenderProperties properties = new RenderUtils .RenderProperties (new Vector4i (0 , 0 , 256 , 256 ), 0 );
132+ renderPanorama (PANORAMA , renderTarget , width , height , properties );
114133 for (int layer = 0 ; layer < 7 ; ++layer ) {
115- final GlTexture texture = (GlTexture ) backgroundTextureView .texture ();
116-
117- final int prevFbo = GL11 .glGetInteger (GL30C .GL_FRAMEBUFFER_BINDING );
118- final int prevTex = GL11 .glGetInteger (GL11 .GL_TEXTURE_BINDING_2D );
119- GlStateManager ._glBindFramebuffer (GL30C .GL_FRAMEBUFFER , ((GlTexture ) renderTarget .getColorTexture ()).getFbo (((GlDevice ) RenderSystem .getDevice ()).directStateAccess (), renderTarget .getDepthTexture ()));
120- GlStateManager ._bindTexture (texture .glId ());
134+ final int prevTex = GlStateManager ._getInteger (GL11 .GL_TEXTURE_BINDING_2D );
135+ GlStateManager ._bindTexture (backgroundTexture .glId ());
121136 GlStateManager ._texParameter (GL11 .GL_TEXTURE_2D , GL11 .GL_TEXTURE_MIN_FILTER , GL11 .GL_LINEAR );
122137 GlStateManager ._texParameter (GL11 .GL_TEXTURE_2D , GL11 .GL_TEXTURE_MAG_FILTER , GL11 .GL_LINEAR );
123138 GL11 .glCopyTexSubImage2D (GL11 .GL_TEXTURE_2D , 0 , 0 , 0 , 0 , 0 , 256 , 256 );
124139 GlStateManager ._bindTexture (prevTex );
125- GlStateManager ._glBindFramebuffer (GL30C .GL_FRAMEBUFFER , prevFbo );
126-
127- guiGraphics .guiRenderState .submitGuiElement (new BlitBlurSkybox (guiGraphics .pose (), backgroundTextureView , width , height ));
140+ RenderUtils .renderInGui (renderTarget , new BlitBlurTexture (guiGraphics .pose (), backgroundTextureView , width , height ), RenderUtils .RenderProperties .DEFAULT );
128141 }
129142
130- guiGraphics . guiRenderState . submitGuiElement ( new BlitFinalTexture (guiGraphics .pose (), backgroundTextureView , width , height ));
143+ // RenderUtils.renderInGui(renderTarget, new BlitFinalTexture(guiGraphics.pose(), backgroundTextureView, width, height), RenderUtils.RenderProperties.DEFAULT );
131144 }
132145
133- private void renderPanorama (final RenderTarget renderTarget , final int width , final int height ) {
146+ private void renderPanorama (final RenderPipeline pipeline , final RenderTarget renderTarget , final int width , final int height , final RenderUtils . RenderProperties renderProperties ) {
134147 RenderSystem .setProjectionMatrix (projectionMatrixBuffer .getBuffer (width , height , 120.0F ), ProjectionType .PERSPECTIVE );
135148 final Matrix4fStack modelViewStack = RenderSystem .getModelViewStack ();
136149 modelViewStack .pushMatrix ();
@@ -159,7 +172,6 @@ private void renderPanorama(final RenderTarget renderTarget, final int width, fi
159172 }
160173
161174 final GpuTextureView panoramaTexture = Minecraft .getInstance ().getTextureManager ().getTexture (PANORAMA_LOCATIONS [panoramaIdx ]).getTextureView ();
162- final RenderPipeline pipeline = PANORAMA ;
163175 try (ByteBufferBuilder byteBufferBuilder = ByteBufferBuilder .exactlySized (pipeline .getVertexFormat ().getVertexSize () * 4 )) {
164176 final BufferBuilder builder = new BufferBuilder (byteBufferBuilder , pipeline .getVertexFormatMode (), pipeline .getVertexFormat ());
165177 final int color = ARGB .white (255.0F / (i4 + 1.0F ));
@@ -168,7 +180,8 @@ private void renderPanorama(final RenderTarget renderTarget, final int width, fi
168180 builder .addVertex (1.0F , 1.0F , 1.0F ).setUv (1.0F , 1.0F ).setColor (color );
169181 builder .addVertex (-1.0F , 1.0F , 1.0F ).setUv (0.0F , 1.0F ).setColor (color );
170182 final GpuBufferSlice dynamicTransforms = DynamicTransformsBuilder .of ().withModelViewMatrix (modelViewStack ).build ();
171- RenderUtils .drawBuffer (pipeline , renderTarget , builder .buildOrThrow (), dynamicTransforms , (pass ) -> {
183+ RenderUtils .drawWithPipeline (renderTarget , pipeline , builder .buildOrThrow (), renderProperties , (pass ) -> {
184+ pass .setUniform ("DynamicTransforms" , dynamicTransforms );
172185 pass .bindSampler ("Sampler0" , panoramaTexture );
173186 });
174187 }
@@ -195,32 +208,28 @@ private float getYRot() {
195208 return -spin * 0.1F ;
196209 }
197210
198- private record BlitBlurSkybox (Matrix3x2f pose , GpuTextureView texture , int width ,
199- int height ) implements GuiElementRenderState {
211+ private record BlitBlurTexture (Matrix3x2f pose , GpuTextureView texture , int width ,
212+ int height ) implements GuiElementRenderState {
200213 @ Override
201214 public void buildVertices (VertexConsumer consumer ) {
202215 for (int cycle = 0 ; cycle < 3 ; cycle ++) {
203216 final int color = ARGB .white (1.0F / (cycle + 1 ));
204217 final float growth = (cycle - 1 ) / 256.0F ;
205- consumer .addVertexWith2DPose (this .pose , width , height ).setUv (0.0F + growth , 1.0F ).setColor (color );
206- consumer .addVertexWith2DPose (this .pose , width , 0.0F ).setUv (1.0F + growth , 1.0F ).setColor (color );
207- consumer .addVertexWith2DPose ( this . pose , 0.0F , 0.0F ).setUv (1.0F + growth , 0.0F ).setColor (color );
208- consumer .addVertexWith2DPose ( this .pose , 0.0F , height ).setUv (0.0F + growth , 0.0F ).setColor (color );
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 );
209222 }
210223 }
211224
212225 @ Override
213226 public @ NotNull RenderPipeline pipeline () {
214- return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
215- .withLocation (Animatium .location ("pipeline/panorama_blur" ))
216- .withBlend (PANORAMA_BLEND )
217- .withColorWrite (true , false )
218- .build ();
227+ return PANORAMA_BLUR ;
219228 }
220229
221230 @ Override
222231 public @ NotNull TextureSetup textureSetup () {
223- return TextureSetup .singleTexture (texture );
232+ return TextureSetup .singleTexture (this . texture );
224233 }
225234
226235 @ Override
@@ -250,9 +259,7 @@ public void buildVertices(VertexConsumer consumer) {
250259
251260 @ Override
252261 public @ NotNull RenderPipeline pipeline () {
253- return RenderPipeline .builder (RenderPipelines .GUI_TEXTURED_SNIPPET )
254- .withLocation (Animatium .location ("pipeline/blit_texture" ))
255- .build ();
262+ return SIMPLE_TEXTURE ;
256263 }
257264
258265 @ Override
0 commit comments