Java Code Examples for com.jogamp.opengl.util.GLBuffers#newDirectIntBuffer()
The following examples show how to use
com.jogamp.opengl.util.GLBuffers#newDirectIntBuffer() .
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_410_fbo_layered.java From jogl-samples with MIT License | 6 votes |
private boolean initFramebuffer(GL4 gl4) { IntBuffer buffersRender = GLBuffers.newDirectIntBuffer(new int[]{GL_COLOR_ATTACHMENT0}); gl4.glGenFramebuffers(1, framebufferName); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(0), 0); gl4.glDrawBuffers(1, buffersRender); if (!isFramebufferComplete(gl4, framebufferName.get(0))) { return false; } gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glDrawBuffer(GL_BACK); if (!isFramebufferComplete(gl4, 0)) { return false; } BufferUtils.destroyDirectBuffer(buffersRender); return checkError(gl4, "initFramebuffer"); }
Example 2
Source File: Es_300_draw_elements.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL3ES3 gl3es3) { FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData); gl3es3.glGenBuffers(Buffer.MAX, bufferName); gl3es3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3es3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); gl3es3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3es3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl3es3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl3es3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(positionBuffer); BufferUtils.destroyDirectBuffer(elementBuffer); return checkError(gl3es3, "initBuffer"); }
Example 3
Source File: Gl_320_query_occlusion.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL3 gl3) { FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(positionBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return checkError(gl3, "initBuffer"); }
Example 4
Source File: Gl_500_shader_group_nv.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); BufferUtils.destroyDirectBuffer(uniformBufferOffset); gl4.glCreateBuffers(Buffer.MAX, bufferName); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); if (!bug1287) { gl4.glNamedBufferStorage(bufferName.get(Buffer.ELEMENT), elementSize, elementBuffer, 0); gl4.glNamedBufferStorage(bufferName.get(Buffer.VERTEX), vertexSize, vertexBuffer, 0); gl4.glNamedBufferStorage(bufferName.get(Buffer.TRANSFORM), uniformBlockSize, null, GL_MAP_WRITE_BIT); } else { gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glBufferStorage(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); } return true; }
Example 5
Source File: Gl_320_texture_derivative.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL3 gl3) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return true; }
Example 6
Source File: Gl_500_texture_sparse_arb.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { 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_SHADER_STORAGE_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glBufferData(GL_SHADER_STORAGE_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); // BufferUtils.destroyDirectBuffer(vertexBuffer); gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); BufferUtils.destroyDirectBuffer(uniformBufferOffset); 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 7
Source File: Gl_400_texture_derivative.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); 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.VERTEX)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); 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(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return true; }
Example 8
Source File: Gl_420_texture_cube.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); for (int i = 0; i < vertexCount; i++) { vertexData[i].toDbb(vertexBuffer, i * Vec2.SIZE); } gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glGetIntegerv( GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Transform.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(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return true; }
Example 9
Source File: Gl_320_texture_2d.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL3 gl3) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return checkError(gl3, "initBuffer"); }
Example 10
Source File: Gl_320_query_occlusion.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } // Set the display viewport gl3.glViewport(0, 0, windowSize.x, windowSize.y); // Clear color buffer with black gl3.glClearBufferfv(GL_COLOR, 0, clearColor); gl3.glUseProgram(programName); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); // Samples count query gl3.glBeginQuery(GL_SAMPLES_PASSED, queryName.get(0)); { gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } gl3.glEndQuery(GL_SAMPLES_PASSED); // Get the count of samples. // If the result of the query isn't here yet, we wait here... IntBuffer samplesCount = GLBuffers.newDirectIntBuffer(1); gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, samplesCount); System.out.println("Samples (fragments) count: " + samplesCount.get(0)); BufferUtils.destroyDirectBuffer(samplesCount); return true; }
Example 11
Source File: Gl_320_transform_feedback_separated.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); // Set the display viewport gl3.glViewport(0, 0, windowSize.x, windowSize.y); // Clear color buffer with black gl3.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl3.glClear(GL_COLOR_BUFFER_BIT); // First draw, capture the attributes { // Disable rasterisation, vertices processing only! gl3.glEnable(GL_RASTERIZER_DISCARD); gl3.glUseProgram(programName[Program.TRANSFORM]); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.POSITION, bufferName.get(Buffer.POSITION)); gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.COLOR, bufferName.get(Buffer.COLOR)); gl3.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM)); gl3.glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryName.get(0)); gl3.glBeginTransformFeedback(GL_TRIANGLES); { gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } gl3.glEndTransformFeedback(); gl3.glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); gl3.glDisable(GL_RASTERIZER_DISCARD); } // Second draw, reuse the captured attributes { gl3.glUseProgram(programName[Program.FEEDBACK]); IntBuffer primitivesWritten = GLBuffers.newDirectIntBuffer(1); gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, primitivesWritten); gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, primitivesWritten.get(0) * 3, 1); BufferUtils.destroyDirectBuffer(primitivesWritten); } return true; }
Example 12
Source File: Gl_430_direct_state_access_ext.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl4.glCreateBuffers(Buffer.MAX, bufferName); gl4.glNamedBufferData(bufferName.get(Buffer.ELEMENT), elementSize, elementBuffer, GL_STATIC_DRAW); gl4.glNamedBufferData(bufferName.get(Buffer.VERTEX), vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glNamedBufferData(bufferName.get(Buffer.TRANSFORM), uniformBlockSize, null, GL_DYNAMIC_DRAW); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return true; }
Example 13
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 14
Source File: Gl_430_atomic_counter.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { boolean validated = true; IntBuffer data = GLBuffers.newDirectIntBuffer(1); ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGetIntegerv(GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGetIntegerv(GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGetIntegerv(GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGetIntegerv(GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS, data); System.out.println("GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS: " + data.get(0)); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, Mat4.SIZE, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); 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.VERTEX)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bufferName.get(Buffer.ATOMIC_COUNTER)); gl4.glBufferData(GL_ATOMIC_COUNTER_BUFFER, Integer.BYTES, null, GL_DYNAMIC_COPY); gl4.glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); BufferUtils.destroyDirectBuffer(data); return validated; }
Example 15
Source File: Gl_500_texture_bindless_arb.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementSize); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, 0); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glBufferStorage(GL_SHADER_STORAGE_BUFFER, vertexSize, vertexBuffer, 0); gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); BufferUtils.destroyDirectBuffer(uniformBufferOffset); 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); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); uniformPointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL)); gl4.glBufferStorage(GL_UNIFORM_BUFFER, Long.BYTES, textureHandle, 0); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); DrawElementsIndirectCommand command = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); IntBuffer commandBuffer = GLBuffers.newDirectIntBuffer(command.toIa_()); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); gl4.glBufferStorage(GL_DRAW_INDIRECT_BUFFER, DrawElementsIndirectCommand.SIZE, commandBuffer, 0); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); BufferUtils.destroyDirectBuffer(commandBuffer); return true; }
Example 16
Source File: Gl_320_draw_without_vertex_attrib.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL3 gl3) { IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(1, bufferName); gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset); int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0)); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(0)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return checkError(gl3, "initBuffer"); }
Example 17
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 18
Source File: Gl_320_fbo_depth_stencil.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; IntBuffer uniformBufferOffsetAlignment = GLBuffers.newDirectIntBuffer(1); { gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffsetAlignment); uniformBufferOffsetAlignment.put(0, glm.ceilMultiple(Mat4.SIZE, uniformBufferOffsetAlignment.get(0))); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, uniformBufferOffsetAlignment.get(0) * 2, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); pointer.asFloatBuffer().put(projection.mul_(viewMat4()).scale(new Vec3(1.00f)).toFa_()); pointer.position(uniformBufferOffsetAlignment.get(0) * 1); pointer.asFloatBuffer().put(projection.mul(viewMat4()).scale(new Vec3(1.05f)).toFa_()); pointer.rewind(); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } { gl3.glEnable(GL_STENCIL_TEST); gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LEQUAL); gl3.glStencilMask(0xFF); gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0f, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl3.glUseProgram(programName[Program.TEXTURE]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), uniformBufferOffsetAlignment.get(0) * 0, uniformBufferOffsetAlignment.get(0)); gl3.glDisable(GL_DEPTH_TEST); gl3.glStencilMask(0xFF); gl3.glStencilFunc(GL_ALWAYS, 1, 0xFF); gl3.glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); gl3.glBindTexture(GL_TEXTURE_2D, 0); // gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), uniformBufferOffsetAlignment.get(0) * 1, uniformBufferOffsetAlignment.get(0)); gl3.glStencilMask(0x00); gl3.glStencilFunc(GL_NOTEQUAL, 1, 0xFF); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } { gl3.glDisable(GL_DEPTH_TEST); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glUseProgram(programName[Program.SPLASH]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); } BufferUtils.destroyDirectBuffer(uniformBufferOffsetAlignment); return true; }
Example 19
Source File: Gl_320_program.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL3 gl3) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); IntBuffer uniformBlockSize = GLBuffers.newDirectIntBuffer(1); gl3.glGenBuffers(Buffer.MAX, bufferName); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); { gl3.glGetActiveUniformBlockiv(programName[Program.USED], uniformTransform, GL_UNIFORM_BLOCK_DATA_SIZE, uniformBlockSize); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize.get(0), null, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); } { FloatBuffer diffuseBuffer = GLBuffers.newDirectFloatBuffer(new float[]{1.0f, 0.5f, 0.0f, 1.0f}); gl3.glGetActiveUniformBlockiv(programName[Program.USED], uniformMaterial, GL_UNIFORM_BLOCK_DATA_SIZE, uniformBlockSize); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL)); gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize.get(0), diffuseBuffer, GL_DYNAMIC_DRAW); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); BufferUtils.destroyDirectBuffer(diffuseBuffer); } BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(positionBuffer); return checkError(gl3, "initBuffer"); }
Example 20
Source File: Gl_320_transform_feedback_interleaved.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); // Set the display viewport gl3.glViewport(0, 0, windowSize.x, windowSize.y); // Clear color buffer clearColor.put(new float[]{0.0f, 0.0f, 0.0f, 1.0f}).rewind(); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); // First draw, capture the attributes // Disable rasterisation, vertices processing only! gl3.glEnable(GL_RASTERIZER_DISCARD); gl3.glUseProgram(programName[Program.TRANSFORM]); gl3.glUniformMatrix4fv(transformUniformMvp, 1, false, mvp.toFa_(), 0); gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.POSITION, bufferName.get(Program.FEEDBACK)); gl3.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM)); gl3.glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryName.get(0)); gl3.glBeginTransformFeedback(GL_TRIANGLES); { gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } gl3.glEndTransformFeedback(); gl3.glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); gl3.glDisable(GL_RASTERIZER_DISCARD); // Second draw, reuse the captured attributes gl3.glUseProgram(programName[Program.FEEDBACK]); IntBuffer primitivesWritten = GLBuffers.newDirectIntBuffer(1); gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, primitivesWritten); gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, primitivesWritten.get(0) * 3, 1); BufferUtils.destroyDirectBuffer(primitivesWritten); return true; }