summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes')
-rwxr-xr-xsrc/jogl/classes/com/jogamp/graph/curve/Region.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java15
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java47
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java6
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java26
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java10
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java494
-rw-r--r--src/jogl/classes/javax/media/opengl/GLArrayData.java2
-rwxr-xr-xsrc/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java57
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java34
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java13
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphString.java5
-rw-r--r--src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java122
16 files changed, 470 insertions, 377 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index a759546ba..eb88b787c 100755
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -117,7 +117,7 @@ public interface Region {
/** Delete and clean the associated OGL
* objects
*/
- public void destroy(GL2ES2 gl);
+ public void destroy(GL2ES2 gl, RenderState rs);
public AABBox getBounds();
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index 2b4c8b7c5..69fdd5c4a 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -79,7 +79,7 @@ public abstract class RegionRenderer extends Renderer {
Iterator<Region> iterator = regions.values().iterator();
while(iterator.hasNext()){
Region region = iterator.next();
- region.destroy(gl);
+ region.destroy(gl, rs);
}
regions.clear();
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
index 6450f9f8b..84323f6e5 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -27,29 +27,28 @@
*/
package com.jogamp.graph.curve.opengl;
-import javax.media.opengl.GL;
-import javax.media.opengl.GLProfile;
+import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
-import com.jogamp.common.os.Platform;
-import com.jogamp.common.util.VersionUtil;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
public interface RenderState {
+ void destroy(GL2ES2 gl);
+
ShaderState getShaderState();
Vertex.Factory<? extends Vertex> getPointFactory();
- PMVMatrix getPMVMatrix();
- GLUniformData getPMVMatrixUniform();
+ PMVMatrix pmvMatrix();
+ GLUniformData getPMVMatrix();
GLUniformData getSharpness();
GLUniformData getAlpha();
GLUniformData getColorStatic();
GLUniformData getStrength();
- RenderState attachTo(GL gl);
- boolean detachFrom(GL gl);
+ RenderState attachTo(GL2ES2 gl);
+ boolean detachFrom(GL2ES2 gl);
StringBuilder toString(StringBuilder sb);
String toString();
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 4db917fdd..35022f769 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -63,7 +63,7 @@ public abstract class Renderer {
/**
* Flushes all cached data
- * @see #dispose(GL2ES2)
+ * @see #destroy(GL2ES2)
*/
public abstract void flushCache(GL2ES2 gl);
@@ -130,58 +130,59 @@ public abstract class Renderer {
rs.attachTo(gl);
gl.glEnable(GL2ES2.GL_BLEND);
- gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA);
+ gl.glBlendFunc(GL2ES2.GL_SRC_ALPHA, GL2ES2.GL_ONE_MINUS_SRC_ALPHA); // FIXME: alpha blending stage ?
initialized = initShaderProgram(gl);
if(!initialized) {
return false;
}
- if(!rs.getShaderState().glUniform(gl, rs.getPMVMatrixUniform())) {
+ if(!rs.getShaderState().uniform(gl, rs.getPMVMatrix())) {
if(DEBUG){
System.err.println("Error setting PMVMatrix in shader: "+rs.getShaderState());
}
return false;
}
- if(!rs.getShaderState().glUniform(gl, rs.getSharpness())) {
+ if(!rs.getShaderState().uniform(gl, rs.getSharpness())) {
if(DEBUG){
System.err.println("Error setting sharpness in shader: "+rs.getShaderState());
}
return false;
}
- if(!rs.getShaderState().glUniform(gl, rs.getAlpha())) {
+ if(!rs.getShaderState().uniform(gl, rs.getAlpha())) {
if(DEBUG){
System.err.println("Error setting global alpha in shader: "+rs.getShaderState());
}
return false;
}
- if(!rs.getShaderState().glUniform(gl, rs.getColorStatic())) {
+ if(!rs.getShaderState().uniform(gl, rs.getColorStatic())) {
if(DEBUG){
System.err.println("Error setting global color in shader: "+rs.getShaderState());
}
return false;
}
- if(!rs.getShaderState().glUniform(gl, rs.getStrength())) {
+ if(!rs.getShaderState().uniform(gl, rs.getStrength())) {
System.err.println("Error setting antialias strength in shader: "+rs.getShaderState());
}
return initialized;
}
- public void dispose(GL2ES2 gl) {
+ public void destroy(GL2ES2 gl) {
if(!initialized){
if(DEBUG_INSTANCE) {
System.err.println("TextRenderer: Not initialized!");
}
return;
}
+ rs.getShaderState().useProgram(gl, false);
flushCache(gl);
disposeImpl(gl);
- rs.getShaderState().destroy(gl);
+ rs.destroy(gl);
initialized = false;
}
@@ -189,7 +190,7 @@ public abstract class Renderer {
public final ShaderState getShaderState() { return rs.getShaderState(); }
public final void enable(GL2ES2 gl, boolean enable) {
- rs.getShaderState().glUseProgram(gl, enable);
+ rs.getShaderState().useProgram(gl, enable);
}
public float getSharpness() {
@@ -199,7 +200,7 @@ public abstract class Renderer {
public void setSharpness(GL2ES2 gl, float v) {
rs.getSharpness().setData(v);
if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().glUniform(gl, rs.getSharpness());
+ rs.getShaderState().uniform(gl, rs.getSharpness());
}
}
@@ -210,7 +211,7 @@ public abstract class Renderer {
public void setStrength(GL2ES2 gl, float v) {
rs.getStrength().setData(v);
if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().glUniform(gl, rs.getStrength());
+ rs.getShaderState().uniform(gl, rs.getStrength());
}
}
@@ -221,7 +222,7 @@ public abstract class Renderer {
public void setAlpha(GL2ES2 gl, float alpha_t) {
rs.getAlpha().setData(alpha_t);
if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().glUniform(gl, rs.getAlpha());
+ rs.getShaderState().uniform(gl, rs.getAlpha());
}
}
@@ -239,36 +240,36 @@ public abstract class Renderer {
fb.put(1, g);
fb.put(2, b);
if(null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().glUniform(gl, rs.getColorStatic());
+ rs.getShaderState().uniform(gl, rs.getColorStatic());
}
}
- public final PMVMatrix getMatrix() { return rs.getPMVMatrix(); }
+ public final PMVMatrix getMatrix() { return rs.pmvMatrix(); }
public void rotate(GL2ES2 gl, float angle, float x, float y, float z) {
- rs.getPMVMatrix().glRotatef(angle, x, y, z);
+ rs.pmvMatrix().glRotatef(angle, x, y, z);
updateMatrix(gl);
}
public void translate(GL2ES2 gl, float x, float y, float z) {
- rs.getPMVMatrix().glTranslatef(x, y, z);
+ rs.pmvMatrix().glTranslatef(x, y, z);
updateMatrix(gl);
}
public void scale(GL2ES2 gl, float x, float y, float z) {
- rs.getPMVMatrix().glScalef(x, y, z);
+ rs.pmvMatrix().glScalef(x, y, z);
updateMatrix(gl);
}
public void resetModelview(GL2ES2 gl) {
- rs.getPMVMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- rs.getPMVMatrix().glLoadIdentity();
+ rs.pmvMatrix().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ rs.pmvMatrix().glLoadIdentity();
updateMatrix(gl);
}
public void updateMatrix(GL2ES2 gl) {
if(initialized && null != gl && rs.getShaderState().inUse()) {
- rs.getShaderState().glUniform(gl, rs.getPMVMatrixUniform());
+ rs.getShaderState().uniform(gl, rs.getPMVMatrix());
}
}
@@ -276,7 +277,7 @@ public abstract class Renderer {
this.vp_width = width;
this.vp_height = height;
final float ratio = (float)width/(float)height;
- final PMVMatrix p = rs.getPMVMatrix();
+ final PMVMatrix p = rs.pmvMatrix();
p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
p.glLoadIdentity();
p.gluPerspective(angle, ratio, near, far);
@@ -287,7 +288,7 @@ public abstract class Renderer {
public boolean reshapeOrtho(GL2ES2 gl, int width, int height, float near, float far) {
this.vp_width = width;
this.vp_height = height;
- final PMVMatrix p = rs.getPMVMatrix();
+ final PMVMatrix p = rs.pmvMatrix();
p.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
p.glLoadIdentity();
p.glOrthof(0, width, 0, height, near, far);
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 a955d5a88..deaa1dfad 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
@@ -96,7 +96,7 @@ public abstract class TextRenderer extends Renderer {
Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
while(iterator.hasNext()){
GlyphString glyphString = iterator.next();
- glyphString.destroy(gl);
+ glyphString.destroy(gl, rs);
}
stringCacheMap.clear();
stringCacheArray.clear();
@@ -167,7 +167,7 @@ public abstract class TextRenderer extends Renderer {
final String key = getKey(font, str, fontSize);
GlyphString glyphString = stringCacheMap.remove(key);
if(null != glyphString) {
- glyphString.destroy(gl);
+ glyphString.destroy(gl, rs);
}
stringCacheArray.remove(key);
}
@@ -176,7 +176,7 @@ public abstract class TextRenderer extends Renderer {
final String key = stringCacheArray.remove(idx);
final GlyphString glyphString = stringCacheMap.remove(key);
if(null != glyphString) {
- glyphString.destroy(gl);
+ glyphString.destroy(gl, rs);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index cb9e4cce5..9e92a9a1d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -37,7 +37,7 @@ public class ImmModeSink {
* a ShaderState must be current, using ShaderState.glUseProgram().
*
* @see #draw(GL, boolean)
- * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
public static ImmModeSink createGLSL(GL gl, int glBufferUsage, int initialSize,
@@ -762,35 +762,35 @@ public class ImmModeSink {
}
if(vComps>0) {
- st.glEnableVertexAttribArray(glsl, vArrayData);
- st.glVertexAttribPointer(glsl, vArrayData);
+ st.enableVertexAttribArray(glsl, vArrayData);
+ st.vertexAttribPointer(glsl, vArrayData);
}
if(cComps>0) {
- st.glEnableVertexAttribArray(glsl, cArrayData);
- st.glVertexAttribPointer(glsl, cArrayData);
+ st.enableVertexAttribArray(glsl, cArrayData);
+ st.vertexAttribPointer(glsl, cArrayData);
}
if(nComps>0) {
- st.glEnableVertexAttribArray(glsl, nArrayData);
- st.glVertexAttribPointer(glsl, nArrayData);
+ st.enableVertexAttribArray(glsl, nArrayData);
+ st.vertexAttribPointer(glsl, nArrayData);
}
if(tComps>0) {
- st.glEnableVertexAttribArray(glsl, tArrayData);
- st.glVertexAttribPointer(glsl, tArrayData);
+ st.enableVertexAttribArray(glsl, tArrayData);
+ st.vertexAttribPointer(glsl, tArrayData);
}
glsl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
if(vComps>0) {
- st.glDisableVertexAttribArray(glsl, vArrayData);
+ st.disableVertexAttribArray(glsl, vArrayData);
}
if(cComps>0) {
- st.glDisableVertexAttribArray(glsl, cArrayData);
+ st.disableVertexAttribArray(glsl, cArrayData);
}
if(nComps>0) {
- st.glDisableVertexAttribArray(glsl, nArrayData);
+ st.disableVertexAttribArray(glsl, nArrayData);
}
if(tComps>0) {
- st.glDisableVertexAttribArray(glsl, tArrayData);
+ st.disableVertexAttribArray(glsl, tArrayData);
}
}
}
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 f771ea019..73a1c2721 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/GLSLArrayHandler.java
@@ -53,7 +53,7 @@ public class GLSLArrayHandler implements GLArrayHandler {
GL2ES2 glsl = gl.getGL2ES2();
if(enable) {
- st.glEnableVertexAttribArray(glsl, ad);
+ st.enableVertexAttribArray(glsl, ad);
Buffer buffer = ad.getBuffer();
@@ -68,7 +68,7 @@ public class GLSLArrayHandler implements GLArrayHandler {
glsl.glBufferData(ad.getVBOTarget(), ad.getByteSize(), buffer, ad.getVBOUsage());
}
ad.setVBOWritten(true);
- st.glVertexAttribPointer(glsl, ad);
+ st.vertexAttribPointer(glsl, ad);
} else {
// didn't experience a performance hit on this query ..
int[] qi = new int[1];
@@ -78,18 +78,18 @@ public class GLSLArrayHandler implements GLArrayHandler {
System.err.println("XXX VA "+ad.getName()+" VBO rebind: "+qi[0]+" -> "+ad.getVBOName());
}
glsl.glBindBuffer(ad.getVBOTarget(), ad.getVBOName());
- st.glVertexAttribPointer(glsl, ad);
+ st.vertexAttribPointer(glsl, ad);
}
}
} else if(null!=buffer) {
- st.glVertexAttribPointer(glsl, ad);
+ st.vertexAttribPointer(glsl, ad);
ad.setVBOWritten(true);
}
} else {
if(ad.isVBO()) {
glsl.glBindBuffer(ad.getVBOTarget(), 0);
}
- st.glDisableVertexAttribArray(glsl, ad);
+ st.disableVertexAttribArray(glsl, ad);
}
}
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 de77a1941..f8fe987d7 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -29,6 +29,7 @@
package com.jogamp.opengl.util.glsl;
import java.security.AccessController;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -58,7 +59,7 @@ public class ShaderState {
/**
* Fetches the current shader state from this thread (TLS) current GLContext
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
@@ -71,7 +72,7 @@ public class ShaderState {
*
* @param gl the GL object referencing the GLContext
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
@@ -130,32 +131,36 @@ public class ShaderState {
* if <code>on</code> is <code>true</code>.
*
* @throws GLException if no program is attached
- * @throws GLException if no program is not linked
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
- public synchronized void glUseProgram(GL2ES2 gl, boolean on) {
- if(null==shaderProgram) { throw new GLException("No program is attached"); }
+ public synchronized void useProgram(GL2ES2 gl, boolean on) throws GLException {
+ if(null==shaderProgram) { throw new GLException("No program is attached"); }
if(on) {
- shaderProgram.useProgram(gl, true);
// update the current ShaderState to the TLS ..
gl.getContext().attachObject(ShaderState.class.getName(), this);
- if(resetAllShaderData) {
- resetAllShaderData = false;
- glResetAllVertexAttributes(gl);
- glResetAllUniforms(gl);
+ if(shaderProgram.linked()) {
+ shaderProgram.useProgram(gl, true);
+ if(resetAllShaderData) {
+ resetAllAttributes(gl);
+ resetAllUniforms(gl);
+ }
+ } else if(resetAllShaderData) {
+ setAllAttributes(gl);
+ if(!shaderProgram.link(gl, System.err)) {
+ throw new GLException("could not link program: "+shaderProgram);
+ }
+ shaderProgram.useProgram(gl, true);
+ resetAllUniforms(gl);
}
+ resetAllShaderData = false;
} else {
shaderProgram.useProgram(gl, false);
}
}
- public synchronized void glUseProgram(GL2ES2 gl, ShaderProgram prog, boolean on) {
-
- }
-
public boolean linked() {
return (null!=shaderProgram)?shaderProgram.linked():false;
}
@@ -167,11 +172,16 @@ public class ShaderState {
/**
* Attach or switch a shader program
*
- * Attaching a shader program the first time,
+ * <p>Attaching a shader program the first time,
* as well as switching to another program on the fly,
- * while managing all attribute and uniform data.
+ * while managing all attribute and uniform data.</p>
+ *
+ * <p>[Re]sets all data and use program in case of a program switch.<br>
+ * Use program if linked in case of a 1st time attachment.</p>
+ *
+ * @throws GLException if program was not linked and linking fails
*/
- public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) {
+ public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) throws GLException {
boolean prgInUse = false; // earmarked state
if(DEBUG) {
@@ -192,7 +202,7 @@ public class ShaderState {
return;
}
prgInUse = shaderProgram.inUse();
- glUseProgram(gl, false);
+ useProgram(gl, false);
resetAllShaderData = true;
}
@@ -200,9 +210,10 @@ public class ShaderState {
shaderProgram = prog;
if(null!=shaderProgram) {
- // reinstall all data ..
- if(shaderProgram.linked()) {
- glUseProgram(gl, true);
+ // [re]set all data and use program if switching program,
+ // or use program if program is linked
+ if(shaderProgram.linked() || resetAllShaderData) {
+ useProgram(gl, true);
if(!prgInUse) {
shaderProgram.useProgram(gl, false);
}
@@ -216,27 +227,27 @@ public class ShaderState {
public ShaderProgram shaderProgram() { return shaderProgram; }
/**
- * Calls release(gl, true, true)
+ * Calls {@link #release(GL2ES2, boolean, boolean, boolean) release(gl, true, true, true)}
*
* @see #glReleaseAllVertexAttributes
* @see #glReleaseAllUniforms
- * @see #release(GL2ES2, boolean, boolean)
+ * @see #release(GL2ES2, boolean, boolean, boolean)
*/
public synchronized void destroy(GL2ES2 gl) {
- release(gl, true, true);
+ release(gl, true, true, true);
attachedObjectsByString.clear();
attachedObjectsByInt.clear();
}
/**
- * Calls release(gl, false, false)
+ * Calls {@link #release(GL2ES2, boolean, boolean, boolean) release(gl, false, false, false)}
*
* @see #glReleaseAllVertexAttributes
* @see #glReleaseAllUniforms
- * @see #release(GL2ES2, boolean, boolean)
+ * @see #release(GL2ES2, boolean, boolean, boolean)
*/
public synchronized void releaseAllData(GL2ES2 gl) {
- release(gl, false, false);
+ release(gl, false, false, false);
}
/**
@@ -244,22 +255,21 @@ public class ShaderState {
* @see #glReleaseAllUniforms
* @see ShaderProgram#release(GL2ES2, boolean)
*/
- public synchronized void release(GL2ES2 gl, boolean releaseProgramToo, boolean releaseShaderToo) {
- boolean prgInUse = false;
- if(null!=shaderProgram) {
- prgInUse = shaderProgram.inUse();
- if(!prgInUse) {
- shaderProgram.useProgram(gl, true);
- }
+ public synchronized void release(GL2ES2 gl, boolean destroyBoundAttributes, boolean releaseProgramToo, boolean releaseShaderToo) {
+ if(null!=shaderProgram) {
+ shaderProgram.useProgram(gl, false);
+ }
+ if(destroyBoundAttributes) {
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ iter.next().destroy(gl);
+ }
}
- glReleaseAllVertexAttributes(gl);
- glReleaseAllUniforms(gl);
+ releaseAllAttributes(gl);
+ releaseAllUniforms(gl);
if(null!=shaderProgram) {
if(releaseProgramToo) {
shaderProgram.release(gl, releaseShaderToo);
- } else if(!prgInUse) {
- shaderProgram.useProgram(gl, false);
- }
+ }
}
}
@@ -273,13 +283,13 @@ public class ShaderState {
* @return -1 if there is no such attribute available,
* otherwise >= 0
*
- * @see #glBindAttribLocation(GL2ES2, int, String)
- * @see #glBindAttribLocation(GL2ES2, int, GLArrayData)
- * @see #glGetAttribLocation(GL2ES2, String)
+ * @see #bindAttribLocation(GL2ES2, int, String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #getAttribLocation(GL2ES2, String)
* @see GL2ES2#glGetAttribLocation(int, String)
*/
public int getAttribLocation(String name) {
- Integer idx = (Integer) attribMap2Location.get(name);
+ Integer idx = (Integer) activeAttribLocationMap.get(name);
return (null!=idx)?idx.intValue():-1;
}
@@ -288,7 +298,7 @@ public class ShaderState {
*
* @return the GLArrayData object, null if not previously set.
*
- * @see #bindAttribute(GLArrayData)
+ * @see #ownAttribute(GLArrayData, boolean)
*
* @see #glEnableVertexAttribArray
* @see #glDisableVertexAttribArray
@@ -299,26 +309,40 @@ public class ShaderState {
* @see ShaderProgram#glReplaceShader
*/
public GLArrayData getAttribute(String name) {
- return (GLArrayData) vertexAttribMap2Data.get(name);
+ return (GLArrayData) activeAttribDataMap.get(name);
}
/**
- * Bind the {@link GLArrayData} to this ShaderState.
- * If an attribute location is cached (ie {@link #glBindAttribLocation(GL2ES2, int, String)})
- * it is promoted to the {@link GLArrayData} instance.
- * To bind a {@link GLArrayData} with a given location
- * {@link #glBindAttribLocation(GL2ES2, int, GLArrayData)} shall be used.
+ * Binds or unbinds the {@link GLArrayData} lifecycle to this ShaderState.
+ *
+ * <p>If an attribute location is cached (ie {@link #bindAttribLocation(GL2ES2, int, String)})
+ * it is promoted to the {@link GLArrayData} instance.</p>
*
- * @param data the {@link GLArrayData} to be processed
- * @see #glBindAttribLocation(GL2ES2, int, String)
+ * <p>The attribute will be destroyed with {@link #destroy(GL2ES2)}
+ * and it's location will be reset when switching shader with {@link #attachShaderProgram(GL2ES2, ShaderProgram)}.</p>
+ *
+ * <p>The data will not be transfered to the GPU, use {@link #vertexAttribPointer(GL2ES2, GLArrayData)} additionally.</p>
+ *
+ * @param attribute the {@link GLArrayData} which lifecycle shall be managed
+ * @param own true if <i>owning</i> shall be performs, false if <i>disowning</i>.
+ *
+ * @see #bindAttribLocation(GL2ES2, int, String)
* @see #getAttribute(String)
*/
- public void bindAttribute(GLArrayData data) {
- final int location = getAttribLocation(data.getName());
- if(0<=location) {
- data.setLocation(location);
+ public void ownAttribute(GLArrayData attribute, boolean own) {
+ if(own) {
+ final int location = getAttribLocation(attribute.getName());
+ if(0<=location) {
+ attribute.setLocation(location);
+ }
+ managedAttributes.add(managedAttributes.size(), attribute);
+ } else {
+ managedAttributes.remove(attribute);
}
- vertexAttribMap2Data.put(data.getName(), data);
+ }
+
+ public boolean ownsAttribute(GLArrayData attribute) {
+ return managedAttributes.contains(attribute);
}
/**
@@ -331,14 +355,14 @@ public class ShaderState {
* @throws GLException if the program is already linked
*
* @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
- * @see #glGetAttribLocation(GL2ES2, String)
+ * @see #getAttribLocation(GL2ES2, String)
* @see #getAttribLocation(String)
*/
- public void glBindAttribLocation(GL2ES2 gl, int location, String name) {
+ public void bindAttribLocation(GL2ES2 gl, int location, String name) {
if(null==shaderProgram) throw new GLException("No program is attached");
if(shaderProgram.linked()) throw new GLException("Program is already linked");
final Integer loc = new Integer(location);
- attribMap2Location.put(name, loc);
+ activeAttribLocationMap.put(name, loc);
gl.glBindAttribLocation(shaderProgram.program(), location, name);
}
@@ -353,14 +377,14 @@ public class ShaderState {
* @throws GLException if the program is already linked
*
* @see javax.media.opengl.GL2ES2#glBindAttribLocation(int, int, String)
- * @see #glGetAttribLocation(GL2ES2, String)
+ * @see #getAttribLocation(GL2ES2, String)
* @see #getAttribLocation(String)
* @see #getAttribute(String)
*/
- public void glBindAttribLocation(GL2ES2 gl, int location, GLArrayData data) {
- glBindAttribLocation(gl, location, data.getName());
+ public void bindAttribLocation(GL2ES2 gl, int location, GLArrayData data) {
+ bindAttribLocation(gl, location, data.getName());
data.setLocation(location);
- vertexAttribMap2Data.put(data.getName(), data);
+ activeAttribDataMap.put(data.getName(), data);
}
/**
@@ -375,11 +399,11 @@ public class ShaderState {
* @throws GLException if the program is not linked and no location was cached.
*
* @see #getAttribLocation(String)
- * @see #glBindAttribLocation(GL2ES2, int, GLArrayData)
- * @see #glBindAttribLocation(GL2ES2, int, String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #bindAttribLocation(GL2ES2, int, String)
* @see GL2ES2#glGetAttribLocation(int, String)
*/
- public int glGetAttribLocation(GL2ES2 gl, String name) {
+ public int getAttribLocation(GL2ES2 gl, String name) {
if(null==shaderProgram) throw new GLException("No program is attached");
int location = getAttribLocation(name);
if(0>location) {
@@ -387,7 +411,7 @@ public class ShaderState {
location = gl.glGetAttribLocation(shaderProgram.program(), name);
if(0<=location) {
Integer idx = new Integer(location);
- attribMap2Location.put(name, idx);
+ activeAttribLocationMap.put(name, idx);
if(DEBUG) {
System.err.println("Info: glGetAttribLocation: "+name+", loc: "+location);
}
@@ -413,15 +437,15 @@ public class ShaderState {
* @throws GLException if the program is not linked and no location was cached.
*
* @see #getAttribLocation(String)
- * @see #glBindAttribLocation(GL2ES2, int, GLArrayData)
- * @see #glBindAttribLocation(GL2ES2, int, String)
+ * @see #bindAttribLocation(GL2ES2, int, GLArrayData)
+ * @see #bindAttribLocation(GL2ES2, int, String)
* @see GL2ES2#glGetAttribLocation(int, String)
* @see #getAttribute(String)
*/
- public int glGetAttribLocation(GL2ES2 gl, GLArrayData data) {
- int location = glGetAttribLocation(gl, data.getName());
+ public int getAttribLocation(GL2ES2 gl, GLArrayData data) {
+ int location = getAttribLocation(gl, data.getName());
data.setLocation(location);
- vertexAttribMap2Data.put(data.getName(), data);
+ activeAttribDataMap.put(data.getName(), data);
return location;
}
@@ -433,7 +457,7 @@ public class ShaderState {
* @return true if the named attribute is enable
*/
public final boolean isVertexAttribArrayEnabled(String name) {
- return enabledVertexAttribArraySet.contains(name);
+ return enabledAttributes.contains(name);
}
/**
@@ -443,10 +467,10 @@ public class ShaderState {
return isVertexAttribArrayEnabled(data.getName());
}
- private boolean glEnableVertexAttribArray(GL2ES2 gl, String name, int location) {
- enabledVertexAttribArraySet.add(name);
+ private boolean enableVertexAttribArray(GL2ES2 gl, String name, int location) {
+ enabledAttributes.add(name);
if(0>location) {
- location = glGetAttribLocation(gl, name);
+ location = getAttribLocation(gl, name);
if(0>location) {
if(verbose) {
Throwable tX = new Throwable("Info: glEnableVertexAttribArray failed, no index for: "+name);
@@ -465,15 +489,14 @@ public class ShaderState {
/**
* Enables a vertex attribute array.
*
- * This method retrieves the the location via {@link #glGetAttribLocation(GL2ES2, GLArrayData)}
- * hence {@link #glEnableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
+ * This method retrieves the the location via {@link #getAttribLocation(GL2ES2, GLArrayData)}
+ * hence {@link #enableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
*
* Even if the attribute is not found in the current shader,
* it is marked enabled in this state.
*
* @return false, if the name is not found, otherwise true
*
- * @throws GLException if no program is attached
* @throws GLException if the program is not linked and no location was cached.
*
* @see #glEnableVertexAttribArray
@@ -481,8 +504,8 @@ public class ShaderState {
* @see #glVertexAttribPointer
* @see #getVertexAttribPointer
*/
- public boolean glEnableVertexAttribArray(GL2ES2 gl, String name) {
- return glEnableVertexAttribArray(gl, name, -1);
+ public boolean enableVertexAttribArray(GL2ES2 gl, String name) {
+ return enableVertexAttribArray(gl, name, -1);
}
@@ -490,8 +513,8 @@ public class ShaderState {
* Enables a vertex attribute array, usually invoked by {@link GLArrayDataEditable#enableBuffer(GL, boolean)}.
*
* This method uses the {@link GLArrayData}'s location if set
- * and is the preferred alternative to {@link #glEnableVertexAttribArray(GL2ES2, String)}.
- * If data location is unset it will be retrieved via {@link #glGetAttribLocation(GL2ES2, GLArrayData)} set
+ * and is the preferred alternative to {@link #enableVertexAttribArray(GL2ES2, String)}.
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set
* and cached in this state.
*
* Even if the attribute is not found in the current shader,
@@ -499,7 +522,6 @@ public class ShaderState {
*
* @return false, if the name is not found, otherwise true
*
- * @throws GLException if no program is attached
* @throws GLException if the program is not linked and no location was cached.
*
* @see #glEnableVertexAttribArray
@@ -508,21 +530,20 @@ public class ShaderState {
* @see #getVertexAttribPointer
* @see GLArrayDataEditable#enableBuffer(GL, boolean)
*/
- public boolean glEnableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
- if(null==shaderProgram) throw new GLException("No program is attached");
+ public boolean enableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
if(0 > data.getLocation()) {
- glGetAttribLocation(gl, data);
+ getAttribLocation(gl, data);
} else {
// ensure data is the current bound one
- vertexAttribMap2Data.put(data.getName(), data);
+ activeAttribDataMap.put(data.getName(), data);
}
- return glEnableVertexAttribArray(gl, data.getName(), data.getLocation());
+ return enableVertexAttribArray(gl, data.getName(), data.getLocation());
}
- private boolean glDisableVertexAttribArray(GL2ES2 gl, String name, int location) {
- enabledVertexAttribArraySet.remove(name);
+ private boolean disableVertexAttribArray(GL2ES2 gl, String name, int location) {
+ enabledAttributes.remove(name);
if(0>location) {
- location = glGetAttribLocation(gl, name);
+ location = getAttribLocation(gl, name);
if(0>location) {
if(verbose) {
Throwable tX = new Throwable("Info: glDisableVertexAttribArray failed, no index for: "+name);
@@ -541,8 +562,8 @@ public class ShaderState {
/**
* Disables a vertex attribute array
*
- * This method retrieves the the location via {@link #glGetAttribLocation(GL2ES2, GLArrayData)}
- * hence {@link #glDisableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
+ * This method retrieves the the location via {@link #getAttribLocation(GL2ES2, GLArrayData)}
+ * hence {@link #disableVertexAttribArray(GL2ES2, GLArrayData)} shall be preferred.
*
* Even if the attribute is not found in the current shader,
* it is removed from this state enabled list.
@@ -557,16 +578,16 @@ public class ShaderState {
* @see #glVertexAttribPointer
* @see #getVertexAttribPointer
*/
- public boolean glDisableVertexAttribArray(GL2ES2 gl, String name) {
- return glDisableVertexAttribArray(gl, name, -1);
+ public boolean disableVertexAttribArray(GL2ES2 gl, String name) {
+ return disableVertexAttribArray(gl, name, -1);
}
/**
* Disables a vertex attribute array
*
* This method uses the {@link GLArrayData}'s location if set
- * and is the preferred alternative to {@link #glDisableVertexAttribArray(GL2ES2, String)}.
- * If data location is unset it will be retrieved via {@link #glGetAttribLocation(GL2ES2, GLArrayData)} set
+ * and is the preferred alternative to {@link #disableVertexAttribArray(GL2ES2, String)}.
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)} set
* and cached in this state.
*
* Even if the attribute is not found in the current shader,
@@ -582,41 +603,40 @@ public class ShaderState {
* @see #glVertexAttribPointer
* @see #getVertexAttribPointer
*/
- public boolean glDisableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
- if(null==shaderProgram) throw new GLException("No program is attached");
+ public boolean disableVertexAttribArray(GL2ES2 gl, GLArrayData data) {
if(0 > data.getLocation()) {
- glGetAttribLocation(gl, data);
+ getAttribLocation(gl, data);
}
- return glDisableVertexAttribArray(gl, data.getName(), data.getLocation());
+ return disableVertexAttribArray(gl, data.getName(), data.getLocation());
}
/**
* Set the {@link GLArrayData} vertex attribute data.
*
* This method uses the {@link GLArrayData}'s location if set.
- * If data location is unset it will be retrieved via {@link #glGetAttribLocation(GL2ES2, GLArrayData)}, set
+ * If data location is unset it will be retrieved via {@link #getAttribLocation(GL2ES2, GLArrayData)}, set
* and cached in this state.
*
* @return false, if the location could not be determined, otherwise true
*
- * @throws GLException if the program is not in use
- *
+ * @throws GLException if no program is attached
+ * @throws GLException if the program is not linked and no location was cached.
+ *
* @see #glEnableVertexAttribArray
* @see #glDisableVertexAttribArray
* @see #glVertexAttribPointer
* @see #getVertexAttribPointer
*/
- public boolean glVertexAttribPointer(GL2ES2 gl, GLArrayData data) {
- if(null==shaderProgram) throw new GLException("No program is attached");
- // if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- if(0 > data.getLocation()) {
- glGetAttribLocation(gl, data);
- } /* else {
- // Already achieved by glEnableVertexAttribArray(..)
+ public boolean vertexAttribPointer(GL2ES2 gl, GLArrayData data) {
+ int location = data.getLocation();
+ if(0 > location) {
+ location = getAttribLocation(gl, data);
+ } /* else {
+ done via enable ..
// ensure data is the current bound one
- vertexAttribMap2Data.put(data.getName(), data);
+ activeAttribDataMap.put(data.getName(), data);
} */
- if(0 <= data.getLocation()) {
+ if(0 <= location) {
// only pass the data, if the attribute exists in the current shader
if(DEBUG) {
System.err.println("Info: glVertexAttribPointer: "+data);
@@ -631,8 +651,6 @@ public class ShaderState {
* Releases all mapped vertex attribute data,
* disables all enabled attributes and loses all indices
*
- * @throws GLException is the program is not in use but the shaderProgram is set
- *
* @see #glEnableVertexAttribArray
* @see #glDisableVertexAttribArray
* @see #glVertexAttribPointer
@@ -642,23 +660,23 @@ public class ShaderState {
* @see #glResetAllVertexAttributes
* @see ShaderProgram#glReplaceShader
*/
- public void glReleaseAllVertexAttributes(GL2ES2 gl) {
+ public void releaseAllAttributes(GL2ES2 gl) {
if(null!=shaderProgram) {
- if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- for(Iterator<GLArrayData> iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) {
- if(!glDisableVertexAttribArray(gl, iter.next())) {
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ if(!disableVertexAttribArray(gl, iter.next())) {
throw new GLException("Internal Error: mapped vertex attribute couldn't be disabled");
}
}
- for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) {
- if(!glDisableVertexAttribArray(gl, (String) iter.next())) {
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
+ if(!disableVertexAttribArray(gl, iter.next())) {
throw new GLException("Internal Error: prev enabled vertex attribute couldn't be disabled");
}
}
}
- vertexAttribMap2Data.clear();
- enabledVertexAttribArraySet.clear();
- attribMap2Location.clear();
+ activeAttribDataMap.clear();
+ enabledAttributes.clear();
+ activeAttribLocationMap.clear();
+ managedAttributes.clear();
}
/**
@@ -669,8 +687,6 @@ public class ShaderState {
*
* This method purpose is more for debugging.
*
- * @throws GLException is the program is not in use but the shaderProgram is set
- *
* @see #glEnableVertexAttribArray
* @see #glDisableVertexAttribArray
* @see #glVertexAttribPointer
@@ -680,62 +696,92 @@ public class ShaderState {
* @see #glResetAllVertexAttributes
* @see ShaderProgram#glReplaceShader
*/
- public void glDisableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) {
- if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
-
- for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) {
- String name = (String) iter.next();
+ public void disableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) {
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
+ String name = iter.next();
if(removeFromState) {
- enabledVertexAttribArraySet.remove(name);
+ enabledAttributes.remove(name);
}
- int index = glGetAttribLocation(gl, name);
+ int index = getAttribLocation(gl, name);
if(0<=index) {
gl.glDisableVertexAttribArray(index);
}
}
}
+ private final void relocateAttribute(GL2ES2 gl, GLArrayData attribute) {
+ // get new location ..
+ String name = attribute.getName();
+ int loc = getAttribLocation(gl, name);
+ attribute.setLocation(loc);
+
+ if(0<=loc) {
+ if(enabledAttributes.contains(name)) {
+ // enable attrib, VBO and pass location/data
+ gl.glEnableVertexAttribArray(loc);
+ }
+
+ if( attribute.isVBO() ) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, attribute.getVBOName());
+ }
+
+ gl.glVertexAttribPointer(attribute);
+ }
+ }
+
/**
* Reset all previously enabled mapped vertex attribute data.
*
- * Attribute data is bound to the GL state<br>
- * Attribute location is bound to the program<br>
+ * <p>Attribute data is bound to the GL state</p>
+ * <p>Attribute location is bound to the program</p>
*
- * However, since binding an attribute to a location via {@link #glBindAttribLocation(GL2ES2, int, GLArrayData)}
+ * <p>However, since binding an attribute to a location via {@link #bindAttribLocation(GL2ES2, int, GLArrayData)}
* <i>must</i> happen before linking <b>and</b> we try to promote the attributes to the new program,
- * we have to gather the probably new location etc.
+ * we have to gather the probably new location etc.</p>
*
- * @throws GLException is the program is not in use
+ * @throws GLException is the program is not linked
*
* @see #attachShaderProgram(GL2ES2, ShaderProgram)
*/
- public void glResetAllVertexAttributes(GL2ES2 gl) {
- if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- attribMap2Location.clear();
+ private final void resetAllAttributes(GL2ES2 gl) {
+ if(!shaderProgram.linked()) throw new GLException("Program is not linked");
+ activeAttribLocationMap.clear();
- for(Iterator<GLArrayData> iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) {
- GLArrayData data = iter.next();
-
- // get new location ..
- String name = data.getName();
- int loc = glGetAttribLocation(gl, name);
- data.setLocation(loc);
-
- if(0>loc) {
- // not used in shader
- continue;
- }
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ iter.next().setLocation(-1);
+ }
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ relocateAttribute(gl, iter.next());
+ }
+ }
+
+ private final void setAttribute(GL2ES2 gl, GLArrayData attribute) {
+ // get new location ..
+ final String name = attribute.getName();
+ final int loc = attribute.getLocation();
+
+ if(0<=loc) {
+ this.bindAttribLocation(gl, loc, name);
- if(enabledVertexAttribArraySet.contains(name)) {
+ if(enabledAttributes.contains(name)) {
// enable attrib, VBO and pass location/data
gl.glEnableVertexAttribArray(loc);
}
-
- if( data.isVBO() ) {
- gl.glBindBuffer(GL.GL_ARRAY_BUFFER, data.getVBOName());
+
+ if( attribute.isVBO() ) {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, attribute.getVBOName());
}
-
- gl.glVertexAttribPointer(data);
+
+ gl.glVertexAttribPointer(attribute);
+ }
+ }
+
+ /**
+ * preserves the attribute location .. (program not linked)
+ */
+ private final void setAllAttributes(GL2ES2 gl) {
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ setAttribute(gl, iter.next());
}
}
@@ -744,6 +790,33 @@ public class ShaderState {
//
/**
+ * Bind the {@link GLUniform} lifecycle to this ShaderState.
+ *
+ * <p>If a uniform location is cached it is promoted to the {@link GLUniformData} instance.</p>
+ *
+ * <p>The attribute will be destroyed with {@link #destroy(GL2ES2)}
+ * and it's location will be reset when switching shader with {@link #attachShaderProgram(GL2ES2, ShaderProgram)}.</p>
+ *
+ * <p>The data will not be transfered to the GPU, use {@link #uniform(GL2ES2, GLUniformData)} additionally.</p>
+ *
+ * @param uniform the {@link GLUniformData} which lifecycle shall be managed
+ *
+ * @see #getUniform(String)
+ */
+ public void ownUniform(GLUniformData uniform) {
+ final int location = getUniformLocation(uniform.getName());
+ if(0<=location) {
+ uniform.setLocation(location);
+ }
+ activeUniformDataMap.put(uniform.getName(), uniform);
+ managedUniforms.add(uniform);
+ }
+
+ public boolean ownsUniform(GLUniformData uniform) {
+ return managedUniforms.contains(uniform);
+ }
+
+ /**
* Gets the index of a shader uniform.
* This must be done when the program is in use !
*
@@ -757,14 +830,14 @@ public class ShaderState {
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
- protected int glGetUniformLocation(GL2ES2 gl, String name) {
+ protected final int getUniformLocation(GL2ES2 gl, String name) {
if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
int location = getUniformLocation(name);
if(0>location) {
location = gl.glGetUniformLocation(shaderProgram.program(), name);
if(0<=location) {
Integer idx = new Integer(location);
- uniformMap2Location.put(name, idx);
+ activeUniformLocationMap.put(name, idx);
} else if(verbose) {
Throwable tX = new Throwable("Info: glUniform failed, no location for: "+name+", index: "+location);
tX.printStackTrace();
@@ -773,8 +846,8 @@ public class ShaderState {
return location;
}
- protected int getUniformLocation(String name) {
- Integer idx = (Integer) uniformMap2Location.get(name);
+ protected final int getUniformLocation(String name) {
+ Integer idx = (Integer) activeUniformLocationMap.get(name);
return (null!=idx)?idx.intValue():-1;
}
@@ -798,11 +871,14 @@ public class ShaderState {
* @see #getUniformLocation
* @see ShaderProgram#glReplaceShader
*/
- public boolean glUniform(GL2ES2 gl, GLUniformData data) {
+ public boolean uniform(GL2ES2 gl, GLUniformData data) {
if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- int location = glGetUniformLocation(gl, data.getName());
- data.setLocation(location);
- uniformMap2Data.put(data.getName(), data);
+ int location = data.getLocation();
+ if(0>location) {
+ location = getUniformLocation(gl, data.getName());
+ data.setLocation(location);
+ }
+ activeUniformDataMap.put(data.getName(), data);
if(0<=location) {
// only pass the data, if the uniform exists in the current shader
if(DEBUG) {
@@ -819,18 +895,17 @@ public class ShaderState {
* @return the GLUniformData object, null if not previously set.
*/
public GLUniformData getUniform(String name) {
- return uniformMap2Data.get(name);
+ return activeUniformDataMap.get(name);
}
/**
* Releases all mapped uniform data
* and loses all indices
- *
- * @throws GLException is the program is not in use
*/
- public void glReleaseAllUniforms(GL2ES2 gl) {
- uniformMap2Data.clear();
- uniformMap2Location.clear();
+ public void releaseAllUniforms(GL2ES2 gl) {
+ activeUniformDataMap.clear();
+ activeUniformLocationMap.clear();
+ managedUniforms.clear();
}
/**
@@ -843,11 +918,16 @@ public class ShaderState {
*
* @see #attachShaderProgram(GL2ES2, ShaderProgram)
*/
- public void glResetAllUniforms(GL2ES2 gl) {
- if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
- uniformMap2Location.clear();
- for(Iterator<GLUniformData> iter = uniformMap2Data.values().iterator(); iter.hasNext(); ) {
- glUniform(gl, iter.next());
+ private final void resetAllUniforms(GL2ES2 gl) {
+ if(!shaderProgram.inUse()) throw new GLException("Program is not in use");
+ activeUniformLocationMap.clear();
+ for(Iterator<GLUniformData> iter = managedUniforms.iterator(); iter.hasNext(); ) {
+ iter.next().setLocation(-1);
+ }
+ for(Iterator<GLUniformData> iter = activeUniformDataMap.values().iterator(); iter.hasNext(); ) {
+ final GLUniformData uniform = iter.next();
+ uniform.setLocation(-1);
+ uniform(gl, uniform);
}
}
@@ -858,26 +938,30 @@ public class ShaderState {
sb.append("ShaderState[");
sb.append(shaderProgram.toString());
- sb.append(",EnabledStates: [");
- for(Iterator iter = enabledVertexAttribArraySet.iterator(); iter.hasNext(); ) {
+ sb.append(", enabledAttributes: [");
+ for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) {
sb.append("\n ");
sb.append((String)iter.next());
}
- sb.append("], [");
- for(Iterator<GLArrayData> iter = vertexAttribMap2Data.values().iterator(); iter.hasNext(); ) {
- GLArrayData data = iter.next();
- if(data.getLocation()>=0) {
- sb.append("\n ");
- sb.append(data);
- }
+ sb.append("], activeAttributes [");
+ for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
}
- sb.append("], [");
- for(Iterator<GLUniformData> iter=uniformMap2Data.values().iterator(); iter.hasNext(); ) {
- GLUniformData data = iter.next();
- if(data.getLocation()>=0) {
- sb.append("\n ");
- sb.append(data);
- }
+ sb.append("], managedAttributes [");
+ for(Iterator<GLArrayData> iter = managedAttributes.iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
+ }
+ sb.append("], activeUniforms [");
+ for(Iterator<GLUniformData> iter=activeUniformDataMap.values().iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
+ }
+ sb.append("], managedUniforms [");
+ for(Iterator<GLUniformData> iter = managedUniforms.iterator(); iter.hasNext(); ) {
+ sb.append("\n ");
+ sb.append(iter.next());
}
sb.append("]");
return sb;
@@ -888,15 +972,17 @@ public class ShaderState {
return toString(null).toString();
}
- protected boolean verbose = false;
- protected ShaderProgram shaderProgram=null;
+ private boolean verbose = false;
+ private ShaderProgram shaderProgram=null;
- protected HashSet<String> enabledVertexAttribArraySet = new HashSet<String>();
- protected HashMap<String, Integer> attribMap2Location = new HashMap<String, Integer>();
- protected HashMap<String, GLArrayData> vertexAttribMap2Data = new HashMap<String, GLArrayData>();
+ private HashSet<String> enabledAttributes = new HashSet<String>();
+ private HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>();
+ private HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>();
+ private ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>();
- protected HashMap<String, Integer> uniformMap2Location = new HashMap<String, Integer>();
- protected HashMap<String, GLUniformData> uniformMap2Data = new HashMap<String, GLUniformData>();
+ private HashMap<String, Integer> activeUniformLocationMap = new HashMap<String, Integer>();
+ private HashMap<String, GLUniformData> activeUniformDataMap = new HashMap<String, GLUniformData>();
+ private ArrayList<GLUniformData> managedUniforms = new ArrayList<GLUniformData>();
private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
private IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
diff --git a/src/jogl/classes/javax/media/opengl/GLArrayData.java b/src/jogl/classes/javax/media/opengl/GLArrayData.java
index f375be623..448ddd10c 100644
--- a/src/jogl/classes/javax/media/opengl/GLArrayData.java
+++ b/src/jogl/classes/javax/media/opengl/GLArrayData.java
@@ -75,7 +75,7 @@ public interface GLArrayData {
* Sets the determined location of the shader attribute
* This is usually done within ShaderState.
*
- * @see com.jogamp.opengl.util.glsl.ShaderState#glVertexAttribPointer(GL2ES2, GLArrayData)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#vertexAttribPointer(GL2ES2, GLArrayData)
*/
public void setLocation(int v);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
index 4dcc4560e..0b47606e4 100755
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java
@@ -62,13 +62,13 @@ public class RegionRendererImpl01 extends RegionRenderer {
sp.init(gl);
st.attachShaderProgram(gl, sp);
- st.glBindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
- st.glBindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("RegionRenderer: Couldn't link program: "+sp);
}
- st.glUseProgram(gl, true);
+ st.useProgram(gl, true);
if(DEBUG) {
System.err.println("RegionRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
index 4c4a325ae..eef64dab5 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java
@@ -29,15 +29,13 @@ package jogamp.graph.curve.opengl;
import java.nio.FloatBuffer;
-import javax.media.opengl.GL;
-import javax.media.opengl.GLProfile;
+import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import jogamp.graph.curve.opengl.shader.UniformNames;
import com.jogamp.common.os.Platform;
-import com.jogamp.common.util.VersionUtil;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
@@ -45,22 +43,22 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class RenderStateImpl implements RenderState {
- public final ShaderState st;
- public final Vertex.Factory<? extends Vertex> pointFactory;
- public final PMVMatrix pmvMatrix;
- public final GLUniformData mgl_PMVMatrix;
+ private final ShaderState st;
+ private final Vertex.Factory<? extends Vertex> pointFactory;
+ private final PMVMatrix pmvMatrix;
+ private final GLUniformData gcu_PMVMatrix;
/**
* Sharpness is equivalent to the texture-coord component <i>t</i>
* on the off-curve vertex. Higher values of sharpness will
* result in higher curvature.
*/
- public final GLUniformData mgl_sharpness;
- public final GLUniformData mgl_alpha;
- public final GLUniformData mgl_colorStatic;
- public final GLUniformData mgl_strength;
+ private final GLUniformData gcu_Sharpness;
+ private final GLUniformData gcu_Alpha;
+ private final GLUniformData gcu_ColorStatic;
+ private final GLUniformData gcu_Strength;
- public static final RenderState getRenderState(GL gl) {
+ public static final RenderState getRenderState(GL2ES2 gl) {
return (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
}
@@ -68,12 +66,17 @@ public class RenderStateImpl implements RenderState {
this.st = st;
this.pointFactory = pointFactory;
this.pmvMatrix = pmvMatrix;
- this.mgl_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
+ this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
+ st.ownUniform(gcu_PMVMatrix);
- mgl_sharpness = new GLUniformData(UniformNames.gcu_P1Y, 0.5f);
- mgl_alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f);
- mgl_colorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3));
- mgl_strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f);
+ gcu_Sharpness = new GLUniformData(UniformNames.gcu_P1Y, 0.5f);
+ st.ownUniform(gcu_PMVMatrix);
+ gcu_Alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f);
+ st.ownUniform(gcu_Alpha);
+ gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3));
+ st.ownUniform(gcu_ColorStatic);
+ gcu_Strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f);
+ st.ownUniform(gcu_Strength);
}
public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
@@ -89,17 +92,21 @@ public class RenderStateImpl implements RenderState {
public final ShaderState getShaderState() { return st; }
public final Vertex.Factory<? extends Vertex> getPointFactory () { return pointFactory; }
- public final PMVMatrix getPMVMatrix() { return pmvMatrix; }
- public final GLUniformData getPMVMatrixUniform() { return mgl_PMVMatrix; }
- public final GLUniformData getSharpness() { return mgl_sharpness; }
- public final GLUniformData getAlpha() { return mgl_alpha; }
- public final GLUniformData getColorStatic() { return mgl_colorStatic; }
- public final GLUniformData getStrength() { return mgl_strength; }
+ public final PMVMatrix pmvMatrix() { return pmvMatrix; }
+ public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
+ public final GLUniformData getSharpness() { return gcu_Sharpness; }
+ public final GLUniformData getAlpha() { return gcu_Alpha; }
+ public final GLUniformData getColorStatic() { return gcu_ColorStatic; }
+ public final GLUniformData getStrength() { return gcu_Strength; }
- public final RenderState attachTo(GL gl) {
+ public void destroy(GL2ES2 gl) {
+ st.destroy(gl);
+ }
+
+ public final RenderState attachTo(GL2ES2 gl) {
return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this);
}
- public final boolean detachFrom(GL gl) {
+ public final boolean detachFrom(GL2ES2 gl) {
RenderState _rs = (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
if(_rs == this) {
gl.getContext().detachObject(RenderState.class.getName());
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
index 3bddaed3b..2255251a7 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
@@ -64,13 +64,13 @@ public class TextRendererImpl01 extends TextRenderer {
sp.init(gl);
st.attachShaderProgram(gl, sp);
- st.glBindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
- st.glBindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
+ st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
if(!sp.link(gl, System.err)) {
throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
}
- st.glUseProgram(gl, true);
+ st.useProgram(gl, true);
if(DEBUG) {
System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
index 181ce77b0..90b3d47cd 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java
@@ -93,7 +93,7 @@ public class VBORegion2PES2 implements Region {
texCoordFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(texCoordFboAttr);
+ st.ownAttribute(texCoordFboAttr, true);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(5);
texCoordFboAttr.putf(5); texCoordFboAttr.putf(6);
texCoordFboAttr.putf(6); texCoordFboAttr.putf(6);
@@ -102,7 +102,7 @@ public class VBORegion2PES2 implements Region {
verticeFboAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(verticeFboAttr);
+ st.ownAttribute(verticeFboAttr, true);
box = new AABBox();
@@ -111,11 +111,11 @@ public class VBORegion2PES2 implements Region {
verticeTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(verticeTxtAttr);
+ st.ownAttribute(verticeTxtAttr, true);
texCoordTxtAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(texCoordTxtAttr);
+ st.ownAttribute(texCoordTxtAttr, true);
if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Create: " + this);
@@ -232,7 +232,7 @@ public class VBORegion2PES2 implements Region {
gl.glGetIntegerv(GL.GL_ACTIVE_TEXTURE, currentActiveTextureEngine, 0);
*/
gl.glActiveTexture(activeTexture);
- st.glUniform(gl, mgl_ActiveTexture);
+ st.uniform(gl, mgl_ActiveTexture);
fbo.use(gl);
verticeFboAttr.enableBuffer(gl, true);
@@ -275,14 +275,14 @@ public class VBORegion2PES2 implements Region {
//render texture
gl.glViewport(0, 0, tex_width_c, tex_height_c);
- st.glUniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
+ st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT);
renderRegion(gl);
fbo.unbind(gl);
- st.glUniform(gl, rs.getPMVMatrixUniform()); // switch back to real PMV matrix
+ st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix
}
private void renderRegion(GL2ES2 gl) {
@@ -316,28 +316,22 @@ public class VBORegion2PES2 implements Region {
return dirty;
}
- public void destroy(GL2ES2 gl) {
+ public void destroy(GL2ES2 gl, RenderState rs) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Destroy: " + this);
}
- destroyFbo(gl);
- destroyTxtAttr(gl);
- destroyFboAttr(gl);
- triangles.clear();
- vertices.clear();
- }
- final void destroyFbo(GL2ES2 gl) {
+ final ShaderState st = rs.getShaderState();
if(null != fbo) {
fbo.destroy(gl);
fbo = null;
}
- }
- final void destroyTxtAttr(GL2ES2 gl) {
if(null != verticeTxtAttr) {
+ st.ownAttribute(verticeTxtAttr, false);
verticeTxtAttr.destroy(gl);
verticeTxtAttr = null;
}
if(null != texCoordTxtAttr) {
+ st.ownAttribute(texCoordTxtAttr, false);
texCoordTxtAttr.destroy(gl);
texCoordTxtAttr = null;
}
@@ -345,13 +339,13 @@ public class VBORegion2PES2 implements Region {
indicesTxt.destroy(gl);
indicesTxt = null;
}
- }
- final void destroyFboAttr(GL2ES2 gl) {
if(null != verticeFboAttr) {
+ st.ownAttribute(verticeFboAttr, false);
verticeFboAttr.destroy(gl);
verticeFboAttr = null;
}
if(null != texCoordFboAttr) {
+ st.ownAttribute(texCoordFboAttr, false);
texCoordFboAttr.destroy(gl);
texCoordFboAttr = null;
}
@@ -359,6 +353,8 @@ public class VBORegion2PES2 implements Region {
indicesFbo.destroy(gl);
indicesFbo = null;
}
+ triangles.clear();
+ vertices.clear();
}
public boolean isFlipped() {
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 1b295de16..7956e5137 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -62,15 +62,15 @@ public class VBORegionSPES2 implements Region {
final int initialSize = 256;
final ShaderState st = rs.getShaderState();
- indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialSize, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
verticeAttr = GLArrayDataServer.createGLSL(st, AttributeNames.VERTEX_ATTR_NAME, 3,
- GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(verticeAttr);
+ GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
+ st.ownAttribute(verticeAttr, true);
texCoordAttr = GLArrayDataServer.createGLSL(st, AttributeNames.TEXCOORD_ATTR_NAME, 2,
GL2ES2.GL_FLOAT, false, initialSize, GL.GL_STATIC_DRAW);
- st.bindAttribute(texCoordAttr);
+ st.ownAttribute(texCoordAttr, true);
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Create: " + this);
@@ -187,15 +187,18 @@ public class VBORegionSPES2 implements Region {
return dirty;
}
- public final void destroy(GL2ES2 gl) {
+ public final void destroy(GL2ES2 gl, RenderState rs) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Destroy: " + this);
}
+ final ShaderState st = rs.getShaderState();
if(null != verticeAttr) {
+ st.ownAttribute(verticeAttr, false);
verticeAttr.destroy(gl);
verticeAttr = null;
}
if(null != texCoordAttr) {
+ st.ownAttribute(texCoordAttr, false);
texCoordAttr.destroy(gl);
texCoordAttr = null;
}
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
index 8f7dcf30a..1faee87ff 100644
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
@@ -155,9 +155,10 @@ public class GlyphString {
}
/** Destroy the associated OGL objects
+ * @param rs TODO
*/
- public void destroy(GL2ES2 gl){
- region.destroy(gl);
+ public void destroy(GL2ES2 gl, RenderState rs){
+ region.destroy(gl, rs);
}
public AABBox getBounds(){
diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
index b77cf4617..fadce2b4d 100644
--- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
+++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncPipeline.java
@@ -83,9 +83,9 @@ public class FixedFuncPipeline {
}
public void glEnableClientState(GL2ES2 gl, int glArrayIndex) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
- shaderState.glEnableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
+ shaderState.enableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
// textureCoordsEnabled |= (1 << activeTextureUnit);
if ( textureCoordsEnabled.get(activeTextureUnit) != 1 ) {
textureCoordsEnabled.put(activeTextureUnit, 1);
@@ -94,9 +94,9 @@ public class FixedFuncPipeline {
}
public void glDisableClientState(GL2ES2 gl, int glArrayIndex) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
- shaderState.glDisableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
+ shaderState.disableVertexAttribArray(gl, getArrayIndexName(glArrayIndex));
// textureCoordsEnabled &= ~(1 << activeTextureUnit);
if ( textureCoordsEnabled.get(activeTextureUnit) != 0 ) {
textureCoordsEnabled.put(activeTextureUnit, 0);
@@ -105,37 +105,37 @@ public class FixedFuncPipeline {
}
public void glVertexPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glColorPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glColor4fv(GL2ES2 gl, FloatBuffer data ) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud = shaderState.getUniform(mgl_ColorStatic);
if(null!=ud) {
ud.setData(data);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glNormalPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.useProgram(gl, true);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glTexCoordPointer(GL2ES2 gl, GLArrayData data) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
data.setName( getArrayIndexName(data.getIndex()) );
- shaderState.glVertexAttribPointer(gl, data);
+ shaderState.vertexAttribPointer(gl, data);
}
public void glLightfv(GL2ES2 gl, int light, int pname, java.nio.FloatBuffer params) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
light -=GLLightingFunc.GL_LIGHT0;
if(0 <= light && light < MAX_LIGHTS) {
GLUniformData ud = null;
@@ -178,7 +178,7 @@ public class FixedFuncPipeline {
}
if(null!=ud) {
ud.setData(params);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
} else if(verbose) {
System.err.println("glLightfv light not within [0.."+MAX_LIGHTS+"]: "+light);
@@ -186,7 +186,7 @@ public class FixedFuncPipeline {
}
public void glMaterialfv(GL2ES2 gl, int face, int pname, java.nio.FloatBuffer params) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
switch (face) {
case GL.GL_FRONT:
@@ -228,33 +228,33 @@ public class FixedFuncPipeline {
}
if(null!=ud) {
ud.setData(params);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glShadeModel(GL2ES2 gl, int mode) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud = shaderState.getUniform(mgl_ShadeModel);
if(null!=ud) {
ud.setData(mode);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
public void glActiveTexture(GL2ES2 gl, int textureUnit) {
textureUnit -= GL.GL_TEXTURE0;
if(0 <= textureUnit && textureUnit<MAX_TEXTURE_UNITS) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud;
ud = shaderState.getUniform(mgl_ActiveTexture);
if(null!=ud) {
ud.setData(textureUnit);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
ud = shaderState.getUniform(mgl_ActiveTextureIdx);
if(null!=ud) {
ud.setData(textureUnit);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
activeTextureUnit = textureUnit;
} else {
@@ -310,20 +310,20 @@ public class FixedFuncPipeline {
}
public void validate(GL2ES2 gl) {
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
GLUniformData ud;
if(pmvMatrix.update()) {
ud = shaderState.getUniform(mgl_PMVMatrix);
if(null!=ud) {
// same data object ..
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
} else {
- throw new GLException("Failed to update: mgl_PMVMatrix");
+ throw new GLException("Failed to update: gcu_PMVMatrix");
}
ud = shaderState.getUniform(mgl_NormalMatrix);
if(null!=ud) {
// same data object ..
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
ud = shaderState.getUniform(mgl_ColorEnabled);
@@ -331,14 +331,14 @@ public class FixedFuncPipeline {
int ca = (shaderState.isVertexAttribArrayEnabled(mgl_Color)==true)?1:0;
if(ca!=ud.intValue()) {
ud.setData(ca);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
ud = shaderState.getUniform(mgl_CullFace);
if(null!=ud) {
if(cullFace!=ud.intValue()) {
ud.setData(cullFace);
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
}
@@ -346,7 +346,7 @@ public class FixedFuncPipeline {
ud = shaderState.getUniform(mgl_LightsEnabled);
if(null!=ud) {
// same data object
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
lightsEnabledDirty=false;
}
@@ -355,7 +355,7 @@ public class FixedFuncPipeline {
ud = shaderState.getUniform(mgl_TexCoordEnabled);
if(null!=ud) {
// same data object
- shaderState.glUniform(gl, ud);
+ shaderState.uniform(gl, ud);
}
textureCoordsEnabledDirty=false;
}
@@ -447,43 +447,43 @@ public class FixedFuncPipeline {
}
shaderState.attachShaderProgram(gl, shaderProgramColor);
- shaderState.glUseProgram(gl, true);
+ shaderState.useProgram(gl, true);
// mandatory ..
- if(!shaderState.glUniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) {
+ if(!shaderState.uniform(gl, new GLUniformData(mgl_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMviMatrixf()))) {
throw new GLException("Error setting PMVMatrix in shader: "+this);
}
// optional parameter ..
- shaderState.glUniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf()));
-
- shaderState.glUniform(gl, new GLUniformData(mgl_ColorEnabled, 0));
- shaderState.glUniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f));
- shaderState.glUniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled));
- shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit));
- shaderState.glUniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit));
- shaderState.glUniform(gl, new GLUniformData(mgl_ShadeModel, 0));
- shaderState.glUniform(gl, new GLUniformData(mgl_CullFace, cullFace));
+ shaderState.uniform(gl, new GLUniformData(mgl_NormalMatrix, 3, 3, pmvMatrix.glGetNormalMatrixf()));
+
+ shaderState.uniform(gl, new GLUniformData(mgl_ColorEnabled, 0));
+ shaderState.uniform(gl, new GLUniformData(mgl_ColorStatic, 4, zero4f));
+ shaderState.uniform(gl, new GLUniformData(mgl_TexCoordEnabled, 1, textureCoordsEnabled));
+ shaderState.uniform(gl, new GLUniformData(mgl_ActiveTexture, activeTextureUnit));
+ shaderState.uniform(gl, new GLUniformData(mgl_ActiveTextureIdx, activeTextureUnit));
+ shaderState.uniform(gl, new GLUniformData(mgl_ShadeModel, 0));
+ shaderState.uniform(gl, new GLUniformData(mgl_CullFace, cullFace));
for(int i=0; i<MAX_LIGHTS; i++) {
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].ambient", 4, defAmbient));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].diffuse", 4, defDiffuse));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].specular", 4, defSpecular));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].position", 4, defPosition));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotDirection", 3, defSpotDir));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotExponent", defSpotExponent));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotCutoff", defSpotCutoff));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].constantAttenuation", defConstantAtten));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].linearAttenuation", defLinearAtten));
- shaderState.glUniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].quadraticAttenuation", defQuadraticAtten));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].ambient", 4, defAmbient));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].diffuse", 4, defDiffuse));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].specular", 4, defSpecular));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].position", 4, defPosition));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotDirection", 3, defSpotDir));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotExponent", defSpotExponent));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].spotCutoff", defSpotCutoff));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].constantAttenuation", defConstantAtten));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].linearAttenuation", defLinearAtten));
+ shaderState.uniform(gl, new GLUniformData(mgl_LightSource+"["+i+"].quadraticAttenuation", defQuadraticAtten));
}
- shaderState.glUniform(gl, new GLUniformData(mgl_LightsEnabled, 1, lightsEnabled));
- shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".ambient", 4, defMatAmbient));
- shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".diffuse", 4, defMatDiffuse));
- shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".specular", 4, defMatSpecular));
- shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".emission", 4, defMatEmission));
- shaderState.glUniform(gl, new GLUniformData(mgl_FrontMaterial+".shininess", defMatShininess));
-
- shaderState.glUseProgram(gl, false);
+ shaderState.uniform(gl, new GLUniformData(mgl_LightsEnabled, 1, lightsEnabled));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".ambient", 4, defMatAmbient));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".diffuse", 4, defMatDiffuse));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".specular", 4, defMatSpecular));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".emission", 4, defMatEmission));
+ shaderState.uniform(gl, new GLUniformData(mgl_FrontMaterial+".shininess", defMatShininess));
+
+ shaderState.useProgram(gl, false);
}
protected static final boolean DEBUG=false;
@@ -508,7 +508,7 @@ public class FixedFuncPipeline {
protected ShaderProgram shaderProgramColorTextureLight;
// uniforms ..
- protected static final String mgl_PMVMatrix = "mgl_PMVMatrix"; // m4fv[3]
+ protected static final String mgl_PMVMatrix = "gcu_PMVMatrix"; // m4fv[3]
protected static final String mgl_NormalMatrix = "mgl_NormalMatrix"; // m4fv
protected static final String mgl_ColorEnabled = "mgl_ColorEnabled"; // 1i
protected static final String mgl_ColorStatic = "mgl_ColorStatic"; // 4fv