Java Code Examples for com.jogamp.opengl.GL4#glMultiDrawElementsIndirect()
The following examples show how to use
com.jogamp.opengl.GL4#glMultiDrawElementsIndirect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Gl_500_glsl_vote_arb.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; { Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, (float) windowSize.x, windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); uniformPointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); } gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y); gl4.glClearBufferfv(GL_COLOR, 0, black); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bufferName.get(Buffer.VERTEX)); gl4.glBindTextures(Semantic.Sampler.DIFFUSE, 1, textureName); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, 1, DrawElementsIndirectCommand.SIZE); return true; }
Example 2
Source File: Gl_430_multi_draw_indirect.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; float[] depth = {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.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE * 3, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x / 3.0f / windowSize.y, 0.1f, 100.0f); Mat4 view = viewMat4(); pointer.position(Mat4.SIZE * 0); pointer.asFloatBuffer().put(projection.mul_(view).translate(new Vec3(0.0f, 0.0f, +0.5f)).toFa_()); pointer.position(Mat4.SIZE * 1); pointer.asFloatBuffer().put(projection.mul_(view).translate(new Vec3(0.0f, 0.0f, +0.0f)).toFa_()); pointer.position(Mat4.SIZE * 2); pointer.asFloatBuffer().put(projection.mul_(view).translate(new Vec3(0.0f, 0.0f, -0.5f)).toFa_()); pointer.rewind(); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.A)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.B)); gl4.glActiveTexture(GL_TEXTURE2); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.C)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.INDIRECTION, bufferName.get(Buffer.VERTEX_INDIRECTION)); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); validate(gl4); // LongBuffer buffer = GLBuffers.newDirectLongBuffer(1); for (int i = 0; i < indirectBufferCount; ++i) { gl4.glViewportIndexedfv(0, viewport[i].toFloatArray(), 0); // buffer.put(5 * Integer.BYTES * drawOffset[i]).rewind(); // buffer.asIntBuffer().put(0).rewind(); // buffer.rewind(); gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, drawCount[i], DrawElementsIndirectCommand.SIZE); } return true; }
Example 3
Source File: Gl_500_multi_draw_indirect_arb.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; float[] depth = {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.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE * indirectBufferCount, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x / 3.0f / windowSize.y, 0.1f, 100.0f); Mat4 view = viewMat4(); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul_(view).translate(0.0f, 0.0f, 0.5f).toFa_()); pointer.position(Mat4.SIZE * 1); pointer.asFloatBuffer().put(projection.mul_(view).translate(0.0f, 0.0f, 0.0f).toFa_()); pointer.position(Mat4.SIZE * 2); pointer.asFloatBuffer().put(projection.mul(view).translate(0.0f, 0.0f, -0.5f).toFa_()); pointer.rewind(); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.A)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.B)); gl4.glActiveTexture(GL_TEXTURE2); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.C)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.INDIRECTION, bufferName.get(Buffer.VERTEX_INDIRECTION)); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); validate(gl4); for (int i = 0; i < indirectBufferCount; ++i) { gl4.glViewportIndexedfv(0, viewport[i].toFA_(), 0); gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, drawCount.get(i), DrawElementsIndirectCommand.SIZE); } return true; }
Example 4
Source File: Gl_440_multi_draw_indirect_id_arb.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL4 gl4 = (GL4) gl; float[] depth = {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); { int padding = Math.max(Mat4.SIZE, uniformArrayStride.get(0)); gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, padding * 3, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x / 3.0f / windowSize.y, 0.1f, 100.0f); Mat4 view = viewMat4(); Mat4 model = new Mat4(1.0f); pointer.position(padding * 0); pointer.asFloatBuffer().put(projection.mul(view).translate(new Mat4(1.0f), new Vec3(0.0f, 0.0f, 0.5f)).toFa_()); // now projection contains projection * view pointer.position(padding * 1); pointer.asFloatBuffer().put(projection.translate(new Mat4(1.0f), new Vec3(0.0f, 0.0f, 0.0f)).toFa_()); pointer.position(padding * 2); pointer.asFloatBuffer().put(projection.translate(new Mat4(1.0f), new Vec3(0.0f, 0.0f, -0.5f)).toFa_()); gl4.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl4.glActiveTexture(GL_TEXTURE0); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.A)); gl4.glActiveTexture(GL_TEXTURE1); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.B)); gl4.glActiveTexture(GL_TEXTURE2); gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.C)); gl4.glBindProgramPipeline(pipelineName.get(0)); gl4.glBindVertexArray(vertexArrayName.get(0)); gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantic.Storage.VERTEX, bufferName.get(Buffer.VERTEX)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.INDIRECTION, bufferName.get(Buffer.VERTEX_INDIRECTION)); gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT)); validate(gl4); for (int i = 0; i < indirectBufferCount; ++i) { gl4.glViewportIndexedfv(0, viewport[i].toFA_(), 0); gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, drawCount[i], DrawElementsIndirectCommand.SIZE); } return true; }
Example 5
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderStaticMeshes(int contextID, Renderer renderer, Mat4d modelViewMat, Camera cam) { if (data.getStaticMeshInstances().size() == 0) { return; } GL2GL3 gl = renderer.getGL(); GL4 gl4 = renderer.getGL4(); if (!_meshVAOs.containsKey(contextID)) { setupVAOForStaticMeshes(contextID, renderer); } int vao = _meshVAOs.get(contextID); gl.glBindVertexArray(vao); gl.glDisable(GL2GL3.GL_CULL_FACE); // Actually draw it gl4.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, meshIndBuffer); // Server side indirect buffer gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, meshIndirectBuffer); gl4.glMultiDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, null, _batches.size(), 0); // Client side indirect buffer // gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, 0); // gl4.glMultiDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, indirectBufferData, _indirectData.size(), 0); // Individual indirect calls // gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, 0); // for (int i = 0; i < _batches.size(); ++i) { // indirectBufferData.position(i*5); // gl4.glDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, indirectBufferData); // } // for (IndirectData id: _indirectData) { // gl4.glDrawElementsInstancedBaseVertexBaseInstance( // GL2GL3.GL_TRIANGLES, // id.count, // GL4.GL_UNSIGNED_INT, // id.firstIndex*4, // id.numInstances, // id.baseVertex, // id.baseInstance // ); // } gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }