aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
diff options
context:
space:
mode:
authorRami Santina <rami.santina@gmail.com>2011-04-08 18:06:21 +0300
committerRami Santina <rami.santina@gmail.com>2011-04-08 18:06:21 +0300
commit1218f8e4d4146831ed729cd1eac33d704529a072 (patch)
tree17bd30d50ed74ce5422e59168d6990f1983176fe /src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
parente6de1dcd253ef4d6ba9f584b4ed3540c85c66d2c (diff)
parentc004a86e24fcc1cd026a7d1d52f61e8eafc8058a (diff)
Merge: merged with sgothel
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java119
1 files changed, 74 insertions, 45 deletions
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;
}