aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java41
1 files changed, 37 insertions, 4 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";
}
/**