Search in sources :

Example 1 with PMVMatrix

use of com.jogamp.opengl.util.PMVMatrix 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)

Aggregations

GLArrayData (com.jogamp.opengl.GLArrayData)1 GLException (com.jogamp.opengl.GLException)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 FloatBuffer (java.nio.FloatBuffer)1