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

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

    GL4 gl4 = (GL4) gl;

    if (uniformPointer == null) {

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
        BufferUtils.destroyDirectBuffer(uniformPointer);
    }

    gl4.glDeleteVertexArrays(Program.MAX, vertexArrayName);
    BufferUtils.destroyDirectBuffer(vertexArrayName);
    gl4.glDeleteBuffers(Buffer.MAX, bufferName);
    BufferUtils.destroyDirectBuffer(bufferName);
    gl4.glDeleteProgram(programName[Program.FEEDBACK]);
    gl4.glDeleteProgram(programName[Program.TRANSFORM]);
    gl4.glDeleteProgramPipelines(Program.MAX, pipelineName);
    BufferUtils.destroyDirectBuffer(pipelineName);
    gl4.glDeleteTransformFeedbacks(1, feedbackName);
    BufferUtils.destroyDirectBuffer(feedbackName);

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

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

    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor);

    // Bind rendering objects
    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.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));

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

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

    return true;
}
 
Example 3
Source File: Gl_420_texture_storage.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, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f));

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

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

    return true;
}
 
Example 4
Source File: Gl_430_image_sampling.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, 4.0f / 3.0f, 0.1f, 1000.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, 0.5f, 0.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindImageTexture(0, textureName.get(0), 0, false, 0, GL_READ_ONLY, GL_RGBA8);
    gl4.glBindImageTexture(1, textureName.get(0), 1, false, 0, GL_READ_ONLY, GL_RGBA8);
    gl4.glBindImageTexture(2, textureName.get(0), 2, false, 0, GL_READ_ONLY, GL_RGBA8);

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 3, 0, 0);

    return true;
}
 
Example 5
Source File: Gl_420_texture_pixel_store.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_COLOR, 0, clearColor.put(0, 1.0f).put(1, 0.5f).put(2, 0.0f).put(3, 1.0f));

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

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

    return true;
}
 
Example 6
Source File: Gl_420_texture_cube.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, Transform.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, 1000.0f);
        Mat4 view = viewMat4();
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = projection.mul(view).mul(model);
        Mat4 mv = view.mul(model);

        Transform transform = new Transform(mvp, mv, new Vec3(0.0f, 0.0f, -cameraDistance()));

        transform.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.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f));

    gl4.glBindProgramPipeline(pipelineName.get(0));
    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, textureName.get(0));
    gl4.glBindSampler(0, samplerName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, vertexCount, 1, 0);

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

    GL4 gl4 = (GL4) gl;

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

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

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

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

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

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

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

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

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

        int[] uniformBufferOffset = {0};
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);
        gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
        BufferUtils.destroyDirectBuffer(positionBuffer);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        uniformTransformOffset = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformTransformOffset * 2, null, GL_DYNAMIC_DRAW);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        uniformMaterialOffset = Math.max(Vec4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformMaterialOffset * 2, null, GL_STATIC_DRAW);
        {
            ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, uniformMaterialOffset * 2,
                    GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

            pointer.asFloatBuffer().put(new float[]{0.0f, 0.5f, 1.0f, 1.0f});
            pointer.position(uniformMaterialOffset);
            pointer.asFloatBuffer().put(new float[]{1.0f, 0.5f, 0.0f, 1.0f});
            pointer.rewind();

            gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
        }
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

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

        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, 0.5f, 0.0f, 1.0f}, 0);

    // 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 10
Source File: Gl_420_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;

    {
        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.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f));

    gl4.glUseProgram(programName);

    gl4.glActiveTexture(GL_TEXTURE0);
    gl4.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0));
    gl4.glBindSampler(0, samplerName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, vertexCount, 15, 0);

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

        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        int[] uniformBufferOffset = new int[]{0};
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);

        int uniformTransformBlockSize = Math.max(2 * Mat4.SIZE, uniformBufferOffset[0]);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformTransformBlockSize, null, GL_DYNAMIC_DRAW);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        int uniformMaterialBlockSize = Math.max(2 * Vec4.SIZE, uniformBufferOffset[0]);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.MATERIAL));
        gl4.glBufferData(GL_UNIFORM_BUFFER, uniformMaterialBlockSize, null, GL_STATIC_DRAW);

        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, 2 * Vec4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
        pointer.asFloatBuffer().put(new float[]{1.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 1.0f});

        gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(positionBuffer);

        return checkError(gl4, "initBuffer");
    }
 
