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

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

    GL4 gl4 = (GL4) gl;

    boolean validated = true;

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

    gl4.glEnable(GL_DEPTH_TEST);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glDrawBuffer(GL_BACK);
    if (!isFramebufferComplete(gl, 0)) {
        return false;
    }

    return validated;
}
 
Example 2
Source File: Gl_440_fbo_without_attachment.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        gl4.glGenFramebuffers(1, framebufferName, 0);
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName[0]);
        gl4.glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, windowSize.x * supersampling);
        gl4.glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, windowSize.y * supersampling);
        gl4.glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_LAYERS, 1);
        gl4.glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 1);
        gl4.glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, GL_TRUE);
        if (!isFramebufferComplete(gl4, framebufferName[0])) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        return true;
    }
 
Example 3
Source File: Gl_430_texture_fetch_dependent.java    From jogl-samples with MIT License 6 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.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.DIFFUSE));
    gl4.glActiveTexture(GL_TEXTURE1);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.INDIRECTION));

    gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
    return true;
}
 
Example 4
Source File: Gl_400_buffer_uniform_array.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    GL4 gl4 = (GL4) gl;

    boolean validated = true;

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

    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glDrawBuffer(GL_BACK);
    if (!isFramebufferComplete(gl, 0)) {
        return false;
    }

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

    GL4 gl4 = (GL4) gl;

    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
    gl4.glBindSampler(0, samplerName.get(0));

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

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

        gl4.glGenFramebuffers(Framebuffer.MAX, framebufferName);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.MULTISAMPLE), 0);
        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.MULTISAMPLE))) {
            return false;
        }
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.COLOR));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.COLOR), 0);
        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.COLOR))) {
            return false;
        }
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        return true;
    }
 
Example 7
Source File: Gl_450_fbo_multisample_explicit.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        gl4.glGenFramebuffers(Framebuffer.MAX, framebufferName);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.MULTISAMPLE_COLORBUFFER), 0);
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureName.get(Texture.MULTISAMPLE_DEPTHBUFFER), 0);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.COLORBUFFER), 0);

        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.RENDER))) {
            return false;
        }
        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.RESOLVE))) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        return true;
    }
 
Example 8
Source File: Gl_400_fbo_layered.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        IntBuffer buffers = GLBuffers.newDirectIntBuffer(new int[]{GL_COLOR_ATTACHMENT0});
        gl4.glGenFramebuffers(1, framebufferName);
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureColorbufferName.get(0), 0);
        gl4.glDrawBuffers(1, buffers);
        if (!isFramebufferComplete(gl4, framebufferName.get(0))) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        gl4.glDrawBuffer(GL_BACK);
        if (!isFramebufferComplete(gl4, 0)) {
            return false;
        }

        return checkError(gl4, "initFramebuffer");
    }
 
Example 9
Source File: Gl_400_fbo_rtt_texture_array.java    From jogl-samples with MIT License 5 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);

    // Pass 1
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    gl4.glViewport(0, 0, framebufferSize.x, framebufferSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0).put(2, 0).put(3, 1));
    gl4.glClearBufferfv(GL_COLOR, 1, clearColor.put(0, 0).put(1, 1).put(2, 0).put(3, 1));
    gl4.glClearBufferfv(GL_COLOR, 2, clearColor.put(0, 0).put(1, 0).put(2, 1).put(3, 1));
    gl4.glClearBufferfv(GL_COLOR, 3, clearColor.put(0, 1).put(1, 1).put(2, 0).put(3, 1));

    // Pass 2
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName);
    gl4.glUniform1i(uniformDiffuse, 0);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));

    for (int i = 0; i < Texture.MAX; ++i) {
        gl4.glViewport((int) viewport[i].x, (int) viewport[i].y, (int) viewport[i].z, (int) viewport[i].w);
        gl4.glUniform1i(uniformLayer, i);

        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

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

    GL4 gl4 = (GL4) gl;

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

    gl4.glUseProgram(programName);
    gl4.glUniform1i(uniformDiffuse, 0);

    // Pass 1, render the scene in a multisampled framebuffer
    gl4.glEnable(GL_MULTISAMPLE);
    gl4.glEnable(GL_SAMPLE_SHADING);
    gl4.glMinSampleShading(4 / 2.0f);

    float[] min = {0};
    gl4.glGetFloatv(GL_MIN_SAMPLE_SHADING_VALUE, min, 0);
    //glEnable(GL_SAMPLE_MASK);
    //glSampleMaski(0, 0xFF);
    renderFBO(gl4, framebufferName.get(Framebuffer.RENDER));
    gl4.glDisable(GL_MULTISAMPLE);

    // Resolved multisampling
    gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
    gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
    gl4.glBlitFramebuffer(
            0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
            0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
            GL_COLOR_BUFFER_BIT, GL_NEAREST);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Pass 2, render the colorbuffer from the multisampled framebuffer
    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    renderFB(gl4, textureName.get(Texture.COLOR));

    return true;
}
 
