From d989b90de1200642fe3508f6a4cd623aa0ba13c9 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 16 Apr 2012 20:59:30 +0200 Subject: ShaderCode: Adding 'replaceInShaderSource a -> b utility function --- .../com/jogamp/opengl/util/glsl/ShaderCode.java | 56 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util') 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 e347b4171..f6b686d7e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -564,6 +564,8 @@ public class ShaderCode { * @param fromIndex start search tag begininig with this index * @param data the text to be inserted. Shall end with an EOL '\n' character. * @return index after the inserted data + * + * @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type StringBuilder */ public int insertShaderSource(int shaderIdx, String tag, int fromIndex, CharSequence data) { if(null==shaderSource) { @@ -607,6 +609,56 @@ public class ShaderCode { return -1; } + /** + * Replaces oldName with newName in all shader sources. + *

+ * In case oldName and newName are equal, no action is performed. + *

+ *

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

+ * + * @param oldName the to be replace string + * @param newName the replacement string + * @return the number of replacements + * + * @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type StringBuilder + */ + public int replaceInShaderSource(String oldName, String newName) { + if(null==shaderSource) { + throw new IllegalStateException("no shader source"); + } + if(oldName == newName || oldName.equals(newName)) { + return 0; + } + final int oldNameLen = oldName.length(); + final int newNameLen = newName.length(); + int num = 0; + final int sourceCount = (null!=shaderSource)?shaderSource.length:0; + for(int shaderIdx = 0; shaderIdxdata at offset in shader source for shader shaderIdx. *

@@ -617,6 +669,8 @@ public class ShaderCode { * @param position in shader source segments of shader shaderIdx * @param data the text to be inserted. Shall end with an EOL '\n' character. * @return index after the inserted data + * + * @throws IllegalStateException if the shader source's CharSequence is immutable, i.e. not of type StringBuilder */ public int insertShaderSource(int shaderIdx, int position, CharSequence data) { if(null==shaderSource) { @@ -645,7 +699,7 @@ public class ShaderCode { } return -1; } - + private static int readShaderSource(Class context, URLConnection conn, StringBuilder result, int lineno) throws IOException { if(DEBUG_CODE) { if(0 == lineno) { -- cgit v1.2.3