Java Code Examples for com.jogamp.opengl.GL4#glDrawElementsInstancedBaseVertex()

The following examples show how to use com.jogamp.opengl.GL4#glDrawElementsInstancedBaseVertex() . 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_420_sampler_gather.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glUniform1i(uniformDiffuse, 0);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl4.glBindSampler(0, samplerName.get(0));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 2
Source File: Gl_400_fbo_shadow.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFramebuffer(GL4 gl4) {

        gl4.glEnable(GL_DEPTH_TEST);
        gl4.glDepthFunc(GL_LESS);

        gl4.glViewport(0, 0, windowSize.x, windowSize.y);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth);
        gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 1));

        gl4.glUseProgram(programName[Program.RENDER]);
        gl4.glUniform1i(uniformShadow, 0);
        gl4.glUniformBlockBinding(programName[Program.RENDER], uniformTransform[Program.RENDER],
                Semantic.Uniform.TRANSFORM0);

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.SHADOWMAP));

        gl4.glBindVertexArray(vertexArrayName.get(Program.RENDER));
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

        gl4.glDisable(GL_DEPTH_TEST);

        checkError(gl4, "renderFramebuffer");
    }
 
Example 3
Source File: Gl_400_program_64.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Mat4d projection = glm.perspective_(Math.PI * 0.25, (double) windowSize.x / windowSize.y, 0.1, 100.0);
    Mat4d model = new Mat4d(1.0);
    Mat4d view = new Mat4d(viewMat4());
    Mat4d mvp = projection.mul(view).mul(model);

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4dv(uniformMvp, 1, false, mvp.toDa_(), 0);
    gl4.glUniform4d(uniformDiffuse, 1.0, 0.5, 0.0, 1.0);

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 4
Source File: Gl_410_glsl_block.java    From jogl-samples with MIT License 5 votes vote down vote up
@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, 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.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    gl4.glUseProgram(programName);
    gl4.glUniform1i(uniformDiffuse, 0);
    gl4.glUniformBlockBinding(programName, uniformTransform, Semantic.Uniform.TRANSFORM0);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 5
Source File: Gl_410_primitive_instanced.java    From jogl-samples with MIT License 5 votes vote down vote up
@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, (float) windowSize.x / windowSize.y, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    // Set the value of uniforms
    gl4.glProgramUniformMatrix4fv(programName[Program.VERT], uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glProgramUniform4fv(programName[Program.FRAG],
            uniformDiffuse, 1, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    // Set the display viewport
    gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, windowSize.x).put(3, windowSize.y));

    // Clear color buffer with white
    gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1));
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    // Bind program
    gl4.glBindProgramPipeline(pipelineName.get(0));

    // Bind vertex array & draw 
    gl4.glBindVertexArray(vertexArrayName.get(0));
    // Must be called after glBindVertexArray
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 6
Source File: Gl_500_primitive_shading_nv.java    From jogl-samples with MIT License 5 votes vote down vote up
@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 7
Source File: Gl_450_texture_derivative.java    From jogl-samples with MIT License 5 votes vote down vote up
@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, 4.0f / 3.0f, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(2.0f));

        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(0));

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(0));

    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 8
Source File: Gl_400_fbo_multisample.java    From jogl-samples with MIT License 5 votes vote down vote up
private void renderFB(GL4 gl4, int texture2dName) {

        Mat4 perspective = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = perspective.mul(viewMat4()).mul(model);

        gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D, texture2dName);

        gl4.glBindVertexArray(vertexArrayName.get(0));
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }
 
Example 9
Source File: Gl_400_program_subroutine.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    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.glViewport(0, 0, windowSize.x, windowSize.y);

    gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1));
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RGB8));

    gl4.glActiveTexture(GL_TEXTURE1);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DXT1));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glUniform1i(uniformRGB8, 0);
    gl4.glUniform1i(uniformDXT1, 1);

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

    gl4.glUniform1f(uniformDisplacement, 1.1f);
    subroutineId.position(Subroutine.DXT1);
    gl4.glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, subroutineId);
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    gl4.glUniform1f(uniformDisplacement, -1.1f);
    subroutineId.position(Subroutine.DXT1);
    gl4.glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, subroutineId);
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    return true;
}
 
