Skip to content

Commit c5d05a4

Browse files
committed
Refactor PanoramaRendererUtility and MixinPanoramaRenderer_LegacyRendering more
1 parent a141d28 commit c5d05a4

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

src/main/java/org/visuals/legacy/animatium/mixins/v1/gui/MixinPanoramaRenderer_LegacyRendering.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,21 @@
2828
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2929
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
3030
import com.llamalad7.mixinextras.sugar.Local;
31-
import com.mojang.blaze3d.opengl.GlStateManager;
32-
import com.mojang.blaze3d.opengl.GlTexture;
33-
import com.mojang.blaze3d.opengl.GlTextureView;
3431
import com.mojang.blaze3d.pipeline.RenderPipeline;
35-
import com.mojang.blaze3d.systems.GpuDevice;
36-
import com.mojang.blaze3d.systems.RenderSystem;
37-
import com.mojang.blaze3d.textures.TextureFormat;
3832
import net.minecraft.client.Minecraft;
3933
import net.minecraft.client.gui.GuiGraphics;
4034
import net.minecraft.client.renderer.CubeMap;
4135
import net.minecraft.client.renderer.PanoramaRenderer;
4236
import net.minecraft.resources.ResourceLocation;
43-
import net.minecraft.util.Mth;
4437
import org.spongepowered.asm.mixin.Mixin;
45-
import org.spongepowered.asm.mixin.Unique;
4638
import org.spongepowered.asm.mixin.injection.At;
4739
import org.visuals.legacy.animatium.Animatium;
4840
import org.visuals.legacy.animatium.config.AnimatiumConfig;
4941
import org.visuals.legacy.animatium.util.PanoramaRendererUtility;
5042

5143
@Mixin(PanoramaRenderer.class)
5244
public abstract class MixinPanoramaRenderer_LegacyRendering {
53-
@Unique
54-
private GlTextureView animatium$backgroundTextureView;
5545

56-
@Unique
57-
private float animatium$spin = 0.0F;
5846

5947
@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CubeMap;render(Lnet/minecraft/client/Minecraft;FF)V", ordinal = 0))
6048
private void animatium$panoramaRendering(
@@ -69,22 +57,15 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
6957
) {
7058
final boolean enabled = Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering;
7159
if (enabled) {
72-
if (animatium$backgroundTextureView == null) {
73-
final GpuDevice device = RenderSystem.getDevice();
74-
final GlTexture animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1);
75-
animatium$backgroundTextureView = (GlTextureView) device.createTextureView(animatium$backgroundTexture);
76-
}
77-
78-
animatium$spin += minecraft.getDeltaTracker().getRealtimeDeltaTicks();
79-
xRot = Mth.sin(animatium$spin / 400.0F) * 25.0F + 20.0F;
80-
yRot = -animatium$spin * 0.1F;
81-
82-
GlStateManager._viewport(0, 0, 256, 256);
60+
PanoramaRendererUtility.setup();
61+
PanoramaRendererUtility.update(minecraft.getDeltaTracker().getRealtimeDeltaTicks());
62+
xRot = PanoramaRendererUtility.getXRot();
63+
yRot = PanoramaRendererUtility.getYRot();
8364
}
8465

8566
original.call(instance, minecraft, xRot, yRot);
8667
if (enabled) {
87-
PanoramaRendererUtility.render(guiGraphics.pose(), animatium$backgroundTextureView, width, height);
68+
PanoramaRendererUtility.render(guiGraphics.pose(), width, height);
8869
}
8970
}
9071

src/main/java/org/visuals/legacy/animatium/util/PanoramaRendererUtility.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@
2525

2626
package org.visuals.legacy.animatium.util;
2727

28+
import com.mojang.blaze3d.opengl.GlStateManager;
29+
import com.mojang.blaze3d.opengl.GlTexture;
2830
import com.mojang.blaze3d.opengl.GlTextureView;
2931
import com.mojang.blaze3d.pipeline.BlendFunction;
3032
import com.mojang.blaze3d.pipeline.RenderPipeline;
3133
import com.mojang.blaze3d.pipeline.RenderTarget;
3234
import com.mojang.blaze3d.platform.DestFactor;
3335
import com.mojang.blaze3d.platform.SourceFactor;
36+
import com.mojang.blaze3d.systems.GpuDevice;
3437
import com.mojang.blaze3d.systems.RenderSystem;
3538
import com.mojang.blaze3d.textures.FilterMode;
39+
import com.mojang.blaze3d.textures.TextureFormat;
3640
import com.mojang.blaze3d.vertex.BufferBuilder;
3741
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
3842
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@@ -41,50 +45,84 @@
4145
import net.minecraft.client.Minecraft;
4246
import net.minecraft.client.renderer.RenderPipelines;
4347
import net.minecraft.util.ARGB;
48+
import net.minecraft.util.Mth;
4449
import org.joml.Matrix3x2f;
4550
import org.visuals.legacy.animatium.Animatium;
4651

