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

The following examples show how to use com.jogamp.opengl.GL4#glBindProgramPipeline() . 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_fbo_multisample_explicit.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFBO(GL4 gl4, int framebuffer) {

        gl4.glEnable(GL_DEPTH_TEST);

        gl4.glBindProgramPipeline(pipelineName.get(Program.THROUGH));
        gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), 0,
                uniformBlockSize);

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

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
        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);

        textureName.position(Texture.DIFFUSE);
        gl4.glBindTextures(0, 1, textureName);
        textureName.rewind();
        gl4.glBindVertexArray(vertexArrayName.get(0));

        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);

        gl4.glDisable(GL_DEPTH_TEST);
    }
 
Example 2
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 3
Source File: Gl_440_sampler_wrap.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    {
        float aspect = (windowSize.x * 0.33f) / (windowSize.y * 0.50f);
        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, aspect, 0.1f, 100.0f);
        Mat4 mvp = projection.mul(viewMat4()).mul(new Mat4(1.0f));

        uniformPointer.asFloatBuffer().put(mvp.toFa_());
    }

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

    gl4.glBindProgramPipeline(pipelineName.get(0));
    bufferName.position(Buffer.TRANSFORM);
    gl4.glBindBuffersBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, 1, bufferName);
    gl4.glBindTextures(Semantic.Sampler.DIFFUSE, 1, textureName);
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName.get(Buffer.VERTEX), 0, Vertex_v2fv2f.SIZE);

    for (int index = 0; index < Viewport.MAX; ++index) {

        gl4.glViewportIndexedf(0,
                viewport[index].x,
                viewport[index].y,
                viewport[index].z,
                viewport[index].w);

        samplerName.position(index);
        gl4.glBindSamplers(0, 1, samplerName);
        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

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

    GL4 gl4 = (GL4) gl;

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

    // Renderer to image
    {
        gl4.glDrawBuffer(GL_NONE);

        gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SAVE));
        gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8);
        gl4.glBindVertexArray(vertexArrayName.get(0));
        gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
    }

    // Read from image
    {
        gl4.glDrawBuffer(GL_BACK);

        gl4.glBindProgramPipeline(pipelineName.get(Pipeline.READ));
        gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8);
        gl4.glBindVertexArray(vertexArrayName.get(0));
        gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
    }

    return true;
}
 
Example 5
Source File: Gl_430_image_sampling.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 | GL_MAP_UNSYNCHRONIZED_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 1000.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);

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindImageTexture(0, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8);
    gl4.glBindImageTexture(1, textureName.get(0), 1, false, 0, GL_READ_ONLY, GL_RGBA8);
    gl4.glBindImageTexture(2, textureName.get(0), 2, false, 0, GL_READ_ONLY, GL_RGBA8);

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 3, 0, 0);

    return true;
}
 
Example 6
Source File: Gl_420_clipping.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);

        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, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    // 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 7
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 8
Source File: Gl_500_texture_bindless_arb.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
    protected boolean begin(GL gl) {

        GL4 gl4 = (GL4) gl;

        boolean validated = gl4.isExtensionAvailable("GL_ARB_bindless_texture");

//		this->sync(test::ASYNC);
        if (validated) {
            validated = initProgram(gl4);
        }
        if (validated) {
            validated = initTexture(gl4);
        }
        if (validated) {
            validated = initBuffer(gl4);
        }
        if (validated) {
            validated = initVertexArray(gl4);
        }

        if (validated) {

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

            gl4.glBindProgramPipeline(pipelineName.get(0));
            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.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantic.Storage.VERTEX, bufferName.get(Buffer.VERTEX));

            gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT));
            gl4.glBindVertexArray(vertexArrayName.get(0));
        }

        return validated;
    }
 
Example 9
Source File: Gl_430_program_compute.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.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.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantics.INPUT, bufferName.get(Buffer.INPUT));
    gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantics.OUTPUT, bufferName.get(Buffer.OUTPUT));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glDispatchCompute(vertexCount, 1, 1);

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

    gl4.glBindProgramPipeline(pipelineName.get(Program.GRAPHICS));
    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.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantics.INPUT, bufferName.get(Buffer.OUTPUT));

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

    return true;
}
 
