Search in sources :

Example 1 with GLException

use of com.jogamp.opengl.GLException in project artisynth_core by artisynth.

the class GLSLTextureRaster method init.

public void init(final GL2ES2 gl) {
    // Create & Compile the shader objects
    final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, jogamp.opengl.util.glsl.GLSLTextureRaster.class, shaderSrcPath, shaderBinPath, shaderBasename, true);
    final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, jogamp.opengl.util.glsl.GLSLTextureRaster.class, shaderSrcPath, shaderBinPath, shaderBasename, true);
    rsVp.defaultShaderCustomization(gl, true, true);
    rsFp.defaultShaderCustomization(gl, true, true);
    // Create & Link the shader program
    sp = new ShaderProgram();
    sp.add(rsVp);
    sp.add(rsFp);
    if (!sp.link(gl, System.err)) {
        throw new GLException("Couldn't link program: " + sp);
    }
    sp.useProgram(gl, true);
    // setup mgl_PMVMatrix
    pmvMatrix = new PMVMatrix();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    // P, Mv
    pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
    if (pmvMatrixUniform.setLocation(gl, sp.program()) < 0) {
        throw new GLException("Couldn't locate " + pmvMatrixUniform + " in shader: " + sp);
    }
    gl.glUniform(pmvMatrixUniform);
    activeTexUniform = new GLUniformData("mgl_Texture0", textureUnit);
    if (activeTexUniform.setLocation(gl, sp.program()) < 0) {
        throw new GLException("Couldn't locate " + activeTexUniform + " in shader: " + sp);
    }
    gl.glUniform(activeTexUniform);
    final float[] s_quadTexCoords;
    if (textureVertFlipped) {
        s_quadTexCoords = s_quadTexCoords01;
    } else {
        s_quadTexCoords = s_quadTexCoords00;
    }
    interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 2, GL.GL_FLOAT, false, 2 * 4, GL.GL_STATIC_DRAW);
    {
        final GLArrayData vArrayData = interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
        if (vArrayData.setLocation(gl, sp.program()) < 0) {
            throw new GLException("Couldn't locate " + vArrayData + " in shader: " + sp);
        }
        final GLArrayData tArrayData = interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);
        if (tArrayData.setLocation(gl, sp.program()) < 0) {
            throw new GLException("Couldn't locate " + tArrayData + " in shader: " + sp);
        }
        final FloatBuffer ib = (FloatBuffer) interleavedVBO.getBuffer();
        for (int i = 0; i < 4; i++) {
            ib.put(s_quadVertices, i * 3, 3);
            ib.put(s_quadTexCoords, i * 2, 2);
        }
    }
    interleavedVBO.seal(gl, true);
    interleavedVBO.enableBuffer(gl, false);
    sp.useProgram(gl, false);
}
Also used : ShaderProgram(com.jogamp.opengl.util.glsl.ShaderProgram) GLException(com.jogamp.opengl.GLException) GLArrayData(com.jogamp.opengl.GLArrayData) FloatBuffer(java.nio.FloatBuffer) PMVMatrix(com.jogamp.opengl.util.PMVMatrix) GLUniformData(com.jogamp.opengl.GLUniformData) ShaderCode(com.jogamp.opengl.util.glsl.ShaderCode)

Example 2 with GLException

use of com.jogamp.opengl.GLException in project processing by processing.

the class PSurfaceJOGL method initGL.

protected void initGL() {
    //  System.out.println("*******************************");
    if (profile == null) {
        if (PJOGL.profile == 1) {
            try {
                profile = GLProfile.getGL2ES1();
            } catch (GLException ex) {
                profile = GLProfile.getMaxFixedFunc(true);
            }
        } else if (PJOGL.profile == 2) {
            try {
                profile = GLProfile.getGL2ES2();
            } catch (GLException ex) {
                profile = GLProfile.getMaxProgrammable(true);
            }
        } else if (PJOGL.profile == 3) {
            try {
                profile = GLProfile.getGL2GL3();
            } catch (GLException ex) {
                profile = GLProfile.getMaxProgrammable(true);
            }
            if (!profile.isGL3()) {
                PGraphics.showWarning("Requested profile GL3 but is not available, got: " + profile);
            }
        } else if (PJOGL.profile == 4) {
            try {
                profile = GLProfile.getGL4ES3();
            } catch (GLException ex) {
                profile = GLProfile.getMaxProgrammable(true);
            }
            if (!profile.isGL4()) {
                PGraphics.showWarning("Requested profile GL4 but is not available, got: " + profile);
            }
        } else
            throw new RuntimeException(PGL.UNSUPPORTED_GLPROF_ERROR);
    }
    // Setting up the desired capabilities;
    GLCapabilities caps = new GLCapabilities(profile);
    caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
    caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
    caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
    //  caps.setPBuffer(false);
    //  caps.setFBO(false);
    //    pgl.reqNumSamples = PGL.smoothToSamples(graphics.smooth);
    caps.setSampleBuffers(true);
    caps.setNumSamples(PGL.smoothToSamples(graphics.smooth));
    caps.setBackgroundOpaque(true);
    caps.setOnscreen(true);
    pgl.setCaps(caps);
}
Also used : GLCapabilities(com.jogamp.opengl.GLCapabilities) GLException(com.jogamp.opengl.GLException)

Example 3 with GLException

use of com.jogamp.opengl.GLException in project artisynth_core by artisynth.

the class GLJPanel method setSurfaceScale.

@Override
public final boolean setSurfaceScale(final float[] pixelScale) {
    // HiDPI
    // support
    System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2);
    final Backend b = backend;
    if (isInitialized && null != b && isShowing) {
        if (isShowing || (printActive && isVisible())) {
            if (EventQueue.isDispatchThread()) {
                setSurfaceScaleAction.run();
            } else {
                try {
                    EventQueue.invokeAndWait(setSurfaceScaleAction);
                } catch (final Exception e) {
                    throw new GLException(e);
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : GLException(com.jogamp.opengl.GLException) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) GLException(com.jogamp.opengl.GLException)

Aggregations

GLException (com.jogamp.opengl.GLException)3 GLArrayData (com.jogamp.opengl.GLArrayData)1 GLCapabilities (com.jogamp.opengl.GLCapabilities)1 GLUniformData (com.jogamp.opengl.GLUniformData)1 PMVMatrix (com.jogamp.opengl.util.PMVMatrix)1 ShaderCode (com.jogamp.opengl.util.glsl.ShaderCode)1 ShaderProgram (com.jogamp.opengl.util.glsl.ShaderProgram)1 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)1 FloatBuffer (java.nio.FloatBuffer)1