Advertisement
baryonSasuke

openGL buffer mapping query

Dec 23rd, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 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. jointsInstancedBuffer = glMapNamedBufferRange(jointsInstancedBufferID, 0, buffersize,flags).asFloatBuffer();syncObj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
  16.  
  17. //                          UPDATE DATA
  18.  
  19. for(var Mesh: instanceMeshes) {
  20.     int waitReturn = GL_UNSIGNALED;
  21.     while (waitReturn != GL_ALREADY_SIGNALED && waitReturn != GL_CONDITION_SATISFIED) {
  22.         waitReturn = glClientWaitSync(syncObj, GL_SYNC_FLUSH_COMMANDS_BIT, 1);
  23.     }
  24.    
  25.     jointsInstancedBuffer.rewind();
  26.     //...update buffer by using buffer.put()
  27.     jointsInstancedBuffer.flip();
  28.    
  29.     glDeleteSync(syncObj);
  30.     syncObj = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
  31.    
  32.     // instance render models belonging to the current mesh
  33. }
  34. // 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