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

The following examples show how to use com.jogamp.opengl.GL3#glUniform1i() . 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: LoopBatcher.java    From constellation with Apache License 2.0 6 votes vote down vote up
@Override
public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) {

    if (batch.isDrawable()) {
        gl.glUseProgram(shader);

        // Uniform variables
        if (drawForHitTest) {
            gl.glUniform1i(shaderLocDrawHitTest, GL3.GL_TRUE);
            drawForHitTest = false;
        } else {
            gl.glUniform1i(shaderLocDrawHitTest, GL3.GL_FALSE);
        }
        gl.glUniformMatrix4fv(shaderMVMatrix, 1, false, mvMatrix.a, 0);
        gl.glUniformMatrix4fv(shaderPMatrix, 1, false, pMatrix.a, 0);
        gl.glUniform1f(shaderVisibilityLow, camera.getVisibilityLow());
        gl.glUniform1f(shaderVisibilityHigh, camera.getVisibilityHigh());
        gl.glUniform1f(shaderMorphMix, camera.getMix());
        gl.glUniform1i(shaderXyzTexture, TextureUnits.VERTICES);
        gl.glUniform1i(shaderImagesTexture, TextureUnits.ICONS);
        batch.draw(gl);
    }
}
 
Example 2
Source File: Gl_320_glsl_discard.java    From jogl-samples with MIT License 6 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.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearColor(1.0f, 0.5f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glBindVertexArray(vertexArrayName.get(0));

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

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

    GL3 gl3 = (GL3) gl;

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

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

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_RECTANGLE, textureRectName.get(0));

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

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

    GL3 gl3 = (GL3) gl;

    // Clear the framebuffer
    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);

    // Pass 1
    // Render the scene in a multisampled framebuffer
    gl3.glEnable(GL_MULTISAMPLE);
    renderFBO(gl3, framebufferName.get(Framebuffer.RENDER));
    gl3.glDisable(GL_MULTISAMPLE);

    // Resolved multisampling
    gl3.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
    gl3.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
    gl3.glBlitFramebuffer(
            0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
            0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
            GL_COLOR_BUFFER_BIT, GL_NEAREST);
    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Pass 2
    // Render the colorbuffer from the multisampled framebuffer
    renderFB(gl3, textureName.get(Texture.COLORBUFFER));

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

    GL3 gl3 = (GL3) gl;

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

    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1));

    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    for (int index = 0; index < Viewport.MAX; ++index) {
        gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);

        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzleR[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzleG[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzleB[index]);
        gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzleA[index]);

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

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

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

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glActiveTexture(GL_TEXTURE0);
    for (int index = 0; index < Texture.MAX; ++index) {
        gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(index));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

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

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

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDiffuse, 0);

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glActiveTexture(GL_TEXTURE0);
    for (int index = 0; index < Texture.MAX; ++index) {
        gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);
        gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(index));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

    return true;
}
 
Example 9
Source File: Gl_320_texture_buffer.java    From jogl-samples with MIT License 5 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
    clearDepth.put(new float[]{1.0f}).rewind();
    gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth);
    clearColor.put(new float[]{1.0f, 1.0f, 1.0f, 1.0f}).rewind();
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor);

    // Bind program
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformDisplacement, 0);
    gl3.glUniform1i(uniformDiffuse, 1);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.DISPLACEMENT));

    gl3.glActiveTexture(GL_TEXTURE1);
    gl3.glBindTexture(GL_TEXTURE_BUFFER, textureName.get(Texture.DIFFUSE));

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

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

    GL3 gl3 = (GL3) gl;

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

    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.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glUseProgram(programName[Program.OFFSET]);
    gl3.glUniform2iv(uniformOffset, 1, new int[]{48, -80}, 0);

    for (int i = 0; i < Program.MAX; ++i) {
        gl3.glUseProgram(programName[i]);
        gl3.glUniformMatrix4fv(uniformMvp[i], 1, false, mvp.toFa_(), 0);
        gl3.glUniform1i(uniformDiffuse[i], 0);

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

        gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0);
    }

    return true;
}
 
