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

The following examples show how to use com.jogamp.opengl.GL4#glUniformBlockBinding() . 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_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 2
Source File: Gl_320_draw_instanced.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, 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 3
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 4
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 5
Source File: Gl_400_fbo_shadow.java    From jogl-samples with MIT License 4 votes vote down vote up
private void renderShadow(GL4 gl4) {

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

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

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.SHADOW));
        gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1));

        // Bind rendering objects
        gl4.glUseProgram(programName[Program.DEPTH]);
        gl4.glUniformBlockBinding(programName[Program.DEPTH], uniformTransform[Program.DEPTH],
                Semantic.Uniform.TRANSFORM0);

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

        gl4.glDisable(GL_DEPTH_TEST);

        checkError(gl4, "renderShadow");
    }
 
Example 6
Source File: Gl_400_sampler_fetch.java    From jogl-samples with MIT License 3 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        // Create program
        if (validated) {

            ShaderProgram shaderProgram = new ShaderProgram();

            ShaderCode vertexShaderCode = ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "vert", null, true);
            ShaderCode fragmentShaderCode = ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "frag", null, true);

            shaderProgram.init(gl4);

            shaderProgram.add(vertexShaderCode);
            shaderProgram.add(fragmentShaderCode);

            programName = shaderProgram.program();

            shaderProgram.link(gl4, System.out);

        }

        // Get variables locations
        if (validated) {

            gl4.glUniformBlockBinding(programName, gl4.glGetUniformBlockIndex(programName, "Transform"),
                    Semantic.Uniform.TRANSFORM0);

            gl4.glUseProgram(programName);
            gl4.glUniform1i(gl4.glGetUniformLocation(programName, "diffuse"), 0);
            gl4.glUseProgram(0);
        }

        return validated & checkError(gl4, "initProgram");
    }
 
Example 7
Source File: Gl_400_buffer_uniform_array.java    From jogl-samples with MIT License 3 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        if (validated) {

            ShaderProgram shaderProgram = new ShaderProgram();

            ShaderCode vertShaderCode = ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT, null,
                    SHADERS_SOURCE, "vert", null, true);
            ShaderCode fragShaderCode = ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT, null,
                    SHADERS_SOURCE, "frag", null, true);

            shaderProgram.init(gl4);

            shaderProgram.add(vertShaderCode);
            shaderProgram.add(fragShaderCode);

            programName = shaderProgram.program();

            shaderProgram.link(gl4, System.out);
        }

        if (validated) {

            int uniformMaterial = gl4.glGetUniformBlockIndex(programName, "Material");
            int uniformTransform0 = gl4.glGetUniformBlockIndex(programName, "Transform[0]");
            int uniformTransform1 = gl4.glGetUniformBlockIndex(programName, "Transform[1]");

            gl4.glUniformBlockBinding(programName, uniformMaterial, Semantic.Uniform.MATERIAL);
            gl4.glUniformBlockBinding(programName, uniformTransform0, Semantic.Uniform.TRANSFORM0);
            gl4.glUniformBlockBinding(programName, uniformTransform1, Semantic.Uniform.TRANSFORM1);
        }

        return validated & checkError(gl4, "initProgram");
    }
 
Example 8
Source File: Gl_400_texture_cube.java    From jogl-samples with MIT License 3 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        // Create program
        if (validated) {

            ShaderProgram shaderProgram = new ShaderProgram();

            ShaderCode vertexShaderCode = ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "vert", null, true);
            ShaderCode fragmentShaderCode = ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "frag", null, true);

            shaderProgram.init(gl4);

            shaderProgram.add(vertexShaderCode);
            shaderProgram.add(fragmentShaderCode);

            programName = shaderProgram.program();

            shaderProgram.link(gl4, System.out);

        }

        // Get variables locations
        if (validated) {

            gl4.glUseProgram(programName);
            gl4.glUniform1i(gl4.glGetUniformLocation(programName, "diffuse"), 0);
            gl4.glUseProgram(0);

            gl4.glUniformBlockBinding(programName, gl4.glGetUniformBlockIndex(programName, "Transform"),
                    Semantic.Uniform.TRANSFORM0);
        }

        return validated & checkError(gl4, "initProgram");
    }
 
Example 9
Source File: Gl_410_buffer_uniform_array.java    From jogl-samples with MIT License 3 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        // Create program
        if (validated) {

            ShaderProgram shaderProgram = new ShaderProgram();

            ShaderCode vertexShaderCode = ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "vert", null, true);
            ShaderCode fragmentShaderCode = ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "frag", null, true);

            shaderProgram.init(gl4);

            shaderProgram.add(vertexShaderCode);
            shaderProgram.add(fragmentShaderCode);

            programName = shaderProgram.program();

            shaderProgram.link(gl4, System.out);

        }

        // Get variables locations
        if (validated) {

            int uniformMaterial = gl4.glGetUniformBlockIndex(programName, "Material");
            int uniformTransform0 = gl4.glGetUniformBlockIndex(programName, "Transform[0]");
            int uniformTransform1 = gl4.glGetUniformBlockIndex(programName, "Transform[1]");

            gl4.glUniformBlockBinding(programName, uniformMaterial, Semantic.Uniform.MATERIAL);
            gl4.glUniformBlockBinding(programName, uniformTransform0, Semantic.Uniform.TRANSFORM0);
            gl4.glUniformBlockBinding(programName, uniformTransform1, Semantic.Uniform.TRANSFORM1);
        }

        return validated & checkError(gl4, "initProgram");
    }
 
Example 10
Source File: Gl_400_sampler_array.java    From jogl-samples with MIT License 2 votes vote down vote up
private boolean initProgram(GL4 gl4) {

        boolean validated = true;

        // Create program
        if (validated) {

            ShaderProgram shaderProgram = new ShaderProgram();

            ShaderCode vertexShaderCode = ShaderCode.create(gl4, GL_VERTEX_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "vert", null, true);
            ShaderCode fragmentShaderCode = ShaderCode.create(gl4, GL_FRAGMENT_SHADER, this.getClass(), SHADERS_ROOT,
                    null, SHADERS_SOURCE, "frag", null, true);

            shaderProgram.init(gl4);

            shaderProgram.add(vertexShaderCode);
            shaderProgram.add(fragmentShaderCode);

            programName = shaderProgram.program();

            shaderProgram.link(gl4, System.out);

        }

        // Get variables locations
        if (validated) {

            gl4.glUniformBlockBinding(programName, gl4.glGetUniformBlockIndex(programName, "Transform"),
                    Semantic.Uniform.TRANSFORM0);

            uniformDiffuseIndex = gl4.glGetUniformLocation(programName, "diffuseIndex");

            gl4.glUseProgram(programName);
            gl4.glUniform1i(gl4.glGetUniformLocation(programName, "diffuse[0]"), 0);
            gl4.glUniform1i(gl4.glGetUniformLocation(programName, "diffuse[1]"), 1);
            gl4.glUseProgram(0);
        }

        return validated & checkError(gl4, "initProgram");
    }