Example 10
Source File: Gl_420_draw_base_instance.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 | GL_MAP_UNSYNCHRONIZED_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);

        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_DEPTH, 0, clearDepth.put(0, 1));
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    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.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT,
            1 * Integer.BYTES, // indices offset
            5, // instance count
            2, // base vertex
            5); // base instance

    return true;
}
 
Example 11
Source File: Gl_500_buffer_pinned_amd.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 | GL_MAP_UNSYNCHRONIZED_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.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor);

    // Bind rendering objects
    gl4.glBindProgramPipeline(pipelineName.get(0));
    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.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

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

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

    return true;
}
 
Example 12
Source File: Gl_500_shader_group_nv.java    From jogl-samples with MIT License 4 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, 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 13
Source File: Gl_410_primitive_tessellation5.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        gl4.glGenProgramPipelines(1, pipelineName);
        gl4.glBindProgramPipeline(pipelineName.get(0));
        gl4.glBindProgramPipeline(0);

        // Create program
        if (validated) {

            ShaderProgram[] shaderPrograms = new ShaderProgram[Program.MAX];

            ShaderCode[] shaderCodes = new ShaderCode[]{
                ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE,
                "vert", null, true),
                ShaderCode.create(gl4, GL_TESS_CONTROL_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE,
                "cont", null, true),
                ShaderCode.create(gl4, GL_TESS_EVALUATION_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE,
                "eval", null, true),
                ShaderCode.create(gl4, GL_GEOMETRY_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE,
                "geom", null, true),
                ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT, null, SHADERS_SOURCE,
                "frag", null, true)};

            for (int i = 0; i < Program.MAX; i++) {

                shaderPrograms[i] = new ShaderProgram();
                shaderPrograms[i].init(gl4);
                shaderPrograms[i].add(shaderCodes[i]);
                programName[i] = shaderPrograms[i].program();
                gl4.glProgramParameteri(programName[i], GL_PROGRAM_SEPARABLE, GL_TRUE);
                shaderPrograms[i].link(gl4, System.out);
            }
        }

        if (validated) {

            gl4.glUseProgramStages(pipelineName.get(0), GL_VERTEX_SHADER_BIT, programName[Program.VERT]);
            gl4.glUseProgramStages(pipelineName.get(0), GL_TESS_CONTROL_SHADER_BIT, programName[Program.CONT]);
            gl4.glUseProgramStages(pipelineName.get(0), GL_TESS_EVALUATION_SHADER_BIT, programName[Program.EVAL]);
            gl4.glUseProgramStages(pipelineName.get(0), GL_GEOMETRY_SHADER_BIT, programName[Program.GEOM]);
            gl4.glUseProgramStages(pipelineName.get(0), GL_FRAGMENT_SHADER_BIT, programName[Program.FRAG]);

        }

        // Get variables locations
        if (validated) {

            uniformMvp = gl4.glGetUniformLocation(programName[Program.VERT], "mvp");
        }

        return validated & checkError(gl4, "initProgram");
    }
 
Example 14
Source File: Gl_500_multi_draw_indirect_arb.java    From jogl-samples with MIT License 4 votes vote down vote up
@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 15
Source File: Gl_410_program_64.java    From jogl-samples with MIT License 4 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        try {

            if (validated) {

                String[] vertexSourceContent = new String[]{new Scanner(new File(SHADERS_ROOT + "/" + SHADERS_SOURCE
                    + ".vert")).useDelimiter("\\A").next()};
                programName[Program.VERT] = gl4.glCreateShaderProgramv(GL_VERTEX_SHADER, 1, vertexSourceContent);
            }

            if (validated) {

                String[] fragmentSourceContent = new String[]{new Scanner(new File(SHADERS_ROOT + "/" + SHADERS_SOURCE
                    + ".frag")).useDelimiter("\\A").next()};
                programName[Program.FRAG] = gl4.glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, fragmentSourceContent);
            }

            if (validated) {

                validated = validated && framework.Compiler.checkProgram(gl4, programName[Program.VERT]);
                validated = validated && framework.Compiler.checkProgram(gl4, programName[Program.FRAG]);
            }

            if (validated) {

                uniformMvp = gl4.glGetUniformLocation(programName[Program.VERT], "mvp");
                uniformDiffuse = gl4.glGetUniformLocation(programName[Program.FRAG], "diffuse");
            }

            if (validated) {

                gl4.glGenProgramPipelines(1, pipelineName);
                gl4.glBindProgramPipeline(pipelineName.get(0));
                gl4.glUseProgramStages(pipelineName.get(0), GL_VERTEX_SHADER_BIT, programName[Program.VERT]);
                gl4.glUseProgramStages(pipelineName.get(0), GL_FRAGMENT_SHADER_BIT, programName[Program.FRAG]);
            }

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Gl_410_program_64.class.getName()).log(Level.SEVERE, null, ex);
        }

        return validated && checkError(gl4, "initProgram");
    }
 
