Java Code Examples for com.jogamp.opengl.GL4#glBindVertexArray()
The following examples show how to use
com.jogamp.opengl.GL4#glBindVertexArray() .
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_450_culling.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glVertexAttribBinding(Semantic.Attr.POSITION, Semantic.Buffer.STATIC); gl4.glVertexAttribFormat(Semantic.Attr.POSITION, 2, GL_FLOAT, false, 0); gl4.glVertexAttribBinding(Semantic.Attr.TEXCOORD, Semantic.Buffer.STATIC); gl4.glVertexAttribFormat(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vec2.SIZE); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); gl4.glBindVertexBuffer(0, bufferName.get(Buffer.VERTEX), 0, glf.Vertex_v2fv2f.SIZE); } gl4.glBindVertexArray(0); return true; }
Example 2
Source File: Gl_500_multi_draw_indirect_count_arb.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(1, vertexArrayName, 0); gl4.glBindVertexArray(vertexArrayName[0]); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.VERTEX]); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0); gl4.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.ELEMENT]); } gl4.glBindVertexArray(0); return true; }
Example 3
Source File: Gl_400_fbo_multisample.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl4.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl4.glBindVertexArray(0); return true; }
Example 4
Source File: Gl_500_buffer_pinned_amd.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { boolean validated = true; gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl4.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); } gl4.glBindVertexArray(0); return validated; }
Example 5
Source File: Gl_450_transform_feedback_arb.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(Program.MAX, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM)); { gl4.glVertexAttribFormat(Semantic.Attr.POSITION, 4, GL_FLOAT, false, 0); gl4.glVertexAttribBinding(Semantic.Attr.POSITION, Semantic.Buffer.STATIC); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); } gl4.glBindVertexArray(0); gl4.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK)); { gl4.glVertexAttribFormat(Semantic.Attr.POSITION, 4, GL_FLOAT, false, 0); gl4.glVertexAttribBinding(Semantic.Attr.POSITION, Semantic.Buffer.STATIC); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glVertexAttribFormat(Semantic.Attr.COLOR, 4, GL_FLOAT, false, Vec4.SIZE); gl4.glVertexAttribBinding(Semantic.Attr.COLOR, Semantic.Buffer.STATIC); gl4.glEnableVertexAttribArray(Semantic.Attr.COLOR); } gl4.glBindVertexArray(0); return true; }
Example 6
Source File: Gl_420_draw_base_instance.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL4 gl4) { boolean validated = true; gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.POSITION)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, 0, 0); gl4.glVertexAttribDivisor(Semantic.Attr.POSITION, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.COLOR)); gl4.glVertexAttribPointer(Semantic.Attr.COLOR, 4, GL_FLOAT, false, 0, 0); gl4.glVertexAttribDivisor(Semantic.Attr.COLOR, 1); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.COLOR); } gl4.glBindVertexArray(0); return validated; }
Example 7
Source File: Gl_500_primitive_shading_nv.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { ByteBuffer pointer = gl4.glMapNamedBufferRange(bufferName.get(Buffer.TRANSFORM), 0, Mat4.SIZE * 1, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapNamedBuffer(bufferName.get(Buffer.TRANSFORM)); } gl4.glViewport(0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, black); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBeginQuery(GL_PRIMITIVES_GENERATED, queryName.get(0)); { gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } gl4.glEndQuery(GL_PRIMITIVES_GENERATED); LongBuffer primitivesGeneratedBuffer = GLBuffers.newDirectLongBuffer(1); gl4.glGetQueryObjectui64v(queryName.get(0), GL_QUERY_RESULT, primitivesGeneratedBuffer); long primitivesGenerated = primitivesGeneratedBuffer.get(0); return primitivesGenerated > 0; }
Example 8
Source File: Gl_410_program_separate.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; // Compute the MVP (Model View Projection matrix) Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x * 0.5f / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); // Render with the separate programs gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, windowSize.x / 2).put(3, windowSize.y)); gl4.glProgramUniformMatrix4fv(separateProgramName[Program.VERTEX], separateUniformMvp, 1, false, mvp.toFa_(), 0); gl4.glProgramUniform1i(separateProgramName[Program.FRAGMENT], separateUniformDiffuse, 0); gl4.glBindProgramPipeline(pipelineName.get(0)); { gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); } gl4.glBindProgramPipeline(0); // Render with the unified programs gl4.glViewportIndexedfv(0, viewportBuffer.put(0, windowSize.x / 2).put(1, 0).put(2, windowSize.x / 2) .put(3, windowSize.y)); gl4.glProgramUniformMatrix4fv(unifiedProgramName, unifiedUniformMvp, 1, false, mvp.toFa_(), 0); gl4.glProgramUniform1i(unifiedProgramName, unifiedUniformDiffuse, 0); gl4.glUseProgram(unifiedProgramName); { gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); } gl4.glUseProgram(0); return true; }
Example 9
Source File: Gl_320_draw_instanced.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, 2 * 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 modelA = new Mat4(1.0f).translate(new Vec3(-1.1f, 0.0f, 0.0f)); Mat4 modelB = new Mat4(1.0f).translate(new Vec3(1.1f, 0.0f, 0.0f)); pointer.asFloatBuffer().put(projection.mul_(viewMat4()).mul(modelA).toFa_()); pointer.position(Mat4.SIZE); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(modelB).toFa_()); pointer.rewind(); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glViewport(0, 0, windowSize.x, windowSize.y); float[] depth = new float[]{1.0f}; gl4.glClearBufferfv(GL_DEPTH, 0, depth, 0); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); gl4.glUseProgram(programName); gl4.glUniformBlockBinding(programName, uniformTransform, Semantic.Uniform.TRANSFORM0); gl4.glUniformBlockBinding(programName, uniformMaterial, Semantic.Uniform.MATERIAL); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 2); return true; }
Example 10
Source File: Gl_450_query_conditional.java From jogl-samples with MIT License | 5 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, 0, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); } gl4.glBindVertexArray(0); return true; }
Example 11
Source File: Gl_430_draw_without_vertex_attrib.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); projection.mul(viewMat4()).mul(model).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0.0f).put(1, 0.0f).put(2, 0.0f).put(3, 1.0f)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bufferName.get(Buffer.VERTEX)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 0); return true; }
Example 12
Source File: Gl_430_texture_buffer.java From jogl-samples with MIT License | 5 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(1, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(0)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, 0, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); } gl4.glBindVertexArray(0); return true; }
Example 13
Source File: Gl_450_culling.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.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_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); // Bind rendering objects gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); return true; }
Example 14
Source File: Gl_410_fbo_layered.java From jogl-samples with MIT License | 5 votes |
private boolean initVertexArray(GL4 gl4) { gl4.glGenVertexArrays(Program.MAX, vertexArrayName); gl4.glBindVertexArray(vertexArrayName.get(Program.VIEWPORT)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl4.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl4.glBindVertexArray(0); gl4.glBindVertexArray(vertexArrayName.get(Program.LAYERING)); { gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl4.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl4.glBindBuffer(GL_ARRAY_BUFFER, 0); gl4.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl4.glBindVertexArray(0); return checkError(gl4, "initVertexArray"); }
Example 15
Source File: Gl_430_program_compute_variable_group_size.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glBindProgramPipeline(pipelineName.get(Program.COMPUTE)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.INPUT)); gl4.glBindImageTexture(ImageUnit.OUTPUT, textureName.get(Texture.OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8); Vec2i workGroupSize = new Vec2i(32); Vec2i ndRange = textureSize.div_(workGroupSize); gl4.glDispatchComputeGroupSizeARB( ndRange.x, ndRange.y, 1, // (8, 8, 1) workGroupSize.x, workGroupSize.y, 1); // (32, 32, 1) gl4.glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, white); gl4.glBindProgramPipeline(pipelineName.get(Program.GRAPHICS)); gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.OUTPUT)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); return true; }
Example 16
Source File: Gl_410_primitive_tessellation2.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; gl4.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl4.glProgramUniformMatrix4fv(programName[Program.VERT], uniformMvp, 1, false, mvp.toFa_(), 0); gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, windowSize.x).put(3, windowSize.y)); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glPatchParameteri(GL_PATCH_VERTICES, vertexCount); gl4.glDrawArraysInstancedBaseInstance(GL_PATCHES, 0, vertexCount, 1, 0); return true; }
Example 17
Source File: Gl_500_shader_group_nv.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { ByteBuffer pointer = gl4.glMapNamedBufferRange(bufferName.get(Buffer.TRANSFORM), 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_()); // Make sure the uniform buffer is uploaded gl4.glUnmapNamedBuffer(bufferName.get(Buffer.TRANSFORM)); } gl4.glEnable(GL_DEPTH_TEST); gl4.glDepthFunc(GL_LESS); gl4.glClearTexImage(textureName.get(Texture.COLORBUFFER), 0, GL_RGBA, GL_UNSIGNED_BYTE, clearColorBuffer); gl4.glClearTexImage(textureName.get(Texture.RENDERBUFFER), 0, GL_DEPTH_COMPONENT, GL_FLOAT, clearRenderBuffer); gl4.glClearTexImage(textureName.get(Texture.INVOCATION_COUNT), 0, GL_RED_INTEGER, GL_UNSIGNED_INT, clearInvocationCount); gl4.glViewportIndexedf(0, 0, 0, windowSize.x * FRAMEBUFFER_SCALE, windowSize.y * FRAMEBUFFER_SCALE); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.TEXTURE)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.TEXTURE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindImageTexture(0, textureName.get(Texture.INVOCATION_COUNT), 0, false, 0, GL_WRITE_ONLY, GL_R32UI); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 5, 0, 0); gl4.glDisable(GL_DEPTH_TEST); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH)); gl4.glBindImageTexture(0, textureName.get(Texture.INVOCATION_COUNT), 0, false, 0, GL_READ_ONLY, GL_R32UI); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
Example 18
Source File: Gl_420_fbo.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); //glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); projection.mul(viewMat4()).mul(model).toDbb(pointer); // Make sure the uniform buffer is uploaded gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glEnable(GL_DEPTH_TEST); gl4.glDepthFunc(GL_LESS); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1)); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1)); // Bind rendering objects gl4.glBindProgramPipeline(pipelineName.get(Pipeline.TEXTURE)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.TEXTURE)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0, 0); gl4.glDisable(GL_DEPTH_TEST); gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH)); gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH)); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
Example 19
Source File: Gl_430_query_occlusion.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.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_()); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } // Set the display viewport gl4.glViewport(0, 0, windowSize.x, windowSize.y); // Clear color buffer with black gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); // Samples count query gl4.glBeginQuery(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, queryName.get(0)); { gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } gl4.glEndQuery(GL_ANY_SAMPLES_PASSED_CONSERVATIVE); // Get the count of samples. // If the result of the query isn't here yet, we wait here... int[] samplesCount = {0}; gl4.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, samplesCount, 0); System.out.println("Samples count: " + (samplesCount[0] == GL_TRUE)); return true; }
Example 20
Source File: Gl_420_transform_feedback_instanced.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) 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); gl4.glProgramUniformMatrix4fv(programName[Pipeline.TRANSFORM], transformUniformMvp, 1, false, mvp.toFa_(), 0); gl4.glProgramUniformMatrix4fv(programName[Pipeline.FEEDBACK], feedbackUniformMvp, 1, false, mvp.toFa_(), 0); gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1.0f)); gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0.0f).put(1, 0.0f).put(2, 0.0f).put(3, 1.0f)); // First draw, capture the attributes // Disable rasterisation, vertices processing only! gl4.glEnable(GL_RASTERIZER_DISCARD); gl4.glBindProgramPipeline(pipelineName.get(Pipeline.TRANSFORM)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.TRANSFORM)); gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName.get(0)); gl4.glBeginTransformFeedback(GL_TRIANGLES); { gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); } gl4.glEndTransformFeedback(); gl4.glDisable(GL_RASTERIZER_DISCARD); // Second draw, reuse the captured attributes gl4.glBindProgramPipeline(pipelineName.get(Pipeline.FEEDBACK)); gl4.glBindVertexArray(vertexArrayName.get(Pipeline.FEEDBACK)); gl4.glDrawTransformFeedbackStreamInstanced(GL_TRIANGLE_STRIP, feedbackName.get(0), 0, 5); return true; }