Example 12
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 13
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 14
Source File: Gl_420_primitive_line_aa.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);

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

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

    //////////////////////////////
    // Render multisampled texture
    //glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE));
    //glEnable(GL_MULTISAMPLE);
    gl4.glViewportIndexedf(0, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);
    gl4.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 0.5f).put(2, 0).put(3, 1));

    gl4.glBindProgramPipeline(pipelineName.get(Pipeline.MULTISAMPLE));
    gl4.glBindVertexArray(vertexArrayName.get(Pipeline.MULTISAMPLE));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

    gl4.glDrawArraysInstancedBaseInstance(GL_LINE_LOOP, 0, vertexData.length, 3, 0);

    //////////////////////////
    // Resolving multisampling
    gl4.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.MULTISAMPLE));
    gl4.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.COLOR));
    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);

    //////////////////////////////////////
    // Render resolved multisample texture
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    //glDisable(GL_MULTISAMPLE);
    gl4.glActiveTexture(GL_TEXTURE0);
    //glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, TextureName[texture::MULTISAMPLE]);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLOR));
    gl4.glBindVertexArray(vertexArrayName.get(Pipeline.SPLASH));
    gl4.glBindProgramPipeline(pipelineName.get(Pipeline.SPLASH));

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

    return true;
}
 
Example 15
Source File: Gl_430_query_conditional.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);
            Mat4 model = new Mat4(1.0f);

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

            gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
        }

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

        // Clear color buffer with black
        gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0);

        gl4.glBindProgramPipeline(pipelineName.get(0));
        gl4.glBindVertexArray(vertexArrayName.get(0));
        gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.MATERIAL, bufferName.get(Buffer.MATERIAL), 0, Vec4.SIZE);

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

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

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

        gl4.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.
        gl4.glBeginConditionalRender(queryName.get(0), GL_QUERY_WAIT);
        {
            // Clear color buffer with white
            gl4.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0);

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

        toggle = !toggle;

        return true;
    }
 
Example 16
Source File: Gl_430_program_compute_variable_group_size.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.glBindProgramPipeline(pipelineName.get(Program.COMPUTE));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.INPUT));
    gl4.glBindImageTexture(ImageUnit.OUTPUT, textureName.get(Texture.OUTPUT), 0, false, 0, GL_WRITE_ONLY, GL_RGBA8);
    Vec2i workGroupSize = new Vec2i(32);
    Vec2i ndRange = textureSize.div_(workGroupSize); 
    gl4.glDispatchComputeGroupSizeARB(
            ndRange.x, ndRange.y, 1, // (8, 8, 1)
            workGroupSize.x, workGroupSize.y, 1); // (32, 32, 1)
    
    gl4.glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
    
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x, windowSize.y);
    gl4.glClearBufferfv(GL_COLOR, 0, white);

    gl4.glBindProgramPipeline(pipelineName.get(Program.GRAPHICS));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Image.DIFFUSE);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.OUTPUT));
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));

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

    return true;
}
 
