aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRami Santina <[email protected]>2011-04-08 18:06:21 +0300
committerRami Santina <[email protected]>2011-04-08 18:06:21 +0300
commit1218f8e4d4146831ed729cd1eac33d704529a072 (patch)
tree17bd30d50ed74ce5422e59168d6990f1983176fe
parente6de1dcd253ef4d6ba9f584b4ed3540c85c66d2c (diff)
parentc004a86e24fcc1cd026a7d1d52f61e8eafc8058a (diff)
Merge: merged with sgothel
-rw-r--r--make/config/jogl/gl-impl-CustomJavaCode-gl2_es2.java2
-rw-r--r--make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java8
-rw-r--r--make/config/jogl/gl-impl-CustomJavaCode-gles1.java8
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/Region.java11
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java3
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java81
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FBObject.java26
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java162
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java13
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java119
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java155
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java8
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java14
-rw-r--r--src/jogl/classes/javax/media/opengl/GLArrayData.java24
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java4
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java4
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java322
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java122
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java8
24 files changed, 735 insertions, 438 deletions
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl2_es2.java b/make/config/jogl/gl-impl-CustomJavaCode-gl2_es2.java
index d99f46ec1..bc2af092b 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gl2_es2.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gl2_es2.java
@@ -2,7 +2,7 @@
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
glVertexAttribPointer(array.getLocation(), array.getComponentNumber(), array.getComponentType(),
- array.getNormalized(), array.getStride(), array.getOffset());
+ array.getNormalized(), array.getStride(), array.getVBOOffset());
} else {
glVertexAttribPointer(array.getLocation(), array.getComponentNumber(), array.getComponentType(),
array.getNormalized(), array.getStride(), array.getBuffer());
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
index 6776feeb7..dbfa3ef4d 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java
@@ -358,7 +358,7 @@ native private ByteBuffer newDirectByteBuffer(long addr, long capacity);
public void glVertexPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -366,7 +366,7 @@ native private ByteBuffer newDirectByteBuffer(long addr, long capacity);
public void glColorPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -378,7 +378,7 @@ native private ByteBuffer newDirectByteBuffer(long addr, long capacity);
throw new GLException("Only 3 components per normal allowed");
}
if(array.isVBO()) {
- glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset());
+ glNormalPointer(array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -386,7 +386,7 @@ native private ByteBuffer newDirectByteBuffer(long addr, long capacity);
public void glTexCoordPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
index faff8b89f..0a0f87897 100644
--- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
+++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java
@@ -295,7 +295,7 @@ native private ByteBuffer newDirectByteBuffer(long addr, long capacity);
public void glVertexPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glVertexPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -303,7 +303,7 @@ public void glVertexPointer(GLArrayData array) {
public void glColorPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glColorPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -315,7 +315,7 @@ public void glNormalPointer(GLArrayData array) {
throw new GLException("Only 3 components per normal allowed");
}
if(array.isVBO()) {
- glNormalPointer(array.getComponentType(), array.getStride(), array.getOffset());
+ glNormalPointer(array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glNormalPointer(array.getComponentType(), array.getStride(), array.getBuffer());
}
@@ -323,7 +323,7 @@ public void glNormalPointer(GLArrayData array) {
public void glTexCoordPointer(GLArrayData array) {
if(array.getComponentNumber()==0) return;
if(array.isVBO()) {
- glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getOffset());
+ glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getVBOOffset());
} else {
glTexCoordPointer(array.getComponentNumber(), array.getComponentType(), array.getStride(), array.getBuffer());
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 40161f067..cc21af859 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -30,6 +30,8 @@ package com.jogamp.graph.curve;
import java.util.ArrayList;
import com.jogamp.graph.geom.AABBox;
+import jogamp.opengl.Debug;
+
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
@@ -45,14 +47,23 @@ import com.jogamp.opengl.util.PMVMatrix;
* @see RegionFactory, OutlineShape
*/
public interface Region {
+ public static final boolean DEBUG = Debug.debug("graph.curve");
+
/** The vertices index in an OGL object
*/
public static int VERTEX_ATTR_IDX = 0;
+ public static String VERTEX_ATTR_NAME = "v_position";
/** The Texture Coord index in an OGL object
*/
public static int TEXCOORD_ATTR_IDX = 1;
+ public static String TEXCOORD_ATTR_NAME = "texCoord";
+ /** The color index in an OGL object
+ */
+ public static int COLOR_ATTR_IDX = 2;
+ public static String COLOR_ATTR_NAME = "v_color";
+
/** single pass rendering, fast, but AA might not be perfect */
public static int SINGLE_PASS = 1;
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
index c9661b52a..ce3e83692 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -6,13 +6,14 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
import jogamp.opengl.Debug;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class Renderer {
- protected static final boolean DEBUG = Debug.debug("CurveRenderer");
+ protected static final boolean DEBUG = Region.DEBUG;
protected abstract boolean initImpl(GL2ES2 gl);
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
index 44d9a9be3..ee8dfb372 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -15,7 +15,6 @@ import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
public abstract class TextRenderer extends Renderer {
-
/**
* Create a Hardware accelerated Text Renderer.
* @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory.
@@ -50,6 +49,9 @@ public abstract class TextRenderer extends Renderer {
* @return the resulting GlyphString inclusive the generated region
*/
public GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) {
+ if(DEBUG) {
+ System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
+ }
AffineTransform affineTransform = new AffineTransform(pointFactory);
Path2D[] paths = new Path2D[str.length()];
@@ -77,32 +79,71 @@ public abstract class TextRenderer extends Renderer {
flushCache();
}
- public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); }
- public final int getCacheMaxSize() { return stringCacheMaxSize; }
+ /**
+ * Sets the cache limit for reusing GlyphString's and their Region.
+ * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited
+ *
+ * @param newLimit new cache size
+ *
+ * @see #DEFAULT_CACHE_LIMIT
+ */
+ public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; validateCache(0); }
+ public final int getCacheLimit() { return stringCacheLimit; }
+
+ /**
+ * @return the current utilized cache size, <= {@link #getCacheLimit()}
+ */
public final int getCacheSize() { return stringCacheArray.size(); }
- protected void validateCache(int space) {
- while ( getCacheSize() + space > getCacheMaxSize() ) {
- String key = stringCacheArray.remove(0);
- stringCacheMap.remove(key);
+ protected final void validateCache(int space) {
+ if ( getCacheLimit() > 0 ) {
+ while ( getCacheSize() + space > getCacheLimit() ) {
+ removeCachedGlyphString(0);
+ }
+ }
+ }
+
+ protected final GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
+ return stringCacheMap.get(getKey(font, str, fontSize));
+ }
+
+ protected final void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) {
+ if ( 0 != getCacheLimit() ) {
+ final String key = getKey(font, str, fontSize);
+ GlyphString oldGlyphString = stringCacheMap.put(key, glyphString);
+ if ( null == oldGlyphString ) {
+ // new entry ..
+ validateCache(1);
+ stringCacheArray.add(stringCacheArray.size(), key);
+ } /// else overwrite is nop ..
}
}
- protected GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
- final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
- return stringCacheMap.get(key);
+ protected final void removeCachedGlyphString(Font font, String str, int fontSize) {
+ final String key = getKey(font, str, fontSize);
+ GlyphString glyphString = stringCacheMap.remove(key);
+ if(null != glyphString) {
+ glyphString.destroy();
+ }
+ stringCacheArray.remove(key);
}
- protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) {
- final String key = font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
- validateCache(1);
- stringCacheMap.put(key, glyphString);
- stringCacheArray.add(stringCacheArray.size(), key);
+ protected final void removeCachedGlyphString(int idx) {
+ final String key = stringCacheArray.remove(idx);
+ final GlyphString glyphString = stringCacheMap.remove(key);
+ if(null != glyphString) {
+ glyphString.destroy();
+ }
+ }
+
+ protected final String getKey(Font font, String str, int fontSize) {
+ return font.getName(Font.NAME_UNIQUNAME) + "." + str.hashCode() + "." + fontSize;
}
- // Cache is adding at the end of the array
- public static final int DEFAULT_CACHE_SIZE = 32;
- private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_SIZE);
- private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_SIZE);
- private int stringCacheMaxSize = DEFAULT_CACHE_SIZE; // -1 unlimited, 0 off, >0 limited
+ /** Default cache limit, see {@link #setCacheLimit(int)} */
+ public static final int DEFAULT_CACHE_LIMIT = 256;
+
+ private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
+ private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
+ private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
index ad32b4ffe..c853bff15 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
@@ -39,17 +39,16 @@ public class FBObject {
private int width, height;
private int fb, fbo_tex, depth_rb, stencil_rb, vStatus;
private int texInternalFormat, texDataFormat, texDataType;
-
- public static final int ATTR_DEPTH = 1 << 0;
- public static final int ATTR_STENCIL = 1 << 1;
-
+ private boolean bound;
+
public FBObject(int width, int height) {
this.width = width;
this.height = height;
this.fb = 0;
this.fbo_tex = 0;
this.depth_rb = 0;
- this.stencil_rb = 0;
+ this.stencil_rb = 0;
+ this.bound = false;
}
public boolean validateStatus(GL gl) {
@@ -283,7 +282,6 @@ public class FBObject {
checkBound(true);
int name[] = new int[1];
gl.glGenRenderbuffers(1, name, 0);
- gl.glGenRenderbuffers(1, name, 0);
stencil_rb = name[0];
if(stencil_rb==0) {
throw new GLException("null generated stencilbuffer");
@@ -331,8 +329,6 @@ public class FBObject {
}
}
- boolean bound = false;
-
private final void checkBound(boolean shallBeBound) {
if(bound != shallBeBound) {
final String s0 = shallBeBound ? "not" : "already" ;
@@ -361,10 +357,14 @@ public class FBObject {
gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); // to use it ..
}
- public int getFBName() {
- return fb;
- }
- public int getTextureName() {
- return fbo_tex;
+ public final boolean isBound() { return bound; }
+ public final int getWidth() { return width; }
+ public final int getHeight() { return height; }
+ public final int getFBName() { return fb; }
+ public final int getTextureName() { return fbo_tex; }
+ public final int getStencilBuffer() { return stencil_rb; }
+ public final int getDepthBuffer() { return depth_rb; }
+ public final String toString() {
+ return "FBO[name "+fb+", size "+width+"x"+height+", tex "+fbo_tex+", depth "+depth_rb+", stencil "+stencil_rb+"]";
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index 4586d1df5..221385cc6 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -28,16 +28,26 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}) != null;
/**
+ * Create a client side buffer object, using a predefined fixed function array index
+ * and starting with a new created Buffer object with initialSize size
+ *
+ * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
+ * On profile ES2 the fixed function emulation will transform these calls to
+ * EnableVertexAttribArray and VertexAttribPointer calls,
+ * and a predefined vertex attribute variable name will be chosen.
+ *
+ * @param gl the current GL instance
* @param index The GL array index
* @param name The optional custom name for the GL array index, maybe null.
* If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
* This name might be used as the shader attribute name.
* @param comps The array component number
* @param dataType The array index GL data type
- * @param normalized Wheather the data shall be normalized
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
- */
+ */
public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized,
int initialSize)
throws GLException
@@ -45,10 +55,32 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, 0, 0);
+ adc.init(name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler, -1, -1, -1, -1);
return adc;
}
+ /**
+ * Create a client side buffer object, using a predefined fixed function array index
+ * and starting with a given Buffer object incl it's stride
+ *
+ * On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
+ * On profile ES2 the fixed function emulation will transform these calls to
+ * EnableVertexAttribArray and VertexAttribPointer calls,
+ * and a predefined vertex attribute variable name will be chosen.
+ *
+ * @param gl the current GL instance
+ * @param index The GL array index
+ * @param name The optional custom name for the GL array index, maybe null.
+ * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
+ * This name might be used as the shader attribute name.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ *
+ * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
+ */
public static GLArrayDataClient createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized,
int stride, Buffer buffer)
throws GLException
@@ -56,10 +88,21 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, 0, 0);
+ adc.init(name, index, comps, dataType, normalized, stride, buffer, comps*comps, false, glArrayHandler, -1, -1, -1, -1);
return adc;
}
+ /**
+ * Create a client side buffer object, using a custom GLSL array attribute name
+ * and starting with a new created Buffer object with initialSize size
+ *
+ * @param gl the current GL instance
+ * @param name The custom name for the GL attribute.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
+ */
public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
int initialSize)
throws GLException
@@ -71,10 +114,22 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, 0, 0);
+ adc.init(name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler, -1, -1, -1, -1);
return adc;
}
+ /**
+ * Create a client side buffer object, using a custom GLSL array attribute name
+ * and starting with a given Buffer object incl it's stride
+ *
+ * @param gl the current GL instance
+ * @param name The custom name for the GL attribute.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ */
public static GLArrayDataClient createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
int stride, Buffer buffer)
throws GLException
@@ -86,7 +141,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
GLArrayDataClient adc = new GLArrayDataClient();
GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, 0, 0);
+ adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, true, glArrayHandler, -1, -1, -1, -1);
return adc;
}
@@ -94,21 +149,20 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
// Data read access
//
- public final boolean isBufferWritten() { return bufferWritten; }
+ public final boolean isVBOWritten() { return bufferWritten; }
public final boolean sealed() { return sealed; }
- public int getBufferUsage() { return -1; }
-
//
// Data and GL state modification ..
//
- public final void setBufferWritten(boolean written) { bufferWritten=written; }
+ public final void setVBOWritten(boolean written) { bufferWritten=written; }
public void destroy(GL gl) {
reset(gl);
buffer=null;
+ valid=false;
}
public void reset(GL gl) {
@@ -131,10 +185,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
public void enableBuffer(GL gl, boolean enable) {
- if(enableBufferAlways && enable) {
- bufferEnabled = false;
- }
- if( bufferEnabled != enable && components>0 ) {
+ if( enableBufferAlways || bufferEnabled != enable ||
+ getVBOName() != gl.glGetBoundBuffer(getVBOTarget()) ) {
if(enable) {
checkSeal(true);
if(null!=buffer) {
@@ -252,7 +304,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
", sealed "+sealed+
", bufferEnabled "+bufferEnabled+
", bufferWritten "+bufferWritten+
- ", buffer "+buffer+
+ ", buffer "+buffer+
+ ", valid "+valid+
"]";
}
@@ -260,55 +313,58 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
protected final boolean growBufferIfNecessary(int spare) {
if(buffer==null || buffer.remaining()<spare) {
- growBuffer(initialSize);
+ growBuffer(Math.max(initialSize, spare));
return true;
}
return false;
}
- protected final void growBuffer(int additional) {
- if(sealed || 0==additional || 0==components) return;
+ protected final void growBuffer(int additional) {
+ if(!valid || sealed) {
+ throw new GLException("Invalid state: "+this);
+ }
// add the stride delta
additional += (additional/components)*(strideL-components);
- if(components>0) {
- int osize = (buffer!=null)?buffer.capacity():0;
- if(clazz==ByteBuffer.class) {
- ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components );
- if(buffer!=null) {
- buffer.flip();
- newBBuffer.put((ByteBuffer)buffer);
- }
- buffer = newBBuffer;
- } else if(clazz==ShortBuffer.class) {
- ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components );
- if(buffer!=null) {
- buffer.flip();
- newSBuffer.put((ShortBuffer)buffer);
- }
- buffer = newSBuffer;
- } else if(clazz==IntBuffer.class) {
- IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components );
- if(buffer!=null) {
- buffer.flip();
- newIBuffer.put((IntBuffer)buffer);
- }
- buffer = newIBuffer;
- } else if(clazz==FloatBuffer.class) {
- FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components );
- if(buffer!=null) {
- buffer.flip();
- newFBuffer.put((FloatBuffer)buffer);
- }
- buffer = newFBuffer;
- } else {
- throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this);
+ int osize = (buffer!=null)?buffer.capacity():0;
+ if(clazz==ByteBuffer.class) {
+ ByteBuffer newBBuffer = Buffers.newDirectByteBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newBBuffer.put((ByteBuffer)buffer);
+ }
+ buffer = newBBuffer;
+ } else if(clazz==ShortBuffer.class) {
+ ShortBuffer newSBuffer = Buffers.newDirectShortBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newSBuffer.put((ShortBuffer)buffer);
}
+ buffer = newSBuffer;
+ } else if(clazz==IntBuffer.class) {
+ IntBuffer newIBuffer = Buffers.newDirectIntBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newIBuffer.put((IntBuffer)buffer);
+ }
+ buffer = newIBuffer;
+ } else if(clazz==FloatBuffer.class) {
+ FloatBuffer newFBuffer = Buffers.newDirectFloatBuffer( (osize+additional) * components );
+ if(buffer!=null) {
+ buffer.flip();
+ newFBuffer.put((FloatBuffer)buffer);
+ }
+ buffer = newFBuffer;
+ } else {
+ throw new GLException("Given Buffer Class not supported: "+clazz+":\n\t"+this);
}
}
protected final void checkSeal(boolean test) throws GLException {
+ if(!valid) {
+ throw new GLException("Invalid state: "+this);
+ }
if(sealed!=test) {
if(test) {
throw new GLException("Not Sealed yet, seal first:\n\t"+this);
@@ -320,11 +376,11 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data,
int initialSize, boolean isVertexAttribute, GLArrayHandler handler,
- int vboName, long bufferOffset)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
super.init(name, index, comps, dataType, normalized, stride, data, isVertexAttribute,
- vboName, bufferOffset);
+ vboName, vboOffset, vboUsage, vboTarget);
this.initialSize = initialSize;
this.glArrayHandler = handler;
@@ -333,7 +389,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
this.bufferEnabled=false;
this.enableBufferAlways=false;
this.bufferWritten=false;
- if(null==buffer) {
+ if(null==buffer && initialSize>0) {
growBuffer(initialSize);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
index 0f8ed27be..32fc5a2a2 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
@@ -16,19 +16,14 @@ public interface GLArrayDataEditable extends GLArrayData {
public boolean sealed();
/**
- * The VBO buffer usage, if it's an VBO, otherwise -1
+ * Is the buffer written to the VBO ?
*/
- public int getBufferUsage();
+ public boolean isVBOWritten();
/**
- * Is the buffer written to the GPU ?
+ * Marks the buffer written to the VBO
*/
- public boolean isBufferWritten();
-
- /**
- * Marks the buffer written to the GPU
- */
- public void setBufferWritten(boolean written);
+ public void setVBOWritten(boolean written);
//
// Data and GL state modification ..
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
index c061e212a..8504aeae3 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
@@ -2,6 +2,7 @@
package com.jogamp.opengl.util;
import javax.media.opengl.*;
+
import java.nio.*;
import com.jogamp.opengl.util.glsl.*;
@@ -13,26 +14,31 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
//
/**
- * Create a VBOBuffer object, using a predefined fixed function array index
+ * Create a VBO, using a predefined fixed function array index
* and starting with a given Buffer object incl it's stride
*
* On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
* On profile ES2 the fixed function emulation will transform these calls to
* EnableVertexAttribArray and VertexAttribPointer calls,
- * and a predefined vertex attribute variable name will be choosen.
+ * and a predefined vertex attribute variable name will be chosen.
*
+ * @param gl the current GL instance
* @param index The GL array index
* @param name The optional custom name for the GL array index, maybe null.
* If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
* This name might be used as the shader attribute name.
* @param comps The array component number
* @param dataType The array index GL data type
- * @param normalized Wheather the data shall be normalized
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer, int vboBufferUsage)
+ int stride, Buffer buffer, int vboUsage, int vboTarget)
throws GLException
{
gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
@@ -40,23 +46,35 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
ads.init(gl, name, index, comps, dataType, normalized, stride, buffer, buffer.limit(), false, glArrayHandler,
- 0, 0, vboBufferUsage);
+ 0, 0, vboUsage, vboTarget);
return ads;
}
/**
- * Create a VBOBuffer object, using a predefined fixed function array index
+ * Create a VBO, using a predefined fixed function array index
* and starting with a new created Buffer object with initialSize size
*
* On profiles GL2 and ES1 the fixed function pipeline behavior is as expected.
* On profile ES2 the fixed function emulation will transform these calls to
* EnableVertexAttribArray and VertexAttribPointer calls,
- * and a predefined vertex attribute variable name will be choosen.
+ * and a predefined vertex attribute variable name will be chosen.
+ *
+ * @param gl the current GL instance
+ * @param index The GL array index
+ * @param name The optional custom name for the GL array index, maybe null.
+ * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'.
+ * This name might be used as the shader attribute name.
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*
* @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
*/
public static GLArrayDataServer createFixed(GL gl, int index, String name, int comps, int dataType, boolean normalized,
- int initialSize, int vboBufferUsage)
+ int initialSize, int vboUsage, int vboTarget)
throws GLException
{
gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
@@ -64,18 +82,25 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
GLArrayDataServer ads = new GLArrayDataServer();
GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
ads.init(gl, name, index, comps, dataType, normalized, 0, null, initialSize, false, glArrayHandler,
- 0, 0, vboBufferUsage);
+ 0, 0, vboUsage, vboTarget);
return ads;
}
/**
- * Create a VBOBuffer object, using a custom GLSL array attribute name
+ * Create a VBO, using a custom GLSL array attribute name
* and starting with a new created Buffer object with initialSize size
*
- * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
+ * @param gl the current GL instance
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param initialSize
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*/
public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int initialSize, int vboBufferUsage)
+ int initialSize, int vboUsage, int vboTarget)
throws GLException
{
if(!gl.hasGLSL()) {
@@ -84,20 +109,33 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true);
GLArrayDataServer ads = new GLArrayDataServer();
- GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
+ GLArrayHandler glArrayHandler;
+ if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) {
+ glArrayHandler = new GLDataArrayHandler(ads);
+ } else {
+ glArrayHandler = new GLSLArrayHandler(ads);
+ }
ads.init(gl, name, -1, comps, dataType, normalized, 0, null, initialSize, true, glArrayHandler,
- 0, 0, vboBufferUsage);
+ 0, 0, vboUsage, vboTarget);
return ads;
}
/**
- * Create a VBOBuffer object, using a custom GLSL array attribute name
+ * Create a VBO, using a custom GLSL array attribute name
* and starting with a given Buffer object incl it's stride
*
- * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int)
+ * @param gl the current GL instance
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*/
public static GLArrayDataServer createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer, int vboBufferUsage)
+ int stride, Buffer buffer, int vboUsage, int vboTarget)
throws GLException
{
if(!gl.hasGLSL()) {
@@ -106,9 +144,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
gl.getGLProfile().isValidArrayDataType(-1, comps, dataType, true, true);
GLArrayDataServer ads = new GLArrayDataServer();
- GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
+ GLArrayHandler glArrayHandler;
+ if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) {
+ glArrayHandler = new GLDataArrayHandler(ads);
+ } else {
+ glArrayHandler = new GLSLArrayHandler(ads);
+ }
ads.init(gl, name, -1, comps, dataType, normalized, stride, buffer, buffer.limit(), true, glArrayHandler,
- 0, 0, vboBufferUsage);
+ 0, 0, vboUsage, vboTarget);
return ads;
}
@@ -116,8 +159,6 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
// Data matters GLArrayData
//
- public int getBufferUsage() { return vboBufferUsage; }
-
//
// Data and GL state modification ..
//
@@ -141,9 +182,9 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* switch to client side data one
* Only possible if buffer is defined.
*/
- public void setVBOUsage(boolean vboUsage) {
+ public void setVBOEnabled(boolean vboUsage) {
checkSeal(false);
- super.setVBOUsage(vboUsage);
+ super.setVBOEnabled(vboUsage);
}
public String toString() {
@@ -157,14 +198,16 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
", initialSize "+initialSize+
- ", vboBufferUsage "+vboBufferUsage+
- ", vboUsage "+vboUsage+
+ ", vboUsage 0x"+Integer.toHexString(vboUsage)+
+ ", vboTarget 0x"+Integer.toHexString(vboTarget)+
+ ", vboEnabled "+vboEnabled+
", vboName "+vboName+
", sealed "+sealed+
", bufferEnabled "+bufferEnabled+
", bufferWritten "+bufferWritten+
", buffer "+buffer+
- ", offset "+bufferOffset+
+ ", offset "+vboOffset+
+ ", valid "+valid+
"]";
}
@@ -175,35 +218,21 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
protected void init(GL gl, String name, int index, int comps, int dataType, boolean normalized,
int stride, Buffer data, int initialSize, boolean isVertexAttribute,
GLArrayHandler glArrayHandler,
- int vboName, long bufferOffset, int vboBufferUsage)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
super.init(name, index, comps, dataType, normalized, stride, data, initialSize, isVertexAttribute, glArrayHandler,
- vboName, bufferOffset);
-
- vboUsage=true;
-
- if( ! (gl.isGL2ES2() && vboBufferUsage==GL2ES2.GL_STREAM_DRAW) ) {
- switch(vboBufferUsage) {
- case -1: // nop
- case GL.GL_STATIC_DRAW:
- case GL.GL_DYNAMIC_DRAW:
- break;
- default:
- throw new GLException("invalid vboBufferUsage: "+vboBufferUsage+":\n\t"+this);
- }
- }
- this.vboBufferUsage=vboBufferUsage;
+ vboName, vboOffset, vboUsage, vboTarget);
+
+ vboEnabled=true;
}
protected void init_vbo(GL gl) {
- if(vboUsage && vboName==0) {
+ if(vboEnabled && vboName==0) {
int[] tmp = new int[1];
gl.glGenBuffers(1, tmp, 0);
vboName = tmp[0];
}
}
-
- protected int vboBufferUsage;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
index 88a8603f9..f2694d39c 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
@@ -9,21 +9,55 @@ import java.nio.*;
public class GLArrayDataWrapper implements GLArrayData {
+ /**
+ * Create a VBO, using a predefined fixed function array index, wrapping the given data.
+ *
+ * @param gl the current GL instance
+ * @param index The GL array index
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboName
+ * @param vboOffset
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @return the new create instance
+ * @throws GLException
+ */
public static GLArrayDataWrapper createFixed(GL gl, int index, int comps, int dataType, boolean normalized,
int stride, Buffer buffer,
- int vboName, long bufferOffset)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
gl.getGLProfile().isValidArrayDataType(index, comps, dataType, false, true);
GLArrayDataWrapper adc = new GLArrayDataWrapper();
adc.init(null, index, comps, dataType, normalized, stride, buffer, false,
- vboName, bufferOffset);
+ vboName, vboOffset, vboUsage, vboTarget);
return adc;
}
+ /**
+ * Create a VBO, using a custom GLSL array attribute name, wrapping the given data.
+ *
+ * @param gl the current GL instance
+ * @param name The custom name for the GL attribute, maybe null if gpuBufferTarget is {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @param comps The array component number
+ * @param dataType The array index GL data type
+ * @param normalized Whether the data shall be normalized
+ * @param stride
+ * @param buffer the user define data
+ * @param vboName
+ * @param vboOffset
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ * @return the new create instance
+ * @throws GLException
+ */
public static GLArrayDataWrapper createGLSL(GL gl, String name, int comps, int dataType, boolean normalized,
- int stride, Buffer buffer,
- int vboName, long bufferOffset)
+ int stride, Buffer buffer,
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
if(!gl.hasGLSL()) {
@@ -33,7 +67,7 @@ public class GLArrayDataWrapper implements GLArrayData {
GLArrayDataWrapper adc = new GLArrayDataWrapper();
adc.init(name, -1, comps, dataType, normalized, stride, buffer, true,
- vboName, bufferOffset);
+ vboName, vboOffset, vboUsage, vboTarget);
return adc;
}
@@ -51,12 +85,16 @@ public class GLArrayDataWrapper implements GLArrayData {
public final String getName() { return name; }
- public final long getOffset() { return vboUsage?bufferOffset:-1; }
+ public final long getVBOOffset() { return vboEnabled?vboOffset:-1; }
- public final int getVBOName() { return vboUsage?vboName:-1; }
+ public final int getVBOName() { return vboEnabled?vboName:-1; }
- public final boolean isVBO() { return vboUsage; }
+ public final boolean isVBO() { return vboEnabled; }
+ public final int getVBOUsage() { return vboEnabled?vboUsage:-1; }
+
+ public final int getVBOTarget() { return vboEnabled?vboTarget:-1; }
+
public final Buffer getBuffer() { return buffer; }
public final int getComponentNumber() { return components; }
@@ -91,14 +129,11 @@ public class GLArrayDataWrapper implements GLArrayData {
public final Class getBufferClass() { return clazz; }
public void destroy(GL gl) {
- this.buffer = null;
- this.components = 0;
- this.stride=0;
- this.strideB=0;
- this.strideL=0;
- this.vboName=0;
- this.vboUsage=false;
- this.bufferOffset=0;
+ buffer = null;
+ vboName=0;
+ vboEnabled=false;
+ vboOffset=-1;
+ valid = false;
}
public String toString() {
@@ -112,9 +147,12 @@ public class GLArrayDataWrapper implements GLArrayData {
", components "+components+
", stride "+stride+"u "+strideB+"b "+strideL+"c"+
", buffer "+buffer+
- ", offset "+bufferOffset+
- ", vboUsage "+vboUsage+
+ ", offset "+vboOffset+
+ ", vboUsage 0x"+Integer.toHexString(vboUsage)+
+ ", vboTarget 0x"+Integer.toHexString(vboTarget)+
+ ", vboEnabled "+vboEnabled+
", vboName "+vboName+
+ ", valid "+valid+
"]";
}
@@ -140,28 +178,60 @@ public class GLArrayDataWrapper implements GLArrayData {
name = newName;
}
- public void setVBOUsage(boolean vboUsage) {
- this.vboUsage=vboUsage;
+ /**
+ * Enable or disable use of VBO.
+ * Only possible if a VBO buffer name is defined.
+ * @see #setVBOName(int)
+ */
+ public void setVBOEnabled(boolean vboEnabled) {
+ this.vboEnabled=vboEnabled;
}
+ /**
+ * Set the VBO buffer name, if valid (>0) enable use of VBO
+ * @see #setVBOEnabled(boolean)
+ */
public void setVBOName(int vboName) {
this.vboName=vboName;
- setVBOUsage(vboName>0);
+ setVBOEnabled(vboName>0);
+ }
+
+ /**
+ * @param vboUsage {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ */
+ public void setVBOUsage(int vboUsage) {
+ this.vboUsage = vboUsage;
}
+
+ /**
+ * @param vboTarget either {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ */
+ public void setVBOTarget(int vboTarget) {
+ this.vboTarget = vboTarget;
+ }
protected void init(String name, int index, int comps, int dataType, boolean normalized, int stride, Buffer data,
boolean isVertexAttribute,
- int vboName, long bufferOffset)
+ int vboName, long vboOffset, int vboUsage, int vboTarget)
throws GLException
{
this.isVertexAttribute = isVertexAttribute;
this.index = index;
this.location = -1;
// We can't have any dependence on the FixedFuncUtil class here for build bootstrapping reasons
- this.name = (null==name)?FixedFuncPipeline.getPredefinedArrayIndexName(index):name;
- if(null==this.name) {
- throw new GLException("Not a valid GL array index: "+index);
+
+ if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) {
+ // ok ..
+ } else if( GL.GL_ARRAY_BUFFER == vboTarget ) {
+ // check name ..
+ this.name = ( null == name ) ? FixedFuncPipeline.getPredefinedArrayIndexName(index) : name ;
+ if(null == this.name ) {
+ throw new GLException("Not a valid array buffer index: "+index);
+ }
+ } else if( 0 <= vboTarget ) {
+ throw new GLException("Invalid GPUBuffer target: 0x"+Integer.toHexString(vboTarget));
}
+
this.dataType = dataType;
this.clazz = getBufferClass(dataType);
switch(dataType) {
@@ -184,17 +254,42 @@ public class GLArrayDataWrapper implements GLArrayData {
throw new GLException("stride ("+stride+") not a multiple of bpc "+bpc);
}
this.buffer = data;
+ if(0 >= comps) {
+ throw new GLException("Invalid number of components: " + comps);
+ }
this.components = comps;
this.stride=stride;
this.strideB=(0==stride)?comps*bpc:stride;
this.strideL=(0==stride)?comps:strideB/bpc;
this.vboName=vboName;
- this.vboUsage=vboName>0;
- this.bufferOffset=bufferOffset;
+ this.vboEnabled=vboName>0;
+ this.vboOffset=vboOffset;
+
+ switch(vboUsage) {
+ case -1: // nop
+ case GL.GL_STATIC_DRAW:
+ case GL.GL_DYNAMIC_DRAW:
+ case GL2ES2.GL_STREAM_DRAW:
+ break;
+ default:
+ throw new GLException("invalid gpuBufferUsage: "+vboUsage+":\n\t"+this);
+ }
+ switch(vboTarget) {
+ case -1: // nop
+ case GL.GL_ARRAY_BUFFER:
+ case GL.GL_ELEMENT_ARRAY_BUFFER:
+ break;
+ default:
+ throw new GLException("invalid gpuBufferTarget: "+vboTarget+":\n\t"+this);
+ }
+ this.vboUsage=vboUsage;
+ this.vboTarget=vboTarget;
+ this.valid=true;
}
protected GLArrayDataWrapper() { }
+ protected boolean valid;
protected int index;
protected int location;
protected String name;
@@ -208,8 +303,10 @@ public class GLArrayDataWrapper implements GLArrayData {
protected Buffer buffer;
protected boolean isVertexAttribute;
- protected long bufferOffset;
+ protected long vboOffset;
protected int vboName;
- protected boolean vboUsage;
+ protected boolean vboEnabled;
+ protected int vboUsage;
+ protected int vboTarget;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
new file mode 100644
index 000000000..74d49aa6c
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLDataArrayHandler.java
@@ -0,0 +1,41 @@
+
+package com.jogamp.opengl.util;
+
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+import com.jogamp.opengl.util.*;
+import java.nio.*;
+
+public class GLDataArrayHandler implements GLArrayHandler {
+ private GLArrayDataEditable ad;
+
+ public GLDataArrayHandler(GLArrayDataEditable ad) {
+ this.ad = ad;
+ }
+
+ public void enableBuffer(GL gl, boolean enable) {
+ GLPointerFunc glp = gl.getGL2ES1();
+ if(enable) {
+ Buffer buffer = ad.getBuffer();
+
+ if(ad.isVBO()) {
+ // always bind and refresh the VBO mgr,
+ // in case more than one gl*Pointer objects are in use
+ gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
+ if(!ad.isVBOWritten()) {
+ if(null!=buffer) {
+ gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
+ }
+ ad.setVBOWritten(true);
+ }
+ } else if(null!=buffer) {
+ ad.setVBOWritten(true);
+ }
+ } else {
+ if(ad.isVBO()) {
+ gl.glBindBuffer(ad.getVBOTarget(), 0);
+ }
+ }
+ }
+}
+
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
index f0f5ea896..a825ca690 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLFixedArrayHandler.java
@@ -13,7 +13,7 @@ public class GLFixedArrayHandler implements GLArrayHandler {
this.ad = ad;
}
- protected final void passArrayPointer(GLPointerFunc gl) {
+ private final void passArrayPointer(GLPointerFunc gl) {
switch(ad.getIndex()) {
case GLPointerFunc.GL_VERTEX_ARRAY:
gl.glVertexPointer(ad);
@@ -42,21 +42,21 @@ public class GLFixedArrayHandler implements GLArrayHandler {
if(ad.isVBO()) {
// always bind and refresh the VBO mgr,
// in case more than one gl*Pointer objects are in use
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName());
- if(!ad.isBufferWritten()) {
+ gl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
+ if(!ad.isVBOWritten()) {
if(null!=buffer) {
- gl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage());
+ gl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
}
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
passArrayPointer(glp);
} else if(null!=buffer) {
passArrayPointer(glp);
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
} else {
if(ad.isVBO()) {
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ gl.glBindBuffer(ad.getVBOTarget(), 0);
}
glp.glDisableClientState(ad.getIndex());
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index d9fce6e6a..be15dfb59 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -861,25 +861,25 @@ public class ImmModeSink {
if(vComps>0) {
vArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, vComps, vDataType, false,
- 0, vertexArray, 0, vOffset);
+ 0, vertexArray, 0, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
} else {
vArrayData = null;
}
if(cComps>0) {
cArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_COLOR_ARRAY, cComps, cDataType, false,
- 0, colorArray, 0, cOffset);
+ 0, colorArray, 0, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
} else {
cArrayData = null;
}
if(nComps>0) {
nArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_NORMAL_ARRAY, nComps, nDataType, false,
- 0, normalArray, 0, nOffset);
+ 0, normalArray, 0, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
} else {
nArrayData = null;
}
if(tComps>0) {
tArrayData = GLArrayDataWrapper.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, tComps, tDataType, false,
- 0, textCoordArray, 0, tOffset);
+ 0, textCoordArray, 0, tOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
} else {
tArrayData = null;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
index 95a550ab6..1ce39d557 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
@@ -39,7 +39,7 @@ public class GLSLArrayHandler implements GLArrayHandler {
this.ad = ad;
}
- protected final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) {
+ private final void passVertexAttribPointer(GL2ES2 gl, ShaderState st) {
st.glVertexAttribPointer(gl, ad);
}
@@ -61,21 +61,21 @@ public class GLSLArrayHandler implements GLArrayHandler {
if(ad.isVBO()) {
// always bind and refresh the VBO mgr,
// in case more than one gl*Pointer objects are in use
- glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, ad.getVBOName());
- if(!ad.isBufferWritten()) {
+ glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
+ if(!ad.isVBOWritten()) {
if(null!=buffer) {
- glsl.glBufferData(GL.GL_ARRAY_BUFFER, buffer.limit() * ad.getComponentSize(), buffer, ad.getBufferUsage());
+ glsl.glBufferData(ad.getVBOTarget(), buffer.limit() * ad.getComponentSize(), buffer, ad.getVBOUsage());
}
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
passVertexAttribPointer(glsl, st);
} else if(null!=buffer) {
passVertexAttribPointer(glsl, st);
- ad.setBufferWritten(true);
+ ad.setVBOWritten(true);
}
} else {
if(ad.isVBO()) {
- glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ glsl.glBindBuffer(ad.getVBOTarget(), 0);
}
st.glDisableVertexAttribArray(glsl, ad.getName());
}
diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java
index 6c8122f27..b449ce232 100644
--- a/src/jogl/classes/javax/media/opengl/GLArrayData.java
+++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java
@@ -37,7 +37,6 @@ import java.nio.*;
*
*/
public interface GLArrayData {
-
/**
* Returns true if this data set is intended for a GLSL vertex shader attribute,
* otherwise false, ie intended for fixed function vertex pointer
@@ -81,23 +80,36 @@ public interface GLArrayData {
public void setLocation(int v);
/**
- * Determines wheather the data is server side (VBO),
+ * Determines whether the data is server side (VBO) and enabled,
* or a client side array (false).
*/
public boolean isVBO();
/**
- * The offset, if it's an VBO, otherwise -1
+ * The VBO buffer offset or -1 if not a VBO
*/
- public long getOffset();
+ public long getVBOOffset();
/**
- * The VBO name, if it's an VBO, otherwise -1
+ * The VBO name or -1 if not a VBO
*/
public int getVBOName();
/**
- * The Buffer holding the data, may be null in case of VBO
+ * The VBO usage or -1 if not a VBO
+ * @return -1 if not a GPU buffer, otherwise {@link GL2ES2#GL_STREAM_DRAW}, {@link GL#GL_STATIC_DRAW} or {@link GL#GL_DYNAMIC_DRAW}
+ */
+ public int getVBOUsage();
+
+ /**
+ * The VBO target or -1 if not a VBO
+ * @return -1 if not a GPU buffer, otherwise {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
+ */
+ public int getVBOTarget();
+
+
+ /**
+ * The Buffer holding the data, may be null if a GPU buffer without client bound data
*/
public Buffer getBuffer();
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 9208afc24..34b46a8b5 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -85,8 +85,8 @@ public class RegionRendererImpl01 extends RegionRenderer {
sp.add(rsFp);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, "v_position");
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, "texCoord");
+ gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, Region.VERTEX_ATTR_NAME);
+ gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, Region.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("RegionRenderer: Couldn't link program: "+sp);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
index 01572de58..69a8e470b 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -87,8 +87,8 @@ public class TextRendererImpl01 extends TextRenderer {
sp.add(rsFp);
sp.init(gl);
- gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, "v_position");
- gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, "texCoord");
+ gl.glBindAttribLocation(sp.program(), Region.VERTEX_ATTR_IDX, Region.VERTEX_ATTR_NAME);
+ gl.glBindAttribLocation(sp.program(), Region.TEXCOORD_ATTR_IDX, Region.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 94293a947..8e487bb29 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -27,9 +27,6 @@
*/
package jogamp.graph.curve.opengl;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.ShortBuffer;
import java.util.ArrayList;
import javax.media.opengl.GL2ES2;
@@ -39,7 +36,7 @@ import javax.media.opengl.GLContext;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
-import com.jogamp.common.nio.Buffers;
+import jogamp.opengl.Debug;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Triangle;
@@ -47,20 +44,23 @@ import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.curve.Region;
import com.jogamp.opengl.util.FBObject;
+import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
-public class VBORegion2PES2 implements Region{
- private int numVertices = 0;
- private IntBuffer vboIds;
-
- private IntBuffer t_vboIds;
-
+public class VBORegion2PES2 implements Region {
+ private int numVertices = 0;
+
private ArrayList<Triangle> triangles = new ArrayList<Triangle>();
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- private GLContext context;
+ private GLArrayDataServer verticeTxtAttr = null;
+ private GLArrayDataServer texCoordTxtAttr = null;
+ private GLArrayDataServer indicesTxt = null;
+ private GLArrayDataServer verticeFboAttr = null;
+ private GLArrayDataServer texCoordFboAttr = null;
+ private GLArrayDataServer indicesFbo = null;
- private int numBuffers = 3;
+ private GLContext context;
private boolean flipped = false;
@@ -77,14 +77,50 @@ public class VBORegion2PES2 implements Region{
public VBORegion2PES2(GLContext context, ShaderState st){
this.context =context;
this.st = st;
+
+ GL2ES2 gl = context.getGL().getGL2ES2();
+
+ indicesFbo = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
+ 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
+ indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
+ indicesFbo.seal(gl, true);
+
+ texCoordFboAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
+ 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ texCoordFboAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
+ texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
+ texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
+ texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
+ texCoordFboAttr.putf(6); texCoordFboAttr.putf(5);
+ texCoordFboAttr.seal(gl, true);
+
+ verticeFboAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
+ 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ verticeFboAttr.setLocation(Region.VERTEX_ATTR_IDX);
+ verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
+ verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
+ verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
+ verticeFboAttr.putf(0f); indicesFbo.putf(0f); indicesFbo.putf(0f);
+ verticeFboAttr.seal(gl, true);
+
+ verticeFboAttr.enableBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ indicesFbo.enableBuffer(gl, false);
+ if(DEBUG) {
+ System.err.println("VBORegion2PES2 Create: " + this);
+ }
}
public void update(){
- box = new AABBox();
-
GL2ES2 gl = context.getGL().getGL2ES2();
- ShortBuffer indicies = Buffers.newDirectShortBuffer(triangles.size() * 3);
+ destroyTxtAttr(gl);
+
+ box = new AABBox();
+
+ indicesTxt = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
+ triangles.size(), GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
for(Triangle t:triangles){
if(t.getVertices()[0].getId() == Integer.MAX_VALUE){
t.getVertices()[0].setId(numVertices++);
@@ -95,83 +131,71 @@ public class VBORegion2PES2 implements Region{
vertices.add(t.getVertices()[1]);
vertices.add(t.getVertices()[2]);
- indicies.put((short) t.getVertices()[0].getId());
- indicies.put((short) t.getVertices()[1].getId());
- indicies.put((short) t.getVertices()[2].getId());
+ indicesTxt.puts((short) t.getVertices()[0].getId());
+ indicesTxt.puts((short) t.getVertices()[1].getId());
+ indicesTxt.puts((short) t.getVertices()[2].getId());
}
else{
Vertex v1 = t.getVertices()[0];
Vertex v2 = t.getVertices()[1];
Vertex v3 = t.getVertices()[2];
- indicies.put((short) v1.getId());
- indicies.put((short) v2.getId());
- indicies.put((short) v3.getId());
+ indicesTxt.puts((short) v1.getId());
+ indicesTxt.puts((short) v2.getId());
+ indicesTxt.puts((short) v3.getId());
}
}
- indicies.rewind();
-
- FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 3);
+ indicesTxt.seal(gl, true);
+
+ verticeTxtAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
+ vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ verticeTxtAttr.setLocation(Region.VERTEX_ATTR_IDX);
for(Vertex v:vertices){
- verticesBuffer.put(v.getX());
+ verticeTxtAttr.putf(v.getX());
if(flipped){
- verticesBuffer.put(-1*v.getY());
- }
- else{
- verticesBuffer.put(v.getY());
+ verticeTxtAttr.putf(-1*v.getY());
+ } else {
+ verticeTxtAttr.putf(v.getY());
}
- verticesBuffer.put(v.getZ());
-
+ verticeTxtAttr.putf(v.getZ());
if(flipped){
box.resize(v.getX(), -1*v.getY(), v.getZ());
- }
- else{
+ } else {
box.resize(v.getX(), v.getY(), v.getZ());
}
}
- verticesBuffer.rewind();
+ verticeTxtAttr.seal(gl, true);
- FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 2);
+ texCoordTxtAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
+ vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ texCoordTxtAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
for(Vertex v:vertices){
float[] tex = v.getTexCoord();
- texCoordBuffer.put(tex[0]);
- texCoordBuffer.put(tex[1]);
+ texCoordTxtAttr.putf(tex[0]);
+ texCoordTxtAttr.putf(tex[1]);
}
- texCoordBuffer.rewind();
+ texCoordTxtAttr.seal(gl, true);
- vboIds = IntBuffer.allocate(numBuffers);
- gl.glGenBuffers(numBuffers, vboIds);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); // vertices
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); //texture
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); //triangles
- gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, triangles.size()* 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0);
-
+ // leave the buffers enabled for subsequent render call
+
dirty = false;
}
public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){
+ GL2ES2 gl = context.getGL().getGL2ES2();
if(null == matrix || vp_width <=0 || vp_height <= 0 || width <= 0){
- renderRegion();
- }
- else {
+ renderRegion(gl);
+ } else {
if(width != tex_width_c){
- initFBOTexture(matrix, width);
+ renderRegion2FBO(gl, matrix, width);
+ setupBBox2FboAttr(gl);
}
// System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3));
- renderTexture(matrix, vp_width, vp_height);
+ renderFBO(gl, matrix, vp_width, vp_height);
}
}
- private void renderTexture(PMVMatrix matrix, int width, int hight){
- GL2ES2 gl = context.getGL().getGL2ES2();
+ private void renderFBO(GL2ES2 gl, PMVMatrix matrix, int width, int hight) {
gl.glViewport(0, 0, width, hight);
if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, matrix.glGetPMvMatrixf()))){
System.out.println("Cnt set tex based mat");
@@ -185,96 +209,50 @@ public class VBORegion2PES2 implements Region{
gl.glUniform1i(loc, 0);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
- gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(1));
- gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
- gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, t_vboIds.get(2));
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, 2 * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
+ verticeFboAttr.enableBuffer(gl, true);
+ texCoordFboAttr.enableBuffer(gl, true);
+ indicesFbo.enableBuffer(gl, true);
+
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementNumber() * indicesFbo.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
+ verticeFboAttr.enableBuffer(gl, false);
+ texCoordFboAttr.enableBuffer(gl, false);
+ indicesFbo.enableBuffer(gl, false);
}
- private void setupBoundingBuffers(){
- GL2ES2 gl = context.getGL().getGL2ES2();
-
- ShortBuffer indicies = Buffers.newDirectShortBuffer(6);
- indicies.put((short) 0); indicies.put((short) 1); indicies.put((short) 3);
- indicies.put((short) 1); indicies.put((short) 2); indicies.put((short) 3);
- indicies.rewind();
-
- FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(4 * 3);
- FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(4 * 2);
-
- verticesBuffer.put(box.getLow()[0]);
- verticesBuffer.put(box.getLow()[1]);
- verticesBuffer.put(box.getLow()[2]);
- texCoordBuffer.put(5);
- texCoordBuffer.put(5);
-
- verticesBuffer.put(box.getLow()[0]);
- verticesBuffer.put(box.getHigh()[1]);
- verticesBuffer.put(box.getLow()[2]);
-
- texCoordBuffer.put(5);
- texCoordBuffer.put(6);
-
- verticesBuffer.put(box.getHigh()[0]);
- verticesBuffer.put(box.getHigh()[1]);
- verticesBuffer.put(box.getLow()[2]);
-
- texCoordBuffer.put(6);
- texCoordBuffer.put(6);
-
- verticesBuffer.put(box.getHigh()[0]);
- verticesBuffer.put(box.getLow()[1]);
- verticesBuffer.put(box.getLow()[2]);
-
- texCoordBuffer.put(6);
- texCoordBuffer.put(5);
-
- verticesBuffer.rewind();
- texCoordBuffer.rewind();
-
- t_vboIds = IntBuffer.allocate(3);
- gl.glGenBuffers(numBuffers, t_vboIds);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(0)); // vertices
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, 4 * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, t_vboIds.get(1)); //texture
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, 4 * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
+ private void setupBBox2FboAttr(GL2ES2 gl){
+ verticeFboAttr.seal(gl, false);
+ verticeFboAttr.rewind();
+
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]);
+ verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]);
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, t_vboIds.get(2)); //triangles
- gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 4 * 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0);
+ verticeFboAttr.seal(gl, true);
}
- private void initFBOTexture(PMVMatrix m, int tex_width){
+ private void renderRegion2FBO(GL2ES2 gl, PMVMatrix m, int tex_width){
tex_width_c = tex_width;
tex_height_c = (int)(tex_width_c*box.getHeight()/box.getWidth());
- System.out.println("FBO Size: "+tex_height_c+"x"+tex_width_c);
- System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5));
+ // System.out.println("FBO Size: "+tex_width+" -> "+tex_height_c+"x"+tex_width_c);
+ // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5));
- GL2ES2 gl = context.getGL().getGL2ES2();
- if(null != fbo) {
+ if(null != fbo && fbo.getWidth() != tex_width_c && fbo.getHeight() != tex_height_c ) {
fbo.destroy(gl);
fbo = null;
}
- fbo = new FBObject(tex_width_c, tex_height_c);
- // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
- fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
- fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ?
-
+ if(null == fbo) {
+ fbo = new FBObject(tex_width_c, tex_height_c);
+ // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth
+ fbo.init(gl, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ // fbo.init(gl, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE);
+ fbo.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); // FIXME: or shall we use 24 or 32 bit depth ?
+ } else {
+ fbo.bind(gl);
+ }
//render texture
PMVMatrix tex_matrix = new PMVMatrix();
@@ -289,28 +267,21 @@ public class VBORegion2PES2 implements Region{
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
- renderRegion();
+ renderRegion(gl);
fbo.unbind(gl);
-
- setupBoundingBuffers();
}
- private void renderRegion(){
- GL2ES2 gl = context.getGL().getGL2ES2();
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
- gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
+ private void renderRegion(GL2ES2 gl) {
+ verticeTxtAttr.enableBuffer(gl, true);
+ texCoordTxtAttr.enableBuffer(gl, true);
+ indicesTxt.enableBuffer(gl, true);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1));
- gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
- gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementNumber() * indicesTxt.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2));
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
+ verticeTxtAttr.enableBuffer(gl, false);
+ texCoordTxtAttr.enableBuffer(gl, false);
+ indicesTxt.enableBuffer(gl, false);
}
public void addTriangles(ArrayList<Triangle> tris) {
@@ -333,14 +304,49 @@ public class VBORegion2PES2 implements Region{
}
public void destroy() {
+ if(DEBUG) {
+ System.err.println("VBORegion2PES2 Destroy: " + this);
+ }
GL2ES2 gl = context.getGL().getGL2ES2();
- gl.glDeleteBuffers(numBuffers, vboIds);
- if(null != fbo) {
- fbo.destroy(gl);
- fbo = null;
- }
+ destroyFbo(gl);
+ destroyTxtAttr(gl);
+ destroyFboAttr(gl);
+ }
+ final void destroyFbo(GL2ES2 gl) {
+ if(null != fbo) {
+ fbo.destroy(gl);
+ fbo = null;
+ }
}
-
+ final void destroyTxtAttr(GL2ES2 gl) {
+ if(null != verticeTxtAttr) {
+ verticeTxtAttr.destroy(gl);
+ verticeTxtAttr = null;
+ }
+ if(null != texCoordTxtAttr) {
+ texCoordTxtAttr.destroy(gl);
+ texCoordTxtAttr = null;
+ }
+ if(null != indicesTxt) {
+ indicesTxt.destroy(gl);
+ indicesTxt = null;
+ }
+ }
+ final void destroyFboAttr(GL2ES2 gl) {
+ if(null != verticeFboAttr) {
+ verticeFboAttr.destroy(gl);
+ verticeFboAttr = null;
+ }
+ if(null != texCoordFboAttr) {
+ texCoordFboAttr.destroy(gl);
+ texCoordFboAttr = null;
+ }
+ if(null != indicesFbo) {
+ indicesFbo.destroy(gl);
+ indicesFbo = null;
+ }
+ }
+
public boolean isFlipped() {
return flipped;
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 8f83d4d04..0d68be8ce 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -27,32 +27,30 @@
*/
package jogamp.graph.curve.opengl;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.ShortBuffer;
import java.util.ArrayList;
+import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLContext;
-import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Triangle;
+import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
-public class VBORegionSPES2 implements Region{
+public class VBORegionSPES2 implements Region {
private int numVertices = 0;
- private IntBuffer vboIds;
private ArrayList<Triangle> triangles = new ArrayList<Triangle>();
private ArrayList<Vertex> vertices = new ArrayList<Vertex>();
+ private GLArrayDataServer verticeAttr = null;
+ private GLArrayDataServer texCoordAttr = null;
+ private GLArrayDataServer indices = null;
private GLContext context;
- private int numBuffers = 3;
-
private boolean flipped = false;
private boolean dirty = false;
@@ -65,8 +63,11 @@ public class VBORegionSPES2 implements Region{
public void update(){
box = new AABBox();
GL2ES2 gl = context.getGL().getGL2ES2();
- ShortBuffer indicies = Buffers.newDirectShortBuffer(triangles.size() * 3);
+ destroy(gl);
+
+ indices = GLArrayDataServer.createGLSL(gl, null, 3, GL2ES2.GL_SHORT, false,
+ triangles.size(), GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
for(Triangle t:triangles){
final Vertex[] t_vertices = t.getVertices();
@@ -74,88 +75,78 @@ public class VBORegionSPES2 implements Region{
t_vertices[0].setId(numVertices++);
t_vertices[1].setId(numVertices++);
t_vertices[2].setId(numVertices++);
-
+
vertices.add(t.getVertices()[0]);
vertices.add(t.getVertices()[1]);
vertices.add(t.getVertices()[2]);
- indicies.put((short) t.getVertices()[0].getId());
- indicies.put((short) t.getVertices()[1].getId());
- indicies.put((short) t.getVertices()[2].getId());
+ indices.puts((short) t.getVertices()[0].getId());
+ indices.puts((short) t.getVertices()[1].getId());
+ indices.puts((short) t.getVertices()[2].getId());
}
else{
Vertex v1 = t_vertices[0];
Vertex v2 = t_vertices[1];
Vertex v3 = t_vertices[2];
- indicies.put((short) v1.getId());
- indicies.put((short) v2.getId());
- indicies.put((short) v3.getId());
+ indices.puts((short) v1.getId());
+ indices.puts((short) v2.getId());
+ indices.puts((short) v3.getId());
}
}
- indicies.rewind();
+ indices.seal(gl, true);
- FloatBuffer verticesBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 3);
+ verticeAttr = GLArrayDataServer.createGLSL(gl, Region.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, false,
+ vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ verticeAttr.setLocation(Region.VERTEX_ATTR_IDX);
for(Vertex v:vertices){
if(flipped){
- verticesBuffer.put(v.getX());
- verticesBuffer.put(-1*v.getY());
- verticesBuffer.put(v.getZ());
+ verticeAttr.putf(v.getX());
+ verticeAttr.putf(-1*v.getY());
+ verticeAttr.putf(v.getZ());
box.resize(v.getX(),-1*v.getY(),v.getZ());
}
else{
- verticesBuffer.put(v.getX());
- verticesBuffer.put(v.getY());
- verticesBuffer.put(v.getZ());
+ verticeAttr.putf(v.getX());
+ verticeAttr.putf(v.getY());
+ verticeAttr.putf(v.getZ());
box.resize(v.getX(),v.getY(),v.getZ());
}
}
- verticesBuffer.rewind();
-
- FloatBuffer texCoordBuffer = Buffers.newDirectFloatBuffer(vertices.size() * 2);
+ verticeAttr.seal(gl, true);
+
+ texCoordAttr = GLArrayDataServer.createGLSL(gl, Region.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, false,
+ vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
+ texCoordAttr.setLocation(Region.TEXCOORD_ATTR_IDX);
for(Vertex v:vertices){
float[] tex = v.getTexCoord();
- texCoordBuffer.put(tex[0]);
- texCoordBuffer.put(tex[1]);
+ texCoordAttr.putf(tex[0]);
+ texCoordAttr.putf(tex[1]);
}
- texCoordBuffer.rewind();
-
- vboIds = IntBuffer.allocate(numBuffers);
- gl.glGenBuffers(numBuffers, vboIds);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0)); // vertices
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 3 * Buffers.SIZEOF_FLOAT, verticesBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1)); //texture
- gl.glBufferData(GL2ES2.GL_ARRAY_BUFFER, numVertices * 2 * Buffers.SIZEOF_FLOAT, texCoordBuffer, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2)); //triangles
- gl.glBufferData(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, triangles.size()* 3 * Buffers.SIZEOF_SHORT, indicies, GL2ES2.GL_STATIC_DRAW);
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, 0);
-
+ texCoordAttr.seal(gl, true);
+
+ verticeAttr.enableBuffer(gl, false);
+ texCoordAttr.enableBuffer(gl, false);
+ indices.enableBuffer(gl, false);
+
dirty = false;
}
private void render() {
GL2ES2 gl = context.getGL().getGL2ES2();
+
+ verticeAttr.enableBuffer(gl, true);
+ texCoordAttr.enableBuffer(gl, true);
+ indices.enableBuffer(gl, true);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(0));
- gl.glEnableVertexAttribArray(VERTEX_ATTR_IDX);
- gl.glVertexAttribPointer(VERTEX_ATTR_IDX, 3, GL2ES2.GL_FLOAT, false, 3 * Buffers.SIZEOF_FLOAT, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, vboIds.get(1));
- gl.glEnableVertexAttribArray(TEXCOORD_ATTR_IDX);
- gl.glVertexAttribPointer(TEXCOORD_ATTR_IDX, 2, GL2ES2.GL_FLOAT, false, 2 * Buffers.SIZEOF_FLOAT, 0);
-
- gl.glBindBuffer(GL2ES2.GL_ELEMENT_ARRAY_BUFFER, vboIds.get(2));
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, triangles.size() * 3, GL2ES2.GL_UNSIGNED_SHORT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementNumber() * indices.getComponentNumber(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- gl.glBindBuffer(GL2ES2.GL_ARRAY_BUFFER, 0);
+ verticeAttr.enableBuffer(gl, false);
+ texCoordAttr.enableBuffer(gl, false);
+ indices.enableBuffer(gl, false);
}
public void render(PMVMatrix matrix, int vp_width, int vp_height, int width){
@@ -183,7 +174,22 @@ public class VBORegionSPES2 implements Region{
public void destroy() {
GL2ES2 gl = context.getGL().getGL2ES2();
- gl.glDeleteBuffers(numBuffers, vboIds);
+ destroy(gl);
+ }
+
+ final void destroy(GL2ES2 gl) {
+ if(null != verticeAttr) {
+ verticeAttr.destroy(gl);
+ verticeAttr = null;
+ }
+ if(null != texCoordAttr) {
+ texCoordAttr.destroy(gl);
+ texCoordAttr = null;
+ }
+ if(null != indices) {
+ indices.destroy(gl);
+ indices = null;
+ }
}
public boolean isFlipped() {
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
index 4e5afc683..d0f8543a3 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java
@@ -214,7 +214,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) {
- glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0));
+ glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false, stride, pointer, -1, -1, -1, -1));
}
public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -222,7 +222,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glVertexPointer(GLArrayDataWrapper.createFixed(gl, GL_VERTEX_ARRAY, size, type, false,
- stride, null, vboName, pointer_buffer_offset));
+ stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
}
public void glColorPointer(GLArrayData array) {
@@ -242,7 +242,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) {
glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false,
- stride, pointer, 0, 0));
+ stride, pointer, -1, -1, -1, -1));
}
public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -250,7 +250,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glColorPointer(GLArrayDataWrapper.createFixed(gl, GL_COLOR_ARRAY, size, type, false,
- stride, null, vboName, pointer_buffer_offset));
+ stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
}
public void glNormalPointer(GLArrayData array) {
@@ -273,7 +273,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) {
glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false,
- stride, pointer, 0, 0));
+ stride, pointer, -1, -1, -1, -1));
}
public void glNormalPointer(int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -281,7 +281,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glNormalPointer(GLArrayDataWrapper.createFixed(gl, GL_NORMAL_ARRAY, 3, type, false,
- stride, null, vboName, pointer_buffer_offset));
+ stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER));
}
public void glTexCoordPointer(GLArrayData array) {
@@ -301,7 +301,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) {
glTexCoordPointer(
- GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0));
+ GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, -1, -1, -1, -1));
}
public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
@@ -310,7 +310,7 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun
}
glTexCoordPointer(
GLArrayDataWrapper.createFixed(gl, GL_TEXTURE_COORD_ARRAY, size, type, false,
- stride, null, vboName, pointer_buffer_offset) );
+ stride, null, vboName, pointer_buffer_offset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER) );
}
public final String toString() {
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
index 40c7d6ac4..1b4a94522 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
@@ -31,6 +31,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;
@@ -62,7 +63,8 @@ public class GPUTextNewtDemo02 {
window.setSize(800, 400);
window.setTitle("GPU Text Newt Demo 02 - r2t1 msaa0");
- GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(Region.TWO_PASS, window.getWidth()*3, DEBUG, TRACE);
+ GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(Region.TWO_PASS, window.getWidth()*3, DEBUG, TRACE);
+ // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java
index f062a7375..9ae317537 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java
@@ -82,7 +82,7 @@ public class RedSquare0 implements GLEventListener {
Assert.assertTrue(0 <= mgl_Vertex);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components);
- GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0);
+ GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0, 0, 0);
{
// Fill them up
FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer();
@@ -111,7 +111,7 @@ public class RedSquare0 implements GLEventListener {
Assert.assertTrue(0 <= mgl_Color);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
buffer = Buffers.newDirectFloatBuffer(numElements * components);
- GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0);
+ GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0, 0, 0);
{
// Fill them up
FloatBuffer colorb = (FloatBuffer) colors.getBuffer();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java
index 96a830a53..67e400f29 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java
@@ -63,9 +63,9 @@ public class ReadBuffer2Screen extends ReadBufferBase {
//readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
// 2, GL.GL_FLOAT, true, 4);
readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
- 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
readTextureVertices.setEnableAlways(enableBufferAlways);
- readTextureVertices.setVBOUsage(enableBufferVBO);
+ readTextureVertices.setVBOEnabled(enableBufferVBO);
{
FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer();
vb.put(-f_edge); vb.put(-f_edge);
@@ -155,9 +155,9 @@ public class ReadBuffer2Screen extends ReadBufferBase {
void updateTextureCoords(GL gl, boolean force) {
if(force || null==readTextureCoords) {
readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0",
- 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER);
readTextureCoords.setEnableAlways(enableBufferAlways);
- readTextureCoords.setVBOUsage(enableBufferVBO);
+ readTextureCoords.setVBOEnabled(enableBufferVBO);
{
TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords();
FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer();