Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SETUP
- jointsInstancedBufferID = glCreateBuffers();
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, jointsInstancedBufferID);
- int flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
- int buffersize = MAX_INSTANCED_SKELETAL_MESHES * MAX_JOINTS * MATRIX_SIZE_BYTES;
- var jointsDataInstancedBuffer = MemoryUtil.memAllocFloat(buffersize);
- glNamedBufferStorage(jointsInstancedBufferID, jointsDataInstancedBuffer, flags);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, jointsInstancedBufferID);
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
- MemoryUtil.memFree(jointsDataInstancedBuffer);
- jointsInstancedBuffer = glMapNamedBufferRange(jointsInstancedBufferID, 0, buffersize,flags).asFloatBuffer();syncObj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- // UPDATE DATA
- for(var Mesh: instanceMeshes) {
- int waitReturn = GL_UNSIGNALED;
- while (waitReturn != GL_ALREADY_SIGNALED && waitReturn != GL_CONDITION_SATISFIED) {
- waitReturn = glClientWaitSync(syncObj, GL_SYNC_FLUSH_COMMANDS_BIT, 1);
- }
- jointsInstancedBuffer.rewind();
- //...update buffer by using buffer.put()
- jointsInstancedBuffer.flip();
- glDeleteSync(syncObj);
- syncObj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- // instance render models belonging to the current mesh
- }
- // This for loop is repeated two more times in another shader in the same frame
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement