diff options
author | Kenneth Russel <[email protected]> | 2009-06-15 22:57:38 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2009-06-15 22:57:38 +0000 |
commit | a959c53b7ac91e489bf0959391e892790b9ff248 (patch) | |
tree | 4664742a4f9f6daa694364292e376ad2e6ee97d1 /make/config/jogl/cg-common-CustomJavaCode.java | |
parent | 506b634b780dcd23aa61015c2ceba3e687196abf (diff) |
Copied JOGL_2_SANDBOX r1957 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1959 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make/config/jogl/cg-common-CustomJavaCode.java')
-rwxr-xr-x | make/config/jogl/cg-common-CustomJavaCode.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/make/config/jogl/cg-common-CustomJavaCode.java b/make/config/jogl/cg-common-CustomJavaCode.java new file mode 100755 index 000000000..1f109d9f6 --- /dev/null +++ b/make/config/jogl/cg-common-CustomJavaCode.java @@ -0,0 +1,29 @@ +static { + com.sun.opengl.impl.NativeLibLoader.loadCgImpl(); +} + +/** A convenience method which reads all available data from the InputStream and then calls cgCreateProgram. */ +public static CGprogram cgCreateProgramFromStream(CGcontext ctx, int program_type, java.io.InputStream stream, int profile, java.lang.String entry, java.lang.String[] args) throws java.io.IOException { + if (stream == null) { + throw new java.io.IOException("null stream"); + } + stream = new java.io.BufferedInputStream(stream); + int avail = stream.available(); + byte[] data = new byte[avail]; + int numRead = 0; + int pos = 0; + do { + if (pos + avail > data.length) { + byte[] newData = new byte[pos + avail]; + System.arraycopy(data, 0, newData, 0, pos); + data = newData; + } + numRead = stream.read(data, pos, avail); + if (numRead >= 0) { + pos += numRead; + } + avail = stream.available(); + } while (avail > 0 && numRead >= 0); + String program = new String(data, 0, pos, "US-ASCII"); + return cgCreateProgram(ctx, program_type, program, profile, entry, args); +} |