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

The following examples show how to use com.jogamp.opengl.GL4#glDrawTransformFeedback() . 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 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

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

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

    // Set the display viewport
    gl4.glViewportIndexedf(0, 0.0f, 0.0f, windowSize.x, windowSize.y);

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

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

    gl4.glBindProgramPipeline(pipelineName.get(Program.TRANSFORM));
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM));
    gl4.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM));
    gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName.get(Buffer.VERTEX), 0, Vec4.SIZE);

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName.get(0));

    gl4.glBeginQueryIndexed(GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB, 0, queryName.get(0));
    gl4.glBeginTransformFeedback(GL_TRIANGLES);
    {
        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl4.glEndTransformFeedback();
    gl4.glEndQueryIndexed(GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB, 0);

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    gl4.glDisable(GL_RASTERIZER_DISCARD);

    IntBuffer streamOverflow = GLBuffers.newDirectIntBuffer(1);
    gl4.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, streamOverflow);

    if (streamOverflow.get(0) == 0) {

        // Second draw, reuse the captured attributes
        gl4.glBindProgramPipeline(pipelineName.get(Program.FEEDBACK));
        gl4.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK));
        gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName.get(Buffer.FEEDBACK), 0, glf.Vertex_v4fc4f.SIZE);

        gl4.glDrawTransformFeedback(GL_TRIANGLES, feedbackName.get(0));
    }
    BufferUtils.destroyDirectBuffer(streamOverflow);
    
    return true;
}
 
Example 2
Source File: Gl_400_transform_feedback_object.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL4 gl4 = (GL4) gl;

    // Compute the MVP (Model View Projection matrix)
    {
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM0));
        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);

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

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

    gl4.glUseProgram(transformProgramName);

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

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName.get(0));
    gl4.glBeginTransformFeedback(GL_TRIANGLES);
    gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    gl4.glEndTransformFeedback();
    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    gl4.glDisable(GL_RASTERIZER_DISCARD);

    // Second draw, reuse the captured attributes
    gl4.glUseProgram(feedbackProgramName);

    gl4.glBindVertexArray(vertexArrayName.get(VertexArray.FEEDBACK));
    gl4.glDrawTransformFeedback(GL_TRIANGLES, feedbackName.get(0));

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

    GL4 gl4 = (GL4) gl;

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

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

    // Set the display viewport
    gl4.glViewportIndexedf(0, 0.0f, 0.0f, windowSize.x, windowSize.y);

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

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

    gl4.glBindProgramPipeline(pipelineName[Program.TRANSFORM]);
    gl4.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName[Buffer.TRANSFORM]);
    gl4.glBindVertexArray(vertexArrayName[Program.TRANSFORM]);
    gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName[Buffer.VERTEX], 0, Vec4.SIZE);

    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedbackName[0]);
    gl4.glBeginTransformFeedback(GL_TRIANGLES);
    {
        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }
    gl4.glEndTransformFeedback();
    gl4.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);

    gl4.glDisable(GL_RASTERIZER_DISCARD);

    // Second draw, reuse the captured attributes
    gl4.glBindProgramPipeline(pipelineName[Program.FEEDBACK]);
    gl4.glBindVertexArray(vertexArrayName[Program.FEEDBACK]);
    gl4.glBindVertexBuffer(Semantic.Buffer.STATIC, bufferName[Buffer.FEEDBACK], 0, glf.Vertex_v4fc4f.SIZE);

    gl4.glDrawTransformFeedback(GL_TRIANGLES, feedbackName[0]);

    return true;
}