Example 16
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 17
Source File: Gl_450_transform_feedback_arb.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

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

        uniformPointer.asFloatBuffer().put(mvp.toFa_());
    }

    // Set the display viewport
    gl4.glViewportIndexedf(0, 0.0f, 0.0f, windowSize.x, windowSize.y);

    // Clear color buffer
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0);

    // First draw, capture the attributes
    // Disable rasterisation, vertices processing only!
    gl4.glEnable(GL_RASTERIZER_DISCARD);

    gl4.glBindProgramPipeline(pipelineName.get(Program.TRANSFORM));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM));
    gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName.get(Buffer.VERTEX), 0, Vec4.SIZE);

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName.get(0));

    gl4.glBeginQueryIndexed(GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB, 0, queryName.get(0));
    gl4.glBeginTransformFeedback(GL_TRIANGLES);
    {
        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl4.glEndTransformFeedback();
    gl4.glEndQueryIndexed(GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB, 0);

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    gl4.glDisable(GL_RASTERIZER_DISCARD);

    IntBuffer streamOverflow = GLBuffers.newDirectIntBuffer(1);
    gl4.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, streamOverflow);

    if (streamOverflow.get(0) == 0) {

        // Second draw, reuse the captured attributes
        gl4.glBindProgramPipeline(pipelineName.get(Program.FEEDBACK));
        gl4.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK));
        gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName.get(Buffer.FEEDBACK), 0, glf.Vertex_v4fc4f.SIZE);

        gl4.glDrawTransformFeedback(GL_TRIANGLES, feedbackName.get(0));
    }
    BufferUtils.destroyDirectBuffer(streamOverflow);
    
    return true;
}
 
Example 18
Source File: Gl_420_texture_compressed.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 | GL_MAP_UNSYNCHRONIZED_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 1000.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);
    }

    // Clear the color buffer
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f));

    // Bind rendering objects
    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindSampler(0, samplerName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));

    // Draw each texture in different viewports
    for (int index = 0; index < Texture.MAX; ++index) {
        gl4.glViewportIndexedfv(0, viewport[index].toDfb(viewportBuffer));

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

        gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
    }

    return true;
}
 
Example 19
Source File: Gl_440_fbo_without_attachment.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[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_());

        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    // Render
    FloatBuffer clearBuffer = GLBuffers.newDirectFloatBuffer(new float[]{1.0f, 0.5f, 0.0f, 1.0f});
    gl4.glClearTexImage(textureName[Texture.COLORBUFFER], 0, GL_RGBA, GL_FLOAT, clearBuffer);
    BufferUtils.destroyDirectBuffer(clearBuffer);

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x * supersampling, windowSize.y * supersampling);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName[0]);
    gl4.glBindSampler(0, samplerName[Pipeline.RENDER]);
    gl4.glBindVertexArray(vertexArrayName[Pipeline.RENDER]);

    gl4.glBindProgramPipeline(pipelineName[Pipeline.RENDER]);
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.DIFFUSE]);
    gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName[Texture.COLORBUFFER], 0, false, 0, GL_WRITE_ONLY,
            GL_RGBA8);
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName[Buffer.TRANSFORM]);
    gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantic.Storage.VERTEX, bufferName[Buffer.VERTEX]);

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

    // Splash
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glBindSampler(0, samplerName[Pipeline.SPLASH]);
    gl4.glBindVertexArray(vertexArrayName[Pipeline.SPLASH]);

    gl4.glBindProgramPipeline(pipelineName[Pipeline.SPLASH]);
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName[Texture.COLORBUFFER]);

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

    return true;
}
 
Example 20
Source File: Gl_430_query_occlusion.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, (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;
}