aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-05-08 05:30:38 +0200
committerSven Gothel <[email protected]>2011-05-08 05:30:38 +0200
commitd60bc9c4bc4a6f99bafa8c723b3d7f3bacc80950 (patch)
tree1afd4889cfe02a255eaa9e297821c3f4eec0e2c1 /src
parent9caa7eeee9408fdafa8b3bc04bd963e2fa818e13 (diff)
Graph: RenderState (interface -> abstract) missing commit of e122b2f92b2302362569cdc9a67efd5750f46eb1
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java79
1 files changed, 65 insertions, 14 deletions
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 991d07012..e0d2490dc 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -30,26 +30,77 @@ package com.jogamp.graph.curve.opengl;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLUniformData;
+import jogamp.graph.curve.opengl.RenderStateImpl;
+import jogamp.graph.curve.opengl.shader.UniformNames;
+
+import com.jogamp.common.os.Platform;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
-public interface RenderState {
+public abstract class RenderState {
+
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) {
+ return new RenderStateImpl(st, pointFactory);
+ }
+
+ public static RenderState createRenderState(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
+ return new RenderStateImpl(st, pointFactory, pmvMatrix);
+ }
+
+ protected final ShaderState st;
+ protected final Vertex.Factory<? extends Vertex> vertexFactory;
+ protected final PMVMatrix pmvMatrix;
+ protected final GLUniformData gcu_PMVMatrix;
+
+ protected RenderState(ShaderState st, Vertex.Factory<? extends Vertex> vertexFactory, PMVMatrix pmvMatrix) {
+ this.st = st;
+ this.vertexFactory = vertexFactory;
+ this.pmvMatrix = pmvMatrix;
+ this.gcu_PMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
+ st.ownUniform(gcu_PMVMatrix);
+ }
+
+ public final ShaderState getShaderState() { return st; }
+ public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
+ public final PMVMatrix pmvMatrix() { return pmvMatrix; }
+ public final GLUniformData getPMVMatrix() { return gcu_PMVMatrix; }
- void destroy(GL2ES2 gl);
+ public void destroy(GL2ES2 gl) {
+ st.destroy(gl);
+ }
- ShaderState getShaderState();
- Vertex.Factory<? extends Vertex> getPointFactory();
- PMVMatrix pmvMatrix();
- GLUniformData getPMVMatrix();
- GLUniformData getWeight();
- GLUniformData getAlpha();
- GLUniformData getColorStatic();
- // GLUniformData getStrength();
+ public abstract GLUniformData getWeight();
+ public abstract GLUniformData getAlpha();
+ public abstract GLUniformData getColorStatic();
+ // public abstract GLUniformData getStrength();
- RenderState attachTo(GL2ES2 gl);
- boolean detachFrom(GL2ES2 gl);
+ public final RenderState attachTo(GL2ES2 gl) {
+ return (RenderState) gl.getContext().attachObject(RenderState.class.getName(), this);
+ }
+
+ public final boolean detachFrom(GL2ES2 gl) {
+ RenderState _rs = (RenderState) gl.getContext().getAttachedObject(RenderState.class.getName());
+ if(_rs == this) {
+ gl.getContext().detachObject(RenderState.class.getName());
+ return true;
+ }
+ return false;
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+
+ sb.append("RenderState[");
+ st.toString(sb).append(Platform.getNewline());
+ sb.append("]");
+
+ return sb;
+ }
- StringBuilder toString(StringBuilder sb);
- String toString();
+ public String toString() {
+ return toString(null).toString();
+ }
}