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

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

    GL4 gl4 = (GL4) gl;

    Mat4d projection = glm.perspective_(Math.PI * 0.25, (double) windowSize.x / windowSize.y, 0.1, 100.0);
    Mat4d model = new Mat4d(1.0);
    Mat4d view = new Mat4d(viewMat4());
    Mat4d mvp = projection.mul(view).mul(model);

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4dv(uniformMvp, 1, false, mvp.toDa_(), 0);
    gl4.glUniform4d(uniformDiffuse, 1.0, 0.5, 0.0, 1.0);

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0);

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

        GL4 gl4 = (GL4) gl;

        {
            Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f);
            uniformPointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(new Mat4(1.0f)).toFa_());
        }

        gl4.glClearBufferfv(GL_COLOR, 0, clearColor);

//        gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, 1, DrawElementsIndirectCommand.SIZEOF);
        gl4.glDrawElements(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0);

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

    GL4 gl4 = (GL4) gl;

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

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

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

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindTextureUnit(Semantic.Sampler.DIFFUSE, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Semantic.Storage.VERTEX, bufferName.get(Buffer.VERTEX));

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

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

    GL4 gl4 = (GL4) gl;

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

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

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

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

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

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

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

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

    GL4 gl4 = (GL4) gl;

    // Compute the MVP (Model View Projection matrix)
    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x * 0.5f / windowSize.y, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

    // Render with the separate programs
    gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, windowSize.x / 2).put(3, windowSize.y));
    gl4.glProgramUniformMatrix4fv(separateProgramName[Program.VERTEX], separateUniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glProgramUniform1i(separateProgramName[Program.FRAGMENT], separateUniformDiffuse, 0);
    gl4.glBindProgramPipeline(pipelineName.get(0));
    {
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);
    }
    gl4.glBindProgramPipeline(0);

    // Render with the unified programs
    gl4.glViewportIndexedfv(0, viewportBuffer.put(0, windowSize.x / 2).put(1, 0).put(2, windowSize.x / 2)
            .put(3, windowSize.y));
    gl4.glProgramUniformMatrix4fv(unifiedProgramName, unifiedUniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glProgramUniform1i(unifiedProgramName, unifiedUniformDiffuse, 0);
    gl4.glUseProgram(unifiedProgramName);
    {
        gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);
    }
    gl4.glUseProgram(0);

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

    GL4 gl4 = (GL4) gl;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

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

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

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

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    // Bind rendering objects
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));

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

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

    GL4 gl4 = (GL4) gl;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);

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

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

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

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

    gl4.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1));
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

    gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT,
            1 * Integer.BYTES, // indices offset
            5, // instance count
            2, // base vertex
            5); // base instance

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

    GL4 gl4 = (GL4) gl;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

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

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

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0.0f).put(1, 0.0f).put(2, 0.0f).put(3, 1.0f));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bufferName.get(Buffer.VERTEX));

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

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

    GL4 gl4 = (GL4) gl;

    {
        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y,
                0.1f, 100.0f);
        viewMat4().print("view");
        uniformPointer.asFloatBuffer().put(viewMat4().toFa_());
        //uniformPointer.asFloatBuffer().put(new Mat4().toFa_());
    }

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


    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);        
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor);
    
    gl4.glBindBufferRange(GL_UNIFORM_BUFFER, 
            Semantic.Uniform.TRANSFORM0, 
            bufferName.get(Buffer.TRANSFORM), 
            0,
            Mat4.SIZE);
    
    gl4.glBindVertexArray(vertexArrayName.get(0));

    gl4.glDrawArrays(GL_TRIANGLES, 0, 3);

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

    GL4 gl4 = (GL4) gl;

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

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

    gl4.glUseProgram(programName);
    gl4.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl4.glUniform4f(uniformDiffuse, 1.0f, 0.5f, 0.0f, 1.0f);

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

    if (useIndirect) {
        gl4.glDrawElementsIndirect(
                GL_TRIANGLES,
                GL_UNSIGNED_INT,
                0);
    } else {
        gl4.glDrawElementsInstancedBaseVertexBaseInstance(
                GL_TRIANGLES,
                command.count,
                GL_UNSIGNED_INT,
                command.firstIndex,
                command.primCount,
                command.baseVertex,
                command.reservedMustBeZero);
    }

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

    GL4 gl4 = (GL4) gl;

    // Setup blending
    gl4.glEnable(GL_BLEND);
    gl4.glBlendEquation(GL_FUNC_ADD);
    gl4.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(
                GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

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

        mvp.toDbb(pointer);

        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    IntBuffer data = IntBuffer.wrap(new int[]{0});
    gl4.glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bufferName.get(Buffer.ATOMIC_COUNTER));
    gl4.glClearBufferSubData(GL_ATOMIC_COUNTER_BUFFER, GL_R8UI, 0, Integer.BYTES, GL_RGBA, GL_UNSIGNED_INT, data);

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0.0f).put(1, 0.0f).put(2, 0.0f).put(3, 1.0f));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, bufferName.get(Buffer.ATOMIC_COUNTER));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

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

    return true;
}
 
