diff options
author | Michael Bien <[email protected]> | 2011-06-20 00:35:16 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-06-20 00:35:16 +0200 |
commit | a256925d0f589e387bd6370a7b4c5ab7c8b0b01e (patch) | |
tree | 38f3c6e99f860fd43c19c59f8ca96a241252684d | |
parent | 3016f4fe04dcabdd82d2475a7c23d3b47e1c8766 (diff) |
varargs createProgram(...) methods for convenient concatenation.
-rw-r--r-- | src/com/jogamp/opencl/CLContext.java | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java index a901de4f..54f95728 100644 --- a/src/com/jogamp/opencl/CLContext.java +++ b/src/com/jogamp/opencl/CLContext.java @@ -255,27 +255,52 @@ public class CLContext extends CLObjectResource { } /** + * Creates a program from the given sources, the returned program is not build yet. + */ + public CLProgram createProgram(String... sources) { + + if(sources.length == 0) + throw new IllegalArgumentException("source string array was empty"); + + StringBuilder sb = new StringBuilder(2048*sources.length); + for (String source : sources) { + sb.append(source); + } + + return createProgram(sb); + } + + /** * Creates a program and reads the source from stream, the returned program is not build yet. * The InputStream is automatically closed after the sources have been read. + * Multiple streams are concatenated to one sourcecode String in the order they are provided. * @throws IOException when a IOException occurred while reading or closing the stream. */ - public CLProgram createProgram(InputStream source) throws IOException { - - if(source == null) - throw new IllegalArgumentException("input stream for program source must not be null"); + public CLProgram createProgram(InputStream... sources) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(source)); - StringBuilder sb = new StringBuilder(2048); + if(sources.length == 0) + throw new IllegalArgumentException("input stream array was empty"); - String line; - try { - while ((line = reader.readLine()) != null) - sb.append(line).append("\n"); - } finally { - reader.close(); + StringBuilder sb = new StringBuilder(2048*sources.length); + for (InputStream source : sources) { + BufferedReader reader = new BufferedReader(new InputStreamReader(source)); + try { + String line; + while ((line = reader.readLine()) != null) + sb.append(line).append("\n"); + } finally { + reader.close(); + } } - return createProgram(sb.toString()); + return createProgram(sb); + } + + /** + * Creates a program from the given sources, the returned program is not build yet. + */ + private CLProgram createProgram(StringBuilder sources) { + return createProgram(sources.toString()); } /** |