Example 11
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 12
Source File: NodeLabelBatcher.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) {

    if (topBatch.isDrawable() || bottomBatch.isDrawable()) {
        gl.glUseProgram(shader);

        // Let the glyph controller bind the glyph info and glyph image textures
        SharedDrawable.updateGlyphTextureController(gl);
        SharedDrawable.getGlyphTextureController().bind(gl, shaderGlyphInfoTexture, TextureUnits.GLYPH_INFO, shaderGlyphImageTexture, TextureUnits.GLYPHS);

        // Uniform variables
        gl.glUniformMatrix4fv(shaderMVMatrix, 1, false, mvMatrix.a, 0);
        gl.glUniformMatrix4fv(shaderPMatrix, 1, false, pMatrix.a, 0);
        gl.glUniformMatrix4fv(shaderLabelBottomInfo, 1, false, labelBottomInfo.a, 0);
        gl.glUniformMatrix4fv(shaderLabelTopInfo, 1, false, labelTopInfo.a, 0);
        gl.glUniform1f(shaderLocWidth, SharedDrawable.getGlyphManager().getWidthScalingFactor());
        gl.glUniform1f(shaderLocHeight, SharedDrawable.getGlyphManager().getHeightScalingFactor());
        gl.glUniform1f(shaderVisibilityLow, camera.getVisibilityLow());
        gl.glUniform1f(shaderVisibilityHigh, camera.getVisibilityHigh());
        gl.glUniform1f(shaderMorphMix, camera.getMix());
        gl.glUniform1i(shaderXyzTexture, TextureUnits.VERTICES);
        gl.glUniform1i(shaderBackgroundGlyphIndex, SharedDrawable.getLabelBackgroundGlyphPosition());
        gl.glUniform4fv(shaderBackgroundColor, 1, backgroundColor, 0);
        gl.glUniform4fv(shaderHighlightColor, 1, highlightColor, 0);

        if (topBatch.isDrawable()) {
            topBatch.draw(gl);
        }
        if (bottomBatch.isDrawable()) {
            bottomBatch.draw(gl);
        }
    }
}
 
Example 13
Source File: Gl_320_texture_cube.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 2.0f / 3.0f, 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);

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

    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMv, 1, false, mv.toFa_(), 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);
    gl3.glUniform1i(uniformEnvironment, 0);
    gl3.glUniform3fv(uniformCamera, 1, new float[]{0.0f, 0.0f, -cameraDistance()}, 0);

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_CUBE_MAP, textureName.get(0));

    gl3.glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
    gl3.glViewport(0, 0, windowSize.x >> 1, windowSize.y);

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

    gl3.glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
    gl3.glViewport(windowSize.x >> 1, 0, windowSize.x >> 1, windowSize.y);

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

    return true;
}
 
Example 14
Source File: GlyphManagerOpenGLController.java    From constellation with Apache License 2.0 4 votes vote down vote up
private void bindGlyphs(GL3 gl, int uniformLocation, int textureUnit) {
    gl.glUniform1i(uniformLocation, textureUnit);
    gl.glActiveTexture(GL3.GL_TEXTURE0 + textureUnit);
    gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, glyphsTextureName[0]);
}
 
Example 15
Source File: GlyphManagerOpenGLController.java    From constellation with Apache License 2.0 4 votes vote down vote up
private void bindCoordinates(GL3 gl, int uniformLocation, int textureUnit) {
    gl.glActiveTexture(GL3.GL_TEXTURE0 + textureUnit);
    gl.glBindTexture(GL3.GL_TEXTURE_BUFFER, coordinatesTextureName[0]);
    gl.glUniform1i(uniformLocation, textureUnit);
}
 
Example 16
Source File: Gl_320_test_scissor.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Vec3 minScissor = new Vec3(10000.f, 10000.f, 10000.f);
    Vec3 maxScissor = new Vec3(-10000.f, -10000.f, -10000.f);

    {
        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 view = viewMat4();
        Mat4 model = new Mat4(1.0f);

        pointer.asFloatBuffer().put(projection.mul_(view).mul(model).toFa_());

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

        for (int i = 0; i < vertexCount; ++i) {

            Vec3 projected = glm.project_(
                    new Vec3(vertexData[i * 4 + 0], vertexData[i * 4 + 1], 0.0f),
                    view.mul_(model),
                    projection,
                    new Vec4(0, 0, windowSize.x, windowSize.y));

            minScissor.min(projected);
            maxScissor.max(projected);
        }
    }

    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.glScissor((int) minScissor.x, (int) minScissor.y, (int) (maxScissor.x - minScissor.x),
            (int) (maxScissor.y - minScissor.y));
    gl3.glEnable(GL_SCISSOR_TEST);
    clearColor.put(new float[]{0.0f, 0.0f, 0.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);

    gl3.glDisable(GL_SCISSOR_TEST);

    return true;
}
 
