Java Code Examples for com.jogamp.opengl.GL4#glCopyBufferSubData()
The following examples show how to use
com.jogamp.opengl.GL4#glCopyBufferSubData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gl_500_buffer_sparse_arb.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { int alignement = 256; IntBuffer bufferPageSize = GLBuffers.newDirectIntBuffer(1); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glGetIntegerv(GL_SPARSE_BUFFER_PAGE_SIZE_ARB, bufferPageSize); boolean validated = true; int copyBufferSize = glm.ceilMultiple(vertexSize, alignement) + glm.ceilMultiple(elementSize, alignement); gl4.glCreateBuffers(Buffer.MAX, bufferName); if (!bug1287) { gl4.glNamedBufferStorage(bufferName.get(Buffer.COPY), copyBufferSize, null, GL_MAP_WRITE_BIT); } else { gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferName.get(Buffer.COPY)); gl4.glBufferStorage(GL_SHADER_STORAGE_BUFFER, copyBufferSize, null, GL_MAP_WRITE_BIT); gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); } ByteBuffer copyBufferPointer = gl4.glMapNamedBufferRange(bufferName.get(Buffer.COPY), 0, copyBufferSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); copyBufferPointer.asFloatBuffer().put(vertexBuffer); copyBufferPointer.position(glm.ceilMultiple(vertexSize, alignement)); copyBufferPointer.asShortBuffer().put(elementBuffer); gl4.glUnmapNamedBuffer(bufferName.get(Buffer.COPY)); gl4.glBindBuffer(GL_COPY_READ_BUFFER, bufferName.get(Buffer.COPY)); gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(elementSize, bufferPageSize.get(0)), null, GL_SPARSE_STORAGE_BIT_ARB); gl4.glBufferPageCommitmentARB(GL_COPY_WRITE_BUFFER, 0, bufferPageSize.get(0), true); gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, alignement), 0, glm.ceilMultiple(elementSize, alignement)); gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, bufferPageSize.get(0)), null, GL_SPARSE_STORAGE_BIT_ARB); gl4.glBufferPageCommitmentARB(GL_COPY_WRITE_BUFFER, 0, bufferPageSize.get(0), true); gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, glm.ceilMultiple(vertexSize, alignement)); int[] uniformBufferOffset = {0}; gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]); if (!bug1287) { gl4.glNamedBufferStorage(bufferName.get(Buffer.TRANSFORM), uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); } else { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); } BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(bufferPageSize); return validated; }
Example 2
Source File: Gl_440_buffer_storage.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { int alignement = 256; boolean validated = true; gl4.glGenBuffers(Buffer.MAX, bufferName); int copyBufferSize = glm.ceilMultiple(vertexSize, alignement) + glm.ceilMultiple(elementSize, alignement); gl4.glBindBuffer(GL_COPY_READ_BUFFER, bufferName.get(Buffer.COPY)); gl4.glBufferStorage(GL_COPY_READ_BUFFER, copyBufferSize, null, GL_MAP_WRITE_BIT); ByteBuffer copyBufferPointer = gl4.glMapBufferRange(GL_COPY_READ_BUFFER, 0, copyBufferSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); copyBufferPointer.asFloatBuffer().put(vertexData); copyBufferPointer.position(glm.ceilMultiple(vertexSize, alignement)); copyBufferPointer.asShortBuffer().put(elementData); copyBufferPointer.rewind(); gl4.glUnmapBuffer(GL_COPY_READ_BUFFER); gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(elementSize, alignement), null, 0); gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, alignement), 0, glm.ceilMultiple(elementSize, alignement)); gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, alignement), null, 0); gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, glm.ceilMultiple(vertexSize, alignement)); int[] uniformBufferOffset = {0}; gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); return validated; }