Java Code Examples for com.jogamp.opengl.GL4#glBufferSubData()
The following examples show how to use
com.jogamp.opengl.GL4#glBufferSubData() .
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_430_multi_draw_indirect.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(vertexBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.DRAW_ID)); IntBuffer drawIdBuffer = GLBuffers.newDirectIntBuffer(drawIdData); gl4.glBufferData(GL_ARRAY_BUFFER, drawSize, drawIdBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(drawIdBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(elementBuffer); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); int[] vertexIndirection = {0, 1, 2}; int paddingInt = Math.max(Integer.BYTES, uniformArrayStrideInt.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.VERTEX_INDIRECTION)); gl4.glBufferData(GL_UNIFORM_BUFFER, paddingInt * 3, null, GL_DYNAMIC_DRAW); IntBuffer paddingIntBuffer = GLBuffers.newDirectIntBuffer(1); paddingIntBuffer.put(0, vertexIndirection[0]); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 0, paddingInt, paddingIntBuffer); paddingIntBuffer.put(0, vertexIndirection[1]); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 1, paddingInt, paddingIntBuffer); paddingIntBuffer.put(0, vertexIndirection[2]); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 2, paddingInt, paddingIntBuffer); BufferUtils.destroyDirectBuffer(paddingIntBuffer); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); int paddingMat = Math.max(Mat4.SIZE, uniformArrayStrideMat.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, paddingMat * 3, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); DrawElementsIndirectCommand[] commands = new DrawElementsIndirectCommand[6]; commands[0] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[1] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[2] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); commands[3] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[4] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[5] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); drawCount[0] = 3; drawCount[1] = 2; drawCount[2] = 1; drawOffset[0] = 0; drawOffset[1] = 1; drawOffset[2] = 3; gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); IntBuffer commandsBuffer = GLBuffers.newDirectIntBuffer(5 * commands.length); for (DrawElementsIndirectCommand command : commands) { commandsBuffer.put(command.toIa_()); } commandsBuffer.rewind(); gl4.glBufferData(GL_DRAW_INDIRECT_BUFFER, commandsBuffer.capacity() * Integer.BYTES, commandsBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(commandsBuffer); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); return true; }
Example 2
Source File: Gl_430_program_compute_image.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); FloatBuffer texCoordBuffer = GLBuffers.newDirectFloatBuffer(texCoordData); FloatBuffer colorBuffer = GLBuffers.newDirectFloatBuffer(colorData); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.POSITION_INPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize * 2, null, GL_STATIC_DRAW); gl4.glBufferSubData(GL_ARRAY_BUFFER, 0, positionSize, positionBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.TEXCOORD_INPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, texCoordSize * 2, texCoordBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.COLOR_INPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, colorSize * 2, colorBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.POSITION_OUTPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize * 2, null, GL_STATIC_COPY); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.TEXCOORD_OUTPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, texCoordSize * 2, null, GL_STATIC_COPY); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.COLOR_OUTPUT)); gl4.glBufferData(GL_ARRAY_BUFFER, colorSize * 2, null, GL_STATIC_COPY); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl4.glGetIntegerv( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(positionBuffer); BufferUtils.destroyDirectBuffer(texCoordBuffer); BufferUtils.destroyDirectBuffer(colorBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return checkError(gl4, "initBuffer"); }
Example 3
Source File: Gl_430_texture_buffer.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { float[] displacement = { +0.1f, +0.3f, -1.0f, -0.5f, +0.0f, -0.5f, -0.2f, -0.2f, +0.0f, +0.3f, +0.2f, +0.5f, +0.1f, -0.3f, +1.0f}; float[] diffuse = { 1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; int[] textureBufferOffsetAlignment = {0}; gl4.glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, textureBufferOffsetAlignment, 0); int displacementSize = Vec3.SIZE * displacement.length; int diffuseSize = Vec3.SIZE * diffuse.length; int displacementMultiple = glm.ceilMultiple(displacementSize, textureBufferOffsetAlignment[0]); int diffuseMultiple = glm.ceilMultiple(diffuseSize, textureBufferOffsetAlignment[0]); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(elementBuffer); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(vertexBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_TEXTURE_BUFFER, bufferName.get(Buffer.DISPLACEMENT)); gl4.glBufferData(GL_TEXTURE_BUFFER, textureBufferOffsetAlignment[0] + displacementMultiple, null, GL_STATIC_DRAW); FloatBuffer displacementBuffer = GLBuffers.newDirectFloatBuffer(displacement); gl4.glBufferSubData(GL_TEXTURE_BUFFER, textureBufferOffsetAlignment[0], displacementSize, displacementBuffer); BufferUtils.destroyDirectBuffer(displacementBuffer); /* void * PointerDisplacement = glMapBufferRange(GL_TEXTURE_BUFFER, 0, sizeof(Displacement), GL_MAP_WRITE_BIT ); memcpy(PointerDisplacement, &Displacement[0], sizeof(Displacement)); glUnmapBuffer(GL_TEXTURE_BUFFER); */ gl4.glBindBuffer(GL_TEXTURE_BUFFER, 0); gl4.glBindBuffer(GL_TEXTURE_BUFFER, bufferName.get(Buffer.DIFFUSE)); gl4.glBufferData(GL_TEXTURE_BUFFER, textureBufferOffsetAlignment[0] + diffuseMultiple, null, GL_STATIC_DRAW); FloatBuffer diffuseBuffer = GLBuffers.newDirectFloatBuffer(diffuse); gl4.glBufferSubData(GL_TEXTURE_BUFFER, textureBufferOffsetAlignment[0], diffuseSize, diffuseBuffer); BufferUtils.destroyDirectBuffer(diffuseBuffer); gl4.glBindBuffer(GL_TEXTURE_BUFFER, 0); 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.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); return true; }
Example 4
Source File: Gl_500_multi_draw_indirect_arb.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(vertexBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(elementBuffer); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); int[] vertexIndirection = {0, 1, 2}; int paddingInt = Math.max(Integer.BYTES, uniformArrayStrideInt.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.VERTEX_INDIRECTION)); gl4.glBufferData(GL_UNIFORM_BUFFER, paddingInt * 3, null, GL_DYNAMIC_DRAW); IntBuffer paddingIntBuffer = GLBuffers.newDirectIntBuffer(1); paddingIntBuffer.put(vertexIndirection[0]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 0, Integer.BYTES, paddingIntBuffer); paddingIntBuffer.put(vertexIndirection[1]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 1, Integer.BYTES, paddingIntBuffer); paddingIntBuffer.put(vertexIndirection[2]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 2, Integer.BYTES, paddingIntBuffer); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, Mat4.SIZE * indirectBufferCount, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); DrawElementsIndirectCommand[] commands = new DrawElementsIndirectCommand[6]; commands[0] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[1] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[2] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); commands[3] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[4] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[5] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); drawCount.put(0, 3); drawCount.put(1, 2); drawCount.put(2, 1); drawOffset.put(0, 0); drawOffset.put(1, 1); drawOffset.put(2, 3); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); IntBuffer commandsBuffer = GLBuffers.newDirectIntBuffer(5 * commands.length); for (DrawElementsIndirectCommand command : commands) { commandsBuffer.put(command.toIa_()); } /** * Critical, I forgot once to rewing the buffer, the driver video crashed. */ commandsBuffer.rewind(); gl4.glBufferData(GL_DRAW_INDIRECT_BUFFER, DrawElementsIndirectCommand.SIZE * commands.length, commandsBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); BufferUtils.destroyDirectBuffer(commandsBuffer); return true; }
Example 5
Source File: Gl_500_multi_draw_indirect_count_arb.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.VERTEX]); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(vertexBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT]); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(elementBuffer); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); int[] vertexIndirection = {0, 1, 2}; int paddingInt = Math.max(Integer.BYTES, uniformArrayStrideInt[0]); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName[Buffer.VERTEX_INDIRECTION]); gl4.glBufferData(GL_UNIFORM_BUFFER, paddingInt * 3, null, GL_DYNAMIC_DRAW); IntBuffer paddingIntBuffer = GLBuffers.newDirectIntBuffer(1); paddingIntBuffer.put(vertexIndirection[0]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 0, Integer.BYTES, paddingIntBuffer); paddingIntBuffer.put(vertexIndirection[1]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 1, Integer.BYTES, paddingIntBuffer); paddingIntBuffer.put(vertexIndirection[2]).rewind(); gl4.glBufferSubData(GL_UNIFORM_BUFFER, paddingInt * 2, Integer.BYTES, paddingIntBuffer); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName[Buffer.TRANSFORM]); gl4.glBufferData(GL_UNIFORM_BUFFER, Mat4.SIZE * drawDataCount, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); DrawElementsIndirectCommand[] commands = new DrawElementsIndirectCommand[6]; commands[0] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[1] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[2] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); commands[3] = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); commands[4] = new DrawElementsIndirectCommand(elementCount >> 1, 1, 6, 4, 1); commands[5] = new DrawElementsIndirectCommand(elementCount, 1, 9, 7, 2); drawCount[0] = 3; drawCount[1] = 2; drawCount[2] = 1; drawOffset[0] = 0; drawOffset[1] = 1; drawOffset[2] = 3; gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName[Buffer.INDIRECT]); IntBuffer commandsBuffer = GLBuffers.newDirectIntBuffer(5 * commands.length); for (DrawElementsIndirectCommand command : commands) { commandsBuffer.put(command.toIa_()); } /** * Critical, I forgot once to rewing the buffer, the driver video crashed. */ commandsBuffer.rewind(); gl4.glBufferData(GL_DRAW_INDIRECT_BUFFER, DrawElementsIndirectCommand.SIZE * commands.length, commandsBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); BufferUtils.destroyDirectBuffer(commandsBuffer); gl4.glBindBuffer(GL_PARAMETER_BUFFER_ARB, bufferName[Buffer.PARAMETER]); IntBuffer drawCountBuffer = GLBuffers.newDirectIntBuffer(drawCount); gl4.glBufferData(GL_PARAMETER_BUFFER_ARB, drawCount.length * Integer.BYTES, drawCountBuffer, GL_DYNAMIC_DRAW); BufferUtils.destroyDirectBuffer(drawCountBuffer); gl4.glBindBuffer(GL_PARAMETER_BUFFER_ARB, 0); return true; }