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

The following examples show how to use com.jogamp.opengl.GL4#glBindTextures() . 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_fbo_multisample_explicit.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFBO(GL4 gl4, int framebuffer) {

        gl4.glEnable(GL_DEPTH_TEST);

        gl4.glBindProgramPipeline(pipelineName.get(Program.THROUGH));
        gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), 0,
                uniformBlockSize);

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

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

        textureName.position(Texture.DIFFUSE);
        gl4.glBindTextures(0, 1, textureName);
        textureName.rewind();
        gl4.glBindVertexArray(vertexArrayName.get(0));

        gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);

        gl4.glDisable(GL_DEPTH_TEST);
    }
 
Example 2
Source File: Gl_450_fbo_multisample_explicit.java    From jogl-samples with MIT License 5 votes vote down vote up
private void resolveMultisampling(GL4 gl4) {

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

        textureName.position(Texture.MULTISAMPLE_COLORBUFFER);
        gl4.glBindTextures(0, 1, textureName);
        textureName.rewind();
        gl4.glBindVertexArray(vertexArrayName.get(0));
        gl4.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM),
                uniformBlockSize, uniformBlockSize);

        gl4.glEnable(GL_SCISSOR_TEST);

        // Box
        {
            gl4.glScissor(1, 1, windowSize.x / 2 - 2, windowSize.y - 2);

            gl4.glBindProgramPipeline(pipelineName.get(Program.RESOLVE_BOX));
            gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

        // Near
        {
            gl4.glScissor(windowSize.x / 2 + 1, 1, windowSize.x / 2 - 2, windowSize.y - 2);

            gl4.glBindProgramPipeline(pipelineName.get(Program.RESOLVE_NEAR));
            gl4.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

        gl4.glDisable(GL_SCISSOR_TEST);
    }
 
Example 3
Source File: Gl_500_texture_sparse_arb.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.001f, 100.0f);
        Mat4 model = new Mat4(1.0f);

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

        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.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindTextures(Semantic.Sampler.DIFFUSE, 1, textureName);
    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_500_glsl_vote_arb.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.perspectiveFov_((float) Math.PI * 0.25f, (float) windowSize.x, windowSize.y, 0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);

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

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

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

    gl4.glBindTextures(Semantic.Sampler.DIFFUSE, 1, textureName);
    gl4.glBindVertexArray(vertexArrayName.get(0));
    gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT));

    gl4.glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, null, 1, DrawElementsIndirectCommand.SIZE);

    return true;
}
 
Example 5
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 6
Source File: Gl_500_texture_cube_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 projection = glm.perspective_((float) Math.PI * 0.25f, windowSize.x * 0.5f / 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 t = new Transform(mvp, mv, new Vec3(0.0f, 0.0f, -cameraDistance()));

        transformPointer.asFloatBuffer().put(t.toFa_());
    }

    gl4.glClearBufferfv(GL_COLOR, 0, white);

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

    // Left side: seamless cubemap filtering
    gl4.glViewportIndexedf(0, 0, 0, windowSize.x * 0.5f, windowSize.y);
    samplerName.position(Sampler.SEAMLESS);
    gl4.glBindSamplers(Semantic.Sampler.DIFFUSE, 1, samplerName);

    gl4.glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, vertexCount, 1, 0);
    
    // Right side: per face cubemap filtering
    gl4.glViewportIndexedf(0, windowSize.x * 0.5f, 0, windowSize.x * 0.5f, windowSize.y);
    samplerName.position(Sampler.NON_SEAMLESS);
    gl4.glBindSamplers(Semantic.Sampler.DIFFUSE, 1, samplerName);

    samplerName.rewind();

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

    return true;
}
 
Example 7
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;
}