diff options
-rw-r--r-- | make/build.xml | 3 | ||||
-rwxr-xr-x | make/cg-common-CustomJavaCode.java | 44 | ||||
-rw-r--r-- | make/cg-common.cfg | 19 |
3 files changed, 47 insertions, 19 deletions
diff --git a/make/build.xml b/make/build.xml index 8ff9e12ea..f707e43d7 100644 --- a/make/build.xml +++ b/make/build.xml @@ -176,7 +176,7 @@ <include name="${stub.includes.dir}/x11/**" /> <include name="${stub.includes.dir}/common/**" /> <include name="*.cfg" /> - <include name="*.java" /> + <include name="gl*.java" /> <include name="*.c" /> <exclude name="cg-common.cfg" /> </fileset> @@ -191,6 +191,7 @@ <fileset id="stub.includes.cg.dependencies.fileset" dir="."> <include name="${stub.includes.dir}/cg/**" /> <include name="cg-common.cfg" /> + <include name="cg-common-CustomJavaCode.java" /> </fileset> <property name="java.includes.dir" value="${java.home.dir}/include" /> <!-- NOTE: this MUST be relative for FileSet --> 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); +} diff --git a/make/cg-common.cfg b/make/cg-common.cfg index 275d9941d..2954538f6 100644 --- a/make/cg-common.cfg +++ b/make/cg-common.cfg @@ -74,21 +74,4 @@ RuntimeExceptionType CgException CustomCCode #include <stdlib.h> CustomCCode #include <Cg/cgGL.h> -CustomJavaCode CgGL static { -CustomJavaCode CgGL AccessController.doPrivileged(new PrivilegedAction() { -CustomJavaCode CgGL public Object run() { -CustomJavaCode CgGL try { -CustomJavaCode CgGL // Workaround so that these don't need to be in the system -CustomJavaCode CgGL // path but can be referenced from java.library.path -CustomJavaCode CgGL // (this is intended to help with Webstarted applications) -CustomJavaCode CgGL System.loadLibrary("cg"); -CustomJavaCode CgGL System.loadLibrary("cgGL"); -CustomJavaCode CgGL } catch (UnsatisfiedLinkError e) { -CustomJavaCode CgGL // Consider this non-fatal -CustomJavaCode CgGL } -CustomJavaCode CgGL // Load the actual Cg binding -CustomJavaCode CgGL System.loadLibrary("jogl_cg"); -CustomJavaCode CgGL return null; -CustomJavaCode CgGL } -CustomJavaCode CgGL }); -CustomJavaCode CgGL } +IncludeAs CustomJavaCode CgGL cg-common-CustomJavaCode.java |