diff options
-rw-r--r-- | make/build.xml | 5 | ||||
-rw-r--r-- | make/gl-common.cfg | 7 | ||||
-rw-r--r-- | make/gl-impl-CustomCCode.c | 15 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode.java | 16 | ||||
-rw-r--r-- | make/gl-impl-macosx.cfg | 3 | ||||
-rw-r--r-- | make/gl-impl-win32.cfg | 3 | ||||
-rw-r--r-- | make/gl-impl-x11.cfg | 3 | ||||
-rw-r--r-- | src/native/jogl/BufferUtils.c | 54 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaEmitter.java | 51 | ||||
-rw-r--r-- | src/net/java/games/gluegen/opengl/GLEmitter.java | 9 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BufferUtils.java | 9 |
11 files changed, 143 insertions, 32 deletions
diff --git a/make/build.xml b/make/build.xml index 7875f57cc..e3ce6476f 100644 --- a/make/build.xml +++ b/make/build.xml @@ -159,6 +159,8 @@ <include name="${stub.includes.dir}/win32/**" /> <include name="${stub.includes.dir}/x11/**" /> <include name="*.cfg" /> + <include name="*.java" /> + <include name="*.c" /> <exclude name="cg-common.cfg" /> </fileset> <dirset id="stub.includes.cg.fileset.all" dir="."> @@ -475,6 +477,9 @@ (the uptodate task doesn't allow arbitrary source and target filesets but should) --> <dependset> <srcfileset refid="stub.includes.dependencies.fileset" /> + <srcfileset dir="."> + <include name="${classes}/net/java/games/gluegen/**/*.class" /> + </srcfileset> <targetfileset dir="."> <include name="${src.generated.java}/**/*.java" /> <include name="${src.generated.c}/**/*.c" /> diff --git a/make/gl-common.cfg b/make/gl-common.cfg index 32664d7a0..9f2acf1c2 100644 --- a/make/gl-common.cfg +++ b/make/gl-common.cfg @@ -49,10 +49,9 @@ Ignore glGetVertexAttribPointervARB Ignore glGetVertexAttribPointervNV Ignore glTracePointerRangeMESA -# FIXME: Temporarily ignore glMapBufferARB as it returns a void* that -# we don't know the size of, and it's so new that there's no -# documentation on its semantics -Ignore glMapBufferARB +# Manually implement glMapBufferARB as the size of the returned buffer +# can only be computed by calling another routine +ManuallyImplement glMapBufferARB # Ignore GL functions that have void** parameters; we cannot yet deal with them Ignore glMultiDrawElements diff --git a/make/gl-impl-CustomCCode.c b/make/gl-impl-CustomCCode.c new file mode 100644 index 000000000..1616353d9 --- /dev/null +++ b/make/gl-impl-CustomCCode.c @@ -0,0 +1,15 @@ +/* Java->C glue code: + * Java package: net.java.games.jogl.impl.windows.WindowsGLImpl + * Java method: java.nio.ByteBuffer dispatch_glMapBufferARB(int target, int access) + * C function: LPVOID glMapBufferARB(GLenum target, GLenum access); + */ +JNIEXPORT jobject JNICALL +Java_net_java_games_jogl_impl_windows_WindowsGLImpl_dispatch_1glMapBufferARB(JNIEnv *env, jobject _unused, jint target, jint access, jint size, jlong glProcAddress) { + PFNGLMAPBUFFERARBPROC ptr_glMapBufferARB; + LPVOID _res; + ptr_glMapBufferARB = (PFNGLMAPBUFFERARBPROC) (intptr_t) glProcAddress; + assert(ptr_glMapBufferARB != NULL); + _res = (* ptr_glMapBufferARB) ((GLenum) target, (GLenum) access); + if (_res == NULL) return NULL; + return (*env)->NewDirectByteBuffer(env, _res, size); +} diff --git a/make/gl-impl-CustomJavaCode.java b/make/gl-impl-CustomJavaCode.java new file mode 100644 index 000000000..31bb91bc1 --- /dev/null +++ b/make/gl-impl-CustomJavaCode.java @@ -0,0 +1,16 @@ +/** Entry point to C language function: <br> <code> LPVOID glMapBufferARB(GLenum target, GLenum access); </code> */ +public java.nio.ByteBuffer glMapBufferARB(int target, int access) { + final long __addr_ = context.getGLProcAddressTable()._addressof_glMapBufferARB; + if (__addr_ == 0) { + throw new GLException("Method \"glMapBufferARB\" not available"); + } + int[] sz = new int[1]; + glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, sz); + ByteBuffer _res; + _res = dispatch_glMapBufferARB(target, access, sz[0], __addr_); + if (_res == null) return null; + return _res.order(ByteOrder.nativeOrder()); +} + +/** Encapsulates function pointer for OpenGL function <br>: <code> LPVOID glMapBufferARB(GLenum target, GLenum access); </code> */ +native private java.nio.ByteBuffer dispatch_glMapBufferARB(int target, int access, int size, long glProcAddress); diff --git a/make/gl-impl-macosx.cfg b/make/gl-impl-macosx.cfg index 5aa8ea786..c5a0ade2f 100644 --- a/make/gl-impl-macosx.cfg +++ b/make/gl-impl-macosx.cfg @@ -68,3 +68,6 @@ CustomJavaCode MacOSXGLImpl { CustomJavaCode MacOSXGLImpl // FIXME CustomJavaCode MacOSXGLImpl throw new GLException("Not yet implemented"); CustomJavaCode MacOSXGLImpl } + +IncludeAs CustomJavaCode MacOSXGLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/gl-impl-win32.cfg b/make/gl-impl-win32.cfg index 4891bd490..18c213769 100644 --- a/make/gl-impl-win32.cfg +++ b/make/gl-impl-win32.cfg @@ -57,3 +57,6 @@ CustomJavaCode WindowsGLImpl */ CustomJavaCode WindowsGLImpl public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { CustomJavaCode WindowsGLImpl return wglAllocateMemoryNV(arg0, arg1, arg2, arg3); CustomJavaCode WindowsGLImpl } + +IncludeAs CustomJavaCode WindowsGLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/gl-impl-x11.cfg b/make/gl-impl-x11.cfg index e94923c64..0ef534df1 100644 --- a/make/gl-impl-x11.cfg +++ b/make/gl-impl-x11.cfg @@ -55,3 +55,6 @@ CustomJavaCode X11GLImpl */ CustomJavaCode X11GLImpl public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { CustomJavaCode X11GLImpl return glXAllocateMemoryNV(arg0, arg1, arg2, arg3); CustomJavaCode X11GLImpl } + +IncludeAs CustomJavaCode X11GLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/src/native/jogl/BufferUtils.c b/src/native/jogl/BufferUtils.c new file mode 100644 index 000000000..f10a8ce6d --- /dev/null +++ b/src/native/jogl/BufferUtils.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +#include <jni.h> + +#ifdef _MSC_VER + /* This typedef is only needed for VC6 */ + #if _MSC_VER <= 1200 + typedef int intptr_t; + #endif +#else + #include <inttypes.h> +#endif + +JNIEXPORT jobject JNICALL +Java_net_java_games_jogl_util_BufferUtils_bufferOffset(JNIEnv* env, jclass unused, jint offset) { + return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) offset, 0); +} diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 824b703b4..63350b2e8 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -391,31 +391,30 @@ public class JavaEmitter implements GlueEmitter { allEmitters.add(entryPointInterface); } - if (cfg.emitImpl() && binding.needsBody() && !isUnimplemented) { - // Generate the method which calls the underlying function - // after unboxing has occurred - PrintWriter output = cfg.allStatic() ? javaWriter() : javaImplWriter(); - JavaMethodBindingEmitter wrappedEntryPoint = - new JavaMethodBindingEmitter(specialBinding, output, cfg.runtimeExceptionType(), true); - wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.PRIVATE); - wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.STATIC); // Doesn't really matter - wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); - allEmitters.add(wrappedEntryPoint); - } - - // If the user has stated that the function will be - // manually implemented, then don't auto-generate a function body. if (cfg.emitImpl()) { - if (!cfg.manuallyImplement(sym.getName()) && !isUnimplemented) - { - CMethodBindingEmitter cEmitter = - makeCEmitter(specialBinding, - overloaded, - (binding != specialBinding), - cfg.implPackageName(), cfg.implClassName(), - cWriter()); - allEmitters.add(cEmitter); + // If the user has stated that the function will be + // manually implemented, then don't auto-generate a function body. + if (!cfg.manuallyImplement(sym.getName()) && !isUnimplemented) { + if (binding.needsBody()) { + // Generate the method which calls the underlying function + // after unboxing has occurred + PrintWriter output = cfg.allStatic() ? javaWriter() : javaImplWriter(); + JavaMethodBindingEmitter wrappedEntryPoint = + new JavaMethodBindingEmitter(specialBinding, output, cfg.runtimeExceptionType(), true); + wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.PRIVATE); + wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.STATIC); // Doesn't really matter + wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); + allEmitters.add(wrappedEntryPoint); } + + CMethodBindingEmitter cEmitter = + makeCEmitter(specialBinding, + overloaded, + (binding != specialBinding), + cfg.implPackageName(), cfg.implClassName(), + cWriter()); + allEmitters.add(cEmitter); + } } } // end iteration over expanded bindings } catch (Exception e) { @@ -1118,6 +1117,12 @@ public class JavaEmitter implements GlueEmitter { protected void emitCHeader(PrintWriter cWriter, String className) { cWriter.println("#include <jni.h>"); cWriter.println(); + + if (getConfig().emitImpl()) { + cWriter.println("#include <assert.h>"); + cWriter.println(); + } + for (Iterator iter = cfg.customCCode().iterator(); iter.hasNext(); ) { cWriter.println((String) iter.next()); } diff --git a/src/net/java/games/gluegen/opengl/GLEmitter.java b/src/net/java/games/gluegen/opengl/GLEmitter.java index 0e64931ba..861e85bb7 100644 --- a/src/net/java/games/gluegen/opengl/GLEmitter.java +++ b/src/net/java/games/gluegen/opengl/GLEmitter.java @@ -67,11 +67,6 @@ public class GLEmitter extends JavaEmitter { this.typedefDictionary = typedefDictionary; - if (getConfig().emitImpl()) { - cWriter().println("#include <assert.h> /* this include emitted by GLEmitter.java */"); - cWriter().println(); - } - if (getGLConfig().emitProcAddressTable()) { beginGLProcAddressTable(); @@ -187,6 +182,10 @@ public class GLEmitter extends JavaEmitter return null; return baseJavaEmitter; } + if (getGLConfig().manuallyImplement(baseJavaEmitter.getName())) { + // User will provide Java-side implementation of this routine + return null; + } return new JavaGLPAWrapperEmitter(baseJavaEmitter, getGLConfig().getProcAddressTableExpr()); } diff --git a/src/net/java/games/jogl/util/BufferUtils.java b/src/net/java/games/jogl/util/BufferUtils.java index aa4653693..05125b75e 100644 --- a/src/net/java/games/jogl/util/BufferUtils.java +++ b/src/net/java/games/jogl/util/BufferUtils.java @@ -69,4 +69,13 @@ public class BufferUtils { dest.put(orig); return dest; } + + /** Creates an "offset buffer" for use with the + ARB_vertex_buffer_object extension. The resulting Buffers are + suitable for use with routines such as glVertexPointer <em>when + used in conjunction with that extension</em>. They have no + capacity and are not suitable for passing to OpenGL routines + that do not support buffer offsets, or to non-OpenGL + routines. */ + public static native ByteBuffer bufferOffset(int offset); } |