Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. //SETUP
  2. jointsInstancedBufferID = glCreateBuffers();
  3. glBindBuffer(GL_SHADER_STORAGE_BUFFER, jointsInstancedBufferID);
  4.  
  5. int flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
  6. int buffersize = MAX_INSTANCED_SKELETAL_MESHES * MAX_JOINTS * MATRIX_SIZE_BYTES;
  7.  
  8. var jointsDataInstancedBuffer = MemoryUtil.memAllocFloat(buffersize);
  9. glNamedBufferStorage(jointsInstancedBufferID, jointsDataInstancedBuffer, flags);
  10. glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, jointsInstancedBufferID);
  11.  
  12. glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
  13. MemoryUtil.memFree(jointsDataInstancedBuffer);
  14.  
  15. //                          UPDATE DATA
  16.  
  17. for(var Mesh: instanceMeshes) {
  18.     int waitReturn = GL_UNSIGNALED;
  19.     while (waitReturn != GL_ALREADY_SIGNALED && waitReturn != GL_CONDITION_SATISFIED) {
  20.         waitReturn = glClientWaitSync(syncObj, GL_SYNC_FLUSH_COMMANDS_BIT, 1);
  21.     }
  22.    
  23.     jointsInstancedBuffer.rewind();
  24.     //...update buffer by using buffer.put()
  25.     jointsInstancedBuffer.flip();
  26.    
  27.     glDeleteSync(syncObj);
  28.     syncObj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
  29.    
  30.     // instance render models belonging to the current mesh
  31. }
  32. // 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