Example 17
Source File: LineBatcher.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) {

    if (batch.isDrawable()) {
        // Uniform variables
        gl.glUseProgram(lineShader);
        if (drawForHitTest) {
            gl.glUniform1i(lineShaderLocDrawHitTest, GL3.GL_TRUE);
            gl.glUniform1f(lineShaderDirectionMotion, -1);
        } else {
            gl.glUniform1i(lineShaderLocDrawHitTest, GL3.GL_FALSE);
            gl.glUniform1f(lineShaderDirectionMotion, motion);
        }
        gl.glUniformMatrix4fv(lineShaderMVMatrix, 1, false, mvMatrix.a, 0);
        gl.glUniformMatrix4fv(lineShaderPMatrix, 1, false, pMatrix.a, 0);
        gl.glUniform1f(lineShaderVisibilityLow, camera.getVisibilityLow());
        gl.glUniform1f(lineShaderVisibilityHigh, camera.getVisibilityHigh());
        gl.glUniform1f(lineShaderMorphMix, camera.getMix());
        gl.glUniform1i(lineShaderXyzTexture, TextureUnits.VERTICES);
        gl.glUniform1f(lineShaderAlpha, opacity);
        gl.glUniform4fv(lineShaderHighlightColor, 1, highlightColor, 0);
        batch.draw(gl);

        gl.glUseProgram(lineLineShader);
        if (drawForHitTest) {
            gl.glUniform1i(lineLineShaderLocDrawHitTest, GL3.GL_TRUE);
            gl.glUniform1f(lineLineShaderDirectionMotion, -1);
        } else {
            gl.glUniform1i(lineLineShaderLocDrawHitTest, GL3.GL_FALSE);
            gl.glUniform1f(lineLineShaderDirectionMotion, motion);
        }
        gl.glUniformMatrix4fv(lineLineShaderMVMatrix, 1, false, mvMatrix.a, 0);
        gl.glUniformMatrix4fv(lineLineShaderPMatrix, 1, false, pMatrix.a, 0);
        gl.glUniform1f(lineLineShaderVisibilityLow, camera.getVisibilityLow());
        gl.glUniform1f(lineLineShaderVisibilityHigh, camera.getVisibilityHigh());
        gl.glUniform1f(lineLineShaderMorphMix, camera.getMix());
        gl.glUniform1i(lineLineShaderXyzTexture, TextureUnits.VERTICES);
        gl.glUniform1f(lineLineShaderAlpha, opacity);
        gl.glUniform4fv(lineLineShaderHighlightColor, 1, highlightColor, 0);
        batch.draw(gl);
    }
    drawForHitTest = false;
}
 
Example 18
Source File: Gl_330_sampler_filter.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, 1000.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glScissor(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1));

    // Bind the program for use
    gl3.glUseProgram(programName);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glBindSampler(Viewport.V00, samplerName.get(Viewport.V00));
    gl3.glBindSampler(Viewport.V10, samplerName.get(Viewport.V10));
    gl3.glBindSampler(Viewport.V11, samplerName.get(Viewport.V11));
    gl3.glBindSampler(Viewport.V01, samplerName.get(Viewport.V01));

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glActiveTexture(GL_TEXTURE1);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glActiveTexture(GL_TEXTURE2);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glActiveTexture(GL_TEXTURE3);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    for (int index = 0; index < Viewport.MAX; ++index) {
        gl3.glUniform1i(uniformDiffuse, index);
        gl3.glScissor(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w);
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
    }

    return true;
}
 
Example 19
Source File: Gl_320_fbo_multisample_explicit.java    From jogl-samples with MIT License 4 votes vote down vote up
private void resolveMultisampling(GL3 gl3) {

        Mat4 perspective = glm.ortho_(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 100.0f);
        Mat4 viewFlip = new Mat4(1.0f).scale(new Vec3(1.0f, -1.0f, 1.0f));
        Mat4 view = viewFlip.translate(new Vec3(0.0f, 0.0f, -cameraDistance() * 1.0f));
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = perspective.mul(view).mul(model);

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

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureName.get(Texture.MULTISAMPLE_COLORBUFFER));

        gl3.glBindVertexArray(vertexArrayName.get(0));

        gl3.glEnable(GL_SCISSOR_TEST);

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

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

            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

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

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

            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5);
        }

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

    GL3 gl3 = (GL3) gl;

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);

    // Pass 1
    gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
    gl3.glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);
    gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.5f, 1.0f, 1.0f}, 0);
    renderFBO(gl3);

    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // Generate FBO mipmaps
    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER));
    gl3.glGenerateMipmap(GL_TEXTURE_2D);
    gl3.glBindTexture(GL_TEXTURE_2D, 0);

    // Blit framebuffers
    int border = 2;
    int tile = 4;
    gl3.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER));
    gl3.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
    gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0);

    for (int j = 0; j < tile; ++j) {
        for (int i = 0; i < tile; ++i) {
            if (((i + j) % 2) != 0) {
                continue;
            }

            gl3.glBlitFramebuffer(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
                    FRAMEBUFFER_SIZE.x / tile * (i + 0) + border,
                    FRAMEBUFFER_SIZE.x / tile * (j + 0) + border,
                    FRAMEBUFFER_SIZE.y / tile * (i + 1) - border,
                    FRAMEBUFFER_SIZE.y / tile * (j + 1) - border,
                    GL_COLOR_BUFFER_BIT, GL_LINEAR);
        }
    }

    // Pass 2
    gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0);
    renderFB(gl3);

    return true;
}