diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index d7e0df101..4418d67f0 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -614,49 +614,51 @@ public class PJOGL extends PGL { @Override protected void beginGL() { - if (projMatrix == null) { - projMatrix = new float[16]; - } - gl2x.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - projMatrix[ 0] = pg.projection.m00; - projMatrix[ 1] = pg.projection.m10; - projMatrix[ 2] = pg.projection.m20; - projMatrix[ 3] = pg.projection.m30; - projMatrix[ 4] = pg.projection.m01; - projMatrix[ 5] = pg.projection.m11; - projMatrix[ 6] = pg.projection.m21; - projMatrix[ 7] = pg.projection.m31; - projMatrix[ 8] = pg.projection.m02; - projMatrix[ 9] = pg.projection.m12; - projMatrix[10] = pg.projection.m22; - projMatrix[11] = pg.projection.m32; - projMatrix[12] = pg.projection.m03; - projMatrix[13] = pg.projection.m13; - projMatrix[14] = pg.projection.m23; - projMatrix[15] = pg.projection.m33; - gl2x.glLoadMatrixf(projMatrix, 0); + if (gl2x != null) { + if (projMatrix == null) { + projMatrix = new float[16]; + } + gl2x.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + projMatrix[ 0] = pg.projection.m00; + projMatrix[ 1] = pg.projection.m10; + projMatrix[ 2] = pg.projection.m20; + projMatrix[ 3] = pg.projection.m30; + projMatrix[ 4] = pg.projection.m01; + projMatrix[ 5] = pg.projection.m11; + projMatrix[ 6] = pg.projection.m21; + projMatrix[ 7] = pg.projection.m31; + projMatrix[ 8] = pg.projection.m02; + projMatrix[ 9] = pg.projection.m12; + projMatrix[10] = pg.projection.m22; + projMatrix[11] = pg.projection.m32; + projMatrix[12] = pg.projection.m03; + projMatrix[13] = pg.projection.m13; + projMatrix[14] = pg.projection.m23; + projMatrix[15] = pg.projection.m33; + gl2x.glLoadMatrixf(projMatrix, 0); - if (mvMatrix == null) { - mvMatrix = new float[16]; + if (mvMatrix == null) { + mvMatrix = new float[16]; + } + gl2x.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + mvMatrix[ 0] = pg.modelview.m00; + mvMatrix[ 1] = pg.modelview.m10; + mvMatrix[ 2] = pg.modelview.m20; + mvMatrix[ 3] = pg.modelview.m30; + mvMatrix[ 4] = pg.modelview.m01; + mvMatrix[ 5] = pg.modelview.m11; + mvMatrix[ 6] = pg.modelview.m21; + mvMatrix[ 7] = pg.modelview.m31; + mvMatrix[ 8] = pg.modelview.m02; + mvMatrix[ 9] = pg.modelview.m12; + mvMatrix[10] = pg.modelview.m22; + mvMatrix[11] = pg.modelview.m32; + mvMatrix[12] = pg.modelview.m03; + mvMatrix[13] = pg.modelview.m13; + mvMatrix[14] = pg.modelview.m23; + mvMatrix[15] = pg.modelview.m33; + gl2x.glLoadMatrixf(mvMatrix, 0); } - gl2x.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - mvMatrix[ 0] = pg.modelview.m00; - mvMatrix[ 1] = pg.modelview.m10; - mvMatrix[ 2] = pg.modelview.m20; - mvMatrix[ 3] = pg.modelview.m30; - mvMatrix[ 4] = pg.modelview.m01; - mvMatrix[ 5] = pg.modelview.m11; - mvMatrix[ 6] = pg.modelview.m21; - mvMatrix[ 7] = pg.modelview.m31; - mvMatrix[ 8] = pg.modelview.m02; - mvMatrix[ 9] = pg.modelview.m12; - mvMatrix[10] = pg.modelview.m22; - mvMatrix[11] = pg.modelview.m32; - mvMatrix[12] = pg.modelview.m03; - mvMatrix[13] = pg.modelview.m13; - mvMatrix[14] = pg.modelview.m23; - mvMatrix[15] = pg.modelview.m33; - gl2x.glLoadMatrixf(mvMatrix, 0); } @@ -1631,7 +1633,9 @@ public class PJOGL extends PGL { @Override public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { - gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); + if (gl2x != null) { + gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); + } } @Override @@ -1656,7 +1660,9 @@ public class PJOGL extends PGL { @Override public void drawElements(int mode, int count, int type, Buffer indices) { - gl2x.glDrawElements(mode, count, type, indices); + if (gl2x != null) { + gl2x.glDrawElements(mode, count, type, indices); + } } ////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index 652d93c97..4dcdc12cd 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -59,6 +59,9 @@ public class PShader implements PConstants { protected PGL pgl; protected int context; // The context that created this shader. + // The shader type: POINT, LINE, POLY, etc. + protected int type; + public int glProgram; public int glVertex; public int glFragment; @@ -83,9 +86,7 @@ public class PShader implements PConstants { protected IntBuffer intBuffer; protected FloatBuffer floatBuffer; - - - protected int type; + // Uniforms common to all shader types protected int transformMatLoc; protected int modelviewMatLoc; protected int projectionMatLoc; @@ -93,20 +94,11 @@ public class PShader implements PConstants { protected int bufferUnit; protected int viewportLoc; - protected int vertexLoc; - protected int colorLoc; - protected int normalLoc; - protected int texCoordLoc; - protected int normalMatLoc; - - // For lines + // Uniforms only for lines and points protected int perspectiveLoc; protected int scaleLoc; - protected int directionLoc; - - // For points - protected int offsetLoc; + // Lighting uniforms protected int lightCountLoc; protected int lightPositionLoc; protected int lightNormalLoc; @@ -116,21 +108,27 @@ public class PShader implements PConstants { protected int lightFalloffLoc; protected int lightSpotLoc; + // Texturing uniforms + protected Texture texture; + protected int texUnit; + protected int textureLoc; + protected int texMatrixLoc; + protected int texOffsetLoc; + protected float[] tcmat; + + // Vertex attributes + protected int vertexLoc; + protected int colorLoc; + protected int normalLoc; + protected int texCoordLoc; + protected int normalMatLoc; + protected int directionLoc; + protected int offsetLoc; protected int ambientLoc; protected int specularLoc; protected int emissiveLoc; protected int shininessLoc; - protected Texture texture; - protected int texUnit; - - protected int textureLoc; - protected int texMatrixLoc; - protected int texOffsetLoc; - - protected float[] tcmat; - - public PShader() { parent = null; pgl = null; @@ -470,14 +468,16 @@ public class PShader implements PConstants { } - - protected boolean setup() { - - return true; + /** + * Extra initialization method that can be used by subclasses, called after + * compiling and attaching the vertex and fragment shaders, and before + * linking the shader program. + * + */ + protected void setup() { } - /** * Returns the ID location of the attribute parameter given its name. *