Search in sources :

Example 1 with GLException

use of javax.media.opengl.GLException in project spaceships-demo by puniverse.

the class ProgramState method getLocation.

private int getLocation(GL3 gl, String attributeName) {
    Integer index = attributes.get(attributeName);
    if (index == null) {
        index = gl.glGetUniformLocation(shader.program(), attributeName);
        if (index < 0)
            throw new GLException("Attribute " + attributeName + " not found");
        attributes.put(attributeName, index);
    }
    return index;
}
Also used : GLException(javax.media.opengl.GLException)

Example 2 with GLException

use of javax.media.opengl.GLException in project spaceships-demo by puniverse.

the class UBO method getInfo.

private Info getInfo(GL3 gl, String uniformName) {
    Info info = attributes.get(uniformName);
    if (info == null) {
        int[] tmp = new int[1];
        gl.glGetUniformIndices(shader.program(), 1, new String[] { blockName + "." + uniformName }, tmp, 0);
        final int index = tmp[0];
        if (index < 0)
            throw new GLException("Uniform " + blockName + "." + uniformName + " not found");
        final int[] indices = new int[] { index };
        gl.glGetActiveUniformsiv(shader.program(), 1, indices, 0, gl.GL_UNIFORM_OFFSET, tmp, 0);
        final int offset = tmp[0];
        gl.glGetActiveUniformsiv(shader.program(), 1, indices, 0, gl.GL_UNIFORM_TYPE, tmp, 0);
        final int type = tmp[0];
        gl.glGetActiveUniformsiv(shader.program(), 1, indices, 0, gl.GL_UNIFORM_SIZE, tmp, 0);
        final int size = tmp[0];
        info = new Info(offset, type, size);
        attributes.put(uniformName, info);
    }
    return info;
}
Also used : GLException(javax.media.opengl.GLException)

Example 3 with GLException

use of javax.media.opengl.GLException in project spaceships-demo by puniverse.

the class GLPort method init.

@Override
public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
    final GL3 gl = drawable.getGL().getGL3();
    try {
        spaceshipTex = TextureIO.newTexture(TextureIO.newTextureData(GLProfile.get(GLProfile.GL3), ClassLoader.getSystemResourceAsStream("spaceship.png"), false, "png"));
        explosionTex = TextureIO.newTexture(TextureIO.newTextureData(GLProfile.get(GLProfile.GL3), ClassLoader.getSystemResourceAsStream("explosion.png"), false, "png"));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    drawableWidth = drawable.getSurfaceWidth();
    drawableHeight = drawable.getSurfaceHeight();
    port.min(X, -drawable.getSurfaceWidth() / 2);
    port.max(X, drawable.getSurfaceWidth() / 2);
    port.min(Y, -drawable.getSurfaceHeight() / 2);
    port.max(Y, drawable.getSurfaceHeight() / 2);
    //gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE);
    gl.glViewport(0, 0, (int) (port.max(X) - port.min(X)), (int) (port.max(Y) - port.min(Y)));
    gl.glClearColor(0, 0, 0, 1);
    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);
    ShaderCode vertexShader = ShaderCode.create(gl, GL3.GL_VERTEX_SHADER, this.getClass(), "shader", null, "vertex", false);
    ShaderCode geometryShader = ShaderCode.create(gl, GL3.GL_GEOMETRY_SHADER, this.getClass(), "shader", null, "geometry", false);
    ShaderCode fragmentShader = ShaderCode.create(gl, GL3.GL_FRAGMENT_SHADER, this.getClass(), "shader", null, "fragment", false);
    if (!vertexShader.compile(gl, System.err))
        throw new GLException("Couldn't compile shader: " + vertexShader);
    if (!geometryShader.compile(gl, System.err))
        throw new GLException("Couldn't compile shader: " + geometryShader);
    if (!fragmentShader.compile(gl, System.err))
        throw new GLException("Couldn't compile shader: " + fragmentShader);
    shaderProgram = new ShaderProgram();
    shaderProgram.add(gl, vertexShader, System.err);
    shaderProgram.add(gl, geometryShader, System.err);
    shaderProgram.add(gl, fragmentShader, System.err);
    if (!shaderProgram.link(gl, System.err))
        throw new GLException("Couldn't link program: " + shaderProgram);
    this.shaderState = new ProgramState(gl, shaderProgram);
    shaderState.bind(gl);
    pmv.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmv.glLoadIdentity();
    this.vao = shaderState.createVAO(gl);
    vao.bind(gl);
    this.vertices = new VBO(gl, 2, GL3.GL_FLOAT, false, maxItems, GL3.GL_DYNAMIC_DRAW);
    this.colors = new VBO(gl, 3, GL3.GL_FLOAT, false, maxItems, GL3.GL_DYNAMIC_DRAW);
    vao.setVertex(gl, "in_Position", vertices);
    vao.setVertex(gl, "in_Vertex", colors);
    shaderState.unbind(gl);
}
Also used : ShaderProgram(com.jogamp.opengl.util.glsl.ShaderProgram) GLException(javax.media.opengl.GLException) DebugGL3(javax.media.opengl.DebugGL3) IOException(java.io.IOException) GL3(javax.media.opengl.GL3) DebugGL3(javax.media.opengl.DebugGL3) ShaderCode(com.jogamp.opengl.util.glsl.ShaderCode)

Example 4 with GLException

use of javax.media.opengl.GLException in project spaceships-demo by puniverse.

the class UBO method verifySize.

private Info verifySize(GL3 gl, String uniformName, int size) {
    final Info info = getInfo(gl, uniformName);
    final int requiredSize = info.size * BO.sizeOfGLType(info.type);
    if (requiredSize != size)
        throw new GLException("Trying to write " + size + " bytes into uniform " + uniformName + " which is of size " + requiredSize);
    return info;
}
Also used : GLException(javax.media.opengl.GLException)

Example 5 with GLException

use of javax.media.opengl.GLException in project spaceships-demo by puniverse.

the class VAO method getLocation.

private int getLocation(GL3 gl, String attributeName) {
    Integer index = attributes.get(attributeName);
    if (index == null) {
        index = gl.glGetAttribLocation(shader.program(), attributeName);
        if (index < 0)
            throw new GLException("Attribute " + attributeName + " not found");
        attributes.put(attributeName, index);
    }
    return index;
}
Also used : GLException(javax.media.opengl.GLException)

Aggregations

GLException (javax.media.opengl.GLException)6 ShaderCode (com.jogamp.opengl.util.glsl.ShaderCode)1 ShaderProgram (com.jogamp.opengl.util.glsl.ShaderProgram)1 IOException (java.io.IOException)1 DoubleBuffer (java.nio.DoubleBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 IntBuffer (java.nio.IntBuffer)1 DebugGL3 (javax.media.opengl.DebugGL3)1 GL3 (javax.media.opengl.GL3)1