From b935d5248aef79e2386a284b32f5888348a382d6 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 Apr 2014 16:31:05 +0200 Subject: Bug 801: WIP 1/2 - Add color attribute; Switch Shader instead of branching in shader; Update attributes and uniforms manually, drop ShaderState; - ShaderCode - add int insertShaderSource(int shaderIdx, int position, Class context, String path) - insertShaderSource(..): pos==-1 -> append code - VectorUtil - add isVec3InTriangle3(..., float epsilon) - add testSeg2SegIntersection(..., float epsilon) - add testTri2SegIntersection(..., float epsilon) - AffineTransform: Return result for chaining - Font - Add pixel precise 'getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize)' - Rename getString*() -> getMetric*() - OTGlyph: Release _points field, no more used - - Graph Triangulation - Count additional vertices in: Triangulator, CDTriangulator2D - OutlineShape: - Allow skipping of 'transformOutlines2Quadratic', i.e. allow tagging OutlineShape to be quadratic_nurbs via 'setIsQuadraticNurbs()' - Clarify cleanup ot outlines in same method 'cleanupOutlines()' - Count additional vertices .. - Graph Shader: - Start splitting and segmenting shader code for: - pass1 / pass2 - features, i.e. sampleCont, color-channel, .. --- .../com/jogamp/opengl/util/glsl/ShaderCode.java | 41 +++++++++++++++++++--- .../com/jogamp/opengl/util/glsl/ShaderState.java | 20 +++++------ 2 files changed, 47 insertions(+), 14 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util/glsl') 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 264b9e2a6..812cbcc9d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -686,13 +686,13 @@ public class ShaderCode { } /** - * Adds data at offset in shader source for shader shaderIdx. + * Adds data at position in shader source for shader shaderIdx. *

* Note: The shader source to be edit must be created using a mutable StringBuilder. *

* * @param shaderIdx the shader index to be used. - * @param position in shader source segments of shader shaderIdx + * @param position in shader source segments of shader shaderIdx, -1 will append data * @param data the text to be inserted. Shall end with an EOL '\n' character * @return index after the inserted data * @@ -718,7 +718,10 @@ public class ShaderCode { } final StringBuilder sb = (StringBuilder)src[j]; curEndIndex += sb.length(); - if(position < curEndIndex) { + if( 0 > position && j == src.length - 1 ) { + position = curEndIndex; + } + if(0 <= position && position <= curEndIndex ) { sb.insert(position, data); return position+data.length(); } @@ -726,6 +729,36 @@ public class ShaderCode { return -1; } + /** + * Adds shader source located in path, + * either relative to the context class or absolute as-is + * at position in shader source for shader shaderIdx. + *

+ * Final location lookup is performed via {@link ClassLoader#getResource(String)} and {@link ClassLoader#getSystemResource(String)}, + * see {@link IOUtil#getResource(Class, String)}. + *

+ *

+ * Note: The shader source to be edit must be created using a mutable StringBuilder. + *

+ * + * @param shaderIdx the shader index to be used. + * @param position in shader source segments of shader shaderIdx, -1 will append data + * @param context class used to help resolve the source location + * @param path location of shader source + * @return index after the inserted code. + * @throws IOException + * @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type StringBuilder + * @see IOUtil#getResource(Class, String) + */ + public int insertShaderSource(int shaderIdx, int position, Class context, String path) throws IOException { + final CharSequence data = readShaderSource(context, path, true); + if( null != data ) { + return insertShaderSource(shaderIdx, position, data); + } else { + return position; + } + } + @SuppressWarnings("resource") private static int readShaderSource(Class context, URLConnection conn, StringBuilder result, int lineno) throws IOException { if(DEBUG_CODE) { @@ -869,7 +902,7 @@ public class ShaderCode { * @return the complete extension directive */ public static String createExtensionDirective(String extensionName, String behavior) { - return "#extension " + extensionName + " : " + behavior; + return "#extension " + extensionName + " : " + behavior + "\n"; } /** 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 f60cb6088..ce4c2615d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -766,7 +766,7 @@ public class ShaderState { activeAttribLocationMap.clear(); for(int i=0; i iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) { relocateAttribute(gl, iter.next()); @@ -816,7 +816,7 @@ public class ShaderState { * otherwise >= 0 */ public final int getCachedUniformLocation(String name) { - Integer idx = (Integer) activeUniformLocationMap.get(name); + Integer idx = activeUniformLocationMap.get(name); return (null!=idx)?idx.intValue():-1; } @@ -1075,16 +1075,16 @@ public class ShaderState { private boolean verbose = DEBUG; private ShaderProgram shaderProgram=null; - private HashMap activedAttribEnabledMap = new HashMap(); - private HashMap activeAttribLocationMap = new HashMap(); - private HashMap activeAttribDataMap = new HashMap(); - private ArrayList managedAttributes = new ArrayList(); + private final HashMap activedAttribEnabledMap = new HashMap(); + private final HashMap activeAttribLocationMap = new HashMap(); + private final HashMap activeAttribDataMap = new HashMap(); + private final ArrayList managedAttributes = new ArrayList(); - private HashMap activeUniformLocationMap = new HashMap(); - private HashMap activeUniformDataMap = new HashMap(); - private ArrayList managedUniforms = new ArrayList(); + private final HashMap activeUniformLocationMap = new HashMap(); + private final HashMap activeUniformDataMap = new HashMap(); + private final ArrayList managedUniforms = new ArrayList(); - private HashMap attachedObjectsByString = new HashMap(); + private final HashMap attachedObjectsByString = new HashMap(); private boolean resetAllShaderData = false; } -- cgit v1.2.3