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

Commit 692d70b

Browse files
committed
Removed unused code, Created OpenGL objects
Added "GlObject", a way to easily interface with OpenGL objects in memory. Made a "DisplayList" object for OpenGL display lists. Used the new DisplayList in WidgetHandler
1 parent 7b50824 commit 692d70b

5 files changed

Lines changed: 191 additions & 11 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
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;
2224
import net.minecraft.client.gui.FontRenderer;
2325
import net.minecraft.client.gui.ScaledResolution;
2426

@@ -47,7 +49,7 @@ public final class WidgetHandler {
4749
/**
4850
* The Open GL instruction list used when rendering
4951
*/
50-
private final int list;
52+
private final DisplayList list = new DisplayList(1);
5153

5254
private float padding, spacing, position;
5355

@@ -58,7 +60,7 @@ public final class WidgetHandler {
5860
private boolean outlines;
5961

6062
public WidgetHandler() {
61-
list = glGenLists(1);
63+
list.gen();
6264
}
6365

6466
/**
@@ -98,7 +100,7 @@ public final void draw(FontRenderer font, ScaledResolution sr) {
98100
// We write to a list so that the height can
99101
// be updated and the required vertical adjustment
100102
// can be made before we actually render the widgets
101-
glNewList(list, GL_COMPILE);
103+
list.start(GlListMode.COMPILE);
102104
widgets.forEach(widget -> {
103105
float mP = (widget.getAlignment().getValue() + 0.5F != 0.0F) ? 1.0F : 0.0F;
104106
float xP = pos.getPadding().getX() * padding * mP;
@@ -115,13 +117,13 @@ public final void draw(FontRenderer font, ScaledResolution sr) {
115117
glTranslatef(0.0F, widget.getHeight() + spacing, 0.0F);
116118
position += widget.getHeight();
117119
});
118-
glEndList();
120+
list.stop();
119121

120122
position += spacing * (widgets.size() - 1);
121123
glTranslatef(0.0F, position * pos.getOffset(), 0.0F);
122124

123125
// Render all of the widgets
124-
glCallList(list);
126+
list.call();
125127

126128
glPopMatrix();
127129
});

src/main/java/me/zero/client/api/util/Messages.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package me.zero.client.api.util;
1818

1919
import me.zero.client.api.util.logger.Level;
20+
import me.zero.client.api.util.logger.ILogger;
2021

2122
/**
2223
* Storage for all Messages used by the Logger's logf method
2324
* as well as some generic messages sent to the client from
2425
* the api.
2526
*
26-
* @see me.zero.client.api.util.logger.ILogger#logf(Level, String, Object...)
27+
* @see ILogger#log(Level, String)
28+
* @see ILogger#logf(Level, String, Object...)
2729
*
2830
* @author Brady
2931
* @since 1/21/2017 12:00 PM
@@ -36,9 +38,4 @@ public interface Messages {
3638
String PLUGIN_CANT_CREATE_MODULE = "Unable to create Module, %s";
3739
String PLUGIN_CANT_LOAD_CLASS = "Unable to load Class, %s";
3840
String PLUGIN_CANT_CREATE_INPUTSTREAM = "Unable to create jar InputStream, %s";
39-
40-
String MODULE_INSTANTIATION = "Unable to instantiate Module, %s";
41-
42-
String COMMAND_MISSING_ARGS = "Missing required argument: %s, with type %s";
43-
String COMMAND_INVALID = "Invalid Command";
4441
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
/**
20+
* Representation of an Object in OpenGL
21+
*
22+
* @author Brady
23+
* @since 7/22/2017 4:18 PM
24+
*/
25+
public abstract class GlObject {
26+
27+
public static final int UNABLE_TO_GENERATE = 0;
28+
public static final int NOT_GENERATED = -1;
29+
30+
private int id = NOT_GENERATED;
31+
32+
/**
33+
* Generates this OpenGL Object. Return value reflects
34+
* whether or not the operation was a success or not.
35+
*
36+
* @return Whether or not the operation was a success.
37+
* May return 'false' if
38+
*/
39+
public final boolean gen() {
40+
return !isGen() && (id = nativeGen()) != UNABLE_TO_GENERATE;
41+
}
42+
43+
/**
44+
* Called by GlObject#gen() to generate this object.
45+
*
46+
* @return The ID of the (possibly) created object
47+
*/
48+
protected abstract int nativeGen();
49+
50+
/**
51+
* Deletes this object from memory.
52+
*
53+
* @return Whether or not the operation was a success
54+
*/
55+
public final boolean delete() {
56+
if (!isGen())
57+
return false;
58+
59+
id = NOT_GENERATED;
60+
nativeDelete();
61+
return true;
62+
}
63+
64+
/**
65+
* Called by GlObject#delete() to delete this object from memory.
66+
*/
67+
protected abstract void nativeDelete();
68+
69+
/**
70+
* @return The ID of this object
71+
*/
72+
public final int id() {
73+
return this.id;
74+
}
75+
76+
/**
77+
* @return Whether or not the object has been successfully generated
78+
*/
79+
public final boolean isGen() {
80+
return id > 0;
81+
}
82+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.glenum;
18+
19+
import static org.lwjgl.opengl.GL11.*;
20+
21+
/**
22+
* @author Brady
23+
* @since 7/22/2017 4:32 PM
24+
*/
25+
public enum GlListMode {
26+
27+
/**
28+
* Commands are merely compiled.
29+
*/
30+
COMPILE(GL_COMPILE),
31+
32+
/**
33+
* Commands are executed as they are compiled into the display list.
34+
*/
35+
COMPILE_AND_EXECUTE(GL_COMPILE_AND_EXECUTE);
36+
37+
public final int id;
38+
39+
GlListMode(int id) {
40+
this.id = id;
41+
}
42+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.object;
18+
19+
import me.zero.client.api.util.render.gl.GlObject;
20+
import me.zero.client.api.util.render.gl.glenum.GlListMode;
21+
22+
import static org.lwjgl.opengl.GL11.*;
23+
24+
/**
25+
* @author Brady
26+
* @since 7/22/2017 4:27 PM
27+
*/
28+
public final class DisplayList extends GlObject {
29+
30+
private final int range;
31+
32+
public DisplayList(int range) {
33+
this.range = range;
34+
}
35+
36+
@Override
37+
protected final int nativeGen() {
38+
return glGenLists(range);
39+
}
40+
41+
@Override
42+
protected final void nativeDelete() {
43+
glDeleteLists(id(), range);
44+
}
45+
46+
public final void start(GlListMode mode) {
47+
glNewList(id(), mode.id);
48+
}
49+
50+
public final void stop() {
51+
glEndList();
52+
}
53+
54+
public final void call() {
55+
glCallList(id());
56+
}
57+
}

0 commit comments

Comments
 (0)