Java Code Examples for com.jogamp.opengl.GL3#glDepthFunc()

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

    GL3 gl3 = (GL3) gl;
    //caps Caps(caps::CORE);

    boolean validated = true;

    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }

    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);
    gl3.glEnable(GL_PROGRAM_POINT_SIZE);
    //glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
    gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);

    return validated && checkError(gl3, "begin");
}
 
Example 2
Source File: Gl_320_primitive_point.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    GL3 gl3 = (GL3) gl;

    boolean validated = true;

    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }

    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);
    gl3.glEnable(GL_PROGRAM_POINT_SIZE);
    //glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
    gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);

    return validated && checkError(gl3, "begin");
}
 
Example 3
Source File: Gl_320_primitive_point_clip.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    GL3 gl3 = (GL3) gl;
    //caps Caps(caps::CORE);

    boolean validated = true;

    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }

    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);
    gl3.glEnable(GL_PROGRAM_POINT_SIZE);
    //glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
    gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);

    return validated && checkError(gl3, "begin");
}
 
Example 4
Source File: Gl_320_draw_base_vertex.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    boolean validated = true;

    GL3 gl3 = (GL3) gl;

    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }
    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);

    return validated && checkError(gl, "begin");
}
 
Example 5
Source File: Gl_320_fbo_shadow.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFramebuffer(GL3 gl3) {

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

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth);
        gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

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

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));

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

        gl3.glDisable(GL_DEPTH_TEST);

        checkError(gl3, "renderFramebuffer");
    }
 
Example 6
Source File: GLRenderer.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final GLAutoDrawable drawable) {

    initialised = true;
    renderables.sort(Comparator.naturalOrder());

    if (debugGl) {
        drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
    }
    final GL3 gl = drawable.getGL().getGL3();

    //Look for Graphics cards that work with GL3, but not 3.3.
    //Graphics cards that don't work with GL3 will raise an exception.
    final String thisversion = gl.glGetString(GL.GL_VERSION);

    if (!VersionUtilities.doesVersionMeetMinimum(thisversion, GLInfo.MINIMUM_OPEN_GL_VERSION)) {
        GLInfo.respondToIncompatibleHardwareOrGL(drawable);
    }

    if (printGlCapabilities) {
        GLInfo.printGLCapabilities(gl);
    }

    gl.glEnable(GL3.GL_DEPTH_TEST);
    gl.glDepthFunc(GL3.GL_LEQUAL);
    gl.glEnable(GL3.GL_BLEND);
    gl.glBlendFunc(GL3.GL_SRC_ALPHA, GL3.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL3.GL_LINE_SMOOTH);
    gl.glHint(GL3.GL_LINE_SMOOTH_HINT, GL3.GL_NICEST);

    renderables.forEach(renderable -> {
        renderable.init(drawable);
    });

    // Reset to the default framebuffer.
    gl.glBindFramebuffer(GL3.GL_DRAW_FRAMEBUFFER, 0);
}
 
Example 7
Source File: Gl_320_primitive_sprite.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    GL3 gl3 = (GL3) gl;

    boolean validated = true;

    if (validated) {
        validated = initTexture(gl3);
    }
    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }

    gl3.glEnable(GL_DEPTH_TEST);
    gl3.glDepthFunc(GL_LESS);
    gl3.glEnable(GL_PROGRAM_POINT_SIZE);
    //glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
    gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);

    return validated;
}
 
