Skip to content

Commit 19e6718

Browse files
committed
better handle line widths
1 parent f480dff commit 19e6718

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/BufferBuilderRenderSink.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.enginehub.worldeditcui.render;
1111

1212
import com.mojang.blaze3d.opengl.GlStateManager;
13-
import com.mojang.blaze3d.systems.RenderSystem;
1413
import com.mojang.blaze3d.vertex.BufferBuilder;
1514
import com.mojang.blaze3d.vertex.Tesselator;
1615
import com.mojang.blaze3d.vertex.VertexFormat;
@@ -28,7 +27,7 @@ public class BufferBuilderRenderSink implements RenderSink {
2827
private final RenderType quads;
2928
private final Runnable preFlush;
3029
private final Runnable postFlush;
31-
private static BufferBuilder builder;
30+
private BufferBuilder builder;
3231
private @Nullable BufferBuilderRenderSink.RenderType activeRenderType;
3332
private boolean active;
3433
private boolean canFlush;
@@ -58,14 +57,11 @@ public static class LineWidth {
5857
private static float lineWidth = GL11.glGetInteger(GL11.GL_LINE_WIDTH);
5958

6059
public static void set(final float width) {
61-
if (HAS_COMPATIBILITY) {
62-
if (lineWidth != width) {
63-
GL11.glLineWidth(width);
64-
lineWidth = width;
65-
}
60+
if (HAS_COMPATIBILITY && lineWidth != width) {
61+
GL11.glLineWidth(width);
6662
}
6763

68-
builder.setLineWidth(width);
64+
lineWidth = width;
6965
}
7066

7167
}
@@ -112,12 +108,12 @@ public RenderSink vertex(final double x, final double y, final double z) {
112108
// duplicate last
113109
if (this.canLoop) {
114110
final Vector3f normal = this.activeRenderType.hasNormals ? this.computeNormal(this.loopX, this.loopY, this.loopZ, x, y, z) : null;
115-
builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a);
111+
builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
116112
if (normal != null) {
117113
// we need to compute normals pointing directly towards the screen
118114
builder.setNormal(normal.x(), normal.y(), normal.z());
119115
}
120-
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a);
116+
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
121117
if (normal != null) {
122118
builder.setNormal(normal.x(), normal.y(), normal.z());
123119
}
@@ -134,11 +130,11 @@ public RenderSink vertex(final double x, final double y, final double z) {
134130
// we buffer vertices so we can compute normals here
135131
if (this.canLoop) {
136132
final Vector3f normal = this.activeRenderType.hasNormals ? this.computeNormal(this.loopX, this.loopY, this.loopZ, x, y, z) : null;
137-
builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a);
133+
builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
138134
if (normal != null) {
139135
builder.setNormal(normal.x(), normal.y(), normal.z());
140136
}
141-
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a);
137+
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
142138
if (normal != null) {
143139
builder.setNormal(normal.x(), normal.y(), normal.z());
144140
}
@@ -150,7 +146,7 @@ public RenderSink vertex(final double x, final double y, final double z) {
150146
this.canLoop = true;
151147
}
152148
} else {
153-
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a);
149+
builder.addVertex((float) x, (float) y, (float) z).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
154150
}
155151
return this;
156152
}
@@ -178,12 +174,12 @@ public RenderSink endLineLoop() {
178174
if (this.canLoop) {
179175
this.canLoop = false;
180176
final Vector3f normal = this.activeRenderType.hasNormals ? this.computeNormal(this.loopX, this.loopY, this.loopZ, this.loopFirstX, this.loopFirstY, this.loopFirstZ) : null;
181-
this.builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a);
177+
this.builder.addVertex(this.loopX, this.loopY, this.loopZ).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
182178
if (normal != null) {
183179
this.builder.setNormal(normal.x(), normal.y(), normal.z());
184180
}
185181

186-
this.builder.addVertex(this.loopFirstX, this.loopFirstY, this.loopFirstZ).setColor(this.r, this.g, this.b, this.a);
182+
this.builder.addVertex(this.loopFirstX, this.loopFirstY, this.loopFirstZ).setColor(this.r, this.g, this.b, this.a).setLineWidth(LineWidth.lineWidth);
187183
if (normal != null) {
188184
this.builder.setNormal(normal.x(), normal.y(), normal.z());
189185
}

worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/render/VanillaPipelineProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static class DefaultTypeFactory implements BufferBuilderRenderSink.TypeFa
3434
private static final BufferBuilderRenderSink.RenderType QUADS = new BufferBuilderRenderSink.RenderType(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR,
3535
RenderType.create("quads", QUADS_SETUP)
3636
);
37-
private static final BufferBuilderRenderSink.RenderType LINES = new BufferBuilderRenderSink.RenderType(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL, RenderTypes.LINES);
38-
private static final BufferBuilderRenderSink.RenderType LINES_LOOP = new BufferBuilderRenderSink.RenderType(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL, RenderTypes.LINES);
37+
private static final BufferBuilderRenderSink.RenderType LINES = new BufferBuilderRenderSink.RenderType(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL_LINE_WIDTH, RenderTypes.LINES);
38+
private static final BufferBuilderRenderSink.RenderType LINES_LOOP = new BufferBuilderRenderSink.RenderType(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL_LINE_WIDTH, RenderTypes.LINES);
3939

4040
private DefaultTypeFactory() {}
4141

0 commit comments

Comments
 (0)