Java Code Examples for com.jogamp.opengl.GL4#glBufferData()
The following examples show how to use
com.jogamp.opengl.GL4#glBufferData() .
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_query_occlusion.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(positionBuffer); gl4.glBindBuffer(GL_ARRAY_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 2
Source File: Gl_410_program_binary.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL4 gl4) { IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); 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); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); return checkError(gl4, "initBuffer"); }
Example 3
Source File: Gl_420_debug_output.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL4 gl4) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); 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, positionSize, positionBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); 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); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(positionBuffer); return true; }
Example 4
Source File: Gl_400_transform_feedback_stream.java From jogl-samples with MIT License | 6 votes |
private boolean initArrayBuffer(GL4 gl4) { IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.TRANSFORM_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.TRANSFORM_ARRAY)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.FEEDBACK)); gl4.glBufferData(GL_ARRAY_BUFFER, 2 * Vec4.SIZE * elementCount, null, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); return checkError(gl4, "initArrayBuffer"); }
Example 5
Source File: Gl_440_fbo_without_attachment.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName, 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); gl4.glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferName[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); 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[Buffer.TRANSFORM]); gl4.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); return true; }
Example 6
Source File: Gl_420_sampler_fetch.java From jogl-samples with MIT License | 6 votes |
private boolean initBuffer(GL4 gl4) { ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); 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.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); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(vertexBuffer); return true; }
Example 7
Source File: Gl_430_program_compute_variable_group_size.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { boolean validated = true; ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); 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); 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(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return validated; }
Example 8
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 9
Source File: Gl_400_draw_indirect.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffers(GL4 gl4) { command = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0); IntBuffer commandBuffer = GLBuffers.newDirectIntBuffer(command.toIa_()); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); gl4.glBufferData(GL_DRAW_INDIRECT_BUFFER, command.SIZE, commandBuffer, GL_STATIC_READ); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.ARRAY)); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_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); BufferUtils.destroyDirectBuffer(positionBuffer); BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(commandBuffer); return checkError(gl4, "initBuffers"); }
Example 10
Source File: Gl_420_buffer_uniform.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { boolean validated = true; ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); FloatBuffer diffuseBuffer = GLBuffers.newDirectFloatBuffer(new float[]{1.0f, 0.5f, 0.0f, 1.0f}); 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, positionSize, positionBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, Mat4.SIZE * instances, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); } { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL)); gl4.glBufferData(GL_UNIFORM_BUFFER, diffuseBuffer.capacity() * Float.BYTES, diffuseBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); } BufferUtils.destroyDirectBuffer(elementBuffer); BufferUtils.destroyDirectBuffer(positionBuffer); BufferUtils.destroyDirectBuffer(diffuseBuffer); return validated; }
Example 11
Source File: Gl_410_primitive_tessellation2.java From jogl-samples with MIT License | 5 votes |
private boolean initArrayBuffer(GL4 gl4) { FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); // Generate a buffer object gl4.glGenBuffers(1, arrayBufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, arrayBufferName.get(0)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(vertexBuffer); return checkError(gl4, "initArrayBuffer"); }
Example 12
Source File: Gl_450_query_conditional.java From jogl-samples with MIT License | 5 votes |
private boolean initBuffer(GL4 gl4) { int[] uniformBufferOffset = {0}; gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0); gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData); gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW); BufferUtils.destroyDirectBuffer(positionBuffer); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); uniformTransformOffset = Math.max(Mat4.SIZE, uniformBufferOffset[0]); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, uniformTransformOffset * 2, null, GL_DYNAMIC_DRAW); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); uniformMaterialOffset = Math.max(Vec4.SIZE, uniformBufferOffset[0]); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL)); gl4.glBufferData(GL_UNIFORM_BUFFER, uniformMaterialOffset * 2, null, GL_STATIC_DRAW); { ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, uniformMaterialOffset * 2, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); pointer.asFloatBuffer().put(new float[]{0.0f, 0.5f, 1.0f, 1.0f}); pointer.position(uniformMaterialOffset); pointer.asFloatBuffer().put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}); pointer.rewind(); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); return true; }
Example 13
Source File: Gl_430_program_subroutine.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)); IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(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); 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_COPY); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); return true; }
Example 14
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 15
Source File: Gl_420_atomic_counter.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { boolean validated = true; int[] maxVertexAtomicCounterBuffers = {0}; int[] maxControlAtomicCounterBuffers = {0}; int[] maxEvaluationAtomicCounterBuffers = {0}; int[] maxGeometryAtomicCounterBuffers = {0}; int[] maxFragmentAtomicCounterBuffers = {0}; int[] maxCombinedAtomicCounterBuffers = {0}; ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData); FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGetIntegerv(GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS, maxVertexAtomicCounterBuffers, 0); gl4.glGetIntegerv(GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS, maxControlAtomicCounterBuffers, 0); gl4.glGetIntegerv(GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS, maxEvaluationAtomicCounterBuffers, 0); gl4.glGetIntegerv(GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS, maxGeometryAtomicCounterBuffers, 0); gl4.glGetIntegerv(GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS, maxFragmentAtomicCounterBuffers, 0); gl4.glGetIntegerv(GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS, maxCombinedAtomicCounterBuffers, 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); return validated; }
Example 16
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 17
Source File: Gl_420_primitive_line_aa.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { int count = 1000; float step = (float) (Math.PI * 2.0f / count); vertexData = new Vec2[count]; ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexData.length * Vec2.SIZE); IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1); for (int i = 0; i < count; ++i) { //VertexData[i] = glm::vec2(glm::fastSin(glm::radians(Step * float(i))), glm::fastCos(glm::radians(Step * float(i)))); /* VertexData[i] = glm::vec2( glm::fastSin(glm::mod(Step * float(i), glm::pi<float>())), glm::fastCos(glm::mod(Step * float(i), glm::pi<float>()))); */ /* VertexData[i] = glm::vec2( glm::sin(Step * float(i)), glm::fastCos(glm::mod(Step * float(i), glm::pi<float>()))); */ vertexData[i] = new Vec2( Math.sin(step * i), Math.cos(step * i)); } gl4.glGenBuffers(Buffer.MAX, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); for (int i = 0; i < vertexData.length; i++) { vertexData[i].toDbb(vertexBuffer, i * Vec2.SIZE); } gl4.glBufferData(GL_ARRAY_BUFFER, vertexData.length * Vec2.SIZE, 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(vertexBuffer); BufferUtils.destroyDirectBuffer(uniformBufferOffset); return true; }
Example 18
Source File: Gl_440_multi_draw_indirect_id_arb.java From jogl-samples with MIT License | 4 votes |
private boolean initBuffer(GL4 gl4) { gl4.glGenBuffers(Buffer.MAX, bufferName); 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); 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}; gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.VERTEX_INDIRECTION)); IntBuffer vertexIndirectionBuffer = GLBuffers.newDirectIntBuffer(vertexIndirection); gl4.glBufferData(GL_UNIFORM_BUFFER, Integer.BYTES * 3, vertexIndirectionBuffer, GL_DYNAMIC_DRAW); BufferUtils.destroyDirectBuffer(vertexIndirectionBuffer); gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0); int padding = Math.max(Mat4.SIZE, uniformArrayStride.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); gl4.glBufferData(GL_UNIFORM_BUFFER, padding * 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; IntBuffer commandsBuffer = GLBuffers.newDirectIntBuffer(5 * commands.length); for (DrawElementsIndirectCommand command : commands) { commandsBuffer.put(command.toIa_()); } commandsBuffer.rewind(); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); 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 19
Source File: Gl_400_program_varying_structs.java From jogl-samples with MIT License | 3 votes |
private boolean initArrayBuffer(GL4 gl4) { FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGenBuffers(1, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(vertexBuffer); return checkError(gl4, "initArrayBuffer"); }
Example 20
Source File: Gl_420_interface_matching.java From jogl-samples with MIT License | 3 votes |
private boolean initBuffer(GL4 gl4) { FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData); gl4.glGenBuffers(1, bufferName); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); BufferUtils.destroyDirectBuffer(vertexBuffer); return true; }