Example 11
Source File: Gl_400_fbo_multisample.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        gl4.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureName.get(Texture.MULTISAMPLE));
        // The second parameter is the number of samples.
        gl4.glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, false);

        gl4.glGenFramebuffers(Framebuffer.MAX, framebufferName);
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.MULTISAMPLE), 0);

        if (!isFramebufferComplete(gl4, framebufferName.get(0))) {
            return false;
        }
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLOR));
        gl4.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, GL_RGBA,
                GL_UNSIGNED_BYTE, null);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.COLOR), 0);

        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.RESOLVE))) {
            return false;
        }
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        return true;
    }
 
Example 12
Source File: Gl_400_fbo_rtt.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        gl4.glGenFramebuffers(1, framebufferName);
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.R), 0);
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, textureName.get(Texture.G), 0);
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, textureName.get(Texture.B), 0);

        if (!isFramebufferComplete(gl4, framebufferName.get(0))) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        return checkError(gl4, "initFramebuffer");
    }
 
Example 13
Source File: Gl_500_direct_state_access_gtc.java    From jogl-samples with MIT License 5 votes vote down vote up
private void renderFB(GL4 gl4) {

        gl4.glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
        gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
        FloatBuffer clear = GLBuffers.newDirectFloatBuffer(new float[]{0.0f, 0.5f, 1.0f, 1.0f});
        gl4.glClearNamedFramebufferfv(0, GL_COLOR, 0, clear);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM),
                uniformBlockSize, uniformBlockSize);
        gl4.glBindTextureUnit(0, textureName.get(Texture.COLORBUFFER));
        gl4.glBindVertexArray(vertexArrayName.get(0));

        gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
    }
 
Example 14
Source File: Gl_400_fbo_shadow.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        boolean validated = true;

        IntBuffer buffersRender = GLBuffers.newDirectIntBuffer(new int[]{GL_COLOR_ATTACHMENT0});

        gl4.glGenFramebuffers(Framebuffer.MAX, framebufferName);

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.FRAMEBUFFER));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.COLORBUFFER), 0);
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureName.get(Texture.RENDERBUFFER), 0);
        gl4.glDrawBuffers(1, buffersRender);
        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.FRAMEBUFFER))) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.SHADOW));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureName.get(Texture.SHADOWMAP), 0);
        gl4.glDrawBuffer(GL_NONE);
        if (!isFramebufferComplete(gl4, framebufferName.get(Framebuffer.SHADOW))) {
            return false;
        }

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
        gl4.glDrawBuffer(GL_BACK);
        if (!isFramebufferComplete(gl4, 0)) {
            return false;
        }

        BufferUtils.destroyDirectBuffer(buffersRender);

        return validated && checkError(gl4, "initFramebuffer");
    }
 
Example 15
Source File: Gl_430_fbo_without_attachment.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.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindSampler(0, samplerName.get(0));

    // Render
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(Pipeline.RENDER));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
    gl4.glBindImageTexture(Semantic.Image.DIFFUSE, textureName.get(Texture.COLORBUFFER), 0, false, 0, GL_WRITE_ONLY,
            GL_RGBA8);

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

    // Splash
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

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

    return true;
}
 
Example 16
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 17
Source File: Gl_500_conservative_raster_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.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x / 16.0f, windowSize.y / 16.0f);

    gl4.glClearBufferfv(GL_COLOR, 0, whiteColor);

    // Bind rendering objects
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x / 16.0f, windowSize.y / 16.0f);
    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.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL0));

    //glSubpixelPrecisionBiasNV(-8, -8);
    gl4.glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
    gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL1));

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

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

    gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH));
    gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH));
    gl4.glBindTextureUnit(0, textureName.get(Texture.COLORBUFFER));

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

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

        projection.mul(viewMat4()).toDbb(pointer);

        // 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, windowSize.x * framebufferScale, windowSize.y * framebufferScale);

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

        // Convert linear clear color to sRGB color space, FramebufferName is a sRGB FBO
        gl4.glEnable(GL_FRAMEBUFFER_SRGB);
        gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1.0f));
        gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f));

        // 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.
        gl4.glDisable(GL_FRAMEBUFFER_SRGB);
        gl4.glUseProgram(programName[Program.TEXTURE]);

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

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

    {
        gl4.glDisable(GL_DEPTH_TEST);

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

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

        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 19
Source File: Gl_440_fbo_depth_stencil.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);

        //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, (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.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

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

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

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

        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.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);
    }

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

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

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

        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 20
Source File: Gl_420_memory_barrier.java    From jogl-samples with MIT License 3 votes vote down vote up
private boolean initFramebuffer(GL4 gl4) {

        boolean validated = true;

        gl4.glGenFramebuffers(1, framebufferName);
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.COLORBUFFER), 0);

        validated = validated && (isFramebufferComplete(gl4, framebufferName.get(0)));

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        return validated;
    }