Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit b8bc1b4

Browse files
committed
More GL Stuff (Read Description)
Capitalized "L" in "GL" for multiple classes Created Query object Rewrote Shader system (Shader and ShaderProgram) Added Geometry shader support Removed GlListMode
1 parent 692d70b commit b8bc1b4

18 files changed

Lines changed: 366 additions & 251 deletions

src/main/java/me/zero/client/api/gui/widget/WidgetHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import me.zero.client.api.gui.widget.data.WidgetPos;
2020
import me.zero.client.api.util.math.Vec2;
2121
import me.zero.client.api.util.render.RenderUtils;
22-
import me.zero.client.api.util.render.gl.glenum.GlListMode;
23-
import me.zero.client.api.util.render.gl.object.DisplayList;
22+
import me.zero.client.api.util.render.gl.DisplayList;
2423
import net.minecraft.client.gui.FontRenderer;
2524
import net.minecraft.client.gui.ScaledResolution;
2625

@@ -100,7 +99,7 @@ public final void draw(FontRenderer font, ScaledResolution sr) {
10099
// We write to a list so that the height can
101100
// be updated and the required vertical adjustment
102101
// can be made before we actually render the widgets
103-
list.start(GlListMode.COMPILE);
102+
list.start(GL_COMPILE);
104103
widgets.forEach(widget -> {
105104
float mP = (widget.getAlignment().getValue() + 0.5F != 0.0F) ? 1.0F : 0.0F;
106105
float xP = pos.getPadding().getX() * padding * mP;

src/main/java/me/zero/client/api/util/render/RenderUtils.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import me.zero.client.api.util.math.Vec2;
2020
import me.zero.client.api.util.math.Vec3;
21-
import me.zero.client.api.util.render.gl.glenum.GlClientState;
21+
import me.zero.client.api.util.render.gl.glenum.GLClientState;
2222
import me.zero.client.api.util.render.gl.GlUtils;
2323
import net.minecraft.client.renderer.GlStateManager;
2424
import net.minecraft.client.renderer.OpenGlHelper;
@@ -80,7 +80,7 @@ public static void setupRender(boolean start) {
8080
*
8181
* @param enabled The new enabled state of {@code GL_VERTEX_ARRAY}
8282
*/
83-
public static void setupClientState(GlClientState state, boolean enabled) {
83+
public static void setupClientState(GLClientState state, boolean enabled) {
8484
csBuffer.clear();
8585
if (state.ordinal() > 0)
8686
csBuffer.add(state.cap);
@@ -141,9 +141,9 @@ public static void drawLine(float x, float y, float z, float x1, float y1, float
141141
glLineWidth(width);
142142

143143
setupRender(true);
144-
setupClientState(GlClientState.VERTEX, true);
144+
setupClientState(GLClientState.VERTEX, true);
145145
tessellator.vertex(x, y, z).vertex(x1, y1, z1).draw(GL_LINE_STRIP);
146-
setupClientState(GlClientState.VERTEX, false);
146+
setupClientState(GLClientState.VERTEX, false);
147147
setupRender(false);
148148
}
149149

@@ -156,7 +156,7 @@ public static void drawLine(float x, float y, float z, float x1, float y1, float
156156
* @param y2 Bottom corner Y of the rectangle
157157
*/
158158
public static void drawFlippedTexturedRect(float x1, float y1, float x2, float y2) {
159-
setupClientState(GlClientState.TEXTURE, true);
159+
setupClientState(GLClientState.TEXTURE, true);
160160

161161
tessellator
162162
.vertex(x1, y2, 0).texture(0, 0)
@@ -165,7 +165,7 @@ public static void drawFlippedTexturedRect(float x1, float y1, float x2, float y
165165
.vertex(x1, y1, 0).texture(0, 1)
166166
.draw(GL_QUADS);
167167

168-
setupClientState(GlClientState.TEXTURE, false);
168+
setupClientState(GLClientState.TEXTURE, false);
169169
}
170170

171171
/**
@@ -177,7 +177,7 @@ public static void drawFlippedTexturedRect(float x1, float y1, float x2, float y
177177
* @param y2 Bottom corner Y of the rectangle
178178
*/
179179
public static void drawReflectedTexturedRect(float x1, float y1, float x2, float y2) {
180-
setupClientState(GlClientState.TEXTURE, true);
180+
setupClientState(GLClientState.TEXTURE, true);
181181

182182
tessellator
183183
.vertex(x1, y2, 0).texture(1, 0)
@@ -186,7 +186,7 @@ public static void drawReflectedTexturedRect(float x1, float y1, float x2, float
186186
.vertex(x1, y1, 0).texture(1, 1)
187187
.draw(GL_QUADS);
188188

189-
setupClientState(GlClientState.TEXTURE, false);
189+
setupClientState(GLClientState.TEXTURE, false);
190190
}
191191

192192
/**
@@ -202,9 +202,9 @@ public static void rectangle(float x1, float y1, float x2, float y2, int color)
202202
GlUtils.glColor(color);
203203

204204
setupRender(true);
205-
setupClientState(GlClientState.VERTEX, true);
205+
setupClientState(GLClientState.VERTEX, true);
206206
tessellator.vertex(x1, y2, 0).vertex(x2, y2, 0).vertex(x2, y1, 0).vertex(x1, y1, 0).draw(GL_QUADS);
207-
setupClientState(GlClientState.VERTEX, false);
207+
setupClientState(GLClientState.VERTEX, false);
208208
setupRender(false);
209209
}
210210

@@ -261,7 +261,7 @@ private static void rectangleGradient(float x1, float y1, float x2, float y2, in
261261
setupRender(true);
262262
OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0);
263263
GlStateManager.shadeModel(GL_FLAT);
264-
setupClientState(GlClientState.COLOR, true);
264+
setupClientState(GLClientState.COLOR, true);
265265

266266
tessellator
267267
.color(r[0], g[0], b[0], a[0]).vertex(x1, y2, 0)
@@ -270,7 +270,7 @@ private static void rectangleGradient(float x1, float y1, float x2, float y2, in
270270
.color(r[3], g[3], b[3], a[3]).vertex(x1, y1, 0)
271271
.draw(GL_QUADS);
272272

273-
setupClientState(GlClientState.COLOR, false);
273+
setupClientState(GLClientState.COLOR, false);
274274
GlStateManager.shadeModel(GL_FLAT);
275275
setupRender(false);
276276
}

src/main/java/me/zero/client/api/util/render/gl/object/DisplayList.java renamed to src/main/java/me/zero/client/api/util/render/gl/DisplayList.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17-
package me.zero.client.api.util.render.gl.object;
17+
package me.zero.client.api.util.render.gl;
1818

19-
import me.zero.client.api.util.render.gl.GlObject;
20-
import me.zero.client.api.util.render.gl.glenum.GlListMode;
19+
import me.zero.client.api.util.render.gl.GLObject;
2120

2221
import static org.lwjgl.opengl.GL11.*;
2322

2423
/**
24+
* Display lists are used to capture OpenGL instructions.
25+
* These instructions can then later be called upon. This
26+
* is generally more efficient then repeating the
27+
* instructions multiple times in the code directly.
28+
*
2529
* @author Brady
2630
* @since 7/22/2017 4:27 PM
2731
*/
28-
public final class DisplayList extends GlObject {
32+
public final class DisplayList extends GLObject {
2933

34+
/**
35+
* The number of contiguous empty display lists to be generated.
36+
* In most cases, '1' will suffice.
37+
*/
3038
private final int range;
3139

3240
public DisplayList(int range) {
@@ -43,14 +51,29 @@ protected final void nativeDelete() {
4351
glDeleteLists(id(), range);
4452
}
4553

46-
public final void start(GlListMode mode) {
47-
glNewList(id(), mode.id);
54+
/**
55+
* Begins capturing all subsequent instructions
56+
*
57+
* @see #stop()
58+
*
59+
* @param mode Instruction capture mode
60+
*/
61+
public final void start(int mode) {
62+
glNewList(id(), mode);
4863
}
4964

65+
/**
66+
* Stops capturing all instructions since start
67+
*
68+
* @see #start(int)
69+
*/
5070
public final void stop() {
5171
glEndList();
5272
}
5373

74+
/**
75+
* Calls all instructions that have been captured by this list
76+
*/
5477
public final void call() {
5578
glCallList(id());
5679
}

src/main/java/me/zero/client/api/util/render/gl/GlObject.java renamed to src/main/java/me/zero/client/api/util/render/gl/GLObject.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Brady
2323
* @since 7/22/2017 4:18 PM
2424
*/
25-
public abstract class GlObject {
25+
public abstract class GLObject {
2626

2727
public static final int UNABLE_TO_GENERATE = 0;
2828
public static final int NOT_GENERATED = -1;
@@ -48,7 +48,9 @@ public final boolean gen() {
4848
protected abstract int nativeGen();
4949

5050
/**
51-
* Deletes this object from memory.
51+
* Deletes this object from memory. This should be called
52+
* when the application is shutting down to efficiently
53+
* garbage collect memory.
5254
*
5355
* @return Whether or not the operation was a success
5456
*/
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package me.zero.client.api.util.render.gl;
18+
19+
import static org.lwjgl.opengl.GL11.*;
20+
import static org.lwjgl.opengl.GL15.*;
21+
22+
/**
23+
* @author Brady
24+
* @since 7/22/2017 10:16 PM
25+
*/
26+
public final class Query extends GLObject {
27+
28+
private final int target;
29+
30+
public Query(int target) {
31+
this.target = target;
32+
}
33+
34+
@Override
35+
protected int nativeGen() {
36+
return glGenQueries();
37+
}
38+
39+
@Override
40+
protected void nativeDelete() {
41+
glDeleteQueries(id());
42+
}
43+
44+
/**
45+
* Marks the starting bounds of the query scope
46+
*/
47+
public final void start() {
48+
glBeginQuery(target, id());
49+
}
50+
51+
/**
52+
* Marks the stopping bounds of the query scope
53+
*/
54+
public final void stop() {
55+
glEndQuery(target);
56+
}
57+
58+
/**
59+
* Returns the result of the query, the result
60+
* will vary based on the query target.
61+
*
62+
* @return The result of the query.
63+
*/
64+
public final int getResult() {
65+
return glGetQueryObjecti(target, GL_QUERY_RESULT);
66+
}
67+
68+
/**
69+
* @return Whether or not the result of the query is available yet
70+
*/
71+
public final boolean isResultAvailable() {
72+
return glGetQueryObjecti(target, GL_QUERY_RESULT_AVAILABLE) == GL_TRUE;
73+
}
74+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package me.zero.client.api.util.render.gl;
18+
19+
import me.zero.client.api.exception.ShaderException;
20+
import me.zero.client.api.util.render.gl.glenum.GLShaderStatus;
21+
import me.zero.client.api.util.render.gl.glenum.GLShaderType;
22+
import me.zero.client.api.util.render.gl.shader.adapter.ShaderAdapter;
23+
import me.zero.client.api.util.render.gl.shader.adapter.ShaderAdapters;
24+
25+
/**
26+
* @author Brady
27+
* @since 7/23/2017 3:24 PM
28+
*/
29+
public final class Shader extends GLObject {
30+
31+
/**
32+
* Instance of the system supported shader adapter
33+
*/
34+
private static final ShaderAdapter adapter = ShaderAdapters.getSystemAdapter();
35+
36+
/**
37+
* Source code of the shader
38+
*/
39+
private final String src;
40+
41+
/**
42+
* Type of shader
43+
*/
44+
private final GLShaderType type;
45+
46+
public Shader(GLShaderType type, String src) {
47+
this.type = type;
48+
this.src = src;
49+
}
50+
51+
@Override
52+
protected int nativeGen() {
53+
int shaderID = adapter.createShader(type);
54+
if (shaderID == 0)
55+
return 0;
56+
57+
try {
58+
adapter.shaderSource(shaderID, src);
59+
adapter.compileShader(shaderID);
60+
adapter.checkStatus(shaderID, GLShaderStatus.COMPILE);
61+
} catch (ShaderException e) {
62+
return 0;
63+
}
64+
65+
return shaderID;
66+
}
67+
68+
@Override
69+
protected void nativeDelete() {
70+
adapter.deleteShader(id());
71+
}
72+
73+
/**
74+
* @return The type of shader this object represents
75+
*/
76+
public final GLShaderType getType() {
77+
return this.type;
78+
}
79+
}

0 commit comments

Comments
 (0)