Example 17
Source File: Gl_430_program_compute_image.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.glBindProgramPipeline(pipelineName.get(Program.COMPUTE));
    gl4.glBindImageTexture(Image.POSITION_INPUT, textureName.get(Texture.POSITION_INPUT), 0, false, 0, GL_READ_ONLY,
            GL_RGBA32F);
    gl4.glBindImageTexture(Image.TEXCOORD_INPUT, textureName.get(Texture.TEXCOORD_INPUT), 0, false, 0, GL_READ_ONLY,
            GL_RGBA32F);
    gl4.glBindImageTexture(Image.COLOR_INPUT, textureName.get(Texture.COLOR_INPUT), 0, false, 0, GL_READ_ONLY,
            GL_RGBA32F);
    gl4.glBindImageTexture(Image.POSITION_OUTPUT, textureName.get(Texture.POSITION_OUTPUT), 0, false, 0,
            GL_WRITE_ONLY, GL_RGBA32F);
    gl4.glBindImageTexture(Image.TEXCOORD_OUTPUT, textureName.get(Texture.TEXCOORD_OUTPUT), 0, false, 0,
            GL_WRITE_ONLY, GL_RGBA32F);
    gl4.glBindImageTexture(Image.COLOR_OUTPUT, textureName.get(Texture.COLOR_OUTPUT), 0, false, 0, GL_WRITE_ONLY,
            GL_RGBA32F);

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

    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(Program.GRAPHICS));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.DIFFUSE);
    gl4.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.POSITION);
    gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.POSITION_OUTPUT));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.TEXCOORD);
    gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.TEXCOORD_OUTPUT));
    gl4.glActiveTexture(GL_TEXTURE0 + Semantic.Sampler.COLOR);
    gl4.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.COLOR_OUTPUT));

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

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

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

        int alignement = 256;

        boolean validated = true;

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        int copyBufferSize = glm.ceilMultiple(vertexSize, alignement) + glm.ceilMultiple(elementSize, alignement);

        gl4.glBindBuffer(GL_COPY_READ_BUFFER, bufferName.get(Buffer.COPY));
        gl4.glBufferStorage(GL_COPY_READ_BUFFER, copyBufferSize, null, GL_MAP_WRITE_BIT);

        ByteBuffer copyBufferPointer = gl4.glMapBufferRange(GL_COPY_READ_BUFFER, 0, copyBufferSize, GL_MAP_WRITE_BIT
                | GL_MAP_INVALIDATE_BUFFER_BIT);
        copyBufferPointer.asFloatBuffer().put(vertexData);
        copyBufferPointer.position(glm.ceilMultiple(vertexSize, alignement));
        copyBufferPointer.asShortBuffer().put(elementData);
        copyBufferPointer.rewind();
        gl4.glUnmapBuffer(GL_COPY_READ_BUFFER);

        gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(elementSize, alignement), null, 0);
        gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, alignement), 0,
                glm.ceilMultiple(elementSize, alignement));

        gl4.glBindBuffer(GL_COPY_WRITE_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferStorage(GL_COPY_WRITE_BUFFER, glm.ceilMultiple(vertexSize, alignement), null, 0);
        gl4.glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, glm.ceilMultiple(vertexSize, alignement));

        int[] uniformBufferOffset = {0};
        gl4.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset[0]);

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null,
                GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        return validated;
    }
 
Example 19
Source File: Gl_440_query_occlusion.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);
            Mat4 model = new Mat4(1.0f);

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

            gl4.glUnmapBuffer(GL_UNIFORM_BUFFER);
        }

        // Clear color buffer with black
        gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0);

        gl4.glBindProgramPipeline(pipelineName.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));

        // Samples count query
        for (int i = 0; i < viewports.length; ++i) {

            gl4.glViewportArrayv(0, 1, viewports[i].toFA_(), 0);

            gl4.glBeginQuery(GL_ANY_SAMPLES_PASSED, queryName.get(i));
            {
                gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
            }
            gl4.glEndQuery(GL_ANY_SAMPLES_PASSED);
        }

        gl4.glBindBuffer(GL_QUERY_BUFFER, bufferName.get(Buffer.QUERY));
        IntBuffer params = GLBuffers.newDirectIntBuffer(1);
        for (int i = 0; i < viewports.length; ++i) {
//            params.put(0, Integer.BYTES * i);
            int[] a = {0};
            gl4.glGetQueryObjectuiv(queryName.get(i), GL_QUERY_RESULT, a, 0);
            System.out.println("a: "+a[0]);
        }

//        ByteBuffer pointer = gl4.glMapBufferRange(GL_QUERY_BUFFER, 0, Integer.BYTES * queryName.capacity(),
//                GL_MAP_READ_BIT);

//        System.out.println("Samples count: " + pointer.get(0) + ", " + pointer.get(1) + ", " + pointer.get(2)
//                + ", " + pointer.get(3) + "\r");

//        gl4.glUnmapBuffer(GL_QUERY_BUFFER);
//        gl4.glBindBuffer(GL_QUERY_BUFFER, 0);

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

    GL4 gl4 = (GL4) gl;

    // Asynchrone update of the uniform buffer
    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        ByteBuffer pointer = gl4.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE,
                GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 1000.0f);
        Mat4 model = new Mat4(1.0f).scale(new Vec3(4.0f));

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

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

    // Clear the color buffer
    gl4.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.5f, 1.0f, 1.0f}, 0);

    gl4.glBindProgramPipeline(pipelineName.get(0));
    bufferName.position(Buffer.TRANSFORM);
    gl4.glBindBuffersBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, 1, bufferName);
    bufferName.rewind();
    gl4.glBindSamplers(0, 1, samplerName);
    gl4.glBindVertexArray(vertexArrayName.get(0));

    // Draw each texture in different viewports
    for (int index = 0; index < Texture.MAX; ++index) {
        gl4.glViewportIndexedfv(0, viewport[index].toFA_(), 0);
        textureName.position(index);
        gl4.glBindTextures(0, 1, textureName);

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

    return true;
}