Skip to content

Commit 711f1ec

Browse files
Merge pull request #134 from RecursivePineapple/rendering-improvements
Various rendering improvements
2 parents f7409f4 + 6ec3107 commit 711f1ec

5 files changed

Lines changed: 381 additions & 197 deletions

File tree

dependencies.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ dependencies {
7474
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Avaritia:1.78:dev")
7575
runtimeOnlyNonPublishable("com.github.GTNewHorizons:Avaritiaddons:1.9.3-GTNH:dev")
7676
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.4.0:dev")
77-
runtimeOnlyNonPublishable('com.github.GTNewHorizons:EnderIO:2.10.8:dev')
77+
// runtimeOnlyNonPublishable('com.github.GTNewHorizons:EnderIO:2.10.8:dev')
7878
runtimeOnlyNonPublishable("com.github.GTNewHorizons:EnderStorage:1.8.0:dev")
7979
runtimeOnlyNonPublishable(rfg.deobf("curse.maven:extra-utilities-225561:2264384"))
8080
runtimeOnlyNonPublishable("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.140:dev")
@@ -97,8 +97,6 @@ dependencies {
9797

9898
testImplementation(platform('org.junit:junit-bom:5.9.2'))
9999
testImplementation('org.junit.jupiter:junit-jupiter')
100-
101-
runtimeOnlyNonPublishable(rfg.deobf("curse.maven:spark-361579:4271867"))
102100
}
103101

104102
// deps may transitively add Baubles, so we replace it

src/main/java/com/recursive_pineapple/matter_manipulator/client/rendering/BoxRenderer.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class BoxRenderer {
2525
private final ShaderProgram program;
2626
private final int time_location;
2727

28+
private final VertexBuffer buffer = new VertexBuffer(DefaultVertexFormat.POSITION_COLOR_TEXTURE, GL11.GL_QUADS);
29+
2830
public BoxRenderer() {
2931
program = new ShaderProgram(
3032
Mods.MatterManipulator.resourceDomain,
@@ -39,8 +41,6 @@ public BoxRenderer() {
3941

4042
/**
4143
* Starts rendering fancy boxes. Should only be called once per frame, to allow quad sorting.
42-
*
43-
* @param partialTickTime
4444
*/
4545
public void start(double partialTickTime) {
4646
TessellatorManager.startCapturing();
@@ -163,13 +163,10 @@ public void finish() {
163163

164164
program.use();
165165

166-
// this should only be done once a frame, but there aren't any side effects from calling it more
167166
GL20.glUniform1f(time_location, (((float) (System.currentTimeMillis() % 2500)) / 1000f));
168167

169-
try (VertexBuffer buffer = new VertexBuffer(DefaultVertexFormat.POSITION_COLOR_TEXTURE, GL11.GL_QUADS);) {
170-
buffer.upload(bytes);
171-
buffer.render();
172-
}
168+
buffer.upload(bytes);
169+
buffer.render();
173170

174171
ShaderProgram.clear();
175172

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.recursive_pineapple.matter_manipulator.common.items.manipulator;
2+
3+
import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
4+
5+
import org.intellij.lang.annotations.MagicConstant;
6+
import org.lwjgl.opengl.ARBBufferStorage;
7+
import org.lwjgl.opengl.GL15;
8+
import org.lwjgl.opengl.GL30;
9+
10+
/// Note: this doesn't work properly for some reason, don't use it as-is
11+
public class FixedLengthVertexBuffer extends StreamingVertexBuffer {
12+
13+
public FixedLengthVertexBuffer(VertexFormat format, int drawMode) {
14+
super(format, drawMode);
15+
}
16+
17+
@Override
18+
public void reallocate() {
19+
generate();
20+
21+
// noinspection MagicConstant
22+
setSize(this.length, this.bufferFlags);
23+
}
24+
25+
@Override
26+
public void allocate(
27+
int vertexCount,
28+
@MagicConstant(intValues = {
29+
ARBBufferStorage.GL_DYNAMIC_STORAGE_BIT,
30+
GL30.GL_MAP_READ_BIT,
31+
GL30.GL_MAP_WRITE_BIT,
32+
ARBBufferStorage.GL_MAP_PERSISTENT_BIT,
33+
ARBBufferStorage.GL_MAP_COHERENT_BIT,
34+
ARBBufferStorage.GL_CLIENT_STORAGE_BIT,
35+
}) int usage
36+
) {
37+
// noinspection MagicConstant
38+
if (this.id == 0 || vertexCount < this.vertexCount / 4 || vertexCount > this.vertexCount || usage != this.bufferFlags) {
39+
generate();
40+
41+
setSize(vertexCount * (long) format.getVertexSize(), usage);
42+
}
43+
44+
this.vertexCount = vertexCount;
45+
}
46+
47+
public void setSize(
48+
long length,
49+
@MagicConstant(intValues = {
50+
ARBBufferStorage.GL_DYNAMIC_STORAGE_BIT,
51+
GL30.GL_MAP_READ_BIT,
52+
GL30.GL_MAP_WRITE_BIT,
53+
ARBBufferStorage.GL_MAP_PERSISTENT_BIT,
54+
ARBBufferStorage.GL_MAP_COHERENT_BIT,
55+
ARBBufferStorage.GL_CLIENT_STORAGE_BIT,
56+
}) int bufferFlags
57+
) {
58+
if (this.length > 0) throw new IllegalStateException("Cannot resize an immutable (fixed length) vertex buffer");
59+
60+
bind();
61+
62+
this.length = length;
63+
this.bufferFlags = bufferFlags;
64+
ARBBufferStorage.glBufferStorage(GL15.GL_ARRAY_BUFFER, length, bufferFlags);
65+
66+
unbind();
67+
}
68+
69+
public void flush() {
70+
bind();
71+
GL30.glFlushMappedBufferRange(GL15.GL_ARRAY_BUFFER, 0, vertexCount * (long) format.getVertexSize());
72+
unbind();
73+
}
74+
75+
public void flushAll() {
76+
bind();
77+
GL30.glFlushMappedBufferRange(GL15.GL_ARRAY_BUFFER, 0, length);
78+
unbind();
79+
}
80+
}

0 commit comments

Comments
 (0)