summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-22 16:38:45 +0200
committerSven Gothel <[email protected]>2011-08-22 16:38:45 +0200
commit87ff90fb03216737df70ff83246664b7fba2663e (patch)
treed62c0a3c95e2f1eabd9fa69a95c814c668c4ff15 /src/jogl/classes/com/jogamp/opengl/util
parent6602d8eb5af13dc317fff8e044db52c3388f99fa (diff)
Fix regression of commit 6c346d98f04e2355210960fe9ffde47432f04d62, where VBO/attribute binding wasn't updated (VBO data written, shader change/switch attribute on same location) ; Optimized interleaved GLSL VBO binding, hence split up GLArrayHandler syncData/enableState
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java8
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java103
3 files changed, 86 insertions, 39 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index 13c61766e..3600081bc 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -162,7 +162,13 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
// init/generate VBO name if not done yet
init_vbo(gl);
}
- glArrayHandler.enableBuffer(gl, enable);
+ if(enable) {
+ glArrayHandler.syncData(gl, true);
+ glArrayHandler.enableState(gl, true);
+ } else {
+ glArrayHandler.enableState(gl, false);
+ glArrayHandler.syncData(gl, false);
+ }
bufferEnabled = enable;
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
index ee80c4299..b30e220bd 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayHandler.java
@@ -11,13 +11,21 @@ import javax.media.opengl.*;
public interface GLArrayHandler {
/**
- * Implementation shall ensure the buffers data is synchronized to the GPU
- * and the array state is enabled.
+ * Implementation shall associate the data with the array
+ * and synchronize the data with the GPU.
+ *
+ * @param gl current GL object
+ * @param enable true if array data shall be valid, otherwise false.
+ */
+ public void syncData(GL gl, boolean enable);
+
+ /**
+ * Implementation shall enable or disable the array state.
*
* @param gl current GL object
* @param enable true if array shall be enabled, otherwise false.
*/
- public void enableBuffer(GL gl, boolean enable);
+ public void enableState(GL gl, boolean enable);
/**
* Supporting interleaved arrays, where sub handlers may handle
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
index e8a547057..a2a012e08 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -303,7 +303,7 @@ public class ShaderState {
* @see #getAttribLocation(GL2ES2, String)
* @see GL2ES2#glGetAttribLocation(int, String)
*/
- public int getAttribLocation(String name) {
+ public int getCachedAttribLocation(String name) {
Integer idx = (Integer) activeAttribLocationMap.get(name);
return (null!=idx)?idx.intValue():-1;
}
@@ -346,7 +346,7 @@ public class ShaderState {
*/
public void ownAttribute(GLArrayData attribute, boolean own) {
if(own) {
- final int location = getAttribLocation(attribute.getName());
+ final int location = getCachedAttribLocation(attribute.getName());
if(0<=location) {
attribute.setLocation(location);
}
@@ -363,7 +363,7 @@ public class ShaderState {
/**
* Binds a shader attribute to a location.
* Multiple names can be bound to one location.
- * The value will be cached and can be retrieved via {@link #getAttribLocation(String)}
+ * The value will be cached and can be retrieved via {@link #getCachedAttribLocation(String)}
* before or after linking.
*
* @throws GLException if no program is attached
@@ -371,7 +371,7 @@ public class ShaderState {
*
* @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
* @see #getAttribLocation(GL2ES2, String)
- * @see #getAttribLocation(String)
+ * @see #getCachedAttribLocation(String)
*/
public void bindAttribLocation(GL2ES2 gl, int location, String name) {
if(null==shaderProgram) throw new GLException("No program is attached");
@@ -384,7 +384,7 @@ public class ShaderState {
/**
* Binds a shader {@link GLArrayData} attribute to a location.
* Multiple names can be bound to one location.
- * The value will be cached and can be retrieved via {@link #getAttribLocation(String)}
+ * The value will be cached and can be retrieved via {@link #getCachedAttribLocation(String)}
* and {@link #getAttribute(String)}before or after linking.
* The {@link GLArrayData}'s location will be set as well.
*
@@ -393,7 +393,7 @@ public class ShaderState {
*
* @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
* @see #getAttribLocation(GL2ES2, String)
- * @see #getAttribLocation(String)
+ * @see #getCachedAttribLocation(String)
* @see #getAttribute(String)
*/
public void bindAttribLocation(GL2ES2 gl, int location, GLArrayData data) {
@@ -403,24 +403,24 @@ public class ShaderState {
}
/**
- * Gets the location of a shader attribute,
- * either the cached value {@link #getAttribLocation(String)} if valid or
- * the retrieved one {@link GL2ES2#glGetAttribLocation(int, String)}.
- * In the latter case the value will be cached.
+ * Gets the location of a shader attribute.<br>
+ * Uses either the cached value {@link #getCachedAttribLocation(String)} if valid,
+ * or the GLSL queried via {@link GL2ES2#glGetAttribLocation(int, String)}.<br>
+ * The location will be cached.
*
* @return -1 if there is no such attribute available,
* otherwise >= 0
* @throws GLException if no program is attached
* @throws GLException if the program is not linked and no location was cached.
*
- * @see #getAttribLocation(String)
+ * @see #getCachedAttribLocation(String)
* @see #bindAttribLocation(GL2ES2, int, GLArrayData)
* @see #bindAttribLocation(GL2ES2, int, String)
* @see GL2ES2#glGetAttribLocation(int, String)
*/
public int getAttribLocation(GL2ES2 gl, String name) {
if(null==shaderProgram) throw new GLException("No program is attached");
- int location = getAttribLocation(name);
+ int location = getCachedAttribLocation(name);
if(0>location) {
if(!shaderProgram.linked()) throw new GLException("Program is not linked");
location = gl.glGetAttribLocation(shaderProgram.program(), name);
@@ -439,11 +439,11 @@ public class ShaderState {
}
/**
- * Gets the location of a shader attribute,
- * either the cached value {@link #getAttribLocation(String)} if valid or
- * the retrieved one {@link GL2ES2#glGetAttribLocation(int, String)}.
- * In the latter case the value will be cached.
- * The {@link GLArrayData}'s location will be set as well.
+ * Validates and returns the location of a shader attribute.<br>
+ * Uses either the cached value {@link #getCachedAttribLocation(String)} if valid,
+ * or the GLSL queried via {@link GL2ES2#glGetAttribLocation(int, String)}.<br>
+ * The location will be cached and set in the
+ * {@link GLArrayData} object.
*
* @return -1 if there is no such attribute available,
* otherwise >= 0
@@ -451,7 +451,7 @@ public class ShaderState {
* @throws GLException if no program is attached
* @throws GLException if the program is not linked and no location was cached.
*
- * @see #getAttribLocation(String)
+ * @see #getCachedAttribLocation(String)
* @see #bindAttribLocation(GL2ES2, int, GLArrayData)
* @see #bindAttribLocation(GL2ES2, int, String)
* @see GL2ES2#glGetAttribLocation(int, String)
@@ -646,11 +646,7 @@ public class ShaderState {
int location = data.getLocation();
if(0 > location) {
location = getAttribLocation(gl, data);
- } /* else {
- done via enable ..
- // ensure data is the current bound one
- activeAttribDataMap.put(data.getName(), data);
- } */
+ }
if(0 <= location) {
// only pass the data, if the attribute exists in the current shader
if(DEBUG) {
@@ -805,6 +801,17 @@ public class ShaderState {
//
/**
+ * Gets the cached location of the shader uniform.
+ *
+ * @return -1 if there is no such uniform available,
+ * otherwise >= 0
+ */
+ public final int getCachedUniformLocation(String name) {
+ Integer idx = (Integer) activeUniformLocationMap.get(name);
+ return (null!=idx)?idx.intValue():-1;
+ }
+
+ /**
* Bind the {@link GLUniform} lifecycle to this ShaderState.
*
* <p>If a uniform location is cached it is promoted to the {@link GLUniformData} instance.</p>
@@ -819,7 +826,7 @@ public class ShaderState {
* @see #getUniform(String)
*/
public void ownUniform(GLUniformData uniform) {
- final int location = getUniformLocation(uniform.getName());
+ final int location = getCachedUniformLocation(uniform.getName());
if(0<=location) {
uniform.setLocation(location);
}
@@ -832,8 +839,13 @@ public class ShaderState {
}
/**
- * Gets the index of a shader uniform.
- * This must be done when the program is in use !
+ * Gets the location of a shader uniform.<br>
+ * Uses either the cached value {@link #getCachedUniformLocation(String)} if valid,
+ * or the GLSL queried via {@link GL2ES2#glGetUniformLocation(int, String)}.<br>
+ * The location will be cached.
+ * <p>
+ * The current shader program ({@link #attachShaderProgram(GL2ES2, ShaderProgram)})
+ * must be in use ({@link #useProgram(GL2ES2, boolean) }) !</p>
*
* @return -1 if there is no such attribute available,
* otherwise >= 0
@@ -845,9 +857,9 @@ public class ShaderState {
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
- protected final int getUniformLocation(GL2ES2 gl, String name) {
+ public final int getUniformLocation(GL2ES2 gl, String name) {
if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- int location = getUniformLocation(name);
+ int location = getCachedUniformLocation(name);
if(0>location) {
location = gl.glGetUniformLocation(shaderProgram.program(), name);
if(0<=location) {
@@ -861,11 +873,33 @@ public class ShaderState {
return location;
}
- protected final int getUniformLocation(String name) {
- Integer idx = (Integer) activeUniformLocationMap.get(name);
- return (null!=idx)?idx.intValue():-1;
- }
+ /**
+ * Validates and returns the location of a shader uniform.<br>
+ * Uses either the cached value {@link #getCachedUniformLocation(String)} if valid,
+ * or the GLSL queried via {@link GL2ES2#glGetUniformLocation(int, String)}.<br>
+ * The location will be cached and set in the
+ * {@link GLUniformData} object.
+ * <p>
+ * The current shader program ({@link #attachShaderProgram(GL2ES2, ShaderProgram)})
+ * must be in use ({@link #useProgram(GL2ES2, boolean) }) !</p>
+ *
+ * @return -1 if there is no such attribute available,
+ * otherwise >= 0
+ * @throws GLException is the program is not linked
+ *
+ * @see #glGetUniformLocation
+ * @see javax.media.opengl.GL2ES2#glGetUniformLocation
+ * @see #getUniformLocation
+ * @see ShaderProgram#glReplaceShader
+ */
+ public int getUniformLocation(GL2ES2 gl, GLUniformData data) {
+ int location = getUniformLocation(gl, data.getName());
+ data.setLocation(location);
+ activeUniformDataMap.put(data.getName(), data);
+ return location;
+ }
+
/**
* Set the uniform data.
*
@@ -883,6 +917,7 @@ public class ShaderState {
*
* @see #glGetUniformLocation
* @see javax.media.opengl.GL2ES2#glGetUniformLocation
+ * @see javax.media.opengl.GL2ES2#glUniform
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
@@ -890,10 +925,8 @@ public class ShaderState {
if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
int location = data.getLocation();
if(0>location) {
- location = getUniformLocation(gl, data.getName());
- data.setLocation(location);
+ location = getUniformLocation(gl, data);
}
- activeUniformDataMap.put(data.getName(), data);
if(0<=location) {
// only pass the data, if the uniform exists in the current shader
if(DEBUG) {