From b08534748543e7e5abec4ec0afb1c47f037f378a Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Wed, 23 Sep 2015 16:10:15 -0400 Subject: [PATCH] Add some GL3ES3 functions to PGL --- core/src/processing/opengl/PGL.java | 30 ++++++++++++++++ core/src/processing/opengl/PJOGL.java | 52 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 880194b5f..7f82f4f6f 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -2666,12 +2666,14 @@ public abstract class PGL { public static int ARRAY_BUFFER; public static int ELEMENT_ARRAY_BUFFER; + public static int PIXEL_PACK_BUFFER; public static int MAX_VERTEX_ATTRIBS; public static int STATIC_DRAW; public static int DYNAMIC_DRAW; public static int STREAM_DRAW; + public static int STREAM_READ; public static int BUFFER_SIZE; public static int BUFFER_USAGE; @@ -2886,6 +2888,10 @@ public abstract class PGL { public static int LINE_SMOOTH; public static int POLYGON_SMOOTH; + public static int SYNC_GPU_COMMANDS_COMPLETE; + public static int ALREADY_SIGNALED; + public static int CONDITION_SATISFIED; + /////////////////////////////////////////////////////////// // Special Functions @@ -2930,6 +2936,14 @@ public abstract class PGL { ////////////////////////////////////////////////////////////////////////////// + // Synchronization + + public abstract long fenceSync(int condition, int flags); + public abstract void deleteSync(long sync); + public abstract int clientWaitSync(long sync, int flags, long timeout); + + ////////////////////////////////////////////////////////////////////////////// + // Viewport and Clipping public abstract void depthRangef(float n, float f); @@ -2959,7 +2973,23 @@ public abstract class PGL { graphics.endReadPixels(); } + public void readPixels(int x, int y, int width, int height, int format, int type, long offset){ + boolean multisampled = isMultisampled() || graphics.offscreenMultisample; + boolean depthReadingEnabled = graphics.getHint(PConstants.ENABLE_BUFFER_READING); + boolean depthRequested = format == STENCIL_INDEX || format == DEPTH_COMPONENT || format == DEPTH_STENCIL; + + if (multisampled && depthRequested && !depthReadingEnabled) { + PGraphics.showWarning(DEPTH_READING_NOT_ENABLED_ERROR); + return; + } + + graphics.beginReadPixels(); + readPixelsImpl(x, y, width, height, format, type, offset); + graphics.endReadPixels(); + } + protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer); + protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, long offset); ////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 5b5ed498b..bad7f3721 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -44,6 +44,7 @@ import com.jogamp.opengl.GL2; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GL2ES3; import com.jogamp.opengl.GL2GL3; +import com.jogamp.opengl.GL3ES3; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLCapabilitiesImmutable; @@ -109,6 +110,9 @@ public class PJOGL extends PGL { * multisampled renderbuffers) */ protected GL2 gl2x; + /** GL3ES3 interface */ + protected GL3ES3 gl3es3; + /** Stores exceptions that ocurred during drawing */ protected Exception drawException; @@ -233,6 +237,7 @@ public class PJOGL extends PGL { this.gl2 = pjogl.gl2; this.gl2x = pjogl.gl2x; this.gl3 = pjogl.gl3; + this.gl3es3 = pjogl.gl3es3; } @@ -253,6 +258,11 @@ public class PJOGL extends PGL { } catch (com.jogamp.opengl.GLException e) { gl3 = null; } + try { + gl3es3 = gl.getGL3ES3(); + } catch (com.jogamp.opengl.GLException e) { + gl3es3 = null; + } } @@ -736,12 +746,14 @@ public class PJOGL extends PGL { ARRAY_BUFFER = GL.GL_ARRAY_BUFFER; ELEMENT_ARRAY_BUFFER = GL.GL_ELEMENT_ARRAY_BUFFER; + PIXEL_PACK_BUFFER = GL3ES3.GL_PIXEL_PACK_BUFFER; MAX_VERTEX_ATTRIBS = GL2ES2.GL_MAX_VERTEX_ATTRIBS; STATIC_DRAW = GL.GL_STATIC_DRAW; DYNAMIC_DRAW = GL.GL_DYNAMIC_DRAW; STREAM_DRAW = GL2ES2.GL_STREAM_DRAW; + STREAM_READ = GL3ES3.GL_STREAM_READ; BUFFER_SIZE = GL.GL_BUFFER_SIZE; BUFFER_USAGE = GL.GL_BUFFER_USAGE; @@ -956,6 +968,10 @@ public class PJOGL extends PGL { MULTISAMPLE = GL.GL_MULTISAMPLE; LINE_SMOOTH = GL.GL_LINE_SMOOTH; POLYGON_SMOOTH = GL2GL3.GL_POLYGON_SMOOTH; + + SYNC_GPU_COMMANDS_COMPLETE = GL3ES3.GL_SYNC_GPU_COMMANDS_COMPLETE; + ALREADY_SIGNALED = GL3ES3.GL_ALREADY_SIGNALED; + CONDITION_SATISFIED = GL3ES3.GL_CONDITION_SATISFIED; } /////////////////////////////////////////////////////////// @@ -1114,6 +1130,37 @@ public class PJOGL extends PGL { ////////////////////////////////////////////////////////////////////////////// + // Synchronization + + @Override + public long fenceSync(int condition, int flags) { + if (gl3es3 != null) { + return gl3es3.glFenceSync(condition, flags); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "fenceSync()")); + } + } + + @Override + public void deleteSync(long sync) { + if (gl3es3 != null) { + gl3es3.glDeleteSync(sync); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "deleteSync()")); + } + } + + @Override + public int clientWaitSync(long sync, int flags, long timeout) { + if (gl3es3 != null) { + return gl3es3.glClientWaitSync(sync, flags, timeout); + } else { + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "clientWaitSync()")); + } + } + + ////////////////////////////////////////////////////////////////////////////// + // Viewport and Clipping @Override @@ -1141,6 +1188,11 @@ public class PJOGL extends PGL { gl.glReadPixels(x, y, width, height, format, type, buffer); } + @Override + protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, long offset) { + gl.glReadPixels(x, y, width, height, format, type, 0); + } + ////////////////////////////////////////////////////////////////////////////// // Vertices