Skip to content

Commit bd29c47

Browse files
committed
toy with using structs for vertex buffers
1 parent b50d9ff commit bd29c47

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

jme3-core/src/main/java/com/jme3/vulkan/mesh/test/Vertex.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,43 @@
77

88
public class Vertex extends Struct {
99

10-
public final Vector3f position = new Vector3f();
11-
public final Vector2f texCoord = new Vector2f();
12-
public final Vector3f normal = new Vector3f();
10+
private final Field<Vector3f> position = new Field<>(new Vector3f());
11+
private final Field<Vector2f> texCoord = new Field<>(new Vector2f());
12+
private final Field<Vector3f> normal = new Field<>(new Vector3f());
1313

14-
public Vertex(StructLayout layout) {
15-
addFields(new Field(position), new Field(texCoord), new Field(normal));
16-
setLayout(layout); // stage layout, not calculated immediately
14+
public Vertex() {
15+
addFields(position, texCoord, normal);
1716
}
1817

18+
public void bind(StructLayout layout, long address) {
19+
for (Field f : fields) {
20+
f.bind(layout, address);
21+
}
22+
}
23+
24+
public void setPosition(Vector3f position) {
25+
updateLayout();
26+
this.position.set(address, position);
27+
}
28+
29+
public void setPosition(float x, float y, float z) {
30+
position.set(position.getAlias().set(x, y, z));
31+
}
32+
33+
public Vector3f getPosition() {
34+
return position.get(address);
35+
}
36+
37+
public void setTexCoord(Vector2f texCoord) {
38+
this.texCoord.set(address, texCoord);
39+
}
1940

41+
public void setTexCoord(float x, float y) {
42+
texCoord.set(address, texCoord.getAlias().set(x, y));
43+
}
44+
45+
public Vector2f getTexCoord() {
46+
return texCoord.get(address);
47+
}
2048

2149
}

jme3-examples/src/main/java/jme3test/vulkan/TestJme4.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.jme3.math.ColorRGBA;
88
import com.jme3.scene.Geometry;
99
import com.jme3.scene.shape.Box;
10+
import com.jme3.util.struct.StructLayout;
1011
import com.jme3.vulkan.formats.Format;
1112
import com.jme3.vulkan.material.structs.UnshadedParams;
1213
import com.jme3.vulkan.mesh.InputRate;
@@ -38,6 +39,10 @@ public void simpleInitApp() {
3839
}));
3940
});
4041

42+
MeshLayout l2 = MeshLayout.build(m -> {
43+
m.addBinding(new VertexBinding(engine, InputRate.Vertex, () -> new Vertex(StructLayout.std140)));
44+
});
45+
4146
Geometry g = new Geometry("geom_jme4", new Box(1f, 1f, 1f));
4247
Material m = engine.createMaterial("Common/MatDefs/Misc/Unshaded.j3md");
4348
UnshadedParams p = m.get("Parameters");

0 commit comments

Comments
 (0)