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

The following examples show how to use com.jogamp.opengl.GL3#glBindBufferBase() . 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_program.java    From jogl-samples with MIT License 5 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.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = projection.mul(viewMat4()).mul(model);

        pointer.asFloatBuffer().put(mvp.toFa_());

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

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName[Program.USED]);
    gl3.glUniformBlockBinding(programName[Program.USED], uniformTransform, Semantic.Uniform.TRANSFORM0);
    gl3.glUniformBlockBinding(programName[Program.USED], uniformMaterial, Semantic.Uniform.MATERIAL);

    // Attach the buffer to UBO binding point semantic::uniform::TRANSFORM0
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    // Attach the buffer to UBO binding point semantic::uniform::MATERIAL
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawElementsInstanced(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1);

    return true;
}
 
Example 2
Source File: Gl_320_texture_pixel_store.java    From jogl-samples with MIT License 5 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.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = projection.mul(viewMat4()).mul(model);

        pointer.asFloatBuffer().put(mvp.toFa_());

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

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

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

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

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

    return true;
}
 
Example 3
Source File: Gl_320_buffer_update.java    From jogl-samples with MIT License 5 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 transformBuffer = 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);
        Mat4 mvp = projection.mul(viewMat4()).mul(model);

        transformBuffer.asFloatBuffer().put(mvp.toFa_());

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

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

    gl3.glUseProgram(programName);

    // Attach the buffer to UBO binding point semantic::uniform::TRANSFORM0
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    // Attach the buffer to UBO binding point semantic::uniform::MATERIAL
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL));

    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
}
 
Example 4
Source File: Gl_320_texture_fetch.java    From jogl-samples with MIT License 5 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.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.glViewport(0, 0, windowSize.x, windowSize.y);
    clearColor.put(new float[]{0.0f, 0.5f, 1.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformBlockBinding(programName, uniformTransform, Semantic.Uniform.TRANSFORM0);

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

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

    return true;
}
 
Example 5
Source File: Gl_320_texture_2d.java    From jogl-samples with MIT License 5 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.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

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

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl3.glDrawBuffer(GL_BACK);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glDisable(GL_FRAMEBUFFER_SRGB);
    clearColor.put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName);

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

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

    return true;
}
 
Example 6
Source File: Gl_320_texture_derivative.java    From jogl-samples with MIT License 5 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.1f, 100.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(2.0f));

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

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

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

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

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

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

    return true;
}
 
Example 7
Source File: Gl_320_glsl_builtin_blocks.java    From jogl-samples with MIT License 5 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.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.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

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

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

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

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

    GL3 gl3 = (GL3) gl;

    {
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(0));
        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.glViewport(0, 0, windowSize.x, windowSize.y);

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

    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(0));

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

    return true;
}
 
Example 9
Source File: Gl_320_draw_base_vertex.java    From jogl-samples with MIT License 5 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 = gl.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);
    }

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

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

    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

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

    return true;
}
 
Example 10
Source File: Gl_320_draw_range_arrays.java    From jogl-samples with MIT License 5 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 / 6.0f, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

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

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

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

    gl3.glUseProgram(programName);
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glViewport(0, 0, windowSize.x / 2, windowSize.y);
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount / 2, 1);

    gl3.glViewport(windowSize.x / 2, 0, windowSize.x / 2, windowSize.y);
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 6, vertexCount / 2, 1);

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

    GL3 gl3 = (GL3) 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);
    {
        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);

        pointer.asFloatBuffer().put(mvp.toFa_());

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

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

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

    gl3.glUseProgram(programName);

    // Attach the buffer to UBO binding point semantic::uniform::TRANSFORM0
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl3.glBindVertexArray(vertexArrayName.get(0));
    /**
     * public void glMultiDrawElementsBaseVertex(int mode, IntBuffer count,
     * int type, PointerBuffer indices, int drawcount, IntBuffer basevertex)
     */
    gl3.glMultiDrawElementsBaseVertex(
            GL_TRIANGLES,
            count,
            GL_UNSIGNED_INT,
            indices,
            2,
            baseVertex);
    return true;
}
 
