]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/renderers/RenderHelper.java
General performance improvements and serverside fixes
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / renderers / RenderHelper.java
1 package com.irtimaled.bbor.client.renderers;
2
3 import com.irtimaled.bbor.client.Camera;
4 import com.irtimaled.bbor.client.config.ConfigManager;
5 import com.mojang.blaze3d.platform.GlStateManager;
6 import com.mojang.blaze3d.systems.RenderSystem;
7 import net.minecraft.client.util.math.MatrixStack;
8 import net.minecraft.util.math.Quaternion;
9 import net.minecraft.util.math.Vec3d;
10 import org.lwjgl.opengl.GL11;
11
12 public class RenderHelper {
13
14     public static void beforeRender() {
15         enableBlend();
16         GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
17         GL11.glEnable(GL11.GL_LINE_SMOOTH);
18         RenderSystem.disableCull();
19         enableDepthTest();
20         RenderSystem.depthMask(true);
21         RenderSystem.depthFunc(GL11.GL_LEQUAL);
22
23         if (ConfigManager.alwaysVisible.get()) {
24             RenderSystem.disableDepthTest();
25         }
26         RenderBatch.beginBatch();
27     }
28
29     public static void afterRender() {
30         RenderBatch.endBatch();
31         enableDepthTest();
32         RenderSystem.enableCull();
33         GL11.glDisable(GL11.GL_LINE_SMOOTH);
34         RenderSystem.setShaderColor(1, 1, 1, 1);
35     }
36
37     public static void beforeRenderFont(MatrixStack matrixStack, OffsetPoint offsetPoint) {
38         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
39         matrixStack.push();
40         polygonModeFill();
41         matrixStack.translate(offsetPoint.getX(), offsetPoint.getY() + 0.002D, offsetPoint.getZ());
42         // GL11.glNormal3f(0.0F, 1.0F, 0.0F);
43         matrixStack.multiply(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F));
44         matrixStack.multiply(new Quaternion(0.0F, 90.0F, 1.0F, 0.0F));
45         matrixStack.scale(-0.0175F, -0.0175F, 0.0175F);
46         enableTexture();
47         enableBlend();
48         GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
49
50         depthMaskTrue();
51     }
52
53     public static void afterRenderFont(MatrixStack matrixStack) {
54         disableTexture();
55         disableBlend();
56         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
57         matrixStack.pop();
58         enableDepthTest();
59     }
60
61 //    public static void disableLighting() {
62 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
63 //        GL11.glDisable(GL11.GL_LIGHTING);
64 //    }
65
66     public static void disableDepthTest() {
67         GlStateManager._disableDepthTest();
68     }
69
70     public static void enableDepthTest() {
71         GlStateManager._enableDepthTest();
72     }
73
74 //    public static void disableFog() {
75 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
76 //        GL11.glDisable(GL11.GL_FOG);
77 //    }
78
79     public static void disableBlend() {
80         GlStateManager._disableBlend();
81     }
82
83     public static void enableBlend() {
84         GlStateManager._enableBlend();
85     }
86
87 //    public static void disableAlphaTest() {
88 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
89 //        GL11.glDisable(GL32.GL_ALPHA_TEST);
90 //    }
91 //
92 //    public static void enableAlphaTest() {
93 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
94 //        GL11.glEnable(GL11.GL_ALPHA_TEST);
95 //    }
96
97     public static void disableTexture() {
98         GlStateManager._disableTexture();
99     }
100
101     public static void enableTexture() {
102         GlStateManager._enableTexture();
103     }
104
105 //    public static void shadeModelSmooth() {
106 //        RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
107 //        GL11.glShadeModel(GL11.GL_SMOOTH);
108 //    }
109 //
110 //    public static void shadeModelFlat() {
111 //        RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
112 //        GL11.glShadeModel(GL11.GL_FLAT);
113 //    }
114
115 //    public static void enablePointSmooth() {
116 //        GL11.glEnable(GL11.GL_POINT_SMOOTH);
117 //    }
118
119     public static void lineWidth2() {
120         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
121         RenderSystem.lineWidth(2f);
122     }
123
124     public static void polygonModeLine() {
125         GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
126     }
127
128     public static void polygonModeFill() {
129         GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
130     }
131
132     public static void polygonOffsetMinusOne() {
133         GlStateManager._polygonOffset(-1.f, -1.f);
134     }
135
136     public static void enablePolygonOffsetLine() {
137         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
138         GL11.glEnable(GL11.GL_POLYGON_OFFSET_LINE);
139     }
140
141     public static void depthMaskTrue() {
142         GlStateManager._depthMask(true);
143     }
144
145     public static void blendFuncGui() {
146         GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
147     }
148
149     public static void depthFuncAlways() {
150         GlStateManager._depthFunc(GL11.GL_ALWAYS);
151     }
152
153     public static void depthFuncLessEqual() {
154         GlStateManager._depthFunc(GL11.GL_LEQUAL);
155     }
156
157     public static void applyRegionalRenderOffset(MatrixStack matrixStack)
158     {
159
160         int regionX = (((int) Camera.getX()) >> 9) << 9;
161         int regionZ = (((int) Camera.getZ()) >> 9) << 9;
162
163         matrixStack.translate(regionX - Camera.getX(), -Camera.getY(),
164                 regionZ - Camera.getZ());
165     }
166
167     /**
168      * Compute hash code for vec3d
169      * @see Vec3d#hashCode()
170      *
171      * @param x x value
172      * @param y y value
173      * @param z z value
174      * @return hash code
175      */
176     public static long hashVec3d(double x, double y, double z) {
177         long l = Double.doubleToLongBits(x);
178         int i = (int)(l ^ l >>> 32);
179         l = Double.doubleToLongBits(y);
180         i = 31 * i + (int)(l ^ l >>> 32);
181         l = Double.doubleToLongBits(z);
182         i = 31 * i + (int)(l ^ l >>> 32);
183         return i;
184     }
185 }