use of io.xol.chunkstories.api.rendering.vertex.VertexBuffer in project chunkstories-api by Hugobros3.
the class VoxelItemRenderer method renderFakeVoxel.
/**
* Look for this configuration of the Voxel in the local cache
*/
private void renderFakeVoxel(RenderingInterface renderingContext, CellData cell) {
String hash = cell.getVoxel().getName() + cell.getMetaData();
// If we did not already cache this variant of the model
if (!voxelItemsModelBuffer.containsKey(hash)) {
// Generous allocation TODO use JEmalloc here
VertexBuffer mesh = renderingContext.newVertexBuffer();
bakeVoxelRenderer(cell, mesh);
voxelItemsModelBuffer.put(hash, mesh);
}
if (voxelItemsModelBuffer.containsKey(hash)) {
VertexBuffer mesh = voxelItemsModelBuffer.get(hash);
// This is why we needed VoxelInHandLayoutBaker!
renderingContext.bindAttribute("vertexIn", mesh.asAttributeSource(VertexFormat.FLOAT, 3, 24, 0));
renderingContext.bindAttribute("texCoordIn", mesh.asAttributeSource(VertexFormat.FLOAT, 2, 24, 12));
renderingContext.bindAttribute("normalIn", mesh.asAttributeSource(VertexFormat.U1010102, 4, 24, 20));
renderingContext.draw(Primitive.TRIANGLE, 0, (int) (mesh.getVramUsage() / 24));
}
}
use of io.xol.chunkstories.api.rendering.vertex.VertexBuffer in project chunkstories by Hugobros3.
the class VertexBufferGL method updateVerticesObjects.
public static long updateVerticesObjects() {
long vram = 0;
Iterator<VertexBufferGL> i = objectsToDestroy.iterator();
while (i.hasNext()) {
VertexBuffer object = i.next();
if (object.destroy()) {
}
i.remove();
}
Iterator<Entry<Integer, WeakReference<VertexBufferGL>>> i2 = allocatedIds.entrySet().iterator();
while (i2.hasNext()) {
Entry<Integer, WeakReference<VertexBufferGL>> entry = i2.next();
int openGLID = entry.getKey();
WeakReference<VertexBufferGL> weakReference = entry.getValue();
VertexBuffer verticesObject = weakReference.get();
if (verticesObject == null) {
// Gives back orphan buffers
glDeleteBuffers(openGLID);
totalVerticesObjects--;
// logger.debug("Destroyed orphan VerticesObject id #"+openGLID);
i2.remove();
}
}
// Iterates over every instance reference, removes null ones and add up valid ones
Iterator<WeakReference<VertexBufferGL>> i3 = allVerticesObjects.iterator();
while (i3.hasNext()) {
WeakReference<VertexBufferGL> reference = i3.next();
VertexBufferGL verticesObject = reference.get();
if (verticesObject != null && verticesObject.glID != -2) {
// Send deffered uploads
verticesObject.uploadPendingDefferedData();
vram += verticesObject.getVramUsage();
} else
// Remove null objects from the list
i3.remove();
}
return vram;
}
use of io.xol.chunkstories.api.rendering.vertex.VertexBuffer in project chunkstories by Hugobros3.
the class TextMeshObject method render.
public void render(RenderingInterface renderingContext) {
// TODO use texture pages
renderingContext.bindAlbedoTexture(font.glTextures[0]);
renderingContext.setCullingMode(CullingMode.DISABLED);
// TODO use texture pages
for (VertexBuffer verticesObject : verticesObjects) {
int stride = 4 * (3 + 2 + 4 + 3);
renderingContext.bindAttribute("vertexIn", verticesObject.asAttributeSource(VertexFormat.FLOAT, 3, stride, 0));
renderingContext.bindAttribute("texCoordIn", verticesObject.asAttributeSource(VertexFormat.FLOAT, 2, stride, 4 * 3));
renderingContext.bindAttribute("colorIn", verticesObject.asAttributeSource(VertexFormat.FLOAT, 4, stride, 4 * (3 + 2)));
renderingContext.bindAttribute("normalIn", verticesObject.asAttributeSource(VertexFormat.FLOAT, 4, stride, 4 * (3 + 2 + 4)));
renderingContext.draw(Primitive.TRIANGLE, 0, (int) (verticesObject.getVramUsage() / stride));
}
// renderingContext.currentShader().setUniform1f("useNormalIn", 1f);
}
use of io.xol.chunkstories.api.rendering.vertex.VertexBuffer in project chunkstories by Hugobros3.
the class ChunkRenderDataHolder method setData.
public void setData(ChunkMeshDataSections newData) {
if (newData == null)
throw new NullPointerException("setData() requires non-null ata");
oneUploadAtATime.acquireUninterruptibly();
noDrawDeleteConflicts.acquireUninterruptibly();
// Meh that's a waste of time then
if (isDestroyed) {
noDrawDeleteConflicts.release();
oneUploadAtATime.release();
// <-- Free the data
newData.notNeeded();
return;
}
// No verticesObject already created; create one, fill it and then change the bails
if (verticesObject == null) {
VertexBuffer wip = worldRenderer.getRenderingInterface().newVertexBuffer();
Fence fence = wip.uploadData(newData.dataToUpload);
// We unlock while waiting for the upload
noDrawDeleteConflicts.release();
fence.traverse();
// Then we lock again
noDrawDeleteConflicts.acquireUninterruptibly();
verticesObject = wip;
currentData = newData;
// And we're good !
} else // Already a VerticesObject present hum, we create another one then delete the old one
{
VertexBuffer wip = worldRenderer.getRenderingInterface().newVertexBuffer();
Fence fence = wip.uploadData(newData.dataToUpload);
// We unlock while waiting for the upload
noDrawDeleteConflicts.release();
fence.traverse();
// Then we lock again
noDrawDeleteConflicts.acquireUninterruptibly();
// We delete the OLD one
verticesObject.destroy();
// We swap the new one in
verticesObject = wip;
currentData = newData;
}
newData.consumed();
noDrawDeleteConflicts.release();
oneUploadAtATime.release();
}
Aggregations