Skip to content

Commit afaf30f

Browse files
committed
change
1 parent 8d38960 commit afaf30f

2 files changed

Lines changed: 88 additions & 48 deletions

File tree

common/src/main/java/generations/gg/generations/core/generationscore/common/client/render/rarecandy/RareCandyVertexArray.java

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,76 @@
22

33
import org.lwjgl.opengl.GL43;
44

5-
public class RareCandyVertexArray {
5+
public final class RareCandyVertexArray {
6+
67
private final int vao;
78
private final int vertexStride;
8-
9+
10+
// binding index used for all vertex attributes
11+
private static final int VERTEX_BINDING = 0;
12+
913
public RareCandyVertexArray(int strideBytes) {
1014
this.vertexStride = strideBytes;
1115
this.vao = GL43.glGenVertexArrays();
12-
1316
setupAttributes();
1417
}
15-
18+
1619
private void setupAttributes() {
1720
GL43.glBindVertexArray(vao);
18-
19-
// Position (vec3)
21+
22+
// Position (vec3) @ location 0
2023
GL43.glEnableVertexAttribArray(0);
21-
GL43.glVertexAttribPointer(0, 3, GL43.GL_FLOAT, false, vertexStride, 0);
22-
23-
// Color (vec4)
24+
GL43.glVertexAttribFormat(0, 3, GL43.GL_FLOAT, false, 0);
25+
GL43.glVertexAttribBinding(0, VERTEX_BINDING);
26+
27+
// Color (vec4) @ location 1
2428
GL43.glEnableVertexAttribArray(1);
25-
GL43.glVertexAttribPointer(1, 4, GL43.GL_FLOAT, false, vertexStride, 12);
26-
27-
// UV0 (vec2)
29+
GL43.glVertexAttribFormat(1, 4, GL43.GL_FLOAT, false, 12);
30+
GL43.glVertexAttribBinding(1, VERTEX_BINDING);
31+
32+
// UV0 (vec2) @ location 2
2833
GL43.glEnableVertexAttribArray(2);
29-
GL43.glVertexAttribPointer(2, 2, GL43.GL_FLOAT, false, vertexStride, 28);
30-
31-
// UV1 (ivec2)
34+
GL43.glVertexAttribFormat(2, 2, GL43.GL_FLOAT, false, 28);
35+
GL43.glVertexAttribBinding(2, VERTEX_BINDING);
36+
37+
// UV1 (ivec2) @ location 3
3238
GL43.glEnableVertexAttribArray(3);
33-
GL43.glVertexAttribIPointer(3, 2, GL43.GL_INT, vertexStride, 36);
34-
35-
// UV2 (ivec2)
39+
GL43.glVertexAttribIFormat(3, 2, GL43.GL_INT, 36);
40+
GL43.glVertexAttribBinding(3, VERTEX_BINDING);
41+
42+
// UV2 (ivec2) @ location 4
3643
GL43.glEnableVertexAttribArray(4);
37-
GL43.glVertexAttribIPointer(4, 2, GL43.GL_INT, vertexStride, 44);
38-
39-
// Normal (vec3)
44+
GL43.glVertexAttribIFormat(4, 2, GL43.GL_INT, 44);
45+
GL43.glVertexAttribBinding(4, VERTEX_BINDING);
46+
47+
// Normal (vec3) @ location 5
4048
GL43.glEnableVertexAttribArray(5);
41-
GL43.glVertexAttribPointer(5, 3, GL43.GL_FLOAT, false, vertexStride, 52);
42-
49+
GL43.glVertexAttribFormat(5, 3, GL43.GL_FLOAT, false, 52);
50+
GL43.glVertexAttribBinding(5, VERTEX_BINDING);
51+
4352
GL43.glBindVertexArray(0);
4453
}
45-
54+
55+
/** Bind VAO only */
4656
public void bind() {
4757
GL43.glBindVertexArray(vao);
4858
}
49-
59+
60+
/** Bind the actual vertex buffer (destBuffer) at draw time */
61+
public void bindVertexBuffer(int bufferId) {
62+
GL43.glBindVertexBuffer(
63+
VERTEX_BINDING,
64+
bufferId,
65+
0,
66+
vertexStride
67+
);
68+
}
69+
5070
public void unbind() {
5171
GL43.glBindVertexArray(0);
5272
}
53-
73+
5474
public void delete() {
5575
GL43.glDeleteVertexArrays(vao);
5676
}
57-
}
77+
}