Example 10
Source File: Gl_400_primitive_smooth_shading.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    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.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 1));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

    gl4.glViewport(0, 0, (int) (windowSize.x * 0.5f), windowSize.y);
    gl4.glUseProgram(programName[Program.TESS]);
    gl4.glUniformMatrix4fv(uniformMvp[Program.TESS], 1, false, mvp.toFa_(), 0);

    gl4.glPatchParameteri(GL_PATCH_VERTICES, vertexCount);
    gl4.glDrawArraysInstanced(GL_PATCHES, 0, vertexCount, 1);

    gl4.glViewport((int) (windowSize.x * 0.5f), 0, (int) (windowSize.x * 0.5f), windowSize.y);
    gl4.glUseProgram(programName[Program.SMOOTH]);
    gl4.glUniformMatrix4fv(uniformMvp[Program.SMOOTH], 1, false, mvp.toFa_(), 0);

    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

    return true;
}
 
Example 11
Source File: Gl_410_program_separate.java    From jogl-samples with MIT License 5 votes vote down vote up
@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 12
Source File: Gl_400_sampler_fetch.java    From jogl-samples with MIT License 5 votes vote down vote up
@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);
    }

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    return true;
}
 
Example 13
Source File: Gl_400_sampler_array_nv.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glUniform1i(uniformDiffuseRGB, 0);
    gl4.glUniform1i(uniformDiffuseBGR, 1);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RGB));
    gl4.glBindSampler(0, samplerName.get(0));

    gl4.glActiveTexture(GL_TEXTURE1);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.BGR));
    gl4.glBindSampler(1, samplerName.get(0));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    return true;
}
 
Example 14
Source File: Gl_410_program_binary.java    From jogl-samples with MIT License 5 votes vote down vote up
@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[Program.VERT], uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glProgramUniform1i(programName[Program.FRAG], uniformDiffuse, 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.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    //!\ Need to be called after glBindVertexArray
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    return true;
}
 
Example 15
Source File: Gl_400_fbo_layered.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Mat4 projection = glm.ortho_(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f);
    Mat4 view = new Mat4(1.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(view).mul(model);

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    // Pass 1
    {
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glViewport(0, 0, windowSize.x / FRAMEBUFFER_SIZE, windowSize.y / FRAMEBUFFER_SIZE);

        gl4.glUseProgram(programName[Program.LAYERING]);
        gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

        gl4.glBindVertexArray(vertexArrayName.get(Program.LAYERING));
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }

    // Pass 2
    {
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl4.glUseProgram(programName[Program.IMAGE_2D]);
        gl4.glUniform1i(uniformDiffuse, 0);

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureColorbufferName.get(0));
        gl4.glBindSampler(0, samplerName.get(0));

        gl4.glBindVertexArray(vertexArrayName.get(Program.IMAGE_2D));

        for (int i = 0; i < 4; ++i) {
            gl4.glUniform1i(uniformLayer, i);
            gl4.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w);
            gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
        }
    }

    return true;
}
 
Example 16
Source File: Gl_410_fbo_layered.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Mat4 projection = glm.ortho_(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f);
    Mat4 view = new Mat4(1.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(view).mul(model);

    gl4.glProgramUniformMatrix4fv(programName[Program.LAYERING], uniformMvp[Program.LAYERING], 1, false,
            mvp.toFa_(), 0);
    gl4.glProgramUniformMatrix4fv(programName[Program.VIEWPORT], uniformMvp[Program.VIEWPORT], 1, false,
            mvp.toFa_(), 0);
    gl4.glProgramUniform1i(programName[Program.VIEWPORT], uniformDiffuse, 0);

    // Pass 1
    {
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, FRAMEBUFFER_SIZE.x).put(3, FRAMEBUFFER_SIZE.y));

        gl4.glUseProgram(programName[Program.LAYERING]);

        gl4.glBindVertexArray(vertexArrayName.get(Program.LAYERING));
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }

    // Pass 2
    {
        int border = 2;

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

        gl4.glViewportIndexedfv(0, viewportBuffer.put(0, border).put(1, border).put(2, windowSize.x * 0.5f - 2.0f * border)
                .put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(1, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, border)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(2, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, windowSize.y * 0.5f + 1)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(3, viewportBuffer.put(0, border).put(1, windowSize.y * 0.5f + border)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));

        gl4.glUseProgram(programName[Program.VIEWPORT]);

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
        gl4.glBindSampler(0, samplerName.get(0));

        gl4.glBindVertexArray(vertexArrayName.get(Program.VIEWPORT));
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }

    return true;
}
 
