summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java41
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java20
2 files changed, 47 insertions, 14 deletions
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 <code>data</code> at <code>offset</code> in shader source for shader <code>shaderIdx</code>.
+ * Adds <code>data</code> at <code>position</code> in shader source for shader <code>shaderIdx</code>.
* <p>
* Note: The shader source to be edit must be created using a mutable StringBuilder.
* </p>
*
* @param shaderIdx the shader index to be used.
- * @param position in shader source segments of shader <code>shaderIdx</code>
+ * @param position in shader source segments of shader <code>shaderIdx</code>, -1 will append data
* @param data the text to be inserted. Shall end with an EOL '\n' character
* @return index after the inserted <code>data</code>
*
@@ -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 <code>path</code>,
+ * either relative to the <code>context</code> class or absolute <i>as-is</i>
+ * at <code>position</code> in shader source for shader <code>shaderIdx</code>.
+ * <p>
+ * Final location lookup is performed via {@link ClassLoader#getResource(String)} and {@link ClassLoader#getSystemResource(String)},
+ * see {@link IOUtil#getResource(Class, String)}.
+ * </p>
+ * <p>
+ * Note: The shader source to be edit must be created using a mutable StringBuilder.
+ * </p>
+ *
+ * @param shaderIdx the shader index to be used.
+ * @param position in shader source segments of shader <code>shaderIdx</code>, -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 <code>StringBuilder</code>
+ * @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<managedAttributes.size(); i++) {
- ((GLArrayData)managedAttributes.get(i)).setLocation(-1);
+ managedAttributes.get(i).setLocation(-1);
}
for(Iterator<GLArrayData> 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<String, Boolean> activedAttribEnabledMap = new HashMap<String, Boolean>();
- 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>();
+ private final HashMap<String, Boolean> activedAttribEnabledMap = new HashMap<String, Boolean>();
+ private final HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>();
+ private final HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>();
+ private final ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>();
- 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 final HashMap<String, Integer> activeUniformLocationMap = new HashMap<String, Integer>();
+ private final HashMap<String, GLUniformData> activeUniformDataMap = new HashMap<String, GLUniformData>();
+ private final ArrayList<GLUniformData> managedUniforms = new ArrayList<GLUniformData>();
- private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
+ private final HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
private boolean resetAllShaderData = false;
}