summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-05-17 07:55:59 +0200
committerSven Gothel <[email protected]>2013-05-17 07:55:59 +0200
commitb2802021acf8aa9b363ebef383c8dc8c8079ffa4 (patch)
tree7a9ba6c7b951e6eaf5fe7f91c5ef00ad9b357279 /src/jogl/classes/com
parent33abeb8097a8f80acd1a4ce94b4866e5dc41f0c0 (diff)
Fix Bug 711: Align Graphs's Curve Shader programmatically to used GL/GLSL version, following all other internal GLSL usage utilizing ShaderCode.
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java35
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java28
2 files changed, 47 insertions, 16 deletions
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 fcccf592e..998129551 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java
@@ -33,6 +33,7 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLException;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.opengl.util.PMVMatrix;
@@ -263,21 +264,31 @@ public abstract class Renderer {
return true;
}
- protected String getVertexShaderName(GL2ES2 gl) {
- return "curverenderer01" + getShaderGLVersionSuffix(gl);
+ protected String getVertexShaderName() {
+ return "curverenderer" + getImplVersion();
}
- protected String getFragmentShaderName(GL2ES2 gl) {
- final String type = "01" ; // Region.isNonUniformWeight(renderModes) ? "02" : "01" ;
- final String pass = Region.isVBAA(renderModes) ? "b" : "a" ;
- return "curverenderer" + type + pass + getShaderGLVersionSuffix(gl);
+ protected String getFragmentShaderName() {
+ final String version = getImplVersion();
+ final String pass = Region.isVBAA(renderModes) ? "-2pass" : "-1pass" ;
+ final String weight = Region.isNonUniformWeight(renderModes) ? "-weight" : "" ;
+ return "curverenderer" + version + pass + weight;
}
-
- protected String getShaderGLVersionSuffix(GL2ES2 gl) {
- if(gl.isGLES2()) {
- return "-es2";
+
+ // FIXME: Really required to have sampler2D def. precision ? If not, we can drop getFragmentShaderPrecision(..) and use default ShaderCode ..
+ public static final String es2_precision_fp = "\nprecision mediump float;\nprecision mediump int;\nprecision mediump sampler2D;\n";
+
+ protected String getFragmentShaderPrecision(GL2ES2 gl) {
+ if( gl.isGLES2() ) {
+ return es2_precision_fp;
}
- return "-gl2";
- }
+ if( ShaderCode.requiresGL3DefaultPrecision(gl) ) {
+ return ShaderCode.gl3_default_precision_fp;
+ }
+ return null;
+ }
+ protected String getImplVersion() {
+ return "01";
+ }
} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
index 80a7efaec..edc3d2677 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
@@ -684,7 +684,7 @@ public class ShaderCode {
*
* @param shaderIdx the shader index to be used.
* @param position in shader source segments of shader <code>shaderIdx</code>
- * @param data the text to be inserted. Shall end with an EOL '\n' character.
+ * @param data the text to be inserted. Shall end with an EOL '\n' character
* @return index after the inserted <code>data</code>
*
* @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type <code>StringBuilder</code>
@@ -833,8 +833,11 @@ public class ShaderCode {
/** Default precision of GLSL &ge; 1.30 as required until &lt; 1.50 for {@link GL2ES2#GL_VERTEX_SHADER vertex-shader} or {@link GL3#GL_GEOMETRY_SHADER geometry-shader}: {@value #gl3_default_precision_vp_gp}. See GLSL Spec 1.30-1.50 Section 4.5.3. */
public static final String gl3_default_precision_vp_gp = "\nprecision highp float;\nprecision highp int;\n";
/** Default precision of GLSL &ge; 1.30 as required until &lt; 1.50 for {@link GL2ES2#GL_FRAGMENT_SHADER fragment-shader}: {@value #gl3_default_precision_fp}. See GLSL Spec 1.30-1.50 Section 4.5.3. */
- public static final String gl3_default_precision_fp = "\nprecision highp float;\nprecision mediump int;\n";
+ public static final String gl3_default_precision_fp = "\nprecision highp float;\nprecision mediump int;\n/*precision mediump sampler2D;*/\n";
+ /** Prefer <code>enable</code> over <code>require</code>, since it won't force a failure. */
+ public static final String extOESDerivativesEnable = "#extension GL_OES_standard_derivatives : enable\n";
+
/**
* Add GLSL version at the head of this shader source code.
* <p>
@@ -860,7 +863,6 @@ public class ShaderCode {
* @return the index after the inserted data, maybe 0 if nothing has be inserted.
*/
public final int addDefaultShaderPrecision(GL2ES2 gl, int pos) {
- final VersionNumber glslVersion = gl.getContext().getGLSLVersionNumber();
final String defaultPrecision;
if( gl.isGLES2() ) {
switch ( shaderType ) {
@@ -872,7 +874,7 @@ public class ShaderCode {
defaultPrecision = null;
break;
}
- } else if( glslVersion.compareTo(GLContext.Version130) >= 0 && glslVersion.compareTo(GLContext.Version150) < 0 ) {
+ } else if( requiresGL3DefaultPrecision(gl) ) {
// GLSL [ 1.30 .. 1.50 [ needs at least fragement float default precision!
switch ( shaderType ) {
case GL2ES2.GL_VERTEX_SHADER:
@@ -893,6 +895,24 @@ public class ShaderCode {
return pos;
}
+ /** Returns true, if GLSL version requires default precision, i.e. ES2 or GLSL [1.30 .. 1.50[. */
+ public static final boolean requiresDefaultPrecision(GL2ES2 gl) {
+ if( gl.isGLES2() ) {
+ return true;
+ }
+ return requiresGL3DefaultPrecision(gl);
+ }
+
+ /** Returns true, if GL3 GLSL version requires default precision, i.e. GLSL [1.30 .. 1.50[. */
+ public static final boolean requiresGL3DefaultPrecision(GL2ES2 gl) {
+ if( gl.isGL3() ) {
+ final VersionNumber glslVersion = gl.getContext().getGLSLVersionNumber();
+ return glslVersion.compareTo(GLContext.Version130) >= 0 && glslVersion.compareTo(GLContext.Version150) < 0 ;
+ } else {
+ return false;
+ }
+ }
+
/**
* Default customization of this shader source code.
* <p>