From 11fd3c0a98890c41ad537bb07c1716dd2d1b9d4d Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 20 Oct 2013 19:33:39 -0400 Subject: [PATCH] getting GL3 profile to work properly --- core/src/processing/opengl/PGL.java | 7 ++- core/src/processing/opengl/PJOGL.java | 90 ++++++++++++++------------- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 26d57e1fe..4f5ff409f 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -284,6 +284,9 @@ public abstract class PGL { protected static final String MISSING_GLFUNC_ERROR = "GL function %1$s is not available on this hardware (or driver)" + WIKI; + protected static final String UNSUPPORTED_GLPROF_ERROR = + "Unsupported OpenGL profile."; + protected static final String TEXUNIT_ERROR = "Number of texture units not supported by this hardware (or driver)" + WIKI; @@ -2421,12 +2424,12 @@ public abstract class PGL { public abstract void vertexAttrib3fv(int index, FloatBuffer values); public abstract void vertexAttri4fv(int index, FloatBuffer values); public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset); - //public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data); + public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data); public abstract void enableVertexAttribArray(int index); public abstract void disableVertexAttribArray(int index); public abstract void drawArrays(int mode, int first, int count); public abstract void drawElements(int mode, int count, int type, int offset); - //public abstract void drawElements(int mode, int count, int type, Buffer indices); + public abstract void drawElements(int mode, int count, int type, Buffer indices); ////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 72824a3cf..bd1988733 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -17,7 +17,6 @@ import javax.media.opengl.GL2ES1; import javax.media.opengl.GL2ES2; import javax.media.opengl.GL2ES3; import javax.media.opengl.GL2GL3; -import javax.media.opengl.GL3bc; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; @@ -138,8 +137,8 @@ public class PJOGL extends PGL { /** GLES2 functionality (shaders, etc) */ protected static GL2ES2 gl2; - /** GL3 with backward compatibility */ - protected static GL3bc gl3bc; + /** GL3 interface */ + protected static GL2GL3 gl3; /** GL2 desktop functionality (blit framebuffer, map buffer range, * multisampled renerbuffers) */ @@ -239,7 +238,7 @@ public class PJOGL extends PGL { } else if (PROFILE == 4) { profile = GLProfile.getGL4ES3(); shaderSource = 1; - } else throw new RuntimeException("Unsupported profile."); + } else throw new RuntimeException(UNSUPPORTED_GLPROF_ERROR); System.out.println(profile); } else { // Restarting... @@ -639,12 +638,11 @@ public class PJOGL extends PGL { @Override protected void beginGL() { - GL2 glfixfunc = gl2x != null ? gl2x : gl3bc; - if (glfixfunc != null) { + if (gl2x != null) { if (projMatrix == null) { projMatrix = new float[16]; } - glfixfunc.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + gl2x.glMatrixMode(GLMatrixFunc.GL_PROJECTION); projMatrix[ 0] = pg.projection.m00; projMatrix[ 1] = pg.projection.m10; projMatrix[ 2] = pg.projection.m20; @@ -661,12 +659,12 @@ public class PJOGL extends PGL { projMatrix[13] = pg.projection.m13; projMatrix[14] = pg.projection.m23; projMatrix[15] = pg.projection.m33; - glfixfunc.glLoadMatrixf(projMatrix, 0); + gl2x.glLoadMatrixf(projMatrix, 0); if (mvMatrix == null) { mvMatrix = new float[16]; } - glfixfunc.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + gl2x.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); mvMatrix[ 0] = pg.modelview.m00; mvMatrix[ 1] = pg.modelview.m10; mvMatrix[ 2] = pg.modelview.m20; @@ -683,7 +681,7 @@ public class PJOGL extends PGL { mvMatrix[13] = pg.modelview.m13; mvMatrix[14] = pg.modelview.m23; mvMatrix[15] = pg.modelview.m33; - glfixfunc.glLoadMatrixf(mvMatrix, 0); + gl2x.glLoadMatrixf(mvMatrix, 0); } } @@ -820,15 +818,15 @@ public class PJOGL extends PGL { gl2x = null; } try { - gl3bc = gl.getGL3bc(); + gl3 = gl.getGL2GL3(); } catch (javax.media.opengl.GLException e) { - gl3bc = null; + gl3 = null; } System.out.println("************"); System.out.println("gl: " + gl); System.out.println("gl2: " + gl2); System.out.println("gl2x: " + gl2x); - System.out.println("gl3: " + gl3bc); + System.out.println("gl3: " + gl3); } } @@ -1609,10 +1607,10 @@ public class PJOGL extends PGL { public ByteBuffer mapBufferRange(int target, int offset, int length, int access) { if (gl2x != null) { return gl2x.glMapBufferRange(target, offset, length, access); - } else if (gl3bc != null) { - return gl3bc.glMapBufferRange(target, offset, length, access); + } else if (gl3 != null) { + return gl3.glMapBufferRange(target, offset, length, access); } else { - return null; + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glMapBufferRange()")); } } @@ -1693,14 +1691,14 @@ public class PJOGL extends PGL { gl2.glVertexAttribPointer(index, size, type, normalized, stride, offset); } -// @Override -// public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { -// if (gl2x != null) { -// gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); -// } else if (gl3bc != null) { -// gl3bc.glVertexAttribPointer(index, size, type, normalized, stride, data); -// } -// } + @Override + public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { + if (gl2x != null) { + gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glVertexAttribPointer()")); + } + } @Override public void enableVertexAttribArray(int index) { @@ -1722,14 +1720,14 @@ public class PJOGL extends PGL { gl.glDrawElements(mode, count, type, offset); } -// @Override -// public void drawElements(int mode, int count, int type, Buffer indices) { -// if (gl2x != null) { -// gl2x.glDrawElements(mode, count, type, indices); -// } else if (gl3bc != null) { -// gl3bc.glDrawElements(mode, count, type, indices); -// } -// } + @Override + public void drawElements(int mode, int count, int type, Buffer indices) { + if (gl2x != null) { + gl2x.glDrawElements(mode, count, type, indices); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glDrawElements()")); + } + } ////////////////////////////////////////////////////////////////////////////// @@ -2216,8 +2214,8 @@ public class PJOGL extends PGL { public void alphaFunc(int func, float ref) { if (gl2x != null) { gl2x.glAlphaFunc(func, ref); - } else if (gl3bc != null) { - gl3bc.glAlphaFunc(func, ref); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glAlphaFunc()")); } } @@ -2343,8 +2341,10 @@ public class PJOGL extends PGL { public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { if (gl2x != null) { gl2x.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); - } else if (gl3bc != null) { - gl3bc.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); + } else if (gl3 != null) { + gl3.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glBlitFramebuffer()")); } } @@ -2352,8 +2352,10 @@ public class PJOGL extends PGL { public void renderbufferStorageMultisample(int target, int samples, int format, int width, int height) { if (gl2x != null) { gl2x.glRenderbufferStorageMultisample(target, samples, format, width, height); - } else if (gl3bc != null) { - gl3bc.glRenderbufferStorageMultisample(target, samples, format, width, height); + } else if (gl3 != null) { + gl3.glRenderbufferStorageMultisample(target, samples, format, width, height); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glRenderbufferStorageMultisample()")); } } @@ -2361,8 +2363,10 @@ public class PJOGL extends PGL { public void readBuffer(int buf) { if (gl2x != null) { gl2x.glReadBuffer(buf); - } else if (gl3bc != null) { - gl3bc.glReadBuffer(buf); + } else if (gl3 != null) { + gl3.glReadBuffer(buf); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glReadBuffer()")); } } @@ -2370,8 +2374,10 @@ public class PJOGL extends PGL { public void drawBuffer(int buf) { if (gl2x != null) { gl2x.glDrawBuffer(buf); - } else if (gl3bc != null) { - gl3bc.glDrawBuffer(buf); + } else if (gl3 != null) { + gl3.glDrawBuffer(buf); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glDrawBuffer()")); } } }