Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit baa176e

Browse files
committed
Remove Tesselator.java
1 parent e11da12 commit baa176e

File tree

10 files changed

+319
-541
lines changed

10 files changed

+319
-541
lines changed

src/main/java/org/overrun/swgl/core/gl/ims/GLImmeMode.java

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class GLImmeMode {
5454
private static final GLProgram pipeline = new GLProgram();
5555
private static GLDrawMode drawMode;
5656
static ByteBuffer buffer; /* Package private, for GLLists */
57-
private static IntBuffer indicesBuffer;
57+
static IntBuffer indicesBuffer; /* Package private, for GLLists */
5858
private static float
5959
x = 0.0f, y = 0.0f, z = 0.0f, w = 1.0f,
6060
s = 0.0f, t = 0.0f, p = 0.0f, q = 1.0f;
@@ -197,6 +197,10 @@ public static int lglGetVertexCount() {
197197
return vertexCount;
198198
}
199199

200+
public static int lglGetIndexCount() {
201+
return indicesBuffer.limit();
202+
}
203+
200204
public static GLDrawMode lglGetDrawMode() {
201205
return drawMode;
202206
}
@@ -212,6 +216,10 @@ public static void lglBuffer(ByteBuffer buf) {
212216
buffer.put(buf);
213217
}
214218

219+
public static void lglIndexBuffer(IntBuffer buf) {
220+
indicesBuffer.put(buf);
221+
}
222+
215223
public static void lglColor(byte r, byte g, byte b, byte a) {
216224
GLImmeMode.r = r;
217225
GLImmeMode.g = g;
@@ -287,24 +295,22 @@ public static void lglIndices(int... indices) {
287295
}
288296

289297
public static void lglEmit() {
290-
if (rendering) {
291-
buffer.putFloat(x).putFloat(y).putFloat(z).putFloat(w);
292-
buffer.put(r).put(g).put(b).put(a);
293-
buffer.putFloat(s).putFloat(t).putFloat(p).putFloat(q);
294-
buffer.put(nx).put(ny).put(nz);
295-
}
298+
buffer.putFloat(x).putFloat(y).putFloat(z).putFloat(w);
299+
buffer.put(r).put(g).put(b).put(a);
300+
buffer.putFloat(s).putFloat(t).putFloat(p).putFloat(q);
301+
buffer.put(nx).put(ny).put(nz);
296302
++vertexCount;
297303
}
298304

299305
public static void lglEnd() {
306+
buffer.flip();
307+
indicesBuffer.flip();
308+
300309
if (rendering)
301310
lglEnd0();
302311
}
303312

304313
private static void lglEnd0() {
305-
buffer.flip();
306-
indicesBuffer.flip();
307-
308314
pipeline.bind();
309315
pipeline.getUniformSafe("projectionMat", GLUniformType.M4F).set(projectionMat);
310316
pipeline.getUniformSafe("modelviewMat", GLUniformType.M4F).set(modelviewMat);
@@ -367,12 +373,12 @@ private static void lglEnd0() {
367373
stride,
368374
36L);
369375

370-
if (indicesBuffer.limit() > 0) {
376+
if (lglGetIndexCount() > 0) {
371377
if (ebo == 0)
372378
ebo = glGenBuffers();
373379
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
374380
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_DYNAMIC_DRAW);
375-
glDrawElements(drawMode.getGlType(), indicesBuffer.limit(), GL_UNSIGNED_INT, 0L);
381+
glDrawElements(drawMode.getGlType(), lglGetIndexCount(), GL_UNSIGNED_INT, 0L);
376382
} else {
377383
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
378384
glDrawArrays(drawMode.getGlType(), 0, vertexCount);
@@ -386,6 +392,15 @@ private static void lglEnd0() {
386392
drawMode = null;
387393
}
388394

395+
public static Matrix4fStack lglGetMatrix(MatrixMode mode) {
396+
return switch (mode) {
397+
case MODELVIEW -> modelviewMat;
398+
case PROJECTION -> projectionMat;
399+
case TEXTURE -> textureMat;
400+
case COLOR -> colorMat;
401+
};
402+
}
403+
389404
public static Matrix4fStack lglGetMatrixMode() {
390405
return currentMat;
391406
}
@@ -399,6 +414,20 @@ public static void lglMatrixMode(MatrixMode mode) {
399414
}
400415
}
401416

417+
public static void lglPerspective(float fovy,
418+
float aspect,
419+
float zNear,
420+
float zFar) {
421+
currentMat.perspective(fovy, aspect, zNear, zFar);
422+
}
423+
424+
public static void lglPerspectiveDeg(float fovy,
425+
float aspect,
426+
float zNear,
427+
float zFar) {
428+
currentMat.perspective(Math.toRadians(fovy), aspect, zNear, zFar);
429+
}
430+
402431
public static void lglFrustum(float left,
403432
float right,
404433
float bottom,

src/main/java/org/overrun/swgl/core/gl/ims/GLList.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.overrun.swgl.core.gl.GLDrawMode;
2929

3030
import java.nio.ByteBuffer;
31+
import java.nio.IntBuffer;
3132

3233
/**
3334
* The IMS OpenGL list includes the buffers.
@@ -40,6 +41,7 @@ public class GLList implements AutoCloseable {
4041
GLDrawMode drawMode;
4142
int vertexCount;
4243
ByteBuffer buffer;
44+
IntBuffer indexBuffer;
4345

4446
public GLList(int id) {
4547
this.id = id;
@@ -53,8 +55,19 @@ public ByteBuffer getBuffer() {
5355
return buffer;
5456
}
5557

58+
public IntBuffer getIndexBuffer() {
59+
return indexBuffer;
60+
}
61+
5662
@Override
5763
public void close() {
58-
MemoryUtil.memFree(buffer);
64+
if (buffer != null) {
65+
MemoryUtil.memFree(buffer);
66+
buffer = null;
67+
}
68+
if (indexBuffer != null) {
69+
MemoryUtil.memFree(indexBuffer);
70+
indexBuffer = null;
71+
}
5972
}
6073
}

src/main/java/org/overrun/swgl/core/gl/ims/GLLists.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.LinkedHashMap;
3131
import java.util.Map;
32+
import java.util.OptionalInt;
3233

3334
import static org.overrun.swgl.core.gl.ims.GLImmeMode.*;
3435

@@ -40,15 +41,20 @@ public class GLLists {
4041
private static final Map<Integer, GLList> LIST_MAP = new LinkedHashMap<>();
4142
private static int nextId = 0;
4243

43-
public static void lglGenLists(int s) {
44+
public static int lglGenLists(int s) {
45+
OptionalInt id = OptionalInt.empty();
4446
for (int i = 0; i < s; i++) {
45-
lglGenList();
47+
int lst = lglGenList();
48+
if (id.isEmpty())
49+
id = OptionalInt.of(lst);
4650
}
51+
return id.orElseThrow();
4752
}
4853

49-
public static void lglGenList() {
54+
public static int lglGenList() {
5055
++nextId;
5156
LIST_MAP.put(nextId, new GLList(nextId));
57+
return nextId;
5258
}
5359

5460
private static boolean checkNotPresent(int list) {
@@ -63,32 +69,53 @@ public static void lglNewList(int n) {
6369
if (checkNotPresent(n))
6470
return;
6571
currentList = LIST_MAP.get(n);
72+
lglSetRendering(false);
6673
}
6774

6875
public static void lglEndList() {
6976
currentList.drawMode = lglGetDrawMode();
7077
currentList.vertexCount = lglGetVertexCount();
71-
currentList.buffer = MemoryUtil.memCalloc(lglGetVertexCount() * lglGetByteStride());
78+
79+
currentList.close();
80+
currentList.buffer = MemoryUtil.memCalloc(buffer.limit());
7281
for (int i = 0; currentList.buffer.hasRemaining(); i++) {
7382
currentList.buffer.put(buffer.get(i));
7483
}
7584
currentList.buffer.flip();
85+
86+
currentList.indexBuffer = MemoryUtil.memCallocInt(indicesBuffer.limit());
87+
for (int i = 0; currentList.indexBuffer.hasRemaining(); i++) {
88+
currentList.indexBuffer.put(indicesBuffer.get(i));
89+
}
90+
currentList.indexBuffer.flip();
91+
7692
currentList = null;
93+
lglSetRendering(true);
7794
}
7895

7996
public static void lglCallList(int list) {
8097
if (checkNotPresent(list))
8198
return;
8299
var lst = LIST_MAP.get(list);
100+
if (lst.getBuffer() == null)
101+
return;
83102
lglBegin(lst.drawMode);
84103
lglBuffer(lst.getBuffer());
104+
lst.getBuffer().position(0);
105+
if (lst.getIndexBuffer() != null) {
106+
lglIndexBuffer(lst.getIndexBuffer());
107+
lst.getIndexBuffer().position(0);
108+
}
85109
lglEnd();
86110
}
87111

88-
public static void lglDeleteList(int list) {
89-
if (checkNotPresent(list))
90-
return;
91-
LIST_MAP.get(list).close();
92-
LIST_MAP.remove(list);
112+
public static void lglDeleteLists(int list, int range) {
113+
for (int i = 0; i < range; i++) {
114+
int lst = list + i;
115+
if (checkNotPresent(lst))
116+
continue;
117+
LIST_MAP.get(lst).close();
118+
LIST_MAP.remove(lst);
119+
}
93120
}
94121
}

0 commit comments

Comments
 (0)