From bdbc77a6cbffd552cd943a9c9b52fb95534004f3 Mon Sep 17 00:00:00 2001 From: Benjamin Maus Date: Fri, 17 May 2013 23:38:25 +0200 Subject: [PATCH 01/46] Fixed: When using the PGraphicsOpenGL renderer Processing would allocate a texture with the maximum allowed width (e.g. 8192x512 pixels for a 10px font) for each font. This lead to severe GPU memory problems, especially when using multiple fonts. Merge doubled code. --- core/src/processing/opengl/PGraphicsOpenGL.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8f2fb3e8a..28936fe5c 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3276,18 +3276,14 @@ public class PGraphicsOpenGL extends PGraphics { protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { textTex = pgPrimary.getFontTexture(textFont); - if (textTex == null) { - textTex = new FontTexture(pgPrimary, textFont, maxTextureSize, - maxTextureSize, is3D()); - pgPrimary.setFontTexture(textFont, textTex); - } else { - if (textTex.contextIsOutdated()) { - textTex = new FontTexture(pgPrimary, textFont, + + if (textTex == null || textTex.contextIsOutdated()) { + textTex = new FontTexture(pgPrimary, textFont, PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); - pgPrimary.setFontTexture(textFont, textTex); - } + pgPrimary.setFontTexture(textFont, textTex); } + textTex.begin(); // Saving style parameters modified by text rendering. From dea8e9dd166ccdcd4b914d11538477d0c07eeaa0 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 11:04:30 -0400 Subject: [PATCH 02/46] Smaller displacement for lines (issue #1790) --- core/src/processing/opengl/PGL.java | 4 ++++ core/src/processing/opengl/PGraphicsOpenGL.java | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 6e350e398..c2b2bd5c4 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -125,6 +125,10 @@ public class PGL { /** Minimum array size to use arrayCopy method(). **/ protected static final int MIN_ARRAYCOPY_SIZE = 2; + /** Factor used to displace the stroke vertices towards the camera in + * order to make sure the lines are always on top of the fill geometry **/ + protected static final float STROKE_DISPLACEMENT = 0.999f; + /** JOGL's windowing toolkit */ // The two windowing toolkits available to use in JOGL: protected static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 5bdab92de..08b04f175 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -7149,10 +7149,11 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent.getHint(DISABLE_OPTIMIZED_STROKE)) { setUniformValue(scaleLoc, 1.0f, 1.0f, 1.0f); } else { + float f = PGL.STROKE_DISPLACEMENT; if (orthoProjection()) { - setUniformValue(scaleLoc, 1.0f, 1.0f, 0.99f); + setUniformValue(scaleLoc, 1, 1, f); } else { - setUniformValue(scaleLoc, 0.99f, 0.99f, 0.99f); + setUniformValue(scaleLoc, f, f, f); } } From a96e68a497fa58497f09ab2b931d3bed5ee061ad Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 11:11:26 -0400 Subject: [PATCH 03/46] Added STROKE_DISPLACEMENT to PGL in LWJGL --- java/libraries/lwjgl/src/processing/lwjgl/PGL.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index feb5400d0..338a18d54 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -131,6 +131,10 @@ public class PGL extends processing.opengl.PGL { /** Minimum array size to use arrayCopy method(). **/ protected static final int MIN_ARRAYCOPY_SIZE = 2; + /** Factor used to displace the stroke vertices towards the camera in + * order to make sure the lines are always on top of the fill geometry **/ + protected static final float STROKE_DISPLACEMENT = 0.999f; + protected static int request_depth_bits = 24; protected static int request_stencil_bits = 8; protected static int request_alpha_bits = 8; From 423e59e934148612fac683fa5633aca70359f794 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 22 May 2013 10:58:55 -0700 Subject: [PATCH 04/46] Fixes processing/processing-web#138 --- core/src/processing/core/PVector.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index 2a631449a..9f04977c5 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -543,8 +543,7 @@ public class PVector implements Serializable { * @webref pvector:method * @usage web_application * @param n the number to multiply with the vector - * @brief Multiply a vector by a scalar or one vector by another - * @nowebref + * @brief Multiply a vector by a scalar */ public void mult(float n) { x *= n; @@ -588,8 +587,7 @@ public class PVector implements Serializable { * @webref pvector:method * @usage web_application * @param n the value to divide by - * @brief Divide a vector by a scalar or one vector by another - * @nowebref + * @brief Divide a vector by a scalar */ public void div(float n) { x /= n; From c5017babaa4df5db5f909344475f3939393d4693 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 14:48:01 -0400 Subject: [PATCH 05/46] Fixes issues #1805 and #1806 --- core/src/processing/opengl/PShapeOpenGL.java | 148 +++++++++++++------ 1 file changed, 105 insertions(+), 43 deletions(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 9d0475a41..e58d3d598 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -182,15 +182,6 @@ public class PShapeOpenGL extends PShape { // ........................................................ - // Modes inherited from renderer - - protected int rectMode; - protected int ellipseMode; - protected int shapeMode; - protected int imageMode; - - // ........................................................ - // Bezier and Catmull-Rom curves protected int bezierDetail = 20; @@ -307,12 +298,8 @@ public class PShapeOpenGL extends PShape { inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED); } - // Modes are retrieved from the current values in the renderer. + // Style parameters are retrieved from the current values in the renderer. textureMode = pg.textureMode; - rectMode = pg.rectMode; - ellipseMode = pg.ellipseMode; - shapeMode = pg.shapeMode; - imageMode = pg.imageMode; colorMode(pg.colorMode, pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA); @@ -757,10 +744,25 @@ public class PShapeOpenGL extends PShape { if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.textureMode(mode); + child.setTextureMode(mode); } } else { - textureMode = mode; + setTextureModeImpl(mode); + } + } + + + protected void setTextureModeImpl(int mode) { + if (textureMode == mode) return; + textureMode = mode; + if (image != null) { + float uFactor = image.width; + float vFactor = image.height; + if (textureMode == NORMAL) { + uFactor = 1.0f / uFactor; + vFactor = 1.0f / vFactor; + } + scaleTextureUV(uFactor, vFactor); } } @@ -778,17 +780,69 @@ public class PShapeOpenGL extends PShape { child.texture(tex); } } else { - PImage tex0 = image; - image = tex; - if (tex0 != tex && parent != null) { - ((PShapeOpenGL)parent).removeTexture(tex); + setTextureImpl(tex); + } + } + + + protected void setTextureImpl(PImage tex) { + PImage image0 = image; + image = tex; + + if (textureMode == IMAGE && image0 != image) { + // Need to rescale the texture coordinates + float uFactor = 1; + float vFactor = 1; + if (image != null) { + uFactor /= image.width; + vFactor /= image.height; } - if (parent != null) { - ((PShapeOpenGL)parent).addTexture(image); - if (is2D() && stroke) { - ((PShapeOpenGL)parent).strokedTexture(true); - } + if (image0 != null) { + uFactor *= image0.width; + vFactor *= image0.height; } + scaleTextureUV(uFactor, vFactor); + } + + if (image0 != tex && parent != null) { + ((PShapeOpenGL)parent).removeTexture(tex); + } + if (parent != null) { + ((PShapeOpenGL)parent).addTexture(image); + if (is2D() && stroke) { + ((PShapeOpenGL)parent).strokedTexture(true); + } + } + } + + + protected void scaleTextureUV(float uFactor, float vFactor) { + if (PGraphicsOpenGL.same(uFactor, 1) && + PGraphicsOpenGL.same(vFactor, 1)) return; + + for (int i = 0; i < inGeo.vertexCount; i++) { + float u = inGeo.texcoords[2 * i + 0]; + float v = inGeo.texcoords[2 * i + 1]; + inGeo.texcoords[2 * i + 0] = PApplet.min(1, u * uFactor); + inGeo.texcoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + + if (shapeCreated && tessellated && hasPolys) { + int last1 = 0; + if (is3D()) { + last1 = lastPolyVertex + 1; + } else if (is2D()) { + last1 = lastPolyVertex + 1; + if (-1 < firstLineVertex) last1 = firstLineVertex; + if (-1 < firstPointVertex) last1 = firstPointVertex; + } + for (int i = firstLineVertex; i < last1; i++) { + float u = tessGeo.polyTexCoords[2 * i + 0]; + float v = tessGeo.polyTexCoords[2 * i + 1]; + tessGeo.polyTexCoords[2 * i + 0] = PApplet.min(1, u * uFactor); + tessGeo.polyTexCoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + root.setModifiedPolyTexCoords(firstPolyVertex, last1 - 1); } } @@ -1524,8 +1578,13 @@ public class PShapeOpenGL extends PShape { return; } + if (image != null && textureMode == IMAGE) { + u = PApplet.min(1, u / image.width); + v = PApplet.min(1, v / image.height); + } inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; + markForTessellation(); } @@ -2629,18 +2688,17 @@ public class PShapeOpenGL extends PShape { rounded = true; } - rectMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); if (rounded) { inGeo.addRect(a, b, c, d, tl, tr, br, bl, - fill, stroke, bezierDetail, rectMode); + fill, stroke, bezierDetail, CORNER); tessellator.tessellatePolygon(false, true, true); } else { inGeo.addRect(a, b, c, d, - fill, stroke, rectMode); + fill, stroke, CORNER); tessellator.tessellateQuads(); } } @@ -2655,11 +2713,10 @@ public class PShapeOpenGL extends PShape { d = params[3]; } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode); + inGeo.addEllipse(a, b, c, d, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -2667,7 +2724,7 @@ public class PShapeOpenGL extends PShape { protected void tessellateArc() { float a = 0, b = 0, c = 0, d = 0; float start = 0, stop = 0; - int mode = 0; +// int mode = 0; if (params.length == 6 || params.length == 7) { a = params[0]; b = params[1]; @@ -2675,16 +2732,16 @@ public class PShapeOpenGL extends PShape { d = params[3]; start = params[4]; stop = params[5]; - if (params.length == 7) { - mode = (int)(params[6]); - } + // Not using arc mode since PShape only uses CORNER +// if (params.length == 7) { +// mode = (int)(params[6]); +// } } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode); + inGeo.addArc(a, b, c, d, start, stop, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -3960,31 +4017,36 @@ public class PShapeOpenGL extends PShape { @Override protected void styles(PGraphics g) { if (g instanceof PGraphicsOpenGL) { - if (stroke) { + if (g.stroke) { + setStroke(true); setStroke(g.strokeColor); setStrokeWeight(g.strokeWeight); - - // These two don't to nothing probably: setStrokeCap(g.strokeCap); setStrokeJoin(g.strokeJoin); } else { setStroke(false); } - if (fill) { + if (g.fill) { + setFill(true); setFill(g.fillColor); } else { setFill(false); } + if (g.tint) { + setTint(true); + setTint(g.tintColor); + } + setAmbient(g.ambientColor); setSpecular(g.specularColor); setEmissive(g.emissiveColor); setShininess(g.shininess); - // What about other style parameters, such as rectMode, etc? - // These should force a tessellation update, same as stroke - // cap and weight... right? + if (image != null) { + setTextureMode(g.textureMode); + } } else { super.styles(g); } From a66f844d8b763b423fa5a757dd4a0d319a247f53 Mon Sep 17 00:00:00 2001 From: REAS Date: Wed, 22 May 2013 12:44:36 -0700 Subject: [PATCH 06/46] Removing two Typography examples from the web --- core/src/processing/data/XML.java | 29 ++++++++++++++++--- .../Basics/Typography/Letters/Letters.pde | 5 +--- .../Basics/Typography/Words/Words.pde | 5 +--- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java index bc1fd7fac..656f6ede5 100644 --- a/core/src/processing/data/XML.java +++ b/core/src/processing/data/XML.java @@ -61,7 +61,9 @@ public class XML implements Serializable { /** Child elements, once loaded. */ protected XML[] children; - + /** + * @nowebref + */ protected XML() { } @@ -81,6 +83,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(File file) throws IOException, ParserConfigurationException, SAXException { this(file, null); @@ -89,12 +93,16 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(File file, String options) throws IOException, ParserConfigurationException, SAXException { this(PApplet.createReader(file), options); } - + /** + * @nowebref + */ public XML(InputStream input) throws IOException, ParserConfigurationException, SAXException { this(input, null); } @@ -104,6 +112,8 @@ public class XML implements Serializable { * Shouldn't be part of main p5 reference, this is for advanced users. * Note that while it doesn't accept anything but UTF-8, this is preserved * so that we have some chance of implementing that in the future. + * + * @nowebref */ public XML(InputStream input, String options) throws IOException, ParserConfigurationException, SAXException { this(PApplet.createReader(input), options); @@ -112,6 +122,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(Reader reader) throws IOException, ParserConfigurationException, SAXException { this(reader, null); @@ -120,6 +132,8 @@ public class XML implements Serializable { /** * Advanced users only; see loadXML() in PApplet. + * + * @nowebref */ public XML(Reader reader, String options) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -166,6 +180,8 @@ public class XML implements Serializable { /** * @param name description TBD + * + * @nowebref */ public XML(String name) { try { @@ -181,7 +197,9 @@ public class XML implements Serializable { } } - + /** + * @nowebref + */ protected XML(XML parent, Node node) { this.node = node; this.parent = parent; @@ -197,12 +215,15 @@ public class XML implements Serializable { * @throws SAXException * @throws ParserConfigurationException * @throws IOException + * @nowebref */ static public XML parse(String data) throws IOException, ParserConfigurationException, SAXException { return XML.parse(data, null); } - + /** + * @nowebref + */ static public XML parse(String data, String options) throws IOException, ParserConfigurationException, SAXException { return new XML(new StringReader(data), null); } diff --git a/java/examples/Basics/Typography/Letters/Letters.pde b/java/examples/Basics/Typography/Letters/Letters.pde index 6f0314c73..781d2aac7 100644 --- a/java/examples/Basics/Typography/Letters/Letters.pde +++ b/java/examples/Basics/Typography/Letters/Letters.pde @@ -5,9 +5,6 @@ * setting the font, and then drawing the letters. */ -// The next line is needed if running in JavaScript Mode with Processing.js -/* @pjs font="Courier.ttf"; */ - PFont f; void setup() { @@ -16,7 +13,7 @@ void setup() { // Create the font println(PFont.list()); - f = createFont("Monospaced", 24); + f = createFont("Georgia", 24); textFont(f); textAlign(CENTER, CENTER); } diff --git a/java/examples/Basics/Typography/Words/Words.pde b/java/examples/Basics/Typography/Words/Words.pde index 445a6fef9..c86bdcbb6 100644 --- a/java/examples/Basics/Typography/Words/Words.pde +++ b/java/examples/Basics/Typography/Words/Words.pde @@ -5,9 +5,6 @@ * The letters can be aligned left, center, or right with the * textAlign() function. */ - -// The next line is needed if running in JavaScript Mode with Processing.js -/* @pjs font="Georgia.ttf"; */ PFont f; @@ -16,7 +13,7 @@ void setup() { // Create the font println(PFont.list()); - f = createFont("Serif", 24); + f = createFont("Georgia", 24); textFont(f); } From 99a4d8fa304dfae48c07a370b51beedc7dd7ad0b Mon Sep 17 00:00:00 2001 From: REAS Date: Wed, 22 May 2013 14:38:13 -0700 Subject: [PATCH 07/46] Adjustment to KeyboardFunctions example --- .../Basics/Input/KeyboardFunctions/KeyboardFunctions.pde | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde b/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde index f0554ab93..e08079140 100644 --- a/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde +++ b/java/examples/Basics/Input/KeyboardFunctions/KeyboardFunctions.pde @@ -54,8 +54,8 @@ void draw() void keyPressed() { - // If the key is between 'A'(65) and 'z'(122) - if( key >= 'A' && key <= 'z') { + // If the key is between 'A'(65) to 'Z' and 'a' to 'z'(122) + if((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) { int keyIndex; if(key <= 'Z') { keyIndex = key-'A'; From 543388c8eb905de83f3bf04b41c3bc7ab902494f Mon Sep 17 00:00:00 2001 From: REAS Date: Wed, 22 May 2013 15:28:43 -0700 Subject: [PATCH 08/46] Add getChildCount() to PShape reference --- core/src/processing/core/PShape.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 026d3214c..e5eaa28fd 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -1647,6 +1647,10 @@ public class PShape implements PConstants { return parent; } + /** + * @webref + * @brief Returns the number of children + */ public int getChildCount() { return childCount; } From a88296abb78b2709c1d3f93e0ac85b1f076d08b8 Mon Sep 17 00:00:00 2001 From: REAS Date: Wed, 22 May 2013 15:56:15 -0700 Subject: [PATCH 09/46] Add wheelMouse() to reference --- core/src/processing/core/PApplet.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 388ea6530..44bed52d9 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -3069,10 +3069,19 @@ public class PApplet extends Applet mouseExited(); } - + /** + * @nowebref + */ public void mouseWheel() { } - + /** + * The event.getAmount() method returns negative values if the mouse wheel + * if rotated up or away from the user and positive in the other direction. + * On OS X with "natural" scrolling enabled, the values are opposite. + * + * @webref input:mouse + * @param event the MouseEvent + */ public void mouseWheel(MouseEvent event) { mouseWheel(); } From 06d0812fc03a629f83ed90593f30d7353931a37e Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 22 May 2013 17:57:52 -0700 Subject: [PATCH 10/46] Added reference for Table addColumn() and removeColumn() --- core/src/processing/data/Table.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index b84ad37cb..71eafdd2e 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -1297,11 +1297,15 @@ public class Table { /** * @webref table:method * @brief Removes a column from the table + * @param columnName the title of the column to be removed */ public void removeColumn(String columnName) { removeColumn(getColumnIndex(columnName)); } + /** + * @param column the index number of the column to be removed + */ public void removeColumn(int column) { int newCount = columns.length - 1; From 566fd7e5394eff809f60159cb528034cf01ee826 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 23 May 2013 11:46:08 -0400 Subject: [PATCH 11/46] Added missing GLES 2.0 functions and constants to PGL interface --- core/src/processing/opengl/PGL.java | 1982 +++++++++++++++------------ 1 file changed, 1117 insertions(+), 865 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index c2b2bd5c4..4e4e78a31 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -70,16 +70,34 @@ import com.jogamp.opengl.FBObject; */ @SuppressWarnings("static-access") public class PGL { + /////////////////////////////////////////////////////////// + + // Public members to access the underlying GL objects and context + + /** Basic GL functionality, common to all profiles */ + public static GL gl; + + /** GLU interface **/ + public static GLU glu; + + /** The rendering context (holds rendering state info) */ + public static GLContext context; + + /** The canvas where OpenGL rendering takes place */ + public static Canvas canvas; + + /** Selected GL profile */ + public static GLProfile profile; /////////////////////////////////////////////////////////// // Parameters - public static final boolean USE_JOGL_FBOLAYER = false; - public static boolean FORCE_SCREEN_FBO = false; - public static final boolean USE_DIRECT_BUFFERS = true; - public static final int MIN_DIRECT_BUFFER_SIZE = 1; - public static final boolean SAVE_SURFACE_TO_PIXELS = true; + protected static final boolean USE_JOGL_FBOLAYER = false; + protected static boolean FORCE_SCREEN_FBO = false; + protected static final boolean USE_DIRECT_BUFFERS = true; + protected static final int MIN_DIRECT_BUFFER_SIZE = 1; + protected static final boolean SAVE_SURFACE_TO_PIXELS = true; /** Enables/disables mipmap use. **/ protected static final boolean MIPMAPS_ENABLED = true; @@ -202,192 +220,6 @@ public class PGL { "precision mediump int;\n" + "#endif\n"; - /////////////////////////////////////////////////////////// - - // OpenGL constants - - public static final int FALSE = GL.GL_FALSE; - public static final int TRUE = GL.GL_TRUE; - - public static final int LESS = GL.GL_LESS; - public static final int LEQUAL = GL.GL_LEQUAL; - - public static final int CCW = GL.GL_CCW; - public static final int CW = GL.GL_CW; - - public static final int CULL_FACE = GL.GL_CULL_FACE; - public static final int FRONT = GL.GL_FRONT; - public static final int BACK = GL.GL_BACK; - public static final int FRONT_AND_BACK = GL.GL_FRONT_AND_BACK; - - public static final int VIEWPORT = GL.GL_VIEWPORT; - - public static final int SCISSOR_TEST = GL.GL_SCISSOR_TEST; - public static final int DEPTH_TEST = GL.GL_DEPTH_TEST; - public static final int DEPTH_WRITEMASK = GL.GL_DEPTH_WRITEMASK; - - public static final int COLOR_BUFFER_BIT = GL.GL_COLOR_BUFFER_BIT; - public static final int DEPTH_BUFFER_BIT = GL.GL_DEPTH_BUFFER_BIT; - public static final int STENCIL_BUFFER_BIT = GL.GL_STENCIL_BUFFER_BIT; - - public static final int FUNC_ADD = GL.GL_FUNC_ADD; - public static final int FUNC_MIN = GL2.GL_MIN; - public static final int FUNC_MAX = GL2.GL_MAX; - public static final int FUNC_REVERSE_SUBTRACT = GL.GL_FUNC_REVERSE_SUBTRACT; - - public static final int TEXTURE_2D = GL.GL_TEXTURE_2D; - public static final int TEXTURE_RECTANGLE = GL2.GL_TEXTURE_RECTANGLE; - - public static final int TEXTURE_BINDING_2D = GL.GL_TEXTURE_BINDING_2D; - public static final int TEXTURE_BINDING_RECTANGLE = - GL2.GL_TEXTURE_BINDING_RECTANGLE; - - public static final int RGB = GL.GL_RGB; - public static final int RGBA = GL.GL_RGBA; - public static final int ALPHA = GL.GL_ALPHA; - public static final int UNSIGNED_INT = GL.GL_UNSIGNED_INT; - public static final int UNSIGNED_BYTE = GL.GL_UNSIGNED_BYTE; - public static final int UNSIGNED_SHORT = GL.GL_UNSIGNED_SHORT; - public static final int FLOAT = GL.GL_FLOAT; - - public static final int NEAREST = GL.GL_NEAREST; - public static final int LINEAR = GL.GL_LINEAR; - public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST; - public static final int LINEAR_MIPMAP_LINEAR = GL.GL_LINEAR_MIPMAP_LINEAR; - - public static final int TEXTURE_MAX_ANISOTROPY = - GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; - public static final int MAX_TEXTURE_MAX_ANISOTROPY = - GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; - - public static final int CLAMP_TO_EDGE = GL.GL_CLAMP_TO_EDGE; - public static final int REPEAT = GL.GL_REPEAT; - - public static final int RGBA8 = GL.GL_RGBA8; - public static final int DEPTH24_STENCIL8 = GL.GL_DEPTH24_STENCIL8; - - public static final int DEPTH_COMPONENT = GL2.GL_DEPTH_COMPONENT; - public static final int DEPTH_COMPONENT16 = GL.GL_DEPTH_COMPONENT16; - public static final int DEPTH_COMPONENT24 = GL.GL_DEPTH_COMPONENT24; - public static final int DEPTH_COMPONENT32 = GL.GL_DEPTH_COMPONENT32; - - public static final int STENCIL_INDEX = GL2.GL_STENCIL_INDEX; - public static final int STENCIL_INDEX1 = GL.GL_STENCIL_INDEX1; - public static final int STENCIL_INDEX4 = GL.GL_STENCIL_INDEX4; - public static final int STENCIL_INDEX8 = GL.GL_STENCIL_INDEX8; - - public static final int ARRAY_BUFFER = GL.GL_ARRAY_BUFFER; - public static final int ELEMENT_ARRAY_BUFFER = GL.GL_ELEMENT_ARRAY_BUFFER; - - public static final int SAMPLES = GL.GL_SAMPLES; - - public static final int FRAMEBUFFER_COMPLETE = - GL.GL_FRAMEBUFFER_COMPLETE; - public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = - GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = - GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = - GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; - public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = - GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS; - public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = - GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; - public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = - GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; - public static final int FRAMEBUFFER_UNSUPPORTED = - GL.GL_FRAMEBUFFER_UNSUPPORTED; - - public static final int STATIC_DRAW = GL.GL_STATIC_DRAW; - public static final int DYNAMIC_DRAW = GL.GL_DYNAMIC_DRAW; - public static final int STREAM_DRAW = GL2.GL_STREAM_DRAW; - - public static final int READ_ONLY = GL2.GL_READ_ONLY; - public static final int WRITE_ONLY = GL2.GL_WRITE_ONLY; - public static final int READ_WRITE = GL2.GL_READ_WRITE; - - public static final int TRIANGLE_FAN = GL.GL_TRIANGLE_FAN; - public static final int TRIANGLE_STRIP = GL.GL_TRIANGLE_STRIP; - public static final int TRIANGLES = GL.GL_TRIANGLES; - - public static final int VENDOR = GL.GL_VENDOR; - public static final int RENDERER = GL.GL_RENDERER; - public static final int VERSION = GL.GL_VERSION; - public static final int EXTENSIONS = GL.GL_EXTENSIONS; - public static final int SHADING_LANGUAGE_VERSION = - GL2ES2.GL_SHADING_LANGUAGE_VERSION; - - public static final int MAX_TEXTURE_SIZE = GL.GL_MAX_TEXTURE_SIZE; - public static final int MAX_SAMPLES = GL2.GL_MAX_SAMPLES; - public static final int ALIASED_LINE_WIDTH_RANGE = - GL.GL_ALIASED_LINE_WIDTH_RANGE; - public static final int ALIASED_POINT_SIZE_RANGE = - GL.GL_ALIASED_POINT_SIZE_RANGE; - public static final int DEPTH_BITS = GL.GL_DEPTH_BITS; - public static final int STENCIL_BITS = GL.GL_STENCIL_BITS; - - public static final int TESS_WINDING_NONZERO = GLU.GLU_TESS_WINDING_NONZERO; - public static final int TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; - - public static final int TEXTURE0 = GL.GL_TEXTURE0; - public static final int TEXTURE1 = GL.GL_TEXTURE1; - public static final int TEXTURE2 = GL.GL_TEXTURE2; - public static final int TEXTURE3 = GL.GL_TEXTURE3; - public static final int TEXTURE_MIN_FILTER = GL.GL_TEXTURE_MIN_FILTER; - public static final int TEXTURE_MAG_FILTER = GL.GL_TEXTURE_MAG_FILTER; - public static final int TEXTURE_WRAP_S = GL.GL_TEXTURE_WRAP_S; - public static final int TEXTURE_WRAP_T = GL.GL_TEXTURE_WRAP_T; - - public static final int BLEND = GL.GL_BLEND; - public static final int ONE = GL.GL_ONE; - public static final int ZERO = GL.GL_ZERO; - public static final int SRC_ALPHA = GL.GL_SRC_ALPHA; - public static final int DST_ALPHA = GL.GL_DST_ALPHA; - public static final int ONE_MINUS_SRC_ALPHA = GL.GL_ONE_MINUS_SRC_ALPHA; - public static final int ONE_MINUS_DST_COLOR = GL.GL_ONE_MINUS_DST_COLOR; - public static final int ONE_MINUS_SRC_COLOR = GL.GL_ONE_MINUS_SRC_COLOR; - public static final int DST_COLOR = GL.GL_DST_COLOR; - public static final int SRC_COLOR = GL.GL_SRC_COLOR; - - public static final int FRAMEBUFFER = GL.GL_FRAMEBUFFER; - public static final int COLOR_ATTACHMENT0 = GL.GL_COLOR_ATTACHMENT0; - public static final int COLOR_ATTACHMENT1 = GL2.GL_COLOR_ATTACHMENT1; - public static final int COLOR_ATTACHMENT2 = GL2.GL_COLOR_ATTACHMENT2; - public static final int COLOR_ATTACHMENT3 = GL2.GL_COLOR_ATTACHMENT3; - public static final int RENDERBUFFER = GL.GL_RENDERBUFFER; - public static final int DEPTH_ATTACHMENT = GL.GL_DEPTH_ATTACHMENT; - public static final int STENCIL_ATTACHMENT = GL.GL_STENCIL_ATTACHMENT; - public static final int READ_FRAMEBUFFER = GL2.GL_READ_FRAMEBUFFER; - public static final int DRAW_FRAMEBUFFER = GL2.GL_DRAW_FRAMEBUFFER; - - public static final int VERTEX_SHADER = GL2.GL_VERTEX_SHADER; - public static final int FRAGMENT_SHADER = GL2.GL_FRAGMENT_SHADER; - public static final int INFO_LOG_LENGTH = GL2.GL_INFO_LOG_LENGTH; - public static final int SHADER_SOURCE_LENGTH = GL2.GL_SHADER_SOURCE_LENGTH; - public static final int COMPILE_STATUS = GL2.GL_COMPILE_STATUS; - public static final int LINK_STATUS = GL2.GL_LINK_STATUS; - public static final int VALIDATE_STATUS = GL2.GL_VALIDATE_STATUS; - - public static final int MULTISAMPLE = GL.GL_MULTISAMPLE; - public static final int POINT_SMOOTH = GL2.GL_POINT_SMOOTH; - public static final int LINE_SMOOTH = GL.GL_LINE_SMOOTH; - public static final int POLYGON_SMOOTH = GL2.GL_POLYGON_SMOOTH; - - /** Basic GL functionality, common to all profiles */ - public static GL gl; - - /** GLU interface **/ - public static GLU glu; - - /** The rendering context (holds rendering state info) */ - public static GLContext context; - - /** The canvas where OpenGL rendering takes place */ - public static Canvas canvas; - - /** Selected GL profile */ - public static GLProfile profile; - /** OpenGL thread */ protected static Thread glThread; @@ -1281,679 +1113,6 @@ public class PGL { } - ////////////////////////////////////////////////////////////////////////////// - - // Caps query - - - public String getString(int name) { - return gl.glGetString(name); - } - - - public void getIntegerv(int name, IntBuffer values) { - if (-1 < name) { - gl.glGetIntegerv(name, values); - } else { - fillIntBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - public void getFloatv(int name, FloatBuffer values) { - if (-1 < name) { - gl.glGetFloatv(name, values); - } else { - fillFloatBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - public void getBooleanv(int name, IntBuffer values) { - if (-1 < name) { - if (byteBuffer.capacity() < values.capacity()) { - byteBuffer = allocateDirectByteBuffer(values.capacity()); - } - gl.glGetBooleanv(name, byteBuffer); - for (int i = 0; i < values.capacity(); i++) { - values.put(i, byteBuffer.get(i)); - } - } else { - fillIntBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - /////////////////////////////////////////////////////////// - - // Enable/disable caps - - - public void enable(int cap) { - if (-1 < cap) { - gl.glEnable(cap); - } - } - - - public void disable(int cap) { - if (-1 < cap) { - gl.glDisable(cap); - } - } - - - /////////////////////////////////////////////////////////// - - // Render control - - - public void flush() { - gl.glFlush(); - } - - - public void finish() { - gl.glFinish(); - } - - - /////////////////////////////////////////////////////////// - - // Error handling - - - public int getError() { - return gl.glGetError(); - } - - - public String errorString(int err) { - return glu.gluErrorString(err); - } - - - /////////////////////////////////////////////////////////// - - // Rendering options - - - public void frontFace(int mode) { - gl.glFrontFace(mode); - } - - - public void cullFace(int mode) { - gl.glCullFace(mode); - } - - - public void depthMask(boolean flag) { - gl.glDepthMask(flag); - } - - - public void depthFunc(int func) { - gl.glDepthFunc(func); - } - - - /////////////////////////////////////////////////////////// - - // Textures - - - public void genTextures(int n, IntBuffer ids) { - gl.glGenTextures(n, ids); - } - - - public void deleteTextures(int n, IntBuffer ids) { - gl.glDeleteTextures(n, ids); - } - - - public void activeTexture(int unit) { - gl.glActiveTexture(unit); - } - - - public void bindTexture(int target, int id) { - gl.glBindTexture(target, id); - if (target == TEXTURE_2D) { - boundTextures[0] = id; - } else if (target == TEXTURE_RECTANGLE) { - boundTextures[1] = id; - } - } - - - public void texImage2D(int target, int level, int internalFormat, - int width, int height, int border, int format, - int type, Buffer data) { - gl.glTexImage2D(target, level, internalFormat, - width, height, border, format, type, data); - } - - - public void texSubImage2D(int target, int level, int xOffset, int yOffset, - int width, int height, int format, - int type, Buffer data) { - gl.glTexSubImage2D(target, level, xOffset, yOffset, - width, height, format, type, data); - } - - - public void texParameteri(int target, int param, int value) { - gl.glTexParameteri(target, param, value); - } - - - public void texParameterf(int target, int param, float value) { - gl.glTexParameterf(target, param, value); - } - - - public void getTexParameteriv(int target, int param, IntBuffer values) { - gl.glGetTexParameteriv(target, param, values); - } - - - public void generateMipmap(int target) { - gl.glGenerateMipmap(target); - } - - - /////////////////////////////////////////////////////////// - - // Vertex Buffers - - - public void genBuffers(int n, IntBuffer ids) { - gl.glGenBuffers(n, ids); - } - - - public void deleteBuffers(int n, IntBuffer ids) { - gl.glDeleteBuffers(n, ids); - } - - - public void bindBuffer(int target, int id) { - gl.glBindBuffer(target, id); - } - - - public void bufferData(int target, int size, Buffer data, int usage) { - gl.glBufferData(target, size, data, usage); - } - - - public void bufferSubData(int target, int offset, int size, Buffer data) { - gl.glBufferSubData(target, offset, size, data); - } - - - public void drawArrays(int mode, int first, int count) { - gl.glDrawArrays(mode, first, count); - } - - - public void drawElements(int mode, int count, int type, int offset) { - gl.glDrawElements(mode, count, type, offset); - } - - - public void enableVertexAttribArray(int loc) { - gl2.glEnableVertexAttribArray(loc); - } - - - public void disableVertexAttribArray(int loc) { - gl2.glDisableVertexAttribArray(loc); - } - - - public void vertexAttribPointer(int loc, int size, int type, - boolean normalized, int stride, int offset) { - gl2.glVertexAttribPointer(loc, size, type, normalized, stride, offset); - } - - - public void vertexAttribPointer(int loc, int size, int type, - boolean normalized, int stride, Buffer data) { - gl2.glVertexAttribPointer(loc, size, type, normalized, stride, data); - } - - - public ByteBuffer mapBuffer(int target, int access) { - return gl2.glMapBuffer(target, access); - } - - - public ByteBuffer mapBufferRange(int target, int offset, int length, - int access) { - if (gl2x != null) { - return gl2x.glMapBufferRange(target, offset, length, access); - } else { - return null; - } - } - - - public void unmapBuffer(int target) { - gl2.glUnmapBuffer(target); - } - - - /////////////////////////////////////////////////////////// - - // Framebuffers, renderbuffers - - - public void genFramebuffers(int n, IntBuffer ids) { - gl.glGenFramebuffers(n, ids); - } - - - public void deleteFramebuffers(int n, IntBuffer ids) { - gl.glDeleteFramebuffers(n, ids); - } - - - public void genRenderbuffers(int n, IntBuffer ids) { - gl.glGenRenderbuffers(n, ids); - } - - - public void deleteRenderbuffers(int n, IntBuffer ids) { - gl.glDeleteRenderbuffers(n, ids); - } - - - public void bindFramebuffer(int target, int id) { - gl.glBindFramebuffer(target, id); - } - - - 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); - } - } - - - public void framebufferTexture2D(int target, int attachment, int texTarget, - int texId, int level) { - gl.glFramebufferTexture2D(target, attachment, texTarget, texId, level); - } - - - public void bindRenderbuffer(int target, int id) { - gl.glBindRenderbuffer(target, id); - } - - - public void renderbufferStorageMultisample(int target, int samples, - int format, int width, int height){ - if (gl2x != null) { - gl2x.glRenderbufferStorageMultisample(target, samples, format, - width, height); - } - } - - - public void renderbufferStorage(int target, int format, - int width, int height) { - gl.glRenderbufferStorage(target, format, width, height); - } - - - public void framebufferRenderbuffer(int target, int attachment, - int rendbufTarget, int rendbufId) { - gl.glFramebufferRenderbuffer(target, attachment, rendbufTarget, rendbufId); - } - - - public int checkFramebufferStatus(int target) { - return gl.glCheckFramebufferStatus(target); - } - - - /////////////////////////////////////////////////////////// - - // Shaders - - - public int createProgram() { - return gl2.glCreateProgram(); - } - - - public void deleteProgram(int id) { - gl2.glDeleteProgram(id); - } - - - public int createShader(int type) { - return gl2.glCreateShader(type); - } - - - public void deleteShader(int id) { - gl2.glDeleteShader(id); - } - - - public void linkProgram(int prog) { - gl2.glLinkProgram(prog); - } - - - public void validateProgram(int prog) { - gl2.glValidateProgram(prog); - } - - - public void useProgram(int prog) { - gl2.glUseProgram(prog); - } - - - public int getAttribLocation(int prog, String name) { - return gl2.glGetAttribLocation(prog, name); - } - - - public int getUniformLocation(int prog, String name) { - return gl2.glGetUniformLocation(prog, name); - } - - - public void uniform1i(int loc, int value) { - gl2.glUniform1i(loc, value); - } - - - public void uniform2i(int loc, int value0, int value1) { - gl2.glUniform2i(loc, value0, value1); - } - - - public void uniform3i(int loc, int value0, int value1, int value2) { - gl2.glUniform3i(loc, value0, value1, value2); - } - - - public void uniform4i(int loc, int value0, int value1, int value2, - int value3) { - gl2.glUniform4i(loc, value0, value1, value2, value3); - } - - - public void uniform1f(int loc, float value) { - gl2.glUniform1f(loc, value); - } - - - public void uniform2f(int loc, float value0, float value1) { - gl2.glUniform2f(loc, value0, value1); - } - - - public void uniform3f(int loc, float value0, float value1, float value2) { - gl2.glUniform3f(loc, value0, value1, value2); - } - - - public void uniform4f(int loc, float value0, float value1, float value2, - float value3) { - gl2.glUniform4f(loc, value0, value1, value2, value3); - } - - - public void uniform1iv(int loc, int count, IntBuffer v) { - gl2.glUniform1iv(loc, count, v); - } - - - public void uniform2iv(int loc, int count, IntBuffer v) { - gl2.glUniform2iv(loc, count, v); - } - - - public void uniform3iv(int loc, int count, IntBuffer v) { - gl2.glUniform3iv(loc, count, v); - } - - - public void uniform4iv(int loc, int count, IntBuffer v) { - gl2.glUniform4iv(loc, count, v); - } - - - public void uniform1fv(int loc, int count, FloatBuffer v) { - gl2.glUniform1fv(loc, count, v); - } - - - public void uniform2fv(int loc, int count, FloatBuffer v) { - gl2.glUniform2fv(loc, count, v); - } - - - public void uniform3fv(int loc, int count, FloatBuffer v) { - gl2.glUniform3fv(loc, count, v); - } - - - public void uniform4fv(int loc, int count, FloatBuffer v) { - gl2.glUniform4fv(loc, count, v); - } - - - public void uniformMatrix2fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - gl2.glUniformMatrix2fv(loc, count, transpose, mat); - } - - - public void uniformMatrix3fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - gl2.glUniformMatrix3fv(loc, count, transpose, mat); - } - - - public void uniformMatrix4fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - gl2.glUniformMatrix4fv(loc, count, transpose, mat); - } - - - public void vertexAttrib1f(int loc, float value) { - gl2.glVertexAttrib1f(loc, value); - } - - - public void vertexAttrib2f(int loc, float value0, float value1) { - gl2.glVertexAttrib2f(loc, value0, value1); - } - - - public void vertexAttrib3f(int loc, float value0, float value1, float value2){ - gl2.glVertexAttrib3f(loc, value0, value1, value2); - } - - - public void vertexAttrib4f(int loc, float value0, float value1, float value2, - float value3) { - gl2.glVertexAttrib4f(loc, value0, value1, value2, value3); - } - - - public void vertexAttrib1fv(int loc, FloatBuffer v) { - gl2.glVertexAttrib1fv(loc, v); - } - - - public void vertexAttrib2fv(int loc, FloatBuffer v) { - gl2.glVertexAttrib2fv(loc, v); - } - - - public void vertexAttrib3fv(int loc, FloatBuffer v) { - gl2.glVertexAttrib3fv(loc, v); - } - - - public void vertexAttri4fv(int loc, FloatBuffer v) { - gl2.glVertexAttrib4fv(loc, v); - } - - - public void shaderSource(int id, String source) { - gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0); - } - - - public void compileShader(int id) { - gl2.glCompileShader(id); - } - - - public void attachShader(int prog, int shader) { - gl2.glAttachShader(prog, shader); - } - - - public void getShaderiv(int shader, int pname, IntBuffer params) { - gl2.glGetShaderiv(shader, pname, params); - } - - - public String getShaderInfoLog(int shader) { - int[] val = { 0 }; - gl2.glGetShaderiv(shader, GL2.GL_INFO_LOG_LENGTH, val, 0); - int length = val[0]; - - byte[] log = new byte[length]; - gl2.glGetShaderInfoLog(shader, length, val, 0, log, 0); - return new String(log); - } - - - public void getProgramiv(int prog, int pname, IntBuffer params) { - gl2.glGetProgramiv(prog, pname, params); - } - - - public String getProgramInfoLog(int prog) { - int[] val = { 0 }; - gl2.glGetShaderiv(prog, GL2.GL_INFO_LOG_LENGTH, val, 0); - int length = val[0]; - - if (0 < length) { - byte[] log = new byte[length]; - gl2.glGetProgramInfoLog(prog, length, val, 0, log, 0); - return new String(log); - } else { - return "Unknow error"; - } - } - - - /////////////////////////////////////////////////////////// - - // Viewport - - - public void viewport(int x, int y, int width, int height) { - gl.glViewport(x, y, width, height); - } - - - /////////////////////////////////////////////////////////// - - // Clipping (scissor test) - - - public void scissor(int x, int y, int w, int h) { - gl.glScissor(x, y, w, h); - } - - - /////////////////////////////////////////////////////////// - - // Blending - - - public void blendEquation(int eq) { - gl.glBlendEquation(eq); - } - - - public void blendFunc(int srcFactor, int dstFactor) { - gl.glBlendFunc(srcFactor, dstFactor); - } - - - /////////////////////////////////////////////////////////// - - // Pixels - - - public void readBuffer(int buf) { - if (gl2x != null) { - gl2x.glReadBuffer(buf); - } - } - - - public void readPixels(int x, int y, int width, int height, int format, - int type, Buffer buffer) { - - - gl.glReadPixels(x, y, width, height, format, type, buffer); - - - } - - - public void drawBuffer(int buf) { - if (gl2x != null) { - gl2x.glDrawBuffer(buf); - } - } - - - public void clearDepth(float d) { - gl.glClearDepthf(d); - } - - - public void clearStencil(int s) { - gl.glClearStencil(s); - } - - - public void colorMask(boolean wr, boolean wg, boolean wb, boolean wa) { - gl.glColorMask(wr, wg, wb, wa); - } - - - public void clearColor(float r, float g, float b, float a) { - gl.glClearColor(r, g, b, a); - } - - - public void clear(int mask) { - gl.glClear(mask); - } - - /////////////////////////////////////////////////////////// // Context interface @@ -3204,7 +2363,8 @@ public class PGL { /////////////////////////////////////////////////////////// - // Java specific stuff + // Event listeners + protected class PGLListener implements GLEventListener { public PGLListener() {} @@ -3448,4 +2608,1096 @@ public class PGL { nativeKeyEvent(e, KeyEvent.TYPE); } } + + + ////////////////////////////////////////////////////////////////////////////// + // + // OpenGL ES 2.0 API, with a few additional functions for multisampling and + // and buffer mapping from OpenGL 2.1+. + // + // The functions are organized following the groups in the GLES 2.0 reference + // card: + // http://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf + // + // The entire GLES 2.0 specification is available below: + // http://www.khronos.org/opengles/2_X/ + // + ////////////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////// + + // Constants + + public static final int FALSE = GL.GL_FALSE; + public static final int TRUE = GL.GL_TRUE; + + public static final int INT = GL2.GL_INT; + public static final int BYTE = GL.GL_BYTE; + public static final int SHORT = GL.GL_SHORT; + public static final int FLOAT = GL.GL_FLOAT; + public static final int UNSIGNED_INT = GL.GL_UNSIGNED_INT; + public static final int UNSIGNED_BYTE = GL.GL_UNSIGNED_BYTE; + public static final int UNSIGNED_SHORT = GL.GL_UNSIGNED_SHORT; + + public static final int RGB = GL.GL_RGB; + public static final int RGBA = GL.GL_RGBA; + public static final int ALPHA = GL.GL_ALPHA; + + public static final int READ_ONLY = GL2.GL_READ_ONLY; + public static final int WRITE_ONLY = GL2.GL_WRITE_ONLY; + public static final int READ_WRITE = GL2.GL_READ_WRITE; + + public static final int TESS_WINDING_NONZERO = GLU.GLU_TESS_WINDING_NONZERO; + public static final int TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; + + public static final int GENERATE_MIPMAP_HINT = GL.GL_GENERATE_MIPMAP_HINT; + public static final int FASTEST = GL.GL_FASTEST; + public static final int NICEST = GL.GL_NICEST; + public static final int DONT_CARE = GL.GL_DONT_CARE; + + public static final int VENDOR = GL.GL_VENDOR; + public static final int RENDERER = GL.GL_RENDERER; + public static final int VERSION = GL.GL_VERSION; + public static final int EXTENSIONS = GL.GL_EXTENSIONS; + public static final int SHADING_LANGUAGE_VERSION = + GL2ES2.GL_SHADING_LANGUAGE_VERSION; + + public static final int ALIASED_LINE_WIDTH_RANGE = + GL.GL_ALIASED_LINE_WIDTH_RANGE; + public static final int ALIASED_POINT_SIZE_RANGE = + GL.GL_ALIASED_POINT_SIZE_RANGE; + public static final int DEPTH_BITS = GL.GL_DEPTH_BITS; + public static final int STENCIL_BITS = GL.GL_STENCIL_BITS; + + public static final int CCW = GL.GL_CCW; + public static final int CW = GL.GL_CW; + public static final int VIEWPORT = GL.GL_VIEWPORT; + public static final int SAMPLES = GL.GL_SAMPLES; + + public static final int ARRAY_BUFFER = GL.GL_ARRAY_BUFFER; + public static final int ELEMENT_ARRAY_BUFFER = GL.GL_ELEMENT_ARRAY_BUFFER; + + public static final int STATIC_DRAW = GL.GL_STATIC_DRAW; + public static final int DYNAMIC_DRAW = GL.GL_DYNAMIC_DRAW; + public static final int STREAM_DRAW = GL2.GL_STREAM_DRAW; + + public static final int BUFFER_SIZE = GL.GL_BUFFER_SIZE; + public static final int BUFFER_USAGE = GL.GL_BUFFER_USAGE; + + public static final int POINTS = GL.GL_POINTS; + public static final int LINE_STRIP = GL.GL_LINE_STRIP; + public static final int LINE_LOOP = GL.GL_LINE_LOOP; + public static final int LINES = GL.GL_LINES; + public static final int TRIANGLE_FAN = GL.GL_TRIANGLE_FAN; + public static final int TRIANGLE_STRIP = GL.GL_TRIANGLE_STRIP; + public static final int TRIANGLES = GL.GL_TRIANGLES; + + public static final int MAX_VERTEX_ATTRIBS = GL2.GL_MAX_VERTEX_ATTRIBS; + + public static final int CULL_FACE = GL.GL_CULL_FACE; + public static final int FRONT = GL.GL_FRONT; + public static final int BACK = GL.GL_BACK; + public static final int FRONT_AND_BACK = GL.GL_FRONT_AND_BACK; + + public static final int POLYGON_OFFSET_FILL = GL.GL_POLYGON_OFFSET_FILL; + + public static final int UNPACK_ALIGNMENT = GL.GL_UNPACK_ALIGNMENT; + public static final int PACK_ALIGNMENT = GL.GL_PACK_ALIGNMENT; + + public static final int TEXTURE_2D = GL.GL_TEXTURE_2D; + public static final int TEXTURE_RECTANGLE = GL2.GL_TEXTURE_RECTANGLE; + + public static final int TEXTURE_BINDING_2D = GL.GL_TEXTURE_BINDING_2D; + public static final int TEXTURE_BINDING_RECTANGLE = + GL2.GL_TEXTURE_BINDING_RECTANGLE; + + public static final int MAX_TEXTURE_SIZE = GL.GL_MAX_TEXTURE_SIZE; + + public static final int NEAREST = GL.GL_NEAREST; + public static final int LINEAR = GL.GL_LINEAR; + public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST; + public static final int LINEAR_MIPMAP_LINEAR = GL.GL_LINEAR_MIPMAP_LINEAR; + + public static final int TEXTURE_MAX_ANISOTROPY = + GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; + public static final int MAX_TEXTURE_MAX_ANISOTROPY = + GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; + + public static final int CLAMP_TO_EDGE = GL.GL_CLAMP_TO_EDGE; + public static final int REPEAT = GL.GL_REPEAT; + + public static final int TEXTURE0 = GL.GL_TEXTURE0; + public static final int TEXTURE1 = GL.GL_TEXTURE1; + public static final int TEXTURE2 = GL.GL_TEXTURE2; + public static final int TEXTURE3 = GL.GL_TEXTURE3; + public static final int TEXTURE_MIN_FILTER = GL.GL_TEXTURE_MIN_FILTER; + public static final int TEXTURE_MAG_FILTER = GL.GL_TEXTURE_MAG_FILTER; + public static final int TEXTURE_WRAP_S = GL.GL_TEXTURE_WRAP_S; + public static final int TEXTURE_WRAP_T = GL.GL_TEXTURE_WRAP_T; + + public static final int MAX_VERTEX_TEXTURE_IMAGE_UNITS = + GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; + public static final int MAX_TEXTURE_IMAGE_UNITS = + GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; + + public static final int TEXTURE_CUBE_MAP_POSITIVE_X = + GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X; + public static final int TEXTURE_CUBE_MAP_POSITIVE_Y = + GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y; + public static final int TEXTURE_CUBE_MAP_POSITIVE_Z = + GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_X = + GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_Y = + GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_Z = + GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; + + public static final int LUMINANCE = GL.GL_LUMINANCE; + public static final int LUMINANCE_ALPHA = GL.GL_LUMINANCE_ALPHA; + + public static final int UNSIGNED_SHORT_5_6_5 = GL.GL_UNSIGNED_SHORT_5_6_5; + public static final int UNSIGNED_SHORT_4_4_4_4 = GL.GL_UNSIGNED_SHORT_4_4_4_4; + public static final int UNSIGNED_SHORT_5_5_5_1 = GL.GL_UNSIGNED_SHORT_5_5_5_1; + + public static final int TEXTURE_CUBE_MAP = GL.GL_TEXTURE_CUBE_MAP; + + public static final int VERTEX_SHADER = GL2.GL_VERTEX_SHADER; + public static final int FRAGMENT_SHADER = GL2.GL_FRAGMENT_SHADER; + public static final int INFO_LOG_LENGTH = GL2.GL_INFO_LOG_LENGTH; + public static final int SHADER_SOURCE_LENGTH = GL2.GL_SHADER_SOURCE_LENGTH; + public static final int COMPILE_STATUS = GL2.GL_COMPILE_STATUS; + public static final int LINK_STATUS = GL2.GL_LINK_STATUS; + public static final int VALIDATE_STATUS = GL2.GL_VALIDATE_STATUS; + + public static final int FLOAT_VEC2 = GL2.GL_FLOAT_VEC2; + public static final int FLOAT_VEC3 = GL2.GL_FLOAT_VEC3; + public static final int FLOAT_VEC4 = GL2.GL_FLOAT_VEC4; + public static final int FLOAT_MAT2 = GL2.GL_FLOAT_MAT2; + public static final int FLOAT_MAT3 = GL2.GL_FLOAT_MAT3; + public static final int FLOAT_MAT4 = GL2.GL_FLOAT_MAT4; + public static final int INT_VEC2 = GL2.GL_INT_VEC2; + public static final int INT_VEC3 = GL2.GL_INT_VEC3; + public static final int INT_VEC4 = GL2.GL_INT_VEC4; + public static final int BOOL = GL2.GL_BOOL; + public static final int BOOL_VEC2 = GL2.GL_BOOL_VEC2; + public static final int BOOL_VEC3 = GL2.GL_BOOL_VEC3; + public static final int BOOL_VEC4 = GL2.GL_BOOL_VEC4; + public static final int SAMPLER_2D = GL2.GL_SAMPLER_2D; + public static final int SAMPLER_CUBE = GL2.GL_SAMPLER_CUBE; + + public static final int SHADER_TYPE = GL2.GL_SHADER_TYPE; + public static final int DELETE_STATUS = GL2.GL_DELETE_STATUS; + + public static final int LOW_FLOAT = GL2.GL_LOW_FLOAT; + public static final int MEDIUM_FLOAT = GL2.GL_MEDIUM_FLOAT; + public static final int HIGH_FLOAT = GL2.GL_HIGH_FLOAT; + public static final int LOW_INT = GL2.GL_LOW_INT; + public static final int MEDIUM_INT = GL2.GL_MEDIUM_INT; + public static final int HIGH_INT = GL2.GL_HIGH_INT; + + public static final int CURRENT_VERTEX_ATTRIB = GL2.GL_CURRENT_VERTEX_ATTRIB; + + public static final int VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = GL2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING; + public static final int VERTEX_ATTRIB_ARRAY_ENABLED = GL2.GL_VERTEX_ATTRIB_ARRAY_ENABLED; + public static final int VERTEX_ATTRIB_ARRAY_SIZE = GL2.GL_VERTEX_ATTRIB_ARRAY_SIZE; + public static final int VERTEX_ATTRIB_ARRAY_STRIDE = GL2.GL_VERTEX_ATTRIB_ARRAY_STRIDE; + public static final int VERTEX_ATTRIB_ARRAY_TYPE = GL2.GL_VERTEX_ATTRIB_ARRAY_TYPE; + public static final int VERTEX_ATTRIB_ARRAY_NORMALIZED = GL2.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED; + + public static final int BLEND = GL.GL_BLEND; + public static final int ONE = GL.GL_ONE; + public static final int ZERO = GL.GL_ZERO; + public static final int SRC_ALPHA = GL.GL_SRC_ALPHA; + public static final int DST_ALPHA = GL.GL_DST_ALPHA; + public static final int ONE_MINUS_SRC_ALPHA = GL.GL_ONE_MINUS_SRC_ALPHA; + public static final int ONE_MINUS_DST_COLOR = GL.GL_ONE_MINUS_DST_COLOR; + public static final int ONE_MINUS_SRC_COLOR = GL.GL_ONE_MINUS_SRC_COLOR; + public static final int DST_COLOR = GL.GL_DST_COLOR; + public static final int SRC_COLOR = GL.GL_SRC_COLOR; + + public static final int SAMPLE_ALPHA_TO_COVERAGE = GL.GL_SAMPLE_ALPHA_TO_COVERAGE; + public static final int SAMPLE_COVERAGE = GL.GL_SAMPLE_COVERAGE; + + public static final int KEEP = GL.GL_KEEP; + public static final int REPLACE = GL.GL_REPLACE; + public static final int INCR = GL.GL_INCR; + public static final int DECR = GL.GL_DECR; + public static final int INVERT = GL.GL_INVERT; + public static final int INCR_WRAP = GL.GL_INCR_WRAP; + public static final int DECR_WRAP = GL.GL_DECR_WRAP; + public static final int NEVER = GL.GL_NEVER; + public static final int ALWAYS = GL.GL_ALWAYS; + + public static final int EQUAL = GL.GL_EQUAL; + public static final int LESS = GL.GL_LESS; + public static final int LEQUAL = GL.GL_LEQUAL; + public static final int GREATER = GL.GL_GREATER; + public static final int GEQUAL = GL.GL_GEQUAL; + public static final int NOTEQUAL = GL.GL_NOTEQUAL; + + public static final int FUNC_ADD = GL.GL_FUNC_ADD; + public static final int FUNC_MIN = GL2.GL_MIN; + public static final int FUNC_MAX = GL2.GL_MAX; + public static final int FUNC_REVERSE_SUBTRACT = GL.GL_FUNC_REVERSE_SUBTRACT; + public static final int FUNC_SUBTRACT = GL.GL_FUNC_SUBTRACT; + + public static final int DITHER = GL.GL_DITHER; + + public static final int CONSTANT_COLOR = GL2.GL_CONSTANT_COLOR; + public static final int CONSTANT_ALPHA = GL2.GL_CONSTANT_ALPHA; + public static final int ONE_MINUS_CONSTANT_COLOR = GL2.GL_ONE_MINUS_CONSTANT_COLOR; + public static final int ONE_MINUS_CONSTANT_ALPHA = GL2.GL_ONE_MINUS_CONSTANT_ALPHA; + public static final int SRC_ALPHA_SATURATE = GL.GL_SRC_ALPHA_SATURATE; + + public static final int SCISSOR_TEST = GL.GL_SCISSOR_TEST; + public static final int DEPTH_TEST = GL.GL_DEPTH_TEST; + public static final int DEPTH_WRITEMASK = GL.GL_DEPTH_WRITEMASK; + public static final int ALPHA_TEST = GL2.GL_ALPHA_TEST; + + public static final int COLOR_BUFFER_BIT = GL.GL_COLOR_BUFFER_BIT; + public static final int DEPTH_BUFFER_BIT = GL.GL_DEPTH_BUFFER_BIT; + public static final int STENCIL_BUFFER_BIT = GL.GL_STENCIL_BUFFER_BIT; + + public static final int FRAMEBUFFER = GL.GL_FRAMEBUFFER; + public static final int COLOR_ATTACHMENT0 = GL.GL_COLOR_ATTACHMENT0; + public static final int COLOR_ATTACHMENT1 = GL2.GL_COLOR_ATTACHMENT1; + public static final int COLOR_ATTACHMENT2 = GL2.GL_COLOR_ATTACHMENT2; + public static final int COLOR_ATTACHMENT3 = GL2.GL_COLOR_ATTACHMENT3; + public static final int RENDERBUFFER = GL.GL_RENDERBUFFER; + public static final int DEPTH_ATTACHMENT = GL.GL_DEPTH_ATTACHMENT; + public static final int STENCIL_ATTACHMENT = GL.GL_STENCIL_ATTACHMENT; + public static final int READ_FRAMEBUFFER = GL2.GL_READ_FRAMEBUFFER; + public static final int DRAW_FRAMEBUFFER = GL2.GL_DRAW_FRAMEBUFFER; + + public static final int RGBA8 = GL.GL_RGBA8; + public static final int DEPTH24_STENCIL8 = GL.GL_DEPTH24_STENCIL8; + + public static final int DEPTH_COMPONENT = GL2.GL_DEPTH_COMPONENT; + public static final int DEPTH_COMPONENT16 = GL.GL_DEPTH_COMPONENT16; + public static final int DEPTH_COMPONENT24 = GL.GL_DEPTH_COMPONENT24; + public static final int DEPTH_COMPONENT32 = GL.GL_DEPTH_COMPONENT32; + + public static final int STENCIL_INDEX = GL2.GL_STENCIL_INDEX; + public static final int STENCIL_INDEX1 = GL.GL_STENCIL_INDEX1; + public static final int STENCIL_INDEX4 = GL.GL_STENCIL_INDEX4; + public static final int STENCIL_INDEX8 = GL.GL_STENCIL_INDEX8; + + public static final int FRAMEBUFFER_COMPLETE = + GL.GL_FRAMEBUFFER_COMPLETE; + public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = + GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = + GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = + GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; + public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = + GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS; + public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = + GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; + public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = + GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; + public static final int FRAMEBUFFER_UNSUPPORTED = + GL.GL_FRAMEBUFFER_UNSUPPORTED; + + public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE; + public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME; + public static final int FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = GL2.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL; + public static final int FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = GL2.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE; + + public static final int RENDERBUFFER_WIDTH = GL2.GL_RENDERBUFFER_WIDTH; + public static final int RENDERBUFFER_HEIGHT = GL2.GL_RENDERBUFFER_HEIGHT; + public static final int RENDERBUFFER_RED_SIZE = GL2.GL_RENDERBUFFER_RED_SIZE; + public static final int RENDERBUFFER_GREEN_SIZE = GL2.GL_RENDERBUFFER_GREEN_SIZE; + public static final int RENDERBUFFER_BLUE_SIZE = GL2.GL_RENDERBUFFER_BLUE_SIZE; + public static final int RENDERBUFFER_ALPHA_SIZE = GL2.GL_RENDERBUFFER_ALPHA_SIZE; + public static final int RENDERBUFFER_DEPTH_SIZE = GL2.GL_RENDERBUFFER_DEPTH_SIZE; + public static final int RENDERBUFFER_STENCIL_SIZE = GL2.GL_RENDERBUFFER_STENCIL_SIZE; + public static final int RENDERBUFFER_INTERNAL_FORMAT = GL2.GL_RENDERBUFFER_INTERNAL_FORMAT; + + public static final int RGBA4 = GL2.GL_RGBA4; + public static final int RGB5_A1 = GL2.GL_RGB5_A1; + public static final int RGB565 = GL2.GL_RGB565; + + public static final int MAX_SAMPLES = GL2.GL_MAX_SAMPLES; + + public static final int MULTISAMPLE = GL.GL_MULTISAMPLE; + public static final int POINT_SMOOTH = GL2.GL_POINT_SMOOTH; + public static final int LINE_SMOOTH = GL.GL_LINE_SMOOTH; + public static final int POLYGON_SMOOTH = GL2.GL_POLYGON_SMOOTH; + + /////////////////////////////////////////////////////////// + + // Special Functions + + public void flush() { + gl.glFlush(); + } + + public void finish() { + gl.glFinish(); + } + + public void hint(int target, int hint) { + gl.glHint(target, hint); + } + + /////////////////////////////////////////////////////////// + + // State and State Requests + + public void enable(int value) { + if (-1 < value) { + gl.glEnable(value); + } + } + + public void disable(int value) { + if (-1 < value) { + gl.glDisable(value); + } + } + + public void getBooleanv(int value, IntBuffer data) { + if (-1 < value) { + if (byteBuffer.capacity() < data.capacity()) { + byteBuffer = allocateDirectByteBuffer(data.capacity()); + } + gl.glGetBooleanv(value, byteBuffer); + for (int i = 0; i < data.capacity(); i++) { + data.put(i, byteBuffer.get(i)); + } + } else { + fillIntBuffer(data, 0, data.capacity() - 1, 0); + } + } + + public void getIntegerv(int value, IntBuffer data) { + if (-1 < value) { + gl.glGetIntegerv(value, data); + } else { + fillIntBuffer(data, 0, data.capacity() - 1, 0); + } + } + + public void getFloatv(int value, FloatBuffer data) { + if (-1 < value) { + gl.glGetFloatv(value, data); + } else { + fillFloatBuffer(data, 0, data.capacity() - 1, 0); + } + } + + public boolean isEnabled(int value) { + return gl.glIsEnabled(value); + } + + public String getString(int name) { + return gl.glGetString(name); + } + + /////////////////////////////////////////////////////////// + + // Error Handling + + public int getError() { + return gl.glGetError(); + } + + public String errorString(int err) { + return glu.gluErrorString(err); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Buffer Objects + + public void genBuffers(int n, IntBuffer buffers) { + gl.glGenBuffers(n, buffers); + } + + public void deleteBuffers(int n, IntBuffer buffers) { + gl.glDeleteBuffers(n, buffers); + } + + public void bindBuffer(int target, int buffer) { + gl.glBindBuffer(target, buffer); + } + + public void bufferData(int target, int size, Buffer data, int usage) { + gl.glBufferData(target, size, data, usage); + } + + public void bufferSubData(int target, int offset, int size, Buffer data) { + gl.glBufferSubData(target, offset, size, data); + } + + public void isBuffer(int buffer) { + gl.glIsBuffer(buffer); + } + + public void getBufferParameteriv(int target, int value, IntBuffer data) { + gl.glGetBufferParameteriv(target, value, data); + } + + public ByteBuffer mapBuffer(int target, int access) { + return gl2.glMapBuffer(target, access); + } + + public ByteBuffer mapBufferRange(int target, int offset, int length, + int access) { + if (gl2x != null) { + return gl2x.glMapBufferRange(target, offset, length, access); + } else { + return null; + } + } + + public void unmapBuffer(int target) { + gl2.glUnmapBuffer(target); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Viewport and Clipping + + public void depthRangef(float n, float f) { + gl.glDepthRangef(n, f); + } + + public void viewport(int x, int y, int w, int h) { + gl.glViewport(x, y, w, h); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Reading Pixels + + public void readPixels(int x, int y, int width, int height, int format, + int type, Buffer buffer) { + gl.glReadPixels(x, y, width, height, format, type, buffer); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Vertices + + public void vertexAttrib1f(int index, float value) { + gl2.glVertexAttrib1f(index, value); + } + + public void vertexAttrib2f(int index, float value0, float value1) { + gl2.glVertexAttrib2f(index, value0, value1); + } + + public void vertexAttrib3f(int index, float value0, float value1, + float value2){ + gl2.glVertexAttrib3f(index, value0, value1, value2); + } + + public void vertexAttrib4f(int index, float value0, float value1, + float value2, float value3) { + gl2.glVertexAttrib4f(index, value0, value1, value2, value3); + } + + public void vertexAttrib1fv(int index, FloatBuffer values) { + gl2.glVertexAttrib1fv(index, values); + } + + public void vertexAttrib2fv(int index, FloatBuffer values) { + gl2.glVertexAttrib2fv(index, values); + } + + public void vertexAttrib3fv(int index, FloatBuffer values) { + gl2.glVertexAttrib3fv(index, values); + } + + public void vertexAttri4fv(int index, FloatBuffer values) { + gl2.glVertexAttrib4fv(index, values); + } + + public void vertexAttribPointer(int index, int size, int type, + boolean normalized, int stride, int offset) { + gl2.glVertexAttribPointer(index, size, type, normalized, stride, offset); + } + + public void vertexAttribPointer(int index, int size, int type, + boolean normalized, int stride, Buffer data) { + gl2.glVertexAttribPointer(index, size, type, normalized, stride, data); + } + + public void enableVertexAttribArray(int index) { + gl2.glEnableVertexAttribArray(index); + } + + public void disableVertexAttribArray(int index) { + gl2.glDisableVertexAttribArray(index); + } + + public void drawArrays(int mode, int first, int count) { + gl.glDrawArrays(mode, first, count); + } + + public void drawElements(int mode, int count, int type, int offset) { + gl.glDrawElements(mode, count, type, offset); + } + + public void drawElements(int mode, int count, int type, Buffer indices) { + gl.glDrawElements(mode, count, type, indices); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Rasterization + + public void lineWidth(float width) { + gl.glLineWidth(width); + } + + public void frontFace(int dir) { + gl.glFrontFace(dir); + } + + public void cullFace(int mode) { + gl.glCullFace(mode); + } + + public void polygonOffset(float factor, float units) { + gl.glPolygonOffset(factor, units); + } + + ////////////////////////////////////////////////////////////////////////////// + + // Pixel Rectangles + + public void pixelStorei(int pname, int param) { + gl.glPixelStorei(pname, param); + } + + /////////////////////////////////////////////////////////// + + // Texturing + + public void activeTexture(int texture) { + gl.glActiveTexture(texture); + } + + public void texImage2D(int target, int level, int internalFormat, + int width, int height, int border, int format, + int type, Buffer data) { + gl.glTexImage2D(target, level, internalFormat, + width, height, border, format, type, data); + } + + public void copyTexImage2D(int target, int level, int internalFormat, + int x, int y, int width, int height, int border) { + gl.glCopyTexImage2D(target, level, internalFormat, + x, y, width, height, border); + } + + public void texSubImage2D(int target, int level, int xOffset, int yOffset, + int width, int height, int format, + int type, Buffer data) { + gl.glTexSubImage2D(target, level, xOffset, yOffset, + width, height, format, type, data); + } + + public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, + int x, int y, int width, int height) { + gl.glCopyTexSubImage2D(target, level, x, y, xOffset, xOffset, + width, height); + } + + public void compressedTexImage2D(int target, int level, int internalFormat, + int width, int height, int border, + int imageSize, Buffer data) { + gl.glCompressedTexImage2D(target, level, internalFormat, + width, height, border, imageSize, data); + } + + public void compressedTexSubImage2D(int target, int level, + int xOffset, int yOffset, + int width, int height, int format, + int imageSize, Buffer data) { + gl.glCompressedTexSubImage2D(target, level, xOffset, yOffset, + width, height, format, imageSize, data); + } + + public void texParameteri(int target, int pname, int param) { + gl.glTexParameteri(target, pname, param); + } + + public void texParameterf(int target, int pname, float param) { + gl.glTexParameterf(target, pname, param); + } + + public void texParameteriv(int target, int pname, IntBuffer params) { + gl.glTexParameteriv(target, pname, params); + } + + public void texParameterfv(int target, int pname, FloatBuffer params) { + gl.glTexParameterfv(target, pname, params); + } + + public void generateMipmap(int target) { + gl.glGenerateMipmap(target); + } + + public void bindTexture(int target, int texture) { + gl.glBindTexture(target, texture); + if (target == TEXTURE_2D) { + boundTextures[0] = texture; + } else if (target == TEXTURE_RECTANGLE) { + boundTextures[1] = texture; + } + } + + public void genTextures(int n, IntBuffer textures) { + gl.glGenTextures(n, textures); + } + + public void deleteTextures(int n, IntBuffer textures) { + gl.glDeleteTextures(n, textures); + } + + public void getTexParameteriv(int target, int pname, IntBuffer params) { + gl.glGetTexParameteriv(target, pname, params); + } + + public void getTexParameterfv(int target, int pname, FloatBuffer params) { + gl.glGetTexParameterfv(target, pname, params); + } + + public boolean isTexture(int texture) { + return gl.glIsTexture(texture); + } + + /////////////////////////////////////////////////////////// + + // Shaders and Programs + + public int createShader(int type) { + return gl2.glCreateShader(type); + } + + public void shaderSource(int id, String source) { + gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0); + } + + public void compileShader(int id) { + gl2.glCompileShader(id); + } + + public void releaseShaderCompiler() { + gl2.glReleaseShaderCompiler(); + } + + public void deleteShader(int id) { + gl2.glDeleteShader(id); + } + + public void shaderBinary(int count, IntBuffer shaders, int binaryFormat, + Buffer binary, int length) { + gl2.glShaderBinary(count, shaders, binaryFormat, binary, length); + } + + public int createProgram() { + return gl2.glCreateProgram(); + } + + public void attachShader(int program, int shader) { + gl2.glAttachShader(program, shader); + } + + public void detachShader(int program, int shader) { + gl2.glDetachShader(program, shader); + } + + public void linkProgram(int program) { + gl2.glLinkProgram(program); + } + + public void useProgram(int program) { + gl2.glUseProgram(program); + } + + public void deleteProgram(int program) { + gl2.glDeleteProgram(program); + } + + public void getActiveAttrib(int program, int index, int bufSize, + IntBuffer length, IntBuffer size, IntBuffer type, + ByteBuffer name) { + gl2.glGetActiveAttrib(program, index, bufSize, length, size, type, name); + } + + public int getAttribLocation(int prog, String name) { + return gl2.glGetAttribLocation(prog, name); + } + + public void bindAttribLocation(int program, int index, String name) { + gl2.glBindAttribLocation(program, index, name); + } + + public int getUniformLocation(int prog, String name) { + return gl2.glGetUniformLocation(prog, name); + } + + public void getActiveUniform(int program, int index, int bufSize, + IntBuffer length, IntBuffer size, IntBuffer type, + ByteBuffer name) { + gl2.glGetActiveUniform(program, index, bufSize, length, size, type, name); + } + + public void uniform1i(int location, int value) { + gl2.glUniform1i(location, value); + } + + public void uniform2i(int location, int value0, int value1) { + gl2.glUniform2i(location, value0, value1); + } + + public void uniform3i(int location, int value0, int value1, int value2) { + gl2.glUniform3i(location, value0, value1, value2); + } + + public void uniform4i(int location, int value0, int value1, int value2, + int value3) { + gl2.glUniform4i(location, value0, value1, value2, value3); + } + + public void uniform1f(int location, float value) { + gl2.glUniform1f(location, value); + } + + public void uniform2f(int location, float value0, float value1) { + gl2.glUniform2f(location, value0, value1); + } + + public void uniform3f(int location, float value0, float value1, + float value2) { + gl2.glUniform3f(location, value0, value1, value2); + } + + public void uniform4f(int location, float value0, float value1, float value2, + float value3) { + gl2.glUniform4f(location, value0, value1, value2, value3); + } + + public void uniform1iv(int location, int count, IntBuffer v) { + gl2.glUniform1iv(location, count, v); + } + + public void uniform2iv(int location, int count, IntBuffer v) { + gl2.glUniform2iv(location, count, v); + } + + public void uniform3iv(int location, int count, IntBuffer v) { + gl2.glUniform3iv(location, count, v); + } + + public void uniform4iv(int location, int count, IntBuffer v) { + gl2.glUniform4iv(location, count, v); + } + + public void uniform1fv(int location, int count, FloatBuffer v) { + gl2.glUniform1fv(location, count, v); + } + + public void uniform2fv(int location, int count, FloatBuffer v) { + gl2.glUniform2fv(location, count, v); + } + + public void uniform3fv(int location, int count, FloatBuffer v) { + gl2.glUniform3fv(location, count, v); + } + + public void uniform4fv(int location, int count, FloatBuffer v) { + gl2.glUniform4fv(location, count, v); + } + + public void uniformMatrix2fv(int location, int count, boolean transpose, + FloatBuffer mat) { + gl2.glUniformMatrix2fv(location, count, transpose, mat); + } + + public void uniformMatrix3fv(int location, int count, boolean transpose, + FloatBuffer mat) { + gl2.glUniformMatrix3fv(location, count, transpose, mat); + } + + public void uniformMatrix4fv(int location, int count, boolean transpose, + FloatBuffer mat) { + gl2.glUniformMatrix4fv(location, count, transpose, mat); + } + + public void validateProgram(int prog) { + gl2.glValidateProgram(prog); + } + + public boolean isShader(int shader) { + return gl2.glIsShader(shader); + } + + public void getShaderiv(int shader, int pname, IntBuffer params) { + gl2.glGetShaderiv(shader, pname, params); + } + + public void getAttachedShaders(int program, int maxCount, IntBuffer count, + IntBuffer shaders) { + gl2.glGetAttachedShaders(program, maxCount, count, shaders); + } + + public String getShaderInfoLog(int shader) { + int[] val = { 0 }; + gl2.glGetShaderiv(shader, GL2.GL_INFO_LOG_LENGTH, val, 0); + int length = val[0]; + + byte[] log = new byte[length]; + gl2.glGetShaderInfoLog(shader, length, val, 0, log, 0); + return new String(log); + } + + public void getShaderSource(int shader, int bufSize, IntBuffer length, + ByteBuffer source) { + gl2.glGetShaderSource(shader, bufSize, length, source); + } + + public void getShaderPrecisionFormat(int shaderType, int precisionType, + IntBuffer range, IntBuffer precision) { + gl2.glGetShaderPrecisionFormat(shaderType, precisionType, range, precision); + } + + public void getVertexAttribfv(int index, int pname, FloatBuffer params) { + gl2.glGetVertexAttribfv(index, pname, params); + } + + public void getVertexAttribiv(int index, int pname, IntBuffer params) { + gl2.glGetVertexAttribiv(index, pname, params); + } + + public void getVertexAttribPointerv() { + throw new RuntimeException("Function glGetVertexAttribPointerv() is not available"); + } + + public void getUniformfv(int program, int location, FloatBuffer params) { + gl2.glGetUniformfv(program, location, params); + } + + public void getUniformiv(int program, int location, IntBuffer params) { + gl2.glGetUniformiv(program, location, params); + } + + public boolean isProgram(int program) { + return gl2.glIsProgram(program); + } + + public void getProgramiv(int prog, int pname, IntBuffer params) { + gl2.glGetProgramiv(prog, pname, params); + } + + public String getProgramInfoLog(int prog) { + int[] val = { 0 }; + gl2.glGetShaderiv(prog, GL2.GL_INFO_LOG_LENGTH, val, 0); + int length = val[0]; + + if (0 < length) { + byte[] log = new byte[length]; + gl2.glGetProgramInfoLog(prog, length, val, 0, log, 0); + return new String(log); + } else { + return "Unknow error"; + } + } + + /////////////////////////////////////////////////////////// + + // Per-Fragment Operations + + public void scissor(int x, int y, int w, int h) { + gl.glScissor(x, y, w, h); + } + + public void sampleCoverage(float value, boolean invert) { + gl2.glSampleCoverage(value, invert); + } + + public void stencilFunc(int func, int ref, int mask) { + gl2.glStencilFunc(func, ref, mask); + } + + public void stencilFuncSeparate(int face, int func, int ref, int mask) { + gl2.glStencilFuncSeparate(face, func, ref, mask); + } + + public void stencilOp(int sfail, int dpfail, int dppass) { + gl2.glStencilOp(sfail, dpfail, dppass); + } + + public void stencilOpSeparate(int face, int sfail, int dpfail, int dppass) { + gl2.glStencilOpSeparate(face, sfail, dpfail, dppass); + } + + public void depthFunc(int func) { + gl.glDepthFunc(func); + } + + public void blendEquation(int mode) { + gl.glBlendEquation(mode); + } + + public void blendEquationSeparate(int modeRGB, int modeAlpha) { + gl.glBlendEquationSeparate(modeRGB, modeAlpha); + } + + public void blendFunc(int src, int dst) { + gl.glBlendFunc(src, dst); + } + + public void blendFuncSeparate(int srcRGB, int dstRGB, + int srcAlpha, int dstAlpha) { + gl.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); + } + + public void blendColor(float red, float green, float blue, float alpha) { + gl2.glBlendColor(red, green, blue, alpha); + } + + public void alphaFunc(int func, float ref) { + if (gl2x != null) { + gl2x.glAlphaFunc(func, ref); + } + } + + /////////////////////////////////////////////////////////// + + // Whole Framebuffer Operations + + public void colorMask(boolean r, boolean g, boolean b, boolean a) { + gl.glColorMask(r, g, b, a); + } + + public void depthMask(boolean mask) { + gl.glDepthMask(mask); + } + + public void stencilMask(int mask) { + gl.glStencilMask(mask); + } + + public void stencilMaskSeparate(int face, int mask) { + gl2.glStencilMaskSeparate(face, mask); + } + + public void clear(int buf) { + gl.glClear(buf); + } + + public void clearColor(float r, float g, float b, float a) { + gl.glClearColor(r, g, b, a); + } + + public void clearDepth(float d) { + gl.glClearDepthf(d); + } + + public void clearStencil(int s) { + gl.glClearStencil(s); + } + + /////////////////////////////////////////////////////////// + + // Framebuffers Objects + + public void bindFramebuffer(int target, int framebuffer) { + gl.glBindFramebuffer(target, framebuffer); + } + + public void deleteFramebuffers(int n, IntBuffer framebuffers) { + gl.glDeleteFramebuffers(n, framebuffers); + } + + public void genFramebuffers(int n, IntBuffer framebuffers) { + gl.glGenFramebuffers(n, framebuffers); + } + + public void bindRenderbuffer(int target, int renderbuffer) { + gl.glBindRenderbuffer(target, renderbuffer); + } + + public void deleteRenderbuffers(int n, IntBuffer renderbuffers) { + gl.glDeleteRenderbuffers(n, renderbuffers); + } + + public void genRenderbuffers(int n, IntBuffer renderbuffers) { + gl.glGenRenderbuffers(n, renderbuffers); + } + + public void renderbufferStorage(int target, int internalFormat, + int width, int height) { + gl.glRenderbufferStorage(target, internalFormat, width, height); + } + + public void framebufferRenderbuffer(int target, int attachment, + int rendbuferfTarget, int renderbuffer) { + gl.glFramebufferRenderbuffer(target, attachment, rendbuferfTarget, + renderbuffer); + } + + public void framebufferTexture2D(int target, int attachment, int texTarget, + int texture, int level) { + gl.glFramebufferTexture2D(target, attachment, texTarget, texture, level); + } + + public int checkFramebufferStatus(int target) { + return gl.glCheckFramebufferStatus(target); + } + + public boolean isFramebuffer(int framebuffer) { + return gl2.glIsFramebuffer(framebuffer); + } + + public void getFramebufferAttachmentParameteriv(int target, int attachment, + int pname, IntBuffer params) { + gl2.glGetFramebufferAttachmentParameteriv(target, attachment, pname, + params); + } + + public boolean isRenderbuffer(int renderbuffer) { + return gl2.glIsRenderbuffer(renderbuffer); + } + + public void getRenderbufferParameteriv(int target, int pname, + IntBuffer params) { + gl2.glGetRenderbufferParameteriv(target, pname, params); + } + + 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); + } + } + + public void renderbufferStorageMultisample(int target, int samples, + int format, int width, int height){ + if (gl2x != null) { + gl2x.glRenderbufferStorageMultisample(target, samples, format, + width, height); + } + } + + public void readBuffer(int buf) { + if (gl2x != null) { + gl2x.glReadBuffer(buf); + } + } + + public void drawBuffer(int buf) { + if (gl2x != null) { + gl2x.glDrawBuffer(buf); + } + } } From 8a0fc976b7bbedfac340d6b6dd372c859d0f014d Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 23 May 2013 16:52:14 -0400 Subject: [PATCH 12/46] Formatting, fixing some implementations in PGL --- core/src/processing/opengl/PGL.java | 456 ++--- .../lwjgl/src/processing/lwjgl/PGL.java | 1736 +++++++++-------- 2 files changed, 1084 insertions(+), 1108 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 4e4e78a31..0c0d496f6 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -361,6 +361,19 @@ public class PGL { protected float[] projMatrix; protected float[] mvMatrix; + /////////////////////////////////////////////////////////// + + // Error messages + + protected static final String MISSING_FBO_ERROR = + "Framebuffer objects are not supported by this hardware (or driver)"; + + protected static final String MISSING_GLSL_ERROR = + "GLSL shaders are not supported by this hardware (or driver)"; + + protected static final String MISSING_GLFUNC_ERROR = + "GL function %1$s is not available on this hardware (or driver)"; + /////////////////////////////////////////////////////////// @@ -2450,10 +2463,10 @@ public class PGL { gl = context.getGL(); if (!hasFBOs()) { - throw new RuntimeException("Framebuffer objects are not supported by this hardware (or driver)"); + throw new RuntimeException(MISSING_FBO_ERROR); } if (!hasShaders()) { - throw new RuntimeException("GLSL shaders are not supported by this hardware (or driver)"); + throw new RuntimeException(MISSING_GLSL_ERROR); } } @@ -2631,17 +2644,28 @@ public class PGL { public static final int FALSE = GL.GL_FALSE; public static final int TRUE = GL.GL_TRUE; - public static final int INT = GL2.GL_INT; - public static final int BYTE = GL.GL_BYTE; - public static final int SHORT = GL.GL_SHORT; + public static final int INT = GL2.GL_INT; + public static final int BYTE = GL.GL_BYTE; + public static final int SHORT = GL.GL_SHORT; public static final int FLOAT = GL.GL_FLOAT; + public static final int BOOL = GL2.GL_BOOL; public static final int UNSIGNED_INT = GL.GL_UNSIGNED_INT; public static final int UNSIGNED_BYTE = GL.GL_UNSIGNED_BYTE; public static final int UNSIGNED_SHORT = GL.GL_UNSIGNED_SHORT; - public static final int RGB = GL.GL_RGB; - public static final int RGBA = GL.GL_RGBA; - public static final int ALPHA = GL.GL_ALPHA; + public static final int RGB = GL.GL_RGB; + public static final int RGBA = GL.GL_RGBA; + public static final int ALPHA = GL.GL_ALPHA; + public static final int LUMINANCE = GL.GL_LUMINANCE; + public static final int LUMINANCE_ALPHA = GL.GL_LUMINANCE_ALPHA; + + public static final int UNSIGNED_SHORT_5_6_5 = GL.GL_UNSIGNED_SHORT_5_6_5; + public static final int UNSIGNED_SHORT_4_4_4_4 = GL.GL_UNSIGNED_SHORT_4_4_4_4; + public static final int UNSIGNED_SHORT_5_5_5_1 = GL.GL_UNSIGNED_SHORT_5_5_5_1; + + public static final int RGBA4 = GL2.GL_RGBA4; + public static final int RGB5_A1 = GL2.GL_RGB5_A1; + public static final int RGB565 = GL2.GL_RGB565; public static final int READ_ONLY = GL2.GL_READ_ONLY; public static final int WRITE_ONLY = GL2.GL_WRITE_ONLY; @@ -2651,32 +2675,35 @@ public class PGL { public static final int TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; public static final int GENERATE_MIPMAP_HINT = GL.GL_GENERATE_MIPMAP_HINT; - public static final int FASTEST = GL.GL_FASTEST; - public static final int NICEST = GL.GL_NICEST; - public static final int DONT_CARE = GL.GL_DONT_CARE; + public static final int FASTEST = GL.GL_FASTEST; + public static final int NICEST = GL.GL_NICEST; + public static final int DONT_CARE = GL.GL_DONT_CARE; public static final int VENDOR = GL.GL_VENDOR; public static final int RENDERER = GL.GL_RENDERER; public static final int VERSION = GL.GL_VERSION; public static final int EXTENSIONS = GL.GL_EXTENSIONS; - public static final int SHADING_LANGUAGE_VERSION = - GL2ES2.GL_SHADING_LANGUAGE_VERSION; + public static final int SHADING_LANGUAGE_VERSION = GL2ES2.GL_SHADING_LANGUAGE_VERSION; - public static final int ALIASED_LINE_WIDTH_RANGE = - GL.GL_ALIASED_LINE_WIDTH_RANGE; - public static final int ALIASED_POINT_SIZE_RANGE = - GL.GL_ALIASED_POINT_SIZE_RANGE; - public static final int DEPTH_BITS = GL.GL_DEPTH_BITS; + public static final int MAX_SAMPLES = GL2.GL_MAX_SAMPLES; + public static final int SAMPLES = GL.GL_SAMPLES; + + public static final int ALIASED_LINE_WIDTH_RANGE = GL.GL_ALIASED_LINE_WIDTH_RANGE; + public static final int ALIASED_POINT_SIZE_RANGE = GL.GL_ALIASED_POINT_SIZE_RANGE; + + public static final int DEPTH_BITS = GL.GL_DEPTH_BITS; public static final int STENCIL_BITS = GL.GL_STENCIL_BITS; - public static final int CCW = GL.GL_CCW; - public static final int CW = GL.GL_CW; + public static final int CCW = GL.GL_CCW; + public static final int CW = GL.GL_CW; + public static final int VIEWPORT = GL.GL_VIEWPORT; - public static final int SAMPLES = GL.GL_SAMPLES; public static final int ARRAY_BUFFER = GL.GL_ARRAY_BUFFER; public static final int ELEMENT_ARRAY_BUFFER = GL.GL_ELEMENT_ARRAY_BUFFER; + public static final int MAX_VERTEX_ATTRIBS = GL2.GL_MAX_VERTEX_ATTRIBS; + public static final int STATIC_DRAW = GL.GL_STATIC_DRAW; public static final int DYNAMIC_DRAW = GL.GL_DYNAMIC_DRAW; public static final int STREAM_DRAW = GL2.GL_STREAM_DRAW; @@ -2684,16 +2711,14 @@ public class PGL { public static final int BUFFER_SIZE = GL.GL_BUFFER_SIZE; public static final int BUFFER_USAGE = GL.GL_BUFFER_USAGE; - public static final int POINTS = GL.GL_POINTS; - public static final int LINE_STRIP = GL.GL_LINE_STRIP; - public static final int LINE_LOOP = GL.GL_LINE_LOOP; - public static final int LINES = GL.GL_LINES; + public static final int POINTS = GL.GL_POINTS; + public static final int LINE_STRIP = GL.GL_LINE_STRIP; + public static final int LINE_LOOP = GL.GL_LINE_LOOP; + public static final int LINES = GL.GL_LINES; public static final int TRIANGLE_FAN = GL.GL_TRIANGLE_FAN; public static final int TRIANGLE_STRIP = GL.GL_TRIANGLE_STRIP; public static final int TRIANGLES = GL.GL_TRIANGLES; - public static final int MAX_VERTEX_ATTRIBS = GL2.GL_MAX_VERTEX_ATTRIBS; - public static final int CULL_FACE = GL.GL_CULL_FACE; public static final int FRONT = GL.GL_FRONT; public static final int BACK = GL.GL_BACK; @@ -2702,27 +2727,26 @@ public class PGL { public static final int POLYGON_OFFSET_FILL = GL.GL_POLYGON_OFFSET_FILL; public static final int UNPACK_ALIGNMENT = GL.GL_UNPACK_ALIGNMENT; - public static final int PACK_ALIGNMENT = GL.GL_PACK_ALIGNMENT; + public static final int PACK_ALIGNMENT = GL.GL_PACK_ALIGNMENT; public static final int TEXTURE_2D = GL.GL_TEXTURE_2D; public static final int TEXTURE_RECTANGLE = GL2.GL_TEXTURE_RECTANGLE; public static final int TEXTURE_BINDING_2D = GL.GL_TEXTURE_BINDING_2D; - public static final int TEXTURE_BINDING_RECTANGLE = - GL2.GL_TEXTURE_BINDING_RECTANGLE; + public static final int TEXTURE_BINDING_RECTANGLE = GL2.GL_TEXTURE_BINDING_RECTANGLE; - public static final int MAX_TEXTURE_SIZE = GL.GL_MAX_TEXTURE_SIZE; + public static final int MAX_TEXTURE_SIZE = GL.GL_MAX_TEXTURE_SIZE; + public static final int TEXTURE_MAX_ANISOTROPY = GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; + public static final int MAX_TEXTURE_MAX_ANISOTROPY = GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; + + public static final int MAX_VERTEX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; + public static final int MAX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; public static final int NEAREST = GL.GL_NEAREST; public static final int LINEAR = GL.GL_LINEAR; public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST; public static final int LINEAR_MIPMAP_LINEAR = GL.GL_LINEAR_MIPMAP_LINEAR; - public static final int TEXTURE_MAX_ANISOTROPY = - GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; - public static final int MAX_TEXTURE_MAX_ANISOTROPY = - GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; - public static final int CLAMP_TO_EDGE = GL.GL_CLAMP_TO_EDGE; public static final int REPEAT = GL.GL_REPEAT; @@ -2735,32 +2759,13 @@ public class PGL { public static final int TEXTURE_WRAP_S = GL.GL_TEXTURE_WRAP_S; public static final int TEXTURE_WRAP_T = GL.GL_TEXTURE_WRAP_T; - public static final int MAX_VERTEX_TEXTURE_IMAGE_UNITS = - GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; - public static final int MAX_TEXTURE_IMAGE_UNITS = - GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; - - public static final int TEXTURE_CUBE_MAP_POSITIVE_X = - GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X; - public static final int TEXTURE_CUBE_MAP_POSITIVE_Y = - GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y; - public static final int TEXTURE_CUBE_MAP_POSITIVE_Z = - GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z; - public static final int TEXTURE_CUBE_MAP_NEGATIVE_X = - GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X; - public static final int TEXTURE_CUBE_MAP_NEGATIVE_Y = - GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; - public static final int TEXTURE_CUBE_MAP_NEGATIVE_Z = - GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; - - public static final int LUMINANCE = GL.GL_LUMINANCE; - public static final int LUMINANCE_ALPHA = GL.GL_LUMINANCE_ALPHA; - - public static final int UNSIGNED_SHORT_5_6_5 = GL.GL_UNSIGNED_SHORT_5_6_5; - public static final int UNSIGNED_SHORT_4_4_4_4 = GL.GL_UNSIGNED_SHORT_4_4_4_4; - public static final int UNSIGNED_SHORT_5_5_5_1 = GL.GL_UNSIGNED_SHORT_5_5_5_1; - public static final int TEXTURE_CUBE_MAP = GL.GL_TEXTURE_CUBE_MAP; + public static final int TEXTURE_CUBE_MAP_POSITIVE_X = GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X; + public static final int TEXTURE_CUBE_MAP_POSITIVE_Y = GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y; + public static final int TEXTURE_CUBE_MAP_POSITIVE_Z = GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_X = GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_Y = GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; + public static final int TEXTURE_CUBE_MAP_NEGATIVE_Z = GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; public static final int VERTEX_SHADER = GL2.GL_VERTEX_SHADER; public static final int FRAGMENT_SHADER = GL2.GL_FRAGMENT_SHADER; @@ -2769,41 +2774,39 @@ public class PGL { public static final int COMPILE_STATUS = GL2.GL_COMPILE_STATUS; public static final int LINK_STATUS = GL2.GL_LINK_STATUS; public static final int VALIDATE_STATUS = GL2.GL_VALIDATE_STATUS; + public static final int SHADER_TYPE = GL2.GL_SHADER_TYPE; + public static final int DELETE_STATUS = GL2.GL_DELETE_STATUS; - public static final int FLOAT_VEC2 = GL2.GL_FLOAT_VEC2; - public static final int FLOAT_VEC3 = GL2.GL_FLOAT_VEC3; - public static final int FLOAT_VEC4 = GL2.GL_FLOAT_VEC4; - public static final int FLOAT_MAT2 = GL2.GL_FLOAT_MAT2; - public static final int FLOAT_MAT3 = GL2.GL_FLOAT_MAT3; - public static final int FLOAT_MAT4 = GL2.GL_FLOAT_MAT4; - public static final int INT_VEC2 = GL2.GL_INT_VEC2; - public static final int INT_VEC3 = GL2.GL_INT_VEC3; - public static final int INT_VEC4 = GL2.GL_INT_VEC4; - public static final int BOOL = GL2.GL_BOOL; - public static final int BOOL_VEC2 = GL2.GL_BOOL_VEC2; - public static final int BOOL_VEC3 = GL2.GL_BOOL_VEC3; - public static final int BOOL_VEC4 = GL2.GL_BOOL_VEC4; - public static final int SAMPLER_2D = GL2.GL_SAMPLER_2D; + public static final int FLOAT_VEC2 = GL2.GL_FLOAT_VEC2; + public static final int FLOAT_VEC3 = GL2.GL_FLOAT_VEC3; + public static final int FLOAT_VEC4 = GL2.GL_FLOAT_VEC4; + public static final int FLOAT_MAT2 = GL2.GL_FLOAT_MAT2; + public static final int FLOAT_MAT3 = GL2.GL_FLOAT_MAT3; + public static final int FLOAT_MAT4 = GL2.GL_FLOAT_MAT4; + public static final int INT_VEC2 = GL2.GL_INT_VEC2; + public static final int INT_VEC3 = GL2.GL_INT_VEC3; + public static final int INT_VEC4 = GL2.GL_INT_VEC4; + public static final int BOOL_VEC2 = GL2.GL_BOOL_VEC2; + public static final int BOOL_VEC3 = GL2.GL_BOOL_VEC3; + public static final int BOOL_VEC4 = GL2.GL_BOOL_VEC4; + public static final int SAMPLER_2D = GL2.GL_SAMPLER_2D; public static final int SAMPLER_CUBE = GL2.GL_SAMPLER_CUBE; - public static final int SHADER_TYPE = GL2.GL_SHADER_TYPE; - public static final int DELETE_STATUS = GL2.GL_DELETE_STATUS; - - public static final int LOW_FLOAT = GL2.GL_LOW_FLOAT; + public static final int LOW_FLOAT = GL2.GL_LOW_FLOAT; public static final int MEDIUM_FLOAT = GL2.GL_MEDIUM_FLOAT; - public static final int HIGH_FLOAT = GL2.GL_HIGH_FLOAT; - public static final int LOW_INT = GL2.GL_LOW_INT; - public static final int MEDIUM_INT = GL2.GL_MEDIUM_INT; - public static final int HIGH_INT = GL2.GL_HIGH_INT; + public static final int HIGH_FLOAT = GL2.GL_HIGH_FLOAT; + public static final int LOW_INT = GL2.GL_LOW_INT; + public static final int MEDIUM_INT = GL2.GL_MEDIUM_INT; + public static final int HIGH_INT = GL2.GL_HIGH_INT; public static final int CURRENT_VERTEX_ATTRIB = GL2.GL_CURRENT_VERTEX_ATTRIB; public static final int VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = GL2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING; - public static final int VERTEX_ATTRIB_ARRAY_ENABLED = GL2.GL_VERTEX_ATTRIB_ARRAY_ENABLED; - public static final int VERTEX_ATTRIB_ARRAY_SIZE = GL2.GL_VERTEX_ATTRIB_ARRAY_SIZE; - public static final int VERTEX_ATTRIB_ARRAY_STRIDE = GL2.GL_VERTEX_ATTRIB_ARRAY_STRIDE; - public static final int VERTEX_ATTRIB_ARRAY_TYPE = GL2.GL_VERTEX_ATTRIB_ARRAY_TYPE; - public static final int VERTEX_ATTRIB_ARRAY_NORMALIZED = GL2.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED; + public static final int VERTEX_ATTRIB_ARRAY_ENABLED = GL2.GL_VERTEX_ATTRIB_ARRAY_ENABLED; + public static final int VERTEX_ATTRIB_ARRAY_SIZE = GL2.GL_VERTEX_ATTRIB_ARRAY_SIZE; + public static final int VERTEX_ATTRIB_ARRAY_STRIDE = GL2.GL_VERTEX_ATTRIB_ARRAY_STRIDE; + public static final int VERTEX_ATTRIB_ARRAY_TYPE = GL2.GL_VERTEX_ATTRIB_ARRAY_TYPE; + public static final int VERTEX_ATTRIB_ARRAY_NORMALIZED = GL2.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED; public static final int BLEND = GL.GL_BLEND; public static final int ONE = GL.GL_ONE; @@ -2817,43 +2820,43 @@ public class PGL { public static final int SRC_COLOR = GL.GL_SRC_COLOR; public static final int SAMPLE_ALPHA_TO_COVERAGE = GL.GL_SAMPLE_ALPHA_TO_COVERAGE; - public static final int SAMPLE_COVERAGE = GL.GL_SAMPLE_COVERAGE; + public static final int SAMPLE_COVERAGE = GL.GL_SAMPLE_COVERAGE; - public static final int KEEP = GL.GL_KEEP; - public static final int REPLACE = GL.GL_REPLACE; - public static final int INCR = GL.GL_INCR; - public static final int DECR = GL.GL_DECR; - public static final int INVERT = GL.GL_INVERT; + public static final int KEEP = GL.GL_KEEP; + public static final int REPLACE = GL.GL_REPLACE; + public static final int INCR = GL.GL_INCR; + public static final int DECR = GL.GL_DECR; + public static final int INVERT = GL.GL_INVERT; public static final int INCR_WRAP = GL.GL_INCR_WRAP; public static final int DECR_WRAP = GL.GL_DECR_WRAP; - public static final int NEVER = GL.GL_NEVER; - public static final int ALWAYS = GL.GL_ALWAYS; + public static final int NEVER = GL.GL_NEVER; + public static final int ALWAYS = GL.GL_ALWAYS; - public static final int EQUAL = GL.GL_EQUAL; - public static final int LESS = GL.GL_LESS; - public static final int LEQUAL = GL.GL_LEQUAL; - public static final int GREATER = GL.GL_GREATER; - public static final int GEQUAL = GL.GL_GEQUAL; + public static final int EQUAL = GL.GL_EQUAL; + public static final int LESS = GL.GL_LESS; + public static final int LEQUAL = GL.GL_LEQUAL; + public static final int GREATER = GL.GL_GREATER; + public static final int GEQUAL = GL.GL_GEQUAL; public static final int NOTEQUAL = GL.GL_NOTEQUAL; public static final int FUNC_ADD = GL.GL_FUNC_ADD; public static final int FUNC_MIN = GL2.GL_MIN; public static final int FUNC_MAX = GL2.GL_MAX; public static final int FUNC_REVERSE_SUBTRACT = GL.GL_FUNC_REVERSE_SUBTRACT; - public static final int FUNC_SUBTRACT = GL.GL_FUNC_SUBTRACT; + public static final int FUNC_SUBTRACT = GL.GL_FUNC_SUBTRACT; public static final int DITHER = GL.GL_DITHER; - public static final int CONSTANT_COLOR = GL2.GL_CONSTANT_COLOR; - public static final int CONSTANT_ALPHA = GL2.GL_CONSTANT_ALPHA; + public static final int CONSTANT_COLOR = GL2.GL_CONSTANT_COLOR; + public static final int CONSTANT_ALPHA = GL2.GL_CONSTANT_ALPHA; public static final int ONE_MINUS_CONSTANT_COLOR = GL2.GL_ONE_MINUS_CONSTANT_COLOR; public static final int ONE_MINUS_CONSTANT_ALPHA = GL2.GL_ONE_MINUS_CONSTANT_ALPHA; - public static final int SRC_ALPHA_SATURATE = GL.GL_SRC_ALPHA_SATURATE; + public static final int SRC_ALPHA_SATURATE = GL.GL_SRC_ALPHA_SATURATE; public static final int SCISSOR_TEST = GL.GL_SCISSOR_TEST; public static final int DEPTH_TEST = GL.GL_DEPTH_TEST; public static final int DEPTH_WRITEMASK = GL.GL_DEPTH_WRITEMASK; - public static final int ALPHA_TEST = GL2.GL_ALPHA_TEST; + public static final int ALPHA_TEST = GL2.GL_ALPHA_TEST; public static final int COLOR_BUFFER_BIT = GL.GL_COLOR_BUFFER_BIT; public static final int DEPTH_BUFFER_BIT = GL.GL_DEPTH_BUFFER_BIT; @@ -2883,44 +2886,30 @@ public class PGL { public static final int STENCIL_INDEX4 = GL.GL_STENCIL_INDEX4; public static final int STENCIL_INDEX8 = GL.GL_STENCIL_INDEX8; - public static final int FRAMEBUFFER_COMPLETE = - GL.GL_FRAMEBUFFER_COMPLETE; - public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = - GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = - GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = - GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; - public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = - GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS; - public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = - GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; - public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = - GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; - public static final int FRAMEBUFFER_UNSUPPORTED = - GL.GL_FRAMEBUFFER_UNSUPPORTED; + public static final int FRAMEBUFFER_COMPLETE = GL.GL_FRAMEBUFFER_COMPLETE; + public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; + public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS; + public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; + public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; + public static final int FRAMEBUFFER_UNSUPPORTED = GL.GL_FRAMEBUFFER_UNSUPPORTED; - public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE; - public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME; - public static final int FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = GL2.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL; + public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE; + public static final int FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = GL2.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME; + public static final int FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = GL2.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL; public static final int FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = GL2.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE; - public static final int RENDERBUFFER_WIDTH = GL2.GL_RENDERBUFFER_WIDTH; - public static final int RENDERBUFFER_HEIGHT = GL2.GL_RENDERBUFFER_HEIGHT; - public static final int RENDERBUFFER_RED_SIZE = GL2.GL_RENDERBUFFER_RED_SIZE; - public static final int RENDERBUFFER_GREEN_SIZE = GL2.GL_RENDERBUFFER_GREEN_SIZE; - public static final int RENDERBUFFER_BLUE_SIZE = GL2.GL_RENDERBUFFER_BLUE_SIZE; - public static final int RENDERBUFFER_ALPHA_SIZE = GL2.GL_RENDERBUFFER_ALPHA_SIZE; - public static final int RENDERBUFFER_DEPTH_SIZE = GL2.GL_RENDERBUFFER_DEPTH_SIZE; - public static final int RENDERBUFFER_STENCIL_SIZE = GL2.GL_RENDERBUFFER_STENCIL_SIZE; + public static final int RENDERBUFFER_WIDTH = GL2.GL_RENDERBUFFER_WIDTH; + public static final int RENDERBUFFER_HEIGHT = GL2.GL_RENDERBUFFER_HEIGHT; + public static final int RENDERBUFFER_RED_SIZE = GL2.GL_RENDERBUFFER_RED_SIZE; + public static final int RENDERBUFFER_GREEN_SIZE = GL2.GL_RENDERBUFFER_GREEN_SIZE; + public static final int RENDERBUFFER_BLUE_SIZE = GL2.GL_RENDERBUFFER_BLUE_SIZE; + public static final int RENDERBUFFER_ALPHA_SIZE = GL2.GL_RENDERBUFFER_ALPHA_SIZE; + public static final int RENDERBUFFER_DEPTH_SIZE = GL2.GL_RENDERBUFFER_DEPTH_SIZE; + public static final int RENDERBUFFER_STENCIL_SIZE = GL2.GL_RENDERBUFFER_STENCIL_SIZE; public static final int RENDERBUFFER_INTERNAL_FORMAT = GL2.GL_RENDERBUFFER_INTERNAL_FORMAT; - public static final int RGBA4 = GL2.GL_RGBA4; - public static final int RGB5_A1 = GL2.GL_RGB5_A1; - public static final int RGB565 = GL2.GL_RGB565; - - public static final int MAX_SAMPLES = GL2.GL_MAX_SAMPLES; - public static final int MULTISAMPLE = GL.GL_MULTISAMPLE; public static final int POINT_SMOOTH = GL2.GL_POINT_SMOOTH; public static final int LINE_SMOOTH = GL.GL_LINE_SMOOTH; @@ -3044,8 +3033,7 @@ public class PGL { return gl2.glMapBuffer(target, access); } - public ByteBuffer mapBufferRange(int target, int offset, int length, - int access) { + public ByteBuffer mapBufferRange(int target, int offset, int length, int access) { if (gl2x != null) { return gl2x.glMapBufferRange(target, offset, length, access); } else { @@ -3073,8 +3061,7 @@ public class PGL { // Reading Pixels - public void readPixels(int x, int y, int width, int height, int format, - int type, Buffer buffer) { + public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) { gl.glReadPixels(x, y, width, height, format, type, buffer); } @@ -3090,13 +3077,11 @@ public class PGL { gl2.glVertexAttrib2f(index, value0, value1); } - public void vertexAttrib3f(int index, float value0, float value1, - float value2){ + public void vertexAttrib3f(int index, float value0, float value1, float value2) { gl2.glVertexAttrib3f(index, value0, value1, value2); } - public void vertexAttrib4f(int index, float value0, float value1, - float value2, float value3) { + public void vertexAttrib4f(int index, float value0, float value1, float value2, float value3) { gl2.glVertexAttrib4f(index, value0, value1, value2, value3); } @@ -3116,13 +3101,11 @@ public class PGL { gl2.glVertexAttrib4fv(index, values); } - public void vertexAttribPointer(int index, int size, int type, - boolean normalized, int stride, int offset) { + public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset) { gl2.glVertexAttribPointer(index, size, type, normalized, stride, offset); } - public void vertexAttribPointer(int index, int size, int type, - boolean normalized, int stride, Buffer data) { + public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { gl2.glVertexAttribPointer(index, size, type, normalized, stride, data); } @@ -3182,45 +3165,28 @@ public class PGL { gl.glActiveTexture(texture); } - public void texImage2D(int target, int level, int internalFormat, - int width, int height, int border, int format, - int type, Buffer data) { - gl.glTexImage2D(target, level, internalFormat, - width, height, border, format, type, data); + public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) { + gl.glTexImage2D(target, level, internalFormat, width, height, border, format, type, data); } - public void copyTexImage2D(int target, int level, int internalFormat, - int x, int y, int width, int height, int border) { - gl.glCopyTexImage2D(target, level, internalFormat, - x, y, width, height, border); + public void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) { + gl.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border); } - public void texSubImage2D(int target, int level, int xOffset, int yOffset, - int width, int height, int format, - int type, Buffer data) { - gl.glTexSubImage2D(target, level, xOffset, yOffset, - width, height, format, type, data); + public void texSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data) { + gl.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, data); } - public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, - int x, int y, int width, int height) { - gl.glCopyTexSubImage2D(target, level, x, y, xOffset, xOffset, - width, height); + public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) { + gl.glCopyTexSubImage2D(target, level, x, y, xOffset, xOffset, width, height); } - public void compressedTexImage2D(int target, int level, int internalFormat, - int width, int height, int border, - int imageSize, Buffer data) { - gl.glCompressedTexImage2D(target, level, internalFormat, - width, height, border, imageSize, data); + public void compressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int imageSize, Buffer data) { + gl.glCompressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data); } - public void compressedTexSubImage2D(int target, int level, - int xOffset, int yOffset, - int width, int height, int format, - int imageSize, Buffer data) { - gl.glCompressedTexSubImage2D(target, level, xOffset, yOffset, - width, height, format, imageSize, data); + public void compressedTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int imageSize, Buffer data) { + gl.glCompressedTexSubImage2D(target, level, xOffset, yOffset, width, height, format, imageSize, data); } public void texParameteri(int target, int pname, int param) { @@ -3280,24 +3246,23 @@ public class PGL { return gl2.glCreateShader(type); } - public void shaderSource(int id, String source) { - gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0); + public void shaderSource(int shader, String source) { + gl2.glShaderSource(shader, 1, new String[] { source }, (int[]) null, 0); } - public void compileShader(int id) { - gl2.glCompileShader(id); + public void compileShader(int shader) { + gl2.glCompileShader(shader); } public void releaseShaderCompiler() { gl2.glReleaseShaderCompiler(); } - public void deleteShader(int id) { - gl2.glDeleteShader(id); + public void deleteShader(int shader) { + gl2.glDeleteShader(shader); } - public void shaderBinary(int count, IntBuffer shaders, int binaryFormat, - Buffer binary, int length) { + public void shaderBinary(int count, IntBuffer shaders, int binaryFormat, Buffer binary, int length) { gl2.glShaderBinary(count, shaders, binaryFormat, binary, length); } @@ -3325,28 +3290,34 @@ public class PGL { gl2.glDeleteProgram(program); } - public void getActiveAttrib(int program, int index, int bufSize, - IntBuffer length, IntBuffer size, IntBuffer type, - ByteBuffer name) { - gl2.glGetActiveAttrib(program, index, bufSize, length, size, type, name); + public void getActiveAttrib(int program, int index, int[] size, int[] type, String[] name) { + int[] tmp = {0, 0, 0}; + byte[] namebuf = new byte[1024]; + gl2.glGetActiveAttrib(program, index, 1024, tmp, 0, tmp, 1, tmp, 2, namebuf, 0); + if (size != null && size.length != 0) size[0] = tmp[1]; + if (type != null && type.length != 0) type[0] = tmp[2]; + if (name != null && name.length != 0) name[0] = new String(namebuf, 0, tmp[0]); } - public int getAttribLocation(int prog, String name) { - return gl2.glGetAttribLocation(prog, name); + public int getAttribLocation(int program, String name) { + return gl2.glGetAttribLocation(program, name); } public void bindAttribLocation(int program, int index, String name) { gl2.glBindAttribLocation(program, index, name); } - public int getUniformLocation(int prog, String name) { - return gl2.glGetUniformLocation(prog, name); + public int getUniformLocation(int program, String name) { + return gl2.glGetUniformLocation(program, name); } - public void getActiveUniform(int program, int index, int bufSize, - IntBuffer length, IntBuffer size, IntBuffer type, - ByteBuffer name) { - gl2.glGetActiveUniform(program, index, bufSize, length, size, type, name); + public void getActiveUniform(int program, int index, int[] size,int[] type, String[] name) { + int[] tmp= {0, 0, 0}; + byte[] namebuf = new byte[1024]; + gl2.glGetActiveUniform(program, index, 1024, tmp, 0, tmp, 1, tmp, 2, namebuf, 0); + if (size != null && size.length != 0) size[0] = tmp[1]; + if (type != null && type.length != 0) type[0] = tmp[2]; + if (name != null && name.length != 0) name[0] = new String(namebuf, 0, tmp[0]); } public void uniform1i(int location, int value) { @@ -3361,8 +3332,7 @@ public class PGL { gl2.glUniform3i(location, value0, value1, value2); } - public void uniform4i(int location, int value0, int value1, int value2, - int value3) { + public void uniform4i(int location, int value0, int value1, int value2, int value3) { gl2.glUniform4i(location, value0, value1, value2, value3); } @@ -3374,13 +3344,11 @@ public class PGL { gl2.glUniform2f(location, value0, value1); } - public void uniform3f(int location, float value0, float value1, - float value2) { + public void uniform3f(int location, float value0, float value1, float value2) { gl2.glUniform3f(location, value0, value1, value2); } - public void uniform4f(int location, float value0, float value1, float value2, - float value3) { + public void uniform4f(int location, float value0, float value1, float value2, float value3) { gl2.glUniform4f(location, value0, value1, value2, value3); } @@ -3416,23 +3384,20 @@ public class PGL { gl2.glUniform4fv(location, count, v); } - public void uniformMatrix2fv(int location, int count, boolean transpose, - FloatBuffer mat) { + public void uniformMatrix2fv(int location, int count, boolean transpose, FloatBuffer mat) { gl2.glUniformMatrix2fv(location, count, transpose, mat); } - public void uniformMatrix3fv(int location, int count, boolean transpose, - FloatBuffer mat) { + public void uniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer mat) { gl2.glUniformMatrix3fv(location, count, transpose, mat); } - public void uniformMatrix4fv(int location, int count, boolean transpose, - FloatBuffer mat) { + public void uniformMatrix4fv(int location, int count, boolean transpose, FloatBuffer mat) { gl2.glUniformMatrix4fv(location, count, transpose, mat); } - public void validateProgram(int prog) { - gl2.glValidateProgram(prog); + public void validateProgram(int program) { + gl2.glValidateProgram(program); } public boolean isShader(int shader) { @@ -3443,8 +3408,7 @@ public class PGL { gl2.glGetShaderiv(shader, pname, params); } - public void getAttachedShaders(int program, int maxCount, IntBuffer count, - IntBuffer shaders) { + public void getAttachedShaders(int program, int maxCount, IntBuffer count, IntBuffer shaders) { gl2.glGetAttachedShaders(program, maxCount, count, shaders); } @@ -3458,13 +3422,14 @@ public class PGL { return new String(log); } - public void getShaderSource(int shader, int bufSize, IntBuffer length, - ByteBuffer source) { - gl2.glGetShaderSource(shader, bufSize, length, source); + public String getShaderSource(int shader) { + int[] len = {0}; + byte[] buf = new byte[1024]; + gl2.glGetShaderSource(shader, 1024, len, 0, buf, 0); + return new String(buf, 0, len[0]); } - public void getShaderPrecisionFormat(int shaderType, int precisionType, - IntBuffer range, IntBuffer precision) { + public void getShaderPrecisionFormat(int shaderType, int precisionType, IntBuffer range, IntBuffer precision) { gl2.glGetShaderPrecisionFormat(shaderType, precisionType, range, precision); } @@ -3477,7 +3442,7 @@ public class PGL { } public void getVertexAttribPointerv() { - throw new RuntimeException("Function glGetVertexAttribPointerv() is not available"); + throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glGetVertexAttribPointerv()")); } public void getUniformfv(int program, int location, FloatBuffer params) { @@ -3492,18 +3457,18 @@ public class PGL { return gl2.glIsProgram(program); } - public void getProgramiv(int prog, int pname, IntBuffer params) { - gl2.glGetProgramiv(prog, pname, params); + public void getProgramiv(int program, int pname, IntBuffer params) { + gl2.glGetProgramiv(program, pname, params); } - public String getProgramInfoLog(int prog) { + public String getProgramInfoLog(int program) { int[] val = { 0 }; - gl2.glGetShaderiv(prog, GL2.GL_INFO_LOG_LENGTH, val, 0); + gl2.glGetShaderiv(program, GL2.GL_INFO_LOG_LENGTH, val, 0); int length = val[0]; if (0 < length) { byte[] log = new byte[length]; - gl2.glGetProgramInfoLog(prog, length, val, 0, log, 0); + gl2.glGetProgramInfoLog(program, length, val, 0, log, 0); return new String(log); } else { return "Unknow error"; @@ -3554,8 +3519,7 @@ public class PGL { gl.glBlendFunc(src, dst); } - public void blendFuncSeparate(int srcRGB, int dstRGB, - int srcAlpha, int dstAlpha) { + public void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) { gl.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); } @@ -3633,19 +3597,15 @@ public class PGL { gl.glGenRenderbuffers(n, renderbuffers); } - public void renderbufferStorage(int target, int internalFormat, - int width, int height) { + public void renderbufferStorage(int target, int internalFormat, int width, int height) { gl.glRenderbufferStorage(target, internalFormat, width, height); } - public void framebufferRenderbuffer(int target, int attachment, - int rendbuferfTarget, int renderbuffer) { - gl.glFramebufferRenderbuffer(target, attachment, rendbuferfTarget, - renderbuffer); + public void framebufferRenderbuffer(int target, int attachment, int rendbuferfTarget, int renderbuffer) { + gl.glFramebufferRenderbuffer(target, attachment, rendbuferfTarget, renderbuffer); } - public void framebufferTexture2D(int target, int attachment, int texTarget, - int texture, int level) { + public void framebufferTexture2D(int target, int attachment, int texTarget, int texture, int level) { gl.glFramebufferTexture2D(target, attachment, texTarget, texture, level); } @@ -3657,35 +3617,27 @@ public class PGL { return gl2.glIsFramebuffer(framebuffer); } - public void getFramebufferAttachmentParameteriv(int target, int attachment, - int pname, IntBuffer params) { - gl2.glGetFramebufferAttachmentParameteriv(target, attachment, pname, - params); + public void getFramebufferAttachmentParameteriv(int target, int attachment, int pname, IntBuffer params) { + gl2.glGetFramebufferAttachmentParameteriv(target, attachment, pname, params); } public boolean isRenderbuffer(int renderbuffer) { return gl2.glIsRenderbuffer(renderbuffer); } - public void getRenderbufferParameteriv(int target, int pname, - IntBuffer params) { + public void getRenderbufferParameteriv(int target, int pname, IntBuffer params) { gl2.glGetRenderbufferParameteriv(target, pname, params); } - public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, - int dstX0, int dstY0, int dstX1, int dstY1, - int mask, int filter) { + 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); + gl2x.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); } } - public void renderbufferStorageMultisample(int target, int samples, - int format, int width, int height){ + public void renderbufferStorageMultisample(int target, int samples, int format, int width, int height) { if (gl2x != null) { - gl2x.glRenderbufferStorageMultisample(target, samples, format, - width, height); + gl2x.glRenderbufferStorageMultisample(target, samples, format, width, height); } } diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index 338a18d54..1792399d9 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -77,15 +77,24 @@ import processing.opengl.Texture; */ @SuppressWarnings("static-access") public class PGL extends processing.opengl.PGL { + /////////////////////////////////////////////////////////// + // Public members to access the underlying GL objects and context + + /** GLU interface **/ + public static GLU glu; + + /** The canvas where OpenGL rendering takes place */ + public static Canvas canvas; + /////////////////////////////////////////////////////////// // Parameters - public static boolean FORCE_SCREEN_FBO = false; - public static final boolean USE_DIRECT_BUFFERS = true; - public static final int MIN_DIRECT_BUFFER_SIZE = 16; - public static final boolean SAVE_SURFACE_TO_PIXELS = true; + protected static boolean FORCE_SCREEN_FBO = false; + protected static final boolean USE_DIRECT_BUFFERS = true; + protected static final int MIN_DIRECT_BUFFER_SIZE = 16; + protected static final boolean SAVE_SURFACE_TO_PIXELS = true; /** Enables/disables mipmap use. **/ protected static final boolean MIPMAPS_ENABLED = true; @@ -173,183 +182,6 @@ public class PGL extends processing.opengl.PGL { "precision mediump int;\n" + "#endif\n"; - /////////////////////////////////////////////////////////// - - // OpenGL constants - - public static final int FALSE = GL11.GL_FALSE; - public static final int TRUE = GL11.GL_TRUE; - - public static final int LESS = GL11.GL_LESS; - public static final int LEQUAL = GL11.GL_LEQUAL; - - public static final int CCW = GL11.GL_CCW; - public static final int CW = GL11.GL_CW; - - public static final int CULL_FACE = GL11.GL_CULL_FACE; - public static final int FRONT = GL11.GL_FRONT; - public static final int BACK = GL11.GL_BACK; - public static final int FRONT_AND_BACK = GL11.GL_FRONT_AND_BACK; - - public static final int VIEWPORT = GL11.GL_VIEWPORT; - - public static final int SCISSOR_TEST = GL11.GL_SCISSOR_TEST; - public static final int DEPTH_TEST = GL11.GL_DEPTH_TEST; - public static final int DEPTH_WRITEMASK = GL11.GL_DEPTH_WRITEMASK; - - public static final int COLOR_BUFFER_BIT = GL11.GL_COLOR_BUFFER_BIT; - public static final int DEPTH_BUFFER_BIT = GL11.GL_DEPTH_BUFFER_BIT; - public static final int STENCIL_BUFFER_BIT = GL11.GL_STENCIL_BUFFER_BIT; - - public static final int FUNC_ADD = GL14.GL_FUNC_ADD; - public static final int FUNC_MIN = GL14.GL_MIN; - public static final int FUNC_MAX = GL14.GL_MAX; - public static final int FUNC_REVERSE_SUBTRACT = GL14.GL_FUNC_REVERSE_SUBTRACT; - - public static final int TEXTURE_2D = GL11.GL_TEXTURE_2D; - public static final int TEXTURE_RECTANGLE = GL31.GL_TEXTURE_RECTANGLE; - - public static final int TEXTURE_BINDING_2D = GL11.GL_TEXTURE_BINDING_2D; - public static final int TEXTURE_BINDING_RECTANGLE = - GL31.GL_TEXTURE_BINDING_RECTANGLE; - - public static final int RGB = GL11.GL_RGB; - public static final int RGBA = GL11.GL_RGBA; - public static final int ALPHA = GL11.GL_ALPHA; - public static final int UNSIGNED_INT = GL11.GL_UNSIGNED_INT; - public static final int UNSIGNED_BYTE = GL11.GL_UNSIGNED_BYTE; - public static final int UNSIGNED_SHORT = GL11.GL_UNSIGNED_SHORT; - public static final int FLOAT = GL11.GL_FLOAT; - - public static final int NEAREST = GL11.GL_NEAREST; - public static final int LINEAR = GL11.GL_LINEAR; - public static final int LINEAR_MIPMAP_NEAREST = GL11.GL_LINEAR_MIPMAP_NEAREST; - public static final int LINEAR_MIPMAP_LINEAR = GL11.GL_LINEAR_MIPMAP_LINEAR; - - public static final int TEXTURE_MAX_ANISOTROPY = - EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT; - public static final int MAX_TEXTURE_MAX_ANISOTROPY = - EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; - - public static final int CLAMP_TO_EDGE = GL12.GL_CLAMP_TO_EDGE; - public static final int REPEAT = GL11.GL_REPEAT; - - public static final int RGBA8 = GL11.GL_RGBA8; - public static final int DEPTH24_STENCIL8 = GL30.GL_DEPTH24_STENCIL8; - - public static final int DEPTH_COMPONENT = GL11.GL_DEPTH_COMPONENT; - public static final int DEPTH_COMPONENT16 = GL14.GL_DEPTH_COMPONENT16; - public static final int DEPTH_COMPONENT24 = GL14.GL_DEPTH_COMPONENT24; - public static final int DEPTH_COMPONENT32 = GL14.GL_DEPTH_COMPONENT32; - - public static final int STENCIL_INDEX = GL11.GL_STENCIL_INDEX; - public static final int STENCIL_INDEX1 = GL30.GL_STENCIL_INDEX1; - public static final int STENCIL_INDEX4 = GL30.GL_STENCIL_INDEX4; - public static final int STENCIL_INDEX8 = GL30.GL_STENCIL_INDEX8; - - public static final int ARRAY_BUFFER = GL15.GL_ARRAY_BUFFER; - public static final int ELEMENT_ARRAY_BUFFER = GL15.GL_ELEMENT_ARRAY_BUFFER; - - public static final int SAMPLES = GL13.GL_SAMPLES; - - public static final int FRAMEBUFFER_COMPLETE = - GL30.GL_FRAMEBUFFER_COMPLETE; - public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = - GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = - GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; - public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = - EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; - public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = - EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; - public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = - GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; - public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = - GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; - public static final int FRAMEBUFFER_UNSUPPORTED = - GL30.GL_FRAMEBUFFER_UNSUPPORTED; - - public static final int STATIC_DRAW = GL15.GL_STATIC_DRAW; - public static final int DYNAMIC_DRAW = GL15.GL_DYNAMIC_DRAW; - public static final int STREAM_DRAW = GL15.GL_STREAM_DRAW; - - public static final int READ_ONLY = GL15.GL_READ_ONLY; - public static final int WRITE_ONLY = GL15.GL_WRITE_ONLY; - public static final int READ_WRITE = GL15.GL_READ_WRITE; - - public static final int TRIANGLE_FAN = GL11.GL_TRIANGLE_FAN; - public static final int TRIANGLE_STRIP = GL11.GL_TRIANGLE_STRIP; - public static final int TRIANGLES = GL11.GL_TRIANGLES; - - public static final int VENDOR = GL11.GL_VENDOR; - public static final int RENDERER = GL11.GL_RENDERER; - public static final int VERSION = GL11.GL_VERSION; - public static final int EXTENSIONS = GL11.GL_EXTENSIONS; - public static final int SHADING_LANGUAGE_VERSION = - GL20.GL_SHADING_LANGUAGE_VERSION; - - public static final int MAX_TEXTURE_SIZE = GL11.GL_MAX_TEXTURE_SIZE; - public static final int MAX_SAMPLES = GL30.GL_MAX_SAMPLES; - public static final int ALIASED_LINE_WIDTH_RANGE = - GL12.GL_ALIASED_LINE_WIDTH_RANGE; - public static final int ALIASED_POINT_SIZE_RANGE = - GL12.GL_ALIASED_POINT_SIZE_RANGE; - public static final int DEPTH_BITS = GL11.GL_DEPTH_BITS; - public static final int STENCIL_BITS = GL11.GL_STENCIL_BITS; - - public static final int TESS_WINDING_NONZERO = GLU.GLU_TESS_WINDING_NONZERO; - public static final int TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; - - public static final int TEXTURE0 = GL13.GL_TEXTURE0; - public static final int TEXTURE1 = GL13.GL_TEXTURE1; - public static final int TEXTURE2 = GL13.GL_TEXTURE2; - public static final int TEXTURE3 = GL13.GL_TEXTURE3; - public static final int TEXTURE_MIN_FILTER = GL11.GL_TEXTURE_MIN_FILTER; - public static final int TEXTURE_MAG_FILTER = GL11.GL_TEXTURE_MAG_FILTER; - public static final int TEXTURE_WRAP_S = GL11.GL_TEXTURE_WRAP_S; - public static final int TEXTURE_WRAP_T = GL11.GL_TEXTURE_WRAP_T; - - public static final int BLEND = GL11.GL_BLEND; - public static final int ONE = GL11.GL_ONE; - public static final int ZERO = GL11.GL_ZERO; - public static final int SRC_ALPHA = GL11.GL_SRC_ALPHA; - public static final int DST_ALPHA = GL11.GL_DST_ALPHA; - public static final int ONE_MINUS_SRC_ALPHA = GL11.GL_ONE_MINUS_SRC_ALPHA; - public static final int ONE_MINUS_DST_COLOR = GL11.GL_ONE_MINUS_DST_COLOR; - public static final int ONE_MINUS_SRC_COLOR = GL11.GL_ONE_MINUS_SRC_COLOR; - public static final int DST_COLOR = GL11.GL_DST_COLOR; - public static final int SRC_COLOR = GL11.GL_SRC_COLOR; - - public static final int FRAMEBUFFER = GL30.GL_FRAMEBUFFER; - public static final int COLOR_ATTACHMENT0 = GL30.GL_COLOR_ATTACHMENT0; - public static final int COLOR_ATTACHMENT1 = GL30.GL_COLOR_ATTACHMENT1; - public static final int COLOR_ATTACHMENT2 = GL30.GL_COLOR_ATTACHMENT2; - public static final int COLOR_ATTACHMENT3 = GL30.GL_COLOR_ATTACHMENT3; - public static final int RENDERBUFFER = GL30.GL_RENDERBUFFER; - public static final int DEPTH_ATTACHMENT = GL30.GL_DEPTH_ATTACHMENT; - public static final int STENCIL_ATTACHMENT = GL30.GL_STENCIL_ATTACHMENT; - public static final int READ_FRAMEBUFFER = GL30.GL_READ_FRAMEBUFFER; - public static final int DRAW_FRAMEBUFFER = GL30.GL_DRAW_FRAMEBUFFER; - - public static final int VERTEX_SHADER = GL20.GL_VERTEX_SHADER; - public static final int FRAGMENT_SHADER = GL20.GL_FRAGMENT_SHADER; - public static final int INFO_LOG_LENGTH = GL20.GL_INFO_LOG_LENGTH; - public static final int SHADER_SOURCE_LENGTH = GL20.GL_SHADER_SOURCE_LENGTH; - public static final int COMPILE_STATUS = GL20.GL_COMPILE_STATUS; - public static final int LINK_STATUS = GL20.GL_LINK_STATUS; - public static final int VALIDATE_STATUS = GL20.GL_VALIDATE_STATUS; - - public static final int MULTISAMPLE = GL13.GL_MULTISAMPLE; - public static final int POINT_SMOOTH = GL11.GL_POINT_SMOOTH; - public static final int LINE_SMOOTH = GL11.GL_LINE_SMOOTH; - public static final int POLYGON_SMOOTH = GL11.GL_POLYGON_SMOOTH; - - /** GLU interface **/ - public static GLU glu; - - /** The canvas where OpenGL rendering takes place */ - public static Canvas canvas; - /** OpenGL thread */ protected static Thread glThread; @@ -464,10 +296,25 @@ public class PGL extends processing.opengl.PGL { protected ByteBuffer stencilBuffer; + /////////////////////////////////////////////////////////// + + // Error messages + + protected static final String MISSING_FBO_ERROR = + "Framebuffer objects are not supported by this hardware (or driver)"; + + protected static final String MISSING_GLSL_ERROR = + "GLSL shaders are not supported by this hardware (or driver)"; + + protected static final String MISSING_GLFUNC_ERROR = + "GL function %1$s is not available on this hardware (or driver)"; + + /////////////////////////////////////////////////////////// // Initialization, finalization + public PGL(PGraphicsOpenGL pg) { this.pg = pg; if (glu == null) { @@ -1023,681 +870,6 @@ public class PGL extends processing.opengl.PGL { } - ////////////////////////////////////////////////////////////////////////////// - - // Caps query - - - public String getString(int name) { - return GL11.glGetString(name); - } - - - public void getIntegerv(int name, IntBuffer values) { - if (-1 < name) { - GL11.glGetInteger(name, values); - } else { - fillIntBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - public void getFloatv(int name, FloatBuffer values) { - if (-1 < name) { - GL11.glGetFloat(name, values); - } else { - fillFloatBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - public void getBooleanv(int name, IntBuffer values) { - if (-1 < name) { - if (byteBuffer.capacity() < values.capacity()) { - byteBuffer = allocateDirectByteBuffer(values.capacity()); - } - GL11.glGetBoolean(name, byteBuffer); - for (int i = 0; i < values.capacity(); i++) { - values.put(i, byteBuffer.get(i)); - } - } else { - fillIntBuffer(values, 0, values.capacity() - 1, 0); - } - } - - - /////////////////////////////////////////////////////////// - - // Enable/disable caps - - - public void enable(int cap) { - if (-1 < cap) { - GL11.glEnable(cap); - } - } - - - public void disable(int cap) { - if (-1 < cap) { - GL11.glDisable(cap); - } - } - - - /////////////////////////////////////////////////////////// - - // Render control - - - public void flush() { - GL11.glFlush(); - } - - - public void finish() { - GL11.glFinish(); - } - - - /////////////////////////////////////////////////////////// - - // Error handling - - - public int getError() { - return GL11.glGetError(); - } - - - public String errorString(int err) { - return glu.gluErrorString(err); - } - - - /////////////////////////////////////////////////////////// - - // Rendering options - - - public void frontFace(int mode) { - GL11.glFrontFace(mode); - } - - - public void cullFace(int mode) { - GL11.glCullFace(mode); - } - - - public void depthMask(boolean flag) { - GL11.glDepthMask(flag); - } - - - public void depthFunc(int func) { - GL11.glDepthFunc(func); - } - - - /////////////////////////////////////////////////////////// - - // Textures - - - public void genTextures(int n, IntBuffer ids) { - GL11.glGenTextures(ids); - } - - - public void deleteTextures(int n, IntBuffer ids) { - GL11.glDeleteTextures(ids); - } - - - public void activeTexture(int unit) { - GL13.glActiveTexture(unit); - } - - - public void bindTexture(int target, int id) { - GL11.glBindTexture(target, id); - if (target == TEXTURE_2D) { - boundTextures[0] = id; - } else if (target == TEXTURE_RECTANGLE) { - boundTextures[1] = id; - } - } - - - public void texImage2D(int target, int level, int internalFormat, - int width, int height, int border, int format, - int type, Buffer data) { - GL11.glTexImage2D(target, level, internalFormat, - width, height, border, format, type, (IntBuffer)data); - } - - - public void texSubImage2D(int target, int level, int xOffset, int yOffset, - int width, int height, int format, - int type, Buffer data) { - GL11.glTexSubImage2D(target, level, xOffset, yOffset, - width, height, format, type, (IntBuffer)data); - } - - - public void texParameteri(int target, int param, int value) { - GL11.glTexParameteri(target, param, value); - } - - - public void texParameterf(int target, int param, float value) { - GL11.glTexParameterf(target, param, value); - } - - - public void getTexParameteriv(int target, int param, IntBuffer values) { - GL11.glGetTexParameter(target, param, values); - } - - - public void generateMipmap(int target) { - GL30.glGenerateMipmap(target); - } - - - /////////////////////////////////////////////////////////// - - // Vertex Buffers - - - public void genBuffers(int n, IntBuffer ids) { - GL15.glGenBuffers(ids); - } - - - public void deleteBuffers(int n, IntBuffer ids) { - GL15.glDeleteBuffers(ids); - } - - - public void bindBuffer(int target, int id) { - GL15.glBindBuffer(target, id); - } - - - public void bufferData(int target, int size, Buffer data, int usage) { - if (data == null) { - FloatBuffer empty = BufferUtils.createFloatBuffer(size); - GL15.glBufferData(target, empty, usage); - } else { - if (data instanceof ByteBuffer) { - GL15.glBufferData(target, (ByteBuffer)data, usage); - } else if (data instanceof ShortBuffer) { - GL15.glBufferData(target, (ShortBuffer)data, usage); - } else if (data instanceof IntBuffer) { - GL15.glBufferData(target, (IntBuffer)data, usage); - } else if (data instanceof FloatBuffer) { - GL15.glBufferData(target, (FloatBuffer)data, usage); - } - } - } - - - public void bufferSubData(int target, int offset, int size, Buffer data) { - if (data instanceof ByteBuffer) { - GL15.glBufferSubData(target, offset, (ByteBuffer)data); - } else if (data instanceof ShortBuffer) { - GL15.glBufferSubData(target, offset, (ShortBuffer)data); - } else if (data instanceof IntBuffer) { - GL15.glBufferSubData(target, offset, (IntBuffer)data); - } else if (data instanceof FloatBuffer) { - GL15.glBufferSubData(target, offset, (FloatBuffer)data); - } - } - - - public void drawArrays(int mode, int first, int count) { - GL11.glDrawArrays(mode, first, count); - } - - - public void drawElements(int mode, int count, int type, int offset) { - GL11.glDrawElements(mode, count, type, offset); - } - - - public void enableVertexAttribArray(int loc) { - GL20.glEnableVertexAttribArray(loc); - } - - - public void disableVertexAttribArray(int loc) { - GL20.glDisableVertexAttribArray(loc); - } - - - public void vertexAttribPointer(int loc, int size, int type, - boolean normalized, int stride, int offset) { - GL20.glVertexAttribPointer(loc, size, type, normalized, stride, offset); - } - - - public void vertexAttribPointer(int loc, int size, int type, - boolean normalized, int stride, Buffer data) { - if (type == UNSIGNED_INT) { - GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (IntBuffer)data); - } else if (type == UNSIGNED_BYTE) { - GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (ByteBuffer)data); - } else if (type == UNSIGNED_SHORT) { - GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (ShortBuffer)data); - } else if (type == FLOAT) { - GL20.glVertexAttribPointer(loc, size, normalized, stride, (FloatBuffer)data); - } - } - - - public ByteBuffer mapBuffer(int target, int access) { - return GL15.glMapBuffer(target, access, null); - } - - - public ByteBuffer mapBufferRange(int target, int offset, int length, - int access) { - return GL30.glMapBufferRange(target, offset, length, access, null); - } - - - public void unmapBuffer(int target) { - GL15.glUnmapBuffer(target); - } - - - /////////////////////////////////////////////////////////// - - // Framebuffers, renderbuffers - - - public void genFramebuffers(int n, IntBuffer ids) { - GL30.glGenFramebuffers(ids); - } - - - public void deleteFramebuffers(int n, IntBuffer ids) { - GL30.glDeleteFramebuffers(ids); - } - - - public void genRenderbuffers(int n, IntBuffer ids) { - GL30.glGenRenderbuffers(ids); - } - - - public void deleteRenderbuffers(int n, IntBuffer ids) { - GL30.glDeleteRenderbuffers(ids); - } - - - public void bindFramebuffer(int target, int id) { - GL30.glBindFramebuffer(target, id); - } - - - public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, - int dstX0, int dstY0, int dstX1, int dstY1, - int mask, int filter) { - GL30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, - dstX0, dstY0, dstX1, dstY1, mask, filter); - } - - - public void framebufferTexture2D(int target, int attachment, int texTarget, - int texId, int level) { - GL30.glFramebufferTexture2D(target, attachment, texTarget, texId, level); - } - - - public void bindRenderbuffer(int target, int id) { - GL30.glBindRenderbuffer(target, id); - } - - - public void renderbufferStorageMultisample(int target, int samples, - int format, int width, int height){ - GL30.glRenderbufferStorageMultisample(target, samples, format, - width, height); - } - - - public void renderbufferStorage(int target, int format, - int width, int height) { - GL30.glRenderbufferStorage(target, format, width, height); - } - - - public void framebufferRenderbuffer(int target, int attachment, - int rendbufTarget, int rendbufId) { - GL30.glFramebufferRenderbuffer(target, attachment, rendbufTarget, rendbufId); - } - - - public int checkFramebufferStatus(int target) { - return GL30.glCheckFramebufferStatus(target); - } - - - /////////////////////////////////////////////////////////// - - // Shaders - - - public int createProgram() { - return GL20.glCreateProgram(); - } - - - public void deleteProgram(int id) { - GL20.glDeleteProgram(id); - } - - - public int createShader(int type) { - return GL20.glCreateShader(type); - } - - - public void deleteShader(int id) { - GL20.glDeleteShader(id); - } - - - public void linkProgram(int prog) { - GL20.glLinkProgram(prog); - } - - - public void validateProgram(int prog) { - GL20.glValidateProgram(prog); - } - - - public void useProgram(int prog) { - GL20.glUseProgram(prog); - } - - - public int getAttribLocation(int prog, String name) { - return GL20.glGetAttribLocation(prog, name); - } - - - public int getUniformLocation(int prog, String name) { - return GL20.glGetUniformLocation(prog, name); - } - - - public void uniform1i(int loc, int value) { - GL20.glUniform1i(loc, value); - } - - - public void uniform2i(int loc, int value0, int value1) { - GL20.glUniform2i(loc, value0, value1); - } - - - public void uniform3i(int loc, int value0, int value1, int value2) { - GL20.glUniform3i(loc, value0, value1, value2); - } - - - public void uniform4i(int loc, int value0, int value1, int value2, - int value3) { - GL20.glUniform4i(loc, value0, value1, value2, value3); - } - - - public void uniform1f(int loc, float value) { - GL20.glUniform1f(loc, value); - } - - - public void uniform2f(int loc, float value0, float value1) { - GL20.glUniform2f(loc, value0, value1); - } - - - public void uniform3f(int loc, float value0, float value1, float value2) { - GL20.glUniform3f(loc, value0, value1, value2); - } - - - public void uniform4f(int loc, float value0, float value1, float value2, - float value3) { - GL20.glUniform4f(loc, value0, value1, value2, value3); - } - - - public void uniform1iv(int loc, int count, IntBuffer v) { - v.limit(count); - GL20.glUniform1(loc, v); - v.clear(); - } - - - public void uniform2iv(int loc, int count, IntBuffer v) { - v.limit(2 * count); - GL20.glUniform2(loc, v); - v.clear(); - } - - - public void uniform3iv(int loc, int count, IntBuffer v) { - v.limit(3 * count); - GL20.glUniform3(loc, v); - v.clear(); - } - - - public void uniform4iv(int loc, int count, IntBuffer v) { - v.limit(4 * count); - GL20.glUniform4(loc, v); - v.clear(); - } - - - public void uniform1fv(int loc, int count, FloatBuffer v) { - v.limit(count); - GL20.glUniform1(loc, v); - v.clear(); - } - - - public void uniform2fv(int loc, int count, FloatBuffer v) { - v.limit(2 * count); - GL20.glUniform2(loc, v); - v.clear(); - } - - - public void uniform3fv(int loc, int count, FloatBuffer v) { - v.limit(3 * count); - GL20.glUniform3(loc, v); - v.clear(); - } - - - public void uniform4fv(int loc, int count, FloatBuffer v) { - v.limit(4 * count); - GL20.glUniform4(loc, v); - v.clear(); - } - - - public void uniformMatrix2fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - mat.limit(4); - GL20.glUniformMatrix2(loc, transpose, mat); - mat.clear(); - } - - - public void uniformMatrix3fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - mat.limit(9); - GL20.glUniformMatrix3(loc, transpose, mat); - mat.clear(); - } - - - public void uniformMatrix4fv(int loc, int count, boolean transpose, - FloatBuffer mat) { - mat.limit(16); - GL20.glUniformMatrix4(loc, transpose, mat); - mat.clear(); - } - - - public void vertexAttrib1f(int loc, float value) { - GL20.glVertexAttrib1f(loc, value); - } - - - public void vertexAttrib2f(int loc, float value0, float value1) { - GL20.glVertexAttrib2f(loc, value0, value1); - } - - - public void vertexAttrib3f(int loc, float value0, float value1, float value2){ - GL20.glVertexAttrib3f(loc, value0, value1, value2); - } - - - public void vertexAttrib4f(int loc, float value0, float value1, float value2, - float value3) { - GL20.glVertexAttrib4f(loc, value0, value1, value2, value3); - } - - - public void shaderSource(int id, String source) { - GL20.glShaderSource(id, source); - } - - - public void compileShader(int id) { - GL20.glCompileShader(id); - } - - - public void attachShader(int prog, int shader) { - GL20.glAttachShader(prog, shader); - } - - - public void getShaderiv(int shader, int pname, IntBuffer params) { - GL20.glGetShader(shader, pname, params); - } - - - public String getShaderInfoLog(int shader) { - int len = GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH); - return GL20.glGetShaderInfoLog(shader, len); - } - - - public void getProgramiv(int prog, int pname, IntBuffer params) { - GL20.glGetProgram(prog, pname, params); - } - - - public String getProgramInfoLog(int prog) { - int len = GL20.glGetProgrami(prog, GL20.GL_INFO_LOG_LENGTH); - return GL20.glGetProgramInfoLog(prog, len); - } - - - /////////////////////////////////////////////////////////// - - // Viewport - - - public void viewport(int x, int y, int width, int height) { - GL11.glViewport(x, y, width, height); - } - - - /////////////////////////////////////////////////////////// - - // Clipping (scissor test) - - - public void scissor(int x, int y, int w, int h) { - GL11.glScissor(x, y, w, h); - } - - - /////////////////////////////////////////////////////////// - - // Blending - - - public void blendEquation(int eq) { - GL14.glBlendEquation(eq); - } - - - public void blendFunc(int srcFactor, int dstFactor) { - GL11.glBlendFunc(srcFactor, dstFactor); - } - - - /////////////////////////////////////////////////////////// - - // Pixels - - - public void readBuffer(int buf) { - GL11.glReadBuffer(buf); - } - - - public void readPixels(int x, int y, int width, int height, int format, - int type, Buffer buffer) { - - GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer)buffer); - } - - - public void drawBuffer(int buf) { - GL11.glDrawBuffer(buf); - } - - - public void clearDepth(float d) { - GL11.glClearDepth(d); - } - - - public void clearStencil(int s) { - GL11.glClearStencil(s); - } - - - public void colorMask(boolean wr, boolean wg, boolean wb, boolean wa) { - GL11.glColorMask(wr, wg, wb, wa); - } - - - public void clearColor(float r, float g, float b, float a) { - GL11.glClearColor(r, g, b, a); - } - - - public void clear(int mask) { - GL11.glClear(mask); - } - - /////////////////////////////////////////////////////////// // Context interface @@ -3346,4 +2518,856 @@ public class PGL extends processing.opengl.PGL { return 0; } } + + + + + // OPENGL API: Still need to add all the missing functions to expose the entire + // GLES 2.0 API + + /////////////////////////////////////////////////////////// + + // OpenGL constants + + public static final int FALSE = GL11.GL_FALSE; + public static final int TRUE = GL11.GL_TRUE; + + public static final int LESS = GL11.GL_LESS; + public static final int LEQUAL = GL11.GL_LEQUAL; + + public static final int CCW = GL11.GL_CCW; + public static final int CW = GL11.GL_CW; + + public static final int CULL_FACE = GL11.GL_CULL_FACE; + public static final int FRONT = GL11.GL_FRONT; + public static final int BACK = GL11.GL_BACK; + public static final int FRONT_AND_BACK = GL11.GL_FRONT_AND_BACK; + + public static final int VIEWPORT = GL11.GL_VIEWPORT; + + public static final int SCISSOR_TEST = GL11.GL_SCISSOR_TEST; + public static final int DEPTH_TEST = GL11.GL_DEPTH_TEST; + public static final int DEPTH_WRITEMASK = GL11.GL_DEPTH_WRITEMASK; + + public static final int COLOR_BUFFER_BIT = GL11.GL_COLOR_BUFFER_BIT; + public static final int DEPTH_BUFFER_BIT = GL11.GL_DEPTH_BUFFER_BIT; + public static final int STENCIL_BUFFER_BIT = GL11.GL_STENCIL_BUFFER_BIT; + + public static final int FUNC_ADD = GL14.GL_FUNC_ADD; + public static final int FUNC_MIN = GL14.GL_MIN; + public static final int FUNC_MAX = GL14.GL_MAX; + public static final int FUNC_REVERSE_SUBTRACT = GL14.GL_FUNC_REVERSE_SUBTRACT; + + public static final int TEXTURE_2D = GL11.GL_TEXTURE_2D; + public static final int TEXTURE_RECTANGLE = GL31.GL_TEXTURE_RECTANGLE; + + public static final int TEXTURE_BINDING_2D = GL11.GL_TEXTURE_BINDING_2D; + public static final int TEXTURE_BINDING_RECTANGLE = + GL31.GL_TEXTURE_BINDING_RECTANGLE; + + public static final int RGB = GL11.GL_RGB; + public static final int RGBA = GL11.GL_RGBA; + public static final int ALPHA = GL11.GL_ALPHA; + public static final int UNSIGNED_INT = GL11.GL_UNSIGNED_INT; + public static final int UNSIGNED_BYTE = GL11.GL_UNSIGNED_BYTE; + public static final int UNSIGNED_SHORT = GL11.GL_UNSIGNED_SHORT; + public static final int FLOAT = GL11.GL_FLOAT; + + public static final int NEAREST = GL11.GL_NEAREST; + public static final int LINEAR = GL11.GL_LINEAR; + public static final int LINEAR_MIPMAP_NEAREST = GL11.GL_LINEAR_MIPMAP_NEAREST; + public static final int LINEAR_MIPMAP_LINEAR = GL11.GL_LINEAR_MIPMAP_LINEAR; + + public static final int TEXTURE_MAX_ANISOTROPY = + EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT; + public static final int MAX_TEXTURE_MAX_ANISOTROPY = + EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; + + public static final int CLAMP_TO_EDGE = GL12.GL_CLAMP_TO_EDGE; + public static final int REPEAT = GL11.GL_REPEAT; + + public static final int RGBA8 = GL11.GL_RGBA8; + public static final int DEPTH24_STENCIL8 = GL30.GL_DEPTH24_STENCIL8; + + public static final int DEPTH_COMPONENT = GL11.GL_DEPTH_COMPONENT; + public static final int DEPTH_COMPONENT16 = GL14.GL_DEPTH_COMPONENT16; + public static final int DEPTH_COMPONENT24 = GL14.GL_DEPTH_COMPONENT24; + public static final int DEPTH_COMPONENT32 = GL14.GL_DEPTH_COMPONENT32; + + public static final int STENCIL_INDEX = GL11.GL_STENCIL_INDEX; + public static final int STENCIL_INDEX1 = GL30.GL_STENCIL_INDEX1; + public static final int STENCIL_INDEX4 = GL30.GL_STENCIL_INDEX4; + public static final int STENCIL_INDEX8 = GL30.GL_STENCIL_INDEX8; + + public static final int ARRAY_BUFFER = GL15.GL_ARRAY_BUFFER; + public static final int ELEMENT_ARRAY_BUFFER = GL15.GL_ELEMENT_ARRAY_BUFFER; + + public static final int SAMPLES = GL13.GL_SAMPLES; + + public static final int FRAMEBUFFER_COMPLETE = + GL30.GL_FRAMEBUFFER_COMPLETE; + public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = + GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = + GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = + EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT; + public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = + EXTFramebufferObject.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT; + public static final int FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = + GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER; + public static final int FRAMEBUFFER_INCOMPLETE_READ_BUFFER = + GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER; + public static final int FRAMEBUFFER_UNSUPPORTED = + GL30.GL_FRAMEBUFFER_UNSUPPORTED; + + public static final int STATIC_DRAW = GL15.GL_STATIC_DRAW; + public static final int DYNAMIC_DRAW = GL15.GL_DYNAMIC_DRAW; + public static final int STREAM_DRAW = GL15.GL_STREAM_DRAW; + + public static final int READ_ONLY = GL15.GL_READ_ONLY; + public static final int WRITE_ONLY = GL15.GL_WRITE_ONLY; + public static final int READ_WRITE = GL15.GL_READ_WRITE; + + public static final int TRIANGLE_FAN = GL11.GL_TRIANGLE_FAN; + public static final int TRIANGLE_STRIP = GL11.GL_TRIANGLE_STRIP; + public static final int TRIANGLES = GL11.GL_TRIANGLES; + + public static final int VENDOR = GL11.GL_VENDOR; + public static final int RENDERER = GL11.GL_RENDERER; + public static final int VERSION = GL11.GL_VERSION; + public static final int EXTENSIONS = GL11.GL_EXTENSIONS; + public static final int SHADING_LANGUAGE_VERSION = + GL20.GL_SHADING_LANGUAGE_VERSION; + + public static final int MAX_TEXTURE_SIZE = GL11.GL_MAX_TEXTURE_SIZE; + public static final int MAX_SAMPLES = GL30.GL_MAX_SAMPLES; + public static final int ALIASED_LINE_WIDTH_RANGE = + GL12.GL_ALIASED_LINE_WIDTH_RANGE; + public static final int ALIASED_POINT_SIZE_RANGE = + GL12.GL_ALIASED_POINT_SIZE_RANGE; + public static final int DEPTH_BITS = GL11.GL_DEPTH_BITS; + public static final int STENCIL_BITS = GL11.GL_STENCIL_BITS; + + public static final int TESS_WINDING_NONZERO = GLU.GLU_TESS_WINDING_NONZERO; + public static final int TESS_WINDING_ODD = GLU.GLU_TESS_WINDING_ODD; + + public static final int TEXTURE0 = GL13.GL_TEXTURE0; + public static final int TEXTURE1 = GL13.GL_TEXTURE1; + public static final int TEXTURE2 = GL13.GL_TEXTURE2; + public static final int TEXTURE3 = GL13.GL_TEXTURE3; + public static final int TEXTURE_MIN_FILTER = GL11.GL_TEXTURE_MIN_FILTER; + public static final int TEXTURE_MAG_FILTER = GL11.GL_TEXTURE_MAG_FILTER; + public static final int TEXTURE_WRAP_S = GL11.GL_TEXTURE_WRAP_S; + public static final int TEXTURE_WRAP_T = GL11.GL_TEXTURE_WRAP_T; + + public static final int BLEND = GL11.GL_BLEND; + public static final int ONE = GL11.GL_ONE; + public static final int ZERO = GL11.GL_ZERO; + public static final int SRC_ALPHA = GL11.GL_SRC_ALPHA; + public static final int DST_ALPHA = GL11.GL_DST_ALPHA; + public static final int ONE_MINUS_SRC_ALPHA = GL11.GL_ONE_MINUS_SRC_ALPHA; + public static final int ONE_MINUS_DST_COLOR = GL11.GL_ONE_MINUS_DST_COLOR; + public static final int ONE_MINUS_SRC_COLOR = GL11.GL_ONE_MINUS_SRC_COLOR; + public static final int DST_COLOR = GL11.GL_DST_COLOR; + public static final int SRC_COLOR = GL11.GL_SRC_COLOR; + + public static final int FRAMEBUFFER = GL30.GL_FRAMEBUFFER; + public static final int COLOR_ATTACHMENT0 = GL30.GL_COLOR_ATTACHMENT0; + public static final int COLOR_ATTACHMENT1 = GL30.GL_COLOR_ATTACHMENT1; + public static final int COLOR_ATTACHMENT2 = GL30.GL_COLOR_ATTACHMENT2; + public static final int COLOR_ATTACHMENT3 = GL30.GL_COLOR_ATTACHMENT3; + public static final int RENDERBUFFER = GL30.GL_RENDERBUFFER; + public static final int DEPTH_ATTACHMENT = GL30.GL_DEPTH_ATTACHMENT; + public static final int STENCIL_ATTACHMENT = GL30.GL_STENCIL_ATTACHMENT; + public static final int READ_FRAMEBUFFER = GL30.GL_READ_FRAMEBUFFER; + public static final int DRAW_FRAMEBUFFER = GL30.GL_DRAW_FRAMEBUFFER; + + public static final int VERTEX_SHADER = GL20.GL_VERTEX_SHADER; + public static final int FRAGMENT_SHADER = GL20.GL_FRAGMENT_SHADER; + public static final int INFO_LOG_LENGTH = GL20.GL_INFO_LOG_LENGTH; + public static final int SHADER_SOURCE_LENGTH = GL20.GL_SHADER_SOURCE_LENGTH; + public static final int COMPILE_STATUS = GL20.GL_COMPILE_STATUS; + public static final int LINK_STATUS = GL20.GL_LINK_STATUS; + public static final int VALIDATE_STATUS = GL20.GL_VALIDATE_STATUS; + + public static final int MULTISAMPLE = GL13.GL_MULTISAMPLE; + public static final int POINT_SMOOTH = GL11.GL_POINT_SMOOTH; + public static final int LINE_SMOOTH = GL11.GL_LINE_SMOOTH; + public static final int POLYGON_SMOOTH = GL11.GL_POLYGON_SMOOTH; + + + ////////////////////////////////////////////////////////////////////////////// + + // Caps query + + + public String getString(int name) { + return GL11.glGetString(name); + } + + + public void getIntegerv(int name, IntBuffer values) { + if (-1 < name) { + GL11.glGetInteger(name, values); + } else { + fillIntBuffer(values, 0, values.capacity() - 1, 0); + } + } + + + public void getFloatv(int name, FloatBuffer values) { + if (-1 < name) { + GL11.glGetFloat(name, values); + } else { + fillFloatBuffer(values, 0, values.capacity() - 1, 0); + } + } + + + public void getBooleanv(int name, IntBuffer values) { + if (-1 < name) { + if (byteBuffer.capacity() < values.capacity()) { + byteBuffer = allocateDirectByteBuffer(values.capacity()); + } + GL11.glGetBoolean(name, byteBuffer); + for (int i = 0; i < values.capacity(); i++) { + values.put(i, byteBuffer.get(i)); + } + } else { + fillIntBuffer(values, 0, values.capacity() - 1, 0); + } + } + + + /////////////////////////////////////////////////////////// + + // Enable/disable caps + + + public void enable(int cap) { + if (-1 < cap) { + GL11.glEnable(cap); + } + } + + + public void disable(int cap) { + if (-1 < cap) { + GL11.glDisable(cap); + } + } + + + /////////////////////////////////////////////////////////// + + // Render control + + + public void flush() { + GL11.glFlush(); + } + + + public void finish() { + GL11.glFinish(); + } + + + /////////////////////////////////////////////////////////// + + // Error handling + + + public int getError() { + return GL11.glGetError(); + } + + + public String errorString(int err) { + return glu.gluErrorString(err); + } + + + /////////////////////////////////////////////////////////// + + // Rendering options + + + public void frontFace(int mode) { + GL11.glFrontFace(mode); + } + + + public void cullFace(int mode) { + GL11.glCullFace(mode); + } + + + public void depthMask(boolean flag) { + GL11.glDepthMask(flag); + } + + + public void depthFunc(int func) { + GL11.glDepthFunc(func); + } + + + /////////////////////////////////////////////////////////// + + // Textures + + + public void genTextures(int n, IntBuffer ids) { + GL11.glGenTextures(ids); + } + + + public void deleteTextures(int n, IntBuffer ids) { + GL11.glDeleteTextures(ids); + } + + + public void activeTexture(int unit) { + GL13.glActiveTexture(unit); + } + + + public void bindTexture(int target, int id) { + GL11.glBindTexture(target, id); + if (target == TEXTURE_2D) { + boundTextures[0] = id; + } else if (target == TEXTURE_RECTANGLE) { + boundTextures[1] = id; + } + } + + + public void texImage2D(int target, int level, int internalFormat, + int width, int height, int border, int format, + int type, Buffer data) { + GL11.glTexImage2D(target, level, internalFormat, + width, height, border, format, type, (IntBuffer)data); + } + + + public void texSubImage2D(int target, int level, int xOffset, int yOffset, + int width, int height, int format, + int type, Buffer data) { + GL11.glTexSubImage2D(target, level, xOffset, yOffset, + width, height, format, type, (IntBuffer)data); + } + + + public void texParameteri(int target, int param, int value) { + GL11.glTexParameteri(target, param, value); + } + + + public void texParameterf(int target, int param, float value) { + GL11.glTexParameterf(target, param, value); + } + + + public void getTexParameteriv(int target, int param, IntBuffer values) { + GL11.glGetTexParameter(target, param, values); + } + + + public void generateMipmap(int target) { + GL30.glGenerateMipmap(target); + } + + + /////////////////////////////////////////////////////////// + + // Vertex Buffers + + + public void genBuffers(int n, IntBuffer ids) { + GL15.glGenBuffers(ids); + } + + + public void deleteBuffers(int n, IntBuffer ids) { + GL15.glDeleteBuffers(ids); + } + + + public void bindBuffer(int target, int id) { + GL15.glBindBuffer(target, id); + } + + + public void bufferData(int target, int size, Buffer data, int usage) { + if (data == null) { + FloatBuffer empty = BufferUtils.createFloatBuffer(size); + GL15.glBufferData(target, empty, usage); + } else { + if (data instanceof ByteBuffer) { + GL15.glBufferData(target, (ByteBuffer)data, usage); + } else if (data instanceof ShortBuffer) { + GL15.glBufferData(target, (ShortBuffer)data, usage); + } else if (data instanceof IntBuffer) { + GL15.glBufferData(target, (IntBuffer)data, usage); + } else if (data instanceof FloatBuffer) { + GL15.glBufferData(target, (FloatBuffer)data, usage); + } + } + } + + + public void bufferSubData(int target, int offset, int size, Buffer data) { + if (data instanceof ByteBuffer) { + GL15.glBufferSubData(target, offset, (ByteBuffer)data); + } else if (data instanceof ShortBuffer) { + GL15.glBufferSubData(target, offset, (ShortBuffer)data); + } else if (data instanceof IntBuffer) { + GL15.glBufferSubData(target, offset, (IntBuffer)data); + } else if (data instanceof FloatBuffer) { + GL15.glBufferSubData(target, offset, (FloatBuffer)data); + } + } + + + public void drawArrays(int mode, int first, int count) { + GL11.glDrawArrays(mode, first, count); + } + + + public void drawElements(int mode, int count, int type, int offset) { + GL11.glDrawElements(mode, count, type, offset); + } + + + public void enableVertexAttribArray(int loc) { + GL20.glEnableVertexAttribArray(loc); + } + + + public void disableVertexAttribArray(int loc) { + GL20.glDisableVertexAttribArray(loc); + } + + + public void vertexAttribPointer(int loc, int size, int type, + boolean normalized, int stride, int offset) { + GL20.glVertexAttribPointer(loc, size, type, normalized, stride, offset); + } + + + public void vertexAttribPointer(int loc, int size, int type, + boolean normalized, int stride, Buffer data) { + if (type == UNSIGNED_INT) { + GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (IntBuffer)data); + } else if (type == UNSIGNED_BYTE) { + GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (ByteBuffer)data); + } else if (type == UNSIGNED_SHORT) { + GL20.glVertexAttribPointer(loc, size, true, normalized, stride, (ShortBuffer)data); + } else if (type == FLOAT) { + GL20.glVertexAttribPointer(loc, size, normalized, stride, (FloatBuffer)data); + } + } + + + public ByteBuffer mapBuffer(int target, int access) { + return GL15.glMapBuffer(target, access, null); + } + + + public ByteBuffer mapBufferRange(int target, int offset, int length, + int access) { + return GL30.glMapBufferRange(target, offset, length, access, null); + } + + + public void unmapBuffer(int target) { + GL15.glUnmapBuffer(target); + } + + + /////////////////////////////////////////////////////////// + + // Framebuffers, renderbuffers + + + public void genFramebuffers(int n, IntBuffer ids) { + GL30.glGenFramebuffers(ids); + } + + + public void deleteFramebuffers(int n, IntBuffer ids) { + GL30.glDeleteFramebuffers(ids); + } + + + public void genRenderbuffers(int n, IntBuffer ids) { + GL30.glGenRenderbuffers(ids); + } + + + public void deleteRenderbuffers(int n, IntBuffer ids) { + GL30.glDeleteRenderbuffers(ids); + } + + + public void bindFramebuffer(int target, int id) { + GL30.glBindFramebuffer(target, id); + } + + + public void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, + int dstX0, int dstY0, int dstX1, int dstY1, + int mask, int filter) { + GL30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1, mask, filter); + } + + + public void framebufferTexture2D(int target, int attachment, int texTarget, + int texId, int level) { + GL30.glFramebufferTexture2D(target, attachment, texTarget, texId, level); + } + + + public void bindRenderbuffer(int target, int id) { + GL30.glBindRenderbuffer(target, id); + } + + + public void renderbufferStorageMultisample(int target, int samples, + int format, int width, int height){ + GL30.glRenderbufferStorageMultisample(target, samples, format, + width, height); + } + + + public void renderbufferStorage(int target, int format, + int width, int height) { + GL30.glRenderbufferStorage(target, format, width, height); + } + + + public void framebufferRenderbuffer(int target, int attachment, + int rendbufTarget, int rendbufId) { + GL30.glFramebufferRenderbuffer(target, attachment, rendbufTarget, rendbufId); + } + + + public int checkFramebufferStatus(int target) { + return GL30.glCheckFramebufferStatus(target); + } + + + /////////////////////////////////////////////////////////// + + // Shaders + + + public int createProgram() { + return GL20.glCreateProgram(); + } + + + public void deleteProgram(int id) { + GL20.glDeleteProgram(id); + } + + + public int createShader(int type) { + return GL20.glCreateShader(type); + } + + + public void deleteShader(int id) { + GL20.glDeleteShader(id); + } + + + public void linkProgram(int prog) { + GL20.glLinkProgram(prog); + } + + + public void validateProgram(int prog) { + GL20.glValidateProgram(prog); + } + + + public void useProgram(int prog) { + GL20.glUseProgram(prog); + } + + + public int getAttribLocation(int prog, String name) { + return GL20.glGetAttribLocation(prog, name); + } + + + public int getUniformLocation(int prog, String name) { + return GL20.glGetUniformLocation(prog, name); + } + + + public void uniform1i(int loc, int value) { + GL20.glUniform1i(loc, value); + } + + + public void uniform2i(int loc, int value0, int value1) { + GL20.glUniform2i(loc, value0, value1); + } + + + public void uniform3i(int loc, int value0, int value1, int value2) { + GL20.glUniform3i(loc, value0, value1, value2); + } + + + public void uniform4i(int loc, int value0, int value1, int value2, + int value3) { + GL20.glUniform4i(loc, value0, value1, value2, value3); + } + + + public void uniform1f(int loc, float value) { + GL20.glUniform1f(loc, value); + } + + + public void uniform2f(int loc, float value0, float value1) { + GL20.glUniform2f(loc, value0, value1); + } + + + public void uniform3f(int loc, float value0, float value1, float value2) { + GL20.glUniform3f(loc, value0, value1, value2); + } + + + public void uniform4f(int loc, float value0, float value1, float value2, + float value3) { + GL20.glUniform4f(loc, value0, value1, value2, value3); + } + + + public void uniform1iv(int loc, int count, IntBuffer v) { + v.limit(count); + GL20.glUniform1(loc, v); + v.clear(); + } + + + public void uniform2iv(int loc, int count, IntBuffer v) { + v.limit(2 * count); + GL20.glUniform2(loc, v); + v.clear(); + } + + + public void uniform3iv(int loc, int count, IntBuffer v) { + v.limit(3 * count); + GL20.glUniform3(loc, v); + v.clear(); + } + + + public void uniform4iv(int loc, int count, IntBuffer v) { + v.limit(4 * count); + GL20.glUniform4(loc, v); + v.clear(); + } + + + public void uniform1fv(int loc, int count, FloatBuffer v) { + v.limit(count); + GL20.glUniform1(loc, v); + v.clear(); + } + + + public void uniform2fv(int loc, int count, FloatBuffer v) { + v.limit(2 * count); + GL20.glUniform2(loc, v); + v.clear(); + } + + + public void uniform3fv(int loc, int count, FloatBuffer v) { + v.limit(3 * count); + GL20.glUniform3(loc, v); + v.clear(); + } + + + public void uniform4fv(int loc, int count, FloatBuffer v) { + v.limit(4 * count); + GL20.glUniform4(loc, v); + v.clear(); + } + + + public void uniformMatrix2fv(int loc, int count, boolean transpose, + FloatBuffer mat) { + mat.limit(4); + GL20.glUniformMatrix2(loc, transpose, mat); + mat.clear(); + } + + + public void uniformMatrix3fv(int loc, int count, boolean transpose, + FloatBuffer mat) { + mat.limit(9); + GL20.glUniformMatrix3(loc, transpose, mat); + mat.clear(); + } + + + public void uniformMatrix4fv(int loc, int count, boolean transpose, + FloatBuffer mat) { + mat.limit(16); + GL20.glUniformMatrix4(loc, transpose, mat); + mat.clear(); + } + + + public void vertexAttrib1f(int loc, float value) { + GL20.glVertexAttrib1f(loc, value); + } + + + public void vertexAttrib2f(int loc, float value0, float value1) { + GL20.glVertexAttrib2f(loc, value0, value1); + } + + + public void vertexAttrib3f(int loc, float value0, float value1, float value2){ + GL20.glVertexAttrib3f(loc, value0, value1, value2); + } + + + public void vertexAttrib4f(int loc, float value0, float value1, float value2, + float value3) { + GL20.glVertexAttrib4f(loc, value0, value1, value2, value3); + } + + + public void shaderSource(int id, String source) { + GL20.glShaderSource(id, source); + } + + + public void compileShader(int id) { + GL20.glCompileShader(id); + } + + + public void attachShader(int prog, int shader) { + GL20.glAttachShader(prog, shader); + } + + + public void getShaderiv(int shader, int pname, IntBuffer params) { + GL20.glGetShader(shader, pname, params); + } + + + public String getShaderInfoLog(int shader) { + int len = GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH); + return GL20.glGetShaderInfoLog(shader, len); + } + + + public void getProgramiv(int prog, int pname, IntBuffer params) { + GL20.glGetProgram(prog, pname, params); + } + + + public String getProgramInfoLog(int prog) { + int len = GL20.glGetProgrami(prog, GL20.GL_INFO_LOG_LENGTH); + return GL20.glGetProgramInfoLog(prog, len); + } + + + /////////////////////////////////////////////////////////// + + // Viewport + + + public void viewport(int x, int y, int width, int height) { + GL11.glViewport(x, y, width, height); + } + + + /////////////////////////////////////////////////////////// + + // Clipping (scissor test) + + + public void scissor(int x, int y, int w, int h) { + GL11.glScissor(x, y, w, h); + } + + + /////////////////////////////////////////////////////////// + + // Blending + + + public void blendEquation(int eq) { + GL14.glBlendEquation(eq); + } + + + public void blendFunc(int srcFactor, int dstFactor) { + GL11.glBlendFunc(srcFactor, dstFactor); + } + + + /////////////////////////////////////////////////////////// + + // Pixels + + + public void readBuffer(int buf) { + GL11.glReadBuffer(buf); + } + + + public void readPixels(int x, int y, int width, int height, int format, + int type, Buffer buffer) { + + GL11.glReadPixels(x, y, width, height, format, type, (IntBuffer)buffer); + } + + + public void drawBuffer(int buf) { + GL11.glDrawBuffer(buf); + } + + + public void clearDepth(float d) { + GL11.glClearDepth(d); + } + + + public void clearStencil(int s) { + GL11.glClearStencil(s); + } + + + public void colorMask(boolean wr, boolean wg, boolean wb, boolean wa) { + GL11.glColorMask(wr, wg, wb, wa); + } + + + public void clearColor(float r, float g, float b, float a) { + GL11.glClearColor(r, g, b, a); + } + + + public void clear(int mask) { + GL11.glClear(mask); + } } From 8ed4286657e9649848565863fce53c3e2a374e56 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 23 May 2013 17:37:29 -0400 Subject: [PATCH 13/46] Remove uv clamping --- core/src/processing/opengl/PGraphicsOpenGL.java | 4 ++-- core/src/processing/opengl/PShapeOpenGL.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 08b04f175..099104a00 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2149,8 +2149,8 @@ public class PGraphicsOpenGL extends PGraphics { } if (textured && textureMode == IMAGE) { - u = PApplet.min(1, u / textureImage.width); - v = PApplet.min(1, v / textureImage.height); + u /= textureImage.width; + v /= textureImage.height; } inGeo.addVertex(x, y, z, diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index e58d3d598..a9912be8d 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1006,9 +1006,9 @@ public class PShapeOpenGL extends PShape { } } - if (image != null && textureMode == IMAGE) { - u = PApplet.min(1, u / image.width); - v = PApplet.min(1, v / image.height); + if (textureMode == IMAGE && image != null) { + u /= image.width; + v /= image.height; } int scolor = 0x00; @@ -1578,9 +1578,9 @@ public class PShapeOpenGL extends PShape { return; } - if (image != null && textureMode == IMAGE) { - u = PApplet.min(1, u / image.width); - v = PApplet.min(1, v / image.height); + if (textureMode == IMAGE && image != null) { + u /= image.width; + v /= image.height; } inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; From b91258399f5e282830d8506ffd8fcb6336fa5bea Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 23 May 2013 14:46:23 -0700 Subject: [PATCH 14/46] Updated PVector mult() and div() reference --- core/src/processing/core/PVector.java | 19 ++++++------------- core/src/processing/data/Table.java | 10 +++++++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index 9f04977c5..725c208b1 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -521,7 +521,7 @@ public class PVector implements Serializable { * Subtract one vector from another and store in another vector * @param v1 the x, y, and z components of a PVector object * @param v2 the x, y, and z components of a PVector object - * @param target PVector to store the result + * @param target PVector in which to store the result */ static public PVector sub(PVector v1, PVector v2, PVector target) { if (target == null) { @@ -542,8 +542,8 @@ public class PVector implements Serializable { * * @webref pvector:method * @usage web_application - * @param n the number to multiply with the vector * @brief Multiply a vector by a scalar + * @param n the number to multiply with the vector */ public void mult(float n) { x *= n; @@ -554,7 +554,6 @@ public class PVector implements Serializable { /** * @param v the vector to multiply by the scalar - * @nowebref */ static public PVector mult(PVector v, float n) { return mult(v, n, null); @@ -563,8 +562,7 @@ public class PVector implements Serializable { /** * Multiply a vector by a scalar, and write the result into a target PVector. - * @param target PVector to store the result - * @nowebref + * @param target PVector in which to store the result */ static public PVector mult(PVector v, float n, PVector target) { if (target == null) { @@ -586,8 +584,8 @@ public class PVector implements Serializable { * * @webref pvector:method * @usage web_application - * @param n the value to divide by * @brief Divide a vector by a scalar + * @param n the number by which to divide the vector */ public void div(float n) { x /= n; @@ -598,10 +596,8 @@ public class PVector implements Serializable { /** * Divide a vector by a scalar and return the result in a new vector. - * @param v any variable of type PVector - * @param n the number to divide with the vector + * @param v the vector to divide by the scalar * @return a new vector that is v1 / n - * @nowebref */ static public PVector div(PVector v, float n) { return div(v, n, null); @@ -609,10 +605,7 @@ public class PVector implements Serializable { /** * Divide a vector by a scalar and store the result in another vector. - * @param v any variable of type PVector - * @param n the number to divide with the vector - * @param target PVector to store the result - * @nowebref + * @param target PVector in which to store the result */ static public PVector div(PVector v, float n, PVector target) { if (target == null) { diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 71eafdd2e..2a7e314cb 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -1717,7 +1717,7 @@ public class Table { rowCount = newCount; } - /** + /** * @webref table:method * @brief Adds a row to the table */ @@ -1726,7 +1726,9 @@ public class Table { return new RowPointer(this, rowCount - 1); } - + /** + * @param source a reference to the original row to be duplicated + */ public TableRow addRow(TableRow source) { int row = rowCount; // Make sure there are enough columns to add this data @@ -1757,7 +1759,9 @@ public class Table { return new RowPointer(this, row); } - + /** + * @nowebref + */ public TableRow addRow(Object[] columnData) { setRow(getRowCount(), columnData); return new RowPointer(this, rowCount - 1); From 482c8ea2e995f7f00c1291bd827600c2e64cebad Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 23 May 2013 19:10:23 -0400 Subject: [PATCH 15/46] Improved the logic that sets the size of the font textures --- core/src/processing/opengl/FontTexture.java | 35 +++++++++++-------- core/src/processing/opengl/PGL.java | 3 +- .../processing/opengl/PGraphicsOpenGL.java | 6 ++-- .../lwjgl/src/processing/lwjgl/PGL.java | 3 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/core/src/processing/opengl/FontTexture.java b/core/src/processing/opengl/FontTexture.java index c14367e15..2a9fbadeb 100644 --- a/core/src/processing/opengl/FontTexture.java +++ b/core/src/processing/opengl/FontTexture.java @@ -26,6 +26,7 @@ package processing.opengl; import processing.core.PApplet; import processing.core.PConstants; import processing.core.PFont; +import processing.core.PGraphics; import processing.core.PImage; import java.util.HashMap; @@ -50,8 +51,8 @@ class FontTexture implements PConstants { protected PGL pgl; protected boolean is3D; - protected int maxTexWidth; - protected int maxTexHeight; + protected int minSize; + protected int maxSize; protected int offsetX; protected int offsetY; protected int lineHeight; @@ -62,12 +63,11 @@ class FontTexture implements PConstants { protected TextureInfo[] glyphTexinfos; protected HashMap texinfoMap; - public FontTexture(PGraphicsOpenGL pg, PFont font, int maxw, int maxh, - boolean is3D) { + public FontTexture(PGraphicsOpenGL pg, PFont font, boolean is3D) { pgl = PGraphicsOpenGL.pgl; this.is3D = is3D; - initTexture(pg, font, maxw, maxh); + initTexture(pg, font); } @@ -84,13 +84,21 @@ class FontTexture implements PConstants { } - protected void initTexture(PGraphicsOpenGL pg, PFont font, int w, int h) { - maxTexWidth = w; - maxTexHeight = h; - + protected void initTexture(PGraphicsOpenGL pg, PFont font) { currentTex = -1; lastTex = -1; + int spow = PGL.nextPowerOfTwo(font.getSize()); + minSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, + PApplet.max(PGL.MIN_FONT_TEX_SIZE, spow)); + maxSize = PApplet.min(PGraphicsOpenGL.maxTextureSize, + PApplet.max(PGL.MAX_FONT_TEX_SIZE, 2 * spow)); + + if (maxSize < spow) { + PGraphics.showWarning("The font size is too large to be properly " + + "displayed with OpenGL"); + } + addTexture(pg); offsetX = 0; @@ -107,15 +115,14 @@ class FontTexture implements PConstants { int w, h; boolean resize; - w = maxTexWidth; - if (-1 < currentTex && textures[currentTex].glHeight < maxTexHeight) { + w = maxSize; + if (-1 < currentTex && textures[currentTex].glHeight < maxSize) { // The height of the current texture is less than the maximum, this // means we can replace it with a larger texture. - h = PApplet.min(2 * textures[currentTex].glHeight, maxTexHeight); + h = PApplet.min(2 * textures[currentTex].glHeight, maxSize); resize = true; } else { - h = PApplet.min(PGraphicsOpenGL.maxTextureSize, PGL.MAX_FONT_TEX_SIZE / 2, - maxTexHeight / 4); + h = minSize; resize = false; } diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 0c0d496f6..ba513c90b 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -127,7 +127,8 @@ public class PGL { */ protected static final int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1; - /** Maximum dimension of a texture used to hold font data. **/ + /** Minimum/maximum dimensions of a texture used to hold font data. **/ + protected static final int MIN_FONT_TEX_SIZE = 256; protected static final int MAX_FONT_TEX_SIZE = 1024; /** Minimum stroke weight needed to apply the full path stroking diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 509d5ff95..a8a2aa2dc 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3278,12 +3278,10 @@ public class PGraphicsOpenGL extends PGraphics { textTex = pgPrimary.getFontTexture(textFont); if (textTex == null || textTex.contextIsOutdated()) { - textTex = new FontTexture(pgPrimary, textFont, - PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), - PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); + textTex = new FontTexture(pgPrimary, textFont, is3D()); pgPrimary.setFontTexture(textFont, textTex); } - + textTex.begin(); // Saving style parameters modified by text rendering. diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index 1792399d9..b3e4955c0 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -124,7 +124,8 @@ public class PGL extends processing.opengl.PGL { */ protected static final int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1; - /** Maximum dimension of a texture used to hold font data. **/ + /** Minimum/maximum dimensions of a texture used to hold font data. **/ + protected static final int MIN_FONT_TEX_SIZE = 256; protected static final int MAX_FONT_TEX_SIZE = 1024; /** Minimum stroke weight needed to apply the full path stroking From ba10293273a05ec25829409fe3629ed9c0f49c9b Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 23 May 2013 16:42:05 -0700 Subject: [PATCH 16/46] Added Table reference for removeColumn(), removeRow(), getRow(), and clearRows() --- core/src/processing/data/Table.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 2a7e314cb..bc0d97fe5 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -1816,6 +1816,7 @@ public class Table { /** * @webref table:method * @brief Removes a row from the table + * @param row ID value of the row to remove */ public void removeRow(int row) { for (int col = 0; col < columns.length; col++) { @@ -2014,6 +2015,7 @@ public class Table { /** * @webref table:method * @brief Gets a row from the table + * @param row ID value of the row to get */ public TableRow getRow(int row) { return new RowPointer(this, row); @@ -2026,7 +2028,7 @@ public class Table { * If you want to iterate in a multi-threaded manner, don't use the iterator. * * @webref table:method - * @brief To come... + * @brief Gets multiple rows from the table */ public Iterable rows() { return new Iterable() { @@ -2916,14 +2918,18 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Finds a row that matches given criteria + * @param value the value to match + * @param column ID number of the column to search */ public TableRow findRow(String value, int column) { int row = findRowIndex(value, column); return (row == -1) ? null : new RowPointer(this, row); } - + /** + * @param columnName title the column to search + */ public TableRow findRow(String value, String columnName) { return findRow(value, getColumnIndex(columnName)); } From b9ab4107f42952fb984020b2a802526912fe565a Mon Sep 17 00:00:00 2001 From: REAS Date: Thu, 23 May 2013 23:17:35 -0700 Subject: [PATCH 17/46] Reference additions for IntDict --- core/src/processing/data/FloatDict.java | 8 ++--- core/src/processing/data/IntDict.java | 39 ++++++++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/core/src/processing/data/FloatDict.java b/core/src/processing/data/FloatDict.java index effdf4209..102493802 100644 --- a/core/src/processing/data/FloatDict.java +++ b/core/src/processing/data/FloatDict.java @@ -312,7 +312,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Add to a value */ public void add(String key, float amount) { int index = index(key); @@ -332,7 +332,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Subtract from a value */ public void sub(String key, float amount) { add(key, -amount); @@ -341,7 +341,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Multiply a value */ public void mult(String key, float amount) { int index = index(key); @@ -353,7 +353,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Divide a value */ public void div(String key, float amount) { int index = index(key); diff --git a/core/src/processing/data/IntDict.java b/core/src/processing/data/IntDict.java index 117b83d7b..22e52c600 100644 --- a/core/src/processing/data/IntDict.java +++ b/core/src/processing/data/IntDict.java @@ -101,8 +101,10 @@ public class IntDict { } /** + * Returns the number of key/value pairs + * * @webref intdict:method - * @brief To come... + * @brief Returns the number of key/value pairs */ public int size() { return count; @@ -241,6 +243,8 @@ public class IntDict { * Fill an already-allocated array with the values (more efficient than * creating a new array each time). If 'array' is null, or not the same * size as the number of values, a new array will be allocated and returned. + * + * @param array values to copy into the array */ public int[] valueArray(int[] array) { if (array == null || array.length != size()) { @@ -264,8 +268,10 @@ public class IntDict { } /** + * Create a new key/value pair or change the value of one. + * * @webref intdict:method - * @brief To come... + * @brief Create a new key/value pair or change the value of one */ public void set(String key, int amount) { int index = index(key); @@ -278,7 +284,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Check if a key is a part of the data structure */ public boolean hasKey(String key) { return index(key) != -1; @@ -286,10 +292,10 @@ public class IntDict { /** - * Increase the value of a specific key by 1. + * Increase the value of a specific key value by 1. * * @webref intdict:method - * @brief Increase the value of a specific key by 1 + * @brief Increase the value of a specific key value by 1 */ public void increment(String key) { add(key, 1); @@ -297,7 +303,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Add to a value */ public void add(String key, int amount) { int index = index(key); @@ -310,7 +316,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Subtract from a value */ public void sub(String key, int amount) { add(key, -amount); @@ -318,7 +324,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Multiply a value */ public void mult(String key, int amount) { int index = index(key); @@ -329,7 +335,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Divide a value */ public void div(String key, int amount) { int index = index(key); @@ -358,7 +364,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Remove a key/value pair */ public void remove(String key) { removeIndex(index(key)); @@ -404,8 +410,11 @@ public class IntDict { } /** + * Sort the keys alphabetically in reverse (ignoring case). Uses the value as a + * tie-breaker (only really possible with a key that has a case change). + * * @webref intdict:method - * @brief To come... + * @brief Sort the keys alphabetially in reverse */ public void sortKeysReverse() { sortImpl(true, true); @@ -413,18 +422,20 @@ public class IntDict { /** - * Sort by values in descending order (largest value will be at [0]). + * Sort by values in ascending order. The smallest value will be at [0]. * * @webref intdict:method - * @brief Sort by values in descending order + * @brief Sort by values in ascending order */ public void sortValues() { sortImpl(false, false); } /** + * Sort by values in descending order. The largest value will be at [0]. + * * @webref intdict:method - * @brief To come... + * @brief Sort by values in descending order */ public void sortValuesReverse() { sortImpl(false, true); From cce3972900df98f5bafd5d895e0914ce991ed1e1 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 25 May 2013 02:10:28 -0400 Subject: [PATCH 18/46] Don't recreate VBOs in PShapeOpenGL, unless there is a new GL context --- core/src/processing/opengl/PShapeOpenGL.java | 248 ++++++++++++++----- 1 file changed, 186 insertions(+), 62 deletions(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index a9912be8d..6ad076cde 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -161,7 +161,10 @@ public class PShapeOpenGL extends PShape { // State/rendering flags protected boolean tessellated; - protected boolean needBufferInit; + protected boolean needBufferInit = false; +// protected boolean polyBuffersCreated = false; +// protected boolean lineBuffersCreated = false; +// protected boolean pointBuffersCreated = false; protected boolean isSolid; protected boolean isClosed; @@ -2360,35 +2363,49 @@ public class PShapeOpenGL extends PShape { protected void updateTessellation() { - if (!root.tessellated || root.contextIsOutdated()) { + if (!root.tessellated) { root.tessellate(); root.aggregate(); + root.initModified(); + root.needBufferInit = true; } } - protected void markForTessellation() { + public void markForTessellation() { root.tessellated = false; tessellated = false; } - protected void tessellate() { - if (root == this && parent == null) { - if (tessGeo == null) { - tessGeo = pg.newTessGeometry(PGraphicsOpenGL.RETAINED); - } - tessGeo.clear(); - - tessellateImpl(); - - // Tessellated arrays are trimmed since they are expanded - // by doubling their old size, which might lead to arrays - // larger than the vertex counts. - tessGeo.trim(); - - modified = false; - needBufferInit = true; + protected void initModified() { + /* + if (hasPolys) { + modifiedPolyVertices = true; + modifiedPolyColors = true; + modifiedPolyNormals = true; + modifiedPolyTexCoords = true; + modifiedPolyAmbient = true; + modifiedPolySpecular = true; + modifiedPolyEmissive = true; + modifiedPolyShininess = true; + firstModifiedPolyVertex = 0; + lastModifiedPolyVertex = tessGeo.polyVertexCount - 1; + firstModifiedPolyColor = 0; + lastModifiedPolyColor = tessGeo.polyVertexCount - 1; + firstModifiedPolyNormal = 0; + lastModifiedPolyNormal = tessGeo.polyVertexCount - 1; + firstModifiedPolyTexcoord = 0; + lastModifiedPolyTexcoord = tessGeo.polyVertexCount - 1; + firstModifiedPolyAmbient = 0; + lastModifiedPolyAmbient = tessGeo.polyVertexCount - 1; + firstModifiedPolySpecular = 0; + lastModifiedPolySpecular = tessGeo.polyVertexCount - 1; + firstModifiedPolyEmissive = 0; + lastModifiedPolyEmissive = tessGeo.polyVertexCount - 1; + firstModifiedPolyShininess = 0; + lastModifiedPolyShininess = tessGeo.polyVertexCount - 1; + } else { modifiedPolyVertices = false; modifiedPolyColors = false; modifiedPolyNormals = false; @@ -2397,15 +2414,6 @@ public class PShapeOpenGL extends PShape { modifiedPolySpecular = false; modifiedPolyEmissive = false; modifiedPolyShininess = false; - - modifiedLineVertices = false; - modifiedLineColors = false; - modifiedLineAttributes = false; - - modifiedPointVertices = false; - modifiedPointColors = false; - modifiedPointAttributes = false; - firstModifiedPolyVertex = PConstants.MAX_INT; lastModifiedPolyVertex = PConstants.MIN_INT; firstModifiedPolyColor = PConstants.MAX_INT; @@ -2422,14 +2430,44 @@ public class PShapeOpenGL extends PShape { lastModifiedPolyEmissive = PConstants.MIN_INT; firstModifiedPolyShininess = PConstants.MAX_INT; lastModifiedPolyShininess = PConstants.MIN_INT; + } + if (hasLines) { + modifiedLineVertices = true; + modifiedLineColors = true; + modifiedLineAttributes = true; + firstModifiedLineVertex = 0; + lastModifiedLineVertex = tessGeo.lineVertexCount - 1; + firstModifiedLineColor = 0; + lastModifiedLineColor = tessGeo.lineVertexCount - 1; + firstModifiedLineAttribute = 0; + lastModifiedLineAttribute = tessGeo.lineVertexCount - 1; + } else { + modifiedLineVertices = false; + modifiedLineColors = false; + modifiedLineAttributes = false; firstModifiedLineVertex = PConstants.MAX_INT; lastModifiedLineVertex = PConstants.MIN_INT; firstModifiedLineColor = PConstants.MAX_INT; lastModifiedLineColor = PConstants.MIN_INT; firstModifiedLineAttribute = PConstants.MAX_INT; lastModifiedLineAttribute = PConstants.MIN_INT; + } + if (hasLines) { + modifiedPointVertices = true; + modifiedPointColors = true; + modifiedPointAttributes = true; + firstModifiedPointVertex = 0; + lastModifiedPointVertex = tessGeo.pointVertexCount - 1; + firstModifiedPointColor = 0; + lastModifiedPointColor = tessGeo.pointVertexCount - 1; + firstModifiedPointAttribute = 0; + lastModifiedPointAttribute = tessGeo.pointVertexCount - 1; + } else { + modifiedPointVertices = false; + modifiedPointColors = false; + modifiedPointAttributes = false; firstModifiedPointVertex = PConstants.MAX_INT; lastModifiedPointVertex = PConstants.MIN_INT; firstModifiedPointColor = PConstants.MAX_INT; @@ -2437,6 +2475,77 @@ public class PShapeOpenGL extends PShape { firstModifiedPointAttribute = PConstants.MAX_INT; lastModifiedPointAttribute = PConstants.MIN_INT; } + + modified = hasPolys || hasLines || hasPoints; +*/ + + + modified = false; + + modifiedPolyVertices = false; + modifiedPolyColors = false; + modifiedPolyNormals = false; + modifiedPolyTexCoords = false; + modifiedPolyAmbient = false; + modifiedPolySpecular = false; + modifiedPolyEmissive = false; + modifiedPolyShininess = false; + + modifiedLineVertices = false; + modifiedLineColors = false; + modifiedLineAttributes = false; + + modifiedPointVertices = false; + modifiedPointColors = false; + modifiedPointAttributes = false; + + firstModifiedPolyVertex = PConstants.MAX_INT; + lastModifiedPolyVertex = PConstants.MIN_INT; + firstModifiedPolyColor = PConstants.MAX_INT; + lastModifiedPolyColor = PConstants.MIN_INT; + firstModifiedPolyNormal = PConstants.MAX_INT; + lastModifiedPolyNormal = PConstants.MIN_INT; + firstModifiedPolyTexcoord = PConstants.MAX_INT; + lastModifiedPolyTexcoord = PConstants.MIN_INT; + firstModifiedPolyAmbient = PConstants.MAX_INT; + lastModifiedPolyAmbient = PConstants.MIN_INT; + firstModifiedPolySpecular = PConstants.MAX_INT; + lastModifiedPolySpecular = PConstants.MIN_INT; + firstModifiedPolyEmissive = PConstants.MAX_INT; + lastModifiedPolyEmissive = PConstants.MIN_INT; + firstModifiedPolyShininess = PConstants.MAX_INT; + lastModifiedPolyShininess = PConstants.MIN_INT; + + firstModifiedLineVertex = PConstants.MAX_INT; + lastModifiedLineVertex = PConstants.MIN_INT; + firstModifiedLineColor = PConstants.MAX_INT; + lastModifiedLineColor = PConstants.MIN_INT; + firstModifiedLineAttribute = PConstants.MAX_INT; + lastModifiedLineAttribute = PConstants.MIN_INT; + + firstModifiedPointVertex = PConstants.MAX_INT; + lastModifiedPointVertex = PConstants.MIN_INT; + firstModifiedPointColor = PConstants.MAX_INT; + lastModifiedPointColor = PConstants.MIN_INT; + firstModifiedPointAttribute = PConstants.MAX_INT; + lastModifiedPointAttribute = PConstants.MIN_INT; + } + + + protected void tessellate() { + if (root == this && parent == null) { + if (tessGeo == null) { + tessGeo = pg.newTessGeometry(PGraphicsOpenGL.RETAINED); + } + tessGeo.clear(); + + tessellateImpl(); + + // Tessellated arrays are trimmed since they are expanded + // by doubling their old size, which might lead to arrays + // larger than the vertex counts. + tessGeo.trim(); + } } @@ -3272,23 +3381,22 @@ public class PShapeOpenGL extends PShape { protected void initBuffers() { - if (needBufferInit) { - context = pgl.getCurrentContext(); + boolean outdated = contextIsOutdated(); + context = pgl.getCurrentContext(); - if (0 < tessGeo.polyVertexCount && 0 < tessGeo.polyIndexCount) { - initPolyBuffers(); - } - - if (0 < tessGeo.lineVertexCount && 0 < tessGeo.lineIndexCount) { - initLineBuffers(); - } - - if (0 < tessGeo.pointVertexCount && 0 < tessGeo.pointIndexCount) { - initPointBuffers(); - } - - needBufferInit = false; + if (hasPolys && (needBufferInit || outdated)) { + initPolyBuffers(); } + + if (hasLines && (needBufferInit || outdated)) { + initLineBuffers(); + } + + if (hasPoints && (needBufferInit || outdated)) { + initPointBuffers(); + } + + needBufferInit = false; } @@ -3298,50 +3406,57 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updatePolyVerticesBuffer(); - glPolyVertex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyVertex == 0) + glPolyVertex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, - tessGeo.polyVerticesBuffer, - PGL.STATIC_DRAW); + tessGeo.polyVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyColorsBuffer(); - glPolyColor = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyColor == 0) + glPolyColor = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyColorsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyNormalsBuffer(); - glPolyNormal = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyNormal == 0) + glPolyNormal = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal); pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, tessGeo.polyNormalsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyTexCoordsBuffer(); - glPolyTexcoord = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyTexcoord == 0) + glPolyTexcoord = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, tessGeo.polyTexCoordsBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyAmbientBuffer(); - glPolyAmbient = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyAmbient == 0) + glPolyAmbient = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyAmbientBuffer, PGL.STATIC_DRAW); tessGeo.updatePolySpecularBuffer(); - glPolySpecular = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolySpecular == 0) + glPolySpecular = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polySpecularBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyEmissiveBuffer(); - glPolyEmissive = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyEmissive == 0) + glPolyEmissive = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.polyEmissiveBuffer, PGL.STATIC_DRAW); tessGeo.updatePolyShininessBuffer(); - glPolyShininess = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyShininess == 0) + glPolyShininess = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess); pgl.bufferData(PGL.ARRAY_BUFFER, sizef, tessGeo.polyShininessBuffer, PGL.STATIC_DRAW); @@ -3349,7 +3464,8 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updatePolyIndicesBuffer(); - glPolyIndex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPolyIndex == 0) + glPolyIndex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, @@ -3365,19 +3481,22 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updateLineVerticesBuffer(); - glLineVertex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glLineVertex == 0) + glLineVertex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.lineVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updateLineColorsBuffer(); - glLineColor = PGraphicsOpenGL.createVertexBufferObject(context); + if (glLineColor == 0) + glLineColor = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.lineColorsBuffer, PGL.STATIC_DRAW); tessGeo.updateLineDirectionsBuffer(); - glLineAttrib = PGraphicsOpenGL.createVertexBufferObject(context); + if (glLineAttrib == 0) + glLineAttrib = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.lineDirectionsBuffer, PGL.STATIC_DRAW); @@ -3385,7 +3504,8 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updateLineIndicesBuffer(); - glLineIndex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glLineIndex == 0) + glLineIndex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, @@ -3401,19 +3521,22 @@ public class PShapeOpenGL extends PShape { int sizei = size * PGL.SIZEOF_INT; tessGeo.updatePointVerticesBuffer(); - glPointVertex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPointVertex == 0) + glPointVertex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, tessGeo.pointVerticesBuffer, PGL.STATIC_DRAW); tessGeo.updatePointColorsBuffer(); - glPointColor = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPointColor == 0) + glPointColor = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); pgl.bufferData(PGL.ARRAY_BUFFER, sizei, tessGeo.pointColorsBuffer, PGL.STATIC_DRAW); tessGeo.updatePointOffsetsBuffer(); - glPointAttrib = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPointAttrib == 0) + glPointAttrib = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, tessGeo.pointOffsetsBuffer, PGL.STATIC_DRAW); @@ -3421,7 +3544,8 @@ public class PShapeOpenGL extends PShape { pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); tessGeo.updatePointIndicesBuffer(); - glPointIndex = PGraphicsOpenGL.createVertexBufferObject(context); + if (glPointIndex == 0) + glPointIndex = PGraphicsOpenGL.createVertexBufferObject(context); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, From de9cbc0dbdac85a2d109e3f2ee86168711fdedfa Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 25 May 2013 02:11:49 -0400 Subject: [PATCH 19/46] markForTessellation shouldn't be public --- core/src/processing/opengl/PShapeOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 6ad076cde..f2a9174bb 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -2372,7 +2372,7 @@ public class PShapeOpenGL extends PShape { } - public void markForTessellation() { + protected void markForTessellation() { root.tessellated = false; tessellated = false; } From 36f92607c3dd98f1b9ea7350eaaa0a672cece119 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 25 May 2013 02:24:11 -0400 Subject: [PATCH 20/46] Removed some commented-out code --- core/src/processing/opengl/PShapeOpenGL.java | 101 ------------------- 1 file changed, 101 deletions(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index f2a9174bb..2f5760b11 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -2379,107 +2379,6 @@ public class PShapeOpenGL extends PShape { protected void initModified() { - /* - if (hasPolys) { - modifiedPolyVertices = true; - modifiedPolyColors = true; - modifiedPolyNormals = true; - modifiedPolyTexCoords = true; - modifiedPolyAmbient = true; - modifiedPolySpecular = true; - modifiedPolyEmissive = true; - modifiedPolyShininess = true; - firstModifiedPolyVertex = 0; - lastModifiedPolyVertex = tessGeo.polyVertexCount - 1; - firstModifiedPolyColor = 0; - lastModifiedPolyColor = tessGeo.polyVertexCount - 1; - firstModifiedPolyNormal = 0; - lastModifiedPolyNormal = tessGeo.polyVertexCount - 1; - firstModifiedPolyTexcoord = 0; - lastModifiedPolyTexcoord = tessGeo.polyVertexCount - 1; - firstModifiedPolyAmbient = 0; - lastModifiedPolyAmbient = tessGeo.polyVertexCount - 1; - firstModifiedPolySpecular = 0; - lastModifiedPolySpecular = tessGeo.polyVertexCount - 1; - firstModifiedPolyEmissive = 0; - lastModifiedPolyEmissive = tessGeo.polyVertexCount - 1; - firstModifiedPolyShininess = 0; - lastModifiedPolyShininess = tessGeo.polyVertexCount - 1; - } else { - modifiedPolyVertices = false; - modifiedPolyColors = false; - modifiedPolyNormals = false; - modifiedPolyTexCoords = false; - modifiedPolyAmbient = false; - modifiedPolySpecular = false; - modifiedPolyEmissive = false; - modifiedPolyShininess = false; - firstModifiedPolyVertex = PConstants.MAX_INT; - lastModifiedPolyVertex = PConstants.MIN_INT; - firstModifiedPolyColor = PConstants.MAX_INT; - lastModifiedPolyColor = PConstants.MIN_INT; - firstModifiedPolyNormal = PConstants.MAX_INT; - lastModifiedPolyNormal = PConstants.MIN_INT; - firstModifiedPolyTexcoord = PConstants.MAX_INT; - lastModifiedPolyTexcoord = PConstants.MIN_INT; - firstModifiedPolyAmbient = PConstants.MAX_INT; - lastModifiedPolyAmbient = PConstants.MIN_INT; - firstModifiedPolySpecular = PConstants.MAX_INT; - lastModifiedPolySpecular = PConstants.MIN_INT; - firstModifiedPolyEmissive = PConstants.MAX_INT; - lastModifiedPolyEmissive = PConstants.MIN_INT; - firstModifiedPolyShininess = PConstants.MAX_INT; - lastModifiedPolyShininess = PConstants.MIN_INT; - } - - if (hasLines) { - modifiedLineVertices = true; - modifiedLineColors = true; - modifiedLineAttributes = true; - firstModifiedLineVertex = 0; - lastModifiedLineVertex = tessGeo.lineVertexCount - 1; - firstModifiedLineColor = 0; - lastModifiedLineColor = tessGeo.lineVertexCount - 1; - firstModifiedLineAttribute = 0; - lastModifiedLineAttribute = tessGeo.lineVertexCount - 1; - } else { - modifiedLineVertices = false; - modifiedLineColors = false; - modifiedLineAttributes = false; - firstModifiedLineVertex = PConstants.MAX_INT; - lastModifiedLineVertex = PConstants.MIN_INT; - firstModifiedLineColor = PConstants.MAX_INT; - lastModifiedLineColor = PConstants.MIN_INT; - firstModifiedLineAttribute = PConstants.MAX_INT; - lastModifiedLineAttribute = PConstants.MIN_INT; - } - - if (hasLines) { - modifiedPointVertices = true; - modifiedPointColors = true; - modifiedPointAttributes = true; - firstModifiedPointVertex = 0; - lastModifiedPointVertex = tessGeo.pointVertexCount - 1; - firstModifiedPointColor = 0; - lastModifiedPointColor = tessGeo.pointVertexCount - 1; - firstModifiedPointAttribute = 0; - lastModifiedPointAttribute = tessGeo.pointVertexCount - 1; - } else { - modifiedPointVertices = false; - modifiedPointColors = false; - modifiedPointAttributes = false; - firstModifiedPointVertex = PConstants.MAX_INT; - lastModifiedPointVertex = PConstants.MIN_INT; - firstModifiedPointColor = PConstants.MAX_INT; - lastModifiedPointColor = PConstants.MIN_INT; - firstModifiedPointAttribute = PConstants.MAX_INT; - lastModifiedPointAttribute = PConstants.MIN_INT; - } - - modified = hasPolys || hasLines || hasPoints; -*/ - - modified = false; modifiedPolyVertices = false; From 1a20adae8c18a1ddef6e1d12cab7fbdb537220c1 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 25 May 2013 10:00:13 -0400 Subject: [PATCH 21/46] updateTessellation() removed PShapeOpenGL.getVertexCount() --- core/src/processing/opengl/PShapeOpenGL.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 2f5760b11..a77636aa6 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1446,7 +1446,6 @@ public class PShapeOpenGL extends PShape { @Override public int getVertexCount() { - updateTessellation(); return family == GROUP ? 0 : inGeo.vertexCount; } From 229869829eb5dfc37ff27c3d0354277980505ef6 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 16:05:26 -0700 Subject: [PATCH 22/46] Added reference for Table rows(), findRow(), findRows(), matchRow(), matchRows() --- core/src/processing/data/Table.java | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index bc0d97fe5..01afee0f1 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -2043,7 +2043,9 @@ public class Table { }; } - + /** + * @nowebref + */ public Iterable rows(final int[] indices) { return new Iterable() { public Iterator iterator() { @@ -2918,7 +2920,7 @@ public class Table { /** * @webref table:method - * @brief Finds a row that matches given criteria + * @brief Finds a row that contains the given value * @param value the value to match * @param column ID number of the column to search */ @@ -2928,7 +2930,7 @@ public class Table { } /** - * @param columnName title the column to search + * @param columnName title of the column to search */ public TableRow findRow(String value, String columnName) { return findRow(value, getColumnIndex(columnName)); @@ -2936,13 +2938,17 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Finds multiple rows that contain the given value + * @param value the value to match + * @param column ID number of the column to search */ public Iterator findRows(String value, int column) { return new RowIndexIterator(this, findRowIndices(value, column)); } - + /** + * @param columnName title of the column to search + */ public Iterator findRows(String value, String columnName) { return findRows(value, getColumnIndex(columnName)); } @@ -3036,27 +3042,35 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Finds a row that matches the given expression + * @param regexp the regular expression to match + * @param column ID number of the column to search */ public TableRow matchRow(String regexp, int column) { int row = matchRowIndex(regexp, column); return (row == -1) ? null : new RowPointer(this, row); } - + /** + * @param columnName title of the column to search + */ public TableRow matchRow(String regexp, String columnName) { return matchRow(regexp, getColumnIndex(columnName)); } /** * @webref table:method - * @brief To come... + * @brief Finds multiple rows that match the given expression + * @param value the regular expression to match + * @param column ID number of the column to search */ public Iterator matchRows(String value, int column) { return new RowIndexIterator(this, matchRowIndices(value, column)); } - + /** + * @param columnName title of the column to search + */ public Iterator matchRows(String value, String columnName) { return matchRows(value, getColumnIndex(columnName)); } From 2a3999eb49df911e5136f4d104058dc8bd9e6ab8 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 17:24:16 -0700 Subject: [PATCH 23/46] Added reference for Table getInt(), getFloat(), getString(), setInt(), setFloat(), setString() --- core/src/processing/data/Table.java | 102 ++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 28 deletions(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 01afee0f1..bc770a285 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -1816,7 +1816,7 @@ public class Table { /** * @webref table:method * @brief Removes a row from the table - * @param row ID value of the row to remove + * @param row ID number of the row to remove */ public void removeRow(int row) { for (int col = 0; col < columns.length; col++) { @@ -2015,7 +2015,7 @@ public class Table { /** * @webref table:method * @brief Gets a row from the table - * @param row ID value of the row to get + * @param row ID number of the row to get */ public TableRow getRow(int row) { return new RowPointer(this, row); @@ -2384,6 +2384,12 @@ public class Table { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + /** + * @webref table:method + * @brief Get an integer value from the specified row and column + * @param row ID number of the row to reference + * @param column ID number of the column to reference + */ public int getInt(int row, int column) { checkBounds(row, column); if (columnTypes[column] == INT || @@ -2396,7 +2402,9 @@ public class Table { missingInt : PApplet.parseInt(str, missingInt); } - + /** + * @param columnName title of the column to reference + */ public int getInt(int row, String columnName) { return getInt(row, getColumnIndex(columnName)); } @@ -2407,6 +2415,13 @@ public class Table { } + /** + * @webref table:method + * @brief Store an integer value in the specified row and column + * @param row ID number of the target row + * @param column ID number of the target column + * @param value value to assign + */ public void setInt(int row, int column, int value) { if (columnTypes[column] == STRING) { setString(row, column, String.valueOf(value)); @@ -2422,7 +2437,9 @@ public class Table { } } - + /** + * @param columnName title of the target column + */ public void setInt(int row, String columnName, int value) { setInt(row, getColumnIndex(columnName), value); } @@ -2535,6 +2552,11 @@ public class Table { * Get a float value from the specified row and column. If the value is null * or not parseable as a float, the "missing" value is returned. By default, * this is Float.NaN, but can be controlled with setMissingFloat(). + * + * @webref table:method + * @brief Get a float value from the specified row and column + * @param row ID number of the row to reference + * @param column ID number of the column to reference */ public float getFloat(int row, int column) { checkBounds(row, column); @@ -2549,7 +2571,9 @@ public class Table { return PApplet.parseFloat(str, missingFloat); } - + /** + * @param columnName title of the column to reference + */ public float getFloat(int row, String columnName) { return getFloat(row, getColumnIndex(columnName)); } @@ -2560,6 +2584,13 @@ public class Table { } + /** + * @webref table:method + * @brief Store a float value in the specified row and column + * @param row ID number of the target row + * @param column ID number of the target column + * @param value value to assign + */ public void setFloat(int row, int column, float value) { if (columnTypes[column] == STRING) { setString(row, column, String.valueOf(value)); @@ -2574,7 +2605,9 @@ public class Table { } } - + /** + * @param columnName title of the target column + */ public void setFloat(int row, String columnName, float value) { setFloat(row, getColumnIndex(columnName), value); } @@ -2740,27 +2773,31 @@ public class Table { /** * Get a String value from the table. If the row is longer than the table - * @param row - * @param col - * @return the String defined by the row and col variables + * + * @webref table:method + * @brief Get an String value from the specified row and column + * @param row ID number of the row to reference + * @param column ID number of the column to reference */ - public String getString(int row, int col) { - checkBounds(row, col); - if (columnTypes[col] == STRING) { - String[] stringData = (String[]) columns[col]; + public String getString(int row, int column) { + checkBounds(row, column); + if (columnTypes[column] == STRING) { + String[] stringData = (String[]) columns[column]; return stringData[row]; - } else if (columnTypes[col] == CATEGORY) { - int cat = getInt(row, col); + } else if (columnTypes[column] == CATEGORY) { + int cat = getInt(row, column); if (cat == missingCategory) { return missingString; } - return columnCategories[col].key(cat); + return columnCategories[column].key(cat); } else { - return String.valueOf(Array.get(columns[col], row)); + return String.valueOf(Array.get(columns[column], row)); } } - + /** + * @param columnName title of the column to reference + */ public String getString(int row, String columnName) { return getString(row, getColumnIndex(columnName)); } @@ -2771,6 +2808,13 @@ public class Table { } + /** + * @webref table:method + * @brief Store a String value in the specified row and column + * @param row ID number of the target row + * @param column ID number of the target column + * @param value value to assign + */ public void setString(int row, int column, String value) { ensureBounds(row, column); if (columnTypes[column] != STRING) { @@ -2780,7 +2824,9 @@ public class Table { stringData[row] = value; } - + /** + * @param columnName title of the target column + */ public void setString(int row, String columnName, String value) { int column = checkColumnIndex(columnName); setString(row, column, value); @@ -2820,7 +2866,7 @@ public class Table { /** * Return the row that contains the first String that matches. * @param value the String to match - * @param column the column to search + * @param column ID number of the column to search */ public int findRowIndex(String value, int column) { checkColumn(column); @@ -2856,7 +2902,7 @@ public class Table { /** * Return the row that contains the first String that matches. * @param value the String to match - * @param columnName the column to search + * @param columnName title of the column to search */ public int findRowIndex(String value, String columnName) { return findRowIndex(value, getColumnIndex(columnName)); @@ -2867,7 +2913,7 @@ public class Table { * Return a list of rows that contain the String passed in. If there are no * matches, a zero length array will be returned (not a null array). * @param value the String to match - * @param column the column to search + * @param column ID number of the column to search */ public int[] findRowIndices(String value, int column) { int[] outgoing = new int[rowCount]; @@ -2909,7 +2955,7 @@ public class Table { * Return a list of rows that contain the String passed in. If there are no * matches, a zero length array will be returned (not a null array). * @param value the String to match - * @param columnName the column to search + * @param columnName title of the column to search */ public int[] findRowIndices(String value, String columnName) { return findRowIndices(value, getColumnIndex(columnName)); @@ -2960,7 +3006,7 @@ public class Table { /** * Return the row that contains the first String that matches. * @param regexp the String to match - * @param column the column to search + * @param column ID number of the column to search */ public int matchRowIndex(String regexp, int column) { checkColumn(column); @@ -2988,7 +3034,7 @@ public class Table { /** * Return the row that contains the first String that matches. * @param what the String to match - * @param columnName the column to search + * @param columnName title of the column to search */ public int matchRowIndex(String what, String columnName) { return matchRowIndex(what, getColumnIndex(columnName)); @@ -2999,7 +3045,7 @@ public class Table { * Return a list of rows that contain the String passed in. If there are no * matches, a zero length array will be returned (not a null array). * @param what the String to match - * @param column the column to search + * @param column ID number of the column to search */ public int[] matchRowIndices(String regexp, int column) { int[] outgoing = new int[rowCount]; @@ -3031,7 +3077,7 @@ public class Table { * Return a list of rows that match the regex passed in. If there are no * matches, a zero length array will be returned (not a null array). * @param what the String to match - * @param columnName the column to search + * @param columnName title of the column to search */ public int[] matchRowIndices(String what, String columnName) { return matchRowIndices(what, getColumnIndex(columnName)); @@ -3139,7 +3185,7 @@ public class Table { * Run String.replaceAll() on all entries in a column. * Only works with columns that are already String values. * @param what the String to match - * @param columnName the column to search + * @param columnName title of the column to search */ public void replaceAll(String regex, String replacement, String columnName) { replaceAll(regex, replacement, getColumnIndex(columnName)); From f2609bd9d5b55f0174493ccd2f983f36a671b2e6 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 19:44:18 -0700 Subject: [PATCH 24/46] Clarified img.set() param description, re: processing/processing-web#153 --- core/src/processing/core/PApplet.java | 2 +- core/src/processing/core/PImage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 44bed52d9..ca7ba0ae9 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -15250,7 +15250,7 @@ public class PApplet extends Applet * No variations are employed, meaning that any scale, tint, or imageMode * settings will be ignored. * - * @param img image to draw on screen + * @param img image to copy into the original image */ public void set(int x, int y, PImage img) { if (recorder != null) recorder.set(x, y, img); diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index cb21ff505..89c062f97 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -912,7 +912,7 @@ public class PImage implements PConstants, Cloneable { * No variations are employed, meaning that any scale, tint, or imageMode * settings will be ignored. * - * @param img image to draw on screen + * @param img image to copy into the original image */ public void set(int x, int y, PImage img) { int sx = 0; From 53d681b089b212ae49511daecc32ee48ef6aee2e Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 20:20:39 -0700 Subject: [PATCH 25/46] Revising PImage @instanceName for processing/processing-web#153 --- core/src/processing/core/PImage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 89c062f97..5887c9d55 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -55,7 +55,7 @@ import javax.imageio.metadata.*; * * @webref image * @usage Web & Application - * @instanceName img any variable of type PImage + * @instanceName img any object of type PImage * @see PApplet#loadImage(String) * @see PApplet#imageMode(int) * @see PApplet#createImage(int, int, int) From 951978f5490f086ec3e93e95a4da877c084967c5 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 21:02:21 -0700 Subject: [PATCH 26/46] Added reference for Table methods getRowCount(), getColumnCount(), getStringColumn(), trim(), removeTokens() --- core/src/processing/data/Table.java | 49 ++++++++++++++++++----------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index bc770a285..49d83793a 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -1223,7 +1223,7 @@ public class Table { /** * @webref table:method - * @brief Adds a new column to the table + * @brief Adds a new column to a table */ public void addColumn() { addColumn(null, STRING); @@ -1296,7 +1296,7 @@ public class Table { /** * @webref table:method - * @brief Removes a column from the table + * @brief Removes a column from a table * @param columnName the title of the column to be removed */ public void removeColumn(String columnName) { @@ -1339,7 +1339,7 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Gets the number of columns in a table */ public int getColumnCount() { return columns.length; @@ -1666,7 +1666,7 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Gets the number of rows in a table */ public int getRowCount() { return rowCount; @@ -1719,7 +1719,7 @@ public class Table { /** * @webref table:method - * @brief Adds a row to the table + * @brief Adds a row to a table */ public TableRow addRow() { setRowCount(rowCount + 1); @@ -1815,7 +1815,7 @@ public class Table { /** * @webref table:method - * @brief Removes a row from the table + * @brief Removes a row from a table * @param row ID number of the row to remove */ public void removeRow(int row) { @@ -2014,7 +2014,7 @@ public class Table { /** * @webref table:method - * @brief Gets a row from the table + * @brief Gets a row from a table * @param row ID number of the row to get */ public TableRow getRow(int row) { @@ -2028,7 +2028,7 @@ public class Table { * If you want to iterate in a multi-threaded manner, don't use the iterator. * * @webref table:method - * @brief Gets multiple rows from the table + * @brief Gets multiple rows from a table */ public Iterable rows() { return new Iterable() { @@ -2834,18 +2834,22 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Gets all values in the specified column + * @param columnName title of the column to search */ - public String[] getStringColumn(String name) { - int col = getColumnIndex(name); + public String[] getStringColumn(String columnName) { + int col = getColumnIndex(columnName); return (col == -1) ? null : getStringColumn(col); } - public String[] getStringColumn(int col) { + /** + * @param column ID number of the column to search + */ + public String[] getStringColumn(int column) { String[] outgoing = new String[rowCount]; for (int i = 0; i < rowCount; i++) { - outgoing[i] = getString(i, col); + outgoing[i] = getString(i, column); } return outgoing; } @@ -3199,7 +3203,8 @@ public class Table { * Remove any of the specified characters from the entire table. * * @webref table:method - * @brief Remove characters from the entire table + * @brief Removes characters from the table + * @param tokens a list of individual characters to be removed */ public void removeTokens(String tokens) { for (int col = 0; col < getColumnCount(); col++) { @@ -3214,6 +3219,8 @@ public class Table { *
    * table.removeTokens(",$", 2);
    * 
+ * + * @param column ID number of the column to process */ public void removeTokens(String tokens, int column) { for (int row = 0; row < rowCount; row++) { @@ -3236,7 +3243,9 @@ public class Table { } } - + /** + * @param columnName title of the column to process + */ public void removeTokens(String tokens, String columnName) { removeTokens(tokens, getColumnIndex(columnName)); } @@ -3246,7 +3255,7 @@ public class Table { /** * @webref table:method - * @brief To come... + * @brief Trims whitespace from values */ public void trim() { for (int col = 0; col < getColumnCount(); col++) { @@ -3254,7 +3263,9 @@ public class Table { } } - + /** + * @param column ID number of the column to trim + */ public void trim(int column) { if (columnTypes[column] == STRING) { String[] stringData = (String[]) columns[column]; @@ -3266,7 +3277,9 @@ public class Table { } } - + /** + * @param columnName title of the column to trim + */ public void trim(String columnName) { trim(getColumnIndex(columnName)); } From 7b60e43550f468849637f6487f62eae2efcdb44a Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 25 May 2013 21:14:42 -0700 Subject: [PATCH 27/46] Adding a couple related reference links for Table methods --- core/src/processing/data/Table.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 49d83793a..6d2d11190 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -54,9 +54,9 @@ import processing.core.PConstants; *

A rough "spec" for CSV can be found here.

* * @webref data:composite - * @see PApplet#createTable() * @see PApplet#loadTable(String) * @see PApplet#saveTable(Table, String) + * @see TableRow */ public class Table { protected int rowCount; @@ -1224,6 +1224,7 @@ public class Table { /** * @webref table:method * @brief Adds a new column to a table + * @see Table#removeColumn(String) */ public void addColumn() { addColumn(null, STRING); @@ -1298,6 +1299,7 @@ public class Table { * @webref table:method * @brief Removes a column from a table * @param columnName the title of the column to be removed + * @see Table#addColumn() */ public void removeColumn(String columnName) { removeColumn(getColumnIndex(columnName)); From b7abfe844707f1d45a26f3ea86aeaa7d8201b42e Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sun, 26 May 2013 15:26:35 -0700 Subject: [PATCH 28/46] Added reference for TableRow plus methods getInt(), getFloat(), getString(), setInt(), setFloat(), setString() --- core/src/processing/data/TableRow.java | 75 +++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/core/src/processing/data/TableRow.java b/core/src/processing/data/TableRow.java index d5b65cee3..949af30f6 100644 --- a/core/src/processing/data/TableRow.java +++ b/core/src/processing/data/TableRow.java @@ -2,21 +2,45 @@ package processing.data; /** * @webref data:composite + * @see Table + * @see Table#addRow() + * @see Table#removeRow(int) + * @see Table#clearRows() + * @see Table#getRow(int) + * @see Table#rows() */ public interface TableRow { /** * @webref tablerow:method - * @brief Get the String value from a column + * @brief Get an String value from the specified column + * @param column ID number of the column to reference + * @see TableRow#getInt(int) + * @see TableRow#getFloat(int) + * @see Table#getInt(int, int) + * @see Table#getFloat(int, int) + * @see Table#getString(int, int) */ public String getString(int column); + /** + * @param columnName title of the column to reference + */ public String getString(String columnName); /** * @webref tablerow:method - * @brief Get the int value from a column + * @brief Get an integer value from the specified column + * @param column ID number of the column to reference + * @see TableRow#getFloat(int) + * @see TableRow#getString(int) + * @see Table#getInt(int, int) + * @see Table#getFloat(int, int) + * @see Table#getString(int, int) */ public int getInt(int column); + /** + * @param columnName title of the column to reference + */ public int getInt(String columnName); public long getLong(int column); @@ -24,9 +48,18 @@ public interface TableRow { /** * @webref tablerow:method - * @brief Get the float value from a column + * @brief Get a float value from the specified column + * @param column ID number of the column to reference + * @see TableRow#getInt(int) + * @see TableRow#getString(int) + * @see Table#getInt(int, int) + * @see Table#getFloat(int, int) + * @see Table#getString(int, int) */ public float getFloat(int column); + /** + * @param columnName title of the column to reference + */ public float getFloat(String columnName); public double getDouble(int column); @@ -34,16 +67,36 @@ public interface TableRow { /** * @webref tablerow:method - * @brief Set the String value in a column + * @brief Store a String value in the specified column + * @param column ID number of the target column + * @param value value to assign + * @see TableRow#setInt(int, int) + * @see TableRow#setFloat(int, float) + * @see Table#setInt(int, int, int) + * @see Table#setFloat(int, int, float) + * @see Table#setString(int, int, String) */ public void setString(int column, String value); + /** + * @param columnName title of the target column + */ public void setString(String columnName, String value); /** * @webref tablerow:method - * @brief Set the int value in a column + * @brief Store an integer value in the specified column + * @param column ID number of the target column + * @param value value to assign + * @see TableRow#setFloat(int, float) + * @see TableRow#setString(int, String) + * @see Table#setInt(int, int, int) + * @see Table#setFloat(int, int, float) + * @see Table#setString(int, int, String) */ public void setInt(int column, int value); + /** + * @param columnName title of the target column + */ public void setInt(String columnName, int value); public void setLong(int column, long value); @@ -51,9 +104,19 @@ public interface TableRow { /** * @webref tablerow:method - * @brief Set the float value in a column + * @brief Store a float value in the specified column + * @param column ID number of the target column + * @param value value to assign + * @see TableRow#setInt(int, int) + * @see TableRow#setString(int, String) + * @see Table#setInt(int, int, int) + * @see Table#setFloat(int, int, float) + * @see Table#setString(int, int, String) */ public void setFloat(int column, float value); + /** + * @param columnName title of the target column + */ public void setFloat(String columnName, float value); public void setDouble(int column, double value); From 1600657e02229e07b667b8b0dbb2a2e859f9606e Mon Sep 17 00:00:00 2001 From: REAS Date: Sun, 26 May 2013 23:41:55 -0700 Subject: [PATCH 29/46] Updates to Int/Float/StringDict for reference --- core/src/processing/data/FloatDict.java | 20 ++++++++++---------- core/src/processing/data/IntDict.java | 2 +- core/src/processing/data/StringDict.java | 24 ++++++++++++------------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/src/processing/data/FloatDict.java b/core/src/processing/data/FloatDict.java index 102493802..777ebc52c 100644 --- a/core/src/processing/data/FloatDict.java +++ b/core/src/processing/data/FloatDict.java @@ -79,7 +79,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Returns the number of key/value pairs */ public int size() { return count; @@ -122,7 +122,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Return the internal array being used to store the keys */ public Iterable keys() { return new Iterable() { @@ -210,7 +210,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Return the internal array being used to store the values */ public Iterable values() { return new Iterable() { @@ -277,9 +277,9 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Create a new key/value pair or change the value of one */ - public void set(String key, int amount) { + public void set(String key, float amount) { int index = index(key); if (index == -1) { create(key, amount); @@ -291,7 +291,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Check if a key is a part of the data structure */ public boolean hasKey(String key) { return index(key) != -1; @@ -392,7 +392,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Remove a key/value pair */ public void remove(String key) { removeIndex(index(key)); @@ -463,7 +463,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Sort the keys alphabetially in reverse */ public void sortKeysReverse() { sortImpl(true, true); @@ -484,7 +484,7 @@ public class FloatDict { * Sort by values in descending order (largest value will be at [0]). * * @webref floatdict:method - * @brief Sort by values in descending order + * @brief Sort by values in ascending order */ public void sortValues() { sortImpl(false, false); @@ -499,7 +499,7 @@ public class FloatDict { /** * @webref floatdict:method - * @brief To come... + * @brief Sort by values in descending order */ public void sortValuesReverse() { sortImpl(false, true); diff --git a/core/src/processing/data/IntDict.java b/core/src/processing/data/IntDict.java index 22e52c600..ae6e06dcd 100644 --- a/core/src/processing/data/IntDict.java +++ b/core/src/processing/data/IntDict.java @@ -201,7 +201,7 @@ public class IntDict { /** * @webref intdict:method - * @brief To come... + * @brief Return the internal array being used to store the keys */ public Iterable values() { return new Iterable() { diff --git a/core/src/processing/data/StringDict.java b/core/src/processing/data/StringDict.java index 7a32db9fe..ad8342b6e 100644 --- a/core/src/processing/data/StringDict.java +++ b/core/src/processing/data/StringDict.java @@ -77,7 +77,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Returns the number of key/value pairs */ public int size() { return count; @@ -120,7 +120,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Return the internal array being used to store the keys */ public Iterable keys() { return new Iterable() { @@ -173,7 +173,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Return the internal array being used to store the values */ public Iterable values() { return new Iterable() { @@ -206,7 +206,7 @@ public class StringDict { * @webref stringdict:method * @brief Create a new array and copy each of the values into it */ - public int[] valueArray() { + public String[] valueArray() { return valueArray(null); } @@ -216,9 +216,9 @@ public class StringDict { * creating a new array each time). If 'array' is null, or not the same * size as the number of values, a new array will be allocated and returned. */ - public int[] valueArray(int[] array) { + public String[] valueArray(String[] array) { if (array == null || array.length != size()) { - array = new int[count]; + array = new String[count]; } System.arraycopy(values, 0, array, 0, count); return array; @@ -239,7 +239,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Create a new key/value pair or change the value of one */ public void set(String key, String amount) { int index = index(key); @@ -258,7 +258,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Check if a key is a part of the data structure */ public boolean hasKey(String key) { return index(key) != -1; @@ -278,7 +278,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Remove a key/value pair */ public void remove(String key) { removeIndex(index(key)); @@ -325,7 +325,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Sort the keys alphabetially in reverse */ public void sortKeysReverse() { sortImpl(true, true); @@ -336,7 +336,7 @@ public class StringDict { * Sort by values in descending order (largest value will be at [0]). * * @webref stringdict:method - * @brief Sort by values in descending order + * @brief Sort by values in ascending order */ public void sortValues() { sortImpl(false, false); @@ -345,7 +345,7 @@ public class StringDict { /** * @webref stringdict:method - * @brief To come... + * @brief Sort by values in descending order */ public void sortValuesReverse() { sortImpl(false, true); From 62d7076a595bd32822b45dc84eda2cb35dfa57c3 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 13:01:29 -0400 Subject: [PATCH 30/46] Fixing several problems with the handling of offsecreen surfaces --- core/src/processing/opengl/FrameBuffer.java | 1 - core/src/processing/opengl/MaskFrag.glsl | 5 + core/src/processing/opengl/PGL.java | 69 ++++---- .../processing/opengl/PGraphicsOpenGL.java | 162 ++++++++++++------ core/src/processing/opengl/PShader.java | 35 ---- core/src/processing/opengl/Texture.java | 31 ++-- 6 files changed, 167 insertions(+), 136 deletions(-) diff --git a/core/src/processing/opengl/FrameBuffer.java b/core/src/processing/opengl/FrameBuffer.java index a063bc87e..8821861c9 100644 --- a/core/src/processing/opengl/FrameBuffer.java +++ b/core/src/processing/opengl/FrameBuffer.java @@ -149,7 +149,6 @@ public class FrameBuffer implements PConstants { @Override protected void finalize() throws Throwable { try { -// PApplet.println("finalize FBO"); if (!screenFb) { if (glFbo != 0) { PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context); diff --git a/core/src/processing/opengl/MaskFrag.glsl b/core/src/processing/opengl/MaskFrag.glsl index 07e590009..508a39649 100644 --- a/core/src/processing/opengl/MaskFrag.glsl +++ b/core/src/processing/opengl/MaskFrag.glsl @@ -18,6 +18,11 @@ Boston, MA 02111-1307 USA */ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + #define PROCESSING_TEXTURE_SHADER uniform sampler2D texture; diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index ba513c90b..8232ed88e 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -965,7 +965,8 @@ public class PGL { // Render previous back texture (now is the front) as background, // because no background() is being used ("incremental drawing") drawTexture(TEXTURE_2D, glColorTex.get(frontTex), - fboWidth, fboHeight, 0, 0, pg.width, pg.height, + fboWidth, fboHeight, pg.width, pg.height, + 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); } @@ -997,6 +998,7 @@ public class PGL { gl.glDisable(GL.GL_BLEND); drawTexture(GL.GL_TEXTURE_2D, backTexAttach.getName(), backTexAttach.getWidth(), backTexAttach.getHeight(), + pg.width, pg.height, 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); backFBO.bind(gl); } @@ -1014,7 +1016,8 @@ public class PGL { // Render current back texture to screen, without blending. disable(BLEND); drawTexture(TEXTURE_2D, glColorTex.get(backTex), - fboWidth, fboHeight, 0, 0, pg.width, pg.height, + fboWidth, fboHeight, pg.width, pg.height, + 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); // Swapping front and back textures. @@ -1329,26 +1332,28 @@ public class PGL { protected void drawTexture(int target, int id, int width, int height, int X0, int Y0, int X1, int Y1) { - drawTexture(target, id, width, height, X0, Y0, X1, Y1, X0, Y0, X1, Y1); + drawTexture(target, id, width, height, width, height, + X0, Y0, X1, Y1, X0, Y0, X1, Y1); } - protected void drawTexture(int target, int id, int width, int height, + protected void drawTexture(int target, int id, + int texW, int texH, int scrW, int scrH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { if (target == TEXTURE_2D) { - drawTexture2D(id, width, height, + drawTexture2D(id, texW, texH, scrW, scrH, texX0, texY0, texX1, texY1, scrX0, scrY0, scrX1, scrY1); } else if (target == TEXTURE_RECTANGLE) { - drawTextureRect(id, width, height, + drawTextureRect(id, texW, texH, scrW, scrH, texX0, texY0, texX1, texY1, scrX0, scrY0, scrX1, scrY1); } } - protected void drawTexture2D(int id, int width, int height, + protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { if (!loadedTex2DShader || @@ -1390,25 +1395,25 @@ public class PGL { // Vertex coordinates of the textured quad are specified // in normalized screen space (-1, 1): // Corner 1 - texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1; - texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1; - texCoords[ 2] = (float)texX0 / width; - texCoords[ 3] = (float)texY0 / height; + texCoords[ 0] = 2 * (float)scrX0 / scrW - 1; + texCoords[ 1] = 2 * (float)scrY0 / scrH - 1; + texCoords[ 2] = (float)texX0 / texW; + texCoords[ 3] = (float)texY0 / texH; // Corner 2 - texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1; - texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1; - texCoords[ 6] = (float)texX1 / width; - texCoords[ 7] = (float)texY0 / height; + texCoords[ 4] = 2 * (float)scrX1 / scrW - 1; + texCoords[ 5] = 2 * (float)scrY0 / scrH - 1; + texCoords[ 6] = (float)texX1 / texW; + texCoords[ 7] = (float)texY0 / texH; // Corner 3 - texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1; - texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1; - texCoords[10] = (float)texX0 / width; - texCoords[11] = (float)texY1 / height; + texCoords[ 8] = 2 * (float)scrX0 / scrW - 1; + texCoords[ 9] = 2 * (float)scrY1 / scrH - 1; + texCoords[10] = (float)texX0 / texW; + texCoords[11] = (float)texY1 / texH; // Corner 4 - texCoords[12] = 2 * (float)scrX1 / pg.width - 1; - texCoords[13] = 2 * (float)scrY1 / pg.height - 1; - texCoords[14] = (float)texX1 / width; - texCoords[15] = (float)texY1 / height; + texCoords[12] = 2 * (float)scrX1 / scrW - 1; + texCoords[13] = 2 * (float)scrY1 / scrH - 1; + texCoords[14] = (float)texX1 / texW; + texCoords[15] = (float)texY1 / texH; texData.rewind(); texData.put(texCoords); @@ -1452,7 +1457,7 @@ public class PGL { } - protected void drawTextureRect(int id, int width, int height, + protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { if (!loadedTexRectShader || @@ -1495,23 +1500,23 @@ public class PGL { // Vertex coordinates of the textured quad are specified // in normalized screen space (-1, 1): // Corner 1 - texCoords[ 0] = 2 * (float)scrX0 / pg.width - 1; - texCoords[ 1] = 2 * (float)scrY0 / pg.height - 1; + texCoords[ 0] = 2 * (float)scrX0 / scrW - 1; + texCoords[ 1] = 2 * (float)scrY0 / scrH - 1; texCoords[ 2] = texX0; texCoords[ 3] = texY0; // Corner 2 - texCoords[ 4] = 2 * (float)scrX1 / pg.width - 1; - texCoords[ 5] = 2 * (float)scrY0 / pg.height - 1; + texCoords[ 4] = 2 * (float)scrX1 / scrW - 1; + texCoords[ 5] = 2 * (float)scrY0 / scrH - 1; texCoords[ 6] = texX1; texCoords[ 7] = texY0; // Corner 3 - texCoords[ 8] = 2 * (float)scrX0 / pg.width - 1; - texCoords[ 9] = 2 * (float)scrY1 / pg.height - 1; + texCoords[ 8] = 2 * (float)scrX0 / scrW - 1; + texCoords[ 9] = 2 * (float)scrY1 / scrH - 1; texCoords[10] = texX0; texCoords[11] = texY1; // Corner 4 - texCoords[12] = 2 * (float)scrX1 / pg.width - 1; - texCoords[13] = 2 * (float)scrY1 / pg.height - 1; + texCoords[12] = 2 * (float)scrX1 / scrW - 1; + texCoords[13] = 2 * (float)scrY1 / scrH - 1; texCoords[14] = texX1; texCoords[15] = texY1; diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a8a2aa2dc..0c96a37c2 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -667,8 +667,6 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void finalize() throws Throwable { try { -// PApplet.println("finalize surface"); - deletePolyBuffers(); deleteLineBuffers(); deletePointBuffers(); @@ -797,7 +795,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glTextureObjects.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining"); } protected static void removeTextureObject(int id, int context) { @@ -862,7 +859,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glVertexBuffers.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining"); } protected static void removeVertexBufferObject(int id, int context) { @@ -929,7 +925,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glFrameBuffers.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining"); } protected static void removeFrameBufferObject(int id, int context) { @@ -994,7 +989,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glRenderBuffers.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining"); } protected static void removeRenderBufferObject(int id, int context) { @@ -1055,7 +1049,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslPrograms.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining"); } protected static void removeGLSLProgramObject(int id, int context) { @@ -1117,7 +1110,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslVertexShaders.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining"); } protected static void removeGLSLVertShaderObject(int id, int context) { @@ -1179,7 +1171,6 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslFragmentShaders.remove(res); } -// PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining"); } protected static void removeGLSLFragShaderObject(int id, int context) { @@ -1637,6 +1628,12 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { beginOnscreenDraw(); } else { + if (pgPrimary.texCache.containsTexture(this)) { + // This offscreen surface is being used as a texture earlier in draw, + // so we should update the rendering up to this point since it will + // modified. + pgPrimary.flush(); + } beginOffscreenDraw(); } setDefaults(); @@ -1644,9 +1641,15 @@ public class PGraphicsOpenGL extends PGraphics { pgCurrent = this; drawing = true; + clearCalled = false; + clearColorBuffer0 = clearColorBuffer; + clearColorBuffer = false; + report("bot beginDraw()"); } + boolean clearCalled; + boolean clearEveryFrame; @Override public void endDraw() { @@ -1657,6 +1660,10 @@ public class PGraphicsOpenGL extends PGraphics { return; } + if (!clearCalled && 0 < parent.frameCount) { + clearEveryFrame = false; + } + // Flushing any remaining geometry. flush(); @@ -1945,6 +1952,7 @@ public class PGraphicsOpenGL extends PGraphics { manipulatingCamera = false; clearColorBuffer = false; + clearEveryFrame = true; // easiest for beginners textureMode(IMAGE); @@ -4899,6 +4907,7 @@ public class PGraphicsOpenGL extends PGraphics { if (0 < parent.frameCount) { clearColorBuffer = true; } + clearCalled = true; } @@ -4920,6 +4929,7 @@ public class PGraphicsOpenGL extends PGraphics { if (0 < parent.frameCount) { clearColorBuffer = true; } + clearCalled = true; } @@ -5278,11 +5288,11 @@ public class PGraphicsOpenGL extends PGraphics { } - public void drawTexture(int target, int id, int width, int height, + public void drawTexture(int target, int id, int texW, int texH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { beginPGL(); - pgl.drawTexture(target, id, width, height, + pgl.drawTexture(target, id, texW, texH, width, height, texX0, texY0, texX1, texY1, scrX0, scrY0, scrX1, scrY1); endPGL(); @@ -5300,20 +5310,27 @@ public class PGraphicsOpenGL extends PGraphics { pgPrimary.setCache(this, texture); if (!primarySurface) { - ptexture = new Texture(width, height, params); - ptexture.invertedY(true); - ptexture.colorBuffer(true); + createPTexture(); } } } + protected void createPTexture() { + ptexture = new Texture(width, height, texture.getParameters()); + ptexture.invertedY(true); + ptexture.colorBuffer(true); + } + + protected void swapTextures() { - int temp = texture.glName; - texture.glName = ptexture.glName; - ptexture.glName = temp; - if (!primarySurface) { - offscreenFramebuffer.setColorBuffer(texture); + if (ptexture != null) { + int temp = texture.glName; + texture.glName = ptexture.glName; + ptexture.glName = temp; + if (!primarySurface) { + offscreenFramebuffer.setColorBuffer(texture); + } } } @@ -5334,13 +5351,40 @@ public class PGraphicsOpenGL extends PGraphics { // invert the y coordinates of the screen rectangle. pgl.disable(PGL.BLEND); pgl.drawTexture(texture.glTarget, texture.glName, - texture.glWidth, texture.glHeight, + texture.glWidth, texture.glHeight, width, height, x, y, x + w, y + h, x, height - (y + h), x + w, height - y); pgl.enable(PGL.BLEND); } + protected void drawPTexture() { + if (ptexture != null) { + // No blend so the texure replaces wherever is on the screen, + // irrespective of the alpha + pgl.disable(PGL.BLEND); + pgl.drawTexture(ptexture.glTarget, ptexture.glName, + ptexture.glWidth, ptexture.glHeight, + 0, 0, width, height); + pgl.enable(PGL.BLEND); + } + } + + + protected void drawPTexture(int x, int y, int w, int h) { + if (ptexture != null) { + // Processing Y axis is inverted with respect to OpenGL, so we need to + // invert the y coordinates of the screen rectangle. + pgl.disable(PGL.BLEND); + pgl.drawTexture(ptexture.glTarget, ptexture.glName, + ptexture.glWidth, ptexture.glHeight, width, height, + x, y, x + w, y + h, + x, height - (y + h), x + w, height - y); + pgl.enable(PGL.BLEND); + } + } + + ////////////////////////////////////////////////////////////// // MASK @@ -5409,8 +5453,14 @@ public class PGraphicsOpenGL extends PGraphics { return; } - pgl.needFBOLayer(); + boolean needEndDraw = false; + if (primarySurface) pgl.needFBOLayer(); + else if (!drawing) { + beginDraw(); + needEndDraw = true; + } loadTexture(); + if (filterTexture == null || filterTexture.contextIsOutdated()) { filterTexture = new Texture(texture.width, texture.height, texture.getParameters()); @@ -5418,6 +5468,7 @@ public class PGraphicsOpenGL extends PGraphics { filterImage = wrapTexture(filterTexture); } filterTexture.set(texture); +// filterTexture.set(ptexture); // Disable writing to the depth buffer, so that after applying the filter we // can still use the depth information to keep adding geometry to the scene. @@ -5438,10 +5489,11 @@ public class PGraphicsOpenGL extends PGraphics { textureMode = NORMAL; boolean prevStroke = stroke; stroke = false; -// int prevBlendMode = blendMode; -// blendMode(REPLACE); + int prevBlendMode = blendMode; + blendMode(REPLACE); TextureShader prevTexShader = textureShader; textureShader = (TextureShader) shader; + beginShape(QUADS); texture(filterImage); vertex(0, 0, 0, 0); @@ -5451,13 +5503,12 @@ public class PGraphicsOpenGL extends PGraphics { endShape(); end2D(); - textureShader = prevTexShader; - // Restoring previous configuration. + textureShader = prevTexShader; stroke = prevStroke; lights = prevLights; textureMode = prevTextureMode; -// blendMode(prevBlendMode); + blendMode(prevBlendMode); if (!hints[DISABLE_DEPTH_TEST]) { pgl.enable(PGL.DEPTH_TEST); @@ -5465,6 +5516,10 @@ public class PGraphicsOpenGL extends PGraphics { if (!hints[DISABLE_DEPTH_MASK]) { pgl.depthMask(true); } + + if (needEndDraw) { + endDraw(); + } } @@ -5696,6 +5751,7 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.bindFrontTexture(); } else { + if (ptexture == null) createPTexture(); ptexture.bind(); } } @@ -5952,9 +6008,17 @@ public class PGraphicsOpenGL extends PGraphics { protected void beginOffscreenDraw() { updateOffscreen(); - - // Just in case the texture was recreated (in a resize event for example) - offscreenFramebuffer.setColorBuffer(texture); + /* + if (!clearColorBuffer) { + // Render previous back texture (now is the front) as background, + // because no background() is being used ("incremental drawing") + drawPTexture(); + } + if (!clearEveryFrame) { + drawPTexture(); + } + */ + drawPTexture(); // Restoring the clipping configuration of the offscreen surface. if (clip) { @@ -5971,22 +6035,6 @@ public class PGraphicsOpenGL extends PGraphics { multisampleFramebuffer.copy(offscreenFramebuffer, currentFramebuffer); } - if (!clearColorBuffer0) { - // Draw the back texture into the front texture, which will be used as - // front texture in the next frame. Otherwise flickering will occur if - // the sketch uses "incremental drawing" (background() not called). - if (offscreenMultisample) { - pushFramebuffer(); - setFramebuffer(offscreenFramebuffer); - } - offscreenFramebuffer.setColorBuffer(ptexture); - drawTexture(); - offscreenFramebuffer.setColorBuffer(texture); - if (offscreenMultisample) { - popFramebuffer(); - } - } - popFramebuffer(); texture.updateTexels(); // Mark all texels in screen texture as modified. @@ -6109,9 +6157,6 @@ public class PGraphicsOpenGL extends PGraphics { modified = false; setgetPixels = false; - - clearColorBuffer0 = clearColorBuffer; - clearColorBuffer = false; } @@ -6879,6 +6924,11 @@ public class PGraphicsOpenGL extends PGraphics { setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset); } + @Override + public int getLastTexUnit() { + return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); + } + @Override public void setTexture(Texture tex) { float scaleu = 1; @@ -6915,7 +6965,7 @@ public class PGraphicsOpenGL extends PGraphics { setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); if (-1 < textureLoc) { - texUnit = bufferUnit + 1; + texUnit = getLastTexUnit() + 1; setUniformValue(textureLoc, texUnit); pgl.activeTexture(PGL.TEXTURE0 + texUnit); tex.bind(); @@ -6999,6 +7049,11 @@ public class PGraphicsOpenGL extends PGraphics { setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset); } + @Override + public int getLastTexUnit() { + return -1 < bufferUnit ? bufferUnit : super.getLastTexUnit(); + } + @Override public void setTexture(Texture tex) { float scaleu = 1; @@ -7035,7 +7090,7 @@ public class PGraphicsOpenGL extends PGraphics { setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); if (-1 < textureLoc) { - texUnit = bufferUnit + 1; + texUnit = getLastTexUnit() + 1; setUniformValue(textureLoc, texUnit); pgl.activeTexture(PGL.TEXTURE0 + texUnit); tex.bind(); @@ -7313,6 +7368,13 @@ public class PGraphicsOpenGL extends PGraphics { hasTextures = false; } + boolean containsTexture(PImage img) { + for (int i = 0; i < size; i++) { + if (textures[i] == img) return true; + } + return false; + } + PImage getTextureImage(int i) { return textures[i]; } diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index 81e561123..03eca7517 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -84,7 +84,6 @@ public class PShader { protected IntBuffer intBuffer; protected FloatBuffer floatBuffer; - public PShader() { parent = null; pgMain = null; @@ -100,8 +99,6 @@ public class PShader { glVertex = 0; glFragment = 0; -// firstTexUnit = 0; - intBuffer = PGL.allocateIntBuffer(1); floatBuffer = PGL.allocateFloatBuffer(1); @@ -927,36 +924,4 @@ public class PShader { this.value = value; } } - - /* - // The individual attribute setters are not really needed, read this: - // http://stackoverflow.com/questions/7718976/what-is-glvertexattrib-versus-glvertexattribpointer-used-for - // except for setting a constant vertex attribute value. - public void set1FloatAttribute(int loc, float x) { - if (-1 < loc) { - pgl.glVertexAttrib1f(loc, x); - } - } - - - public void set2FloatAttribute(int loc, float x, float y) { - if (-1 < loc) { - pgl.glVertexAttrib2f(loc, x, y); - } - } - - - public void set3FloatAttribute(int loc, float x, float y, float z) { - if (-1 < loc) { - pgl.glVertexAttrib3f(loc, x, y, z); - } - } - - - public void set4FloatAttribute(int loc, float x, float y, float z, float w) { - if (-1 < loc) { - pgl.glVertexAttrib4f(loc, x, y, z, w); - } - } - */ } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index e59c22a19..4a1ba290e 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -80,7 +80,7 @@ public class Texture implements PConstants { protected PGL pgl; // The interface between Processing and OpenGL. protected int context; // The context that created this texture. - protected boolean colorBuffer; // true if it is the color attachment of + protected boolean colorBuffer; // true if it is the color attachment of // FrameBuffer object. protected boolean usingMipmaps; @@ -270,18 +270,6 @@ public class Texture implements PConstants { // Set methods -// public void set(PImage tex) { -// Texture tex = (Texture)pg.getCache(img); -// set(tex); -// } - - -// public void set(PImage img, int x, int y, int w, int h) { -// Texture tex = (Texture)pg.getCache(img); -// set(tex, x, y, w, h); -// } - - public void set(Texture tex) { copyTexture(tex, 0, 0, tex.width, tex.height, true); } @@ -851,6 +839,7 @@ public class Texture implements PConstants { pixelBuffer = PGL.updateIntBuffer(pixelBuffer, pixels, true); } + //////////////////////////////////////////////////////////// // Buffer sink interface. @@ -1135,7 +1124,6 @@ public class Texture implements PConstants { } - /////////////////////////////////////////////////////////// // Allocate/release texture. @@ -1281,18 +1269,21 @@ public class Texture implements PConstants { if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. - pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, + tex.glWidth, tex.glHeight, tempFbo.width, tempFbo.height, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. - pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, + tex.glWidth, tex.glHeight, tempFbo.width, tempFbo.height, x, y, w, h, x, y, w, h); } PGraphicsOpenGL.popFramebuffer(); updateTexels(x, y, w, h); + PApplet.println(width + " " + height + " " + tempFbo.width + " " + tempFbo.height); } @@ -1314,18 +1305,22 @@ public class Texture implements PConstants { if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. - pgl.drawTexture(texTarget, texName, texWidth, texHeight, + pgl.drawTexture(texTarget, texName, + texWidth, texHeight, tempFbo.width, tempFbo.height, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. - pgl.drawTexture(texTarget, texName, texWidth, texHeight, + pgl.drawTexture(texTarget, texName, + texWidth, texHeight, tempFbo.width, tempFbo.height, x, y, w, h, x, y, w, h); } PGraphicsOpenGL.popFramebuffer(); updateTexels(x, y, w, h); + + PApplet.println(width + " " + height + " " + tempFbo.width + " " + tempFbo.height); } From 6c4218a9bf0251a87d56899b70b6d04d84e64198 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 14:57:59 -0400 Subject: [PATCH 31/46] setting viewport before anything else in beginDraw() --- .../processing/opengl/PGraphicsOpenGL.java | 63 +++++++------------ core/src/processing/opengl/Texture.java | 3 - 2 files changed, 22 insertions(+), 44 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 0c96a37c2..8d6639e14 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -552,13 +552,6 @@ public class PGraphicsOpenGL extends PGraphics { } - // now implemented in PGraphics -// public void setParent(PApplet parent) { -// super.setParent(parent); -// quality = parent.sketchQuality(); -// } - - @Override public void setPrimary(boolean primary) { super.setPrimary(primary); @@ -1621,22 +1614,24 @@ public class PGraphicsOpenGL extends PGraphics { return; } + if (!primarySurface && pgPrimary.texCache.containsTexture(this)) { + // This offscreen surface is being used as a texture earlier in draw, + // so we should update the rendering up to this point since it will + // modified. + pgPrimary.flush(); + } + if (!glParamsRead) { getGLParameters(); } + setViewport(); if (primarySurface) { beginOnscreenDraw(); } else { - if (pgPrimary.texCache.containsTexture(this)) { - // This offscreen surface is being used as a texture earlier in draw, - // so we should update the rendering up to this point since it will - // modified. - pgPrimary.flush(); - } beginOffscreenDraw(); } - setDefaults(); + setDrawDefaults(); pgCurrent = this; drawing = true; @@ -5323,14 +5318,12 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void swapTextures() { + protected void swapOffscreenTextures() { if (ptexture != null) { int temp = texture.glName; texture.glName = ptexture.glName; ptexture.glName = temp; - if (!primarySurface) { - offscreenFramebuffer.setColorBuffer(texture); - } + offscreenFramebuffer.setColorBuffer(texture); } } @@ -5371,20 +5364,6 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void drawPTexture(int x, int y, int w, int h) { - if (ptexture != null) { - // Processing Y axis is inverted with respect to OpenGL, so we need to - // invert the y coordinates of the screen rectangle. - pgl.disable(PGL.BLEND); - pgl.drawTexture(ptexture.glTarget, ptexture.glName, - ptexture.glWidth, ptexture.glHeight, width, height, - x, y, x + w, y + h, - x, height - (y + h), x + w, height - y); - pgl.enable(PGL.BLEND); - } - } - - ////////////////////////////////////////////////////////////// // MASK @@ -5468,7 +5447,6 @@ public class PGraphicsOpenGL extends PGraphics { filterImage = wrapTexture(filterTexture); } filterTexture.set(texture); -// filterTexture.set(ptexture); // Disable writing to the depth buffer, so that after applying the filter we // can still use the depth information to keep adding geometry to the scene. @@ -5993,7 +5971,7 @@ public class PGraphicsOpenGL extends PGraphics { // The back texture of the past frame becomes the front, // and the front texture becomes the new back texture where the // new frame is drawn to. - swapTextures(); + swapOffscreenTextures(); } } @@ -6019,6 +5997,7 @@ public class PGraphicsOpenGL extends PGraphics { } */ drawPTexture(); + //texture.set(ptexture); // Restoring the clipping configuration of the offscreen surface. if (clip) { @@ -6042,7 +6021,15 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void setDefaults() { + protected void setViewport() { + viewport.put(0, 0); viewport.put(1, 0); + viewport.put(2, width); viewport.put(3, height); + pgl.viewport(viewport.get(0), viewport.get(1), + viewport.get(2), viewport.get(3)); + } + + + protected void setDrawDefaults() { inGeo.clear(); tessGeo.clear(); texCache.clear(); @@ -6087,12 +6074,6 @@ public class PGraphicsOpenGL extends PGraphics { pgl.disable(PGL.LINE_SMOOTH); pgl.disable(PGL.POLYGON_SMOOTH); - // setup opengl viewport. - viewport.put(0, 0); viewport.put(1, 0); - viewport.put(2, width); viewport.put(3, height); - pgl.viewport(viewport.get(0), viewport.get(1), - viewport.get(2), viewport.get(3)); - if (sized) { // To avoid having garbage in the screen after a resize, // in the case background is not called in draw(). diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 4a1ba290e..005686fb0 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -1283,7 +1283,6 @@ public class Texture implements PConstants { } PGraphicsOpenGL.popFramebuffer(); updateTexels(x, y, w, h); - PApplet.println(width + " " + height + " " + tempFbo.width + " " + tempFbo.height); } @@ -1319,8 +1318,6 @@ public class Texture implements PConstants { } PGraphicsOpenGL.popFramebuffer(); updateTexels(x, y, w, h); - - PApplet.println(width + " " + height + " " + tempFbo.width + " " + tempFbo.height); } From 1aea167374aedd4af1e49851f05ad8c66459a55b Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 15:22:08 -0400 Subject: [PATCH 32/46] Don't create ptexture unless is needed by a shader to read the previous frame. --- .../processing/opengl/PGraphicsOpenGL.java | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8d6639e14..a33c7177b 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -1636,15 +1636,9 @@ public class PGraphicsOpenGL extends PGraphics { pgCurrent = this; drawing = true; - clearCalled = false; - clearColorBuffer0 = clearColorBuffer; - clearColorBuffer = false; - report("bot beginDraw()"); } - boolean clearCalled; - boolean clearEveryFrame; @Override public void endDraw() { @@ -1655,10 +1649,6 @@ public class PGraphicsOpenGL extends PGraphics { return; } - if (!clearCalled && 0 < parent.frameCount) { - clearEveryFrame = false; - } - // Flushing any remaining geometry. flush(); @@ -1947,7 +1937,6 @@ public class PGraphicsOpenGL extends PGraphics { manipulatingCamera = false; clearColorBuffer = false; - clearEveryFrame = true; // easiest for beginners textureMode(IMAGE); @@ -4902,7 +4891,6 @@ public class PGraphicsOpenGL extends PGraphics { if (0 < parent.frameCount) { clearColorBuffer = true; } - clearCalled = true; } @@ -4924,7 +4912,6 @@ public class PGraphicsOpenGL extends PGraphics { if (0 < parent.frameCount) { clearColorBuffer = true; } - clearCalled = true; } @@ -5303,10 +5290,6 @@ public class PGraphicsOpenGL extends PGraphics { texture.invertedY(true); texture.colorBuffer(true); pgPrimary.setCache(this, texture); - - if (!primarySurface) { - createPTexture(); - } } } @@ -5986,18 +5969,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void beginOffscreenDraw() { updateOffscreen(); - /* - if (!clearColorBuffer) { - // Render previous back texture (now is the front) as background, - // because no background() is being used ("incremental drawing") - drawPTexture(); - } - if (!clearEveryFrame) { - drawPTexture(); - } - */ + // Render previous back texture (now is the front) as background drawPTexture(); - //texture.set(ptexture); // Restoring the clipping configuration of the offscreen surface. if (clip) { @@ -6136,6 +6109,9 @@ public class PGraphicsOpenGL extends PGraphics { pixelsOp = OP_NONE; + clearColorBuffer0 = clearColorBuffer; + clearColorBuffer = false; + modified = false; setgetPixels = false; } From 52dc0874af8065237dd5a363ce0c6b13123990a4 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 18:08:02 -0400 Subject: [PATCH 33/46] Some reworking of the offscreen logic, in order to reduce resource utilization. --- core/src/processing/opengl/PGL.java | 497 ++++++++++-------- .../processing/opengl/PGraphicsOpenGL.java | 6 +- .../lwjgl/src/processing/lwjgl/PGL.java | 6 +- 3 files changed, 289 insertions(+), 220 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 8232ed88e..fde807849 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -93,13 +93,18 @@ public class PGL { // Parameters - protected static final boolean USE_JOGL_FBOLAYER = false; - protected static boolean FORCE_SCREEN_FBO = false; - protected static final boolean USE_DIRECT_BUFFERS = true; - protected static final int MIN_DIRECT_BUFFER_SIZE = 1; - protected static final boolean SAVE_SURFACE_TO_PIXELS = true; + /** Switches between the use of regular and direct buffers. */ + protected static final boolean USE_DIRECT_BUFFERS = true; + protected static final int MIN_DIRECT_BUFFER_SIZE = 1; - /** Enables/disables mipmap use. **/ + /** This flag enables/disables a hack to make sure that anything drawn + * in setup will be maintained even a renderer restart (e.g.: smooth change). + * See the code and comments involving this constant in + * PGraphicsOpenGL.endDraw(). + */ + protected static final boolean SAVE_SURFACE_TO_PIXELS_HACK = true; + + /** Enables/disables mipmap use. */ protected static final boolean MIPMAPS_ENABLED = true; /** Initial sizes for arrays of input and tessellated data. */ @@ -115,7 +120,8 @@ public class PGL { /** Maximum index value of a tessellated vertex. GLES restricts the vertex * indices to be of type unsigned short. Since Java only supports signed * shorts as primitive type we have 2^15 = 32768 as the maximum number of - * vertices that can be referred to within a single VBO. */ + * vertices that can be referred to within a single VBO. + */ protected static final int MAX_VERTEX_INDEX = 32767; protected static final int MAX_VERTEX_INDEX1 = MAX_VERTEX_INDEX + 1; @@ -127,7 +133,7 @@ public class PGL { */ protected static final int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1; - /** Minimum/maximum dimensions of a texture used to hold font data. **/ + /** Minimum/maximum dimensions of a texture used to hold font data. */ protected static final int MIN_FONT_TEX_SIZE = 256; protected static final int MAX_FONT_TEX_SIZE = 1024; @@ -141,11 +147,11 @@ public class PGL { */ protected static final int MAX_CAPS_JOINS_LENGTH = 5000; - /** Minimum array size to use arrayCopy method(). **/ + /** Minimum array size to use arrayCopy method(). */ protected static final int MIN_ARRAYCOPY_SIZE = 2; /** Factor used to displace the stroke vertices towards the camera in - * order to make sure the lines are always on top of the fill geometry **/ + * order to make sure the lines are always on top of the fill geometry */ protected static final float STROKE_DISPLACEMENT = 0.999f; /** JOGL's windowing toolkit */ @@ -153,8 +159,14 @@ public class PGL { protected static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing protected static final int NEWT = 1; // http://jogamp.org/jogl/doc/NEWT-Overview.html - protected static int toolkit; - protected static int events; + /** OS-specific configuration */ + protected static int WINDOW_TOOLKIT; + protected static int EVENTS_TOOLKIT; + protected static boolean USE_FBOLAYER_BY_DEFAULT; + protected static boolean USE_JOGL_FBOLAYER; + protected static int REQUESTED_DEPTH_BITS = 24; + protected static int REQUESTED_STENCIL_BITS = 8; + protected static int REQUESTED_ALPHA_BITS = 8; static { if (PApplet.platform == PConstants.WINDOWS) { // Using AWT on Windows because NEWT displays a black background while @@ -163,26 +175,43 @@ public class PGL { // GLWindow.setPointerVisible(false); // but apparently nothing to set the cursor icon: // https://jogamp.org/bugzilla/show_bug.cgi?id=409 - toolkit = AWT; - events = AWT; + WINDOW_TOOLKIT = AWT; + EVENTS_TOOLKIT = AWT; + USE_FBOLAYER_BY_DEFAULT = false; + USE_JOGL_FBOLAYER = false; + REQUESTED_DEPTH_BITS = 24; + REQUESTED_STENCIL_BITS = 8; + REQUESTED_ALPHA_BITS = 8; } else if (PApplet.platform == PConstants.MACOSX) { // NEWT solves the issues with Java 7 and OS X 10.7+: calls to frame // hanging the sketch, as well as cursor, etc. - toolkit = AWT; - events = AWT; + WINDOW_TOOLKIT = AWT; + EVENTS_TOOLKIT = AWT; + USE_FBOLAYER_BY_DEFAULT = true; + USE_JOGL_FBOLAYER = true; + REQUESTED_DEPTH_BITS = 24; + REQUESTED_STENCIL_BITS = 8; + REQUESTED_ALPHA_BITS = 8; } else if (PApplet.platform == PConstants.LINUX) { - toolkit = NEWT; // AWT extremely broken on Linux? - events = NEWT; + WINDOW_TOOLKIT = NEWT; // AWT extremely broken on Linux? + EVENTS_TOOLKIT = NEWT; + USE_FBOLAYER_BY_DEFAULT = false; + USE_JOGL_FBOLAYER = false; + REQUESTED_DEPTH_BITS = 24; + REQUESTED_STENCIL_BITS = 8; + REQUESTED_ALPHA_BITS = 8; } else if (PApplet.platform == PConstants.OTHER) { - toolkit = NEWT; // NEWT should work on the Raspberry pi - events = NEWT; + WINDOW_TOOLKIT = NEWT; // NEWT should work on the Raspberry pi + EVENTS_TOOLKIT = NEWT; + USE_FBOLAYER_BY_DEFAULT = false; + USE_JOGL_FBOLAYER = false; + REQUESTED_DEPTH_BITS = 24; + REQUESTED_STENCIL_BITS = 8; + REQUESTED_ALPHA_BITS = 8; } } - protected static int request_depth_bits = 24; - protected static int request_stencil_bits = 8; - protected static int request_alpha_bits = 8; - + /** Size of different types in bytes */ protected static final int SIZEOF_SHORT = Short.SIZE / 8; protected static final int SIZEOF_INT = Integer.SIZE / 8; protected static final int SIZEOF_FLOAT = Float.SIZE / 8; @@ -190,11 +219,7 @@ public class PGL { protected static final int SIZEOF_INDEX = SIZEOF_SHORT; protected static final int INDEX_TYPE = GL.GL_UNSIGNED_SHORT; - /** Error string from framebuffer errors **/ - protected static final String FRAMEBUFFER_ERROR_MESSAGE = - "Framebuffer error (%1$s), rendering will probably not work as expected"; - - /** Machine Epsilon for float precision. **/ + /** Machine Epsilon for float precision. */ protected static float FLOAT_EPS = Float.MIN_VALUE; // Calculation of the Machine Epsilon for float precision. From: // http://en.wikipedia.org/wiki/Machine_epsilon#Approximation_using_Java @@ -268,8 +293,7 @@ public class PGL { /////////////////////////////////////////////////////////// // FBO layer - - protected static boolean fboLayerByDefault = FORCE_SCREEN_FBO; + protected static boolean fboLayerRequested = false; protected static boolean fboLayerCreated = false; protected static boolean fboLayerInUse = false; protected static boolean firstFrame = true; @@ -366,6 +390,9 @@ public class PGL { // Error messages + protected static final String FRAMEBUFFER_ERROR = + "Framebuffer error (%1$s), rendering will probably not work as expected"; + protected static final String MISSING_FBO_ERROR = "Framebuffer objects are not supported by this hardware (or driver)"; @@ -441,10 +468,42 @@ public class PGL { sinkFBO = backFBO = frontFBO = null; } - // Setting up the desired GL capabilities; + // Setting up the desired capabilities; GLCapabilities caps = new GLCapabilities(profile); caps.setBackgroundOpaque(true); caps.setOnscreen(true); + if (USE_FBOLAYER_BY_DEFAULT) { + if (USE_JOGL_FBOLAYER) { + caps.setPBuffer(false); + caps.setFBO(true); + if (1 < antialias) { + caps.setSampleBuffers(true); + caps.setNumSamples(antialias); + } else { + caps.setSampleBuffers(false); + } + fboLayerRequested = false; + } else { + caps.setPBuffer(false); + caps.setFBO(false); + caps.setSampleBuffers(false); + fboLayerRequested = 1 < antialias; + } + } else { + if (1 < antialias) { + caps.setSampleBuffers(true); + caps.setNumSamples(antialias); + } else { + caps.setSampleBuffers(false); + } + fboLayerRequested = false; + } + caps.setDepthBits(REQUESTED_DEPTH_BITS); + caps.setStencilBits(REQUESTED_STENCIL_BITS); + caps.setAlphaBits(REQUESTED_ALPHA_BITS); + reqNumSamples = qualityToSamples(antialias); + +/* if (USE_JOGL_FBOLAYER) { if (1 < antialias) { caps.setSampleBuffers(true); @@ -452,15 +511,16 @@ public class PGL { } else { caps.setSampleBuffers(false); } + fboLayerRequested = false; } else { caps.setSampleBuffers(false); reqNumSamples = qualityToSamples(antialias); + fboLayerRequested = 1 < reqNumSamples; } - caps.setDepthBits(request_depth_bits); - caps.setStencilBits(request_stencil_bits); - caps.setAlphaBits(request_alpha_bits); + */ - if (toolkit == AWT) { + + if (WINDOW_TOOLKIT == AWT) { canvasAWT = new GLCanvas(caps); //canvas = new GLCanvas(caps, context); @@ -479,7 +539,7 @@ public class PGL { listener = new PGLListener(); canvasAWT.addGLEventListener(listener); - } else if (toolkit == NEWT) { + } else if (WINDOW_TOOLKIT == NEWT) { window = GLWindow.create(caps); canvasNEWT = new NewtCanvasAWT(window); canvasNEWT.setBounds(0, 0, pg.width, pg.height); @@ -489,7 +549,7 @@ public class PGL { pg.parent.setLayout(new BorderLayout()); pg.parent.add(canvasNEWT, BorderLayout.CENTER); - if (events == NEWT) { + if (EVENTS_TOOLKIT == NEWT) { NEWTMouseListener mouseListener = new NEWTMouseListener(); window.addMouseListener(mouseListener); NEWTKeyListener keyListener = new NEWTKeyListener(); @@ -497,7 +557,7 @@ public class PGL { NEWTWindowListener winListener = new NEWTWindowListener(); window.addWindowListener(winListener); canvasNEWT.addFocusListener(pg.parent); // So focus detection work. - } else if (events == AWT) { + } else if (EVENTS_TOOLKIT == AWT) { pg.parent.removeListeners(canvasNEWT); pg.parent.addListeners(canvasNEWT); } @@ -546,148 +606,13 @@ public class PGL { protected void update() { if (!setFps) setFps(targetFps); - if (USE_JOGL_FBOLAYER) return; - - if (!fboLayerCreated) { - String ext = getString(EXTENSIONS); - if (-1 < ext.indexOf("texture_non_power_of_two")) { - fboWidth = pg.width; - fboHeight = pg.height; - } else { - fboWidth = nextPowerOfTwo(pg.width); - fboHeight = nextPowerOfTwo(pg.height); - } - - getIntegerv(MAX_SAMPLES, intBuffer); - if (-1 < ext.indexOf("_framebuffer_multisample") && - 1 < intBuffer.get(0)) { - numSamples = reqNumSamples; - } else { - numSamples = 1; - } - boolean multisample = 1 < numSamples; - - boolean packed = ext.indexOf("packed_depth_stencil") != -1; - int depthBits = getDepthBits(); - int stencilBits = getStencilBits(); - - genTextures(2, glColorTex); - for (int i = 0; i < 2; i++) { - bindTexture(TEXTURE_2D, glColorTex.get(i)); - texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, NEAREST); - texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, NEAREST); - texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE); - texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE); - texImage2D(TEXTURE_2D, 0, RGBA, fboWidth, fboHeight, 0, - RGBA, UNSIGNED_BYTE, null); - initTexture(TEXTURE_2D, RGBA, fboWidth, fboHeight, pg.backgroundColor); - } - bindTexture(TEXTURE_2D, 0); - - backTex = 0; - frontTex = 1; - - genFramebuffers(1, glColorFbo); - bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0)); - framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, - glColorTex.get(backTex), 0); - - if (multisample) { - // Creating multisampled FBO - genFramebuffers(1, glMultiFbo); - bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0)); - - // color render buffer... - genRenderbuffers(1, glColorBuf); - bindRenderbuffer(RENDERBUFFER, glColorBuf.get(0)); - renderbufferStorageMultisample(RENDERBUFFER, numSamples, - RGBA8, fboWidth, fboHeight); - framebufferRenderbuffer(FRAMEBUFFER, COLOR_ATTACHMENT0, - RENDERBUFFER, glColorBuf.get(0)); - } - - // Creating depth and stencil buffers - if (packed && depthBits == 24 && stencilBits == 8) { - // packed depth+stencil buffer - genRenderbuffers(1, glDepthStencil); - bindRenderbuffer(RENDERBUFFER, glDepthStencil.get(0)); - if (multisample) { - renderbufferStorageMultisample(RENDERBUFFER, numSamples, - DEPTH24_STENCIL8, fboWidth, fboHeight); - } else { - renderbufferStorage(RENDERBUFFER, DEPTH24_STENCIL8, - fboWidth, fboHeight); - } - framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, - glDepthStencil.get(0)); - framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, RENDERBUFFER, - glDepthStencil.get(0)); - } else { - // separate depth and stencil buffers - if (0 < depthBits) { - int depthComponent = DEPTH_COMPONENT16; - if (depthBits == 32) { - depthComponent = DEPTH_COMPONENT32; - } else if (depthBits == 24) { - depthComponent = DEPTH_COMPONENT24; - } else if (depthBits == 16) { - depthComponent = DEPTH_COMPONENT16; - } - - genRenderbuffers(1, glDepth); - bindRenderbuffer(RENDERBUFFER, glDepth.get(0)); - if (multisample) { - renderbufferStorageMultisample(RENDERBUFFER, numSamples, - depthComponent, fboWidth, fboHeight); - } else { - renderbufferStorage(RENDERBUFFER, depthComponent, - fboWidth, fboHeight); - } - framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, - RENDERBUFFER, glDepth.get(0)); - } - - if (0 < stencilBits) { - int stencilIndex = STENCIL_INDEX1; - if (stencilBits == 8) { - stencilIndex = STENCIL_INDEX8; - } else if (stencilBits == 4) { - stencilIndex = STENCIL_INDEX4; - } else if (stencilBits == 1) { - stencilIndex = STENCIL_INDEX1; - } - - genRenderbuffers(1, glStencil); - bindRenderbuffer(RENDERBUFFER, glStencil.get(0)); - if (multisample) { - renderbufferStorageMultisample(RENDERBUFFER, numSamples, - stencilIndex, fboWidth, fboHeight); - } else { - renderbufferStorage(RENDERBUFFER, stencilIndex, - fboWidth, fboHeight); - } - framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, - RENDERBUFFER, glStencil.get(0)); - } - } - - validateFramebuffer(); - - // Clear all buffers. - clearDepth(1); - clearStencil(0); - int argb = pg.backgroundColor; - float a = ((argb >> 24) & 0xff) / 255.0f; - float r = ((argb >> 16) & 0xff) / 255.0f; - float g = ((argb >> 8) & 0xff) / 255.0f; - float b = ((argb) & 0xff) / 255.0f; - clearColor(r, g, b, a); - clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT); - - bindFramebuffer(FRAMEBUFFER, 0); - - fboLayerCreated = true; + if (fboLayerRequested && !fboLayerCreated && !USE_JOGL_FBOLAYER) { + createFBOLayer(); } +// if (USE_JOGL_FBOLAYER) return; +// if (!fboLayerCreated) { +// createFBOLayer(); +// } } @@ -748,8 +673,8 @@ public class PGL { } - protected void needFBOLayer() { - FORCE_SCREEN_FBO = true; + protected void requestFBOLayer() { + fboLayerRequested = true; } @@ -935,6 +860,148 @@ public class PGL { } + protected void createFBOLayer() { + String ext = getString(EXTENSIONS); + if (-1 < ext.indexOf("texture_non_power_of_two")) { + fboWidth = pg.width; + fboHeight = pg.height; + } else { + fboWidth = nextPowerOfTwo(pg.width); + fboHeight = nextPowerOfTwo(pg.height); + } + + getIntegerv(MAX_SAMPLES, intBuffer); + if (-1 < ext.indexOf("_framebuffer_multisample") && + 1 < intBuffer.get(0)) { + numSamples = reqNumSamples; + } else { + numSamples = 1; + } + boolean multisample = 1 < numSamples; + + boolean packed = ext.indexOf("packed_depth_stencil") != -1; + int depthBits = getDepthBits(); + int stencilBits = getStencilBits(); + + genTextures(2, glColorTex); + for (int i = 0; i < 2; i++) { + bindTexture(TEXTURE_2D, glColorTex.get(i)); + texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, NEAREST); + texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, NEAREST); + texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE); + texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE); + texImage2D(TEXTURE_2D, 0, RGBA, fboWidth, fboHeight, 0, + RGBA, UNSIGNED_BYTE, null); + initTexture(TEXTURE_2D, RGBA, fboWidth, fboHeight, pg.backgroundColor); + } + bindTexture(TEXTURE_2D, 0); + + backTex = 0; + frontTex = 1; + + genFramebuffers(1, glColorFbo); + bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0)); + framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, + glColorTex.get(backTex), 0); + + if (multisample) { + // Creating multisampled FBO + genFramebuffers(1, glMultiFbo); + bindFramebuffer(FRAMEBUFFER, glMultiFbo.get(0)); + + // color render buffer... + genRenderbuffers(1, glColorBuf); + bindRenderbuffer(RENDERBUFFER, glColorBuf.get(0)); + renderbufferStorageMultisample(RENDERBUFFER, numSamples, + RGBA8, fboWidth, fboHeight); + framebufferRenderbuffer(FRAMEBUFFER, COLOR_ATTACHMENT0, + RENDERBUFFER, glColorBuf.get(0)); + } + + // Creating depth and stencil buffers + if (packed && depthBits == 24 && stencilBits == 8) { + // packed depth+stencil buffer + genRenderbuffers(1, glDepthStencil); + bindRenderbuffer(RENDERBUFFER, glDepthStencil.get(0)); + if (multisample) { + renderbufferStorageMultisample(RENDERBUFFER, numSamples, + DEPTH24_STENCIL8, fboWidth, fboHeight); + } else { + renderbufferStorage(RENDERBUFFER, DEPTH24_STENCIL8, + fboWidth, fboHeight); + } + framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, + glDepthStencil.get(0)); + framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, RENDERBUFFER, + glDepthStencil.get(0)); + } else { + // separate depth and stencil buffers + if (0 < depthBits) { + int depthComponent = DEPTH_COMPONENT16; + if (depthBits == 32) { + depthComponent = DEPTH_COMPONENT32; + } else if (depthBits == 24) { + depthComponent = DEPTH_COMPONENT24; + } else if (depthBits == 16) { + depthComponent = DEPTH_COMPONENT16; + } + + genRenderbuffers(1, glDepth); + bindRenderbuffer(RENDERBUFFER, glDepth.get(0)); + if (multisample) { + renderbufferStorageMultisample(RENDERBUFFER, numSamples, + depthComponent, fboWidth, fboHeight); + } else { + renderbufferStorage(RENDERBUFFER, depthComponent, + fboWidth, fboHeight); + } + framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, + RENDERBUFFER, glDepth.get(0)); + } + + if (0 < stencilBits) { + int stencilIndex = STENCIL_INDEX1; + if (stencilBits == 8) { + stencilIndex = STENCIL_INDEX8; + } else if (stencilBits == 4) { + stencilIndex = STENCIL_INDEX4; + } else if (stencilBits == 1) { + stencilIndex = STENCIL_INDEX1; + } + + genRenderbuffers(1, glStencil); + bindRenderbuffer(RENDERBUFFER, glStencil.get(0)); + if (multisample) { + renderbufferStorageMultisample(RENDERBUFFER, numSamples, + stencilIndex, fboWidth, fboHeight); + } else { + renderbufferStorage(RENDERBUFFER, stencilIndex, + fboWidth, fboHeight); + } + framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, + RENDERBUFFER, glStencil.get(0)); + } + } + + validateFramebuffer(); + + // Clear all buffers. + clearDepth(1); + clearStencil(0); + int argb = pg.backgroundColor; + float a = ((argb >> 24) & 0xff) / 255.0f; + float r = ((argb >> 16) & 0xff) / 255.0f; + float g = ((argb >> 8) & 0xff) / 255.0f; + float b = ((argb) & 0xff) / 255.0f; + clearColor(r, g, b, a); + clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT); + + bindFramebuffer(FRAMEBUFFER, 0); + + fboLayerCreated = true; + } + + /////////////////////////////////////////////////////////// // Frame rendering @@ -943,7 +1010,7 @@ public class PGL { protected void beginDraw(boolean clear0) { if (USE_JOGL_FBOLAYER) return; - if (fboLayerInUse(clear0)) { + if (needFBOLayer(clear0)) { bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0)); framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, glColorTex.get(backTex), 0); @@ -979,31 +1046,33 @@ public class PGL { firstFrame = false; } - if (!fboLayerByDefault) { + if (!USE_FBOLAYER_BY_DEFAULT) { // The result of this assignment is the following: if the user requested - // at some point the use of the FBO layer, but subsequently didn't do - // request it again, then the rendering won't use the FBO layer if not - // needed, since it is slower than simple onscreen rendering. - FORCE_SCREEN_FBO = false; + // at some point the use of the FBO layer, but subsequently didn't + // request it again, then the rendering won't render to the FBO layer if + // not needed by the condif, since it is slower than simple onscreen + // rendering. + fboLayerRequested = false; } } + protected void endDraw(boolean clear0) { - if (USE_JOGL_FBOLAYER) { - if (!clear0 && isFBOBacked() && !isMultisampled()) { - // Draw the back texture into the front texture, which will be used as - // back texture in the next frame. Otherwise flickering will occur if - // the sketch uses "incremental drawing" (background() not called). - frontFBO.bind(gl); - gl.glDisable(GL.GL_BLEND); - drawTexture(GL.GL_TEXTURE_2D, backTexAttach.getName(), - backTexAttach.getWidth(), backTexAttach.getHeight(), - pg.width, pg.height, - 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); - backFBO.bind(gl); - } - } else { - if (fboLayerInUse) { + if (isFBOBacked()) { + if (USE_JOGL_FBOLAYER) { + if (!clear0 && isFBOBacked() && !isMultisampled()) { + // Draw the back texture into the front texture, which will be used as + // back texture in the next frame. Otherwise flickering will occur if + // the sketch uses "incremental drawing" (background() not called). + frontFBO.bind(gl); + gl.glDisable(GL.GL_BLEND); + drawTexture(GL.GL_TEXTURE_2D, backTexAttach.getName(), + backTexAttach.getWidth(), backTexAttach.getHeight(), + pg.width, pg.height, + 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); + backFBO.bind(gl); + } + } else if (fboLayerInUse) { syncBackTexture(); // Draw the contents of the back texture to the screen framebuffer. @@ -1050,9 +1119,9 @@ public class PGL { protected void requestDraw() { if (pg.initialized && pg.parent.canDraw()) { try { - if (toolkit == AWT) { + if (WINDOW_TOOLKIT == AWT) { canvasAWT.display(); - } else if (toolkit == NEWT) { + } else if (WINDOW_TOOLKIT == NEWT) { window.display(); } } catch (GLException e) { @@ -1073,8 +1142,8 @@ public class PGL { } - protected boolean fboLayerInUse(boolean clear0) { - boolean cond = !clear0 || FORCE_SCREEN_FBO || 1 < numSamples; + protected boolean needFBOLayer(boolean clear0) { + boolean cond = !clear0 || fboLayerRequested || 1 < numSamples; return cond && glColorFbo.get(0) != 0; } @@ -1953,22 +2022,22 @@ public class PGL { if (status == FRAMEBUFFER_COMPLETE) { return true; } else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "incomplete attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "incomplete missing attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "incomplete dimensions")); } else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "incomplete formats")); } else if (status == FRAMEBUFFER_UNSUPPORTED) { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "framebuffer unsupported")); } else { - System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + System.err.println(String.format(FRAMEBUFFER_ERROR, "unknown error")); } return false; @@ -2407,7 +2476,7 @@ public class PGL { // The onscreen drawing surface is backed by an FBO layer. GLFBODrawable fboDrawable = null; - if (toolkit == AWT) { + if (WINDOW_TOOLKIT == AWT) { GLCanvas glCanvas = (GLCanvas)glDrawable; fboDrawable = (GLFBODrawable)glCanvas.getDelegatedDrawable(); } else { diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a33c7177b..233fbf8e3 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -1652,7 +1652,7 @@ public class PGraphicsOpenGL extends PGraphics { // Flushing any remaining geometry. flush(); - if (PGL.SAVE_SURFACE_TO_PIXELS && + if (PGL.SAVE_SURFACE_TO_PIXELS_HACK && (!pgPrimary.initialized || parent.frameCount == 0)) { // Smooth was disabled/enabled at some point during drawing. We save // the current contents of the back buffer (because the buffers haven't @@ -5416,7 +5416,7 @@ public class PGraphicsOpenGL extends PGraphics { } boolean needEndDraw = false; - if (primarySurface) pgl.needFBOLayer(); + if (primarySurface) pgl.requestFBOLayer(); else if (!drawing) { beginDraw(); needEndDraw = true; @@ -6535,7 +6535,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void unbind() { if (-1 < bufferLoc) { - pgl.needFBOLayer(); + pgl.requestFBOLayer(); pgl.activeTexture(PGL.TEXTURE0 + bufferUnit); pgCurrent.unbindBackTexture(); pgl.activeTexture(PGL.TEXTURE0); diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index b3e4955c0..1d41920dd 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -639,7 +639,7 @@ public class PGL extends processing.opengl.PGL { } - protected void needFBOLayer() { + protected void requestFBOLayer() { FORCE_SCREEN_FBO = true; } @@ -763,7 +763,7 @@ public class PGL extends processing.opengl.PGL { protected void beginDraw(boolean clear0) { - if (fboLayerInUse(clear0)) { + if (needFBOLayer(clear0)) { bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0)); framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, glColorTex.get(backTex), 0); @@ -865,7 +865,7 @@ public class PGL extends processing.opengl.PGL { } - protected boolean fboLayerInUse(boolean clear0) { + protected boolean needFBOLayer(boolean clear0) { boolean cond = !clear0 || FORCE_SCREEN_FBO || 1 < numSamples; return cond && glColorFbo.get(0) != 0; } From bfec690a28b8adf4b720821e35f5b6396f29c8ea Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 18:26:30 -0400 Subject: [PATCH 34/46] removed some commented code --- core/src/processing/opengl/PGL.java | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index fde807849..a818820f8 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -503,28 +503,8 @@ public class PGL { caps.setAlphaBits(REQUESTED_ALPHA_BITS); reqNumSamples = qualityToSamples(antialias); -/* - if (USE_JOGL_FBOLAYER) { - if (1 < antialias) { - caps.setSampleBuffers(true); - caps.setNumSamples(antialias); - } else { - caps.setSampleBuffers(false); - } - fboLayerRequested = false; - } else { - caps.setSampleBuffers(false); - reqNumSamples = qualityToSamples(antialias); - fboLayerRequested = 1 < reqNumSamples; - } - */ - - if (WINDOW_TOOLKIT == AWT) { canvasAWT = new GLCanvas(caps); - - //canvas = new GLCanvas(caps, context); - canvasAWT.setBounds(0, 0, pg.width, pg.height); canvasAWT.setBackground(new Color(pg.backgroundColor, true)); canvasAWT.setFocusable(true); From c589c2d459025f05fa9b98f51f00d7d20c466822 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 27 May 2013 23:31:42 -0400 Subject: [PATCH 35/46] PGL.readPixels() calls beginPixelsOp/endPixelsOp to properly set the framebuffers for reading. --- core/src/processing/opengl/PGL.java | 8 ++++++++ core/src/processing/opengl/PGraphicsOpenGL.java | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index a818820f8..a633b5154 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -3117,6 +3117,14 @@ public class PGL { // Reading Pixels public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) { + // The beginPixelsOp/endPixelsOp calls are needed to properly setup the + // framebuffers to read from. + PGraphicsOpenGL.pgCurrent.beginPixelsOp(PGraphicsOpenGL.OP_READ); + readPixelsImpl(x, y, width, height, format, type, buffer); + PGraphicsOpenGL.pgCurrent.endPixelsOp(); + } + + protected void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) { gl.glReadPixels(x, y, width, height, format, type, buffer); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 233fbf8e3..314e1d4cf 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5056,13 +5056,13 @@ public class PGraphicsOpenGL extends PGraphics { protected void readPixels() { beginPixelsOp(OP_READ); try { - // The readPixels() call in inside a try/catch block because it appears + // The readPixelsImpl() call in inside a try/catch block because it appears // that (only sometimes) JOGL will run beginDraw/endDraw on the EDT // thread instead of the Animation thread right after a resize. Because // of this the width and height might have a different size than the // one of the pixels arrays. - pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, - pixelBuffer); + pgl.readPixelsImpl(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, + pixelBuffer); } catch (IndexOutOfBoundsException e) { // Silently catch the exception. } @@ -5217,9 +5217,9 @@ public class PGraphicsOpenGL extends PGraphics { beginPixelsOp(OP_READ); try { - // Se comments in readPixels() for the reason for this try/catch. - pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, - nativePixelBuffer); + // See comments in readPixels() for the reason for this try/catch. + pgl.readPixelsImpl(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE, + nativePixelBuffer); } catch (IndexOutOfBoundsException e) { } endPixelsOp(); From 54bb25645c630cc48e5877662807c34f72c214a1 Mon Sep 17 00:00:00 2001 From: REAS Date: Mon, 27 May 2013 23:25:24 -0700 Subject: [PATCH 36/46] Edits to *List classes for reference --- core/src/processing/data/FloatList.java | 20 ++++++++++---------- core/src/processing/data/IntList.java | 20 ++++++++++---------- core/src/processing/data/StringList.java | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index 90cbd0e90..24ab1d9ba 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -391,7 +391,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Check if a number is a part of the list */ public boolean hasValue(float value) { if (Float.isNaN(value)) { @@ -418,7 +418,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Add to a value */ public void add(int index, float amount) { data[index] += amount; @@ -426,7 +426,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Subtract from a value */ public void sub(int index, float amount) { data[index] -= amount; @@ -434,7 +434,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Multiply a value */ public void mult(int index, float amount) { data[index] *= amount; @@ -442,7 +442,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Divide a value */ public void div(int index, float amount) { data[index] /= amount; @@ -450,7 +450,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Return the smallest value */ public float min() { if (count == 0) { @@ -480,7 +480,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Return the largest value */ public float max() { if (count == 0) { @@ -513,7 +513,7 @@ public class FloatList implements Iterable { * Sorts the array in place. * * @webref floatlist:method - * @brief Sorts an array in place + * @brief Sorts an array, lowest to highest */ public void sort() { Arrays.sort(data, 0, count); @@ -524,7 +524,7 @@ public class FloatList implements Iterable { * Reverse sort, orders values from highest to lowest * * @webref floatlist:method - * @brief To come... + * @brief Reverse sort, orders values from highest to lowest */ public void sortReverse() { new Sort() { @@ -567,7 +567,7 @@ public class FloatList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Reverse sort, orders values by first digit */ public void reverse() { int ii = count - 1; diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index d326c0c3b..3837bfd3d 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -338,7 +338,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Check if a number is a part of the data structure */ public boolean hasValue(int value) { // if (indexCache == null) { @@ -355,7 +355,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Add one to a value */ public void increment(int index) { data[index]++; @@ -363,7 +363,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Add to a value */ public void add(int index, int amount) { data[index] += amount; @@ -371,7 +371,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Subtract from a value */ public void sub(int index, int amount) { data[index] -= amount; @@ -379,7 +379,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Multiply a value */ public void mult(int index, int amount) { data[index] *= amount; @@ -387,7 +387,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Divide a value */ public void div(int index, int amount) { data[index] /= amount; @@ -395,7 +395,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Return the smallest value */ public int min() { if (count == 0) { @@ -410,7 +410,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Return the largest value */ public int max() { if (count == 0) { @@ -428,7 +428,7 @@ public class IntList implements Iterable { * Sorts the array in place. * * @webref floatlist:method - * @brief Sorts the array in place + * @brief Sorts the array, lowest to highest */ public void sort() { Arrays.sort(data, 0, count); @@ -482,7 +482,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief To come... + * @brief Reverse sort, orders values by first digit */ public void reverse() { int ii = count - 1; diff --git a/core/src/processing/data/StringList.java b/core/src/processing/data/StringList.java index 1a8c7561c..1abfd1ce9 100644 --- a/core/src/processing/data/StringList.java +++ b/core/src/processing/data/StringList.java @@ -387,7 +387,7 @@ public class StringList implements Iterable { /** * @webref stringlist:method - * @brief To come... + * @brief Check if a value is a part of the list */ public boolean hasValue(String value) { if (value == null) { From aa2ac0600b2f57f152554b0ce1790a17a44f0599 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 10:37:55 -0400 Subject: [PATCH 37/46] PShapeOpenGL.setTexture() calls setTexture() on children shapes. --- core/src/processing/opengl/PShapeOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index a77636aa6..6a525c11d 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -780,7 +780,7 @@ public class PShapeOpenGL extends PShape { if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.texture(tex); + child.setTexture(tex); } } else { setTextureImpl(tex); From 751d76db1c0c9e8a269a7ebd4f306690ae1aad41 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 11:38:23 -0400 Subject: [PATCH 39/46] Use AWT on Linux --- core/src/processing/opengl/PGL.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index a633b5154..d973952ea 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -193,8 +193,8 @@ public class PGL { REQUESTED_STENCIL_BITS = 8; REQUESTED_ALPHA_BITS = 8; } else if (PApplet.platform == PConstants.LINUX) { - WINDOW_TOOLKIT = NEWT; // AWT extremely broken on Linux? - EVENTS_TOOLKIT = NEWT; + WINDOW_TOOLKIT = AWT; // AWT extremely broken on Linux? With jogl-2.0-b993 + EVENTS_TOOLKIT = AWT; // appears not. USE_FBOLAYER_BY_DEFAULT = false; USE_JOGL_FBOLAYER = false; REQUESTED_DEPTH_BITS = 24; From 93ee78c6002dcf7096fbd1855a4ea173ef941f17 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 14:17:23 -0400 Subject: [PATCH 40/46] keeping track of bound textures on all units --- core/src/processing/opengl/PGL.java | 65 ++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index d973952ea..40f5d69b5 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -287,8 +287,10 @@ public class PGL { /** Which texturing targets are enabled */ protected static boolean[] texturingTargets = { false, false }; - /** Which textures are bound to each target */ - protected static int[] boundTextures = { 0, 0 }; + /** Used to keep track of which textures are bound to each target */ + protected static int maxTexUnits; + protected static int activeTexUnit = 0; + protected static int[][] boundTextures; /////////////////////////////////////////////////////////// @@ -402,6 +404,9 @@ public class PGL { protected static final String MISSING_GLFUNC_ERROR = "GL function %1$s is not available on this hardware (or driver)"; + protected static final String TEXUNIT_ERROR = + "Number of texture units not supported by this hardware (or driver)"; + /////////////////////////////////////////////////////////// @@ -703,7 +708,7 @@ public class PGL { if (USE_JOGL_FBOLAYER) { Texture tex = new Texture(); tex.init(pg.width, pg.height, - backTexAttach.getName(), GL.GL_TEXTURE_2D, GL.GL_RGBA, + backTexAttach.getName(), TEXTURE_2D, RGBA, backTexAttach.getWidth(), backTexAttach.getHeight(), backTexAttach.minFilter, backTexAttach.magFilter, backTexAttach.wrapS, backTexAttach.wrapT); @@ -729,7 +734,7 @@ public class PGL { if (USE_JOGL_FBOLAYER) { Texture tex = new Texture(); tex.init(pg.width, pg.height, - backTexAttach.getName(), GL.GL_TEXTURE_2D, GL.GL_RGBA, + backTexAttach.getName(), TEXTURE_2D, RGBA, frontTexAttach.getWidth(), frontTexAttach.getHeight(), frontTexAttach.minFilter, frontTexAttach.magFilter, frontTexAttach.wrapS, frontTexAttach.wrapT); @@ -769,10 +774,10 @@ public class PGL { protected void bindFrontTexture() { if (USE_JOGL_FBOLAYER) { - if (!texturingIsEnabled(GL.GL_TEXTURE_2D)) { - enableTexturing(GL.GL_TEXTURE_2D); + if (!texturingIsEnabled(TEXTURE_2D)) { + enableTexturing(TEXTURE_2D); } - gl.glBindTexture(GL.GL_TEXTURE_2D, frontTexAttach.getName()); + bindTexture(TEXTURE_2D, frontTexAttach.getName()); } else { if (!texturingIsEnabled(TEXTURE_2D)) { enableTexturing(TEXTURE_2D); @@ -784,15 +789,15 @@ public class PGL { protected void unbindFrontTexture() { if (USE_JOGL_FBOLAYER) { - if (textureIsBound(GL.GL_TEXTURE_2D, frontTexAttach.getName())) { + if (textureIsBound(TEXTURE_2D, frontTexAttach.getName())) { // We don't want to unbind another texture // that might be bound instead of this one. - if (!texturingIsEnabled(GL.GL_TEXTURE_2D)) { - enableTexturing(GL.GL_TEXTURE_2D); - gl.glBindTexture(GL.GL_TEXTURE_2D, 0); - disableTexturing(GL.GL_TEXTURE_2D); + if (!texturingIsEnabled(TEXTURE_2D)) { + enableTexturing(TEXTURE_2D); + bindTexture(TEXTURE_2D, 0); + disableTexturing(TEXTURE_2D); } else { - gl.glBindTexture(GL.GL_TEXTURE_2D, 0); + bindTexture(TEXTURE_2D, 0); } } } else { @@ -1046,7 +1051,7 @@ public class PGL { // the sketch uses "incremental drawing" (background() not called). frontFBO.bind(gl); gl.glDisable(GL.GL_BLEND); - drawTexture(GL.GL_TEXTURE_2D, backTexAttach.getName(), + drawTexture(TEXTURE_2D, backTexAttach.getName(), backTexAttach.getWidth(), backTexAttach.getHeight(), pg.width, pg.height, 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); @@ -1330,10 +1335,12 @@ public class PGL { protected boolean textureIsBound(int target, int id) { + if (boundTextures == null) return false; + if (target == TEXTURE_2D) { - return boundTextures[0] == id; + return boundTextures[activeTexUnit][0] == id; } else if (target == TEXTURE_RECTANGLE) { - return boundTextures[1] == id; + return boundTextures[activeTexUnit][1] == id; } else { return false; } @@ -2075,6 +2082,12 @@ public class PGL { } + protected int getMaxTexUnits() { + getIntegerv(MAX_TEXTURE_IMAGE_UNITS, intBuffer); + return intBuffer.get(0); + } + + protected static ByteBuffer allocateDirectByteBuffer(int size) { int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_BYTE; return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()); @@ -2794,8 +2807,9 @@ public class PGL { public static final int TEXTURE_MAX_ANISOTROPY = GL.GL_TEXTURE_MAX_ANISOTROPY_EXT; public static final int MAX_TEXTURE_MAX_ANISOTROPY = GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT; - public static final int MAX_VERTEX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; - public static final int MAX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; + public static final int MAX_VERTEX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS; + public static final int MAX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; + public static final int MAX_COMBINED_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS; public static final int NEAREST = GL.GL_NEAREST; public static final int LINEAR = GL.GL_LINEAR; @@ -3226,6 +3240,7 @@ public class PGL { public void activeTexture(int texture) { gl.glActiveTexture(texture); + activeTexUnit = texture - TEXTURE0; } public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) { @@ -3274,10 +3289,20 @@ public class PGL { public void bindTexture(int target, int texture) { gl.glBindTexture(target, texture); + + if (boundTextures == null) { + maxTexUnits = getMaxTexUnits(); + boundTextures = new int[maxTexUnits][2]; + } + + if (maxTexUnits <= activeTexUnit) { + throw new RuntimeException(TEXUNIT_ERROR); + } + if (target == TEXTURE_2D) { - boundTextures[0] = texture; + boundTextures[activeTexUnit][0] = texture; } else if (target == TEXTURE_RECTANGLE) { - boundTextures[1] = texture; + boundTextures[activeTexUnit][1] = texture; } } From be83796795ea7862186fe600ccbdd4fc36d11609 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 14:44:22 -0400 Subject: [PATCH 41/46] removed PGL.update(), and updatePrimary, updateOffscreen() in PGraphicsOpenGL. --- core/src/processing/opengl/PGL.java | 18 +++++------------- .../src/processing/opengl/PGraphicsOpenGL.java | 12 +----------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 40f5d69b5..ac429025d 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -295,6 +295,7 @@ public class PGL { /////////////////////////////////////////////////////////// // FBO layer + protected static boolean fboLayerRequested = false; protected static boolean fboLayerCreated = false; protected static boolean fboLayerInUse = false; @@ -588,19 +589,6 @@ public class PGL { } - protected void update() { - if (!setFps) setFps(targetFps); - - if (fboLayerRequested && !fboLayerCreated && !USE_JOGL_FBOLAYER) { - createFBOLayer(); - } -// if (USE_JOGL_FBOLAYER) return; -// if (!fboLayerCreated) { -// createFBOLayer(); -// } - } - - protected int getReadFramebuffer() { if (fboLayerInUse) { return glColorFbo.get(0); @@ -993,9 +981,13 @@ public class PGL { protected void beginDraw(boolean clear0) { + if (!setFps) setFps(targetFps); + if (USE_JOGL_FBOLAYER) return; if (needFBOLayer(clear0)) { + if (!fboLayerCreated) createFBOLayer(); + bindFramebuffer(FRAMEBUFFER, glColorFbo.get(0)); framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D, glColorTex.get(backTex), 0); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 314e1d4cf..8512aab4e 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5852,13 +5852,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void updatePrimary() { - pgl.update(); - } - - protected void beginOnscreenDraw() { - updatePrimary(); pgl.beginDraw(clearColorBuffer); if (drawFramebuffer == null) { @@ -5939,7 +5933,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void updateOffscreen() { + protected void beginOffscreenDraw() { if (!initialized) { initOffscreen(); } else { @@ -5964,11 +5958,7 @@ public class PGraphicsOpenGL extends PGraphics { } else { setFramebuffer(offscreenFramebuffer); } - } - - protected void beginOffscreenDraw() { - updateOffscreen(); // Render previous back texture (now is the front) as background drawPTexture(); From d1ac58a07690664eed8a08525b04087ad3f5a5f0 Mon Sep 17 00:00:00 2001 From: REAS Date: Tue, 28 May 2013 11:51:41 -0700 Subject: [PATCH 42/46] Reference additions for Lists and Dicts --- core/src/processing/data/FloatList.java | 13 ++++++++++--- core/src/processing/data/IntList.java | 11 +++++++---- core/src/processing/data/StringList.java | 7 +++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index 24ab1d9ba..31479e4cc 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -8,6 +8,13 @@ import processing.core.PApplet; /** + * Helper class for a list of floats. Lists are designed to have some of the + * features of ArrayLists, but to maintain the simplicity and efficiency of + * working with arrays. + * + * Functions like sort() and shuffle() always act on the list itself. To get + * a sorted copy, use list.copy().sort(). + * * @webref data:composite */ public class FloatList implements Iterable { @@ -665,7 +672,7 @@ public class FloatList implements Iterable { * @webref floatlist:method * @brief Create a new array with a copy of all the values */ - public int[] array() { + public float[] array() { return array(null); } @@ -674,9 +681,9 @@ public class FloatList implements Iterable { * Copy as many values as possible into the specified array. * @param array */ - public int[] array(int[] array) { + public float[] array(float[] array) { if (array == null || array.length != count) { - array = new int[count]; + array = new float[count]; } System.arraycopy(data, 0, array, 0, count); return array; diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index 3837bfd3d..58780421a 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -13,9 +13,12 @@ import processing.core.PApplet; /** - * Helper class for a list of ints. By design (for efficiency), functions like - * sort() and shuffle() always act on the list itself. To get a sorted copy, - * use list.copy().sort(). + * Helper class for a list of ints. Lists are designed to have some of the + * features of ArrayLists, but to maintain the simplicity and efficiency of + * working with arrays. + * + * Functions like sort() and shuffle() always act on the list itself. To get + * a sorted copy, use list.copy().sort(). * * @webref data:composite */ @@ -338,7 +341,7 @@ public class IntList implements Iterable { /** * @webref floatlist:method - * @brief Check if a number is a part of the data structure + * @brief Check if a number is a part of the list */ public boolean hasValue(int value) { // if (indexCache == null) { diff --git a/core/src/processing/data/StringList.java b/core/src/processing/data/StringList.java index 1abfd1ce9..abc1cae8d 100644 --- a/core/src/processing/data/StringList.java +++ b/core/src/processing/data/StringList.java @@ -7,6 +7,13 @@ import java.util.Random; import processing.core.PApplet; /** + * Helper class for a list of Strings. Lists are designed to have some of the + * features of ArrayLists, but to maintain the simplicity and efficiency of + * working with arrays. + * + * Functions like sort() and shuffle() always act on the list itself. To get + * a sorted copy, use list.copy().sort(). + * * @webref data:composite */ public class StringList implements Iterable { From 8a048994302024f2a445c4cfb8f5891059128581 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 28 May 2013 12:29:14 -0700 Subject: [PATCH 43/46] Added reference for JSONArray, JSONObject, loadJSONArray(), loadJSONObject(), saveJSONArray(), saveJSONObject() --- core/src/processing/core/PApplet.java | 22 +++++++++++++++++ core/src/processing/data/JSONArray.java | 31 ++++++++++++++++++------ core/src/processing/data/JSONObject.java | 18 ++++++++++++++ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index ca7ba0ae9..fce0463b2 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -6119,6 +6119,12 @@ public class PApplet extends Applet /** * @webref output:files + * @param filename name of a file in the data folder or a URL + * @see JSONObject + * @see JSONArray + * @see PApplet#loadJSONArray(String) + * @see PApplet#saveJSONObject(JSONObject, String) + * @see PApplet#saveJSONArray(JSONArray, String) */ public JSONObject loadJSONObject(String filename) { return new JSONObject(createReader(filename)); @@ -6126,6 +6132,11 @@ public class PApplet extends Applet /** * @webref output:files + * @see JSONObject + * @see JSONArray + * @see PApplet#loadJSONObject(String) + * @see PApplet#loadJSONArray(String) + * @see PApplet#saveJSONArray(JSONArray, String) */ public boolean saveJSONObject(JSONObject json, String filename) { return saveJSONObject(json, filename, null); @@ -6143,6 +6154,12 @@ public class PApplet extends Applet /** * @webref output:files + * @param filename name of a file in the data folder or a URL + * @see JSONObject + * @see JSONArray + * @see PApplet#loadJSONObject(String) + * @see PApplet#saveJSONObject(JSONObject, String) + * @see PApplet#saveJSONArray(JSONArray, String) */ public JSONArray loadJSONArray(String filename) { return new JSONArray(createReader(filename)); @@ -6150,6 +6167,11 @@ public class PApplet extends Applet /** * @webref output:files + * @see JSONObject + * @see JSONArray + * @see PApplet#loadJSONObject(String) + * @see PApplet#loadJSONArray(String) + * @see PApplet#saveJSONObject(JSONObject, String) */ public boolean saveJSONArray(JSONArray json, String filename) { return saveJSONArray(json, filename); diff --git a/core/src/processing/data/JSONArray.java b/core/src/processing/data/JSONArray.java index 2d74ef602..a12d7d197 100644 --- a/core/src/processing/data/JSONArray.java +++ b/core/src/processing/data/JSONArray.java @@ -92,6 +92,11 @@ import processing.core.PApplet; * @author JSON.org * @version 2012-11-13 * @webref data:composite + * @see JSONObject + * @see PApplet#loadJSONObject(String) + * @see PApplet#loadJSONArray(String) + * @see PApplet#saveJSONObject(JSONObject, String) + * @see PApplet#saveJSONArray(JSONArray, String) */ public class JSONArray { @@ -103,12 +108,16 @@ public class JSONArray { /** * Construct an empty JSONArray. + * @nowebref */ public JSONArray() { this.myArrayList = new ArrayList(); } + /** + * @nowebref + */ public JSONArray(Reader reader) { this(new JSONTokener(reader)); } @@ -152,6 +161,9 @@ public class JSONArray { } + /** + * @nowebref + */ public JSONArray(IntList list) { myArrayList = new ArrayList(); for (int item : list.values()) { @@ -160,6 +172,9 @@ public class JSONArray { } + /** + * @nowebref + */ public JSONArray(FloatList list) { myArrayList = new ArrayList(); for (float item : list.values()) { @@ -168,6 +183,9 @@ public class JSONArray { } + /** + * @nowebref + */ public JSONArray(StringList list) { myArrayList = new ArrayList(); for (String item : list.values()) { @@ -658,10 +676,10 @@ public class JSONArray { /** * Append an String value. This increases the array's length by one. * + * @webref jsonarray:method + * @brief Appends a String value, increasing the array's length by one * @param value A String value. * @return this. - * @webref jsonarray:method - * @brief Append an String value. This increases the array's length by one. */ public JSONArray append(String value) { this.append((Object)value); @@ -959,9 +977,9 @@ public class JSONArray { /** * Get the number of elements in the JSONArray, included nulls. * - * @return The length (or size). * @webref jsonarray:method - * @brief Get the number of elements in the JSONArray, included nulls + * @brief Gets the number of elements in the JSONArray, included nulls + * @return The length (or size). */ public int size() { return myArrayList.size(); @@ -982,11 +1000,10 @@ public class JSONArray { /** * Remove an index and close the hole. * - * @param index The index of the element to be removed. - * @return The value that was associated with the index, - * or null if there was no value. * @webref jsonarray:method * @brief Remove an index and close the hole + * @param index The index of the element to be removed. + * @return The value that was associated with the index, or null if there was no value. */ public Object remove(int index) { Object o = this.opt(index); diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index 589066d8b..a4fdc5dcc 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -104,6 +104,11 @@ import processing.core.PApplet; * @author JSON.org * @version 2012-12-01 * @webref data:composite + * @see JSONArray + * @see PApplet#loadJSONObject(String) + * @see PApplet#loadJSONArray(String) + * @see PApplet#saveJSONObject(JSONObject, String) + * @see PApplet#saveJSONArray(JSONArray, String) */ public class JSONObject { /** @@ -189,6 +194,7 @@ public class JSONObject { /** * Construct an empty JSONObject. + * @nowebref */ public JSONObject() { this.map = new HashMap(); @@ -215,6 +221,9 @@ public class JSONObject { // } + /** + * @nowebref + */ public JSONObject(Reader reader) { this(new JSONTokener(reader)); } @@ -299,6 +308,9 @@ public class JSONObject { } + /** + * @nowebref + */ public JSONObject(IntDict dict) { map = new HashMap(); for (int i = 0; i < dict.size(); i++) { @@ -307,6 +319,9 @@ public class JSONObject { } + /** + * @nowebref + */ public JSONObject(FloatDict dict) { map = new HashMap(); for (int i = 0; i < dict.size(); i++) { @@ -315,6 +330,9 @@ public class JSONObject { } + /** + * @nowebref + */ public JSONObject(StringDict dict) { map = new HashMap(); for (int i = 0; i < dict.size(); i++) { From a7bbd378406384ad16c57937e9052b938984ee6e Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 16:37:22 -0400 Subject: [PATCH 44/46] Added the GL constants to query compressed texture formats --- core/src/processing/opengl/PGL.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index ac429025d..c840a2fac 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -2803,6 +2803,9 @@ public class PGL { public static final int MAX_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_TEXTURE_IMAGE_UNITS; public static final int MAX_COMBINED_TEXTURE_IMAGE_UNITS = GL2ES2.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS; + public static final int NUM_COMPRESSED_TEXTURE_FORMATS = GL2ES2.GL_NUM_COMPRESSED_TEXTURE_FORMATS; + public static final int COMPRESSED_TEXTURE_FORMATS = GL2ES2.GL_COMPRESSED_TEXTURE_FORMATS; + public static final int NEAREST = GL.GL_NEAREST; public static final int LINEAR = GL.GL_LINEAR; public static final int LINEAR_MIPMAP_NEAREST = GL.GL_LINEAR_MIPMAP_NEAREST; From 7376912a74bd43114e63aadbb9870e197dd7cb76 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 21:53:51 -0400 Subject: [PATCH 45/46] Implementing SHAPE text mode in the OpenGL renderer (#777) --- .../processing/opengl/PGraphicsOpenGL.java | 405 +++++++++++++++--- 1 file changed, 352 insertions(+), 53 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8512aab4e..be8b7669f 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -24,6 +24,12 @@ package processing.opengl; import processing.core.*; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.PathIterator; import java.net.URL; import java.nio.*; import java.util.*; @@ -3241,7 +3247,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected boolean textModeCheck(int mode) { - return mode == MODEL; + return mode == MODEL || mode == SHAPE; } // public void textSize(float size) @@ -3267,54 +3273,59 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { - textTex = pgPrimary.getFontTexture(textFont); + if (textMode == MODEL) { + textTex = pgPrimary.getFontTexture(textFont); - if (textTex == null || textTex.contextIsOutdated()) { - textTex = new FontTexture(pgPrimary, textFont, is3D()); - pgPrimary.setFontTexture(textFont, textTex); + if (textTex == null || textTex.contextIsOutdated()) { + textTex = new FontTexture(pgPrimary, textFont, is3D()); + pgPrimary.setFontTexture(textFont, textTex); + } + + textTex.begin(); + + // Saving style parameters modified by text rendering. + int savedTextureMode = textureMode; + boolean savedStroke = stroke; + float savedNormalX = normalX; + float savedNormalY = normalY; + float savedNormalZ = normalZ; + boolean savedTint = tint; + int savedTintColor = tintColor; + int savedBlendMode = blendMode; + + // Setting style used in text rendering. + textureMode = NORMAL; + stroke = false; + normalX = 0; + normalY = 0; + normalZ = 1; + tint = true; + tintColor = fillColor; + + blendMode(BLEND); + + super.textLineImpl(buffer, start, stop, x, y); + + // Restoring original style. + textureMode = savedTextureMode; + stroke = savedStroke; + normalX = savedNormalX; + normalY = savedNormalY; + normalZ = savedNormalZ; + tint = savedTint; + tintColor = savedTintColor; + + // Note that if the user is using a blending mode different from + // BLEND, and has a bunch of continuous text rendering, the performance + // won't be optimal because at the end of each text() call the geometry + // will be flushed when restoring the user's blend. + blendMode(savedBlendMode); + + textTex.end(); + } else if (textMode == SHAPE) { + super.textLineImpl(buffer, start, stop, x, y); } - textTex.begin(); - - // Saving style parameters modified by text rendering. - int savedTextureMode = textureMode; - boolean savedStroke = stroke; - float savedNormalX = normalX; - float savedNormalY = normalY; - float savedNormalZ = normalZ; - boolean savedTint = tint; - int savedTintColor = tintColor; - int savedBlendMode = blendMode; - - // Setting style used in text rendering. - textureMode = NORMAL; - stroke = false; - normalX = 0; - normalY = 0; - normalZ = 1; - tint = true; - tintColor = fillColor; - - blendMode(BLEND); - - super.textLineImpl(buffer, start, stop, x, y); - - // Restoring original style. - textureMode = savedTextureMode; - stroke = savedStroke; - normalX = savedNormalX; - normalY = savedNormalY; - normalZ = savedNormalZ; - tint = savedTint; - tintColor = savedTintColor; - - // Note that if the user is using a blending mode different from - // BLEND, and has a bunch of continuous text rendering, the performance - // won't be optimal because at the end of each text() call the geometry - // will be flushed when restoring the user's blend. - blendMode(savedBlendMode); - - textTex.end(); } @@ -3323,14 +3334,14 @@ public class PGraphicsOpenGL extends PGraphics { PFont.Glyph glyph = textFont.getGlyph(ch); if (glyph != null) { - FontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); - - if (tinfo == null) { - // Adding new glyph to the font texture. - tinfo = textTex.addToTexture(pgPrimary, glyph); - } - if (textMode == MODEL) { + FontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); + + if (tinfo == null) { + // Adding new glyph to the font texture. + tinfo = textTex.addToTexture(pgPrimary, glyph); + } + float high = glyph.height / (float) textFont.getSize(); float bwidth = glyph.width / (float) textFont.getSize(); float lextent = glyph.leftExtent / (float) textFont.getSize(); @@ -3342,6 +3353,8 @@ public class PGraphicsOpenGL extends PGraphics { float y2 = y1 + high * textSize; textCharModelImpl(tinfo, x1, y1, x2, y2); + } else if (textMode == SHAPE) { + textCharShapeImpl(ch, x, y); } } } @@ -3365,6 +3378,292 @@ public class PGraphicsOpenGL extends PGraphics { } + protected void textCharShapeImpl(char ch, float x, float y) { + // save the current stroke because it needs to be disabled + // while the text is being drawn + boolean strokeSaved = stroke; + stroke = false; + + char textArray[] = new char[] { ch }; + Graphics2D graphics = (Graphics2D) parent.getGraphics(); + FontRenderContext frc = graphics.getFontRenderContext(); + Font font = (Font) textFont.getNative(); + GlyphVector gv = font.createGlyphVector(frc, textArray); + Shape shp = gv.getOutline(); + PathIterator iter = shp.getPathIterator(null); + + PApplet.println("Drawing model of character " + ch); + + // six element array received from the Java2D path iterator + float textPoints[] = new float[6]; + float lastX = 0; + float lastY = 0; + + beginShape(); + while (!iter.isDone()) { + int type = iter.currentSegment(textPoints); + switch (type) { + case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints + case PathIterator.SEG_LINETO: // 1 point + if (type == PathIterator.SEG_MOVETO) { + PApplet.println("moveto"); + beginContour(); + +// if (DEBUG_OPCODES) { +// System.out.println("moveto\t" + +// textPoints[0] + "\t" + textPoints[1]); +// } +// glu.gluTessBeginContour(tobj); + } + vertex(x + textPoints[0], y + textPoints[1]); + +// vertex = new double[] { +// x + textPoints[0], y + textPoints[1], 0 +// }; +// glu.gluTessVertex(tobj, vertex, 0, vertex); + lastX = textPoints[0]; + lastY = textPoints[1]; + break; + + case PathIterator.SEG_QUADTO: // 2 points + PApplet.println("quadto"); +// if (DEBUG_OPCODES) { +// System.out.println("quadto\t" + +// textPoints[0] + "\t" + textPoints[1] + "\t" + +// textPoints[2] + "\t" + textPoints[3]); +// } + + for (int i = 1; i < bezierDetail; i++) { + float t = (float)i / (float)bezierDetail; +// vertex = new double[] { +// x + bezierPoint(lastX, +// lastX + (float) ((textPoints[0] - lastX) * 2/3.0), +// textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), +// textPoints[2], t), +// y + bezierPoint(lastY, +// lastY + (float) ((textPoints[1] - lastY) * 2/3.0), +// textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), +// textPoints[3], t), +// 0.0f +// }; + vertex(x + bezierPoint(lastX, + lastX + (float) ((textPoints[0] - lastX) * 2/3.0), + textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), + textPoints[2], t), + y + bezierPoint(lastY, + lastY + (float) ((textPoints[1] - lastY) * 2/3.0), + textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), + textPoints[3], t)); + //glu.gluTessVertex(tobj, vertex, 0, vertex); + } + + lastX = textPoints[2]; + lastY = textPoints[3]; + break; + + case PathIterator.SEG_CUBICTO: // 3 points + PApplet.println("cubicto"); +// if (DEBUG_OPCODES) { +// System.out.println("cubicto\t" + +// textPoints[0] + "\t" + textPoints[1] + "\t" + +// textPoints[2] + "\t" + textPoints[3] + "\t" + +// textPoints[4] + "\t" + textPoints[5]); +// } + + for (int i = 1; i < bezierDetail; i++) { + float t = (float)i / (float)bezierDetail; + vertex(x + bezierPoint(lastX, textPoints[0], + textPoints[2], textPoints[4], t), + y + bezierPoint(lastY, textPoints[1], + textPoints[3], textPoints[5], t)); +// vertex = new double[] { +// x + bezierPoint(lastX, textPoints[0], +// textPoints[2], textPoints[4], t), +// y + bezierPoint(lastY, textPoints[1], +// textPoints[3], textPoints[5], t), 0 +// }; + //glu.gluTessVertex(tobj, vertex, 0, vertex); + } + + lastX = textPoints[4]; + lastY = textPoints[5]; + break; + + case PathIterator.SEG_CLOSE: + PApplet.println("close"); +// if (DEBUG_OPCODES) { +// System.out.println("close"); +// System.out.println(); +// } +// glu.gluTessEndContour(tobj); + endContour(); + break; + } + iter.next(); + PApplet.println(lastX + " " + lastY); + } + endShape(); + // glu.gluTessEndPolygon(tobj); + + PApplet.println("*********************"); + + // re-enable stroke if it was in use before + stroke = strokeSaved; + } + + // ORIGINAL CODE FROM 1.5.1 + /** + * This uses the tesselation functions from GLU to handle triangulation + * to convert the character into a series of shapes. + *

+ * No attempt has been made to optimize this code + *

+ * TODO: Should instead override textPlacedImpl() because createGlyphVector + * takes a char array. Or better yet, cache the font on a per-char basis, + * so that it's not being re-tessellated each time, could make it into + * a display list which would be nice and speedy. + *

+ * Also a problem where some fonts seem to be a bit slight, as if the + * control points aren't being mapped quite correctly. Probably doing + * something dumb that the control points don't map to P5's control + * points. Perhaps it's returning b-spline data from the TrueType font? + * Though it seems like that would make a lot of garbage rather than + * just a little flattening. + *

+ * There also seems to be a bug that is causing a line (but not a filled + * triangle) back to the origin on some letters (i.e. a capital L when + * tested with Akzidenz Grotesk Light). But this won't be visible + * with the stroke shut off, so tabling that bug for now. + */ + /* + protected void textCharShapeImpl(char ch, float x, float y) { + // save the current stroke because it needs to be disabled + // while the text is being drawn + boolean strokeSaved = stroke; + stroke = false; + + // six element array received from the Java2D path iterator + float textPoints[] = new float[6]; + + // array passed to createGylphVector + char textArray[] = new char[] { ch }; + + Graphics2D graphics = (Graphics2D) parent.getGraphics(); + FontRenderContext frc = graphics.getFontRenderContext(); + Font font = textFont.getFont(); + GlyphVector gv = font.createGlyphVector(frc, textArray); + Shape shp = gv.getOutline(); + //PathIterator iter = shp.getPathIterator(null, 0.05); + PathIterator iter = shp.getPathIterator(null); + + glu.gluTessBeginPolygon(tobj, null); + // second param to gluTessVertex is for a user defined object that contains + // additional info about this point, but that's not needed for anything + + float lastX = 0; + float lastY = 0; + + // unfortunately the tesselator won't work properly unless a + // new array of doubles is allocated for each point. that bites ass, + // but also just reaffirms that in order to make things fast, + // display lists will be the way to go. + double vertex[]; + + final boolean DEBUG_OPCODES = false; //true; + + while (!iter.isDone()) { + int type = iter.currentSegment(textPoints); + switch (type) { + case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints + case PathIterator.SEG_LINETO: // 1 point + if (type == PathIterator.SEG_MOVETO) { + if (DEBUG_OPCODES) { + System.out.println("moveto\t" + + textPoints[0] + "\t" + textPoints[1]); + } + glu.gluTessBeginContour(tobj); + } else { + if (DEBUG_OPCODES) { + System.out.println("lineto\t" + + textPoints[0] + "\t" + textPoints[1]); + } + } + vertex = new double[] { + x + textPoints[0], y + textPoints[1], 0 + }; + glu.gluTessVertex(tobj, vertex, 0, vertex); + lastX = textPoints[0]; + lastY = textPoints[1]; + break; + + case PathIterator.SEG_QUADTO: // 2 points + if (DEBUG_OPCODES) { + System.out.println("quadto\t" + + textPoints[0] + "\t" + textPoints[1] + "\t" + + textPoints[2] + "\t" + textPoints[3]); + } + + for (int i = 1; i < bezierDetail; i++) { + float t = (float)i / (float)bezierDetail; + vertex = new double[] { + x + bezierPoint(lastX, + lastX + (float) ((textPoints[0] - lastX) * 2/3.0), + textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), + textPoints[2], t), + y + bezierPoint(lastY, + lastY + (float) ((textPoints[1] - lastY) * 2/3.0), + textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), + textPoints[3], t), + 0.0f + }; + glu.gluTessVertex(tobj, vertex, 0, vertex); + } + + lastX = textPoints[2]; + lastY = textPoints[3]; + break; + + case PathIterator.SEG_CUBICTO: // 3 points + if (DEBUG_OPCODES) { + System.out.println("cubicto\t" + + textPoints[0] + "\t" + textPoints[1] + "\t" + + textPoints[2] + "\t" + textPoints[3] + "\t" + + textPoints[4] + "\t" + textPoints[5]); + } + + for (int i = 1; i < bezierDetail; i++) { + float t = (float)i / (float)bezierDetail; + vertex = new double[] { + x + bezierPoint(lastX, textPoints[0], + textPoints[2], textPoints[4], t), + y + bezierPoint(lastY, textPoints[1], + textPoints[3], textPoints[5], t), 0 + }; + glu.gluTessVertex(tobj, vertex, 0, vertex); + } + + lastX = textPoints[4]; + lastY = textPoints[5]; + break; + + case PathIterator.SEG_CLOSE: + if (DEBUG_OPCODES) { + System.out.println("close"); + System.out.println(); + } + glu.gluTessEndContour(tobj); + break; + } + iter.next(); + } + glu.gluTessEndPolygon(tobj); + + // re-enable stroke if it was in use before + stroke = strokeSaved; + } + */ + + ////////////////////////////////////////////////////////////// // MATRIX STACK From d51819d5ef2fd0e0909e5430a9f5ceeeadaf6c4c Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 28 May 2013 22:58:47 -0400 Subject: [PATCH 46/46] Finished implementing shape mode text. --- core/src/processing/opengl/PGL.java | 49 ++++ .../processing/opengl/PGraphicsOpenGL.java | 273 +++--------------- 2 files changed, 86 insertions(+), 236 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index c840a2fac..6dab21fbd 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -26,6 +26,12 @@ package processing.opengl; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.PathIterator; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -1285,6 +1291,49 @@ public class PGL { } + /////////////////////////////////////////////////////////// + + // FontOutline interface + + + protected final static boolean SHAPE_TEXT_SUPPORTED = true; + + protected final static int SEG_MOVETO = PathIterator.SEG_MOVETO; + protected final static int SEG_LINETO = PathIterator.SEG_LINETO; + protected final static int SEG_QUADTO = PathIterator.SEG_QUADTO; + protected final static int SEG_CUBICTO = PathIterator.SEG_CUBICTO; + protected final static int SEG_CLOSE = PathIterator.SEG_CLOSE; + + protected FontOutline createFontOutline(char ch, Object font) { + return new FontOutline(ch, font); + } + + protected class FontOutline { + PathIterator iter; + + public FontOutline(char ch, Object font) { + char textArray[] = new char[] { ch }; + Graphics2D graphics = (Graphics2D) pg.parent.getGraphics(); + FontRenderContext frc = graphics.getFontRenderContext(); + GlyphVector gv = ((Font)font).createGlyphVector(frc, textArray); + Shape shp = gv.getOutline(); + iter = shp.getPathIterator(null); + } + + public boolean isDone() { + return iter.isDone(); + } + + public int currentSegment(float coords[]) { + return iter.currentSegment(coords); + } + + public void next() { + iter.next(); + } + } + + /////////////////////////////////////////////////////////// // Utility functions diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index be8b7669f..619b260f2 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -24,12 +24,6 @@ package processing.opengl; import processing.core.*; -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.GlyphVector; -import java.awt.geom.PathIterator; import java.net.URL; import java.nio.*; import java.util.*; @@ -3247,7 +3241,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected boolean textModeCheck(int mode) { - return mode == MODEL || mode == SHAPE; + return mode == MODEL || (mode == SHAPE && PGL.SHAPE_TEXT_SUPPORTED); } // public void textSize(float size) @@ -3325,7 +3319,6 @@ public class PGraphicsOpenGL extends PGraphics { } else if (textMode == SHAPE) { super.textLineImpl(buffer, start, stop, x, y); } - } @@ -3378,150 +3371,22 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void textCharShapeImpl(char ch, float x, float y) { - // save the current stroke because it needs to be disabled - // while the text is being drawn - boolean strokeSaved = stroke; - stroke = false; - - char textArray[] = new char[] { ch }; - Graphics2D graphics = (Graphics2D) parent.getGraphics(); - FontRenderContext frc = graphics.getFontRenderContext(); - Font font = (Font) textFont.getNative(); - GlyphVector gv = font.createGlyphVector(frc, textArray); - Shape shp = gv.getOutline(); - PathIterator iter = shp.getPathIterator(null); - - PApplet.println("Drawing model of character " + ch); - - // six element array received from the Java2D path iterator - float textPoints[] = new float[6]; - float lastX = 0; - float lastY = 0; - - beginShape(); - while (!iter.isDone()) { - int type = iter.currentSegment(textPoints); - switch (type) { - case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints - case PathIterator.SEG_LINETO: // 1 point - if (type == PathIterator.SEG_MOVETO) { - PApplet.println("moveto"); - beginContour(); - -// if (DEBUG_OPCODES) { -// System.out.println("moveto\t" + -// textPoints[0] + "\t" + textPoints[1]); -// } -// glu.gluTessBeginContour(tobj); - } - vertex(x + textPoints[0], y + textPoints[1]); - -// vertex = new double[] { -// x + textPoints[0], y + textPoints[1], 0 -// }; -// glu.gluTessVertex(tobj, vertex, 0, vertex); - lastX = textPoints[0]; - lastY = textPoints[1]; - break; - - case PathIterator.SEG_QUADTO: // 2 points - PApplet.println("quadto"); -// if (DEBUG_OPCODES) { -// System.out.println("quadto\t" + -// textPoints[0] + "\t" + textPoints[1] + "\t" + -// textPoints[2] + "\t" + textPoints[3]); -// } - - for (int i = 1; i < bezierDetail; i++) { - float t = (float)i / (float)bezierDetail; -// vertex = new double[] { -// x + bezierPoint(lastX, -// lastX + (float) ((textPoints[0] - lastX) * 2/3.0), -// textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), -// textPoints[2], t), -// y + bezierPoint(lastY, -// lastY + (float) ((textPoints[1] - lastY) * 2/3.0), -// textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), -// textPoints[3], t), -// 0.0f -// }; - vertex(x + bezierPoint(lastX, - lastX + (float) ((textPoints[0] - lastX) * 2/3.0), - textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), - textPoints[2], t), - y + bezierPoint(lastY, - lastY + (float) ((textPoints[1] - lastY) * 2/3.0), - textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), - textPoints[3], t)); - //glu.gluTessVertex(tobj, vertex, 0, vertex); - } - - lastX = textPoints[2]; - lastY = textPoints[3]; - break; - - case PathIterator.SEG_CUBICTO: // 3 points - PApplet.println("cubicto"); -// if (DEBUG_OPCODES) { -// System.out.println("cubicto\t" + -// textPoints[0] + "\t" + textPoints[1] + "\t" + -// textPoints[2] + "\t" + textPoints[3] + "\t" + -// textPoints[4] + "\t" + textPoints[5]); -// } - - for (int i = 1; i < bezierDetail; i++) { - float t = (float)i / (float)bezierDetail; - vertex(x + bezierPoint(lastX, textPoints[0], - textPoints[2], textPoints[4], t), - y + bezierPoint(lastY, textPoints[1], - textPoints[3], textPoints[5], t)); -// vertex = new double[] { -// x + bezierPoint(lastX, textPoints[0], -// textPoints[2], textPoints[4], t), -// y + bezierPoint(lastY, textPoints[1], -// textPoints[3], textPoints[5], t), 0 -// }; - //glu.gluTessVertex(tobj, vertex, 0, vertex); - } - - lastX = textPoints[4]; - lastY = textPoints[5]; - break; - - case PathIterator.SEG_CLOSE: - PApplet.println("close"); -// if (DEBUG_OPCODES) { -// System.out.println("close"); -// System.out.println(); -// } -// glu.gluTessEndContour(tobj); - endContour(); - break; - } - iter.next(); - PApplet.println(lastX + " " + lastY); - } - endShape(); - // glu.gluTessEndPolygon(tobj); - - PApplet.println("*********************"); - - // re-enable stroke if it was in use before - stroke = strokeSaved; - } - - // ORIGINAL CODE FROM 1.5.1 /** - * This uses the tesselation functions from GLU to handle triangulation - * to convert the character into a series of shapes. - *

+ * Ported from the implementation of textCharShapeImpl() in 1.5.1 + * * No attempt has been made to optimize this code *

- * TODO: Should instead override textPlacedImpl() because createGlyphVector - * takes a char array. Or better yet, cache the font on a per-char basis, - * so that it's not being re-tessellated each time, could make it into - * a display list which would be nice and speedy. + * TODO: Implement a FontShape class where each glyph is tessellated and + * stored inside a larger PShapeOpenGL object (which needs to be expanded as + * new glyphs are added and exceed the initial capacity in a similar way as + * the textures in FontTexture work). When a string of text is to be rendered + * in shape mode, then the correct sequences of vertex indices are computed + * (akin to the texcoords in the texture case) and used to draw only those + * parts of the PShape object that are required for the text. + *

+ * + * Some issues of the original implementation probably remain, so they are + * reproduced below: *

* Also a problem where some fonts seem to be a bit slight, as if the * control points aren't being mapped quite correctly. Probably doing @@ -3535,133 +3400,69 @@ public class PGraphicsOpenGL extends PGraphics { * tested with Akzidenz Grotesk Light). But this won't be visible * with the stroke shut off, so tabling that bug for now. */ - /* protected void textCharShapeImpl(char ch, float x, float y) { // save the current stroke because it needs to be disabled // while the text is being drawn boolean strokeSaved = stroke; stroke = false; + PGL.FontOutline outline = pgl.createFontOutline(ch, textFont.getNative()); + // six element array received from the Java2D path iterator float textPoints[] = new float[6]; - - // array passed to createGylphVector - char textArray[] = new char[] { ch }; - - Graphics2D graphics = (Graphics2D) parent.getGraphics(); - FontRenderContext frc = graphics.getFontRenderContext(); - Font font = textFont.getFont(); - GlyphVector gv = font.createGlyphVector(frc, textArray); - Shape shp = gv.getOutline(); - //PathIterator iter = shp.getPathIterator(null, 0.05); - PathIterator iter = shp.getPathIterator(null); - - glu.gluTessBeginPolygon(tobj, null); - // second param to gluTessVertex is for a user defined object that contains - // additional info about this point, but that's not needed for anything - float lastX = 0; float lastY = 0; - // unfortunately the tesselator won't work properly unless a - // new array of doubles is allocated for each point. that bites ass, - // but also just reaffirms that in order to make things fast, - // display lists will be the way to go. - double vertex[]; - - final boolean DEBUG_OPCODES = false; //true; - - while (!iter.isDone()) { - int type = iter.currentSegment(textPoints); + beginShape(); + while (!outline.isDone()) { + int type = outline.currentSegment(textPoints); switch (type) { - case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints - case PathIterator.SEG_LINETO: // 1 point - if (type == PathIterator.SEG_MOVETO) { - if (DEBUG_OPCODES) { - System.out.println("moveto\t" + - textPoints[0] + "\t" + textPoints[1]); - } - glu.gluTessBeginContour(tobj); - } else { - if (DEBUG_OPCODES) { - System.out.println("lineto\t" + - textPoints[0] + "\t" + textPoints[1]); - } + case PGL.SEG_MOVETO: // 1 point (2 vars) in textPoints + case PGL.SEG_LINETO: // 1 point + if (type == PGL.SEG_MOVETO) { + beginContour(); } - vertex = new double[] { - x + textPoints[0], y + textPoints[1], 0 - }; - glu.gluTessVertex(tobj, vertex, 0, vertex); + vertex(x + textPoints[0], y + textPoints[1]); lastX = textPoints[0]; lastY = textPoints[1]; break; - - case PathIterator.SEG_QUADTO: // 2 points - if (DEBUG_OPCODES) { - System.out.println("quadto\t" + - textPoints[0] + "\t" + textPoints[1] + "\t" + - textPoints[2] + "\t" + textPoints[3]); - } - + case PGL.SEG_QUADTO: // 2 points for (int i = 1; i < bezierDetail; i++) { float t = (float)i / (float)bezierDetail; - vertex = new double[] { - x + bezierPoint(lastX, + vertex(x + bezierPoint(lastX, lastX + (float) ((textPoints[0] - lastX) * 2/3.0), textPoints[2] + (float) ((textPoints[0] - textPoints[2]) * 2/3.0), textPoints[2], t), - y + bezierPoint(lastY, + y + bezierPoint(lastY, lastY + (float) ((textPoints[1] - lastY) * 2/3.0), textPoints[3] + (float) ((textPoints[1] - textPoints[3]) * 2/3.0), - textPoints[3], t), - 0.0f - }; - glu.gluTessVertex(tobj, vertex, 0, vertex); + textPoints[3], t)); } - lastX = textPoints[2]; lastY = textPoints[3]; break; - - case PathIterator.SEG_CUBICTO: // 3 points - if (DEBUG_OPCODES) { - System.out.println("cubicto\t" + - textPoints[0] + "\t" + textPoints[1] + "\t" + - textPoints[2] + "\t" + textPoints[3] + "\t" + - textPoints[4] + "\t" + textPoints[5]); - } - + case PGL.SEG_CUBICTO: // 3 points for (int i = 1; i < bezierDetail; i++) { float t = (float)i / (float)bezierDetail; - vertex = new double[] { - x + bezierPoint(lastX, textPoints[0], - textPoints[2], textPoints[4], t), - y + bezierPoint(lastY, textPoints[1], - textPoints[3], textPoints[5], t), 0 - }; - glu.gluTessVertex(tobj, vertex, 0, vertex); + vertex(x + bezierPoint(lastX, textPoints[0], + textPoints[2], textPoints[4], t), + y + bezierPoint(lastY, textPoints[1], + textPoints[3], textPoints[5], t)); } - lastX = textPoints[4]; lastY = textPoints[5]; break; - - case PathIterator.SEG_CLOSE: - if (DEBUG_OPCODES) { - System.out.println("close"); - System.out.println(); - } - glu.gluTessEndContour(tobj); + case PGL.SEG_CLOSE: + endContour(); break; } - iter.next(); + outline.next(); } - glu.gluTessEndPolygon(tobj); + endShape(); // re-enable stroke if it was in use before stroke = strokeSaved; } - */ //////////////////////////////////////////////////////////////