Example 17
Source File: Gl_400_texture_derivative.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    Vec2i framebufferSize = new Vec2i(windowSize.x / FRAMEBUFFER_SIZE, windowSize.y / FRAMEBUFFER_SIZE);

    // Update of the uniform buffer
    {
        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, 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.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glEnable(GL_DEPTH_TEST);
    gl4.glDepthFunc(GL_LESS);

    gl4.glViewport(0, 0, framebufferSize.x, framebufferSize.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, 0).put(1, 0).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName[Program.TEXTURE]);
    gl4.glUniform1i(uniformDiffuse[Program.TEXTURE], 0);
    gl4.glUniformBlockBinding(programName[Program.TEXTURE], uniformTransform,
            Semantic.Uniform.TRANSFORM0);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
    gl4.glBindVertexArray(vertexArrayName.get(Program.TEXTURE));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glEnable(GL_SCISSOR_TEST);
    {
        gl4.glScissor(0, 0, framebufferSize.x / 2, framebufferSize.y);
        gl4.glUniform1i(uniformUseGrad, 1);
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);

        gl4.glScissor(framebufferSize.x / 2, 0, framebufferSize.x / 2, framebufferSize.y);
        gl4.glUniform1i(uniformUseGrad, 0);
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);
    }
    gl4.glDisable(GL_SCISSOR_TEST);

    gl4.glDisable(GL_DEPTH_TEST);
    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glUseProgram(programName[Program.SPLASH]);
    gl4.glUniform1i(uniformDiffuse[Program.SPLASH], 0);
    gl4.glUniform1f(uniformFramebufferSize, FRAMEBUFFER_SIZE);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindVertexArray(vertexArrayName.get(Program.SPLASH));
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));

    gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);

    return true;
}
 
Example 18
Source File: Gl_420_transform_feedback_instanced.java    From jogl-samples with MIT License 4 votes vote down vote up
@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;
}
 
Example 19
Source File: Gl_430_texture_buffer.java    From jogl-samples with MIT License 4 votes vote down vote up
@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.identity()).toFa_());

        // Make sure the uniform buffer is uploaded
        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);

    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.glUseProgram(programName);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.DISPLACEMENT));

    gl4.glActiveTexture(GL_TEXTURE1);
    gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.DIFFUSE));

    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 5, 0);

    return true;
}
 
Example 20
Source File: Gl_430_program_subroutine.java    From jogl-samples with MIT License 4 votes vote down vote up
@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, windowSize.x * 0.5f / 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);
    }

    float[] depth = {1.0f};
    gl4.glClearBufferfv(GL_DEPTH, 0, depth, 0);
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    gl4.glActiveTexture(GL_TEXTURE0 + Sampler.RGB8);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RGB8));

    gl4.glActiveTexture(GL_TEXTURE0 + Sampler.DXT1);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DXT1));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(0));

    gl4.glUseProgram(programName);
    IntBuffer index = GLBuffers.newDirectIntBuffer(new int[]{Sampling.RGB8, Sampling.DXT1});

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x / 2.0f, windowSize.y);
    gl4.glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, index);
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    gl4.glViewportIndexedf(0, windowSize.x / 2.0f, 0, windowSize.x / 2.0f, windowSize.y);
    gl4.glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, index);
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);

    return true;
}