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

Commit 0c43925

Browse files
committed
No stencil test
1 parent 3324c96 commit 0c43925

File tree

7 files changed

+160
-114
lines changed

7 files changed

+160
-114
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public class GLImmeMode {
7878
private static boolean rendering = true;
7979
static GLList currentList;
8080

81+
/**
82+
* The matrix modes.
83+
*/
8184
public enum MatrixMode {
8285
MODELVIEW,
8386
PROJECTION,
@@ -110,7 +113,9 @@ public static GLDrawMode lglGetDrawMode() {
110113
///////////////////////////////////////////////////////////////////////////
111114

112115
/**
113-
* Request an immediate mode simulation context.
116+
* Request an immediate mode simulation (IMS) context.
117+
*
118+
* @see #lglDestroyContext()
114119
*/
115120
public static void lglRequestContext() {
116121
buffer = memCalloc(imsVertexCount * lglGetByteStride());
@@ -612,6 +617,11 @@ public static void lglTranslate(float x,
612617
// End
613618
///////////////////////////////////////////////////////////////////////////
614619

620+
/**
621+
* Destroy an IMS context.
622+
*
623+
* @see #lglRequestContext()
624+
*/
615625
public static void lglDestroyContext() {
616626
pipeline.close();
617627
if (ENABLE_CORE_PROFILE && glIsVertexArray(vao))

src/main/java/org/overrun/swgl/core/util/FloatTri.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,73 @@
3131
public class FloatTri implements ITri<Float, Float, Float> {
3232
private final float left, middle, right;
3333

34+
/**
35+
* Construct a float tri.
36+
*
37+
* @param left The left number.
38+
* @param middle The middle number.
39+
* @param right The right number.
40+
*/
3441
public FloatTri(float left, float middle, float right) {
3542
this.left = left;
3643
this.middle = middle;
3744
this.right = right;
3845
}
3946

47+
/**
48+
* Get the left value.
49+
*
50+
* @return the left value
51+
*/
4052
public float leftFloat() {
4153
return left;
4254
}
4355

56+
/**
57+
* Get the middle value.
58+
*
59+
* @return the middle value
60+
*/
4461
public float middleFloat() {
4562
return middle;
4663
}
4764

65+
/**
66+
* Get the right value.
67+
*
68+
* @return the right value
69+
*/
4870
public float rightFloat() {
4971
return right;
5072
}
5173

74+
/**
75+
* {@inheritDoc}
76+
*
77+
* @deprecated Please use {@link #leftFloat()}
78+
*/
5279
@Override
5380
@Deprecated(since = "0.1.0")
5481
public Float left() {
5582
return left;
5683
}
5784

85+
/**
86+
* {@inheritDoc}
87+
*
88+
* @deprecated Please use {@link #middleFloat()}
89+
*/
5890
@Override
5991
@Deprecated(since = "0.1.0")
6092
public Float middle() {
6193
return middle;
6294
}
6395

96+
/**
97+
* {@inheritDoc}
98+
*
99+
* @deprecated Please use {@link #rightFloat()}
100+
*/
64101
@Override
65102
@Deprecated(since = "0.1.0")
66103
public Float right() {

src/main/java/org/overrun/swgl/core/util/ITri.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,33 @@
3636
* @since 0.1.0
3737
*/
3838
public interface ITri<L, M, R> {
39+
/**
40+
* Get the left value.
41+
*
42+
* @return the left value
43+
*/
3944
L left();
4045

46+
/**
47+
* Get the middle value.
48+
*
49+
* @return the middle value
50+
*/
4151
M middle();
4252

53+
/**
54+
* Get the right value.
55+
*
56+
* @return the right value
57+
*/
4358
R right();
4459

60+
/**
61+
* Convert a tri to string.
62+
*
63+
* @param tri the tri
64+
* @return the string
65+
*/
4566
static String toString(ITri<?, ?, ?> tri) {
4667
return new StringJoiner(", ", tri.getClass().getSimpleName() + "[", "]")
4768
.add("left=" + tri.left())

src/main/java/org/overrun/swgl/core/util/IntTri.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,73 @@
3131
public class IntTri implements ITri<Integer, Integer, Integer> {
3232
private final int left, middle, right;
3333

34+
/**
35+
* Construct an int tri.
36+
*
37+
* @param left The left number.
38+
* @param middle The middle number.
39+
* @param right The right number.
40+
*/
3441
public IntTri(int left, int middle, int right) {
3542
this.left = left;
3643
this.middle = middle;
3744
this.right = right;
3845
}
3946

47+
/**
48+
* Get the left value.
49+
*
50+
* @return the left value
51+
*/
4052
public int leftInt() {
4153
return left;
4254
}
4355

56+
/**
57+
* Get the middle value.
58+
*
59+
* @return the middle value
60+
*/
4461
public int middleInt() {
4562
return middle;
4663
}
4764

65+
/**
66+
* Get the right value.
67+
*
68+
* @return the right value
69+
*/
4870
public int rightInt() {
4971
return right;
5072
}
5173

74+
/**
75+
* {@inheritDoc}
76+
*
77+
* @deprecated Please use {@link #leftInt()}
78+
*/
5279
@Override
5380
@Deprecated(since = "0.1.0")
5481
public Integer left() {
5582
return left;
5683
}
5784

85+
/**
86+
* {@inheritDoc}
87+
*
88+
* @deprecated Please use {@link #middleInt()}
89+
*/
5890
@Override
5991
@Deprecated(since = "0.1.0")
6092
public Integer middle() {
6193
return middle;
6294
}
6395

96+
/**
97+
* {@inheritDoc}
98+
*
99+
* @deprecated Please use {@link #rightInt()}
100+
*/
64101
@Override
65102
@Deprecated(since = "0.1.0")
66103
public Integer right() {

src/test/java/org/overrun/swgl/game/phys/AABB.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.overrun.swgl.core.util.math.Direction;
3232

3333
/**
34-
* The axis-aligned box.
34+
* The axis-aligned bounding box.
3535
*
3636
* @author squid233
3737
* @since 0.1.0
@@ -40,6 +40,17 @@ public class AABB {
4040
public final Vector3f min = new Vector3f();
4141
public final Vector3f max = new Vector3f();
4242

43+
/**
44+
* The box consumer.
45+
*
46+
* @author squid233
47+
* @since 0.1.0
48+
*/
49+
@FunctionalInterface
50+
public interface BoxConsumer {
51+
void accept(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
52+
}
53+
4354
public boolean isValid() {
4455
return min.x < max.x && min.y < max.y && min.z < max.z;
4556
}
@@ -179,6 +190,39 @@ public AABB grow(float x, float y, float z) {
179190
return aabb;
180191
}
181192

193+
public void forEachEdge(BoxConsumer consumer) {
194+
// 12 edges
195+
196+
// -x
197+
// [-x..-x], [-y..+y], [-z..-z]
198+
consumer.accept(min.x, min.y, min.z, min.x, max.y, min.z);
199+
// [-x..-x], [-y..+y], [+z..+z]
200+
consumer.accept(min.x, min.y, max.z, min.x, max.y, max.z);
201+
// [-x..-x], [-y..-y], [-z..+z]
202+
consumer.accept(min.x, min.y, min.z, min.x, min.y, max.z);
203+
// [-x..-x], [+y..+y], [-z..+z]
204+
consumer.accept(min.x, max.y, min.z, min.x, max.y, max.z);
205+
206+
// +x
207+
// [+x..+x], [-y..+y], [-z..-z]
208+
consumer.accept(max.x, min.y, min.z, max.x, max.y, min.z);
209+
// [+x..+x], [-y..+y], [+z..+z]
210+
consumer.accept(max.x, min.y, max.z, max.x, max.y, max.z);
211+
// [+x..+x], [-y..-y], [-z..+z]
212+
consumer.accept(max.x, min.y, min.z, max.x, min.y, max.z);
213+
// [+x..+x], [+y..+y], [-z..+z]
214+
consumer.accept(max.x, max.y, min.z, max.x, max.y, max.z);
215+
216+
// [-x..+x], [-y..-y], [-z..-z]
217+
consumer.accept(min.x, min.y, min.z, max.x, min.y, min.z);
218+
// [-x..+x], [-y..-y], [+z..+z]
219+
consumer.accept(min.x, min.y, max.z, max.x, min.y, max.z);
220+
// [-x..+x], [+y..+y], [+z..+z]
221+
consumer.accept(min.x, max.y, max.z, max.x, max.y, max.z);
222+
// [-x..+x], [+y..+y], [-z..-z]
223+
consumer.accept(min.x, max.y, min.z, max.x, max.y, min.z);
224+
}
225+
182226
public float clipXCollide(AABB other, float dt) {
183227
// Pass
184228
if (other.max.y <= min.y || other.min.y >= max.y || other.max.z <= min.z || other.min.z >= max.z)

src/test/java/org/overrun/swgl/game/world/WorldRenderer.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,21 @@ public void updateDirtyChunks(Player player) {
110110
}
111111

112112
public void renderHit(HitResult hitResult) {
113-
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
114113
disableDepthTest();
115114
enableBlend();
116115
blendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
117-
lglBegin(GLDrawMode.TRIANGLES);
118-
lglColor(0, 0, 0, 0.5f);
119-
hitResult.block().renderOutline(world, hitResult.x(), hitResult.y(), hitResult.z());
116+
lglBegin(GLDrawMode.LINES);
117+
lglColor(0, 0, 0, 0.4f);
118+
var outline = hitResult.block().getOutline(hitResult.x(), hitResult.y(), hitResult.z());
119+
outline.forEachEdge((minX, minY, minZ, maxX, maxY, maxZ) -> {
120+
lglVertex(minX, minY, minZ);
121+
lglEmit();
122+
lglVertex(maxX, maxY, maxZ);
123+
lglEmit();
124+
});
120125
lglEnd();
121126
disableBlend();
122127
enableDepthTest();
123-
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
124128
}
125129

126130
public HitResult pick(Player player, Matrix4fc viewMatrix, FpsCamera camera) {

0 commit comments

Comments
 (0)