Example 8
Source File: ConnectionLabelBatcher.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) {

    if (attributeLabelBatch.isDrawable() || summaryLabelBatch.isDrawable()) {
        gl.glUseProgram(shader);

        // Let the glyph controller bind the glyph info and glyph image textures
        SharedDrawable.updateGlyphTextureController(gl);
        SharedDrawable.getGlyphTextureController().bind(gl, shaderGlyphInfoTexture, TextureUnits.GLYPH_INFO, shaderGlyphImageTexture, TextureUnits.GLYPHS);

        // This is kind of weird - fix this to actually mean something?
        final int further_f = 0;
        final int further_u = 1;
        gl.glPolygonOffset(further_f, further_u);
        gl.glDepthFunc(GL.GL_LEQUAL);

        // Uniform variables
        gl.glUniformMatrix4fv(shaderMVMatrix, 1, false, mvMatrix.a, 0);
        gl.glUniformMatrix4fv(shaderPMatrix, 1, false, pMatrix.a, 0);
        gl.glUniform1f(shaderLocWidth, SharedDrawable.getGlyphManager().getWidthScalingFactor());
        gl.glUniform1f(shaderLocHeight, SharedDrawable.getGlyphManager().getHeightScalingFactor());
        gl.glUniform1f(shaderVisibilityLow, camera.getVisibilityLow());
        gl.glUniform1f(shaderVisibilityHigh, camera.getVisibilityHigh());
        gl.glUniform1f(shaderMorphMix, camera.getMix());
        gl.glUniform1i(shaderXyzTexture, TextureUnits.VERTICES);
        gl.glUniform1i(shaderBackgroundGlyphIndex, SharedDrawable.getLabelBackgroundGlyphPosition());
        gl.glUniform4fv(shaderBackgroundColor, 1, backgroundColor, 0);
        gl.glUniform4fv(shaderHighlightColor, 1, highlightColor, 0);

        if (attributeLabelBatch.isDrawable()) {
            gl.glUniformMatrix4fv(shaderLabelInfo, 1, false, attributeLabelInfo.a, 0);
            attributeLabelBatch.draw(gl);
        }

        if (summaryLabelBatch.isDrawable()) {
            gl.glUniformMatrix4fv(shaderLabelInfo, 1, false, summaryLabelInfo.a, 0);
            summaryLabelBatch.draw(gl);
        }

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

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.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
        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    {
        gl3.glEnable(GL_DEPTH_TEST);
        gl3.glDepthFunc(GL_LESS);

        gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale);

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        //glEnable(GL_FRAMEBUFFER_SRGB);
        float[] depth = {1.0f};
        gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0);
        gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

        gl3.glUseProgram(programName[Program.TEXTURE]);

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

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }

    {
        gl3.glDisable(GL_DEPTH_TEST);

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        //glDisable(GL_FRAMEBUFFER_SRGB);

        gl3.glUseProgram(programName[Program.SPLASH]);

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

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);
    }

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

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.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.5f, 8.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(5.0f));
        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

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

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

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

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    float[] depth = {1.0f};
    gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0);

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

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

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

    gl3.glDisable(GL_DEPTH_TEST);

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glUseProgram(programName[Program.SPLASH]);

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

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

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

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.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, 4.0f / 3.0f, 0.1f, 8.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(5.0f));

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

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

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

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

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.DEPTH_MULTISAMPLE));
    gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth);

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

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

    gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);

    // Pass 2
    gl3.glDisable(GL_DEPTH_TEST);

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glUseProgram(programName[Program.SPLASH]);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH));
    gl3.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureName.get(Texture.MULTISAMPLE));

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

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

    GL3 gl3 = (GL3) gl;

    IntBuffer uniformBufferOffsetAlignment = GLBuffers.newDirectIntBuffer(1);
    {
        gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffsetAlignment);
        uniformBufferOffsetAlignment.put(0, glm.ceilMultiple(Mat4.SIZE, uniformBufferOffsetAlignment.get(0)));

        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, uniformBufferOffsetAlignment.get(0) * 2,
                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);

        pointer.asFloatBuffer().put(projection.mul_(viewMat4()).scale(new Vec3(1.00f)).toFa_());
        pointer.position(uniformBufferOffsetAlignment.get(0) * 1);
        pointer.asFloatBuffer().put(projection.mul(viewMat4()).scale(new Vec3(1.05f)).toFa_());
        pointer.rewind();

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

    {
        gl3.glEnable(GL_STENCIL_TEST);
        gl3.glEnable(GL_DEPTH_TEST);
        gl3.glDepthFunc(GL_LEQUAL);
        gl3.glStencilMask(0xFF);

        gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale);

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl3.glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0f, 0);
        gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

        gl3.glUseProgram(programName[Program.TEXTURE]);

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
        gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE));

        gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM),
                uniformBufferOffsetAlignment.get(0) * 0, uniformBufferOffsetAlignment.get(0));

        gl3.glDisable(GL_DEPTH_TEST);
        gl3.glStencilMask(0xFF);
        gl3.glStencilFunc(GL_ALWAYS, 1, 0xFF);
        gl3.glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

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

        gl3.glBindTexture(GL_TEXTURE_2D, 0); // 
        gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM),
                uniformBufferOffsetAlignment.get(0) * 1, uniformBufferOffsetAlignment.get(0));

        gl3.glStencilMask(0x00);
        gl3.glStencilFunc(GL_NOTEQUAL, 1, 0xFF);

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);
    }

    {
        gl3.glDisable(GL_DEPTH_TEST);

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl3.glUseProgram(programName[Program.SPLASH]);

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

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);
    }

    BufferUtils.destroyDirectBuffer(uniformBufferOffsetAlignment);

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

    GL3 gl3 = (GL3) gl;
    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.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);

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

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

    // Render a textured quad to a sRGB framebuffer object.
    {
        gl3.glEnable(GL_DEPTH_TEST);
        gl3.glDepthFunc(GL_LESS);

        gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale);

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        // Explicitly convert linear pixel color to sRGB color space, as FramebufferName is an sRGB FBO
        // Shader execution is done with linear color to get correct linear algebra working.
        gl3.glEnable(GL_FRAMEBUFFER_SRGB);

        gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth);
        gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

        gl3.glUseProgram(programName[Program.TEXTURE]);

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

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);
    }

    // Blit the sRGB framebuffer to the default framebuffer back buffer.
    {
        gl3.glDisable(GL_DEPTH_TEST);

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        // Uncomment to avoid the extra linear to sRGB conversion and hence get correct display
        gl3.glDisable(GL_FRAMEBUFFER_SRGB);

        gl3.glUseProgram(programName[Program.SPLASH]);

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

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);
    }

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

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl3.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);

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

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

    {
        gl3.glEnable(GL_DEPTH_TEST);
        gl3.glDepthFunc(GL_LESS);

        gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale);

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));

        gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth);
        gl3.glClearBufferfv(GL_COLOR, 0, clearColorSRGB);

        // TextureName[texture::DIFFUSE] is a sRGB texture which sRGB conversion on fetch has been disabled
        // Hence in the shader, the value is stored as sRGB so we should not convert it to sRGB.
        gl3.glUseProgram(programName[Program.TEXTURE]);

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

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);
    }

    {
        gl3.glDisable(GL_DEPTH_TEST);

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl3.glUseProgram(programName[Program.SPLASH]);

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

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);
    }

    return true;
}
 
Example 15
Source File: Gl_320_fbo_shadow.java    From jogl-samples with MIT License 3 votes vote down vote up
private void renderShadow(GL3 gl3) {

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

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

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        float[] depth = {1.0f};
        gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0);

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

        gl3.glBindVertexArray(vertexArrayName.get(Program.RENDER));

        checkError(gl3, "renderShadow 0");

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

        checkError(gl3, "renderShadow 1");

        gl3.glDisable(GL_DEPTH_TEST);

        checkError(gl3, "renderShadow");
    }