3030import com .mojang .blaze3d .opengl .GlStateManager ;
3131import com .mojang .blaze3d .opengl .GlTexture ;
3232import com .mojang .blaze3d .opengl .GlTextureView ;
33- import com .mojang .blaze3d .pipeline .BlendFunction ;
3433import com .mojang .blaze3d .pipeline .RenderPipeline ;
35- import com .mojang .blaze3d .pipeline .RenderTarget ;
36- import com .mojang .blaze3d .platform .DestFactor ;
37- import com .mojang .blaze3d .platform .SourceFactor ;
3834import com .mojang .blaze3d .systems .GpuDevice ;
3935import com .mojang .blaze3d .systems .RenderSystem ;
40- import com .mojang .blaze3d .textures .FilterMode ;
4136import com .mojang .blaze3d .textures .TextureFormat ;
42- import com .mojang .blaze3d .vertex .BufferBuilder ;
43- import com .mojang .blaze3d .vertex .ByteBufferBuilder ;
44- import com .mojang .blaze3d .vertex .DefaultVertexFormat ;
45- import com .mojang .blaze3d .vertex .VertexFormat ;
46- import net .minecraft .client .Minecraft ;
4737import net .minecraft .client .gui .GuiGraphics ;
4838import net .minecraft .client .renderer .PanoramaRenderer ;
49- import net .minecraft .client .renderer .RenderPipelines ;
5039import net .minecraft .resources .ResourceLocation ;
51- import net .minecraft .util .ARGB ;
52- import org .joml .Matrix3x2f ;
53- import org .spongepowered .asm .mixin .Final ;
5440import org .spongepowered .asm .mixin .Mixin ;
55- import org .spongepowered .asm .mixin .Shadow ;
5641import org .spongepowered .asm .mixin .Unique ;
5742import org .spongepowered .asm .mixin .injection .At ;
5843import org .spongepowered .asm .mixin .injection .Inject ;
5944import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
6045import org .visuals .legacy .animatium .Animatium ;
6146import org .visuals .legacy .animatium .config .AnimatiumConfig ;
62- import org .visuals .legacy .animatium .util .RenderUtils ;
47+ import org .visuals .legacy .animatium .util .PanoramaRendererUtility ;
6348
6449@ Mixin (PanoramaRenderer .class )
6550public abstract class MixinPanoramaRenderer_LegacyRendering {
66- @ Unique
67- private static final RenderPipeline .Snippet animatium$TEXTURE_SNIPPET =
68- RenderPipeline .builder (RenderPipelines .MATRICES_PROJECTION_SNIPPET )
69- .withVertexShader ("core/position_tex" )
70- .withFragmentShader ("core/position_tex" )
71- .withSampler ("Sampler0" )
72- .withVertexFormat (DefaultVertexFormat .POSITION_TEX_COLOR , VertexFormat .Mode .QUADS )
73- .buildSnippet ();
74- @ Unique
75- private static final RenderPipeline animatium$BLUR_TEXTURE =
76- RenderPipeline .builder (animatium$TEXTURE_SNIPPET )
77- .withLocation (Animatium .id ("pipeline/blur_texture" ))
78- .withColorWrite (true , false )
79- .withBlend (new BlendFunction (SourceFactor .SRC_ALPHA , DestFactor .ONE_MINUS_SRC_ALPHA , SourceFactor .ONE , DestFactor .ZERO ))
80- .build ();
81- @ Unique
82- private static final RenderPipeline animatium$BASIC_TEXTURE =
83- RenderPipeline .builder (animatium$TEXTURE_SNIPPET )
84- .withLocation (Animatium .id ("pipeline/basic_texture" ))
85- .build ();
86- @ Shadow
87- @ Final
88- private Minecraft minecraft ;
89- @ Unique
90- private GlTexture animatium$backgroundTexture ;
91-
9251 @ Unique
9352 private GlTextureView animatium$backgroundTextureView ;
9453
9554 @ Inject (method = "render" , at = @ At ("HEAD" ))
9655 private void animatium$panoramaStart (GuiGraphics guiGraphics , int width , int height , boolean spin , CallbackInfo ci ) {
9756 if (Animatium .ENABLED && AnimatiumConfig .instance ().screen .panoramaRendering ) {
98- if (animatium$backgroundTexture == null ) {
99- GpuDevice device = RenderSystem .getDevice ();
100- animatium$backgroundTexture = (GlTexture ) device .createTexture (() -> "Background texture" , 15 , TextureFormat .RGBA8 , 256 , 256 , 1 , 1 );
57+ if (animatium$backgroundTextureView == null ) {
58+ final GpuDevice device = RenderSystem .getDevice ();
59+ final GlTexture animatium$backgroundTexture = (GlTexture ) device .createTexture (() -> "Background texture" , 15 , TextureFormat .RGBA8 , 256 , 256 , 1 , 1 );
10160 animatium$backgroundTextureView = (GlTextureView ) device .createTextureView (animatium$backgroundTexture );
10261 }
10362
@@ -108,13 +67,7 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
10867 @ Inject (method = "render" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/renderer/CubeMap;render(Lnet/minecraft/client/Minecraft;FF)V" , ordinal = 0 , shift = At .Shift .AFTER ))
10968 private void animatium$panoramaFinish (GuiGraphics guiGraphics , int width , int height , boolean spin , CallbackInfo ci ) {
11069 if (Animatium .ENABLED && AnimatiumConfig .instance ().screen .panoramaRendering ) {
111- final RenderTarget renderTarget = minecraft .getMainRenderTarget ();
112- for (int i = 0 ; i < 6 ; ++i ) {
113- this .animatium$writeAndBlitBlurTexture (guiGraphics , renderTarget , animatium$backgroundTextureView , width , height );
114- }
115-
116- GlStateManager ._viewport (0 , 0 , renderTarget .width , renderTarget .height );
117- animatium$renderFinalTexture (renderTarget , animatium$backgroundTextureView , width , height );
70+ PanoramaRendererUtility .render (guiGraphics .pose (), animatium$backgroundTextureView , width , height );
11871 }
11972 }
12073
@@ -127,55 +80,4 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
12780 original .call (instance , pipeline , atlas , x , y , u , v , width , height , uWidth , vHeight , textureWidth , textureHeight );
12881 }
12982 }
130-
131- @ Unique
132- private void animatium$writeAndBlitBlurTexture (GuiGraphics guiGraphics , RenderTarget renderTarget , GlTextureView texture , int width , int height ) {
133- texture .texture ().setTextureFilter (FilterMode .LINEAR , false );
134- // Ensures enough width/height for it to not crash when window is resized
135- if (renderTarget .width >= 256 && renderTarget .height >= 256 ) {
136- RenderSystem .getDevice ().createCommandEncoder ().copyTextureToTexture (
137- renderTarget .getColorTexture (),
138- texture .texture (),
139- 0 , // mips?
140- 0 , 0 , // srcXY
141- 0 , 0 , // dstXY
142- 256 , 256 // w/h
143- );
144- }
145-
146- RenderPipeline pipeline = animatium$BLUR_TEXTURE ;
147- ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder (pipeline .getVertexFormat ().getVertexSize () * 12 );
148- BufferBuilder bufferBuilder = new BufferBuilder (byteBufferBuilder , pipeline .getVertexFormatMode (), pipeline .getVertexFormat ());
149- final Matrix3x2f matrix = guiGraphics .pose ();
150- for (int i = 0 ; i < 3 ; ++i ) {
151- final float growth = (float ) (i - 1 ) / 256.0F ;
152- final int color = ARGB .colorFromFloat (1.0F / (float ) (i + 1 ), 1.0F , 1.0F , 1.0F );
153- bufferBuilder .addVertexWith2DPose (matrix , width , height ).setUv (0.0F + growth , 1.0F ).setColor (color );
154- bufferBuilder .addVertexWith2DPose (matrix , width , 0.0F ).setUv (1.0F + growth , 1.0F ).setColor (color );
155- bufferBuilder .addVertexWith2DPose (matrix , 0.0F , 0.0F ).setUv (1.0F + growth , 0.0F ).setColor (color );
156- bufferBuilder .addVertexWith2DPose (matrix , 0.0F , height ).setUv (0.0F + growth , 0.0F ).setColor (color );
157- }
158-
159- RenderUtils .drawBuffer (animatium$BLUR_TEXTURE , renderTarget , bufferBuilder .buildOrThrow (), (pass ) -> {
160- pass .bindSampler ("Sampler0" , texture );
161- });
162- }
163-
164- @ Unique
165- private void animatium$renderFinalTexture (RenderTarget renderTarget , GlTextureView texture , int width , int height ) {
166- float f = 120.0F / (float ) (Math .max (width , height ));
167- float g = (float ) height * f / 256.0F ;
168- float h = (float ) width * f / 256.0F ;
169- final int color = ARGB .white (1.0F );
170- RenderPipeline pipeline = animatium$BASIC_TEXTURE ;
171- ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder (pipeline .getVertexFormat ().getVertexSize () * 4 );
172- BufferBuilder bufferBuilder = new BufferBuilder (byteBufferBuilder , pipeline .getVertexFormatMode (), pipeline .getVertexFormat ());
173- bufferBuilder .addVertex (0.0F , height , 0.0F ).setUv (0.5F - g , 0.5F + h ).setColor (color );
174- bufferBuilder .addVertex (width , height , 0.0F ).setUv (0.5F - g , 0.5F - h ).setColor (color );
175- bufferBuilder .addVertex (width , 0.0F , 0.0F ).setUv (0.5F + g , 0.5F - h ).setColor (color );
176- bufferBuilder .addVertex (0.0F , 0.0F , 0.0F ).setUv (0.5F + g , 0.5F + h ).setColor (color );
177- RenderUtils .drawBuffer (animatium$BASIC_TEXTURE , renderTarget , bufferBuilder .buildOrThrow (), (pass ) -> {
178- pass .bindSampler ("Sampler0" , texture );
179- });
180- }
18183}
0 commit comments