4752
@UtilityClass
4853
// Ported code of the old <=1.12.2 panorama renderer (w/ blur)
4954
public class PanoramaRendererUtility {
50-
private static final RenderPipeline.Snippet TEXTURE_SNIPPET =
55+
private final RenderPipeline.Snippet TEXTURE_SNIPPET =
5156
RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
5257
.withVertexShader("core/position_tex")
5358
.withFragmentShader("core/position_tex")
5459
.withSampler("Sampler0")
5560
.withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS)
5661
.buildSnippet();
5762

58-
private static final RenderPipeline BLUR_TEXTURED_PIPELINE =
63+
private final RenderPipeline BLUR_TEXTURED_PIPELINE =
5964
RenderPipeline.builder(TEXTURE_SNIPPET)
6065
.withLocation(Animatium.location("pipeline/blur_texture"))
6166
.withColorWrite(true, false)
6267
.withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO))
6368
.build();
6469

65-
private static final RenderPipeline BASIC_TEXTURED_PIPELINE =
70+
private final RenderPipeline BASIC_TEXTURED_PIPELINE =
6671
RenderPipeline.builder(TEXTURE_SNIPPET)
6772
.withLocation(Animatium.location("pipeline/basic_texture"))
6873
.build();
6974

75+
private GlTextureView backgroundTextureView = null;
76+
private float spin = 0.0F;
77+
78+
public void setup() {
79+
if (backgroundTextureView == null) {
80+
final GpuDevice device = RenderSystem.getDevice();
81+
final GlTexture animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1);
82+
backgroundTextureView = (GlTextureView) device.createTextureView(animatium$backgroundTexture);
83+
}
84+
85+
GlStateManager._viewport(0, 0, 256, 256);
86+
}
87+
7088
/**
7189
* In PanoramaRenderer, before ``cubeMap.render``, set viewPort to (0, 0, 256, 256)
7290
* then call this method after ``cubeMap.render``
7391
*
74-
* @param matrix The 2D GUI matrix
75-
* @param textureView The texture we are drawing to
76-
* @param width Screen width
77-
* @param height Screen Height
92+
* @param matrix The 2D GUI matrix
93+
* @param width Screen width
94+
* @param height Screen Height
7895
*/
79-
public void render(Matrix3x2f matrix, GlTextureView textureView, int width, int height) {
96+
public void render(Matrix3x2f matrix, int width, int height) {
8097
final RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
8198
for (int i = 0; i < 7; ++i) {
82-
writeAndBlitBlurTexture(matrix, renderTarget, textureView, width, height);
99+
writeAndBlitBlurTexture(matrix, renderTarget, backgroundTextureView, width, height);
83100
}
84101

85-
renderFinalTexture(matrix, renderTarget, textureView, width, height);
102+
renderFinalTexture(matrix, renderTarget, backgroundTextureView, width, height);
103+
}
104+
105+
public void update(float tickDelta) {
106+
spin += tickDelta;
107+
}
108+
109+
public float getXRot() {
110+
return Mth.sin(spin / 400.0F) * 25.0F + 20.0F;
86111
}
87112

113+
public float getYRot() {
114+
return -spin * 0.1F;
115+
}
116+
117+
/**
118+
* Render & Blur the texture
119+
*
120+
* @param matrix The 2D GUI matrix
121+
* @param renderTarget The texture we are drawing to
122+
* @param texture The temporary texture
123+
* @param width Screen width
124+
* @param height Screen Height
125+
*/
88126
private void writeAndBlitBlurTexture(Matrix3x2f matrix, RenderTarget renderTarget, GlTextureView texture, int width, int height) {
89127
texture.texture().setTextureFilter(FilterMode.LINEAR, FilterMode.LINEAR, false);
90128
// Ensures enough width/height for it to not crash when window is resized

0 commit comments

Comments
 (0)