Example 12
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 13
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 14
Source File: Gl_330_query_conditional.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);

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

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    // Set the display viewport
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    // Clear color buffer with black
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 1));

    // Bind program
    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL), 0, Vec4.SIZE);

    // The first orange quad is not written in the framebuffer.
    gl3.glColorMaski(0, false, false, false, false);

    // Beginning of the samples count query
    gl3.glBeginQuery(GL_ANY_SAMPLES_PASSED, queryName.get(0));
    {
        if (toggle) {
            // To test the condional rendering, comment this line, the next draw call won't happen.
            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
        }
    }
    // End of the samples count query
    gl3.glEndQuery(GL_ANY_SAMPLES_PASSED);

    // The second blue quad is written in the framebuffer only if a sample pass the occlusion query.
    gl3.glColorMaski(0, true, true, true, true);

    gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL),
            uniformMaterialOffset, Vec4.SIZE);

    // Draw only if one sample went through the tests, 
    // we don't need to get the query result which prevent the rendering pipeline to stall.
    gl3.glBeginConditionalRender(queryName.get(0), GL_QUERY_WAIT);
    {
        // Clear color buffer with white
        gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl3.glEndConditionalRender();

    toggle = !toggle;

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

    GL3 gl3 = (GL3) 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);

    // Set the display viewport
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

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

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

    gl3.glUseProgram(programName[Program.TRANSFORM]);
    gl3.glUniformMatrix4fv(transformUniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.POSITION, bufferName.get(Program.FEEDBACK));
    gl3.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM));

    gl3.glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryName.get(0));
    gl3.glBeginTransformFeedback(GL_TRIANGLES);
    {
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl3.glEndTransformFeedback();
    gl3.glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);

    gl3.glDisable(GL_RASTERIZER_DISCARD);

    // Second draw, reuse the captured attributes
    gl3.glUseProgram(programName[Program.FEEDBACK]);

    IntBuffer primitivesWritten = GLBuffers.newDirectIntBuffer(1);
    gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, primitivesWritten);

    gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK));
    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, primitivesWritten.get(0) * 3, 1);

    BufferUtils.destroyDirectBuffer(primitivesWritten);

    return true;
}
 
Example 16
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 17
Source File: Gl_320_query_occlusion.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_());

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    // Set the display viewport
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    // Clear color buffer with black
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    // Samples count query
    gl3.glBeginQuery(GL_SAMPLES_PASSED, queryName.get(0));
    {
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl3.glEndQuery(GL_SAMPLES_PASSED);

    // Get the count of samples. 
    // If the result of the query isn't here yet, we wait here...
    IntBuffer samplesCount = GLBuffers.newDirectIntBuffer(1);
    gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, samplesCount);
    System.out.println("Samples (fragments) count: " + samplesCount.get(0));

    BufferUtils.destroyDirectBuffer(samplesCount);

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

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

        gl3.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    // Set the display viewport
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    // Clear color buffer with black
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 1));

    gl3.glUseProgram(programName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    // Samples count query
    gl3.glBeginQuery(GL_ANY_SAMPLES_PASSED, queryName.get(0));
    {
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl3.glEndQuery(GL_ANY_SAMPLES_PASSED);

    // Get the count of samples. 
    // If the result of the query isn't here yet, we wait here...
    gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, samplesCount);
    System.out.println("any samples passed: " + (samplesCount.get(0) == GL_TRUE));

    return true;
}
 
Example 19
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 20
Source File: Gl_320_transform_feedback_separated.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) 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);

    // Set the display viewport
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    // Clear color buffer with black
    gl3.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

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

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

        gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.POSITION, bufferName.get(Buffer.POSITION));
        gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.COLOR, bufferName.get(Buffer.COLOR));

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

        gl3.glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryName.get(0));
        gl3.glBeginTransformFeedback(GL_TRIANGLES);
        {
            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
        }
        gl3.glEndTransformFeedback();
        gl3.glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);

        gl3.glDisable(GL_RASTERIZER_DISCARD);
    }

    // Second draw, reuse the captured attributes
    {
        gl3.glUseProgram(programName[Program.FEEDBACK]);

        IntBuffer primitivesWritten = GLBuffers.newDirectIntBuffer(1);
        gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, primitivesWritten);

        gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, primitivesWritten.get(0) * 3, 1);

        BufferUtils.destroyDirectBuffer(primitivesWritten);
    }

    return true;
}