Example 12
Source File: Gl_450_query_statistics_arb.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.perspectiveFov_((float) Math.PI * 0.25f, windowSize.x, windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_());

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

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

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBeginQuery(GL_VERTICES_SUBMITTED_ARB, queryName.get(Statistics.VERTICES_SUBMITTED));
    gl4.glBeginQuery(GL_PRIMITIVES_SUBMITTED_ARB, queryName.get(Statistics.PRIMITIVES_SUBMITTED));
    gl4.glBeginQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.VERTEX_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB, queryName.get(Statistics.TESS_CONTROL_SHADER_PATCHES));
    gl4.glBeginQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB,
            queryName.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_GEOMETRY_SHADER_INVOCATIONS, queryName.get(Statistics.GEOMETRY_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB,
            queryName.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED));
    gl4.glBeginQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.FRAGMENT_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB, queryName.get(Statistics.COMPUTE_SHADER_INVOCATIONS));
    gl4.glBeginQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_INPUT_PRIMITIVES));
    gl4.glBeginQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB, queryName.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES));
    {
        gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
    }
    gl4.glEndQuery(GL_VERTICES_SUBMITTED_ARB);
    gl4.glEndQuery(GL_PRIMITIVES_SUBMITTED_ARB);
    gl4.glEndQuery(GL_VERTEX_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_TESS_CONTROL_SHADER_PATCHES_ARB);
    gl4.glEndQuery(GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_GEOMETRY_SHADER_INVOCATIONS);
    gl4.glEndQuery(GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB);
    gl4.glEndQuery(GL_FRAGMENT_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_COMPUTE_SHADER_INVOCATIONS_ARB);
    gl4.glEndQuery(GL_CLIPPING_INPUT_PRIMITIVES_ARB);
    gl4.glEndQuery(GL_CLIPPING_OUTPUT_PRIMITIVES_ARB);

    IntBuffer queryResult = GLBuffers.newDirectIntBuffer(Statistics.MAX);
    for (int i = 0; i < queryResult.capacity(); ++i) {
        gl4.glGetQueryObjectuiv(queryName.get(i), GL_QUERY_RESULT, queryResult);
    }
    System.out.println("Verts: " + queryResult.get(Statistics.VERTICES_SUBMITTED)
            + "; Prims: (" + queryResult.get(Statistics.PRIMITIVES_SUBMITTED) + ", "
            + queryResult.get(Statistics.GEOMETRY_SHADER_PRIMITIVES_EMITTED)
            + "); Shaders(" + queryResult.get(Statistics.VERTEX_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.TESS_CONTROL_SHADER_PATCHES) + ", "
            + queryResult.get(Statistics.TESS_EVALUATION_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.GEOMETRY_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.FRAGMENT_SHADER_INVOCATIONS) + ", "
            + queryResult.get(Statistics.COMPUTE_SHADER_INVOCATIONS)
            + "); Clip(" + queryResult.get(Statistics.CLIPPING_INPUT_PRIMITIVES) + ", "
            + queryResult.get(Statistics.CLIPPING_OUTPUT_PRIMITIVES) + ")\r");

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

    GL4 gl4 = (GL4) gl;

    Mat4 projection = glm.ortho_(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f);
    Mat4 view = new Mat4(1.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(view).mul(model);

    gl4.glProgramUniformMatrix4fv(programName[Program.LAYERING], uniformMvp[Program.LAYERING], 1, false,
            mvp.toFa_(), 0);
    gl4.glProgramUniformMatrix4fv(programName[Program.VIEWPORT], uniformMvp[Program.VIEWPORT], 1, false,
            mvp.toFa_(), 0);
    gl4.glProgramUniform1i(programName[Program.VIEWPORT], uniformDiffuse, 0);

    // Pass 1
    {
        gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
        gl4.glViewportIndexedfv(0, viewportBuffer.put(0, 0).put(1, 0).put(2, FRAMEBUFFER_SIZE.x).put(3, FRAMEBUFFER_SIZE.y));

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

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

    // Pass 2
    {
        int border = 2;

        gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);

        gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0));

        gl4.glViewportIndexedfv(0, viewportBuffer.put(0, border).put(1, border).put(2, windowSize.x * 0.5f - 2.0f * border)
                .put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(1, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, border)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(2, viewportBuffer.put(0, windowSize.x * 0.5f + border).put(1, windowSize.y * 0.5f + 1)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));
        gl4.glViewportIndexedfv(3, viewportBuffer.put(0, border).put(1, windowSize.y * 0.5f + border)
                .put(2, windowSize.x * 0.5f - 2.0f * border).put(3, windowSize.y * 0.5f - 2.0f * border));

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

        gl4.glActiveTexture(GL_TEXTURE0);
        gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
        gl4.glBindSampler(0, samplerName.get(0));

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

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

    GL4 gl4 = (GL4) gl;

    diffuseIndex++;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0,
                Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

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

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

        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    gl4.glUseProgram(programName);
    gl4.glUniform1ui(uniformDiffuseIndex, (diffuseIndex / 100) % 2);

    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.RGB));
    gl4.glBindSampler(0, samplerName.get(0));

    gl4.glActiveTexture(GL_TEXTURE1);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.BGR));
    gl4.glBindSampler(1, samplerName.get(0));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 2, 0);

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

    GL4 gl4 = (GL4) gl;

    // Pass 1: Compute the MVP (Model View Projection matrix)
    Mat4 projection = glm.ortho_(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
    Mat4 viewTranslate = new Mat4(1.0f).translate(new Vec3(0.0f, 0.0f, 0.0f));
    Mat4 view = viewTranslate;
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(view).mul(model);

    gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0));
    gl4.glViewport(0, 0, windowSize.x, windowSize.y);

    gl4.glUseProgram(programName[Program.COLORBUFFERS]);
    gl4.glUniformMatrix4fv(uniformMvpMultiple, 1, false, mvp.toFa_(), 0);

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

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

    gl4.glUseProgram(programName[Program.BLIT]);
    gl4.glUniform1i(uniformDiffuseSingle, 0);

    {
        projection.ortho(-1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f);
        view.identity();
        model.identity();
        mvp = projection.mul(view).mul(model);
        gl4.glUniformMatrix4fv(uniformMvpSingle, 1, false, mvp.toFa_(), 0);
    }

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

        gl4.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w);

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

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

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

    GL4 gl4 = (GL4) gl;

    int uniformBufferOffset = Math.max(uniformBufferAlignment.get(0), Mat4.SIZE);
    int uniformBufferRange = uniformBufferOffset * 2;

    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER,
                0, uniformBufferRange, 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 model0 = new Mat4(1.0f).translate(new Vec3(+1, 0, 0));
        Mat4 model1 = new Mat4(1.0f).translate(new Vec3(-1, 0, 0));

        pointer.position(uniformBufferOffset * 0);
        pointer.asFloatBuffer().put(projection.mul_(viewMat4()).mul(model0).toFa_());
        pointer.position(uniformBufferOffset * 1);
        pointer.asFloatBuffer().put(projection.mul_(viewMat4()).mul(model1).toFa_());

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

    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);

    // Attach the buffer to UBO binding point semantic::uniform::TRANSFORM0
    gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), 0,
            Mat4.SIZE);
    gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM1, bufferName.get(Buffer.TRANSFORM),
            uniformBufferOffset, Mat4.SIZE);

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

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0);

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

    GL4 gl4 = (GL4) gl;

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

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

    GL4 gl4 = (GL4) gl;

    gl4.glViewport(0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

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

      GL4 gl4 = (GL4) gl;

      /*// Measure speed

double currentTime = glfwGetTime();

nbFrames++;

if (currentTime - lastTime >= 1.0) { // If last prinf() was more than 1 sec ago

									 // printf and reset timer

	printf("%f ms/frame\n", 1000.0 / double(nbFrames));

	nbFrames = 0;

	lastTime += 1.0;

}*/
      {
          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);

          gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
          ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT);
          pointer.asFloatBuffer().put(mvp.toFa_());
          gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
      }

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

      gl4.glBindProgramPipeline(pipelineName.get(0));
      gl4.glBindTextureUnit(0, textureName.get(0));
      gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
      gl4.glBindVertexArray(vertexArrayName.get(0));

      gl4.glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, Semantic.Attr.POSITION, address.get(0), vertexSize);
      gl4.glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, Semantic.Attr.TEXCOORD, address.get(0) + Vec2.SIZE,
              vertexSize - Vec2.SIZE);

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

      return true;
  }