diff options
author | Rami Santina <[email protected]> | 2011-04-08 18:06:21 +0300 |
---|---|---|
committer | Rami Santina <[email protected]> | 2011-04-08 18:06:21 +0300 |
commit | 1218f8e4d4146831ed729cd1eac33d704529a072 (patch) | |
tree | 17bd30d50ed74ce5422e59168d6990f1983176fe /src/jogl/classes/com | |
parent | e6de1dcd253ef4d6ba9f584b4ed3540c85c66d2c (diff) | |
parent | c004a86e24fcc1cd026a7d1d52f61e8eafc8058a (diff) |
Merge: merged with sgothel
Diffstat (limited to 'src/jogl/classes/com')
12 files changed, 459 insertions, 188 deletions
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()); } |