use of org.lwjgl.demo.opengl.util.WavefrontMeshLoader.MeshObject in project lwjgl3-demos by LWJGL.
the class HybridDemoSsboTriangles method createSceneSSBO.
/**
* Create two SSBOs:
* <ul>
* <li>one to hold all our triangles of the mesh
* <li>another to hold the objects of the mesh with their AABBs and triangle
* indexes
* </ul>
*/
private void createSceneSSBO() {
this.trianglesSsbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, trianglesSsbo);
ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4) * mesh.numVertices);
FloatBuffer fv = ssboData.asFloatBuffer();
for (int i = 0; i < mesh.numVertices; i++) {
float x = mesh.positions.get(3 * i + 0);
float y = mesh.positions.get(3 * i + 1);
float z = mesh.positions.get(3 * i + 2);
fv.put(x).put(y).put(z).put(0.0f);
/* We do not take normals into account, currently! */
// float nx = mesh.normals.get(3 * i + 0);
// float ny = mesh.normals.get(3 * i + 1);
// float nz = mesh.normals.get(3 * i + 2);
// fv.put(nx).put(ny).put(nz).put(0.0f);
}
glBufferData(GL_ARRAY_BUFFER, ssboData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
this.objectsSsbo = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, objectsSsbo);
DynamicByteBuffer objectsBuffer = new DynamicByteBuffer();
List<GPUObject> objects = new ArrayList<GPUObject>();
for (MeshObject o : mesh.objects) {
GPUObject obj = new GPUObject();
obj.min = o.min;
obj.max = o.max;
obj.first = o.first;
obj.count = o.count;
objects.add(obj);
}
Std430Writer.write(objects, GPUObject.class, objectsBuffer);
objectsBuffer.flip();
glBufferData(GL_ARRAY_BUFFER, objectsBuffer.bb, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Aggregations