common/src/main/java/generations/gg/generations/core/generationscore/common/client/render/rarecandy/loading/GenerationsMultiRenderObject.java

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,64 @@ public boolean shouldRender(int mesh, ObjectInstance instance) {
4545
@Override
4646
public void render(RenderStage renderStage, List<ObjectInstance> list) {
4747
updateSSBOs();
48+
49+
System.out.println("vao=" + Pipelines.vao);
4850
Pipelines.vao.bind();
4951

52+
System.out.println("glBindBuffer ARRAY_BUFFER destBuffer=" + destBuffer);
5053
RenderSystem.glBindBuffer(GL43.GL_ARRAY_BUFFER, destBuffer);
5154

5255
for (int i = 0; i < instances.size(); i++) {
56+
System.out.println("instanceIndex=" + i);
5357
Pipelines.transformVertices(this, i);
5458

5559
var instance = instances.get(i);
56-
for (int mesh = 0; mesh < meshes.length; mesh++) {
57-
if (shouldRender(mesh, instance)) {
58-
var model = this.meshes[mesh];
59-
60-
if (model == null) {
61-
continue;
62-
}
63-
6460

65-
System.out.println("modelBuffer: " + modelBuffer);
66-
System.out.println("destBuffer: " + destBuffer);
67-
System.out.println("instanceBuffer.bufferId: " + instanceBuffer.getBufferId());
68-
System.out.println("uvTransformBuffer.bufferId: " + uvTransformBuffer.getBufferId());
69-
70-
Pipelines.processMaterial(instance, this, mesh);
61+
for (int mesh = 0; mesh < meshes.length; mesh++) {
62+
System.out.println("meshIndex=" + mesh);
7163

72-
Pipelines.commonOn();
64+
if (!shouldRender(mesh, instance)) {
65+
System.out.println("skipRender mesh=" + mesh);
66+
continue;
67+
}
7368

74-
Pipelines.solidOn();
75-
model.render();
76-
Pipelines.solidOff();
69+
var model = this.meshes[mesh];
70+
System.out.println("model=" + model);
7771

78-
Pipelines.emissiveOn();
79-
model.render();
80-
Pipelines.emissiveOff();
72+
if (model == null) {
73+
System.out.println("model NULL mesh=" + mesh);
74+
continue;
8175
}
76+
77+
System.out.println("modelBuffer=" + modelBuffer);
78+
System.out.println("destBuffer=" + destBuffer);
79+
System.out.println("instanceBufferId=" + instanceBuffer.getBufferId());
80+
System.out.println("uvTransformBufferId=" + uvTransformBuffer.getBufferId());
81+
82+
System.out.println("processMaterial");
83+
Pipelines.processMaterial(instance, this, mesh);
84+
85+
System.out.println("commonOn");
86+
Pipelines.commonOn();
87+
88+
System.out.println("solidOn");
89+
Pipelines.solidOn();
90+
System.out.println("model.render SOLID");
91+
model.render();
92+
System.out.println("solidOff");
93+
Pipelines.solidOff();
94+
95+
System.out.println("emissiveOn");
96+
Pipelines.emissiveOn();
97+
System.out.println("model.render EMISSIVE");
98+
model.render();
99+
System.out.println("emissiveOff");
100+
Pipelines.emissiveOff();
82101
}
83102
}
84103
}
85104

105+
86106
//TODO: calculate
87107
@Override
88108
public int targetVertexStride() {

0 commit comments

Comments
 (0)