aboutsummaryrefslogtreecommitdiffstats
path: root/make/cg-common-CustomJavaCode.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-05-13 23:57:47 +0000
committerKenneth Russel <[email protected]>2005-05-13 23:57:47 +0000
commit898b3381fc80f0b08225f33c6fc0669ffb0540af (patch)
treef9c551649d397172ada718b2b173ac79ff79eda7 /make/cg-common-CustomJavaCode.java
parent36b29b9dd1ede94e4408de4d9cfaf0bf73763954 (diff)
Added CgGL.cgCreateProgramFromStream and updated JOGL Cg demos to use
it so they can be run with Java Web Start. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@272 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make/cg-common-CustomJavaCode.java')
-rwxr-xr-xmake/cg-common-CustomJavaCode.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/make/cg-common-CustomJavaCode.java b/make/cg-common-CustomJavaCode.java
new file mode 100755
index 000000000..ba0df4ee9
--- /dev/null
+++ b/make/cg-common-CustomJavaCode.java
@@ -0,0 +1,44 @@
+static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ try {
+ // Workaround so that these don't need to be in the system
+ // path but can be referenced from java.library.path
+ // (this is intended to help with Webstarted applications)
+ System.loadLibrary("cg");
+ System.loadLibrary("cgGL");
+ } catch (UnsatisfiedLinkError e) {
+ // Consider this non-fatal
+ }
+ // Load the actual Cg binding
+ System.loadLibrary("jogl_cg");
+ return null;
+ }
+ });
+}
+
+/** 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);
+}