Skip to content

Commit a326f7a

Browse files
fix: Use TRIANGLE_STRIP for drawFilledBoundingBox
1 parent 27f2cf6 commit a326f7a

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

mod/src/main/kotlin/gg/skytils/skytilsmod/utils/RenderUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ object RenderUtil {
8282
block(this.red, this.green, this.blue, this.alpha)
8383

8484
fun drawFilledBoundingBox(matrixStack: UMatrixStack, aabb: Box, c: Color, alphaMultiplier: Float = 1f, throughWalls: Boolean = false) {
85-
val buffer = UBufferBuilder.create(UGraphics.DrawMode.TRIANGLES, UGraphics.CommonVertexFormats.POSITION_COLOR)
85+
val buffer = UBufferBuilder.create(UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR)
8686
DrawHelper.writeFilledCube(buffer, matrixStack, aabb, c.multAlpha(alphaMultiplier))
8787
buffer.build()?.drawAndClose(if (throughWalls) SRenderPipelines.noDepthBoxPipeline else SRenderPipelines.boxPipeline)
8888
}

mod/src/main/kotlin/gg/skytils/skytilsmod/utils/rendering/DrawHelper.kt

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ object DrawHelper {
9595

9696
/**
9797
* Writes a filled cube to the given buffer. Draw must still be called manually.
98-
* Buffer must be created with [gg.essential.universal.UGraphics.DrawMode.TRIANGLES]
98+
* Buffer must be created with [gg.essential.universal.UGraphics.DrawMode.TRIANGLE_STRIP]
9999
*/
100100
fun writeFilledCube(
101101
buffer: UBufferBuilder,
@@ -104,47 +104,36 @@ object DrawHelper {
104104
color: Color
105105
) {
106106
box.apply {
107+
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
108+
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
109+
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
107110
buffer.pos(matrices, minX, minY, maxZ).color(color).endVertex()
108-
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
109-
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
110-
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
111+
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
112+
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
111113
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
112114
buffer.pos(matrices, minX, minY, maxZ).color(color).endVertex()
113-
114-
buffer.pos(matrices, maxX, minY, minZ).color(color).endVertex()
115-
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
116-
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
117-
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
118-
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
115+
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
116+
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
117+
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
119118
buffer.pos(matrices, maxX, minY, minZ).color(color).endVertex()
120-
121-
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
122119
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
123120
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
124121
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
122+
buffer.pos(matrices, maxX, minY, minZ).color(color).endVertex()
125123
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
126-
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
127-
124+
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
128125
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
129126
buffer.pos(matrices, maxX, minY, minZ).color(color).endVertex()
130-
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
131-
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
132127
buffer.pos(matrices, minX, minY, maxZ).color(color).endVertex()
133-
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
134-
135128
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
136-
buffer.pos(matrices, maxX, minY, minZ).color(color).endVertex()
137-
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
138-
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
139-
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
140129
buffer.pos(matrices, maxX, minY, maxZ).color(color).endVertex()
141-
142-
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
143-
buffer.pos(matrices, minX, minY, maxZ).color(color).endVertex()
144-
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
145-
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
146130
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
147-
buffer.pos(matrices, minX, minY, minZ).color(color).endVertex()
131+
buffer.pos(matrices, minX, maxY, minZ).color(color).endVertex()
132+
buffer.pos(matrices, minX, maxY, maxZ).color(color).endVertex()
133+
buffer.pos(matrices, maxX, maxY, minZ).color(color).endVertex()
134+
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
135+
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
136+
buffer.pos(matrices, maxX, maxY, maxZ).color(color).endVertex()
148137
}
149138
}
150139

mod/src/main/kotlin/gg/skytils/skytilsmod/utils/rendering/SRenderPipelines.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ object SRenderPipelines {
5454
}.build()
5555

5656
val boxPipeline = URenderPipeline.builderWithDefaultShader("skytils:pipeline/box",
57-
UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR
57+
UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR
5858
).apply {
5959
blendState = BlendState.ALPHA
6060
}.build()
6161

6262
val noDepthBoxPipeline = URenderPipeline.builderWithDefaultShader("skytils:pipeline/no_depth_box",
63-
UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR
63+
UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR
6464
).apply {
6565
depthTest = URenderPipeline.DepthTest.Always
6666
blendState = BlendState.ALPHA

0 commit comments

Comments
 (0)