diff options
-rw-r--r-- | doc/userguide/index.html | 9 | ||||
-rwxr-xr-x | make/142-packages/package-list | 135 | ||||
-rw-r--r-- | make/build-gluegen.xml | 8 | ||||
-rw-r--r-- | make/build-staticglgen.xml | 6 | ||||
-rw-r--r-- | make/build.xml | 201 | ||||
-rw-r--r-- | make/cg-common.cfg | 51 | ||||
-rw-r--r-- | make/cgl-macosx.cfg | 2 | ||||
-rwxr-xr-x | make/cglext.cfg | 53 | ||||
-rw-r--r-- | make/gl-cgl-macosx.cfg | 10 | ||||
-rw-r--r-- | make/gl-common-macosx.cfg | 3 | ||||
-rw-r--r-- | make/gl-common-win32.cfg | 3 | ||||
-rw-r--r-- | make/gl-common-x11.cfg | 15 | ||||
-rw-r--r-- | make/gl-common.cfg | 304 | ||||
-rw-r--r-- | make/gl-glx-common.cfg | 85 | ||||
-rw-r--r-- | make/gl-glx-x11.cfg | 14 | ||||
-rw-r--r-- | make/gl-impl-CustomCCode.c | 70 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode.java | 136 | ||||
-rw-r--r-- | make/gl-impl-macosx.cfg | 81 | ||||
-rw-r--r-- | make/gl-impl-win32.cfg | 70 | ||||
-rw-r--r-- | make/gl-impl-x11.cfg | 67 | ||||
-rw-r--r-- | make/gl-macosx.cfg | 34 | ||||
-rw-r--r-- | make/gl-wgl-win32.cfg | 10 | ||||
-rw-r--r-- | make/gl-win32.cfg | 37 | ||||
-rw-r--r-- | make/gl-x11.cfg | 40 | ||||
-rw-r--r-- | make/glu-CustomJavaCode.java | 1457 | ||||
-rw-r--r-- | make/glu-common.cfg | 193 | ||||
-rw-r--r-- | make/glu-impl-common-CustomCCode.c | 833 | ||||
-rw-r--r-- | make/glu-impl-common-CustomJavaCode.java | 1426 | ||||
-rw-r--r-- | make/glu-impl-common.cfg | 22 | ||||
-rw-r--r-- | make/glu-impl-win32-GLU13Hacks.cfg | 122 | ||||
-rw-r--r-- | make/glu-interface-common-CustomJavaCode.java | 982 | ||||
-rwxr-xr-x[-rw-r--r--] | make/glu-macosx.cfg (renamed from make/glu-impl-macosx.cfg) | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | make/glu-win32.cfg (renamed from make/glu-impl-win32.cfg) | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | make/glu-x11.cfg (renamed from make/glu-impl-x11.cfg) | 3 | ||||
-rw-r--r-- | make/glu.cfg | 9 | ||||
-rw-r--r-- | make/glx-x11.cfg | 24 | ||||
-rwxr-xr-x | make/glxext.cfg | 133 | ||||
-rw-r--r-- | make/jawt-macosx.cfg | 6 | ||||
-rw-r--r-- | make/jawt-win32.cfg | 6 | ||||
-rw-r--r-- | make/jawt-x11.cfg | 6 | ||||
-rwxr-xr-x | make/lib/cpptasks-cvs-040628.jar | bin | 335649 -> 0 bytes | |||
-rw-r--r-- | make/lib/cpptasks-patch.tar.gz | bin | 0 -> 7743 bytes | |||
-rwxr-xr-x | make/lib/cpptasks-version.txt | 4 | ||||
-rw-r--r-- | make/stub_includes/cg/CG/cg.h | 236 | ||||
-rw-r--r-- | make/stub_includes/cg/CG/cg_datatypes.h | 228 | ||||
-rwxr-xr-x | make/stub_includes/cg/CG/cg_enums.h | 4 | ||||
-rw-r--r-- | make/stub_includes/cg/CG/cg_errors.h | 67 | ||||
-rw-r--r-- | make/stub_includes/cg/CG/cg_profiles.h | 1 | ||||
-rwxr-xr-x | make/stub_includes/macosx/cglext.c | 1 | ||||
-rwxr-xr-x | make/stub_includes/win32/wglext.c | 13 | ||||
-rw-r--r-- | make/stub_includes/win32/windows.h | 1 | ||||
-rw-r--r-- | make/stub_includes/win32/wingdi.h | 34 | ||||
-rw-r--r-- | make/stub_includes/x11/glxext.c (renamed from make/stub_includes/common/gl-impl.c) | 9 | ||||
-rwxr-xr-x | make/wgl-CustomCCode.c | 77 | ||||
-rw-r--r-- | make/wglext.cfg | 58 | ||||
-rw-r--r-- | make/wingdi-win32.cfg | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/ArrayTypes.java (renamed from src/net/java/games/gluegen/ArrayTypes.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/CMethodBindingEmitter.java (renamed from src/net/java/games/gluegen/CMethodBindingEmitter.java) | 707 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/CodeGenUtils.java (renamed from src/net/java/games/gluegen/CodeGenUtils.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/CommentEmitter.java (renamed from src/net/java/games/gluegen/CommentEmitter.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/DebugEmitter.java (renamed from src/net/java/games/gluegen/DebugEmitter.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/FunctionEmitter.java (renamed from src/net/java/games/gluegen/FunctionEmitter.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/GlueEmitter.java (renamed from src/net/java/games/gluegen/GlueEmitter.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/GlueEmitterControls.java (renamed from src/net/java/games/gluegen/GlueEmitterControls.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/GlueGen.java (renamed from src/net/java/games/gluegen/GlueGen.java) | 19 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/JavaConfiguration.java (renamed from src/net/java/games/gluegen/JavaConfiguration.java) | 416 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/JavaEmitter.java (renamed from src/net/java/games/gluegen/JavaEmitter.java) | 774 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java | 720 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/JavaType.java (renamed from src/net/java/games/gluegen/JavaType.java) | 177 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/MethodBinding.java (renamed from src/net/java/games/gluegen/MethodBinding.java) | 303 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/ReferencedStructs.java (renamed from src/net/java/games/gluegen/ReferencedStructs.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/StructLayout.java (renamed from src/net/java/games/gluegen/StructLayout.java) | 5 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/TypeInfo.java (renamed from src/net/java/games/gluegen/TypeInfo.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/ant/GlueGenTask.java (renamed from src/net/java/games/gluegen/ant/GlueGenTask.java) | 14 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/ant/StaticGLGenTask.java (renamed from src/net/java/games/gluegen/ant/StaticGLGenTask.java) | 14 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/CSymbolTable.java (renamed from src/net/java/games/gluegen/cgram/CSymbolTable.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/CToken.java (renamed from src/net/java/games/gluegen/cgram/CToken.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/Define.java (renamed from src/net/java/games/gluegen/cgram/Define.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/GnuCEmitter.g (renamed from src/net/java/games/gluegen/cgram/GnuCEmitter.g) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/GnuCParser.g (renamed from src/net/java/games/gluegen/cgram/GnuCParser.g) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/GnuCTreeParser.g (renamed from src/net/java/games/gluegen/cgram/GnuCTreeParser.g) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/HeaderParser.g (renamed from src/net/java/games/gluegen/cgram/HeaderParser.g) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/LineObject.java (renamed from src/net/java/games/gluegen/cgram/LineObject.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/PreprocessorInfoChannel.java (renamed from src/net/java/games/gluegen/cgram/PreprocessorInfoChannel.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/StdCParser.g (renamed from src/net/java/games/gluegen/cgram/StdCParser.g) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/TNode.java (renamed from src/net/java/games/gluegen/cgram/TNode.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/TNodeFactory.java (renamed from src/net/java/games/gluegen/cgram/TNodeFactory.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/ArrayType.java (renamed from src/net/java/games/gluegen/cgram/types/ArrayType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/BitType.java (renamed from src/net/java/games/gluegen/cgram/types/BitType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/CVAttributes.java (renamed from src/net/java/games/gluegen/cgram/types/CVAttributes.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/CompoundType.java (renamed from src/net/java/games/gluegen/cgram/types/CompoundType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/CompoundTypeKind.java (renamed from src/net/java/games/gluegen/cgram/types/CompoundTypeKind.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/DoubleType.java (renamed from src/net/java/games/gluegen/cgram/types/DoubleType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/EnumType.java (renamed from src/net/java/games/gluegen/cgram/types/EnumType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/Field.java (renamed from src/net/java/games/gluegen/cgram/types/Field.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/FloatType.java (renamed from src/net/java/games/gluegen/cgram/types/FloatType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/FunctionSymbol.java (renamed from src/net/java/games/gluegen/cgram/types/FunctionSymbol.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/FunctionType.java (renamed from src/net/java/games/gluegen/cgram/types/FunctionType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/IntType.java (renamed from src/net/java/games/gluegen/cgram/types/IntType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/MachineDescription.java (renamed from src/net/java/games/gluegen/cgram/types/MachineDescription.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java (renamed from src/net/java/games/gluegen/cgram/types/MachineDescription32Bit.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java (renamed from src/net/java/games/gluegen/cgram/types/MachineDescription64Bit.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/PointerType.java (renamed from src/net/java/games/gluegen/cgram/types/PointerType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java (renamed from src/net/java/games/gluegen/cgram/types/PrimitiveType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/Type.java (renamed from src/net/java/games/gluegen/cgram/types/Type.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/TypeDictionary.java (renamed from src/net/java/games/gluegen/cgram/types/TypeDictionary.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/TypeVisitor.java (renamed from src/net/java/games/gluegen/cgram/types/TypeVisitor.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/cgram/types/VoidType.java (renamed from src/net/java/games/gluegen/cgram/types/VoidType.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/opengl/BuildComposablePipeline.java (renamed from src/net/java/games/gluegen/opengl/BuildComposablePipeline.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/opengl/BuildStaticGLInfo.java (renamed from src/net/java/games/gluegen/opengl/BuildStaticGLInfo.java) | 185 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/opengl/ConvertFromGL4Java.java (renamed from src/net/java/games/gluegen/opengl/ConvertFromGL4Java.java) | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java (renamed from src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java) | 210 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/opengl/GLEmitter.java (renamed from src/net/java/games/gluegen/opengl/GLEmitter.java) | 326 | ||||
-rwxr-xr-x | src/classes/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java | 163 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/pcpp/PCPP.java (renamed from src/net/java/games/gluegen/pcpp/PCPP.java) | 28 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/runtime/BufferFactory.java | 164 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/runtime/ProcAddressHelper.java (renamed from src/net/java/games/gluegen/runtime/ProcAddressHelper.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/gluegen/runtime/StructAccessor.java (renamed from src/net/java/games/gluegen/runtime/StructAccessor.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/cg/CgException.java (renamed from src/net/java/games/cg/CgException.java) | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/Debug.java (renamed from src/net/java/games/jogl/impl/Debug.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java (renamed from src/net/java/games/jogl/impl/FunctionAvailabilityCache.java) | 38 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLContextImpl.java | 270 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLContextLock.java | 118 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLContextShareSet.java (renamed from src/net/java/games/jogl/impl/GLContextShareSet.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java | 104 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLDrawableHelper.java | 150 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/GLDrawableImpl.java (renamed from src/net/java/games/jogl/impl/GLContextInitActionPair.java) | 22 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/GLPbufferImpl.java (renamed from src/net/java/games/jogl/impl/GLPbufferImpl.java) | 135 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/GLUquadricImpl.java (renamed from src/net/java/games/jogl/impl/GLUquadricImpl.java) | 27 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/InternalBufferUtils.java (renamed from src/net/java/games/jogl/impl/InternalBufferUtils.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java (renamed from src/net/java/games/jogl/impl/JAWT_PlatformInfo.java) | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/Java2D.java | 215 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/NativeLibLoader.java (renamed from src/net/java/games/jogl/impl/NativeLibLoader.java) | 7 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/Project.java (renamed from src/net/java/games/jogl/impl/Project.java) | 125 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/Util.java (renamed from src/net/java/games/jogl/impl/Util.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/error/Error.java (renamed from src/net/java/games/jogl/impl/error/Error.java) | 19 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/glue/Glue.java (renamed from src/net/java/games/jogl/impl/glue/Glue.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXDummyGLContext.java (renamed from src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java) | 49 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java (renamed from src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java) | 213 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawable.java | 78 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawableFactory.java | 141 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLContext.java | 64 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLDrawable.java (renamed from src/native/jogl/BufferUtils.c) | 33 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java (renamed from src/net/java/games/gluegen/CMethodBindingImplEmitter.java) | 97 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java | 228 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLContext.java | 101 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLDrawable.java | 160 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/BuildMipmap.java (renamed from src/net/java/games/jogl/impl/mipmap/BuildMipmap.java) | 73 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract1010102.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract1010102.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract1555rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract1555rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract2101010rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract2101010rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract233rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract233rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract332.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract332.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract4444.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract4444.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract4444rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract4444rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract5551.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract5551.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract565.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract565.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract565rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract565rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract8888.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract8888.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Extract8888rev.java (renamed from src/net/java/games/jogl/impl/mipmap/Extract8888rev.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractFloat.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractFloat.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractPrimitive.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractPrimitive.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractSByte.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractSByte.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractSInt.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractSInt.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractSShort.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractSShort.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractUByte.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractUByte.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractUInt.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractUInt.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ExtractUShort.java (renamed from src/net/java/games/jogl/impl/mipmap/ExtractUShort.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/HalveImage.java (renamed from src/net/java/games/jogl/impl/mipmap/HalveImage.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Image.java (renamed from src/net/java/games/jogl/impl/mipmap/Image.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Mipmap.java (renamed from src/net/java/games/jogl/impl/mipmap/Mipmap.java) | 101 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/PixelStorageModes.java (renamed from src/net/java/games/jogl/impl/mipmap/PixelStorageModes.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/ScaleInternal.java (renamed from src/net/java/games/jogl/impl/mipmap/ScaleInternal.java) | 62 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/mipmap/Type_Widget.java (renamed from src/net/java/games/jogl/impl/mipmap/Type_Widget.java) | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/README-PORTING.txt (renamed from src/net/java/games/jogl/impl/nurbs/README-PORTING.txt) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/Arc.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/Arc.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/ArcTesselator.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/ArcTesselator.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/Backend.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/Backend.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/BasicCurveEvaluator.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/BasicCurveEvaluator.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/BasicSurfaceEvaluator.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/BasicSurfaceEvaluator.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/BezierArc.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/BezierArc.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/Bin.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/Bin.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/CachingEvaluator.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/CachingEvaluator.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/Defines.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/Defines.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/NurbsConsts.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/NurbsConsts.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/NurbsException.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/NurbsException.java) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/nurbs/internals/Subdivider.java (renamed from src/net/java/games/jogl/impl/nurbs/internals/Subdivider.java) | 0 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/registry/Registry.java (renamed from src/net/java/games/jogl/impl/registry/Registry.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/ActiveRegion.java (renamed from src/net/java/games/jogl/impl/tesselator/ActiveRegion.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/CachedVertex.java (renamed from src/net/java/games/jogl/impl/tesselator/CachedVertex.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Dict.java (renamed from src/net/java/games/jogl/impl/tesselator/Dict.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/DictNode.java (renamed from src/net/java/games/jogl/impl/tesselator/DictNode.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/GLUface.java (renamed from src/net/java/games/jogl/impl/tesselator/GLUface.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/GLUhalfEdge.java (renamed from src/net/java/games/jogl/impl/tesselator/GLUhalfEdge.java) | 6 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/GLUmesh.java (renamed from src/net/java/games/jogl/impl/tesselator/GLUmesh.java) | 8 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/GLUtessellatorImpl.java (renamed from src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java) | 63 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/GLUvertex.java (renamed from src/net/java/games/jogl/impl/tesselator/GLUvertex.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Geom.java (renamed from src/net/java/games/jogl/impl/tesselator/Geom.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Mesh.java (renamed from src/net/java/games/jogl/impl/tesselator/Mesh.java) | 158 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Normal.java (renamed from src/net/java/games/jogl/impl/tesselator/Normal.java) | 29 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/PriorityQ.java (renamed from src/net/java/games/jogl/impl/tesselator/PriorityQ.java) | 4 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/PriorityQHeap.java (renamed from src/net/java/games/jogl/impl/tesselator/PriorityQHeap.java) | 38 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/PriorityQSort.java (renamed from src/net/java/games/jogl/impl/tesselator/PriorityQSort.java) | 26 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Render.java (renamed from src/net/java/games/jogl/impl/tesselator/Render.java) | 61 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/Sweep.java (renamed from src/net/java/games/jogl/impl/tesselator/Sweep.java) | 61 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/TessMono.java (renamed from src/net/java/games/jogl/impl/tesselator/TessMono.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/tessellator/TessState.java (renamed from src/net/java/games/jogl/impl/tesselator/TessState.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java (renamed from src/net/java/games/jogl/impl/GLDrawableHelper.java) | 71 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java | 77 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/windows/WindowsExternalGLDrawable.java | 69 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java | 286 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java | 502 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java | 223 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLContext.java (renamed from src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java) | 39 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java (renamed from src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java) | 123 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java (renamed from src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java) | 96 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java | 198 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLContext.java | 163 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java | 399 | ||||
-rwxr-xr-x[-rw-r--r--] | src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java (renamed from src/net/java/games/jogl/GLContextHelper.java) | 57 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java | 212 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11GLContext.java | 301 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java | 172 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java (renamed from src/net/java/games/jogl/impl/x11/X11GLContextFactory.java) | 225 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11OffscreenGLContext.java | 74 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java | 143 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java (renamed from src/net/java/games/gluegen/runtime/BufferFactory.java) | 78 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java (renamed from src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java) | 164 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java | 151 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java | 264 | ||||
-rw-r--r--[-rwxr-xr-x] | src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java (renamed from src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java) | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/utils/Animator.java | 308 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/BitmapCharRec.java (renamed from src/net/java/games/jogl/util/BitmapCharRec.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/BitmapFontRec.java (renamed from src/net/java/games/jogl/util/BitmapFontRec.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/BufferUtils.java | 266 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/CoordRec.java (renamed from src/net/java/games/jogl/util/CoordRec.java) | 2 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/utils/FPSAnimator.java | 99 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUT.java (renamed from src/net/java/games/jogl/util/GLUT.java) | 152 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmap8x13.java (renamed from src/net/java/games/jogl/util/GLUTBitmap8x13.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmap9x15.java (renamed from src/net/java/games/jogl/util/GLUTBitmap9x15.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica10.java (renamed from src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica12.java (renamed from src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica18.java (renamed from src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman10.java (renamed from src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman24.java (renamed from src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTStrokeMonoRoman.java (renamed from src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/GLUTStrokeRoman.java (renamed from src/net/java/games/jogl/util/GLUTStrokeRoman.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/StrokeCharRec.java (renamed from src/net/java/games/jogl/util/StrokeCharRec.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/StrokeFontRec.java (renamed from src/net/java/games/jogl/util/StrokeFontRec.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/StrokeRec.java (renamed from src/net/java/games/jogl/util/StrokeRec.java) | 2 | ||||
-rw-r--r-- | src/classes/com/sun/opengl/utils/Version.java (renamed from src/net/java/games/jogl/Version.java) | 4 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/ComponentEvents.java (renamed from src/net/java/games/jogl/ComponentEvents.java) | 2 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java (renamed from src/net/java/games/jogl/DefaultGLCapabilitiesChooser.java) | 4 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLAutoDrawable.java | 117 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLCanvas.java (renamed from src/net/java/games/jogl/GLCanvas.java) | 184 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLCapabilities.java (renamed from src/net/java/games/jogl/GLCapabilities.java) | 2 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLCapabilitiesChooser.java (renamed from src/net/java/games/jogl/GLCapabilitiesChooser.java) | 2 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLContext.java | 159 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLDrawable.java | 118 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLDrawableFactory.java | 282 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLEventListener.java (renamed from src/net/java/games/jogl/GLEventListener.java) | 33 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLException.java (renamed from src/net/java/games/jogl/GLException.java) | 2 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLJPanel.java | 877 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLPbuffer.java (renamed from src/net/java/games/jogl/GLPbuffer.java) | 25 | ||||
-rwxr-xr-x | src/classes/javax/media/opengl/Threading.java | 215 | ||||
-rwxr-xr-x | src/classes/javax/media/opengl/glu/GLUquadric.java (renamed from src/net/java/games/jogl/GLUquadric.java) | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/classes/javax/media/opengl/glu/GLUtessellator.java (renamed from src/net/java/games/jogl/GLUtesselator.java) | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | src/classes/javax/media/opengl/glu/GLUtessellatorCallback.java (renamed from src/net/java/games/jogl/GLUtesselatorCallback.java) | 145 | ||||
-rwxr-xr-x[-rw-r--r--] | src/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java (renamed from src/net/java/games/jogl/GLUtesselatorCallbackAdapter.java) | 12 | ||||
-rw-r--r-- | src/native/jogl/InternalBufferUtils.c | 2 | ||||
-rw-r--r-- | src/native/jogl/JAWT_DrawingSurfaceInfo.c | 8 | ||||
-rw-r--r-- | src/native/jogl/MacOSXWindowSystemInterface.m | 18 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaMethodBindingEmitter.java | 269 | ||||
-rw-r--r-- | src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java | 263 | ||||
-rw-r--r-- | src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java | 180 | ||||
-rw-r--r-- | src/net/java/games/jogl/Animator.java | 158 | ||||
-rw-r--r-- | src/net/java/games/jogl/GLDrawable.java | 219 | ||||
-rw-r--r-- | src/net/java/games/jogl/GLDrawableFactory.java | 195 | ||||
-rw-r--r-- | src/net/java/games/jogl/GLJPanel.java | 730 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/GLContext.java | 764 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/GLContextFactory.java | 105 | ||||
-rwxr-xr-x | src/net/java/games/jogl/impl/GLContextStack.java | 127 | ||||
-rwxr-xr-x | src/net/java/games/jogl/impl/SingleThreadedWorkaround.java | 115 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java | 248 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java | 203 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/windows/WindowsGLContext.java | 717 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java | 361 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java | 228 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java | 529 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/x11/X11GLContext.java | 410 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java | 175 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java | 343 | ||||
-rw-r--r-- | src/net/java/games/jogl/util/BufferUtils.java | 121 |
294 files changed, 15067 insertions, 13496 deletions
diff --git a/doc/userguide/index.html b/doc/userguide/index.html index 58b8b3e29..6a3e08c75 100644 --- a/doc/userguide/index.html +++ b/doc/userguide/index.html @@ -702,16 +702,17 @@ following steps should be taken: <UL> <LI> Instantiate a -<CODE>net.java.games.jogl.impl.macosx.MacOSXGLImpl</CODE> using the +<CODE>net.java.games.jogl.impl.macosx.MacOSXDummyGLContext</CODE> using the public constructor taking no arguments. <LI> Upon the first render of your application, or whenever the available OpenGL routines might have changed (because a window moved from one screen to another) call the publicly-accessible method -<CODE>MacOSXGLImpl.resetGLFunctionAvailability()</CODE>. +<CODE>MacOSXDummyGLContext.resetGLFunctionAvailability()</CODE>. -<LI> Only use the GL instance when the OpenGL context from the -NSOpenGLView is current. +<LI> Fetch the GL instance out of the context using getGL() as usual. +Only use the GL instance when the OpenGL context from the NSOpenGLView +is current. </UL> diff --git a/make/142-packages/package-list b/make/142-packages/package-list new file mode 100755 index 000000000..fecd4d4ff --- /dev/null +++ b/make/142-packages/package-list @@ -0,0 +1,135 @@ +java.applet +java.awt +java.awt.color +java.awt.datatransfer +java.awt.dnd +java.awt.event +java.awt.font +java.awt.geom +java.awt.im +java.awt.im.spi +java.awt.image +java.awt.image.renderable +java.awt.print +java.beans +java.beans.beancontext +java.io +java.lang +java.lang.ref +java.lang.reflect +java.math +java.net +java.nio +java.nio.channels +java.nio.channels.spi +java.nio.charset +java.nio.charset.spi +java.rmi +java.rmi.activation +java.rmi.dgc +java.rmi.registry +java.rmi.server +java.security +java.security.acl +java.security.cert +java.security.interfaces +java.security.spec +java.sql +java.text +java.util +java.util.jar +java.util.logging +java.util.prefs +java.util.regex +java.util.zip +javax.accessibility +javax.crypto +javax.crypto.interfaces +javax.crypto.spec +javax.imageio +javax.imageio.event +javax.imageio.metadata +javax.imageio.plugins.jpeg +javax.imageio.spi +javax.imageio.stream +javax.naming +javax.naming.directory +javax.naming.event +javax.naming.ldap +javax.naming.spi +javax.net +javax.net.ssl +javax.print +javax.print.attribute +javax.print.attribute.standard +javax.print.event +javax.rmi +javax.rmi.CORBA +javax.security.auth +javax.security.auth.callback +javax.security.auth.kerberos +javax.security.auth.login +javax.security.auth.spi +javax.security.auth.x500 +javax.security.cert +javax.sound.midi +javax.sound.midi.spi +javax.sound.sampled +javax.sound.sampled.spi +javax.sql +javax.swing +javax.swing.border +javax.swing.colorchooser +javax.swing.event +javax.swing.filechooser +javax.swing.plaf +javax.swing.plaf.basic +javax.swing.plaf.metal +javax.swing.plaf.multi +javax.swing.table +javax.swing.text +javax.swing.text.html +javax.swing.text.html.parser +javax.swing.text.rtf +javax.swing.tree +javax.swing.undo +javax.transaction +javax.transaction.xa +javax.xml.parsers +javax.xml.transform +javax.xml.transform.dom +javax.xml.transform.sax +javax.xml.transform.stream +org.ietf.jgss +org.omg.CORBA +org.omg.CORBA.DynAnyPackage +org.omg.CORBA.ORBPackage +org.omg.CORBA.TypeCodePackage +org.omg.CORBA.portable +org.omg.CORBA_2_3 +org.omg.CORBA_2_3.portable +org.omg.CosNaming +org.omg.CosNaming.NamingContextExtPackage +org.omg.CosNaming.NamingContextPackage +org.omg.Dynamic +org.omg.DynamicAny +org.omg.DynamicAny.DynAnyFactoryPackage +org.omg.DynamicAny.DynAnyPackage +org.omg.IOP +org.omg.IOP.CodecFactoryPackage +org.omg.IOP.CodecPackage +org.omg.Messaging +org.omg.PortableInterceptor +org.omg.PortableInterceptor.ORBInitInfoPackage +org.omg.PortableServer +org.omg.PortableServer.CurrentPackage +org.omg.PortableServer.POAManagerPackage +org.omg.PortableServer.POAPackage +org.omg.PortableServer.ServantLocatorPackage +org.omg.PortableServer.portable +org.omg.SendingContext +org.omg.stub.java.rmi +org.w3c.dom +org.xml.sax +org.xml.sax.ext +org.xml.sax.helpers diff --git a/make/build-gluegen.xml b/make/build-gluegen.xml index b9e522d3c..fb21071ef 100644 --- a/make/build-gluegen.xml +++ b/make/build-gluegen.xml @@ -27,12 +27,12 @@ </path> <!-- The location of the GlueGen source and the C grammar files. --> - <property name="gluegen" value="${src}/net/java/games/gluegen" /> + <property name="gluegen" value="${src.java}/com/sun/gluegen" /> <property name="c.grammar" value="${gluegen}/cgram" /> <!-- The resulting location of the generated Java files from the - C grammar via ANTLR. --> - <property name="gluegen.build" value="${src.generated.java}/net/java/games/gluegen" /> + <property name="gluegen.build" value="${src.generated.java}/com/sun/gluegen" /> <property name="generated.java.from.grammar" value="${gluegen.build}/cgram" /> </target> @@ -89,7 +89,7 @@ - a separate task. --> <javac destdir="${classes}" includes="**/gluegen/**" excludes="**/GlueGenTask.java" source="1.4" debug="true" debuglevel="source,lines"> - <src path="${src}" /> + <src path="${src.java}" /> <src path="${src.generated.java}" /> <classpath refid="antlr.classpath" /> </javac> @@ -141,7 +141,7 @@ - NOTE: ONLY the GlueGenTask is built at this time. GlueGen - itself is built in a separate task. --> <javac destdir="${classes}" includes="**/GlueGenTask.java" source="1.4" debug="true" debuglevel="source,lines"> - <src path="${src}" /> + <src path="${src.java}" /> <classpath refid="antlr.classpath" /> </javac> diff --git a/make/build-staticglgen.xml b/make/build-staticglgen.xml index 0f72bcfa7..9ef1147a3 100644 --- a/make/build-staticglgen.xml +++ b/make/build-staticglgen.xml @@ -17,7 +17,7 @@ --> <target name="declare" description="Declare properties"> <!-- The location of the BuildStaticGLInfo source. --> - <property name="static.gl.src" value="${src}/net/java/games/gluegen/opengl" /> + <property name="static.gl.src" value="${src.java}/com/sun/gluegen/opengl" /> </target> <!-- ================================================================== --> @@ -29,7 +29,7 @@ <mkdir dir="${classes}" /> <!-- Compile BuildStaticGLInfo --> - <javac srcdir="${src}" destdir="${classes}" includes="**/BuildStaticGLInfo.java" source="1.4" debug="true" debuglevel="source,lines"> + <javac srcdir="${src.java}" destdir="${classes}" includes="**/BuildStaticGLInfo.java" source="1.4" debug="true" debuglevel="source,lines"> <classpath refid="antlr.classpath" /> </javac> @@ -50,7 +50,7 @@ - NOTE: ONLY the StaticGLGen is built at this time. BuildStaticGLInfo - itself is built in a separate task. --> <javac destdir="${classes}" includes="**/StaticGLGenTask.java" source="1.4" debug="true" debuglevel="source,lines"> - <src path="${src}" /> + <src path="${src.java}" /> <classpath refid="classpath" /> </javac> diff --git a/make/build.xml b/make/build.xml index ef72433f5..e9ad12c93 100644 --- a/make/build.xml +++ b/make/build.xml @@ -124,8 +124,8 @@ Some of these are used in FileMappers later for dependence information and need exact string matching, which is why they use file.separator instead of "/". --> - <property name="rootrel.src" value="src" /> - <property name="rootrel.src.c.jogl" value="${rootrel.src}${sep}native${sep}jogl" /> + <property name="rootrel.src.java" value="src${sep}classes" /> + <property name="rootrel.src.c.jogl" value="src${sep}native${sep}jogl" /> <property name="rootrel.build" value="build" /> <property name="rootrel.src.generated" value="${rootrel.build}${sep}gensrc" /> <property name="rootrel.generated.java" value="${rootrel.src.generated}${sep}classes" /> @@ -136,19 +136,19 @@ <property name="rootrel.obj.cg" value="${rootrel.obj}${sep}jogl_cg" /> <!-- The source directories. --> - <property name="src" value="${project.root}/${rootrel.src}" /> - <property name="src.c" value="${project.root}/${rootrel.src.c}" /> - <property name="build" value="${project.root}/${rootrel.build}" /> + <property name="src.java" value="${project.root}/${rootrel.src.java}" /> + <property name="src.c" value="${project.root}/${rootrel.src.c}" /> + <property name="build" value="${project.root}/${rootrel.build}" /> <!-- The generated source directories. --> <property name="src.generated" value="${build}/gensrc" /> <property name="src.generated.java" value="${src.generated}/classes" /> - <property name="src.generated.java.cg" value="${src.generated}/classes/net/java/games/cg" /> + <property name="src.generated.java.cg" value="${src.generated}/classes/com/sun/opengl/cg" /> <property name="src.generated.c" value="${src.generated}/native/jogl" /> <property name="src.generated.c.cg" value="${src.generated}/native/jogl_cg" /> <!-- The composable pipeline source files --> <property name="src.generated.java.pipeline" - value="net/java/games/jogl/DebugGL.java,net/java/games/jogl/TraceGL.java" /> + value="javax/media/opengl/DebugGL.java,javax/media/opengl/TraceGL.java" /> <!-- The compiler output directories. --> <property name="classes" value="${build}/classes" /> @@ -215,10 +215,10 @@ <property name="java.lib.dir.macosx" value="/System/Library/Frameworks/JavaVM.framework/Libraries" /> <property name="gl.headers" value="${stub.includes.dir}/opengl/**/*.h" /> <!-- NOTE: this MUST be relative for FileSet --> <!-- CHECK: this may need to be pruned for each platform --> - <!-- Java files to exclude based on platform (relative to "src") --> - <property name="java.excludes.win32" value="net/java/games/jogl/impl/x11/**, net/java/games/jogl/impl/macosx/**" /> - <property name="java.excludes.x11" value="net/java/games/jogl/impl/windows/**, net/java/games/jogl/impl/macosx/**" /> - <property name="java.excludes.macosx" value="net/java/games/jogl/impl/x11/**, net/java/games/jogl/impl/windows/**" /> + <!-- Java files to exclude based on platform (relative to "src.java") --> + <property name="java.excludes.win32" value="com/sun/opengl/impl/x11/**, com/sun/opengl/impl/macosx/**" /> + <property name="java.excludes.x11" value="com/sun/opengl/impl/windows/**, com/sun/opengl/impl/macosx/**" /> + <property name="java.excludes.macosx" value="com/sun/opengl/impl/x11/**, com/sun/opengl/impl/windows/**" /> <!-- Create the classpath for that includes ANTLR and any already - compiled classes. This requires the user-defined "antlr.jar" @@ -236,11 +236,12 @@ <property name="javadoc" value="${project.root}/javadoc_public" /> <property name="javadoc.dev" value="${project.root}/javadoc_jogl_dev" /> <property name="javadoc.link" value="http://java.sun.com/j2se/1.4.2/docs/api/" /> - <property name="javadoc.packagenames" value="net.java.games.jogl,net.java.games.gluegen.runtime,net.java.games.jogl.util" /> - <property name="javadoc.dev.packagenames.win32" value="net.java.games.jogl.impl.windows" /> - <property name="javadoc.dev.packagenames.x11" value="net.java.games.jogl.impl.x11" /> - <property name="javadoc.dev.packagenames.macosx" value="net.java.games.jogl.impl.macosx" /> - <property name="javadoc.dev.packagenames" value="net.java.games.jogl,net.java.games.jogl.impl,net.java.games.jogl.util,net.java.games.gluegen" /> + <property name="javadoc.windowtitle" value="JOGL API -- JSR-231 Early Draft Review Specification" /> + <property name="javadoc.packagenames" value="javax.media.opengl,javax.media.opengl.glu,com.sun.opengl.utils" /> + <property name="javadoc.dev.packagenames.win32" value="com.sun.opengl.impl.windows" /> + <property name="javadoc.dev.packagenames.x11" value="com.sun.opengl.impl.x11" /> + <property name="javadoc.dev.packagenames.macosx" value="com.sun.opengl.impl.macosx" /> + <property name="javadoc.dev.packagenames" value="javax.media.opengl,javax.media.opengl.glu,com.sun.opengl.impl,com.sun.opengl.utils,com.sun.gluegen,com.sun.gluegen.runtime" /> </target> @@ -251,18 +252,20 @@ <target name="declare.win32" depends="init"> <!-- Set platform configuration files. --> <property name="gl.cfg" value="${config}/gl-win32.cfg" /> - <property name="gl.impl.cfg" value="${config}/gl-impl-win32.cfg" /> - <property name="glu.cfg" value="${config}/glu.cfg" /> - <property name="glu.impl.cfg" value="${config}/glu-impl-win32.cfg" /> + <property name="glext.platform.cfg" value="${config}/wglext.cfg" /> + <property name="glu.cfg" value="${config}/glu-win32.cfg" /> <property name="jawt.cfg" value="${config}/jawt-win32.cfg" /> <property name="window.cfg" value="${config}/wingdi-win32.cfg" /> + <!-- Set platform headers. --> + <property name="glext.platform.header" value="${stub.includes.dir}/win32/wglext.c" /> + <!-- Set platform directories. --> <property name="stub.includes.platform" value="${stub.includes}/win32" /> <property name="java.includes.dir.platform" value="${java.includes.dir.win32}" /> <property name="java.lib.dir.platform" value="${java.lib.dir.win32}" /> <property name="java.excludes.platform" value="${java.excludes.win32}" /> - <property name="stub.includes.fileset.platform.params" value="${stub.includes.dir}/win32/** ${stub.includes.dir}/common/**" /> + <property name="stub.includes.fileset.platform.params" value="${stub.includes.dir}/win32/** ${stub.includes.dir}/common/** ${stub.includes.dir}/opengl/**" /> <!-- Set Javadoc properties. --> <property name="javadoc.dev.packagenames.platform" value="${javadoc.dev.packagenames.win32}" /> @@ -292,12 +295,14 @@ <target name="declare.x11" depends="init"> <!-- Set platform configuration files. --> <property name="gl.cfg" value="${config}/gl-x11.cfg" /> - <property name="gl.impl.cfg" value="${config}/gl-impl-x11.cfg" /> - <property name="glu.cfg" value="${config}/glu.cfg" /> - <property name="glu.impl.cfg" value="${config}/glu-impl-x11.cfg" /> + <property name="glext.platform.cfg" value="${config}/glxext.cfg" /> + <property name="glu.cfg" value="${config}/glu-x11.cfg" /> <property name="jawt.cfg" value="${config}/jawt-x11.cfg" /> <property name="window.cfg" value="${config}/glx-x11.cfg" /> + <!-- Set platform headers. --> + <property name="glext.platform.header" value="${stub.includes.dir}/x11/glxext.c" /> + <!-- Set platform directories. --> <property name="stub.includes.platform" value="${stub.includes.x11}" /> <property name="java.excludes.platform" value="${java.excludes.x11}" /> @@ -353,18 +358,20 @@ <target name="declare.macosx" depends="init"> <!-- Set platform configuration files. --> <property name="gl.cfg" value="${config}/gl-macosx.cfg" /> - <property name="gl.impl.cfg" value="${config}/gl-impl-macosx.cfg" /> - <property name="glu.cfg" value="${config}/glu.cfg" /> - <property name="glu.impl.cfg" value="${config}/glu-impl-macosx.cfg" /> + <property name="glext.platform.cfg" value="${config}/cglext.cfg" /> + <property name="glu.cfg" value="${config}/glu-macosx.cfg" /> <property name="jawt.cfg" value="${config}/jawt-macosx.cfg" /> <property name="window.cfg" value="${config}/cgl-macosx.cfg" /> + <!-- Set platform headers. --> + <property name="glext.platform.header" value="${stub.includes.dir}/macosx/cglext.c" /> + <!-- Set platform directories. --> <property name="stub.includes.platform" value="${stub.includes}/macosx" /> <property name="java.includes.dir.platform" value="${java.includes.dir.macosx}" /> <property name="java.lib.dir.platform" value="${java.lib.dir.macosx}" /> <property name="java.excludes.platform" value="${java.excludes.macosx}" /> - <property name="stub.includes.fileset.platform.params" value="${stub.includes.dir}/macosx/** ${stub.includes.dir}/common/**" /> + <property name="stub.includes.fileset.platform.params" value="${stub.includes.dir}/macosx/** ${stub.includes.dir}/common/** ${stub.includes.dir}/opengl/**" /> <!-- Set Javadoc properties. --> <property name="javadoc.dev.packagenames.platform" value="${javadoc.dev.packagenames.macosx}" /> @@ -424,7 +431,7 @@ <dependset> <srcfileset refid="stub.includes.dependencies.fileset" /> <srcfileset dir="."> - <include name="${classes}/net/java/games/gluegen/**/*.class" /> + <include name="${classes}/com/sun/gluegen/**/*.class" /> </srcfileset> <targetfileset dir="."> <include name="${src.generated.java}/**/*.java" /> @@ -435,7 +442,7 @@ <!-- Now check for the presence of one well-known file --> <uptodate property="java.generate.skip"> <srcfiles refid="stub.includes.dependencies.fileset" /> - <mapper type="merge" to="${src.generated.java}/net/java/games/jogl/GL.java" /> + <mapper type="merge" to="${src.generated.java}/javax/media/opengl/GL.java" /> </uptodate> </target> @@ -455,56 +462,29 @@ </path> <!-- Add the GlueGen and BuildStaticGLInfo tasks to ANT --> - <taskdef name="gluegen" classname="net.java.games.gluegen.ant.GlueGenTask" + <taskdef name="gluegen" classname="com.sun.gluegen.ant.GlueGenTask" classpathref="gen.classpath" /> - <taskdef name="staticglgen" classname="net.java.games.gluegen.ant.StaticGLGenTask" + <taskdef name="staticglgen" classname="com.sun.gluegen.ant.StaticGLGenTask" classpathref="gen.classpath" /> <!-- Use the GlueGen and BuildStaticGLInfo tasks to generate the - Java files --> - <!-- Generate GL interface class --> - <echo message="Generating GL interface class" /> + <!-- Generate GL interface and implementation --> + <echo message="Generating GL interface and implementation" /> <gluegen src="${stub.includes.common}/gl.c" config="${gl.cfg}" includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> - <classpath refid="gen.classpath" /> - </gluegen> - - <!-- Generate GL implementation class --> - <echo message="Generating GL implementation class" /> - <gluegen src="${stub.includes.common}/gl-impl.c" - config="${gl.impl.cfg}" - includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> + emitter="com.sun.gluegen.opengl.GLEmitter"> <classpath refid="gen.classpath" /> </gluegen> - <!-- Generate WGL interface class --> - <echo message="Generating WGL interface class" /> - <gluegen src="${stub.includes.common}/gl-impl.c" - config="${config}/gl-wgl-win32.cfg" + <!-- Generate platform-specific extension class (WGLExt, GLXExt, etc.) --> + <echo message="Generating platform-specific OpenGL extension class" /> + <gluegen src="${glext.platform.header}" + config="${glext.platform.cfg}" includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> - <classpath refid="gen.classpath" /> - </gluegen> - - <!-- Generate GLX interface class --> - <echo message="Generating GLX interface class" /> - <gluegen src="${stub.includes.common}/gl-impl.c" - config="${config}/gl-glx-x11.cfg" - includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> - <classpath refid="gen.classpath" /> - </gluegen> - - <!-- Generate CGL interface class --> - <echo message="Generating CGL interface class" /> - <gluegen src="${stub.includes.common}/gl-impl.c" - config="${config}/gl-cgl-macosx.cfg" - includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> + emitter="com.sun.gluegen.opengl.GLEmitter"> <classpath refid="gen.classpath" /> </gluegen> @@ -519,7 +499,7 @@ config="${jawt.cfg}" literalInclude="${java.includes.dir}" includeRefid="stub.includes.fileset.platform" - emitter="net.java.games.gluegen.JavaEmitter"> + emitter="com.sun.gluegen.JavaEmitter"> <classpath refid="gen.classpath" /> </gluegen> @@ -528,33 +508,24 @@ <gluegen src="${stub.includes.platform}/window-system.c" config="${window.cfg}" includeRefid="stub.includes.fileset.platform" - emitter="net.java.games.gluegen.opengl.GLEmitter"> + emitter="com.sun.gluegen.opengl.GLEmitter"> <classpath refid="gen.classpath" /> </gluegen> <!-- Generate StaticGLInfo class --> <echo message="Generating StaticGLInfo class" /> - <staticglgen package="net.java.games.jogl.impl" + <staticglgen package="com.sun.opengl.impl" headers="${gl.headers}" - outputdir="${src.generated.java}/net/java/games/jogl/impl"> + outputdir="${src.generated.java}/com/sun/opengl/impl"> <classpath refid="gen.classpath" /> </staticglgen> - <!-- Generate GLU interface class --> - <echo message="Generating GLU interface class" /> + <!-- Generate GLU class --> + <echo message="Generating GLU class" /> <gluegen src="${stub.includes.common}/glu.c" config="${glu.cfg}" includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> - <classpath refid="gen.classpath" /> - </gluegen> - - <!-- Generate GLU implementation class --> - <echo message="Generating GLU implementation class" /> - <gluegen src="${stub.includes.common}/glu-impl.c" - config="${glu.impl.cfg}" - includeRefid="stub.includes.fileset.all" - emitter="net.java.games.gluegen.opengl.GLEmitter"> + emitter="com.sun.gluegen.opengl.GLEmitter"> <classpath refid="gen.classpath" /> </gluegen> @@ -579,7 +550,7 @@ <!-- Now check for the presence of one well-known file --> <uptodate property="java.generate.cg.skip"> <srcfiles refid="stub.includes.cg.dependencies.fileset" /> - <mapper type="merge" to="${src.generated.java}/net/java/games/cg/CgGL.java" /> + <mapper type="merge" to="${src.generated.java}/com/sun/opengl/cg/CgGL.java" /> </uptodate> </target> @@ -599,16 +570,16 @@ </path> <!-- Add the GlueGen and BuildStaticGLInfo tasks to ANT --> - <taskdef name="gluegen" classname="net.java.games.gluegen.ant.GlueGenTask" + <taskdef name="gluegen" classname="com.sun.gluegen.ant.GlueGenTask" classpathref="gen.classpath" /> - <taskdef name="staticglgen" classname="net.java.games.gluegen.ant.StaticGLGenTask" + <taskdef name="staticglgen" classname="com.sun.gluegen.ant.StaticGLGenTask" classpathref="gen.classpath" /> <!-- Generate CgGL interface class --> <gluegen src="${stub.includes.common}/cg.c" config="cg-common.cfg" includeRefid="stub.includes.cg.fileset.all" - emitter="net.java.games.gluegen.JavaEmitter"> + emitter="com.sun.gluegen.JavaEmitter"> <classpath refid="gen.classpath" /> </gluegen> </target> @@ -621,28 +592,28 @@ <!-- Blow away the DebugGL.java and TraceGL.java sources if GL.class has changed (the uptodate element doesn't support arbitrary source and destination files) --> <dependset> - <srcfilelist dir="${classes}/net/java/games/jogl" files="GL.class" /> - <srcfilelist dir="${classes}/net/java/games/gluegen/opengl" files="BuildComposablePipeline.class" /> - <targetfileset dir="${src.generated.java}/net/java/games/jogl" + <srcfilelist dir="${classes}/javax/media/opengl" files="GL.class" /> + <srcfilelist dir="${classes}/com/sun/gluegen/opengl" files="BuildComposablePipeline.class" /> + <targetfileset dir="${src.generated.java}/javax/media/opengl" includes="DebugGL.java,TraceGL.java" /> </dependset> <!-- Now choose one of the two to test to see if we have to regenerate --> <uptodate property="java.compile.composable.pipeline.skip" - srcfile="${classes}/net/java/games/jogl/GL.class" - targetfile="${src.generated.java}/net/java/games/jogl/DebugGL.java" /> + srcfile="${classes}/javax/media/opengl/GL.class" + targetfile="${src.generated.java}/javax/media/opengl/DebugGL.java" /> </target> <target name="java.compile.composable.pipeline" depends="java.compile.composable.pipeline.check" unless="java.compile.composable.pipeline.skip"> - <java classname="net.java.games.gluegen.opengl.BuildComposablePipeline" fork="yes"> - <arg value="net.java.games.jogl.GL" /> - <arg value="${src.generated.java}/net/java/games/jogl" /> + <java classname="com.sun.gluegen.opengl.BuildComposablePipeline" fork="yes"> + <arg value="javax.media.opengl.GL" /> + <arg value="${src.generated.java}/javax/media/opengl" /> <classpath refid="antlr.classpath" /> </java> <!-- Perform the second pass Java compile which compiles the composable pipelines. --> <javac destdir="${classes}" includes="${src.generated.java.pipeline}" source="1.4" debug="true" debuglevel="source,lines"> - <src path="${src}" /> + <src path="${src.java}" /> <src path="${src.generated.java}" /> <classpath refid="antlr.classpath" /> </javac> @@ -657,8 +628,8 @@ <target name="java.compile" depends="java.generate,java.generate.cg"> <!-- Perform the first pass Java compile. --> <javac destdir="${classes}" - excludes="${java.excludes.platform},net/java/games/jogl/impl/nurbs/**" source="1.4" debug="true" debuglevel="source,lines"> - <src path="${src}" /> + excludes="${java.excludes.platform},com/sun/opengl/impl/nurbs/**" source="1.4" debug="true" debuglevel="source,lines"> + <src path="${src.java}" /> <src path="${src.generated.java}" /> <classpath refid="antlr.classpath" /> </javac> @@ -917,9 +888,11 @@ <!-- Build the jar excluding any build specific classes. --> <jar destfile="${jogl.jar}"> <fileset dir="${classes}"> - <include name="net/java/games/jogl/**" /> - <include name="net/java/games/gluegen/runtime/**" /> - <include name="net/java/games/cg/**" /> + <include name="javax/media/opengl/**" /> + <include name="com/sun/gluegen/runtime/**" /> + <include name="com/sun/opengl/impl/**" /> + <include name="com/sun/opengl/utils/**" /> + <include name="com/sun/opengl/cg/**" /> </fileset> </jar> @@ -935,20 +908,20 @@ <target name="javadoc.nocg" depends="setup.java.home.dir,init" unless="jogl.cg"> <!-- Build the general Javadoc --> <javadoc packagenames="${javadoc.packagenames}" - sourcepath="${src};${src.generated.java}" - destdir="${javadoc}" windowtitle="JOGL API" + sourcepath="${src.java};${src.generated.java}" + destdir="${javadoc}" windowtitle="${javadoc.windowtitle}" source="1.4" - link="${javadoc.link}" /> + linkoffline="${javadoc.link} 142-packages" /> </target> <!-- Same as above but with Cg directories added --> <target name="javadoc.cg" depends="setup.java.home.dir,init" if="jogl.cg"> <!-- Build the general Javadoc --> - <javadoc packagenames="${javadoc.packagenames},net.java.games.cg" - sourcepath="${src};${src.generated.java}" - destdir="${javadoc}" windowtitle="JOGL API" + <javadoc packagenames="${javadoc.packagenames},com.sun.opengl.cg" + sourcepath="${src.java};${src.generated.java}" + destdir="${javadoc}" windowtitle="${javadoc.windowtitle}" source="1.4" - link="${javadoc.link}" /> + linkoffline="${javadoc.link} 142-packages" /> </target> <target name="javadoc" depends="javadoc.nocg,javadoc.cg" /> @@ -956,20 +929,20 @@ <target name="javadoc.dev.nocg" depends="init" unless="jogl.cg"> <!-- Build the internal developer Javadoc --> <javadoc packagenames="${javadoc.dev.packagenames},${javadoc.dev.packagenames.platform}" - sourcepath="${src};${src.generated.java}" - destdir="${javadoc.dev}" windowtitle="JOGL API" + sourcepath="${src.java};${src.generated.java}" + destdir="${javadoc.dev}" windowtitle="${javadoc.windowtitle}" source="1.4" - link="${javadoc.link}" /> + linkoffline="${javadoc.link} 142-packages" /> </target> <!-- Same as above but with Cg directories added --> <target name="javadoc.dev.cg" depends="init" if="jogl.cg"> <!-- Build the internal developer Javadoc --> - <javadoc packagenames="${javadoc.dev.packagenames},${javadoc.dev.packagenames.platform},net.java.games.cg" - sourcepath="${src};${src.generated.java}" - destdir="${javadoc.dev}" windowtitle="JOGL API" + <javadoc packagenames="${javadoc.dev.packagenames},${javadoc.dev.packagenames.platform},com.sun.opengl.cg" + sourcepath="${src.java};${src.generated.java}" + destdir="${javadoc.dev}" windowtitle="${javadoc.windowtitle}" source="1.4" - link="${javadoc.link}" /> + linkoffline="${javadoc.link} 142-packages" /> </target> <target name="javadoc.dev.win32" depends="setup.java.home.dir,declare.win32,javadoc.dev.nocg,javadoc.dev.cg" /> diff --git a/make/cg-common.cfg b/make/cg-common.cfg index 2954538f6..4e42ceb48 100644 --- a/make/cg-common.cfg +++ b/make/cg-common.cfg @@ -1,44 +1,67 @@ # This .cfg file provides common options used among all Cg glue code # generated for Jogl on all platforms. -Package net.java.games.cg -ImplPackage net.java.games.cg.impl +Package com.sun.opengl.cg JavaClass CgGL Style AllStatic JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl_cg HierarchicalNativeOutput false -# Generate "flattened" NIO variants for routines taking C primitive -# pointers that aren't of type void* -NioMode ALL_POINTERS -FlattenNIOVariants true - # # Map const char* return values to Java strings for these functions # +ReturnsString cgGetAnnotationName ReturnsString cgGetEnumString ReturnsString cgGetErrorString ReturnsString cgGetLastErrorString ReturnsString cgGetLastListing ReturnsString cgGetParameterName ReturnsString cgGetParameterSemantic +ReturnsString cgGetPassName ReturnsString cgGetProfileString ReturnsString cgGetProgramString ReturnsString cgGetResourceString +ReturnsString cgGetStateName ReturnsString cgGetString +ReturnsString cgGetStringAnnotationValue +ReturnsString cgGetStringParameterValue +ReturnsString cgGetStringStateAssignmentValue +ReturnsString cgGetTechniqueName ReturnsString cgGetTypeString +ArgumentIsString cgAddStateEnumerant 1 +ArgumentIsString cgCreateArrayState 1 +ArgumentIsString cgCreateArraySamplerState 1 +ArgumentIsString cgCreateEffect 1 2 +ArgumentIsString cgCreateEffectFromFile 1 2 ArgumentIsString cgCreateProgram 2 4 5 ArgumentIsString cgCreateProgramFromFile 2 4 5 +ArgumentIsString cgCreateProgramFromEffect 2 3 +ArgumentIsString cgCreateSamplerState 1 +ArgumentIsString cgCreateState 1 +ArgumentIsString cgGetEffectParameterBySemantic 1 ArgumentIsString cgGetEnum 0 +ArgumentIsString cgGetNamedEffectParameter 1 ArgumentIsString cgGetNamedParameter 1 +ArgumentIsString cgGetNamedPass 1 ArgumentIsString cgGetNamedProgramParameter 2 +ArgumentIsString cgGetNamedSamplerState 1 +ArgumentIsString cgGetNamedState 1 +ArgumentIsString cgGetNamedSamplerStateAssignment 1 +ArgumentIsString cgGetNamedStateAssignment 1 ArgumentIsString cgGetNamedStructParameter 1 +ArgumentIsString cgGetNamedTechnique 1 +ArgumentIsString cgGetNamedTechniqueAnnotation 1 +ArgumentIsString cgGetNamedPassAnnotation 1 +ArgumentIsString cgGetNamedParameterAnnotation 1 +ArgumentIsString cgGetNamedProgramAnnotation 1 ArgumentIsString cgGetNamedUserType 1 ArgumentIsString cgGetProfile 0 ArgumentIsString cgGetType 0 ArgumentIsString cgGetResource 0 +ArgumentIsString cgSetLastListing 1 ArgumentIsString cgSetParameterSemantic 1 +ArgumentIsString cgSetStringParameterValue 1 # Opaque definitions Opaque boolean CGbool @@ -47,14 +70,26 @@ Opaque boolean CGbool # FIXME!!!! Ignore these functions for now because we can't # automatically handle C callbacks # -Ignore cgGetErrorCallback Ignore cgSetErrorCallback +Ignore cgGetErrorCallback +Ignore cgSetErrorHandler +Ignore cgGetErrorHandler +Ignore cgSetStateCallbacks +Ignore cgGetStateSetCallback +Ignore cgGetStateResetCallback +Ignore cgGetStateValidateCallback # # FIXME!!!! Ignore these functions for now because bugs in the # emitter code can't handle them # Ignore cgGetParameterValues +Ignore cgGetBooleanAnnotationValues +Ignore cgGetBoolStateAssignmentValues +Ignore cgGetFloatAnnotationValues +Ignore cgGetFloatStateAssignmentValues +Ignore cgGetIntAnnotationValues +Ignore cgGetIntStateAssignmentValues # # Need to import New IO for Buffer classes diff --git a/make/cgl-macosx.cfg b/make/cgl-macosx.cfg index 1a963f135..ccf25e718 100644 --- a/make/cgl-macosx.cfg +++ b/make/cgl-macosx.cfg @@ -1,6 +1,6 @@ # This .cfg file is used to generate the interface to the CGL routines # used internally by the MacOSXGLContext implementation. -Package net.java.games.jogl.impl.macosx +Package com.sun.opengl.impl.macosx JavaOutputDir ..\build\gensrc\classes NativeOutputDir ..\build\gensrc\native\jogl JavaClass CGL diff --git a/make/cglext.cfg b/make/cglext.cfg new file mode 100755 index 000000000..74e7ac841 --- /dev/null +++ b/make/cglext.cfg @@ -0,0 +1,53 @@ +# This .cfg file is used to generate the interface and implementing +# class for the CGL extensions. +# Note that there are currently no such extensions exposed on Mac OS +# X, but if in the future there are, this structure will allow them to +# be easily exposed. +Package com.sun.opengl.impl.macosx +Style InterfaceAndImpl +JavaClass CGLExt +ImplPackage com.sun.opengl.impl.macosx +ImplJavaClass CGLExtImpl +Include gl-common-macosx.cfg + +EmitProcAddressTable true +ProcAddressTableClassName CGLExtProcAddressTable +ContextVariableName _context + +# Ignore everything that doesn't start with cgl or CGL +IgnoreNot ^(cgl|CGL).+ + +CustomCCode #include <inttypes.h> +CustomCCode #include <stdlib.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> + +CustomCCode #include </usr/include/machine/types.h> + +CustomCCode /* Provide Windows typedefs */ +CustomCCode typedef void* LPVOID; +CustomCCode typedef unsigned int* PUINT; + +CustomJavaCode CGLExt public boolean isFunctionAvailable(String glFunctionName); +CustomJavaCode CGLExt public boolean isExtensionAvailable(String glExtensionName); + +CustomJavaCode CGLExtImpl public CGLExtImpl(MacOSXGLContext context) { +CustomJavaCode CGLExtImpl this._context = context; +CustomJavaCode CGLExtImpl } + +CustomJavaCode CGLExtImpl public boolean isFunctionAvailable(String glFunctionName) +CustomJavaCode CGLExtImpl { +CustomJavaCode CGLExtImpl return _context.isFunctionAvailable(glFunctionName); +CustomJavaCode CGLExtImpl } + +CustomJavaCode CGLExtImpl public boolean isExtensionAvailable(String glExtensionName) +CustomJavaCode CGLExtImpl { +CustomJavaCode CGLExtImpl return _context.isExtensionAvailable(glExtensionName); +CustomJavaCode CGLExtImpl } + +CustomJavaCode CGLExtImpl private MacOSXGLContext _context; diff --git a/make/gl-cgl-macosx.cfg b/make/gl-cgl-macosx.cfg deleted file mode 100644 index 20653251a..000000000 --- a/make/gl-cgl-macosx.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# This .cfg file is used to generate the interface which contains the -# window system-specific extensions which are exposed (via -# inheritance) to the GL interface. -Package net.java.games.jogl -Style InterfaceOnly -JavaClass CGL -Include gl-common-macosx.cfg - -# Ignore everything that doesn't start with cgl -IgnoreNot ^(cgl|CGL).+ diff --git a/make/gl-common-macosx.cfg b/make/gl-common-macosx.cfg index baeace1d7..f72775dd0 100644 --- a/make/gl-common-macosx.cfg +++ b/make/gl-common-macosx.cfg @@ -5,6 +5,3 @@ HierarchicalNativeOutput false Include gl-common.cfg JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl - -Unimplemented wgl.+ -Unimplemented glX.+ diff --git a/make/gl-common-win32.cfg b/make/gl-common-win32.cfg index 2ab42d4eb..1d2451270 100644 --- a/make/gl-common-win32.cfg +++ b/make/gl-common-win32.cfg @@ -5,6 +5,3 @@ HierarchicalNativeOutput false Include gl-common.cfg JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl - -Unimplemented cgl.+ -Unimplemented glX.+ diff --git a/make/gl-common-x11.cfg b/make/gl-common-x11.cfg index dcaeac4f2..63981cb2a 100644 --- a/make/gl-common-x11.cfg +++ b/make/gl-common-x11.cfg @@ -7,18 +7,3 @@ NativeOutputDir ../build/gensrc/native/jogl # XID needs to be treated as a long for 32/64 bit compatibility Opaque long XID - -# Get returned array's capacity from XGetVisualInfo to be correct -TemporaryCVariableDeclaration XGetVisualInfo int count; -TemporaryCVariableAssignment XGetVisualInfo count = _ptr3[0]; -ReturnValueCapacity XGetVisualInfo count * sizeof(XVisualInfo) -ReturnedArrayLength XGetVisualInfo {3}[0] -ReturnValueCapacity glXChooseVisual sizeof(XVisualInfo) -ReturnValueCapacity glXGetVisualFromFBConfig sizeof(XVisualInfo) -ReturnValueCapacity glXGetVisualFromFBConfigSGIX sizeof(XVisualInfo) -# Elide the version of XGetVisualInfo taking a direct buffer for the third argument -# (since we can't specify different glue code for different overloadings -- FIXME) -NoNio XGetVisualInfo - -Unimplemented cgl.+ -Unimplemented wgl.+ diff --git a/make/gl-common.cfg b/make/gl-common.cfg index 515b3726c..ab8af9e09 100644 --- a/make/gl-common.cfg +++ b/make/gl-common.cfg @@ -7,13 +7,13 @@ RuntimeExceptionType GLException # Imports needed by all glue code Import java.nio.* Import java.util.* -Import net.java.games.jogl.* -Import net.java.games.jogl.impl.* +Import javax.media.opengl.* +Import com.sun.opengl.impl.* -# Generate "flattened" NIO variants for routines taking C primitive -# pointers that aren't of type void* -NioMode ALL_POINTERS -FlattenNIOVariants true +# Inform the glue code generator of the association between #defines +# and functions and the extensions in which they are defined +GLHeader GL/gl.h +GLHeader GL/glext.h # Don't output #defines of GL version identifier strings as constants, # because we don't need them java-side. @@ -74,14 +74,6 @@ Ignore glUnmapObjectBufferATI # Ignore some GL functions that have outgoing void** parameters; we cannot yet deal with them Ignore glGetVariantPointervEXT -# Some GL functions have multiple void* arguments but require them to -# contain data of the same type; make sure that when bindings are -# expanded those arguments have the same type. -MirrorExpandedBindingArgs glSeparableFilter2D 6 7 -MirrorExpandedBindingArgs glSeparableFilter2DEXT 6 7 -MirrorExpandedBindingArgs glGetSeparableFilter 3 4 -MirrorExpandedBindingArgs glGetSeparableFilterEXT 3 4 - # FIXME: these extensions require either a handle to a device context # or take void** parameters or both. Until we think through the # semantics of each of these individually we need to disable them. @@ -120,6 +112,67 @@ Ignore wglAssociateImageBufferEventsI3D Ignore wglReleaseImageBufferEventsI3D # +# IgnoreExtension directives +# + +# Ignore extensions requiring persistent pointer-to-pointer storage as +# there is no such thing as a direct "BufferBuffer" +IgnoreExtension GL_IBM_vertex_array_lists +IgnoreExtension GL_INTEL_parallel_arrays +IgnoreExtension GL_SUN_triangle_list + +# Ignore extensions never approved by the ARB +IgnoreExtension GL_EXT_coordinate_frame + +# Ignore discontinued extensions +IgnoreExtension GL_NV_element_array + +# Ignore extensions subsumed in OpenGL 1.1 (from OpenGL 1.1 spec, Appendix C) +IgnoreExtension GL_EXT_vertex_array +IgnoreExtension GL_EXT_blend_logic_op +IgnoreExtension GL_EXT_copy_texture +IgnoreExtension GL_EXT_polygon_offset +IgnoreExtension GL_EXT_subtexture +IgnoreExtension GL_EXT_texture +IgnoreExtension GL_EXT_texture_object + +# Ignore extensions subsumed in OpenGL 1.2 and 1.2.1 (from OpenGL 1.2.1 spec, Appendix D) +IgnoreExtension GL_EXT_bgra +IgnoreExtension GL_EXT_blend_color +IgnoreExtension GL_EXT_blend_minmax +IgnoreExtension GL_EXT_blend_subtract +IgnoreExtension GL_EXT_color_subtable +IgnoreExtension GL_EXT_convolution +IgnoreExtension GL_EXT_draw_range_elements +IgnoreExtension GL_EXT_histogram +IgnoreExtension GL_EXT_packed_pixels +# FIXME: is GL_EXT_paletted_texture also obsolete? +IgnoreExtension GL_EXT_rescale_normal +IgnoreExtension GL_EXT_separate_specular_color +IgnoreExtension GL_EXT_texture3D +IgnoreExtension GL_HP_convolution_border_modes +IgnoreExtension GL_SGI_color_matrix +IgnoreExtension GL_SGI_color_table +IgnoreExtension GL_SGIS_texture_edge_clamp +IgnoreExtension GL_SGIS_texture_lod + +# Ignore extensions subsumed in OpenGL 1.3 (from OpenGL 1.3 spec, Appendix F) +IgnoreExtension GL_ARB_multisample +IgnoreExtension GL_ARB_multitexture +IgnoreExtension GL_ARB_texture_compression +IgnoreExtension GL_ARB_texture_cube_map +IgnoreExtension GL_ARB_texture_border_clamp +IgnoreExtension GL_ARB_texture_env_add +IgnoreExtension GL_ARB_texture_env_combine +IgnoreExtension GL_ARB_texture_env_dot3 +IgnoreExtension GL_ARB_transpose_matrix +IgnoreExtension GL_EXT_texture_cube_map +IgnoreExtension GL_EXT_texture_env_add +IgnoreExtension GL_EXT_texture_env_combine +IgnoreExtension GL_EXT_texture_env_dot3 +IgnoreExtension GL_SGIS_texture_border_clamp + +# # Opaques and other directives for platform-independent routines # @@ -127,51 +180,50 @@ Opaque boolean GLboolean ReturnsString glGetString # -# NIOOnly directives for vertex arrays and other core routines +# NIODirectOnly directives for vertex arrays and other core routines # -NIOOnly glColorPointer -NIOOnly glEdgeFlagPointer -NIOOnly glFeedbackBuffer -NIOOnly glIndexPointer -NIOOnly glNormalPointer -NIOOnly glSelectBuffer -NIOOnly glTexCoordPointer -NIOOnly glVertexPointer +NIODirectOnly glColorPointer +NIODirectOnly glEdgeFlagPointer +NIODirectOnly glFeedbackBuffer +NIODirectOnly glIndexPointer +NIODirectOnly glNormalPointer +NIODirectOnly glSelectBuffer +NIODirectOnly glTexCoordPointer +NIODirectOnly glVertexPointer # # FIXME: we should probably be ignoring the "EXT" variants of these # -NIOOnly glColorPointerEXT -NIOOnly glEdgeFlagPointerEXT -NIOOnly glIndexPointerEXT -NIOOnly glNormalPointerEXT -NIOOnly glTexCoordPointerEXT -NIOOnly glVertexPointerEXT +NIODirectOnly glColorPointerEXT +NIODirectOnly glEdgeFlagPointerEXT +NIODirectOnly glIndexPointerEXT +NIODirectOnly glNormalPointerEXT +NIODirectOnly glTexCoordPointerEXT +NIODirectOnly glVertexPointerEXT # -# NIOOnly directives for other extensions +# NIODirectOnly directives for other extensions # -NIOOnly glBinormalPointerEXT -NIOOnly glGetBufferSubDataARB +NIODirectOnly glBinormalPointerEXT +NIODirectOnly glGetBufferSubDataARB # FIXME: should add way to restrict argument to be a direct ByteBuffer -NIOOnly glGetProgramStringARB -NIOOnly glElementPointerATI -NIOOnly glElementPointerNV -NIOOnly glFogCoordPointer -NIOOnly glFogCoordPointerEXT -NIOOnly glMatrixIndexPointerARB -# NIOOnly glNewObjectBufferATI # FIXME: look up semantics of this routine -NIOOnly glPixelDataRangeNV -NIOOnly glSecondaryColorPointer -NIOOnly glSecondaryColorPointerEXT -NIOOnly glTangentPointerEXT -# NIOOnly glUpdateObjectBufferATI # FIXME: look up semantics of this routine -# NIOOnly glVariantPointerEXT # FIXME: look up semantics of this routine -NIOOnly glVertexArrayRangeNV -NIOOnly glVertexAttribPointerARB -NIOOnly glVertexAttribPointerNV -NIOOnly glVertexWeightPointerEXT -NIOOnly glWeightPointerARB -NIOOnly wglFreeMemoryNV -NIOOnly glXFreeMemoryNV +NIODirectOnly glGetProgramStringARB +NIODirectOnly glElementPointerATI +NIODirectOnly glElementPointerNV +NIODirectOnly glElementPointerAPPLE +NIODirectOnly glFogCoordPointer +NIODirectOnly glFogCoordPointerEXT +NIODirectOnly glMatrixIndexPointerARB +NIODirectOnly glPixelDataRangeNV +NIODirectOnly glSecondaryColorPointer +NIODirectOnly glSecondaryColorPointerEXT +NIODirectOnly glTangentPointerEXT +NIODirectOnly glVertexArrayRangeNV +NIODirectOnly glVertexArrayRangeApple +NIODirectOnly glVertexAttribPointerARB +NIODirectOnly glVertexAttribPointerNV +NIODirectOnly glVertexWeightPointerEXT +NIODirectOnly glWeightPointerARB +NIODirectOnly wglFreeMemoryNV +NIODirectOnly glXFreeMemoryNV # Capacity of wglAllocateMemoryNV/glXAllocateMemoryNV return value is # same as value of first argument @@ -189,11 +241,96 @@ ArgumentIsString glProgramNamedParameter4fvNV 2 ArgumentIsString glProgramNamedParameter4dvNV 2 ArgumentIsString glGetProgramNamedParameterfvNV 2 ArgumentIsString glGetProgramNamedParameterdvNV 2 +ArgumentIsString glShaderSource 2 ArgumentIsString glShaderSourceARB 2 +ArgumentIsString glGetUniformLocation 1 ArgumentIsString glGetUniformLocationARB 1 +ArgumentIsString glBindAttribLocation 2 ArgumentIsString glBindAttribLocationARB 2 +ArgumentIsString glGetAttribLocation 1 ArgumentIsString glGetAttribLocationARB 1 +# +# Directives for Vertex Buffer Object and Pixel Buffer Object checking +# +# NOTE: we currently don't emit glue code for some of these but +# include them for completeness. +# +# FIXME: what about glMultiDrawElements? Do we want to add a VBO +# variant for that, or simply add checks to the top of the current +# implementation? +# +JavaPrologue glBegin inBeginEndPair = true; +JavaEpilogue glEnd inBeginEndPair = false; +BufferObjectKind UnpackPixel glBitmap +BufferObjectKind UnpackPixel glColorTable +BufferObjectKind UnpackPixel glColorSubTable +BufferObjectKind UnpackPixel glCompressedTexImage1D +BufferObjectKind UnpackPixel glCompressedTexImage1DARB +BufferObjectKind UnpackPixel glCompressedTexImage2D +BufferObjectKind UnpackPixel glCompressedTexImage2DARB +BufferObjectKind UnpackPixel glCompressedTexImage3D +BufferObjectKind UnpackPixel glCompressedTexImage3DARB +BufferObjectKind UnpackPixel glCompressedTexSubImage1D +BufferObjectKind UnpackPixel glCompressedTexSubImage1DARB +BufferObjectKind UnpackPixel glCompressedTexSubImage2D +BufferObjectKind UnpackPixel glCompressedTexSubImage2DARB +BufferObjectKind UnpackPixel glCompressedTexSubImage3D +BufferObjectKind UnpackPixel glCompressedTexSubImage3DARB +BufferObjectKind UnpackPixel glConvolutionFilter1D +BufferObjectKind UnpackPixel glConvolutionFilter2D +BufferObjectKind UnpackPixel glDrawPixels +BufferObjectKind UnpackPixel glPixelMapfv +BufferObjectKind UnpackPixel glPixelMapuiv +BufferObjectKind UnpackPixel glPixelMapusv +BufferObjectKind UnpackPixel glPolygonStipple +BufferObjectKind UnpackPixel glSeparableFilter2D +BufferObjectKind UnpackPixel glTexImage1D +BufferObjectKind UnpackPixel glTexImage2D +BufferObjectKind UnpackPixel glTexImage3D +BufferObjectKind UnpackPixel glTexSubImage1D +BufferObjectKind UnpackPixel glTexSubImage2D +BufferObjectKind UnpackPixel glTexSubImage3D + +BufferObjectKind PackPixel glGetColorTable +BufferObjectKind PackPixel glGetCompressedTexImage +BufferObjectKind PackPixel glGetCompressedTexImageARB +BufferObjectKind PackPixel glGetConvolutionFilter +BufferObjectKind PackPixel glGetHistogram +BufferObjectKind PackPixel glGetMinmax +BufferObjectKind PackPixel glGetPixelMapfv +BufferObjectKind PackPixel glGetPixelMapuiv +BufferObjectKind PackPixel glGetPixelMapusv +BufferObjectKind PackPixel glGetPolygonStipple +BufferObjectKind PackPixel glGetSeparableFilter +BufferObjectKind PackPixel glGetTexImage +BufferObjectKind PackPixel glReadPixels + +BufferObjectKind Array glColorPointer +BufferObjectKind Array glEdgeFlagPointer +BufferObjectKind Array glElementPointerATI +BufferObjectKind Array glFogCoordPointer +BufferObjectKind Array glFogCoordPointerEXT +# The next one is problematic. It isn't discussed by the specs and +# doesn't have any associated state. +BufferObjectKind Array glInterleavedArrays +BufferObjectKind Array glMatrixIndexPointerARB +BufferObjectKind Array glNormalPointer +BufferObjectKind Array glSecondaryColorPointer +BufferObjectKind Array glSecondaryColorPointerEXT +BufferObjectKind Array glTexCoordPointer +BufferObjectKind Array glVariantPointerEXT +BufferObjectKind Array glVertexPointer +BufferObjectKind Array glVertexAttribPointer +BufferObjectKind Array glVertexAttribPointerARB +BufferObjectKind Array glVertexAttribPointerNV +BufferObjectKind Array glVertexWeightPointerEXT +BufferObjectKind Array glWeightPointerARB + +BufferObjectKind Element glDrawElements +BufferObjectKind Element glDrawRangeElements +BufferObjectKind Element glDrawRangeElementsEXT + # Javadoc for the GL class ClassJavadoc GL /** ClassJavadoc GL * <P> The basic interface to OpenGL, providing access to core @@ -220,25 +357,16 @@ ClassJavadoc GL * However, in this case it is up to the end user to know which ClassJavadoc GL * routines or functionality are associated with which OpenGL ClassJavadoc GL * extensions. ClassJavadoc GL * -ClassJavadoc GL * <P> Access to window system-specific extensions is provided through -ClassJavadoc GL * the {@link WGL} and {@link GLX} interfaces. However, most of these -ClassJavadoc GL * extensions require access to low-level window system data -ClassJavadoc GL * structures which are not exposed by this binding, and are therefore -ClassJavadoc GL * not useful. Calling one particular window system's extension on -ClassJavadoc GL * another platform will cause a {@link GLException} to be raised -ClassJavadoc GL * indicating the routine is unimplemented on the current platform. -ClassJavadoc GL * </P> -ClassJavadoc GL * ClassJavadoc GL * <P> Exceptions to the window system extension naming rules: ClassJavadoc GL * ClassJavadoc GL * <UL> ClassJavadoc GL * -ClassJavadoc GL * <LI> The NVidia vertex_array_range (VAR) extension, in particular {@link -ClassJavadoc GL * WGL#wglAllocateMemoryNV} / {@link GLX#glXAllocateMemoryNV} and -ClassJavadoc GL * associated routines. {@link #glAllocateMemoryNV} has been provided -ClassJavadoc GL * for window system-independent access to VAR. {@link -ClassJavadoc GL * #isFunctionAvailable} will translate an argument of -ClassJavadoc GL * "glAllocateMemoryNV" or "glFreeMemoryNV" into the appropriate +ClassJavadoc GL * <LI> The memory allocators for the NVidia vertex_array_range (VAR) +ClassJavadoc GL * extension, in particular <code>wglAllocateMemoryNV</code> / +ClassJavadoc GL * <code>glXAllocateMemoryNV</code> and associated routines. {@link +ClassJavadoc GL * #glAllocateMemoryNV} has been provided for window system-independent +ClassJavadoc GL * access to VAR. {@link #isFunctionAvailable} will translate an argument +ClassJavadoc GL * of "glAllocateMemoryNV" or "glFreeMemoryNV" into the appropriate ClassJavadoc GL * window system-specific name. </P> ClassJavadoc GL * ClassJavadoc GL * <LI> WGL_ARB_pbuffer, WGL_ARB_pixel_format, and other @@ -320,11 +448,11 @@ CustomJavaCode GL * depth of the display). Any application that is concerned CustomJavaCode GL * these situations correctly should confirm availability after a display CustomJavaCode GL * change before calling a questionable OpenGL function. To detect a change in CustomJavaCode GL * the display device, please see {@link -CustomJavaCode GL * GLEventListener#displayChanged(GLDrawable,boolean,boolean)}. +CustomJavaCode GL * GLEventListener#displayChanged(GLAutoDrawable,boolean,boolean)}. CustomJavaCode GL * CustomJavaCode GL * @param glFunctionName the name of the OpenGL function (e.g., use -CustomJavaCode GL * "glPolygonOffsetEXT" to check if the {@link -CustomJavaCode GL * #glPolygonOffsetEXT(float,float)} is available). +CustomJavaCode GL * "glBindRenderbufferEXT" to check if {@link +CustomJavaCode GL * #glBindRenderbufferEXT(int,int)} is available). CustomJavaCode GL */ CustomJavaCode GL public boolean isFunctionAvailable(String glFunctionName); @@ -339,8 +467,8 @@ CustomJavaCode GL */ CustomJavaCode GL public boolean isExtensionAvailable(String glExtensionName); CustomJavaCode GL /** -CustomJavaCode GL * Provides platform-independent access to the {@link WGL#wglAllocateMemoryNV} / -CustomJavaCode GL * {@link GLX#glXAllocateMemoryNV} extension. +CustomJavaCode GL * Provides platform-independent access to the <code>wglAllocateMemoryNV</code> / +CustomJavaCode GL * <code>glXAllocateMemoryNV</code> extension. CustomJavaCode GL */ CustomJavaCode GL public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3); @@ -354,6 +482,38 @@ CustomJavaCode GL have an effect, and in particular only affects heavyweig CustomJavaCode GL onscreen components. */ CustomJavaCode GL public void setSwapInterval(int interval); +CustomJavaCode GL /** +CustomJavaCode GL * Returns an object through which platform-specific OpenGL extensions +CustomJavaCode GL * (WGL, GLX, etc.) may be accessed. The data type of the returned +CustomJavaCode GL * object and its associated capabilities are undefined. Most +CustomJavaCode GL * applications will never need to call this method. It is highly +CustomJavaCode GL * recommended that any applications which do call this method perform +CustomJavaCode GL * all accesses on the returned object reflectively to guard +CustomJavaCode GL * themselves against changes to the implementation. +CustomJavaCode GL */ +CustomJavaCode GL public Object getPlatformGLExtensions(); + +CustomJavaCode GL /** +CustomJavaCode GL * Returns an object providing access to the specified OpenGL +CustomJavaCode GL * extension. This is intended to provide a mechanism for vendors who +CustomJavaCode GL * which to provide access to new OpenGL extensions without changing +CustomJavaCode GL * the public API of the core package. For example, a user may request +CustomJavaCode GL * access to extension "GL_VENDOR_foo" and receive back an object +CustomJavaCode GL * which implements a vendor-specified interface which can call the +CustomJavaCode GL * OpenGL extension functions corresponding to that extension. It is +CustomJavaCode GL * up to the vendor to specify both the extension name and Java API +CustomJavaCode GL * for accessing it, including which class or interface contains the +CustomJavaCode GL * functions. +CustomJavaCode GL * +CustomJavaCode GL * <P> +CustomJavaCode GL * +CustomJavaCode GL * Note: it is the intent to add new extensions as quickly as possible +CustomJavaCode GL * to the core GL API. Therefore it is unlikely that most vendors will +CustomJavaCode GL * use this extension mechanism, but it is being provided for +CustomJavaCode GL * completeness. +CustomJavaCode GL */ +CustomJavaCode GL public Object getExtension(String extensionName); + # # Directives needed when processing wglext.h on Windows and other platforms # diff --git a/make/gl-glx-common.cfg b/make/gl-glx-common.cfg deleted file mode 100644 index a613149bc..000000000 --- a/make/gl-glx-common.cfg +++ /dev/null @@ -1,85 +0,0 @@ -# This .cfg file causes the core GLX routines to be ignored from both -# the public API as well as from the GL implementation files on -# non-X11 platforms. - -# Ignore all of the core GLX routines, which are exposed only in the -# implementation GLX class -Ignore glXChooseVisual -Ignore glXCreateContext -Ignore glXDestroyContext -Ignore glXMakeCurrent -Ignore glXCopyContext -Ignore glXSwapBuffers -Ignore glXCreateGLXPixmap -Ignore glXDestroyGLXPixmap -Ignore glXQueryExtension -Ignore glXQueryVersion -Ignore glXIsDirect -Ignore glXGetConfig -Ignore glXGetCurrentContext -Ignore glXGetCurrentDrawable -Ignore glXWaitGL -Ignore glXWaitX -Ignore glXUseXFont -Ignore glXQueryExtensionsString -Ignore glXQueryServerString -Ignore glXGetClientString -Ignore glXGetCurrentDisplay -Ignore glXChooseFBConfig -Ignore glXGetFBConfigAttrib -Ignore glXGetFBConfigs -Ignore glXGetVisualFromFBConfig -Ignore glXCreateWindow -Ignore glXDestroyWindow -Ignore glXCreatePixmap -Ignore glXDestroyPixmap -Ignore glXCreatePbuffer -Ignore glXDestroyPbuffer -Ignore glXQueryDrawable -Ignore glXCreateNewContext -Ignore glXMakeContextCurrent -Ignore glXGetCurrentReadDrawable -Ignore glXQueryContext -Ignore glXSelectEvent -Ignore glXGetSelectedEvent -Ignore glXGetProcAddress - -# Ignore a few extensions that bring in data types we don't want to -# expose in the public API (and that are useless anyway without -# exposing more of the implementation) -Ignore glXGetFBConfigAttribSGIX -Ignore glXChooseFBConfigSGIX -Ignore glXCreateGLXPixmapWithConfigSGIX -Ignore glXCreateContextWithConfigSGIX -Ignore glXGetVisualFromFBConfigSGIX -Ignore glXGetFBConfigFromVisualSGIX -Ignore glXCreateGLXPbufferSGIX -Ignore glXDestroyGLXPbufferSGIX -Ignore glXQueryGLXPbufferSGIX -Ignore glXSelectEventSGIX -Ignore glXGetSelectedEventSGIX -Ignore glXCreateGLXPixmapMESA - -# Now we can ignore the GLXFBConfig and XVisualInfo data types in the -# public API on all platforms -Ignore GLXFBConfig -Ignore XVisualInfo - -# Ignore the SGI hyperpipe extension, which will require more GlueGen -# work to expose the pipeName fields in the various structs -Ignore glXQueryHyperpipeNetworkSGIX -Ignore glXHyperpipeConfigSGIX -Ignore glXQueryHyperpipeConfigSGIX -Ignore glXDestroyHyperpipeConfigSGIX -Ignore glXBindHyperpipeSGIX -Ignore glXQueryHyperpipeBestAttribSGIX -Ignore glXHyperpipeAttribSGIX -Ignore glXQueryHyperpipeAttribSGIX -Ignore GLXHyperpipeNetworkSGIX -Ignore GLXHyperpipeConfigSGIX -Ignore GLXPipeRect -Ignore GLXPipeRectLimits - -# XID shows up in the public API (and shouldn't -- will be removed in -# the JSR 231/239 APIs) and needs to be treated as a long for now -Opaque long XID diff --git a/make/gl-glx-x11.cfg b/make/gl-glx-x11.cfg deleted file mode 100644 index 359e35c62..000000000 --- a/make/gl-glx-x11.cfg +++ /dev/null @@ -1,14 +0,0 @@ -# This .cfg file is used to generate the interface which contains the -# window system-specific extensions which are exposed (via -# inheritance) to the GL interface. -Package net.java.games.jogl -Style InterfaceOnly -JavaClass GLX -Include gl-common-x11.cfg - -# Ignore everything that doesn't start with glX or GLX -IgnoreNot ^(glX|GLX).+ - -# Pick up ignores that must also be included in other platforms' impl -# files -Include gl-glx-common.cfg diff --git a/make/gl-impl-CustomCCode.c b/make/gl-impl-CustomCCode.c index f0c7cb45a..2ea5376e7 100644 --- a/make/gl-impl-CustomCCode.c +++ b/make/gl-impl-CustomCCode.c @@ -1,10 +1,10 @@ /* Java->C glue code: - * Java package: net.java.games.jogl.impl.windows.WindowsGLImpl + * Java package: net.java.games.jogl.impl.GLImpl * Java method: long dispatch_glMapBuffer(int target, int access) * C function: LPVOID glMapBuffer(GLenum target, GLenum access); */ JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_windows_WindowsGLImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { +Java_com_sun_opengl_impl_GLImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { PFNGLMAPBUFFERPROC ptr_glMapBuffer; LPVOID _res; ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; @@ -14,12 +14,12 @@ Java_net_java_games_jogl_impl_windows_WindowsGLImpl_dispatch_1glMapBuffer(JNIEnv } /* Java->C glue code: - * Java package: net.java.games.jogl.impl.windows.WindowsGLImpl + * Java package: net.java.games.jogl.impl.GLImpl * Java method: long dispatch_glMapBufferARB(int target, int access) * C function: LPVOID glMapBufferARB(GLenum target, GLenum access); */ JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_windows_WindowsGLImpl_dispatch_1glMapBufferARB(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { +Java_com_sun_opengl_impl_GLImpl_dispatch_1glMapBufferARB(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { PFNGLMAPBUFFERARBPROC ptr_glMapBufferARB; LPVOID _res; ptr_glMapBufferARB = (PFNGLMAPBUFFERARBPROC) (intptr_t) glProcAddress; @@ -27,65 +27,3 @@ Java_net_java_games_jogl_impl_windows_WindowsGLImpl_dispatch_1glMapBufferARB(JNI _res = (* ptr_glMapBufferARB) ((GLenum) target, (GLenum) access); return (jlong) (intptr_t) _res; } - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.x11.X11GLImpl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: LPVOID glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_x11_X11GLImpl_dispatch_1glMapBuffer(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - LPVOID _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.x11.X11GLImpl - * Java method: long dispatch_glMapBufferARB(int target, int access) - * C function: LPVOID glMapBufferARB(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_x11_X11GLImpl_dispatch_1glMapBufferARB(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) { - PFNGLMAPBUFFERARBPROC ptr_glMapBufferARB; - LPVOID _res; - ptr_glMapBufferARB = (PFNGLMAPBUFFERARBPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBufferARB != NULL); - _res = (* ptr_glMapBufferARB) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.macosx.MacOSXGLImpl - * Java method: long dispatch_glMapBufferARB(int target, int access) - * C function: LPVOID glMapBufferARB(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_macosx_MacOSXGLImpl_dispatch_1glMapBuffer( JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) -{ - PFNGLMAPBUFFERPROC ptr_glMapBuffer; - LPVOID _res; - ptr_glMapBuffer = (PFNGLMAPBUFFERPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBuffer != NULL); - _res = (* ptr_glMapBuffer) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.macosx.MacOSXGLImpl - * Java method: long dispatch_glMapBuffer(int target, int access) - * C function: LPVOID glMapBuffer(GLenum target, GLenum access); - */ -JNIEXPORT jlong JNICALL -Java_net_java_games_jogl_impl_macosx_MacOSXGLImpl_dispatch_1glMapBufferARB(JNIEnv *env, jobject _unused, jint target, jint access, jlong glProcAddress) -{ - PFNGLMAPBUFFERARBPROC ptr_glMapBufferARB; - LPVOID _res; - ptr_glMapBufferARB = (PFNGLMAPBUFFERARBPROC) (intptr_t) glProcAddress; - assert(ptr_glMapBufferARB != NULL); - _res = (* ptr_glMapBufferARB) ((GLenum) target, (GLenum) access); - return (jlong) (intptr_t) _res; -} diff --git a/make/gl-impl-CustomJavaCode.java b/make/gl-impl-CustomJavaCode.java index a4709fde4..5b4a3fa17 100644 --- a/make/gl-impl-CustomJavaCode.java +++ b/make/gl-impl-CustomJavaCode.java @@ -1,3 +1,135 @@ +// Tracks glBegin/glEnd calls to determine whether it is legal to +// query Vertex Buffer Object state +private boolean inBeginEndPair; + +public GLImpl(GLContextImpl context) { + this._context = context; +} + +public boolean isFunctionAvailable(String glFunctionName) { + return _context.isFunctionAvailable(glFunctionName); +} + +public boolean isExtensionAvailable(String glExtensionName) { + return _context.isExtensionAvailable(glExtensionName); +} + +public Object getExtension(String extensionName) { + // At this point we don't expose any extensions using this mechanism + return null; +} + +private GLContextImpl _context; + +/** + * Provides platform-independent access to the wglAllocateMemoryNV / + * glXAllocateMemoryNV extension. + */ +public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return _context.glAllocateMemoryNV(arg0, arg1, arg2, arg3); +} + +public void setSwapInterval(int interval) { + _context.setSwapInterval(interval); +} + +public Object getPlatformGLExtensions() { + return _context.getPlatformGLExtensions(); +} + +private void checkBufferObject(String extension1, + String extension2, + boolean enabled, + int state, + String kind) { + if (inBeginEndPair) { + throw new GLException("May not call this between glBegin and glEnd"); + } + boolean avail = ((extension1 != null && isExtensionAvailable(extension1)) || + (extension2 != null && isExtensionAvailable(extension2))); + if (!avail) { + if (!enabled) + return; + throw new GLException("Required extensions not available to call this function"); + } + int[] val = new int[1]; + glGetIntegerv(state, val, 0); + if (enabled) { + if (val[0] == 0) { + throw new GLException(kind + " must be enabled to call this method"); + } + } else { + if (val[0] != 0) { + throw new GLException(kind + " must be disabled to call this method"); + } + } +} + +private void checkUnpackPBODisabled() { + checkBufferObject("GL_ARB_pixel_buffer_object", + "GL_EXT_pixel_buffer_object", + false, + GL.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, + "unpack pixel_buffer_object"); +} + +private void checkUnpackPBOEnabled() { + checkBufferObject("GL_ARB_pixel_buffer_object", + "GL_EXT_pixel_buffer_object", + true, + GL.GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, + "unpack pixel_buffer_object"); +} + +private void checkPackPBODisabled() { + checkBufferObject("GL_ARB_pixel_buffer_object", + "GL_EXT_pixel_buffer_object", + false, + GL.GL_PIXEL_PACK_BUFFER_BINDING_ARB, + "pack pixel_buffer_object"); +} + +private void checkPackPBOEnabled() { + checkBufferObject("GL_ARB_pixel_buffer_object", + "GL_EXT_pixel_buffer_object", + true, + GL.GL_PIXEL_PACK_BUFFER_BINDING_ARB, + "pack pixel_buffer_object"); +} + + +private void checkArrayVBODisabled() { + checkBufferObject("GL_VERSION_1_5", + "GL_ARB_vertex_buffer_object", + false, + GL.GL_ARRAY_BUFFER_BINDING, + "array vertex_buffer_object"); +} + +private void checkArrayVBOEnabled() { + checkBufferObject("GL_VERSION_1_5", + "GL_ARB_vertex_buffer_object", + true, + GL.GL_ARRAY_BUFFER_BINDING, + "array vertex_buffer_object"); +} + +private void checkElementVBODisabled() { + checkBufferObject("GL_VERSION_1_5", + "GL_ARB_vertex_buffer_object", + false, + GL.GL_ELEMENT_ARRAY_BUFFER_BINDING, + "element vertex_buffer_object"); +} + +private void checkElementVBOEnabled() { + checkBufferObject("GL_VERSION_1_5", + "GL_ARB_vertex_buffer_object", + true, + GL.GL_ELEMENT_ARRAY_BUFFER_BINDING, + "element vertex_buffer_object"); +} + // Attempt to return the same ByteBuffer object from glMapBufferARB if // the vertex buffer object's base address and size haven't changed private static class ARBVBOKey { @@ -32,7 +164,7 @@ public java.nio.ByteBuffer glMapBuffer(int target, int access) { throw new GLException("Method \"glMapBuffer\" not available"); } int[] sz = new int[1]; - glGetBufferParameteriv(target, GL_BUFFER_SIZE_ARB, sz); + glGetBufferParameteriv(target, GL_BUFFER_SIZE_ARB, sz, 0); long addr; addr = dispatch_glMapBuffer(target, access, __addr_); if (addr == 0 || sz[0] == 0) { @@ -55,7 +187,7 @@ public java.nio.ByteBuffer glMapBufferARB(int target, int access) { throw new GLException("Method \"glMapBufferARB\" not available"); } int[] sz = new int[1]; - glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, sz); + glGetBufferParameterivARB(target, GL_BUFFER_SIZE_ARB, sz, 0); long addr; addr = dispatch_glMapBufferARB(target, access, __addr_); if (addr == 0 || sz[0] == 0) { diff --git a/make/gl-impl-macosx.cfg b/make/gl-impl-macosx.cfg deleted file mode 100644 index 5a09750dd..000000000 --- a/make/gl-impl-macosx.cfg +++ /dev/null @@ -1,81 +0,0 @@ -# This .cfg file is used to generate the class which implements the GL -# interface on a particular platform. -Package net.java.games.jogl -Style ImplOnly -JavaClass GL -ImplPackage net.java.games.jogl.impl.macosx -ImplJavaClass MacOSXGLImpl -Include gl-common-macosx.cfg -Include gl-glx-common.cfg - -EmitProcAddressTable true -ProcAddressTableClassName GLProcAddressTable -ContextVariableName _context - -CustomCCode #include <inttypes.h> -CustomCCode #include <stdlib.h> - -CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in -CustomCCode "glext.h" are parsed. */ -CustomCCode #define GL_GLEXT_PROTOTYPES - -CustomCCode /* Include the OpenGL headers */ -CustomCCode #include <GL/gl.h> - -CustomCCode #include </usr/include/machine/types.h> - -CustomCCode /* Provide Windows typedefs */ -CustomCCode typedef void* LPVOID; -CustomCCode typedef unsigned int* PUINT; - -CustomJavaCode MacOSXGLImpl public MacOSXGLImpl(MacOSXGLContext context) -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl this._context = context; -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl /** This constructor should be used manually in order to -CustomJavaCode MacOSXGLImpl create a GL object that can be used with the Cocoa NSOpenGLView. */ -CustomJavaCode MacOSXGLImpl public MacOSXGLImpl() -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl this._context = new MacOSXDummyGLContext(this); -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl public boolean isFunctionAvailable(String glFunctionName) -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl return _context.isFunctionAvailable(glFunctionName); -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl public boolean isExtensionAvailable(String glExtensionName) -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl return _context.isExtensionAvailable(glExtensionName); -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl /** Forces a recomputation of which extensions are available. -CustomJavaCode MacOSXGLImpl Should only be called if this MacOSXGLImpl is being used -CustomJavaCode MacOSXGLImpl in conjunction with an NSOpenGLView instead of a GLCanvas. */ -CustomJavaCode MacOSXGLImpl public void resetGLFunctionAvailability() -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl if (!(_context instanceof MacOSXDummyGLContext)) { -CustomJavaCode MacOSXGLImpl throw new GLException("Should only be called if being used with NSOpenGLView"); -CustomJavaCode MacOSXGLImpl } -CustomJavaCode MacOSXGLImpl ((MacOSXDummyGLContext) _context).resetGLFunctionAvailability(); -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl private MacOSXGLContext _context; - -CustomJavaCode MacOSXGLImpl /** -CustomJavaCode MacOSXGLImpl * Provides platform-independent access to the wglAllocateMemoryNV / -CustomJavaCode MacOSXGLImpl * glXAllocateMemoryNV extension. -CustomJavaCode MacOSXGLImpl */ -CustomJavaCode MacOSXGLImpl public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) -CustomJavaCode MacOSXGLImpl { -CustomJavaCode MacOSXGLImpl // FIXME -CustomJavaCode MacOSXGLImpl throw new GLException("Not yet implemented"); -CustomJavaCode MacOSXGLImpl } - -CustomJavaCode MacOSXGLImpl public void setSwapInterval(int interval) { // FIXME: not implemented yet -CustomJavaCode MacOSXGLImpl _context.setSwapInterval(interval); -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 deleted file mode 100644 index 252425659..000000000 --- a/make/gl-impl-win32.cfg +++ /dev/null @@ -1,70 +0,0 @@ -# This .cfg file is used to generate the class which implements the GL -# interface on a particular platform. -Package net.java.games.jogl -Style ImplOnly -JavaClass GL -ImplPackage net.java.games.jogl.impl.windows -ImplJavaClass WindowsGLImpl -Include gl-common-win32.cfg -Include gl-glx-common.cfg - -EmitProcAddressTable true -ProcAddressTableClassName GLProcAddressTable -ContextVariableName _context - -CustomCCode #define WIN32_LEAN_AND_MEAN -CustomCCode #include <windows.h> -CustomCCode #undef WIN32_LEAN_AND_MEAN -CustomCCode #include <stdlib.h> -CustomCCode #include <stddef.h> -CustomCCode #include <malloc.h> - -CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in -CustomCCode "glext.h" are parsed. */ -CustomCCode #define GL_GLEXT_PROTOTYPES - -CustomCCode /* Define WGL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in -CustomCCode "wglext.h" are parsed. */ -CustomCCode #define WGL_GLEXT_PROTOTYPES - -CustomCCode /* Include the OpenGL headers */ -CustomCCode #include <GL/gl.h> -CustomCCode #include <GL/wglext.h> - -CustomCCode /* This typedef is only needed for VC6 */ -CustomCCode #if _MSC_VER <= 1200 -CustomCCode typedef int intptr_t; -CustomCCode #endif - -CustomJavaCode WindowsGLImpl public WindowsGLImpl(WindowsGLContext context) { -CustomJavaCode WindowsGLImpl this._context = context; -CustomJavaCode WindowsGLImpl } - -CustomJavaCode WindowsGLImpl public boolean isFunctionAvailable(String glFunctionName) -CustomJavaCode WindowsGLImpl { -CustomJavaCode WindowsGLImpl return _context.isFunctionAvailable(glFunctionName); -CustomJavaCode WindowsGLImpl } - -CustomJavaCode WindowsGLImpl public boolean isExtensionAvailable(String glExtensionName) -CustomJavaCode WindowsGLImpl { -CustomJavaCode WindowsGLImpl return _context.isExtensionAvailable(glExtensionName); -CustomJavaCode WindowsGLImpl } - -CustomJavaCode WindowsGLImpl private WindowsGLContext _context; - -CustomJavaCode WindowsGLImpl /** -CustomJavaCode WindowsGLImpl * Provides platform-independent access to the wglAllocateMemoryNV / -CustomJavaCode WindowsGLImpl * glXAllocateMemoryNV extension. -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 } - -CustomJavaCode WindowsGLImpl public void setSwapInterval(int interval) { -CustomJavaCode WindowsGLImpl if (isExtensionAvailable("WGL_EXT_swap_control")) { -CustomJavaCode WindowsGLImpl wglSwapIntervalEXT(interval); -CustomJavaCode WindowsGLImpl } -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 deleted file mode 100644 index b60a28787..000000000 --- a/make/gl-impl-x11.cfg +++ /dev/null @@ -1,67 +0,0 @@ -# This .cfg file is used to generate the class which implements the GL -# interface on a particular platform. -Package net.java.games.jogl -Style ImplOnly -JavaClass GL -ImplPackage net.java.games.jogl.impl.x11 -ImplJavaClass X11GLImpl -Include gl-common-x11.cfg -Include gl-glx-common.cfg - -EmitProcAddressTable true -ProcAddressTableClassName GLProcAddressTable -ContextVariableName _context - -CustomCCode #include <inttypes.h> -CustomCCode #include <stdlib.h> -CustomCCode #include <X11/Xlib.h> - -CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in -CustomCCode "glext.h" are parsed. */ -CustomCCode #define GL_GLEXT_PROTOTYPES - -CustomCCode /* Define GLX_GLXEXT_PROTOTYPES so that the OpenGL extension prototypes in -CustomCCode "glxext.h" are parsed. */ -CustomCCode #define GLX_GLXEXT_PROTOTYPES - -CustomCCode /* Include the OpenGL headers */ -CustomCCode #include <GL/gl.h> -CustomCCode #include <GL/glx.h> -CustomCCode #include <GL/glxext.h> - -CustomCCode /* Provide Windows typedefs */ -CustomCCode typedef void* LPVOID; -CustomCCode typedef unsigned int* PUINT; - -CustomJavaCode X11GLImpl public X11GLImpl(X11GLContext context) { -CustomJavaCode X11GLImpl this._context = context; -CustomJavaCode X11GLImpl } - -CustomJavaCode X11GLImpl public boolean isFunctionAvailable(String glFunctionName) -CustomJavaCode X11GLImpl { -CustomJavaCode X11GLImpl return _context.isFunctionAvailable(glFunctionName); -CustomJavaCode X11GLImpl } - -CustomJavaCode X11GLImpl public boolean isExtensionAvailable(String glExtensionName) -CustomJavaCode X11GLImpl { -CustomJavaCode X11GLImpl return _context.isExtensionAvailable(glExtensionName); -CustomJavaCode X11GLImpl } - -CustomJavaCode X11GLImpl private X11GLContext _context; - -CustomJavaCode X11GLImpl /** -CustomJavaCode X11GLImpl * Provides platform-independent access to the wglAllocateMemoryNV / -CustomJavaCode X11GLImpl * glXAllocateMemoryNV extension. -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 } - -CustomJavaCode X11GLImpl public void setSwapInterval(int interval) { -CustomJavaCode X11GLImpl if (isExtensionAvailable("GLX_SGI_swap_control")) { -CustomJavaCode X11GLImpl glXSwapIntervalSGI(interval); -CustomJavaCode X11GLImpl } -CustomJavaCode X11GLImpl } - -IncludeAs CustomJavaCode X11GLImpl gl-impl-CustomJavaCode.java -IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/gl-macosx.cfg b/make/gl-macosx.cfg index a22b13477..156f66b77 100644 --- a/make/gl-macosx.cfg +++ b/make/gl-macosx.cfg @@ -1,10 +1,30 @@ -# This .cfg file is used to generate the GL interface. -Package net.java.games.jogl -Style InterfaceOnly +# This .cfg file is used to generate the GL interface and implementing class. +Package javax.media.opengl +Style InterfaceAndImpl JavaClass GL -Extends GL WGL -Extends GL GLX -Extends GL CGL +ImplPackage com.sun.opengl.impl +ImplJavaClass GLImpl Include gl-common-macosx.cfg -EmitProcAddressTable false +EmitProcAddressTable true +ProcAddressTableClassName GLProcAddressTable +ContextVariableName _context + +CustomCCode #include <inttypes.h> +CustomCCode #include <stdlib.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> + +CustomCCode #include </usr/include/machine/types.h> + +CustomCCode /* Provide Windows typedefs */ +CustomCCode typedef void* LPVOID; +CustomCCode typedef unsigned int* PUINT; + +IncludeAs CustomJavaCode GLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/gl-wgl-win32.cfg b/make/gl-wgl-win32.cfg deleted file mode 100644 index fb5f9556e..000000000 --- a/make/gl-wgl-win32.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# This .cfg file is used to generate the interface which contains the -# window system-specific extensions which are exposed (via -# inheritance) to the GL interface. -Package net.java.games.jogl -Style InterfaceOnly -JavaClass WGL -Include gl-common-win32.cfg - -# Ignore everything that doesn't start with wgl or WGL -Ignore ^[^wW].+ diff --git a/make/gl-win32.cfg b/make/gl-win32.cfg index 83cb3e3bd..950d67320 100644 --- a/make/gl-win32.cfg +++ b/make/gl-win32.cfg @@ -1,10 +1,33 @@ -# This .cfg file is used to generate the GL interface. -Package net.java.games.jogl -Style InterfaceOnly +# This .cfg file is used to generate the GL interface and implementing class. +Package javax.media.opengl +Style InterfaceAndImpl JavaClass GL -Extends GL WGL -Extends GL GLX -Extends GL CGL +ImplPackage com.sun.opengl.impl +ImplJavaClass GLImpl Include gl-common-win32.cfg -EmitProcAddressTable false +EmitProcAddressTable true +ProcAddressTableClassName GLProcAddressTable +ContextVariableName _context + +CustomCCode #define WIN32_LEAN_AND_MEAN +CustomCCode #include <windows.h> +CustomCCode #undef WIN32_LEAN_AND_MEAN +CustomCCode #include <stdlib.h> +CustomCCode #include <stddef.h> +CustomCCode #include <malloc.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> + +CustomCCode /* This typedef is only needed for VC6 */ +CustomCCode #if _MSC_VER <= 1200 +CustomCCode typedef int intptr_t; +CustomCCode #endif + +IncludeAs CustomJavaCode GLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/gl-x11.cfg b/make/gl-x11.cfg index e20deed55..fd793c5b9 100644 --- a/make/gl-x11.cfg +++ b/make/gl-x11.cfg @@ -1,11 +1,35 @@ -# This .cfg file is used to generate the class which implements the GL -# interface on a particular platform. -Package net.java.games.jogl -Style InterfaceOnly +# This .cfg file is used to generate the GL interface and implementing class. +Package javax.media.opengl +Style InterfaceAndImpl JavaClass GL -Extends GL WGL -Extends GL GLX -Extends GL CGL +ImplPackage com.sun.opengl.impl +ImplJavaClass GLImpl Include gl-common-x11.cfg -EmitProcAddressTable false
\ No newline at end of file +EmitProcAddressTable true +ProcAddressTableClassName GLProcAddressTable +ContextVariableName _context + +CustomCCode #include <inttypes.h> +CustomCCode #include <stdlib.h> +CustomCCode #include <X11/Xlib.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Define GLX_GLXEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glxext.h" are parsed. */ +CustomCCode #define GLX_GLXEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> +CustomCCode #include <GL/glx.h> +CustomCCode #include <GL/glxext.h> + +CustomCCode /* Provide Windows typedefs */ +CustomCCode typedef void* LPVOID; +CustomCCode typedef unsigned int* PUINT; + +IncludeAs CustomJavaCode GLImpl gl-impl-CustomJavaCode.java +IncludeAs CustomCCode gl-impl-CustomCCode.c diff --git a/make/glu-CustomJavaCode.java b/make/glu-CustomJavaCode.java new file mode 100644 index 000000000..be919da1e --- /dev/null +++ b/make/glu-CustomJavaCode.java @@ -0,0 +1,1457 @@ +private static boolean useJavaMipmapCode = true; + +static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val = System.getProperty("jogl.glu.nojava"); + if (val != null && !val.toLowerCase().equals("false")) { + useJavaMipmapCode = false; + } + return null; + } + }); +} + +/** + * Instantiates a new OpenGL Utility Library object. A GLU object may + * be instantiated at any point in the application and is not + * inherently tied to any particular OpenGL context; however, the GLU + * object may only be used when an OpenGL context is current on the + * current thread. Attempts to call most of the methods in the GLU + * library when no OpenGL context is current will cause an exception + * to be thrown. + * + * <P> + * + * The returned GLU object is not guaranteed to be thread-safe and + * should only be used from one thread at a time. Multiple GLU objects + * may be instantiated to be used from different threads + * simultaneously. + */ + +public GLU() +{ + this.project = new Project(); +} + +//---------------------------------------------------------------------- +// Utility routines +// + +/** + * Returns the GL object associated with the OpenGL context current on + * the current thread. Throws GLException if no OpenGL context is + * current. + */ + +public static GL getCurrentGL() throws GLException { + GLContext curContext = GLContext.getCurrent(); + if (curContext == null) { + throw new GLException("No OpenGL context current on this thread"); + } + return curContext.getGL(); +} + +public String gluErrorString(int errorCode) { + return Error.gluErrorString(errorCode); +} + +/* extName is an extension name. + * extString is a string of extensions separated by blank(s). There may or + * may not be leading or trailing blank(s) in extString. + * This works in cases of extensions being prefixes of another like + * GL_EXT_texture and GL_EXT_texture3D. + * Returns true if extName is found otherwise it returns false. + */ +public boolean gluCheckExtension(java.lang.String extName, java.lang.String extString) { + return Registry.gluCheckExtension(extName, extString); +} + +public String gluGetString(int name) { + return Registry.gluGetString(name); +} + +/** + * Returns true if the specified GLU core- or extension-function can be + * successfully used through this GLU instance. By "successfully" we mean + * that the function is both <i>callable</i> on the machine running the + * program and <i>available</i> on the current display.<P> + * + * A GLU function is <i>callable</i> if it is a GLU core- or extension-function + * that is supported by the underlying GLU implementation. The function is + * <i>available</i> if the OpenGL implementation on the display meets the + * requirements of the GLU function being called (because GLU functions utilize + * OpenGL functions). <P> + * + * Whether or not a GLU function is <i>callable</i> is determined as follows: + * <ul> + * <li>If the function is a GLU core function (i.e., not an + * extension), <code>gluGetString(GLU_VERSION)</code> is used to determine the + * version number of the underlying GLU implementation on the host. + * then the function name is cross-referenced with that specification to + * see if it is part of that version's specification. + * + * <li> If the function is a GLU extension, the function name is + * cross-referenced with the list returned by + * <code>gluGetString(GLU_EXTENSIONS)</code> to see if the function is one of + * the extensions that is supported by the underlying GLU implementation. + * </ul> + * + * Whether or not a GLU function is <i>available</i> is determined as follows: + * <ul> + * <li>If the function is a GLU core function then the function is first + * cross-referenced with the GLU specifications to find the minimum GLU + * version required to <i>call</i> that GLU function. Then the following table + * is consulted to determine the minimum GL version required for that version + * of GLU: + * <ul> + * <li> GLU 1.0 requires OpenGL 1.0 + * <li> GLU 1.1 requires OpenGL 1.0 + * <li> GLU 1.2 requires OpenGL 1.1 + * <li> GLU 1.3 requires OpenGL 1.2 + * </ul> + * Finally, <code>glGetString(GL_VERSION)</code> is used to determine the + * highest OpenGL version that both host and display support, and from that it + * is possible to determine if the GL facilities required by the GLU function + * are <i>available</i> on the display. + * + * <li> If the function is a GLU extension, the function name is + * cross-referenced with the list returned by + * <code>gluGetString(GLU_EXTENSIONS)</code> to see if the function is one of + * the extensions that is supported by the underlying GLU implementation. + * </ul> + * + * <b>NOTE:</b>The availability of a function may change at runtime in + * response to changes in the display environment. For example, when a window + * is dragged from one display to another on a multi-display system, or when + * the properties of the display device are modified (e.g., changing the color + * depth of the display). Any application that is concerned with handling + * these situations correctly should confirm availability after a display + * change before calling a questionable OpenGL function. To detect a change in + * the display device, please see {@link + * GLEventListener#displayChanged(GLAutoDrawable,boolean,boolean)}. + * + * @param gluFunctionName the name of the OpenGL function (e.g., use + * "gluNurbsCallbackDataEXT" to check if the <code> + * gluNurbsCallbackDataEXT(GLUnurbs, GLvoid)</code> extension is available). + */ +public boolean isFunctionAvailable(String gluFunctionName) +{ + if (useJavaMipmapCode) { + // All GLU functions are available in Java port + return true; + } + return (gluProcAddressTable.getAddressFor(gluFunctionName) != 0); +} + +//---------------------------------------------------------------------- +// Tessellation routines +// + +/***************************************************************************** + * <b>gluNewTess</b> creates and returns a new tessellation object. This + * object must be referred to when calling tesselation methods. A return + * value of null means that there was not enough memeory to allocate the + * object. + * + * @return A new tessellation object. + * + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluDeleteTess gluDeleteTess + * @see #gluTessCallback gluTessCallback + ****************************************************************************/ +public GLUtessellator gluNewTess() { + return GLUtessellatorImpl.gluNewTess(); +} + +/***************************************************************************** + * <b>gluDeleteTess</b> destroys the indicated tessellation object (which was + * created with {@link #gluNewTess gluNewTess}). + * + * @param tessellator + * Specifies the tessellation object to destroy. + * + * @see #gluBeginPolygon gluBeginPolygon + * @see #gluNewTess gluNewTess + * @see #gluTessCallback gluTessCallback + ****************************************************************************/ +public void gluDeleteTess(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluDeleteTess(); +} + +/***************************************************************************** + * <b>gluTessProperty</b> is used to control properites stored in a + * tessellation object. These properties affect the way that the polygons are + * interpreted and rendered. The legal value for <i>which</i> are as + * follows:<P> + * + * <b>GLU_TESS_WINDING_RULE</b> + * <UL> + * Determines which parts of the polygon are on the "interior". + * <em>value</em> may be set to one of + * <BR><b>GLU_TESS_WINDING_ODD</b>, + * <BR><b>GLU_TESS_WINDING_NONZERO</b>, + * <BR><b>GLU_TESS_WINDING_POSITIVE</b>, or + * <BR><b>GLU_TESS_WINDING_NEGATIVE</b>, or + * <BR><b>GLU_TESS_WINDING_ABS_GEQ_TWO</b>.<P> + * + * To understand how the winding rule works, consider that the input + * contours partition the plane into regions. The winding rule determines + * which of these regions are inside the polygon.<P> + * + * For a single contour C, the winding number of a point x is simply the + * signed number of revolutions we make around x as we travel once around C + * (where CCW is positive). When there are several contours, the individual + * winding numbers are summed. This procedure associates a signed integer + * value with each point x in the plane. Note that the winding number is + * the same for all points in a single region.<P> + * + * The winding rule classifies a region as "inside" if its winding number + * belongs to the chosen category (odd, nonzero, positive, negative, or + * absolute value of at least two). The previous GLU tessellator (prior to + * GLU 1.2) used the "odd" rule. The "nonzero" rule is another common way + * to define the interior. The other three rules are useful for polygon CSG + * operations. + * </UL> + * <BR><b>GLU_TESS_BOUNDARY_ONLY</b> + * <UL> + * Is a boolean value ("value" should be set to GL_TRUE or GL_FALSE). When + * set to GL_TRUE, a set of closed contours separating the polygon interior + * and exterior are returned instead of a tessellation. Exterior contours + * are oriented CCW with respect to the normal; interior contours are + * oriented CW. The <b>GLU_TESS_BEGIN</b> and <b>GLU_TESS_BEGIN_DATA</b> + * callbacks use the type GL_LINE_LOOP for each contour. + * </UL> + * <BR><b>GLU_TESS_TOLERANCE</b> + * <UL> + * Specifies a tolerance for merging features to reduce the size of the + * output. For example, two vertices that are very close to each other + * might be replaced by a single vertex. The tolerance is multiplied by the + * largest coordinate magnitude of any input vertex; this specifies the + * maximum distance that any feature can move as the result of a single + * merge operation. If a single feature takes part in several merge + * operations, the toal distance moved could be larger.<P> + * + * Feature merging is completely optional; the tolerance is only a hint. + * The implementation is free to merge in some cases and not in others, or + * to never merge features at all. The initial tolerance is 0.<P> + * + * The current implementation merges vertices only if they are exactly + * coincident, regardless of the current tolerance. A vertex is spliced + * into an edge only if the implementation is unable to distinguish which + * side of the edge the vertex lies on. Two edges are merged only when both + * endpoints are identical. + * </UL> + * + * @param tessellator + * Specifies the tessellation object created with + * {@link #gluNewTess gluNewTess} + * @param which + * Specifies the property to be set. Valid values are + * <b>GLU_TESS_WINDING_RULE</b>, <b>GLU_TESS_BOUNDARDY_ONLY</b>, + * <b>GLU_TESS_TOLERANCE</b>. + * @param value + * Specifices the value of the indicated property. + * + * @see #gluGetTessProperty gluGetTessProperty + * @see #gluNewTess gluNewTess + ****************************************************************************/ +public void gluTessProperty(GLUtessellator tessellator, int which, double value) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessProperty(which, value); +} + +/***************************************************************************** + * <b>gluGetTessProperty</b> retrieves properties stored in a tessellation + * object. These properties affect the way that tessellation objects are + * interpreted and rendered. See the + * {@link #gluTessProperty gluTessProperty} reference + * page for information about the properties and what they do. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * @param which + * Specifies the property whose value is to be fetched. Valid values + * are <b>GLU_TESS_WINDING_RULE</b>, <b>GLU_TESS_BOUNDARY_ONLY</b>, + * and <b>GLU_TESS_TOLERANCES</b>. + * @param value + * Specifices an array into which the value of the named property is + * written. + * + * @see #gluNewTess gluNewTess + * @see #gluTessProperty gluTessProperty + ****************************************************************************/ +public void gluGetTessProperty(GLUtessellator tessellator, int which, double[] value, int value_offset) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluGetTessProperty(which, value, value_offset); +} + +/***************************************************************************** + * <b>gluTessNormal</b> describes a normal for a polygon that the program is + * defining. All input data will be projected onto a plane perpendicular to + * the one of the three coordinate axes before tessellation and all output + * triangles will be oriented CCW with repsect to the normal (CW orientation + * can be obtained by reversing the sign of the supplied normal). For + * example, if you know that all polygons lie in the x-y plane, call + * <b>gluTessNormal</b>(tess, 0.0, 0.0, 0.0) before rendering any polygons.<P> + * + * If the supplied normal is (0.0, 0.0, 0.0)(the initial value), the normal + * is determined as follows. The direction of the normal, up to its sign, is + * found by fitting a plane to the vertices, without regard to how the + * vertices are connected. It is expected that the input data lies + * approximately in the plane; otherwise, projection perpendicular to one of + * the three coordinate axes may substantially change the geometry. The sign + * of the normal is chosen so that the sum of the signed areas of all input + * contours is nonnegative (where a CCW contour has positive area).<P> + * + * The supplied normal persists until it is changed by another call to + * <b>gluTessNormal</b>. + * + * @param tessellator + * Specifies the tessellation object (created by + * {@link #gluNewTess gluNewTess}). + * @param x + * Specifies the first component of the normal. + * @param y + * Specifies the second component of the normal. + * @param z + * Specifies the third component of the normal. + * + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessEndPolygon gluTessEndPolygon + ****************************************************************************/ +public void gluTessNormal(GLUtessellator tessellator, double x, double y, double z) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessNormal(x, y, z); +} + +/***************************************************************************** + * <b>gluTessCallback</b> is used to indicate a callback to be used by a + * tessellation object. If the specified callback is already defined, then it + * is replaced. If <i>aCallback</i> is null, then the existing callback + * becomes undefined.<P> + * + * These callbacks are used by the tessellation object to describe how a + * polygon specified by the user is broken into triangles. Note that there are + * two versions of each callback: one with user-specified polygon data and one + * without. If both versions of a particular callback are specified, then the + * callback with user-specified polygon data will be used. Note that the + * polygonData parameter used by some of the methods is a copy of the + * reference that was specified when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The legal callbacks are as follows:<P> + * + * <b>GLU_TESS_BEGIN</b> + * <UL> + * The begin callback is invoked like {@link javax.media.opengl.GL#glBegin + * glBegin} to indicate the start of a (triangle) primitive. The method + * takes a single argument of type int. If the + * <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_FALSE</b>, then + * the argument is set to either <b>GL_TRIANGLE_FAN</b>, + * <b>GL_TRIANGLE_STRIP</b>, or <b>GL_TRIANGLES</b>. If the + * <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_TRUE</b>, then the + * argument will be set to <b>GL_LINE_LOOP</b>. The method prototype for + * this callback is: + * </UL> + * + * <PRE> + * void begin(int type);</PRE><P> + * + * <b>GLU_TESS_BEGIN_DATA</b> + * <UL> + * The same as the <b>GLU_TESS_BEGIN</b> callback except + * that it takes an additional reference argument. This reference is + * identical to the opaque reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void beginData(int type, Object polygonData);</PRE> + * + * <b>GLU_TESS_EDGE_FLAG</b> + * <UL> + * The edge flag callback is similar to + * {@link javax.media.opengl.GL#glEdgeFlag glEdgeFlag}. The method takes + * a single boolean boundaryEdge that indicates which edges lie on the + * polygon boundary. If the boundaryEdge is <b>GL_TRUE</b>, then each vertex + * that follows begins an edge that lies on the polygon boundary, that is, + * an edge that separates an interior region from an exterior one. If the + * boundaryEdge is <b>GL_FALSE</b>, then each vertex that follows begins an + * edge that lies in the polygon interior. The edge flag callback (if + * defined) is invoked before the first vertex callback.<P> + * + * Since triangle fans and triangle strips do not support edge flags, the + * begin callback is not called with <b>GL_TRIANGLE_FAN</b> or + * <b>GL_TRIANGLE_STRIP</b> if a non-null edge flag callback is provided. + * (If the callback is initialized to null, there is no impact on + * performance). Instead, the fans and strips are converted to independent + * triangles. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void edgeFlag(boolean boundaryEdge);</PRE> + * + * <b>GLU_TESS_EDGE_FLAG_DATA</b> + * <UL> + * The same as the <b>GLU_TESS_EDGE_FLAG</b> callback except that it takes + * an additional reference argument. This reference is identical to the + * opaque reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void edgeFlagData(boolean boundaryEdge, Object polygonData);</PRE> + * + * <b>GLU_TESS_VERTEX</b> + * <UL> + * The vertex callback is invoked between the begin and end callbacks. It is + * similar to {@link javax.media.opengl.GL#glVertex3f glVertex3f}, and it + * defines the vertices of the triangles created by the tessellation + * process. The method takes a reference as its only argument. This + * reference is identical to the opaque reference provided by the user when + * the vertex was described (see + * {@link #gluTessVertex gluTessVertex}). The method + * prototype for this callback is: + * </UL> + * + * <PRE> + * void vertex(Object vertexData);</PRE> + * + * <b>GLU_TESS_VERTEX_DATA</b> + * <UL> + * The same as the <b>GLU_TESS_VERTEX</b> callback except that it takes an + * additional reference argument. This reference is identical to the opaque + * reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void vertexData(Object vertexData, Object polygonData);</PRE> + * + * <b>GLU_TESS_END</b> + * <UL> + * The end callback serves the same purpose as + * {@link javax.media.opengl.GL#glEnd glEnd}. It indicates the end of a + * primitive and it takes no arguments. The method prototype for this + * callback is: + * </UL> + * + * <PRE> + * void end();</PRE> + * + * <b>GLU_TESS_END_DATA</b> + * <UL> + * The same as the <b>GLU_TESS_END</b> callback except that it takes an + * additional reference argument. This reference is identical to the opaque + * reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void endData(Object polygonData);</PRE> + * + * <b>GLU_TESS_COMBINE</b> + * <UL> + * The combine callback is called to create a new vertex when the + * tessellation detects an intersection, or wishes to merge features. The + * method takes four arguments: an array of three elements each of type + * double, an array of four references, an array of four elements each of + * type float, and a reference to a reference. The prototype is: + * </UL> + * + * <PRE> + * void combine(double[] coords, Object[] data, + * float[] weight, Object[] outData);</PRE> + * + * <UL> + * The vertex is defined as a linear combination of up to four existing + * vertices, stored in <i>data</i>. The coefficients of the linear + * combination are given by <i>weight</i>; these weights always add up to 1. + * All vertex pointers are valid even when some of the weights are 0. + * <i>coords</i> gives the location of the new vertex.<P> + * + * The user must allocate another vertex, interpolate parameters using + * <i>data</i> and <i>weight</i>, and return the new vertex pointer + * in <i>outData</i>. This handle is supplied during rendering callbacks. + * The user is responsible for freeing the memory some time after + * {@link #gluTessEndPolygon gluTessEndPolygon} is + * called.<P> + * + * For example, if the polygon lies in an arbitrary plane in 3-space, and a + * color is associated with each vertex, the <b>GLU_TESS_COMBINE</b> + * callback might look like this: + * </UL> + * <PRE> + * void myCombine(double[] coords, Object[] data, + * float[] weight, Object[] outData) + * { + * MyVertex newVertex = new MyVertex(); + * + * newVertex.x = coords[0]; + * newVertex.y = coords[1]; + * newVertex.z = coords[2]; + * newVertex.r = weight[0]*data[0].r + + * weight[1]*data[1].r + + * weight[2]*data[2].r + + * weight[3]*data[3].r; + * newVertex.g = weight[0]*data[0].g + + * weight[1]*data[1].g + + * weight[2]*data[2].g + + * weight[3]*data[3].g; + * newVertex.b = weight[0]*data[0].b + + * weight[1]*data[1].b + + * weight[2]*data[2].b + + * weight[3]*data[3].b; + * newVertex.a = weight[0]*data[0].a + + * weight[1]*data[1].a + + * weight[2]*data[2].a + + * weight[3]*data[3].a; + * outData = newVertex; + * }</PRE> + * + * <UL> + * If the tessellation detects an intersection, then the + * <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback (see + * below) must be defined, and it must write a non-null reference into + * <i>outData</i>. Otherwise the <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> error + * occurs, and no output is generated. + * </UL> + * + * <b>GLU_TESS_COMBINE_DATA</b> + * <UL> + * The same as the <b>GLU_TESS_COMBINE</b> callback except that it takes an + * additional reference argument. This reference is identical to the opaque + * reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void combineData(double[] coords, Object[] data, + float[] weight, Object[] outData, + Object polygonData);</PRE> + * + * <b>GLU_TESS_ERROR</b> + * <UL> + * The error callback is called when an error is encountered. The one + * argument is of type int; it indicates the specific error that occurred + * and will be set to one of <b>GLU_TESS_MISSING_BEGIN_POLYGON</b>, + * <b>GLU_TESS_MISSING_END_POLYGON</b>, + * <b>GLU_TESS_MISSING_BEGIN_CONTOUR</b>, + * <b>GLU_TESS_MISSING_END_CONTOUR</b>, <b>GLU_TESS_COORD_TOO_LARGE</b>, + * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> or <b>GLU_OUT_OF_MEMORY</b>. + * Character strings describing these errors can be retrieved with the + * {@link #gluErrorString gluErrorString} call. The + * method prototype for this callback is: + * </UL> + * + * <PRE> + * void error(int errnum);</PRE> + * + * <UL> + * The GLU library will recover from the first four errors by inserting the + * missing call(s). <b>GLU_TESS_COORD_TOO_LARGE</b> indicates that some + * vertex coordinate exceeded the predefined constant + * <b>GLU_TESS_MAX_COORD</b> in absolute value, and that the value has been + * clamped. (Coordinate values must be small enough so that two can be + * multiplied together without overflow.) + * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> indicates that the tessellation + * detected an intersection between two edges in the input data, and the + * <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback was not + * provided. No output is generated. <b>GLU_OUT_OF_MEMORY</b> indicates that + * there is not enough memory so no output is generated. + * </UL> + * + * <b>GLU_TESS_ERROR_DATA</b> + * <UL> + * The same as the GLU_TESS_ERROR callback except that it takes an + * additional reference argument. This reference is identical to the opaque + * reference provided when + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * was called. The method prototype for this callback is: + * </UL> + * + * <PRE> + * void errorData(int errnum, Object polygonData);</PRE> + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * @param which + * Specifies the callback being defined. The following values are + * valid: <b>GLU_TESS_BEGIN</b>, <b>GLU_TESS_BEGIN_DATA</b>, + * <b>GLU_TESS_EDGE_FLAG</b>, <b>GLU_TESS_EDGE_FLAG_DATA</b>, + * <b>GLU_TESS_VERTEX</b>, <b>GLU_TESS_VERTEX_DATA</b>, + * <b>GLU_TESS_END</b>, <b>GLU_TESS_END_DATA</b>, + * <b>GLU_TESS_COMBINE</b>, <b>GLU_TESS_COMBINE_DATA</b>, + * <b>GLU_TESS_ERROR</b>, and <b>GLU_TESS_ERROR_DATA</b>. + * @param aCallback + * Specifies the callback object to be called. + * + * @see javax.media.opengl.GL#glBegin glBegin + * @see javax.media.opengl.GL#glEdgeFlag glEdgeFlag + * @see javax.media.opengl.GL#glVertex3f glVertex3f + * @see #gluNewTess gluNewTess + * @see #gluErrorString gluErrorString + * @see #gluTessVertex gluTessVertex + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessBeginContour gluTessBeginContour + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + ****************************************************************************/ +public void gluTessCallback(GLUtessellator tessellator, int which, GLUtessellatorCallback aCallback) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessCallback(which, aCallback); +} + +/***************************************************************************** + * <b>gluTessVertex</b> describes a vertex on a polygon that the program + * defines. Successive <b>gluTessVertex</b> calls describe a closed contour. + * For example, to describe a quadrilateral <b>gluTessVertex</b> should be + * called four times. <b>gluTessVertex</b> can only be called between + * {@link #gluTessBeginContour gluTessBeginContour} and + * {@link #gluTessBeginContour gluTessEndContour}.<P> + * + * <b>data</b> normally references to a structure containing the vertex + * location, as well as other per-vertex attributes such as color and normal. + * This reference is passed back to the user through the + * <b>GLU_TESS_VERTEX</b> or <b>GLU_TESS_VERTEX_DATA</b> callback after + * tessellation (see the {@link #gluTessCallback + * gluTessCallback} reference page). + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * @param coords + * Specifies the coordinates of the vertex. + * @param data + * Specifies an opaque reference passed back to the program with the + * vertex callback (as specified by + * {@link #gluTessCallback gluTessCallback}). + * + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluNewTess gluNewTess + * @see #gluTessBeginContour gluTessBeginContour + * @see #gluTessCallback gluTessCallback + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + * @see #gluTessEndPolygon gluTessEndPolygon + ****************************************************************************/ +public void gluTessVertex(GLUtessellator tessellator, double[] coords, int coords_offset, Object data) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessVertex(coords, coords_offset, data); +} + +/***************************************************************************** + * <b>gluTessBeginPolygon</b> and + * {@link #gluTessEndPolygon gluTessEndPolygon} delimit + * the definition of a convex, concave or self-intersecting polygon. Within + * each <b>gluTessBeginPolygon</b>/ + * {@link #gluTessEndPolygon gluTessEndPolygon} pair, + * there must be one or more calls to + * {@link #gluTessBeginContour gluTessBeginContour}/ + * {@link #gluTessEndContour gluTessEndContour}. Within + * each contour, there are zero or more calls to + * {@link #gluTessVertex gluTessVertex}. The vertices + * specify a closed contour (the last vertex of each contour is automatically + * linked to the first). See the {@link #gluTessVertex + * gluTessVertex}, {@link #gluTessBeginContour + * gluTessBeginContour}, and {@link #gluTessEndContour + * gluTessEndContour} reference pages for more details.<P> + * + * <b>data</b> is a reference to a user-defined data structure. If the + * appropriate callback(s) are specified (see + * {@link #gluTessCallback gluTessCallback}), then this + * reference is returned to the callback method(s). Thus, it is a convenient + * way to store per-polygon information.<P> + * + * Once {@link #gluTessEndPolygon gluTessEndPolygon} is + * called, the polygon is tessellated, and the resulting triangles are + * described through callbacks. See + * {@link #gluTessCallback gluTessCallback} for + * descriptions of the callback methods. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * @param data + * Specifies a reference to user polygon data. + * + * @see #gluNewTess gluNewTess + * @see #gluTessBeginContour gluTessBeginContour + * @see #gluTessVertex gluTessVertex + * @see #gluTessCallback gluTessCallback + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + * @see #gluTessEndPolygon gluTessEndPolygon + ****************************************************************************/ +public void gluTessBeginPolygon(GLUtessellator tessellator, Object data) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessBeginPolygon(data); +} + +/***************************************************************************** + * <b>gluTessBeginContour</b> and + * {@link #gluTessEndContour gluTessEndContour} delimit + * the definition of a polygon contour. Within each + * <b>gluTessBeginContour</b>/ + * {@link #gluTessEndContour gluTessEndContour} pair, + * there can be zero or more calls to + * {@link #gluTessVertex gluTessVertex}. The vertices + * specify a closed contour (the last vertex of each contour is automatically + * linked to the first). See the {@link #gluTessVertex + * gluTessVertex} reference page for more details. <b>gluTessBeginContour</b> + * can only be called between + * {@link #gluTessBeginPolygon gluTessBeginPolygon} and + * {@link #gluTessEndPolygon gluTessEndPolygon}. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * + * @see #gluNewTess gluNewTess + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessVertex gluTessVertex + * @see #gluTessCallback gluTessCallback + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + * @see #gluTessEndPolygon gluTessEndPolygon + ****************************************************************************/ +public void gluTessBeginContour(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessBeginContour(); +} + +/***************************************************************************** + * <b>gluTessEndContour</b> and + * {@link #gluTessBeginContour gluTessBeginContour} + * delimit the definition of a polygon contour. Within each + * {@link #gluTessBeginContour gluTessBeginContour}/ + * <b>gluTessEndContour</b> pair, there can be zero or more calls to + * {@link #gluTessVertex gluTessVertex}. The vertices + * specify a closed contour (the last vertex of each contour is automatically + * linked to the first). See the {@link #gluTessVertex + * gluTessVertex} reference page for more details. + * {@link #gluTessBeginContour gluTessBeginContour} can + * only be called between {@link #gluTessBeginPolygon + * gluTessBeginPolygon} and + * {@link #gluTessEndPolygon gluTessEndPolygon}. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * + * @see #gluNewTess gluNewTess + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessVertex gluTessVertex + * @see #gluTessCallback gluTessCallback + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + * @see #gluTessEndPolygon gluTessEndPolygon + ****************************************************************************/ +public void gluTessEndContour(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessEndContour(); +} + +/***************************************************************************** + * <b>gluTessEndPolygon</b> and + * {@link #gluTessBeginPolygon gluTessBeginPolygon} + * delimit the definition of a convex, concave or self-intersecting polygon. + * Within each {@link #gluTessBeginPolygon + * gluTessBeginPolygon}/<b>gluTessEndPolygon</b> pair, there must be one or + * more calls to {@link #gluTessBeginContour + * gluTessBeginContour}/{@link #gluTessEndContour + * gluTessEndContour}. Within each contour, there are zero or more calls to + * {@link #gluTessVertex gluTessVertex}. The vertices + * specify a closed contour (the last vertex of each contour is automatically + * linked to the first). See the {@link #gluTessVertex + * gluTessVertex}, {@link #gluTessBeginContour + * gluTessBeginContour} and {@link #gluTessEndContour + * gluTessEndContour} reference pages for more details.<P> + * + * Once <b>gluTessEndPolygon</b> is called, the polygon is tessellated, and + * the resulting triangles are described through callbacks. See + * {@link #gluTessCallback gluTessCallback} for + * descriptions of the callback functions. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * + * @see #gluNewTess gluNewTess + * @see #gluTessBeginContour gluTessBeginContour + * @see #gluTessVertex gluTessVertex + * @see #gluTessCallback gluTessCallback + * @see #gluTessProperty gluTessProperty + * @see #gluTessNormal gluTessNormal + * @see #gluTessBeginPolygon gluTessBeginPolygon + ****************************************************************************/ +public void gluTessEndPolygon(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluTessEndPolygon(); +} + +/***************************************************************************** + + * <b>gluBeginPolygon</b> and {@link #gluEndPolygon gluEndPolygon} + * delimit the definition of a nonconvex polygon. To define such a + * polygon, first call <b>gluBeginPolygon</b>. Then define the + * contours of the polygon by calling {@link #gluTessVertex + * gluTessVertex} for each vertex and {@link #gluNextContour + * gluNextContour} to start each new contour. Finally, call {@link + * #gluEndPolygon gluEndPolygon} to signal the end of the + * definition. See the {@link #gluTessVertex gluTessVertex} and {@link + * #gluNextContour gluNextContour} reference pages for more + * details.<P> + + * + * Once {@link #gluEndPolygon gluEndPolygon} is called, + * the polygon is tessellated, and the resulting triangles are described + * through callbacks. See {@link #gluTessCallback + * gluTessCallback} for descriptions of the callback methods. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * + * @see #gluNewTess gluNewTess + * @see #gluNextContour gluNextContour + * @see #gluTessCallback gluTessCallback + * @see #gluTessVertex gluTessVertex + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessBeginContour gluTessBeginContour + ****************************************************************************/ +public void gluBeginPolygon(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluBeginPolygon(); +} + +/***************************************************************************** + * <b>gluNextContour</b> is used to describe polygons with multiple + * contours. After you describe the first contour through a series of + * {@link #gluTessVertex gluTessVertex} calls, a + * <b>gluNextContour</b> call indicates that the previous contour is complete + * and that the next contour is about to begin. Perform another series of + * {@link #gluTessVertex gluTessVertex} calls to + * describe the new contour. Repeat this process until all contours have been + * described.<P> + * + * The type parameter defines what type of contour follows. The following + * values are valid. <P> + * + * <b>GLU_EXTERIOR</b> + * <UL> + * An exterior contour defines an exterior boundary of the polygon. + * </UL> + * <b>GLU_INTERIOR</b> + * <UL> + * An interior contour defines an interior boundary of the polygon (such as + * a hole). + * </UL> + * <b>GLU_UNKNOWN</b> + * <UL> + * An unknown contour is analyzed by the library to determine whether it is + * interior or exterior. + * </UL> + * <b>GLU_CCW, GLU_CW</b> + * <UL> + * The first <b>GLU_CCW</b> or <b>GLU_CW</b> contour defined is considered + * to be exterior. All other contours are considered to be exterior if they + * are oriented in the same direction (clockwise or counterclockwise) as the + * first contour, and interior if they are not. If one contour is of type + * <b>GLU_CCW</b> or <b>GLU_CW</b>, then all contours must be of the same + * type (if they are not, then all <b>GLU_CCW</b> and <b>GLU_CW</b> contours + * will be changed to <b>GLU_UNKNOWN</b>). Note that there is no + * real difference between the <b>GLU_CCW</b> and <b>GLU_CW</b> contour + * types. + * </UL><P> + * + * To define the type of the first contour, you can call <b>gluNextContour</b> + * before describing the first contour. If you do not call + * <b>gluNextContour</b> before the first contour, the first contour is marked + * <b>GLU_EXTERIOR</b>.<P> + * + * <UL> + * <b>Note:</b> The <b>gluNextContour</b> function is obsolete and is + * provided for backward compatibility only. The <b>gluNextContour</b> + * function is mapped to {@link #gluTessEndContour + * gluTessEndContour} followed by + * {@link #gluTessBeginContour gluTessBeginContour}. + * </UL> + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * @param type + * The type of the contour being defined. + * + * @see #gluNewTess gluNewTess + * @see #gluTessBeginContour gluTessBeginContour + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessCallback gluTessCallback + * @see #gluTessEndContour gluTessEndContour + * @see #gluTessVertex gluTessVertex + ****************************************************************************/ +public void gluNextContour(GLUtessellator tessellator, int type) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluNextContour(type); +} + +/***************************************************************************** + * <b>gluEndPolygon</b> and {@link #gluBeginPolygon + * gluBeginPolygon} delimit the definition of a nonconvex polygon. To define + * such a polygon, first call {@link #gluBeginPolygon + * gluBeginPolygon}. Then define the contours of the polygon by calling + * {@link #gluTessVertex gluTessVertex} for each vertex + * and {@link #gluNextContour gluNextContour} to start + * each new contour. Finally, call <b>gluEndPolygon</b> to signal the end of + * the definition. See the {@link #gluTessVertex + * gluTessVertex} and {@link #gluNextContour + * gluNextContour} reference pages for more details.<P> + * + * Once <b>gluEndPolygon</b> is called, the polygon is tessellated, and the + * resulting triangles are described through callbacks. See + * {@link #gluTessCallback gluTessCallback} for + * descriptions of the callback methods. + * + * @param tessellator + * Specifies the tessellation object (created with + * {@link #gluNewTess gluNewTess}). + * + * @see #gluNewTess gluNewTess + * @see #gluNextContour gluNextContour + * @see #gluTessCallback gluTessCallback + * @see #gluTessVertex gluTessVertex + * @see #gluTessBeginPolygon gluTessBeginPolygon + * @see #gluTessBeginContour gluTessBeginContour + ****************************************************************************/ +public void gluEndPolygon(GLUtessellator tessellator) { + GLUtessellatorImpl tess = (GLUtessellatorImpl) tessellator; + tess.gluEndPolygon(); +} + +//---------------------------------------------------------------------- +// Quadric functionality +// + +/** Interface to C language function: <br> <code> void gluCylinder(GLUquadric * quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks); </code> */ +public void gluCylinder(GLUquadric quad, double base, double top, double height, int slices, int stacks) { + ((GLUquadricImpl) quad).drawCylinder(getCurrentGL(), (float) base, (float) top, (float) height, slices, stacks); +} + +/** Interface to C language function: <br> <code> void gluDeleteQuadric(GLUquadric * quad); </code> */ +public void gluDeleteQuadric(GLUquadric quad) { +} + +/** Interface to C language function: <br> <code> void gluDisk(GLUquadric * quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops); </code> */ +public void gluDisk(GLUquadric quad, double inner, double outer, int slices, int loops) { + ((GLUquadricImpl) quad).drawDisk(getCurrentGL(), (float) inner, (float) outer, slices, loops); +} + +/** Interface to C language function: <br> <code> GLUquadric * gluNewQuadric(void); </code> */ +public GLUquadric gluNewQuadric() { + return new GLUquadricImpl(); +} + +/** Interface to C language function: <br> <code> void gluPartialDisk(GLUquadric * quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops, GLdouble start, GLdouble sweep); </code> */ +public void gluPartialDisk(GLUquadric quad, double inner, double outer, int slices, int loops, double start, double sweep) { + ((GLUquadricImpl) quad).drawPartialDisk(getCurrentGL(), (float) inner, (float) outer, slices, loops, (float) start, (float) sweep); +} + +/** Interface to C language function: <br> <code> void gluQuadricDrawStyle(GLUquadric * quad, GLenum draw); </code> */ +public void gluQuadricDrawStyle(GLUquadric quad, int draw) { + ((GLUquadricImpl) quad).setDrawStyle(draw); +} + +/** Interface to C language function: <br> <code> void gluQuadricNormals(GLUquadric * quad, GLenum normal); </code> */ +public void gluQuadricNormals(GLUquadric quad, int normal) { + ((GLUquadricImpl) quad).setNormals(normal); +} + +/** Interface to C language function: <br> <code> void gluQuadricOrientation(GLUquadric * quad, GLenum orientation); </code> */ +public void gluQuadricOrientation(GLUquadric quad, int orientation) { + ((GLUquadricImpl) quad).setOrientation(orientation); +} + +/** Interface to C language function: <br> <code> void gluQuadricTexture(GLUquadric * quad, GLboolean texture); </code> */ +public void gluQuadricTexture(GLUquadric quad, boolean texture) { + ((GLUquadricImpl) quad).setTextureFlag(texture); +} + +/** Interface to C language function: <br> <code> void gluSphere(GLUquadric * quad, GLdouble radius, GLint slices, GLint stacks); </code> */ +public void gluSphere(GLUquadric quad, double radius, int slices, int stacks) { + ((GLUquadricImpl) quad).drawSphere(getCurrentGL(), (float) radius, slices, stacks); +} + +//---------------------------------------------------------------------- +// Projection routines +// + +private Project project; + +public void gluOrtho2D(double left, double right, double bottom, double top) { + project.gluOrtho2D(getCurrentGL(), left, right, bottom, top); +} + +public void gluPerspective(double fovy, double aspect, double zNear, double zFar) { + project.gluPerspective(getCurrentGL(), fovy, aspect, zNear, zFar); +} + +public void gluLookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ) { + project.gluLookAt(getCurrentGL(), eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); +} + +/** Interface to C language function: <br> <code> GLint gluProject(GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble * winX, GLdouble * winY, GLdouble * winZ); </code> */ +public boolean gluProject(double objX, double objY, double objZ, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double[] winX, int winX_offset, double[] winY, int winY_offset, double[] winZ, int winZ_offset) { + double[] tmp = new double[3]; + boolean res = project.gluProject(objX, objY, objZ, model, model_offset, proj, proj_offset, view, view_offset, tmp, 0); + winX[winX_offset] = tmp[0]; + winY[winY_offset] = tmp[1]; + winZ[winZ_offset] = tmp[2]; + return res; +} + +/** + * Convenience routine for gluProject that accepts the outgoing window + * coordinates as a single array. + */ +public boolean gluProject(double objX, double objY, double objZ, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double[] winPos, int winPos_offset) { + return project.gluProject(objX, objY, objZ, model, model_offset, proj, proj_offset, view, view_offset, winPos, winPos_offset); +} + +/** Interface to C language function: <br> <code> GLint gluUnProject(GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble * objX, GLdouble * objY, GLdouble * objZ); </code> */ +public boolean gluUnProject(double winX, double winY, double winZ, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double[] objX, int objX_offset, double[] objY, int objY_offset, double[] objZ, int objZ_offset) { + double[] tmp = new double[3]; + boolean res = project.gluUnProject(winX, winY, winZ, model, model_offset, proj, proj_offset, view, view_offset, tmp, 0); + objX[objX_offset] = tmp[0]; + objY[objY_offset] = tmp[1]; + objZ[objZ_offset] = tmp[2]; + return res; +} + +/** + * Convenience routine for gluUnProject that accepts the outgoing + * object coordinates (a 3-vector) as a single array. + */ +public boolean gluUnProject(double winX, double winY, double winZ, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double[] objPos, int objPos_offset) { + return project.gluUnProject(winX, winY, winZ, model, model_offset, proj, proj_offset, view, view_offset, objPos, objPos_offset); +} + +/** Interface to C language function: <br> <code> GLint gluUnProject4(GLdouble winX, GLdouble winY, GLdouble winZ, GLdouble clipW, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble nearVal, GLdouble farVal, GLdouble * objX, GLdouble * objY, GLdouble * objZ, GLdouble * objW); </code> */ +public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double nearVal, double farVal, double[] objX, int objX_offset, double[] objY, int objY_offset, double[] objZ, int objZ_offset, double[] objW, int objW_offset) { + double[] tmp = new double[4]; + boolean res = project.gluUnProject4(winX, winY, winZ, clipW, model, model_offset, proj, proj_offset, + view, view_offset, nearVal, farVal, tmp, 0); + objX[objX_offset] = tmp[0]; + objY[objY_offset] = tmp[1]; + objZ[objZ_offset] = tmp[2]; + objW[objW_offset] = tmp[3]; + return res; +} + +/** + * Convenience routine for gluUnProject4 that accepts the outgoing + * object coordinates (a 4-vector) as a single array. + */ +public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, int model_offset, double[] proj, int proj_offset, int[] view, int view_offset, double nearVal, double farVal, double[] objPos, int objPos_offset) { + return project.gluUnProject4(winX, winY, winZ, clipW, model, model_offset, proj, proj_offset, view, view_offset, nearVal, farVal, objPos, objPos_offset); +} + +public void gluPickMatrix(double x, double y, double delX, double delY, int[] viewport, int viewport_offset) { + project.gluPickMatrix(getCurrentGL(), x, y, delX, delY, viewport, viewport_offset); +} + +public void gluPickMatrix(double x, double y, double delX, double delY, IntBuffer viewport) { + project.gluPickMatrix(getCurrentGL(), x, y, delX, delY, viewport); +} + +//---------------------------------------------------------------------- +// Mipmap and image scaling functionality + + +// Boolean +public static final int GLU_FALSE = 0; +public static final int GLU_TRUE = 1; + +// String Name +public static final int GLU_VERSION = 100800; +public static final int GLU_EXTENSIONS = 100801; + +// Extensions +public static final String versionString = "1.3"; +public static final String extensionString = "GLU_EXT_nurbs_tessellator " + + "GLU_EXT_object_space_tess "; + +// ErrorCode +public static final int GLU_INVALID_ENUM = 100900; +public static final int GLU_INVALID_VALUE = 100901; +public static final int GLU_OUT_OF_MEMORY = 100902; +public static final int GLU_INVALID_OPERATION = 100904; + +// NurbsDisplay +// GLU_FILL +public static final int GLU_OUTLINE_POLYGON = 100240; +public static final int GLU_OUTLINE_PATCH = 100241; + +// NurbsCallback +public static final int GLU_NURBS_ERROR = 100103; +public static final int GLU_ERROR = 100103; +public static final int GLU_NURBS_BEGIN = 100164; +public static final int GLU_NURBS_BEGIN_EXT = 100164; +public static final int GLU_NURBS_VERTEX = 100165; +public static final int GLU_NURBS_VERTEX_EXT = 100165; +public static final int GLU_NURBS_NORMAL = 100166; +public static final int GLU_NURBS_NORMAL_EXT = 100166; +public static final int GLU_NURBS_COLOR = 100167; +public static final int GLU_NURBS_COLOR_EXT = 100167; +public static final int GLU_NURBS_TEXTURE_COORD = 100168; +public static final int GLU_NURBS_TEX_COORD_EXT = 100168; +public static final int GLU_NURBS_END = 100169; +public static final int GLU_NURBS_END_EXT = 100169; +public static final int GLU_NURBS_BEGIN_DATA = 100170; +public static final int GLU_NURBS_BEGIN_DATA_EXT = 100170; +public static final int GLU_NURBS_VERTEX_DATA = 100171; +public static final int GLU_NURBS_VERTEX_DATA_EXT = 100171; +public static final int GLU_NURBS_NORMAL_DATA = 100172; +public static final int GLU_NURBS_NORMAL_DATA_EXT = 100172; +public static final int GLU_NURBS_COLOR_DATA = 100173; +public static final int GLU_NURBS_COLOR_DATA_EXT = 100173; +public static final int GLU_NURBS_TEXTURE_COORD_DATA = 100174; +public static final int GLU_NURBS_TEX_COORD_DATA_EXT = 100174; +public static final int GLU_NURBS_END_DATA = 100175; +public static final int GLU_NURBS_END_DATA_EXT = 100175; + +// NurbsError +public static final int GLU_NURBS_ERROR1 = 100251; +public static final int GLU_NURBS_ERROR2 = 100252; +public static final int GLU_NURBS_ERROR3 = 100253; +public static final int GLU_NURBS_ERROR4 = 100254; +public static final int GLU_NURBS_ERROR5 = 100255; +public static final int GLU_NURBS_ERROR6 = 100256; +public static final int GLU_NURBS_ERROR7 = 100257; +public static final int GLU_NURBS_ERROR8 = 100258; +public static final int GLU_NURBS_ERROR9 = 100259; +public static final int GLU_NURBS_ERROR10 = 100260; +public static final int GLU_NURBS_ERROR11 = 100261; +public static final int GLU_NURBS_ERROR12 = 100262; +public static final int GLU_NURBS_ERROR13 = 100263; +public static final int GLU_NURBS_ERROR14 = 100264; +public static final int GLU_NURBS_ERROR15 = 100265; +public static final int GLU_NURBS_ERROR16 = 100266; +public static final int GLU_NURBS_ERROR17 = 100267; +public static final int GLU_NURBS_ERROR18 = 100268; +public static final int GLU_NURBS_ERROR19 = 100269; +public static final int GLU_NURBS_ERROR20 = 100270; +public static final int GLU_NURBS_ERROR21 = 100271; +public static final int GLU_NURBS_ERROR22 = 100272; +public static final int GLU_NURBS_ERROR23 = 100273; +public static final int GLU_NURBS_ERROR24 = 100274; +public static final int GLU_NURBS_ERROR25 = 100275; +public static final int GLU_NURBS_ERROR26 = 100276; +public static final int GLU_NURBS_ERROR27 = 100277; +public static final int GLU_NURBS_ERROR28 = 100278; +public static final int GLU_NURBS_ERROR29 = 100279; +public static final int GLU_NURBS_ERROR30 = 100280; +public static final int GLU_NURBS_ERROR31 = 100281; +public static final int GLU_NURBS_ERROR32 = 100282; +public static final int GLU_NURBS_ERROR33 = 100283; +public static final int GLU_NURBS_ERROR34 = 100284; +public static final int GLU_NURBS_ERROR35 = 100285; +public static final int GLU_NURBS_ERROR36 = 100286; +public static final int GLU_NURBS_ERROR37 = 100287; + +// NurbsProperty +public static final int GLU_AUTO_LOAD_MATRIX = 100200; +public static final int GLU_CULLING = 100201; +public static final int GLU_SAMPLING_TOLERANCE = 100203; +public static final int GLU_DISPLAY_MODE = 100204; +public static final int GLU_PARAMETRIC_TOLERANCE = 100202; +public static final int GLU_SAMPLING_METHOD = 100205; +public static final int GLU_U_STEP = 100206; +public static final int GLU_V_STEP = 100207; +public static final int GLU_NURBS_MODE = 100160; +public static final int GLU_NURBS_MODE_EXT = 100160; +public static final int GLU_NURBS_TESSELLATOR = 100161; +public static final int GLU_NURBS_TESSELLATOR_EXT = 100161; +public static final int GLU_NURBS_RENDERER = 100162; +public static final int GLU_NURBS_RENDERER_EXT = 100162; + +// NurbsSampling +public static final int GLU_OBJECT_PARAMETRIC_ERROR = 100208; +public static final int GLU_OBJECT_PARAMETRIC_ERROR_EXT = 100208; +public static final int GLU_OBJECT_PATH_LENGTH = 100209; +public static final int GLU_OBJECT_PATH_LENGTH_EXT = 100209; +public static final int GLU_PATH_LENGTH = 100215; +public static final int GLU_PARAMETRIC_ERROR = 100216; +public static final int GLU_DOMAIN_DISTANCE = 100217; + +// NurbsTrim +public static final int GLU_MAP1_TRIM_2 = 100210; +public static final int GLU_MAP1_TRIM_3 = 100211; + +// QuadricDrawStyle +public static final int GLU_POINT = 100010; +public static final int GLU_LINE = 100011; +public static final int GLU_FILL = 100012; +public static final int GLU_SILHOUETTE = 100013; + +// QuadricCallback +// GLU_ERROR + +// QuadricNormal +public static final int GLU_SMOOTH = 100000; +public static final int GLU_FLAT = 100001; +public static final int GLU_NONE = 100002; + +// QuadricOrientation +public static final int GLU_OUTSIDE = 100020; +public static final int GLU_INSIDE = 100021; + +// TessCallback +public static final int GLU_TESS_BEGIN = 100100; +public static final int GLU_BEGIN = 100100; +public static final int GLU_TESS_VERTEX = 100101; +public static final int GLU_VERTEX = 100101; +public static final int GLU_TESS_END = 100102; +public static final int GLU_END = 100102; +public static final int GLU_TESS_ERROR = 100103; +public static final int GLU_TESS_EDGE_FLAG = 100104; +public static final int GLU_EDGE_FLAG = 100104; +public static final int GLU_TESS_COMBINE = 100105; +public static final int GLU_TESS_BEGIN_DATA = 100106; +public static final int GLU_TESS_VERTEX_DATA = 100107; +public static final int GLU_TESS_END_DATA = 100108; +public static final int GLU_TESS_ERROR_DATA = 100109; +public static final int GLU_TESS_EDGE_FLAG_DATA = 100110; +public static final int GLU_TESS_COMBINE_DATA = 100111; + +// TessContour +public static final int GLU_CW = 100120; +public static final int GLU_CCW = 100121; +public static final int GLU_INTERIOR = 100122; +public static final int GLU_EXTERIOR = 100123; +public static final int GLU_UNKNOWN = 100124; + +// TessProperty +public static final int GLU_TESS_WINDING_RULE = 100140; +public static final int GLU_TESS_BOUNDARY_ONLY = 100141; +public static final int GLU_TESS_TOLERANCE = 100142; + +// TessError +public static final int GLU_TESS_ERROR1 = 100151; +public static final int GLU_TESS_ERROR2 = 100152; +public static final int GLU_TESS_ERROR3 = 100153; +public static final int GLU_TESS_ERROR4 = 100154; +public static final int GLU_TESS_ERROR5 = 100155; +public static final int GLU_TESS_ERROR6 = 100156; +public static final int GLU_TESS_ERROR7 = 100157; +public static final int GLU_TESS_ERROR8 = 100158; +public static final int GLU_TESS_MISSING_BEGIN_POLYGON = 100151; +public static final int GLU_TESS_MISSING_BEGIN_CONTOUR = 100152; +public static final int GLU_TESS_MISSING_END_POLYGON = 100153; +public static final int GLU_TESS_MISSING_END_CONTOUR = 100154; +public static final int GLU_TESS_COORD_TOO_LARGE = 100155; +public static final int GLU_TESS_NEED_COMBINE_CALLBACK = 100156; + +// TessWinding +public static final int GLU_TESS_WINDING_ODD = 100130; +public static final int GLU_TESS_WINDING_NONZERO = 100131; +public static final int GLU_TESS_WINDING_POSITIVE = 100132; +public static final int GLU_TESS_WINDING_NEGATIVE = 100133; +public static final int GLU_TESS_WINDING_ABS_GEQ_TWO = 100134; +public static final double GLU_TESS_MAX_COORD = 1.0e150; + +private ByteBuffer copyToByteBuffer(Buffer buf) { + if (buf instanceof ByteBuffer) { + if (buf.position() == 0) { + return (ByteBuffer) buf; + } + return BufferUtils.copyByteBuffer((ByteBuffer) buf); + } else if (buf instanceof ShortBuffer) { + return BufferUtils.copyShortBufferAsByteBuffer((ShortBuffer) buf); + } else if (buf instanceof IntBuffer) { + return BufferUtils.copyIntBufferAsByteBuffer((IntBuffer) buf); + } else if (buf instanceof FloatBuffer) { + return BufferUtils.copyFloatBufferAsByteBuffer((FloatBuffer) buf); + } else { + throw new IllegalArgumentException("Unsupported buffer type (must be one of byte, short, int, or float)"); + } +} + +private int gluScaleImageJava( int format, int widthin, int heightin, + int typein, Buffer datain, int widthout, int heightout, + int typeout, Buffer dataout ) { + ByteBuffer in = null; + ByteBuffer out = null; + in = copyToByteBuffer(datain); + if( dataout instanceof ByteBuffer ) { + out = (ByteBuffer)dataout; + } else if( dataout instanceof ShortBuffer ) { + out = BufferUtils.newByteBuffer(dataout.remaining() * BufferUtils.SIZEOF_SHORT); + } else if ( dataout instanceof IntBuffer ) { + out = BufferUtils.newByteBuffer(dataout.remaining() * BufferUtils.SIZEOF_INT); + } else if ( dataout instanceof FloatBuffer ) { + out = BufferUtils.newByteBuffer(dataout.remaining() * BufferUtils.SIZEOF_FLOAT); + } else { + throw new IllegalArgumentException("Unsupported destination buffer type (must be byte, short, int, or float)"); + } + int errno = Mipmap.gluScaleImage( getCurrentGL(), format, widthin, heightin, typein, in, + widthout, heightout, typeout, out ); + if( errno == 0 ) { + out.rewind(); + if( dataout instanceof ShortBuffer ) { + ((ShortBuffer) dataout).put(out.asShortBuffer()); + } else if( dataout instanceof IntBuffer ) { + ((IntBuffer) dataout).put(out.asIntBuffer()); + } else if( dataout instanceof FloatBuffer ) { + ((FloatBuffer) dataout).put(out.asFloatBuffer()); + } else { + throw new RuntimeException("Should not reach here"); + } + } + return( errno ); +} + + +private int gluBuild1DMipmapLevelsJava( int target, int internalFormat, int width, + int format, int type, int userLevel, int baseLevel, int maxLevel, + Buffer data ) { + ByteBuffer buffer = copyToByteBuffer(data); + return( Mipmap.gluBuild1DMipmapLevels( getCurrentGL(), target, internalFormat, width, + format, type, userLevel, baseLevel, maxLevel, buffer ) ); +} + + +private int gluBuild1DMipmapsJava( int target, int internalFormat, int width, + int format, int type, Buffer data ) { + ByteBuffer buffer = copyToByteBuffer(data); + return( Mipmap.gluBuild1DMipmaps( getCurrentGL(), target, internalFormat, width, format, + type, buffer ) ); +} + + +private int gluBuild2DMipmapLevelsJava( int target, int internalFormat, int width, + int height, int format, int type, int userLevel, int baseLevel, + int maxLevel, Buffer data ) { + // While the code below handles other data types, it doesn't handle non-ByteBuffers + data = copyToByteBuffer(data); + return( Mipmap.gluBuild2DMipmapLevels( getCurrentGL(), target, internalFormat, width, + height, format, type, userLevel, baseLevel, maxLevel, data ) ); +} + +private int gluBuild2DMipmapsJava( int target, int internalFormat, int width, + int height, int format, int type, Buffer data ) { + // While the code below handles other data types, it doesn't handle non-ByteBuffers + data = copyToByteBuffer(data); + return( Mipmap.gluBuild2DMipmaps( getCurrentGL(), target, internalFormat, width, height, + format, type, data) ); +} + +private int gluBuild3DMipmapLevelsJava( int target, int internalFormat, int width, + int height, int depth, int format, int type, int userLevel, int baseLevel, + int maxLevel, Buffer data) { + ByteBuffer buffer = copyToByteBuffer(data); + return( Mipmap.gluBuild3DMipmapLevels( getCurrentGL(), target, internalFormat, width, + height, depth, format, type, userLevel, baseLevel, maxLevel, buffer) ); +} + +private int gluBuild3DMipmapsJava( int target, int internalFormat, int width, + int height, int depth, int format, int type, Buffer data ) { + ByteBuffer buffer = copyToByteBuffer(data); + return( Mipmap.gluBuild3DMipmaps( getCurrentGL(), target, internalFormat, width, height, + depth, format, type, buffer ) ); +} + + +//---------------------------------------------------------------------- +// Wrappers for mipmap and image scaling entry points which dispatch either +// to the Java or C versions. +// + +/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ +public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); + } else { + return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); + } +} + +/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ +public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild1DMipmapsJava(target, internalFormat, width, format, type, data); + } else { + return gluBuild1DMipmapsC(target, internalFormat, width, format, type, data); + } +} + +/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ +public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); + } else { + return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); + } +} + + +/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ +public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); + } else { + return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); + } +} + + +/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ +public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); + } else { + return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); + } +} + +/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ +public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data) { + if (useJavaMipmapCode) { + return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); + } else { + return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); + } +} + + +/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ +public int gluScaleImage(int format, int wIn, int hIn, int typeIn, java.nio.Buffer dataIn, int wOut, int hOut, int typeOut, java.nio.Buffer dataOut) { + if (useJavaMipmapCode) { + return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); + } else { + return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); + } +} + +//---------------------------------------------------------------------- +// GLUProcAddressTable handling +// + +private static GLUProcAddressTable gluProcAddressTable; + +private static GLUProcAddressTable getGLUProcAddressTable() { + if (gluProcAddressTable == null) { + GLUProcAddressTable tmp = new GLUProcAddressTable(); + GLDrawableFactoryImpl.getFactoryImpl().resetProcAddressTable(tmp); + gluProcAddressTable = tmp; + } + return gluProcAddressTable; +} diff --git a/make/glu-common.cfg b/make/glu-common.cfg index 917a95a62..e0a5b150a 100644 --- a/make/glu-common.cfg +++ b/make/glu-common.cfg @@ -1,19 +1,39 @@ # This .cfg file provides common options used among all GLU glue code # generated for Jogl on all platforms. -Package net.java.games.jogl -ImplPackage net.java.games.jogl.impl -JavaClass GLU -ImplJavaClass GLUImpl +Style ImplOnly +ImplPackage javax.media.opengl.glu +ImplJavaClass GLU JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl HierarchicalNativeOutput false +EmitProcAddressTable true +ProcAddressTablePackage com.sun.opengl.impl +ProcAddressTableClassName GLUProcAddressTable +GetProcAddressTableExpr getGLUProcAddressTable() + # # Imports needed by all glue code # Import java.nio.* -Import net.java.games.jogl.* -Import net.java.games.jogl.impl.* +Import javax.media.opengl.* +Import javax.media.opengl.glu.* +Import com.sun.opengl.impl.* + +# GLU needs access to the GLUtesselatorImpl class for GLUtesselator +# and to the Mipmap class for scaling and mipmap generation +Import com.sun.opengl.impl.tessellator.GLUtessellatorImpl +Import com.sun.opengl.impl.error.Error +Import com.sun.opengl.impl.mipmap.Mipmap +Import com.sun.opengl.impl.registry.Registry +Import com.sun.opengl.utils.* +Import java.security.* + +# Custom Java code for GLU class +IncludeAs CustomJavaCode GLU glu-CustomJavaCode.java + +CustomCCode /* Include the OpenGL GLU header */ +CustomCCode #include <GL/glu.h> # Raise GLException instead of RuntimeException in glue code RuntimeExceptionType GLException @@ -26,25 +46,6 @@ Opaque boolean GLboolean Opaque boolean BOOL # -# Some functions that return native byte pointers or accept them as -# arguments should have them auto-converted to Java Strings -# -ReturnsString gluGetString -ReturnsString gluErrorString -ArgumentIsString gluCheckExtension 0 1 - -# -# Some routines should only use the Java New IO package -# -#NIOOnly gluScaleImage -#NIOOnly gluBuild1DMipmaps -#NIOOnly gluBuild2DMipmaps -#NIOOnly gluBuild3DMipmaps -#NIOOnly gluBuild1DMipmapLevels -#NIOOnly gluBuild2DMipmapLevels -#NIOOnly gluBuild3DMipmapLevels - -# # Don't output #defines of GLU version identifier strings as constants, # because we don't need them java-side. # @@ -67,24 +68,38 @@ Ignore GLU_EXT_.+ # Javadoc for the GLU class ClassJavadoc GLU /** -ClassJavadoc GLU * Provides access to the OpenGL utility library routines. -ClassJavadoc GLU * See {@link GL} for more information. +ClassJavadoc GLU * Provides access to the OpenGL Utility Library (GLU). This library +ClassJavadoc GLU * provides standard methods for setting up view volumes, building +ClassJavadoc GLU * mipmaps and performing other common operations. +ClassJavadoc GLU * +ClassJavadoc GLU * <P> +ClassJavadoc GLU * +ClassJavadoc GLU * Thanks to the contributions of many individuals, this class is a +ClassJavadoc GLU * pure Java port of SGI's original C sources. All of the projection, +ClassJavadoc GLU * mipmap, scaling, and tessellation routines that are exposed are +ClassJavadoc GLU * compatible with the GLU 1.3 specification. The GLU NURBS routines +ClassJavadoc GLU * are not currently exposed. ClassJavadoc GLU */ -# Javadoc for the GLUnurbs class -ClassJavadoc GLUnurbs /** -ClassJavadoc GLUnurbs * Wrapper for a GLU NURBS object. -ClassJavadoc GLUnurbs */ +# +# We ignore most of the function declarations in glu.h because we +# provide a pure Java implementation of most of GLU. Currently the +# only reason we generate glue code for this class is to provide a +# fallback path to the C code for the mipmap routines in case of bugs +# with the Java port (although it has been pretty thoroughly debugged +# at this point). +# -# Javadoc for the GLUquadric class -ClassJavadoc GLUquadric /** -ClassJavadoc GLUquadric * Wrapper for a GLU quadric object. -ClassJavadoc GLUquadric */ +# +# ------------------------ +# Utility routines +# ------------------------ +# -# Javadoc for the GLUtesselator class -ClassJavadoc GLUtesselator /** -ClassJavadoc GLUtesselator * Wrapper for a GLU tesselator object. -ClassJavadoc GLUtesselator */ +# These are implemented by pure Java +Ignore gluCheckExtension +Ignore gluErrorString +Ignore gluGetString # # ------------------------ @@ -113,6 +128,7 @@ Ignore gluNurbsCurve Ignore gluNurbsSurface Ignore GLU_NURB.+ Ignore GLU_.*PARAMETRIC.+ +Ignore GLUnurbs # # ------------------------ @@ -154,16 +170,16 @@ Ignore gluQuadricCallback.* # Manually implement the GLU quadric functionality to mostly conform # to the C APIs Ignore GLUquadric -ManuallyImplement gluCylinder -ManuallyImplement gluDeleteQuadric -ManuallyImplement gluDisk -ManuallyImplement gluNewQuadric -ManuallyImplement gluPartialDisk -ManuallyImplement gluQuadricDrawStyle -ManuallyImplement gluQuadricNormals -ManuallyImplement gluQuadricOrientation -ManuallyImplement gluQuadricTexture -ManuallyImplement gluSphere +Ignore gluCylinder +Ignore gluDeleteQuadric +Ignore gluDisk +Ignore gluNewQuadric +Ignore gluPartialDisk +Ignore gluQuadricDrawStyle +Ignore gluQuadricNormals +Ignore gluQuadricOrientation +Ignore gluQuadricTexture +Ignore gluSphere # Ignore a few of the projection/unprojection APIs altogether because # their signatures aren't specified correctly in the header file @@ -172,35 +188,60 @@ Ignore gluUnProject Ignore gluUnProject4 # Manually implement the rest of the projection / unprojection APIs -ManuallyImplement gluOrtho2D -ManuallyImplement gluPerspective -ManuallyImplement gluLookAt -ManuallyImplement gluPickMatrix +Ignore gluOrtho2D +Ignore gluPerspective +Ignore gluLookAt +Ignore gluPickMatrix + + + + + +# +# Some functions that return native byte pointers or accept them as +# arguments should have them auto-converted to Java Strings +# +# ReturnsString gluGetString +# ReturnsString gluErrorString +# ArgumentIsString gluCheckExtension 0 1 + +# +# Some routines should only use the Java New IO package +# +#NIOOnly gluScaleImage +#NIOOnly gluBuild1DMipmaps +#NIOOnly gluBuild2DMipmaps +#NIOOnly gluBuild3DMipmaps +#NIOOnly gluBuild1DMipmapLevels +#NIOOnly gluBuild2DMipmapLevels +#NIOOnly gluBuild3DMipmapLevels # # ------------------------ -# Mipmaps +# Mipmaps # ------------------------ # -# Ignore the mipmap routines and use GKW's Java port instead. -# Currently the Java and native code have fallback paths to the -# C code, but this will be removed in a future release. - -Ignore gluBuild1DMipmapLevels -Ignore gluBuild1DMipmaps -Ignore gluBuild2DMipmapLevels -Ignore gluBuild2DMipmaps -Ignore gluBuild3DMipmapLevels -Ignore gluBuild3DMipmaps -Ignore gluScaleImage - -# Must force proc address generation for these routines, though, since -# we still fall back on the C implementations - -ForceProcAddressGen gluBuild1DMipmapLevels -ForceProcAddressGen gluBuild1DMipmaps -ForceProcAddressGen gluBuild2DMipmapLevels -ForceProcAddressGen gluBuild2DMipmaps -ForceProcAddressGen gluBuild3DMipmapLevels -ForceProcAddressGen gluBuild3DMipmaps -ForceProcAddressGen gluScaleImage +# Ignore the C versions of the mipmap code in the public interface and +# use GKW's Java port instead. The bindings to the C entry points are +# still being left in for now, but only for debugging purposes and the +# intent is to remove them in a future release. + +# Emit these entry points as private + +AccessControl gluBuild1DMipmapLevels PRIVATE +AccessControl gluBuild1DMipmaps PRIVATE +AccessControl gluBuild2DMipmapLevels PRIVATE +AccessControl gluBuild2DMipmaps PRIVATE +AccessControl gluBuild3DMipmapLevels PRIVATE +AccessControl gluBuild3DMipmaps PRIVATE +AccessControl gluScaleImage PRIVATE + +# Rename these methods in the implementing class + +RenameJavaMethod gluBuild1DMipmapLevels gluBuild1DMipmapLevelsC +RenameJavaMethod gluBuild1DMipmaps gluBuild1DMipmapsC +RenameJavaMethod gluBuild2DMipmapLevels gluBuild2DMipmapLevelsC +RenameJavaMethod gluBuild2DMipmaps gluBuild2DMipmapsC +RenameJavaMethod gluBuild3DMipmapLevels gluBuild3DMipmapLevelsC +RenameJavaMethod gluBuild3DMipmaps gluBuild3DMipmapsC +RenameJavaMethod gluScaleImage gluScaleImageC diff --git a/make/glu-impl-common-CustomCCode.c b/make/glu-impl-common-CustomCCode.c deleted file mode 100644 index 5a3f645c5..000000000 --- a/make/glu-impl-common-CustomCCode.c +++ /dev/null @@ -1,833 +0,0 @@ -/* Include the OpenGL GLU header */ -#include <GL/glu.h> - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data) - * C function: GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmapLevels__IIIIIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jint level, jint base, jint max, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPLEVELSPROC ptr_gluBuild1DMipmapLevels; - void * _ptr8 = NULL; - GLint _res; - ptr_gluBuild1DMipmapLevels = (PFNGLUBUILD1DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmapLevels != NULL); - if (data != NULL) { - _ptr8 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr8); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data) - * C function: GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmapLevels__IIIIIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jint level, jint base, jint max, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPLEVELSPROC ptr_gluBuild1DMipmapLevels; - void * _ptr8 = NULL; - GLint _res; - ptr_gluBuild1DMipmapLevels = (PFNGLUBUILD1DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmapLevels != NULL); - if (data != NULL) { - _ptr8 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr8); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data) - * C function: GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmapLevels__IIIIIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jint level, jint base, jint max, jintArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPLEVELSPROC ptr_gluBuild1DMipmapLevels; - void * _ptr8 = NULL; - GLint _res; - ptr_gluBuild1DMipmapLevels = (PFNGLUBUILD1DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmapLevels != NULL); - if (data != NULL) { - _ptr8 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr8); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data) - * C function: GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmapLevels__IIIIIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jint level, jint base, jint max, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPLEVELSPROC ptr_gluBuild1DMipmapLevels; - void * _ptr8 = NULL; - GLint _res; - ptr_gluBuild1DMipmapLevels = (PFNGLUBUILD1DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmapLevels != NULL); - if (data != NULL) { - _ptr8 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr8); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.ByteBuffer data) - * C function: GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmapLevels__IIIIIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jint level, jint base, jint max, jobject data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPLEVELSPROC ptr_gluBuild1DMipmapLevels; - void * _ptr8 = NULL; - GLint _res; - if (data != NULL) { - _ptr8 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr8 = NULL; - } - ptr_gluBuild1DMipmapLevels = (PFNGLUBUILD1DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmapLevels != NULL); - _res = (* ptr_gluBuild1DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr8); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, byte[] data) - * C function: GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmaps__IIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPSPROC ptr_gluBuild1DMipmaps; - void * _ptr5 = NULL; - GLint _res; - ptr_gluBuild1DMipmaps = (PFNGLUBUILD1DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmaps != NULL); - if (data != NULL) { - _ptr5 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (void *) _ptr5); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr5, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, short[] data) - * C function: GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmaps__IIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPSPROC ptr_gluBuild1DMipmaps; - void * _ptr5 = NULL; - GLint _res; - ptr_gluBuild1DMipmaps = (PFNGLUBUILD1DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmaps != NULL); - if (data != NULL) { - _ptr5 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (void *) _ptr5); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr5, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, int[] data) - * C function: GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmaps__IIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jintArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPSPROC ptr_gluBuild1DMipmaps; - void * _ptr5 = NULL; - GLint _res; - ptr_gluBuild1DMipmaps = (PFNGLUBUILD1DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmaps != NULL); - if (data != NULL) { - _ptr5 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (void *) _ptr5); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr5, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, float[] data) - * C function: GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmaps__IIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPSPROC ptr_gluBuild1DMipmaps; - void * _ptr5 = NULL; - GLint _res; - ptr_gluBuild1DMipmaps = (PFNGLUBUILD1DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmaps != NULL); - if (data != NULL) { - _ptr5 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild1DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (void *) _ptr5); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr5, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, java.nio.ByteBuffer data) - * C function: GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild1DMipmaps__IIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint format, jint type, jobject data, jlong glProcAddress) { - PFNGLUBUILD1DMIPMAPSPROC ptr_gluBuild1DMipmaps; - void * _ptr5 = NULL; - GLint _res; - if (data != NULL) { - _ptr5 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr5 = NULL; - } - ptr_gluBuild1DMipmaps = (PFNGLUBUILD1DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild1DMipmaps != NULL); - _res = (* ptr_gluBuild1DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLenum) format, (GLenum) type, (void *) _ptr5); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data) - * C function: GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmapLevels__IIIIIIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jint level, jint base, jint max, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPLEVELSPROC ptr_gluBuild2DMipmapLevels; - void * _ptr9 = NULL; - GLint _res; - ptr_gluBuild2DMipmapLevels = (PFNGLUBUILD2DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmapLevels != NULL); - if (data != NULL) { - _ptr9 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr9); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr9, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data) - * C function: GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmapLevels__IIIIIIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jint level, jint base, jint max, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPLEVELSPROC ptr_gluBuild2DMipmapLevels; - void * _ptr9 = NULL; - GLint _res; - ptr_gluBuild2DMipmapLevels = (PFNGLUBUILD2DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmapLevels != NULL); - if (data != NULL) { - _ptr9 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr9); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr9, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data) - * C function: GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmapLevels__IIIIIIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jint level, jint base, jint max, jintArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPLEVELSPROC ptr_gluBuild2DMipmapLevels; - void * _ptr9 = NULL; - GLint _res; - ptr_gluBuild2DMipmapLevels = (PFNGLUBUILD2DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmapLevels != NULL); - if (data != NULL) { - _ptr9 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr9); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr9, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data) - * C function: GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmapLevels__IIIIIIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jint level, jint base, jint max, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPLEVELSPROC ptr_gluBuild2DMipmapLevels; - void * _ptr9 = NULL; - GLint _res; - ptr_gluBuild2DMipmapLevels = (PFNGLUBUILD2DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmapLevels != NULL); - if (data != NULL) { - _ptr9 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr9); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr9, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.ByteBuffer data) - * C function: GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmapLevels__IIIIIIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jint level, jint base, jint max, jobject data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPLEVELSPROC ptr_gluBuild2DMipmapLevels; - void * _ptr9 = NULL; - GLint _res; - if (data != NULL) { - _ptr9 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr9 = NULL; - } - ptr_gluBuild2DMipmapLevels = (PFNGLUBUILD2DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmapLevels != NULL); - _res = (* ptr_gluBuild2DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr9); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, byte[] data) - * C function: GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmaps__IIIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPSPROC ptr_gluBuild2DMipmaps; - void * _ptr6 = NULL; - GLint _res; - ptr_gluBuild2DMipmaps = (PFNGLUBUILD2DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmaps != NULL); - if (data != NULL) { - _ptr6 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (void *) _ptr6); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr6, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, short[] data) - * C function: GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmaps__IIIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPSPROC ptr_gluBuild2DMipmaps; - void * _ptr6 = NULL; - GLint _res; - ptr_gluBuild2DMipmaps = (PFNGLUBUILD2DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmaps != NULL); - if (data != NULL) { - _ptr6 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (void *) _ptr6); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr6, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, int[] data) - * C function: GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmaps__IIIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jintArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPSPROC ptr_gluBuild2DMipmaps; - void * _ptr6 = NULL; - GLint _res; - ptr_gluBuild2DMipmaps = (PFNGLUBUILD2DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmaps != NULL); - if (data != NULL) { - _ptr6 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (void *) _ptr6); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr6, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, float[] data) - * C function: GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmaps__IIIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPSPROC ptr_gluBuild2DMipmaps; - void * _ptr6 = NULL; - GLint _res; - ptr_gluBuild2DMipmaps = (PFNGLUBUILD2DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmaps != NULL); - if (data != NULL) { - _ptr6 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild2DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (void *) _ptr6); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr6, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, java.nio.ByteBuffer data) - * C function: GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild2DMipmaps__IIIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint format, jint type, jobject data, jlong glProcAddress) { - PFNGLUBUILD2DMIPMAPSPROC ptr_gluBuild2DMipmaps; - void * _ptr6 = NULL; - GLint _res; - if (data != NULL) { - _ptr6 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr6 = NULL; - } - ptr_gluBuild2DMipmaps = (PFNGLUBUILD2DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild2DMipmaps != NULL); - _res = (* ptr_gluBuild2DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLenum) format, (GLenum) type, (void *) _ptr6); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data) - * C function: GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmapLevels__IIIIIIIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jint level, jint base, jint max, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPLEVELSPROC ptr_gluBuild3DMipmapLevels; - void * _ptr10 = NULL; - GLint _res; - ptr_gluBuild3DMipmapLevels = (PFNGLUBUILD3DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmapLevels != NULL); - if (data != NULL) { - _ptr10 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr10); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr10, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data) - * C function: GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmapLevels__IIIIIIIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jint level, jint base, jint max, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPLEVELSPROC ptr_gluBuild3DMipmapLevels; - void * _ptr10 = NULL; - GLint _res; - ptr_gluBuild3DMipmapLevels = (PFNGLUBUILD3DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmapLevels != NULL); - if (data != NULL) { - _ptr10 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr10); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr10, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data) - * C function: GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmapLevels__IIIIIIIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jint level, jint base, jint max, jintArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPLEVELSPROC ptr_gluBuild3DMipmapLevels; - void * _ptr10 = NULL; - GLint _res; - ptr_gluBuild3DMipmapLevels = (PFNGLUBUILD3DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmapLevels != NULL); - if (data != NULL) { - _ptr10 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr10); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr10, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data) - * C function: GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmapLevels__IIIIIIIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jint level, jint base, jint max, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPLEVELSPROC ptr_gluBuild3DMipmapLevels; - void * _ptr10 = NULL; - GLint _res; - ptr_gluBuild3DMipmapLevels = (PFNGLUBUILD3DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmapLevels != NULL); - if (data != NULL) { - _ptr10 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr10); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr10, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.ByteBuffer data) - * C function: GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmapLevels__IIIIIIIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jint level, jint base, jint max, jobject data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPLEVELSPROC ptr_gluBuild3DMipmapLevels; - void * _ptr10 = NULL; - GLint _res; - if (data != NULL) { - _ptr10 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr10 = NULL; - } - ptr_gluBuild3DMipmapLevels = (PFNGLUBUILD3DMIPMAPLEVELSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmapLevels != NULL); - _res = (* ptr_gluBuild3DMipmapLevels) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (GLint) level, (GLint) base, (GLint) max, (void *) _ptr10); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data) - * C function: GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmaps__IIIIIII_3BJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jbyteArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPSPROC ptr_gluBuild3DMipmaps; - void * _ptr7 = NULL; - GLint _res; - ptr_gluBuild3DMipmaps = (PFNGLUBUILD3DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmaps != NULL); - if (data != NULL) { - _ptr7 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (void *) _ptr7); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr7, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data) - * C function: GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmaps__IIIIIII_3SJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jshortArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPSPROC ptr_gluBuild3DMipmaps; - void * _ptr7 = NULL; - GLint _res; - ptr_gluBuild3DMipmaps = (PFNGLUBUILD3DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmaps != NULL); - if (data != NULL) { - _ptr7 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (void *) _ptr7); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr7, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data) - * C function: GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmaps__IIIIIII_3IJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jintArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPSPROC ptr_gluBuild3DMipmaps; - void * _ptr7 = NULL; - GLint _res; - ptr_gluBuild3DMipmaps = (PFNGLUBUILD3DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmaps != NULL); - if (data != NULL) { - _ptr7 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (void *) _ptr7); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr7, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data) - * C function: GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmaps__IIIIIII_3FJ(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jfloatArray data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPSPROC ptr_gluBuild3DMipmaps; - void * _ptr7 = NULL; - GLint _res; - ptr_gluBuild3DMipmaps = (PFNGLUBUILD3DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmaps != NULL); - if (data != NULL) { - _ptr7 = (void *) (*env)->GetPrimitiveArrayCritical(env, data, NULL); - } - _res = (* ptr_gluBuild3DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (void *) _ptr7); - if (data != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, data, _ptr7, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.ByteBuffer data) - * C function: GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluBuild3DMipmaps__IIIIIIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint target, jint internalFormat, jint width, jint height, jint depth, jint format, jint type, jobject data, jlong glProcAddress) { - PFNGLUBUILD3DMIPMAPSPROC ptr_gluBuild3DMipmaps; - void * _ptr7 = NULL; - GLint _res; - if (data != NULL) { - _ptr7 = (void *) (*env)->GetDirectBufferAddress(env, data); - } else { - _ptr7 = NULL; - } - ptr_gluBuild3DMipmaps = (PFNGLUBUILD3DMIPMAPSPROC) (intptr_t) glProcAddress; - assert(ptr_gluBuild3DMipmaps != NULL); - _res = (* ptr_gluBuild3DMipmaps) ((GLenum) target, (GLint) internalFormat, (GLsizei) width, (GLsizei) height, (GLsizei) depth, (GLenum) format, (GLenum) type, (void *) _ptr7); - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, byte[] dataIn, int wOut, int hOut, int typeOut, byte[] dataOut) - * C function: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluScaleImage__IIII_3BIII_3BJ(JNIEnv *env, jobject _unused, jint format, jint wIn, jint hIn, jint typeIn, jbyteArray dataIn, jint wOut, jint hOut, jint typeOut, jbyteArray dataOut, jlong glProcAddress) { - PFNGLUSCALEIMAGEPROC ptr_gluScaleImage; - void * _ptr4 = NULL; - GLvoid * _ptr8 = NULL; - GLint _res; - ptr_gluScaleImage = (PFNGLUSCALEIMAGEPROC) (intptr_t) glProcAddress; - assert(ptr_gluScaleImage != NULL); - if (dataIn != NULL) { - _ptr4 = (void *) (*env)->GetPrimitiveArrayCritical(env, dataIn, NULL); - } - if (dataOut != NULL) { - _ptr8 = (GLvoid *) (*env)->GetPrimitiveArrayCritical(env, dataOut, NULL); - } - _res = (* ptr_gluScaleImage) ((GLenum) format, (GLsizei) wIn, (GLsizei) hIn, (GLenum) typeIn, (void *) _ptr4, (GLsizei) wOut, (GLsizei) hOut, (GLenum) typeOut, (GLvoid *) _ptr8); - if (dataIn != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataIn, _ptr4, JNI_ABORT); - } - if (dataOut != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataOut, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, short[] dataIn, int wOut, int hOut, int typeOut, short[] dataOut) - * C function: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluScaleImage__IIII_3SIII_3SJ(JNIEnv *env, jobject _unused, jint format, jint wIn, jint hIn, jint typeIn, jshortArray dataIn, jint wOut, jint hOut, jint typeOut, jshortArray dataOut, jlong glProcAddress) { - PFNGLUSCALEIMAGEPROC ptr_gluScaleImage; - void * _ptr4 = NULL; - GLvoid * _ptr8 = NULL; - GLint _res; - ptr_gluScaleImage = (PFNGLUSCALEIMAGEPROC) (intptr_t) glProcAddress; - assert(ptr_gluScaleImage != NULL); - if (dataIn != NULL) { - _ptr4 = (void *) (*env)->GetPrimitiveArrayCritical(env, dataIn, NULL); - } - if (dataOut != NULL) { - _ptr8 = (GLvoid *) (*env)->GetPrimitiveArrayCritical(env, dataOut, NULL); - } - _res = (* ptr_gluScaleImage) ((GLenum) format, (GLsizei) wIn, (GLsizei) hIn, (GLenum) typeIn, (void *) _ptr4, (GLsizei) wOut, (GLsizei) hOut, (GLenum) typeOut, (GLvoid *) _ptr8); - if (dataIn != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataIn, _ptr4, JNI_ABORT); - } - if (dataOut != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataOut, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, int[] dataIn, int wOut, int hOut, int typeOut, int[] dataOut) - * C function: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluScaleImage__IIII_3IIII_3IJ(JNIEnv *env, jobject _unused, jint format, jint wIn, jint hIn, jint typeIn, jintArray dataIn, jint wOut, jint hOut, jint typeOut, jintArray dataOut, jlong glProcAddress) { - PFNGLUSCALEIMAGEPROC ptr_gluScaleImage; - void * _ptr4 = NULL; - GLvoid * _ptr8 = NULL; - GLint _res; - ptr_gluScaleImage = (PFNGLUSCALEIMAGEPROC) (intptr_t) glProcAddress; - assert(ptr_gluScaleImage != NULL); - if (dataIn != NULL) { - _ptr4 = (void *) (*env)->GetPrimitiveArrayCritical(env, dataIn, NULL); - } - if (dataOut != NULL) { - _ptr8 = (GLvoid *) (*env)->GetPrimitiveArrayCritical(env, dataOut, NULL); - } - _res = (* ptr_gluScaleImage) ((GLenum) format, (GLsizei) wIn, (GLsizei) hIn, (GLenum) typeIn, (void *) _ptr4, (GLsizei) wOut, (GLsizei) hOut, (GLenum) typeOut, (GLvoid *) _ptr8); - if (dataIn != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataIn, _ptr4, JNI_ABORT); - } - if (dataOut != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataOut, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, float[] dataIn, int wOut, int hOut, int typeOut, float[] dataOut) - * C function: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluScaleImage__IIII_3FIII_3FJ(JNIEnv *env, jobject _unused, jint format, jint wIn, jint hIn, jint typeIn, jfloatArray dataIn, jint wOut, jint hOut, jint typeOut, jfloatArray dataOut, jlong glProcAddress) { - PFNGLUSCALEIMAGEPROC ptr_gluScaleImage; - void * _ptr4 = NULL; - GLvoid * _ptr8 = NULL; - GLint _res; - ptr_gluScaleImage = (PFNGLUSCALEIMAGEPROC) (intptr_t) glProcAddress; - assert(ptr_gluScaleImage != NULL); - if (dataIn != NULL) { - _ptr4 = (void *) (*env)->GetPrimitiveArrayCritical(env, dataIn, NULL); - } - if (dataOut != NULL) { - _ptr8 = (GLvoid *) (*env)->GetPrimitiveArrayCritical(env, dataOut, NULL); - } - _res = (* ptr_gluScaleImage) ((GLenum) format, (GLsizei) wIn, (GLsizei) hIn, (GLenum) typeIn, (void *) _ptr4, (GLsizei) wOut, (GLsizei) hOut, (GLenum) typeOut, (GLvoid *) _ptr8); - if (dataIn != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataIn, _ptr4, JNI_ABORT); - } - if (dataOut != NULL) { - (*env)->ReleasePrimitiveArrayCritical(env, dataOut, _ptr8, JNI_ABORT); - } - return _res; -} - - -/* Java->C glue code: - * Java package: net.java.games.jogl.impl.GLUImpl - * Java method: int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, java.nio.ByteBuffer dataIn, int wOut, int hOut, int typeOut, java.nio.ByteBuffer dataOut) - * C function: GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); - */ -JNIEXPORT jint JNICALL -Java_net_java_games_jogl_impl_GLUImpl_dispatch_1gluScaleImage__IIIILjava_nio_Buffer_2IIILjava_nio_Buffer_2J(JNIEnv *env, jobject _unused, jint format, jint wIn, jint hIn, jint typeIn, jobject dataIn, jint wOut, jint hOut, jint typeOut, jobject dataOut, jlong glProcAddress) { - PFNGLUSCALEIMAGEPROC ptr_gluScaleImage; - void * _ptr4 = NULL; - GLvoid * _ptr8 = NULL; - GLint _res; - if (dataIn != NULL) { - _ptr4 = (void *) (*env)->GetDirectBufferAddress(env, dataIn); - } else { - _ptr4 = NULL; - } - if (dataOut != NULL) { - _ptr8 = (GLvoid *) (*env)->GetDirectBufferAddress(env, dataOut); - } else { - _ptr8 = NULL; - } - ptr_gluScaleImage = (PFNGLUSCALEIMAGEPROC) (intptr_t) glProcAddress; - assert(ptr_gluScaleImage != NULL); - _res = (* ptr_gluScaleImage) ((GLenum) format, (GLsizei) wIn, (GLsizei) hIn, (GLenum) typeIn, (void *) _ptr4, (GLsizei) wOut, (GLsizei) hOut, (GLenum) typeOut, (GLvoid *) _ptr8); - return _res; -} diff --git a/make/glu-impl-common-CustomJavaCode.java b/make/glu-impl-common-CustomJavaCode.java deleted file mode 100644 index 0706aa390..000000000 --- a/make/glu-impl-common-CustomJavaCode.java +++ /dev/null @@ -1,1426 +0,0 @@ -private static boolean useJavaMipmapCode = true; - -static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String val = System.getProperty("jogl.glu.nojava"); - if (val != null && !val.toLowerCase().equals("false")) { - useJavaMipmapCode = false; - } - return null; - } - }); -} - -/** Indicates whether the given GLU routine is available to be called. */ -public boolean isFunctionAvailable(String gluFunctionName) -{ - return (gluProcAddressTable.getAddressFor(gluFunctionName) != 0); -} - -private GLUProcAddressTable gluProcAddressTable; -private GL gl; - -public GLUImpl(GLUProcAddressTable gluProcAddressTable) -{ - this.gluProcAddressTable = gluProcAddressTable; - this.project = new Project(); -} - -// Used for pure-Java port of GLU -public void setGL(GL gl) { - this.gl = gl; -} - -//---------------------------------------------------------------------- -// Tesselator functionality -// - -public GLUtesselator gluNewTess() { - return GLUtesselatorImpl.gluNewTess(); -} - -public void gluDeleteTess(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluDeleteTess(); -} - -public void gluTessProperty(GLUtesselator tesselator, int which, double value) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessProperty(which, value); -} - -public void gluGetTessProperty(GLUtesselator tesselator, int which, double[] value) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluGetTessProperty(which, value); -} - -public void gluTessNormal(GLUtesselator tesselator, double x, double y, double z) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessNormal(x, y, z); -} - -public void gluTessCallback(GLUtesselator tesselator, int which, GLUtesselatorCallback aCallback) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessCallback(which, aCallback); -} - -public void gluTessVertex(GLUtesselator tesselator, double[] coords, Object data) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessVertex(coords, data); -} - -public void gluTessBeginPolygon(GLUtesselator tesselator, Object data) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessBeginPolygon(data); -} - -public void gluTessBeginContour(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessBeginContour(); -} - -public void gluTessEndContour(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessEndContour(); -} - -public void gluTessEndPolygon(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluTessEndPolygon(); -} - -public void gluBeginPolygon(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluBeginPolygon(); -} - -public void gluNextContour(GLUtesselator tesselator, int type) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluNextContour(type); -} - -public void gluEndPolygon(GLUtesselator tesselator) { - GLUtesselatorImpl tess = (GLUtesselatorImpl) tesselator; - tess.gluEndPolygon(); -} - -//---------------------------------------------------------------------- -// Quadric functionality -// - -/** Interface to C language function: <br> <code> void gluCylinder(GLUquadric * quad, GLdouble base, GLdouble top, GLdouble height, GLint slices, GLint stacks); </code> */ -public void gluCylinder(GLUquadric quad, double base, double top, double height, int slices, int stacks) { - ((GLUquadricImpl) quad).drawCylinder(gl, (float) base, (float) top, (float) height, slices, stacks); -} - -/** Interface to C language function: <br> <code> void gluDeleteQuadric(GLUquadric * quad); </code> */ -public void gluDeleteQuadric(GLUquadric quad) { -} - -/** Interface to C language function: <br> <code> void gluDisk(GLUquadric * quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops); </code> */ -public void gluDisk(GLUquadric quad, double inner, double outer, int slices, int loops) { - ((GLUquadricImpl) quad).drawDisk(gl, (float) inner, (float) outer, slices, loops); -} - -/** Interface to C language function: <br> <code> GLUquadric * gluNewQuadric(void); </code> */ -public GLUquadric gluNewQuadric() { - return new GLUquadricImpl(); -} - -/** Interface to C language function: <br> <code> void gluPartialDisk(GLUquadric * quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops, GLdouble start, GLdouble sweep); </code> */ -public void gluPartialDisk(GLUquadric quad, double inner, double outer, int slices, int loops, double start, double sweep) { - ((GLUquadricImpl) quad).drawPartialDisk(gl, (float) inner, (float) outer, slices, loops, (float) start, (float) sweep); -} - -/** Interface to C language function: <br> <code> void gluQuadricDrawStyle(GLUquadric * quad, GLenum draw); </code> */ -public void gluQuadricDrawStyle(GLUquadric quad, int draw) { - ((GLUquadricImpl) quad).setDrawStyle(draw); -} - -/** Interface to C language function: <br> <code> void gluQuadricNormals(GLUquadric * quad, GLenum normal); </code> */ -public void gluQuadricNormals(GLUquadric quad, int normal) { - ((GLUquadricImpl) quad).setNormals(normal); -} - -/** Interface to C language function: <br> <code> void gluQuadricOrientation(GLUquadric * quad, GLenum orientation); </code> */ -public void gluQuadricOrientation(GLUquadric quad, int orientation) { - ((GLUquadricImpl) quad).setOrientation(orientation); -} - -/** Interface to C language function: <br> <code> void gluQuadricTexture(GLUquadric * quad, GLboolean texture); </code> */ -public void gluQuadricTexture(GLUquadric quad, boolean texture) { - ((GLUquadricImpl) quad).setTextureFlag(texture); -} - -/** Interface to C language function: <br> <code> void gluSphere(GLUquadric * quad, GLdouble radius, GLint slices, GLint stacks); </code> */ -public void gluSphere(GLUquadric quad, double radius, int slices, int stacks) { - ((GLUquadricImpl) quad).drawSphere(gl, (float) radius, slices, stacks); -} - -//---------------------------------------------------------------------- -// Projection functionality -// - -private Project project; - -public void gluOrtho2D(double left, double right, double bottom, double top) { - project.gluOrtho2D(gl, left, right, bottom, top); -} - -public void gluPerspective(double fovy, double aspect, double zNear, double zFar) { - project.gluPerspective(gl, fovy, aspect, zNear, zFar); -} - -public void gluLookAt(double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ) { - project.gluLookAt(gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); -} - -public boolean gluProject(double objX, double objY, double objZ, double[] model, double[] proj, int[] view, double[] winX, double[] winY, double[] winZ) { - double[] tmp = new double[3]; - boolean res = project.gluProject(objX, objY, objZ, model, proj, view, tmp); - winX[0] = tmp[0]; - winY[0] = tmp[1]; - winZ[0] = tmp[2]; - return res; -} - -public boolean gluProject(double objX, double objY, double objZ, double[] model, double[] proj, int[] view, double[] winPos) { - return project.gluProject(objX, objY, objZ, model, proj, view, winPos); -} - -public boolean gluUnProject(double winX, double winY, double winZ, double[] model, double[] proj, int[] view, double[] objX, double[] objY, double[] objZ) { - double[] tmp = new double[3]; - boolean res = project.gluUnProject(winX, winY, winZ, model, proj, view, tmp); - objX[0] = tmp[0]; - objY[0] = tmp[1]; - objZ[0] = tmp[2]; - return res; -} - -public boolean gluUnProject(double winX, double winY, double winZ, double[] model, double[] proj, int[] view, double[] objPos) { - return project.gluUnProject(winX, winY, winZ, model, proj, view, objPos); -} - -public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, double[] proj, int[] view, double nearVal, double farVal, double[] objX, double[] objY, double[] objZ, double[] objW) { - double[] tmp = new double[4]; - boolean res = project.gluUnProject4(winX, winY, winZ, clipW, model, proj, view, nearVal, farVal, tmp); - objX[0] = tmp[0]; - objY[0] = tmp[1]; - objZ[0] = tmp[2]; - objW[0] = tmp[3]; - return res; -} - -public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, double[] proj, int[] view, double nearVal, double farVal, double[] objPos) { - return project.gluUnProject4(winX, winY, winZ, clipW, model, proj, view, nearVal, farVal, objPos); -} - -public void gluPickMatrix(double x, double y, double delX, double delY, int[] viewport) { - project.gluPickMatrix(gl, x, y, delX, delY, viewport); -} - -//---------------------------------------------------------------------- -// Mipmap and image scaling functionality - - -// Boolean -public static final int GLU_FALSE = 0; -public static final int GLU_TRUE = 1; - -// String Name -public static final int GLU_VERSION = 100800; -public static final int GLU_EXTENSIONS = 100801; - -// Extensions -public static final String versionString = "1.3"; -public static final String extensionString = "GLU_EXT_nurbs_tessellator " + - "GLU_EXT_object_space_tess "; - -// ErrorCode -public static final int GLU_INVALID_ENUM = 100900; -public static final int GLU_INVALID_VALUE = 100901; -public static final int GLU_OUT_OF_MEMORY = 100902; -public static final int GLU_INVALID_OPERATION = 100904; - -// NurbsDisplay -// GLU_FILL -public static final int GLU_OUTLINE_POLYGON = 100240; -public static final int GLU_OUTLINE_PATCH = 100241; - -// NurbsCallback -public static final int GLU_NURBS_ERROR = 100103; -public static final int GLU_ERROR = 100103; -public static final int GLU_NURBS_BEGIN = 100164; -public static final int GLU_NURBS_BEGIN_EXT = 100164; -public static final int GLU_NURBS_VERTEX = 100165; -public static final int GLU_NURBS_VERTEX_EXT = 100165; -public static final int GLU_NURBS_NORMAL = 100166; -public static final int GLU_NURBS_NORMAL_EXT = 100166; -public static final int GLU_NURBS_COLOR = 100167; -public static final int GLU_NURBS_COLOR_EXT = 100167; -public static final int GLU_NURBS_TEXTURE_COORD = 100168; -public static final int GLU_NURBS_TEX_COORD_EXT = 100168; -public static final int GLU_NURBS_END = 100169; -public static final int GLU_NURBS_END_EXT = 100169; -public static final int GLU_NURBS_BEGIN_DATA = 100170; -public static final int GLU_NURBS_BEGIN_DATA_EXT = 100170; -public static final int GLU_NURBS_VERTEX_DATA = 100171; -public static final int GLU_NURBS_VERTEX_DATA_EXT = 100171; -public static final int GLU_NURBS_NORMAL_DATA = 100172; -public static final int GLU_NURBS_NORMAL_DATA_EXT = 100172; -public static final int GLU_NURBS_COLOR_DATA = 100173; -public static final int GLU_NURBS_COLOR_DATA_EXT = 100173; -public static final int GLU_NURBS_TEXTURE_COORD_DATA = 100174; -public static final int GLU_NURBS_TEX_COORD_DATA_EXT = 100174; -public static final int GLU_NURBS_END_DATA = 100175; -public static final int GLU_NURBS_END_DATA_EXT = 100175; - -// NurbsError -public static final int GLU_NURBS_ERROR1 = 100251; -public static final int GLU_NURBS_ERROR2 = 100252; -public static final int GLU_NURBS_ERROR3 = 100253; -public static final int GLU_NURBS_ERROR4 = 100254; -public static final int GLU_NURBS_ERROR5 = 100255; -public static final int GLU_NURBS_ERROR6 = 100256; -public static final int GLU_NURBS_ERROR7 = 100257; -public static final int GLU_NURBS_ERROR8 = 100258; -public static final int GLU_NURBS_ERROR9 = 100259; -public static final int GLU_NURBS_ERROR10 = 100260; -public static final int GLU_NURBS_ERROR11 = 100261; -public static final int GLU_NURBS_ERROR12 = 100262; -public static final int GLU_NURBS_ERROR13 = 100263; -public static final int GLU_NURBS_ERROR14 = 100264; -public static final int GLU_NURBS_ERROR15 = 100265; -public static final int GLU_NURBS_ERROR16 = 100266; -public static final int GLU_NURBS_ERROR17 = 100267; -public static final int GLU_NURBS_ERROR18 = 100268; -public static final int GLU_NURBS_ERROR19 = 100269; -public static final int GLU_NURBS_ERROR20 = 100270; -public static final int GLU_NURBS_ERROR21 = 100271; -public static final int GLU_NURBS_ERROR22 = 100272; -public static final int GLU_NURBS_ERROR23 = 100273; -public static final int GLU_NURBS_ERROR24 = 100274; -public static final int GLU_NURBS_ERROR25 = 100275; -public static final int GLU_NURBS_ERROR26 = 100276; -public static final int GLU_NURBS_ERROR27 = 100277; -public static final int GLU_NURBS_ERROR28 = 100278; -public static final int GLU_NURBS_ERROR29 = 100279; -public static final int GLU_NURBS_ERROR30 = 100280; -public static final int GLU_NURBS_ERROR31 = 100281; -public static final int GLU_NURBS_ERROR32 = 100282; -public static final int GLU_NURBS_ERROR33 = 100283; -public static final int GLU_NURBS_ERROR34 = 100284; -public static final int GLU_NURBS_ERROR35 = 100285; -public static final int GLU_NURBS_ERROR36 = 100286; -public static final int GLU_NURBS_ERROR37 = 100287; - -// NurbsProperty -public static final int GLU_AUTO_LOAD_MATRIX = 100200; -public static final int GLU_CULLING = 100201; -public static final int GLU_SAMPLING_TOLERANCE = 100203; -public static final int GLU_DISPLAY_MODE = 100204; -public static final int GLU_PARAMETRIC_TOLERANCE = 100202; -public static final int GLU_SAMPLING_METHOD = 100205; -public static final int GLU_U_STEP = 100206; -public static final int GLU_V_STEP = 100207; -public static final int GLU_NURBS_MODE = 100160; -public static final int GLU_NURBS_MODE_EXT = 100160; -public static final int GLU_NURBS_TESSELLATOR = 100161; -public static final int GLU_NURBS_TESSELLATOR_EXT = 100161; -public static final int GLU_NURBS_RENDERER = 100162; -public static final int GLU_NURBS_RENDERER_EXT = 100162; - -// NurbsSampling -public static final int GLU_OBJECT_PARAMETRIC_ERROR = 100208; -public static final int GLU_OBJECT_PARAMETRIC_ERROR_EXT = 100208; -public static final int GLU_OBJECT_PATH_LENGTH = 100209; -public static final int GLU_OBJECT_PATH_LENGTH_EXT = 100209; -public static final int GLU_PATH_LENGTH = 100215; -public static final int GLU_PARAMETRIC_ERROR = 100216; -public static final int GLU_DOMAIN_DISTANCE = 100217; - -// NurbsTrim -public static final int GLU_MAP1_TRIM_2 = 100210; -public static final int GLU_MAP1_TRIM_3 = 100211; - -// QuadricDrawStyle -public static final int GLU_POINT = 100010; -public static final int GLU_LINE = 100011; -public static final int GLU_FILL = 100012; -public static final int GLU_SILHOUETTE = 100013; - -// QuadricCallback -// GLU_ERROR - -// QuadricNormal -public static final int GLU_SMOOTH = 100000; -public static final int GLU_FLAT = 100001; -public static final int GLU_NONE = 100002; - -// QuadricOrientation -public static final int GLU_OUTSIDE = 100020; -public static final int GLU_INSIDE = 100021; - -// TessCallback -public static final int GLU_TESS_BEGIN = 100100; -public static final int GLU_BEGIN = 100100; -public static final int GLU_TESS_VERTEX = 100101; -public static final int GLU_VERTEX = 100101; -public static final int GLU_TESS_END = 100102; -public static final int GLU_END = 100102; -public static final int GLU_TESS_ERROR = 100103; -public static final int GLU_TESS_EDGE_FLAG = 100104; -public static final int GLU_EDGE_FLAG = 100104; -public static final int GLU_TESS_COMBINE = 100105; -public static final int GLU_TESS_BEGIN_DATA = 100106; -public static final int GLU_TESS_VERTEX_DATA = 100107; -public static final int GLU_TESS_END_DATA = 100108; -public static final int GLU_TESS_ERROR_DATA = 100109; -public static final int GLU_TESS_EDGE_FLAG_DATA = 100110; -public static final int GLU_TESS_COMBINE_DATA = 100111; - -// TessContour -public static final int GLU_CW = 100120; -public static final int GLU_CCW = 100121; -public static final int GLU_INTERIOR = 100122; -public static final int GLU_EXTERIOR = 100123; -public static final int GLU_UNKNOWN = 100124; - -// TessProperty -public static final int GLU_TESS_WINDING_RULE = 100140; -public static final int GLU_TESS_BOUNDRY_ONLY = 100141; -public static final int GLU_TESS_TOLERANCE = 100142; - -// TessError -public static final int GLU_TESS_ERROR1 = 100151; -public static final int GLU_TESS_ERROR2 = 100152; -public static final int GLU_TESS_ERROR3 = 100153; -public static final int GLU_TESS_ERROR4 = 100154; -public static final int GLU_TESS_ERROR5 = 100155; -public static final int GLU_TESS_ERROR6 = 100156; -public static final int GLU_TESS_ERROR7 = 100157; -public static final int GLU_TESS_ERROR8 = 100158; -public static final int GLU_TESS_MISSING_BEGIN_POLYGON = 100151; -public static final int GLU_TESS_MISSING_BEGIN_CONTOUR = 100152; -public static final int GLU_TESS_MISSING_END_POLYGON = 100153; -public static final int GLU_TESS_MISSING_END_CONTOUR = 100154; -public static final int GLU_TESS_COORD_TOO_LARGE = 100155; -public static final int GLU_TESS_NEED_COMBINE_CALLBACK = 100156; - -// TessWinding -public static final int GLU_TESS_WINDING_ODD = 100130; -public static final int GLU_TESS_WINDING_NONZERO = 100131; -public static final int GLU_TESS_WINDING_POSITIVE = 100132; -public static final int GLU_TESS_WINDING_NEGATIVE = 100133; -public static final int GLU_TESS_WINDING_ABS_GEQ_TWO = 100134; - -public int gluScaleImageJava( int format, int widthin, int heightin, - int typein, Object datain, int widthout, int heightout, - int typeout, Object dataout ) { - ByteBuffer in = null; - ByteBuffer out = null; - if( datain instanceof ByteBuffer ) { - in = (ByteBuffer)datain; - } else if( datain instanceof byte[] ) { - in = ByteBuffer.allocateDirect( ((byte[])datain).length ).order( ByteOrder.nativeOrder() ); - in.put((byte[]) datain).rewind(); - } else if( datain instanceof short[] ) { - in = ByteBuffer.allocateDirect( ((byte[])datain).length * 2 ).order( ByteOrder.nativeOrder() ); - in.asShortBuffer().put((short[]) datain).rewind(); - } else if( datain instanceof int[] ) { - in = ByteBuffer.allocateDirect( ((byte[])datain).length * 4 ).order( ByteOrder.nativeOrder() ); - in.asIntBuffer().put((int[]) datain).rewind(); - } else if( datain instanceof float[] ) { - in = ByteBuffer.allocateDirect( ((byte[])datain).length * 4 ).order( ByteOrder.nativeOrder() ); - in.asFloatBuffer().put((float[]) datain).rewind(); - } else { - throw new IllegalArgumentException( "Input data must be a primitive array or a ByteBuffer" ); - } - if( dataout instanceof ByteBuffer ) { - out = (ByteBuffer)dataout; - } else if( dataout instanceof byte[] ) { - out = ByteBuffer.wrap( ((byte[])dataout) ); - } else if( dataout instanceof short[] ) { - out = ByteBuffer.allocate( ((short[])dataout).length * 2 ); - } else if( dataout instanceof int[] ) { - out = ByteBuffer.allocate( ((int[])dataout).length * 4 ); - } else if( dataout instanceof float[] ) { - out = ByteBuffer.allocate( ((float[])dataout).length * 4 ); - } else { - throw new IllegalArgumentException( "Output data must be a primitive array or a ByteBuffer" ); - } - int errno = Mipmap.gluScaleImage( gl, format, widthin, heightin, typein, in, - widthout, heightout, typeout, out ); - if( errno == 0 ) { - if( dataout instanceof short[] ) { - out.asShortBuffer().get( (short[])dataout ); - } else if( dataout instanceof int[] ) { - out.asIntBuffer().get( (int[])dataout ); - } else if( dataout instanceof float[] ) { - out.asFloatBuffer().get( (float[])dataout ); - } - } - return( errno ); -} - -public int gluBuild1DMipmapLevelsJava( int target, int internalFormat, int width, - int format, int type, int userLevel, int baseLevel, int maxLevel, - Object data ) { - ByteBuffer buffer = null; - if( data instanceof ByteBuffer ) { - buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - buffer = ByteBuffer.allocateDirect( ((byte[])data).length ).order( ByteOrder.nativeOrder() ); - buffer.put( (byte[])data ); - } else if( data instanceof short[] ) { - buffer = ByteBuffer.allocateDirect( ((short[])data).length * 2 ).order( ByteOrder.nativeOrder() ); - buffer.asShortBuffer().put( (short[])data ); - } else if( data instanceof int[] ) { - buffer = ByteBuffer.allocateDirect( ((int[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asIntBuffer().put( (int[])data ); - } else if( data instanceof float[] ) { - buffer = ByteBuffer.allocateDirect( ((float[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asFloatBuffer().put( (float[])data ); - } else { - throw new IllegalArgumentException( "Input data must be a primitive array or a ByteBuffer" ); - } - return( Mipmap.gluBuild1DMipmapLevels( gl, target, internalFormat, width, - format, type, userLevel, baseLevel, maxLevel, buffer ) ); -} - -public int gluBuild1DMipmapsJava( int target, int internalFormat, int width, - int format, int type, Object data ) { - ByteBuffer buffer = null; - if( data instanceof ByteBuffer ) { - buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - buffer = ByteBuffer.allocateDirect( ((byte[])data).length ).order( ByteOrder.nativeOrder() ); - buffer.put( (byte[])data ); - } else if( data instanceof short[] ) { - buffer = ByteBuffer.allocateDirect( ((short[])data).length * 2 ).order( ByteOrder.nativeOrder() ); - buffer.asShortBuffer().put( (short[])data ); - } else if( data instanceof int[] ) { - buffer = ByteBuffer.allocateDirect( ((int[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asIntBuffer().put( (int[])data ); - } else if( data instanceof float[] ) { - buffer = ByteBuffer.allocateDirect( ((float[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asFloatBuffer().put( (float[])data ); - } else { - throw new IllegalArgumentException( "Input data must be a primitive array or a ByteBuffer" ); - } - return( Mipmap.gluBuild1DMipmaps( gl, target, internalFormat, width, format, - type, buffer ) ); -} - -public int gluBuild2DMipmapLevelsJava( int target, int internalFormat, int width, - int height, int format, int type, int userLevel, int baseLevel, - int maxLevel, Object data ) { - return( Mipmap.gluBuild2DMipmapLevels( gl, target, internalFormat, width, - height, format, type, userLevel, baseLevel, maxLevel, data ) ); -} - -public int gluBuild2DMipmapsJava( int target, int internalFormat, int width, - int height, int format, int type, Object data ) { - return( Mipmap.gluBuild2DMipmaps( gl, target, internalFormat, width, height, - format, type, data ) ); -} - -public int gluBuild3DMipmapLevelsJava( int target, int internalFormat, int width, - int height, int depth, int format, int type, int userLevel, int baseLevel, - int maxLevel, Object data ) { - ByteBuffer buffer = null; - if( data instanceof ByteBuffer ) { - buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - buffer = ByteBuffer.allocateDirect( ((byte[])data).length ).order( ByteOrder.nativeOrder() ); - buffer.put( (byte[])data ); - } else if( data instanceof short[] ) { - buffer = ByteBuffer.allocateDirect( ((short[])data).length * 2 ).order( ByteOrder.nativeOrder() ); - buffer.asShortBuffer().put( (short[])data ); - } else if( data instanceof int[] ) { - buffer = ByteBuffer.allocateDirect( ((int[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asIntBuffer().put( (int[])data ); - } else if( data instanceof float[] ) { - buffer = ByteBuffer.allocateDirect( ((float[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asFloatBuffer().put( (float[])data ); - } else { - throw new IllegalArgumentException( "Input data must be a primitive array or a ByteBuffer" ); - } - return( Mipmap.gluBuild3DMipmapLevels( gl, target, internalFormat, width, - height, depth, format, type, userLevel, baseLevel, maxLevel, buffer ) ); -} - -public int gluBuild3DMipmapsJava( int target, int internalFormat, int width, - int height, int depth, int format, int type, Object data ) { - ByteBuffer buffer = null; - if( data instanceof ByteBuffer ) { - buffer = (ByteBuffer)data; - } else if( data instanceof byte[] ) { - buffer = ByteBuffer.allocateDirect( ((byte[])data).length ).order( ByteOrder.nativeOrder() ); - buffer.put( (byte[])data ); - } else if( data instanceof short[] ) { - buffer = ByteBuffer.allocateDirect( ((short[])data).length * 2 ).order( ByteOrder.nativeOrder() ); - buffer.asShortBuffer().put( (short[])data ); - } else if( data instanceof int[] ) { - buffer = ByteBuffer.allocateDirect( ((int[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asIntBuffer().put( (int[])data ); - } else if( data instanceof float[] ) { - buffer = ByteBuffer.allocateDirect( ((float[])data).length * 4 ).order( ByteOrder.nativeOrder() ); - buffer.asFloatBuffer().put( (float[])data ); - } else { - throw new IllegalArgumentException( "Input data must be a primitive array or a ByteBuffer" ); - } - return( Mipmap.gluBuild3DMipmaps( gl, target, internalFormat, width, height, - depth, format, type, buffer ) ); -} - - -//---------------------------------------------------------------------- -// Wrappers for mipmap and image scaling entry points which dispatch either -// to the Java or C versions. -// - - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); - } else { - return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); - } else { - return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); - } else { - return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); - } else { - return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapLevelsJava(target, internalFormat, width, format, type, level, base, max, data); - } else { - return gluBuild1DMipmapLevelsC(target, internalFormat, width, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapsJava(target, internalFormat, width, format, type, data); - } else { - return gluBuild1DMipmapsC(target, internalFormat, width, format, type, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, short[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapsJava(target, internalFormat, width, format, type, data); - } else { - return gluBuild1DMipmapsC(target, internalFormat, width, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, int[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapsJava(target, internalFormat, width, format, type, data); - } else { - return gluBuild1DMipmapsC(target, internalFormat, width, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, float[] data) { - if (useJavaMipmapCode) { - return gluBuild1DMipmapsJava(target, internalFormat, width, format, type, data); - } else { - return gluBuild1DMipmapsC(target, internalFormat, width, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); - } else { - return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); - } -} - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); - } else { - return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); - } else { - return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); - } else { - return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapLevelsJava(target, internalFormat, width, height, format, type, level, base, max, data); - } else { - return gluBuild2DMipmapLevelsC(target, internalFormat, width, height, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); - } else { - return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, short[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); - } else { - return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, int[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); - } else { - return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, float[] data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); - } else { - return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, java.nio.Buffer data) { - if (useJavaMipmapCode) { - return gluBuild2DMipmapsJava(target, internalFormat, width, height, format, type, data); - } else { - return gluBuild2DMipmapsC(target, internalFormat, width, height, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } else { - return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } else { - return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } else { - return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } else { - return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapLevelsJava(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } else { - return gluBuild3DMipmapLevelsC(target, internalFormat, width, height, depth, format, type, level, base, max, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); - } else { - return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); - } else { - return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); - } else { - return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); - } else { - return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data) { - if (useJavaMipmapCode) { - return gluBuild3DMipmapsJava(target, internalFormat, width, height, depth, format, type, data); - } else { - return gluBuild3DMipmapsC(target, internalFormat, width, height, depth, format, type, data); - } -} - - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, byte[] dataIn, int wOut, int hOut, int typeOut, byte[] dataOut) { - if (useJavaMipmapCode) { - return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } else { - return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } -} - - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, short[] dataIn, int wOut, int hOut, int typeOut, short[] dataOut) { - if (useJavaMipmapCode) { - return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } else { - return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } -} - - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, int[] dataIn, int wOut, int hOut, int typeOut, int[] dataOut) { - if (useJavaMipmapCode) { - return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } else { - return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } -} - - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, float[] dataIn, int wOut, int hOut, int typeOut, float[] dataOut) { - if (useJavaMipmapCode) { - return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } else { - return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } -} - - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, java.nio.Buffer dataIn, int wOut, int hOut, int typeOut, java.nio.Buffer dataOut) { - if (useJavaMipmapCode) { - return gluScaleImageJava(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } else { - return gluScaleImageC(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut); - } -} - - - -//---------------------------------------------------------------------- -// Wrappers for C entry points for mipmap and scaling functionality. -// (These are only used as a fallback and will be removed in a future release) - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild1DMipmapLevelsC(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmapLevels\" not available"); - } - return dispatch_gluBuild1DMipmapLevels(target, internalFormat, width, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild1DMipmapLevelsC(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmapLevels\" not available"); - } - return dispatch_gluBuild1DMipmapLevels(target, internalFormat, width, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild1DMipmapLevelsC(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmapLevels\" not available"); - } - return dispatch_gluBuild1DMipmapLevels(target, internalFormat, width, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data, long glProcAddress); - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild1DMipmapLevelsC(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmapLevels\" not available"); - } - return dispatch_gluBuild1DMipmapLevels(target, internalFormat, width, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data, long glProcAddress); - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild1DMipmapLevelsC(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmapLevels\" not available"); - } - return dispatch_gluBuild1DMipmapLevels(target, internalFormat, width, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - native private int dispatch_gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data, long glProcAddress); - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild1DMipmapsC(int target, int internalFormat, int width, int format, int type, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmaps\" not available"); - } - return dispatch_gluBuild1DMipmaps(target, internalFormat, width, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild1DMipmapsC(int target, int internalFormat, int width, int format, int type, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmaps\" not available"); - } - return dispatch_gluBuild1DMipmaps(target, internalFormat, width, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild1DMipmapsC(int target, int internalFormat, int width, int format, int type, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmaps\" not available"); - } - return dispatch_gluBuild1DMipmaps(target, internalFormat, width, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, int[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild1DMipmapsC(int target, int internalFormat, int width, int format, int type, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmaps\" not available"); - } - return dispatch_gluBuild1DMipmaps(target, internalFormat, width, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, float[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild1DMipmapsC(int target, int internalFormat, int width, int format, int type, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild1DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild1DMipmaps\" not available"); - } - return dispatch_gluBuild1DMipmaps(target, internalFormat, width, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ - native private int dispatch_gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, java.nio.Buffer data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild2DMipmapLevelsC(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmapLevels\" not available"); - } - return dispatch_gluBuild2DMipmapLevels(target, internalFormat, width, height, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild2DMipmapLevelsC(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmapLevels\" not available"); - } - return dispatch_gluBuild2DMipmapLevels(target, internalFormat, width, height, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild2DMipmapLevelsC(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmapLevels\" not available"); - } - return dispatch_gluBuild2DMipmapLevels(target, internalFormat, width, height, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild2DMipmapLevelsC(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmapLevels\" not available"); - } - return dispatch_gluBuild2DMipmapLevels(target, internalFormat, width, height, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild2DMipmapLevelsC(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmapLevels\" not available"); - } - return dispatch_gluBuild2DMipmapLevels(target, internalFormat, width, height, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - native private int dispatch_gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild2DMipmapsC(int target, int internalFormat, int width, int height, int format, int type, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmaps\" not available"); - } - return dispatch_gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild2DMipmapsC(int target, int internalFormat, int width, int height, int format, int type, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmaps\" not available"); - } - return dispatch_gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild2DMipmapsC(int target, int internalFormat, int width, int height, int format, int type, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmaps\" not available"); - } - return dispatch_gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, int[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild2DMipmapsC(int target, int internalFormat, int width, int height, int format, int type, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmaps\" not available"); - } - return dispatch_gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, float[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild2DMipmapsC(int target, int internalFormat, int width, int height, int format, int type, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild2DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild2DMipmaps\" not available"); - } - return dispatch_gluBuild2DMipmaps(target, internalFormat, width, height, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ - native private int dispatch_gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, java.nio.Buffer data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild3DMipmapLevelsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmapLevels\" not available"); - } - return dispatch_gluBuild3DMipmapLevels(target, internalFormat, width, height, depth, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild3DMipmapLevelsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmapLevels\" not available"); - } - return dispatch_gluBuild3DMipmapLevels(target, internalFormat, width, height, depth, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild3DMipmapLevelsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmapLevels\" not available"); - } - return dispatch_gluBuild3DMipmapLevels(target, internalFormat, width, height, depth, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild3DMipmapLevelsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmapLevels\" not available"); - } - return dispatch_gluBuild3DMipmapLevels(target, internalFormat, width, height, depth, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - public int gluBuild3DMipmapLevelsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmapLevels; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmapLevels\" not available"); - } - return dispatch_gluBuild3DMipmapLevels(target, internalFormat, width, height, depth, format, type, level, base, max, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ - native private int dispatch_gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild3DMipmapsC(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmaps\" not available"); - } - return dispatch_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild3DMipmapsC(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmaps\" not available"); - } - return dispatch_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild3DMipmapsC(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmaps\" not available"); - } - return dispatch_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild3DMipmapsC(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data) - { - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmaps\" not available"); - } - return dispatch_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - private native int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - public int gluBuild3DMipmapsC(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data) - { - if (!BufferFactory.isDirect(data)) - throw new GLException("Argument \"data\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluBuild3DMipmaps; - if (__addr_ == 0) { - throw new GLException("Method \"gluBuild3DMipmaps\" not available"); - } - return dispatch_gluBuild3DMipmaps(target, internalFormat, width, height, depth, format, type, data, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ - native private int dispatch_gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - public int gluScaleImageC(int format, int wIn, int hIn, int typeIn, byte[] dataIn, int wOut, int hOut, int typeOut, byte[] dataOut) - { - final long __addr_ = gluProcAddressTable._addressof_gluScaleImage; - if (__addr_ == 0) { - throw new GLException("Method \"gluScaleImage\" not available"); - } - return dispatch_gluScaleImage(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - private native int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, byte[] dataIn, int wOut, int hOut, int typeOut, byte[] dataOut, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - public int gluScaleImageC(int format, int wIn, int hIn, int typeIn, short[] dataIn, int wOut, int hOut, int typeOut, short[] dataOut) - { - final long __addr_ = gluProcAddressTable._addressof_gluScaleImage; - if (__addr_ == 0) { - throw new GLException("Method \"gluScaleImage\" not available"); - } - return dispatch_gluScaleImage(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - private native int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, short[] dataIn, int wOut, int hOut, int typeOut, short[] dataOut, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - public int gluScaleImageC(int format, int wIn, int hIn, int typeIn, int[] dataIn, int wOut, int hOut, int typeOut, int[] dataOut) - { - final long __addr_ = gluProcAddressTable._addressof_gluScaleImage; - if (__addr_ == 0) { - throw new GLException("Method \"gluScaleImage\" not available"); - } - return dispatch_gluScaleImage(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - private native int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, int[] dataIn, int wOut, int hOut, int typeOut, int[] dataOut, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - public int gluScaleImageC(int format, int wIn, int hIn, int typeIn, float[] dataIn, int wOut, int hOut, int typeOut, float[] dataOut) - { - final long __addr_ = gluProcAddressTable._addressof_gluScaleImage; - if (__addr_ == 0) { - throw new GLException("Method \"gluScaleImage\" not available"); - } - return dispatch_gluScaleImage(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - private native int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, float[] dataIn, int wOut, int hOut, int typeOut, float[] dataOut, long glProcAddress); - - - /** Entry point to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - public int gluScaleImageC(int format, int wIn, int hIn, int typeIn, java.nio.Buffer dataIn, int wOut, int hOut, int typeOut, java.nio.Buffer dataOut) - { - if (!BufferFactory.isDirect(dataIn)) - throw new GLException("Argument \"dataIn\" was not a direct buffer"); - if (!BufferFactory.isDirect(dataOut)) - throw new GLException("Argument \"dataOut\" was not a direct buffer"); - final long __addr_ = gluProcAddressTable._addressof_gluScaleImage; - if (__addr_ == 0) { - throw new GLException("Method \"gluScaleImage\" not available"); - } - return dispatch_gluScaleImage(format, wIn, hIn, typeIn, dataIn, wOut, hOut, typeOut, dataOut, __addr_); - } - - /** Encapsulates function pointer for OpenGL function <br>: <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ - native private int dispatch_gluScaleImage(int format, int wIn, int hIn, int typeIn, java.nio.Buffer dataIn, int wOut, int hOut, int typeOut, java.nio.Buffer dataOut, long glProcAddress); - - - diff --git a/make/glu-impl-common.cfg b/make/glu-impl-common.cfg deleted file mode 100644 index 6710d0369..000000000 --- a/make/glu-impl-common.cfg +++ /dev/null @@ -1,22 +0,0 @@ -# This .cfg file contains common directives used when generating the -# GLU implementation class on all platforms. - -Include glu-common.cfg - -Style ImplOnly - -EmitProcAddressTable true -ProcAddressTableClassName GLUProcAddressTable -GetProcAddressTableExpr gluProcAddressTable - -# GLUImpl needs access to the GLUtesselatorImpl class for GLUtesselator -# and to the Mipmap class for scaling and mipmap generation -Import net.java.games.jogl.impl.tesselator.GLUtesselatorImpl -Import net.java.games.jogl.impl.mipmap.Mipmap -Import java.security.* - -# Custom Java code for GLUImpl class -IncludeAs CustomJavaCode GLUImpl glu-impl-common-CustomJavaCode.java - -# Custom C code for GLUImpl class -IncludeAs CustomCCode glu-impl-common-CustomCCode.c diff --git a/make/glu-impl-win32-GLU13Hacks.cfg b/make/glu-impl-win32-GLU13Hacks.cfg deleted file mode 100644 index 186ee5ca1..000000000 --- a/make/glu-impl-win32-GLU13Hacks.cfg +++ /dev/null @@ -1,122 +0,0 @@ -#### FIXME!!!!!!! -# win32 only ships with GLU 1.2 support so we can't link -# the native JNI bindings. -# -# For now, don't autogenerate bindings for these GLU 1.3 routines on -# win32. What we'll do instead is implement them by hand, and make -# them throw exceptions for the time being until we have a GLU1.3 -# solution for win32. -Ignore gluBuild(1|2|3)DMipmapLevels -Ignore gluBuild3DMipmaps -Ignore gluCheckExtension - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, boolean[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, char[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, long[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, double[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, boolean[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, char[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, long[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, double[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, boolean[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, char[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, long[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, double[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, boolean[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, char[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, long[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, double[] data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *CustomJavaCode GLUImpl data); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } - -CustomJavaCode GLUImpl /** Entry point to C language function: <br> <code> GLboolean gluCheckExtension(const GLubyte *CustomJavaCode GLUImpl extName, const GLubyte *CustomJavaCode GLUImpl extString); </code>CustomJavaCode GLUImpl CustomJavaCode GLUImpl */ -CustomJavaCode GLUImpl public boolean gluCheckExtension(java.lang.String extName, java.lang.String extString) { throw new GLException("This GLU 1.3 function is not available on Win32 platforms because Microsoft Windows ships with a GLU 1.2 implementation"); } diff --git a/make/glu-interface-common-CustomJavaCode.java b/make/glu-interface-common-CustomJavaCode.java deleted file mode 100644 index 8be08f0a6..000000000 --- a/make/glu-interface-common-CustomJavaCode.java +++ /dev/null @@ -1,982 +0,0 @@ -//---------------------------------------------------------------------- -// Projection routines -// - -/** Interface to C language function: <br> <code> GLint gluProject(GLdouble objX, GLdouble objY, GLdouble objZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble * winX, GLdouble * winY, GLdouble * winZ); </code> */ -public boolean gluProject(double objX, double objY, double objZ, double[] model, double[] proj, int[] view, double[] winX, double[] winY, double[] winZ); - -/** - * Convenience routine for gluProject that accepts the outgoing window - * coordinates as a single array. - */ -public boolean gluProject(double objx, - double objy, - double objz, - double[] modelMatrix, - double[] projMatrix, - int[] viewport, - double[] winPos); - -/** Interface to C language function: <br> <code> GLint gluUnProject(GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble * objX, GLdouble * objY, GLdouble * objZ); </code> */ -public boolean gluUnProject(double winX, double winY, double winZ, double[] model, double[] proj, int[] view, double[] objX, double[] objY, double[] objZ); - -/** - * Convenience routine for gluUnProject that accepts the outgoing - * object coordinates (a 3-vector) as a single array. - */ -public boolean gluUnProject(double winX, double winY, double winZ, double[] model, double[] proj, int[] view, double[] objPos); - -/** Interface to C language function: <br> <code> GLint gluUnProject4(GLdouble winX, GLdouble winY, GLdouble winZ, GLdouble clipW, const GLdouble * model, const GLdouble * proj, const GLint * view, GLdouble nearVal, GLdouble farVal, GLdouble * objX, GLdouble * objY, GLdouble * objZ, GLdouble * objW); </code> */ -public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, double[] proj, int[] view, double nearVal, double farVal, double[] objX, double[] objY, double[] objZ, double[] objW); - -/** - * Convenience routine for gluUnProject4 that accepts the outgoing - * object coordinates (a 4-vector) as a single array. - */ -public boolean gluUnProject4(double winX, double winY, double winZ, double clipW, double[] model, double[] proj, int[] view, double nearVal, double farVal, double[] objPos); - - - -//---------------------------------------------------------------------- -// Tesselation routines -// - -/***************************************************************************** - * <b>gluBeginPolygon</b> and {@link net.java.games.jogl.GLU#gluEndPolygon - * gluEndPolygon} delimit the definition of a nonconvex polygon. To define - * such a polygon, first call <b>gluBeginPolygon</b>. Then define the contours - * of the polygon by calling {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex} for each vertex and - * {@link net.java.games.jogl.GLU#gluNextContour gluNextContour} to start each - * new contour. Finally, call {@link net.java.games.jogl.GLU#gluEndPolygon - * gluEndPolygon} to signal the end of the definition. See the - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex} and - * {@link net.java.games.jogl.GLU#gluNextContour gluNextContour} reference - * pages for more details.<P> - * - * Once {@link net.java.games.jogl.GLU#gluEndPolygon gluEndPolygon} is called, - * the polygon is tessellated, and the resulting triangles are described - * through callbacks. See {@link net.java.games.jogl.GLU#gluTessCallback - * gluTessCallback} for descriptions of the callback methods. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluNextContour gluNextContour - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - ****************************************************************************/ -public void gluBeginPolygon(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluDeleteTess</b> destroys the indicated tessellation object (which was - * created with {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @param tesselator - * Specifies the tessellation object to destroy. - * - * @see net.java.games.jogl.GLU#gluBeginPolygon gluBeginPolygon - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - ****************************************************************************/ -public void gluDeleteTess(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluEndPolygon</b> and {@link net.java.games.jogl.GLU#gluBeginPolygon - * gluBeginPolygon} delimit the definition of a nonconvex polygon. To define - * such a polygon, first call {@link net.java.games.jogl.GLU#gluBeginPolygon - * gluBeginPolygon}. Then define the contours of the polygon by calling - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex} for each vertex - * and {@link net.java.games.jogl.GLU#gluNextContour gluNextContour} to start - * each new contour. Finally, call <b>gluEndPolygon</b> to signal the end of - * the definition. See the {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex} and {@link net.java.games.jogl.GLU#gluNextContour - * gluNextContour} reference pages for more details.<P> - * - * Once <b>gluEndPolygon</b> is called, the polygon is tessellated, and the - * resulting triangles are described through callbacks. See - * {@link net.java.games.jogl.GLU#gluTessCallback gluTessCallback} for - * descriptions of the callback methods. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluNextContour gluNextContour - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - ****************************************************************************/ -public void gluEndPolygon(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluGetTessProperty</b> retrieves properties stored in a tessellation - * object. These properties affect the way that tessellation objects are - * interpreted and rendered. See the - * {@link net.java.games.jogl.GLU#gluTessProperty gluTessProperty} reference - * page for information about the properties and what they do. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param which - * Specifies the property whose value is to be fetched. Valid values - * are <b>GLU_TESS_WINDING_RULE</b>, <b>GLU_TESS_BOUNDARY_ONLY</b>, - * and <b>GLU_TESS_TOLERANCES</b>. - * @param value - * Specifices an array into which the value of the named property is - * written. - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - ****************************************************************************/ -public void gluGetTessProperty(GLUtesselator tesselator, int which, double[] value); - - -/***************************************************************************** - * <b>gluNewTess</b> creates and returns a new tessellation object. This - * object must be referred to when calling tesselation methods. A return - * value of null means that there was not enough memeory to allocate the - * object. - * - * @return A new tessellation object. - * - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluDeleteTess gluDeleteTess - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - ****************************************************************************/ -public GLUtesselator gluNewTess(); - - -/***************************************************************************** - * <b>gluNextContour</b> is used to describe polygons with multiple - * contours. After you describe the first contour through a series of - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex} calls, a - * <b>gluNextContour</b> call indicates that the previous contour is complete - * and that the next contour is about to begin. Perform another series of - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex} calls to - * describe the new contour. Repeat this process until all contours have been - * described.<P> - * - * The type parameter defines what type of contour follows. The following - * values are valid. <P> - * - * <b>GLU_EXTERIOR</b> - * <UL> - * An exterior contour defines an exterior boundary of the polygon. - * </UL> - * <b>GLU_INTERIOR</b> - * <UL> - * An interior contour defines an interior boundary of the polygon (such as - * a hole). - * </UL> - * <b>GLU_UNKNOWN</b> - * <UL> - * An unknown contour is analyzed by the library to determine whether it is - * interior or exterior. - * </UL> - * <b>GLU_CCW, GLU_CW</b> - * <UL> - * The first <b>GLU_CCW</b> or <b>GLU_CW</b> contour defined is considered - * to be exterior. All other contours are considered to be exterior if they - * are oriented in the same direction (clockwise or counterclockwise) as the - * first contour, and interior if they are not. If one contour is of type - * <b>GLU_CCW</b> or <b>GLU_CW</b>, then all contours must be of the same - * type (if they are not, then all <b>GLU_CCW</b> and <b>GLU_CW</b> contours - * will be changed to <b>GLU_UNKNOWN</b>). Note that there is no - * real difference between the <b>GLU_CCW</b> and <b>GLU_CW</b> contour - * types. - * </UL><P> - * - * To define the type of the first contour, you can call <b>gluNextContour</b> - * before describing the first contour. If you do not call - * <b>gluNextContour</b> before the first contour, the first contour is marked - * <b>GLU_EXTERIOR</b>.<P> - * - * <UL> - * <b>Note:</b> The <b>gluNextContour</b> function is obsolete and is - * provided for backward compatibility only. The <b>gluNextContour</b> - * function is mapped to {@link net.java.games.jogl.GLU#gluTessEndContour - * gluTessEndContour} followed by - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour}. - * </UL> - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param type - * The type of the contour being defined. - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessEndContour gluTessEndContour - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - ****************************************************************************/ -public void gluNextContour(GLUtesselator tesselator, int type); - - -/***************************************************************************** - * <b>gluTessBeginContour</b> and - * {@link net.java.games.jogl.GLU#gluTessEndContour gluTessEndContour} delimit - * the definition of a polygon contour. Within each - * <b>gluTessBeginContour</b>/ - * {@link net.java.games.jogl.GLU#gluTessEndContour gluTessEndContour} pair, - * there can be zero or more calls to - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex}. The vertices - * specify a closed contour (the last vertex of each contour is automatically - * linked to the first). See the {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex} reference page for more details. <b>gluTessBeginContour</b> - * can only be called between - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} and - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon}. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - * @see net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon - ****************************************************************************/ -public void gluTessBeginContour(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluTessBeginPolygon</b> and - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon} delimit - * the definition of a convex, concave or self-intersecting polygon. Within - * each <b>gluTessBeginPolygon</b>/ - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon} pair, - * there must be one or more calls to - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour}/ - * {@link net.java.games.jogl.GLU#gluTessEndContour gluTessEndContour}. Within - * each contour, there are zero or more calls to - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex}. The vertices - * specify a closed contour (the last vertex of each contour is automatically - * linked to the first). See the {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex}, {@link net.java.games.jogl.GLU#gluTessBeginContour - * gluTessBeginContour}, and {@link net.java.games.jogl.GLU#gluTessEndContour - * gluTessEndContour} reference pages for more details.<P> - * - * <b>data</b> is a reference to a user-defined data structure. If the - * appropriate callback(s) are specified (see - * {@link net.java.games.jogl.GLU#gluTessCallback gluTessCallback}), then this - * reference is returned to the callback method(s). Thus, it is a convenient - * way to store per-polygon information.<P> - * - * Once {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon} is - * called, the polygon is tessellated, and the resulting triangles are - * described through callbacks. See - * {@link net.java.games.jogl.GLU#gluTessCallback gluTessCallback} for - * descriptions of the callback methods. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param data - * Specifies a reference to user polygon data. - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - * @see net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon - ****************************************************************************/ -public void gluTessBeginPolygon(GLUtesselator tesselator, Object data); - - -/***************************************************************************** - * <b>gluTessCallback</b> is used to indicate a callback to be used by a - * tessellation object. If the specified callback is already defined, then it - * is replaced. If <i>aCallback</i> is null, then the existing callback - * becomes undefined.<P> - * - * These callbacks are used by the tessellation object to describe how a - * polygon specified by the user is broken into triangles. Note that there are - * two versions of each callback: one with user-specified polygon data and one - * without. If both versions of a particular callback are specified, then the - * callback with user-specified polygon data will be used. Note that the - * polygonData parameter used by some of the methods is a copy of the - * reference that was specified when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The legal callbacks are as follows:<P> - * - * <b>GLU_TESS_BEGIN</b> - * <UL> - * The begin callback is invoked like {@link net.java.games.jogl.GL#glBegin - * glBegin} to indicate the start of a (triangle) primitive. The method - * takes a single argument of type int. If the - * <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_FALSE</b>, then - * the argument is set to either <b>GL_TRIANGLE_FAN</b>, - * <b>GL_TRIANGLE_STRIP</b>, or <b>GL_TRIANGLES</b>. If the - * <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_TRUE</b>, then the - * argument will be set to <b>GL_LINE_LOOP</b>. The method prototype for - * this callback is: - * </UL> - * - * <PRE> - * void begin(int type);</PRE><P> - * - * <b>GLU_TESS_BEGIN_DATA</b> - * <UL> - * The same as the <b>GLU_TESS_BEGIN</b> callback except - * that it takes an additional reference argument. This reference is - * identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void beginData(int type, Object polygonData);</PRE> - * - * <b>GLU_TESS_EDGE_FLAG</b> - * <UL> - * The edge flag callback is similar to - * {@link net.java.games.jogl.GL#glEdgeFlag glEdgeFlag}. The method takes - * a single boolean boundaryEdge that indicates which edges lie on the - * polygon boundary. If the boundaryEdge is <b>GL_TRUE</b>, then each vertex - * that follows begins an edge that lies on the polygon boundary, that is, - * an edge that separates an interior region from an exterior one. If the - * boundaryEdge is <b>GL_FALSE</b>, then each vertex that follows begins an - * edge that lies in the polygon interior. The edge flag callback (if - * defined) is invoked before the first vertex callback.<P> - * - * Since triangle fans and triangle strips do not support edge flags, the - * begin callback is not called with <b>GL_TRIANGLE_FAN</b> or - * <b>GL_TRIANGLE_STRIP</b> if a non-null edge flag callback is provided. - * (If the callback is initialized to null, there is no impact on - * performance). Instead, the fans and strips are converted to independent - * triangles. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void edgeFlag(boolean boundaryEdge);</PRE> - * - * <b>GLU_TESS_EDGE_FLAG_DATA</b> - * <UL> - * The same as the <b>GLU_TESS_EDGE_FLAG</b> callback except that it takes - * an additional reference argument. This reference is identical to the - * opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void edgeFlagData(boolean boundaryEdge, Object polygonData);</PRE> - * - * <b>GLU_TESS_VERTEX</b> - * <UL> - * The vertex callback is invoked between the begin and end callbacks. It is - * similar to {@link net.java.games.jogl.GL#glVertex3f glVertex3f}, and it - * defines the vertices of the triangles created by the tessellation - * process. The method takes a reference as its only argument. This - * reference is identical to the opaque reference provided by the user when - * the vertex was described (see - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex}). The method - * prototype for this callback is: - * </UL> - * - * <PRE> - * void vertex(Object vertexData);</PRE> - * - * <b>GLU_TESS_VERTEX_DATA</b> - * <UL> - * The same as the <b>GLU_TESS_VERTEX</b> callback except that it takes an - * additional reference argument. This reference is identical to the opaque - * reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void vertexData(Object vertexData, Object polygonData);</PRE> - * - * <b>GLU_TESS_END</b> - * <UL> - * The end callback serves the same purpose as - * {@link net.java.games.jogl.GL#glEnd glEnd}. It indicates the end of a - * primitive and it takes no arguments. The method prototype for this - * callback is: - * </UL> - * - * <PRE> - * void end();</PRE> - * - * <b>GLU_TESS_END_DATA</b> - * <UL> - * The same as the <b>GLU_TESS_END</b> callback except that it takes an - * additional reference argument. This reference is identical to the opaque - * reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void endData(Object polygonData);</PRE> - * - * <b>GLU_TESS_COMBINE</b> - * <UL> - * The combine callback is called to create a new vertex when the - * tessellation detects an intersection, or wishes to merge features. The - * method takes four arguments: an array of three elements each of type - * double, an array of four references, an array of four elements each of - * type float, and a reference to a reference. The prototype is: - * </UL> - * - * <PRE> - * void combine(double[] coords, Object[] data, - * float[] weight, Object[] outData);</PRE> - * - * <UL> - * The vertex is defined as a linear combination of up to four existing - * vertices, stored in <i>data</i>. The coefficients of the linear - * combination are given by <i>weight</i>; these weights always add up to 1. - * All vertex pointers are valid even when some of the weights are 0. - * <i>coords</i> gives the location of the new vertex.<P> - * - * The user must allocate another vertex, interpolate parameters using - * <i>data</i> and <i>weight</i>, and return the new vertex pointer - * in <i>outData</i>. This handle is supplied during rendering callbacks. - * The user is responsible for freeing the memory some time after - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon} is - * called.<P> - * - * For example, if the polygon lies in an arbitrary plane in 3-space, and a - * color is associated with each vertex, the <b>GLU_TESS_COMBINE</b> - * callback might look like this: - * </UL> - * <PRE> - * void myCombine(double[] coords, Object[] data, - * float[] weight, Object[] outData) - * { - * MyVertex newVertex = new MyVertex(); - * - * newVertex.x = coords[0]; - * newVertex.y = coords[1]; - * newVertex.z = coords[2]; - * newVertex.r = weight[0]*data[0].r + - * weight[1]*data[1].r + - * weight[2]*data[2].r + - * weight[3]*data[3].r; - * newVertex.g = weight[0]*data[0].g + - * weight[1]*data[1].g + - * weight[2]*data[2].g + - * weight[3]*data[3].g; - * newVertex.b = weight[0]*data[0].b + - * weight[1]*data[1].b + - * weight[2]*data[2].b + - * weight[3]*data[3].b; - * newVertex.a = weight[0]*data[0].a + - * weight[1]*data[1].a + - * weight[2]*data[2].a + - * weight[3]*data[3].a; - * outData = newVertex; - * }</PRE> - * - * <UL> - * If the tessellation detects an intersection, then the - * <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback (see - * below) must be defined, and it must write a non-null reference into - * <i>outData</i>. Otherwise the <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> error - * occurs, and no output is generated. - * </UL> - * - * <b>GLU_TESS_COMBINE_DATA</b> - * <UL> - * The same as the <b>GLU_TESS_COMBINE</b> callback except that it takes an - * additional reference argument. This reference is identical to the opaque - * reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void combineData(double[] coords, Object[] data, - float[] weight, Object[] outData, - Object polygonData);</PRE> - * - * <b>GLU_TESS_ERROR</b> - * <UL> - * The error callback is called when an error is encountered. The one - * argument is of type int; it indicates the specific error that occurred - * and will be set to one of <b>GLU_TESS_MISSING_BEGIN_POLYGON</b>, - * <b>GLU_TESS_MISSING_END_POLYGON</b>, - * <b>GLU_TESS_MISSING_BEGIN_CONTOUR</b>, - * <b>GLU_TESS_MISSING_END_CONTOUR</b>, <b>GLU_TESS_COORD_TOO_LARGE</b>, - * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> or <b>GLU_OUT_OF_MEMORY</b>. - * Character strings describing these errors can be retrieved with the - * {@link net.java.games.jogl.GLU#gluErrorString gluErrorString} call. The - * method prototype for this callback is: - * </UL> - * - * <PRE> - * void error(int errnum);</PRE> - * - * <UL> - * The GLU library will recover from the first four errors by inserting the - * missing call(s). <b>GLU_TESS_COORD_TOO_LARGE</b> indicates that some - * vertex coordinate exceeded the predefined constant - * <b>GLU_TESS_MAX_COORD</b> in absolute value, and that the value has been - * clamped. (Coordinate values must be small enough so that two can be - * multiplied together without overflow.) - * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> indicates that the tessellation - * detected an intersection between two edges in the input data, and the - * <b>GLU_TESS_COMBINE</b> or <b>GLU_TESS_COMBINE_DATA</b> callback was not - * provided. No output is generated. <b>GLU_OUT_OF_MEMORY</b> indicates that - * there is not enough memory so no output is generated. - * </UL> - * - * <b>GLU_TESS_ERROR_DATA</b> - * <UL> - * The same as the GLU_TESS_ERROR callback except that it takes an - * additional reference argument. This reference is identical to the opaque - * reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * was called. The method prototype for this callback is: - * </UL> - * - * <PRE> - * void errorData(int errnum, Object polygonData);</PRE> - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param which - * Specifies the callback being defined. The following values are - * valid: <b>GLU_TESS_BEGIN</b>, <b>GLU_TESS_BEGIN_DATA</b>, - * <b>GLU_TESS_EDGE_FLAG</b>, <b>GLU_TESS_EDGE_FLAG_DATA</b>, - * <b>GLU_TESS_VERTEX</b>, <b>GLU_TESS_VERTEX_DATA</b>, - * <b>GLU_TESS_END</b>, <b>GLU_TESS_END_DATA</b>, - * <b>GLU_TESS_COMBINE</b>, <b>GLU_TESS_COMBINE_DATA</b>, - * <b>GLU_TESS_ERROR</b>, and <b>GLU_TESS_ERROR_DATA</b>. - * @param aCallback - * Specifies the callback object to be called. - * - * @see net.java.games.jogl.GL#glBegin glBegin - * @see net.java.games.jogl.GL#glEdgeFlag glEdgeFlag - * @see net.java.games.jogl.GL#glVertex3f glVertex3f - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluErrorString gluErrorString - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - ****************************************************************************/ -public void gluTessCallback(GLUtesselator tesselator, int which, - GLUtesselatorCallback aCallback); - - -/***************************************************************************** - * <b>gluTessEndContour</b> and - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour} - * delimit the definition of a polygon contour. Within each - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour}/ - * <b>gluTessEndContour</b> pair, there can be zero or more calls to - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex}. The vertices - * specify a closed contour (the last vertex of each contour is automatically - * linked to the first). See the {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex} reference page for more details. - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour} can - * only be called between {@link net.java.games.jogl.GLU#gluTessBeginPolygon - * gluTessBeginPolygon} and - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon}. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - * @see net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon - ****************************************************************************/ -public void gluTessEndContour(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluTessEndPolygon</b> and - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} - * delimit the definition of a convex, concave or self-intersecting polygon. - * Within each {@link net.java.games.jogl.GLU#gluTessBeginPolygon - * gluTessBeginPolygon}/<b>gluTessEndPolygon</b> pair, there must be one or - * more calls to {@link net.java.games.jogl.GLU#gluTessBeginContour - * gluTessBeginContour}/{@link net.java.games.jogl.GLU#gluTessEndContour - * gluTessEndContour}. Within each contour, there are zero or more calls to - * {@link net.java.games.jogl.GLU#gluTessVertex gluTessVertex}. The vertices - * specify a closed contour (the last vertex of each contour is automatically - * linked to the first). See the {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex}, {@link net.java.games.jogl.GLU#gluTessBeginContour - * gluTessBeginContour} and {@link net.java.games.jogl.GLU#gluTessEndContour - * gluTessEndContour} reference pages for more details.<P> - * - * Once <b>gluTessEndPolygon</b> is called, the polygon is tessellated, and - * the resulting triangles are described through callbacks. See - * {@link net.java.games.jogl.GLU#gluTessCallback gluTessCallback} for - * descriptions of the callback functions. - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - * @see net.java.games.jogl.GLU#gluTessVertex gluTessVertex - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - ****************************************************************************/ -public void gluTessEndPolygon(GLUtesselator tesselator); - - -/***************************************************************************** - * <b>gluTessNormal</b> describes a normal for a polygon that the program is - * defining. All input data will be projected onto a plane perpendicular to - * the one of the three coordinate axes before tessellation and all output - * triangles will be oriented CCW with repsect to the normal (CW orientation - * can be obtained by reversing the sign of the supplied normal). For - * example, if you know that all polygons lie in the x-y plane, call - * <b>gluTessNormal</b>(tess, 0.0, 0.0, 0.0) before rendering any polygons.<P> - * - * If the supplied normal is (0.0, 0.0, 0.0)(the initial value), the normal - * is determined as follows. The direction of the normal, up to its sign, is - * found by fitting a plane to the vertices, without regard to how the - * vertices are connected. It is expected that the input data lies - * approximately in the plane; otherwise, projection perpendicular to one of - * the three coordinate axes may substantially change the geometry. The sign - * of the normal is chosen so that the sum of the signed areas of all input - * contours is nonnegative (where a CCW contour has positive area).<P> - * - * The supplied normal persists until it is changed by another call to - * <b>gluTessNormal</b>. - * - * @param tesselator - * Specifies the tessellation object (created by - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param x - * Specifies the first component of the normal. - * @param y - * Specifies the second component of the normal. - * @param z - * Specifies the third component of the normal. - * - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon - ****************************************************************************/ -public void gluTessNormal(GLUtesselator tesselator, double x, double y, double z); - - -/***************************************************************************** - * <b>gluTessProperty</b> is used to control properites stored in a - * tessellation object. These properties affect the way that the polygons are - * interpreted and rendered. The legal value for <i>which</i> are as - * follows:<P> - * - * <b>GLU_TESS_WINDING_RULE</b> - * <UL> - * Determines which parts of the polygon are on the "interior". - * <em>value</em> may be set to one of - * <BR><b>GLU_TESS_WINDING_ODD</b>, - * <BR><b>GLU_TESS_WINDING_NONZERO</b>, - * <BR><b>GLU_TESS_WINDING_POSITIVE</b>, or - * <BR><b>GLU_TESS_WINDING_NEGATIVE</b>, or - * <BR><b>GLU_TESS_WINDING_ABS_GEQ_TWO</b>.<P> - * - * To understand how the winding rule works, consider that the input - * contours partition the plane into regions. The winding rule determines - * which of these regions are inside the polygon.<P> - * - * For a single contour C, the winding number of a point x is simply the - * signed number of revolutions we make around x as we travel once around C - * (where CCW is positive). When there are several contours, the individual - * winding numbers are summed. This procedure associates a signed integer - * value with each point x in the plane. Note that the winding number is - * the same for all points in a single region.<P> - * - * The winding rule classifies a region as "inside" if its winding number - * belongs to the chosen category (odd, nonzero, positive, negative, or - * absolute value of at least two). The previous GLU tesselator (prior to - * GLU 1.2) used the "odd" rule. The "nonzero" rule is another common way - * to define the interior. The other three rules are useful for polygon CSG - * operations. - * </UL> - * <BR><b>GLU_TESS_BOUNDARY_ONLY</b> - * <UL> - * Is a boolean value ("value" should be set to GL_TRUE or GL_FALSE). When - * set to GL_TRUE, a set of closed contours separating the polygon interior - * and exterior are returned instead of a tessellation. Exterior contours - * are oriented CCW with respect to the normal; interior contours are - * oriented CW. The <b>GLU_TESS_BEGIN</b> and <b>GLU_TESS_BEGIN_DATA</b> - * callbacks use the type GL_LINE_LOOP for each contour. - * </UL> - * <BR><b>GLU_TESS_TOLERANCE</b> - * <UL> - * Specifies a tolerance for merging features to reduce the size of the - * output. For example, two vertices that are very close to each other - * might be replaced by a single vertex. The tolerance is multiplied by the - * largest coordinate magnitude of any input vertex; this specifies the - * maximum distance that any feature can move as the result of a single - * merge operation. If a single feature takes part in several merge - * operations, the toal distance moved could be larger.<P> - * - * Feature merging is completely optional; the tolerance is only a hint. - * The implementation is free to merge in some cases and not in others, or - * to never merge features at all. The initial tolerance is 0.<P> - * - * The current implementation merges vertices only if they are exactly - * coincident, regardless of the current tolerance. A vertex is spliced - * into an edge only if the implementation is unable to distinguish which - * side of the edge the vertex lies on. Two edges are merged only when both - * endpoints are identical. - * </UL> - * - * @param tesselator - * Specifies the tessellation object created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess} - * @param which - * Specifies the property to be set. Valid values are - * <b>GLU_TESS_WINDING_RULE</b>, <b>GLU_TESS_BOUNDARDY_ONLY</b>, - * <b>GLU_TESS_TOLERANCE</b>. - * @param value - * Specifices the value of the indicated property. - * - * @see net.java.games.jogl.GLU#gluGetTessProperty gluGetTessProperty - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - ****************************************************************************/ -public void gluTessProperty(GLUtesselator tesselator, int which, double value); - - -/***************************************************************************** - * <b>gluTessVertex</b> describes a vertex on a polygon that the program - * defines. Successive <b>gluTessVertex</b> calls describe a closed contour. - * For example, to describe a quadrilateral <b>gluTessVertex</b> should be - * called four times. <b>gluTessVertex</b> can only be called between - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour} and - * {@link net.java.games.jogl.GLU#gluTessBeginContour gluTessEndContour}.<P> - * - * <b>data</b> normally references to a structure containing the vertex - * location, as well as other per-vertex attributes such as color and normal. - * This reference is passed back to the user through the - * <b>GLU_TESS_VERTEX</b> or <b>GLU_TESS_VERTEX_DATA</b> callback after - * tessellation (see the {@link net.java.games.jogl.GLU#gluTessCallback - * gluTessCallback} reference page). - * - * @param tesselator - * Specifies the tessellation object (created with - * {@link net.java.games.jogl.GLU#gluNewTess gluNewTess}). - * @param coords - * Specifies the coordinates of the vertex. - * @param data - * Specifies an opaque reference passed back to the program with the - * vertex callback (as specified by - * {@link net.java.games.jogl.GLU#gluTessCallback gluTessCallback}). - * - * @see net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon - * @see net.java.games.jogl.GLU#gluNewTess gluNewTess - * @see net.java.games.jogl.GLU#gluTessBeginContour gluTessBeginContour - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLU#gluTessProperty gluTessProperty - * @see net.java.games.jogl.GLU#gluTessNormal gluTessNormal - * @see net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon - ****************************************************************************/ -public void gluTessVertex(GLUtesselator tesselator, double[] coords, Object data); - - -//---------------------------------------------------------------------- -// Mipmap and scaling routines -// - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild1DMipmapLevels(int target, int internalFormat, int width, int format, int type, int level, int base, int max, java.nio.Buffer data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild1DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild1DMipmaps(int target, int internalFormat, int width, int format, int type, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild2DMipmapLevels(int target, int internalFormat, int width, int height, int format, int type, int level, int base, int max, java.nio.Buffer data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild2DMipmaps(int target, int internalFormat, int width, int height, int format, int type, java.nio.Buffer data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint level, GLint base, GLint max, const void * data); </code> */ -public int gluBuild3DMipmapLevels(int target, int internalFormat, int width, int height, int depth, int format, int type, int level, int base, int max, java.nio.Buffer data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, byte[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, short[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, int[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, float[] data); - -/** Interface to C language function: <br> <code> GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void * data); </code> */ -public int gluBuild3DMipmaps(int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data); - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, byte[] dataIn, int wOut, int hOut, int typeOut, byte[] dataOut); - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, short[] dataIn, int wOut, int hOut, int typeOut, short[] dataOut); - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, int[] dataIn, int wOut, int hOut, int typeOut, int[] dataOut); - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, float[] dataIn, int wOut, int hOut, int typeOut, float[] dataOut); - -/** Interface to C language function: <br> <code> GLint gluScaleImage(GLenum format, GLsizei wIn, GLsizei hIn, GLenum typeIn, const void * dataIn, GLsizei wOut, GLsizei hOut, GLenum typeOut, GLvoid * dataOut); </code> */ -public int gluScaleImage(int format, int wIn, int hIn, int typeIn, java.nio.Buffer dataIn, int wOut, int hOut, int typeOut, java.nio.Buffer dataOut); - - -//---------------------------------------------------------------------- -// Function availability routines -// - - -/** - * Returns true if the specified GLU core- or extension-function can be - * successfully used through this GLU instance. By "successfully" we mean - * that the function is both <i>callable</i> on the machine running the - * program and <i>available</i> on the current display.<P> - * - * A GLU function is <i>callable</i> if it is a GLU core- or extension-function - * that is supported by the underlying GLU implementation. The function is - * <i>available</i> if the OpenGL implementation on the display meets the - * requirements of the GLU function being called (because GLU functions utilize - * OpenGL functions). <P> - * - * Whether or not a GLU function is <i>callable</i> is determined as follows: - * <ul> - * <li>If the function is a GLU core function (i.e., not an - * extension), <code>gluGetString(GLU_VERSION)</code> is used to determine the - * version number of the underlying GLU implementation on the host. - * then the function name is cross-referenced with that specification to - * see if it is part of that version's specification. - * - * <li> If the function is a GLU extension, the function name is - * cross-referenced with the list returned by - * <code>gluGetString(GLU_EXTENSIONS)</code> to see if the function is one of - * the extensions that is supported by the underlying GLU implementation. - * </ul> - * - * Whether or not a GLU function is <i>available</i> is determined as follows: - * <ul> - * <li>If the function is a GLU core function then the function is first - * cross-referenced with the GLU specifications to find the minimum GLU - * version required to <i>call</i> that GLU function. Then the following table - * is consulted to determine the minimum GL version required for that version - * of GLU: - * <ul> - * <li> GLU 1.0 requires OpenGL 1.0 - * <li> GLU 1.1 requires OpenGL 1.0 - * <li> GLU 1.2 requires OpenGL 1.1 - * <li> GLU 1.3 requires OpenGL 1.2 - * </ul> - * Finally, <code>glGetString(GL_VERSION)</code> is used to determine the - * highest OpenGL version that both host and display support, and from that it - * is possible to determine if the GL facilities required by the GLU function - * are <i>available</i> on the display. - * - * <li> If the function is a GLU extension, the function name is - * cross-referenced with the list returned by - * <code>gluGetString(GLU_EXTENSIONS)</code> to see if the function is one of - * the extensions that is supported by the underlying GLU implementation. - * </ul> - * - * <b>NOTE:</b>The availability of a function may change at runtime in - * response to changes in the display environment. For example, when a window - * is dragged from one display to another on a multi-display system, or when - * the properties of the display device are modified (e.g., changing the color - * depth of the display). Any application that is concerned with handling - * these situations correctly should confirm availability after a display - * change before calling a questionable OpenGL function. To detect a change in - * the display device, please see {@link - * GLEventListener#displayChanged(GLDrawable,boolean,boolean)}. - * - * @param gluFunctionName the name of the OpenGL function (e.g., use - * "gluNurbsCallbackDataEXT" to check if the <code> - * gluNurbsCallbackDataEXT(GLUnurbs, GLvoid)</code> extension is available). - */ -public boolean isFunctionAvailable(String gluFunctionName); diff --git a/make/glu-impl-macosx.cfg b/make/glu-macosx.cfg index 21e9b3700..ef106a3eb 100644..100755 --- a/make/glu-impl-macosx.cfg +++ b/make/glu-macosx.cfg @@ -6,4 +6,4 @@ CustomCCode #include <jni.h> CustomCCode #include </usr/include/machine/types.h> -Include glu-impl-common.cfg +Include glu-common.cfg diff --git a/make/glu-impl-win32.cfg b/make/glu-win32.cfg index 983513712..5221a5c01 100644..100755 --- a/make/glu-impl-win32.cfg +++ b/make/glu-win32.cfg @@ -11,9 +11,5 @@ CustomCCode #if _MSC_VER <= 1200 CustomCCode typedef int intptr_t; CustomCCode #endif -Include glu-impl-common.cfg +Include glu-common.cfg -# FIXME!!!! -# Include some hacks to get around the fact that GLU1.3 is not yet -# supported in Windows distributions. -# Include glu-impl-win32-GLU13Hacks.cfg diff --git a/make/glu-impl-x11.cfg b/make/glu-x11.cfg index 35fc7034d..ec7b1bce4 100644..100755 --- a/make/glu-impl-x11.cfg +++ b/make/glu-x11.cfg @@ -3,4 +3,5 @@ CustomCCode #include <inttypes.h> -Include glu-impl-common.cfg +Include glu-common.cfg + diff --git a/make/glu.cfg b/make/glu.cfg deleted file mode 100644 index d4374a127..000000000 --- a/make/glu.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# This .cfg file is used to generate the GLU interface for all -# platforms. - -Style InterfaceOnly - -Include glu-common.cfg - -# Custom Java code for GLU interface -IncludeAs CustomJavaCode GLU glu-interface-common-CustomJavaCode.java diff --git a/make/glx-x11.cfg b/make/glx-x11.cfg index 39098f0a8..fd381760e 100644 --- a/make/glx-x11.cfg +++ b/make/glx-x11.cfg @@ -1,6 +1,6 @@ # This .cfg file is used to generate the interface to the GLX routines # used internally by the X11GLContext implementation. -Package net.java.games.jogl.impl.x11 +Package com.sun.opengl.impl.x11 JavaClass GLX Style allstatic Include gl-common-x11.cfg @@ -30,15 +30,15 @@ ArgumentIsString XOpenDisplay 0 CustomJavaCode GLX public static native int DefaultScreen(long display); CustomJavaCode GLX public static native long RootWindow(long display, int screen); CustomCCode JNIEXPORT jlong JNICALL -CustomCCode Java_net_java_games_jogl_impl_x11_GLX_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { +CustomCCode Java_com_sun_opengl_impl_x11_GLX_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) { CustomCCode return DefaultScreen((Display*) (intptr_t) display); CustomCCode } CustomCCode JNIEXPORT jlong JNICALL -CustomCCode Java_net_java_games_jogl_impl_x11_GLX_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) { +CustomCCode Java_com_sun_opengl_impl_x11_GLX_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) { CustomCCode return RootWindow((Display*) (intptr_t) display, screen); CustomCCode } CustomCCode JNIEXPORT jlong JNICALL -CustomCCode Java_net_java_games_jogl_impl_x11_GLX_dlsym(JNIEnv *env, jclass _unused, jstring name) { +CustomCCode Java_com_sun_opengl_impl_x11_GLX_dlsym(JNIEnv *env, jclass _unused, jstring name) { CustomCCode const jbyte* chars; CustomCCode void* res; CustomCCode chars = (*env)->GetStringUTFChars(env, name, NULL); @@ -47,6 +47,22 @@ CustomCCode (*env)->ReleaseStringUTFChars(env, name, chars); CustomCCode return (jlong) ((intptr_t) res); CustomCCode } +# Get returned array's capacity from XGetVisualInfo to be correct +TemporaryCVariableDeclaration XGetVisualInfo int count; +TemporaryCVariableAssignment XGetVisualInfo count = _ptr3[0]; +ReturnValueCapacity XGetVisualInfo count * sizeof(XVisualInfo) +# FIXME: this is terrible but currently needed because we have two +# overloadings for the third argument (IntBuffer and int[]) and can't +# specify different glue code for different overloadings +# +# The NoNio directive which was present in an earlier version of +# GlueGen, which resolved this more cleanly, is also not yet available +# in this version. +ReturnedArrayLength XGetVisualInfo ((((Object) {3}) instanceof Buffer) ? ((IntBuffer) ((Object) {3})).get(0) : ((int[]) ((Object) {3}))[0]) +ReturnValueCapacity glXChooseVisual sizeof(XVisualInfo) +ReturnValueCapacity glXGetVisualFromFBConfig sizeof(XVisualInfo) +ReturnValueCapacity glXGetVisualFromFBConfigSGIX sizeof(XVisualInfo) + # Ignore everything not in the GLX core (up through GLX 1.4) aside from glXGetProcAddress # FIXME: this needs to be kept in sync with the stub headers more than usual Ignore glXFreeContextEXT diff --git a/make/glxext.cfg b/make/glxext.cfg new file mode 100755 index 000000000..b3186a254 --- /dev/null +++ b/make/glxext.cfg @@ -0,0 +1,133 @@ +# This .cfg file is used to generate the interface and implementing +# class for the GLX extensions. +Package com.sun.opengl.impl.x11 +Style InterfaceAndImpl +JavaClass GLXExt +ImplPackage com.sun.opengl.impl.x11 +ImplJavaClass GLXExtImpl +Include gl-common-x11.cfg + +EmitProcAddressTable true +ProcAddressTableClassName GLXExtProcAddressTable +ContextVariableName _context + +# Ignore everything that doesn't start with glX or GLX +IgnoreNot ^(glX|GLX).+ + +CustomCCode #include <inttypes.h> +CustomCCode #include <stdlib.h> +CustomCCode #include <X11/Xlib.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Define GLX_GLXEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glxext.h" are parsed. */ +CustomCCode #define GLX_GLXEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> +CustomCCode #include <GL/glx.h> +CustomCCode #include <GL/glxext.h> + +CustomCCode /* Provide Windows typedefs */ +CustomCCode typedef void* LPVOID; +CustomCCode typedef unsigned int* PUINT; + +CustomJavaCode GLXExt public boolean isFunctionAvailable(String glFunctionName); +CustomJavaCode GLXExt public boolean isExtensionAvailable(String glExtensionName); + +CustomJavaCode GLXExtImpl public GLXExtImpl(X11GLContext context) { +CustomJavaCode GLXExtImpl this._context = context; +CustomJavaCode GLXExtImpl } + +CustomJavaCode GLXExtImpl public boolean isFunctionAvailable(String glFunctionName) +CustomJavaCode GLXExtImpl { +CustomJavaCode GLXExtImpl return _context.isFunctionAvailable(glFunctionName); +CustomJavaCode GLXExtImpl } + +CustomJavaCode GLXExtImpl public boolean isExtensionAvailable(String glExtensionName) +CustomJavaCode GLXExtImpl { +CustomJavaCode GLXExtImpl return _context.isExtensionAvailable(glExtensionName); +CustomJavaCode GLXExtImpl } + +CustomJavaCode GLXExtImpl private X11GLContext _context; + + +# These Ignores cause the core GLX routines to be ignored from the +# GLXExt interface and GLXExtImpl implementing class. +Ignore glXChooseVisual +Ignore glXCreateContext +Ignore glXDestroyContext +Ignore glXMakeCurrent +Ignore glXCopyContext +Ignore glXSwapBuffers +Ignore glXCreateGLXPixmap +Ignore glXDestroyGLXPixmap +Ignore glXQueryExtension +Ignore glXQueryVersion +Ignore glXIsDirect +Ignore glXGetConfig +Ignore glXGetCurrentContext +Ignore glXGetCurrentDrawable +Ignore glXWaitGL +Ignore glXWaitX +Ignore glXUseXFont +Ignore glXQueryExtensionsString +Ignore glXQueryServerString +Ignore glXGetClientString +Ignore glXGetCurrentDisplay +Ignore glXChooseFBConfig +Ignore glXGetFBConfigAttrib +Ignore glXGetFBConfigs +Ignore glXGetVisualFromFBConfig +Ignore glXCreateWindow +Ignore glXDestroyWindow +Ignore glXCreatePixmap +Ignore glXDestroyPixmap +Ignore glXCreatePbuffer +Ignore glXDestroyPbuffer +Ignore glXQueryDrawable +Ignore glXCreateNewContext +Ignore glXMakeContextCurrent +Ignore glXGetCurrentReadDrawable +Ignore glXQueryContext +Ignore glXSelectEvent +Ignore glXGetSelectedEvent +Ignore glXGetProcAddress + +# Ignore a few extensions that bring in data types we don't want to +# expose in the public API (and that are useless anyway without +# exposing more of the implementation) +Ignore glXGetFBConfigAttribSGIX +Ignore glXChooseFBConfigSGIX +Ignore glXCreateGLXPixmapWithConfigSGIX +Ignore glXCreateContextWithConfigSGIX +Ignore glXGetVisualFromFBConfigSGIX +Ignore glXGetFBConfigFromVisualSGIX +Ignore glXCreateGLXPbufferSGIX +Ignore glXDestroyGLXPbufferSGIX +Ignore glXQueryGLXPbufferSGIX +Ignore glXSelectEventSGIX +Ignore glXGetSelectedEventSGIX +Ignore glXCreateGLXPixmapMESA + +# Now we can ignore the GLXFBConfig and XVisualInfo data types +Ignore GLXFBConfig +Ignore XVisualInfo + +# Ignore the SGI hyperpipe extension, which will require more GlueGen +# work to expose the pipeName fields in the various structs +Ignore glXQueryHyperpipeNetworkSGIX +Ignore glXHyperpipeConfigSGIX +Ignore glXQueryHyperpipeConfigSGIX +Ignore glXDestroyHyperpipeConfigSGIX +Ignore glXBindHyperpipeSGIX +Ignore glXQueryHyperpipeBestAttribSGIX +Ignore glXHyperpipeAttribSGIX +Ignore glXQueryHyperpipeAttribSGIX +Ignore GLXHyperpipeNetworkSGIX +Ignore GLXHyperpipeConfigSGIX +Ignore GLXPipeRect +Ignore GLXPipeRectLimits diff --git a/make/jawt-macosx.cfg b/make/jawt-macosx.cfg index ebdbad734..10097ec65 100644 --- a/make/jawt-macosx.cfg +++ b/make/jawt-macosx.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the MacOSXOnscreenGLContext. Style AllStatic -Package net.java.games.jogl.impl +Package com.sun.opengl.impl JavaClass JAWTFactory JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl @@ -20,8 +20,8 @@ CustomCCode #include <jawt.h> CustomCCode #include </usr/include/machine/types.h> -Import net.java.games.jogl.impl.JAWT_PlatformInfo -StructPackage JAWT_MacOSXDrawingSurfaceInfo net.java.games.jogl.impl.macosx +Import com.sun.opengl.impl.JAWT_PlatformInfo +StructPackage JAWT_MacOSXDrawingSurfaceInfo com.sun.opengl.impl.macosx EmitStruct JAWT_MacOSXDrawingSurfaceInfo Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo diff --git a/make/jawt-win32.cfg b/make/jawt-win32.cfg index 4fe44b085..c8a81ecfd 100644 --- a/make/jawt-win32.cfg +++ b/make/jawt-win32.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the WindowsOnscreenGLContext. Style AllStatic -Package net.java.games.jogl.impl +Package com.sun.opengl.impl JavaClass JAWTFactory JavaOutputDir ..\build\gensrc\classes NativeOutputDir ..\build\gensrc\native\jogl @@ -19,8 +19,8 @@ CustomCCode #if _MSC_VER <= 1200 CustomCCode typedef int intptr_t; CustomCCode #endif -Import net.java.games.jogl.impl.JAWT_PlatformInfo -StructPackage JAWT_Win32DrawingSurfaceInfo net.java.games.jogl.impl.windows +Import com.sun.opengl.impl.JAWT_PlatformInfo +StructPackage JAWT_Win32DrawingSurfaceInfo com.sun.opengl.impl.windows EmitStruct JAWT_Win32DrawingSurfaceInfo Implements JAWT_Win32DrawingSurfaceInfo JAWT_PlatformInfo CustomJavaCode JAWT_DrawingSurfaceInfo public JAWT_PlatformInfo platformInfo() { diff --git a/make/jawt-x11.cfg b/make/jawt-x11.cfg index 5794ed4e0..d326c2f26 100644 --- a/make/jawt-x11.cfg +++ b/make/jawt-x11.cfg @@ -1,7 +1,7 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the X11OnscreenGLContext. Style AllStatic -Package net.java.games.jogl.impl +Package com.sun.opengl.impl JavaClass JAWTFactory JavaOutputDir ../build/gensrc/classes NativeOutputDir ../build/gensrc/native/jogl @@ -14,8 +14,8 @@ IgnoreField JAWT_DrawingSurfaceInfo platformInfo IgnoreField JAWT_X11DrawingSurfaceInfo GetAWTColor CustomCCode #include <inttypes.h> CustomCCode #include <jawt.h> -Import net.java.games.jogl.impl.JAWT_PlatformInfo -StructPackage JAWT_X11DrawingSurfaceInfo net.java.games.jogl.impl.x11 +Import com.sun.opengl.impl.JAWT_PlatformInfo +StructPackage JAWT_X11DrawingSurfaceInfo com.sun.opengl.impl.x11 EmitStruct JAWT_X11DrawingSurfaceInfo Implements JAWT_X11DrawingSurfaceInfo JAWT_PlatformInfo diff --git a/make/lib/cpptasks-cvs-040628.jar b/make/lib/cpptasks-cvs-040628.jar Binary files differdeleted file mode 100755 index 01e20f93f..000000000 --- a/make/lib/cpptasks-cvs-040628.jar +++ /dev/null diff --git a/make/lib/cpptasks-patch.tar.gz b/make/lib/cpptasks-patch.tar.gz Binary files differnew file mode 100644 index 000000000..22f1cdeaa --- /dev/null +++ b/make/lib/cpptasks-patch.tar.gz diff --git a/make/lib/cpptasks-version.txt b/make/lib/cpptasks-version.txt new file mode 100755 index 000000000..2e7dd7244 --- /dev/null +++ b/make/lib/cpptasks-version.txt @@ -0,0 +1,4 @@ +Current cpptasks is from CVS repository at +:pserver:[email protected]:/cvsroot/ant-contrib +as of 10/5/2005 with patches applied for Forte C compiler (Bug +1314266) and fat binary generation on Mac OS X (Bug 1313421). diff --git a/make/stub_includes/cg/CG/cg.h b/make/stub_includes/cg/CG/cg.h index 5ff03872f..fe1cf2a75 100644 --- a/make/stub_includes/cg/CG/cg.h +++ b/make/stub_includes/cg/CG/cg.h @@ -8,7 +8,7 @@ /* * - * Copyright (c) 2002, NVIDIA Corporation. + * Copyright (c) 2002-2004, NVIDIA Corporation. * * * @@ -62,15 +62,7 @@ #define _cg_h -#define CG_VERSION_1_2 1 -#define CG_VERSION_NUM 1200 - - -// -// This #define foreces the old API for now. This will be removed soon, but -// the user will still have the ability to enable it. -// -// #define CG_DEPRECATED_1_1_API 1 +#define CG_VERSION_NUM 1400 // Set up for either Win32 import/export/lib. #ifndef CGDLL_API @@ -103,7 +95,15 @@ typedef int CGbool; typedef struct _CGcontext *CGcontext; typedef struct _CGprogram *CGprogram; typedef struct _CGparameter *CGparameter; +typedef struct _CGeffect *CGeffect; +typedef struct _CGtechnique *CGtechnique; +typedef struct _CGpass *CGpass; +typedef struct _CGstate *CGstate; +typedef struct _CGstateassignment *CGstateassignment; +typedef struct _CGannotation *CGannotation; +typedef void *CGhandle; +typedef CGbool (*CGstatecallback)(CGstateassignment); //!!! PREPROCESS BEGIN @@ -114,7 +114,8 @@ typedef enum CG_ARRAY, CG_TYPE_START_ENUM = 1024, -//# define CG_DATATYPE_MACRO(name, compiler_name, enum_name, ncols, nrows) enum_name , +// # define CG_DATATYPE_MACRO(name, compiler_name, enum_name, base_name, ncols, nrows, pc) \ +// enum_name , #include <CG/cg_datatypes.h> @@ -122,7 +123,9 @@ typedef enum typedef enum { -//# define CG_BINDLOCATION_MACRO(name,enum_name,compiler_name,enum_int,addressable,param_type) enum_name = enum_int, +// # define CG_BINDLOCATION_MACRO(name,enum_name,compiler_name,\ +// enum_int,addressable,param_type) \ +// enum_name = enum_int, #include <CG/cg_bindlocations.h> @@ -135,7 +138,8 @@ typedef enum CG_PROFILE_START = 6144, CG_PROFILE_UNKNOWN, -//# define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) CG_PROFILE_##compiler_id_caps = int_id, +// # define CG_PROFILE_MACRO(name, compiler_id, compiler_id_caps, compiler_opt,int_id,vertex_profile) \ +// CG_PROFILE_##compiler_id_caps = int_id, #include <CG/cg_profiles.h> @@ -144,15 +148,29 @@ typedef enum typedef enum { -//# define CG_ERROR_MACRO(code, enum_name, new_enum_name, message) new_enum_name = code, +// # define CG_ERROR_MACRO(code, enum_name, message) \ +// enum_name = code, # include <CG/cg_errors.h> } CGerror; +typedef enum + { + CG_PARAMETERCLASS_UNKNOWN = 0, + CG_PARAMETERCLASS_SCALAR, + CG_PARAMETERCLASS_VECTOR, + CG_PARAMETERCLASS_MATRIX, + CG_PARAMETERCLASS_STRUCT, + CG_PARAMETERCLASS_ARRAY, + CG_PARAMETERCLASS_SAMPLER, + CG_PARAMETERCLASS_OBJECT + } CGparameterclass; + //!!! PREPROCESS END typedef enum { -//# define CG_ENUM_MACRO(enum_name, enum_val) enum_name = enum_val, +// # define CG_ENUM_MACRO(enum_name, enum_val) \ +// enum_name = enum_val, # include <CG/cg_enums.h> } CGenum; @@ -163,6 +181,7 @@ extern "C" { #endif typedef void (*CGerrorCallbackFunc)(void); +typedef void (*CGerrorHandlerFunc)(CGcontext ctx, CGerror err, void *data); /*************************************************************************/ /*** Functions ***/ @@ -176,7 +195,9 @@ CGDLL_API CGcontext cgCreateContext(void); CGDLL_API void cgDestroyContext(CGcontext ctx); CGDLL_API CGbool cgIsContext(CGcontext ctx); CGDLL_API const char *cgGetLastListing(CGcontext ctx); +CGDLL_API void cgSetLastListing(CGhandle handle, const char *listing); CGDLL_API void cgSetAutoCompile(CGcontext ctx, CGenum flag); +CGDLL_API CGenum cgGetAutoCompile(CGcontext ctx); /*** Program functions ***/ CGDLL_API CGprogram cgCreateProgram(CGcontext ctx, @@ -203,6 +224,9 @@ CGDLL_API void cgCompileProgram(CGprogram program); CGDLL_API CGbool cgIsProgramCompiled(CGprogram program); CGDLL_API const char *cgGetProgramString(CGprogram prog, CGenum pname); CGDLL_API CGprofile cgGetProgramProfile(CGprogram prog); +CGDLL_API void cgSetProgramProfile(CGprogram prog, CGprofile profile); + +CGDLL_API void cgSetPassProgramParameters(CGprogram); /*** Parameter functions ***/ @@ -242,6 +266,7 @@ CGDLL_API CGparameter cgGetArrayParameter(CGparameter aparam, int index); CGDLL_API int cgGetArrayDimension(CGparameter param); CGDLL_API CGtype cgGetArrayType(CGparameter param); CGDLL_API int cgGetArraySize(CGparameter param, int dimension); +CGDLL_API int cgGetArrayTotalSize(CGparameter param); CGDLL_API void cgSetArraySize(CGparameter param, int size); CGDLL_API void cgSetMultiDimArraySize(CGparameter param, const int *sizes); @@ -250,6 +275,10 @@ CGDLL_API CGcontext cgGetParameterContext(CGparameter param); CGDLL_API CGbool cgIsParameter(CGparameter param); CGDLL_API const char *cgGetParameterName(CGparameter param); CGDLL_API CGtype cgGetParameterType(CGparameter param); +CGDLL_API CGtype cgGetParameterBaseType(CGparameter param); +CGDLL_API CGparameterclass cgGetParameterClass(CGparameter param); +CGDLL_API int cgGetParameterRows(CGparameter param); +CGDLL_API int cgGetParameterColumns(CGparameter param); CGDLL_API CGtype cgGetParameterNamedType(CGparameter param); CGDLL_API const char *cgGetParameterSemantic(CGparameter param); CGDLL_API CGresource cgGetParameterResource(CGparameter param); @@ -258,9 +287,25 @@ CGDLL_API unsigned long cgGetParameterResourceIndex(CGparameter param); CGDLL_API CGenum cgGetParameterVariability(CGparameter param); CGDLL_API CGenum cgGetParameterDirection(CGparameter param); CGDLL_API CGbool cgIsParameterReferenced(CGparameter param); +CGDLL_API CGbool cgIsParameterUsed(CGparameter param, CGhandle handle); CGDLL_API const double *cgGetParameterValues(CGparameter param, CGenum value_type, int *nvalues); +CGDLL_API void cgSetParameterValuedr(CGparameter param, int n, const double *vals); +CGDLL_API void cgSetParameterValuedc(CGparameter param, int n, const double *vals); +CGDLL_API void cgSetParameterValuefr(CGparameter param, int n, const float *vals); +CGDLL_API void cgSetParameterValuefc(CGparameter param, int n, const float *vals); +CGDLL_API void cgSetParameterValueir(CGparameter param, int n, const int *vals); +CGDLL_API void cgSetParameterValueic(CGparameter param, int n, const int *vals); +CGDLL_API int cgGetParameterValuedr(CGparameter param, int n, double *vals); +CGDLL_API int cgGetParameterValuedc(CGparameter param, int n, double *vals); +CGDLL_API int cgGetParameterValuefr(CGparameter param, int n, float *vals); +CGDLL_API int cgGetParameterValuefc(CGparameter param, int n, float *vals); +CGDLL_API int cgGetParameterValueir(CGparameter param, int n, int *vals); +CGDLL_API int cgGetParameterValueic(CGparameter param, int n, int *vals); +CGDLL_API const char *cgGetStringParameterValue(CGparameter param); +CGDLL_API void cgSetStringParameterValue(CGparameter param, const char *str); + CGDLL_API int cgGetParameterOrdinalNumber(CGparameter param); CGDLL_API CGbool cgIsParameterGlobal(CGparameter param); CGDLL_API int cgGetParameterIndex(CGparameter param); @@ -268,7 +313,6 @@ CGDLL_API int cgGetParameterIndex(CGparameter param); CGDLL_API void cgSetParameterVariability(CGparameter param, CGenum vary); CGDLL_API void cgSetParameterSemantic(CGparameter param, const char *semantic); - CGDLL_API void cgSetParameter1f(CGparameter param, float x); CGDLL_API void cgSetParameter2f(CGparameter param, float x, float y); CGDLL_API void cgSetParameter3f(CGparameter param, float x, float y, float z); @@ -288,8 +332,20 @@ CGDLL_API void cgSetParameter4d(CGparameter param, double y, double z, double w); - - +CGDLL_API void cgSetParameter1i(CGparameter param, int x); +CGDLL_API void cgSetParameter2i(CGparameter param, int x, int y); +CGDLL_API void cgSetParameter3i(CGparameter param, int x, int y, int z); +CGDLL_API void cgSetParameter4i(CGparameter param, + int x, + int y, + int z, + int w); + + +CGDLL_API void cgSetParameter1iv(CGparameter param, const int *v); +CGDLL_API void cgSetParameter2iv(CGparameter param, const int *v); +CGDLL_API void cgSetParameter3iv(CGparameter param, const int *v); +CGDLL_API void cgSetParameter4iv(CGparameter param, const int *v); CGDLL_API void cgSetParameter1fv(CGparameter param, const float *v); CGDLL_API void cgSetParameter2fv(CGparameter param, const float *v); CGDLL_API void cgSetParameter3fv(CGparameter param, const float *v); @@ -299,21 +355,29 @@ CGDLL_API void cgSetParameter2dv(CGparameter param, const double *v); CGDLL_API void cgSetParameter3dv(CGparameter param, const double *v); CGDLL_API void cgSetParameter4dv(CGparameter param, const double *v); +CGDLL_API void cgSetMatrixParameterir(CGparameter param, const int *matrix); CGDLL_API void cgSetMatrixParameterdr(CGparameter param, const double *matrix); CGDLL_API void cgSetMatrixParameterfr(CGparameter param, const float *matrix); +CGDLL_API void cgSetMatrixParameteric(CGparameter param, const int *matrix); CGDLL_API void cgSetMatrixParameterdc(CGparameter param, const double *matrix); CGDLL_API void cgSetMatrixParameterfc(CGparameter param, const float *matrix); +CGDLL_API void cgGetMatrixParameterir(CGparameter param, int *matrix); +CGDLL_API void cgGetMatrixParameterdr(CGparameter param, double *matrix); +CGDLL_API void cgGetMatrixParameterfr(CGparameter param, float *matrix); +CGDLL_API void cgGetMatrixParameteric(CGparameter param, int *matrix); +CGDLL_API void cgGetMatrixParameterdc(CGparameter param, double *matrix); +CGDLL_API void cgGetMatrixParameterfc(CGparameter param, float *matrix); /*** Type Functions ***/ CGDLL_API const char *cgGetTypeString(CGtype type); CGDLL_API CGtype cgGetType(const char *type_string); -CGDLL_API CGtype cgGetNamedUserType(CGprogram program, const char *name); +CGDLL_API CGtype cgGetNamedUserType(CGhandle handle, const char *name); -CGDLL_API int cgGetNumUserTypes(CGprogram program); -CGDLL_API CGtype cgGetUserType(CGprogram program, int index); +CGDLL_API int cgGetNumUserTypes(CGhandle handle); +CGDLL_API CGtype cgGetUserType(CGhandle handle, int index); CGDLL_API int cgGetNumParentTypes(CGtype type); CGDLL_API CGtype cgGetParentType(CGtype type, int index); @@ -339,27 +403,134 @@ CGDLL_API CGprofile cgGetProfile(const char *profile_string); /*** Error Functions ***/ CGDLL_API CGerror cgGetError(void); +CGDLL_API CGerror cgGetFirstError(void); CGDLL_API const char *cgGetErrorString(CGerror error); CGDLL_API const char *cgGetLastErrorString(CGerror *error); CGDLL_API void cgSetErrorCallback(CGerrorCallbackFunc func); CGDLL_API CGerrorCallbackFunc cgGetErrorCallback(void); +CGDLL_API void cgSetErrorHandler(CGerrorHandlerFunc func, void *data); +CGDLL_API CGerrorHandlerFunc cgGetErrorHandler(void **data); /*** Misc Functions ***/ CGDLL_API const char *cgGetString(CGenum sname); -/*** Support for deprecated Cg 1.1 API ***/ - -CGDLL_API CGparameter cgGetNextParameter_depr1_1(CGparameter current); -CGDLL_API CGparameter cgGetNextLeafParameter_depr1_1(CGparameter current); - -#ifdef CG_DEPRECATED_1_1_API - -#define cgGetNextParameter cgGetNextParameter_depr1_1 -#define cgGetNextLeafParameter cgGetNextLeafParameter_depr1_1 - -#endif +/*** CgFX Functions ***/ + +CGDLL_API CGeffect cgCreateEffect(CGcontext, const char *code, const char **args); +CGDLL_API CGeffect cgCreateEffectFromFile(CGcontext, const char *filename, + const char **args); +CGDLL_API void cgDestroyEffect(CGeffect); +CGDLL_API CGcontext cgGetEffectContext(CGeffect); +CGDLL_API CGbool cgIsEffect(CGeffect effect); + +CGDLL_API CGeffect cgGetFirstEffect(CGcontext); +CGDLL_API CGeffect cgGetNextEffect(CGeffect); + +CGDLL_API CGprogram cgCreateProgramFromEffect(CGeffect effect, + CGprofile profile, + const char *entry, + const char **args); + +CGDLL_API CGtechnique cgGetFirstTechnique(CGeffect); +CGDLL_API CGtechnique cgGetNextTechnique(CGtechnique); +CGDLL_API CGtechnique cgGetNamedTechnique(CGeffect, const char *name); +CGDLL_API const char *cgGetTechniqueName(CGtechnique); +CGDLL_API CGbool cgIsTechnique(CGtechnique); +CGDLL_API CGbool cgValidateTechnique(CGtechnique); +CGDLL_API CGbool cgIsTechniqueValidated(CGtechnique); +CGDLL_API CGeffect cgGetTechniqueEffect(CGtechnique); + +CGDLL_API CGpass cgGetFirstPass(CGtechnique); +CGDLL_API CGpass cgGetNamedPass(CGtechnique, const char *name); +CGDLL_API CGpass cgGetNextPass(CGpass); +CGDLL_API CGbool cgIsPass(CGpass); +CGDLL_API const char *cgGetPassName(CGpass); +CGDLL_API CGtechnique cgGetPassTechnique(CGpass); + +CGDLL_API void cgSetPassState(CGpass); +CGDLL_API void cgResetPassState(CGpass); + +CGDLL_API CGstateassignment cgGetFirstStateAssignment(CGpass); +CGDLL_API CGstateassignment cgGetNamedStateAssignment(CGpass, const char *name); +CGDLL_API CGstateassignment cgGetNextStateAssignment(CGstateassignment); +CGDLL_API CGbool cgIsStateAssignment(CGstateassignment); +CGDLL_API CGbool cgCallStateSetCallback(CGstateassignment); +CGDLL_API CGbool cgCallStateValidateCallback(CGstateassignment); +CGDLL_API CGbool cgCallStateResetCallback(CGstateassignment); +CGDLL_API CGpass cgGetStateAssignmentPass(CGstateassignment); +CGDLL_API CGparameter cgGetSamplerStateAssignmentParameter(CGstateassignment); + +CGDLL_API const float *cgGetFloatStateAssignmentValues(CGstateassignment, int *nVals); +CGDLL_API const int *cgGetIntStateAssignmentValues(CGstateassignment, int *nVals); +CGDLL_API const CGbool *cgGetBoolStateAssignmentValues(CGstateassignment, int *nVals); +CGDLL_API const char *cgGetStringStateAssignmentValue(CGstateassignment); +CGDLL_API CGprogram cgGetProgramStateAssignmentValue(CGstateassignment); +CGDLL_API CGparameter cgGetTextureStateAssignmentValue(CGstateassignment); +CGDLL_API CGparameter cgGetSamplerStateAssignmentValue(CGstateassignment); +CGDLL_API int cgGetStateAssignmentIndex(CGstateassignment); + +CGDLL_API int cgGetNumDependentStateAssignmentParameters(CGstateassignment); +CGDLL_API CGparameter cgGetDependentStateAssignmentParameter(CGstateassignment, int index); + +CGDLL_API CGstate cgGetStateAssignmentState(CGstateassignment); +CGDLL_API CGstate cgGetSamplerStateAssignmentState(CGstateassignment); + +CGDLL_API CGstate cgCreateState(CGcontext, const char *name, CGtype); +CGDLL_API CGstate cgCreateArrayState(CGcontext, const char *name, CGtype, int nelems); +CGDLL_API void cgSetStateCallbacks(CGstate, CGstatecallback set, CGstatecallback reset, + CGstatecallback validate); +CGDLL_API CGstatecallback cgGetStateSetCallback(CGstate); +CGDLL_API CGstatecallback cgGetStateResetCallback(CGstate); +CGDLL_API CGstatecallback cgGetStateValidateCallback(CGstate); +CGDLL_API CGtype cgGetStateType(CGstate); +CGDLL_API const char *cgGetStateName(CGstate); +CGDLL_API CGstate cgGetNamedState(CGcontext, const char *name); +CGDLL_API CGstate cgGetFirstState(CGcontext); +CGDLL_API CGstate cgGetNextState(CGstate); +CGDLL_API CGbool cgIsState(CGstate); +CGDLL_API void cgAddStateEnumerant(CGstate, const char *name, int value); + +CGDLL_API CGstate cgCreateSamplerState(CGcontext, const char *name, CGtype); +CGDLL_API CGstate cgCreateArraySamplerState(CGcontext, const char *name, CGtype, int nelems); +CGDLL_API CGstate cgGetNamedSamplerState(CGcontext, const char *name); +CGDLL_API CGstate cgGetFirstSamplerState(CGcontext); + +CGDLL_API CGstateassignment cgGetFirstSamplerStateAssignment(CGparameter); +CGDLL_API CGstateassignment cgGetNamedSamplerStateAssignment(CGparameter, const char *); +CGDLL_API void cgSetSamplerState(CGparameter); + +CGDLL_API CGparameter cgGetNamedEffectParameter(CGeffect, const char *); +CGDLL_API CGparameter cgGetFirstLeafEffectParameter(CGeffect); +CGDLL_API CGparameter cgGetFirstEffectParameter(CGeffect); +CGDLL_API CGparameter cgGetEffectParameterBySemantic(CGeffect, const char *); + +CGDLL_API CGannotation cgGetFirstTechniqueAnnotation(CGtechnique); +CGDLL_API CGannotation cgGetFirstPassAnnotation(CGpass); +CGDLL_API CGannotation cgGetFirstParameterAnnotation(CGparameter); +CGDLL_API CGannotation cgGetFirstProgramAnnotation(CGprogram); +CGDLL_API CGannotation cgGetNextAnnotation(CGannotation); + +CGDLL_API CGannotation cgGetNamedTechniqueAnnotation(CGtechnique, const char *); +CGDLL_API CGannotation cgGetNamedPassAnnotation(CGpass, const char *); +CGDLL_API CGannotation cgGetNamedParameterAnnotation(CGparameter, const char *); +CGDLL_API CGannotation cgGetNamedProgramAnnotation(CGprogram, const char *); + +CGDLL_API CGbool cgIsAnnotation(CGannotation); + +CGDLL_API const char *cgGetAnnotationName(CGannotation); +CGDLL_API CGtype cgGetAnnotationType(CGannotation); + +CGDLL_API const float *cgGetFloatAnnotationValues(CGannotation, int *nvalues); +CGDLL_API const int *cgGetIntAnnotationValues(CGannotation, int *nvalues); +CGDLL_API const char *cgGetStringAnnotationValue(CGannotation); +CGDLL_API const int *cgGetBooleanAnnotationValues(CGannotation, int *nvalues); + +CGDLL_API int cgGetNumDependentAnnotationParameters(CGannotation); +CGDLL_API CGparameter cgGetDependentAnnotationParameter(CGannotation, int index); + +CGDLL_API void cgEvaluateProgram(CGprogram, float *, int ncomps, int nx, int ny, int nz); #endif @@ -367,5 +538,4 @@ CGDLL_API CGparameter cgGetNextLeafParameter_depr1_1(CGparameter current); } #endif - #endif diff --git a/make/stub_includes/cg/CG/cg_datatypes.h b/make/stub_includes/cg/CG/cg_datatypes.h index a728ca638..2eb0ff85a 100644 --- a/make/stub_includes/cg/CG/cg_datatypes.h +++ b/make/stub_includes/cg/CG/cg_datatypes.h @@ -69,124 +69,124 @@ * compiler_name : The name of the data type within the compiler syntax. * enum_name : The C enumerant. * nrows : Number of rows for matrix types. Should be 0 other-wise. - * ncols : Number of columns for matrix types. Should be 0 - * other-wise. + * ncols : Number of columns for scalar, vector, and matrix types. * */ -/*CG_DATATYPE_MACRO(Half,half,*/CG_HALF,//0,1) -/*CG_DATATYPE_MACRO(Half2,half2,*/CG_HALF2,//0,2) -/*CG_DATATYPE_MACRO(Half3,half3,*/CG_HALF3,//0,3) -/*CG_DATATYPE_MACRO(Half4,half4,*/CG_HALF4,//0,4) -/*CG_DATATYPE_MACRO(Half1x1,half1x1,*/CG_HALF1x1,//1,1) -/*CG_DATATYPE_MACRO(Half1x2,half1x2,*/CG_HALF1x2,//1,2) -/*CG_DATATYPE_MACRO(Half1x3,half1x3,*/CG_HALF1x3,//1,3) -/*CG_DATATYPE_MACRO(Half1x4,half1x4,*/CG_HALF1x4,//1,4) -/*CG_DATATYPE_MACRO(Half2x1,half2x1,*/CG_HALF2x1,//2,1) -/*CG_DATATYPE_MACRO(Half2x2,half2x2,*/CG_HALF2x2,//2,2) -/*CG_DATATYPE_MACRO(Half2x3,half2x3,*/CG_HALF2x3,//2,3) -/*CG_DATATYPE_MACRO(Half2x4,half2x4,*/CG_HALF2x4,//2,4) -/*CG_DATATYPE_MACRO(Half3x1,half3x1,*/CG_HALF3x1,//3,1) -/*CG_DATATYPE_MACRO(Half3x2,half3x2,*/CG_HALF3x2,//3,2) -/*CG_DATATYPE_MACRO(Half3x3,half3x3,*/CG_HALF3x3,//3,3) -/*CG_DATATYPE_MACRO(Half3x4,half3x4,*/CG_HALF3x4,//3,4) -/*CG_DATATYPE_MACRO(Half4x1,half4x1,*/CG_HALF4x1,//4,1) -/*CG_DATATYPE_MACRO(Half4x2,half4x2,*/CG_HALF4x2,//4,2) -/*CG_DATATYPE_MACRO(Half4x3,half4x3,*/CG_HALF4x3,//4,3) -/*CG_DATATYPE_MACRO(Half4x4,half4x4,*/CG_HALF4x4,//4,4) -/*CG_DATATYPE_MACRO(Float,float,*/CG_FLOAT,//0,1) -/*CG_DATATYPE_MACRO(Float2,float2,*/CG_FLOAT2,//0,2) -/*CG_DATATYPE_MACRO(Float3,float3,*/CG_FLOAT3,//0,3) -/*CG_DATATYPE_MACRO(Float4,float4,*/CG_FLOAT4,//0,4) -/*CG_DATATYPE_MACRO(Float1x1,float1x1,*/CG_FLOAT1x1,//1,1) -/*CG_DATATYPE_MACRO(Float1x2,float1x2,*/CG_FLOAT1x2,//1,2) -/*CG_DATATYPE_MACRO(Float1x3,float1x3,*/CG_FLOAT1x3,//1,3) -/*CG_DATATYPE_MACRO(Float1x4,float1x4,*/CG_FLOAT1x4,//1,4) -/*CG_DATATYPE_MACRO(Float2x1,float2x1,*/CG_FLOAT2x1,//2,1) -/*CG_DATATYPE_MACRO(Float2x2,float2x2,*/CG_FLOAT2x2,//2,2) -/*CG_DATATYPE_MACRO(Float2x3,float2x3,*/CG_FLOAT2x3,//2,3) -/*CG_DATATYPE_MACRO(Float2x4,float2x4,*/CG_FLOAT2x4,//2,4) -/*CG_DATATYPE_MACRO(Float3x1,float3x1,*/CG_FLOAT3x1,//3,1) -/*CG_DATATYPE_MACRO(Float3x2,float3x2,*/CG_FLOAT3x2,//3,2) -/*CG_DATATYPE_MACRO(Float3x3,float3x3,*/CG_FLOAT3x3,//3,3) -/*CG_DATATYPE_MACRO(Float3x4,float3x4,*/CG_FLOAT3x4,//3,4) -/*CG_DATATYPE_MACRO(Float4x1,float4x1,*/CG_FLOAT4x1,//4,1) -/*CG_DATATYPE_MACRO(Float4x2,float4x2,*/CG_FLOAT4x2,//4,2) -/*CG_DATATYPE_MACRO(Float4x3,float4x3,*/CG_FLOAT4x3,//4,3) -/*CG_DATATYPE_MACRO(Float4x4,float4x4,*/CG_FLOAT4x4,//4,4) -/*CG_DATATYPE_MACRO(Sampler1D,sampler1D,*/CG_SAMPLER1D,//0,0) -/*CG_DATATYPE_MACRO(Sampler2D,sampler2D,*/CG_SAMPLER2D,//0,0) -/*CG_DATATYPE_MACRO(Sampler3D,sampler3D,*/CG_SAMPLER3D,//0,0) -/*CG_DATATYPE_MACRO(SamplerRECT,samplerRECT,*/CG_SAMPLERRECT,//0,0) -/*CG_DATATYPE_MACRO(SamplerCUBE,samplerCUBE,*/CG_SAMPLERCUBE,//0,0) -/*CG_DATATYPE_MACRO(Fixed,fixed,*/CG_FIXED,//0,1) -/*CG_DATATYPE_MACRO(Fixed2,fixed2,*/CG_FIXED2,//0,2) -/*CG_DATATYPE_MACRO(Fixed3,fixed3,*/CG_FIXED3,//0,3) -/*CG_DATATYPE_MACRO(Fixed4,fixed4,*/CG_FIXED4,//0,4) -/*CG_DATATYPE_MACRO(Fixed1x1,fixed1x1,*/CG_FIXED1x1,//1,1) -/*CG_DATATYPE_MACRO(Fixed1x2,fixed1x2,*/CG_FIXED1x2,//1,2) -/*CG_DATATYPE_MACRO(Fixed1x3,fixed1x3,*/CG_FIXED1x3,//1,3) -/*CG_DATATYPE_MACRO(Fixed1x4,fixed1x4,*/CG_FIXED1x4,//1,4) -/*CG_DATATYPE_MACRO(Fixed2x1,fixed2x1,*/CG_FIXED2x1,//2,1) -/*CG_DATATYPE_MACRO(Fixed2x2,fixed2x2,*/CG_FIXED2x2,//2,2) -/*CG_DATATYPE_MACRO(Fixed2x3,fixed2x3,*/CG_FIXED2x3,//2,3) -/*CG_DATATYPE_MACRO(Fixed2x4,fixed2x4,*/CG_FIXED2x4,//2,4) -/*CG_DATATYPE_MACRO(Fixed3x1,fixed3x1,*/CG_FIXED3x1,//3,1) -/*CG_DATATYPE_MACRO(Fixed3x2,fixed3x2,*/CG_FIXED3x2,//3,2) -/*CG_DATATYPE_MACRO(Fixed3x3,fixed3x3,*/CG_FIXED3x3,//3,3) -/*CG_DATATYPE_MACRO(Fixed3x4,fixed3x4,*/CG_FIXED3x4,//3,4) -/*CG_DATATYPE_MACRO(Fixed4x1,fixed4x1,*/CG_FIXED4x1,//4,1) -/*CG_DATATYPE_MACRO(Fixed4x2,fixed4x2,*/CG_FIXED4x2,//4,2) -/*CG_DATATYPE_MACRO(Fixed4x3,fixed4x3,*/CG_FIXED4x3,//4,3) -/*CG_DATATYPE_MACRO(Fixed4x4,fixed4x4,*/CG_FIXED4x4,//4,4) -/*CG_DATATYPE_MACRO(Half1,half1,*/CG_HALF1,//0,1) -/*CG_DATATYPE_MACRO(Float1,float1,*/CG_FLOAT1,//0,1) -/*CG_DATATYPE_MACRO(Fixed1,fixed1,*/CG_FIXED1,//0,1) -/*CG_DATATYPE_MACRO(Int,int,*/CG_INT,//0,1) -/*CG_DATATYPE_MACRO(Int1,int1,*/CG_INT1,//0,1) -/*CG_DATATYPE_MACRO(Int2,int2,*/CG_INT2,//0,2) -/*CG_DATATYPE_MACRO(Int3,int3,*/CG_INT3,//0,3) -/*CG_DATATYPE_MACRO(Int4,int4,*/CG_INT4,//0,4) -/*CG_DATATYPE_MACRO(Int1x1,int1x1,*/CG_INT1x1,//1,1) -/*CG_DATATYPE_MACRO(Int1x2,int1x2,*/CG_INT1x2,//1,2) -/*CG_DATATYPE_MACRO(Int1x3,int1x3,*/CG_INT1x3,//1,3) -/*CG_DATATYPE_MACRO(Int1x4,int1x4,*/CG_INT1x4,//1,4) -/*CG_DATATYPE_MACRO(Int2x1,int2x1,*/CG_INT2x1,//2,1) -/*CG_DATATYPE_MACRO(Int2x2,int2x2,*/CG_INT2x2,//2,2) -/*CG_DATATYPE_MACRO(Int2x3,int2x3,*/CG_INT2x3,//2,3) -/*CG_DATATYPE_MACRO(Int2x4,int2x4,*/CG_INT2x4,//2,4) -/*CG_DATATYPE_MACRO(Int3x1,int3x1,*/CG_INT3x1,//3,1) -/*CG_DATATYPE_MACRO(Int3x2,int3x2,*/CG_INT3x2,//3,2) -/*CG_DATATYPE_MACRO(Int3x3,int3x3,*/CG_INT3x3,//3,3) -/*CG_DATATYPE_MACRO(Int3x4,int3x4,*/CG_INT3x4,//3,4) -/*CG_DATATYPE_MACRO(Int4x1,int4x1,*/CG_INT4x1,//4,1) -/*CG_DATATYPE_MACRO(Int4x2,int4x2,*/CG_INT4x2,//4,2) -/*CG_DATATYPE_MACRO(Int4x3,int4x3,*/CG_INT4x3,//4,3) -/*CG_DATATYPE_MACRO(Int4x4,int4x4,*/CG_INT4x4,//4,4) -/*CG_DATATYPE_MACRO(Bool,bool,*/CG_BOOL,//0,1) -/*CG_DATATYPE_MACRO(Bool1,bool1,*/CG_BOOL1,//0,1) -/*CG_DATATYPE_MACRO(Bool2,bool2,*/CG_BOOL2,//0,2) -/*CG_DATATYPE_MACRO(Bool3,bool3,*/CG_BOOL3,//0,3) -/*CG_DATATYPE_MACRO(Bool4,bool4,*/CG_BOOL4,//0,4) -/*CG_DATATYPE_MACRO(Bool1x1,bool1x1,*/CG_BOOL1x1,//1,1) -/*CG_DATATYPE_MACRO(Bool1x2,bool1x2,*/CG_BOOL1x2,//1,2) -/*CG_DATATYPE_MACRO(Bool1x3,bool1x3,*/CG_BOOL1x3,//1,3) -/*CG_DATATYPE_MACRO(Bool1x4,bool1x4,*/CG_BOOL1x4,//1,4) -/*CG_DATATYPE_MACRO(Bool2x1,bool2x1,*/CG_BOOL2x1,//2,1) -/*CG_DATATYPE_MACRO(Bool2x2,bool2x2,*/CG_BOOL2x2,//2,2) -/*CG_DATATYPE_MACRO(Bool2x3,bool2x3,*/CG_BOOL2x3,//2,3) -/*CG_DATATYPE_MACRO(Bool2x4,bool2x4,*/CG_BOOL2x4,//2,4) -/*CG_DATATYPE_MACRO(Bool3x1,bool3x1,*/CG_BOOL3x1,//3,1) -/*CG_DATATYPE_MACRO(Bool3x2,bool3x2,*/CG_BOOL3x2,//3,2) -/*CG_DATATYPE_MACRO(Bool3x3,bool3x3,*/CG_BOOL3x3,//3,3) -/*CG_DATATYPE_MACRO(Bool3x4,bool3x4,*/CG_BOOL3x4,//3,4) -/*CG_DATATYPE_MACRO(Bool4x1,bool4x1,*/CG_BOOL4x1,//4,1) -/*CG_DATATYPE_MACRO(Bool4x2,bool4x2,*/CG_BOOL4x2,//4,2) -/*CG_DATATYPE_MACRO(Bool4x3,bool4x3,*/CG_BOOL4x3,//4,3) -/*CG_DATATYPE_MACRO(Bool4x4,bool4x4,*/CG_BOOL4x4,//4,4) +/*CG_DATATYPE_MACRO(Half,half,*/CG_HALF,//CG_HALF,0,1,CG_PARAMETERCLASS_SCALAR) +/*CG_DATATYPE_MACRO(Half2,half2,*/CG_HALF2,//CG_HALF,0,2,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Half3,half3,*/CG_HALF3,//CG_HALF,0,3,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Half4,half4,*/CG_HALF4,//CG_HALF,0,4,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Half1x1,half1x1,*/CG_HALF1x1,//CG_HALF,1,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half1x2,half1x2,*/CG_HALF1x2,//CG_HALF,1,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half1x3,half1x3,*/CG_HALF1x3,//CG_HALF,1,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half1x4,half1x4,*/CG_HALF1x4,//CG_HALF,1,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half2x1,half2x1,*/CG_HALF2x1,//CG_HALF,2,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half2x2,half2x2,*/CG_HALF2x2,//CG_HALF,2,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half2x3,half2x3,*/CG_HALF2x3,//CG_HALF,2,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half2x4,half2x4,*/CG_HALF2x4,//CG_HALF,2,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half3x1,half3x1,*/CG_HALF3x1,//CG_HALF,3,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half3x2,half3x2,*/CG_HALF3x2,//CG_HALF,3,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half3x3,half3x3,*/CG_HALF3x3,//CG_HALF,3,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half3x4,half3x4,*/CG_HALF3x4,//CG_HALF,3,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half4x1,half4x1,*/CG_HALF4x1,//CG_HALF,4,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half4x2,half4x2,*/CG_HALF4x2,//CG_HALF,4,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half4x3,half4x3,*/CG_HALF4x3,//CG_HALF,4,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half4x4,half4x4,*/CG_HALF4x4,//CG_HALF,4,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float,float,*/CG_FLOAT,//CG_FLOAT,0,1,CG_PARAMETERCLASS_SCALAR) +/*CG_DATATYPE_MACRO(Float2,float2,*/CG_FLOAT2,//CG_FLOAT,0,2,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Float3,float3,*/CG_FLOAT3,//CG_FLOAT,0,3,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Float4,float4,*/CG_FLOAT4,//CG_FLOAT,0,4,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Float1x1,float1x1,*/CG_FLOAT1x1,//CG_FLOAT,1,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float1x2,float1x2,*/CG_FLOAT1x2,//CG_FLOAT,1,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float1x3,float1x3,*/CG_FLOAT1x3,//CG_FLOAT,1,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float1x4,float1x4,*/CG_FLOAT1x4,//CG_FLOAT,1,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float2x1,float2x1,*/CG_FLOAT2x1,//CG_FLOAT,2,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float2x2,float2x2,*/CG_FLOAT2x2,//CG_FLOAT,2,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float2x3,float2x3,*/CG_FLOAT2x3,//CG_FLOAT,2,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float2x4,float2x4,*/CG_FLOAT2x4,//CG_FLOAT,2,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float3x1,float3x1,*/CG_FLOAT3x1,//CG_FLOAT,3,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float3x2,float3x2,*/CG_FLOAT3x2,//CG_FLOAT,3,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float3x3,float3x3,*/CG_FLOAT3x3,//CG_FLOAT,3,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float3x4,float3x4,*/CG_FLOAT3x4,//CG_FLOAT,3,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float4x1,float4x1,*/CG_FLOAT4x1,//CG_FLOAT,4,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float4x2,float4x2,*/CG_FLOAT4x2,//CG_FLOAT,4,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float4x3,float4x3,*/CG_FLOAT4x3,//CG_FLOAT,4,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Float4x4,float4x4,*/CG_FLOAT4x4,//CG_FLOAT,4,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Sampler1D,sampler1D,*/CG_SAMPLER1D,//CG_SAMPLER1D,0,0,CG_PARAMETERCLASS_SAMPLER) +/*CG_DATATYPE_MACRO(Sampler2D,sampler2D,*/CG_SAMPLER2D,//CG_SAMPLER2D,0,0,CG_PARAMETERCLASS_SAMPLER) +/*CG_DATATYPE_MACRO(Sampler3D,sampler3D,*/CG_SAMPLER3D,//CG_SAMPLER3D,0,0,CG_PARAMETERCLASS_SAMPLER) +/*CG_DATATYPE_MACRO(SamplerRECT,samplerRECT,*/CG_SAMPLERRECT,//CG_SAMPLERRECT,0,0,CG_PARAMETERCLASS_SAMPLER) +/*CG_DATATYPE_MACRO(SamplerCUBE,samplerCUBE,*/CG_SAMPLERCUBE,//CG_SAMPLERCUBE,0,0,CG_PARAMETERCLASS_SAMPLER) +/*CG_DATATYPE_MACRO(Fixed,fixed,*/CG_FIXED,//CG_FIXED,0,1,CG_PARAMETERCLASS_SCALAR) +/*CG_DATATYPE_MACRO(Fixed2,fixed2,*/CG_FIXED2,//CG_FIXED,0,2,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Fixed3,fixed3,*/CG_FIXED3,//CG_FIXED,0,3,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Fixed4,fixed4,*/CG_FIXED4,//CG_FIXED,0,4,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Fixed1x1,fixed1x1,*/CG_FIXED1x1,//CG_FIXED,1,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed1x2,fixed1x2,*/CG_FIXED1x2,//CG_FIXED,1,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed1x3,fixed1x3,*/CG_FIXED1x3,//CG_FIXED,1,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed1x4,fixed1x4,*/CG_FIXED1x4,//CG_FIXED,1,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed2x1,fixed2x1,*/CG_FIXED2x1,//CG_FIXED,2,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed2x2,fixed2x2,*/CG_FIXED2x2,//CG_FIXED,2,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed2x3,fixed2x3,*/CG_FIXED2x3,//CG_FIXED,2,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed2x4,fixed2x4,*/CG_FIXED2x4,//CG_FIXED,2,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed3x1,fixed3x1,*/CG_FIXED3x1,//CG_FIXED,3,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed3x2,fixed3x2,*/CG_FIXED3x2,//CG_FIXED,3,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed3x3,fixed3x3,*/CG_FIXED3x3,//CG_FIXED,3,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed3x4,fixed3x4,*/CG_FIXED3x4,//CG_FIXED,3,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed4x1,fixed4x1,*/CG_FIXED4x1,//CG_FIXED,4,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed4x2,fixed4x2,*/CG_FIXED4x2,//CG_FIXED,4,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed4x3,fixed4x3,*/CG_FIXED4x3,//CG_FIXED,4,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Fixed4x4,fixed4x4,*/CG_FIXED4x4,//CG_FIXED,4,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Half1,half1,*/CG_HALF1,//CG_HALF,0,1,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Float1,float1,*/CG_FLOAT1,//CG_FLOAT,0,1,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Fixed1,fixed1,*/CG_FIXED1,//CG_FIXED,0,1,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Int,int,*/CG_INT,//CG_INT,0,1,CG_PARAMETERCLASS_SCALAR) +/*CG_DATATYPE_MACRO(Int1,int1,*/CG_INT1,//CG_INT,0,1,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Int2,int2,*/CG_INT2,//CG_INT,0,2,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Int3,int3,*/CG_INT3,//CG_INT,0,3,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Int4,int4,*/CG_INT4,//CG_INT,0,4,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Int1x1,int1x1,*/CG_INT1x1,//CG_INT,1,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int1x2,int1x2,*/CG_INT1x2,//CG_INT,1,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int1x3,int1x3,*/CG_INT1x3,//CG_INT,1,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int1x4,int1x4,*/CG_INT1x4,//CG_INT,1,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int2x1,int2x1,*/CG_INT2x1,//CG_INT,2,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int2x2,int2x2,*/CG_INT2x2,//CG_INT,2,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int2x3,int2x3,*/CG_INT2x3,//CG_INT,2,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int2x4,int2x4,*/CG_INT2x4,//CG_INT,2,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int3x1,int3x1,*/CG_INT3x1,//CG_INT,3,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int3x2,int3x2,*/CG_INT3x2,//CG_INT,3,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int3x3,int3x3,*/CG_INT3x3,//CG_INT,3,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int3x4,int3x4,*/CG_INT3x4,//CG_INT,3,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int4x1,int4x1,*/CG_INT4x1,//CG_INT,4,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int4x2,int4x2,*/CG_INT4x2,//CG_INT,4,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int4x3,int4x3,*/CG_INT4x3,//CG_INT,4,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Int4x4,int4x4,*/CG_INT4x4,//CG_INT,4,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool,bool,*/CG_BOOL,//CG_BOOL,0,1,CG_PARAMETERCLASS_SCALAR) +/*CG_DATATYPE_MACRO(Bool1,bool1,*/CG_BOOL1,//CG_BOOL,0,1,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Bool2,bool2,*/CG_BOOL2,//CG_BOOL,0,2,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Bool3,bool3,*/CG_BOOL3,//CG_BOOL,0,3,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Bool4,bool4,*/CG_BOOL4,//CG_BOOL,0,4,CG_PARAMETERCLASS_VECTOR) +/*CG_DATATYPE_MACRO(Bool1x1,bool1x1,*/CG_BOOL1x1,//CG_BOOL,1,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool1x2,bool1x2,*/CG_BOOL1x2,//CG_BOOL,1,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool1x3,bool1x3,*/CG_BOOL1x3,//CG_BOOL,1,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool1x4,bool1x4,*/CG_BOOL1x4,//CG_BOOL,1,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool2x1,bool2x1,*/CG_BOOL2x1,//CG_BOOL,2,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool2x2,bool2x2,*/CG_BOOL2x2,//CG_BOOL,2,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool2x3,bool2x3,*/CG_BOOL2x3,//CG_BOOL,2,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool2x4,bool2x4,*/CG_BOOL2x4,//CG_BOOL,2,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool3x1,bool3x1,*/CG_BOOL3x1,//CG_BOOL,3,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool3x2,bool3x2,*/CG_BOOL3x2,//CG_BOOL,3,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool3x3,bool3x3,*/CG_BOOL3x3,//CG_BOOL,3,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool3x4,bool3x4,*/CG_BOOL3x4,//CG_BOOL,3,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool4x1,bool4x1,*/CG_BOOL4x1,//CG_BOOL,4,1,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool4x2,bool4x2,*/CG_BOOL4x2,//CG_BOOL,4,2,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool4x3,bool4x3,*/CG_BOOL4x3,//CG_BOOL,4,3,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(Bool4x4,bool4x4,*/CG_BOOL4x4,//CG_BOOL,4,4,CG_PARAMETERCLASS_MATRIX) +/*CG_DATATYPE_MACRO(String,string,*/CG_STRING,//CG_STRING,0,1,CG_PARAMETERCLASS_OBJECT) +/*CG_DATATYPE_MACRO(Program,program,*/CG_PROGRAM_TYPE,//CG_PROGRAM_TYPE,0,0,CG_PARAMETERCLASS_OBJECT) +/*CG_DATATYPE_MACRO(Texture,texture,*/CG_TEXTURE,//CG_TEXTURE,0,0,CG_PARAMETERCLASS_OBJECT) //#undef CG_DATATYPE_MACRO - - diff --git a/make/stub_includes/cg/CG/cg_enums.h b/make/stub_includes/cg/CG/cg_enums.h index 24d97a320..cb7262feb 100755 --- a/make/stub_includes/cg/CG/cg_enums.h +++ b/make/stub_includes/cg/CG/cg_enums.h @@ -89,7 +89,9 @@ /*CG_ENUM_MACRO(*/CG_CURRENT=/*, */4117,//) /*CG_ENUM_MACRO(*/CG_LITERAL=/*, */4118,//) /*CG_ENUM_MACRO(*/CG_VERSION=/*, */4119,//) +/*CG_ENUM_MACRO(*/CG_ROW_MAJOR=/*, */4120,//) +/*CG_ENUM_MACRO(*/CG_COLUMN_MAJOR=/*, */4121,//) -#undef CG_ENUM_MACRO +// #undef CG_ENUM_MACRO diff --git a/make/stub_includes/cg/CG/cg_errors.h b/make/stub_includes/cg/CG/cg_errors.h index 2ad510f8f..c785da252 100644 --- a/make/stub_includes/cg/CG/cg_errors.h +++ b/make/stub_includes/cg/CG/cg_errors.h @@ -8,7 +8,7 @@ /* * - * Copyright (c) 2002, NVIDIA Corporation. + * Copyright (c) 2002-2004, NVIDIA Corporation. * * * @@ -278,5 +278,70 @@ CG_TYPE_IS_NOT_DEFINED_IN_PROGRAM_ERROR= "source parameter is not defined within the given program " "or does not match the type with the same name in the program.")*/ +CG_INVALID_EFFECT_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/40,/* + CG_INVALID_EFFECT_HANDLE_ERROR, + "Invalid effect handle.")*/ + +CG_INVALID_STATE_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/41,/* + CG_INVALID_STATE_HANDLE_ERROR, + "Invalid state handle.")*/ + +CG_INVALID_STATE_ASSIGNMENT_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/42,/* + CG_INVALID_STATE_ASSIGNMENT_HANDLE_ERROR, + "Invalid stateassignment handle.")*/ + +CG_INVALID_PASS_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/43,/* + CG_INVALID_PASS_HANDLE_ERROR, + "Invalid pass handle.")*/ + +CG_INVALID_ANNOTATION_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/44,/* + CG_INVALID_ANNOTATION_HANDLE_ERROR, + "Invalid annotation handle.")*/ + +CG_INVALID_TECHNIQUE_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/45,/* + CG_INVALID_TECHNIQUE_HANDLE_ERROR, + "Invalid technique handle.")*/ + +CG_INVALID_PARAMETER_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/46,/* + CG_INVALID_PARAMETER_HANDLE_ERROR, + "Invalid parameter handle.")*/ + +CG_STATE_ASSIGNMENT_TYPE_MISMATCH_ERROR= +/*CG_ERROR_MACRO(*/47,/* + CG_STATE_ASSIGNMENT_TYPE_MISMATCH_ERROR, + "Invalid parameter handle.")*/ + +CG_INVALID_FUNCTION_HANDLE_ERROR= +/*CG_ERROR_MACRO(*/48,/* + CG_INVALID_FUNCTION_HANDLE_ERROR, + "Invalid function handle.")*/ + +CG_INVALID_TECHNIQUE_ERROR= +/*CG_ERROR_MACRO(*/49,/* + CG_INVALID_TECHNIQUE_ERROR, + "Technique did not pass validation.")*/ + +CG_INVALID_POINTER_ERROR= +/*CG_ERROR_MACRO(*/50,/* + CG_INVALID_POINTER_ERROR, + "The supplied pointer is NULL.")*/ + +CG_NOT_ENOUGH_DATA_ERROR= +/*CG_ERROR_MACRO(*/51,/* + CG_NOT_ENOUGH_DATA_ERROR, + "Not enough data was provided.")*/ + +CG_NON_NUMERIC_PARAMETER_ERROR= +/*CG_ERROR_MACRO(*/52,/* + CG_NON_NUMERIC_PARAMETER_ERROR, + "The parameter is not of a numeric type.")*/ + //#undef CG_ERROR_MACRO diff --git a/make/stub_includes/cg/CG/cg_profiles.h b/make/stub_includes/cg/CG/cg_profiles.h index c77f45229..8217a569a 100644 --- a/make/stub_includes/cg/CG/cg_profiles.h +++ b/make/stub_includes/cg/CG/cg_profiles.h @@ -91,6 +91,7 @@ /*CG_PROFILE_MACRO(DX9Pixel20,ps_2_0,*/CG_PROFILE_PS_2_0=/*,"ps_2_0",*/6162,//0) /*CG_PROFILE_MACRO(DX9Pixel2x,ps_2_x,*/CG_PROFILE_PS_2_X=/*,"ps_2_x",*/6163,//0) +/*CG_PROFILE_MACRO(Generic, generic,*/ GENERIC=/*, "generic",*/ 7002,//0) //#undef CG_PROFILE_MACRO #undef CG_IN_PROFILES_INCLUDE diff --git a/make/stub_includes/macosx/cglext.c b/make/stub_includes/macosx/cglext.c new file mode 100755 index 000000000..14010fcc4 --- /dev/null +++ b/make/stub_includes/macosx/cglext.c @@ -0,0 +1 @@ +#include <cglext.h> diff --git a/make/stub_includes/win32/wglext.c b/make/stub_includes/win32/wglext.c new file mode 100755 index 000000000..9c6120411 --- /dev/null +++ b/make/stub_includes/win32/wglext.c @@ -0,0 +1,13 @@ +#define GLAPI + +// Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +// "glext.h" are parsed. +#define GL_GLEXT_PROTOTYPES + +#include <GL/gl.h> + +// Bring in the wgl extensions +#define WGL_WGLEXT_PROTOTYPES +#define SKIP_WGL_HANDLE_DEFINITIONS +#include <windows.h> +#include <GL/wglext.h> diff --git a/make/stub_includes/win32/windows.h b/make/stub_includes/win32/windows.h index fa4ae1c95..e2d78deef 100644 --- a/make/stub_includes/win32/windows.h +++ b/make/stub_includes/win32/windows.h @@ -4,6 +4,7 @@ #define FAR #define WINBASEAPI #define WINGDIAPI +#define WINUSERAPI #define WINAPI #define APIENTRY #define CONST const diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h index 2141135e7..35f754178 100644 --- a/make/stub_includes/win32/wingdi.h +++ b/make/stub_includes/win32/wingdi.h @@ -144,6 +144,25 @@ typedef struct tagPIXELFORMATDESCRIPTOR #define ERROR_PROC_NOT_FOUND 127 #define ERROR_INVALID_WINDOW_HANDLE 1400 +/* + * ShowWindow() Commands + */ +#define SW_HIDE 0 +#define SW_SHOWNORMAL 1 +#define SW_NORMAL 1 +#define SW_SHOWMINIMIZED 2 +#define SW_SHOWMAXIMIZED 3 +#define SW_MAXIMIZE 3 +#define SW_SHOWNOACTIVATE 4 +#define SW_SHOW 5 +#define SW_MINIMIZE 6 +#define SW_SHOWMINNOACTIVE 7 +#define SW_SHOWNA 8 +#define SW_RESTORE 9 +#define SW_SHOWDEFAULT 10 +#define SW_FORCEMINIMIZE 11 +#define SW_MAX 11 + // Windows routines WINBASEAPI DWORD WINAPI GetLastError(VOID); WINBASEAPI HMODULE WINAPI LoadLibraryA(LPCSTR lpLibFileName); @@ -183,10 +202,11 @@ WINGDIAPI BOOL WINAPI DeleteDC(HDC); WINGDIAPI BOOL WINAPI DeleteObject(HGDIOBJ); WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ); -// Routines for creation of a dummy device context and OpenGL context -// for the purposes of getting wglChoosePixelFormatARB and associated -// routines -WINGDIAPI HDC WINAPI GetDC(HDC); -WINGDIAPI HDC WINAPI CreateDummyWindow(int,int,int,int); -WINGDIAPI VOID WINAPI DestroyDummyWindow(HWND,HDC); -WINGDIAPI VOID WINAPI NativeEventLoop(); +// Routines for creation of a dummy window, device context and OpenGL +// context for the purposes of getting wglChoosePixelFormatARB and +// associated routines +HDC CreateDummyWindow(int,int,int,int); +WINUSERAPI BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow); +WINUSERAPI HDC WINAPI GetDC(HWND); +WINUSERAPI int WINAPI ReleaseDC(HWND hWnd, HDC hDC); +WINUSERAPI BOOL WINAPI DestroyWindow(HWND hWnd); diff --git a/make/stub_includes/common/gl-impl.c b/make/stub_includes/x11/glxext.c index 53221a21a..67906a088 100644 --- a/make/stub_includes/common/gl-impl.c +++ b/make/stub_includes/x11/glxext.c @@ -12,12 +12,3 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <GL/glxext.h> - -// Bring in the wgl extensions -#define WGL_WGLEXT_PROTOTYPES -#define SKIP_WGL_HANDLE_DEFINITIONS -#include <windows.h> -#include <GL/wglext.h> - -// Bring in the Mac OS X cgl extensions -#include <GL/cglext.h> diff --git a/make/wgl-CustomCCode.c b/make/wgl-CustomCCode.c index be233fd9a..0fe9ee628 100755 --- a/make/wgl-CustomCCode.c +++ b/make/wgl-CustomCCode.c @@ -1,37 +1,25 @@ #include <stdio.h> -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +#define JOGL_DUMMY_WINDOW_NAME "__jogl_dummy_window" + +LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + return DefWindowProc(hWnd,uMsg,wParam,lParam); +} + ATOM oglClass = 0; HWND CreateDummyWindow( int x, int y, int width, int height ) { - RECT rect; HINSTANCE hInstance; DWORD dwExStyle; DWORD dwStyle; HWND hWnd; - ZeroMemory( &rect, sizeof( rect ) ); - // I don't know if we need this but it can't hurt - if( width < 0 ) { - rect.left = x + width; - rect.right = x; - } else { - rect.left = x; - rect.right = x + width; - } - if( height < 0 ) { - rect.top = y + height; - rect.bottom = y; - } else { - rect.top = y; - rect.bottom = y + height; - } + hInstance = GetModuleHandle(NULL); - if( !oglClass ) { WNDCLASS wc; ZeroMemory( &wc, sizeof( wc ) ); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = (WNDPROC) WndProc; + wc.lpfnWndProc = (WNDPROC) DummyWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; @@ -39,7 +27,7 @@ HWND CreateDummyWindow( int x, int y, int width, int height ) { wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; - wc.lpszClassName = "OpenGL"; + wc.lpszClassName = JOGL_DUMMY_WINDOW_NAME; if( !(oglClass = RegisterClass( &wc )) ) { printf( "RegisterClass Failed: %d\n", GetLastError() ); return( 0 ); @@ -48,52 +36,13 @@ HWND CreateDummyWindow( int x, int y, int width, int height ) { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; - if( !(hWnd=CreateWindowEx( dwExStyle, "OpenGL", "OpenGL", + if( !(hWnd=CreateWindowEx( dwExStyle, + JOGL_DUMMY_WINDOW_NAME, + JOGL_DUMMY_WINDOW_NAME, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + x, y, width, height, NULL, NULL, hInstance, NULL ) ) ) { return( 0 ); } return( hWnd ); } - -void NativeEventLoop() { - MSG msg; - BOOL ret; - // Grab windows system messages from queue - while( ( ret = GetMessage( &msg, NULL, 0, 0 ) ) != 0 ) { - if( ret == -1 ) { - printf( "Error GetMessage: %d", GetLastError() ); - } else { - DispatchMessage( &msg ); - } - } -} - -void DestroyDummyWindow(HWND handle, HDC hdc) { - // Post a close window message from shutdown hook thread to - // window message pump thread - if( !PostMessage( handle, WM_CLOSE, 0, (LPARAM) hdc ) ) { - printf( "PostMessage Failed: %d\n", GetLastError() ); - } -} - -LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch( uMsg ) { - case WM_CLOSE: - // Destroy HDC - if( ReleaseDC( hWnd, (HDC) lParam ) != 1 ) { - printf( "Error Releasing DC: %d\n", GetLastError() ); - } - // Destroy HWND - if( DestroyWindow( hWnd ) == 0 ) { - printf( "Error Destroying Window: %d\n", GetLastError() ); - } - break; - case WM_DESTROY: - // Terminate Dummy Window - PostQuitMessage(0); - return(0); - } - return DefWindowProc(hWnd,uMsg,wParam,lParam); -} diff --git a/make/wglext.cfg b/make/wglext.cfg new file mode 100644 index 000000000..bc27252a5 --- /dev/null +++ b/make/wglext.cfg @@ -0,0 +1,58 @@ +# This .cfg file is used to generate the interface and implementing +# class for the WGL extensions. +Package com.sun.opengl.impl.windows +Style InterfaceAndImpl +JavaClass WGLExt +ImplPackage com.sun.opengl.impl.windows +ImplJavaClass WGLExtImpl +Include gl-common-win32.cfg + +EmitProcAddressTable true +ProcAddressTableClassName WGLExtProcAddressTable +ContextVariableName _context + +# Ignore everything that doesn't start with wgl or WGL +Ignore ^[^wW].+ + +CustomCCode #define WIN32_LEAN_AND_MEAN +CustomCCode #include <windows.h> +CustomCCode #undef WIN32_LEAN_AND_MEAN +CustomCCode #include <stdlib.h> +CustomCCode #include <stddef.h> +CustomCCode #include <malloc.h> + +CustomCCode /* Define GL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "glext.h" are parsed. */ +CustomCCode #define GL_GLEXT_PROTOTYPES + +CustomCCode /* Define WGL_GLEXT_PROTOTYPES so that the OpenGL extension prototypes in +CustomCCode "wglext.h" are parsed. */ +CustomCCode #define WGL_GLEXT_PROTOTYPES + +CustomCCode /* Include the OpenGL headers */ +CustomCCode #include <GL/gl.h> +CustomCCode #include <GL/wglext.h> + +CustomCCode /* This typedef is only needed for VC6 */ +CustomCCode #if _MSC_VER <= 1200 +CustomCCode typedef int intptr_t; +CustomCCode #endif + +CustomJavaCode WGLExt public boolean isFunctionAvailable(String glFunctionName); +CustomJavaCode WGLExt public boolean isExtensionAvailable(String glExtensionName); + +CustomJavaCode WGLExtImpl public WGLExtImpl(WindowsGLContext context) { +CustomJavaCode WGLExtImpl this._context = context; +CustomJavaCode WGLExtImpl } + +CustomJavaCode WGLExtImpl public boolean isFunctionAvailable(String glFunctionName) +CustomJavaCode WGLExtImpl { +CustomJavaCode WGLExtImpl return _context.isFunctionAvailable(glFunctionName); +CustomJavaCode WGLExtImpl } + +CustomJavaCode WGLExtImpl public boolean isExtensionAvailable(String glExtensionName) +CustomJavaCode WGLExtImpl { +CustomJavaCode WGLExtImpl return _context.isExtensionAvailable(glExtensionName); +CustomJavaCode WGLExtImpl } + +CustomJavaCode WGLExtImpl private WindowsGLContext _context; diff --git a/make/wingdi-win32.cfg b/make/wingdi-win32.cfg index a3c5a5ebb..d5b630a89 100644 --- a/make/wingdi-win32.cfg +++ b/make/wingdi-win32.cfg @@ -1,6 +1,6 @@ # This .cfg file is used to generate the interface to the wgl routines # used internally by the WindowsGLContext implementation. -Package net.java.games.jogl.impl.windows +Package com.sun.opengl.impl.windows JavaOutputDir ..\build\gensrc\classes NativeOutputDir ..\build\gensrc\native\jogl JavaClass WGL diff --git a/src/net/java/games/gluegen/ArrayTypes.java b/src/classes/com/sun/gluegen/ArrayTypes.java index 1a75f7306..7e5dd9597 100644 --- a/src/net/java/games/gluegen/ArrayTypes.java +++ b/src/classes/com/sun/gluegen/ArrayTypes.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.nio.*; diff --git a/src/net/java/games/gluegen/CMethodBindingEmitter.java b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java index f8afd06e4..70877ff5e 100644 --- a/src/net/java/games/gluegen/CMethodBindingEmitter.java +++ b/src/classes/com/sun/gluegen/CMethodBindingEmitter.java @@ -37,13 +37,13 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; import java.io.*; import java.text.MessageFormat; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** Emits the C-side component of the Java<->C JNI binding. */ public class CMethodBindingEmitter extends FunctionEmitter @@ -55,7 +55,7 @@ public class CMethodBindingEmitter extends FunctionEmitter protected static final String arrayRes = "_array_res"; protected static final String arrayIdx = "_array_idx"; - private MethodBinding binding; + protected MethodBinding binding; /** Name of the package in which the corresponding Java method resides.*/ private String packageName; @@ -75,6 +75,10 @@ public class CMethodBindingEmitter extends FunctionEmitter */ private boolean isJavaMethodStatic; + // Flags which change various aspects of glue code generation + protected boolean forImplementingMethodCall; + protected boolean forIndirectBufferAndArrayImplementation; + /** * Optional List of Strings containing temporary C variables to declare. */ @@ -115,11 +119,13 @@ public class CMethodBindingEmitter extends FunctionEmitter * being bound. */ public CMethodBindingEmitter(MethodBinding binding, - boolean isOverloadedBinding, + PrintWriter output, String javaPackageName, String javaClassName, + boolean isOverloadedBinding, boolean isJavaMethodStatic, - PrintWriter output) + boolean forImplementingMethodCall, + boolean forIndirectBufferAndArrayImplementation) { super(output); @@ -132,13 +138,17 @@ public class CMethodBindingEmitter extends FunctionEmitter this.className = javaClassName; this.isOverloadedBinding = isOverloadedBinding; this.isJavaMethodStatic = isJavaMethodStatic; + + this.forImplementingMethodCall = forImplementingMethodCall; + this.forIndirectBufferAndArrayImplementation = forIndirectBufferAndArrayImplementation; + setCommentEmitter(defaultCommentEmitter); } public final MethodBinding getBinding() { return binding; } public String getName() { - return binding.getName(); + return binding.getRenamedMethodName(); } /** @@ -151,8 +161,8 @@ public class CMethodBindingEmitter extends FunctionEmitter /** * If this function returns a void* encapsulated in a - * java.nio.Buffer, sets the expression for the capacity of the - * returned Buffer. + * java.nio.Buffer (or compound type wrapper), sets the expression + * for the capacity of the returned Buffer. * * @param expression a MessageFormat which, when applied to an array * of type String[] that contains each of the arguments names of the @@ -162,18 +172,20 @@ public class CMethodBindingEmitter extends FunctionEmitter * returned from this method. * * @throws IllegalArgumentException if the <code> - * binding.getJavaReturnType().isNIOBuffer() == false + * binding.getJavaReturnType().isNIOBuffer() == false and + * binding.getJavaReturnType().isCompoundTypeWrapper() == false * </code> */ public final void setReturnValueCapacityExpression(MessageFormat expression) { returnValueCapacityExpression = expression; - if (!binding.getJavaReturnType().isNIOBuffer()) + if (!binding.getJavaReturnType().isNIOBuffer() && + !binding.getJavaReturnType().isCompoundTypeWrapper()) { throw new IllegalArgumentException( "Cannot specify return value capacity for a method that does not " + - "return java.nio.Buffer: \"" + binding + "\""); + "return java.nio.Buffer or a compound type wrapper: \"" + binding + "\""); } } @@ -204,7 +216,8 @@ public class CMethodBindingEmitter extends FunctionEmitter { returnValueLengthExpression = expression; - if (!binding.getJavaReturnType().isArray()) + if (!binding.getJavaReturnType().isArray() && + !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers()) { throw new IllegalArgumentException( "Cannot specify return value length for a method that does not " + @@ -272,6 +285,12 @@ public class CMethodBindingEmitter extends FunctionEmitter */ public final boolean getIsJavaMethodStatic() { return isJavaMethodStatic; } + /** + * Is this CMethodBindingEmitter implementing the case of an + * indirect buffer or array being passed down to C code? + */ + public final boolean forIndirectBufferAndArrayImplementation() { return forIndirectBufferAndArrayImplementation; } + protected void emitReturnType(PrintWriter writer) { writer.print("JNIEXPORT "); @@ -290,15 +309,26 @@ public class CMethodBindingEmitter extends FunctionEmitter if (isOverloadedBinding) { writer.print(jniMangle(binding)); - //System.err.println("OVERLOADED MANGLING FOR " + binding.getName() + + //System.err.println("OVERLOADED MANGLING FOR " + getName() + // " = " + jniMangle(binding)); } else { - writer.print(jniMangle(binding.getName())); + writer.print(jniMangle(getName())); //System.err.println(" NORMAL MANGLING FOR " + binding.getName() + - // " = " + jniMangle(binding.getName())); + // " = " + jniMangle(getName())); + } + } + + protected String getImplSuffix() { + if (forImplementingMethodCall) { + if (forIndirectBufferAndArrayImplementation) { + return "1"; + } else { + return "0"; + } } + return ""; } protected int emitArguments(PrintWriter writer) @@ -338,8 +368,15 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print(" "); writer.print(binding.getArgumentName(i)); ++numEmitted; - } + if (javaArgType.isPrimitiveArray() || + javaArgType.isNIOBuffer()) { + writer.print(", jint " + byteOffsetArgName(i)); + } else if (javaArgType.isNIOBufferArray()) { + writer.print(", jintArray " + + byteOffsetArrayArgName(i)); + } + } return numEmitted; } @@ -378,7 +415,7 @@ public class CMethodBindingEmitter extends FunctionEmitter continue; } - if (type.isArray() || type.isNIOBuffer()) { + if (type.isArray() || type.isNIOBuffer() || type.isCompoundTypeWrapper()) { String convName = pointerConversionArgumentName(i); // handle array/buffer argument types boolean needsDataCopy = @@ -393,6 +430,10 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.println(" jobject _tmpObj;"); writer.println(" int _copyIndex;"); writer.println(" jsize _tmpArrayLen;"); + + // Pointer to the data in the Buffer, taking the offset into account + writer.println(" int * _offsetHandle = NULL;"); + emittedDataCopyTemps = true; } } else if (type.isString()) { @@ -413,37 +454,36 @@ public class CMethodBindingEmitter extends FunctionEmitter // Note we must respect const/volatile for return argument writer.print(binding.getCSymbol().getReturnType().getName(true)); writer.println(" _res;"); - if (javaReturnType.isArray()) { - if (javaReturnType.isNIOByteBufferArray()) { - writer.print(" int "); - writer.print(arrayResLength); - writer.println(";"); - writer.print(" int "); - writer.print(arrayIdx); - writer.println(";"); - writer.print(" jobjectArray "); - writer.print(arrayRes); - writer.println(";"); - } else { - writer.print(" int "); - writer.print(arrayResLength); - writer.println(";"); - - Class componentType = javaReturnType.getJavaClass().getComponentType(); - if (componentType.isArray()) { - throw new RuntimeException("Multi-dimensional arrays not supported yet"); - } + if (javaReturnType.isNIOByteBufferArray() || + javaReturnType.isArrayOfCompoundTypeWrappers()) { + writer.print(" int "); + writer.print(arrayResLength); + writer.println(";"); + writer.print(" int "); + writer.print(arrayIdx); + writer.println(";"); + writer.print(" jobjectArray "); + writer.print(arrayRes); + writer.println(";"); + } else if (javaReturnType.isArray()) { + writer.print(" int "); + writer.print(arrayResLength); + writer.println(";"); - String javaTypeName = componentType.getName(); - capitalizedComponentType = - "" + Character.toUpperCase(javaTypeName.charAt(0)) + javaTypeName.substring(1); - String javaArrayTypeName = "j" + javaTypeName + "Array"; - writer.print(" "); - writer.print(javaArrayTypeName); - writer.print(" "); - writer.print(arrayRes); - writer.println(";"); + Class componentType = javaReturnType.getJavaClass().getComponentType(); + if (componentType.isArray()) { + throw new RuntimeException("Multi-dimensional arrays not supported yet"); } + + String javaTypeName = componentType.getName(); + capitalizedComponentType = + "" + Character.toUpperCase(javaTypeName.charAt(0)) + javaTypeName.substring(1); + String javaArrayTypeName = "j" + javaTypeName + "Array"; + writer.print(" "); + writer.print(javaArrayTypeName); + writer.print(" "); + writer.print(arrayRes); + writer.println(";"); } } } @@ -460,6 +500,17 @@ public class CMethodBindingEmitter extends FunctionEmitter } } + /** Checks a type (expected to be pointer-to-pointer) for const-ness */ + protected boolean isConstPtrPtr(Type type) { + if (type.pointerDepth() != 2) { + return false; + } + if (type.asPointer().getTargetType().asPointer().getTargetType().isConst()) { + return true; + } + return false; + } + /** * Code to init the variables that were declared in * emitBodyVariableDeclarations(), PRIOR TO calling the actual C @@ -477,7 +528,8 @@ public class CMethodBindingEmitter extends FunctionEmitter binding.getContainingType(), binding.getContainingCType(), JavaMethodBindingEmitter.javaThisArgumentName(), - CMethodBindingEmitter.cThisArgumentName()); + CMethodBindingEmitter.cThisArgumentName(), + null); } for (int i = 0; i < binding.getNumArguments(); i++) { @@ -485,11 +537,14 @@ public class CMethodBindingEmitter extends FunctionEmitter if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { continue; } - if (type.isNIOBuffer()) { + + if (type.isCompoundTypeWrapper() || + (type.isNIOBuffer() && !forIndirectBufferAndArrayImplementation)) { emitPointerConversion(writer, binding, type, binding.getCArgumentType(i), binding.getArgumentName(i), - pointerConversionArgumentName(i)); + pointerConversionArgumentName(i), + byteOffsetArgName(i)); } } } @@ -502,9 +557,9 @@ public class CMethodBindingEmitter extends FunctionEmitter continue; } - if (javaArgType.isArray()) { + if (javaArgType.isArray() || + (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation)) { boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); - Class subArrayElementJavaType = javaArgType.getJavaClass().getComponentType(); // We only defer the emission of GetPrimitiveArrayCritical // calls that won't be matched up until after the function @@ -529,15 +584,17 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print(" "); writer.print(convName); writer.print(" = ("); - if (javaArgType.isArray() && - javaArgType.getJavaClass().getComponentType() == java.lang.String.class) { + if (javaArgType.isStringArray()) { // java-side type is String[] cArgTypeName = "jstring *"; } writer.print(cArgTypeName); - writer.print(") (*env)->GetPrimitiveArrayCritical(env, "); + writer.print(") (((char*) (*env)->GetPrimitiveArrayCritical(env, "); writer.print(binding.getArgumentName(i)); - writer.println(", NULL);"); + writer.println(", NULL)) + " + byteOffsetArgName(i) + ");"); +//if(cargtypename is void*) +// _ptrX = ((char*)convName + index1*sizeof(thisArgsJavaType)); + } else { // Handle the case where the array elements are of a type that needs a // data copy operation to convert from the java memory model to the C @@ -545,7 +602,7 @@ public class CMethodBindingEmitter extends FunctionEmitter // // FIXME: should factor out this whole block of code into a separate // method for clarity and maintenance purposes - if (cArgType.toString().indexOf("const") == -1) { + if (!isConstPtrPtr(cArgType)) { // FIXME: if the arg type is non-const, the sematics might be that // the function modifies the argument -- we don't yet support // this. @@ -592,34 +649,43 @@ public class CMethodBindingEmitter extends FunctionEmitter arrayLenName, "Could not allocate buffer for copying data in argument \\\""+binding.getArgumentName(i)+"\\\""); + // Get the handle for the byte offset array sent down for Buffers + // FIXME: not 100% sure this is correct with respect to the + // JNI spec because it may be illegal to call + // GetObjectArrayElement while in a critical section. May + // need to do another loop and add in the offsets. + if (javaArgType.isNIOBufferArray()) { + writer.println + (" _offsetHandle = (int *) (*env)->GetPrimitiveArrayCritical(env, " + + byteOffsetArrayArgName(i) + + ", NULL);"); + } + // process each element in the array writer.println(" for (_copyIndex = 0; _copyIndex < "+arrayLenName+"; ++_copyIndex) {"); // get each array element writer.println(" /* get each element of the array argument \"" + binding.getArgumentName(i) + "\" */"); - String subArrayElementJNITypeString = jniType(subArrayElementJavaType); - writer.print(" _tmpObj = ("); - writer.print(subArrayElementJNITypeString); - writer.print(") (*env)->GetObjectArrayElement(env, "); + writer.print(" _tmpObj = (*env)->GetObjectArrayElement(env, "); writer.print(binding.getArgumentName(i)); writer.println(", _copyIndex);"); - if (subArrayElementJNITypeString == "jstring") - { + if (javaArgType.isStringArray()) { writer.print(" "); emitGetStringUTFChars(writer, "(jstring) _tmpObj", - convName+"_copy[_copyIndex]"); - } - else if (isNIOBufferClass(subArrayElementJavaType)) - { + convName+"_copy[_copyIndex]", + true); + } else if (javaArgType.isNIOBufferArray()) { + /* We always assume an integer "byte offset" argument follows any Buffer + in the method binding. */ emitGetDirectBufferAddress(writer, "_tmpObj", cArgElementType.getName(), - convName + "_copy[_copyIndex]"); - } - else - { + convName + "_copy[_copyIndex]", + "_offsetHandle[_copyIndex]", + true); + } else { // Question: do we always need to copy the sub-arrays, or just // GetPrimitiveArrayCritical on each jobjectarray element and // assign it to the appropriate elements at pointer depth 1? @@ -627,29 +693,35 @@ public class CMethodBindingEmitter extends FunctionEmitter // Malloc enough space to hold a copy of each sub-array writer.print(" "); emitMalloc( - writer, - convName+"_copy[_copyIndex]", - cArgElementType.getTargetType().getName(), // assumes cArgPtrType is ptr-to-ptr-to-primitive !! - "(*env)->GetArrayLength(env, _tmpObj)", - "Could not allocate buffer during copying of data in argument \\\""+binding.getArgumentName(i)+"\\\""); + writer, + convName+"_copy[_copyIndex]", + cArgElementType.getTargetType().getName(), // assumes cArgPtrType is ptr-to-ptr-to-primitive !! + "(*env)->GetArrayLength(env, _tmpObj)", + "Could not allocate buffer during copying of data in argument \\\""+binding.getArgumentName(i)+"\\\""); // FIXME: copy the data (use matched Get/ReleasePrimitiveArrayCritical() calls) if (true) throw new RuntimeException( - "Cannot yet handle type \"" + cArgType.getName() + - "\"; need to add support for copying ptr-to-ptr-to-primitiveType subarrays"); + "Cannot yet handle type \"" + cArgType.getName() + + "\"; need to add support for copying ptr-to-ptr-to-primitiveType subarrays"); } writer.println(" }"); + if (javaArgType.isNIOBufferArray()) { + writer.println + (" (*env)->ReleasePrimitiveArrayCritical(env, " + + byteOffsetArrayArgName(i) + + ", _offsetHandle, JNI_ABORT);"); + } + writer.println(); } // end of data copy if (EMIT_NULL_CHECKS) { writer.println(" }"); } - } else if (javaArgType.isString()) { - if (emittingPrimitiveArrayCritical) { + if (!emittingPrimitiveArrayCritical) { continue; } @@ -661,7 +733,8 @@ public class CMethodBindingEmitter extends FunctionEmitter emitGetStringUTFChars(writer, binding.getArgumentName(i), - "_UTF8" + binding.getArgumentName(i)); + "_UTF8" + binding.getArgumentName(i), + false); if (EMIT_NULL_CHECKS) { writer.println(" }"); @@ -688,9 +761,10 @@ public class CMethodBindingEmitter extends FunctionEmitter if (javaArgType.isJNIEnv() || binding.isArgumentThisPointer(i)) { continue; } - if (javaArgType.isArray()) { + + if (javaArgType.isArray() || + (javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation)) { boolean needsDataCopy = javaArgTypeNeedsDataCopy(javaArgType); - Class subArrayElementJavaType = javaArgType.getJavaClass().getComponentType(); if ((!needsDataCopy && !emittingPrimitiveArrayCritical) || (needsDataCopy && emittingPrimitiveArrayCritical)) { @@ -736,7 +810,7 @@ public class CMethodBindingEmitter extends FunctionEmitter // Only need to perform cleanup for individual array // elements if they are not direct buffers - if (!isNIOBufferClass(subArrayElementJavaType)) { + if (!javaArgType.isNIOBufferArray()) { // Re-fetch length of array that was copied String arrayLenName = "_tmpArrayLen"; writer.print(" "); @@ -759,14 +833,11 @@ public class CMethodBindingEmitter extends FunctionEmitter // get each array element writer.println(" /* free each element of " +convName +"_copy */"); - String subArrayElementJNITypeString = jniType(subArrayElementJavaType); - writer.print(" _tmpObj = ("); - writer.print(subArrayElementJNITypeString); - writer.print(") (*env)->GetObjectArrayElement(env, "); + writer.print(" _tmpObj = (*env)->GetObjectArrayElement(env, "); writer.print(binding.getArgumentName(i)); writer.println(", _copyIndex);"); - if (subArrayElementJNITypeString == "jstring") { + if (javaArgType.isStringArray()) { writer.print(" (*env)->ReleaseStringUTFChars(env, "); writer.print("(jstring) _tmpObj"); writer.print(", "); @@ -818,24 +889,9 @@ public class CMethodBindingEmitter extends FunctionEmitter } } - protected void emitBodyCallCFunction(PrintWriter writer) - { - // Make the call to the actual C function - writer.print(" "); - - // WARNING: this code assumes that the return type has already been - // typedef-resolved. - Type cReturnType = binding.getCReturnType(); - - if (!cReturnType.isVoid()) { - writer.print("_res = "); - } - if (binding.hasContainingType()) { - // Call through function pointer - writer.print(CMethodBindingEmitter.cThisArgumentName() + "->"); - } - writer.print(binding.getCSymbol().getName()); - writer.print("("); + /** Returns the number of arguments passed so calling code knows + whether to print a comma */ + protected int emitBodyPassCArguments(PrintWriter writer) { for (int i = 0; i < binding.getNumArguments(); i++) { if (i != 0) { writer.print(", "); @@ -861,7 +917,7 @@ public class CMethodBindingEmitter extends FunctionEmitter if (binding.getCArgumentType(i).isPointer() && binding.getJavaArgumentType(i).isPrimitive()) { writer.print("(intptr_t) "); } - if (javaArgType.isArray() || javaArgType.isNIOBuffer()) { + if (javaArgType.isArray() || javaArgType.isNIOBuffer() || javaArgType.isCompoundTypeWrapper()) { writer.print(pointerConversionArgumentName(i)); if (javaArgTypeNeedsDataCopy(javaArgType)) { writer.print("_copy"); @@ -872,6 +928,28 @@ public class CMethodBindingEmitter extends FunctionEmitter } } } + return binding.getNumArguments(); + } + + protected void emitBodyCallCFunction(PrintWriter writer) { + + // Make the call to the actual C function + writer.print(" "); + + // WARNING: this code assumes that the return type has already been + // typedef-resolved. + Type cReturnType = binding.getCReturnType(); + + if (!cReturnType.isVoid()) { + writer.print("_res = "); + } + if (binding.hasContainingType()) { + // Call through function pointer + writer.print(CMethodBindingEmitter.cThisArgumentName() + "->"); + } + writer.print(binding.getCSymbol().getName()); + writer.print("("); + emitBodyPassCArguments(writer); writer.println(");"); } @@ -887,9 +965,6 @@ public class CMethodBindingEmitter extends FunctionEmitter } } - // FIXME: refactor this so that subclasses (in particular, - // net.java.games.gluegen.opengl.CGLPAWrapperEmitter) don't have to copy the whole - // method protected void emitBodyReturnResult(PrintWriter writer) { // WARNING: this code assumes that the return type has already been @@ -907,7 +982,8 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.print("(" + javaReturnType.jniTypeName() + ") (intptr_t) "); } writer.println("_res;"); - } else if (javaReturnType.isNIOBuffer()) { + } else if (javaReturnType.isNIOBuffer() || + javaReturnType.isCompoundTypeWrapper()) { writer.println(" if (_res == NULL) return NULL;"); writer.print(" return (*env)->NewDirectByteBuffer(env, _res, "); // See whether capacity has been specified @@ -925,7 +1001,7 @@ public class CMethodBindingEmitter extends FunctionEmitter cReturnType.asPointer().getTargetType().isCompound()) { sz = cReturnType.asPointer().getTargetType().getSize(); if (sz == -1) { - throw new InternalError( + throw new RuntimeException( "Error emitting code for compound return type "+ "for function \"" + binding + "\": " + "Structs to be emitted should have been laid out by this point " + @@ -946,64 +1022,67 @@ public class CMethodBindingEmitter extends FunctionEmitter } else if (javaReturnType.isString()) { writer.print(" if (_res == NULL) return NULL;"); writer.println(" return (*env)->NewStringUTF(env, _res);"); - } else if (javaReturnType.isArray()) { - if (javaReturnType.isNIOByteBufferArray()) { - writer.println(" if (_res == NULL) return NULL;"); - if (returnValueLengthExpression == null) { - throw new RuntimeException("Error while generating C code: no length specified for array returned from function " + - binding); - } - String[] argumentNames = new String[binding.getNumArguments()]; - for (int i = 0; i < binding.getNumArguments(); i++) { - argumentNames[i] = binding.getArgumentName(i); - } - writer.println(" " + arrayResLength + " = " + returnValueLengthExpression.format(argumentNames) + ";"); - writer.println(" " + arrayRes + " = (*env)->NewObjectArray(env, " + arrayResLength + ", (*env)->FindClass(env, \"java/nio/ByteBuffer\"), NULL);"); - writer.println(" for (" + arrayIdx + " = 0; " + arrayIdx + " < " + arrayResLength + "; " + arrayIdx + "++) {"); - Type retType = binding.getCSymbol().getReturnType(); - Type baseType; - if (retType.isPointer()) { - baseType = retType.asPointer().getTargetType().asPointer().getTargetType(); - } else { - baseType = retType.asArray().getElementType().asPointer().getTargetType(); - } - int sz = baseType.getSize(); - if (sz < 0) - sz = 0; - writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx + - ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], " + sz + "));"); - writer.println(" }"); - writer.println(" return " + arrayRes + ";"); + } else if (javaReturnType.isArrayOfCompoundTypeWrappers() || + (javaReturnType.isArray() && javaReturnType.isNIOByteBufferArray())) { + writer.println(" if (_res == NULL) return NULL;"); + if (returnValueLengthExpression == null) { + throw new RuntimeException("Error while generating C code: no length specified for array returned from function " + + binding); + } + String[] argumentNames = new String[binding.getNumArguments()]; + for (int i = 0; i < binding.getNumArguments(); i++) { + argumentNames[i] = binding.getArgumentName(i); + } + writer.println(" " + arrayResLength + " = " + returnValueLengthExpression.format(argumentNames) + ";"); + writer.println(" " + arrayRes + " = (*env)->NewObjectArray(env, " + arrayResLength + ", (*env)->FindClass(env, \"java/nio/ByteBuffer\"), NULL);"); + writer.println(" for (" + arrayIdx + " = 0; " + arrayIdx + " < " + arrayResLength + "; " + arrayIdx + "++) {"); + Type retType = binding.getCSymbol().getReturnType(); + Type baseType; + if (retType.isPointer()) { + baseType = retType.asPointer().getTargetType().asPointer().getTargetType(); } else { - // FIXME: must have user provide length of array in .cfg file - // by providing a constant value, input parameter, or - // expression which computes the array size (already present - // as ReturnValueCapacity, not yet implemented / tested here) - - throw new RuntimeException( - "Could not emit native code for function \"" + binding + - "\": array return values for non-char types not implemented yet"); - - // FIXME: This is approximately what will be required here - // - //writer.print(" "); - //writer.print(arrayRes); - //writer.print(" = (*env)->New"); - //writer.print(capitalizedComponentType); - //writer.print("Array(env, "); - //writer.print(arrayResLength); - //writer.println(");"); - //writer.print(" (*env)->Set"); - //writer.print(capitalizedComponentType); - //writer.print("ArrayRegion(env, "); - //writer.print(arrayRes); - //writer.print(", 0, "); - //writer.print(arrayResLength); - //writer.println(", _res);"); - //writer.print(" return "); - //writer.print(arrayRes); - //writer.println(";"); + baseType = retType.asArray().getElementType().asPointer().getTargetType(); } + int sz = baseType.getSize(); + if (sz < 0) + sz = 0; + writer.println(" (*env)->SetObjectArrayElement(env, " + arrayRes + ", " + arrayIdx + + ", (*env)->NewDirectByteBuffer(env, _res[" + arrayIdx + "], " + sz + "));"); + writer.println(" }"); + writer.println(" return " + arrayRes + ";"); + } else if (javaReturnType.isArray()) { + // FIXME: must have user provide length of array in .cfg file + // by providing a constant value, input parameter, or + // expression which computes the array size (already present + // as ReturnValueCapacity, not yet implemented / tested here) + + throw new RuntimeException( + "Could not emit native code for function \"" + binding + + "\": array return values for non-char types not implemented yet"); + + // FIXME: This is approximately what will be required here + // + //writer.print(" "); + //writer.print(arrayRes); + //writer.print(" = (*env)->New"); + //writer.print(capitalizedComponentType); + //writer.print("Array(env, "); + //writer.print(arrayResLength); + //writer.println(");"); + //writer.print(" (*env)->Set"); + //writer.print(capitalizedComponentType); + //writer.print("ArrayRegion(env, "); + //writer.print(arrayRes); + //writer.print(", 0, "); + //writer.print(arrayResLength); + //writer.println(", _res);"); + //writer.print(" return "); + //writer.print(arrayRes); + //writer.println(";"); + } else { + System.err.print("Unhandled return type: "); + javaReturnType.dump(); + throw new RuntimeException("Unhandled return type"); } } } @@ -1019,26 +1098,57 @@ public class CMethodBindingEmitter extends FunctionEmitter protected String jniMangle(MethodBinding binding) { StringBuffer buf = new StringBuffer(); - buf.append(jniMangle(binding.getName())); + buf.append(jniMangle(getName())); + buf.append(getImplSuffix()); buf.append("__"); + if (binding.hasContainingType()) { + // "this" argument always comes down in argument 0 as direct buffer + jniMangle(java.nio.ByteBuffer.class, buf, true); + } for (int i = 0; i < binding.getNumArguments(); i++) { + if (binding.isArgumentThisPointer(i)) { + continue; + } JavaType type = binding.getJavaArgumentType(i); - Class c = type.getJavaClass(); - if (c != null) { - jniMangle(c, buf); + if (type.isVoid()) { + // We should only see "void" as the first argument of a 1-argument function + // FIXME: should normalize this in the parser + if ((i != 0) || (binding.getNumArguments() > 1)) { + throw new RuntimeException("Saw illegal \"void\" argument while emitting \"" + getName() + "\""); + } } else { - // FIXME: add support for char* -> String conversion - throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); + Class c = type.getJavaClass(); + if (c != null) { + jniMangle(c, buf, false); + // If Buffer offset arguments were added, we need to mangle the JNI for the + // extra arguments + if (type.isNIOBuffer()) { + jniMangle(Integer.TYPE, buf, false); + } else if (type.isNIOBufferArray()) { + int[] intArrayType = new int[0]; + c = intArrayType.getClass(); + jniMangle(c , buf, true); + } + if (type.isPrimitiveArray()) { + jniMangle(Integer.TYPE, buf, false); + } + } else if (type.isCompoundTypeWrapper()) { + // Mangle wrappers for C structs as ByteBuffer + jniMangle(java.nio.ByteBuffer.class, buf, true); + } else if (type.isJNIEnv()) { + // These are not exposed at the Java level + } else { + // FIXME: add support for char* -> String conversion + throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); + } } } + return buf.toString(); } - protected void jniMangle(Class c, StringBuffer res) { - if (c.isArray()) { - res.append("_3"); - jniMangle(c.getComponentType(), res); - } else if (c.isPrimitive()) { + protected void jniMangle(Class c, StringBuffer res, boolean syntheticArgument) { + if (c.isPrimitive()) { if (c == Boolean.TYPE) res.append("Z"); else if (c == Byte.TYPE) res.append("B"); else if (c == Character.TYPE) res.append("C"); @@ -1047,29 +1157,40 @@ public class CMethodBindingEmitter extends FunctionEmitter else if (c == Long.TYPE) res.append("J"); else if (c == Float.TYPE) res.append("F"); else if (c == Double.TYPE) res.append("D"); - else throw new InternalError("Illegal primitive type"); + else throw new RuntimeException("Illegal primitive type \"" + c.getName() + "\""); } else { - res.append("L"); - res.append(c.getName().replace('.', '_')); - res.append("_2"); + // Arrays and NIO Buffers are always passed down as java.lang.Object. + // The only arrays that show up as true arrays in the signature + // are the synthetic byte offset arrays created when passing + // down arrays of direct Buffers. Compound type wrappers are + // passed down as ByteBuffers (no good reason, just to avoid + // accidental conflation) so we mangle them differently. + if (syntheticArgument) { + if (c.isArray()) { + res.append("_3"); + jniMangle(c.getComponentType(), res, false); + } else { + res.append("L"); + res.append(c.getName().replace('.', '_')); + res.append("_2"); + } + } else { + if (c.isArray()) { + res.append("_3"); + jniMangle(c.getComponentType(), res, false); + } else if (c == java.lang.String.class) { + res.append("L"); + res.append(c.getName().replace('.', '_')); + res.append("_2"); + } else { + res.append("L"); + res.append("java_lang_Object"); + res.append("_2"); + } + } } } - private String jniType(Class javaType) - { - if (javaType.isPrimitive()) { - return "j" + javaType.getName(); - } else if (javaType == java.lang.String.class) { - return "jstring"; - } else if (isNIOBufferClass(javaType)) { - return "jobject"; - } else { - throw new RuntimeException( - "Could not determine JNI type for Java class \"" + - javaType.getName() + "\"; was not String, primitive or direct buffer"); - } - } - private void emitOutOfMemoryCheck(PrintWriter writer, String varName, String errorMessage) { @@ -1079,7 +1200,7 @@ public class CMethodBindingEmitter extends FunctionEmitter writer.println(" (*env)->ThrowNew(env, (*env)->FindClass(env, \"java/lang/OutOfMemoryError\"),"); writer.print(" \"" + errorMessage); writer.print(" in native dispatcher for \\\""); - writer.print(binding.getName()); + writer.print(getName()); writer.println("\\\"\");"); writer.print(" return"); if (!binding.getJavaReturnType().isVoid()) { @@ -1114,11 +1235,14 @@ public class CMethodBindingEmitter extends FunctionEmitter private void emitGetStringUTFChars(PrintWriter writer, String sourceVarName, - String receivingVarName) + String receivingVarName, + boolean emitElseClause) { - writer.print(" if ("); - writer.print(sourceVarName); - writer.println(" != NULL) {"); + if (EMIT_NULL_CHECKS) { + writer.print(" if ("); + writer.print(sourceVarName); + writer.println(" != NULL) {"); + } writer.print(" "); writer.print(receivingVarName); writer.print(" = (*env)->GetStringUTFChars(env, "); @@ -1131,38 +1255,57 @@ public class CMethodBindingEmitter extends FunctionEmitter writer, receivingVarName, "Failed to get UTF-8 chars for argument \\\""+sourceVarName+"\\\""); } - writer.println(" } else {"); - writer.print(" "); - writer.print(receivingVarName); - writer.println(" = NULL;"); - writer.println(" }"); + if (EMIT_NULL_CHECKS) { + writer.print(" }"); + if (emitElseClause) { + writer.print(" else {"); + writer.print(" "); + writer.print(receivingVarName); + writer.println(" = NULL;"); + writer.println(" }"); + } else { + writer.println(); + } + } } + + private void emitGetDirectBufferAddress(PrintWriter writer, String sourceVarName, String receivingVarTypeString, - String receivingVarName) { + String receivingVarName, + String byteOffsetVarName, + boolean emitElseClause) { if (EMIT_NULL_CHECKS) { - writer.print(" if ("); + writer.print(" if ("); writer.print(sourceVarName); writer.println(" != NULL) {"); + writer.print(" "); } - writer.print(" "); + + writer.print(" "); writer.print(receivingVarName); writer.print(" = ("); writer.print(receivingVarTypeString); - writer.print(") (*env)->GetDirectBufferAddress(env, "); + + writer.print(") (((char*) (*env)->GetDirectBufferAddress(env, "); writer.print(sourceVarName); - writer.println(");"); + writer.println(")) + " + ((byteOffsetVarName != null) ? byteOffsetVarName : "0") + ");"); + if (EMIT_NULL_CHECKS) { - writer.println(" } else {"); - writer.print(" "); - writer.print(receivingVarName); - writer.println(" = NULL;"); - writer.println(" }"); + writer.print(" }"); + if (emitElseClause) { + writer.println(" else {"); + writer.print(" "); + writer.print(receivingVarName); + writer.println(" = NULL;"); + writer.println(" }"); + } else { + writer.println(); + } } } - // Note: if the data in the Type needs to be converted from the Java memory // model to the C memory model prior to calling any C-side functions, then @@ -1180,80 +1323,54 @@ public class CMethodBindingEmitter extends FunctionEmitter // // Note that we don't need to obey const/volatile for outgoing arguments // - if (javaType.isNIOBuffer()) - { + if (javaType.isNIOBuffer()) { ptrTypeString = cType.getName(); - } - else if (javaType.isArray()) { + } else if (javaType.isArray()) { needsDataCopy = javaArgTypeNeedsDataCopy(javaType); - // It's an array; get the type of the elements in the array - Class elementType = javaType.getJavaClass().getComponentType(); - if (elementType.isPrimitive()) - { + if (javaType.isPrimitiveArray() || + javaType.isNIOBufferArray()) { ptrTypeString = cType.getName(); - } - else if (elementType == java.lang.String.class) - { - ptrTypeString = "jstring"; - } - else if (elementType.isArray()) - { - Class subElementType = elementType.getComponentType(); - if (subElementType.isPrimitive()) - { - // type is pointer to pointer to primitive - ptrTypeString = cType.getName(); - } - else - { + } else if (!javaType.isStringArray()) { + Class elementType = javaType.getJavaClass().getComponentType(); + if (elementType.isArray()) { + Class subElementType = elementType.getComponentType(); + if (subElementType.isPrimitive()) { + // type is pointer to pointer to primitive + ptrTypeString = cType.getName(); + } else { + // type is pointer to pointer of some type we don't support (maybe + // it's an array of pointers to structs?) + throw new RuntimeException("Unsupported pointer type: \"" + cType.getName() + "\""); + } + } else { // type is pointer to pointer of some type we don't support (maybe // it's an array of pointers to structs?) throw new RuntimeException("Unsupported pointer type: \"" + cType.getName() + "\""); } - - } - else if (isNIOBufferClass(elementType)) - { - // type is an array of direct buffers of some sort - ptrTypeString = cType.getName(); } - else - { - // Type is pointer to something we can't/don't handle - throw new RuntimeException("Unsupported pointer type: \"" + cType.getName() + "\""); - } - } - else if (javaType.isArrayOfCompoundTypeWrappers()) - { + } else if (javaType.isArrayOfCompoundTypeWrappers()) { // FIXME throw new RuntimeException("Outgoing arrays of StructAccessors not yet implemented"); - } - else - { + } else { ptrTypeString = cType.getName(); } - if (!needsDataCopy) - { + if (!needsDataCopy) { // declare the pointer variable writer.print(" "); writer.print(ptrTypeString); writer.print(" "); writer.print(cVariableName); writer.println(" = NULL;"); - } - else - { + } else { // Declare a variable to hold a copy of the argument data in which the // incoming data has been properly laid out in memory to match the C // memory model - //writer.print(" const "); Class elementType = javaType.getJavaClass().getComponentType(); - if (javaType.isArray() && - javaType.getJavaClass().getComponentType() == java.lang.String.class) { + if (javaType.isStringArray()) { writer.print(" const char **"); } else { - writer.print(ptrTypeString); + writer.print(" " + ptrTypeString); } writer.print(" "); writer.print(cVariableName); @@ -1270,33 +1387,33 @@ public class CMethodBindingEmitter extends FunctionEmitter JavaType type, Type cType, String incomingArgumentName, - String cVariableName) { + String cVariableName, + String byteOffsetVarName) { + // Compound type wrappers do not get byte offsets added on + if (type.isCompoundTypeWrapper()) { + byteOffsetVarName = null; + } + emitGetDirectBufferAddress(writer, incomingArgumentName, cType.getName(), - cVariableName); + cVariableName, + byteOffsetVarName, + false); + } - /* - if (EMIT_NULL_CHECKS) { - writer.print(" if ("); - writer.print(incomingArgumentName); - writer.println(" != NULL) {"); - } - - writer.print(" "); - writer.print(cVariableName); - writer.print(" = ("); - writer.print(cType.getName()); - writer.print(") (*env)->GetDirectBufferAddress(env, "); - writer.print(incomingArgumentName); - writer.println(");"); - - if (EMIT_NULL_CHECKS) { - writer.println(" }"); - } - */ + protected String byteOffsetArgName(int i) { + return byteOffsetArgName(binding.getArgumentName(i)); } + protected String byteOffsetArgName(String s) { + return s + "_byte_offset"; + } + + protected String byteOffsetArrayArgName(int i) { + return binding.getArgumentName(i) + "_byte_offset_array"; + } + protected String pointerConversionArgumentName(int i) { return "_ptr" + i; } @@ -1328,16 +1445,10 @@ public class CMethodBindingEmitter extends FunctionEmitter protected boolean javaArgTypeNeedsDataCopy(JavaType javaArgType) { if (javaArgType.isArray()) { - Class subArrayElementJavaType = javaArgType.getJavaClass().getComponentType(); - return (subArrayElementJavaType.isArray() || - subArrayElementJavaType == java.lang.String.class || - isNIOBufferClass(subArrayElementJavaType)); + return (javaArgType.isNIOBufferArray() || + javaArgType.isStringArray() || + javaArgType.getJavaClass().getComponentType().isArray()); } return false; } - - protected static boolean isNIOBufferClass(Class c) { - return java.nio.Buffer.class.isAssignableFrom(c); - } } - diff --git a/src/net/java/games/gluegen/CodeGenUtils.java b/src/classes/com/sun/gluegen/CodeGenUtils.java index b89994cdf..553ef26b3 100644 --- a/src/net/java/games/gluegen/CodeGenUtils.java +++ b/src/classes/com/sun/gluegen/CodeGenUtils.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.io.*; import java.util.*; @@ -94,7 +94,7 @@ public class CodeGenUtils w.print(imports[i]); w.println(';'); } - w.println("import net.java.games.gluegen.runtime.*;"); + w.println("import com.sun.gluegen.runtime.*;"); w.println(); diff --git a/src/net/java/games/gluegen/CommentEmitter.java b/src/classes/com/sun/gluegen/CommentEmitter.java index 10256acba..30004f8bc 100644 --- a/src/net/java/games/gluegen/CommentEmitter.java +++ b/src/classes/com/sun/gluegen/CommentEmitter.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.io.*; diff --git a/src/net/java/games/gluegen/DebugEmitter.java b/src/classes/com/sun/gluegen/DebugEmitter.java index c8e8b3869..bbcde0e0d 100644 --- a/src/net/java/games/gluegen/DebugEmitter.java +++ b/src/classes/com/sun/gluegen/DebugEmitter.java @@ -37,11 +37,11 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** Debug emitter which prints the parsing results to standard output. */ diff --git a/src/net/java/games/gluegen/FunctionEmitter.java b/src/classes/com/sun/gluegen/FunctionEmitter.java index 77a79b6fc..baf08b93a 100644 --- a/src/net/java/games/gluegen/FunctionEmitter.java +++ b/src/classes/com/sun/gluegen/FunctionEmitter.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; import java.io.*; diff --git a/src/net/java/games/gluegen/GlueEmitter.java b/src/classes/com/sun/gluegen/GlueEmitter.java index 00147dfd2..d6f5fede8 100644 --- a/src/net/java/games/gluegen/GlueEmitter.java +++ b/src/classes/com/sun/gluegen/GlueEmitter.java @@ -37,10 +37,10 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** Specifies the interface by which GlueGen requests glue code to be generated. Can be replaced to generate glue code for other diff --git a/src/net/java/games/gluegen/GlueEmitterControls.java b/src/classes/com/sun/gluegen/GlueEmitterControls.java index 15df83654..46ff9fd91 100644 --- a/src/net/java/games/gluegen/GlueEmitterControls.java +++ b/src/classes/com/sun/gluegen/GlueEmitterControls.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; /** Specifies the interface by which a GlueEmitter can request additional information from the glue generator. */ @@ -46,4 +46,8 @@ public interface GlueEmitterControls { /** Requests emission of an accessor for a struct that will not be referenced by any functions or other structs. */ public void forceStructEmission(String typedefName); + + /** Finds the full path name of the specified header file based on + the include directories specified on the command line. */ + public String findHeaderFile(String headerFileName); } diff --git a/src/net/java/games/gluegen/GlueGen.java b/src/classes/com/sun/gluegen/GlueGen.java index 442f6405b..c192ae8cd 100644 --- a/src/net/java/games/gluegen/GlueGen.java +++ b/src/classes/com/sun/gluegen/GlueGen.java @@ -37,26 +37,31 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.io.*; import java.util.*; import antlr.*; import antlr.collections.*; -import net.java.games.gluegen.cgram.*; -import net.java.games.gluegen.cgram.types.*; -import net.java.games.gluegen.pcpp.*; +import com.sun.gluegen.cgram.*; +import com.sun.gluegen.cgram.types.*; +import com.sun.gluegen.pcpp.*; /** Glue code generator for C functions and data structures. */ public class GlueGen implements GlueEmitterControls { private java.util.List forcedStructNames = new ArrayList(); + private PCPP preprocessor; public void forceStructEmission(String typedefName) { forcedStructNames.add(typedefName); } + public String findHeaderFile(String headerFileName) { + return preprocessor.findFile(headerFileName); + } + public void run(String[] args) { try { Reader reader = null; @@ -99,7 +104,7 @@ public class GlueGen implements GlueEmitterControls { } } - final PCPP preprocessor = new PCPP(includePaths); + preprocessor = new PCPP(includePaths); PipedInputStream ppIn = new PipedInputStream(); final PipedOutputStream ppOut = new PipedOutputStream(ppIn); preprocessor.setOut(ppOut); @@ -311,8 +316,8 @@ public class GlueGen implements GlueEmitterControls { System.out.println("passing input through minimal pseudo-C-preprocessor. Use -I"); System.out.println("command-line arguments to specify the search path for #includes."); System.out.println("Emitter class name can be specified with -E option: i.e.,"); - System.out.println("-Enet.java.games.gluegen.JavaEmitter (the default). Use"); - System.out.println("-Enet.java.games.gluegen.DebugEmitter to print recognized entities"); + System.out.println("-Ecom.sun.gluegen.JavaEmitter (the default). Use"); + System.out.println("-Ecom.sun.gluegen.DebugEmitter to print recognized entities"); System.out.println("(#define directives to constant numbers, typedefs, and function"); System.out.println("declarations) to standard output. Emitter-specific configuration"); System.out.println("file or files can be specified with -C option; e.g,"); diff --git a/src/net/java/games/gluegen/JavaConfiguration.java b/src/classes/com/sun/gluegen/JavaConfiguration.java index 8722725df..a48582a3f 100644 --- a/src/net/java/games/gluegen/JavaConfiguration.java +++ b/src/classes/com/sun/gluegen/JavaConfiguration.java @@ -37,18 +37,19 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.io.*; import java.util.*; import java.util.regex.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** Parses and provides access to the contents of .cfg files for the JavaEmitter. */ public class JavaConfiguration { + private int nestedReads; private String packageName; private String implPackageName; @@ -85,6 +86,7 @@ public class JavaConfiguration { * checks fail. Defaults to RuntimeException. */ private String runtimeExceptionType = "RuntimeException"; + private Map/*<String,Integer>*/ accessControl = new HashMap(); private Map/*<String,TypeInfo>*/ typeInfoMap = new HashMap(); private Set/*<String>*/ returnsString = new HashSet(); private Map/*<String, String>*/ returnedArrayLengths = new HashMap(); @@ -94,24 +96,16 @@ public class JavaConfiguration { */ private Map/*<String,List<Integer>>*/ argumentsAreString = new HashMap(); private Set/*<Pattern>*/ ignores = new HashSet(); + private Map/*<String,Pattern>*/ ignoreMap = new HashMap(); private Set/*<Pattern>*/ ignoreNots = new HashSet(); private Set/*<Pattern>*/ unimplemented = new HashSet(); - private Set/*<String>*/ nioOnly = new HashSet(); - /** See {@link #nioMode} */ - public static final int NIO_MODE_VOID_ONLY = 1; - /** See {@link #nioMode} */ - public static final int NIO_MODE_ALL_POINTERS = 2; - private int nioMode = NIO_MODE_VOID_ONLY; - private Set/*<String>*/ noNio = new HashSet(); - private Set/*<String>*/ forcedNio = new HashSet(); - private boolean flattenNIOVariants = true; + private Set/*<String>*/ nioDirectOnly = new HashSet(); private Set/*<String>*/ manuallyImplement = new HashSet(); private Map/*<String,List<String>>*/ customJavaCode = new HashMap(); private Map/*<String,List<String>>*/ classJavadoc = new HashMap(); private Map/*<String,String>*/ structPackages = new HashMap(); private List/*<String>*/ customCCode = new ArrayList(); private List/*<String>*/ forcedStructs = new ArrayList(); - private Map/*<String,List<Integer>>*/ mirroredArgs = new HashMap(); private Map/*<String, String>*/ returnValueCapacities = new HashMap(); private Map/*<String, String>*/ returnValueLengths = new HashMap(); private Map/*<String, List<String>>*/ temporaryCVariableDeclarations = new HashMap(); @@ -119,6 +113,9 @@ public class JavaConfiguration { private Map/*<String,List<String>>*/ extendedInterfaces = new HashMap(); private Map/*<String,List<String>>*/ implementedInterfaces = new HashMap(); private Map/*<String,String>*/ javaTypeRenames = new HashMap(); + private Map/*<String,String>*/ javaMethodRenames = new HashMap(); + private Map/*<String,List<String>>*/ javaPrologues = new HashMap(); + private Map/*<String,List<String>>*/ javaEpilogues = new HashMap(); /** Reads the configuration file. @param filename path to file that should be read @@ -182,10 +179,10 @@ public class JavaConfiguration { "\"Style AllStatic\""); } - if (className == null) { + if (className == null && (emissionStyle() != JavaEmitter.IMPL_ONLY)) { throw new RuntimeException("Output class name was not specified in configuration file"); } - if (packageName == null) { + if (packageName == null && (emissionStyle() != JavaEmitter.IMPL_ONLY)) { throw new RuntimeException("Output package name was not specified in configuration file"); } @@ -198,11 +195,17 @@ public class JavaConfiguration { if (implClassName == null) { // implClassName defaults to "<className>Impl" if ImplJavaClass // directive is not used + if (className == null) { + throw new RuntimeException("If ImplJavaClass is not specified, must specify JavaClass"); + } implClassName = className + "Impl"; } if (implPackageName == null) { // implPackageName defaults to "<packageName>.impl" if ImplPackage // directive is not used + if (packageName == null) { + throw new RuntimeException("If ImplPackageName is not specified, must specify PackageName"); + } implPackageName = packageName + ".impl"; } } @@ -225,6 +228,16 @@ public class JavaConfiguration { public boolean nativeOutputUsesJavaHierarchy() { return nativeOutputUsesJavaHierarchy; } /** Returns the code emission style (constants in JavaEmitter) parsed from the configuration file. */ public int emissionStyle() { return emissionStyle; } + /** Returns the access control for the emitted Java method. Returns one of JavaEmitter.ACC_PUBLIC, JavaEmitter.ACC_PROTECTED, JavaEmitter.ACC_PRIVATE, or JavaEmitter.ACC_PACKAGE_PRIVATE. */ + public int accessControl(String methodName) { + Integer ret = (Integer) accessControl.get(methodName); + if (ret != null) { + return ret.intValue(); + } + // Default access control is public + return JavaEmitter.ACC_PUBLIC; + } + /** Returns the kind of exception to raise if run-time checks fail in the generated code. */ public String runtimeExceptionType() { return runtimeExceptionType; } /** Returns the list of imports that should be emitted at the top of each .java file. */ @@ -316,42 +329,8 @@ public class JavaConfiguration { /** Returns true if the given function should only create a java.nio variant, and no array variants, for <code>void*</code> and other C primitive pointers. */ - public boolean nioOnly(String functionName) { - return nioOnly.contains(functionName); - } - - /** Returns true if the user requested that the given function - should only create array variants, and no java.nio variant, for - <code>void*</code> and other C primitive pointers, overriding - the NIO mode default. */ - public boolean noNio(String functionName) { - return noNio.contains(functionName); - } - - /** Returns true if the user requested that the given function - should create a java.nio variant for the given function's - <code>void*</code> and other C primitive pointers, overriding - the NIO mode default. */ - public boolean forcedNio(String functionName) { - return forcedNio.contains(functionName); - } - - /** Returns the default NIO generation mode for C primitive pointer - arguments. NIO_MODE_VOID_ONLY is the default and specifies - that only void* arguments will have java.nio variants generated - for them. NIO_MODE_ALL_POINTERS specifies that all C - primitive arguments will have java.nio variants generated. */ - public int nioMode() { - return nioMode; - } - - /** Returns true if, for the plethora of java.nio variants generated - for primitive C pointer types, the emitter should flatten the - output down to two variants: one taking only Java primitive - arrays as arguments, and one taking only java.nio.Buffers as - arguments. */ - public boolean flattenNIOVariants() { - return flattenNIOVariants; + public boolean nioDirectOnly(String functionName) { + return nioDirectOnly.contains(functionName); } /** Returns true if the glue code for the given function will be @@ -409,14 +388,6 @@ public class JavaConfiguration { return forcedStructs; } - /** Returns a List of Integers indicating the indices of arguments - in this function that should be expanded to the same type when - binding functions with multiple void* arguments. Returns null if - no such indices were specified. */ - public List/*<Integer>*/ mirroredArgs(String functionName) { - return (List) mirroredArgs.get(functionName); - } - /** Returns a MessageFormat string of the C expression calculating the capacity of the java.nio.ByteBuffer being returned from a native method, or null if no expression has been specified. */ @@ -540,6 +511,14 @@ public class JavaConfiguration { return javaTypeName; } + /** Returns a replacement name for this function which should be + used as the Java name for the bound method. It still calls the + originally-named C function under the hood. Returns null if this + function has not been explicitly renamed. */ + public String getJavaMethodRename(String functionName) { + return (String) javaMethodRenames.get(functionName); + } + /** Returns true if the emission style is AllStatic. */ public boolean allStatic() { return (emissionStyle == JavaEmitter.ALL_STATIC); @@ -558,6 +537,38 @@ public class JavaConfiguration { emissionStyle() == JavaEmitter.IMPL_ONLY); } + /** Returns a list of Strings which should be emitted as a prologue + to the body for the Java-side glue code for the given method. + Returns null if no prologue was specified. */ + public List/*<String>*/ javaPrologueForMethod(MethodBinding binding, + boolean forImplementingMethodCall, + boolean eraseBufferAndArrayTypes) { + List/*<String>*/ res = (List/*<String>*/) javaPrologues.get(binding.getName()); + if (res == null) { + // Try again with method name and descriptor + res = (List/*<String>*/) javaPrologues.get(binding.getName() + + binding.getDescriptor(forImplementingMethodCall, + eraseBufferAndArrayTypes)); + } + return res; + } + + /** Returns a list of Strings which should be emitted as an epilogue + to the body for the Java-side glue code for the given method. + Returns null if no epilogue was specified. */ + public List/*<String>*/ javaEpilogueForMethod(MethodBinding binding, + boolean forImplementingMethodCall, + boolean eraseBufferAndArrayTypes) { + List/*<String>*/ res = (List/*<String>*/) javaEpilogues.get(binding.getName()); + if (res == null) { + // Try again with method name and descriptor + res = (List/*<String>*/) javaEpilogues.get(binding.getName() + + binding.getDescriptor(forImplementingMethodCall, + eraseBufferAndArrayTypes)); + } + return res; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -593,6 +604,8 @@ public class JavaConfiguration { System.err.println("WARNING: Error parsing \"style\" command at line " + lineNo + " in file \"" + filename + "\""); } + } else if (cmd.equalsIgnoreCase("AccessControl")) { + readAccessControl(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("Import")) { imports.add(readString("Import", tok, filename, lineNo)); } else if (cmd.equalsIgnoreCase("Opaque")) { @@ -607,6 +620,8 @@ public class JavaConfiguration { readArgumentIsString(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("Ignore")) { readIgnore(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("Unignore")) { + readUnignore(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("IgnoreNot")) { readIgnoreNot(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("Unimplemented")) { @@ -627,20 +642,10 @@ public class JavaConfiguration { readClassJavadoc(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because readClassJavadoc changes them. - } else if (cmd.equalsIgnoreCase("NioOnly")) { - nioOnly.add(readString("NioOnly", tok, filename, lineNo)); - } else if (cmd.equalsIgnoreCase("NoNio")) { - noNio.add(readString("NoNio", tok, filename, lineNo)); - } else if (cmd.equalsIgnoreCase("ForcedNio")) { - forcedNio.add(readString("ForcedNio", tok, filename, lineNo)); - } else if (cmd.equalsIgnoreCase("NioMode")) { - readNioMode(tok, filename, lineNo); - } else if (cmd.equalsIgnoreCase("FlattenNIOVariants")) { - flattenNIOVariants = readBoolean("FlattenNIOVariants", tok, filename, lineNo).booleanValue(); + } else if (cmd.equalsIgnoreCase("NioDirectOnly")) { + nioDirectOnly.add(readString("NioDirectOnly", tok, filename, lineNo)); } else if (cmd.equalsIgnoreCase("EmitStruct")) { forcedStructs.add(readString("EmitStruct", tok, filename, lineNo)); - } else if (cmd.equalsIgnoreCase("MirrorExpandedBindingArgs")) { - readMirrorExpandedBindingArgs(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("StructPackage")) { readStructPackage(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("TemporaryCVariableDeclaration")) { @@ -669,8 +674,18 @@ public class JavaConfiguration { readImplements(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("RenameJavaType")) { readRenameJavaType(tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("RenameJavaMethod")) { + readRenameJavaMethod(tok, filename, lineNo); } else if (cmd.equalsIgnoreCase("RuntimeExceptionType")) { runtimeExceptionType = readString("RuntimeExceptionType", tok, filename, lineNo); + } else if (cmd.equalsIgnoreCase("JavaPrologue")) { + readJavaPrologueOrEpilogue(tok, filename, lineNo, true); + // Warning: make sure delimiters are reset at the top of this loop + // because readJavaPrologueOrEpilogue changes them. + } else if (cmd.equalsIgnoreCase("JavaEpilogue")) { + readJavaPrologueOrEpilogue(tok, filename, lineNo, false); + // Warning: make sure delimiters are reset at the top of this loop + // because readJavaPrologueOrEpilogue changes them. } else { throw new RuntimeException("Unknown command \"" + cmd + "\" in command file " + filename + @@ -708,6 +723,30 @@ public class JavaConfiguration { throw new RuntimeException("Only primitive types are supported here"); } + protected void readAccessControl(StringTokenizer tok, String filename, int lineNo) { + try { + String methodName = tok.nextToken(); + String style = tok.nextToken(); + int acc = 0; + if (style.equalsIgnoreCase("PUBLIC")) { + acc = JavaEmitter.ACC_PUBLIC; + } else if (style.equalsIgnoreCase("PROTECTED")) { + acc = JavaEmitter.ACC_PROTECTED; + } else if (style.equalsIgnoreCase("PRIVATE")) { + acc = JavaEmitter.ACC_PRIVATE; + } else if (style.equalsIgnoreCase("PACKAGE_PRIVATE")) { + acc = JavaEmitter.ACC_PRIVATE; + } else { + throw new RuntimeException("Error parsing \"AccessControl\" command at line " + lineNo + + " in file \"" + filename + "\""); + } + accessControl.put(methodName, new Integer(acc)); + } catch (Exception e) { + throw new RuntimeException("Error parsing \"AccessControl\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected void readOpaque(StringTokenizer tok, String filename, int lineNo) { try { JavaType javaType = JavaType.createForClass(stringToPrimitiveType(tok.nextToken())); @@ -756,7 +795,9 @@ public class JavaConfiguration { protected void readIgnore(StringTokenizer tok, String filename, int lineNo) { try { String regex = tok.nextToken(); - ignores.add(Pattern.compile(regex)); + Pattern pattern = Pattern.compile(regex); + ignores.add(pattern); + ignoreMap.put(regex, pattern); //System.err.println("IGNORING " + regex + " / " + ignores.get(regex)); } catch (NoSuchElementException e) { throw new RuntimeException("Error parsing \"Ignore\" command at line " + lineNo + @@ -764,6 +805,19 @@ public class JavaConfiguration { } } + protected void readUnignore(StringTokenizer tok, String filename, int lineNo) { + try { + String regex = tok.nextToken(); + Pattern pattern = (Pattern) ignoreMap.get(regex); + ignoreMap.remove(regex); + ignores.remove(pattern); + //System.err.println("UN-IGNORING " + regex + " / " + ignores.get(regex)); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"Unignore\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected void readIgnoreNot(StringTokenizer tok, String filename, int lineNo) { try { String regex = tok.nextToken(); @@ -848,119 +902,6 @@ public class JavaConfiguration { codeList.add(code); } - /** - * Sets the default NIO generation mode for C primitive - * pointers. Options are VOID_ONLY or ALL_POINTERS. When the mode is - * set to VOID_ONLY, java.nio variants of methods are only generated - * for C primitive pointers of type <code>void*</code>. All other - * pointers are translated by default into Java primitive arrays. - * When the mode is set to ALL_POINTERS, C primitive pointers of - * other types (i.e., <code>int*</code>) will have java.nio variants - * generated for them (i.e., <code>IntBuffer</code> as opposed to - * merely <code>int[]</code>). This default mode can be overridden - * with the NioOnly and NoNio directives. The default for this mode - * is currently VOID_ONLY. - */ - protected void readNioMode(StringTokenizer tok, String filename, int lineNo) { - try { - String mode = tok.nextToken(); - if (mode.equalsIgnoreCase("VOID_ONLY")) { - nioMode = NIO_MODE_VOID_ONLY; - } else if (mode.equalsIgnoreCase("ALL_POINTERS")) { - nioMode = NIO_MODE_ALL_POINTERS; - } else { - throw new RuntimeException("Error parsing \"NioMode\" command at line " + lineNo + - " in file \"" + filename + "\"; expected VOID_ONLY or ALL_POINTERS"); - } - } catch (NoSuchElementException e) { - throw new RuntimeException( - "Error parsing \"NioMode\" command at line " + lineNo + - " in file \"" + filename + "\"", e); - } - } - - /** - * When void* arguments in the C function prototypes are encountered, the - * emitter will try to expand the binding and create Java entry points for - * all possible array types. If there are 2 or more void* arguments in the C - * prototype, this directive lets you specify which of those arguments - * should always be expanded to the same type. <p> - * - * For example, given the C prototype: - * <pre> - * void FuncName(void *foo, void *bar); - * </pre> - * - * The emitter will normally emit multiple Java entry points: - * <pre> - * public abstract void FuncName(boolean[] foo, java.nio.Buffer bar); - * public abstract void FuncName(boolean[] foo, boolean[] bar); - * public abstract void FuncName(boolean[] foo, byte[] bar); - * public abstract void FuncName(boolean[] foo, char[] bar); - * public abstract void FuncName(boolean[] foo, short[] bar); - * public abstract void FuncName(boolean[] foo, int[] bar); - * public abstract void FuncName(boolean[] foo, long[] bar); - * public abstract void FuncName(boolean[] foo, float[] bar); - * public abstract void FuncName(boolean[] foo, double[] bar); - * - * public abstract void FuncName(byte[] foo, java.nio.Buffer bar); - * public abstract void FuncName(byte[] foo, boolean[] bar); - * public abstract void FuncName(byte[] foo, byte[] bar); - * <...etc for all variants on the second parameter...> - * - * public abstract void FuncName(char[] foo, java.nio.Buffer bar); - * public abstract void FuncName(char[] foo, boolean[] bar); - * public abstract void FuncName(char[] foo, byte[] bar); - * <...etc for all variants on the second parameter...> - * <...and so on for all remaining variants on the first parameter...> - * </pre> - * - * This directive lets you specify that arguments at a particular index - * should always be expanded to the same type. For example, the directive: - * <pre> - * MirrorExpandedBindingArgs FuncName 0 1 - * </pre> - * will force the first and second arguments in function FuncName to be - * expanded identically. This would result in the emission of the following - * entry points only: - * <pre> - * public abstract void FuncName(java.nio.Buffer[] foo, java.nio.Buffer bar); - * public abstract void FuncName(boolean[] foo, boolean[] bar); - * public abstract void FuncName(byte[] foo, byte[] bar); - * public abstract void FuncName(char[] foo, char[] bar); - * public abstract void FuncName(short[] foo, short[] bar); - * public abstract void FuncName(int[] foo, int[] bar); - * public abstract void FuncName(long[] foo, long[] bar); - * public abstract void FuncName(float[] foo, float[] bar); - * public abstract void FuncName(double[] foo, double[] bar); - * </pre> - */ - protected void readMirrorExpandedBindingArgs(StringTokenizer tok, String filename, int lineNo) { - try { - String methodName = tok.nextToken(); - ArrayList argIndices = new ArrayList(2); - while (tok.hasMoreTokens()) - { - Integer idx = Integer.valueOf(tok.nextToken()); - argIndices.add(idx); - } - - if(argIndices.size() > 1) - { - mirroredArgs.put(methodName, argIndices); - } - else - { - throw new RuntimeException("ERROR: Error parsing \"MirrorExpandedBindingArgs\" command at line " + lineNo + - " in file \"" + filename + "\": directive requires at least 2 argument indices"); - } - } catch (NoSuchElementException e) { - throw new RuntimeException( - "Error parsing \"MirrorExpandedBindingArgs\" command at line " + lineNo + - " in file \"" + filename + "\"", e); - } - } - /** * When const char* arguments in the C function prototypes are encountered, * the emitter will normally convert them to <code>byte[]</code> @@ -1150,6 +1091,46 @@ public class JavaConfiguration { } } + protected void readRenameJavaMethod(StringTokenizer tok, String filename, int lineNo) { + try { + String fromName = tok.nextToken(); + String toName = tok.nextToken(); + javaMethodRenames.put(fromName, toName); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"RenameJavaMethod\" command at line " + lineNo + + " in file \"" + filename + "\": missing expected parameter", e); + } + } + + protected void readJavaPrologueOrEpilogue(StringTokenizer tok, String filename, int lineNo, boolean prologue) { + try { + String methodName = tok.nextToken(); + String restOfLine = tok.nextToken("\n\r\f"); + restOfLine = restOfLine.trim(); + if (startsWithDescriptor(restOfLine)) { + // Assume it starts with signature for disambiguation + int spaceIdx = restOfLine.indexOf(' '); + if (spaceIdx > 0) { + String descriptor = restOfLine.substring(0, spaceIdx); + restOfLine = restOfLine.substring(spaceIdx + 1, restOfLine.length()); + methodName = methodName + descriptor; + } + } + Map code = (prologue ? javaPrologues : javaEpilogues); + List/*<String>*/ data = (List/*<String>*/) code.get(methodName); + if (data == null) { + data = new ArrayList/*<String>*/(); + code.put(methodName, data); + } + data.add(restOfLine); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"" + + (prologue ? "JavaPrologue" : "JavaEpilogue") + + "\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected static TypeInfo parseTypeInfo(String cType, JavaType javaType) { String typeName = null; int pointerDepth = 0; @@ -1181,4 +1162,71 @@ public class JavaConfiguration { } tmp.setNext(info); } + + private static int nextIndexAfterType(String s, int idx) { + int len = s.length(); + while (idx < len) { + char c = s.charAt(idx); + + if (Character.isJavaIdentifierStart(c) || + Character.isJavaIdentifierPart(c) || + (c == '/')) { + idx++; + } else if (c == ';') { + return (idx + 1); + } else { + return -1; + } + } + return -1; + } + + private static int nextIndexAfterDescriptor(String s, int idx) { + char c = s.charAt(idx); + switch (c) { + case 'B': + case 'C': + case 'D': + case 'F': + case 'I': + case 'J': + case 'S': + case 'Z': + case 'V': return (1 + idx); + case 'L': return nextIndexAfterType(s, idx + 1); + case ')': return idx; + default: break; + } + return -1; + } + + protected static boolean startsWithDescriptor(String s) { + // Try to see whether the String s starts with a valid Java + // descriptor. + + int idx = 0; + int len = s.length(); + while ((idx < len) && s.charAt(idx) == ' ') { + ++idx; + } + + if (idx >= len) return false; + if (s.charAt(idx++) != '(') return false; + while (idx < len) { + int nextIdx = nextIndexAfterDescriptor(s, idx); + if (nextIdx < 0) { + return false; + } + if (nextIdx == idx) { + // ')' + break; + } + idx = nextIdx; + } + int nextIdx = nextIndexAfterDescriptor(s, idx + 1); + if (nextIdx < 0) { + return false; + } + return true; + } } diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/classes/com/sun/gluegen/JavaEmitter.java index ba412fb55..24687d36f 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/classes/com/sun/gluegen/JavaEmitter.java @@ -37,13 +37,13 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.io.*; import java.util.*; import java.text.MessageFormat; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; // PROBLEMS: // - what if something returns 'const int *'? Could we @@ -68,10 +68,18 @@ public class JavaEmitter implements GlueEmitter { * (InterfaceAndImpl), only the interface (InterfaceOnly), or only * the implementation (ImplOnly). */ - static final int ALL_STATIC = 1; - static final int INTERFACE_AND_IMPL = 2; - static final int INTERFACE_ONLY = 3; - static final int IMPL_ONLY = 4; + public static final int ALL_STATIC = 1; + public static final int INTERFACE_AND_IMPL = 2; + public static final int INTERFACE_ONLY = 3; + public static final int IMPL_ONLY = 4; + + /** + * Access control for emitted Java methods. + */ + public static final int ACC_PUBLIC = 1; + public static final int ACC_PROTECTED = 2; + public static final int ACC_PRIVATE = 3; + public static final int ACC_PACKAGE_PRIVATE = 4; private PrintWriter javaWriter; // Emits either interface or, in AllStatic mode, everything private PrintWriter javaImplWriter; // Only used in non-AllStatic modes for impl class @@ -300,119 +308,304 @@ public class JavaEmitter implements GlueEmitter { } /** + * Generates the public emitters for this MethodBinding which will + * produce either simply signatures (for the interface class, if + * any) or function definitions with or without a body (depending on + * whether or not the implementing function can go directly to + * native code because it doesn't need any processing of the + * outgoing arguments). + */ + protected void generatePublicEmitters(MethodBinding binding, + List allEmitters, + boolean signatureOnly) { + PrintWriter writer = ((signatureOnly || cfg.allStatic()) ? javaWriter() : javaImplWriter()); + + if (cfg.manuallyImplement(binding.getName()) && !signatureOnly) { + // We only generate signatures for manually-implemented methods; + // user provides the implementation + return; + } + + // It's possible we may not need a body even if signatureOnly is + // set to false; for example, if the routine doesn't take any + // arrays or buffers as arguments + boolean isUnimplemented = cfg.isUnimplemented(binding.getName()); + List/*<String>*/ prologue = cfg.javaPrologueForMethod(binding, false, false); + List/*<String>*/ epilogue = cfg.javaEpilogueForMethod(binding, false, false); + boolean needsBody = (isUnimplemented || + (binding.needsNIOWrappingOrUnwrapping() || + binding.signatureUsesJavaPrimitiveArrays()) || + (prologue != null) || + (epilogue != null)); + + JavaMethodBindingEmitter emitter = + new JavaMethodBindingEmitter(binding, + writer, + cfg.runtimeExceptionType(), + !signatureOnly && needsBody, + false, + cfg.nioDirectOnly(binding.getName()), + false, + false, + false, + isUnimplemented); + switch (cfg.accessControl(binding.getName())) { + case ACC_PUBLIC: emitter.addModifier(JavaMethodBindingEmitter.PUBLIC); break; + case ACC_PROTECTED: emitter.addModifier(JavaMethodBindingEmitter.PROTECTED); break; + case ACC_PRIVATE: emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); break; + default: break; // package-private adds no modifiers + } + if (cfg.allStatic()) { + emitter.addModifier(JavaMethodBindingEmitter.STATIC); + } + if (!isUnimplemented && !needsBody && !signatureOnly) { + emitter.addModifier(JavaMethodBindingEmitter.NATIVE); + } + emitter.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); + emitter.setPrologue(prologue); + emitter.setEpilogue(epilogue); + allEmitters.add(emitter); + } + + /** + * Generates the private emitters for this MethodBinding. On the + * Java side these will simply produce signatures for native + * methods. On the C side these will create the emitters which will + * write the JNI code to interface to the functions. We need to be + * careful to make the signatures all match up and not produce too + * many emitters which would lead to compilation errors from + * creating duplicated methods / functions. + */ + protected void generatePrivateEmitters(MethodBinding binding, + List allEmitters) { + if (cfg.manuallyImplement(binding.getName())) { + // Don't produce emitters for the implementation class + return; + } + + boolean hasPrologueOrEpilogue = + ((cfg.javaPrologueForMethod(binding, false, false) != null) || + (cfg.javaEpilogueForMethod(binding, false, false) != null)); + + // If we already generated a public native entry point for this + // method, don't emit another one + if (!cfg.isUnimplemented(binding.getName()) && + (binding.needsNIOWrappingOrUnwrapping() || + binding.signatureUsesJavaPrimitiveArrays() || + hasPrologueOrEpilogue)) { + PrintWriter writer = (cfg.allStatic() ? javaWriter() : javaImplWriter()); + + // If the binding uses primitive arrays, we are going to emit + // the private native entry point for it along with the version + // taking only NIO buffers + if (!binding.signatureUsesJavaPrimitiveArrays()) { + // (Always) emit the entry point taking only direct buffers + JavaMethodBindingEmitter emitter = + new JavaMethodBindingEmitter(binding, + writer, + cfg.runtimeExceptionType(), + false, + true, + cfg.nioDirectOnly(binding.getName()), + true, + true, + false, + false); + emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); + if (cfg.allStatic()) { + emitter.addModifier(JavaMethodBindingEmitter.STATIC); + } + emitter.addModifier(JavaMethodBindingEmitter.NATIVE); + emitter.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); + allEmitters.add(emitter); + + // Optionally emit the entry point taking arrays which handles + // both the public entry point taking arrays as well as the + // indirect buffer case + if (!cfg.nioDirectOnly(binding.getName()) && + binding.signatureCanUseIndirectNIO()) { + emitter = + new JavaMethodBindingEmitter(binding, + writer, + cfg.runtimeExceptionType(), + false, + true, + false, + true, + false, + true, + false); + + emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); + if (cfg.allStatic()) { + emitter.addModifier(JavaMethodBindingEmitter.STATIC); + } + emitter.addModifier(JavaMethodBindingEmitter.NATIVE); + emitter.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); + allEmitters.add(emitter); + } + } + } + + // Now generate the C emitter(s). We need to produce one for every + // Java native entry point (public or private). The only + // situations where we don't produce one are (a) when the method + // is unimplemented, and (b) when the signature contains primitive + // arrays, since the latter is handled by the method binding + // variant taking only NIO Buffers. + if (!cfg.isUnimplemented(binding.getName()) && + !binding.signatureUsesJavaPrimitiveArrays()) { + // See whether we need an expression to help calculate the + // length of any return type + MessageFormat returnValueCapacityFormat = null; + MessageFormat returnValueLengthFormat = null; + JavaType javaReturnType = binding.getJavaReturnType(); + if (javaReturnType.isNIOBuffer() || + javaReturnType.isCompoundTypeWrapper()) { + // See whether capacity has been specified + String capacity = cfg.returnValueCapacity(binding.getName()); + if (capacity != null) { + returnValueCapacityFormat = new MessageFormat(capacity); + } + } else if (javaReturnType.isArray() || + javaReturnType.isArrayOfCompoundTypeWrappers()) { + // NOTE: adding a check here because the CMethodBindingEmitter + // also doesn't yet handle returning scalar arrays. In order + // to implement this, return the type as a Buffer instead + // (i.e., IntBuffer, FloatBuffer) and add code as necessary. + if (javaReturnType.isPrimitiveArray()) { + throw new RuntimeException("Primitive array return types not yet supported"); + } + + // See whether length has been specified + String len = cfg.returnValueLength(binding.getName()); + if (len != null) { + returnValueLengthFormat = new MessageFormat(len); + } + } + + CMethodBindingEmitter cEmitter = + new CMethodBindingEmitter(binding, + cWriter(), + cfg.implPackageName(), + cfg.implClassName(), + true, /* NOTE: we always disambiguate with a suffix now, so this is optional */ + cfg.allStatic(), + (binding.needsNIOWrappingOrUnwrapping() || hasPrologueOrEpilogue), + false); + if (returnValueCapacityFormat != null) { + cEmitter.setReturnValueCapacityExpression(returnValueCapacityFormat); + } + if (returnValueLengthFormat != null) { + cEmitter.setReturnValueLengthExpression(returnValueLengthFormat); + } + cEmitter.setTemporaryCVariableDeclarations(cfg.temporaryCVariableDeclarations(binding.getName())); + cEmitter.setTemporaryCVariableAssignments(cfg.temporaryCVariableAssignments(binding.getName())); + allEmitters.add(cEmitter); + + // Now see if we have to emit another entry point to handle the + // indirect buffer and array case + if (binding.argumentsUseNIO() && + binding.signatureCanUseIndirectNIO() && + !cfg.nioDirectOnly(binding.getName())) { + cEmitter = + new CMethodBindingEmitter(binding, + cWriter(), + cfg.implPackageName(), + cfg.implClassName(), + true, /* NOTE: we always disambiguate with a suffix now, so this is optional */ + cfg.allStatic(), + binding.needsNIOWrappingOrUnwrapping(), + true); + if (returnValueCapacityFormat != null) { + cEmitter.setReturnValueCapacityExpression(returnValueCapacityFormat); + } + if (returnValueLengthFormat != null) { + cEmitter.setReturnValueLengthExpression(returnValueLengthFormat); + } + cEmitter.setTemporaryCVariableDeclarations(cfg.temporaryCVariableDeclarations(binding.getName())); + cEmitter.setTemporaryCVariableAssignments(cfg.temporaryCVariableAssignments(binding.getName())); + allEmitters.add(cEmitter); + } + } + } + + /** * Generate all appropriate Java bindings for the specified C function * symbols. */ protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { - ArrayList/*<FunctionEmitter>*/ allEmitters = new ArrayList(1); + ArrayList/*<FunctionEmitter>*/ allEmitters = new ArrayList(); try { // Get Java binding for the function MethodBinding mb = bindFunction(sym, null, null); - // Expand all void* arguments + // JavaTypes representing C pointers in the initial + // MethodBinding have not been lowered yet to concrete types List bindings = expandMethodBinding(mb); - boolean overloaded = (bindings.size() > 1); - if (overloaded) { - // resize ahead of time for speed - allEmitters.ensureCapacity(bindings.size()); - } - - // List of the indices of the arguments in this function that should be - // expanded to the same type when binding functions with multiple void* - // arguments - List mirrorIdxs = cfg.mirroredArgs(sym.getName()); for (Iterator iter = bindings.iterator(); iter.hasNext(); ) { MethodBinding binding = (MethodBinding) iter.next(); - // Honor the MirrorExpandedBindingArgs directive in .cfg files - if (mirrorIdxs != null) { - assert(mirrorIdxs.size() >= 2); // sanity check. - boolean typesMatch = true; - int argIndex = ((Integer)mirrorIdxs.get(0)).intValue(); - JavaType leftArgType = binding.getJavaArgumentType(argIndex); - for (int i = 1; i < mirrorIdxs.size(); ++i) { - argIndex = ((Integer)mirrorIdxs.get(i)).intValue(); - JavaType rightArgType = binding.getJavaArgumentType(argIndex); - if (!(leftArgType.equals(rightArgType))) { - typesMatch = false; - break; - } - leftArgType = rightArgType; - } - // Don't emit the binding if the specified args aren't the same type - if (!typesMatch) { continue; } // skip this binding - } - - // Try to create an NIOBuffer variant for this expanded binding. If - // it's the same as the original binding, then we'll be able to emit - // the binding like any normal binding because no special binding - // generation (wrapper methods, etc) will be necessary. - MethodBinding specialBinding = binding.createNIOBufferVariant(); - if (cfg.allStatic() && binding.hasContainingType()) { // This should not currently happen since structs are emitted using a different mechanism throw new IllegalArgumentException("Cannot create binding in AllStatic mode because method has containing type: \"" + binding + "\""); } - boolean isUnimplemented = cfg.isUnimplemented(binding.getName()); - - if (cfg.emitImpl()) { - // Generate the emitter for the method which may do conversion - // from type wrappers to NIO Buffers or which may call the - // underlying function directly - JavaMethodBindingImplEmitter entryPoint = - new JavaMethodBindingImplEmitter(binding, - (cfg.allStatic() ? javaWriter() : javaImplWriter()), - cfg.runtimeExceptionType(), - isUnimplemented); - entryPoint.addModifier(JavaMethodBindingEmitter.PUBLIC); - if (cfg.allStatic()) { - entryPoint.addModifier(JavaMethodBindingEmitter.STATIC); - } - if (!isUnimplemented && !bindingNeedsBody(binding)) { - entryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); - } - entryPoint.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); - allEmitters.add(entryPoint); - } + // The structure of the generated glue code looks something like this: + // Simple method (no arrays, void pointers, etc.): + // Interface class: + // public void fooMethod(); + // Implementation class: + // public native void fooMethod(); + // + // Method taking void* argument: + // Interface class: + // public void fooMethod(Buffer arg); + // Implementation class: + // public void fooMethod(Buffer arg) { + // ... bounds checks, etc. ... + // if (arg.isDirect()) { + // fooMethod0(arg, computeDirectBufferByteOffset(arg)); + // } else { + // fooMethod1(getIndirectBufferArray(arg), computeIndirectBufferByteOffset(arg)); + // } + // } + // private native void fooMethod0(Object arg, int arg_byte_offset); + // private native void fooMethod1(Object arg, int arg_byte_offset); + // + // Method taking primitive array argument: + // Interface class: + // public void fooMethod(int[] arg, int arg_offset); + // public void fooMethod(IntBuffer arg); + // Implementing class: + // public void fooMethod(int[] arg, int arg_offset) { + // ... range checks, etc. ... + // fooMethod1(arg, SIZEOF_INT * arg_offset); + // } + // public void fooMethod(IntBuffer arg) { + // ... bounds checks, etc. ... + // if (arg.isDirect()) { + // fooMethod0(arg, computeDirectBufferByteOffset(arg)); + // } else { + // fooMethod1(getIndirectBufferArray(arg), computeIndirectBufferByteOffset(arg)); + // } + // } + // private native void fooMethod0(Object arg, int arg_byte_offset); + // private native void fooMethod1(Object arg, int arg_byte_offset); + // + // Note in particular that the public entry point taking an + // array is merely a special case of the indirect buffer case. if (cfg.emitInterface()) { - // Generate an emitter that will emit just the interface to the function - JavaMethodBindingEmitter entryPointInterface = - new JavaMethodBindingEmitter(binding, javaWriter(), cfg.runtimeExceptionType()); - entryPointInterface.addModifier(JavaMethodBindingEmitter.PUBLIC); - entryPointInterface.setReturnedArrayLengthExpression(cfg.returnedArrayLength(binding.getName())); - allEmitters.add(entryPointInterface); + generatePublicEmitters(binding, allEmitters, true); } - if (cfg.emitImpl()) { - // 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 (bindingNeedsBody(binding)) { - // Generate the method which calls the underlying C 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); - } + generatePublicEmitters(binding, allEmitters, false); + generatePrivateEmitters(binding, allEmitters); } } // end iteration over expanded bindings } catch (Exception e) { @@ -511,7 +704,7 @@ public class JavaEmitter implements GlueEmitter { writer.println(); writer.println("import java.nio.*;"); writer.println(); - writer.println("import net.java.games.gluegen.runtime.*;"); + writer.println("import com.sun.gluegen.runtime.*;"); writer.println(); List/*<String>*/ imports = cfg.imports(); for (Iterator iter = imports.iterator(); iter.hasNext(); ) { @@ -564,28 +757,49 @@ public class JavaEmitter implements GlueEmitter { FunctionSymbol funcSym = new FunctionSymbol(field.getName(), funcType); MethodBinding binding = bindFunction(funcSym, containingType, containingCType); binding.findThisPointer(); // FIXME: need to provide option to disable this on per-function basis - MethodBinding specialBinding = binding.createNIOBufferVariant(); writer.println(); - JavaMethodBindingEmitter entryPoint = new JavaMethodBindingImplEmitter(binding, writer, cfg.runtimeExceptionType()); - entryPoint.addModifier(JavaMethodBindingEmitter.PUBLIC); - if (!bindingNeedsBody(binding) && !binding.hasContainingType()) { - entryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); - } - entryPoint.emit(); - - JavaMethodBindingEmitter wrappedEntryPoint = new JavaMethodBindingEmitter(specialBinding, writer, cfg.runtimeExceptionType(), true); - wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.PRIVATE); - wrappedEntryPoint.addModifier(JavaMethodBindingEmitter.NATIVE); - wrappedEntryPoint.emit(); - + // Emit public Java entry point for calling this function pointer + JavaMethodBindingEmitter emitter = + new JavaMethodBindingEmitter(binding, + writer, + cfg.runtimeExceptionType(), + true, + false, + true, // FIXME: should unify this with the general emission code + false, + false, // FIXME: should unify this with the general emission code + false, // FIXME: should unify this with the general emission code + false); + emitter.addModifier(JavaMethodBindingEmitter.PUBLIC); + emitter.emit(); + + // Emit private native Java entry point for calling this function pointer + emitter = + new JavaMethodBindingEmitter(binding, + writer, + cfg.runtimeExceptionType(), + false, + true, + true, // FIXME: should unify this with the general emission code + true, + true, // FIXME: should unify this with the general emission code + false, // FIXME: should unify this with the general emission code + false); + emitter.addModifier(JavaMethodBindingEmitter.PRIVATE); + emitter.addModifier(JavaMethodBindingEmitter.NATIVE); + emitter.emit(); + + // Emit (private) C entry point for calling this function pointer CMethodBindingEmitter cEmitter = - makeCEmitter(specialBinding, - false, // overloaded - true, // doing impl routine? - structClassPkg, - containingTypeName, - cWriter); + new CMethodBindingEmitter(binding, + cWriter, + structClassPkg, + containingTypeName, + true, // FIXME: this is optional at this point + false, + true, + false); // FIXME: should unify this with the general emission code cEmitter.emit(); } catch (Exception e) { System.err.println("While processing field " + field + " of type " + name + ":"); @@ -674,57 +888,6 @@ public class JavaEmitter implements GlueEmitter { // Internals only below this point // - protected boolean bindingNeedsBody(MethodBinding binding) { - // We need to perform NIO checks and conversions and array length - // checks - return binding.signatureUsesNIO() || binding.signatureUsesCArrays(); - } - - private CMethodBindingEmitter makeCEmitter(MethodBinding binding, - boolean overloaded, - boolean doingImplRoutine, - String bindingJavaPackageName, - String bindingJavaClassName, - PrintWriter output) { - MessageFormat returnValueCapacityFormat = null; - MessageFormat returnValueLengthFormat = null; - JavaType javaReturnType = binding.getJavaReturnType(); - if (javaReturnType.isNIOBuffer()) { - // See whether capacity has been specified - String capacity = cfg.returnValueCapacity(binding.getName()); - if (capacity != null) { - returnValueCapacityFormat = new MessageFormat(capacity); - } - } else if (javaReturnType.isArray()) { - // See whether length has been specified - String len = cfg.returnValueLength(binding.getName()); - if (len != null) { - returnValueLengthFormat = new MessageFormat(len); - } - } - CMethodBindingEmitter cEmitter; - if (doingImplRoutine) { - cEmitter = new CMethodBindingImplEmitter(binding, overloaded, - bindingJavaPackageName, - bindingJavaClassName, - cfg.allStatic(), output); - } else { - cEmitter = new CMethodBindingEmitter(binding, overloaded, - bindingJavaPackageName, - bindingJavaClassName, - cfg.allStatic(), output); - } - if (returnValueCapacityFormat != null) { - cEmitter.setReturnValueCapacityExpression(returnValueCapacityFormat); - } - if (returnValueLengthFormat != null) { - cEmitter.setReturnValueLengthExpression(returnValueLengthFormat); - } - cEmitter.setTemporaryCVariableDeclarations(cfg.temporaryCVariableDeclarations(binding.getName())); - cEmitter.setTemporaryCVariableAssignments(cfg.temporaryCVariableAssignments(binding.getName())); - return cEmitter; - } - private JavaType typeToJavaType(Type cType, boolean outgoingArgument) { // Recognize JNIEnv* case up front PointerType opt = cType.asPointer(); @@ -942,9 +1105,11 @@ public class JavaEmitter implements GlueEmitter { } private void openWriters() throws IOException { - String jRoot = - cfg.javaOutputDir() + File.separator + - CodeGenUtils.packageAsPath(cfg.packageName()); + String jRoot = null; + if (cfg.allStatic() || cfg.emitInterface()) { + jRoot = cfg.javaOutputDir() + File.separator + + CodeGenUtils.packageAsPath(cfg.packageName()); + } String jImplRoot = null; if (!cfg.allStatic()) { jImplRoot = @@ -1102,7 +1267,7 @@ public class JavaEmitter implements GlueEmitter { } if (!cfg.allStatic() && cfg.emitImpl()) { - final List/*<String>*/ implDocs = cfg.javadocForClass(cfg.className()); + final List/*<String>*/ implDocs = cfg.javadocForClass(cfg.implClassName()); CodeGenUtils.EmissionCallback docEmitter = new CodeGenUtils.EmissionCallback() { public void emit(PrintWriter w) { @@ -1115,9 +1280,15 @@ public class JavaEmitter implements GlueEmitter { String[] interfaces; List userSpecifiedInterfaces = null; userSpecifiedInterfaces = cfg.implementedInterfaces(cfg.implClassName()); - interfaces = new String[1 + userSpecifiedInterfaces.size()]; + int additionalNum = 0; + if (cfg.className() != null) { + additionalNum = 1; + } + interfaces = new String[additionalNum + userSpecifiedInterfaces.size()]; userSpecifiedInterfaces.toArray(interfaces); - interfaces[userSpecifiedInterfaces.size()] = cfg.className(); + if (additionalNum == 1) { + interfaces[userSpecifiedInterfaces.size()] = cfg.className(); + } CodeGenUtils.emitJavaHeaders( javaImplWriter, @@ -1179,12 +1350,20 @@ public class JavaEmitter implements GlueEmitter { return JavaType.createForClass(c); } + /** Maps the C types in the specified function to Java types through + the MethodBinding interface. Note that the JavaTypes in the + returned MethodBinding are "intermediate" JavaTypes (some + potentially representing C pointers rather than true Java types) + and must be lowered to concrete Java types before creating + emitters for them. */ private MethodBinding bindFunction(FunctionSymbol sym, JavaType containingType, Type containingCType) { MethodBinding binding = new MethodBinding(sym, containingType, containingCType); + binding.setRenamedMethodName(cfg.getJavaMethodRename(sym.getName())); + if (cfg.returnsString(binding.getName())) { PointerType prt = sym.getReturnType().asPointer(); if (prt == null || @@ -1238,162 +1417,119 @@ public class JavaEmitter implements GlueEmitter { return binding; } - // Expands a MethodBinding containing C primitive pointer types into - // multiple variants taking Java primitive arrays and NIO buffers, subject - // to the per-function "NIO only" rule in the configuration file - private List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) { - List result = new ArrayList(); - result.add(binding); - int i = 0; - while (i < result.size()) { - MethodBinding mb = (MethodBinding) result.get(i); - boolean shouldRemoveCurrent = false; - for (int j = 0; j < mb.getNumArguments(); j++) { - JavaType t = mb.getJavaArgumentType(j); - if (t.isCPrimitivePointerType()) { - // Remove original from list - shouldRemoveCurrent = true; - MethodBinding variant = null; - - // Non-NIO variants for void* and other C primitive pointer types - if (!cfg.nioOnly(mb.getCSymbol().getName())) { - if (t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.booleanArrayClass)); - if (! result.contains(variant)) result.add(variant); - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.charArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCCharPointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.byteArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCShortPointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.shortArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCInt32PointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.intArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCInt64PointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.longArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCFloatPointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.floatArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - if (t.isCDoublePointerType() || t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, javaType(ArrayTypes.doubleArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - } - // NIO variants for void* and other C primitive pointer types - if (!cfg.noNio(mb.getCSymbol().getName())) { - if (t.isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOBufferClass()); - if (! result.contains(variant)) result.add(variant); - } + private MethodBinding lowerMethodBindingPointerTypes(MethodBinding inputBinding, + boolean convertToArrays, + boolean[] canProduceArrayVariant) { + MethodBinding result = inputBinding; + boolean arrayPossible = false; + + for (int i = 0; i < inputBinding.getNumArguments(); i++) { + JavaType t = inputBinding.getJavaArgumentType(i); + if (t.isCPrimitivePointerType()) { + if (t.isCVoidPointerType()) { + // These are always bound to java.nio.Buffer + result = result.replaceJavaArgumentType(i, JavaType.forNIOBufferClass()); + } else if (t.isCCharPointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.byteArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIOByteBufferClass()); } - - if ((cfg.nioMode() == JavaConfiguration.NIO_MODE_ALL_POINTERS && !cfg.noNio(mb.getCSymbol().getName())) || - (cfg.nioMode() == JavaConfiguration.NIO_MODE_VOID_ONLY && cfg.forcedNio(mb.getCSymbol().getName()))) { - if (t.isCCharPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOByteBufferClass()); - if (! result.contains(variant)) result.add(variant); - } - - if (t.isCShortPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOShortBufferClass()); - if (! result.contains(variant)) result.add(variant); - } - - if (t.isCInt32PointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOIntBufferClass()); - if (! result.contains(variant)) result.add(variant); - } - - if (t.isCInt64PointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOLongBufferClass()); - if (! result.contains(variant)) result.add(variant); - } - - if (t.isCFloatPointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIOFloatBufferClass()); - if (! result.contains(variant)) result.add(variant); - } - - if (t.isCDoublePointerType()) { - variant = mb.createCPrimitivePointerVariant(j, JavaType.forNIODoubleBufferClass()); - if (! result.contains(variant)) result.add(variant); - } + } else if (t.isCShortPointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.shortArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIOShortBufferClass()); } + } else if (t.isCInt32PointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.intArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIOIntBufferClass()); + } + } else if (t.isCInt64PointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.longArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIOLongBufferClass()); + } + } else if (t.isCFloatPointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.floatArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIOFloatBufferClass()); + } + } else if (t.isCDoublePointerType()) { + arrayPossible = true; + if (convertToArrays) { + result = result.replaceJavaArgumentType(i, javaType(ArrayTypes.doubleArrayClass)); + } else { + result = result.replaceJavaArgumentType(i, JavaType.forNIODoubleBufferClass()); + } + } else { + throw new RuntimeException("Unknown C pointer type " + t); } } - if (mb.getJavaReturnType().isCPrimitivePointerType()) { - MethodBinding variant = null; - if (mb.getJavaReturnType().isCVoidPointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, JavaType.forNIOByteBufferClass()); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCCharPointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.byteArrayClass)); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCShortPointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.shortArrayClass)); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCInt32PointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.intArrayClass)); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCInt64PointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.longArrayClass)); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCFloatPointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.floatArrayClass)); - if (! result.contains(variant)) result.add(variant); - } else if (mb.getJavaReturnType().isCDoublePointerType()) { - variant = mb.createCPrimitivePointerVariant(-1, javaType(ArrayTypes.doubleArrayClass)); - if (! result.contains(variant)) result.add(variant); - } - shouldRemoveCurrent = true; - } - if (shouldRemoveCurrent) { - result.remove(i); - --i; + } + + // Always return primitive pointer types as NIO buffers + JavaType t = result.getJavaReturnType(); + if (t.isCPrimitivePointerType()) { + if (t.isCVoidPointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOByteBufferClass()); + } else if (t.isCCharPointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOByteBufferClass()); + } else if (t.isCShortPointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOShortBufferClass()); + } else if (t.isCInt32PointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOIntBufferClass()); + } else if (t.isCInt64PointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOLongBufferClass()); + } else if (t.isCFloatPointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIOFloatBufferClass()); + } else if (t.isCDoublePointerType()) { + result = result.replaceJavaArgumentType(-1, JavaType.forNIODoubleBufferClass()); + } else { + throw new RuntimeException("Unknown C pointer type " + t); } - ++i; - } - - // Honor the flattenNIOVariants directive in the configuration file - if (cfg.flattenNIOVariants()) { - i = 0; - while (i < result.size()) { - boolean shouldRemoveCurrent = false; - MethodBinding mb = (MethodBinding) result.get(i); - for (int j = 0; j < binding.getNumArguments() && !shouldRemoveCurrent; j++) { - JavaType t1 = binding.getJavaArgumentType(j); - if (t1.isCPrimitivePointerType() && !t1.isCVoidPointerType()) { - for (int k = j + 1; k < binding.getNumArguments() && !shouldRemoveCurrent; k++) { - JavaType t2 = binding.getJavaArgumentType(k); - if (t2.isCPrimitivePointerType() && !t2.isCVoidPointerType()) { - // The "NIO-ness" of the converted arguments in the - // new binding must match - JavaType nt1 = mb.getJavaArgumentType(j); - JavaType nt2 = mb.getJavaArgumentType(k); - if (nt1.isNIOBuffer() != nt2.isNIOBuffer()) { - shouldRemoveCurrent = true; - } - } - } - } - } - if (shouldRemoveCurrent) { - result.remove(i); - --i; - } + } + + if (canProduceArrayVariant != null) { + canProduceArrayVariant[0] = arrayPossible; + } - ++i; + return result; + } + + // Expands a MethodBinding containing C primitive pointer types into + // multiple variants taking Java primitive arrays and NIO buffers, subject + // to the per-function "NIO only" rule in the configuration file + protected List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) { + List result = new ArrayList(); + // Indicates whether it is possible to produce an array variant + // Prevents e.g. char* -> String conversions from emitting two entry points + boolean[] canProduceArrayVariant = new boolean[1]; + + if (binding.signatureUsesCPrimitivePointers() || + binding.signatureUsesCVoidPointers() || + binding.signatureUsesCArrays()) { + result.add(lowerMethodBindingPointerTypes(binding, false, canProduceArrayVariant)); + + // FIXME: should add new configuration flag for this + if (canProduceArrayVariant[0] && + (binding.signatureUsesCPrimitivePointers() || + binding.signatureUsesCArrays()) && + !cfg.nioDirectOnly(binding.getName())) { + result.add(lowerMethodBindingPointerTypes(binding, true, null)); } + } else { + result.add(binding); } return result; diff --git a/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java new file mode 100644 index 000000000..8dbb20d28 --- /dev/null +++ b/src/classes/com/sun/gluegen/JavaMethodBindingEmitter.java @@ -0,0 +1,720 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.gluegen; + +import java.io.*; +import java.util.*; +import java.text.MessageFormat; + +import com.sun.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.*; + +/** + * An emitter that emits only the interface for a Java<->C JNI binding. + */ +public class JavaMethodBindingEmitter extends FunctionEmitter +{ + public static final EmissionModifier PUBLIC = new EmissionModifier("public"); + public static final EmissionModifier PROTECTED = new EmissionModifier("protected"); + public static final EmissionModifier PRIVATE = new EmissionModifier("private"); + public static final EmissionModifier ABSTRACT = new EmissionModifier("abstract"); + public static final EmissionModifier FINAL = new EmissionModifier("final"); + public static final EmissionModifier NATIVE = new EmissionModifier("native"); + public static final EmissionModifier SYNCHRONIZED = new EmissionModifier("synchronized"); + + protected final CommentEmitter defaultJavaCommentEmitter = new DefaultCommentEmitter(); + protected final CommentEmitter defaultInterfaceCommentEmitter = + new InterfaceCommentEmitter(); + + // Exception type raised in the generated code if runtime checks fail + private String runtimeExceptionType; + + protected boolean emitBody; + protected boolean eraseBufferAndArrayTypes; + protected boolean directNIOOnly; + protected boolean forImplementingMethodCall; + protected boolean forDirectBufferImplementation; + protected boolean forIndirectBufferAndArrayImplementation; + protected boolean isUnimplemented; + + protected MethodBinding binding; + + // Manually-specified prologue and epilogue code + protected List/*<String>*/ prologue; + protected List/*<String>*/ epilogue; + + // A non-null value indicates that rather than returning a compound + // type accessor we are returning an array of such accessors; this + // expression is a MessageFormat string taking the names of the + // incoming Java arguments as parameters and computing as an int the + // number of elements of the returned array. + private String returnedArrayLengthExpression; + + public JavaMethodBindingEmitter(MethodBinding binding, + PrintWriter output, + String runtimeExceptionType, + boolean emitBody, + boolean eraseBufferAndArrayTypes, + boolean directNIOOnly, + boolean forImplementingMethodCall, + boolean forDirectBufferImplementation, + boolean forIndirectBufferAndArrayImplementation, + boolean isUnimplemented) + { + super(output); + this.binding = binding; + this.runtimeExceptionType = runtimeExceptionType; + this.emitBody = emitBody; + this.eraseBufferAndArrayTypes = eraseBufferAndArrayTypes; + this.directNIOOnly = directNIOOnly; + this.forImplementingMethodCall = forImplementingMethodCall; + this.forDirectBufferImplementation = forDirectBufferImplementation; + this.forIndirectBufferAndArrayImplementation = forIndirectBufferAndArrayImplementation; + this.isUnimplemented = isUnimplemented; + if (forImplementingMethodCall) { + setCommentEmitter(defaultJavaCommentEmitter); + } else { + setCommentEmitter(defaultInterfaceCommentEmitter); + } + } + + public JavaMethodBindingEmitter(JavaMethodBindingEmitter arg) { + super(arg); + binding = arg.binding; + runtimeExceptionType = arg.runtimeExceptionType; + emitBody = arg.emitBody; + eraseBufferAndArrayTypes = arg.eraseBufferAndArrayTypes; + directNIOOnly = arg.directNIOOnly; + forImplementingMethodCall = arg.forImplementingMethodCall; + forDirectBufferImplementation = arg.forDirectBufferImplementation; + forIndirectBufferAndArrayImplementation = arg.forIndirectBufferAndArrayImplementation; + isUnimplemented = arg.isUnimplemented; + returnedArrayLengthExpression = arg.returnedArrayLengthExpression; + prologue = arg.prologue; + epilogue = arg.epilogue; + } + + public final MethodBinding getBinding() { return binding; } + + public boolean isForImplementingMethodCall() { return forImplementingMethodCall; } + + public String getName() { + return binding.getRenamedMethodName(); + } + + protected String getArgumentName(int i) { + return binding.getArgumentName(i); + } + + /** The type of exception (must subclass + <code>java.lang.RuntimeException</code>) raised if runtime + checks fail in the generated code. */ + public String getRuntimeExceptionType() { + return runtimeExceptionType; + } + + /** If the underlying function returns an array (currently only + arrays of compound types are supported) as opposed to a pointer + to an object, this method should be called to provide a + MessageFormat string containing an expression that computes the + number of elements of the returned array. The parameters to the + MessageFormat expression are the names of the incoming Java + arguments. */ + public void setReturnedArrayLengthExpression(String expr) { + returnedArrayLengthExpression = expr; + } + + /** Sets the manually-generated prologue code for this emitter. */ + public void setPrologue(List/*<String>*/ prologue) { + this.prologue = prologue; + } + + /** Sets the manually-generated epilogue code for this emitter. */ + public void setEpilogue(List/*<String>*/ epilogue) { + this.epilogue = epilogue; + } + + /** Indicates whether this emitter will print only a signature, or + whether it will emit Java code for the body of the method as + well. */ + public boolean signatureOnly() { + return !emitBody; + } + + /** Accessor for subclasses. */ + public void setEmitBody(boolean emitBody) { + this.emitBody = emitBody; + } + + /** Accessor for subclasses. */ + public void setEraseBufferAndArrayTypes(boolean erase) { + this.eraseBufferAndArrayTypes = erase; + } + + /** Accessor for subclasses. */ + public void setForImplementingMethodCall(boolean impl) { + this.forImplementingMethodCall = impl; + } + + protected void emitReturnType(PrintWriter writer) + { + writer.print(getReturnTypeString(false)); + } + + protected String erasedTypeString(JavaType type, boolean skipBuffers) { + if (eraseBufferAndArrayTypes) { + if (type.isNIOBuffer() || + type.isPrimitiveArray()) { + if (!skipBuffers) { + // Direct buffers and arrays sent down as Object (but + // returned as e.g. ByteBuffer) + return "Object"; + } + } else if (type.isCompoundTypeWrapper()) { + // Compound type wrappers are unwrapped to ByteBuffer + return "java.nio.ByteBuffer"; + } else if (type.isArrayOfCompoundTypeWrappers()) { + return "java.nio.ByteBuffer"; + } + } + return type.getName(); + } + + protected String getReturnTypeString(boolean skipArray) { + // The first arm of the "if" clause is used by the glue code + // generation for arrays of compound type wrappers + if (skipArray || + // The following arm is used by most other kinds of return types + (getReturnedArrayLengthExpression() == null && + !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers()) || + // The following arm is used specifically to get the splitting up + // of one returned ByteBuffer into an array of compound type + // wrappers to work (e.g., XGetVisualInfo) + (eraseBufferAndArrayTypes && + binding.getJavaReturnType().isCompoundTypeWrapper() && + (getReturnedArrayLengthExpression() != null))) { + return erasedTypeString(binding.getJavaReturnType(), true); + } + return erasedTypeString(binding.getJavaReturnType(), true) + "[]"; + } + + protected void emitName(PrintWriter writer) + { + if (forImplementingMethodCall) { + if (forIndirectBufferAndArrayImplementation) { + writer.print(getImplMethodName(false)); + } else { + writer.print(getImplMethodName(true)); + } + } else { + writer.print(getName()); + } + } + + protected int emitArguments(PrintWriter writer) + { + boolean needComma = false; + int numEmitted = 0; + + if (forImplementingMethodCall && binding.hasContainingType()) { + // Always emit outgoing "this" argument + writer.print("java.nio.ByteBuffer "); + writer.print(javaThisArgumentName()); + ++numEmitted; + needComma = true; + } + + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + if (binding.getNumArguments() != 1) { + throw new InternalError( + "\"void\" argument type found in " + + "multi-argument function \"" + binding + "\""); + } + continue; + } + + if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { + // Don't need to expose these at the Java level + continue; + } + + if (needComma) { + writer.print(", "); + } + + writer.print(erasedTypeString(type, false)); + writer.print(" "); + writer.print(getArgumentName(i)); + + ++numEmitted; + needComma = true; + + // Add Buffer and array index offset arguments after each associated argument + if (forDirectBufferImplementation || forIndirectBufferAndArrayImplementation) { + if (type.isNIOBuffer()) { + writer.print(", int " + byteOffsetArgName(i)); + } else if (type.isNIOBufferArray()) { + writer.print(", int[] " + + byteOffsetArrayArgName(i)); + } + } + + // Add offset argument after each primitive array + if (type.isPrimitiveArray()) { + writer.print(", int " + offsetArgName(i)); + } + } + return numEmitted; + } + + + protected String getImplMethodName(boolean direct) { + if (direct) { + return binding.getRenamedMethodName() + "0"; + } else { + return binding.getRenamedMethodName() + "1"; + } + } + + protected String byteOffsetArgName(int i) { + return byteOffsetArgName(getArgumentName(i)); + } + + protected String byteOffsetArgName(String s) { + return s + "_byte_offset"; + } + + protected String byteOffsetArrayArgName(int i) { + return getArgumentName(i) + "_byte_offset_array"; + } + + protected String offsetArgName(int i) { + return getArgumentName(i) + "_offset"; + } + + protected void emitBody(PrintWriter writer) + { + if (!emitBody) { + writer.println(';'); + } else { + MethodBinding binding = getBinding(); + writer.println(); + writer.println(" {"); + if (isUnimplemented) { + writer.println(" throw new " + getRuntimeExceptionType() + "(\"Unimplemented\");"); + } else { + emitPrologueOrEpilogue(prologue, writer); + emitPreCallSetup(binding, writer); + //emitReturnVariableSetup(binding, writer); + emitReturnVariableSetupAndCall(binding, writer); + emitPrologueOrEpilogue(epilogue, writer); + } + writer.println(" }"); + } + } + + protected void emitPrologueOrEpilogue(List/*<String>*/ code, PrintWriter writer) { + if (code != null) { + for (Iterator iter = code.iterator(); iter.hasNext(); ) { + writer.println(" " + (String) iter.next()); + } + } + } + + protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { + emitArrayLengthAndNIOBufferChecks(binding, writer); + } + + protected void emitArrayLengthAndNIOBufferChecks(MethodBinding binding, PrintWriter writer) { + int numBufferOffsetArrayArgs = 0; + boolean firstBuffer = true; + // Check lengths of any incoming arrays if necessary + for (int i = 0; i < binding.getNumArguments(); i++) { + Type type = binding.getCArgumentType(i); + if (type.isArray()) { + ArrayType arrayType = type.asArray(); + writer.println(" if (" + getArgumentName(i) + ".length < " + + arrayType.getLength() + ")"); + writer.println(" throw new " + getRuntimeExceptionType() + + "(\"Length of array \\\"" + getArgumentName(i) + + "\\\" was less than the required " + arrayType.getLength() + "\");"); + } else { + JavaType javaType = binding.getJavaArgumentType(i); + if (javaType.isNIOBuffer()) { + if (directNIOOnly) { + writer.println(" if (!BufferFactory.isDirect(" + getArgumentName(i) + "))"); + writer.println(" throw new " + getRuntimeExceptionType() + "(\"Argument \\\"" + + getArgumentName(i) + "\\\" was not a direct buffer\");"); + } else { + if(firstBuffer) { + firstBuffer = false; + writer.println(" boolean _direct = BufferFactory.isDirect(" + getArgumentName(i) + ");"); + } else { + writer.println(" if (_direct != BufferFactory.isDirect(" + getArgumentName(i) + "))"); + writer.println(" throw new " + getRuntimeExceptionType() + + "(\"Argument \\\"" + getArgumentName(i) + + "\\\" : Buffers passed to this method must all be either direct or indirect\");"); + } + } + } else if (javaType.isNIOBufferArray()) { + // All buffers passed down in an array of NIO buffers must be direct + String argName = getArgumentName(i); + String arrayName = byteOffsetArrayArgName(i); + writer.println(" int[] " + arrayName + " = new int[" + argName + ".length];"); + // Check direct buffer properties of all buffers within + writer.println(" if (" + argName + " != null) {"); + writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {"); + writer.println(" if (!BufferFactory.isDirect(" + argName + "[_ctr])) {"); + writer.println(" throw new " + getRuntimeExceptionType() + + "(\"Element \" + _ctr + \" of argument \\\"" + + getArgumentName(i) + "\\\" was not a direct buffer\");"); + writer.println(" }"); + // get the Buffer Array offset values and save them into another array to send down to JNI + writer.print (" " + arrayName + "[_ctr] = BufferFactory.getDirectBufferByteOffset("); + writer.println(argName + "[_ctr]);"); + writer.println(" }"); + writer.println(" }"); + } else if (javaType.isPrimitiveArray()) { + String argName = getArgumentName(i); + String offsetArg = offsetArgName(i); + writer.println(" if(" + argName + " != null && " + argName + ".length <= " + offsetArg + ")"); + writer.print (" throw new " + getRuntimeExceptionType()); + writer.println("(\"array offset argument \\\"" + offsetArg + "\\\" (\" + " + offsetArg + + " + \") equals or exceeds array length (\" + " + argName + ".length + \")\");"); + } + } + } + } + + protected void emitCall(MethodBinding binding, PrintWriter writer, boolean direct) { + writer.print(getImplMethodName(direct)); + writer.print("("); + emitCallArguments(binding, writer, direct); + writer.print(");"); + } + + + protected void emitReturnVariableSetupAndCall(MethodBinding binding, PrintWriter writer) { + writer.print(" "); + JavaType returnType = binding.getJavaReturnType(); + boolean needsResultAssignment = false; + + if (!returnType.isVoid()) { + if (returnType.isCompoundTypeWrapper() || + returnType.isNIOByteBuffer()) { + writer.println("ByteBuffer _res;"); + needsResultAssignment = true; + } else if (returnType.isArrayOfCompoundTypeWrappers()) { + writer.println("ByteBuffer[] _res;"); + needsResultAssignment = true; + } + } + + if (binding.signatureCanUseIndirectNIO() && !directNIOOnly) { + // Must generate two calls for this gated on whether the NIO + // buffers coming in are all direct or indirect + writer.println("if (_direct) {"); + writer.print (" "); + } + + if (needsResultAssignment) { + writer.print(" _res = "); + } else { + writer.print(" "); + if (!returnType.isVoid()) { + writer.print("return "); + } + } + + if (binding.signatureUsesJavaPrimitiveArrays() && + !binding.signatureCanUseIndirectNIO()) { + // FIXME: what happens with a C function of the form + // void foo(int* arg0, void* arg1); + // ? + + // Only one call being made in this body, going to indirect + // buffer / array entry point + emitCall(binding, writer, false); + writer.println(); + } else { + emitCall(binding, writer, true); + } + + if (binding.signatureCanUseIndirectNIO() && !directNIOOnly) { + // Must generate two calls for this gated on whether the NIO + // buffers coming in are all direct or indirect + writer.println(); + writer.println(" } else {"); + writer.print (" "); + if (needsResultAssignment) { + writer.print(" _res = "); + } else { + writer.print(" "); + if (!returnType.isVoid()) { + writer.print("return "); + } + } + emitCall(binding, writer, false); + writer.println(); + writer.println(" }"); + } else { + writer.println(); + } + if (needsResultAssignment) { + emitCallResultReturn(binding, writer); + } + } + + protected int emitCallArguments(MethodBinding binding, PrintWriter writer, boolean direct) { + boolean needComma = false; + int numArgsEmitted = 0; + + if (binding.hasContainingType()) { + // Emit this pointer + assert(binding.getContainingType().isCompoundTypeWrapper()); + writer.print("getBuffer()"); + needComma = true; + ++numArgsEmitted; + } + for (int i = 0; i < binding.getNumArguments(); i++) { + JavaType type = binding.getJavaArgumentType(i); + if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { + // Don't need to expose these at the Java level + continue; + } + + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + assert(binding.getNumArguments() == 1); + continue; + } + + if (needComma) { + writer.print(", "); + } + + if (type.isCompoundTypeWrapper()) { + writer.print("(("); + } + + if (type.isNIOBuffer() && !direct) { + writer.print("BufferFactory.getArray(" + getArgumentName(i) + ")"); + } else { + writer.print(getArgumentName(i)); + } + + if (type.isCompoundTypeWrapper()) { + writer.print(" == null) ? null : "); + writer.print(getArgumentName(i)); + writer.print(".getBuffer())"); + } + needComma = true; + ++numArgsEmitted; + if (type.isNIOBuffer()) { + if (direct) { + writer.print(", BufferFactory.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); + } else { + writer.print(", BufferFactory.getIndirectBufferByteOffset(" + getArgumentName(i) + ")"); + } + } else if (type.isNIOBufferArray()) { + writer.print(", " + byteOffsetArrayArgName(i)); + } + + // Add Array offset parameter for primitive arrays + if (type.isPrimitiveArray()) { + if(type.isFloatArray()) { + writer.print(", BufferFactory.SIZEOF_FLOAT * "); + } else if(type.isDoubleArray()) { + writer.print(", BufferFactory.SIZEOF_DOUBLE * "); + } else if(type.isByteArray()) { + writer.print(", "); + } else if(type.isLongArray()) { + writer.print(", BufferFactory.SIZEOF_LONG * "); + } else if(type.isShortArray()) { + writer.print(", BufferFactory.SIZEOF_SHORT * "); + } else if(type.isIntArray()) { + writer.print(", BufferFactory.SIZEOF_INT * "); + } else { + throw new RuntimeException("Unsupported type for calculating array offset argument for " + + getArgumentName(i) + + "-- error occurred while processing Java glue code for " + getName()); + } + writer.print(offsetArgName(i)); + } + } + return numArgsEmitted; + } + + protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) { + JavaType returnType = binding.getJavaReturnType(); + + if (returnType.isCompoundTypeWrapper()) { + String fmt = getReturnedArrayLengthExpression(); + writer.println(" if (_res == null) return null;"); + if (fmt == null) { + writer.print(" return new " + returnType.getName() + "(_res.order(ByteOrder.nativeOrder()))"); + } else { + writer.println(" _res.order(ByteOrder.nativeOrder());"); + String[] argumentNames = new String[binding.getNumArguments()]; + for (int i = 0; i < binding.getNumArguments(); i++) { + argumentNames[i] = getArgumentName(i); + } + String expr = new MessageFormat(fmt).format(argumentNames); + PointerType cReturnTypePointer = binding.getCReturnType().asPointer(); + CompoundType cReturnType = null; + if (cReturnTypePointer != null) { + cReturnType = cReturnTypePointer.getTargetType().asCompound(); + } + if (cReturnType == null) { + throw new RuntimeException("ReturnedArrayLength directive currently only supported for pointers to compound types " + + "(error occurred while generating Java glue code for " + getName() + ")"); + } + writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];"); + writer.println(" for (int _count = 0; _count < " + expr + "; _count++) {"); + // Create temporary ByteBuffer slice + // FIXME: probably need Type.getAlignedSize() for arrays of + // compound types (rounding up to machine-dependent alignment) + writer.println(" _res.position(_count * " + cReturnType.getSize() + ");"); + writer.println(" _res.limit ((1 + _count) * " + cReturnType.getSize() + ");"); + writer.println(" ByteBuffer _tmp = _res.slice();"); + writer.println(" _tmp.order(ByteOrder.nativeOrder());"); + writer.println(" _res.position(0);"); + writer.println(" _res.limit(_res.capacity());"); + writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_tmp);"); + writer.println(" }"); + writer.print (" return _retarray"); + } + writer.println(";"); + } else if (returnType.isNIOBuffer()) { + writer.println(" if (_res == null) return null;"); + writer.println(" return _res.order(ByteOrder.nativeOrder());"); + } else if (returnType.isArrayOfCompoundTypeWrappers()) { + writer.println(" if (_res == null) return null;"); + writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); + writer.println(" for (int _count = 0; _count < _res.length; _count++) {"); + writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_res[_count]);"); + writer.println(" }"); + writer.println(" return _retarray;"); + } + } + + public static String javaThisArgumentName() { + return "jthis0"; + } + + protected String getCommentStartString() { return "/** "; } + + protected String getBaseIndentString() { return " "; } + + protected String getReturnedArrayLengthExpression() { + return returnedArrayLengthExpression; + } + + /** + * Class that emits a generic comment for JavaMethodBindingEmitters; the comment + * includes the C signature of the native method that is being bound by the + * emitter java method. + */ + protected class DefaultCommentEmitter implements CommentEmitter { + public void emit(FunctionEmitter emitter, PrintWriter writer) { + emitBeginning(emitter, writer); + emitBindingCSignature(((JavaMethodBindingEmitter)emitter).getBinding(), writer); + emitEnding(emitter, writer); + } + protected void emitBeginning(FunctionEmitter emitter, PrintWriter writer) { + writer.print("Entry point to C language function: <br> "); + } + protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { + writer.print("<code> "); + writer.print(binding.getCSymbol()); + writer.print(" </code> "); + } + protected void emitEnding(FunctionEmitter emitter, PrintWriter writer) { + // If argument type is a named enum, then emit a comment detailing the + // acceptable values of that enum. + // If we're emitting a direct buffer variant only, then declare + // that the NIO buffer arguments must be direct. + MethodBinding binding = ((JavaMethodBindingEmitter)emitter).getBinding(); + for (int i = 0; i < binding.getNumArguments(); i++) { + Type type = binding.getCArgumentType(i); + JavaType javaType = binding.getJavaArgumentType(i); + // don't emit param comments for anonymous enums, since we can't + // distinguish between the values found within multiple anonymous + // enums in the same C translation unit. + if (type.isEnum() && type.getName() != HeaderParser.ANONYMOUS_ENUM_NAME) { + EnumType enumType = (EnumType)type; + writer.println(); + writer.print(emitter.getBaseIndentString()); + writer.print(" "); + writer.print("@param "); + writer.print(getArgumentName(i)); + writer.print(" valid values are: <code>"); + for (int j = 0; j < enumType.getNumEnumerates(); ++j) { + if (j>0) writer.print(", "); + writer.print(enumType.getEnumName(j)); + } + writer.println("</code>"); + } else if (directNIOOnly && javaType.isNIOBuffer()) { + writer.println(); + writer.print(emitter.getBaseIndentString()); + writer.print(" "); + writer.print("@param "); + writer.print(getArgumentName(i)); + writer.print(" a direct {@link " + javaType.getName() + "}"); + } + } + } + } + + protected class InterfaceCommentEmitter + extends JavaMethodBindingEmitter.DefaultCommentEmitter + { + protected void emitBeginning(FunctionEmitter emitter, + PrintWriter writer) { + writer.print("Interface to C language function: <br> "); + } + } +} + diff --git a/src/net/java/games/gluegen/JavaType.java b/src/classes/com/sun/gluegen/JavaType.java index 76b2f107c..496fd6961 100644 --- a/src/net/java/games/gluegen/JavaType.java +++ b/src/classes/com/sun/gluegen/JavaType.java @@ -37,11 +37,11 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.nio.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** * Describes a java-side representation of a type that is used to represent @@ -98,6 +98,10 @@ public class JavaType { return clazz.hashCode(); } + public JavaType getElementType() { + return new JavaType(elementType); + } + /** Creates a JavaType corresponding to the given Java type. This can be used to represent arrays of primitive values or Strings; the emitters understand how to perform proper conversion from @@ -218,8 +222,7 @@ public class JavaType { } /** - * Returns the name corresponding to this type. Returns null when this - * object does not represent a C-language "struct" type. + * Returns the Java type name corresponding to this type. */ public String getName() { if (clazz != null) { @@ -234,10 +237,37 @@ public class JavaType { return name; } + /** + * Returns the descriptor (internal type signature) corresponding to + * this type. + */ + public String getDescriptor() { + // FIXME: this is not completely accurate at this point (for + // example, it knows nothing about the packages for compound + // types) + if (clazz != null) { + return descriptor(clazz); + } + if (elementType != null) { + return "[" + descriptor(elementType.getName()); + } + return descriptor(name); + } + /** Returns the String corresponding to the JNI type for this type, or NULL if it can't be represented (i.e., it's a boxing class that we need to call getBuffer() on.) */ public String jniTypeName() { + if (isCompoundTypeWrapper()) { + // These are sent down as Buffers (e.g., jobject) + return "jobject"; + } + + if (isArrayOfCompoundTypeWrappers()) { + // These are returned as arrays of ByteBuffers (e.g., jobjectArray) + return "jobjectArray /* of ByteBuffer */"; + } + if (clazz == null) { return null; } @@ -246,48 +276,41 @@ public class JavaType { return "void"; } - if (clazz.isPrimitive()) { + if (isPrimitive()) { return "j" + clazz.getName(); } - if (clazz.isArray()) { - Class elementType = clazz.getComponentType(); - if (elementType.isPrimitive()) - { - // Type is array-of-primitive - return "j" + elementType.getName() + "Array"; - } - else if (elementType == java.lang.String.class) - { - // Type is array-of-string + if (isPrimitiveArray() || isNIOBuffer()) { + // We now pass primitive arrays and buffers uniformly down to native code as java.lang.Object. + return "jobject"; + } + + if (isArray()) { + if (isStringArray()) { return "jobjectArray /*elements are String*/"; - //return "jobjectArray"; } - else if (java.nio.Buffer.class.isAssignableFrom(elementType)) - { + + Class elementType = clazz.getComponentType(); + + if (isNIOBufferArray()) { return "jobjectArray /*elements are " + elementType.getName() + "*/"; } - else if (elementType.isArray()) - { + + if (elementType.isArray()) { // Type is array-of-arrays-of-something - if (elementType.getComponentType().isPrimitive()) - { + if (elementType.getComponentType().isPrimitive()) { // Type is an array-of-arrays-of-primitive return "jobjectArray /* elements are " + elementType.getComponentType() + "[]*/"; //return "jobjectArray"; - } - else - { + } else { throw new RuntimeException("Multi-dimensional arrays of types that are not primitives or Strings are not supported."); } } - else - { - // Some unusual type that we don't handle - throw new RuntimeException("Unexpected and unsupported type: \"" + this + "\""); - } - } // end array type case + + // Some unusual type that we don't handle + throw new RuntimeException("Unexpected and unsupported array type: \"" + this + "\""); + } if (isString()) { return "jstring"; @@ -321,6 +344,35 @@ public class JavaType { return ((clazz != null) && clazz.isArray()); } + public boolean isFloatArray() { + return(clazz.isArray() && clazz.getComponentType() == Float.TYPE); + } + + public boolean isDoubleArray() { + return(clazz.isArray() && clazz.getComponentType() == Double.TYPE); + } + + public boolean isByteArray() { + return(clazz.isArray() && clazz.getComponentType() == Byte.TYPE); + } + + public boolean isIntArray() { + return(clazz.isArray() && clazz.getComponentType() == Integer.TYPE); + } + + public boolean isShortArray() { + return(clazz.isArray() && clazz.getComponentType() == Short.TYPE); + } + + public boolean isLongArray() { + return(clazz.isArray() && clazz.getComponentType() == Long.TYPE); + } + + public boolean isStringArray() { + return(clazz.isArray() && clazz.getComponentType() == java.lang.String.class); + } + + public boolean isPrimitive() { return ((clazz != null) && !isArray() && clazz.isPrimitive() && (clazz != Void.TYPE)); } @@ -329,6 +381,30 @@ public class JavaType { return (isArray() && (clazz.getComponentType().isPrimitive())); } + public boolean isShort() { + return (clazz == Short.TYPE); + } + + public boolean isFloat() { + return (clazz == Float.TYPE); + } + + public boolean isDouble() { + return (clazz == Double.TYPE); + } + + public boolean isByte() { + return (clazz == Byte.TYPE); + } + + public boolean isLong() { + return (clazz == Long.TYPE); + } + + public boolean isInt() { + return (clazz == Integer.TYPE); + } + public boolean isVoid() { return (clazz == Void.TYPE); } @@ -395,6 +471,11 @@ public class JavaType { // Internals only below this point // + // For debugging + public void dump() { + System.err.println("[clazz = " + clazz + " , name = " + name + " , elementType = " + elementType + " , primitivePointerType = " + primitivePointerType + "]"); + } + /** * Constructs a representation for a type corresponding to the given Class * argument. @@ -432,5 +513,37 @@ public class JavaType { } return buf.toString(); } - + + private String arrayDescriptor(Class clazz) { + StringBuffer buf = new StringBuffer(); + int arrayCount = 0; + while (clazz.isArray()) { + buf.append("["); + clazz = clazz.getComponentType(); + } + buf.append(descriptor(clazz)); + return buf.toString(); + } + + private String descriptor(Class clazz) { + if (clazz.isPrimitive()) { + if (clazz == Boolean.TYPE) return "Z"; + if (clazz == Byte.TYPE) return "B"; + if (clazz == Double.TYPE) return "D"; + if (clazz == Float.TYPE) return "F"; + if (clazz == Integer.TYPE) return "I"; + if (clazz == Long.TYPE) return "J"; + if (clazz == Short.TYPE) return "S"; + if (clazz == Void.TYPE) return "V"; + throw new RuntimeException("Unexpected primitive type " + clazz.getName()); + } + if (clazz.isArray()) { + return arrayDescriptor(clazz); + } + return descriptor(clazz.getName()); + } + + private String descriptor(String referenceTypeName) { + return "L" + referenceTypeName.replace('.', '/') + ";"; + } } diff --git a/src/net/java/games/gluegen/MethodBinding.java b/src/classes/com/sun/gluegen/MethodBinding.java index d8b91acaf..b8ebb092a 100644 --- a/src/net/java/games/gluegen/MethodBinding.java +++ b/src/classes/com/sun/gluegen/MethodBinding.java @@ -37,11 +37,11 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; /** Represents the binding of a C function to a Java method. Also used to represent calls through function pointers contained in @@ -50,12 +50,18 @@ import net.java.games.gluegen.cgram.types.*; public class MethodBinding { private FunctionSymbol sym; + private String renamedMethodName; private JavaType javaReturnType; private List javaArgumentTypes; private boolean computedSignatureProperties; + private boolean argumentsUseNIO; private boolean signatureUsesNIO; + private boolean signatureCanUseIndirectNIO; + private boolean signatureUsesCompoundTypeWrappers; + private boolean signatureUsesCVoidPointers; + private boolean signatureUsesCPrimitivePointers; private boolean signatureUsesCArrays; - private boolean signatureUsesPrimitiveArrays; + private boolean signatureUsesJavaPrimitiveArrays; private JavaType containingType; private Type containingCType; private int thisPointerIndex = -1; @@ -68,15 +74,21 @@ public class MethodBinding { public MethodBinding(MethodBinding bindingToCopy) { this.sym = bindingToCopy.sym; - this.containingType = bindingToCopy.containingType; - this.containingCType = bindingToCopy.containingCType; - this.javaReturnType = bindingToCopy.javaReturnType; - this.javaArgumentTypes = (List)((ArrayList)bindingToCopy.javaArgumentTypes).clone(); - this.computedSignatureProperties = bindingToCopy.computedSignatureProperties; - this.signatureUsesNIO = bindingToCopy.signatureUsesNIO; - this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays; - this.signatureUsesPrimitiveArrays = bindingToCopy.signatureUsesPrimitiveArrays; - this.thisPointerIndex = bindingToCopy.thisPointerIndex; + this.renamedMethodName = bindingToCopy.renamedMethodName; + this.containingType = bindingToCopy.containingType; + this.containingCType = bindingToCopy.containingCType; + this.javaReturnType = bindingToCopy.javaReturnType; + this.javaArgumentTypes = (List)((ArrayList)bindingToCopy.javaArgumentTypes).clone(); + this.computedSignatureProperties = bindingToCopy.computedSignatureProperties; + this.argumentsUseNIO = bindingToCopy.argumentsUseNIO; + this.signatureUsesNIO = bindingToCopy.signatureUsesNIO; + this.signatureCanUseIndirectNIO = bindingToCopy.signatureCanUseIndirectNIO; + this.signatureUsesCompoundTypeWrappers = bindingToCopy.signatureUsesCompoundTypeWrappers; + this.signatureUsesCVoidPointers = bindingToCopy.signatureUsesCVoidPointers; + this.signatureUsesCPrimitivePointers = bindingToCopy.signatureUsesCPrimitivePointers; + this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays; + this.signatureUsesJavaPrimitiveArrays = bindingToCopy.signatureUsesJavaPrimitiveArrays; + this.thisPointerIndex = bindingToCopy.thisPointerIndex; } /** Constructor for calling a C function. */ @@ -146,12 +158,26 @@ public class MethodBinding { return sym.getName(); } - /** Replaces the C primitive pointer argument at slot <i>argumentNumber</i> - (0..getNumArguments() - 1) with the specified type. If - argumentNumber is less than 0 then replaces the return type. */ - public MethodBinding createCPrimitivePointerVariant(int argumentNumber, - JavaType newArgType) { - MethodBinding binding = new MethodBinding(sym); + public String getRenamedMethodName() { + // Defaults to same as C symbol unless renamed + if (renamedMethodName != null) { + return renamedMethodName; + } + return sym.getName(); + } + + /** Supports renaming C function in Java binding. */ + public void setRenamedMethodName(String name) { + renamedMethodName = name; + } + + /** Creates a new MethodBinding replacing the specified Java + argument type with a new argument type. If argumentNumber is + less than 0 then replaces the return type. */ + public MethodBinding replaceJavaArgumentType(int argumentNumber, + JavaType newArgType) { + MethodBinding binding = (MethodBinding) clone(); + binding.javaArgumentTypes = null; if (argumentNumber < 0) { binding.setJavaReturnType(newArgType); } else { @@ -168,6 +194,16 @@ public class MethodBinding { } /** + * Returns true if any of the outgoing arguments in the method's + * signature require conversion or checking due to the use of New + * I/O. + */ + public boolean argumentsUseNIO() { + computeSignatureProperties(); + return argumentsUseNIO; + } + + /** * Returns true if the return type or any of the outgoing arguments * in the method's signature require conversion or checking due to * the use of New I/O. @@ -178,9 +214,55 @@ public class MethodBinding { } /** - * Returns true if any of the outgoing arguments in the method's - * signature represent fixed-length C arrays which require length - * checking during the call. + * Returns true if it is possible for any of the outgoing arguments + * to be indirect NIO buffers. + */ + public boolean signatureCanUseIndirectNIO() { + computeSignatureProperties(); + return signatureCanUseIndirectNIO; + } + + /** + * Returns true if the return type or any of the outgoing arguments + * in the method's signature use "compound type wrappers", or + * NIO-based wrappers for C data structures. + */ + public boolean signatureUsesCompoundTypeWrappers() { + computeSignatureProperties(); + return signatureUsesCompoundTypeWrappers; + } + + /** + * Returns true if the function needs NIO-related + * wrapping/unwrapping or conversion of various arguments. Currently + * this returns the logical OR of signatureUsesNIO() and + * signatureUsesCompoundTypeWrappers(). + */ + public boolean needsNIOWrappingOrUnwrapping() { + return (signatureUsesNIO() || signatureUsesCompoundTypeWrappers()); + } + + /** + * Returns true if the return type or any of the outgoing arguments + * in the method's signature represent C void* pointers. + */ + public boolean signatureUsesCVoidPointers() { + computeSignatureProperties(); + return signatureUsesCVoidPointers; + } + + /** + * Returns true if the return type or any of the outgoing arguments + * in the method's signature represent C primitive pointers. + */ + public boolean signatureUsesCPrimitivePointers() { + computeSignatureProperties(); + return signatureUsesCPrimitivePointers; + } + + /** + * Returns true if the return type or any of the outgoing arguments + * in the method's signature represent C arrays. */ public boolean signatureUsesCArrays() { computeSignatureProperties(); @@ -188,13 +270,12 @@ public class MethodBinding { } /** - * Returns true if any of the outgoing arguments in the method's - * signature represent primitive arrays which require a - * GetPrimitiveArrayCritical or similar operation during the call. + * Returns true if the return type or any of the outgoing arguments + * in the method's signature represent Java primitive arrays. */ - public boolean signatureUsesPrimitiveArrays() { + public boolean signatureUsesJavaPrimitiveArrays() { computeSignatureProperties(); - return signatureUsesPrimitiveArrays; + return signatureUsesJavaPrimitiveArrays; } /** @@ -205,68 +286,91 @@ public class MethodBinding { if (computedSignatureProperties) return; + argumentsUseNIO = false; signatureUsesNIO = false; + signatureCanUseIndirectNIO = false; + signatureUsesCompoundTypeWrappers = false; + signatureUsesCVoidPointers = false; + signatureUsesCPrimitivePointers = false; signatureUsesCArrays = false; - signatureUsesPrimitiveArrays = false; + signatureUsesJavaPrimitiveArrays = false; + + if (javaReturnType.isCompoundTypeWrapper()) { + // Needs wrapping and/or setting of byte order (neither of which + // can be done easily from native code) + signatureUsesCompoundTypeWrappers = true; + } - if (javaReturnType.isCompoundTypeWrapper() || - javaReturnType.isNIOByteBuffer() || + if (javaReturnType.isNIOByteBuffer() || javaReturnType.isArrayOfCompoundTypeWrappers()) { - // Needs wrapping and/or setting of byte order (neither of - // which can be done easily from native code) + // Needs setting of byte order which can't be done easily from + // native code signatureUsesNIO = true; } + Type cRetType = sym.getReturnType(); + if (cRetType.isArray()) { + // Needs checking of array lengths + signatureUsesCArrays = true; + if (cRetType.asArray().getElementType().isPrimitive()) { + signatureUsesCPrimitivePointers = true; + } + } + + if (cRetType.isPointer()) { + if (cRetType.asPointer().getTargetType().isPrimitive()) { + signatureUsesCPrimitivePointers = true; + } else if (cRetType.asPointer().getTargetType().isVoid()) { + signatureUsesCVoidPointers = true; + } + } + for (int i = 0; i < getNumArguments(); i++) { JavaType javaArgType = getJavaArgumentType(i); Type cArgType = getCArgumentType(i); - if (javaArgType.isCompoundTypeWrapper() || - javaArgType.isNIOBuffer() || + if (javaArgType.isCompoundTypeWrapper()) { + // Needs unwrapping of accessors + signatureUsesCompoundTypeWrappers = true; + } + + if (javaArgType.isNIOBuffer() || javaArgType.isNIOBufferArray()) { - // Needs unwrapping of accessors or checking of direct - // buffer property + // Needs checking of direct buffer property signatureUsesNIO = true; + argumentsUseNIO = true; + + if (javaArgType.isNIOBuffer()) { + // Potential conversion to indirect buffer + signatureCanUseIndirectNIO = true; + } } if (cArgType.isArray()) { // Needs checking of array lengths signatureUsesCArrays = true; + if (cArgType.asArray().getElementType().isPrimitive()) { + signatureUsesCPrimitivePointers = true; + } + } + + if (cArgType.isPointer()) { + if (cArgType.asPointer().getTargetType().isPrimitive()) { + signatureUsesCPrimitivePointers = true; + } else if (cArgType.asPointer().getTargetType().isVoid()) { + signatureUsesCVoidPointers = true; + } } if (javaArgType.isPrimitiveArray()) { // Needs getPrimitiveArrayCritical or similar construct // depending on native code calling convention - signatureUsesPrimitiveArrays = true; + signatureUsesJavaPrimitiveArrays = true; } } computedSignatureProperties = true; } - - public MethodBinding createNIOBufferVariant() { - if (!signatureUsesNIO()) { - return this; - } - MethodBinding binding = new MethodBinding(sym, containingType, containingCType); - binding.thisPointerIndex = thisPointerIndex; - if (javaReturnType.isCompoundTypeWrapper()) { - binding.setJavaReturnType(JavaType.forNIOByteBufferClass()); - } else if (javaReturnType.isArrayOfCompoundTypeWrappers()) { - binding.setJavaReturnType(JavaType.forNIOByteBufferArrayClass()); - } else { - binding.setJavaReturnType(javaReturnType); - } - for (int i = 0; i < getNumArguments(); i++) { - JavaType type = getJavaArgumentType(i); - if (type.isCompoundTypeWrapper()) { - type = JavaType.forNIOBufferClass(); - } - binding.addJavaArgumentType(type); - } - return binding; - } - /** Indicates whether this MethodBinding is for a function pointer contained in a struct. */ public boolean hasContainingType() { @@ -353,7 +457,7 @@ public class MethodBinding { StringBuffer buf = new StringBuffer(200); buf.append(getJavaReturnType().getName()); buf.append(" "); - buf.append(getName()); + buf.append(getRenamedMethodName()); buf.append("("); boolean needComma = false; for (int i = 0; i < getNumArguments(); i++) { @@ -386,5 +490,82 @@ public class MethodBinding { return new MethodBinding(this); } + /** Returns a String containing the descriptor (signature in + internal format) of this MethodBinding as it will be + emitted. This is used to disambiguate between overloadings when + manually specifying prologue and epilogue code, for example. */ + public String getDescriptor(boolean forImplementingMethodCall, + boolean eraseBufferAndArrayTypes) { + StringBuffer buf = new StringBuffer(); + + buf.append("("); + + if (forImplementingMethodCall && hasContainingType()) { + // Always emit outgoing "this" argument + buf.append("Ljava/nio/ByteBuffer;"); + } + + for (int i = 0; i < getNumArguments(); i++) { + JavaType type = getJavaArgumentType(i); + if (type.isVoid()) { + // Make sure this is the only param to the method; if it isn't, + // there's something wrong with our parsing of the headers. + if (getNumArguments() != 1) { + throw new InternalError( + "\"void\" argument type found in " + + "multi-argument function \"" + this + "\""); + } + continue; + } + + if (type.isJNIEnv() || isArgumentThisPointer(i)) { + // Don't need to expose these at the Java level + continue; + } + + buf.append(erasedTypeDescriptor(type, eraseBufferAndArrayTypes, false)); + + // Add Buffer and array index offset arguments after each associated argument + if (forImplementingMethodCall) { + if (type.isNIOBuffer()) { + buf.append("I"); + } else if (type.isNIOBufferArray()) { + buf.append("[I"); + } + } + + // Add offset argument after each primitive array + if (type.isPrimitiveArray()) { + buf.append("I"); + } + } + + buf.append(")"); + + // Emit return type for completeness even though we can't overload + // based solely on return type + buf.append(erasedTypeDescriptor(getJavaReturnType(), eraseBufferAndArrayTypes, false)); + + return buf.toString(); + } + + protected String erasedTypeDescriptor(JavaType type, boolean eraseBufferAndArrayTypes, boolean skipBuffers) { + if (eraseBufferAndArrayTypes) { + if (type.isNIOBuffer() || + type.isPrimitiveArray()) { + if (!skipBuffers) { + // Direct buffers and arrays sent down as Object (but + // returned as e.g. ByteBuffer) + return "Ljava/lang/Object;"; + } + } else if (type.isCompoundTypeWrapper()) { + // Compound type wrappers are unwrapped to ByteBuffer + return "Ljava/nio/ByteBuffer;"; + } else if (type.isArrayOfCompoundTypeWrappers()) { + return "Ljava/nio/ByteBuffer;"; + } + } + return type.getDescriptor(); + } } diff --git a/src/net/java/games/gluegen/ReferencedStructs.java b/src/classes/com/sun/gluegen/ReferencedStructs.java index 824346be8..6c0dfb401 100644 --- a/src/net/java/games/gluegen/ReferencedStructs.java +++ b/src/classes/com/sun/gluegen/ReferencedStructs.java @@ -37,10 +37,10 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; import java.util.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; public class ReferencedStructs implements TypeVisitor { private Set results = new HashSet(); diff --git a/src/net/java/games/gluegen/StructLayout.java b/src/classes/com/sun/gluegen/StructLayout.java index 77542b714..a7dbab61f 100644 --- a/src/net/java/games/gluegen/StructLayout.java +++ b/src/classes/com/sun/gluegen/StructLayout.java @@ -37,9 +37,9 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.cgram.types.*; public class StructLayout { private int baseOffset; @@ -124,6 +124,7 @@ public class StructLayout { if ((os.startsWith("windows") && cpu.equals("x86")) || (os.startsWith("linux") && cpu.equals("i386")) || (os.startsWith("linux") && cpu.equals("amd64")) || + (os.startsWith("linux") && cpu.equals("x86_64")) || (os.startsWith("linux") && cpu.equals("ia64")) || (os.startsWith("sunos") && cpu.equals("sparc")) || (os.startsWith("sunos") && cpu.equals("x86")) || diff --git a/src/net/java/games/gluegen/TypeInfo.java b/src/classes/com/sun/gluegen/TypeInfo.java index 60146fa48..437fa8564 100644 --- a/src/net/java/games/gluegen/TypeInfo.java +++ b/src/classes/com/sun/gluegen/TypeInfo.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.gluegen; /** Utility class for handling Opaque directives for JavaEmitter. */ diff --git a/src/net/java/games/gluegen/ant/GlueGenTask.java b/src/classes/com/sun/gluegen/ant/GlueGenTask.java index c9849c29d..b90009883 100644 --- a/src/net/java/games/gluegen/ant/GlueGenTask.java +++ b/src/classes/com/sun/gluegen/ant/GlueGenTask.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.ant; +package com.sun.gluegen.ant; /* * GlueGenTask.java @@ -60,7 +60,7 @@ import org.apache.tools.ant.util.JavaEnvUtils; /** * <p>An <a href="http://ant.apache.org">ANT</a> {@link org.apache.tools.ant.Task} - * for using {@link net.java.games.gluegen.GlueGen}.</p> + * for using {@link com.sun.gluegen.GlueGen}.</p> * * <p>Usage:</p> * <pre> @@ -80,14 +80,14 @@ import org.apache.tools.ant.util.JavaEnvUtils; public class GlueGenTask extends Task { /** - * <p>The {@link net.java.games.gluegen.GlueGen} classname.</p> + * <p>The {@link com.sun.gluegen.GlueGen} classname.</p> */ - private static final String GLUE_GEN = "net.java.games.gluegen.GlueGen"; + private static final String GLUE_GEN = "com.sun.gluegen.GlueGen"; // ========================================================================= /** * <p>The {@link org.apache.tools.ant.types.CommandlineJava} that is used - * to execute {@link net.java.games.gluegen.GlueGen}.</p> + * to execute {@link com.sun.gluegen.GlueGen}.</p> */ private CommandlineJava gluegenCommandline; @@ -304,7 +304,7 @@ public class GlueGenTask extends Task } /** - * <p>Add an optional classpath that defines the location of {@link net.java.games.gluegen.GlueGen} + * <p>Add an optional classpath that defines the location of {@link com.sun.gluegen.GlueGen} * and <code>GlueGen</code>'s dependencies.</p> * * @returns {@link org.apache.tools.ant.types.Path} @@ -466,7 +466,7 @@ public class GlueGenTask extends Task } /** - * <p>Execute {@link net.java.games.gluegen.GlueGen} in a forked JVM.</p> + * <p>Execute {@link com.sun.gluegen.GlueGen} in a forked JVM.</p> * * @throws BuildException */ diff --git a/src/net/java/games/gluegen/ant/StaticGLGenTask.java b/src/classes/com/sun/gluegen/ant/StaticGLGenTask.java index 35ed2d504..255ab8a1a 100644 --- a/src/net/java/games/gluegen/ant/StaticGLGenTask.java +++ b/src/classes/com/sun/gluegen/ant/StaticGLGenTask.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.ant; +package com.sun.gluegen.ant; /* * StaticGLGenTask.java @@ -55,7 +55,7 @@ import org.apache.tools.ant.util.JavaEnvUtils; /** * <p>An <a href="http://ant.apache.org">ANT</a> {@link org.apache.tools.ant.Task} - * for using {@link net.java.games.gluegen.opengl.BuildStaticGLInfo}.</p> + * for using {@link com.sun.gluegen.opengl.BuildStaticGLInfo}.</p> * * <p>Usage:</p> * <pre> @@ -70,14 +70,14 @@ import org.apache.tools.ant.util.JavaEnvUtils; public class StaticGLGenTask extends Task { /** - * <p>The {@link net.java.games.gluegen.opengl.BuildStaticGLInfo} classname.</p> + * <p>The {@link com.sun.gluegen.opengl.BuildStaticGLInfo} classname.</p> */ - private static final String GL_GEN = "net.java.games.gluegen.opengl.BuildStaticGLInfo"; + private static final String GL_GEN = "com.sun.gluegen.opengl.BuildStaticGLInfo"; // ========================================================================= /** * <p>The {@link org.apache.tools.ant.types.CommandlineJava} that is used - * to execute {@link net.java.games.gluegen.opengl.BuildStaticGLInfo}.</p> + * to execute {@link com.sun.gluegen.opengl.BuildStaticGLInfo}.</p> */ private CommandlineJava glgenCommandline; @@ -170,7 +170,7 @@ public class StaticGLGenTask extends Task } /** - * <p>Add an optional classpath that defines the location of {@link net.java.games.gluegen.opengl.BuildStaticGLInfo} + * <p>Add an optional classpath that defines the location of {@link com.sun.gluegen.opengl.BuildStaticGLInfo} * and <code>BuildStaticGLInfo</code>'s dependencies.</p> * * @returns {@link org.apache.tools.ant.types.Path} @@ -274,7 +274,7 @@ public class StaticGLGenTask extends Task } /** - * <p>Execute {@link net.java.games.gluegen.opengl.BuildStaticGLInfo} in a + * <p>Execute {@link com.sun.gluegen.opengl.BuildStaticGLInfo} in a * forked JVM.</p> * * @throws BuildException diff --git a/src/net/java/games/gluegen/cgram/CSymbolTable.java b/src/classes/com/sun/gluegen/cgram/CSymbolTable.java index e22274b90..51edf44c3 100644 --- a/src/net/java/games/gluegen/cgram/CSymbolTable.java +++ b/src/classes/com/sun/gluegen/cgram/CSymbolTable.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; import java.util.Vector; import java.util.Hashtable; diff --git a/src/net/java/games/gluegen/cgram/CToken.java b/src/classes/com/sun/gluegen/cgram/CToken.java index facd95a08..5d85c48c7 100644 --- a/src/net/java/games/gluegen/cgram/CToken.java +++ b/src/classes/com/sun/gluegen/cgram/CToken.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; import antlr.CommonToken; diff --git a/src/net/java/games/gluegen/cgram/Define.java b/src/classes/com/sun/gluegen/cgram/Define.java index 9fbd8636d..a71c538bb 100644 --- a/src/net/java/games/gluegen/cgram/Define.java +++ b/src/classes/com/sun/gluegen/cgram/Define.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; /** Represents a #define of a literal to a value (a number represented in string form.) */ diff --git a/src/net/java/games/gluegen/cgram/GnuCEmitter.g b/src/classes/com/sun/gluegen/cgram/GnuCEmitter.g index 87294fc53..82003c3a0 100644 --- a/src/net/java/games/gluegen/cgram/GnuCEmitter.g +++ b/src/classes/com/sun/gluegen/cgram/GnuCEmitter.g @@ -17,7 +17,7 @@ DESCRIPTION: header { - package net.java.games.gluegen.cgram; + package com.sun.gluegen.cgram; import java.io.*; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/GnuCParser.g b/src/classes/com/sun/gluegen/cgram/GnuCParser.g index feed4518e..c90e01179 100644 --- a/src/net/java/games/gluegen/cgram/GnuCParser.g +++ b/src/classes/com/sun/gluegen/cgram/GnuCParser.g @@ -17,7 +17,7 @@ DESCRIPTION: header { - package net.java.games.gluegen.cgram; + package com.sun.gluegen.cgram; import java.io.*; diff --git a/src/net/java/games/gluegen/cgram/GnuCTreeParser.g b/src/classes/com/sun/gluegen/cgram/GnuCTreeParser.g index 8400e3e59..5231dee17 100644 --- a/src/net/java/games/gluegen/cgram/GnuCTreeParser.g +++ b/src/classes/com/sun/gluegen/cgram/GnuCTreeParser.g @@ -17,7 +17,7 @@ DESCRIPTION: header { - package net.java.games.gluegen.cgram; + package com.sun.gluegen.cgram; import java.io.*; diff --git a/src/net/java/games/gluegen/cgram/HeaderParser.g b/src/classes/com/sun/gluegen/cgram/HeaderParser.g index 1263c30b8..212e56091 100644 --- a/src/net/java/games/gluegen/cgram/HeaderParser.g +++ b/src/classes/com/sun/gluegen/cgram/HeaderParser.g @@ -38,13 +38,13 @@ */ header { - package net.java.games.gluegen.cgram; + package com.sun.gluegen.cgram; import java.io.*; import java.util.*; import antlr.CommonAST; - import net.java.games.gluegen.cgram.types.*; + import com.sun.gluegen.cgram.types.*; } class HeaderParser extends GnuCTreeParser; diff --git a/src/net/java/games/gluegen/cgram/LineObject.java b/src/classes/com/sun/gluegen/cgram/LineObject.java index 578e14194..0ed470c92 100644 --- a/src/net/java/games/gluegen/cgram/LineObject.java +++ b/src/classes/com/sun/gluegen/cgram/LineObject.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; class LineObject { LineObject parent = null; diff --git a/src/net/java/games/gluegen/cgram/PreprocessorInfoChannel.java b/src/classes/com/sun/gluegen/cgram/PreprocessorInfoChannel.java index f2de592c7..431af91d3 100644 --- a/src/net/java/games/gluegen/cgram/PreprocessorInfoChannel.java +++ b/src/classes/com/sun/gluegen/cgram/PreprocessorInfoChannel.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/StdCParser.g b/src/classes/com/sun/gluegen/cgram/StdCParser.g index 65f7468bf..e84fbfd6e 100644 --- a/src/net/java/games/gluegen/cgram/StdCParser.g +++ b/src/classes/com/sun/gluegen/cgram/StdCParser.g @@ -47,7 +47,7 @@ TODO: header { - package net.java.games.gluegen.cgram; + package com.sun.gluegen.cgram; import java.io.*; diff --git a/src/net/java/games/gluegen/cgram/TNode.java b/src/classes/com/sun/gluegen/cgram/TNode.java index 2a93b939c..f5b2c17e2 100644 --- a/src/net/java/games/gluegen/cgram/TNode.java +++ b/src/classes/com/sun/gluegen/cgram/TNode.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; import antlr.collections.AST; import antlr.CommonAST; diff --git a/src/net/java/games/gluegen/cgram/TNodeFactory.java b/src/classes/com/sun/gluegen/cgram/TNodeFactory.java index 8cda2cfa9..452363263 100644 --- a/src/net/java/games/gluegen/cgram/TNodeFactory.java +++ b/src/classes/com/sun/gluegen/cgram/TNodeFactory.java @@ -1,4 +1,4 @@ -package net.java.games.gluegen.cgram; +package com.sun.gluegen.cgram; import antlr.Token; import antlr.ASTFactory; diff --git a/src/net/java/games/gluegen/cgram/types/ArrayType.java b/src/classes/com/sun/gluegen/cgram/types/ArrayType.java index 1a73284e7..c61e6457f 100644 --- a/src/net/java/games/gluegen/cgram/types/ArrayType.java +++ b/src/classes/com/sun/gluegen/cgram/types/ArrayType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Represents an array type. This differs from a pointer type in C syntax by the use of "[]" rather than "*". The length may or may diff --git a/src/net/java/games/gluegen/cgram/types/BitType.java b/src/classes/com/sun/gluegen/cgram/types/BitType.java index 915f847f8..293eb3969 100644 --- a/src/net/java/games/gluegen/cgram/types/BitType.java +++ b/src/classes/com/sun/gluegen/cgram/types/BitType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Represents a bitfield in a struct. */ diff --git a/src/net/java/games/gluegen/cgram/types/CVAttributes.java b/src/classes/com/sun/gluegen/cgram/types/CVAttributes.java index 481a7be00..589904b36 100644 --- a/src/net/java/games/gluegen/cgram/types/CVAttributes.java +++ b/src/classes/com/sun/gluegen/cgram/types/CVAttributes.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Enumeration for const/volatile attributes. These are passed in to the constructor of the type. */ diff --git a/src/net/java/games/gluegen/cgram/types/CompoundType.java b/src/classes/com/sun/gluegen/cgram/types/CompoundType.java index 4c8c2d9ac..6ad7580e0 100644 --- a/src/net/java/games/gluegen/cgram/types/CompoundType.java +++ b/src/classes/com/sun/gluegen/cgram/types/CompoundType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/types/CompoundTypeKind.java b/src/classes/com/sun/gluegen/cgram/types/CompoundTypeKind.java index eedabfd2f..8df12ac7f 100644 --- a/src/net/java/games/gluegen/cgram/types/CompoundTypeKind.java +++ b/src/classes/com/sun/gluegen/cgram/types/CompoundTypeKind.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Type-safe enum for discriminating between structs and unions, which are both represented as compound types. */ diff --git a/src/net/java/games/gluegen/cgram/types/DoubleType.java b/src/classes/com/sun/gluegen/cgram/types/DoubleType.java index 3d0ca6fe1..e2be470fb 100644 --- a/src/net/java/games/gluegen/cgram/types/DoubleType.java +++ b/src/classes/com/sun/gluegen/cgram/types/DoubleType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Represents a double-word floating-point type (C type "double".) */ diff --git a/src/net/java/games/gluegen/cgram/types/EnumType.java b/src/classes/com/sun/gluegen/cgram/types/EnumType.java index 4ddd1e514..7f4b9e559 100644 --- a/src/net/java/games/gluegen/cgram/types/EnumType.java +++ b/src/classes/com/sun/gluegen/cgram/types/EnumType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/types/Field.java b/src/classes/com/sun/gluegen/cgram/types/Field.java index a2ea44363..3514c8f7e 100644 --- a/src/net/java/games/gluegen/cgram/types/Field.java +++ b/src/classes/com/sun/gluegen/cgram/types/Field.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Represents a field in a struct or union. */ diff --git a/src/net/java/games/gluegen/cgram/types/FloatType.java b/src/classes/com/sun/gluegen/cgram/types/FloatType.java index 8b81e0c3f..9f59b3564 100644 --- a/src/net/java/games/gluegen/cgram/types/FloatType.java +++ b/src/classes/com/sun/gluegen/cgram/types/FloatType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; /** Represents a single-word floating-point type (C type "float".) */ diff --git a/src/net/java/games/gluegen/cgram/types/FunctionSymbol.java b/src/classes/com/sun/gluegen/cgram/types/FunctionSymbol.java index ab72dfb83..50ee8ccff 100644 --- a/src/net/java/games/gluegen/cgram/types/FunctionSymbol.java +++ b/src/classes/com/sun/gluegen/cgram/types/FunctionSymbol.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/types/FunctionType.java b/src/classes/com/sun/gluegen/cgram/types/FunctionType.java index 5d309a83f..9c94daea2 100644 --- a/src/net/java/games/gluegen/cgram/types/FunctionType.java +++ b/src/classes/com/sun/gluegen/cgram/types/FunctionType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/types/IntType.java b/src/classes/com/sun/gluegen/cgram/types/IntType.java index 50223af11..2816c561c 100644 --- a/src/net/java/games/gluegen/cgram/types/IntType.java +++ b/src/classes/com/sun/gluegen/cgram/types/IntType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class IntType extends PrimitiveType { private boolean unsigned; diff --git a/src/net/java/games/gluegen/cgram/types/MachineDescription.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java index 7acb919bc..41923979b 100644 --- a/src/net/java/games/gluegen/cgram/types/MachineDescription.java +++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class MachineDescription { private int charSizeInBytes; diff --git a/src/net/java/games/gluegen/cgram/types/MachineDescription32Bit.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java index fca7edce7..1dbbb700c 100644 --- a/src/net/java/games/gluegen/cgram/types/MachineDescription32Bit.java +++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription32Bit.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class MachineDescription32Bit extends MachineDescription { public MachineDescription32Bit() { diff --git a/src/net/java/games/gluegen/cgram/types/MachineDescription64Bit.java b/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java index 4ef78639b..00d581266 100644 --- a/src/net/java/games/gluegen/cgram/types/MachineDescription64Bit.java +++ b/src/classes/com/sun/gluegen/cgram/types/MachineDescription64Bit.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class MachineDescription64Bit extends MachineDescription { public MachineDescription64Bit() { diff --git a/src/net/java/games/gluegen/cgram/types/PointerType.java b/src/classes/com/sun/gluegen/cgram/types/PointerType.java index ffe369761..142a2f12d 100644 --- a/src/net/java/games/gluegen/cgram/types/PointerType.java +++ b/src/classes/com/sun/gluegen/cgram/types/PointerType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class PointerType extends Type { private Type targetType; diff --git a/src/net/java/games/gluegen/cgram/types/PrimitiveType.java b/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java index 405f1016d..8807e2615 100644 --- a/src/net/java/games/gluegen/cgram/types/PrimitiveType.java +++ b/src/classes/com/sun/gluegen/cgram/types/PrimitiveType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public abstract class PrimitiveType extends Type { protected PrimitiveType(String name, int size, int cvAttributes) { diff --git a/src/net/java/games/gluegen/cgram/types/Type.java b/src/classes/com/sun/gluegen/cgram/types/Type.java index 6c0ea9f79..2ac492d3f 100644 --- a/src/net/java/games/gluegen/cgram/types/Type.java +++ b/src/classes/com/sun/gluegen/cgram/types/Type.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.List; diff --git a/src/net/java/games/gluegen/cgram/types/TypeDictionary.java b/src/classes/com/sun/gluegen/cgram/types/TypeDictionary.java index 3909919aa..5c74455cb 100644 --- a/src/net/java/games/gluegen/cgram/types/TypeDictionary.java +++ b/src/classes/com/sun/gluegen/cgram/types/TypeDictionary.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; import java.util.*; diff --git a/src/net/java/games/gluegen/cgram/types/TypeVisitor.java b/src/classes/com/sun/gluegen/cgram/types/TypeVisitor.java index 4679327d1..88f7dd544 100644 --- a/src/net/java/games/gluegen/cgram/types/TypeVisitor.java +++ b/src/classes/com/sun/gluegen/cgram/types/TypeVisitor.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public interface TypeVisitor { public void visitType(Type t); diff --git a/src/net/java/games/gluegen/cgram/types/VoidType.java b/src/classes/com/sun/gluegen/cgram/types/VoidType.java index 00130b708..db4c43f81 100644 --- a/src/net/java/games/gluegen/cgram/types/VoidType.java +++ b/src/classes/com/sun/gluegen/cgram/types/VoidType.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.cgram.types; +package com.sun.gluegen.cgram.types; public class VoidType extends Type { public VoidType(int cvAttributes) { diff --git a/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java b/src/classes/com/sun/gluegen/opengl/BuildComposablePipeline.java index eaed4a100..5235631be 100644 --- a/src/net/java/games/gluegen/opengl/BuildComposablePipeline.java +++ b/src/classes/com/sun/gluegen/opengl/BuildComposablePipeline.java @@ -37,9 +37,9 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.opengl; +package com.sun.gluegen.opengl; -import net.java.games.gluegen.*; +import com.sun.gluegen.*; import java.lang.reflect.*; import java.io.*; @@ -511,7 +511,7 @@ public class BuildComposablePipeline { output.println("/** <P> Composable pipline which wraps an underlying {@link GL} implementation,"); output.println(" providing tracing information to a user-specified {@link java.io.PrintStream}"); - output.println(" before after each OpenGL method call. Sample code which installs this pipeline: </P>"); + output.println(" before and after each OpenGL method call. Sample code which installs this pipeline: </P>"); output.println(); output.println("<PRE>"); output.println(" drawable.setGL(new TraceGL(drawable.getGL(), System.err));"); diff --git a/src/net/java/games/gluegen/opengl/BuildStaticGLInfo.java b/src/classes/com/sun/gluegen/opengl/BuildStaticGLInfo.java index e4a091946..52b9fde51 100644 --- a/src/net/java/games/gluegen/opengl/BuildStaticGLInfo.java +++ b/src/classes/com/sun/gluegen/opengl/BuildStaticGLInfo.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.opengl; +package com.sun.gluegen.opengl; import java.io.*; import java.util.*; @@ -90,10 +90,18 @@ import java.util.regex.*; * */ public class BuildStaticGLInfo { + // Handles function pointer protected static Pattern funcPattern = - Pattern.compile("^(GLAPI|extern)?(\\s*)(\\w+)(\\*)?(\\s+)(APIENTRY|WINAPI)?(\\s*)([w]?gl\\w+)\\s?(\\(.*)"); + Pattern.compile("^(GLAPI|extern)?(\\s*)(\\w+)(\\*)?(\\s+)(GLAPIENTRY|APIENTRY|WINAPI)?(\\s*)([w]?gl\\w+)\\s?(\\(.*)"); protected static Pattern associationPattern = Pattern.compile("\\#ifndef ([W]?GL[X]?_[A-Za-z0-9_]+)"); + protected static Pattern definePattern = + Pattern.compile("\\#define ([W]?GL[X]?_[A-Za-z0-9_]+)\\s*([A-Za-z0-9_]+)"); + // Maps function / #define names to the names of the extensions they're declared in + protected Map declarationToExtensionMap = new HashMap(); + // Maps extension names to Set of identifiers (both #defines and + // function names) this extension declares + protected Map/*<String, Set<String>*/ extensionToDeclarationMap = new HashMap(); /** * The first argument is the package to which the StaticGLInfo class @@ -101,8 +109,17 @@ public class BuildStaticGLInfo * classes reside, and the remaining arguments are paths to the C header * files that should be parsed */ - public static void main(String[] args) + public static void main(String[] args) throws IOException { + if (args.length > 0 && args[0].equals("-test")) { + BuildStaticGLInfo builder = new BuildStaticGLInfo(); + String[] newArgs = new String[args.length - 1]; + System.arraycopy(args, 1, newArgs, 0, args.length - 1); + builder.parse(newArgs); + builder.dump(); + System.exit(0); + } + String packageName = args[0]; String packageDir = args[1]; @@ -110,18 +127,18 @@ public class BuildStaticGLInfo System.arraycopy(args, 2, cHeaderFilePaths, 0, cHeaderFilePaths.length); BuildStaticGLInfo builder = new BuildStaticGLInfo(); - try - { + try { + builder.parse(cHeaderFilePaths); + File file = new File(packageDir + File.separatorChar + "StaticGLInfo.java"); String parentDir = file.getParent(); - if (parentDir != null) - { + if (parentDir != null) { File pDirFile = new File(parentDir); pDirFile.mkdirs(); } PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file))); - builder.build(writer, packageName, cHeaderFilePaths); + builder.emitJavaCode(writer, packageName); writer.flush(); writer.close(); @@ -140,53 +157,71 @@ public class BuildStaticGLInfo } } - protected void build(PrintWriter output, String packageName, String[] cHeaderFilePaths) throws IOException - { - HashMap groupToFuncHash = new HashMap(50); - for (int i = 0; i < cHeaderFilePaths.length; ++i) - { - process(groupToFuncHash, new FileReader(cHeaderFilePaths[i])); + + /** Parses the supplied C header files and adds the function + associations contained therein to the internal map. */ + public void parse(String[] cHeaderFilePaths) throws IOException { + for (int i = 0; i < cHeaderFilePaths.length; i++) { + parse(cHeaderFilePaths[i]); } - - emitJavaCode(output, packageName, groupToFuncHash); } - - protected void process(HashMap groupToFuncHash, FileReader headerFile) throws IOException - { - BufferedReader reader = new BufferedReader(headerFile); + + /** Parses the supplied C header file and adds the function + associations contained therein to the internal map. */ + public void parse(String cHeaderFilePath) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(cHeaderFilePath)); String line, activeAssociation = null; - Matcher m; - while ((line = reader.readLine()) != null) - { + Matcher m = null; + while ((line = reader.readLine()) != null) { // see if we're inside a #ifndef GL_XXX block and matching a function - if (activeAssociation != null && (m = funcPattern.matcher(line)).matches()) - { - // We found a new function associated with the last #ifndef block we - // were associated with - - String funcName = m.group(8); - HashSet funcsForGroup = (HashSet)groupToFuncHash.get(activeAssociation); - if (funcsForGroup == null) - { - funcsForGroup = new HashSet(8); - groupToFuncHash.put(activeAssociation, funcsForGroup); + if (activeAssociation != null) { + String identifier = null; + if ((m = funcPattern.matcher(line)).matches()) { + identifier = m.group(8); + } else if ((m = definePattern.matcher(line)).matches()) { + identifier = m.group(1); + } else if (line.startsWith("#endif")) { + activeAssociation = null; } - funcsForGroup.add(funcName); - - //System.err.println("FOUND ASSOCIATION FOR " + activeAssociation + ": " + funcName); - } - else if ((m = associationPattern.matcher(line)).matches()) - { + if ((identifier != null) && + (activeAssociation != null) && + // Handles #ifndef GL_... #define GL_... + !identifier.equals(activeAssociation)) { + addAssociation(identifier, activeAssociation); + } + } else if ((m = associationPattern.matcher(line)).matches()) { // found a new #ifndef GL_XXX block activeAssociation = m.group(1); - + //System.err.println("FOUND NEW ASSOCIATION BLOCK: " + activeAssociation); } } + reader.close(); + } + + public void dump() { + for (Iterator i1 = extensionToDeclarationMap.keySet().iterator(); i1.hasNext(); ) { + String name = (String) i1.next(); + Set decls = (Set) extensionToDeclarationMap.get(name); + System.out.println(name + ":"); + List l = new ArrayList(); + l.addAll(decls); + Collections.sort(l); + for (Iterator i2 = l.iterator(); i2.hasNext(); ) { + System.out.println(" " + (String) i2.next()); + } + } + } + + public String getExtension(String identifier) { + return (String) declarationToExtensionMap.get(identifier); } - protected void emitJavaCode(PrintWriter output, String packageName, HashMap groupToFuncHash) - { + public Set getDeclarations(String extension) { + return (Set) extensionToDeclarationMap.get(extension); + } + + public void emitJavaCode(PrintWriter output, String packageName) { output.println("package " + packageName + ";"); output.println(); output.println("import java.util.*;"); @@ -227,31 +262,59 @@ public class BuildStaticGLInfo output.println(" static"); output.println(" {"); - output.println(" funcToAssocMap = new HashMap(1536); // approximate max capacity"); + + // Compute max capacity + int maxCapacity = 0; + for (Iterator iter = declarationToExtensionMap.keySet().iterator(); iter.hasNext(); ) { + String name = (String) iter.next(); + if (!name.startsWith("GL")) { + ++maxCapacity; + } + } + + output.println(" funcToAssocMap = new HashMap(" + maxCapacity + "); // approximate max capacity"); output.println(" String group;"); - ArrayList sets = new ArrayList(groupToFuncHash.keySet()); + ArrayList sets = new ArrayList(extensionToDeclarationMap.keySet()); Collections.sort(sets); - for (int i = 0; i < sets.size(); ++i) - { - String groupName = (String) sets.get(i); - //System.err.println(groupName); // debug - output.println(); - output.println(" //----------------------------------------------------------------"); - output.println(" // " + groupName); - output.println(" //----------------------------------------------------------------"); - output.println(" group = \"" + groupName + "\";"); - HashSet funcs = (HashSet)groupToFuncHash.get(groupName); - Iterator funcIter = funcs.iterator(); - while (funcIter.hasNext()) - { + for (Iterator iter = sets.iterator(); iter.hasNext(); ) { + String groupName = (String) iter.next(); + Set funcs = (Set) extensionToDeclarationMap.get(groupName); + List l = new ArrayList(); + l.addAll(funcs); + Collections.sort(l); + Iterator funcIter = l.iterator(); + boolean printedHeader = false; + while (funcIter.hasNext()) { String funcName = (String)funcIter.next(); - //System.err.println(" " + funcName); // debug - output.println(" funcToAssocMap.put(\"" + funcName + "\", group);"); + if (!funcName.startsWith("GL")) { + if (!printedHeader) { + output.println(); + output.println(" //----------------------------------------------------------------"); + output.println(" // " + groupName); + output.println(" //----------------------------------------------------------------"); + output.println(" group = \"" + groupName + "\";"); + printedHeader = true; + } + + output.println(" funcToAssocMap.put(\"" + funcName + "\", group);"); + } } } output.println(" }"); - output.println("} // end class StaticGLInfo"); } + //---------------------------------------------------------------------- + // Internals only below this point + // + + protected void addAssociation(String identifier, String association) { + declarationToExtensionMap.put(identifier, association); + Set/*<String>*/ identifiers = (Set) extensionToDeclarationMap.get(association); + if (identifiers == null) { + identifiers = new HashSet/*<String>*/(); + extensionToDeclarationMap.put(association, identifiers); + } + identifiers.add(identifier); + } } diff --git a/src/net/java/games/gluegen/opengl/ConvertFromGL4Java.java b/src/classes/com/sun/gluegen/opengl/ConvertFromGL4Java.java index 428aba110..2f051a78b 100644 --- a/src/net/java/games/gluegen/opengl/ConvertFromGL4Java.java +++ b/src/classes/com/sun/gluegen/opengl/ConvertFromGL4Java.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.opengl; +package com.sun.gluegen.opengl; import java.io.*; @@ -62,7 +62,7 @@ public class ConvertFromGL4Java { String trimmed = line.trim(); boolean isImport = false; if (trimmed.startsWith("import gl4java")) { - line = "import net.java.games.jogl.*;"; + line = "import javax.media.opengl.*;"; isImport = true; } if (!isImport || diff --git a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java b/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java index 9ec2a81f9..653a8cd3d 100644..100755 --- a/src/net/java/games/gluegen/opengl/CGLPAWrapperEmitter.java +++ b/src/classes/com/sun/gluegen/opengl/GLCMethodBindingEmitter.java @@ -37,37 +37,50 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.opengl; +package com.sun.gluegen.opengl; import java.io.*; import java.util.*; -import net.java.games.gluegen.*; -import net.java.games.gluegen.cgram.types.*; +import com.sun.gluegen.*; +import com.sun.gluegen.cgram.types.*; -public class CGLPAWrapperEmitter extends CMethodBindingEmitter -{ +public class GLCMethodBindingEmitter extends CMethodBindingEmitter { private static final CommentEmitter defaultCommentEmitter = new CGLPAWrapperCommentEmitter(); - private CMethodBindingEmitter emitterBeingWrapped; + private boolean callThroughProcAddress; private String glFuncPtrTypedefValue; private static String procAddressJavaTypeName = JavaType.createForClass(Long.TYPE).jniTypeName(); - public CGLPAWrapperEmitter(CMethodBindingEmitter methodToWrap) - { + public GLCMethodBindingEmitter(CMethodBindingEmitter methodToWrap, + final boolean callThroughProcAddress) { super( new MethodBinding(methodToWrap.getBinding()) { public String getName() { - return GLEmitter.WRAP_PREFIX + super.getName(); + if (callThroughProcAddress) { + return GLEmitter.WRAP_PREFIX + super.getName(); + } else { + return super.getName(); + } + } + + public String getRenamedMethodName() { + if (callThroughProcAddress) { + return GLEmitter.WRAP_PREFIX + super.getRenamedMethodName(); + } else { + return super.getRenamedMethodName(); + } } }, - methodToWrap.getIsOverloadedBinding(), + methodToWrap.getDefaultOutput(), methodToWrap.getJavaPackageName(), methodToWrap.getJavaClassName(), + methodToWrap.getIsOverloadedBinding(), methodToWrap.getIsJavaMethodStatic(), - methodToWrap.getDefaultOutput() - ); + true, + methodToWrap.forIndirectBufferAndArrayImplementation() + ); if (methodToWrap.getReturnValueCapacityExpression() != null) { setReturnValueCapacityExpression(methodToWrap.getReturnValueCapacityExpression()); @@ -79,140 +92,105 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter setTemporaryCVariableAssignments (methodToWrap.getTemporaryCVariableAssignments ()); setCommentEmitter(defaultCommentEmitter); + this.callThroughProcAddress = callThroughProcAddress; } - protected int emitArguments(PrintWriter writer) - { + protected int emitArguments(PrintWriter writer) { int numEmitted = super.emitArguments(writer); - if (numEmitted > 0) - { - writer.print(", "); + if (callThroughProcAddress) { + if (numEmitted > 0) + { + writer.print(", "); + } + //writer.print("long glProcAddress"); + writer.print(procAddressJavaTypeName); + writer.print(" glProcAddress"); + ++numEmitted; } - //writer.print("long glProcAddress"); - writer.print(procAddressJavaTypeName); - writer.print(" glProcAddress"); - ++numEmitted; return numEmitted; } - protected void emitBodyVariableDeclarations(PrintWriter writer) - { - // create variable for the function pointer with the right type, and set - // it to the value of the passed-in glProcAddress - FunctionSymbol cSym = getBinding().getCSymbol(); - String funcPointerTypedefName = - GLEmitter.getGLFunctionPointerTypedefName(cSym); + protected void emitBodyVariableDeclarations(PrintWriter writer) { + if (callThroughProcAddress) { + // create variable for the function pointer with the right type, and set + // it to the value of the passed-in glProcAddress + FunctionSymbol cSym = getBinding().getCSymbol(); + String funcPointerTypedefName = + GLEmitter.getGLFunctionPointerTypedefName(cSym); - writer.print(" "); - writer.print(funcPointerTypedefName); - writer.print(" ptr_"); - writer.print(cSym.getName()); - writer.println(";"); + writer.print(" "); + writer.print(funcPointerTypedefName); + writer.print(" ptr_"); + writer.print(cSym.getName()); + writer.println(";"); + } super.emitBodyVariableDeclarations(writer); } protected void emitBodyVariablePreCallSetup(PrintWriter writer, - boolean emittingPrimitiveArrayCritical) - { + boolean emittingPrimitiveArrayCritical) { super.emitBodyVariablePreCallSetup(writer, emittingPrimitiveArrayCritical); - if (!emittingPrimitiveArrayCritical) { - // set the function pointer to the value of the passed-in glProcAddress - FunctionSymbol cSym = getBinding().getCSymbol(); - String funcPointerTypedefName = - GLEmitter.getGLFunctionPointerTypedefName(cSym); + if (callThroughProcAddress) { + if (!emittingPrimitiveArrayCritical) { + // set the function pointer to the value of the passed-in glProcAddress + FunctionSymbol cSym = getBinding().getCSymbol(); + String funcPointerTypedefName = + GLEmitter.getGLFunctionPointerTypedefName(cSym); - String ptrVarName = "ptr_" + cSym.getName(); + String ptrVarName = "ptr_" + cSym.getName(); - writer.print(" "); - writer.print(ptrVarName); - writer.print(" = ("); - writer.print(funcPointerTypedefName); - writer.println(") (intptr_t) glProcAddress;"); + writer.print(" "); + writer.print(ptrVarName); + writer.print(" = ("); + writer.print(funcPointerTypedefName); + writer.println(") (intptr_t) glProcAddress;"); - writer.println(" assert(" + ptrVarName + " != NULL);"); + writer.println(" assert(" + ptrVarName + " != NULL);"); + } } } - // FIXME: refactor this and the superclass version so we don't have to copy - // the whole function - protected void emitBodyCallCFunction(PrintWriter writer) - { - // Make the call to the actual C function - writer.print(" "); - - // WARNING: this code assumes that the return type has already been - // typedef-resolved. - Type cReturnType = getBinding().getCReturnType(); - - if (!cReturnType.isVoid()) { - writer.print("_res = "); - } - - // !!!!!!!!! BEGIN CHANGES FROM SUPERCLASS METHOD + protected void emitBodyCallCFunction(PrintWriter writer) { + if (!callThroughProcAddress) { + super.emitBodyCallCFunction(writer); + } else { + // Make the call to the actual C function + writer.print(" "); - MethodBinding binding = getBinding(); - if (binding.hasContainingType()) { - // Cannot call GL func through function pointer - throw new IllegalStateException( - "Cannot call GL func through function pointer: " + binding); - } + // WARNING: this code assumes that the return type has already been + // typedef-resolved. + Type cReturnType = binding.getCReturnType(); - // call throught the run-time function pointer - writer.print("(* ptr_"); - writer.print(binding.getCSymbol().getName()); - writer.print(") "); - - // !!!!!!!!! END CHANGES FROM SUPERCLASS METHOD - - - writer.print("("); - for (int i = 0; i < binding.getNumArguments(); i++) { - if (i != 0) { - writer.print(", "); + if (!cReturnType.isVoid()) { + writer.print("_res = "); } - JavaType javaType = binding.getJavaArgumentType(i); - // Handle case where only param is void. - if (javaType.isVoid()) { - // Make sure this is the only param to the method; if it isn't, - // there's something wrong with our parsing of the headers. - assert(binding.getNumArguments() == 1); - continue; - } - - if (javaType.isJNIEnv()) { - writer.print("env"); - } else if (binding.isArgumentThisPointer(i)) { - writer.print(CMethodBindingEmitter.cThisArgumentName()); - } else { - writer.print("("); - writer.print(binding.getCSymbol().getArgumentType(i).getName()); - writer.print(") "); - if (binding.getCArgumentType(i).isPointer() && binding.getJavaArgumentType(i).isPrimitive()) { - writer.print("(intptr_t) "); - } - if (javaType.isArray() || javaType.isNIOBuffer()) { - writer.print(pointerConversionArgumentName(i)); - if (javaArgTypeNeedsDataCopy(javaType)) { - writer.print("_copy"); - } - } else { - if (javaType.isString()) { writer.print("_UTF8"); } - writer.print(binding.getArgumentName(i)); - } + MethodBinding binding = getBinding(); + if (binding.hasContainingType()) { + // Cannot call GL func through function pointer + throw new IllegalStateException( + "Cannot call GL func through function pointer: " + binding); } + + // call throught the run-time function pointer + writer.print("(* ptr_"); + writer.print(binding.getCSymbol().getName()); + writer.print(") "); + writer.print("("); + emitBodyPassCArguments(writer); + writer.println(");"); } - writer.println(");"); } protected String jniMangle(MethodBinding binding) { - StringBuffer buf = new StringBuffer(); - buf.append(super.jniMangle(binding)); - jniMangle(Long.TYPE, buf); + StringBuffer buf = new StringBuffer(super.jniMangle(binding)); + if (callThroughProcAddress) { + jniMangle(Long.TYPE, buf, false); // to account for the additional _addr_ parameter + } return buf.toString(); - } + } /** This class emits the comment for the wrapper method */ private static class CGLPAWrapperCommentEmitter extends CMethodBindingEmitter.DefaultCommentEmitter { @@ -220,4 +198,4 @@ public class CGLPAWrapperEmitter extends CMethodBindingEmitter writer.print(" -- FIXME: IMPLEMENT COMMENT FOR CGLPAWrapperCommentEmitter -- "); } } -} // end class CGLPAWrapperEmitter +} // end class GLCMethodBindingEmitter diff --git a/src/net/java/games/gluegen/opengl/GLEmitter.java b/src/classes/com/sun/gluegen/opengl/GLEmitter.java index f36d7b1ac..4ba1df87b 100644 --- a/src/net/java/games/gluegen/opengl/GLEmitter.java +++ b/src/classes/com/sun/gluegen/opengl/GLEmitter.java @@ -37,14 +37,14 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.opengl; +package com.sun.gluegen.opengl; import java.io.*; import java.text.MessageFormat; import java.util.*; -import net.java.games.gluegen.*; -import net.java.games.gluegen.cgram.types.*; -import net.java.games.gluegen.runtime.*; +import com.sun.gluegen.*; +import com.sun.gluegen.cgram.types.*; +import com.sun.gluegen.runtime.*; /** * A subclass of JavaEmitter that modifies the normal emission of C and Java @@ -60,7 +60,25 @@ public class GLEmitter extends JavaEmitter private String tableClassPackage; private String tableClassName; private int numProcAddressEntries; + // Keeps track of which MethodBindings were created for handling + // Buffer Object variants. Used as a Set rather than a Map. + private Map/*<MethodBinding>*/ bufferObjectMethodBindings = new IdentityHashMap(); + + static class BufferObjectKind { + private BufferObjectKind() {} + + static final BufferObjectKind UNPACK_PIXEL = new BufferObjectKind(); + static final BufferObjectKind PACK_PIXEL = new BufferObjectKind(); + static final BufferObjectKind ARRAY = new BufferObjectKind(); + static final BufferObjectKind ELEMENT = new BufferObjectKind(); + } + public void beginEmission(GlueEmitterControls controls) throws IOException + { + getGLConfig().parseGLHeaders(controls); + super.beginEmission(controls); + } + public void beginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map canonMap) throws Exception @@ -93,19 +111,66 @@ public class GLEmitter extends JavaEmitter return new GLConfiguration(); } + /** In order to implement Buffer Object variants of certain + functions we generate another MethodBinding which maps the void* + argument to a Java long. The generation of emitters then takes + place as usual. We do however need to keep track of the modified + MethodBinding object so that we can also modify the emitters + later to inform them that their argument has changed. We might + want to push this functionality down into the MethodBinding + (i.e., mutators for argument names). We also would need to + inform the CMethodBindingEmitter that it is overloaded in this + case (though we default to true currently). */ + protected List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) { + List/*<MethodBinding>*/ bindings = super.expandMethodBinding(binding); + + if (!getGLConfig().isBufferObjectFunction(binding.getName())) { + return bindings; + } + + List/*<MethodBinding>*/ newBindings = new ArrayList(); + newBindings.addAll(bindings); + + // Need to expand each one of the generated bindings to take a + // Java long instead of a Buffer for each void* argument + for (Iterator iter = bindings.iterator(); iter.hasNext(); ) { + MethodBinding cur = (MethodBinding) iter.next(); + + // Some of these routines (glBitmap) take strongly-typed + // primitive pointers as arguments which are expanded into + // non-void* arguments + // This test (rather than !signatureUsesNIO) is used to catch + // more unexpected situations + if (cur.signatureUsesJavaPrimitiveArrays()) { + continue; + } + + MethodBinding result = cur; + for (int i = 0; i < cur.getNumArguments(); i++) { + if (cur.getJavaArgumentType(i).isNIOBuffer()) { + result = result.replaceJavaArgumentType(i, JavaType.createForClass(Long.TYPE)); + } + } + + if (result == cur) { + throw new RuntimeException("Error: didn't find any void* arguments for BufferObject function " + + binding.getName()); + } + + newBindings.add(result); + // Now need to flag this MethodBinding so that we generate the + // correct flags in the emitters later + bufferObjectMethodBindings.put(result, result); + } + + return newBindings; + } + protected List generateMethodBindingEmitters(FunctionSymbol sym) throws Exception { return generateMethodBindingEmittersImpl(sym); } - protected List generateMethodBindingEmitters(FunctionSymbol sym, boolean skipProcessing) throws Exception { - if (skipProcessing) { - return super.generateMethodBindingEmitters(sym); - } else { - return generateMethodBindingEmittersImpl(sym); - } - } - private List generateMethodBindingEmittersImpl(FunctionSymbol sym) throws Exception { List defaultEmitters = super.generateMethodBindingEmitters(sym); @@ -118,20 +183,21 @@ public class GLEmitter extends JavaEmitter return defaultEmitters; } - // Don't do anything special if this symbol doesn't require passing of - // Opengl procedure addresses in order to function correctly. - if (!needsProcAddressWrapper(sym) || getConfig().isUnimplemented(sym.getName())) + // Don't do anything special if this symbol doesn't require + // OpenGL-related modifications + if ((!needsProcAddressWrapper(sym) && !needsBufferObjectVariant(sym)) || + getConfig().isUnimplemented(sym.getName())) { return defaultEmitters; } - // 9 is default # expanded bindings for void* - ArrayList modifiedEmitters = new ArrayList(9); + ArrayList modifiedEmitters = new ArrayList(defaultEmitters.size()); - if (getGLConfig().emitProcAddressTable()) - { - // emit an entry in the GL proc address table for this method. - emitGLProcAddressTableEntryForSymbol(sym); + if (needsProcAddressWrapper(sym)) { + if (getGLConfig().emitProcAddressTable()) { + // emit an entry in the GL proc address table for this method. + emitGLProcAddressTableEntryForSymbol(sym); + } } for (Iterator iter = defaultEmitters.iterator(); iter.hasNext(); ) @@ -139,16 +205,11 @@ public class GLEmitter extends JavaEmitter FunctionEmitter emitter = (FunctionEmitter) iter.next(); if (emitter instanceof JavaMethodBindingEmitter) { - JavaMethodBindingEmitter newEmitter = - generateModifiedEmitter((JavaMethodBindingEmitter)emitter); - if (newEmitter != null) { - modifiedEmitters.add(newEmitter); - } + generateModifiedEmitters((JavaMethodBindingEmitter) emitter, modifiedEmitters); } else if (emitter instanceof CMethodBindingEmitter) { - modifiedEmitters.add( - generateModifiedEmitter((CMethodBindingEmitter)emitter)); + generateModifiedEmitters((CMethodBindingEmitter) emitter, modifiedEmitters); } else { @@ -181,38 +242,64 @@ public class GLEmitter extends JavaEmitter // Internals only below this point // - protected JavaMethodBindingEmitter generateModifiedEmitter(JavaMethodBindingEmitter baseJavaEmitter) - { - if (!(baseJavaEmitter instanceof JavaMethodBindingImplEmitter)) { - // We only want to wrap the native entry point in the implementation - // class, not the public interface in the interface class. - // - // If the superclass has generated a "0" emitter for this routine because - // it needs argument conversion or similar, filter that out since we will - // be providing such an emitter ourselves. Otherwise return the emitter - // unmodified. - if (baseJavaEmitter.isForImplementingMethodCall()) - return null; - return baseJavaEmitter; - } + protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List emitters) { if (getGLConfig().manuallyImplement(baseJavaEmitter.getName())) { - // User will provide Java-side implementation of this routine - return null; + // User will provide Java-side implementation of this routine; + // pass through any emitters which will produce signatures for + // it unmodified + emitters.add(baseJavaEmitter); + return; + } + + // See whether we need a proc address entry for this one + boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol()); + // See whether this is one of the Buffer Object variants + boolean bufferObjectVariant = bufferObjectMethodBindings.containsKey(baseJavaEmitter.getBinding()); + + GLJavaMethodBindingEmitter emitter = + new GLJavaMethodBindingEmitter(baseJavaEmitter, + callThroughProcAddress, + getGLConfig().getProcAddressTableExpr(), + baseJavaEmitter.isForImplementingMethodCall(), + bufferObjectVariant); + emitters.add(emitter); + + // If this emitter doesn't have a body (i.e., is a public native + // call), we need to force it to emit a body, and produce another + // one to act as the entry point + if (baseJavaEmitter.signatureOnly() && + baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.PUBLIC) && + baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE) && + callThroughProcAddress) { + emitter.setEmitBody(true); + emitter.removeModifier(JavaMethodBindingEmitter.NATIVE); + emitter = new GLJavaMethodBindingEmitter(baseJavaEmitter, + callThroughProcAddress, + getGLConfig().getProcAddressTableExpr(), + true, + bufferObjectVariant); + emitter.setForImplementingMethodCall(true); + emitters.add(emitter); } - return new JavaGLPAWrapperEmitter(baseJavaEmitter, getGLConfig().getProcAddressTableExpr()); } - protected CMethodBindingEmitter generateModifiedEmitter(CMethodBindingEmitter baseCEmitter) + protected void generateModifiedEmitters(CMethodBindingEmitter baseCEmitter, List emitters) { + // See whether we need a proc address entry for this one + boolean callThroughProcAddress = needsProcAddressWrapper(baseCEmitter.getBinding().getCSymbol()); + // Note that we don't care much about the naming of the C argument + // variables so to keep things simple we ignore the buffer object + // property for the binding + // The C-side JNI binding for this particular function will have an // extra final argument, which is the address (the OpenGL procedure // address) of the function it needs to call - CGLPAWrapperEmitter res = new CGLPAWrapperEmitter(baseCEmitter); + GLCMethodBindingEmitter res = new GLCMethodBindingEmitter(baseCEmitter, callThroughProcAddress); MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression(); if (exp != null) { res.setReturnValueCapacityExpression(exp); } - return res; + emitters.add(res); } protected boolean needsProcAddressWrapper(FunctionSymbol sym) @@ -250,6 +337,10 @@ public class GLEmitter extends JavaEmitter return shouldWrap; } + + protected boolean needsBufferObjectVariant(FunctionSymbol sym) { + return getGLConfig().isBufferObjectFunction(sym.getName()); + } private void beginGLProcAddressTable() throws Exception { @@ -309,7 +400,7 @@ public class GLEmitter extends JavaEmitter w.println(" * and therefore does not have a valid GL procedure address. "); w.println(" */"); w.println(" public long getAddressFor(String glFunctionName) {"); - w.println(" String addressFieldName = net.java.games.gluegen.opengl.GLEmitter.PROCADDRESS_VAR_PREFIX + glFunctionName;"); + w.println(" String addressFieldName = com.sun.gluegen.opengl.GLEmitter.PROCADDRESS_VAR_PREFIX + glFunctionName;"); w.println(" try { "); w.println(" java.lang.reflect.Field addressField = this.getClass().getField(addressFieldName);"); w.println(" return addressField.getLong(this);"); @@ -351,7 +442,7 @@ public class GLEmitter extends JavaEmitter return (GLConfiguration) getConfig(); } - protected static class GLConfiguration extends JavaConfiguration + protected class GLConfiguration extends JavaConfiguration { private boolean emitProcAddressTable = false; private String tableClassPackage; @@ -359,8 +450,13 @@ public class GLEmitter extends JavaEmitter private Set/*<String>*/ skipProcAddressGen = new HashSet(); private List/*<String>*/ forceProcAddressGen = new ArrayList(); private String contextVariableName = "context"; - private String defaultGetProcAddressTableExpr = ".getGLProcAddressTable()"; private String getProcAddressTableExpr; + // The following data members support ignoring an entire extension at a time + private List/*<String>*/ glHeaders = new ArrayList(); + private Set/*<String>*/ ignoredExtensions = new HashSet(); + private BuildStaticGLInfo glInfo; + // Maps function names to the kind of buffer object it deals with + private Map/*<String,BufferObjectKind>*/ bufferObjectKinds = new HashMap(); protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException { if (cmd.equalsIgnoreCase("EmitProcAddressTable")) @@ -394,6 +490,20 @@ public class GLEmitter extends JavaEmitter { getProcAddressTableExpr = readGetProcAddressTableExpr(tok, filename, lineNo); } + else if (cmd.equalsIgnoreCase("IgnoreExtension")) + { + String sym = readString("IgnoreExtension", tok, filename, lineNo); + ignoredExtensions.add(sym); + } + else if (cmd.equalsIgnoreCase("GLHeader")) + { + String sym = readString("GLHeader", tok, filename, lineNo); + glHeaders.add(sym); + } + else if (cmd.equalsIgnoreCase("BufferObjectKind")) + { + readBufferObjectKind(tok, filename, lineNo); + } else { super.dispatch(cmd,tok,file,filename,lineNo); @@ -410,6 +520,32 @@ public class GLEmitter extends JavaEmitter } } + protected void readBufferObjectKind(StringTokenizer tok, String filename, int lineNo) { + try { + String kindString = tok.nextToken(); + BufferObjectKind kind = null; + String target = tok.nextToken(); + if (kindString.equalsIgnoreCase("UnpackPixel")) { + kind = BufferObjectKind.UNPACK_PIXEL; + } else if (kindString.equalsIgnoreCase("PackPixel")) { + kind = BufferObjectKind.PACK_PIXEL; + } else if (kindString.equalsIgnoreCase("Array")) { + kind = BufferObjectKind.ARRAY; + } else if (kindString.equalsIgnoreCase("Element")) { + kind = BufferObjectKind.ELEMENT; + } else { + throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo + + " in file \"" + filename + "\": illegal BufferObjectKind \"" + + kindString + "\", expected one of UnpackPixel, PackPixel, Array, or Element"); + } + + bufferObjectKinds.put(target, kind); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"BufferObjectKind\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + public boolean emitProcAddressTable() { return emitProcAddressTable; } public String tableClassPackage() { return tableClassPackage; } public String tableClassName() { return tableClassName; } @@ -418,10 +554,94 @@ public class GLEmitter extends JavaEmitter public String contextVariableName() { return contextVariableName; } public String getProcAddressTableExpr() { if (getProcAddressTableExpr == null) { - getProcAddressTableExpr = contextVariableName + defaultGetProcAddressTableExpr; + getProcAddressTableExpr = contextVariableName + ".get" + tableClassName + "()"; } return getProcAddressTableExpr; } + + public boolean shouldIgnore(String symbol) { + // Check ignored extensions based on our knowledge of the static GL info + if (glInfo != null) { + String extension = glInfo.getExtension(symbol); + if (extension != null && + ignoredExtensions.contains(extension)) { + return true; + } + } + + return super.shouldIgnore(symbol); + } + + /** Overrides javaPrologueForMethod in superclass and + automatically generates prologue code for functions associated + with buffer objects. */ + public List/*<String>*/ javaPrologueForMethod(MethodBinding binding, + boolean forImplementingMethodCall, + boolean eraseBufferAndArrayTypes) { + List/*<String>*/ res = super.javaPrologueForMethod(binding, + forImplementingMethodCall, + eraseBufferAndArrayTypes); + BufferObjectKind kind = getBufferObjectKind(binding.getName()); + if (kind != null) { + // Need to generate appropriate prologue based on both buffer + // object kind and whether this variant of the MethodBinding + // is the one accepting a "long" as argument + if (res == null) { + res = new ArrayList(); + } + + String prologue = "check"; + + if (kind == BufferObjectKind.UNPACK_PIXEL) { + prologue = prologue + "UnpackPBO"; + } else if (kind == BufferObjectKind.PACK_PIXEL) { + prologue = prologue + "PackPBO"; + } else if (kind == BufferObjectKind.ARRAY) { + prologue = prologue + "ArrayVBO"; + } else if (kind == BufferObjectKind.ELEMENT) { + prologue = prologue + "ElementVBO"; + } else { + throw new RuntimeException("Unknown BufferObjectKind " + kind); + } + + if (bufferObjectMethodBindings.containsKey(binding)) { + prologue = prologue + "Enabled"; + } else { + prologue = prologue + "Disabled"; + } + + prologue = prologue + "();"; + + res.add(0, prologue); + } + + return res; + } + + /** Returns the kind of buffer object this function deals with, or + null if none. */ + public BufferObjectKind getBufferObjectKind(String name) { + return (BufferObjectKind) bufferObjectKinds.get(name); + } + + public boolean isBufferObjectFunction(String name) { + return (getBufferObjectKind(name) != null); + } + + /** Parses any GL headers specified in the configuration file for + the purpose of being able to ignore an extension at a time. */ + public void parseGLHeaders(GlueEmitterControls controls) throws IOException { + if (!glHeaders.isEmpty()) { + glInfo = new BuildStaticGLInfo(); + for (Iterator iter = glHeaders.iterator(); iter.hasNext(); ) { + String file = (String) iter.next(); + String fullPath = controls.findHeaderFile(file); + if (fullPath == null) { + throw new IOException("Unable to locate header file \"" + file + "\""); + } + glInfo.parse(fullPath); + } + } + } } // end class GLConfiguration } - diff --git a/src/classes/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java b/src/classes/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java new file mode 100755 index 000000000..1e72cd633 --- /dev/null +++ b/src/classes/com/sun/gluegen/opengl/GLJavaMethodBindingEmitter.java @@ -0,0 +1,163 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.gluegen.opengl; + +import java.io.*; +import java.util.*; +import com.sun.gluegen.*; +import com.sun.gluegen.cgram.types.*; + +public class GLJavaMethodBindingEmitter extends JavaMethodBindingEmitter { + private final CommentEmitter commentEmitterForWrappedMethod = + new WrappedMethodCommentEmitter(); + + private boolean callThroughProcAddress; + private boolean changeNameAndArguments; + private String getProcAddressTableExpr; + private boolean bufferObjectVariant; + + public GLJavaMethodBindingEmitter(JavaMethodBindingEmitter methodToWrap, + boolean callThroughProcAddress, + String getProcAddressTableExpr, + boolean changeNameAndArguments, + boolean bufferObjectVariant) { + super(methodToWrap); + this.callThroughProcAddress = callThroughProcAddress; + this.getProcAddressTableExpr = getProcAddressTableExpr; + this.changeNameAndArguments = changeNameAndArguments; + this.bufferObjectVariant = bufferObjectVariant; + if (callThroughProcAddress) { + setCommentEmitter(new WrappedMethodCommentEmitter()); + } + + if (methodToWrap.getBinding().hasContainingType()) + { + throw new IllegalArgumentException( + "Cannot create OpenGL proc. address wrapper; method has containing type: \"" + + methodToWrap.getBinding() + "\""); + } + } + + public String getName() { + String res = super.getName(); + if (changeNameAndArguments) { + return GLEmitter.WRAP_PREFIX + res; + } + return res; + } + + protected String getArgumentName(int i) { + String name = super.getArgumentName(i); + + if (!bufferObjectVariant) { + return name; + } + + // Emitters for VBO/PBO-related routines change the outgoing + // argument name for the buffer + if (binding.getJavaArgumentType(i).isLong()) { + Type cType = binding.getCArgumentType(i); + if (cType.isPointer() && + (cType.asPointer().getTargetType().isVoid() || + cType.asPointer().getTargetType().isPrimitive())) { + return name + "_buffer_offset"; + } + } + + return name; + } + + protected int emitArguments(PrintWriter writer) { + int numEmitted = super.emitArguments(writer); + if (callThroughProcAddress) { + if (changeNameAndArguments) { + if (numEmitted > 0) { + writer.print(", "); + } + + writer.print("long glProcAddress"); + ++numEmitted; + } + } + + return numEmitted; + } + + protected String getImplMethodName(boolean direct) { + String name = super.getImplMethodName(direct); + if (callThroughProcAddress) { + return GLEmitter.WRAP_PREFIX + name; + } + return name; + } + + protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { + super.emitPreCallSetup(binding, writer); + + if (callThroughProcAddress) { + String procAddressVariable = + GLEmitter.PROCADDRESS_VAR_PREFIX + binding.getName(); + writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); + writer.println(" if (__addr_ == 0) {"); + writer.println(" throw new GLException(\"Method \\\"" + binding.getName() + "\\\" not available\");"); + writer.println(" }"); + } + } + + protected int emitCallArguments(MethodBinding binding, PrintWriter writer, boolean indirect) { + int numEmitted = super.emitCallArguments(binding, writer, indirect); + if (callThroughProcAddress) { + if (numEmitted > 0) { + writer.print(", "); + } + writer.print("__addr_"); + ++numEmitted; + } + + return numEmitted; + } + + /** This class emits the comment for the wrapper method */ + private class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { + protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) { + writer.print("Encapsulates function pointer for OpenGL function <br>: "); + } + } +} // end class GLJavaMethodBindingEmitter diff --git a/src/net/java/games/gluegen/pcpp/PCPP.java b/src/classes/com/sun/gluegen/pcpp/PCPP.java index 0990bb155..a2d3ab09b 100644 --- a/src/net/java/games/gluegen/pcpp/PCPP.java +++ b/src/classes/com/sun/gluegen/pcpp/PCPP.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.pcpp; +package com.sun.gluegen.pcpp; import java.io.*; import java.util.*; @@ -125,6 +125,19 @@ public class PCPP { } } + public String findFile(String filename) { + String sep = File.separator; + for (Iterator iter = includePaths.iterator(); iter.hasNext(); ) { + String inclPath = (String) iter.next(); + String fullPath = inclPath + sep + filename; + File file = new File(fullPath); + if (file.exists()) { + return fullPath; + } + } + return null; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -748,19 +761,6 @@ public class PCPP { } } - private String findFile(String filename) { - String sep = System.getProperty("file.separator"); - for (Iterator iter = includePaths.iterator(); iter.hasNext(); ) { - String inclPath = (String) iter.next(); - String fullPath = inclPath + sep + filename; - File file = new File(fullPath); - if (file.exists()) { - return fullPath; - } - } - return null; - } - //////////// // Output // //////////// diff --git a/src/classes/com/sun/gluegen/runtime/BufferFactory.java b/src/classes/com/sun/gluegen/runtime/BufferFactory.java new file mode 100644 index 000000000..ca66e6915 --- /dev/null +++ b/src/classes/com/sun/gluegen/runtime/BufferFactory.java @@ -0,0 +1,164 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.gluegen.runtime; + +import java.nio.*; +import com.sun.opengl.utils.BufferUtils; + +public class BufferFactory { + + public static int SIZEOF_FLOAT = BufferUtils.SIZEOF_FLOAT; + public static int SIZEOF_DOUBLE = BufferUtils.SIZEOF_DOUBLE; + public static int SIZEOF_INT = BufferUtils.SIZEOF_INT; + public static int SIZEOF_SHORT = BufferUtils.SIZEOF_SHORT; + public static int SIZEOF_LONG = BufferUtils.SIZEOF_LONG; + + public static ByteBuffer newDirectByteBuffer(int size) { + ByteBuffer buf = ByteBuffer.allocateDirect(size); + buf.order(ByteOrder.nativeOrder()); + return buf; + } + + /** Helper routine to tell whether a buffer is direct or not. Null + pointers are considered direct. isDirect() should really be + public in Buffer and not replicated in all subclasses. */ + public static boolean isDirect(Buffer buf) { + if (buf == null) { + return true; + } + if (buf instanceof ByteBuffer) { + return ((ByteBuffer) buf).isDirect(); + } else if (buf instanceof FloatBuffer) { + return ((FloatBuffer) buf).isDirect(); + } else if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).isDirect(); + } else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).isDirect(); + } else if (buf instanceof ShortBuffer) { + return ((ShortBuffer) buf).isDirect(); + } else if (buf instanceof IntBuffer) { + return ((IntBuffer) buf).isDirect(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).isDirect(); + } + throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); + } + + + /** Helper routine to get the Buffer byte offset by taking into + account the Buffer position and the underlying type. This is + the total offset for Direct Buffers. */ + + public static int getDirectBufferByteOffset(Buffer buf) { + if(buf == null) { + return 0; + } + if(buf instanceof ByteBuffer) { + return (buf.position()); + } else if (buf instanceof FloatBuffer) { + return (buf.position() * BufferUtils.SIZEOF_FLOAT); + } else if (buf instanceof IntBuffer) { + return (buf.position() * BufferUtils.SIZEOF_INT); + } else if (buf instanceof ShortBuffer) { + return (buf.position() * BufferUtils.SIZEOF_SHORT); + } else if (buf instanceof DoubleBuffer) { + return (buf.position() * BufferUtils.SIZEOF_DOUBLE); + } else if (buf instanceof LongBuffer) { + return (buf.position() * BufferUtils.SIZEOF_LONG); + } + + throw new RuntimeException("Disallowed array backing store type in buffer " + + buf.getClass().getName()); + } + + + /** Helper routine to return the array backing store reference from + a Buffer object. */ + + public static Object getArray(Buffer buf) { + if (buf == null) { + return null; + } + if(buf instanceof ByteBuffer) { + return ((ByteBuffer) buf).array(); + } else if (buf instanceof FloatBuffer) { + return ((FloatBuffer) buf).array(); + } else if (buf instanceof IntBuffer) { + return ((IntBuffer) buf).array(); + } else if (buf instanceof ShortBuffer) { + return ((ShortBuffer) buf).array(); + } else if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).array(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).array(); + } + + throw new RuntimeException("Disallowed array backing store type in buffer " + + buf.getClass().getName()); + } + + + /** Helper routine to get the full byte offset from the beginning of + the array that is the storage for the indirect Buffer + object. The array offset also includes the position offset + within the buffer, in addition to any array offset. */ + + public static int getIndirectBufferByteOffset(Buffer buf) { + if(buf == null) { + return 0; + } + int pos = buf.position(); + if(buf instanceof ByteBuffer) { + return (((ByteBuffer)buf).arrayOffset() + pos); + } else if(buf instanceof FloatBuffer) { + return (BufferUtils.SIZEOF_FLOAT*(((FloatBuffer)buf).arrayOffset() + pos)); + } else if(buf instanceof IntBuffer) { + return (BufferUtils.SIZEOF_INT*(((IntBuffer)buf).arrayOffset() + pos)); + } else if(buf instanceof ShortBuffer) { + return (BufferUtils.SIZEOF_SHORT*(((ShortBuffer)buf).arrayOffset() + pos)); + } else if(buf instanceof DoubleBuffer) { + return (BufferUtils.SIZEOF_DOUBLE*(((DoubleBuffer)buf).arrayOffset() + pos)); + } else if(buf instanceof LongBuffer) { + return (BufferUtils.SIZEOF_LONG*(((LongBuffer)buf).arrayOffset() + pos)); + } + + throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); + } +} diff --git a/src/net/java/games/gluegen/runtime/ProcAddressHelper.java b/src/classes/com/sun/gluegen/runtime/ProcAddressHelper.java index f98ae0c2b..4d40fd487 100644 --- a/src/net/java/games/gluegen/runtime/ProcAddressHelper.java +++ b/src/classes/com/sun/gluegen/runtime/ProcAddressHelper.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.runtime; +package com.sun.gluegen.runtime; /** Contains constants used in glue code generation. */ diff --git a/src/net/java/games/gluegen/runtime/StructAccessor.java b/src/classes/com/sun/gluegen/runtime/StructAccessor.java index 581eb7202..5a0fa5d25 100644 --- a/src/net/java/games/gluegen/runtime/StructAccessor.java +++ b/src/classes/com/sun/gluegen/runtime/StructAccessor.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.runtime; +package com.sun.gluegen.runtime; import java.nio.*; diff --git a/src/net/java/games/cg/CgException.java b/src/classes/com/sun/opengl/cg/CgException.java index 341ba3dbf..3380bb540 100644 --- a/src/net/java/games/cg/CgException.java +++ b/src/classes/com/sun/opengl/cg/CgException.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.cg; +package com.sun.opengl.cg; /** * A generic exception for errors that occur throughout the NVidia Cg diff --git a/src/net/java/games/jogl/impl/Debug.java b/src/classes/com/sun/opengl/impl/Debug.java index 164c5afbd..8d25db304 100755..100644 --- a/src/net/java/games/jogl/impl/Debug.java +++ b/src/classes/com/sun/opengl/impl/Debug.java @@ -37,10 +37,10 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; import java.security.*; -import net.java.games.jogl.Version; +import com.sun.opengl.utils.Version; /** Helper routines for logging and debugging. */ diff --git a/src/net/java/games/jogl/impl/FunctionAvailabilityCache.java b/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java index be5e26067..754e1d918 100644 --- a/src/net/java/games/jogl/impl/FunctionAvailabilityCache.java +++ b/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java @@ -37,9 +37,9 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; -import net.java.games.jogl.*; +import javax.media.opengl.*; import java.util.*; import java.awt.Canvas; import java.awt.Graphics; @@ -54,7 +54,7 @@ import java.lang.reflect.*; public final class FunctionAvailabilityCache { private static final boolean DEBUG = Debug.debug("FunctionAvailabilityCache"); - FunctionAvailabilityCache(GLContext context) + FunctionAvailabilityCache(GLContextImpl context) { this.context = context; } @@ -128,6 +128,28 @@ public final class FunctionAvailabilityCache { } } + // Put GL version strings in the table as well + Version version = new Version(gl.glGetString(GL.GL_VERSION)); + int major = version.getMajor(); + int minor = version.getMinor(); + // FIXME: this needs to be adjusted when the major and minor + // revs change beyond the known ones + switch (major) { + default: + if (major < 2) + break; + case 2: availableExtensionCache.add("GL_VERSION_2_0"); minor = 5; + case 1: + switch (minor) { + case 5: availableExtensionCache.add("GL_VERSION_1_5"); + case 4: availableExtensionCache.add("GL_VERSION_1_4"); + case 3: availableExtensionCache.add("GL_VERSION_1_3"); + case 2: availableExtensionCache.add("GL_VERSION_1_2"); + case 1: availableExtensionCache.add("GL_VERSION_1_1"); + case 0: availableExtensionCache.add("GL_VERSION_1_0"); + } + } + // put a dummy var in here so that the cache is no longer empty even if // no extensions are in the GL_EXTENSIONS string availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>"); @@ -243,7 +265,7 @@ public final class FunctionAvailabilityCache { private HashMap availabilityCache = new HashMap(50); private HashSet availableExtensionCache = new HashSet(50); - private GLContext context; + private GLContextImpl context; /** * A class for storing and comparing revision version numbers. @@ -309,6 +331,14 @@ public final class FunctionAvailabilityCache { return 0; // they are equal } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } } // end class Version } diff --git a/src/classes/com/sun/opengl/impl/GLContextImpl.java b/src/classes/com/sun/opengl/impl/GLContextImpl.java new file mode 100644 index 000000000..f2dfa216b --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLContextImpl.java @@ -0,0 +1,270 @@ +/* + * 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. + */ + +package com.sun.opengl.impl; + +import java.awt.Component; +import java.nio.*; + +import javax.media.opengl.*; +import com.sun.gluegen.runtime.*; + +public abstract class GLContextImpl extends GLContext { + protected GLContextLock lock = new GLContextLock(); + protected static final boolean DEBUG = Debug.debug("GLContextImpl"); + protected static final boolean VERBOSE = Debug.verbose(); + protected static final boolean NO_FREE = Debug.isPropertyDefined("jogl.GLContext.nofree"); + + // Cache of the functions that are available to be called at the current + // moment in time + protected FunctionAvailabilityCache functionAvailability; + // Table that holds the addresses of the native C-language entry points for + // OpenGL functions. + private GLProcAddressTable glProcAddressTable; + + protected GL gl; + public GLContextImpl(GLContext shareWith) { + setGL(createGL()); + functionAvailability = new FunctionAvailabilityCache(this); + if (shareWith != null) { + GLContextShareSet.registerSharing(this, shareWith); + } + } + + public int makeCurrent() throws GLException { + lock.lock(); + int res = 0; + try { + res = makeCurrentImpl(); + } catch (GLException e) { + lock.unlock(); + throw(e); + } + if (res == CONTEXT_NOT_CURRENT) { + lock.unlock(); + } else { + setCurrent(this); + } + return res; + } + + protected abstract int makeCurrentImpl() throws GLException; + + public void release() throws GLException { + if (!lock.isHeld()) { + throw new GLException("Context not current on current thread"); + } + setCurrent(null); + try { + releaseImpl(); + } finally { + lock.unlock(); + } + } + + protected abstract void releaseImpl() throws GLException; + + public void destroy() { + if (lock.isHeld()) { + throw new GLException("Can not destroy context while it is current"); + } + // Should we check the lock state? It should not be current on any + // thread. + destroyImpl(); + } + + protected abstract void destroyImpl() throws GLException; + + public boolean isSynchronized() { + return !lock.getFailFastMode(); + } + + public void setSynchronized(boolean isSynchronized) { + lock.setFailFastMode(!isSynchronized); + } + + public GL getGL() { + return gl; + } + + public void setGL(GL gl) { + this.gl = gl; + } + + public abstract Object getPlatformGLExtensions(); + + //---------------------------------------------------------------------- + // Helpers for various context implementations + // + + /** Create the GL for this context. */ + protected GL createGL() { + return new GLImpl(this); + } + + public GLProcAddressTable getGLProcAddressTable() { + if (glProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + glProcAddressTable = new GLProcAddressTable(); + } + return glProcAddressTable; + } + + /** + * Pbuffer support; given that this is a GLContext associated with a + * pbuffer, binds this pbuffer to its texture target. + */ + public abstract void bindPbufferToTexture(); + + /** + * Pbuffer support; given that this is a GLContext associated with a + * pbuffer, releases this pbuffer from its texture target. + */ + public abstract void releasePbufferFromTexture(); + + public abstract ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3); + + /* + * Sets the swap interval for onscreen OpenGL contexts. Has no + * effect for offscreen contexts. + */ + public void setSwapInterval(final int interval) { + } + + /** Maps the given "platform-independent" function name to a real function + name. Currently this is only used to map "glAllocateMemoryNV" and + associated routines to wglAllocateMemoryNV / glXAllocateMemoryNV. */ + protected abstract String mapToRealGLFunctionName(String glFunctionName); + + /** Maps the given "platform-independent" extension name to a real + function name. Currently this is only used to map + "GL_ARB_pbuffer" and "GL_ARB_pixel_format" to "WGL_ARB_pbuffer" + and "WGL_ARB_pixel_format" (not yet mapped to X11). */ + protected abstract String mapToRealGLExtensionName(String glExtensionName); + + /** Returns a non-null (but possibly empty) string containing the + space-separated list of available platform-dependent (e.g., WGL, + GLX) extensions. Can only be called while this context is + current. */ + public abstract String getPlatformExtensionsString(); + + /** Helper routine which resets a ProcAddressTable generated by the + GLEmitter by looking up anew all of its function pointers. */ + protected void resetProcAddressTable(Object table) { + GLDrawableFactoryImpl.getFactoryImpl().resetProcAddressTable(table); + } + + /** Indicates whether the underlying OpenGL context has been + created. This is used to manage sharing of display lists and + textures between contexts. */ + public abstract boolean isCreated(); + + /** + * Resets the cache of which GL functions are available for calling through this + * context. See {@link #isFunctionAvailable(String)} for more information on + * the definition of "available". + */ + protected void resetGLFunctionAvailability() { + // In order to be able to allow the user to uniformly install the + // debug and trace pipelines in their GLEventListener.init() + // method (for both GLCanvas and GLJPanel), we need to reset the + // actual GL object in the GLDrawable as well + setGL(createGL()); + + functionAvailability.flush(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing OpenGL extension address table for " + this); + } + resetProcAddressTable(getGLProcAddressTable()); + } + + /** + * Returns true if the specified OpenGL core- or extension-function can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isFunctionAvailable(String)} for more details. + * + * @param glFunctionName the name of the OpenGL function (e.g., use + * "glPolygonOffsetEXT" to check if the {@link + * javax.media.opengl.GL#glPolygonOffsetEXT(float,float)} is available). + */ + protected boolean isFunctionAvailable(String glFunctionName) { + return functionAvailability.isFunctionAvailable(mapToRealGLFunctionName(glFunctionName)); + } + + /** + * Returns true if the specified OpenGL extension can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isExtensionAvailable(String)} for more details. + * + * @param glExtensionName the name of the OpenGL extension (e.g., + * "GL_VERTEX_PROGRAM_ARB"). + */ + public boolean isExtensionAvailable(String glExtensionName) { + return functionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); + } + + /** Indicates which floating-point pbuffer implementation is in + use. Returns one of GLPbuffer.APPLE_FLOAT, GLPbuffer.ATI_FLOAT, + or GLPbuffer.NV_FLOAT. */ + public int getFloatingPointMode() throws GLException { + throw new GLException("Not supported on non-pbuffer contexts"); + } + + /** On some platforms the mismatch between OpenGL's coordinate + system (origin at bottom left) and the window system's + coordinate system (origin at top left) necessitates a vertical + flip of pixels read from offscreen contexts. */ + public abstract boolean offscreenImageNeedsVerticalFlip(); + + /** Only called for offscreen contexts; needed by glReadPixels */ + public abstract int getOffscreenContextPixelDataType(); + + protected static String getThreadName() { + return Thread.currentThread().getName(); + } + + public static String toHexString(long hex) { + return "0x" + Long.toHexString(hex); + } +} diff --git a/src/classes/com/sun/opengl/impl/GLContextLock.java b/src/classes/com/sun/opengl/impl/GLContextLock.java new file mode 100644 index 000000000..7668678b7 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLContextLock.java @@ -0,0 +1,118 @@ +/* + * 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. + */ + +package com.sun.opengl.impl; + +import javax.media.opengl.*; + +/** Implements the makeCurrent / release locking behavior of the + GLContext class. When "fail fast mode" is enabled, attempts to + lock the same GLContextLock on more than one thread cause + GLException to be raised. This lock is not recursive. Attempts to + lock it more than once on a given thread will cause GLException to + be raised. */ + +public class GLContextLock { + private Object lock = new Object(); + private Thread owner; + private boolean failFastMode = true; + + /** Locks this GLContextLock on the current thread. If fail fast + mode is enabled and the GLContextLock is already owned by + another thread, throws GLException. */ + public void lock() throws GLException { + synchronized(lock) { + Thread current = Thread.currentThread(); + if (owner == null) { + owner = current; + } else if (owner != current) { + while (owner != null) { + if (failFastMode) { + throw new GLException("Attempt to make context current on thread " + current + + " which is already current on thread " + owner); + } else { + try { + lock.wait(); + } catch (InterruptedException e) { + throw new GLException(e); + } + } + } + owner = current; + } else { + throw new GLException("Attempt to make the same context current twice on thread " + current); + } + } + } + + /** Unlocks this GLContextLock. */ + public void unlock() throws GLException { + synchronized (lock) { + Thread current = Thread.currentThread(); + if (owner == current) { + owner = null; + lock.notifyAll(); + } else { + if (owner != null) { + throw new GLException("Attempt by thread " + current + + " to release context owned by thread " + owner); + } else { + throw new GLException("Attempt by thread " + current + + " to release unowned context"); + } + } + } + } + + /** Indicates whether this lock is held by the current thread. */ + public boolean isHeld() { + synchronized(lock) { + Thread current = Thread.currentThread(); + return (owner == current); + } + } + + public void setFailFastMode(boolean onOrOff) { + failFastMode = onOrOff; + } + + public boolean getFailFastMode() { + return failFastMode; + } +} diff --git a/src/net/java/games/jogl/impl/GLContextShareSet.java b/src/classes/com/sun/opengl/impl/GLContextShareSet.java index 60c6b7d59..a797ae69c 100644 --- a/src/net/java/games/jogl/impl/GLContextShareSet.java +++ b/src/classes/com/sun/opengl/impl/GLContextShareSet.java @@ -37,10 +37,11 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; import java.lang.ref.*; import java.util.*; +import javax.media.opengl.*; /** Provides a mechanism by which OpenGL contexts can share textures and display lists in the face of multithreading and asynchronous @@ -61,7 +62,8 @@ public class GLContextShareSet { public void add(GLContext ctx) { if (allShares.put(ctx, dummyValue) == null) { - if (ctx.isCreated()) { + // FIXME: downcast to GLContextImpl undesirable + if (((GLContextImpl) ctx).isCreated()) { createdShares.put(ctx, dummyValue); } else { destroyedShares.put(ctx, dummyValue); diff --git a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java new file mode 100644 index 000000000..37dea5c15 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java @@ -0,0 +1,104 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl; + +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import com.sun.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX +import javax.media.opengl.*; + +/** Extends GLDrawableFactory with a few methods for handling + typically software-accelerated offscreen rendering (Device + Independent Bitmaps on Windows, pixmaps on X11). Direct access to + these GLDrawables is not supplied directly to end users, though + they may be instantiated by the GLJPanel implementation. */ +public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { + /** Creates a (typically software-accelerated) offscreen GLDrawable + used to implement the fallback rendering path of the + GLJPanel. */ + public abstract GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser); + + /** Helper routine which resets a ProcAddressTable generated by the + GLEmitter by looking up anew all of its function pointers. */ + public void resetProcAddressTable(Object table) { + Class tableClass = table.getClass(); + java.lang.reflect.Field[] fields = tableClass.getDeclaredFields(); + + for (int i = 0; i < fields.length; ++i) { + String addressFieldName = fields[i].getName(); + if (!addressFieldName.startsWith(ProcAddressHelper.PROCADDRESS_VAR_PREFIX)) { + // not a proc address variable + continue; + } + int startOfMethodName = ProcAddressHelper.PROCADDRESS_VAR_PREFIX.length(); + String glFuncName = addressFieldName.substring(startOfMethodName); + try { + java.lang.reflect.Field addressField = tableClass.getDeclaredField(addressFieldName); + assert(addressField.getType() == Long.TYPE); + long newProcAddress = dynamicLookupFunction(glFuncName); + // set the current value of the proc address variable in the table object + addressField.setLong(table, newProcAddress); + } catch (Exception e) { + throw new GLException("Cannot get GL proc address for method \"" + + glFuncName + "\": Couldn't set value of field \"" + addressFieldName + + "\" in class " + tableClass.getName(), e); + } + } + } + + /** Dynamically looks up the given function. */ + public abstract long dynamicLookupFunction(String glFuncName); + + /** Locks the AWT for the purposes of Java2D/JOGL integration. This + * is not necessary on some platforms. + */ + public abstract void lockAWTForJava2D(); + + /** Unlocks the AWT for the purposes of Java2D/JOGL integration. + * This is not necessary on some platforms. + */ + public abstract void unlockAWTForJava2D(); + + public static GLDrawableFactoryImpl getFactoryImpl() { + return (GLDrawableFactoryImpl) getFactory(); + } +} diff --git a/src/classes/com/sun/opengl/impl/GLDrawableHelper.java b/src/classes/com/sun/opengl/impl/GLDrawableHelper.java new file mode 100644 index 000000000..014e35f7e --- /dev/null +++ b/src/classes/com/sun/opengl/impl/GLDrawableHelper.java @@ -0,0 +1,150 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl; + +import java.util.*; +import javax.media.opengl.*; + +/** Encapsulates the implementation of most of the GLAutoDrawable's + methods to be able to share it between GLCanvas and GLJPanel. */ + +public class GLDrawableHelper { + private volatile List listeners = new ArrayList(); + private static final boolean DEBUG = Debug.debug("GLDrawableHelper"); + private static final boolean VERBOSE = Debug.verbose(); + private boolean autoSwapBufferMode = true; + + public GLDrawableHelper() { + } + + public synchronized void addGLEventListener(GLEventListener listener) { + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.add(listener); + listeners = newListeners; + } + + public synchronized void removeGLEventListener(GLEventListener listener) { + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.remove(listener); + listeners = newListeners; + } + + public void init(GLAutoDrawable drawable) { + for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { + ((GLEventListener) iter.next()).init(drawable); + } + } + + public void display(GLAutoDrawable drawable) { + for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { + ((GLEventListener) iter.next()).display(drawable); + } + } + + public void reshape(GLAutoDrawable drawable, + int x, int y, int width, int height) { + for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { + ((GLEventListener) iter.next()).reshape(drawable, x, y, width, height); + } + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + autoSwapBufferMode = onOrOff; + } + + public boolean getAutoSwapBufferMode() { + return autoSwapBufferMode; + } + + private static final ThreadLocal perThreadInitAction = new ThreadLocal(); + /** Principal helper method which runs a Runnable with the context + made current. This could have been made part of GLContext, but a + desired goal is to be able to implement the GLCanvas in terms of + the GLContext's public APIs, and putting it into a separate + class helps ensure that we don't inadvertently use private + methods of the GLContext or its implementing classes. */ + public void invokeGL(GLDrawable drawable, + GLContext context, + Runnable runnable, + Runnable initAction) { + // Support for recursive makeCurrent() calls as well as calling + // other drawables' display() methods from within another one's + GLContext lastContext = GLContext.getCurrent(); + Runnable lastInitAction = (Runnable) perThreadInitAction.get(); + if (lastContext != null) { + lastContext.release(); + } + + int res = 0; + try { + res = context.makeCurrent(); + if (res != GLContext.CONTEXT_NOT_CURRENT) { + if (res == GLContext.CONTEXT_CURRENT_NEW) { + if (DEBUG) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction"); + } + initAction.run(); + } + if (DEBUG && VERBOSE) { + System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running runnable"); + } + runnable.run(); + if (autoSwapBufferMode) { + if (drawable != null) { + drawable.swapBuffers(); + } + } + } + } finally { + try { + if (res != GLContext.CONTEXT_NOT_CURRENT) { + context.release(); + } + } catch (Exception e) { + } + if (lastContext != null) { + int res2 = lastContext.makeCurrent(); + if (res2 == GLContext.CONTEXT_CURRENT_NEW) { + lastInitAction.run(); + } + } + } + } +} diff --git a/src/net/java/games/jogl/impl/GLContextInitActionPair.java b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java index 379dda3ee..f93ed9663 100755..100644 --- a/src/net/java/games/jogl/impl/GLContextInitActionPair.java +++ b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java @@ -37,22 +37,16 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; -public class GLContextInitActionPair { - private GLContext ctx; - private Runnable initAction; +import javax.media.opengl.*; - public GLContextInitActionPair(GLContext ctx, Runnable initAction) { - this.ctx = ctx; - this.initAction = initAction; - } +public abstract class GLDrawableImpl implements GLDrawable { + /** For offscreen GLDrawables (pbuffers and "pixmap" drawables), + indicates that native resources should be reclaimed. */ + public abstract void destroy() throws GLException; - public GLContext getContext() { - return ctx; - } - - public Runnable getInitAction() { - return initAction; + public static String toHexString(long hex) { + return GLContextImpl.toHexString(hex); } } diff --git a/src/net/java/games/jogl/impl/GLPbufferImpl.java b/src/classes/com/sun/opengl/impl/GLPbufferImpl.java index 7b17c3010..196ea7223 100644 --- a/src/net/java/games/jogl/impl/GLPbufferImpl.java +++ b/src/classes/com/sun/opengl/impl/GLPbufferImpl.java @@ -37,14 +37,14 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.*; import java.beans.PropertyChangeListener; -import net.java.games.jogl.*; +import javax.media.opengl.*; /** Platform-independent class exposing pbuffer functionality to applications. This class is not exposed in the public API as it @@ -52,20 +52,23 @@ import net.java.games.jogl.*; interface so can be interacted with via its display() method. */ public class GLPbufferImpl implements GLPbuffer { - // GLPbufferContext - private GLContext context; + private GLDrawableImpl pbufferDrawable; + private GLContextImpl context; private GLDrawableHelper drawableHelper = new GLDrawableHelper(); - private boolean isInitialized=false; private int floatMode; - public GLPbufferImpl(GLContext context) { - this.context = context; + public GLPbufferImpl(GLDrawableImpl pbufferDrawable, + GLContext parentContext) { + this.pbufferDrawable = pbufferDrawable; + context = (GLContextImpl) pbufferDrawable.createContext(parentContext); + context.setSynchronized(true); } - public void display() { - maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction, - displayAction, - false); + public GLContext createContext(GLContext shareWith) { + return pbufferDrawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { } public void setSize(int width, int height) { @@ -73,17 +76,22 @@ public class GLPbufferImpl implements GLPbuffer { throw new GLException("Not yet implemented"); } - public void setSize(Dimension d) { - setSize(d.width, d.height); + public int getWidth() { + return pbufferDrawable.getWidth(); } - public Dimension getSize() { - return getSize(null); + public int getHeight() { + return pbufferDrawable.getHeight(); } - public Dimension getSize(Dimension d) { - // FIXME - throw new GLException("Not yet implemented"); + public void display() { + maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction, + displayAction, + false); + } + + public void repaint() { + display(); } public void addGLEventListener(GLEventListener listener) { @@ -94,64 +102,34 @@ public class GLPbufferImpl implements GLPbuffer { drawableHelper.removeGLEventListener(listener); } - public GL getGL() { - return context.getGL(); - } - - public void setGL(GL gl) { - context.setGL(gl); - } - - public GLU getGLU() { - return context.getGLU(); - } - - public void setGLU(GLU glu) { - context.setGLU(glu); - } - - void willSetRenderingThread() { - // Not supported for pbuffers - } - - public void setRenderingThread(Thread currentThreadOrNull) throws GLException { - // Not supported for pbuffers + public GLContext getContext() { + return context; } - public Thread getRenderingThread() { - // Not supported for pbuffers - return null; + public GLDrawable getDrawable() { + return pbufferDrawable; } - public void setNoAutoRedrawMode(boolean noAutoRedraws) { + public GL getGL() { + return getContext().getGL(); } - public boolean getNoAutoRedrawMode() { - return false; + public void setGL(GL gl) { + getContext().setGL(gl); } public void setAutoSwapBufferMode(boolean onOrOff) { - context.setAutoSwapBufferMode(onOrOff); + drawableHelper.setAutoSwapBufferMode(onOrOff); } public boolean getAutoSwapBufferMode() { - return context.getAutoSwapBufferMode(); + return drawableHelper.getAutoSwapBufferMode(); } public void swapBuffers() { maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction, false); } - public boolean canCreateOffscreenDrawable() { - return false; - } - - public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - public void bindTexture() { // Doesn't make much sense to try to do this on the event dispatch // thread given that it has to be called while the context is current @@ -164,10 +142,6 @@ public class GLPbufferImpl implements GLPbuffer { context.releasePbufferFromTexture(); } - public GLContext getContext() { - return context; - } - //---------------------------------------------------------------------- // No-ops for ComponentEvents // @@ -197,15 +171,9 @@ public class GLPbufferImpl implements GLPbuffer { public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {} - /** Queries initialization status of this pBuffer. - * @return true if initialized - * */ - public boolean isInitialized(){ - return isInitialized; - } - public void destroy() { context.destroy(); + pbufferDrawable.destroy(); } public int getFloatingPointMode() { @@ -222,30 +190,16 @@ public class GLPbufferImpl implements GLPbuffer { private void maybeDoSingleThreadedWorkaround(Runnable eventDispatchThreadAction, Runnable invokeGLAction, boolean isReshape) { - if (SingleThreadedWorkaround.doWorkaround() && !EventQueue.isDispatchThread()) { - try { - // Reshape events must not block on the event queue due to the - // possibility of deadlocks during initial component creation. - // This solution is not optimal, because it changes the - // semantics of reshape() to have some of the processing being - // done asynchronously, but at least it preserves the - // semantics of the single-threaded workaround. - if (!isReshape) { - EventQueue.invokeAndWait(eventDispatchThreadAction); - } else { - EventQueue.invokeLater(eventDispatchThreadAction); - } - } catch (Exception e) { - throw new GLException(e); - } + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(eventDispatchThreadAction); } else { - context.invokeGL(invokeGLAction, isReshape, initAction); + drawableHelper.invokeGL(pbufferDrawable, context, invokeGLAction, initAction); } } class InitAction implements Runnable { public void run() { - isInitialized=true; floatMode = context.getFloatingPointMode(); drawableHelper.init(GLPbufferImpl.this); } @@ -260,8 +214,9 @@ public class GLPbufferImpl implements GLPbuffer { private DisplayAction displayAction = new DisplayAction(); class SwapBuffersAction implements Runnable { + // FIXME: currently a no-op public void run() { - context.swapBuffers(); + pbufferDrawable.swapBuffers(); } } private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); @@ -271,14 +226,14 @@ public class GLPbufferImpl implements GLPbuffer { // being resized on the AWT event dispatch thread class DisplayOnEventDispatchThreadAction implements Runnable { public void run() { - context.invokeGL(displayAction, false, initAction); + drawableHelper.invokeGL(pbufferDrawable, context, displayAction, initAction); } } private DisplayOnEventDispatchThreadAction displayOnEventDispatchThreadAction = new DisplayOnEventDispatchThreadAction(); class SwapBuffersOnEventDispatchThreadAction implements Runnable { public void run() { - context.invokeGL(swapBuffersAction, false, initAction); + drawableHelper.invokeGL(pbufferDrawable, context, swapBuffersAction, initAction); } } private SwapBuffersOnEventDispatchThreadAction swapBuffersOnEventDispatchThreadAction = diff --git a/src/net/java/games/jogl/impl/GLUquadricImpl.java b/src/classes/com/sun/opengl/impl/GLUquadricImpl.java index dfc167dcb..b56f33368 100755..100644 --- a/src/net/java/games/jogl/impl/GLUquadricImpl.java +++ b/src/classes/com/sun/opengl/impl/GLUquadricImpl.java @@ -103,9 +103,10 @@ * facility. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; /** * GLUquadricImpl.java @@ -116,13 +117,13 @@ import net.java.games.jogl.*; * @author Kenneth Russell */ -class GLUquadricImpl implements GLUquadric { +public class GLUquadricImpl implements GLUquadric { private int drawStyle; private int orientation; private boolean textureFlag; private int normals; - GLUquadricImpl() { + public GLUquadricImpl() { drawStyle = GLU.GLU_FILL; orientation = GLU.GLU_OUTSIDE; textureFlag = false; @@ -147,7 +148,7 @@ class GLUquadricImpl implements GLUquadric { * * @param drawStyle The drawStyle to set */ - void setDrawStyle(int drawStyle) { + public void setDrawStyle(int drawStyle) { this.drawStyle = drawStyle; } @@ -164,7 +165,7 @@ class GLUquadricImpl implements GLUquadric { * * @param normals The normals to set */ - void setNormals(int normals) { + public void setNormals(int normals) { this.normals = normals; } @@ -181,7 +182,7 @@ class GLUquadricImpl implements GLUquadric { * * @param orientation The orientation to set */ - void setOrientation(int orientation) { + public void setOrientation(int orientation) { this.orientation = orientation; } @@ -196,7 +197,7 @@ class GLUquadricImpl implements GLUquadric { * * @param textureFlag The textureFlag to set */ - void setTextureFlag(boolean textureFlag) { + public void setTextureFlag(boolean textureFlag) { this.textureFlag = textureFlag; } @@ -204,7 +205,7 @@ class GLUquadricImpl implements GLUquadric { * Returns the drawStyle. * @return int */ - int getDrawStyle() { + public int getDrawStyle() { return drawStyle; } @@ -212,7 +213,7 @@ class GLUquadricImpl implements GLUquadric { * Returns the normals. * @return int */ - int getNormals() { + public int getNormals() { return normals; } @@ -220,7 +221,7 @@ class GLUquadricImpl implements GLUquadric { * Returns the orientation. * @return int */ - int getOrientation() { + public int getOrientation() { return orientation; } @@ -228,7 +229,7 @@ class GLUquadricImpl implements GLUquadric { * Returns the textureFlag. * @return boolean */ - boolean getTextureFlag() { + public boolean getTextureFlag() { return textureFlag; } @@ -257,7 +258,7 @@ class GLUquadricImpl implements GLUquadric { * @param slices Specifies the number of subdivisions around the z axis. * @param stacks Specifies the number of subdivisions along the z axis. */ - void drawCylinder(GL gl, float baseRadius, float topRadius, float height, int slices, int stacks) { + public void drawCylinder(GL gl, float baseRadius, float topRadius, float height, int slices, int stacks) { float da, r, dr, dz; float x, y, z, nz, nsign; diff --git a/src/net/java/games/jogl/impl/InternalBufferUtils.java b/src/classes/com/sun/opengl/impl/InternalBufferUtils.java index 7ae5efb0e..89639c493 100644 --- a/src/net/java/games/jogl/impl/InternalBufferUtils.java +++ b/src/classes/com/sun/opengl/impl/InternalBufferUtils.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/JAWT_PlatformInfo.java b/src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java index 55eb43d42..ca101eff9 100644 --- a/src/net/java/games/jogl/impl/JAWT_PlatformInfo.java +++ b/src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; /** Marker class for all window system-specific JAWT data structures. */ diff --git a/src/classes/com/sun/opengl/impl/Java2D.java b/src/classes/com/sun/opengl/impl/Java2D.java new file mode 100755 index 000000000..7d666e138 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/Java2D.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2003-2005 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl; + +import java.awt.*; +import java.lang.reflect.*; +import java.security.*; + +import javax.media.opengl.*; + +/** Defines integration with the Java2D OpenGL pipeline. This + integration is only supported in 1.6 and is highly experimental. */ + +public class Java2D { + private static boolean DEBUG = Debug.debug("Java2D"); + private static boolean VERBOSE = Debug.verbose(); + private static boolean isOGLPipelineActive; + private static Method invokeWithOGLContextCurrentMethod; + private static Method isQueueFlusherThreadMethod; + private static Method getOGLViewportMethod; + private static Method getOGLScissorBoxMethod; + private static Method getOGLSurfaceIdentifierMethod; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + if (DEBUG && VERBOSE) { + System.err.println("Checking for Java2D/OpenGL support"); + } + // Figure out whether the default graphics configuration is an + // OpenGL graphics configuration + GraphicsConfiguration cfg = + GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice(). + getDefaultConfiguration(); + String name = cfg.getClass().getName(); + if (DEBUG && VERBOSE) { + System.err.println("Java2D support: default GraphicsConfiguration = " + name); + } + isOGLPipelineActive = (name.startsWith("sun.java2d.opengl")); + + if (isOGLPipelineActive) { + try { + // Try to get methods we need to integrate + Class utils = Class.forName("sun.java2d.opengl.OGLUtilities"); + invokeWithOGLContextCurrentMethod = utils.getDeclaredMethod("invokeWithOGLContextCurrent", + new Class[] { + Graphics.class, + Runnable.class + }); + invokeWithOGLContextCurrentMethod.setAccessible(true); + + isQueueFlusherThreadMethod = utils.getDeclaredMethod("isQueueFlusherThread", + new Class[] {}); + isQueueFlusherThreadMethod.setAccessible(true); + + getOGLViewportMethod = utils.getDeclaredMethod("getOGLViewport", + new Class[] { + Graphics.class, + Integer.TYPE, + Integer.TYPE + }); + getOGLViewportMethod.setAccessible(true); + + getOGLScissorBoxMethod = utils.getDeclaredMethod("getOGLScissorBox", + new Class[] { + Graphics.class + }); + getOGLScissorBoxMethod.setAccessible(true); + + getOGLSurfaceIdentifierMethod = utils.getDeclaredMethod("getOGLSurfaceIdentifier", + new Class[] { + Graphics.class + }); + getOGLSurfaceIdentifierMethod.setAccessible(true); + } catch (Exception e) { + if (DEBUG && VERBOSE) { + e.printStackTrace(); + } + isOGLPipelineActive = false; + } + } + + if (DEBUG) { + System.err.println("JOGL/Java2D integration " + (isOGLPipelineActive ? "enabled" : "disabled")); + } + return null; + } + }); + } + + public static boolean isOGLPipelineActive() { + return isOGLPipelineActive; + } + + public static boolean isQueueFlusherThread() { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + + try { + return ((Boolean) isQueueFlusherThreadMethod.invoke(null, new Object[] {})).booleanValue(); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + /** Makes current the OpenGL context associated with the passed + Graphics object and runs the given Runnable on the Queue + Flushing Thread in one atomic action. */ + public static void invokeWithOGLContextCurrent(Graphics g, Runnable r) throws GLException { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + + try { + GLDrawableFactoryImpl.getFactoryImpl().lockAWTForJava2D(); + try { + invokeWithOGLContextCurrentMethod.invoke(null, new Object[] {g, r}); + } finally { + GLDrawableFactoryImpl.getFactoryImpl().unlockAWTForJava2D(); + } + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + public static Rectangle getOGLViewport(Graphics g, + int componentWidth, + int componentHeight) { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + + try { + return (Rectangle) getOGLViewportMethod.invoke(null, new Object[] {g, + new Integer(componentWidth), + new Integer(componentHeight)}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + public static Rectangle getOGLScissorBox(Graphics g) { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + + try { + return (Rectangle) getOGLScissorBoxMethod.invoke(null, new Object[] {g}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } + + + public static Object getOGLSurfaceIdentifier(Graphics g) { + if (!isOGLPipelineActive()) { + throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)"); + } + + try { + return getOGLSurfaceIdentifierMethod.invoke(null, new Object[] {g}); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (Exception e) { + throw (InternalError) new InternalError().initCause(e); + } + } +} diff --git a/src/net/java/games/jogl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java index 54d37f6ce..fa535c7d5 100644 --- a/src/net/java/games/jogl/impl/NativeLibLoader.java +++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java @@ -37,8 +37,9 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; +import java.awt.Toolkit; import java.security.*; public class NativeLibLoader { @@ -60,6 +61,10 @@ public class NativeLibLoader { boolean isOSX = System.getProperty("os.name").equals("Mac OS X"); if (!isOSX) { try { + // On X11 systems, toolkit must be loaded before + // trying to resolve JAWT in order for libmawt.so to + // be found properly + Toolkit.getDefaultToolkit(); System.loadLibrary("jawt"); } catch (UnsatisfiedLinkError e) { // Accessibility technologies load JAWT themselves; safe to continue diff --git a/src/net/java/games/jogl/impl/Project.java b/src/classes/com/sun/opengl/impl/Project.java index 90770309f..655434319 100755 --- a/src/net/java/games/jogl/impl/Project.java +++ b/src/classes/com/sun/opengl/impl/Project.java @@ -102,12 +102,12 @@ * in the design, construction, operation or maintenance of any nuclear * facility. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; -import net.java.games.jogl.*; -import net.java.games.jogl.util.*; +import java.nio.*; -import java.nio.DoubleBuffer; +import javax.media.opengl.*; +import com.sun.opengl.utils.*; /** * Project.java @@ -118,7 +118,7 @@ import java.nio.DoubleBuffer; * @author Erik Duijs * @author Kenneth Russell */ -class Project { +public class Project { private static final double[] IDENTITY_MATRIX = new double[] { 1.0, 0.0, 0.0, 0.0, @@ -159,14 +159,13 @@ class Project { * @param in * @param out */ - private void __gluMultMatrixVecd(double[] matrix, double[] in, double[] out) { + private void __gluMultMatrixVecd(double[] matrix, int matrix_offset, double[] in, double[] out) { for (int i = 0; i < 4; i++) { out[i] = - in[0] * matrix[0*4+i] + - in[1] * matrix[1*4+i] + - in[2] * matrix[2*4+i] + - in[3] * matrix[3*4+i]; - + in[0] * matrix[0*4+i+matrix_offset] + + in[1] * matrix[1*4+i+matrix_offset] + + in[2] * matrix[2*4+i+matrix_offset] + + in[3] * matrix[3*4+i+matrix_offset]; } } @@ -245,14 +244,14 @@ class Project { * @param b * @param r */ - private void __gluMultMatricesd(double[] a, double[] b, double[] r) { + private void __gluMultMatricesd(double[] a, int a_offset, double[] b, int b_offset, double[] r) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { r[i*4+j] = - a[i*4+0]*b[0*4+j] + - a[i*4+1]*b[1*4+j] + - a[i*4+2]*b[2*4+j] + - a[i*4+3]*b[3*4+j]; + a[i*4+0+a_offset]*b[0*4+j+b_offset] + + a[i*4+1+a_offset]*b[1*4+j+b_offset] + + a[i*4+2+a_offset]*b[2*4+j+b_offset] + + a[i*4+3+a_offset]*b[3*4+j+b_offset]; } } } @@ -414,9 +413,13 @@ class Project { double objy, double objz, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, - double[] win_pos) { + int viewport_offset, + double[] win_pos, + int win_pos_offset ) { double[] in = this.in; double[] out = this.out; @@ -426,8 +429,8 @@ class Project { in[2] = objz; in[3] = 1.0; - __gluMultMatrixVecd(modelMatrix, in, out); - __gluMultMatrixVecd(projMatrix, out, in); + __gluMultMatrixVecd(modelMatrix, modelMatrix_offset, in, out); + __gluMultMatrixVecd(projMatrix, projMatrix_offset, out, in); if (in[3] == 0.0) return false; @@ -440,9 +443,9 @@ class Project { in[2] = in[2] * in[3] + 0.5f; // Map x,y to viewport - win_pos[0] = in[0] * viewport[2] + viewport[0]; - win_pos[1] = in[1] * viewport[3] + viewport[1]; - win_pos[2] = in[2]; + win_pos[0+win_pos_offset] = in[0] * viewport[2+viewport_offset] + viewport[0+viewport_offset]; + win_pos[1+win_pos_offset] = in[1] * viewport[3+viewport_offset] + viewport[1+viewport_offset]; + win_pos[2+win_pos_offset] = in[2]; return true; } @@ -464,13 +467,17 @@ class Project { double winy, double winz, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, - double[] obj_pos) { + int viewport_offset, + double[] obj_pos, + int obj_pos_offset) { double[] in = this.in; double[] out = this.out; - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, finalMatrix); if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return false; @@ -481,24 +488,24 @@ class Project { in[3] = 1.0; // Map x and y from window coordinates - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; // Map to range -1 to 1 in[0] = in[0] * 2 - 1; in[1] = in[1] * 2 - 1; in[2] = in[2] * 2 - 1; - __gluMultMatrixVecd(finalMatrix, in, out); + __gluMultMatrixVecd(finalMatrix, 0, in, out); if (out[3] == 0.0) return false; out[3] = 1.0 / out[3]; - obj_pos[0] = out[0] * out[3]; - obj_pos[1] = out[1] * out[3]; - obj_pos[2] = out[2] * out[3]; + obj_pos[0+obj_pos_offset] = out[0] * out[3]; + obj_pos[1+obj_pos_offset] = out[1] * out[3]; + obj_pos[2+obj_pos_offset] = out[2] * out[3]; return true; } @@ -524,15 +531,19 @@ class Project { double winz, double clipw, double[] modelMatrix, + int modelMatrix_offset, double[] projMatrix, + int projMatrix_offset, int[] viewport, + int viewport_offset, double near, double far, - double[] obj_pos) { + double[] obj_pos, + int obj_pos_offset ) { double[] in = this.in; double[] out = this.out; - __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix); + __gluMultMatricesd(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, finalMatrix); if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return false; @@ -543,8 +554,8 @@ class Project { in[3] = clipw; // Map x and y from window coordinates - in[0] = (in[0] - viewport[0]) / viewport[2]; - in[1] = (in[1] - viewport[1]) / viewport[3]; + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; in[2] = (in[2] - near) / (far - near); // Map to range -1 to 1 @@ -552,15 +563,15 @@ class Project { in[1] = in[1] * 2 - 1; in[2] = in[2] * 2 - 1; - __gluMultMatrixVecd(finalMatrix, in, out); + __gluMultMatrixVecd(finalMatrix, 0, in, out); if (out[3] == 0.0) return false; - obj_pos[0] = out[0]; - obj_pos[1] = out[1]; - obj_pos[2] = out[2]; - obj_pos[3] = out[3]; + obj_pos[0+obj_pos_offset] = out[0]; + obj_pos[1+obj_pos_offset] = out[1]; + obj_pos[2+obj_pos_offset] = out[2]; + obj_pos[3+obj_pos_offset] = out[3]; return true; } @@ -578,15 +589,43 @@ class Project { double y, double deltaX, double deltaY, - int[] viewport) { + IntBuffer viewport) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + gl.glTranslated((viewport.get(2) - 2 * (x - viewport.get(0))) / deltaX, + (viewport.get(3) - 2 * (y - viewport.get(1))) / deltaY, + 0); + gl.glScaled(viewport.get(2) / deltaX, viewport.get(3) / deltaY, 1.0); + } + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + * @param viewport_offset + */ + public void gluPickMatrix(GL gl, + double x, + double y, + double deltaX, + double deltaY, + int[] viewport, + int viewport_offset) { if (deltaX <= 0 || deltaY <= 0) { return; } /* Translate and scale the picked region to the entire window */ - gl.glTranslated((viewport[2] - 2 * (x - viewport[0])) / deltaX, - (viewport[3] - 2 * (y - viewport[1])) / deltaY, + gl.glTranslated((viewport[2+viewport_offset] - 2 * (x - viewport[0+viewport_offset])) / deltaX, + (viewport[3+viewport_offset] - 2 * (y - viewport[1+viewport_offset])) / deltaY, 0); - gl.glScaled(viewport[2] / deltaX, viewport[3] / deltaY, 1.0); + gl.glScaled(viewport[2+viewport_offset] / deltaX, viewport[3+viewport_offset] / deltaY, 1.0); } } diff --git a/src/net/java/games/jogl/impl/Util.java b/src/classes/com/sun/opengl/impl/Util.java index 46bdfc79a..b4b501659 100755..100644 --- a/src/net/java/games/jogl/impl/Util.java +++ b/src/classes/com/sun/opengl/impl/Util.java @@ -66,10 +66,10 @@ * facility. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl; import java.nio.IntBuffer; -import net.java.games.jogl.*; +import javax.media.opengl.*; /** * Util.java @@ -236,7 +236,7 @@ class Util { * @return int */ protected int glGetIntegerv(GL gl, int what) { - gl.glGetIntegerv(what, scratch); + gl.glGetIntegerv(what, scratch, 0); return scratch[0]; } } diff --git a/src/net/java/games/jogl/impl/error/Error.java b/src/classes/com/sun/opengl/impl/error/Error.java index a9b4c48f1..b19fb4903 100644 --- a/src/net/java/games/jogl/impl/error/Error.java +++ b/src/classes/com/sun/opengl/impl/error/Error.java @@ -32,11 +32,10 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.error; +package com.sun.opengl.impl.error; -import net.java.games.jogl.GL; -import net.java.games.jogl.GLU; -import net.java.games.jogl.impl.GLUImpl; +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; /** * @@ -75,14 +74,14 @@ public class Error { if( errorCode == GL.GL_TABLE_TOO_LARGE ) { return( "table too large" ); } - if( (errorCode >= GLUImpl.GLU_INVALID_ENUM) && (errorCode <= GLUImpl.GLU_INVALID_OPERATION) ) { - return( gluErrorStrings[ errorCode - GLUImpl.GLU_INVALID_ENUM ] ); + if( (errorCode >= GLU.GLU_INVALID_ENUM) && (errorCode <= GLU.GLU_INVALID_OPERATION) ) { + return( gluErrorStrings[ errorCode - GLU.GLU_INVALID_ENUM ] ); } - if( (errorCode >= GLUImpl.GLU_NURBS_ERROR1) && (errorCode <= GLUImpl.GLU_NURBS_ERROR37) ) { - return( gluErrorStrings[ errorCode - (GLUImpl.GLU_NURBS_ERROR1 - 1) ] ); + if( (errorCode >= GLU.GLU_NURBS_ERROR1) && (errorCode <= GLU.GLU_NURBS_ERROR37) ) { + return( gluErrorStrings[ errorCode - (GLU.GLU_NURBS_ERROR1 - 1) ] ); } - if( (errorCode >= GLUImpl.GLU_TESS_ERROR1) && (errorCode <= GLUImpl.GLU_TESS_ERROR8) ) { - return( gluErrorStrings[ errorCode - (GLUImpl.GLU_TESS_ERROR1 - 1) ] ); + if( (errorCode >= GLU.GLU_TESS_ERROR1) && (errorCode <= GLU.GLU_TESS_ERROR8) ) { + return( gluErrorStrings[ errorCode - (GLU.GLU_TESS_ERROR1 - 1) ] ); } return( null ); } diff --git a/src/net/java/games/jogl/impl/glue/Glue.java b/src/classes/com/sun/opengl/impl/glue/Glue.java index 65ba2ad9d..5938f6e0d 100644 --- a/src/net/java/games/jogl/impl/glue/Glue.java +++ b/src/classes/com/sun/opengl/impl/glue/Glue.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.glue; +package com.sun.opengl.impl.glue; /** * diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXDummyGLContext.java index 29a3ef63b..fef5584ab 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXDummyGLContext.java @@ -37,10 +37,10 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.macosx; +package com.sun.opengl.impl.macosx; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; /** This MacOSXGLContext implementation provides interoperability with the NSOpenGLView Cocoa widget. The MacOSXGLImpl can be @@ -49,21 +49,10 @@ import net.java.games.jogl.impl.*; function lookup is supported in this configuration by having this object provide the FunctionAvailabilityTable. */ -class MacOSXDummyGLContext extends MacOSXGLContext +public class MacOSXDummyGLContext extends MacOSXGLContext { - private MacOSXGLImpl gl; - - MacOSXDummyGLContext(MacOSXGLImpl gl) { - super(null, null, null, null); - this.gl = gl; - } - - protected GL createGL() { - return gl; - } - - protected boolean isOffscreen() { - return false; + public MacOSXDummyGLContext() { + super(null, null); } public int getOffscreenContextReadBuffer() { @@ -78,10 +67,12 @@ class MacOSXDummyGLContext extends MacOSXGLContext throw new GLException("Should not call this"); } - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { + public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, + int initialWidth, + int initialHeight) { throw new GLException("Should not call this"); } - + public void bindPbufferToTexture() { throw new GLException("Should not call this"); } @@ -90,26 +81,6 @@ class MacOSXDummyGLContext extends MacOSXGLContext throw new GLException("Should not call this"); } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - throw new GLException("Should not call this"); - } - - public synchronized void swapBuffers() throws GLException { - throw new GLException("Should not call this"); - } - - protected synchronized void free() throws GLException { - throw new GLException("Should not call this"); - } - - protected boolean create() { - throw new GLException("Should not call this"); - } - - public void destroy() { - throw new GLException("Should not call this"); - } - public void resetGLFunctionAvailability() { super.resetGLFunctionAvailability(); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java index ec58de9a6..e7b06e32e 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLContext.java @@ -37,37 +37,44 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.macosx; +package com.sun.opengl.impl.macosx; -import java.awt.Component; +import java.nio.*; import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -public abstract class MacOSXGLContext extends GLContext +public abstract class MacOSXGLContext extends GLContextImpl { - private static JAWT jawt; + protected MacOSXGLDrawable drawable; protected long nsContext; // NSOpenGLContext - protected long nsView; // NSView - protected long updater; // ContextUpdater + private CGLExt cglExt; // Table that holds the addresses of the native C-language entry points for - // OpenGL functions. - private GLProcAddressTable glProcAddressTable; + // CGL extension functions. + private CGLExtProcAddressTable cglExtProcAddressTable; - public MacOSXGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, + public MacOSXGLContext(MacOSXGLDrawable drawable, GLContext shareWith) { - super(component, capabilities, chooser, shareWith); + super(shareWith); + this.drawable = drawable; } - protected GL createGL() - { - return new MacOSXGLImpl(this); + public Object getPlatformGLExtensions() { + return getCGLExt(); } - + + public CGLExt getCGLExt() { + if (cglExt == null) { + cglExt = new CGLExtImpl(this); + } + return cglExt; + } + + public GLDrawable getGLDrawable() { + return drawable; + } + protected String mapToRealGLFunctionName(String glFunctionName) { return glFunctionName; @@ -78,48 +85,13 @@ public abstract class MacOSXGLContext extends GLContext return glExtensionName; } - protected boolean isFunctionAvailable(String glFunctionName) - { - return super.isFunctionAvailable(glFunctionName); - } - - public boolean isExtensionAvailable(String glExtensionName) { - if (glExtensionName.equals("GL_ARB_pbuffer") || - glExtensionName.equals("GL_ARB_pixel_format")) { - return true; - } - return super.isExtensionAvailable(glExtensionName); - } - - protected abstract boolean isOffscreen(); - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextWidth() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextHeight() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - protected boolean create() { return create(false, false); } /** * Creates and initializes an appropriate OpenGl nsContext. Should only be - * called by {@link makeCurrent(Runnable)}. + * called by {@link makeCurrentImpl()}. */ protected boolean create(boolean pbuffer, boolean floatingPoint) { MacOSXGLContext other = (MacOSXGLContext) GLContextShareSet.getShareContext(this); @@ -131,8 +103,9 @@ public abstract class MacOSXGLContext extends GLContext } } int[] viewNotReady = new int[1]; + GLCapabilities capabilities = drawable.getCapabilities(); nsContext = CGL.createContext(share, - nsView, + drawable.getView(), capabilities.getDoubleBuffered() ? 1 : 0, capabilities.getStereo() ? 1 : 0, capabilities.getRedBits(), @@ -149,7 +122,7 @@ public abstract class MacOSXGLContext extends GLContext capabilities.getNumSamples(), (pbuffer ? 1 : 0), (floatingPoint ? 1 : 0), - viewNotReady); + viewNotReady, 0); if (nsContext == 0) { if (viewNotReady[0] == 1) { if (DEBUG) { @@ -160,40 +133,37 @@ public abstract class MacOSXGLContext extends GLContext } throw new GLException("Error creating nsContext"); } - //updater = CGL.updateContextRegister(nsContext, nsView); // gznote: not thread safe yet! GLContextShareSet.contextCreated(this); return true; } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - boolean created = false; - if (nsContext == 0) { - if (!create()) { - return false; - } - if (DEBUG) { - System.err.println("!!! Created GL nsContext for " + getClass().getName()); - } - created = true; + protected int makeCurrentImpl() throws GLException { + boolean created = false; + if (nsContext == 0) { + if (!create()) { + return CONTEXT_NOT_CURRENT; } - - if (!CGL.makeCurrentContext(nsContext, nsView)) { - throw new GLException("Error making nsContext current"); + if (DEBUG) { + System.err.println("!!! Created GL nsContext for " + getClass().getName()); } + created = true; + } - if (created) { - resetGLFunctionAvailability(); - if (initAction != null) { - initAction.run(); - } - } - return true; + if (!CGL.makeCurrentContext(nsContext, drawable.getView())) { + throw new GLException("Error making nsContext current"); + } + + if (created) { + resetGLFunctionAvailability(); + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; } - protected synchronized void free() throws GLException { - if (!CGL.clearCurrentContext(nsContext, nsView)) { - throw new GLException("Error freeing OpenGL nsContext"); - } + protected void releaseImpl() throws GLException { + if (!CGL.clearCurrentContext(nsContext, drawable.getView())) { + throw new GLException("Error freeing OpenGL nsContext"); + } } protected void destroyImpl() throws GLException { @@ -205,15 +175,10 @@ public abstract class MacOSXGLContext extends GLContext System.err.println("!!! Destroyed OpenGL context " + nsContext); } nsContext = 0; + GLContextShareSet.contextDestroyed(this); } } - public abstract void swapBuffers() throws GLException; - - protected long dynamicLookupFunction(String glFuncName) { - return CGL.getProcAddress(glFuncName); - } - public boolean isCreated() { return (nsContext != 0); } @@ -222,21 +187,20 @@ public abstract class MacOSXGLContext extends GLContext { super.resetGLFunctionAvailability(); if (DEBUG) { - System.err.println("!!! Initializing OpenGL extension address table"); + System.err.println("!!! Initializing CGL extension address table"); } - resetProcAddressTable(getGLProcAddressTable()); + resetProcAddressTable(getCGLExtProcAddressTable()); } - public GLProcAddressTable getGLProcAddressTable() - { - if (glProcAddressTable == null) { + public CGLExtProcAddressTable getCGLExtProcAddressTable() { + if (cglExtProcAddressTable == null) { // FIXME: cache ProcAddressTables by capability bits so we can // share them among contexts with the same capabilities - glProcAddressTable = new GLProcAddressTable(); + cglExtProcAddressTable = new CGLExtProcAddressTable(); } - return glProcAddressTable; + return cglExtProcAddressTable; } - + public String getPlatformExtensionsString() { return ""; @@ -249,6 +213,44 @@ public abstract class MacOSXGLContext extends GLContext CGL.setSwapInterval(nsContext, interval); } + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + // FIXME: apparently the Apple extension doesn't require a custom memory allocator + throw new GLException("Not yet implemented"); + } + + protected boolean isFunctionAvailable(String glFunctionName) + { + return super.isFunctionAvailable(glFunctionName); + } + + public boolean isExtensionAvailable(String glExtensionName) { + if (glExtensionName.equals("GL_ARB_pbuffer") || + glExtensionName.equals("GL_ARB_pixel_format")) { + return true; + } + return super.isExtensionAvailable(glExtensionName); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -256,23 +258,4 @@ public abstract class MacOSXGLContext extends GLContext protected long getNSContext() { return nsContext; } - - protected long getNSView() { - return nsView; - } - - protected JAWT getJAWT() - { - if (jawt == null) - { - JAWT j = new JAWT(); - j.version(JAWTFactory.JAWT_VERSION_1_4); - if (!JAWTFactory.JAWT_GetAWT(j)) - { - throw new RuntimeException("Unable to initialize JAWT"); - } - jawt = j; - } - return jawt; - } } diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawable.java new file mode 100644 index 000000000..26ea8ec54 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawable.java @@ -0,0 +1,78 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.macosx; + +import java.awt.Component; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public abstract class MacOSXGLDrawable extends GLDrawableImpl { + protected static final boolean DEBUG = Debug.debug("MacOSXGLDrawable"); + + protected long nsView; // NSView + protected GLCapabilities capabilities; + protected GLCapabilitiesChooser chooser; + + public MacOSXGLDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + this.capabilities = (GLCapabilities) capabilities.clone(); + this.chooser = chooser; + } + + public void setRealized(boolean val) { + throw new GLException("Should not call this (should only be called for onscreen GLDrawables)"); + } + + public void destroy() { + throw new GLException("Should not call this (should only be called for offscreen GLDrawables)"); + } + + public void swapBuffers() throws GLException { + } + + public GLCapabilities getCapabilities() { + return capabilities; + } + + public long getView() { + return nsView; + } +}
\ No newline at end of file diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawableFactory.java new file mode 100644 index 000000000..62b7f3b93 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXGLDrawableFactory.java @@ -0,0 +1,141 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.macosx; + +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class MacOSXGLDrawableFactory extends GLDrawableFactoryImpl { + static { + NativeLibLoader.load(); + } + + public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GraphicsDevice device) { + return null; + } + + public GLDrawable getGLDrawable(Object target, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + if (!(target instanceof Component)) { + throw new IllegalArgumentException("GLDrawables not supported for objects of type " + + target.getClass().getName() + " (only Components are supported in this implementation)"); + } + if (capabilities == null) { + capabilities = new GLCapabilities(); + } + if (chooser == null) { + chooser = new DefaultGLCapabilitiesChooser(); + } + return new MacOSXOnscreenGLDrawable((Component) target, capabilities, chooser); + } + + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + return new MacOSXOffscreenGLDrawable(capabilities); + } + + public boolean canCreateGLPbuffer() { + return true; + } + + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final int initialWidth, + final int initialHeight, + final GLContext shareWith) { + final List returnList = new ArrayList(); + Runnable r = new Runnable() { + public void run() { + MacOSXPbufferGLDrawable pbufferDrawable = new MacOSXPbufferGLDrawable(capabilities, + initialWidth, + initialHeight); + GLPbufferImpl pbuffer = new GLPbufferImpl(pbufferDrawable, shareWith); + returnList.add(pbuffer); + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLPbuffer) returnList.get(0); + } + + public GLContext createExternalGLContext() { + // FIXME + throw new GLException("Not yet implemented"); + } + + public boolean canCreateExternalGLDrawable() { + return false; + } + + public GLDrawable createExternalGLDrawable() { + // FIXME + throw new GLException("Not yet implemented"); + } + + public long dynamicLookupFunction(String glFuncName) { + return CGL.getProcAddress(glFuncName); + } + + private void maybeDoSingleThreadedWorkaround(Runnable action) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(action); + } else { + action.run(); + } + } + + public void lockAWTForJava2D() { + } + + public void unlockAWTForJava2D() { + } +} diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLContext.java new file mode 100644 index 000000000..c1d106da8 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLContext.java @@ -0,0 +1,64 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.macosx; + +import java.awt.image.BufferedImage; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext +{ + public MacOSXOffscreenGLContext(MacOSXPbufferGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + } + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_INT_8_8_8_8_REV; + } + + public int getOffscreenContextReadBuffer() { + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + return true; + } +} diff --git a/src/native/jogl/BufferUtils.c b/src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLDrawable.java index 7698b00ba..f478f43fc 100644 --- a/src/native/jogl/BufferUtils.c +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOffscreenGLDrawable.java @@ -20,7 +20,7 @@ * 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 + * MICROSYSTEMS, 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 @@ -37,18 +37,25 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -#include <jni.h> +package com.sun.opengl.impl.macosx; -#ifdef _MSC_VER - /* This typedef seems to be needed at least for VC6 and Visual Studio 2003 */ - #if _MSC_VER <= 1400 - typedef int intptr_t; - #endif -#else - #include <inttypes.h> -#endif +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -JNIEXPORT jobject JNICALL -Java_net_java_games_jogl_util_BufferUtils_bufferOffset0(JNIEnv* env, jclass unused, jint offset) { - return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) offset, 0); +public class MacOSXOffscreenGLDrawable extends MacOSXPbufferGLDrawable { + + public MacOSXOffscreenGLDrawable(GLCapabilities capabilities) { + super(capabilities, 0, 0); + } + + public GLContext createContext(GLContext shareWith) { + return new MacOSXOffscreenGLContext(this, shareWith); + } + + public void setSize(int width, int height) { + destroy(); + initWidth = width; + initHeight = height; + createPbuffer(); + } } diff --git a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java index 91789f027..9e20dd6dd 100644 --- a/src/net/java/games/gluegen/CMethodBindingImplEmitter.java +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLContext.java @@ -37,63 +37,68 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen; +package com.sun.opengl.impl.macosx; import java.util.*; -import java.io.*; -import java.text.MessageFormat; -public class CMethodBindingImplEmitter extends CMethodBindingEmitter -{ - protected static final CommentEmitter defaultCImplCommentEmitter = - new CImplCommentEmitter(); +import javax.media.opengl.*; +import com.sun.opengl.impl.*; - public CMethodBindingImplEmitter(MethodBinding binding, - boolean isOverloadedBinding, - String javaPackageName, - String javaClassName, - boolean isJavaMethodStatic, - PrintWriter output) - { - super(binding, isOverloadedBinding, - javaPackageName, javaClassName, - isJavaMethodStatic, output); - setCommentEmitter(defaultCImplCommentEmitter); - } +public class MacOSXOnscreenGLContext extends MacOSXGLContext { + protected MacOSXOnscreenGLDrawable drawable; - protected void emitName(PrintWriter writer) - { - super.emitName(writer); - if (!getIsOverloadedBinding()) { - writer.print("0"); - } + public MacOSXOnscreenGLContext(MacOSXOnscreenGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; } - /** - * Gets the mangled name for the binding, but assumes that this is an Impl - * routine - */ - protected String jniMangle(MethodBinding binding) { - StringBuffer buf = new StringBuffer(); - buf.append(jniMangle(binding.getName())); - buf.append("0"); - buf.append("__"); - for (int i = 0; i < binding.getNumArguments(); i++) { - JavaType type = binding.getJavaArgumentType(i); - Class c = type.getJavaClass(); - if (c != null) { - jniMangle(c, buf); + protected int makeCurrentImpl() throws GLException { + try { + int lockRes = drawable.lockSurface(); + if (lockRes == MacOSXOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + if (lockRes == MacOSXOnscreenGLDrawable.LOCK_SURFACE_CHANGED) { + super.destroy(); + } + int ret = super.makeCurrentImpl(); + if ((ret == CONTEXT_CURRENT) || + (ret == CONTEXT_CURRENT_NEW)) { + // Assume the canvas might have been resized or moved and tell the OpenGL + // context to update itself. This used to be done only upon receiving a + // reshape event but that doesn't appear to be sufficient. An experiment + // was also done to add a HierarchyBoundsListener to the GLCanvas and + // do this updating only upon reshape of this component or reshape or movement + // of an ancestor, but this also wasn't sufficient and left garbage on the + // screen in some situations. + CGL.updateContext(nsContext, drawable.getView()); } else { - // FIXME: add support for char* -> String conversion - throw new RuntimeException("Unknown kind of JavaType: name="+type.getName()); + // View might not have been ready + drawable.unlockSurface(); } + return ret; + } catch (RuntimeException e) { + try { + drawable.unlockSurface(); + } catch (Exception e2) { + // do nothing if unlockSurface throws + } + throw(e); } - return buf.toString(); } - - protected static class CImplCommentEmitter extends CMethodBindingEmitter.DefaultCommentEmitter { - protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) { - writer.print(" -- FIXME: PUT A COMMENT HERE -- "); + + protected void releaseImpl() throws GLException { + try { + super.releaseImpl(); + } finally { + drawable.unlockSurface(); + } + } + + public void swapBuffers() throws GLException { + if (!CGL.flushBuffer(nsContext, drawable.getView())) { + throw new GLException("Error swapping buffers"); } } } diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java new file mode 100644 index 000000000..e7f6537b9 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXOnscreenGLDrawable.java @@ -0,0 +1,228 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.macosx; + +import java.awt.Component; +import java.lang.ref.WeakReference; +import java.security.*; +import java.util.*; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class MacOSXOnscreenGLDrawable extends MacOSXGLDrawable { + public static final int LOCK_SURFACE_NOT_READY = 1; + public static final int LOCK_SURFACE_CHANGED = 2; + public static final int LOCK_SUCCESS = 3; + + private static JAWT jawt; + protected Component component; + + private List/*<WeakReference<GLContext>>*/ createdContexts = + new ArrayList(); + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; + + // Indicates whether the component (if an onscreen context) has been + // realized. Plausibly, before the component is realized the JAWT + // should return an error or NULL object from some of its + // operations; this appears to be the case on Win32 but is not true + // at least with Sun's current X11 implementation (1.4.x), which + // crashes with no other error reported if the DrawingSurfaceInfo is + // fetched from a locked DrawingSurface during the validation as a + // result of calling show() on the main thread. To work around this + // we prevent any JAWT or OpenGL operations from being done until + // addNotify() is called on the component. + protected boolean realized; + + // Workaround for instance of 4796548 + private boolean firstLock = true; + + public MacOSXOnscreenGLDrawable(Component component, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + super(capabilities, chooser); + this.component = component; + } + + public GLContext createContext(GLContext shareWith) { + MacOSXOnscreenGLContext context = + new MacOSXOnscreenGLContext(this, shareWith); + // NOTE: we need to keep track of the created contexts in order to + // implement swapBuffers() because of how Mac OS X implements its + // OpenGL window interface + synchronized (this) { + List newContexts = new ArrayList(); + newContexts.addAll(createdContexts); + newContexts.add(new WeakReference(context)); + createdContexts = newContexts; + } + return context; + } + + public void setRealized(boolean realized) { + this.realized = realized; + } + + public void setSize(int width, int height) { + component.setSize(width, height); + } + + public int getWidth() { + return component.getWidth(); + } + + public int getHeight() { + return component.getHeight(); + } + + public void swapBuffers() throws GLException { + for (Iterator iter = createdContexts.iterator(); iter.hasNext(); ) { + WeakReference ref = (WeakReference) iter.next(); + MacOSXOnscreenGLContext ctx = (MacOSXOnscreenGLContext) ref.get(); + // FIXME: clear out unreachable contexts + if (ctx != null) { + ctx.swapBuffers(); + } + } + } + + public int lockSurface() throws GLException { + if (!realized) { + return LOCK_SURFACE_NOT_READY; + } + if (nsView != 0) { + throw new GLException("Surface already locked"); + } + ds = getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { + throw new GLException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + int ret = LOCK_SUCCESS; + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + if (firstLock) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + dsi = ds.GetDrawingSurfaceInfo(); + return null; + } + }); + } else { + dsi = ds.GetDrawingSurfaceInfo(); + } + if (dsi == null) { + // Widget not yet realized + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + return LOCK_SURFACE_NOT_READY; + } + firstLock = false; + macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); + if (macosxdsi == null) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + return LOCK_SURFACE_NOT_READY; + } + nsView = macosxdsi.cocoaViewRef(); + if (nsView == 0) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + macosxdsi = null; + return LOCK_SURFACE_NOT_READY; + } + return ret; + } + + public void unlockSurface() throws GLException { + if (nsView == 0) { + throw new GLException("Surface already unlocked"); + } + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + macosxdsi = null; + nsView = 0; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private JAWT getJAWT() + { + if (jawt == null) + { + JAWT j = new JAWT(); + j.version(JAWTFactory.JAWT_VERSION_1_4); + if (!JAWTFactory.JAWT_GetAWT(j)) + { + throw new RuntimeException("Unable to initialize JAWT"); + } + jawt = j; + } + return jawt; + } +}
\ No newline at end of file diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLContext.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLContext.java new file mode 100644 index 000000000..048a256ea --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLContext.java @@ -0,0 +1,101 @@ +package com.sun.opengl.impl.macosx; + +import java.security.*; +import java.util.*; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class MacOSXPbufferGLContext extends MacOSXGLContext { + protected MacOSXPbufferGLDrawable drawable; + + // State for render-to-texture and render-to-texture-rectangle support + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + private static boolean isTigerOrLater; + + static { + String osVersion = + (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty("os.version"); + } + }); + StringTokenizer tok = new StringTokenizer(osVersion, ". "); + int major = Integer.parseInt(tok.nextToken()); + int minor = Integer.parseInt(tok.nextToken()); + isTigerOrLater = ((major > 10) || (minor > 3)); + } + + public MacOSXPbufferGLContext(MacOSXPbufferGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; + } + + public void bindPbufferToTexture() { + GL gl = getGL(); + gl.glBindTexture(textureTarget, texture); + // FIXME: not clear whether this is really necessary, but since + // the API docs seem to imply it is and since it doesn't seem to + // impact performance, leaving it in + CGL.setContextTextureImageToPBuffer(nsContext, drawable.getPbuffer(), GL.GL_FRONT); + } + + public void releasePbufferFromTexture() { + } + + protected int makeCurrentImpl() throws GLException { + if (drawable.getPbuffer() == 0) { + if (DEBUG) { + System.err.println("Pbuffer not instantiated yet for " + this); + } + // pbuffer not instantiated yet + return CONTEXT_NOT_CURRENT; + } + + int res = super.makeCurrentImpl(); + if (res == CONTEXT_CURRENT_NEW) { + // Initialize render-to-texture support if requested + boolean rect = drawable.getCapabilities().getOffscreenRenderToTextureRectangle(); + GL gl = getGL(); + if (rect) { + if (!gl.isExtensionAvailable("GL_EXT_texture_rectangle")) { + System.err.println("MacOSXPbufferGLContext: WARNING: GL_EXT_texture_rectangle extension not " + + "supported; skipping requested render_to_texture_rectangle support for pbuffer"); + rect = false; + } + } + textureTarget = (rect ? GL.GL_TEXTURE_RECTANGLE_EXT : GL.GL_TEXTURE_2D); + int[] tmp = new int[1]; + gl.glGenTextures(1, tmp, 0); + texture = tmp[0]; + gl.glBindTexture(textureTarget, texture); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); + gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, drawable.getWidth(), drawable.getHeight(), 0); + } + return res; + } + + public int getFloatingPointMode() { + return GLPbuffer.APPLE_FLOAT; + } + + protected boolean create() { + GLCapabilities capabilities = drawable.getCapabilities(); + if (capabilities.getOffscreenFloatingPointBuffers() && + !isTigerOrLater) { + throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); + } + if (!super.create(true, capabilities.getOffscreenFloatingPointBuffers())) { + return false; + } + // Must now associate the pbuffer with our newly-created context + CGL.setContextPBuffer(nsContext, drawable.getPbuffer()); + return true; + } +} diff --git a/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLDrawable.java new file mode 100644 index 000000000..038b1d759 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/macosx/MacOSXPbufferGLDrawable.java @@ -0,0 +1,160 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.macosx; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class MacOSXPbufferGLDrawable extends MacOSXGLDrawable { + private static final boolean DEBUG = Debug.debug("MacOSXPbufferGLContext"); + + protected int initWidth; + protected int initHeight; + + protected long pBuffer; + + protected int width; + protected int height; + + // State for render-to-texture and render-to-texture-rectangle support + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + public MacOSXPbufferGLDrawable(GLCapabilities capabilities, int initialWidth, int initialHeight) { + super(capabilities, null); + this.initWidth = initialWidth; + this.initHeight = initialHeight; + + createPbuffer(); + } + + public GLContext createContext(GLContext shareWith) { + return new MacOSXPbufferGLContext(this, shareWith); + } + + public void destroy() { + if (this.pBuffer != 0) { + CGL.destroyPBuffer(0, pBuffer); + this.pBuffer = 0; + + if (DEBUG) { + System.err.println("Destroyed pbuffer " + width + " x " + height); + } + } + } + + public void setSize(int width, int height) { + // FIXME + throw new GLException("Not yet implemented"); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public GLCapabilities getCapabilities() { + return capabilities; + } + + public long getPbuffer() { + return pBuffer; + } + + public void swapBuffers() throws GLException { + // FIXME: do we need to do anything if the pbuffer is double-buffered? + } + + protected void createPbuffer() { + int renderTarget; + if (capabilities.getOffscreenRenderToTextureRectangle()) { + width = initWidth; + height = initHeight; + renderTarget = GL.GL_TEXTURE_RECTANGLE_EXT; + } else { + width = getNextPowerOf2(initWidth); + height = getNextPowerOf2(initHeight); + renderTarget = GL.GL_TEXTURE_2D; + } + + int internalFormat = GL.GL_RGBA; + if (capabilities.getOffscreenFloatingPointBuffers()) { + // FIXME: want to check availability of GL_APPLE_float_pixels + // extension, but need valid OpenGL context in order to do so -- + // in worst case would need to create dummy window / GLCanvas + // (undesirable) -- could maybe also do this with pbuffers + /* + if (!gl.isExtensionAvailable("GL_APPLE_float_pixels")) { + throw new GLException("Floating-point support (GL_APPLE_float_pixels) not available"); + } + */ + switch (capabilities.getRedBits()) { + case 16: internalFormat = GL.GL_RGBA_FLOAT16_APPLE; break; + case 32: internalFormat = GL.GL_RGBA_FLOAT32_APPLE; break; + default: throw new GLException("Invalid floating-point bit depth (only 16 and 32 supported)"); + } + } + + pBuffer = CGL.createPBuffer(renderTarget, internalFormat, width, height); + if (pBuffer == 0) { + throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); + } + + if (DEBUG) { + System.err.println("Created pbuffer 0x" + toHexString(pBuffer) + ", " + width + " x " + height + " for " + this); + } + } + + private int getNextPowerOf2(int number) { + if (((number-1) & number) == 0) { + //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 + return number; + } + int power = 0; + while (number > 0) { + number = number>>1; + power++; + } + return (1<<power); + } +} diff --git a/src/net/java/games/jogl/impl/mipmap/BuildMipmap.java b/src/classes/com/sun/opengl/impl/mipmap/BuildMipmap.java index 9c9c3122b..4a499420f 100644 --- a/src/net/java/games/jogl/impl/mipmap/BuildMipmap.java +++ b/src/classes/com/sun/opengl/impl/mipmap/BuildMipmap.java @@ -32,11 +32,11 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; -import net.java.games.jogl.GL; -import net.java.games.jogl.GLU; -import net.java.games.jogl.impl.Debug; +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; +import com.sun.opengl.impl.Debug; import java.nio.*; import java.io.*; @@ -46,7 +46,8 @@ import java.io.*; */ public class BuildMipmap { - private static boolean DEBUG = Debug.debug("BuildMipmap"); + private static final boolean DEBUG = Debug.debug("BuildMipmap"); + private static final boolean VERBOSE = Debug.verbose(); /** Creates a new instance of BuildMipmap */ public BuildMipmap() { @@ -663,16 +664,18 @@ public class BuildMipmap { gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, srcImage ); if (DEBUG) { System.err.println("GL Error(" + level + "): " + gl.glGetError() ); - try { - File file = new File( "glu2DMipmapJ" + level + ".bin" ); - FileOutputStream fos = new FileOutputStream( file ); - srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); - fos.getChannel().write( srcImage ); - srcImage.clear(); - fos.close(); - } catch( IOException e ) { - System.err.println("IOException"); - System.err.println(e.getMessage()); + if (VERBOSE) { + try { + File file = new File( "glu2DMipmapJ" + level + ".bin" ); + FileOutputStream fos = new FileOutputStream( file ); + srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); + fos.getChannel().write( srcImage ); + srcImage.clear(); + fos.close(); + } catch( IOException e ) { + System.err.println("IOException"); + System.err.println(e.getMessage()); + } } } } @@ -769,15 +772,17 @@ public class BuildMipmap { gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, srcImage ); if (DEBUG) { System.err.println("GL Error(" + level + "): " + gl.glGetError() ); - try { - File file = new File( "glu2DMipmapJ" + level + ".bin" ); - FileOutputStream fos = new FileOutputStream( file ); - srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); - fos.getChannel().write( srcImage ); - srcImage.clear(); - } catch( IOException e ) { - System.err.println("IOException"); - System.err.println(e.getMessage()); + if (VERBOSE) { + try { + File file = new File( "glu2DMipmapJ" + level + ".bin" ); + FileOutputStream fos = new FileOutputStream( file ); + srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); + fos.getChannel().write( srcImage ); + srcImage.clear(); + } catch( IOException e ) { + System.err.println("IOException"); + System.err.println(e.getMessage()); + } } } } @@ -817,15 +822,17 @@ public class BuildMipmap { gl.glTexImage2D( target, level, internalFormat, newwidth, newheight, 0, format, type, newMipmapImage ); if (DEBUG) { System.err.println("GL Error: " + gl.glGetError() ); - try { - File file = new File( "glu2DMipmapJ" + level + ".bin" ); - FileOutputStream fos = new FileOutputStream( file ); - srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); - fos.getChannel().write( newMipmapImage ); - srcImage.clear(); - } catch( IOException e ) { - System.err.println("IOException"); - System.err.println(e.getMessage()); + if (VERBOSE) { + try { + File file = new File( "glu2DMipmapJ" + level + ".bin" ); + FileOutputStream fos = new FileOutputStream( file ); + srcImage.limit( Mipmap.image_size( newwidth, newheight, format, type ) ); + fos.getChannel().write( newMipmapImage ); + srcImage.clear(); + } catch( IOException e ) { + System.err.println("IOException"); + System.err.println(e.getMessage()); + } } } } diff --git a/src/net/java/games/jogl/impl/mipmap/Extract.java b/src/classes/com/sun/opengl/impl/mipmap/Extract.java index c78bcd9ce..12362011e 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract1010102.java b/src/classes/com/sun/opengl/impl/mipmap/Extract1010102.java index d6fcc5977..d337e5dcd 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract1010102.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract1010102.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract1555rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract1555rev.java index 10a132417..1b8372e84 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract1555rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract1555rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract2101010rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract2101010rev.java index 5d98f19a7..adef3d58d 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract2101010rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract2101010rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract233rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract233rev.java index 46d45cbcb..1a3e9582e 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract233rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract233rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract332.java b/src/classes/com/sun/opengl/impl/mipmap/Extract332.java index 6a3bcdc0a..e925a2cc1 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract332.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract332.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract4444.java b/src/classes/com/sun/opengl/impl/mipmap/Extract4444.java index c2b5fc95f..b4dff1b72 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract4444.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract4444.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract4444rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract4444rev.java index e8adf3004..761d057b1 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract4444rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract4444rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract5551.java b/src/classes/com/sun/opengl/impl/mipmap/Extract5551.java index b7e3a027b..047298152 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract5551.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract5551.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract565.java b/src/classes/com/sun/opengl/impl/mipmap/Extract565.java index 43158bb6c..c9346ecf6 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract565.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract565.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract565rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract565rev.java index b6f3af966..9b0596b3f 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract565rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract565rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract8888.java b/src/classes/com/sun/opengl/impl/mipmap/Extract8888.java index c013fae28..9f57bc39e 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract8888.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract8888.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/Extract8888rev.java b/src/classes/com/sun/opengl/impl/mipmap/Extract8888rev.java index 9104ed7b1..2c0d90595 100644 --- a/src/net/java/games/jogl/impl/mipmap/Extract8888rev.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Extract8888rev.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractFloat.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractFloat.java index 3dad2de29..b1a0ee51e 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractFloat.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractFloat.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractPrimitive.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractPrimitive.java index 242d8f331..4ba6f734e 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractPrimitive.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractPrimitive.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractSByte.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractSByte.java index f925eb7bd..f8cfcda2e 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractSByte.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractSByte.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractSInt.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractSInt.java index c874c82f1..5411f6daa 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractSInt.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractSInt.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractSShort.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractSShort.java index 73a0f9c5e..ace44b3a9 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractSShort.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractSShort.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractUByte.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractUByte.java index 031aa74ce..0c0a2716b 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractUByte.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractUByte.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.ByteBuffer; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractUInt.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractUInt.java index b80afd41e..feba26f96 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractUInt.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractUInt.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/ExtractUShort.java b/src/classes/com/sun/opengl/impl/mipmap/ExtractUShort.java index 130f2c833..1b7abd70b 100644 --- a/src/net/java/games/jogl/impl/mipmap/ExtractUShort.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ExtractUShort.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/mipmap/HalveImage.java b/src/classes/com/sun/opengl/impl/mipmap/HalveImage.java index ea12577b9..5e854c13d 100644 --- a/src/net/java/games/jogl/impl/mipmap/HalveImage.java +++ b/src/classes/com/sun/opengl/impl/mipmap/HalveImage.java @@ -32,9 +32,9 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; -import net.java.games.jogl.GL; +import javax.media.opengl.GL; import java.nio.*; /** diff --git a/src/net/java/games/jogl/impl/mipmap/Image.java b/src/classes/com/sun/opengl/impl/mipmap/Image.java index 1ea3b1f52..777434586 100644 --- a/src/net/java/games/jogl/impl/mipmap/Image.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Image.java @@ -32,9 +32,9 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; -import net.java.games.jogl.GL; +import javax.media.opengl.GL; import java.nio.*; /** diff --git a/src/net/java/games/jogl/impl/mipmap/Mipmap.java b/src/classes/com/sun/opengl/impl/mipmap/Mipmap.java index b3954704d..2b4a30edc 100644 --- a/src/net/java/games/jogl/impl/mipmap/Mipmap.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Mipmap.java @@ -32,11 +32,11 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; -import net.java.games.jogl.GL; -import net.java.games.jogl.GLU; -import net.java.games.jogl.GLException; +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.GLException; import java.nio.*; /** @@ -263,23 +263,23 @@ public class Mipmap { if( target == GL.GL_TEXTURE_2D || target == GL.GL_PROXY_TEXTURE_2D ) { proxyTarget = GL.GL_PROXY_TEXTURE_2D; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, 0, format, type, (double[])null ); - } else if( (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB) || - (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB) || - (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB) || - (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB) || - (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB) || - (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) ) { - proxyTarget = GL.GL_PROXY_TEXTURE_CUBE_MAP_ARB; + heightAtLevelOne, 0, format, type, null ); + } else if( (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X) || + (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X) || + (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y) || + (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) || + (target == GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z) || + (target == GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) ) { + proxyTarget = GL.GL_PROXY_TEXTURE_CUBE_MAP; gl.glTexImage2D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, 0, format, type, (double[])null ); + heightAtLevelOne, 0, format, type, null ); } else { assert( target == GL.GL_TEXTURE_1D || target == GL.GL_PROXY_TEXTURE_1D ); proxyTarget = GL.GL_PROXY_TEXTURE_1D; gl.glTexImage1D( proxyTarget, 1, internalFormat, widthAtLevelOne, - 0, format, type, (double[])null ); + 0, format, type, null ); } - gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth ); + gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth, 0 ); // does it fit? if( proxyWidth[0] == 0 ) { // nope, so try again with theses sizes if( widthPowerOf2 == 1 && heightPowerOf2 == 1 ) { @@ -308,7 +308,7 @@ public class Mipmap { } } int[] maxsize = new int[1]; - gl.glGetIntegerv( GL.GL_MAX_TEXTURE_SIZE, maxsize ); + gl.glGetIntegerv( GL.GL_MAX_TEXTURE_SIZE, maxsize , 0); // clamp user's texture sizes to maximum sizes, if necessary newWidth[0] = nearestPower( width ); if( newWidth[0] > maxsize[0] ) { @@ -342,9 +342,9 @@ public class Mipmap { if( target == GL.GL_TEXTURE_3D || target == GL.GL_PROXY_TEXTURE_3D ) { proxyTarget = GL.GL_PROXY_TEXTURE_3D; gl.glTexImage3D( proxyTarget, 1, internalFormat, widthAtLevelOne, - heightAtLevelOne, depthAtLevelOne, 0, format, type, (double[])null ); + heightAtLevelOne, depthAtLevelOne, 0, format, type, null ); } - gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth ); + gl.glGetTexLevelParameteriv( proxyTarget, 1, GL.GL_TEXTURE_WIDTH, proxyWidth, 0 ); // does it fit if( proxyWidth[0] == 0 ) { if( widthPowerOf2 == 1 && heightPowerOf2 == 1 && depthPowerOf2 == 1 ) { @@ -463,67 +463,67 @@ public class Mipmap { public static void retrieveStoreModes( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a, 0); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a, 0); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a, 0); psm.setPackSwapBytes( ( a[0] == 1 ) ); } public static void retrieveStoreModes3D( GL gl, PixelStorageModes psm ) { int[] a = new int[1]; - gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ALIGNMENT, a, 0); psm.setUnpackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_UNPACK_ROW_LENGTH, a, 0); psm.setUnpackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_ROWS, a, 0); psm.setUnpackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_PIXELS, a, 0); psm.setUnpackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_UNPACK_LSB_FIRST, a, 0); psm.setUnpackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SWAP_BYTES, a, 0); psm.setUnpackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_UNPACK_SKIP_IMAGES, a ); + gl.glGetIntegerv( GL.GL_UNPACK_SKIP_IMAGES, a, 0); psm.setUnpackSkipImages( a[0] ); - gl.glGetIntegerv( GL.GL_UNPACK_IMAGE_HEIGHT, a ); + gl.glGetIntegerv( GL.GL_UNPACK_IMAGE_HEIGHT, a, 0); psm.setUnpackImageHeight( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a ); + gl.glGetIntegerv( GL.GL_PACK_ALIGNMENT, a, 0); psm.setPackAlignment( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a ); + gl.glGetIntegerv( GL.GL_PACK_ROW_LENGTH, a, 0); psm.setPackRowLength( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_ROWS, a, 0); psm.setPackSkipRows( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_PIXELS, a, 0 ); psm.setPackSkipPixels( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a ); + gl.glGetIntegerv( GL.GL_PACK_LSB_FIRST, a, 0 ); psm.setPackLsbFirst( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a ); + gl.glGetIntegerv( GL.GL_PACK_SWAP_BYTES, a, 0 ); psm.setPackSwapBytes( ( a[0] == 1 ) ); - gl.glGetIntegerv( GL.GL_PACK_SKIP_IMAGES, a ); + gl.glGetIntegerv( GL.GL_PACK_SKIP_IMAGES, a, 0 ); psm.setPackSkipImages( a[0] ); - gl.glGetIntegerv( GL.GL_PACK_IMAGE_HEIGHT, a ); + gl.glGetIntegerv( GL.GL_PACK_IMAGE_HEIGHT, a, 0 ); psm.setPackImageHeight( a[0] ); } @@ -611,7 +611,8 @@ public class Mipmap { return( BuildMipmap.gluBuild1DMipmapLevelsCore( gl, target, internalFormat, width, widthPowerOf2[0], format, type, 0, 0, levels, data ) ); } - + + public static int gluBuild2DMipmapLevels( GL gl, int target, int internalFormat, int width, int height, int format, int type, int userLevel, int baseLevel, int maxLevel, Object data ) { @@ -666,7 +667,8 @@ public class Mipmap { width, height, width, height, format, type, userLevel, baseLevel, maxLevel, buffer ) ); } - + + public static int gluBuild2DMipmaps( GL gl, int target, int internalFormat, int width, int height, int format, int type, Object data ) { int[] widthPowerOf2 = new int[1]; @@ -720,7 +722,8 @@ public class Mipmap { width, height, widthPowerOf2[0], heightPowerOf2[0], format, type, 0, 0, levels, buffer ) ); } - + + public static int gluBuild3DMipmaps( GL gl, int target, int internalFormat, int width, int height, int depth, int format, int type, ByteBuffer data ) { int[] widthPowerOf2 = new int[1]; diff --git a/src/net/java/games/jogl/impl/mipmap/PixelStorageModes.java b/src/classes/com/sun/opengl/impl/mipmap/PixelStorageModes.java index cc3b4ed47..990e4b90a 100644 --- a/src/net/java/games/jogl/impl/mipmap/PixelStorageModes.java +++ b/src/classes/com/sun/opengl/impl/mipmap/PixelStorageModes.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; /** * diff --git a/src/net/java/games/jogl/impl/mipmap/ScaleInternal.java b/src/classes/com/sun/opengl/impl/mipmap/ScaleInternal.java index 06c8e582f..e000c2043 100644 --- a/src/net/java/games/jogl/impl/mipmap/ScaleInternal.java +++ b/src/classes/com/sun/opengl/impl/mipmap/ScaleInternal.java @@ -32,10 +32,10 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; -import net.java.games.jogl.GLU; -import net.java.games.jogl.GL; +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; import java.nio.*; /** @@ -334,6 +334,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -545,6 +552,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -819,6 +833,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -1109,6 +1130,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -1390,6 +1418,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -1680,6 +1715,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -1970,6 +2012,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthin - 1) { + int delta = (highx_int - widthin + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; @@ -2196,6 +2245,13 @@ public class ScaleInternal { highx_float -= 1.0f; highx_int++; } + + // Clamp to make sure we don't run off the right edge + if (highx_int > widthIn - 1) { + int delta = (highx_int - widthIn + 1); + lowx_int -= delta; + highx_int -= delta; + } } lowy_int = highy_int; lowy_float = highy_float; diff --git a/src/net/java/games/jogl/impl/mipmap/Type_Widget.java b/src/classes/com/sun/opengl/impl/mipmap/Type_Widget.java index f749d5348..0431748e9 100644 --- a/src/net/java/games/jogl/impl/mipmap/Type_Widget.java +++ b/src/classes/com/sun/opengl/impl/mipmap/Type_Widget.java @@ -32,7 +32,7 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.mipmap; +package com.sun.opengl.impl.mipmap; import java.nio.*; diff --git a/src/net/java/games/jogl/impl/nurbs/README-PORTING.txt b/src/classes/com/sun/opengl/impl/nurbs/README-PORTING.txt index df5f41782..df5f41782 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/README-PORTING.txt +++ b/src/classes/com/sun/opengl/impl/nurbs/README-PORTING.txt diff --git a/src/net/java/games/jogl/impl/nurbs/internals/Arc.java b/src/classes/com/sun/opengl/impl/nurbs/internals/Arc.java index 076c68b72..076c68b72 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/Arc.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/Arc.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/ArcTesselator.java b/src/classes/com/sun/opengl/impl/nurbs/internals/ArcTesselator.java index cb77dfbd0..cb77dfbd0 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/ArcTesselator.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/ArcTesselator.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/Backend.java b/src/classes/com/sun/opengl/impl/nurbs/internals/Backend.java index e99822f0b..e99822f0b 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/Backend.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/Backend.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/BasicCurveEvaluator.java b/src/classes/com/sun/opengl/impl/nurbs/internals/BasicCurveEvaluator.java index 3aae3674b..3aae3674b 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/BasicCurveEvaluator.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/BasicCurveEvaluator.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/BasicSurfaceEvaluator.java b/src/classes/com/sun/opengl/impl/nurbs/internals/BasicSurfaceEvaluator.java index f2b4a6679..f2b4a6679 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/BasicSurfaceEvaluator.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/BasicSurfaceEvaluator.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/BezierArc.java b/src/classes/com/sun/opengl/impl/nurbs/internals/BezierArc.java index feac7d544..feac7d544 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/BezierArc.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/BezierArc.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/Bin.java b/src/classes/com/sun/opengl/impl/nurbs/internals/Bin.java index 55bec5eae..55bec5eae 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/Bin.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/Bin.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/CachingEvaluator.java b/src/classes/com/sun/opengl/impl/nurbs/internals/CachingEvaluator.java index c9c8c5cf9..c9c8c5cf9 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/CachingEvaluator.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/CachingEvaluator.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/Defines.java b/src/classes/com/sun/opengl/impl/nurbs/internals/Defines.java index fc284abbd..fc284abbd 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/Defines.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/Defines.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/NurbsConsts.java b/src/classes/com/sun/opengl/impl/nurbs/internals/NurbsConsts.java index 74c9c150c..74c9c150c 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/NurbsConsts.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/NurbsConsts.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/NurbsException.java b/src/classes/com/sun/opengl/impl/nurbs/internals/NurbsException.java index 5453807cd..5453807cd 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/NurbsException.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/NurbsException.java diff --git a/src/net/java/games/jogl/impl/nurbs/internals/Subdivider.java b/src/classes/com/sun/opengl/impl/nurbs/internals/Subdivider.java index 155b6b7ac..155b6b7ac 100755..100644 --- a/src/net/java/games/jogl/impl/nurbs/internals/Subdivider.java +++ b/src/classes/com/sun/opengl/impl/nurbs/internals/Subdivider.java diff --git a/src/net/java/games/jogl/impl/registry/Registry.java b/src/classes/com/sun/opengl/impl/registry/Registry.java index ef9f868f3..d1f386d83 100644 --- a/src/net/java/games/jogl/impl/registry/Registry.java +++ b/src/classes/com/sun/opengl/impl/registry/Registry.java @@ -32,10 +32,10 @@ * compliant with the OpenGL(R) version 1.2.1 Specification. */ -package net.java.games.jogl.impl.registry; +package com.sun.opengl.impl.registry; import java.util.regex.*; -import net.java.games.jogl.GLU; +import javax.media.opengl.glu.GLU; /** * @@ -56,7 +56,7 @@ public class Registry { return( null ); } - public static boolean gluCheckExtensions( String extName, String extString ) { + public static boolean gluCheckExtension( String extName, String extString ) { if( extName == null || extString == null ) { return( false ); } diff --git a/src/net/java/games/jogl/impl/tesselator/ActiveRegion.java b/src/classes/com/sun/opengl/impl/tessellator/ActiveRegion.java index a3b3f953a..b626157fe 100644 --- a/src/net/java/games/jogl/impl/tesselator/ActiveRegion.java +++ b/src/classes/com/sun/opengl/impl/tessellator/ActiveRegion.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class ActiveRegion { GLUhalfEdge eUp; /* upper edge, directed right to left */ diff --git a/src/net/java/games/jogl/impl/tesselator/CachedVertex.java b/src/classes/com/sun/opengl/impl/tessellator/CachedVertex.java index 3f8661d78..70260d615 100644 --- a/src/net/java/games/jogl/impl/tesselator/CachedVertex.java +++ b/src/classes/com/sun/opengl/impl/tessellator/CachedVertex.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class CachedVertex { public double[] coords = new double[3]; diff --git a/src/net/java/games/jogl/impl/tesselator/Dict.java b/src/classes/com/sun/opengl/impl/tessellator/Dict.java index 6d3d80d0c..84da2dda6 100644 --- a/src/net/java/games/jogl/impl/tesselator/Dict.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Dict.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class Dict { DictNode head; diff --git a/src/net/java/games/jogl/impl/tesselator/DictNode.java b/src/classes/com/sun/opengl/impl/tessellator/DictNode.java index da870b6d9..698121392 100644 --- a/src/net/java/games/jogl/impl/tesselator/DictNode.java +++ b/src/classes/com/sun/opengl/impl/tessellator/DictNode.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class DictNode { Object key; diff --git a/src/net/java/games/jogl/impl/tesselator/GLUface.java b/src/classes/com/sun/opengl/impl/tessellator/GLUface.java index fa2449a5a..225c5460c 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUface.java +++ b/src/classes/com/sun/opengl/impl/tessellator/GLUface.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class GLUface { public GLUface next; /* next face (never NULL) */ diff --git a/src/net/java/games/jogl/impl/tesselator/GLUhalfEdge.java b/src/classes/com/sun/opengl/impl/tessellator/GLUhalfEdge.java index 8e2abcb78..d58df6278 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUhalfEdge.java +++ b/src/classes/com/sun/opengl/impl/tessellator/GLUhalfEdge.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; @@ -50,10 +50,10 @@ class GLUhalfEdge { public GLUhalfEdge Onext; /* next edge CCW around origin */ public GLUhalfEdge Lnext; /* next edge CCW around left face */ public GLUvertex Org; /* origin vertex (Overtex too long) */ - public net.java.games.jogl.impl.tesselator.GLUface Lface; /* left face */ + public com.sun.opengl.impl.tessellator.GLUface Lface; /* left face */ /* Internal data (keep hidden) */ - public net.java.games.jogl.impl.tesselator.ActiveRegion activeRegion; /* a region with this upper edge (sweep.c) */ + public com.sun.opengl.impl.tessellator.ActiveRegion activeRegion; /* a region with this upper edge (sweep.c) */ public int winding; /* change in winding number when crossing */ public boolean first; diff --git a/src/net/java/games/jogl/impl/tesselator/GLUmesh.java b/src/classes/com/sun/opengl/impl/tessellator/GLUmesh.java index 0ab3b2626..d1ed8286b 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUmesh.java +++ b/src/classes/com/sun/opengl/impl/tessellator/GLUmesh.java @@ -40,13 +40,13 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class GLUmesh { GLUvertex vHead = new GLUvertex(); /* dummy header for vertex list */ - net.java.games.jogl.impl.tesselator.GLUface fHead = new GLUface(); /* dummy header for face list */ - net.java.games.jogl.impl.tesselator.GLUhalfEdge eHead = new GLUhalfEdge(true); /* dummy header for edge list */ - net.java.games.jogl.impl.tesselator.GLUhalfEdge eHeadSym = new GLUhalfEdge(false); /* and its symmetric counterpart */ + com.sun.opengl.impl.tessellator.GLUface fHead = new GLUface(); /* dummy header for face list */ + com.sun.opengl.impl.tessellator.GLUhalfEdge eHead = new GLUhalfEdge(true); /* dummy header for edge list */ + com.sun.opengl.impl.tessellator.GLUhalfEdge eHeadSym = new GLUhalfEdge(false); /* and its symmetric counterpart */ } diff --git a/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java b/src/classes/com/sun/opengl/impl/tessellator/GLUtessellatorImpl.java index 90de5bcc9..98a0fba3a 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUtesselatorImpl.java +++ b/src/classes/com/sun/opengl/impl/tessellator/GLUtessellatorImpl.java @@ -40,12 +40,13 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.tesselator.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import com.sun.opengl.impl.tessellator.*; -public class GLUtesselatorImpl implements GLUtesselator { +public class GLUtessellatorImpl implements GLUtessellator { public static final int TESS_MAX_CACHE = 100; private int state; /* what begin/end calls have we seen? */ @@ -88,30 +89,30 @@ public class GLUtesselatorImpl implements GLUtesselator { /*** rendering callbacks that also pass polygon data ***/ private Object polygonData; /* client data for current polygon */ - private GLUtesselatorCallback callBegin; - private GLUtesselatorCallback callEdgeFlag; - private GLUtesselatorCallback callVertex; - private GLUtesselatorCallback callEnd; -// private GLUtesselatorCallback callMesh; - private GLUtesselatorCallback callError; - private GLUtesselatorCallback callCombine; - - private GLUtesselatorCallback callBeginData; - private GLUtesselatorCallback callEdgeFlagData; - private GLUtesselatorCallback callVertexData; - private GLUtesselatorCallback callEndData; -// private GLUtesselatorCallback callMeshData; - private GLUtesselatorCallback callErrorData; - private GLUtesselatorCallback callCombineData; + private GLUtessellatorCallback callBegin; + private GLUtessellatorCallback callEdgeFlag; + private GLUtessellatorCallback callVertex; + private GLUtessellatorCallback callEnd; +// private GLUtessellatorCallback callMesh; + private GLUtessellatorCallback callError; + private GLUtessellatorCallback callCombine; + + private GLUtessellatorCallback callBeginData; + private GLUtessellatorCallback callEdgeFlagData; + private GLUtessellatorCallback callVertexData; + private GLUtessellatorCallback callEndData; +// private GLUtessellatorCallback callMeshData; + private GLUtessellatorCallback callErrorData; + private GLUtessellatorCallback callCombineData; private static final double GLU_TESS_DEFAULT_TOLERANCE = 0.0; // private static final int GLU_TESS_MESH = 100112; /* void (*)(GLUmesh *mesh) */ - private static GLUtesselatorCallback NULL_CB = new GLUtesselatorCallbackAdapter(); + private static GLUtessellatorCallback NULL_CB = new GLUtessellatorCallbackAdapter(); // #define MAX_FAST_ALLOC (MAX(sizeof(EdgePair), \ // MAX(sizeof(GLUvertex),sizeof(GLUface)))) - private GLUtesselatorImpl() { + private GLUtessellatorImpl() { state = TessState.T_DORMANT; normal[0] = 0; @@ -145,9 +146,9 @@ public class GLUtesselatorImpl implements GLUtesselator { } } - static public GLUtesselator gluNewTess() + static public GLUtessellator gluNewTess() { - return new GLUtesselatorImpl(); + return new GLUtessellatorImpl(); } @@ -231,12 +232,12 @@ public class GLUtesselatorImpl implements GLUtesselator { } /* Returns tessellator property */ - public void gluGetTessProperty(int which, double[] value) { + public void gluGetTessProperty(int which, double[] value, int value_offset) { switch (which) { case GLU.GLU_TESS_TOLERANCE: /* tolerance should be in range [0..1] */ assert (0.0 <= relTolerance && relTolerance <= 1.0); - value[0] = relTolerance; + value[value_offset] = relTolerance; break; case GLU.GLU_TESS_WINDING_RULE: assert (windingRule == GLU.GLU_TESS_WINDING_ODD || @@ -244,14 +245,14 @@ public class GLUtesselatorImpl implements GLUtesselator { windingRule == GLU.GLU_TESS_WINDING_POSITIVE || windingRule == GLU.GLU_TESS_WINDING_NEGATIVE || windingRule == GLU.GLU_TESS_WINDING_ABS_GEQ_TWO); - value[0] = windingRule; + value[value_offset] = windingRule; break; case GLU.GLU_TESS_BOUNDARY_ONLY: assert (boundaryOnly == true || boundaryOnly == false); - value[0] = boundaryOnly ? 1 : 0; + value[value_offset] = boundaryOnly ? 1 : 0; break; default: - value[0] = 0.0; + value[value_offset] = 0.0; callErrorOrErrorData(GLU.GLU_INVALID_ENUM); break; } @@ -263,7 +264,7 @@ public class GLUtesselatorImpl implements GLUtesselator { normal[2] = z; } - public void gluTessCallback(int which, GLUtesselatorCallback aCallback) { + public void gluTessCallback(int which, GLUtessellatorCallback aCallback) { switch (which) { case GLU.GLU_TESS_BEGIN: callBegin = aCallback == null ? NULL_CB : aCallback; @@ -386,7 +387,7 @@ public class GLUtesselatorImpl implements GLUtesselator { return true; } - public void gluTessVertex(double[] coords, Object vertexData) { + public void gluTessVertex(double[] coords, int coords_offset, Object vertexData) { int i; boolean tooLarge = false; double x; @@ -402,7 +403,7 @@ public class GLUtesselatorImpl implements GLUtesselator { lastEdge = null; } for (i = 0; i < 3; ++i) { - x = coords[i]; + x = coords[i+coords_offset]; if (x < -GLU.GLU_TESS_MAX_COORD) { x = -GLU.GLU_TESS_MAX_COORD; tooLarge = true; diff --git a/src/net/java/games/jogl/impl/tesselator/GLUvertex.java b/src/classes/com/sun/opengl/impl/tessellator/GLUvertex.java index 6497aa2d7..05836beda 100644 --- a/src/net/java/games/jogl/impl/tesselator/GLUvertex.java +++ b/src/classes/com/sun/opengl/impl/tessellator/GLUvertex.java @@ -40,12 +40,12 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class GLUvertex { public GLUvertex next; /* next vertex (never NULL) */ public GLUvertex prev; /* previous vertex (never NULL) */ - public net.java.games.jogl.impl.tesselator.GLUhalfEdge anEdge; /* a half-edge with this origin */ + public com.sun.opengl.impl.tessellator.GLUhalfEdge anEdge; /* a half-edge with this origin */ public Object data; /* client's data */ /* Internal data (keep hidden) */ diff --git a/src/net/java/games/jogl/impl/tesselator/Geom.java b/src/classes/com/sun/opengl/impl/tessellator/Geom.java index 9693b3a48..10e3d8050 100644 --- a/src/net/java/games/jogl/impl/tesselator/Geom.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Geom.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class Geom { private Geom() { diff --git a/src/net/java/games/jogl/impl/tesselator/Mesh.java b/src/classes/com/sun/opengl/impl/tessellator/Mesh.java index 4eee1f8ac..f5a81f65d 100644 --- a/src/net/java/games/jogl/impl/tesselator/Mesh.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Mesh.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class Mesh { private Mesh() { @@ -51,19 +51,19 @@ class Mesh { * No vertex or face structures are allocated, but these must be assigned * before the current edge operation is completed. */ - static net.java.games.jogl.impl.tesselator.GLUhalfEdge MakeEdge(net.java.games.jogl.impl.tesselator.GLUhalfEdge eNext) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; - net.java.games.jogl.impl.tesselator.GLUhalfEdge eSym; - net.java.games.jogl.impl.tesselator.GLUhalfEdge ePrev; + static com.sun.opengl.impl.tessellator.GLUhalfEdge MakeEdge(com.sun.opengl.impl.tessellator.GLUhalfEdge eNext) { + com.sun.opengl.impl.tessellator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUhalfEdge eSym; + com.sun.opengl.impl.tessellator.GLUhalfEdge ePrev; // EdgePair * pair = (EdgePair *) // memAlloc(sizeof(EdgePair)); // if (pair == NULL) return NULL; // // e = &pair - > e; - e = new net.java.games.jogl.impl.tesselator.GLUhalfEdge(true); + e = new com.sun.opengl.impl.tessellator.GLUhalfEdge(true); // eSym = &pair - > eSym; - eSym = new net.java.games.jogl.impl.tesselator.GLUhalfEdge(false); + eSym = new com.sun.opengl.impl.tessellator.GLUhalfEdge(false); /* Make sure eNext points to the first edge of the edge pair */ @@ -105,9 +105,9 @@ class Mesh { * depending on whether a and b belong to different face or vertex rings. * For more explanation see __gl_meshSplice() below. */ - static void Splice(net.java.games.jogl.impl.tesselator.GLUhalfEdge a, net.java.games.jogl.impl.tesselator.GLUhalfEdge b) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge aOnext = a.Onext; - net.java.games.jogl.impl.tesselator.GLUhalfEdge bOnext = b.Onext; + static void Splice(com.sun.opengl.impl.tessellator.GLUhalfEdge a, com.sun.opengl.impl.tessellator.GLUhalfEdge b) { + com.sun.opengl.impl.tessellator.GLUhalfEdge aOnext = a.Onext; + com.sun.opengl.impl.tessellator.GLUhalfEdge bOnext = b.Onext; aOnext.Sym.Lnext = b; bOnext.Sym.Lnext = a; @@ -121,11 +121,11 @@ class Mesh { * the new vertex *before* vNext so that algorithms which walk the vertex * list will not see the newly created vertices. */ - static void MakeVertex(net.java.games.jogl.impl.tesselator.GLUvertex newVertex, - net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrig, net.java.games.jogl.impl.tesselator.GLUvertex vNext) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; - net.java.games.jogl.impl.tesselator.GLUvertex vPrev; - net.java.games.jogl.impl.tesselator.GLUvertex vNew = newVertex; + static void MakeVertex(com.sun.opengl.impl.tessellator.GLUvertex newVertex, + com.sun.opengl.impl.tessellator.GLUhalfEdge eOrig, com.sun.opengl.impl.tessellator.GLUvertex vNext) { + com.sun.opengl.impl.tessellator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUvertex vPrev; + com.sun.opengl.impl.tessellator.GLUvertex vNew = newVertex; assert (vNew != null); @@ -154,10 +154,10 @@ class Mesh { * the new face *before* fNext so that algorithms which walk the face * list will not see the newly created faces. */ - static void MakeFace(net.java.games.jogl.impl.tesselator.GLUface newFace, net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrig, net.java.games.jogl.impl.tesselator.GLUface fNext) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; - net.java.games.jogl.impl.tesselator.GLUface fPrev; - net.java.games.jogl.impl.tesselator.GLUface fNew = newFace; + static void MakeFace(com.sun.opengl.impl.tessellator.GLUface newFace, com.sun.opengl.impl.tessellator.GLUhalfEdge eOrig, com.sun.opengl.impl.tessellator.GLUface fNext) { + com.sun.opengl.impl.tessellator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUface fPrev; + com.sun.opengl.impl.tessellator.GLUface fNew = newFace; assert (fNew != null); @@ -189,8 +189,8 @@ class Mesh { /* KillEdge( eDel ) destroys an edge (the half-edges eDel and eDel->Sym), * and removes from the global edge list. */ - static void KillEdge(net.java.games.jogl.impl.tesselator.GLUhalfEdge eDel) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge ePrev, eNext; + static void KillEdge(com.sun.opengl.impl.tessellator.GLUhalfEdge eDel) { + com.sun.opengl.impl.tessellator.GLUhalfEdge ePrev, eNext; /* Half-edges are allocated in pairs, see EdgePair above */ if (!eDel.first) { @@ -208,9 +208,9 @@ class Mesh { /* KillVertex( vDel ) destroys a vertex and removes it from the global * vertex list. It updates the vertex loop to point to a given new vertex. */ - static void KillVertex(net.java.games.jogl.impl.tesselator.GLUvertex vDel, net.java.games.jogl.impl.tesselator.GLUvertex newOrg) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, eStart = vDel.anEdge; - net.java.games.jogl.impl.tesselator.GLUvertex vPrev, vNext; + static void KillVertex(com.sun.opengl.impl.tessellator.GLUvertex vDel, com.sun.opengl.impl.tessellator.GLUvertex newOrg) { + com.sun.opengl.impl.tessellator.GLUhalfEdge e, eStart = vDel.anEdge; + com.sun.opengl.impl.tessellator.GLUvertex vPrev, vNext; /* change the origin of all affected edges */ e = eStart; @@ -229,9 +229,9 @@ class Mesh { /* KillFace( fDel ) destroys a face and removes it from the global face * list. It updates the face loop to point to a given new face. */ - static void KillFace(net.java.games.jogl.impl.tesselator.GLUface fDel, net.java.games.jogl.impl.tesselator.GLUface newLface) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, eStart = fDel.anEdge; - net.java.games.jogl.impl.tesselator.GLUface fPrev, fNext; + static void KillFace(com.sun.opengl.impl.tessellator.GLUface fDel, com.sun.opengl.impl.tessellator.GLUface newLface) { + com.sun.opengl.impl.tessellator.GLUhalfEdge e, eStart = fDel.anEdge; + com.sun.opengl.impl.tessellator.GLUface fPrev, fNext; /* change the left face of all affected edges */ e = eStart; @@ -253,11 +253,11 @@ class Mesh { /* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face). * The loop consists of the two new half-edges. */ - public static net.java.games.jogl.impl.tesselator.GLUhalfEdge __gl_meshMakeEdge(net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUvertex newVertex1 = new net.java.games.jogl.impl.tesselator.GLUvertex(); - net.java.games.jogl.impl.tesselator.GLUvertex newVertex2 = new net.java.games.jogl.impl.tesselator.GLUvertex(); - net.java.games.jogl.impl.tesselator.GLUface newFace = new net.java.games.jogl.impl.tesselator.GLUface(); - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; + public static com.sun.opengl.impl.tessellator.GLUhalfEdge __gl_meshMakeEdge(com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUvertex newVertex1 = new com.sun.opengl.impl.tessellator.GLUvertex(); + com.sun.opengl.impl.tessellator.GLUvertex newVertex2 = new com.sun.opengl.impl.tessellator.GLUvertex(); + com.sun.opengl.impl.tessellator.GLUface newFace = new com.sun.opengl.impl.tessellator.GLUface(); + com.sun.opengl.impl.tessellator.GLUhalfEdge e; e = MakeEdge(mesh.eHead); if (e == null) return null; @@ -292,7 +292,7 @@ class Mesh { * If eDst == eOrg->Onext, the new vertex will have a single edge. * If eDst == eOrg->Oprev, the old vertex will have a single edge. */ - public static boolean __gl_meshSplice(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrg, net.java.games.jogl.impl.tesselator.GLUhalfEdge eDst) { + public static boolean __gl_meshSplice(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrg, com.sun.opengl.impl.tessellator.GLUhalfEdge eDst) { boolean joiningLoops = false; boolean joiningVertices = false; @@ -313,7 +313,7 @@ class Mesh { Splice(eDst, eOrg); if (!joiningVertices) { - net.java.games.jogl.impl.tesselator.GLUvertex newVertex = new net.java.games.jogl.impl.tesselator.GLUvertex(); + com.sun.opengl.impl.tessellator.GLUvertex newVertex = new com.sun.opengl.impl.tessellator.GLUvertex(); /* We split one vertex into two -- the new vertex is eDst.Org. * Make sure the old vertex points to a valid half-edge. @@ -322,7 +322,7 @@ class Mesh { eOrg.Org.anEdge = eOrg; } if (!joiningLoops) { - net.java.games.jogl.impl.tesselator.GLUface newFace = new net.java.games.jogl.impl.tesselator.GLUface(); + com.sun.opengl.impl.tessellator.GLUface newFace = new com.sun.opengl.impl.tessellator.GLUface(); /* We split one loop into two -- the new loop is eDst.Lface. * Make sure the old face points to a valid half-edge. @@ -345,8 +345,8 @@ class Mesh { * plus a few calls to memFree, but this would allocate and delete * unnecessary vertices and faces. */ - static boolean __gl_meshDelete(net.java.games.jogl.impl.tesselator.GLUhalfEdge eDel) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge eDelSym = eDel.Sym; + static boolean __gl_meshDelete(com.sun.opengl.impl.tessellator.GLUhalfEdge eDel) { + com.sun.opengl.impl.tessellator.GLUhalfEdge eDelSym = eDel.Sym; boolean joiningLoops = false; /* First step: disconnect the origin vertex eDel.Org. We make all @@ -367,7 +367,7 @@ class Mesh { Splice(eDel, eDel.Sym.Lnext); if (!joiningLoops) { - net.java.games.jogl.impl.tesselator.GLUface newFace = new net.java.games.jogl.impl.tesselator.GLUface(); + com.sun.opengl.impl.tessellator.GLUface newFace = new com.sun.opengl.impl.tessellator.GLUface(); /* We are splitting one loop into two -- create a new loop for eDel. */ MakeFace(newFace, eDel, eDel.Lface); @@ -405,9 +405,9 @@ class Mesh { * eNew == eOrg.Lnext, and eNew.Dst is a newly created vertex. * eOrg and eNew will have the same left face. */ - static net.java.games.jogl.impl.tesselator.GLUhalfEdge __gl_meshAddEdgeVertex(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrg) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge eNewSym; - net.java.games.jogl.impl.tesselator.GLUhalfEdge eNew = MakeEdge(eOrg); + static com.sun.opengl.impl.tessellator.GLUhalfEdge __gl_meshAddEdgeVertex(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrg) { + com.sun.opengl.impl.tessellator.GLUhalfEdge eNewSym; + com.sun.opengl.impl.tessellator.GLUhalfEdge eNew = MakeEdge(eOrg); eNewSym = eNew.Sym; @@ -417,7 +417,7 @@ class Mesh { /* Set the vertex and face information */ eNew.Org = eOrg.Sym.Org; { - net.java.games.jogl.impl.tesselator.GLUvertex newVertex = new net.java.games.jogl.impl.tesselator.GLUvertex(); + com.sun.opengl.impl.tessellator.GLUvertex newVertex = new com.sun.opengl.impl.tessellator.GLUvertex(); MakeVertex(newVertex, eNewSym, eNew.Org); } @@ -431,9 +431,9 @@ class Mesh { * such that eNew == eOrg.Lnext. The new vertex is eOrg.Sym.Org == eNew.Org. * eOrg and eNew will have the same left face. */ - public static net.java.games.jogl.impl.tesselator.GLUhalfEdge __gl_meshSplitEdge(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrg) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge eNew; - net.java.games.jogl.impl.tesselator.GLUhalfEdge tempHalfEdge = __gl_meshAddEdgeVertex(eOrg); + public static com.sun.opengl.impl.tessellator.GLUhalfEdge __gl_meshSplitEdge(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrg) { + com.sun.opengl.impl.tessellator.GLUhalfEdge eNew; + com.sun.opengl.impl.tessellator.GLUhalfEdge tempHalfEdge = __gl_meshAddEdgeVertex(eOrg); eNew = tempHalfEdge.Sym; @@ -462,10 +462,10 @@ class Mesh { * If (eOrg.Lnext == eDst), the old face is reduced to a single edge. * If (eOrg.Lnext.Lnext == eDst), the old face is reduced to two edges. */ - static net.java.games.jogl.impl.tesselator.GLUhalfEdge __gl_meshConnect(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrg, net.java.games.jogl.impl.tesselator.GLUhalfEdge eDst) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge eNewSym; + static com.sun.opengl.impl.tessellator.GLUhalfEdge __gl_meshConnect(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrg, com.sun.opengl.impl.tessellator.GLUhalfEdge eDst) { + com.sun.opengl.impl.tessellator.GLUhalfEdge eNewSym; boolean joiningLoops = false; - net.java.games.jogl.impl.tesselator.GLUhalfEdge eNew = MakeEdge(eOrg); + com.sun.opengl.impl.tessellator.GLUhalfEdge eNew = MakeEdge(eOrg); eNewSym = eNew.Sym; @@ -488,7 +488,7 @@ class Mesh { eOrg.Lface.anEdge = eNewSym; if (!joiningLoops) { - net.java.games.jogl.impl.tesselator.GLUface newFace = new net.java.games.jogl.impl.tesselator.GLUface(); + com.sun.opengl.impl.tessellator.GLUface newFace = new com.sun.opengl.impl.tessellator.GLUface(); /* We split one loop into two -- the new loop is eNew.Lface */ MakeFace(newFace, eNew, eOrg.Lface); @@ -506,10 +506,10 @@ class Mesh { * An entire mesh can be deleted by zapping its faces, one at a time, * in any order. Zapped faces cannot be used in further mesh operations! */ - static void __gl_meshZapFace(net.java.games.jogl.impl.tesselator.GLUface fZap) { - net.java.games.jogl.impl.tesselator.GLUhalfEdge eStart = fZap.anEdge; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, eNext, eSym; - net.java.games.jogl.impl.tesselator.GLUface fPrev, fNext; + static void __gl_meshZapFace(com.sun.opengl.impl.tessellator.GLUface fZap) { + com.sun.opengl.impl.tessellator.GLUhalfEdge eStart = fZap.anEdge; + com.sun.opengl.impl.tessellator.GLUhalfEdge e, eNext, eSym; + com.sun.opengl.impl.tessellator.GLUface fPrev, fNext; /* walk around face, deleting edges whose right face is also null */ eNext = eStart.Lnext; @@ -551,12 +551,12 @@ class Mesh { /* __gl_meshNewMesh() creates a new mesh with no edges, no vertices, * and no loops (what we usually call a "face"). */ - public static net.java.games.jogl.impl.tesselator.GLUmesh __gl_meshNewMesh() { - net.java.games.jogl.impl.tesselator.GLUvertex v; - net.java.games.jogl.impl.tesselator.GLUface f; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; - net.java.games.jogl.impl.tesselator.GLUhalfEdge eSym; - net.java.games.jogl.impl.tesselator.GLUmesh mesh = new net.java.games.jogl.impl.tesselator.GLUmesh(); + public static com.sun.opengl.impl.tessellator.GLUmesh __gl_meshNewMesh() { + com.sun.opengl.impl.tessellator.GLUvertex v; + com.sun.opengl.impl.tessellator.GLUface f; + com.sun.opengl.impl.tessellator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUhalfEdge eSym; + com.sun.opengl.impl.tessellator.GLUmesh mesh = new com.sun.opengl.impl.tessellator.GLUmesh(); v = mesh.vHead; f = mesh.fHead; @@ -599,13 +599,13 @@ class Mesh { /* __gl_meshUnion( mesh1, mesh2 ) forms the union of all structures in * both meshes, and returns the new mesh (the old meshes are destroyed). */ - static net.java.games.jogl.impl.tesselator.GLUmesh __gl_meshUnion(net.java.games.jogl.impl.tesselator.GLUmesh mesh1, net.java.games.jogl.impl.tesselator.GLUmesh mesh2) { - net.java.games.jogl.impl.tesselator.GLUface f1 = mesh1.fHead; - net.java.games.jogl.impl.tesselator.GLUvertex v1 = mesh1.vHead; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e1 = mesh1.eHead; - net.java.games.jogl.impl.tesselator.GLUface f2 = mesh2.fHead; - net.java.games.jogl.impl.tesselator.GLUvertex v2 = mesh2.vHead; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e2 = mesh2.eHead; + static com.sun.opengl.impl.tessellator.GLUmesh __gl_meshUnion(com.sun.opengl.impl.tessellator.GLUmesh mesh1, com.sun.opengl.impl.tessellator.GLUmesh mesh2) { + com.sun.opengl.impl.tessellator.GLUface f1 = mesh1.fHead; + com.sun.opengl.impl.tessellator.GLUvertex v1 = mesh1.vHead; + com.sun.opengl.impl.tessellator.GLUhalfEdge e1 = mesh1.eHead; + com.sun.opengl.impl.tessellator.GLUface f2 = mesh2.fHead; + com.sun.opengl.impl.tessellator.GLUvertex v2 = mesh2.vHead; + com.sun.opengl.impl.tessellator.GLUhalfEdge e2 = mesh2.eHead; /* Add the faces, vertices, and edges of mesh2 to those of mesh1 */ if (f2.next != f2) { @@ -635,8 +635,8 @@ class Mesh { /* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. */ - static void __gl_meshDeleteMeshZap(net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUface fHead = mesh.fHead; + static void __gl_meshDeleteMeshZap(com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUface fHead = mesh.fHead; while (fHead.next != fHead) { __gl_meshZapFace(fHead.next); @@ -646,10 +646,10 @@ class Mesh { /* __gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. */ - public static void __gl_meshDeleteMesh(net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUface f, fNext; - net.java.games.jogl.impl.tesselator.GLUvertex v, vNext; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, eNext; + public static void __gl_meshDeleteMesh(com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUface f, fNext; + com.sun.opengl.impl.tessellator.GLUvertex v, vNext; + com.sun.opengl.impl.tessellator.GLUhalfEdge e, eNext; for (f = mesh.fHead.next; f != mesh.fHead; f = fNext) { fNext = f.next; @@ -667,13 +667,13 @@ class Mesh { /* __gl_meshCheckMesh( mesh ) checks a mesh for self-consistency. */ - public static void __gl_meshCheckMesh(net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUface fHead = mesh.fHead; - net.java.games.jogl.impl.tesselator.GLUvertex vHead = mesh.vHead; - net.java.games.jogl.impl.tesselator.GLUhalfEdge eHead = mesh.eHead; - net.java.games.jogl.impl.tesselator.GLUface f, fPrev; - net.java.games.jogl.impl.tesselator.GLUvertex v, vPrev; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, ePrev; + public static void __gl_meshCheckMesh(com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUface fHead = mesh.fHead; + com.sun.opengl.impl.tessellator.GLUvertex vHead = mesh.vHead; + com.sun.opengl.impl.tessellator.GLUhalfEdge eHead = mesh.eHead; + com.sun.opengl.impl.tessellator.GLUface f, fPrev; + com.sun.opengl.impl.tessellator.GLUvertex v, vPrev; + com.sun.opengl.impl.tessellator.GLUhalfEdge e, ePrev; fPrev = fHead; for (fPrev = fHead; (f = fPrev.next) != fHead; fPrev = f) { diff --git a/src/net/java/games/jogl/impl/tesselator/Normal.java b/src/classes/com/sun/opengl/impl/tessellator/Normal.java index 900219662..98d4c50a1 100644 --- a/src/net/java/games/jogl/impl/tesselator/Normal.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Normal.java @@ -40,9 +40,10 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; class Normal { private Normal() { @@ -98,18 +99,18 @@ class Normal { return i; } - static void ComputeNormal(GLUtesselatorImpl tess, double[] norm) { - net.java.games.jogl.impl.tesselator.GLUvertex v, v1, v2; + static void ComputeNormal(GLUtessellatorImpl tess, double[] norm) { + com.sun.opengl.impl.tessellator.GLUvertex v, v1, v2; double c, tLen2, maxLen2; double[] maxVal, minVal, d1, d2, tNorm; - net.java.games.jogl.impl.tesselator.GLUvertex[] maxVert, minVert; - net.java.games.jogl.impl.tesselator.GLUvertex vHead = tess.mesh.vHead; + com.sun.opengl.impl.tessellator.GLUvertex[] maxVert, minVert; + com.sun.opengl.impl.tessellator.GLUvertex vHead = tess.mesh.vHead; int i; maxVal = new double[3]; minVal = new double[3]; - minVert = new net.java.games.jogl.impl.tesselator.GLUvertex[3]; - maxVert = new net.java.games.jogl.impl.tesselator.GLUvertex[3]; + minVert = new com.sun.opengl.impl.tessellator.GLUvertex[3]; + maxVert = new com.sun.opengl.impl.tessellator.GLUvertex[3]; d1 = new double[3]; d2 = new double[3]; tNorm = new double[3]; @@ -181,11 +182,11 @@ class Normal { } } - static void CheckOrientation(GLUtesselatorImpl tess) { + static void CheckOrientation(GLUtessellatorImpl tess) { double area; - net.java.games.jogl.impl.tesselator.GLUface f, fHead = tess.mesh.fHead; - net.java.games.jogl.impl.tesselator.GLUvertex v, vHead = tess.mesh.vHead; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUface f, fHead = tess.mesh.fHead; + com.sun.opengl.impl.tessellator.GLUvertex v, vHead = tess.mesh.vHead; + com.sun.opengl.impl.tessellator.GLUhalfEdge e; /* When we compute the normal automatically, we choose the orientation * so that the the sum of the signed areas of all contours is non-negative. @@ -213,8 +214,8 @@ class Normal { /* Determine the polygon normal and project vertices onto the plane * of the polygon. */ - public static void __gl_projectPolygon(GLUtesselatorImpl tess) { - net.java.games.jogl.impl.tesselator.GLUvertex v, vHead = tess.mesh.vHead; + public static void __gl_projectPolygon(GLUtessellatorImpl tess) { + com.sun.opengl.impl.tessellator.GLUvertex v, vHead = tess.mesh.vHead; double w; double[] norm = new double[3]; double[] sUnit, tUnit; diff --git a/src/net/java/games/jogl/impl/tesselator/PriorityQ.java b/src/classes/com/sun/opengl/impl/tessellator/PriorityQ.java index 0f92dcecd..84c00eb82 100644 --- a/src/net/java/games/jogl/impl/tesselator/PriorityQ.java +++ b/src/classes/com/sun/opengl/impl/tessellator/PriorityQ.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; abstract class PriorityQ { public static final int INIT_SIZE = 32; @@ -66,7 +66,7 @@ abstract class PriorityQ { /* Violates modularity, but a little faster */ // #include "geom.h" public static boolean LEQ(Leq leq, Object x, Object y) { - return net.java.games.jogl.impl.tesselator.Geom.VertLeq((net.java.games.jogl.impl.tesselator.GLUvertex) x, (net.java.games.jogl.impl.tesselator.GLUvertex) y); + return com.sun.opengl.impl.tessellator.Geom.VertLeq((com.sun.opengl.impl.tessellator.GLUvertex) x, (com.sun.opengl.impl.tessellator.GLUvertex) y); } static PriorityQ pqNewPriorityQ(Leq leq) { diff --git a/src/net/java/games/jogl/impl/tesselator/PriorityQHeap.java b/src/classes/com/sun/opengl/impl/tessellator/PriorityQHeap.java index b360e37d3..f220a207e 100644 --- a/src/net/java/games/jogl/impl/tesselator/PriorityQHeap.java +++ b/src/classes/com/sun/opengl/impl/tessellator/PriorityQHeap.java @@ -40,27 +40,27 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] handles; +class PriorityQHeap extends com.sun.opengl.impl.tessellator.PriorityQ { + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] handles; int size, max; int freeList; boolean initialized; - net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq; + com.sun.opengl.impl.tessellator.PriorityQ.Leq leq; /* really __gl_pqHeapNewPriorityQ */ - public PriorityQHeap(net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq) { + public PriorityQHeap(com.sun.opengl.impl.tessellator.PriorityQ.Leq leq) { size = 0; - max = net.java.games.jogl.impl.tesselator.PriorityQ.INIT_SIZE; - nodes = new net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[net.java.games.jogl.impl.tesselator.PriorityQ.INIT_SIZE + 1]; + max = com.sun.opengl.impl.tessellator.PriorityQ.INIT_SIZE; + nodes = new com.sun.opengl.impl.tessellator.PriorityQ.PQnode[com.sun.opengl.impl.tessellator.PriorityQ.INIT_SIZE + 1]; for (int i = 0; i < nodes.length; i++) { nodes[i] = new PQnode(); } - handles = new net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[net.java.games.jogl.impl.tesselator.PriorityQ.INIT_SIZE + 1]; + handles = new com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[com.sun.opengl.impl.tessellator.PriorityQ.INIT_SIZE + 1]; for (int i = 0; i < handles.length; i++) { handles[i] = new PQhandleElem(); } @@ -79,8 +79,8 @@ class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { } void FloatDown(int curr) { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] n = nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] h = handles; + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] n = nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] h = handles; int hCurr, hChild; int child; @@ -108,8 +108,8 @@ class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { void FloatUp(int curr) { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] n = nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] h = handles; + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] n = nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] h = handles; int hCurr, hParent; int parent; @@ -150,8 +150,8 @@ class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { curr = ++size; if ((curr * 2) > max) { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] saveNodes = nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] saveHandles = handles; + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] saveNodes = nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] saveHandles = handles; /* If the heap overflows, double its size. */ max <<= 1; @@ -200,8 +200,8 @@ class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { /* really __gl_pqHeapExtractMin */ Object pqExtractMin() { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] n = nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] h = handles; + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] n = nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] h = handles; int hMin = n[1].handle; Object min = h[hMin].key; @@ -222,8 +222,8 @@ class PriorityQHeap extends net.java.games.jogl.impl.tesselator.PriorityQ { /* really __gl_pqHeapDelete */ void pqDelete(int hCurr) { - net.java.games.jogl.impl.tesselator.PriorityQ.PQnode[] n = nodes; - net.java.games.jogl.impl.tesselator.PriorityQ.PQhandleElem[] h = handles; + com.sun.opengl.impl.tessellator.PriorityQ.PQnode[] n = nodes; + com.sun.opengl.impl.tessellator.PriorityQ.PQhandleElem[] h = handles; int curr; assert (hCurr >= 1 && hCurr <= max && h[hCurr].key != null); diff --git a/src/net/java/games/jogl/impl/tesselator/PriorityQSort.java b/src/classes/com/sun/opengl/impl/tessellator/PriorityQSort.java index d37580ff2..426c2d4ca 100644 --- a/src/net/java/games/jogl/impl/tesselator/PriorityQSort.java +++ b/src/classes/com/sun/opengl/impl/tessellator/PriorityQSort.java @@ -35,12 +35,12 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -class PriorityQSort extends net.java.games.jogl.impl.tesselator.PriorityQ { - net.java.games.jogl.impl.tesselator.PriorityQHeap heap; +class PriorityQSort extends com.sun.opengl.impl.tessellator.PriorityQ { + com.sun.opengl.impl.tessellator.PriorityQHeap heap; Object[] keys; // JAVA: 'order' contains indices into the keys array. @@ -49,15 +49,15 @@ class PriorityQSort extends net.java.games.jogl.impl.tesselator.PriorityQ { int[] order; int size, max; boolean initialized; - net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq; + com.sun.opengl.impl.tessellator.PriorityQ.Leq leq; - public PriorityQSort(net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq) { - heap = new net.java.games.jogl.impl.tesselator.PriorityQHeap(leq); + public PriorityQSort(com.sun.opengl.impl.tessellator.PriorityQ.Leq leq) { + heap = new com.sun.opengl.impl.tessellator.PriorityQHeap(leq); - keys = new Object[net.java.games.jogl.impl.tesselator.PriorityQ.INIT_SIZE]; + keys = new Object[com.sun.opengl.impl.tessellator.PriorityQ.INIT_SIZE]; size = 0; - max = net.java.games.jogl.impl.tesselator.PriorityQ.INIT_SIZE; + max = com.sun.opengl.impl.tessellator.PriorityQ.INIT_SIZE; initialized = false; this.leq = leq; } @@ -69,12 +69,12 @@ class PriorityQSort extends net.java.games.jogl.impl.tesselator.PriorityQ { keys = null; } - private static boolean LT(net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq, Object x, Object y) { - return (!net.java.games.jogl.impl.tesselator.PriorityQHeap.LEQ(leq, y, x)); + private static boolean LT(com.sun.opengl.impl.tessellator.PriorityQ.Leq leq, Object x, Object y) { + return (!com.sun.opengl.impl.tessellator.PriorityQHeap.LEQ(leq, y, x)); } - private static boolean GT(net.java.games.jogl.impl.tesselator.PriorityQ.Leq leq, Object x, Object y) { - return (!net.java.games.jogl.impl.tesselator.PriorityQHeap.LEQ(leq, x, y)); + private static boolean GT(com.sun.opengl.impl.tessellator.PriorityQ.Leq leq, Object x, Object y) { + return (!com.sun.opengl.impl.tessellator.PriorityQHeap.LEQ(leq, x, y)); } private static void Swap(int[] array, int a, int b) { @@ -241,7 +241,7 @@ class PriorityQSort extends net.java.games.jogl.impl.tesselator.PriorityQ { sortMin = keys[order[size - 1]]; if (!heap.pqIsEmpty()) { heapMin = heap.pqMinimum(); - if (net.java.games.jogl.impl.tesselator.PriorityQHeap.LEQ(leq, heapMin, sortMin)) { + if (com.sun.opengl.impl.tessellator.PriorityQHeap.LEQ(leq, heapMin, sortMin)) { return heapMin; } } diff --git a/src/net/java/games/jogl/impl/tesselator/Render.java b/src/classes/com/sun/opengl/impl/tessellator/Render.java index 4763992b8..a7a126a4c 100644 --- a/src/net/java/games/jogl/impl/tesselator/Render.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Render.java @@ -40,9 +40,10 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; class Render { private static final boolean USE_OPTIMIZED_CODE_PATH = false; @@ -62,19 +63,19 @@ class Render { public FaceCount() { } - public FaceCount(long size, net.java.games.jogl.impl.tesselator.GLUhalfEdge eStart, renderCallBack render) { + public FaceCount(long size, com.sun.opengl.impl.tessellator.GLUhalfEdge eStart, renderCallBack render) { this.size = size; this.eStart = eStart; this.render = render; } long size; /* number of triangles used */ - net.java.games.jogl.impl.tesselator.GLUhalfEdge eStart; /* edge where this primitive starts */ + com.sun.opengl.impl.tessellator.GLUhalfEdge eStart; /* edge where this primitive starts */ renderCallBack render; }; private static interface renderCallBack { - void render(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUhalfEdge e, long size); + void render(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUhalfEdge e, long size); } /************************ Strips and Fans decomposition ******************/ @@ -86,8 +87,8 @@ class Render { * * The rendering output is provided as callbacks (see the api). */ - public static void __gl_renderMesh(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUface f; + public static void __gl_renderMesh(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUface f; /* Make a list of separate triangles so we can render them all at once */ tess.lonelyTriList = null; @@ -113,7 +114,7 @@ class Render { } - static void RenderMaximumFaceGroup(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUface fOrig) { + static void RenderMaximumFaceGroup(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUface fOrig) { /* We want to find the largest triangle fan or strip of unmarked faces * which includes the given face fOrig. There are 3 possible fans * passing through fOrig (one centered at each vertex), and 3 possible @@ -121,7 +122,7 @@ class Render { * is to try all of these, and take the primitive which uses the most * triangles (a greedy approach). */ - net.java.games.jogl.impl.tesselator.GLUhalfEdge e = fOrig.anEdge; + com.sun.opengl.impl.tessellator.GLUhalfEdge e = fOrig.anEdge; FaceCount max = new FaceCount(); FaceCount newFace = new FaceCount(); @@ -167,17 +168,17 @@ class Render { * more complicated, and we need a general tracking method like the * one here. */ - private static boolean Marked(net.java.games.jogl.impl.tesselator.GLUface f) { + private static boolean Marked(com.sun.opengl.impl.tessellator.GLUface f) { return !f.inside || f.marked; } - private static GLUface AddToTrail(net.java.games.jogl.impl.tesselator.GLUface f, net.java.games.jogl.impl.tesselator.GLUface t) { + private static GLUface AddToTrail(com.sun.opengl.impl.tessellator.GLUface f, com.sun.opengl.impl.tessellator.GLUface t) { f.trail = t; f.marked = true; return f; } - private static void FreeTrail(net.java.games.jogl.impl.tesselator.GLUface t) { + private static void FreeTrail(com.sun.opengl.impl.tessellator.GLUface t) { if (true) { while (t != null) { t.marked = false; @@ -188,14 +189,14 @@ class Render { } } - static FaceCount MaximumFan(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrig) { + static FaceCount MaximumFan(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrig) { /* eOrig.Lface is the face we want to render. We want to find the size * of a maximal fan around eOrig.Org. To do this we just walk around * the origin vertex as far as possible in both directions. */ FaceCount newFace = new FaceCount(0, null, renderFan); - net.java.games.jogl.impl.tesselator.GLUface trail = null; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUface trail = null; + com.sun.opengl.impl.tessellator.GLUhalfEdge e; for (e = eOrig; !Marked(e.Lface); e = e.Onext) { trail = AddToTrail(e.Lface, trail); @@ -216,7 +217,7 @@ class Render { return (n & 0x1L) == 0; } - static FaceCount MaximumStrip(net.java.games.jogl.impl.tesselator.GLUhalfEdge eOrig) { + static FaceCount MaximumStrip(com.sun.opengl.impl.tessellator.GLUhalfEdge eOrig) { /* Here we are looking for a maximal strip that contains the vertices * eOrig.Org, eOrig.Dst, eOrig.Lnext.Dst (in that order or the * reverse, such that all triangles are oriented CCW). @@ -229,8 +230,8 @@ class Render { */ FaceCount newFace = new FaceCount(0, null, renderStrip); long headSize = 0, tailSize = 0; - net.java.games.jogl.impl.tesselator.GLUface trail = null; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e, eTail, eHead; + com.sun.opengl.impl.tessellator.GLUface trail = null; + com.sun.opengl.impl.tessellator.GLUhalfEdge e, eTail, eHead; for (e = eOrig; !Marked(e.Lface); ++tailSize, e = e.Onext) { trail = AddToTrail(e.Lface, trail); @@ -268,7 +269,7 @@ class Render { } private static class RenderTriangle implements renderCallBack { - public void render(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUhalfEdge e, long size) { + public void render(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUhalfEdge e, long size) { /* Just add the triangle to a triangle list, so we can render all * the separate triangles at once. */ @@ -278,11 +279,11 @@ class Render { } - static void RenderLonelyTriangles(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUface f) { + static void RenderLonelyTriangles(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUface f) { /* Now we render all the separate triangles which could not be * grouped into a triangle fan or strip. */ - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; + com.sun.opengl.impl.tessellator.GLUhalfEdge e; int newState; int edgeState = -1; /* force edge state output for first vertex */ @@ -312,7 +313,7 @@ class Render { } private static class RenderFan implements renderCallBack { - public void render(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUhalfEdge e, long size) { + public void render(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUhalfEdge e, long size) { /* Render as many CCW triangles as possible in a fan starting from * edge "e". The fan *should* contain exactly "size" triangles * (otherwise we've goofed up somewhere). @@ -334,7 +335,7 @@ class Render { } private static class RenderStrip implements renderCallBack { - public void render(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUhalfEdge e, long size) { + public void render(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUhalfEdge e, long size) { /* Render as many CCW triangles as possible in a strip starting from * edge "e". The strip *should* contain exactly "size" triangles * (otherwise we've goofed up somewhere). @@ -367,9 +368,9 @@ class Render { * contour for each face marked "inside". The rendering output is * provided as callbacks (see the api). */ - public static void __gl_renderBoundary(GLUtesselatorImpl tess, net.java.games.jogl.impl.tesselator.GLUmesh mesh) { - net.java.games.jogl.impl.tesselator.GLUface f; - net.java.games.jogl.impl.tesselator.GLUhalfEdge e; + public static void __gl_renderBoundary(GLUtessellatorImpl tess, com.sun.opengl.impl.tessellator.GLUmesh mesh) { + com.sun.opengl.impl.tessellator.GLUface f; + com.sun.opengl.impl.tessellator.GLUhalfEdge e; for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) { if (f.inside) { @@ -389,7 +390,7 @@ class Render { private static final int SIGN_INCONSISTENT = 2; - static int ComputeNormal(GLUtesselatorImpl tess, double[] norm, boolean check) + static int ComputeNormal(GLUtessellatorImpl tess, double[] norm, boolean check) /* * If check==false, we compute the polygon normal and place it in norm[]. * If check==true, we check that each triangle in the fan from v0 has a @@ -398,7 +399,7 @@ class Render { * are degenerate return 0; otherwise (no consistent orientation) return * SIGN_INCONSISTENT. */ { - net.java.games.jogl.impl.tesselator.CachedVertex[] v = tess.cache; + com.sun.opengl.impl.tessellator.CachedVertex[] v = tess.cache; // CachedVertex vn = v0 + tess.cacheCount; int vn = tess.cacheCount; // CachedVertex vc; @@ -476,8 +477,8 @@ class Render { * Returns true if the polygon was successfully rendered. The rendering * output is provided as callbacks (see the api). */ - public static boolean __gl_renderCache(GLUtesselatorImpl tess) { - net.java.games.jogl.impl.tesselator.CachedVertex[] v = tess.cache; + public static boolean __gl_renderCache(GLUtessellatorImpl tess) { + com.sun.opengl.impl.tessellator.CachedVertex[] v = tess.cache; // CachedVertex vn = v0 + tess.cacheCount; int vn = tess.cacheCount; // CachedVertex vc; diff --git a/src/net/java/games/jogl/impl/tesselator/Sweep.java b/src/classes/com/sun/opengl/impl/tessellator/Sweep.java index 3674d12e1..901207d31 100644 --- a/src/net/java/games/jogl/impl/tesselator/Sweep.java +++ b/src/classes/com/sun/opengl/impl/tessellator/Sweep.java @@ -40,18 +40,19 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; class Sweep { private Sweep() { } // #ifdef FOR_TRITE_TEST_PROGRAM -// extern void DebugEvent( GLUtesselator *tess ); +// extern void DebugEvent( GLUtessellator *tess ); // #else - private static void DebugEvent(GLUtesselatorImpl tess) { + private static void DebugEvent(GLUtessellatorImpl tess) { } // #endif @@ -103,7 +104,7 @@ class Sweep { return ((ActiveRegion) Dict.dictKey(Dict.dictSucc(r.nodeUp))); } - static boolean EdgeLeq(GLUtesselatorImpl tess, ActiveRegion reg1, ActiveRegion reg2) + static boolean EdgeLeq(GLUtessellatorImpl tess, ActiveRegion reg1, ActiveRegion reg2) /* * Both edges must be directed from right to left (this is the canonical * direction for the upper edge of each region). @@ -145,7 +146,7 @@ class Sweep { } - static void DeleteRegion(GLUtesselatorImpl tess, ActiveRegion reg) { + static void DeleteRegion(GLUtessellatorImpl tess, ActiveRegion reg) { if (reg.fixUpperEdge) { /* It was created with zero winding number, so it better be * deleted with zero winding number (ie. it better not get merged @@ -202,7 +203,7 @@ class Sweep { return reg; } - static ActiveRegion AddRegionBelow(GLUtesselatorImpl tess, + static ActiveRegion AddRegionBelow(GLUtessellatorImpl tess, ActiveRegion regAbove, GLUhalfEdge eNewUp) /* @@ -226,7 +227,7 @@ class Sweep { return regNew; } - static boolean IsWindingInside(GLUtesselatorImpl tess, int n) { + static boolean IsWindingInside(GLUtessellatorImpl tess, int n) { switch (tess.windingRule) { case GLU.GLU_TESS_WINDING_ODD: return (n & 1) != 0; @@ -246,13 +247,13 @@ class Sweep { } - static void ComputeWinding(GLUtesselatorImpl tess, ActiveRegion reg) { + static void ComputeWinding(GLUtessellatorImpl tess, ActiveRegion reg) { reg.windingNumber = RegionAbove(reg).windingNumber + reg.eUp.winding; reg.inside = IsWindingInside(tess, reg.windingNumber); } - static void FinishRegion(GLUtesselatorImpl tess, ActiveRegion reg) + static void FinishRegion(GLUtessellatorImpl tess, ActiveRegion reg) /* * Delete a region from the sweep line. This happens when the upper * and lower chains of a region meet (at a vertex on the sweep line). @@ -269,7 +270,7 @@ class Sweep { } - static GLUhalfEdge FinishLeftRegions(GLUtesselatorImpl tess, + static GLUhalfEdge FinishLeftRegions(GLUtessellatorImpl tess, ActiveRegion regFirst, ActiveRegion regLast) /* * We are given a vertex with one or more left-going edges. All affected @@ -324,7 +325,7 @@ class Sweep { } - static void AddRightEdges(GLUtesselatorImpl tess, ActiveRegion regUp, + static void AddRightEdges(GLUtessellatorImpl tess, ActiveRegion regUp, GLUhalfEdge eFirst, GLUhalfEdge eLast, GLUhalfEdge eTopLeft, boolean cleanUp) /* @@ -395,7 +396,7 @@ class Sweep { } - static void CallCombine(GLUtesselatorImpl tess, GLUvertex isect, + static void CallCombine(GLUtessellatorImpl tess, GLUvertex isect, Object[] data, float[] weights, boolean needed) { double[] coords = new double[3]; @@ -421,7 +422,7 @@ class Sweep { } } - static void SpliceMergeVertices(GLUtesselatorImpl tess, GLUhalfEdge e1, + static void SpliceMergeVertices(GLUtessellatorImpl tess, GLUhalfEdge e1, GLUhalfEdge e2) /* * Two vertices with idential coordinates are combined into one. @@ -456,7 +457,7 @@ class Sweep { } - static void GetIntersectData(GLUtesselatorImpl tess, GLUvertex isect, + static void GetIntersectData(GLUtessellatorImpl tess, GLUvertex isect, GLUvertex orgUp, GLUvertex dstUp, GLUvertex orgLo, GLUvertex dstLo) /* @@ -483,7 +484,7 @@ class Sweep { CallCombine(tess, isect, data, weights, true); } - static boolean CheckForRightSplice(GLUtesselatorImpl tess, ActiveRegion regUp) + static boolean CheckForRightSplice(GLUtessellatorImpl tess, ActiveRegion regUp) /* * Check the upper and lower edge of "regUp", to make sure that the * eUp.Org is above eLo, or eLo.Org is below eUp (depending on which @@ -539,7 +540,7 @@ class Sweep { return true; } - static boolean CheckForLeftSplice(GLUtesselatorImpl tess, ActiveRegion regUp) + static boolean CheckForLeftSplice(GLUtessellatorImpl tess, ActiveRegion regUp) /* * Check the upper and lower edge of "regUp", to make sure that the * eUp.Sym.Org is above eLo, or eLo.Sym.Org is below eUp (depending on which @@ -588,7 +589,7 @@ class Sweep { } - static boolean CheckForIntersect(GLUtesselatorImpl tess, ActiveRegion regUp) + static boolean CheckForIntersect(GLUtessellatorImpl tess, ActiveRegion regUp) /* * Check the upper and lower edges of the given region to see if * they intersect. If so, create the intersection and add it @@ -741,7 +742,7 @@ class Sweep { return false; } - static void WalkDirtyRegions(GLUtesselatorImpl tess, ActiveRegion regUp) + static void WalkDirtyRegions(GLUtessellatorImpl tess, ActiveRegion regUp) /* * When the upper or lower edge of any region changes, the region is * marked "dirty". This routine walks through all the dirty regions @@ -826,7 +827,7 @@ class Sweep { } - static void ConnectRightVertex(GLUtesselatorImpl tess, ActiveRegion regUp, + static void ConnectRightVertex(GLUtessellatorImpl tess, ActiveRegion regUp, GLUhalfEdge eBottomLeft) /* * Purpose: connect a "right" vertex vEvent (one where all edges go left) @@ -919,7 +920,7 @@ class Sweep { */ private static final boolean TOLERANCE_NONZERO = false; - static void ConnectLeftDegenerate(GLUtesselatorImpl tess, + static void ConnectLeftDegenerate(GLUtessellatorImpl tess, ActiveRegion regUp, GLUvertex vEvent) /* * The event vertex lies exacty on an already-processed edge or vertex. @@ -978,7 +979,7 @@ class Sweep { } - static void ConnectLeftVertex(GLUtesselatorImpl tess, GLUvertex vEvent) + static void ConnectLeftVertex(GLUtessellatorImpl tess, GLUvertex vEvent) /* * Purpose: connect a "left" vertex (one where both edges go right) * to the processed portion of the mesh. Let R be the active region @@ -1044,7 +1045,7 @@ class Sweep { } - static void SweepEvent(GLUtesselatorImpl tess, GLUvertex vEvent) + static void SweepEvent(GLUtessellatorImpl tess, GLUvertex vEvent) /* * Does everything necessary when the sweep line crosses a vertex. * Updates the mesh and the edge dictionary. @@ -1103,7 +1104,7 @@ class Sweep { */ private static final double SENTINEL_COORD = (4.0 * GLU.GLU_TESS_MAX_COORD); - static void AddSentinel(GLUtesselatorImpl tess, double t) + static void AddSentinel(GLUtessellatorImpl tess, double t) /* * We add two sentinel edges above and below all other edges, * to avoid special cases at the top and bottom. @@ -1132,7 +1133,7 @@ class Sweep { } - static void InitEdgeDict(final GLUtesselatorImpl tess) + static void InitEdgeDict(final GLUtessellatorImpl tess) /* * We maintain an ordering of edge intersections with the sweep line. * This order is maintained in a dynamic dictionary. @@ -1150,7 +1151,7 @@ class Sweep { } - static void DoneEdgeDict(GLUtesselatorImpl tess) { + static void DoneEdgeDict(GLUtessellatorImpl tess) { ActiveRegion reg; int fixedEdges = 0; @@ -1173,7 +1174,7 @@ class Sweep { } - static void RemoveDegenerateEdges(GLUtesselatorImpl tess) + static void RemoveDegenerateEdges(GLUtessellatorImpl tess) /* * Remove zero-length edges, and contours with fewer than 3 vertices. */ { @@ -1210,7 +1211,7 @@ class Sweep { } } - static boolean InitPriorityQ(GLUtesselatorImpl tess) + static boolean InitPriorityQ(GLUtessellatorImpl tess) /* * Insert all vertices into the priority queue which determines the * order in which vertices cross the sweep line. @@ -1241,7 +1242,7 @@ class Sweep { } - static void DonePriorityQ(GLUtesselatorImpl tess) { + static void DonePriorityQ(GLUtessellatorImpl tess) { tess.pq.pqDeletePriorityQ(); /* __gl_pqSortDeletePriorityQ */ } @@ -1279,7 +1280,7 @@ class Sweep { return true; } - public static boolean __gl_computeInterior(GLUtesselatorImpl tess) + public static boolean __gl_computeInterior(GLUtessellatorImpl tess) /* * __gl_computeInterior( tess ) computes the planar arrangement specified * by the given contours, and further subdivides this arrangement diff --git a/src/net/java/games/jogl/impl/tesselator/TessMono.java b/src/classes/com/sun/opengl/impl/tessellator/TessMono.java index 9e55e1194..ef2230c35 100644 --- a/src/net/java/games/jogl/impl/tesselator/TessMono.java +++ b/src/classes/com/sun/opengl/impl/tessellator/TessMono.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class TessMono { /* __gl_meshTessellateMonoRegion( face ) tessellates a monotone region diff --git a/src/net/java/games/jogl/impl/tesselator/TessState.java b/src/classes/com/sun/opengl/impl/tessellator/TessState.java index 6d89d4678..5e96a20a1 100644 --- a/src/net/java/games/jogl/impl/tesselator/TessState.java +++ b/src/classes/com/sun/opengl/impl/tessellator/TessState.java @@ -40,7 +40,7 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl.impl.tesselator; +package com.sun.opengl.impl.tessellator; class TessState { diff --git a/src/net/java/games/jogl/impl/GLDrawableHelper.java b/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java index dd5d7c17f..d57ddec2a 100644 --- a/src/net/java/games/jogl/impl/GLDrawableHelper.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java @@ -37,48 +37,61 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl; +package com.sun.opengl.impl.windows; -import java.util.*; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -/** Encapsulates the implementation of most of the GLDrawable's - methods to be able to share it between GLCanvas and GLJPanel. */ +public class WindowsDummyGLDrawable extends WindowsGLDrawable { + private long hwnd; -public class GLDrawableHelper { - private volatile List listeners = new ArrayList(); - - public GLDrawableHelper() { + public WindowsDummyGLDrawable() { + super(null, new GLCapabilities(), null); + // All entries to CreateDummyWindow must synchronize on one object + // to avoid accidentally registering the dummy window class twice + synchronized (WindowsDummyGLDrawable.class) { + hwnd = WGL.CreateDummyWindow(0, 0, 1, 1); + } + hdc = WGL.GetDC(hwnd); + // Choose a (hopefully hardware-accelerated) OpenGL pixel format for this device context + GLCapabilities caps = new GLCapabilities(); + caps.setDepthBits(16); + PIXELFORMATDESCRIPTOR pfd = glCapabilities2PFD(caps, true); + int pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); + if ((pixelFormat == 0) || + (!WGL.SetPixelFormat(hdc, pixelFormat, pfd))) { + destroy(); + } } - public synchronized void addGLEventListener(GLEventListener listener) { - List newListeners = (List) ((ArrayList) listeners).clone(); - newListeners.add(listener); - listeners = newListeners; + public void setSize(int width, int height) { } - - public synchronized void removeGLEventListener(GLEventListener listener) { - List newListeners = (List) ((ArrayList) listeners).clone(); - newListeners.remove(listener); - listeners = newListeners; + + public int getWidth() { + return 1; } - public void init(GLDrawable drawable) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - ((GLEventListener) iter.next()).init(drawable); - } + public int getHeight() { + return 1; } - public void display(GLDrawable drawable) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - ((GLEventListener) iter.next()).display(drawable); + public GLContext createContext(GLContext shareWith) { + if (hdc == 0) { + // Construction failed + return null; } + return new WindowsGLContext(this, shareWith); } - public void reshape(GLDrawable drawable, - int x, int y, int width, int height) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - ((GLEventListener) iter.next()).reshape(drawable, x, y, width, height); + public void destroy() { + if (hdc != 0) { + WGL.ReleaseDC(hwnd, hdc); + hdc = 0; + } + if (hwnd != 0) { + WGL.ShowWindow(hwnd, WGL.SW_HIDE); + WGL.DestroyWindow(hwnd); + hwnd = 0; } } } diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java new file mode 100755 index 000000000..694aa6b0d --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java @@ -0,0 +1,77 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsExternalGLContext extends WindowsGLContext { + private boolean firstMakeCurrent = true; + private boolean created = true; + + public WindowsExternalGLContext() { + super(null, null); + hglrc = WGL.wglGetCurrentContext(); + GLContextShareSet.contextCreated(this); + resetGLFunctionAvailability(); + } + + protected int makeCurrentImpl() throws GLException { + if (firstMakeCurrent) { + firstMakeCurrent = false; + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + created = false; + GLContextShareSet.contextDestroyed(this); + } + + public boolean isCreated() { + return created; + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLDrawable.java new file mode 100755 index 000000000..f934c1d23 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLDrawable.java @@ -0,0 +1,69 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsExternalGLDrawable extends WindowsGLDrawable { + public WindowsExternalGLDrawable() { + super(null, new GLCapabilities(), null); + hdc = WGL.wglGetCurrentDC(); + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsGLContext(this, shareWith); + } + + public void setSize(int newWidth, int newHeight) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } + + public void destroy() { + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java new file mode 100644 index 000000000..d4b10dbfb --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java @@ -0,0 +1,286 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsGLContext extends GLContextImpl { + protected WindowsGLDrawable drawable; + protected long hglrc; + private boolean wglGetExtensionsStringEXTInitialized; + private boolean wglGetExtensionsStringEXTAvailable; + private static final Map/*<String, String>*/ functionNameMap; + private static final Map/*<String, String>*/ extensionNameMap; + private WGLExt wglExt; + // Table that holds the addresses of the native C-language entry points for + // WGL extension functions. + private WGLExtProcAddressTable wglExtProcAddressTable; + + static { + functionNameMap = new HashMap(); + functionNameMap.put("glAllocateMemoryNV", "wglAllocateMemoryNV"); + functionNameMap.put("glFreeMemoryNV", "wglFreeMemoryNV"); + + extensionNameMap = new HashMap(); + extensionNameMap.put("GL_ARB_pbuffer", "WGL_ARB_pbuffer"); + extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format"); + } + + public WindowsGLContext(WindowsGLDrawable drawable, + GLContext shareWith) { + super(shareWith); + this.drawable = drawable; + } + + public Object getPlatformGLExtensions() { + return getWGLExt(); + } + + public WGLExt getWGLExt() { + if (wglExt == null) { + wglExt = new WGLExtImpl(this); + } + return wglExt; + } + + public GLDrawable getGLDrawable() { + return drawable; + } + + protected String mapToRealGLFunctionName(String glFunctionName) { + String lookup = (String) functionNameMap.get(glFunctionName); + if (lookup != null) { + return lookup; + } + return glFunctionName; + } + + protected String mapToRealGLExtensionName(String glExtensionName) { + String lookup = (String) extensionNameMap.get(glExtensionName); + if (lookup != null) { + return lookup; + } + return glExtensionName; + } + + /** + * Creates and initializes an appropriate OpenGL context. Should only be + * called by {@link #makeCurrentImpl()}. + */ + protected void create() { + if (drawable.getHDC() == 0) { + throw new GLException("Internal error: attempted to create OpenGL context without an associated drawable"); + } + hglrc = WGL.wglCreateContext(drawable.getHDC()); + if (hglrc == 0) { + throw new GLException("Unable to create OpenGL context for device context " + toHexString(drawable.getHDC())); + } + // Windows can set up sharing of display lists after creation time + WindowsGLContext other = (WindowsGLContext) GLContextShareSet.getShareContext(this); + long hglrc2 = 0; + if (other != null) { + hglrc2 = other.getHGLRC(); + if (hglrc2 == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + if (!WGL.wglShareLists(hglrc2, hglrc)) { + throw new GLException("wglShareLists(" + toHexString(hglrc2) + + ", " + toHexString(hglrc) + ") failed: error code " + + WGL.GetLastError()); + } + } + GLContextShareSet.contextCreated(this); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created OpenGL context " + toHexString(hglrc) + " for " + this + ", device context " + toHexString(drawable.getHDC()) + ", sharing with " + toHexString(hglrc2)); + } + } + + protected int makeCurrentImpl() throws GLException { + boolean created = false; + if (hglrc == 0) { + create(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); + } + created = true; + } + + boolean skipMakeCurrent = false; + if (NO_FREE) { + if (WGL.wglGetCurrentContext() == hglrc) { + if (DEBUG && VERBOSE) { + System.err.println(getThreadName() + ": skipping wglMakeCurrent because context already current"); + } + skipMakeCurrent = true; + } + } + + if (!skipMakeCurrent) { + if (!WGL.wglMakeCurrent(drawable.getHDC(), hglrc)) { + throw new GLException("Error making context current: " + WGL.GetLastError()); + } else { + if (DEBUG && VERBOSE) { + System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getHDC()) + + ", hglrc " + toHexString(hglrc) + ") succeeded"); + } + } + } + + if (created) { + resetGLFunctionAvailability(); + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } + + protected void releaseImpl() throws GLException { + if (!NO_FREE) { + if (!WGL.wglMakeCurrent(0, 0)) { + throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError()); + } + } + } + + protected void destroyImpl() throws GLException { + if (hglrc != 0) { + if (!WGL.wglDeleteContext(hglrc)) { + throw new GLException("Unable to delete OpenGL context"); + } + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + toHexString(hglrc)); + } + hglrc = 0; + GLContextShareSet.contextDestroyed(this); + } + } + + public boolean isCreated() { + return (hglrc != 0); + } + + protected void resetGLFunctionAvailability() { + super.resetGLFunctionAvailability(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing WGL extension address table for " + this); + } + resetProcAddressTable(getWGLExtProcAddressTable()); + } + + public WGLExtProcAddressTable getWGLExtProcAddressTable() { + if (wglExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + wglExtProcAddressTable = new WGLExtProcAddressTable(); + } + return wglExtProcAddressTable; + } + + public String getPlatformExtensionsString() { + if (!wglGetExtensionsStringEXTInitialized) { + wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); + wglGetExtensionsStringEXTInitialized = true; + } + if (wglGetExtensionsStringEXTAvailable) { + return getWGLExt().wglGetExtensionsStringEXT(); + } else { + return ""; + } + } + + protected boolean isFunctionAvailable(String glFunctionName) + { + boolean available = super.isFunctionAvailable(glFunctionName); + + // Sanity check for implementations that use proc addresses for run-time + // linking: if the function IS available, then make sure there's a proc + // address for it if it's an extension or not part of the OpenGL 1.1 core + // (post GL 1.1 functions are run-time linked on windows). + assert(!available || + (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || + FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) + ); + + return available; + } + + public void setSwapInterval(int interval) { + // FIXME: make the context current first? Currently assumes that + // will not be necessary. Make the caller do this? + WGLExt wglExt = getWGLExt(); + if (wglExt.isExtensionAvailable("WGL_EXT_swap_control")) { + wglExt.wglSwapIntervalEXT(interval); + } + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return getWGLExt().wglAllocateMemoryNV(arg0, arg1, arg2, arg3); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + protected long getHGLRC() { + return hglrc; + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java new file mode 100644 index 000000000..ae95f5505 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java @@ -0,0 +1,502 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public abstract class WindowsGLDrawable extends GLDrawableImpl { + protected static final boolean DEBUG = Debug.debug("WindowsGLDrawable"); + + protected long hdc; + protected Component component; + protected GLCapabilities capabilities; + protected GLCapabilitiesChooser chooser; + protected boolean pixelFormatChosen; + + protected static final int MAX_PFORMATS = 256; + protected static final int MAX_ATTRIBS = 256; + + public WindowsGLDrawable(Component component, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + this.component = component; + this.capabilities = (GLCapabilities) capabilities.clone(); + this.chooser = chooser; + } + + public void setRealized(boolean val) { + throw new GLException("Should not call this (should only be called for onscreen GLDrawables)"); + } + + public void destroy() { + throw new GLException("Should not call this (should only be called for offscreen GLDrawables)"); + } + + public void swapBuffers() throws GLException { + } + + public long getHDC() { + return hdc; + } + + public void choosePixelFormat(boolean onscreen) { + PIXELFORMATDESCRIPTOR pfd = null; + int pixelFormat = 0; + if (onscreen) { + if (WGL.GetPixelFormat(hdc) != 0) { + // The Java2D/OpenGL pipeline probably already set a pixel + // format for this canvas. + if (DEBUG) { + System.err.println("NOTE: pixel format already chosen (by Java2D/OpenGL pipeline?) for window: " + + WGL.GetPixelFormat(hdc)); + } + pixelFormatChosen = true; + return; + } + + GLCapabilities[] availableCaps = null; + int numFormats = 0; + pfd = newPixelFormatDescriptor(); + GraphicsConfiguration config = component.getGraphicsConfiguration(); + GraphicsDevice device = config.getDevice(); + // Produce a recommended pixel format selection for the GLCapabilitiesChooser. + // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available + WindowsGLDrawable dummyDrawable = null; + GLContextImpl dummyContext = null; + WGLExt dummyWGLExt = null; + if (capabilities.getSampleBuffers()) { + dummyDrawable = new WindowsDummyGLDrawable(); + dummyContext = (GLContextImpl) dummyDrawable.createContext(null); + if (dummyContext != null) { + dummyContext.makeCurrent(); + dummyWGLExt = (WGLExt) dummyContext.getPlatformGLExtensions(); + } + } + int recommendedPixelFormat = -1; + boolean haveWGLChoosePixelFormatARB = false; + boolean haveWGLARBMultisample = false; + boolean gotAvailableCaps = false; + if (dummyWGLExt != null) { + haveWGLChoosePixelFormatARB = dummyWGLExt.isExtensionAvailable("WGL_ARB_pixel_format"); + haveWGLARBMultisample = dummyWGLExt.isExtensionAvailable("WGL_ARB_multisample"); + + try { + if (haveWGLChoosePixelFormatARB) { + int[] iattributes = new int [2 * MAX_ATTRIBS]; + int[] iresults = new int [2 * MAX_ATTRIBS]; + float[] fattributes = new float[2 * MAX_ATTRIBS]; + int niattribs = 0; + int nfattribs = 0; + iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB; + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + if (capabilities.getDoubleBuffered()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB; + if (capabilities.getStereo()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = capabilities.getDepthBits(); + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = capabilities.getRedBits(); + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = capabilities.getGreenBits(); + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = capabilities.getBlueBits(); + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = capabilities.getAlphaBits(); + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = capabilities.getStencilBits(); + if (capabilities.getAccumRedBits() > 0 || + capabilities.getAccumGreenBits() > 0 || + capabilities.getAccumBlueBits() > 0 || + capabilities.getAccumAlphaBits() > 0) { + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BITS_ARB; + iattributes[niattribs++] = (capabilities.getAccumRedBits() + + capabilities.getAccumGreenBits() + + capabilities.getAccumBlueBits() + + capabilities.getAccumAlphaBits()); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumRedBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumGreenBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumBlueBits(); + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumAlphaBits(); + } + if (haveWGLARBMultisample) { + if (capabilities.getSampleBuffers()) { + iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB; + iattributes[niattribs++] = capabilities.getNumSamples(); + } + } + + int[] pformats = new int[MAX_PFORMATS]; + int[] numFormatsTmp = new int[1]; + if (dummyWGLExt.wglChoosePixelFormatARB(hdc, + iattributes, 0, + fattributes, 0, + MAX_PFORMATS, + pformats, 0, + numFormatsTmp, 0)) { + numFormats = numFormatsTmp[0]; + if (numFormats > 0) { + // Remove one-basing of pixel format (added on later) + recommendedPixelFormat = pformats[0] - 1; + if (DEBUG) { + System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); + } + } + } else { + if (DEBUG) { + System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); + Thread.dumpStack(); + } + } + if (DEBUG) { + if (recommendedPixelFormat < 0) { + System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); + if (capabilities.getSampleBuffers()) { + System.err.print(" for multisampled GLCapabilities"); + } + System.err.println(); + } + } + + // Produce a list of GLCapabilities to give to the + // GLCapabilitiesChooser. + // Use wglGetPixelFormatAttribivARB instead of + // DescribePixelFormat to get higher-precision information + // about the pixel format (should make the GLCapabilities + // more precise as well...i.e., remove the + // "HardwareAccelerated" bit, which is basically + // meaningless, and put in whether it can render to a + // window, to a pbuffer, or to a pixmap) + niattribs = 0; + iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB; + if (dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) { + numFormats = iresults[0]; + // Should we be filtering out the pixel formats which aren't + // applicable, as we are doing here? + // We don't have enough information in the GLCapabilities to + // represent those that aren't... + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB; + iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB; + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB; + if (haveWGLARBMultisample) { + iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB; + } + + availableCaps = new GLCapabilities[numFormats]; + for (int i = 0; i < numFormats; i++) { + if (!dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) { + throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); + } + availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); + } + gotAvailableCaps = true; + } else { + int lastErr = WGL.GetLastError(); + // Intel Extreme graphics fails with a zero error code + if (lastErr != 0) { + throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError()); + } + } + } + } finally { + dummyContext.release(); + dummyContext.destroy(); + dummyDrawable.destroy(); + } + } + + // Fallback path for older cards, in particular Intel Extreme motherboard graphics + if (!gotAvailableCaps) { + if (DEBUG) { + if (!capabilities.getSampleBuffers()) { + System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested"); + } else { + System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB"); + } + } + pfd = glCapabilities2PFD(capabilities, onscreen); + // Remove one-basing of pixel format (added on later) + recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd) - 1; + + numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null); + if (numFormats == 0) { + throw new GLException("Unable to enumerate pixel formats of window for GLCapabilitiesChooser"); + } + availableCaps = new GLCapabilities[numFormats]; + for (int i = 0; i < numFormats; i++) { + if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) { + throw new GLException("Error describing pixel format " + (1 + i) + " of device context"); + } + availableCaps[i] = pfd2GLCapabilities(pfd); + } + } + + // Supply information to chooser + pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat); + if ((pixelFormat < 0) || (pixelFormat >= numFormats)) { + throw new GLException("Invalid result " + pixelFormat + + " from GLCapabilitiesChooser (should be between 0 and " + + (numFormats - 1) + ")"); + } + if (DEBUG) { + System.err.println(getThreadName() + ": Chosen pixel format (" + pixelFormat + "):"); + System.err.println(availableCaps[pixelFormat]); + } + pixelFormat += 1; // one-base the index + if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) { + throw new GLException("Error re-describing the chosen pixel format: " + WGL.GetLastError()); + } + } else { + // For now, use ChoosePixelFormat for offscreen surfaces until + // we figure out how to properly choose an offscreen- + // compatible pixel format + pfd = glCapabilities2PFD(capabilities, onscreen); + pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); + } + if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) { + int lastError = WGL.GetLastError(); + if (DEBUG) { + System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() + + ", current DC = " + WGL.wglGetCurrentDC()); + System.err.println(getThreadName() + ": GetPixelFormat(hdc " + toHexString(hdc) + ") returns " + WGL.GetPixelFormat(hdc)); + } + throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError); + } + pixelFormatChosen = true; + } + + static PIXELFORMATDESCRIPTOR glCapabilities2PFD(GLCapabilities caps, boolean onscreen) { + int colorDepth = (caps.getRedBits() + + caps.getGreenBits() + + caps.getBlueBits()); + if (colorDepth < 15) { + throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); + } + PIXELFORMATDESCRIPTOR pfd = newPixelFormatDescriptor(); + int pfdFlags = (WGL.PFD_SUPPORT_OPENGL | + WGL.PFD_GENERIC_ACCELERATED); + if (caps.getDoubleBuffered()) { + pfdFlags |= WGL.PFD_DOUBLEBUFFER; + } + if (onscreen) { + pfdFlags |= WGL.PFD_DRAW_TO_WINDOW; + } else { + pfdFlags |= WGL.PFD_DRAW_TO_BITMAP; + } + pfd.dwFlags(pfdFlags); + pfd.iPixelType((byte) WGL.PFD_TYPE_RGBA); + pfd.cColorBits((byte) colorDepth); + pfd.cRedBits ((byte) caps.getRedBits()); + pfd.cGreenBits((byte) caps.getGreenBits()); + pfd.cBlueBits ((byte) caps.getBlueBits()); + pfd.cAlphaBits((byte) caps.getAlphaBits()); + int accumDepth = (caps.getAccumRedBits() + + caps.getAccumGreenBits() + + caps.getAccumBlueBits()); + pfd.cAccumBits ((byte) accumDepth); + pfd.cAccumRedBits ((byte) caps.getAccumRedBits()); + pfd.cAccumGreenBits((byte) caps.getAccumGreenBits()); + pfd.cAccumBlueBits ((byte) caps.getAccumBlueBits()); + pfd.cAccumAlphaBits((byte) caps.getAccumAlphaBits()); + pfd.cDepthBits((byte) caps.getDepthBits()); + pfd.cStencilBits((byte) caps.getStencilBits()); + pfd.iLayerType((byte) WGL.PFD_MAIN_PLANE); + return pfd; + } + + static PIXELFORMATDESCRIPTOR newPixelFormatDescriptor() { + PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR(); + pfd.nSize((short) pfd.size()); + pfd.nVersion((short) 1); + return pfd; + } + + static GLCapabilities pfd2GLCapabilities(PIXELFORMATDESCRIPTOR pfd) { + if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) { + return null; + } + GLCapabilities res = new GLCapabilities(); + res.setRedBits (pfd.cRedBits()); + res.setGreenBits (pfd.cGreenBits()); + res.setBlueBits (pfd.cBlueBits()); + res.setAlphaBits (pfd.cAlphaBits()); + res.setAccumRedBits (pfd.cAccumRedBits()); + res.setAccumGreenBits(pfd.cAccumGreenBits()); + res.setAccumBlueBits (pfd.cAccumBlueBits()); + res.setAccumAlphaBits(pfd.cAccumAlphaBits()); + res.setDepthBits (pfd.cDepthBits()); + res.setStencilBits (pfd.cStencilBits()); + res.setDoubleBuffered((pfd.dwFlags() & WGL.PFD_DOUBLEBUFFER) != 0); + res.setStereo ((pfd.dwFlags() & WGL.PFD_STEREO) != 0); + res.setHardwareAccelerated(((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) || + ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0)); + return res; + } + + static GLCapabilities iattributes2GLCapabilities(int[] iattribs, + int[] iresults, + int niattribs, + boolean requireRenderToWindow) { + GLCapabilities res = new GLCapabilities(); + for (int i = 0; i < niattribs; i++) { + switch (iattribs[i]) { + case WGLExt.WGL_DRAW_TO_WINDOW_ARB: + if (iresults[i] != GL.GL_TRUE) + return null; + break; + + case WGLExt.WGL_ACCELERATION_ARB: + res.setHardwareAccelerated(iresults[i] == WGLExt.WGL_FULL_ACCELERATION_ARB); + break; + + case WGLExt.WGL_SUPPORT_OPENGL_ARB: + if (iresults[i] != GL.GL_TRUE) + return null; + break; + + case WGLExt.WGL_DEPTH_BITS_ARB: + res.setDepthBits(iresults[i]); + break; + + case WGLExt.WGL_STENCIL_BITS_ARB: + res.setStencilBits(iresults[i]); + break; + + case WGLExt.WGL_DOUBLE_BUFFER_ARB: + res.setDoubleBuffered(iresults[i] == GL.GL_TRUE); + break; + + case WGLExt.WGL_STEREO_ARB: + res.setStereo(iresults[i] == GL.GL_TRUE); + break; + + case WGLExt.WGL_PIXEL_TYPE_ARB: + if (iresults[i] != WGLExt.WGL_TYPE_RGBA_ARB) + return null; + break; + + case WGLExt.WGL_RED_BITS_ARB: + res.setRedBits(iresults[i]); + break; + + case WGLExt.WGL_GREEN_BITS_ARB: + res.setGreenBits(iresults[i]); + break; + + case WGLExt.WGL_BLUE_BITS_ARB: + res.setBlueBits(iresults[i]); + break; + + case WGLExt.WGL_ALPHA_BITS_ARB: + res.setAlphaBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_RED_BITS_ARB: + res.setAccumRedBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_GREEN_BITS_ARB: + res.setAccumGreenBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_BLUE_BITS_ARB: + res.setAccumBlueBits(iresults[i]); + break; + + case WGLExt.WGL_ACCUM_ALPHA_BITS_ARB: + res.setAccumAlphaBits(iresults[i]); + break; + + case WGLExt.WGL_SAMPLE_BUFFERS_ARB: + res.setSampleBuffers(iresults[i] == GL.GL_TRUE); + break; + + case WGLExt.WGL_SAMPLES_ARB: + res.setNumSamples(iresults[i]); + break; + + default: + throw new GLException("Unknown pixel format attribute " + iattribs[i]); + } + } + return res; + } + + protected static String getThreadName() { + return Thread.currentThread().getName(); + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java new file mode 100644 index 000000000..ae48be999 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java @@ -0,0 +1,223 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Rectangle; +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.List; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { + private static final boolean DEBUG = Debug.debug("WindowsGLDrawableFactory"); + private static final boolean VERBOSE = Debug.verbose(); + + // Handle to GLU32.dll + // FIXME: this should go away once we delete support for the C GLU library + private long hglu32; + + static { + NativeLibLoader.load(); + } + + public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GraphicsDevice device) { + return null; + } + + public GLDrawable getGLDrawable(Object target, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + if (!(target instanceof Component)) { + throw new IllegalArgumentException("GLDrawables not supported for objects of type " + + target.getClass().getName() + " (only Components are supported in this implementation)"); + } + if (capabilities == null) { + capabilities = new GLCapabilities(); + } + if (chooser == null) { + chooser = new DefaultGLCapabilitiesChooser(); + } + return new WindowsOnscreenGLDrawable((Component) target, capabilities, chooser); + } + + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + return new WindowsOffscreenGLDrawable(capabilities, chooser); + } + + private boolean pbufferSupportInitialized = false; + private boolean canCreateGLPbuffer = false; + public boolean canCreateGLPbuffer() { + if (!pbufferSupportInitialized) { + Runnable r = new Runnable() { + public void run() { + WindowsDummyGLDrawable dummyDrawable = new WindowsDummyGLDrawable(); + GLContext dummyContext = dummyDrawable.createContext(null); + if (dummyContext != null) { + GLContext lastContext = GLContext.getCurrent(); + if (lastContext != null) { + lastContext.release(); + } + dummyContext.makeCurrent(); + GL dummyGL = dummyContext.getGL(); + canCreateGLPbuffer = dummyGL.isExtensionAvailable("GL_ARB_pbuffer"); + pbufferSupportInitialized = true; + dummyContext.release(); + dummyContext.destroy(); + dummyDrawable.destroy(); + if (lastContext != null) { + lastContext.makeCurrent(); + } + } + } + }; + maybeDoSingleThreadedWorkaround(r); + } + return canCreateGLPbuffer; + } + + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final int initialWidth, + final int initialHeight, + final GLContext shareWith) { + if (!canCreateGLPbuffer()) { + throw new GLException("Pbuffer support not available with current graphics card"); + } + final List returnList = new ArrayList(); + Runnable r = new Runnable() { + public void run() { + WindowsDummyGLDrawable dummyDrawable = new WindowsDummyGLDrawable(); + WindowsGLContext dummyContext = (WindowsGLContext) dummyDrawable.createContext(null); + GLContext lastContext = GLContext.getCurrent(); + if (lastContext != null) { + lastContext.release(); + } + dummyContext.makeCurrent(); + WGLExt dummyWGLExt = dummyContext.getWGLExt(); + try { + WindowsPbufferGLDrawable pbufferDrawable = new WindowsPbufferGLDrawable(capabilities, + initialWidth, + initialHeight, + dummyDrawable, + dummyWGLExt); + GLPbufferImpl pbuffer = new GLPbufferImpl(pbufferDrawable, shareWith); + returnList.add(pbuffer); + dummyContext.release(); + dummyContext.destroy(); + dummyDrawable.destroy(); + } finally { + if (lastContext != null) { + lastContext.makeCurrent(); + } + } + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLPbuffer) returnList.get(0); + } + + public GLContext createExternalGLContext() { + return new WindowsExternalGLContext(); + } + + public boolean canCreateExternalGLDrawable() { + return true; + } + + public GLDrawable createExternalGLDrawable() { + return new WindowsExternalGLDrawable(); + } + + public long dynamicLookupFunction(String glFuncName) { + long res = WGL.wglGetProcAddress(glFuncName); + if (res == 0) { + // GLU routines aren't known to the OpenGL function lookup + if (hglu32 == 0) { + hglu32 = WGL.LoadLibraryA("GLU32"); + if (hglu32 == 0) { + throw new GLException("Error loading GLU32.DLL"); + } + } + res = WGL.GetProcAddress(hglu32, glFuncName); + } + return res; + } + + static String wglGetLastError() { + int err = WGL.GetLastError(); + String detail = null; + switch (err) { + case WGL.ERROR_INVALID_PIXEL_FORMAT: detail = "ERROR_INVALID_PIXEL_FORMAT"; break; + case WGL.ERROR_NO_SYSTEM_RESOURCES: detail = "ERROR_NO_SYSTEM_RESOURCES"; break; + case WGL.ERROR_INVALID_DATA: detail = "ERROR_INVALID_DATA"; break; + case WGL.ERROR_PROC_NOT_FOUND: detail = "ERROR_PROC_NOT_FOUND"; break; + case WGL.ERROR_INVALID_WINDOW_HANDLE:detail = "ERROR_INVALID_WINDOW_HANDLE"; break; + default: detail = "(Unknown error code " + err + ")"; break; + } + return detail; + } + + private void maybeDoSingleThreadedWorkaround(Runnable action) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(action); + } else { + action.run(); + } + } + + public void lockAWTForJava2D() { + } + + public void unlockAWTForJava2D() { + } +} diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLContext.java index 25f15b3f2..d9430638c 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContextFactory.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLContext.java @@ -37,29 +37,28 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.macosx; +package com.sun.opengl.impl.windows; -import java.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -public class MacOSXGLContextFactory extends GLContextFactory { - public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GraphicsDevice device) { - return null; +public class WindowsOffscreenGLContext extends WindowsGLContext { + public WindowsOffscreenGLContext(WindowsOffscreenGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); } - public GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - if (component != null) { - return new MacOSXOnscreenGLContext(component, capabilities, chooser, shareWith); - } else { - return new MacOSXOffscreenGLContext(capabilities, chooser, shareWith); - } + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_BYTE; + } + + public int getOffscreenContextReadBuffer() { + // On Windows these contexts are always single-buffered + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + // We can take care of this in the DIB creation (see below) + return false; } } diff --git a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java index c70607da7..7dd6d2361 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java @@ -37,106 +37,45 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.windows; +package com.sun.opengl.impl.windows; -import java.awt.image.BufferedImage; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -public class WindowsOffscreenGLContext extends WindowsGLContext { +public class WindowsOffscreenGLDrawable extends WindowsGLDrawable { private long origbitmap; private long hbitmap; // Width and height of the underlying bitmap private int width; private int height; - public WindowsOffscreenGLContext(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(null, capabilities, chooser, shareWith); + public WindowsOffscreenGLDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + super(null, capabilities, chooser); } - protected GL createGL() - { - return new WindowsGLImpl(this); + public GLContext createContext(GLContext shareWith) { + return new WindowsOffscreenGLContext(this, shareWith); } - protected boolean isOffscreen() { - return true; - } - - public int getOffscreenContextWidth() { - return width; - } - - public int getOffscreenContextHeight() { - return height; - } - - public int getOffscreenContextPixelDataType() { - return GL.GL_UNSIGNED_BYTE; - } - - public int getOffscreenContextReadBuffer() { - // On Windows these contexts are always single-buffered - return GL.GL_FRONT; - } - - public boolean offscreenImageNeedsVerticalFlip() { - // We can take care of this in the DIB creation (see below) - return false; - } - - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (pendingOffscreenResize) { - if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - if (hglrc != 0) { - destroyImpl(); - } - width = pendingOffscreenWidth; - height = pendingOffscreenHeight; - pendingOffscreenResize = false; - } + public void setSize(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if (hdc != 0) { + destroy(); } - return super.makeCurrent(initAction); + create(); } - protected void destroyImpl() { - if (hglrc != 0) { - super.destroyImpl(); - // Must destroy OpenGL context, bitmap and device context - WGL.SelectObject(hdc, origbitmap); - WGL.DeleteObject(hbitmap); - WGL.DeleteDC(hdc); - origbitmap = 0; - hbitmap = 0; - hdc = 0; - } + public int getWidth() { + return width; } - public synchronized void swapBuffers() throws GLException { + public int getHeight() { + return height; } - - protected void create() { + + private void create() { BITMAPINFO info = new BITMAPINFO(); BITMAPINFOHEADER header = info.bmiHeader(); int bitsPerPixel = (capabilities.getRedBits() + @@ -164,13 +103,31 @@ public class WindowsOffscreenGLContext extends WindowsGLContext { } hbitmap = WGL.CreateDIBSection(hdc, info, WGL.DIB_RGB_COLORS, 0, 0, 0); if (hbitmap == 0) { + WGL.DeleteDC(hdc); + hdc = 0; throw new GLException("Error creating offscreen bitmap of width " + width + ", height " + height); } if ((origbitmap = WGL.SelectObject(hdc, hbitmap)) == 0) { + WGL.DeleteObject(hbitmap); + hbitmap = 0; + WGL.DeleteDC(hdc); + hdc = 0; throw new GLException("Error selecting bitmap into new device context"); } - choosePixelFormatAndCreateContext(false); + choosePixelFormat(false); + } + + public void destroy() { + if (hdc != 0) { + // Must destroy bitmap and device context + WGL.SelectObject(hdc, origbitmap); + WGL.DeleteObject(hbitmap); + WGL.DeleteDC(hdc); + origbitmap = 0; + hbitmap = 0; + hdc = 0; + } } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java index 37b2302c0..00647e7dd 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLContext.java @@ -37,65 +37,57 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.macosx; +package com.sun.opengl.impl.windows; -import java.awt.image.BufferedImage; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import java.util.*; -public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext -{ - public MacOSXOffscreenGLContext(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(capabilities, -1, -1); - } - - protected boolean isOffscreen() { - return true; - } - - public boolean offscreenImageNeedsVerticalFlip() { - return true; - } - - public int getOffscreenContextWidth() { - return initWidth; - } +import javax.media.opengl.*; +import com.sun.opengl.impl.*; - public int getOffscreenContextHeight() { - return initWidth; - } +public class WindowsOnscreenGLContext extends WindowsGLContext { + protected WindowsOnscreenGLDrawable drawable; - public int getOffscreenContextPixelDataType() { - return GL.GL_UNSIGNED_INT_8_8_8_8_REV; + public WindowsOnscreenGLContext(WindowsOnscreenGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; } - - public int getOffscreenContextReadBuffer() { - return GL.GL_BACK; + + protected int makeCurrentImpl() throws GLException { + try { + int lockRes = drawable.lockSurface(); + if (lockRes == WindowsOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + if (lockRes == WindowsOnscreenGLDrawable.LOCK_SURFACE_CHANGED) { + if (hglrc != 0) { + if (!WGL.wglDeleteContext(hglrc)) { + throw new GLException("Unable to delete old GL context after surface changed"); + } + GLContextShareSet.contextDestroyed(this); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + toHexString(hglrc) + " due to JAWT_LOCK_SURFACE_CHANGED"); + } + hglrc = 0; + } + } + int ret = super.makeCurrentImpl(); + return ret; + } catch (RuntimeException e) { + try { + drawable.unlockSurface(); + } catch (Exception e2) { + // do nothing if unlockSurface throws + } + throw(e); + } } - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (pendingOffscreenResize && (nsContext != 0)) { - if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - destroyPBuffer(); - initWidth = pendingOffscreenWidth; - initHeight = pendingOffscreenHeight; - createPbuffer(0, 0); - pendingOffscreenResize = false; - } + protected void releaseImpl() throws GLException { + try { + super.releaseImpl(); + } finally { + drawable.unlockSurface(); } - return super.makeCurrent(initAction); } - - public synchronized void swapBuffers() throws GLException { - } } diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java new file mode 100644 index 000000000..b1f2d57a1 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java @@ -0,0 +1,198 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import java.awt.Component; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsOnscreenGLDrawable extends WindowsGLDrawable { + public static final int LOCK_SURFACE_NOT_READY = 1; + public static final int LOCK_SURFACE_CHANGED = 2; + public static final int LOCK_SUCCESS = 3; + private static JAWT jawt; + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_Win32DrawingSurfaceInfo win32dsi; + + // Indicates whether the component (if an onscreen context) has been + // realized. Plausibly, before the component is realized the JAWT + // should return an error or NULL object from some of its + // operations; this appears to be the case on Win32 but is not true + // at least with Sun's current X11 implementation (1.4.x), which + // crashes with no other error reported if the DrawingSurfaceInfo is + // fetched from a locked DrawingSurface during the validation as a + // result of calling show() on the main thread. To work around this + // we prevent any JAWT or OpenGL operations from being done until + // addNotify() is called on the component. + protected boolean realized; + + public WindowsOnscreenGLDrawable(Component component, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + super(component, capabilities, chooser); + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsOnscreenGLContext(this, shareWith); + } + + public void setRealized(boolean realized) { + this.realized = realized; + if (!realized) { + // Assume heavyweight widget was destroyed + pixelFormatChosen = false; + } + } + + public void setSize(int width, int height) { + component.setSize(width, height); + } + + public int getWidth() { + return component.getWidth(); + } + + public int getHeight() { + return component.getHeight(); + } + + public void swapBuffers() throws GLException { + boolean didLock = false; + + if (hdc == 0) { + if (lockSurface() == LOCK_SURFACE_NOT_READY) { + return; + } + didLock = true; + } + + if (!WGL.SwapBuffers(hdc) && (WGL.GetLastError() != 0)) { + throw new GLException("Error swapping buffers"); + } + + if (didLock) { + unlockSurface(); + } + } + + public int lockSurface() throws GLException { + if (!realized) { + return LOCK_SURFACE_NOT_READY; + } + if (hdc != 0) { + throw new GLException("Surface already locked"); + } + ds = getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { + throw new GLException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + int ret = LOCK_SUCCESS; + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + dsi = ds.GetDrawingSurfaceInfo(); + if (dsi == null) { + // Widget not yet realized + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + return LOCK_SURFACE_NOT_READY; + } + win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); + hdc = win32dsi.hdc(); + if (hdc == 0) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + win32dsi = null; + return LOCK_SURFACE_NOT_READY; + } + if (!pixelFormatChosen) { + choosePixelFormat(true); + } + return ret; + } + + public void unlockSurface() { + if (hdc == 0) { + throw new GLException("Surface already unlocked"); + } + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + win32dsi = null; + hdc = 0; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private JAWT getJAWT() { + if (jawt == null) { + JAWT j = new JAWT(); + j.version(JAWTFactory.JAWT_VERSION_1_4); + if (!JAWTFactory.JAWT_GetAWT(j)) { + throw new RuntimeException("Unable to initialize JAWT"); + } + jawt = j; + } + return jawt; + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLContext.java new file mode 100644 index 000000000..edfc70e5f --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLContext.java @@ -0,0 +1,163 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsPbufferGLContext extends WindowsGLContext { + private static final boolean DEBUG = Debug.debug("WindowsPbufferGLContext"); + + // State for render-to-texture and render-to-texture-rectangle support + private WindowsPbufferGLDrawable drawable; + private boolean rtt; // render-to-texture? + private boolean hasRTT; // render-to-texture extension available? + private boolean rect; // render-to-texture-rectangle? + private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV + private int texture; // actual texture object + + public WindowsPbufferGLContext(WindowsPbufferGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; + } + + public void bindPbufferToTexture() { + if (!rtt) { + throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + + "specified in its GLCapabilities"); + } + GL gl = getGL(); + WGLExt wglExt = getWGLExt(); + gl.glBindTexture(textureTarget, texture); + if (rtt && hasRTT) { + if (!wglExt.wglBindTexImageARB(drawable.getPbuffer(), WGLExt.WGL_FRONT_LEFT_ARB)) { + throw new GLException("Binding of pbuffer to texture failed: " + wglGetLastError()); + } + } + // FIXME: comment is wrong now + // Note that if the render-to-texture extension is not supported, + // we perform a glCopyTexImage2D in swapBuffers(). + } + + public void releasePbufferFromTexture() { + if (!rtt) { + throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + + "specified in its GLCapabilities"); + } + if (rtt && hasRTT) { + WGLExt wglExt = getWGLExt(); + if (!wglExt.wglReleaseTexImageARB(drawable.getPbuffer(), WGLExt.WGL_FRONT_LEFT_ARB)) { + throw new GLException("Releasing of pbuffer from texture failed: " + wglGetLastError()); + } + } + } + + protected int makeCurrentImpl() throws GLException { + if (drawable.getHDC() == 0) { + // pbuffer not instantiated (yet?) + if (DEBUG) { + System.err.println("pbuffer not instantiated"); + } + return CONTEXT_NOT_CURRENT; + } + + int res = super.makeCurrentImpl(); + if (DEBUG && VERBOSE) { + System.err.println("WindowsPbufferGLContext: super.makeCurrentImpl() = " + res); + } + if (res == CONTEXT_CURRENT_NEW) { + GLCapabilities capabilities = drawable.getCapabilities(); + + // Initialize render-to-texture support if requested + rtt = capabilities.getOffscreenRenderToTexture(); + rect = capabilities.getOffscreenRenderToTextureRectangle(); + GL gl = getGL(); + + if (rtt) { + if (DEBUG) { + System.err.println("Initializing render-to-texture support"); + } + + if (!gl.isExtensionAvailable("WGL_ARB_render_texture")) { + System.err.println("WindowsPbufferGLContext: WARNING: WGL_ARB_render_texture extension not " + + "supported; implementing render_to_texture support using slow texture readback"); + } else { + hasRTT = true; + + if (rect && !gl.isExtensionAvailable("GL_NV_texture_rectangle")) { + System.err.println("WindowsPbufferGLContext: WARNING: GL_NV_texture_rectangle extension not " + + "supported; skipping requested render_to_texture_rectangle support for pbuffer"); + rect = false; + } + if (rect) { + if (DEBUG) { + System.err.println(" Using render-to-texture-rectangle"); + } + textureTarget = GL.GL_TEXTURE_RECTANGLE_NV; + } else { + if (DEBUG) { + System.err.println(" Using vanilla render-to-texture"); + } + textureTarget = GL.GL_TEXTURE_2D; + } + int[] tmp = new int[1]; + gl.glGenTextures(1, tmp, 0); + texture = tmp[0]; + gl.glBindTexture(textureTarget, texture); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); + gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, drawable.getWidth(), drawable.getHeight(), 0); + } + } + } + return res; + } + + public int getFloatingPointMode() { + return drawable.getFloatingPointMode(); + } + + private static String wglGetLastError() { + return WindowsGLDrawableFactory.wglGetLastError(); + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java new file mode 100644 index 000000000..8e660cc51 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java @@ -0,0 +1,399 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.windows; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class WindowsPbufferGLDrawable extends WindowsGLDrawable { + private int initWidth; + private int initHeight; + + private WGLExt cachedWGLExt; // cached WGLExt instance from parent GLCanvas, + // needed to destroy pbuffer + private long buffer; // pbuffer handle + private int width; + private int height; + + private int floatMode; + + public WindowsPbufferGLDrawable(GLCapabilities capabilities, + int initialWidth, + int initialHeight, + WindowsGLDrawable dummyDrawable, + WGLExt wglExt) { + super(null, capabilities, null); + this.initWidth = initialWidth; + this.initHeight = initialHeight; + if (initWidth <= 0 || initHeight <= 0) { + throw new GLException("Initial width and height of pbuffer must be positive (were (" + + initWidth + ", " + initHeight + "))"); + } + + if (DEBUG) { + System.out.println("Pbuffer caps on init: " + capabilities + + (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + + (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + + (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); + } + + createPbuffer(dummyDrawable.getHDC(), wglExt); + } + + public GLContext createContext(GLContext shareWith) { + return new WindowsPbufferGLContext(this, shareWith); + } + + public void destroy() { + if (hdc != 0) { + // Must release DC and pbuffer + // NOTE that since the context is not current, glGetError() can + // not be called here, so we skip the use of any composable + // pipelines (see WindowsOnscreenGLContext.makeCurrentImpl) + WGLExt wglExt = cachedWGLExt; + if (wglExt.wglReleasePbufferDCARB(buffer, hdc) == 0) { + throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); + } + hdc = 0; + if (!wglExt.wglDestroyPbufferARB(buffer)) { + throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); + } + buffer = 0; + } + } + + public void setSize(int width, int height) { + // FIXME + throw new GLException("Not yet implemented"); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public GLCapabilities getCapabilities() { + return capabilities; + } + + public long getPbuffer() { + return buffer; + } + + public int getFloatingPointMode() { + return floatMode; + } + + public void swapBuffers() throws GLException { + // FIXME: this doesn't make sense any more because we don't have + // access to our OpenGL context here + /* + // FIXME: do we need to do anything if the pbuffer is double-buffered? + // For now, just grab the pixels for the render-to-texture support. + if (rtt && !hasRTT) { + if (DEBUG) { + System.err.println("Copying pbuffer data to GL_TEXTURE_2D state"); + } + + GL gl = getGL(); + gl.glCopyTexSubImage2D(textureTarget, 0, 0, 0, 0, 0, width, height); + } + */ + } + + private void createPbuffer(long parentHdc, WGLExt wglExt) { + int[] iattributes = new int [2*MAX_ATTRIBS]; + float[] fattributes = new float[2*MAX_ATTRIBS]; + int nfattribs = 0; + int niattribs = 0; + + if (DEBUG) { + System.out.println("Pbuffer parentHdc = " + toHexString(parentHdc)); + System.out.println("Pbuffer caps: " + capabilities + + (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + + (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + + (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); + } + + boolean rtt = capabilities.getOffscreenRenderToTexture(); + boolean rect = capabilities.getOffscreenRenderToTextureRectangle(); + boolean useFloat = capabilities.getOffscreenFloatingPointBuffers(); + boolean ati = false; + + // Since we are trying to create a pbuffer, the pixel format we + // request (and subsequently use) must be "p-buffer capable". + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + + if (rtt && !rect) { + throw new GLException("Render-to-texture-rectangle requires render-to-texture to be specified"); + } + + if (rect) { + if (!wglExt.isExtensionAvailable("GL_NV_texture_rectangle")) { + throw new GLException("Render-to-texture-rectangle requires GL_NV_texture_rectangle extension"); + } + } + + if (useFloat) { + if (!wglExt.isExtensionAvailable("WGL_ATI_pixel_format_float") && + !wglExt.isExtensionAvailable("WGL_NV_float_buffer")) { + throw new GLException("Floating-point pbuffers not supported by this hardware"); + } + + // Prefer NVidia extension over ATI + if (wglExt.isExtensionAvailable("WGL_NV_float_buffer")) { + ati = false; + floatMode = GLPbuffer.NV_FLOAT; + } else { + ati = true; + floatMode = GLPbuffer.ATI_FLOAT; + } + if (DEBUG) { + System.err.println("Using " + (ati ? "ATI" : "NVidia") + " floating-point extension"); + } + } + + if (useFloat && ati) { + if (rtt) { + throw new GLException("Render-to-floating-point-texture not supported on ATI hardware"); + } else { + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_FLOAT_ATI; + } + } else { + if (!rtt) { + // Currently we don't support non-truecolor visuals in the + // GLCapabilities, so we don't offer the option of making + // color-index pbuffers. + iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA_ARB; + } + } + + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + if (capabilities.getDoubleBuffered()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = capabilities.getDepthBits(); + + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = capabilities.getRedBits(); + + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = capabilities.getGreenBits(); + + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = capabilities.getBlueBits(); + + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = capabilities.getAlphaBits(); + + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + if (capabilities.getStencilBits() > 0) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + + if (capabilities.getAccumRedBits() > 0 || + capabilities.getAccumGreenBits() > 0 || + capabilities.getAccumBlueBits() > 0) { + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BITS_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } + + if (useFloat && !ati) { + iattributes[niattribs++] = WGLExt.WGL_FLOAT_COMPONENTS_NV; + iattributes[niattribs++] = GL.GL_TRUE; + } + + if (rtt) { + if (useFloat) { + assert(!ati); + if (!rect) { + throw new GLException("Render-to-floating-point-texture only supported on NVidia hardware with render-to-texture-rectangle"); + } + iattributes[niattribs++] = WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV; + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = rect ? WGLExt.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGLExt.WGL_BIND_TO_TEXTURE_RGB_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + } + } + + iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + + int[] pformats = new int[MAX_PFORMATS]; + int nformats; + int[] nformatsTmp = new int[1]; + if (!wglExt.wglChoosePixelFormatARB(parentHdc, + iattributes, 0, + fattributes, 0, + MAX_PFORMATS, + pformats, 0, + nformatsTmp, 0)) { + throw new GLException("pbuffer creation error: wglChoosePixelFormatARB() failed"); + } + nformats = nformatsTmp[0]; + if (nformats <= 0) { + throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); + } + + if (DEBUG) { + System.err.println("" + nformats + " suitable pixel formats found"); + // query pixel format + iattributes[0] = WGLExt.WGL_RED_BITS_ARB; + iattributes[1] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[2] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[3] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[4] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[5] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE_ARB : WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS_ARB); + iattributes[6] = WGLExt.WGL_SAMPLE_BUFFERS_EXT; + iattributes[7] = WGLExt.WGL_SAMPLES_EXT; + iattributes[8] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; + int[] ivalues = new int[9]; + for (int i = 0; i < nformats; i++) { + if (!wglExt.wglGetPixelFormatAttribivARB(parentHdc, pformats[i], 0, 9, iattributes, 0, ivalues, 0)) { + throw new GLException("Error while querying pixel format " + pformats[i] + + "'s (index " + i + "'s) capabilities for debugging"); + } + System.err.print("pixel format " + pformats[i] + " (index " + i + "): "); + System.err.print( "r: " + ivalues[0]); + System.err.print(" g: " + ivalues[1]); + System.err.print(" b: " + ivalues[2]); + System.err.print(" a: " + ivalues[3]); + System.err.print(" depth: " + ivalues[4]); + System.err.print(" multisample: " + ivalues[6]); + System.err.print(" samples: " + ivalues[7]); + if (useFloat) { + if (ati) { + if (ivalues[5] == WGLExt.WGL_TYPE_RGBA_FLOAT_ATI) { + System.err.print(" [ati float]"); + } else if (ivalues[5] != WGLExt.WGL_TYPE_RGBA_ARB) { + System.err.print(" [unknown pixel type " + ivalues[5] + "]"); + } + } else { + if (ivalues[5] != 0) { + System.err.print(" [float]"); + } + } + } + + if (ivalues[8] != 0) { + System.err.print(" [pbuffer]"); + } + System.err.println(); + } + } + + long tmpBuffer = 0; + int whichFormat = 0; + // Loop is a workaround for bugs in NVidia's recent drivers + do { + int format = pformats[whichFormat]; + + // Create the p-buffer. + niattribs = 0; + + if (rtt) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FORMAT_ARB; + if (useFloat) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FLOAT_RGB_NV; + } else { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_RGBA_ARB; + } + + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_TARGET_ARB; + iattributes[niattribs++] = rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D_ARB; + + iattributes[niattribs++] = WGLExt.WGL_MIPMAP_TEXTURE_ARB; + iattributes[niattribs++] = GL.GL_FALSE; + + iattributes[niattribs++] = WGLExt.WGL_PBUFFER_LARGEST_ARB; + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = 0; + + tmpBuffer = wglExt.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes, 0); + ++whichFormat; + } while ((tmpBuffer == 0) && (whichFormat < nformats)); + + if (tmpBuffer == 0) { + throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: tried " + nformats + + " pixel formats, last error was: " + wglGetLastError()); + } + + // Get the device context. + long tmpHdc = wglExt.wglGetPbufferDCARB(tmpBuffer); + if (tmpHdc == 0) { + throw new GLException("pbuffer creation error: wglGetPbufferDCARB() failed"); + } + + // Set up instance variables + buffer = tmpBuffer; + hdc = tmpHdc; + cachedWGLExt = wglExt; + + // Determine the actual width and height we were able to create. + int[] tmp = new int[1]; + wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_WIDTH_ARB, tmp, 0 ); + width = tmp[0]; + wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_HEIGHT_ARB, tmp, 0 ); + height = tmp[0]; + + if (DEBUG) { + System.err.println("Created pbuffer " + width + " x " + height); + } + } + + private static String wglGetLastError() { + return WindowsGLDrawableFactory.wglGetLastError(); + } +} diff --git a/src/net/java/games/jogl/GLContextHelper.java b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java index f4878a723..4d329ba24 100644..100755 --- a/src/net/java/games/jogl/GLContextHelper.java +++ b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java @@ -37,32 +37,47 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package com.sun.opengl.impl.x11; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; -/** This package-private class helps extract a GLContext from a - GLDrawable. The getContext() method can not be placed in the - public API of GLDrawable without exposing the GLContext class to - the public API, which is not desired. */ +public class X11ExternalGLContext extends X11GLContext { + private boolean firstMakeCurrent = true; + private boolean created = true; -class GLContextHelper { - static GLContext getContext(GLDrawable drawable) throws GLException { - if (drawable == null) { - return null; + public X11ExternalGLContext() { + super(null, null); + lockAWT(); + try { + context = GLX.glXGetCurrentContext(); + } finally { + unlockAWT(); } + GLContextShareSet.contextCreated(this); + resetGLFunctionAvailability(); + } + + protected void create() { + } - if (drawable instanceof GLCanvas) { - return ((GLCanvas) drawable).getContext(); - } else if (drawable instanceof GLJPanel) { - return ((GLJPanel) drawable).getContext(); - } else if (drawable instanceof GLPbufferImpl) { - return ((GLPbufferImpl) drawable).getContext(); - } else { - throw new GLException( - "Sharing of contexts and display lists not supported among user-defined GLDrawables " + - "(unknown drawable type " + drawable.getClass().getName() + ")" - ); + protected int makeCurrentImpl() throws GLException { + if (firstMakeCurrent) { + firstMakeCurrent = false; + return CONTEXT_CURRENT_NEW; } + return CONTEXT_CURRENT; + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + created = false; + GLContextShareSet.contextDestroyed(this); + } + + public boolean isCreated() { + return created; } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java new file mode 100755 index 000000000..371930013 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java @@ -0,0 +1,212 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11ExternalGLDrawable extends X11GLDrawable { + private int fbConfigID; + private int renderType; + private int screen; + private long readDrawable; + + public X11ExternalGLDrawable() { + super(null, null, null); + lockAWT(); + try { + display = GLX.glXGetCurrentDisplay(); + drawable = GLX.glXGetCurrentDrawable(); + readDrawable = GLX.glXGetCurrentReadDrawable(); + + // Need GLXFBConfig ID in order to properly create new contexts + // on this drawable + long context = GLX.glXGetCurrentContext(); + int[] val = new int[1]; + GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0); + fbConfigID = val[0]; + renderType = GLX.GLX_RGBA_TYPE; + GLX.glXQueryContext(display, context, GLX.GLX_RENDER_TYPE, val, 0); + if ((val[0] & GLX.GLX_RGBA_BIT) == 0) { + if (DEBUG) { + System.err.println("X11ExternalGLDrawable: WARNING: forcing GLX_RGBA_TYPE for newly created contexts"); + } + } + GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0); + screen = val[0]; + } finally { + unlockAWT(); + } + } + + public GLContext createContext(GLContext shareWith) { + return new Context(shareWith); + } + + public void setSize(int newWidth, int newHeight) { + throw new GLException("Should not call this"); + } + + public int getWidth() { + throw new GLException("Should not call this"); + } + + public int getHeight() { + throw new GLException("Should not call this"); + } + + public void destroy() { + } + + class Context extends X11GLContext { + Context(GLContext shareWith) { + super(X11ExternalGLDrawable.this, shareWith); + this.drawable = drawable; + } + + protected int makeCurrentImpl() throws GLException { + if (drawable.getDrawable() == 0) { + // parent drawable not properly initialized + // FIXME: signal error? + if (DEBUG) { + System.err.println("parent drawable not properly initialized"); + } + return CONTEXT_NOT_CURRENT; + } + + // Note that we have to completely override makeCurrentImpl + // because the underlying makeCurrent call differs from the norm + lockAWT(); + try { + boolean created = false; + if (context == 0) { + create(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); + } + created = true; + } + + if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), + drawable.getDrawable(), + readDrawable, + context)) { + throw new GLException("Error making context current"); + } else { + mostRecentDisplay = drawable.getDisplay(); + if (DEBUG && VERBOSE) { + System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(drawable.getDisplay()) + + ", drawable " + toHexString(drawable.getDrawable()) + + ", context " + toHexString(context) + ") succeeded"); + } + } + + if (created) { + resetGLFunctionAvailability(); + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } finally { + unlockAWT(); + } + } + + protected void releaseImpl() throws GLException { + lockAWT(); + try { + if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), 0, 0, 0)) { + throw new GLException("Error freeing OpenGL context"); + } + } finally { + unlockAWT(); + } + } + + protected void create() { + // We already have the GLXFBConfig ID for the context. All we + // need to do is use it to choose the GLXFBConfig and then + // create a context with it. + int[] iattributes = new int[] { + GLX.GLX_FBCONFIG_ID, + fbConfigID, + 0, + 0 + }; + float[] fattributes = new float[0]; + int[] nelementsTmp = new int[1]; + GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, 0, nelementsTmp, 0); + int nelements = nelementsTmp[0]; + if (nelements <= 0) { + throw new GLException("context creation error: couldn't find a suitable frame buffer configuration"); + } + if (nelements != 1) { + throw new GLException("context creation error: shouldn't get more than one GLXFBConfig"); + } + // Note that we currently don't allow selection of anything but + // the first GLXFBConfig in the returned list (there should be only one) + GLXFBConfig fbConfig = fbConfigs[0]; + // Create a gl context for the drawable + X11GLContext other = (X11GLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + share = other.getContext(); + if (share == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + } + // FIXME: how to determine "direct" bit? + context = GLX.glXCreateNewContext(display, fbConfig, renderType, share, true); + if (context == 0) { + String detail = " display=" + toHexString(display) + + " fbconfig=" + fbConfig + + " fbconfigID=" + toHexString(fbConfigID) + + " renderType=" + toHexString(renderType) + + " share=" + toHexString(share); + throw new GLException("context creation error: glXCreateNewContext() failed: " + detail); + } + GLContextShareSet.contextCreated(this); + + if (DEBUG) { + System.err.println("Created context " + toHexString(context) + + " for GLXDrawable " + toHexString(drawable.getDrawable())); + } + } + } +} diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLContext.java b/src/classes/com/sun/opengl/impl/x11/X11GLContext.java new file mode 100644 index 000000000..ed9736f22 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11GLContext.java @@ -0,0 +1,301 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import java.nio.*; +import java.util.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public abstract class X11GLContext extends GLContextImpl { + protected X11GLDrawable drawable; + protected long context; + private boolean glXQueryExtensionsStringInitialized; + private boolean glXQueryExtensionsStringAvailable; + private static final Map/*<String, String>*/ functionNameMap; + private GLXExt glXExt; + // Table that holds the addresses of the native C-language entry points for + // GLX extension functions. + private GLXExtProcAddressTable glXExtProcAddressTable; + // Cache the most recent value of the "display" variable (which we + // only guarantee to be valid in between makeCurrent / free pairs) + // so that we can implement displayImpl() (which must be done when + // the context is not current) + protected long mostRecentDisplay; + + static { + functionNameMap = new HashMap(); + functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); + functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); + } + + public X11GLContext(X11GLDrawable drawable, + GLContext shareWith) { + super(shareWith); + this.drawable = drawable; + } + + public Object getPlatformGLExtensions() { + return getGLXExt(); + } + + public GLXExt getGLXExt() { + if (glXExt == null) { + glXExt = new GLXExtImpl(this); + } + return glXExt; + } + + public GLDrawable getGLDrawable() { + return drawable; + } + + protected String mapToRealGLFunctionName(String glFunctionName) { + String lookup = (String) functionNameMap.get(glFunctionName); + if (lookup != null) { + return lookup; + } + return glFunctionName; + } + + protected String mapToRealGLExtensionName(String glExtensionName) { + return glExtensionName; + } + + /** Helper routine which usually just turns around and calls + * createContext (except for pbuffers, which use a different context + * creation mechanism). Should only be called by {@link + * makeCurrentImpl()}. + */ + protected abstract void create(); + + /** + * Creates and initializes an appropriate OpenGL context. Should only be + * called by {@link create()}. + */ + protected void createContext(boolean onscreen) { + XVisualInfo vis = drawable.chooseVisual(onscreen); + X11GLContext other = (X11GLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + share = other.getContext(); + if (share == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + } + context = GLX.glXCreateContext(drawable.getDisplay(), vis, share, onscreen); + if (context == 0) { + throw new GLException("Unable to create OpenGL context"); + } + GLContextShareSet.contextCreated(this); + } + + protected int makeCurrentImpl() throws GLException { + // FIXME: in offscreen (non-pbuffer) case this is run without the + // AWT lock held + boolean created = false; + if (context == 0) { + create(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); + } + created = true; + } + + if (!GLX.glXMakeCurrent(drawable.getDisplay(), drawable.getDrawable(), context)) { + throw new GLException("Error making context current"); + } else { + mostRecentDisplay = drawable.getDisplay(); + if (DEBUG && VERBOSE) { + System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(drawable.getDisplay()) + + ", drawable " + toHexString(drawable.getDrawable()) + + ", context " + toHexString(context) + ") succeeded"); + } + } + + if (created) { + resetGLFunctionAvailability(); + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } + + protected void releaseImpl() throws GLException { + if (!GLX.glXMakeCurrent(drawable.getDisplay(), 0, 0)) { + throw new GLException("Error freeing OpenGL context"); + } + } + + protected void destroyImpl() throws GLException { + lockAWT(); + if (context != 0) { + GLX.glXDestroyContext(mostRecentDisplay, context); + if (DEBUG) { + System.err.println("!!! Destroyed OpenGL context " + context); + } + context = 0; + mostRecentDisplay = 0; + GLContextShareSet.contextDestroyed(this); + } + unlockAWT(); + } + + public boolean isCreated() { + return (context != 0); + } + + protected void resetGLFunctionAvailability() { + super.resetGLFunctionAvailability(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Initializing GLX extension address table"); + } + resetProcAddressTable(getGLXExtProcAddressTable()); + } + + public GLXExtProcAddressTable getGLXExtProcAddressTable() { + if (glXExtProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + glXExtProcAddressTable = new GLXExtProcAddressTable(); + } + return glXExtProcAddressTable; + } + + public synchronized String getPlatformExtensionsString() { + if (drawable.getDisplay() == 0) { + throw new GLException("Context not current"); + } + if (!glXQueryExtensionsStringInitialized) { + glXQueryExtensionsStringAvailable = + (GLDrawableFactoryImpl.getFactoryImpl().dynamicLookupFunction("glXQueryExtensionsString") != 0); + glXQueryExtensionsStringInitialized = true; + } + if (glXQueryExtensionsStringAvailable) { + lockAWT(); + try { + String ret = GLX.glXQueryExtensionsString(drawable.getDisplay(), GLX.DefaultScreen(drawable.getDisplay())); + if (DEBUG) { + System.err.println("!!! GLX extensions: " + ret); + } + return ret; + } finally { + unlockAWT(); + } + } else { + return ""; + } + } + + protected boolean isFunctionAvailable(String glFunctionName) + { + boolean available = super.isFunctionAvailable(glFunctionName); + + // Sanity check for implementations that use proc addresses for run-time + // linking: if the function IS available, then make sure there's a proc + // address for it if it's an extension or not part of the OpenGL 1.1 core + // (post GL 1.1 functions are run-time linked on windows). + assert(!available || + (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || + FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) + ); + + return available; + } + + public boolean isExtensionAvailable(String glExtensionName) { + if (glExtensionName.equals("GL_ARB_pbuffer") || + glExtensionName.equals("GL_ARB_pixel_format")) { + return GLDrawableFactory.getFactory().canCreateGLPbuffer(); + } + return super.isExtensionAvailable(glExtensionName); + } + + + public void setSwapInterval(int interval) { + // FIXME: make the context current first? Currently assumes that + // will not be necessary. Make the caller do this? + GLXExt glXExt = getGLXExt(); + if (glXExt.isExtensionAvailable("GLX_SGI_swap_control")) { + glXExt.glXSwapIntervalSGI(interval); + } + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + return getGLXExt().glXAllocateMemoryNV(arg0, arg1, arg2, arg3); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + protected long getContext() { + return context; + } + + // These synchronization primitives prevent the AWT from making + // requests from the X server asynchronously to this code. + protected void lockAWT() { + X11GLDrawableFactory.lockAWT(); + } + + protected void unlockAWT() { + X11GLDrawableFactory.unlockAWT(); + } +} diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java new file mode 100644 index 000000000..1d4f5389b --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java @@ -0,0 +1,172 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import java.awt.Component; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public abstract class X11GLDrawable extends GLDrawableImpl { + protected static final boolean DEBUG = Debug.debug("X11GLDrawable"); + + protected long display; + protected long drawable; + protected long visualID; + protected Component component; + protected GLCapabilities capabilities; + protected GLCapabilitiesChooser chooser; + + public X11GLDrawable(Component component, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + this.component = component; + this.capabilities = (capabilities == null) ? null : + ((GLCapabilities) capabilities.clone()); + this.chooser = chooser; + } + + public void setRealized(boolean val) { + throw new GLException("Should not call this (should only be called for onscreen GLDrawables)"); + } + + public void destroy() { + throw new GLException("Should not call this (should only be called for offscreen GLDrawables)"); + } + + public void swapBuffers() throws GLException { + } + + public long getDisplay() { + return display; + } + + public long getDrawable() { + return drawable; + } + + //--------------------------------------------------------------------------- + // Internals only below this point + // + + protected XVisualInfo chooseVisual(boolean onscreen) { + if (display == 0) { + throw new GLException("null display"); + } + + // FIXME + if (onscreen) { + // The visual has already been chosen by the time we get here; + // it's specified by the GraphicsConfiguration of the + // GLCanvas. Fortunately, the JAWT supplies the visual ID for + // the component in a portable fashion, so all we have to do is + // use XGetVisualInfo with a VisualIDMask to get the + // corresponding XVisualInfo to pass into glXChooseVisual. + int[] count = new int[1]; + XVisualInfo template = new XVisualInfo(); + // FIXME: probably not 64-bit clean + template.visualid((int) visualID); + lockAWT(); + XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count, 0); + unlockAWT(); + if (infos == null || infos.length == 0) { + throw new GLException("Error while getting XVisualInfo for visual ID " + visualID); + } + // FIXME: the storage for the infos array is leaked (should + // clean it up somehow when we're done with the visual we're + // returning) + return infos[0]; + } else { + // It isn't clear to me whether we need this much code to handle + // the offscreen case, where we're creating a pixmap into which + // to render...this is what we (incorrectly) used to do for the + // onscreen case + + int screen = 0; // FIXME: provide way to specify this? + XVisualInfo vis = null; + int[] count = new int[1]; + XVisualInfo template = new XVisualInfo(); + template.screen(screen); + XVisualInfo[] infos = null; + GLCapabilities[] caps = null; + lockAWT(); + try { + infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0); + if (infos == null) { + throw new GLException("Error while enumerating available XVisualInfos"); + } + caps = new GLCapabilities[infos.length]; + for (int i = 0; i < infos.length; i++) { + caps[i] = X11GLDrawableFactory.xvi2GLCapabilities(display, infos[i]); + } + } finally { + unlockAWT(); + } + int chosen = chooser.chooseCapabilities(capabilities, caps, -1); + if (chosen < 0 || chosen >= caps.length) { + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + } + if (DEBUG) { + System.err.println("Chosen visual (" + chosen + "):"); + System.err.println(caps[chosen]); + } + vis = infos[chosen]; + if (vis == null) { + throw new GLException("GLCapabilitiesChooser chose an invalid visual"); + } + // FIXME: the storage for the infos array is leaked (should + // clean it up somehow when we're done with the visual we're + // returning) + + return vis; + } + } + + + // These synchronization primitives prevent the AWT from making + // requests from the X server asynchronously to this code. + protected void lockAWT() { + X11GLDrawableFactory.lockAWT(); + } + + protected void unlockAWT() { + X11GLDrawableFactory.unlockAWT(); + } +} diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java index a1b299478..f4523c95e 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java @@ -37,17 +37,43 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.x11; +package com.sun.opengl.impl.x11; import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import java.awt.GraphicsEnvironment; +import java.security.*; +import java.util.ArrayList; +import java.util.List; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11GLDrawableFactory extends GLDrawableFactoryImpl { + private static final boolean DEBUG = Debug.debug("X11GLDrawableFactory"); + + // There is currently a bug on Linux/AMD64 distributions in glXGetProcAddressARB + private static boolean isLinuxAMD64; -public class X11GLContextFactory extends GLContextFactory { static { NativeLibLoader.load(); + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String os = System.getProperty("os.name").toLowerCase(); + String arch = System.getProperty("os.arch").toLowerCase(); + if (os.startsWith("linux") && arch.equals("amd64")) { + isLinuxAMD64 = true; + } + return null; + } + }); + } + + public X11GLDrawableFactory() { + // Must initialize GLX support eagerly in case a pbuffer is the + // first thing instantiated + resetProcAddressTable(GLX.getGLXProcAddressTable()); } private static final int MAX_ATTRIBS = 128; @@ -55,6 +81,16 @@ public class X11GLContextFactory extends GLContextFactory { public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GraphicsDevice device) { + if (capabilities == null) { + capabilities = new GLCapabilities(); + } + if (chooser == null) { + chooser = new DefaultGLCapabilitiesChooser(); + } + if (device == null) { + device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + } + int screen = X11SunJDKReflection.graphicsDeviceGetScreen(device); // Until we have a rock-solid visual selection algorithm written // in pure Java, we're going to provide the underlying window @@ -67,11 +103,11 @@ public class X11GLContextFactory extends GLContextFactory { lockAWT(); try { long display = getDisplayConnection(); - XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); + XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); int[] count = new int[1]; XVisualInfo template = new XVisualInfo(); template.screen(screen); - infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); + infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0); if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } @@ -119,50 +155,145 @@ public class X11GLContextFactory extends GLContextFactory { return null; } - public GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - if (component != null) { - return new X11OnscreenGLContext(component, capabilities, chooser, shareWith); - } else { - return new X11OffscreenGLContext(capabilities, chooser, shareWith); + public GLDrawable getGLDrawable(Object target, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + if (!(target instanceof Component)) { + throw new IllegalArgumentException("GLDrawables not supported for objects of type " + + target.getClass().getName() + " (only Components are supported in this implementation)"); + } + return new X11OnscreenGLDrawable((Component) target); + } + + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + return new X11OffscreenGLDrawable(capabilities, chooser); + } + + private boolean pbufferSupportInitialized = false; + private boolean canCreateGLPbuffer = false; + public boolean canCreateGLPbuffer() { + if (!pbufferSupportInitialized) { + Runnable r = new Runnable() { + public void run() { + long display = getDisplayConnection(); + lockAWT(); + try { + int[] major = new int[1]; + int[] minor = new int[1]; + if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { + throw new GLException("glXQueryVersion failed"); + } + if (DEBUG) { + System.err.println("!!! GLX version: major " + major[0] + + ", minor " + minor[0]); + } + + int screen = 0; // FIXME: provide way to specify this? + + // Work around bugs in ATI's Linux drivers where they report they + // only implement GLX version 1.2 but actually do support pbuffers + if (major[0] == 1 && minor[0] == 2) { + String str = GLX.glXQueryServerString(display, screen, GLX.GLX_VENDOR); + if (str != null && str.indexOf("ATI") >= 0) { + canCreateGLPbuffer = true; + } + } else { + canCreateGLPbuffer = ((major[0] > 1) || (minor[0] > 2)); + } + + pbufferSupportInitialized = true; + } finally { + unlockAWT(); + } + } + }; + maybeDoSingleThreadedWorkaround(r); + } + return canCreateGLPbuffer; + } + + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final int initialWidth, + final int initialHeight, + final GLContext shareWith) { + if (!canCreateGLPbuffer()) { + throw new GLException("Pbuffer support not available with current graphics card"); } + final List returnList = new ArrayList(); + Runnable r = new Runnable() { + public void run() { + X11PbufferGLDrawable pbufferDrawable = new X11PbufferGLDrawable(capabilities, + initialWidth, + initialHeight); + GLPbufferImpl pbuffer = new GLPbufferImpl(pbufferDrawable, shareWith); + returnList.add(pbuffer); + } + }; + maybeDoSingleThreadedWorkaround(r); + return (GLPbuffer) returnList.get(0); + } + + public GLContext createExternalGLContext() { + return new X11ExternalGLContext(); + } + + public boolean canCreateExternalGLDrawable() { + return canCreateGLPbuffer(); + } + + public GLDrawable createExternalGLDrawable() { + return new X11ExternalGLDrawable(); + } + + public long dynamicLookupFunction(String glFuncName) { + long res = 0; + if (!isLinuxAMD64) { + res = GLX.glXGetProcAddressARB(glFuncName); + } + if (res == 0) { + // GLU routines aren't known to the OpenGL function lookup + res = GLX.dlsym(glFuncName); + } + return res; } public static GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { int[] tmp = new int[1]; - int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp); + int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); if (val == 0) { // Visual does not support OpenGL return null; } - val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp); + val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp, 0); if (val == 0) { // Visual does not support RGBA return null; } GLCapabilities res = new GLCapabilities(); - res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp) != 0); - res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp) != 0); + res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); + res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp, 0) != 0); // Note: use of hardware acceleration is determined by // glXCreateContext, not by the XVisualInfo. Optimistically claim // that all GLCapabilities have the capability to be hardware // accelerated. res.setHardwareAccelerated(true); - res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp)); - res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp)); - res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp)); - res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp)); - res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp)); - res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp)); - res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp)); - res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp)); - res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp)); - res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp)); + res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp, 0)); + res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp, 0)); + res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp, 0)); + res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp, 0)); + res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp, 0)); + res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp, 0)); + res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp, 0)); + res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp, 0)); + res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp, 0)); + res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp, 0)); if (isMultisampleAvailable()) { - res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS_ARB, tmp) != 0); - res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES_ARB, tmp)); + res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS_ARB, tmp, 0) != 0); + res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES_ARB, tmp, 0)); } return res; } @@ -203,9 +334,9 @@ public class X11GLContextFactory extends GLContextFactory { res[idx++] = GLX.GLX_ACCUM_BLUE_SIZE; res[idx++] = caps.getAccumBlueBits(); if (isMultisampleAvailable && caps.getSampleBuffers()) { - res[idx++] = GL.GLX_SAMPLE_BUFFERS_ARB; + res[idx++] = GLXExt.GLX_SAMPLE_BUFFERS_ARB; res[idx++] = GL.GL_TRUE; - res[idx++] = GL.GLX_SAMPLES_ARB; + res[idx++] = GLXExt.GLX_SAMPLES_ARB; res[idx++] = caps.getNumSamples(); } res[idx++] = 0; @@ -227,11 +358,22 @@ public class X11GLContextFactory extends GLContextFactory { } public static void lockAWT() { - getJAWT().Lock(); + if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) { + getJAWT().Lock(); + } } public static void unlockAWT() { - getJAWT().Unlock(); + if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) { + getJAWT().Unlock(); + } + } + + public void lockAWTForJava2D() { + lockAWT(); + } + public void unlockAWTForJava2D() { + unlockAWT(); } // Display connection for use by visual selection algorithm and by all offscreen surfaces @@ -275,14 +417,23 @@ public class X11GLContextFactory extends GLContextFactory { } } - public static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp) { + public static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp, int tmp_offset) { if (display == 0) { throw new GLException("No display connection"); } - int res = GLX.glXGetConfig(display, info, attrib, tmp); + int res = GLX.glXGetConfig(display, info, attrib, tmp, tmp_offset); if (res != 0) { throw new GLException("glXGetConfig failed: error code " + glXGetConfigErrorCode(res)); } - return tmp[0]; + return tmp[tmp_offset]; + } + + private void maybeDoSingleThreadedWorkaround(Runnable action) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(action); + } else { + action.run(); + } } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLContext.java new file mode 100644 index 000000000..e1c8eb3d1 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLContext.java @@ -0,0 +1,74 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11OffscreenGLContext extends X11GLContext { + private X11OffscreenGLDrawable drawable; + + public X11OffscreenGLContext(X11OffscreenGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; + } + + public int getOffscreenContextPixelDataType() { + return GL.GL_UNSIGNED_INT_8_8_8_8_REV; + } + + public int getOffscreenContextReadBuffer() { + if (drawable.isDoubleBuffered()) { + return GL.GL_BACK; + } + return GL.GL_FRONT; + } + + public boolean offscreenImageNeedsVerticalFlip() { + // There doesn't seem to be a way to do this in the construction + // of the Pixmap or GLXPixmap + return true; + } + + protected void create() { + createContext(false); + } +} diff --git a/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java new file mode 100644 index 000000000..2d7dedd7f --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java @@ -0,0 +1,143 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11OffscreenGLDrawable extends X11GLDrawable { + private long pixmap; + private boolean isDoubleBuffered; + // Width and height of the underlying bitmap + private int width; + private int height; + + public X11OffscreenGLDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + super(null, capabilities, chooser); + } + + public GLContext createContext(GLContext shareWith) { + return new X11OffscreenGLContext(this, shareWith); + } + + public void setSize(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + if (pixmap != 0) { + destroy(); + } + create(); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + private void create() { + display = X11GLDrawableFactory.getDisplayConnection(); + XVisualInfo vis = chooseVisual(false); + int bitsPerPixel = vis.depth(); + + lockAWT(); + try { + int screen = GLX.DefaultScreen(display); + pixmap = GLX.XCreatePixmap(display, (int) GLX.RootWindow(display, screen), width, height, bitsPerPixel); + if (pixmap == 0) { + throw new GLException("XCreatePixmap failed"); + } + drawable = GLX.glXCreateGLXPixmap(display, vis, pixmap); + if (drawable == 0) { + GLX.XFreePixmap(display, pixmap); + pixmap = 0; + throw new GLException("glXCreateGLXPixmap failed"); + } + isDoubleBuffered = (X11GLDrawableFactory.glXGetConfig(display, vis, GLX.GLX_DOUBLEBUFFER, new int[1], 0) != 0); + if (DEBUG) { + System.err.println("Created pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(display)); + } + } finally { + unlockAWT(); + } + } + + public void destroy() { + if (pixmap != 0) { + if (DEBUG) { + System.err.println("Destroying pixmap " + toHexString(pixmap) + + ", GLXPixmap " + toHexString(drawable) + + ", display " + toHexString(display)); + } + + // Must destroy pixmap and GLXPixmap + lockAWT(); + + if (DEBUG) { + long cur = GLX.glXGetCurrentContext(); + if (cur != 0) { + System.err.println("WARNING: found context " + toHexString(cur) + " current during pixmap destruction"); + } + } + + // FIXME: workaround for crashes on NVidia hardware when + // destroying pixmap (no context is current at the point of the + // crash, at least from the point of view of + // glXGetCurrentContext) + GLX.glXMakeCurrent(display, 0, 0); + + GLX.glXDestroyGLXPixmap(display, drawable); + GLX.XFreePixmap(display, pixmap); + unlockAWT(); + drawable = 0; + pixmap = 0; + display = 0; + } + } + + public boolean isDoubleBuffered() { + return isDoubleBuffered; + } +} diff --git a/src/net/java/games/gluegen/runtime/BufferFactory.java b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java index 1661026dc..d6b79cb8f 100644 --- a/src/net/java/games/gluegen/runtime/BufferFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLContext.java @@ -37,39 +37,59 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.gluegen.runtime; +package com.sun.opengl.impl.x11; -import java.nio.*; +import java.util.*; -public class BufferFactory { - public static ByteBuffer newDirectByteBuffer(int size) { - ByteBuffer buf = ByteBuffer.allocateDirect(size); - buf.order(ByteOrder.nativeOrder()); - return buf; - } +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11OnscreenGLContext extends X11GLContext { + protected X11OnscreenGLDrawable drawable; - /** Helper routine to tell whether a buffer is direct or not. Null - pointers are considered direct. isDirect() should really be - public in Buffer and not replicated in all subclasses. */ - public static boolean isDirect(Buffer buf) { - if (buf == null) { - return true; + public X11OnscreenGLContext(X11OnscreenGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; + } + + protected int makeCurrentImpl() throws GLException { + try { + int lockRes = drawable.lockSurface(); + if (lockRes == X11OnscreenGLDrawable.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + if (lockRes == X11OnscreenGLDrawable.LOCK_SURFACE_CHANGED) { + if (context != 0) { + GLX.glXDestroyContext(mostRecentDisplay, context); + GLContextShareSet.contextDestroyed(this); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + toHexString(context) + " due to JAWT_LOCK_SURFACE_CHANGED"); + } + context = 0; + } + } + int ret = super.makeCurrentImpl(); + return ret; + } catch (RuntimeException e) { + try { + drawable.unlockSurface(); + } catch (Exception e2) { + // do nothing if unlockSurface throws + } + throw(e); } - if (buf instanceof ByteBuffer) { - return ((ByteBuffer) buf).isDirect(); - } else if (buf instanceof FloatBuffer) { - return ((FloatBuffer) buf).isDirect(); - } else if (buf instanceof DoubleBuffer) { - return ((DoubleBuffer) buf).isDirect(); - } else if (buf instanceof CharBuffer) { - return ((CharBuffer) buf).isDirect(); - } else if (buf instanceof ShortBuffer) { - return ((ShortBuffer) buf).isDirect(); - } else if (buf instanceof IntBuffer) { - return ((IntBuffer) buf).isDirect(); - } else if (buf instanceof LongBuffer) { - return ((LongBuffer) buf).isDirect(); + } + + protected void releaseImpl() throws GLException { + try { + super.releaseImpl(); + } finally { + drawable.unlockSurface(); } - throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); + } + + protected void create() { + createContext(true); } } diff --git a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java index 2fd340d79..49000fc14 100644 --- a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java +++ b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java @@ -37,135 +37,106 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.x11; +package com.sun.opengl.impl.x11; import java.awt.Component; -import java.util.*; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11OnscreenGLDrawable extends X11GLDrawable { + public static final int LOCK_SURFACE_NOT_READY = 1; + public static final int LOCK_SURFACE_CHANGED = 2; + public static final int LOCK_SUCCESS = 3; -public class X11OnscreenGLContext extends X11GLContext { // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; private JAWT_DrawingSurfaceInfo dsi; private JAWT_X11DrawingSurfaceInfo x11dsi; - - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); - - public X11OnscreenGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - protected boolean isOffscreen() { - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); + // Indicates whether the component (if an onscreen context) has been + // realized. Plausibly, before the component is realized the JAWT + // should return an error or NULL object from some of its + // operations; this appears to be the case on Win32 but is not true + // at least with Sun's current X11 implementation (1.4.x), which + // crashes with no other error reported if the DrawingSurfaceInfo is + // fetched from a locked DrawingSurface during the validation as a + // result of calling show() on the main thread. To work around this + // we prevent any JAWT or OpenGL operations from being done until + // addNotify() is called on the component. + protected boolean realized; + + public X11OnscreenGLDrawable(Component component) { + super(component, null, null); } - public boolean canCreatePbufferContext() { - // FIXME: should we gate this on GLX 1.3 being available? - return true; + public GLContext createContext(GLContext shareWith) { + return new X11OnscreenGLContext(this, shareWith); } - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - X11PbufferGLContext ctx = new X11PbufferGLContext(capabilities, initialWidth, initialHeight); - pbuffersToInstantiate.add(ctx); - return ctx; + public void setRealized(boolean realized) { + this.realized = realized; } - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); + public void setSize(int width, int height) { + component.setSize(width, height); } - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); + public int getWidth() { + return component.getWidth(); } - public void setSwapInterval(int interval) { - GL gl = getGL(); - if (gl.isExtensionAvailable("GLX_SGI_swap_control")) { - gl.glXSwapIntervalSGI(interval); - } + public int getHeight() { + return component.getHeight(); } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - try { - if (!lockSurface()) { - return false; - } - boolean ret = super.makeCurrent(initAction); - if (ret) { - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - X11PbufferGLContext ctx = - (X11PbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - ctx.createPbuffer(display, context, getGL()); + public void swapBuffers() throws GLException { + lockAWT(); + try { + boolean didLock = false; + + if (drawable == 0) { + if (lockSurface() == LOCK_SURFACE_NOT_READY) { + return; } + + didLock = true; } - return ret; - } catch (RuntimeException e) { - try { + + GLX.glXSwapBuffers(display, drawable); + + if (didLock) { unlockSurface(); - } catch (Exception e2) { - // do nothing if unlockSurface throws } - throw(e); - } - } - - protected synchronized void free() throws GLException { - try { - super.free(); } finally { - unlockSurface(); + unlockAWT(); } } - public synchronized void swapBuffers() throws GLException { - // FIXME: this cast to int would be wrong on 64-bit platforms - // where the argument type to glXMakeCurrent would change (should - // probably make GLXDrawable, and maybe XID, Opaque as long) - GLX.glXSwapBuffers(display, (int) drawable); - } - - private boolean lockSurface() throws GLException { + public int lockSurface() throws GLException { + if (!realized) { + return LOCK_SURFACE_NOT_READY; + } if (drawable != 0) { throw new GLException("Surface already locked"); } ds = getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - return false; + return LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { throw new GLException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old - // OpenGL context so it will be recreated + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + int ret = LOCK_SUCCESS; if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { - if (context != 0) { - GLX.glXDestroyContext(display, context); - context = 0; - } + ret = LOCK_SURFACE_CHANGED; } dsi = ds.GetDrawingSurfaceInfo(); if (dsi == null) { @@ -173,7 +144,7 @@ public class X11OnscreenGLContext extends X11GLContext { ds.Unlock(); getJAWT().FreeDrawingSurface(ds); ds = null; - return false; + return LOCK_SURFACE_NOT_READY; } x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); display = x11dsi.display(); @@ -190,13 +161,12 @@ public class X11OnscreenGLContext extends X11GLContext { display = 0; drawable = 0; visualID = 0; - return false; + return LOCK_SURFACE_NOT_READY; } - mostRecentDisplay = display; - return true; + return ret; } - private void unlockSurface() { + public void unlockSurface() { if (drawable == 0) { throw new GLException("Surface already unlocked"); } @@ -211,7 +181,11 @@ public class X11OnscreenGLContext extends X11GLContext { visualID = 0; } - protected void create() { - chooseVisualAndCreateContext(true); - } + //---------------------------------------------------------------------- + // Internals only below this point + // + + private JAWT getJAWT() { + return X11GLDrawableFactory.getJAWT(); + } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java new file mode 100644 index 000000000..0cb945de7 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java @@ -0,0 +1,151 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11PbufferGLContext extends X11GLContext { + private X11PbufferGLDrawable drawable; + + public X11PbufferGLContext(X11PbufferGLDrawable drawable, + GLContext shareWith) { + super(drawable, shareWith); + this.drawable = drawable; + } + + public void bindPbufferToTexture() { + // FIXME: figure out how to implement this + throw new GLException("Not yet implemented"); + } + + public void releasePbufferFromTexture() { + // FIXME: figure out how to implement this + throw new GLException("Not yet implemented"); + } + + protected int makeCurrentImpl() throws GLException { + if (drawable.getDrawable() == 0) { + // pbuffer not instantiated (yet?) + if (DEBUG) { + System.err.println("pbuffer not instantiated"); + } + return CONTEXT_NOT_CURRENT; + } + + // Note that we have to completely override makeCurrentImpl + // because the underlying makeCurrent call differs for pbuffers + lockAWT(); + try { + boolean created = false; + if (context == 0) { + create(); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); + } + created = true; + } + + if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), + drawable.getDrawable(), + drawable.getDrawable(), + context)) { + throw new GLException("Error making context current"); + } else { + mostRecentDisplay = drawable.getDisplay(); + if (DEBUG && VERBOSE) { + System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(drawable.getDisplay()) + + ", drawable " + toHexString(drawable.getDrawable()) + + ", context " + toHexString(context) + ") succeeded"); + } + } + + if (created) { + resetGLFunctionAvailability(); + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } finally { + unlockAWT(); + } + } + + protected void releaseImpl() throws GLException { + lockAWT(); + try { + if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), 0, 0, 0)) { + throw new GLException("Error freeing OpenGL context"); + } + } finally { + unlockAWT(); + } + } + + public int getFloatingPointMode() { + return drawable.getFloatingPointMode(); + } + + protected void create() { + if (DEBUG) { + System.err.println("Creating context for pbuffer " + drawable.getWidth() + + " x " + drawable.getHeight()); + } + + // Create a gl context for the p-buffer. + X11GLContext other = (X11GLContext) GLContextShareSet.getShareContext(this); + long share = 0; + if (other != null) { + share = other.getContext(); + if (share == 0) { + throw new GLException("GLContextShareSet returned an invalid OpenGL context"); + } + } + context = GLX.glXCreateNewContext(drawable.getDisplay(), drawable.getFBConfig(), GLXExt.GLX_RGBA_TYPE, share, true); + if (context == 0) { + throw new GLException("pbuffer creation error: glXCreateNewContext() failed"); + } + GLContextShareSet.contextCreated(this); + + if (DEBUG) { + System.err.println("Created context for pbuffer " + drawable.getWidth() + + " x " + drawable.getHeight()); + } + } +} diff --git a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java new file mode 100644 index 000000000..2a1248405 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java @@ -0,0 +1,264 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.impl.x11; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class X11PbufferGLDrawable extends X11GLDrawable { + private int initWidth; + private int initHeight; + + // drawable in superclass is a GLXPbuffer + private GLXFBConfig fbConfig; + private int width; + private int height; + + protected static final int MAX_PFORMATS = 256; + protected static final int MAX_ATTRIBS = 256; + + public X11PbufferGLDrawable(GLCapabilities capabilities, int initialWidth, int initialHeight) { + super(null, capabilities, null); + this.initWidth = initialWidth; + this.initHeight = initialHeight; + if (initWidth <= 0 || initHeight <= 0) { + throw new GLException("Initial width and height of pbuffer must be positive (were (" + + initWidth + ", " + initHeight + "))"); + } + + if (DEBUG) { + System.out.println("Pbuffer caps on init: " + capabilities + + (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + + (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + + (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); + } + + createPbuffer(X11GLDrawableFactory.getDisplayConnection()); + } + + public GLContext createContext(GLContext shareWith) { + return new X11PbufferGLContext(this, shareWith); + } + + public void destroy() { + lockAWT(); + if (drawable != 0) { + GLX.glXDestroyPbuffer(display, drawable); + } + unlockAWT(); + display = 0; + } + + public void setSize(int width, int height) { + // FIXME + throw new GLException("Not yet implemented"); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public void createPbuffer(long display) { + lockAWT(); + try { + if (display == 0) { + throw new GLException("Null display"); + } + + if (capabilities.getOffscreenRenderToTexture()) { + throw new GLException("Render-to-texture pbuffers not supported yet on X11"); + } + + if (capabilities.getOffscreenRenderToTextureRectangle()) { + throw new GLException("Render-to-texture-rectangle pbuffers not supported yet on X11"); + } + + int[] iattributes = new int [2*MAX_ATTRIBS]; + float[] fattributes = new float[2*MAX_ATTRIBS]; + int nfattribs = 0; + int niattribs = 0; + + // Since we are trying to create a pbuffer, the GLXFBConfig we + // request (and subsequently use) must be "p-buffer capable". + iattributes[niattribs++] = GLXExt.GLX_DRAWABLE_TYPE; + iattributes[niattribs++] = GLXExt.GLX_PBUFFER_BIT; + + iattributes[niattribs++] = GLXExt.GLX_RENDER_TYPE; + iattributes[niattribs++] = GLXExt.GLX_RGBA_BIT; + + iattributes[niattribs++] = GLX.GLX_DOUBLEBUFFER; + if (capabilities.getDoubleBuffered()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + + iattributes[niattribs++] = GLX.GLX_DEPTH_SIZE; + iattributes[niattribs++] = capabilities.getDepthBits(); + + iattributes[niattribs++] = GLX.GLX_RED_SIZE; + iattributes[niattribs++] = capabilities.getRedBits(); + + iattributes[niattribs++] = GLX.GLX_GREEN_SIZE; + iattributes[niattribs++] = capabilities.getGreenBits(); + + iattributes[niattribs++] = GLX.GLX_BLUE_SIZE; + iattributes[niattribs++] = capabilities.getBlueBits(); + + iattributes[niattribs++] = GLX.GLX_ALPHA_SIZE; + iattributes[niattribs++] = capabilities.getAlphaBits(); + + if (capabilities.getStencilBits() > 0) { + iattributes[niattribs++] = GLX.GLX_STENCIL_SIZE; + iattributes[niattribs++] = capabilities.getStencilBits(); + } + + if (capabilities.getAccumRedBits() > 0 || + capabilities.getAccumGreenBits() > 0 || + capabilities.getAccumBlueBits() > 0) { + iattributes[niattribs++] = GLX.GLX_ACCUM_RED_SIZE; + iattributes[niattribs++] = capabilities.getAccumRedBits(); + iattributes[niattribs++] = GLX.GLX_ACCUM_GREEN_SIZE; + iattributes[niattribs++] = capabilities.getAccumGreenBits(); + iattributes[niattribs++] = GLX.GLX_ACCUM_BLUE_SIZE; + iattributes[niattribs++] = capabilities.getAccumBlueBits(); + } + + int screen = 0; // FIXME: provide way to specify this? + + if (capabilities.getOffscreenFloatingPointBuffers()) { + String glXExtensions = GLX.glXQueryExtensionsString(display, screen); + if (glXExtensions == null || + glXExtensions.indexOf("GLX_NV_float_buffer") < 0) { + throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware"); + } + iattributes[niattribs++] = GLX.GLX_FLOAT_COMPONENTS_NV; + iattributes[niattribs++] = GL.GL_TRUE; + } + + // FIXME: add FSAA support? Don't want to get into a situation + // where we have to retry the glXChooseFBConfig call if it fails + // due to a lack of an antialiased visual... + + iattributes[niattribs++] = 0; // null-terminate + + int[] nelementsTmp = new int[1]; + GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, 0, nelementsTmp, 0); + if (fbConfigs == null || fbConfigs.length == 0 || fbConfigs[0] == null) { + throw new GLException("pbuffer creation error: glXChooseFBConfig() failed"); + } + int nelements = nelementsTmp[0]; + if (nelements <= 0) { + throw new GLException("pbuffer creation error: couldn't find a suitable frame buffer configuration"); + } + // Note that we currently don't allow selection of anything but + // the first GLXFBConfig in the returned list + GLXFBConfig fbConfig = fbConfigs[0]; + + if (DEBUG) { + System.err.println("Found " + fbConfigs.length + " matching GLXFBConfigs"); + System.err.println("Parameters of default one:"); + System.err.println("render type: 0x" + Integer.toHexString(queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE))); + System.err.println("rgba: " + ((queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE) & GLX.GLX_RGBA_BIT) != 0)); + System.err.println("r: " + queryFBConfig(display, fbConfig, GLX.GLX_RED_SIZE)); + System.err.println("g: " + queryFBConfig(display, fbConfig, GLX.GLX_GREEN_SIZE)); + System.err.println("b: " + queryFBConfig(display, fbConfig, GLX.GLX_BLUE_SIZE)); + System.err.println("a: " + queryFBConfig(display, fbConfig, GLX.GLX_ALPHA_SIZE)); + System.err.println("depth: " + queryFBConfig(display, fbConfig, GLX.GLX_DEPTH_SIZE)); + System.err.println("double buffered: " + queryFBConfig(display, fbConfig, GLX.GLX_DOUBLEBUFFER)); + } + + // Create the p-buffer. + niattribs = 0; + + iattributes[niattribs++] = GLXExt.GLX_PBUFFER_WIDTH; + iattributes[niattribs++] = initWidth; + iattributes[niattribs++] = GLXExt.GLX_PBUFFER_HEIGHT; + iattributes[niattribs++] = initHeight; + + iattributes[niattribs++] = 0; + + long tmpBuffer = GLX.glXCreatePbuffer(display, fbConfig, iattributes, 0); + if (tmpBuffer == 0) { + // FIXME: query X error code for detail error message + throw new GLException("pbuffer creation error: glXCreatePbuffer() failed"); + } + + // Set up instance variables + this.display = display; + drawable = tmpBuffer; + this.fbConfig = fbConfig; + + // Determine the actual width and height we were able to create. + int[] tmp = new int[1]; + GLX.glXQueryDrawable(display, drawable, GLXExt.GLX_WIDTH, tmp, 0); + width = tmp[0]; + GLX.glXQueryDrawable(display, drawable, GLXExt.GLX_HEIGHT, tmp, 0); + height = tmp[0]; + + if (DEBUG) { + System.err.println("Created pbuffer " + width + " x " + height); + } + } finally { + unlockAWT(); + } + } + + public int getFloatingPointMode() { + // Floating-point pbuffers currently require NVidia hardware on X11 + return GLPbuffer.NV_FLOAT; + } + + public GLXFBConfig getFBConfig() { + return fbConfig; + } + + private int queryFBConfig(long display, GLXFBConfig fbConfig, int attrib) { + int[] tmp = new int[1]; + if (GLX.glXGetFBConfigAttrib(display, fbConfig, attrib, tmp, 0) != 0) { + throw new GLException("glXGetFBConfigAttrib failed"); + } + return tmp[0]; + } +} diff --git a/src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java b/src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java index 59208e5a9..0760399ab 100755..100644 --- a/src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java +++ b/src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.impl.x11; +package com.sun.opengl.impl.x11; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; diff --git a/src/classes/com/sun/opengl/utils/Animator.java b/src/classes/com/sun/opengl/utils/Animator.java new file mode 100755 index 000000000..5920b93b9 --- /dev/null +++ b/src/classes/com/sun/opengl/utils/Animator.java @@ -0,0 +1,308 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.utils; + +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Rectangle; +import java.util.*; +import javax.swing.*; + +import javax.media.opengl.*; + +/** <P> An Animator can be attached to one or more {@link + GLAutoDrawable}s to drive their display() methods in a loop. </P> + + <P> The Animator class creates a background thread in which the + calls to <code>display()</code> are performed. After each drawable + has been redrawn, a brief pause is performed to avoid swamping the + CPU, unless {@link #setRunAsFastAsPossible} has been called. </P> +*/ + +public class Animator { + private volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + private Runnable runnable; + private Thread thread; + private volatile boolean shouldStop; + protected boolean ignoreExceptions; + protected boolean printExceptions; + private boolean runAsFastAsPossible; + + // For efficient rendering of Swing components, in particular when + // they overlap one another + private List lightweights = new ArrayList(); + private Map repaintManagers = new IdentityHashMap(); + private Map dirtyRegions = new IdentityHashMap(); + + /** Creates a new, empty Animator. */ + public Animator() { + } + + /** Creates a new Animator for a particular drawable. */ + public Animator(GLAutoDrawable drawable) { + add(drawable); + } + + /** Adds a drawable to the list managed by this Animator. */ + public synchronized void add(GLAutoDrawable drawable) { + ArrayList newList = (ArrayList) drawables.clone(); + newList.add(drawable); + drawables = newList; + notifyAll(); + } + + /** Removes a drawable from the list managed by this Animator. */ + public synchronized void remove(GLAutoDrawable drawable) { + ArrayList newList = (ArrayList) drawables.clone(); + newList.remove(drawable); + drawables = newList; + } + + /** Returns an iterator over the drawables managed by this + Animator. */ + public Iterator/*<GLAutoDrawable>*/ drawableIterator() { + return drawables.iterator(); + } + + /** Sets a flag causing this Animator to ignore exceptions produced + while redrawing the drawables. By default this flag is set to + false, causing any exception thrown to halt the Animator. */ + public void setIgnoreExceptions(boolean ignoreExceptions) { + this.ignoreExceptions = ignoreExceptions; + } + + /** Sets a flag indicating that when exceptions are being ignored by + this Animator (see {@link #setIgnoreExceptions}), to print the + exceptions' stack traces for diagnostic information. Defaults to + false. */ + public void setPrintExceptions(boolean printExceptions) { + this.printExceptions = printExceptions; + } + + /** Sets a flag in this Animator indicating that it is to run as + fast as possible. By default there is a brief pause in the + animation loop which prevents the CPU from getting swamped. + This method may not have an effect on subclasses. */ + public final void setRunAsFastAsPossible(boolean runFast) { + runAsFastAsPossible = runFast; + } + + /** Called every frame to cause redrawing of all of the + GLAutoDrawables this Animator manages. Subclasses should call + this to get the most optimized painting behavior for the set of + components this Animator manages, in particular when multiple + lightweight widgets are continually being redrawn. */ + protected void display() { + Iterator iter = drawableIterator(); + while (iter.hasNext()) { + GLAutoDrawable drawable = (GLAutoDrawable) iter.next(); + if (drawable instanceof JComponent) { + // Lightweight components need a more efficient drawing + // scheme than simply forcing repainting of each one in + // turn since drawing one can force another one to be + // drawn in turn + lightweights.add(drawable); + } else { + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); + } + } + } + } + if (lightweights.size() > 0) { + try { + SwingUtilities.invokeAndWait(drawWithRepaintManagerRunnable); + } catch (Exception e) { + e.printStackTrace(); + } + lightweights.clear(); + } + } + + class MainLoop implements Runnable { + public void run() { + try { + while (!shouldStop) { + // Don't consume CPU unless there is work to be done + if (drawables.size() == 0) { + synchronized (Animator.this) { + while (drawables.size() == 0 && !shouldStop) { + try { + Animator.this.wait(); + } catch (InterruptedException e) { + } + } + } + } + display(); + if (!runAsFastAsPossible) { + // Avoid swamping the CPU + Thread.yield(); + } + } + } finally { + shouldStop = false; + synchronized (Animator.this) { + thread = null; + Animator.this.notify(); + } + } + } + } + + /** Starts this animator. */ + public synchronized void start() { + if (thread != null) { + throw new GLException("Already started"); + } + if (runnable == null) { + runnable = new MainLoop(); + } + thread = new Thread(runnable); + thread.start(); + } + + /** Indicates whether this animator is currently running. This + should only be used as a heuristic to applications because in + some circumstances the Animator may be in the process of + shutting down and this method will still return true. */ + public synchronized boolean isAnimating() { + return (thread != null); + } + + /** Stops this animator. In most situations this method blocks until + completion, except when called from the animation thread itself + or in some cases from an implementation-internal thread like the + AWT event queue thread. */ + public synchronized void stop() { + shouldStop = true; + notifyAll(); + // It's hard to tell whether the thread which calls stop() has + // dependencies on the Animator's internal thread. Currently we + // use a couple of heuristics to determine whether we should do + // the blocking wait(). + if ((Thread.currentThread() == thread) || EventQueue.isDispatchThread()) { + return; + } + while (shouldStop && thread != null) { + try { + wait(); + } catch (InterruptedException ie) { + } + } + } + + // Uses RepaintManager APIs to implement more efficient redrawing of + // the Swing widgets we're animating + private Runnable drawWithRepaintManagerRunnable = new Runnable() { + public void run() { + for (Iterator iter = lightweights.iterator(); iter.hasNext(); ) { + JComponent comp = (JComponent) iter.next(); + RepaintManager rm = RepaintManager.currentManager(comp); + rm.markCompletelyDirty(comp); + repaintManagers.put(rm, rm); + + // RepaintManagers don't currently optimize the case of + // overlapping sibling components. If we have two + // JInternalFrames in a JDesktopPane, the redraw of the + // bottom one will cause the top one to be redrawn as + // well. The top one will then be redrawn separately. In + // order to optimize this case we need to compute the union + // of all of the dirty regions on a particular JComponent if + // optimized drawing isn't enabled for it. + + // Walk up the hierarchy trying to find a non-optimizable + // ancestor + Rectangle visible = comp.getVisibleRect(); + int x = visible.x; + int y = visible.y; + while (comp != null) { + x += comp.getX(); + y += comp.getY(); + Component c = comp.getParent(); + if ((c == null) || (!(c instanceof JComponent))) { + comp = null; + } else { + comp = (JComponent) c; + if (!comp.isOptimizedDrawingEnabled()) { + rm = RepaintManager.currentManager(comp); + repaintManagers.put(rm, rm); + // Need to dirty this region + Rectangle dirty = (Rectangle) dirtyRegions.get(comp); + if (dirty == null) { + dirty = new Rectangle(x, y, visible.width, visible.height); + dirtyRegions.put(comp, dirty); + } else { + // Compute union with already dirty region + // Note we could compute multiple non-overlapping + // regions: might want to do that in the future + // (prob. need more complex algorithm -- dynamic + // programming?) + dirty.add(new Rectangle(x, y, visible.width, visible.height)); + } + } + } + } + } + + // Dirty any needed regions on non-optimizable components + for (Iterator iter = dirtyRegions.keySet().iterator(); iter.hasNext(); ) { + JComponent comp = (JComponent) iter.next(); + Rectangle rect = (Rectangle) dirtyRegions.get(comp); + RepaintManager rm = RepaintManager.currentManager(comp); + rm.addDirtyRegion(comp, rect.x, rect.y, rect.width, rect.height); + } + + // Draw all dirty regions + for (Iterator iter = repaintManagers.keySet().iterator(); iter.hasNext(); ) { + ((RepaintManager) iter.next()).paintDirtyRegions(); + } + dirtyRegions.clear(); + repaintManagers.clear(); + } + }; +} diff --git a/src/net/java/games/jogl/util/BitmapCharRec.java b/src/classes/com/sun/opengl/utils/BitmapCharRec.java index 642bbb465..a24ab1122 100644 --- a/src/net/java/games/jogl/util/BitmapCharRec.java +++ b/src/classes/com/sun/opengl/utils/BitmapCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/jogl/util/BitmapFontRec.java b/src/classes/com/sun/opengl/utils/BitmapFontRec.java index 32ea9c183..c300ad159 100644 --- a/src/net/java/games/jogl/util/BitmapFontRec.java +++ b/src/classes/com/sun/opengl/utils/BitmapFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/classes/com/sun/opengl/utils/BufferUtils.java b/src/classes/com/sun/opengl/utils/BufferUtils.java new file mode 100644 index 000000000..995fa0646 --- /dev/null +++ b/src/classes/com/sun/opengl/utils/BufferUtils.java @@ -0,0 +1,266 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.utils; + +import java.nio.*; +import java.util.*; + +/** Utility routines for dealing with direct buffers. */ + +public class BufferUtils { + public static final int SIZEOF_BYTE = 1; + public static final int SIZEOF_SHORT = 2; + public static final int SIZEOF_INT = 4; + public static final int SIZEOF_FLOAT = 4; + public static final int SIZEOF_LONG = 8; + public static final int SIZEOF_DOUBLE = 8; + + //---------------------------------------------------------------------- + // Allocation routines + // + + /** Allocates a new direct ByteBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static ByteBuffer newByteBuffer(int numElements) { + ByteBuffer bb = ByteBuffer.allocateDirect(numElements); + bb.order(ByteOrder.nativeOrder()); + return bb; + } + + /** Allocates a new direct DoubleBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static DoubleBuffer newDoubleBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); + return bb.asDoubleBuffer(); + } + + /** Allocates a new direct FloatBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static FloatBuffer newFloatBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); + return bb.asFloatBuffer(); + } + + /** Allocates a new direct IntBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static IntBuffer newIntBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); + return bb.asIntBuffer(); + } + + /** Allocates a new direct LongBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static LongBuffer newLongBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); + return bb.asLongBuffer(); + } + + /** Allocates a new direct ShortBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static ShortBuffer newShortBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); + return bb.asShortBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-type) + // + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed ByteBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyByteBuffer(ByteBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining()); + orig.mark(); + dest.put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed DoubleBuffer + into a newly-allocated direct DoubleBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static DoubleBuffer copyDoubleBuffer(DoubleBuffer orig) { + return copyDoubleBufferAsByteBuffer(orig).asDoubleBuffer(); + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed FloatBuffer + into a newly-allocated direct FloatBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { + return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed IntBuffer + into a newly-allocated direct IntBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static IntBuffer copyIntBuffer(IntBuffer orig) { + return copyIntBufferAsByteBuffer(orig).asIntBuffer(); + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed LongBuffer + into a newly-allocated direct LongBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static LongBuffer copyLongBuffer(LongBuffer orig) { + return copyLongBufferAsByteBuffer(orig).asLongBuffer(); + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed ShortBuffer + into a newly-allocated direct ShortBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ShortBuffer copyShortBuffer(ShortBuffer orig) { + return copyShortBufferAsByteBuffer(orig).asShortBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-ByteBuffer) + // + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed DoubleBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyDoubleBufferAsByteBuffer(DoubleBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_DOUBLE); + orig.mark(); + dest.asDoubleBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed FloatBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); + orig.mark(); + dest.asFloatBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed IntBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); + orig.mark(); + dest.asIntBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed LongBuffer into + a newly-allocated direct ByteBuffer. The returned buffer will + have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyLongBufferAsByteBuffer(LongBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_LONG); + orig.mark(); + dest.asLongBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } + + /** Copies the <i>remaining</i> elements (as defined by + <code>limit() - position()</code>) in the passed ShortBuffer + into a newly-allocated direct ByteBuffer. The returned buffer + will have its byte order set to the host platform's native byte + order. The position of the newly-allocated buffer will be zero, + and the position of the passed buffer is unchanged (though its + mark is changed). */ + public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { + ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); + orig.mark(); + dest.asShortBuffer().put(orig); + orig.reset(); + dest.rewind(); + return dest; + } +} diff --git a/src/net/java/games/jogl/util/CoordRec.java b/src/classes/com/sun/opengl/utils/CoordRec.java index 661ed23ff..44f786377 100644 --- a/src/net/java/games/jogl/util/CoordRec.java +++ b/src/classes/com/sun/opengl/utils/CoordRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/classes/com/sun/opengl/utils/FPSAnimator.java b/src/classes/com/sun/opengl/utils/FPSAnimator.java new file mode 100755 index 000000000..c45ff15c4 --- /dev/null +++ b/src/classes/com/sun/opengl/utils/FPSAnimator.java @@ -0,0 +1,99 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package com.sun.opengl.utils; + +import java.util.*; +import javax.media.opengl.*; + +/** An Animator subclass which attempts to achieve a target + frames-per-second rate to avoid using all CPU time. The target FPS + is only an estimate and is not guaranteed. */ + +public class FPSAnimator extends Animator { + private Timer timer; + private int fps; + + /** Creates an FPSAnimator with a given target frames-per-second value. */ + public FPSAnimator(int fps) { + this(null, fps); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value and an initial drawable to animate. */ + public FPSAnimator(GLAutoDrawable drawable, int fps) { + this.fps = fps; + if (drawable != null) { + add(drawable); + } + } + + /** Starts this FPSAnimator. */ + public synchronized void start() { + if (timer != null) { + throw new GLException("Already started"); + } + timer = new Timer(); + long delay = (long) (1000.0f / (float) fps); + timer.schedule(new TimerTask() { + public void run() { + display(); + } + }, 0, delay); + } + + /** Indicates whether this FPSAnimator is currently running. This + should only be used as a heuristic to applications because in + some circumstances the FPSAnimator may be in the process of + shutting down and this method will still return true. */ + public synchronized boolean isAnimating() { + return (timer != null); + } + + /** Stops this FPSAnimator. Due to the implementation of the + FPSAnimator it is not guaranteed that the FPSAnimator will be + completely stopped by the time this method returns. */ + public synchronized void stop() { + if (timer == null) { + throw new GLException("Already stopped"); + } + timer.cancel(); + timer = null; + } +} diff --git a/src/net/java/games/jogl/util/GLUT.java b/src/classes/com/sun/opengl/utils/GLUT.java index 9f9ed1558..2896729e2 100644 --- a/src/net/java/games/jogl/util/GLUT.java +++ b/src/classes/com/sun/opengl/utils/GLUT.java @@ -37,9 +37,10 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; -import net.java.games.jogl.*; +import javax.media.opengl.*; +import javax.media.opengl.glu.*; /** Subset of the routines provided by the GLUT interface. Note the signatures of many of the methods are necessarily different than @@ -101,11 +102,13 @@ public class GLUT { public static final int BITMAP_HELVETICA_12 = 7; public static final int BITMAP_HELVETICA_18 = 8; + private GLU glu = new GLU(); + //---------------------------------------------------------------------- // Shapes // - public void glutWireSphere(GLU glu, double radius, int slices, int stacks) { + public void glutWireSphere(double radius, int slices, int stacks) { quadObjInit(glu); glu.gluQuadricDrawStyle(quadObj, GLU.GLU_LINE); glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); @@ -115,7 +118,7 @@ public class GLUT { glu.gluSphere(quadObj, radius, slices, stacks); } - public void glutSolidSphere(GLU glu, double radius, int slices, int stacks) { + public void glutSolidSphere(double radius, int slices, int stacks) { quadObjInit(glu); glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL); glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH); @@ -125,8 +128,7 @@ public class GLUT { glu.gluSphere(quadObj, radius, slices, stacks); } - public void glutWireCone(GLU glu, - double base, double height, + public void glutWireCone(double base, double height, int slices, int stacks) { quadObjInit(glu); glu.gluQuadricDrawStyle(quadObj, GLU.GLU_LINE); @@ -137,8 +139,7 @@ public class GLUT { glu.gluCylinder(quadObj, base, 0.0, height, slices, stacks); } - public void glutSolidCone(GLU glu, - double base, double height, + public void glutSolidCone(double base, double height, int slices, int stacks) { quadObjInit(glu); glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL); @@ -149,72 +150,69 @@ public class GLUT { glu.gluCylinder(quadObj, base, 0.0, height, slices, stacks); } - public void glutWireCube(GL gl, float size) { - drawBox(gl, size, GL.GL_LINE_LOOP); + public void glutWireCube(float size) { + drawBox(GLU.getCurrentGL(), size, GL.GL_LINE_LOOP); } - public void glutSolidCube(GL gl, float size) { - drawBox(gl, size, GL.GL_QUADS); + public void glutSolidCube(float size) { + drawBox(GLU.getCurrentGL(), size, GL.GL_QUADS); } - public void glutWireTorus(GL gl, - double innerRadius, double outerRadius, + public void glutWireTorus(double innerRadius, double outerRadius, int nsides, int rings) { + GL gl = GLU.getCurrentGL(); gl.glPushAttrib(GL.GL_POLYGON_BIT); gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); doughnut(gl, innerRadius, outerRadius, nsides, rings); gl.glPopAttrib(); } - public void glutSolidTorus(GL gl, - double innerRadius, double outerRadius, + public void glutSolidTorus(double innerRadius, double outerRadius, int nsides, int rings) { - doughnut(gl, innerRadius, outerRadius, nsides, rings); + doughnut(GLU.getCurrentGL(), innerRadius, outerRadius, nsides, rings); } - public void glutWireDodecahedron(GL gl) { - dodecahedron(gl, GL.GL_LINE_LOOP); + public void glutWireDodecahedron() { + dodecahedron(GLU.getCurrentGL(), GL.GL_LINE_LOOP); } - public void glutSolidDodecahedron(GL gl) { - dodecahedron(gl, GL.GL_TRIANGLE_FAN); + public void glutSolidDodecahedron() { + dodecahedron(GLU.getCurrentGL(), GL.GL_TRIANGLE_FAN); } - public void glutWireOctahedron(GL gl) { - octahedron(gl, GL.GL_LINE_LOOP); + public void glutWireOctahedron() { + octahedron(GLU.getCurrentGL(), GL.GL_LINE_LOOP); } - public void glutSolidOctahedron(GL gl) { - octahedron(gl, GL.GL_TRIANGLES); + public void glutSolidOctahedron() { + octahedron(GLU.getCurrentGL(), GL.GL_TRIANGLES); } - public void glutWireIcosahedron(GL gl) { - icosahedron(gl, GL.GL_LINE_LOOP); + public void glutWireIcosahedron() { + icosahedron(GLU.getCurrentGL(), GL.GL_LINE_LOOP); } - public void glutSolidIcosahedron(GL gl) { - icosahedron(gl, GL.GL_TRIANGLES); + public void glutSolidIcosahedron() { + icosahedron(GLU.getCurrentGL(), GL.GL_TRIANGLES); } - public void glutWireTetrahedron(GL gl) { - tetrahedron(gl, GL.GL_LINE_LOOP); + public void glutWireTetrahedron() { + tetrahedron(GLU.getCurrentGL(), GL.GL_LINE_LOOP); } - public void glutSolidTetrahedron(GL gl) { - tetrahedron(gl, GL.GL_TRIANGLES); + public void glutSolidTetrahedron() { + tetrahedron(GLU.getCurrentGL(), GL.GL_TRIANGLES); } /** * Renders the teapot as a solid shape of the specified size. The teapot is * created in a way that replicates the C GLUT implementation. * - * @param gl - * the OpenGL context in which to render the teapot * @param scale * the factor by which to scale the teapot */ - public void glutSolidTeapot(GL gl, double scale) { - glutSolidTeapot(gl, scale, true); + public void glutSolidTeapot(double scale) { + glutSolidTeapot(scale, true); } /** @@ -226,29 +224,25 @@ public class GLUT { * for the teapot are generated. The teapot is generated with OpenGL * evaluators. * - * @param gl - * the OpenGL context in which to render the teapot * @param scale * the factor by which to scale the teapot * @param cStyle * whether to create the teapot in exactly the same way as in the C * implementation of GLUT */ - public void glutSolidTeapot(GL gl, double scale, boolean cStyle) { - teapot(gl, 14, scale, GL.GL_FILL, cStyle); + public void glutSolidTeapot(double scale, boolean cStyle) { + teapot(GLU.getCurrentGL(), 14, scale, GL.GL_FILL, cStyle); } /** * Renders the teapot as a wireframe shape of the specified size. The teapot * is created in a way that replicates the C GLUT implementation. * - * @param gl - * the OpenGL context in which to render the teapot * @param scale * the factor by which to scale the teapot */ - public void glutWireTeapot(GL gl, double scale) { - glutWireTeapot(gl, scale, true); + public void glutWireTeapot(double scale) { + glutWireTeapot(scale, true); } /** @@ -260,30 +254,29 @@ public class GLUT { * coordinates for the teapot are generated. The teapot is generated with * OpenGL evaluators. * - * @param gl - * the OpenGL context in which to render the teapot * @param scale * the factor by which to scale the teapot * @param cStyle * whether to create the teapot in exactly the same way as in the C * implementation of GLUT */ - public void glutWireTeapot(GL gl, double scale, boolean cStyle) { - teapot(gl, 10, scale, GL.GL_LINE, cStyle); + public void glutWireTeapot(double scale, boolean cStyle) { + teapot(GLU.getCurrentGL(), 10, scale, GL.GL_LINE, cStyle); } //---------------------------------------------------------------------- // Fonts // - public void glutBitmapCharacter(GL gl, int font, char character) { + public void glutBitmapCharacter(int font, char character) { + GL gl = GLU.getCurrentGL(); int[] swapbytes = new int[1]; int[] lsbfirst = new int[1]; int[] rowlength = new int[1]; int[] skiprows = new int[1]; int[] skippixels = new int[1]; int[] alignment = new int[1]; - beginBitmap(gl, + beginBitmap(gl, swapbytes, lsbfirst, rowlength, @@ -291,7 +284,7 @@ public class GLUT { skippixels, alignment); bitmapCharacterImpl(gl, font, character); - endBitmap(gl, + endBitmap(gl, swapbytes, lsbfirst, rowlength, @@ -300,7 +293,8 @@ public class GLUT { alignment); } - public void glutBitmapString (GL gl, int font, String string) { + public void glutBitmapString (int font, String string) { + GL gl = GLU.getCurrentGL(); int[] swapbytes = new int[1]; int[] lsbfirst = new int[1]; int[] rowlength = new int[1]; @@ -339,7 +333,8 @@ public class GLUT { return 0; } - public void glutStrokeCharacter(GL gl, int font, char character) { + public void glutStrokeCharacter(int font, char character) { + GL gl = GLU.getCurrentGL(); StrokeFontRec fontinfo = getStrokeFont(font); int c = character & 0xFFFF; if (c < 0 || c >= fontinfo.num_chars) @@ -359,7 +354,8 @@ public class GLUT { } } - public void glutStrokeString(GL gl, int font, String string) { + public void glutStrokeString(int font, String string) { + GL gl = GLU.getCurrentGL(); StrokeFontRec fontinfo = getStrokeFont(font); int len = string.length(); for (int pos = 0; pos < len; pos++) { @@ -525,7 +521,7 @@ public class GLUT { int[][] faces = boxFaces; for (int i = 5; i >= 0; i--) { gl.glBegin(type); - gl.glNormal3fv(n[i]); + gl.glNormal3fv(n[i], 0); float[] vt = v[faces[i][0]]; gl.glVertex3f(vt[0] * size, vt[1] * size, vt[2] * size); vt = v[faces[i][1]]; @@ -614,12 +610,12 @@ public class GLUT { normalize(n0); gl.glBegin(shadeType); - gl.glNormal3fv(n0); - gl.glVertex3fv(dodec[a]); - gl.glVertex3fv(dodec[b]); - gl.glVertex3fv(dodec[c]); - gl.glVertex3fv(dodec[d]); - gl.glVertex3fv(dodec[e]); + gl.glNormal3fv(n0, 0); + gl.glVertex3fv(dodec[a], 0); + gl.glVertex3fv(dodec[b], 0); + gl.glVertex3fv(dodec[c], 0); + gl.glVertex3fv(dodec[d], 0); + gl.glVertex3fv(dodec[e], 0); gl.glEnd(); } @@ -651,10 +647,10 @@ public class GLUT { normalize(q1); gl.glBegin(shadeType); - gl.glNormal3fv(q1); - gl.glVertex3fv(n1); - gl.glVertex3fv(n2); - gl.glVertex3fv(n3); + gl.glNormal3fv(q1, 0); + gl.glVertex3fv(n1, 0); + gl.glVertex3fv(n2, 0); + gl.glVertex3fv(n3, 0); gl.glEnd(); } @@ -1024,16 +1020,16 @@ public class GLUT { } } } - gl.glMap2f(GL.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, teapotTex); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p); + gl.glMap2f(GL.GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, teapotTex, 0); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, p, 0); gl.glMapGrid2f(grid, 0.0f, 1.0f, grid, 0.0f, 1.0f); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, q, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); if (i < 6) { - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, r, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); - gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s); + gl.glMap2f(GL.GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, s, 0); evaluateTeapotMesh(gl, grid, type, i, !backCompatible); } } @@ -1101,7 +1097,7 @@ public class GLUT { BitmapCharRec ch = fontinfo.ch[c - fontinfo.first]; if (ch != null) { gl.glBitmap(ch.width, ch.height, ch.xorig, ch.yorig, - ch.advance, 0, ch.bitmap); + ch.advance, 0, ch.bitmap, 0); } } @@ -1165,12 +1161,12 @@ public class GLUT { int[] skiprows, int[] skippixels, int[] alignment) { - gl.glGetIntegerv(GL.GL_UNPACK_SWAP_BYTES, swapbytes); - gl.glGetIntegerv(GL.GL_UNPACK_LSB_FIRST, lsbfirst); - gl.glGetIntegerv(GL.GL_UNPACK_ROW_LENGTH, rowlength); - gl.glGetIntegerv(GL.GL_UNPACK_SKIP_ROWS, skiprows); - gl.glGetIntegerv(GL.GL_UNPACK_SKIP_PIXELS, skippixels); - gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, alignment); + gl.glGetIntegerv(GL.GL_UNPACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL.GL_UNPACK_LSB_FIRST, lsbfirst, 0); + gl.glGetIntegerv(GL.GL_UNPACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL.GL_UNPACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL.GL_UNPACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, alignment, 0); /* Little endian machines (DEC Alpha for example) could benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE instead of GL_FALSE, but this would require changing the diff --git a/src/net/java/games/jogl/util/GLUTBitmap8x13.java b/src/classes/com/sun/opengl/utils/GLUTBitmap8x13.java index caa007726..a373aeb8d 100644 --- a/src/net/java/games/jogl/util/GLUTBitmap8x13.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmap8x13.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmap8x13 { diff --git a/src/net/java/games/jogl/util/GLUTBitmap9x15.java b/src/classes/com/sun/opengl/utils/GLUTBitmap9x15.java index 05aa2635b..c1668967d 100644 --- a/src/net/java/games/jogl/util/GLUTBitmap9x15.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmap9x15.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmap9x15 { diff --git a/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica10.java index d238d7d16..9a329f6a3 100644 --- a/src/net/java/games/jogl/util/GLUTBitmapHelvetica10.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmapHelvetica10 { diff --git a/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica12.java index fe29ab84f..e27431c4e 100644 --- a/src/net/java/games/jogl/util/GLUTBitmapHelvetica12.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica12.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmapHelvetica12 { diff --git a/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica18.java index 31fbda94c..baf95d818 100644 --- a/src/net/java/games/jogl/util/GLUTBitmapHelvetica18.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmapHelvetica18.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmapHelvetica18 { diff --git a/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java b/src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman10.java index 175b857e0..00cf2975c 100644 --- a/src/net/java/games/jogl/util/GLUTBitmapTimesRoman10.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman10.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmapTimesRoman10 { diff --git a/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java b/src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman24.java index 25684ceff..22d2a19a2 100644 --- a/src/net/java/games/jogl/util/GLUTBitmapTimesRoman24.java +++ b/src/classes/com/sun/opengl/utils/GLUTBitmapTimesRoman24.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTBitmapTimesRoman24 { diff --git a/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java b/src/classes/com/sun/opengl/utils/GLUTStrokeMonoRoman.java index f5d2ebcff..39aaf8a18 100644 --- a/src/net/java/games/jogl/util/GLUTStrokeMonoRoman.java +++ b/src/classes/com/sun/opengl/utils/GLUTStrokeMonoRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTStrokeMonoRoman { diff --git a/src/net/java/games/jogl/util/GLUTStrokeRoman.java b/src/classes/com/sun/opengl/utils/GLUTStrokeRoman.java index 2755b8dfc..de040508a 100644 --- a/src/net/java/games/jogl/util/GLUTStrokeRoman.java +++ b/src/classes/com/sun/opengl/utils/GLUTStrokeRoman.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; class GLUTStrokeRoman { diff --git a/src/net/java/games/jogl/util/StrokeCharRec.java b/src/classes/com/sun/opengl/utils/StrokeCharRec.java index 7c961fb4d..8601e4079 100644 --- a/src/net/java/games/jogl/util/StrokeCharRec.java +++ b/src/classes/com/sun/opengl/utils/StrokeCharRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/jogl/util/StrokeFontRec.java b/src/classes/com/sun/opengl/utils/StrokeFontRec.java index 133380a77..2ea2d21ac 100644 --- a/src/net/java/games/jogl/util/StrokeFontRec.java +++ b/src/classes/com/sun/opengl/utils/StrokeFontRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/jogl/util/StrokeRec.java b/src/classes/com/sun/opengl/utils/StrokeRec.java index cc4571465..bc875856e 100644 --- a/src/net/java/games/jogl/util/StrokeRec.java +++ b/src/classes/com/sun/opengl/utils/StrokeRec.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl.util; +package com.sun.opengl.utils; /* Copyright (c) Mark J. Kilgard, 1994, 1998. */ diff --git a/src/net/java/games/jogl/Version.java b/src/classes/com/sun/opengl/utils/Version.java index 7d28f7fc8..843dc9a03 100644 --- a/src/net/java/games/jogl/Version.java +++ b/src/classes/com/sun/opengl/utils/Version.java @@ -31,7 +31,7 @@ * design, construction, operation or maintenance of any nuclear facility. */ -package net.java.games.jogl; +package com.sun.opengl.utils; /** * The version and build number of this implementation. @@ -89,7 +89,7 @@ public final class Version { /** * Version string of this build. */ - private static final String version = "1.1.1"; + private static final String version = "jsr231-1.0-beta1-b01"; /** * Returns the version string and build number of diff --git a/src/net/java/games/jogl/ComponentEvents.java b/src/classes/javax/media/opengl/ComponentEvents.java index e21441aeb..bfbbb957b 100644 --- a/src/net/java/games/jogl/ComponentEvents.java +++ b/src/classes/javax/media/opengl/ComponentEvents.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; import java.awt.event.*; import java.beans.PropertyChangeListener; diff --git a/src/net/java/games/jogl/DefaultGLCapabilitiesChooser.java b/src/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java index 119007617..391787a01 100644 --- a/src/net/java/games/jogl/DefaultGLCapabilitiesChooser.java +++ b/src/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java @@ -37,9 +37,9 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; -import net.java.games.jogl.impl.Debug; +import com.sun.opengl.impl.Debug; /** <P> The default implementation of the {@link GLCapabilitiesChooser} interface, which provides consistent visual diff --git a/src/classes/javax/media/opengl/GLAutoDrawable.java b/src/classes/javax/media/opengl/GLAutoDrawable.java new file mode 100644 index 000000000..18adfde54 --- /dev/null +++ b/src/classes/javax/media/opengl/GLAutoDrawable.java @@ -0,0 +1,117 @@ +/* + * 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. + */ + +package javax.media.opengl; + +import javax.media.opengl.glu.*; + +/** A higher-level abstraction than {@link GLDrawable} which supplies + an event based mechanism ({@link GLEventListener}) for performing + OpenGL rendering. A GLAutoDrawable automatically creates a primary + rendering context which is associated with the GLAutoDrawable for + the lifetime of the object. This context has the {@link + GLContext#setSynchronized synchronized} property enabled so that + calls to {@link GLContext#makeCurrent makeCurrent} will block if + the context is current on another thread. This allows the internal + GLContext for the GLAutoDrawable to be used both by the event + based rendering mechanism as well by end users directly. */ + +public interface GLAutoDrawable extends GLDrawable, ComponentEvents { + /** + * Returns the context associated with this drawable. The returned + * context will be synchronized. + */ + public GLContext getContext(); + + /** Adds a {@link GLEventListener} to this drawable. If multiple + listeners are added to a given drawable, they are notified of + events in an arbitrary order. */ + public void addGLEventListener(GLEventListener listener); + + /** Removes a {@link GLEventListener} from this drawable. Note that + if this is done from within a particular drawable's {@link + GLEventListener} handler (reshape, display, etc.) that it is not + guaranteed that all other listeners will be evaluated properly + during this update cycle. */ + public void removeGLEventListener(GLEventListener listener); + + /** Causes OpenGL rendering to be performed for this GLAutoDrawable + by calling {@link GLEventListener#display display} for all + registered {@link GLEventListener}s. Called automatically by the + window system toolkit upon receiving a repaint() request. this + routine may be called manually for better control over the + rendering process. It is legal to call another GLAutoDrawable's + display method from within the {@link GLEventListener#display + display} callback. */ + public void display(); + + /** Schedules a repaint of the component at some point in the + future. */ + public void repaint(); + + /** Enables or disables automatic buffer swapping for this drawable. + By default this property is set to true; when true, after all + GLEventListeners have been called for a display() event, the + front and back buffers are swapped, displaying the results of + the render. When disabled, the user is responsible for calling + {@link #swapBuffers} manually. */ + public void setAutoSwapBufferMode(boolean onOrOff); + + /** Indicates whether automatic buffer swapping is enabled for this + drawable. See {@link #setAutoSwapBufferMode}. */ + public boolean getAutoSwapBufferMode(); + + /** Returns the {@link GL} pipeline object this GLAutoDrawable uses. + If this method is called outside of the {@link + GLEventListener}'s callback methods (init, display, etc.) it may + return null. Users should not rely on the identity of the + returned GL object; for example, users should not maintain a + hash table with the GL object as the key. Additionally, the GL + object should not be cached in client code, but should be + re-fetched from the GLAutoDrawable at the beginning of each call + to init, display, etc. */ + public GL getGL(); + + /** Sets the {@link GL} pipeline object this GLAutoDrawable uses. + This should only be called from within the GLEventListener's + callback methods, and usually only from within the init() + method, in order to install a composable pipeline. See the JOGL + demos for examples. */ + public void setGL(GL gl); +} diff --git a/src/net/java/games/jogl/GLCanvas.java b/src/classes/javax/media/opengl/GLCanvas.java index f73a006ae..f2ca1bf80 100644 --- a/src/net/java/games/jogl/GLCanvas.java +++ b/src/classes/javax/media/opengl/GLCanvas.java @@ -37,13 +37,14 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; import java.awt.Canvas; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.GraphicsConfiguration; -import net.java.games.jogl.impl.*; +import java.awt.GraphicsDevice; +import com.sun.opengl.impl.*; // FIXME: Subclasses need to call resetGLFunctionAvailability() on their // context whenever the displayChanged() function is called on our @@ -57,41 +58,70 @@ import net.java.games.jogl.impl.*; instantiated directly; use {@link GLDrawableFactory} to construct them. */ -public final class GLCanvas extends Canvas implements GLDrawable { +public class GLCanvas extends Canvas implements GLAutoDrawable { - protected static final boolean DEBUG = Debug.debug("GLCanvas"); + private static final boolean DEBUG = Debug.debug("GLCanvas"); private GLDrawableHelper drawableHelper = new GLDrawableHelper(); - private GLContext context; - - GLCanvas(GraphicsConfiguration config, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLDrawable shareWith) { - super(config); - context = GLContextFactory.getFactory().createGLContext(this, capabilities, chooser, - GLContextHelper.getContext(shareWith)); + private GLDrawable drawable; + private GLContextImpl context; + private boolean autoSwapBufferMode = true; + private boolean sendReshape = false; + + /** Creates a new GLCanvas component. The passed GLCapabilities must + be non-null and specifies the OpenGL capabilities for the + component. The GLCapabilitiesChooser must be non-null and + specifies the algorithm for selecting one of the available + GLCapabilities for the component; the GLDrawableFactory uses a + DefaultGLCapabilitesChooser if the user does not provide + one. The passed GLContext may be null and specifies an OpenGL + context with which to share textures, display lists and other + OpenGL state. The passed GraphicsDevice must be non-null and + indicates the screen on which to create the GLCanvas; the + GLDrawableFactory uses the default screen device of the local + GraphicsEnvironment if the user does not provide one. */ + protected GLCanvas(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GLContext shareWith, + GraphicsDevice device) { + // The platform-specific GLDrawableFactory will only provide a + // non-null GraphicsConfiguration on platforms where this is + // necessary (currently only X11, as Windows allows the pixel + // format of the window to be set later and Mac OS X seems to + // handle this very differently than all other platforms). On + // other platforms this method returns null; it is the case (at + // least in the Sun AWT implementation) that this will result in + // equivalent behavior to calling the no-arg super() constructor + // for Canvas. + super(GLDrawableFactory.getFactory().chooseGraphicsConfiguration(capabilities, chooser, device)); + drawable = GLDrawableFactory.getFactory().getGLDrawable(this, capabilities, chooser); + context = (GLContextImpl) drawable.createContext(shareWith); + context.setSynchronized(true); } + public GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + public void display() { maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction, - displayAction, - false); + displayAction); } /** Overridden from Canvas; calls {@link #display}. Should not be invoked by applications directly. */ public void paint(Graphics g) { - if (!context.getNoAutoRedrawMode()) { - display(); - } + display(); } /** Overridden from Canvas; used to indicate when it's safe to create an OpenGL context for the component. */ public void addNotify() { super.addNotify(); - context.setRealized(); + drawable.setRealized(true); if (DEBUG) { System.err.println("GLCanvas.addNotify()"); } @@ -101,6 +131,7 @@ public final class GLCanvas extends Canvas implements GLDrawable { safe to have an OpenGL context for the component. */ public void removeNotify() { context.destroy(); + drawable.setRealized(false); super.removeNotify(); if (DEBUG) { System.err.println("GLCanvas.removeNotify()"); @@ -113,24 +144,7 @@ public final class GLCanvas extends Canvas implements GLDrawable { directly. */ public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, height); - // Note: we ignore the given x and y within the parent component - // since we are drawing directly into this heavyweight component. - final int fx = 0; - final int fy = 0; - final int fwidth = width; - final int fheight = height; - final Runnable reshapeRunnable = new Runnable() { - public void run() { - getGL().glViewport(fx, fy, fwidth, fheight); - drawableHelper.reshape(GLCanvas.this, fx, fy, fwidth, fheight); - } - }; - final Runnable reshapeOnEDTRunnable = new Runnable() { - public void run() { - context.invokeGL(reshapeRunnable, true, initAction); - } - }; - maybeDoSingleThreadedWorkaround(reshapeOnEDTRunnable, reshapeRunnable, true); + sendReshape = true; } /** Overridden from Canvas to prevent Java2D's clearing of the @@ -147,66 +161,28 @@ public final class GLCanvas extends Canvas implements GLDrawable { drawableHelper.removeGLEventListener(listener); } - public GL getGL() { - return context.getGL(); - } - - public void setGL(GL gl) { - context.setGL(gl); - } - - public GLU getGLU() { - return context.getGLU(); - } - - public void setGLU(GLU glu) { - context.setGLU(glu); - } - - void willSetRenderingThread() { - context.willSetRenderingThread(); - } - - public void setRenderingThread(Thread currentThreadOrNull) throws GLException { - context.setRenderingThread(currentThreadOrNull, initAction); - } - - public Thread getRenderingThread() { - return context.getRenderingThread(); + public GLContext getContext() { + return context; } - public void setNoAutoRedrawMode(boolean noAutoRedraw) { - context.setNoAutoRedrawMode(noAutoRedraw); + public GL getGL() { + return getContext().getGL(); } - public boolean getNoAutoRedrawMode() { - return context.getNoAutoRedrawMode(); + public void setGL(GL gl) { + getContext().setGL(gl); } public void setAutoSwapBufferMode(boolean onOrOff) { - context.setAutoSwapBufferMode(onOrOff); + drawableHelper.setAutoSwapBufferMode(onOrOff); } public boolean getAutoSwapBufferMode() { - return context.getAutoSwapBufferMode(); + return drawableHelper.getAutoSwapBufferMode(); } public void swapBuffers() { - maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction, false); - } - - public boolean canCreateOffscreenDrawable() { - return context.canCreatePbufferContext(); - } - - public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - return new GLPbufferImpl(context.createPbufferContext(capabilities, initialWidth, initialHeight)); - } - - GLContext getContext() { - return context; + maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction); } //---------------------------------------------------------------------- @@ -214,26 +190,12 @@ public final class GLCanvas extends Canvas implements GLDrawable { // private void maybeDoSingleThreadedWorkaround(Runnable eventDispatchThreadAction, - Runnable invokeGLAction, - boolean isReshape) { - if (SingleThreadedWorkaround.doWorkaround() && !EventQueue.isDispatchThread()) { - try { - // Reshape events must not block on the event queue due to the - // possibility of deadlocks during initial component creation. - // This solution is not optimal, because it changes the - // semantics of reshape() to have some of the processing being - // done asynchronously, but at least it preserves the - // semantics of the single-threaded workaround. - if (!isReshape) { - EventQueue.invokeAndWait(eventDispatchThreadAction); - } else { - EventQueue.invokeLater(eventDispatchThreadAction); - } - } catch (Exception e) { - throw new GLException(e); - } + Runnable invokeGLAction) { + if (Threading.isSingleThreaded() && + !Threading.isOpenGLThread()) { + Threading.invokeOnOpenGLThread(eventDispatchThreadAction); } else { - context.invokeGL(invokeGLAction, isReshape, initAction); + drawableHelper.invokeGL(drawable, context, invokeGLAction, initAction); } } @@ -246,6 +208,16 @@ public final class GLCanvas extends Canvas implements GLDrawable { class DisplayAction implements Runnable { public void run() { + if (sendReshape) { + // Note: we ignore the given x and y within the parent component + // since we are drawing directly into this heavyweight component. + int width = getWidth(); + int height = getHeight(); + getGL().glViewport(0, 0, width, height); + drawableHelper.reshape(GLCanvas.this, 0, 0, width, height); + sendReshape = false; + } + drawableHelper.display(GLCanvas.this); } } @@ -253,7 +225,7 @@ public final class GLCanvas extends Canvas implements GLDrawable { class SwapBuffersAction implements Runnable { public void run() { - context.swapBuffers(); + drawable.swapBuffers(); } } private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); @@ -263,14 +235,14 @@ public final class GLCanvas extends Canvas implements GLDrawable { // being resized on the AWT event dispatch thread class DisplayOnEventDispatchThreadAction implements Runnable { public void run() { - context.invokeGL(displayAction, false, initAction); + drawableHelper.invokeGL(drawable, context, displayAction, initAction); } } private DisplayOnEventDispatchThreadAction displayOnEventDispatchThreadAction = new DisplayOnEventDispatchThreadAction(); class SwapBuffersOnEventDispatchThreadAction implements Runnable { public void run() { - context.invokeGL(swapBuffersAction, false, initAction); + drawableHelper.invokeGL(drawable, context, swapBuffersAction, initAction); } } private SwapBuffersOnEventDispatchThreadAction swapBuffersOnEventDispatchThreadAction = diff --git a/src/net/java/games/jogl/GLCapabilities.java b/src/classes/javax/media/opengl/GLCapabilities.java index d645a71a6..77ada1b1a 100644 --- a/src/net/java/games/jogl/GLCapabilities.java +++ b/src/classes/javax/media/opengl/GLCapabilities.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; /** Specifies a set of OpenGL capabilities that a rendering context must support, such as color depth and whether stereo is enabled. diff --git a/src/net/java/games/jogl/GLCapabilitiesChooser.java b/src/classes/javax/media/opengl/GLCapabilitiesChooser.java index 951dd52a1..9d970ff42 100644 --- a/src/net/java/games/jogl/GLCapabilitiesChooser.java +++ b/src/classes/javax/media/opengl/GLCapabilitiesChooser.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; /** Provides a mechanism by which applications can customize the window type selection for a given {@link GLCapabilities}. diff --git a/src/classes/javax/media/opengl/GLContext.java b/src/classes/javax/media/opengl/GLContext.java new file mode 100644 index 000000000..82997bc8f --- /dev/null +++ b/src/classes/javax/media/opengl/GLContext.java @@ -0,0 +1,159 @@ +/* + * 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. + */ + +package javax.media.opengl; + +/** Abstraction for an OpenGL rendering context. In order to perform + OpenGL rendering, a context must be "made current" on the current + thread. OpenGL rendering semantics specify that only one context + may be current on the current thread at any given time, and also + that a given context may be current on only one thread at any + given time. Because components can be added to and removed from + the component hierarchy at any time, it is possible that the + underlying OpenGL context may need to be destroyed and recreated + multiple times over the lifetime of a given component. This + process is handled by the implementation, and the GLContext + abstraction provides a stable object which clients can use to + refer to a given context. */ + +public abstract class GLContext { + /** Indicates that the context was not made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_NOT_CURRENT = 0; + /** Indicates that the context was made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_CURRENT = 1; + /** Indicates that a newly-created context was made current during the last call to {@link #makeCurrent makeCurrent}. */ + public static final int CONTEXT_CURRENT_NEW = 2; + + private static ThreadLocal currentContext = new ThreadLocal(); + + /** + * Returns the GLDrawable to which this context may be used to + * draw. + */ + public abstract GLDrawable getGLDrawable(); + + /** + * Makes this GLContext current on the calling thread. + * + * There are two return values that indicate success and one that + * indicates failure. A return value of CONTEXT_CURRENT_NEW + * indicates that that context has been made current, and that + * this is the first time this context has been made current, or + * that the state of the underlying context or drawable may have + * changed since the last time this context was made current. In + * this case, the application may wish to initialize the state. A + * return value of CONTEXT_CURRENT indicates that the context has + * been made currrent, with its previous state restored. + * + * If the context could not be made current (for example, because + * the underlying drawable has not ben realized on the display) , + * a value of CONTEXT_NOT_CURRENT is returned. + * + * If the context is in use by another thread at the time of the + * call, then if isSynchronized() is true the call will + * block. If isSynchronized() is false, an exception will be + * thrown and the context will remain current on the other thread. + * + * @return CONTEXT_CURRENT if the context was successfully made current + * @return CONTEXT_CURRENT_NEW if the context was successfully made + * current, but need to be initialized. + * + * @return CONTEXT_NOT_CURRENT if the context could not be made current. + * + * @throws GLException if synchronization is disabled and the + * context is current on another thread, or because the context + * could not be created or made current due to non-recoverable, + * window system-specific errors. + */ + public abstract int makeCurrent() throws GLException; + + /** + * Releases control of this GLContext from the current thread. + * + * @throws GLException if the context had not previously been made + * current on the current thread + */ + public abstract void release() throws GLException; + + /** + * Returns the context which is current on the current thread. If no + * context is current, returns null. + * + * @return the context current on this thread, or null if no context + * is current. + */ + public static GLContext getCurrent() { + return (GLContext) currentContext.get(); + } + + /** + * Sets the current context object on the current thread. This + * method is called by GLContext implementations during {@link + * #makeCurrent} and does not need to be called by end users. + * + */ + public static void setCurrent(GLContext cur) { + currentContext.set(cur); + } + + /** + * Destroys this OpenGL context and frees its associated resources. + */ + public abstract void destroy(); + + /** + * Returns true if 'makeCurrent' will exhibit synchronized behavior. + */ + public abstract boolean isSynchronized(); + + /** + * Determines whether 'makeCurrent' will exhibit synchronized behavior. + */ + public abstract void setSynchronized(boolean isSynchronized); + + /** + * Returns the GL pipeline object for this GLContext. + */ + public abstract GL getGL(); + + /** + * Sets the GL pipeline object for this GLContext. + */ + public abstract void setGL(GL gl); +} diff --git a/src/classes/javax/media/opengl/GLDrawable.java b/src/classes/javax/media/opengl/GLDrawable.java new file mode 100644 index 000000000..5b54bd369 --- /dev/null +++ b/src/classes/javax/media/opengl/GLDrawable.java @@ -0,0 +1,118 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package javax.media.opengl; + +// FIXME: We need some way to tell when the device upon which the canvas is +// being displayed has changed (e.g., the user drags the canvas's parent +// window from one screen on multi-screen environment to another, when the +// user changes the display bit depth or screen resolution, etc). When this +// occurs, we need the canvas to reset the gl function pointer tables for the +// canvas, because the new device may have different capabilities (e.g., +// doesn't support as many opengl extensions) from the original device. This +// hook would also be useful in other GLDrawables (for example, offscreen +// buffers such as pbuffers, whose contents may or may not be invalidated when +// the display mode changes, depending on the vendor's GL implementation). +// +// Right now I'm not sure how hook into when this change occurs. There isn't +// any AWT event corresponding to a device change (as far as I can +// tell). We could constantly check the GraphicsConfiguration of the canvas's top-level +// parent to see if it has changed, but this would be very slow (we'd have to +// do it every time the context is made current). There has got to be a better +// solution, but I'm not sure what it is. + +// FIXME: Subclasses need to call resetGLFunctionAvailability() on their +// context whenever the displayChanged() function is called on our +// GLEventListeners + +/** An abstraction for an OpenGL rendering target. A GLDrawable's + primary functionality is to create OpenGL contexts which can be + used to perform rendering. A GLDrawable does not automatically + create an OpenGL context, but all implementations of {@link + GLAutoDrawable} do so upon creation. */ + +public interface GLDrawable { + /** + * Creates a new context for drawing to this drawable that will + * share display lists with the given GLContext. + * + * The GLContext <code>share</code> need not be associated with this + * GLDrawable. + */ + public GLContext createContext(GLContext shareWith); + + /** + + * Indicates to on-screen GLDrawable implementations whether the + * underlying window has been created and can be drawn into. This + * method must be called from GLDrawables obtained from the + * GLDrawableFactory via the {@link GLDrawableFactory#getGLDrawable + * GLDrawableFactory.getGLDrawable()} method. It must typically be + * called with an argument of <code>true</code> in the + * <code>addNotify</code> method of components performing OpenGL + * rendering and with an argument of <code>false</code> in the + * <code>removeNotify</code> method. Calling this method has no + * other effects. For example, if <code>removeNotify</code> is + * called on a Canvas implementation for which a GLDrawable has been + * created, it is also necessary to destroy all OpenGL contexts + * associated with that GLDrawable. This is not done automatically + * by the implementation. It is not necessary to call + * <code>setRealized</code> on a GLCanvas, a GLJPanel, or a + * GLPbuffer, as these perform the appropriate calls on their + * underlying GLDrawables internally.. + */ + public void setRealized(boolean realized); + + /** Requests a new width and height for this GLDrawable. Not all + drawables are able to respond to this request and may silently + ignore it. */ + public void setSize(int width, int height); + + /** Returns the current width of this GLDrawable. */ + public int getWidth(); + + /** Returns the current height of this GLDrawable. */ + public int getHeight(); + + /** Swaps the front and back buffers of this drawable. For {@link + GLAutoDrawable} implementations, when automatic buffer swapping + is enabled (as is the default), it is not necessary to call this + method and doing so may have undefined results. */ + public void swapBuffers() throws GLException; +} diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java new file mode 100644 index 000000000..c45bb16e0 --- /dev/null +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -0,0 +1,282 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package javax.media.opengl; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import com.sun.opengl.impl.*; + +/** <P> Provides a virtual machine- and operating system-independent + mechanism for creating {@link GLDrawable}s. </P> + + <P> The {@link javax.media.opengl.GLCapabilities} objects passed in to the + various factory methods are used as a hint for the properties of + the returned drawable. The default capabilities selection + algorithm (equivalent to passing in a null {@link + GLCapabilitiesChooser}) is described in {@link + DefaultGLCapabilitiesChooser}. Sophisticated applications needing + to change the selection algorithm may pass in their own {@link + GLCapabilitiesChooser} which can select from the available pixel + formats. </P> + + <P> Because of the multithreaded nature of the Java platform's + window system toolkit, it is typically not possible to immediately + reject a given {@link GLCapabilities} as being unsupportable by + either returning <code>null</code> from the creation routines or + raising a {@link GLException}. The semantics of the rejection + process are (unfortunately) left unspecified for now. The current + implementation will cause a {@link GLException} to be raised + during the first repaint of the {@link GLCanvas} or {@link + GLJPanel} if the capabilities can not be met. Pbuffers are always + created immediately and their creation will fail with a {@link + GLException} if errors occur. </P> +*/ + +public abstract class GLDrawableFactory { + private static GLDrawableFactory factory; + + protected GLDrawableFactory() {} + + /** Returns the sole GLDrawableFactory instance. */ + public static GLDrawableFactory getFactory() { + if (factory == null) { + try { + String osName = System.getProperty("os.name"); + String osNameLowerCase = osName.toLowerCase(); + Class factoryClass = null; + + // Because there are some complications with generating all + // platforms' Java glue code on all platforms (among them that we + // would have to include jawt.h and jawt_md.h in the jogl + // sources, which we currently don't have to do) we break the only + // static dependencies with platform-specific code here using reflection. + + if (osNameLowerCase.startsWith("wind")) { + factoryClass = Class.forName("com.sun.opengl.impl.windows.WindowsGLDrawableFactory"); + } else if (osNameLowerCase.startsWith("mac os x")) { + factoryClass = Class.forName("com.sun.opengl.impl.macosx.MacOSXGLDrawableFactory"); + } else { + // Assume Linux, Solaris, etc. Should probably test for these explicitly. + factoryClass = Class.forName("com.sun.opengl.impl.x11.X11GLDrawableFactory"); + } + + if (factoryClass == null) { + throw new GLException("OS " + osName + " not yet supported"); + } + + factory = (GLDrawableFactory) factoryClass.newInstance(); + } catch (ClassNotFoundException e) { + throw new GLException(e); + } catch (InstantiationException e) { + throw new GLException(e); + } catch (IllegalAccessException e) { + throw new GLException(e); + } + } + + return factory; + } + + /** + * Selects an AWT GraphicsConfiguration on the specified + * GraphicsDevice compatible with the supplied GLCapabilities. This + * method is intended to be used by applications which do not use + * the supplied GLCanvas class but instead wrap their own Canvas + * with a GLDrawable. Some platforms (specifically X11) require the + * GraphicsConfiguration to be specified when the platform-specific + * window system object, such as a Canvas, is created. This method + * returns null on platforms on which the OpenGL pixel format + * selection process is performed later. + * + * @see java.awt.Canvas#Canvas(java.awt.GraphicsConfiguration) + */ + public abstract GraphicsConfiguration + chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GraphicsDevice device); + + /** + * Returns a GLDrawable that wraps a platform-specific window system + * object, such as an AWT or LCDUI Canvas. On platforms which + * support it, selects a pixel format compatible with the supplied + * GLCapabilities, or if the passed GLCapabilities object is null, + * uses a default set of capabilities. On these platforms, uses + * either the supplied GLCapabilitiesChooser object, or if the + * passed GLCapabilitiesChooser object is null, uses a + * DefaultGLCapabilitiesChooser instance. + * + * @throws IllegalArgumentException if the passed target is either + * null or its data type is not supported by this GLDrawableFactory. + * @throws GLException if any window system-specific errors caused + * the creation of the GLDrawable to fail. + */ + public abstract GLDrawable getGLDrawable(Object target, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) + throws IllegalArgumentException, GLException; + + //---------------------------------------------------------------------- + // Methods to create high-level objects + + /** Creates a {@link GLCanvas} on the default graphics device with + the specified capabilities using the default capabilities + selection algorithm. */ + public GLCanvas createGLCanvas(GLCapabilities capabilities) { + return createGLCanvas(capabilities, null, null, null); + } + + /** Creates a {@link GLCanvas} on the specified graphics device with + the specified capabilities using the supplied capabilities + selection algorithm. A null chooser is equivalent to using the + {@link DefaultGLCapabilitiesChooser}. The canvas will share + textures and display lists with the specified {@link GLContext}; + the context must either be null or have been fabricated by + classes in this package. A null context indicates no sharing. A + null GraphicsDevice is equivalent to using that returned from + <code>GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()</code>. */ + public GLCanvas createGLCanvas(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GLContext shareWith, + GraphicsDevice device) { + return new GLCanvas(capabilities, + chooser, + shareWith, + device); + } + + /** Creates a {@link GLJPanel} with the specified capabilities using + the default capabilities selection algorithm. */ + public GLJPanel createGLJPanel(GLCapabilities capabilities) { + return createGLJPanel(capabilities, null, null); + } + + /** Creates a {@link GLJPanel} with the specified capabilities using + the supplied capabilities selection algorithm. A null chooser is + equivalent to using the {@link DefaultGLCapabilitiesChooser}. + The panel will share textures and display lists with the + specified {@link GLContext}; the context must either be null or + have been fabricated by classes in this package. A null context + indicates no sharing. */ + public GLJPanel createGLJPanel(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + GLContext shareWith) { + return new GLJPanel(capabilities, chooser, shareWith); + } + + /** + * Returns true if it is possible to create a GLPbuffer. Some older + * graphics cards do not have this capability. + */ + public abstract boolean canCreateGLPbuffer(); + + /** + * Creates a GLPbuffer with the given capabilites and dimensions. + */ + public abstract GLPbuffer createGLPbuffer(GLCapabilities capabilities, + int initialWidth, + int initialHeight, + GLContext shareWith); + + //---------------------------------------------------------------------- + // Methods for interacting with third-party OpenGL libraries + + /** + * <P> Creates a GLContext object representing an existing OpenGL + * context in an external (third-party) OpenGL-based library. This + * GLContext object may be used to draw into this preexisting + * context using its {@link GL} and {@link + * javax.media.opengl.glu.GLU} objects. New contexts created through + * {@link GLDrawable}s may share textures and display lists with + * this external context. </P> + * + * <P> The underlying OpenGL context must be current on the current + * thread at the time this method is called. The user is responsible + * for the maintenance of the underlying OpenGL context; calls to + * <code>makeCurrent</code> and <code>release</code> on the returned + * GLContext object have no effect. If the underlying OpenGL context + * is destroyed, the <code>destroy</code> method should be called on + * the <code>GLContext</code>. A new <code>GLContext</code> object + * should be created for each newly-created underlying OpenGL + * context. + */ + public abstract GLContext createExternalGLContext(); + + /** + * Returns true if it is possible to create an external GLDrawable + * object via {@link #createExternalGLDrawable}. + */ + public abstract boolean canCreateExternalGLDrawable(); + + /** + * <P> Creates a {@link GLDrawable} object representing an existing + * OpenGL drawable in an external (third-party) OpenGL-based + * library. This GLDrawable object may be used to create new, + * fully-functional {@link GLContext}s on the OpenGL drawable. This + * is useful when interoperating with a third-party OpenGL-based + * library and it is essential to not perturb the state of the + * library's existing context, even to the point of not sharing + * textures or display lists with that context. </P> + * + * <P> An underlying OpenGL context must be current on the desired + * drawable and the current thread at the time this method is + * called. The user is responsible for the maintenance of the + * underlying drawable. If one or more contexts are created on the + * drawable using {@link GLDrawable#createContext}, and the drawable + * is deleted by the third-party library, the user is responsible + * for calling {@link GLContext#destroy} on these contexts. </P> + * + * <P> Calls to <code>setSize</code>, <code>getWidth</code> and + * <code>getHeight</code> are illegal on the returned GLDrawable. If + * these operations are required by the user, they must be performed + * by the third-party library. </P> + * + * <P> It is legal to create both an external GLContext and + * GLDrawable representing the same third-party OpenGL entities. + * This can be used, for example, to query current state information + * using the external GLContext and then create and set up new + * GLContexts using the external GLDrawable. </P> + * + * <P> This functionality may not be available on all platforms and + * {@link #canCreateExternalGLDrawable} should be called first to + * see if it is present. For example, on X11 platforms, this API + * requires the presence of GLX 1.3 or later. + */ + public abstract GLDrawable createExternalGLDrawable(); +} diff --git a/src/net/java/games/jogl/GLEventListener.java b/src/classes/javax/media/opengl/GLEventListener.java index 0f345e6c7..3aadbf833 100644 --- a/src/net/java/games/jogl/GLEventListener.java +++ b/src/classes/javax/media/opengl/GLEventListener.java @@ -37,54 +37,55 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; import java.util.EventListener; /** Declares events which client code can use to manage OpenGL - rendering into a {@link GLDrawable}. At the time any of these + rendering into a {@link GLAutoDrawable}. At the time any of these methods is called, the drawable has made its associated OpenGL context current, so it is valid to make OpenGL calls. */ public interface GLEventListener extends EventListener { /** Called by the drawable immediately after the OpenGL context is initialized. Can be used to perform one-time OpenGL - initialization such as setup of lights and display lists. Note + initialization such as setup of lights and display lists. Note that this method may be called more than once if the underlying - OpenGL context for the GLDrawable is destroyed and recreated, - for example if a GLCanvas is removed from the widget hierarchy - and later added again. + OpenGL context for the GLAutoDrawable is destroyed and + recreated, for example if a GLCanvas is removed from the widget + hierarchy and later added again. */ - public void init(GLDrawable drawable); + public void init(GLAutoDrawable drawable); /** Called by the drawable to initiate OpenGL rendering by the client. After all GLEventListeners have been notified of a - display event, the drawable will swap its buffers if necessary. - */ - public void display(GLDrawable drawable); + display event, the drawable will swap its buffers if {@link + GLAutoDrawable#setAutoSwapBufferMode setAutoSwapBufferMode} is + enabled. */ + public void display(GLAutoDrawable drawable); /** Called by the drawable during the first repaint after the component has been resized. The client can update the viewport and view volume of the window appropriately, for example by a - call to {@link net.java.games.jogl.GL#glViewport}; note that for + call to {@link javax.media.opengl.GL#glViewport}; note that for convenience the component has already called <code>glViewport(x, y, width, height)</code> when this method is called, so the client may not have to do anything in this method. */ - public void reshape(GLDrawable drawable, int x, int y, int width, int height); + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height); /** Called by the drawable when the display mode or the display device - associated with the GLDrawable has changed. The two boolean parameters + associated with the GLAutoDrawable has changed. The two boolean parameters indicate the types of change(s) that have occurred. (<b> !!! CURRENTLY UNIMPLEMENTED !!! </b>) <P> An example of a display <i>mode</i> change is when the bit depth changes (e.g., - from 32-bit to 16-bit color) on monitor upon which the GLDrawable is + from 32-bit to 16-bit color) on monitor upon which the GLAutoDrawable is currently being displayed. <p> An example of a display <i>device</i> change is when the user drags the - window containing the GLDrawable from one monitor to another in a + window containing the GLAutoDrawable from one monitor to another in a multiple-monitor setup. <p> The reason that this function handles both types of changes (instead of @@ -94,5 +95,5 @@ public interface GLEventListener extends EventListener { adjustments to compensate for a device change if it knows that the mode on the new device is identical the previous mode. */ - public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged); + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged); } diff --git a/src/net/java/games/jogl/GLException.java b/src/classes/javax/media/opengl/GLException.java index e814ecbc8..644042e15 100644 --- a/src/net/java/games/jogl/GLException.java +++ b/src/classes/javax/media/opengl/GLException.java @@ -37,7 +37,7 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; /** A generic exception for OpenGL errors used throughout the binding as a substitute for {@link RuntimeException}. */ diff --git a/src/classes/javax/media/opengl/GLJPanel.java b/src/classes/javax/media/opengl/GLJPanel.java new file mode 100644 index 000000000..3d6f4e831 --- /dev/null +++ b/src/classes/javax/media/opengl/GLJPanel.java @@ -0,0 +1,877 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package javax.media.opengl; + +import java.awt.*; +import java.awt.geom.*; +import java.awt.image.*; +import javax.swing.*; +import java.nio.*; +import java.security.*; +import javax.swing.JComponent; +import javax.swing.JPanel; +import com.sun.opengl.impl.*; + +// FIXME: Subclasses need to call resetGLFunctionAvailability() on their +// context whenever the displayChanged() function is called on their +// GLEventListeners + +/** A lightweight Swing component which provides OpenGL rendering + support. Provided for compatibility with Swing user interfaces + when adding a heavyweight doesn't work either because of + Z-ordering or LayoutManager problems. This component attempts to + use hardware-accelerated rendering via pbuffers and falls back on + to software rendering if problems occur. This class can not be + instantiated directly; use {@link GLDrawableFactory} to construct + them. <P> + + Note that because this component attempts to use pbuffers for + rendering, and because pbuffers can not be resized, somewhat + surprising behavior may occur during resize operations; the {@link + GLEventListener#init} method may be called multiple times as the + pbuffer is resized to be able to cover the size of the GLJPanel. + This behavior is correct, as the textures and display lists for + the GLJPanel will have been lost during the resize operation. The + application should attempt to make its GLEventListener.init() + methods as side-effect-free as possible. <P> + + The GLJPanel can be made transparent by creating it with a + GLCapabilities object with alpha bits specified and calling {@link + #setOpaque}(false). Pixels with resulting OpenGL alpha values less + than 1.0 will be overlaid on any underlying Java2D rendering. +*/ + +public class GLJPanel extends JPanel implements GLAutoDrawable { + private static final boolean DEBUG = Debug.debug("GLJPanel"); + private static final boolean VERBOSE = Debug.verbose(); + + private GLDrawableHelper drawableHelper = new GLDrawableHelper(); + private volatile boolean isInitialized; + private volatile boolean shouldInitialize = false; + + // Data used for either pbuffers or pixmap-based offscreen surfaces + private GLCapabilities offscreenCaps; + private GLCapabilitiesChooser chooser; + private GLContext shareWith; + // This image is exactly the correct size to render into the panel + private BufferedImage offscreenImage; + // One of these is used to store the read back pixels before storing + // in the BufferedImage + private ByteBuffer readBackBytes; + private IntBuffer readBackInts; + private int readBackWidthInPixels; + private int readBackHeightInPixels; + // Width of the actual GLJPanel + private int panelWidth = 0; + private int panelHeight = 0; + private Updater updater; + private int awtFormat; + private int glFormat; + private int glType; + // Lazy reshape notification + private boolean handleReshape = false; + private boolean sendReshape = true; + + // Implementation using pbuffers + private static boolean hardwareAccelerationDisabled = + Debug.isPropertyDefined("jogl.gljpanel.nohw"); + private static boolean softwareRenderingDisabled = + Debug.isPropertyDefined("jogl.gljpanel.nosw"); + private GLPbuffer pbuffer; + private int pbufferWidth = 256; + private int pbufferHeight = 256; + + // Implementation using software rendering + private GLDrawableImpl offscreenDrawable; + private GLContextImpl offscreenContext; + + // For handling reshape events lazily + private int reshapeX; + private int reshapeY; + private int reshapeWidth; + private int reshapeHeight; + + // For saving/restoring of OpenGL state during ReadPixels + private int[] swapbytes = new int[1]; + private int[] rowlength = new int[1]; + private int[] skiprows = new int[1]; + private int[] skippixels = new int[1]; + private int[] alignment = new int[1]; + + // Implementation using Java2D OpenGL pipeline's back buffer + private static boolean swingBufferPerWindow = + Debug.isPropertyDefined("swing.bufferPerWindow") ? + Debug.getBooleanProperty("swing.bufferPerWindow") : + true; + private boolean oglPipelineEnabled = + Java2D.isOGLPipelineActive() && + !Debug.isPropertyDefined("jogl.gljpanel.noogl"); + // Opaque Object identifier representing the Java2D surface we are + // drawing to; used to determine when to destroy and recreate JOGL + // context + private Object j2dSurface; + // Graphics object being used during Java2D update action + // (absolutely essential to cache this) + private Graphics cached2DGraphics; + // No-op context representing the Java2D OpenGL context + private GLContext j2dContext; + // Context associated with no-op drawable representing the JOGL + // OpenGL context + private GLDrawable joglDrawable; + // The real OpenGL context JOGL uses to render + private GLContext joglContext; + // State captured from Java2D OpenGL context necessary in order to + // properly render into Java2D back buffer + private int[] drawBuffer = new int[1]; + private int[] readBuffer = new int[1]; + // These are always set to (0, 0) except when the Java2D / OpenGL + // pipeline is active + private int viewportX; + private int viewportY; + + /** Creates a new GLJPanel component. The passed GLCapabilities must + be non-null and specifies the OpenGL capabilities for the + component. The GLCapabilitiesChooser must be non-null and + specifies the algorithm for selecting one of the available + GLCapabilities for the component; the GLDrawableFactory uses a + DefaultGLCapabilitiesChooser if the user does not provide + one. The passed GLContext may be null and specifies an OpenGL + context with which to share textures, display lists and other + OpenGL state. */ + protected GLJPanel(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith) { + super(); + + // Works around problems on many vendors' cards; we don't need a + // back buffer for the offscreen surface anyway + if (capabilities != null) { + offscreenCaps = (GLCapabilities) capabilities.clone(); + } else { + offscreenCaps = new GLCapabilities(); + } + offscreenCaps.setDoubleBuffered(false); + this.chooser = ((chooser != null) ? chooser : new DefaultGLCapabilitiesChooser()); + this.shareWith = shareWith; + } + + public void display() { + if (EventQueue.isDispatchThread()) { + // Want display() to be synchronous, so call paintImmediately() + paintImmediately(0, 0, getWidth(), getHeight()); + } else { + // Multithreaded redrawing of Swing components is not allowed, + // so do everything on the event dispatch thread + try { + EventQueue.invokeAndWait(paintImmediatelyAction); + } catch (Exception e) { + throw new GLException(e); + } + } + } + + private void captureJ2DState(GL gl) { + gl.glGetIntegerv(GL.GL_DRAW_BUFFER, drawBuffer, 0); + gl.glGetIntegerv(GL.GL_READ_BUFFER, readBuffer, 0); + } + + private boolean preGL(Graphics g) { + GL gl = joglContext.getGL(); + // Set up needed state in JOGL context from Java2D context + gl.glEnable(GL.GL_SCISSOR_TEST); + Rectangle r = Java2D.getOGLScissorBox(g); + if (r == null) { + return false; + } + gl.glScissor(r.x, r.y, r.width, r.height); + Rectangle oglViewport = Java2D.getOGLViewport(g, panelWidth, panelHeight); + // If the viewport X or Y changes, in addition to the panel's + // width or height, we need to send a reshape operation to the + // client + if ((viewportX != oglViewport.x) || + (viewportY != oglViewport.y)) { + sendReshape = true; + if (DEBUG) { + System.err.println("Sending reshape because viewport changed"); + System.err.println(" viewportX (" + viewportX + ") ?= oglViewport.x (" + oglViewport.x + ")"); + System.err.println(" viewportY (" + viewportY + ") ?= oglViewport.y (" + oglViewport.y + ")"); + } + } + viewportX = oglViewport.x; + viewportY = oglViewport.y; + + gl.glDrawBuffer(drawBuffer[0]); + gl.glReadBuffer(readBuffer[0]); + return true; + } + + /** Overridden from JComponent; calls event listeners' {@link + GLEventListener#display display} methods. Should not be invoked + by applications directly. */ + public void paintComponent(final Graphics g) { + if (shouldInitialize) { + initialize(); + } + + if (!isInitialized) { + return; + } + + // NOTE: must do this when the context is not current as it may + // involve destroying the pbuffer (current context) and + // re-creating it -- tricky to do properly while the context is + // current + if (handleReshape) { + handleReshape(); + } + + updater.setGraphics(g); + + if (oglPipelineEnabled) { + Java2D.invokeWithOGLContextCurrent(g, new Runnable() { + public void run() { + // Create no-op context representing Java2D context + if (j2dContext == null) { + j2dContext = GLDrawableFactory.getFactory().createExternalGLContext(); + + // Check to see whether we can support the requested + // capabilities or need to fall back to a pbuffer + // FIXME: add more checks? + + GL gl = j2dContext.getGL(); + if ((getGLInteger(gl, GL.GL_RED_BITS) < offscreenCaps.getRedBits()) || + (getGLInteger(gl, GL.GL_GREEN_BITS) < offscreenCaps.getGreenBits()) || + (getGLInteger(gl, GL.GL_BLUE_BITS) < offscreenCaps.getBlueBits()) || + // (getGLInteger(gl, GL.GL_ALPHA_BITS) < offscreenCaps.getAlphaBits()) || + (getGLInteger(gl, GL.GL_ACCUM_RED_BITS) < offscreenCaps.getAccumRedBits()) || + (getGLInteger(gl, GL.GL_ACCUM_GREEN_BITS) < offscreenCaps.getAccumGreenBits()) || + (getGLInteger(gl, GL.GL_ACCUM_BLUE_BITS) < offscreenCaps.getAccumBlueBits()) || + (getGLInteger(gl, GL.GL_ACCUM_ALPHA_BITS) < offscreenCaps.getAccumAlphaBits()) || + // (getGLInteger(gl, GL.GL_DEPTH_BITS) < offscreenCaps.getDepthBits()) || + (getGLInteger(gl, GL.GL_STENCIL_BITS) < offscreenCaps.getStencilBits())) { + if (DEBUG) { + System.err.println("GLJPanel: Falling back to pbuffer-based support because Java2D context insufficient"); + System.err.println(" Available Required"); + System.err.println("GL_RED_BITS " + getGLInteger(gl, GL.GL_RED_BITS) + " " + offscreenCaps.getRedBits()); + System.err.println("GL_GREEN_BITS " + getGLInteger(gl, GL.GL_GREEN_BITS) + " " + offscreenCaps.getGreenBits()); + System.err.println("GL_BLUE_BITS " + getGLInteger(gl, GL.GL_BLUE_BITS) + " " + offscreenCaps.getBlueBits()); + System.err.println("GL_ALPHA_BITS " + getGLInteger(gl, GL.GL_ALPHA_BITS) + " " + offscreenCaps.getAlphaBits()); + System.err.println("GL_ACCUM_RED_BITS " + getGLInteger(gl, GL.GL_ACCUM_RED_BITS) + " " + offscreenCaps.getAccumRedBits()); + System.err.println("GL_ACCUM_GREEN_BITS " + getGLInteger(gl, GL.GL_ACCUM_GREEN_BITS) + " " + offscreenCaps.getAccumGreenBits()); + System.err.println("GL_ACCUM_BLUE_BITS " + getGLInteger(gl, GL.GL_ACCUM_BLUE_BITS) + " " + offscreenCaps.getAccumBlueBits()); + System.err.println("GL_ACCUM_ALPHA_BITS " + getGLInteger(gl, GL.GL_ACCUM_ALPHA_BITS) + " " + offscreenCaps.getAccumAlphaBits()); + System.err.println("GL_DEPTH_BITS " + getGLInteger(gl, GL.GL_DEPTH_BITS) + " " + offscreenCaps.getDepthBits()); + System.err.println("GL_STENCIL_BITS " + getGLInteger(gl, GL.GL_STENCIL_BITS) + " " + offscreenCaps.getStencilBits()); + } + isInitialized = false; + shouldInitialize = true; + oglPipelineEnabled = false; + handleReshape = true; + j2dContext.destroy(); + j2dContext = null; + return; + } + } + + j2dContext.makeCurrent(); + try { + captureJ2DState(j2dContext.getGL()); + Object curSurface = Java2D.getOGLSurfaceIdentifier(g); + if (curSurface != null) { + if (j2dSurface != curSurface) { + if (joglContext != null) { + joglContext.destroy(); + joglContext = null; + joglDrawable = null; + sendReshape = true; + if (DEBUG) { + System.err.println("Sending reshape because surface changed"); + System.err.println("New surface = " + curSurface); + } + } + j2dSurface = curSurface; + } + if (joglContext == null) { + joglDrawable = GLDrawableFactory.getFactory().createExternalGLDrawable(); + joglContext = joglDrawable.createContext(shareWith); + } + drawableHelper.invokeGL(joglDrawable, joglContext, displayAction, initAction); + } + } finally { + j2dContext.release(); + } + } + }); + } else { + if (!hardwareAccelerationDisabled) { + pbuffer.display(); + } else { + drawableHelper.invokeGL(offscreenDrawable, offscreenContext, displayAction, initAction); + } + } + } + + /** Overridden from JPanel; used to indicate that an OpenGL context + may be created for the component. */ + public void addNotify() { + super.addNotify(); + shouldInitialize = true; + if (DEBUG) { + System.err.println("GLJPanel.addNotify()"); + } + } + + /** Overridden from JPanel; used to indicate that it's no longer + safe to have an OpenGL context for the component. */ + public void removeNotify() { + if (DEBUG) { + System.err.println("GLJPanel.removeNotify()"); + } + if (oglPipelineEnabled) { + Java2D.invokeWithOGLContextCurrent(null, new Runnable() { + public void run() { + if (joglContext != null) { + joglContext.destroy(); + joglContext = null; + } + joglDrawable = null; + if (j2dContext != null) { + j2dContext.destroy(); + j2dContext = null; + } + } + }); + } else { + if (!hardwareAccelerationDisabled) { + if (pbuffer != null) { + pbuffer.destroy(); + pbuffer = null; + } + } else { + if (offscreenContext != null) { + offscreenContext.destroy(); + offscreenContext = null; + } + if (offscreenDrawable != null) { + offscreenDrawable.destroy(); + offscreenDrawable = null; + } + } + } + isInitialized = false; + super.removeNotify(); + } + + /** Overridden from Canvas; causes {@link GLEventListener#reshape + reshape} to be called on all registered {@link + GLEventListener}s. Called automatically by the AWT; should not + be invoked by applications directly. */ + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + + reshapeX = x; + reshapeY = y; + reshapeWidth = width; + reshapeHeight = height; + handleReshape = true; + } + + public void setOpaque(boolean opaque) { + if (opaque != isOpaque()) { + if (offscreenImage != null) { + offscreenImage.flush(); + offscreenImage = null; + } + } + super.setOpaque(opaque); + } + + public void addGLEventListener(GLEventListener listener) { + drawableHelper.addGLEventListener(listener); + } + + public void removeGLEventListener(GLEventListener listener) { + drawableHelper.removeGLEventListener(listener); + } + + public GLContext createContext(GLContext shareWith) { + if (!hardwareAccelerationDisabled) { + return pbuffer.createContext(shareWith); + } else { + return offscreenDrawable.createContext(shareWith); + } + } + + public void setRealized(boolean realized) { + } + + public GLContext getContext() { + if (oglPipelineEnabled) { + return joglContext; + } else { + if (!hardwareAccelerationDisabled) { + return pbuffer.getContext(); + } else { + return offscreenContext; + } + } + } + + public GL getGL() { + GLContext context = getContext(); + return (context == null) ? null : context.getGL(); + } + + public void setGL(GL gl) { + GLContext context = getContext(); + if (context != null) { + context.setGL(gl); + } + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + if (!hardwareAccelerationDisabled) { + pbuffer.setAutoSwapBufferMode(onOrOff); + } else { + drawableHelper.setAutoSwapBufferMode(onOrOff); + } + } + + public boolean getAutoSwapBufferMode() { + if (!hardwareAccelerationDisabled) { + return pbuffer.getAutoSwapBufferMode(); + } else { + return drawableHelper.getAutoSwapBufferMode(); + } + } + + public void swapBuffers() { + if (!hardwareAccelerationDisabled) { + pbuffer.swapBuffers(); + } else { + drawableHelper.invokeGL(offscreenDrawable, offscreenContext, swapBuffersAction, initAction); + } + } + + /** For a translucent GLJPanel (one for which {@link #setOpaque + setOpaque}(false) has been called), indicates whether the + application should preserve the OpenGL color buffer + (GL_COLOR_BUFFER_BIT) for correct rendering of the GLJPanel and + underlying widgets which may show through portions of the + GLJPanel with alpha values less than 1. Most Swing + implementations currently expect the GLJPanel to be completely + cleared (e.g., by <code>glClear(GL_COLOR_BUFFER_BIT | + GL_DEPTH_BUFFER_BIT)</code>), but for certain optimized Java2D + and Swing implementations which use OpenGL internally, it may be + possible to perform OpenGL rendering using the GLJPanel into the + same OpenGL drawable as the Java2D implementation. */ + public boolean shouldPreserveColorBufferIfTranslucent() { + return oglPipelineEnabled; + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void initialize() { + if (panelWidth == 0 || + panelHeight == 0) { + // See whether we have a non-zero size yet and can go ahead with + // initialization + if (reshapeWidth == 0 || + reshapeHeight == 0) { + return; + } + + // Pull down reshapeWidth and reshapeHeight into panelWidth and + // panelHeight eagerly in order to complete initialization, and + // force a reshape later + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + } + + if (!oglPipelineEnabled) { + // Initialize either the hardware-accelerated rendering path or + // the lightweight rendering path + if (!hardwareAccelerationDisabled) { + if (GLDrawableFactory.getFactory().canCreateGLPbuffer()) { + if (pbuffer != null) { + throw new InternalError("Creating pbuffer twice without destroying it (memory leak / correctness bug)"); + } + try { + pbuffer = GLDrawableFactory.getFactory().createGLPbuffer(offscreenCaps, + pbufferWidth, + pbufferHeight, + shareWith); + updater = new Updater(); + pbuffer.addGLEventListener(updater); + shouldInitialize = false; + isInitialized = true; + return; + } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + System.err.println("GLJPanel: Falling back on software rendering because of problems creating pbuffer"); + } + hardwareAccelerationDisabled = true; + } + } else { + if (DEBUG) { + System.err.println("GLJPanel: Falling back on software rendering because no pbuffer support"); + } + + // If the factory reports that it can't create a pbuffer, + // don't try again the next time, and fall through to the + // software rendering path + hardwareAccelerationDisabled = true; + } + } + + if (softwareRenderingDisabled) { + throw new GLException("Fallback to software rendering disabled by user"); + } + + // Fall-through path: create an offscreen context instead + offscreenDrawable = GLDrawableFactoryImpl.getFactoryImpl().createOffscreenDrawable(offscreenCaps, chooser); + offscreenDrawable.setSize(Math.max(1, panelWidth), Math.max(1, panelHeight)); + offscreenContext = (GLContextImpl) offscreenDrawable.createContext(shareWith); + offscreenContext.setSynchronized(true); + } + updater = new Updater(); + shouldInitialize = false; + isInitialized = true; + } + + private void handleReshape() { + readBackWidthInPixels = 0; + readBackHeightInPixels = 0; + + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + + if (DEBUG) { + System.err.println("GLJPanel.handleReshape: (w,h) = (" + + panelWidth + "," + panelHeight + ")"); + } + + sendReshape = true; + + if (!oglPipelineEnabled) { + if (!hardwareAccelerationDisabled) { + // Use factor larger than 2 during shrinks for some hysteresis + float shrinkFactor = 2.5f; + if ((panelWidth > pbufferWidth ) || (panelHeight > pbufferHeight) || + (panelWidth < (pbufferWidth / shrinkFactor)) || (panelHeight < (pbufferWidth / shrinkFactor))) { + if (DEBUG) { + System.err.println("Resizing pbuffer from (" + pbufferWidth + ", " + pbufferHeight + ") " + + " to fit (" + panelWidth + ", " + panelHeight + ")"); + } + // Must destroy and recreate pbuffer to fit + if (pbuffer != null) { + pbuffer.destroy(); + } + pbuffer = null; + isInitialized = false; + pbufferWidth = getNextPowerOf2(panelWidth); + pbufferHeight = getNextPowerOf2(panelHeight); + if (DEBUG) { + System.err.println("New pbuffer size is (" + pbufferWidth + ", " + pbufferHeight + ")"); + } + initialize(); + } + + // It looks like NVidia's drivers (at least the ones on my + // notebook) are buggy and don't allow a rectangle of less than + // the pbuffer's width to be read...this doesn't really matter + // because it's the Graphics.drawImage() calls that are the + // bottleneck. Should probably make the size of the offscreen + // image be the exact size of the pbuffer to save some work on + // resize operations... + readBackWidthInPixels = pbufferWidth; + readBackHeightInPixels = panelHeight; + } else { + offscreenContext.destroy(); + offscreenDrawable.setSize(Math.max(1, panelWidth), Math.max(1, panelHeight)); + readBackWidthInPixels = Math.max(1, panelWidth); + readBackHeightInPixels = Math.max(1, panelHeight); + } + + if (offscreenImage != null) { + offscreenImage.flush(); + offscreenImage = null; + } + } + + handleReshape = false; + } + + // FIXME: it isn't clear whether this works any more given that + // we're accessing the GLDrawable inside of the GLPbuffer directly + // up in reshape() -- need to rethink and clean this up + class Updater implements GLEventListener { + private Graphics g; + + public void setGraphics(Graphics g) { + this.g = g; + } + + public void init(GLAutoDrawable drawable) { + if (oglPipelineEnabled) { + if (!preGL(g)) { + return; + } + } + drawableHelper.init(GLJPanel.this); + } + + public void display(GLAutoDrawable drawable) { + if (oglPipelineEnabled) { + if (!preGL(g)) { + return; + } + } + + if (sendReshape) { + if (DEBUG) { + System.err.println("glViewport(" + viewportX + ", " + viewportY + ", " + panelWidth + ", " + panelHeight + ")"); + } + getGL().glViewport(viewportX, viewportY, panelWidth, panelHeight); + drawableHelper.reshape(GLJPanel.this, viewportX, viewportY, panelWidth, panelHeight); + sendReshape = false; + } + + drawableHelper.display(GLJPanel.this); + + if (!oglPipelineEnabled) { + // Must now copy pixels from offscreen context into surface + if (offscreenImage == null) { + if (panelWidth > 0 && panelHeight > 0) { + // It looks like NVidia's drivers (at least the ones on my + // notebook) are buggy and don't allow a sub-rectangle to be + // read from a pbuffer...this doesn't really matter because + // it's the Graphics.drawImage() calls that are the + // bottleneck + + int awtFormat = 0; + int hwGLFormat = 0; + if (!hardwareAccelerationDisabled) { + // This seems to be a good choice on all platforms + hwGLFormat = GL.GL_UNSIGNED_INT_8_8_8_8_REV; + } + + // Should be more flexible in these BufferedImage formats; + // perhaps see what the preferred image types are on the + // given platform + if (isOpaque()) { + awtFormat = BufferedImage.TYPE_INT_RGB; + } else { + awtFormat = BufferedImage.TYPE_INT_ARGB; + } + + offscreenImage = new BufferedImage(panelWidth, + panelHeight, + awtFormat); + switch (awtFormat) { + case BufferedImage.TYPE_3BYTE_BGR: + glFormat = GL.GL_BGR; + glType = GL.GL_UNSIGNED_BYTE; + readBackBytes = ByteBuffer.allocate(readBackWidthInPixels * readBackHeightInPixels * 3); + break; + + case BufferedImage.TYPE_INT_RGB: + case BufferedImage.TYPE_INT_ARGB: + glFormat = GL.GL_BGRA; + glType = (hardwareAccelerationDisabled + ? offscreenContext.getOffscreenContextPixelDataType() + : hwGLFormat); + readBackInts = IntBuffer.allocate(readBackWidthInPixels * readBackHeightInPixels); + break; + + default: + // FIXME: Support more off-screen image types (current + // offscreen context implementations don't use others, and + // some of the OpenGL formats aren't supported in the 1.1 + // headers, which we're currently using) + throw new GLException("Unsupported offscreen image type " + awtFormat); + } + } + } + + if (offscreenImage != null) { + GL gl = getGL(); + // Save current modes + gl.glGetIntegerv(GL.GL_PACK_SWAP_BYTES, swapbytes, 0); + gl.glGetIntegerv(GL.GL_PACK_ROW_LENGTH, rowlength, 0); + gl.glGetIntegerv(GL.GL_PACK_SKIP_ROWS, skiprows, 0); + gl.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS, skippixels, 0); + gl.glGetIntegerv(GL.GL_PACK_ALIGNMENT, alignment, 0); + + gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, GL.GL_FALSE); + gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, readBackWidthInPixels); + gl.glPixelStorei(GL.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); + + // Actually read the pixels. + gl.glReadBuffer(GL.GL_FRONT); + if (readBackBytes != null) { + gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackBytes); + } else if (readBackInts != null) { + gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackInts); + } + + // Restore saved modes. + gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, swapbytes[0]); + gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, rowlength[0]); + gl.glPixelStorei(GL.GL_PACK_SKIP_ROWS, skiprows[0]); + gl.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, skippixels[0]); + gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, alignment[0]); + + if (readBackBytes != null || readBackInts != null) { + // Copy temporary data into raster of BufferedImage for faster + // blitting Note that we could avoid this copy in the cases + // where !offscreenContext.offscreenImageNeedsVerticalFlip(), + // but that's the software rendering path which is very slow + // anyway + Object src = null; + Object dest = null; + int srcIncr = 0; + int destIncr = 0; + + if (readBackBytes != null) { + src = readBackBytes.array(); + dest = ((DataBufferByte) offscreenImage.getRaster().getDataBuffer()).getData(); + srcIncr = readBackWidthInPixels * 3; + destIncr = offscreenImage.getWidth() * 3; + } else { + src = readBackInts.array(); + dest = ((DataBufferInt) offscreenImage.getRaster().getDataBuffer()).getData(); + srcIncr = readBackWidthInPixels; + destIncr = offscreenImage.getWidth(); + } + + if (!hardwareAccelerationDisabled || + offscreenContext.offscreenImageNeedsVerticalFlip()) { + int srcPos = 0; + int destPos = (offscreenImage.getHeight() - 1) * destIncr; + for (; destPos >= 0; srcPos += srcIncr, destPos -= destIncr) { + System.arraycopy(src, srcPos, dest, destPos, destIncr); + } + } else { + int srcPos = 0; + int destEnd = destIncr * offscreenImage.getHeight(); + for (int destPos = 0; destPos < destEnd; srcPos += srcIncr, destPos += destIncr) { + System.arraycopy(src, srcPos, dest, destPos, destIncr); + } + } + + // Draw resulting image in one shot + g.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), GLJPanel.this); + } + } + } else { + // Cause OpenGL pipeline to flush its results because + // otherwise it's possible we will buffer up multiple frames' + // rendering results, resulting in apparent mouse lag + GL gl = getGL(); + gl.glFinish(); + } + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + // This is handled above and dispatched directly to the appropriate context + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + } + + class InitAction implements Runnable { + public void run() { + updater.init(GLJPanel.this); + } + } + private InitAction initAction = new InitAction(); + + class DisplayAction implements Runnable { + public void run() { + updater.display(GLJPanel.this); + } + } + private DisplayAction displayAction = new DisplayAction(); + + // This one is used exclusively in the non-hardware-accelerated case + class SwapBuffersAction implements Runnable { + public void run() { + offscreenDrawable.swapBuffers(); + } + } + private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); + + class PaintImmediatelyAction implements Runnable { + public void run() { + paintImmediately(0, 0, getWidth(), getHeight()); + } + } + private PaintImmediatelyAction paintImmediatelyAction = new PaintImmediatelyAction(); + + private int getNextPowerOf2(int number) { + // Workaround for problems where 0 width or height are transiently + // seen during layout + if (number == 0) { + return 2; + } + + if (((number-1) & number) == 0) { + //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 + return number; + } + int power = 0; + while (number > 0) { + number = number>>1; + power++; + } + return (1<<power); + } + + private int getGLInteger(GL gl, int which) { + int[] tmp = new int[1]; + gl.glGetIntegerv(which, tmp, 0); + return tmp[0]; + } +} diff --git a/src/net/java/games/jogl/GLPbuffer.java b/src/classes/javax/media/opengl/GLPbuffer.java index b073388f5..607c5c9fa 100644 --- a/src/net/java/games/jogl/GLPbuffer.java +++ b/src/classes/javax/media/opengl/GLPbuffer.java @@ -37,16 +37,17 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package net.java.games.jogl; +package javax.media.opengl; -/** Offscreen rendering support via pbuffers. This class adds very - little functionality over the GLDrawable class; the only methods - are those which allow access to the pbuffer's contents as a - texture map and which enable offscreen rendering to floating-point - buffers. These methods are currently highly experimental and may - be removed in a future release. */ +/** Provides offscreen rendering support via pbuffers. The principal + addition of this interface is a {@link #destroy} method to + deallocate the pbuffer and its associated resources. It also + contains experimental methods for accessing the pbuffer's contents + as a texture map and enabling rendering to floating-point frame + buffers. These methods are not guaranteed to be supported on all + platforms and may change or be removed in a future release. */ -public interface GLPbuffer extends GLDrawable { +public interface GLPbuffer extends GLAutoDrawable { /** Indicates the GL_APPLE_float_pixels extension is being used for this pbuffer. */ public static final int APPLE_FLOAT = 1; @@ -71,12 +72,12 @@ public interface GLPbuffer extends GLDrawable { /** Unbinds the pbuffer from its internal texture target. */ public void releaseTexture(); - /** Queries initialization status of this pBuffer. */ - public boolean isInitialized(); - /** Destroys the native resources associated with this pbuffer. It is not valid to call display() or any other routines on this - pbuffer after it has been destroyed. */ + pbuffer after it has been destroyed. Before destroying the + pbuffer, the application must destroy any additional OpenGL + contexts which have been created for the pbuffer via {@link + #createContext}. */ public void destroy(); /** Indicates which vendor's extension is being used to support diff --git a/src/classes/javax/media/opengl/Threading.java b/src/classes/javax/media/opengl/Threading.java new file mode 100755 index 000000000..28dc00b9c --- /dev/null +++ b/src/classes/javax/media/opengl/Threading.java @@ -0,0 +1,215 @@ +/* + * 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 + * MICROSYSTEMS, 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. + */ + +package javax.media.opengl; + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import com.sun.opengl.impl.*; + +/** Defines the threading model for the implementation of the classes + in this package. + + <P> + + OpenGL is specified as a thread-safe API, but in practice there + are multithreading-related issues on most, if not all, of the + platforms which support it. For example, some OpenGL + implementations do not behave well when one context is made + current first on one thread, released, and then made current on a + second thread, although this is legal according to the OpenGL + specification. On other platforms there are other problems. + + <P> + + Due to these limitations, and due to the inherent multithreading + in the Java platform (in particular, in the Abstract Window + Toolkit), it is necessary to limit the multithreading occurring in + the typical application using the JOGL API. This has been done by + forcing all OpenGL-related work for GLAutoDrawables on to a single + thread. In other words, if an application uses only the + GLAutoDrawable and GLEventListener callback mechanism, it is + guaranteed to have the most correct single-threaded behavior on + all platforms. + + <P> + + Applications using the GLContext makeCurrent/release API directly + will inherently break this single-threaded model, as these methods + require that the OpenGL context be made current on the current + thread immediately. For applications wishing to integrate better + with the single-threaded model, this class provides public access + to the mechanism used by the JOGL implementation. Users can + execute Runnables on the internal thread used for performing + OpenGL work, and query whether the current thread is already this + thread. Using these mechanisms the user can move work from the + current thread on to the internal OpenGL thread if desired. + + <P> + + This class also provides mechanisms for querying whether this + internal serialization of OpenGL work is in effect, and a + programmatic way of disabling it. Currently it is enabled by + default, although it could be disabled in the future if OpenGL + drivers become more robust on all platforms. + + <P> + + In addition to specifying programmatically whether the single + thread for OpenGL work is enabled, users may switch it on and off + using the system property <code>jogl.1thread</code>. Valid values + for this system property are: + + <PRE> + -Djogl.1thread=false Disable single-threading of OpenGL work + -Djogl.1thread=true Enable single-threading of OpenGL work (default) + -Djogl.1thread=auto Select default single-threading behavior (currently on) + </PRE> +*/ + +public class Threading { + private static boolean singleThreaded = true; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String workaround = System.getProperty("jogl.1thread"); + if (workaround != null && (!workaround.equals("auto"))) { + singleThreaded = Boolean.valueOf(workaround).booleanValue(); + } + printWorkaroundNotice(); + return null; + } + }); + } + + /** No reason to ever instantiate this class */ + private Threading() {} + + /** Provides a mechanism for end users to disable the default + single-threading of the JOGL implementation. Users are strongly + discouraged from calling this method unless they are aware of + all of the consequences and are prepared to enforce some amount + of threading restrictions in their applications. Disabling this + single-threading, for example, will have unintended consequences + on GLAutoDrawable implementations such as GLCanvas, GLJPanel and + GLPbuffer. Currently there is no supported way to re-enable it + once disabled, partly to discourage careless use of this + method. */ + public static void disableSingleThreading() { + singleThreaded = false; + if (Debug.verbose()) { + System.err.println("Application forced disabling of single-threading of JOGL implementation"); + } + } + + /** Indicates whether OpenGL work is being automatically forced to a + single thread by the JOGL implementation. */ + public static boolean isSingleThreaded() { + return singleThreaded; + } + + /** Indicates whether the current thread is the single thread on + which the JOGL implementation performs all of its OpenGL-related + work. This method should only be called if the single-thread + model is in effect. */ + public static boolean isOpenGLThread() throws GLException { + if (!isSingleThreaded()) { + throw new GLException("Should only call this in single-threaded mode"); + } + + if (Java2D.isOGLPipelineActive()) { + // FIXME: ideally only the QFT would be considered to be the + // "OpenGL thread", but we can not currently run all of JOGL's + // OpenGL work on that thread. For now, run the GLJPanel's + // Java2D/JOGL bridge on the QFT but everything else on the + // EDT, except when we're already on the QFT. + return (Java2D.isQueueFlusherThread() || + EventQueue.isDispatchThread()); + } else { + return EventQueue.isDispatchThread(); + } + } + + /** Executes the passed Runnable on the single thread used for all + OpenGL work in the JOGL implementation. It is not specified + exactly which thread is used for this purpose. This method + should only be called if the single-thread model is in use and + if the current thread is not the OpenGL thread (i.e., if + <code>isOpenGLThread()</code> returns false). It is up to the + end user to check to see whether the current thread is the + OpenGL thread and either execute the Runnable directly or + perform the work inside it. */ + public static void invokeOnOpenGLThread(Runnable r) throws GLException { + if (!isSingleThreaded()) { + throw new GLException ("Should only call this in single-threaded mode"); + } + + if (isOpenGLThread()) { + throw new GLException ("Should only call this from other threads than the OpenGL thread"); + } + + // FIXME: ideally should run all OpenGL work on the Java2D QFT + // thread when it's enabled, but there are issues with this when + // the GLJPanel is not using the Java2D bridge; would like to run + // its OpenGL work on the QFT, but do the image drawing from the + // EDT. Other issues still remain with the GLCanvas as well. + + // if (Java2D.isOGLPipelineActive()) { + // Java2D.invokeWithOGLContextCurrent(null, r); + // } else { + try { + EventQueue.invokeAndWait(r); + } catch (InvocationTargetException e) { + throw new GLException(e.getTargetException()); + } catch (InterruptedException e) { + throw new GLException(e); + } + // } + } + + private static void printWorkaroundNotice() { + if (singleThreaded && Debug.verbose()) { + System.err.println("Using single thread for performing OpenGL work in JOGL implementation"); + } + } +} diff --git a/src/net/java/games/jogl/GLUquadric.java b/src/classes/javax/media/opengl/glu/GLUquadric.java index 3aeccc166..bcb21fb90 100755 --- a/src/net/java/games/jogl/GLUquadric.java +++ b/src/classes/javax/media/opengl/glu/GLUquadric.java @@ -1,4 +1,4 @@ -package net.java.games.jogl; +package javax.media.opengl.glu; /** * Wrapper for a GLU quadric object. diff --git a/src/net/java/games/jogl/GLUtesselator.java b/src/classes/javax/media/opengl/glu/GLUtessellator.java index ea80ccb02..df42a8a82 100644..100755 --- a/src/net/java/games/jogl/GLUtesselator.java +++ b/src/classes/javax/media/opengl/glu/GLUtessellator.java @@ -40,17 +40,17 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl; +package javax.media.opengl.glu; /** - * The <b>GLUtesselator</b> object is used to hold the data, such as the + * The <b>GLUtessellator</b> object is used to hold the data, such as the * vertices, edges and callback objects, to describe and tessellate complex - * polygons. A <b>GLUtesselator</b> object is used with the - * {@link net.java.games.jogl.GLU GLU} tesselator methods and - * {@link net.java.games.jogl.GLUtesselatorCallback GLU callbacks}. + * polygons. A <b>GLUtessellator</b> object is used with the + * {@link GLU GLU} tessellator methods and + * {@link GLUtessellatorCallback GLU callbacks}. * * @author Eric Veach, July 1994 * @author Java Port: Pepijn Van Eechhoudt, July 2003 * @author Java Port: Nathan Parker Burg, August 2003 */ -public interface GLUtesselator {} +public interface GLUtessellator {} diff --git a/src/net/java/games/jogl/GLUtesselatorCallback.java b/src/classes/javax/media/opengl/glu/GLUtessellatorCallback.java index 0da9a15fd..9d4946b00 100644..100755 --- a/src/net/java/games/jogl/GLUtesselatorCallback.java +++ b/src/classes/javax/media/opengl/glu/GLUtessellatorCallback.java @@ -40,20 +40,20 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl; +package javax.media.opengl.glu; /** - * <b>GLUtesselatorCallback</b> interface provides methods that the user will + * <b>GLUtessellatorCallback</b> interface provides methods that the user will * override to define the callbacks for a tessellation object. * * @author Eric Veach, July 1994 * @author Java Port: Pepijn Van Eeckhoudt, July 2003 * @author Java Port: Nathan Parker Burg, August 2003 */ -public interface GLUtesselatorCallback { +public interface GLUtessellatorCallback { /** * The <b>begin</b> callback method is invoked like - * {@link net.java.games.jogl.GL#glBegin glBegin} to indicate the start of a + * {@link javax.media.opengl.GL#glBegin glBegin} to indicate the start of a * (triangle) primitive. The method takes a single argument of type int. If * the <b>GLU_TESS_BOUNDARY_ONLY</b> property is set to <b>GL_FALSE</b>, then * the argument is set to either <b>GL_TRIANGLE_FAN</b>, @@ -66,18 +66,17 @@ public interface GLUtesselatorCallback { * values are valid: <b>GL_TRIANGLE_FAN</b>, <b>GL_TRIANGLE_STRIP</b>, * <b>GL_TRIANGLES</b> or <b>GL_LINE_LOOP</b>. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#end end - * @see net.java.games.jogl.GLUtesselatorCallback#begin begin + * @see GLU#gluTessCallback gluTessCallback + * @see #end end + * @see #begin begin */ public void begin(int type); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#begin - * begin} callback method except that it takes an additional reference - * argument. This reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #begin begin} callback method except that + * it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param type * Specifics the type of begin/end pair being defined. The following @@ -86,16 +85,16 @@ public interface GLUtesselatorCallback { * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#endData endData - * @see net.java.games.jogl.GLUtesselatorCallback#begin begin + * @see GLU#gluTessCallback gluTessCallback + * @see #endData endData + * @see #begin begin */ public void beginData(int type, Object polygonData); /** * The <b>edgeFlag</b> callback method is similar to - * {@link net.java.games.jogl.GL#glEdgeFlag glEdgeFlag}. The method takes + * {@link javax.media.opengl.GL#glEdgeFlag glEdgeFlag}. The method takes * a single boolean boundaryEdge that indicates which edges lie on the * polygon boundary. If the boundaryEdge is <b>GL_TRUE</b>, then each vertex * that follows begins an edge that lies on the polygon boundary, that is, @@ -114,57 +113,54 @@ public interface GLUtesselatorCallback { * @param boundaryEdge * Specifics which edges lie on the polygon boundary. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#edgeFlagData edgeFlagData + * @see GLU#gluTessCallback gluTessCallback + * @see #edgeFlagData edgeFlagData */ public void edgeFlag(boolean boundaryEdge); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#edgeFlag - * edgeFlage} callback method except that it takes an additional reference - * argument. This reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #edgeFlag edgeFlage} callback method + * except that it takes an additional reference argument. This + * reference is identical to the opaque reference provided when + * {@link GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param boundaryEdge * Specifics which edges lie on the polygon boundary. * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#edgeFlag edgeFlag + * @see GLU#gluTessCallback gluTessCallback + * @see #edgeFlag edgeFlag */ public void edgeFlagData(boolean boundaryEdge, Object polygonData); /** - * The <b>vertex</b> callback method is invoked between the - * {@link net.java.games.jogl.GLUtesselatorCallback#begin begin} and - * {@link net.java.games.jogl.GLUtesselatorCallback#end end} callback methods. - * It is similar to {@link net.java.games.jogl.GL#glVertex3f glVertex3f}, and it - * defines the vertices of the triangles created by the tessellation process. - * The method takes a reference as its only argument. This reference is - * identical to the opaque reference provided by the user when the vertex was - * described (see {@link net.java.games.jogl.GLU#gluTessVertex - * gluTessVertex}). + * The <b>vertex</b> callback method is invoked between the {@link + * #begin begin} and {@link #end end} callback methods. It is + * similar to {@link javax.media.opengl.GL#glVertex3f glVertex3f}, + * and it defines the vertices of the triangles created by the + * tessellation process. The method takes a reference as its only + * argument. This reference is identical to the opaque reference + * provided by the user when the vertex was described (see {@link + * GLU#gluTessVertex gluTessVertex}). * * @param vertexData * Specifics a reference to the vertices of the triangles created * byt the tessellatin process. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#vertexData vertexData + * @see GLU#gluTessCallback gluTessCallback + * @see #vertexData vertexData */ public void vertex(Object vertexData); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#vertex - * vertex} callback method except that it takes an additional reference - * argument. This reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #vertex vertex} callback method except + * that it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param vertexData * Specifics a reference to the vertices of the triangles created @@ -172,37 +168,36 @@ public interface GLUtesselatorCallback { * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#vertex vertex + * @see GLU#gluTessCallback gluTessCallback + * @see #vertex vertex */ public void vertexData(Object vertexData, Object polygonData); /** * The end callback serves the same purpose as - * {@link net.java.games.jogl.GL#glEnd glEnd}. It indicates the end of a + * {@link javax.media.opengl.GL#glEnd glEnd}. It indicates the end of a * primitive and it takes no arguments. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#begin begin - * @see net.java.games.jogl.GLUtesselatorCallback#endData endData + * @see GLU#gluTessCallback gluTessCallback + * @see #begin begin + * @see #endData endData */ public void end(); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#end end} - * callback method except that it takes an additional reference argument. This - * reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #end end} callback method except that it + * takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#beginData beginData - * @see net.java.games.jogl.GLUtesselatorCallback#end end + * @see GLU#gluTessCallback gluTessCallback + * @see #beginData beginData + * @see #end end */ public void endData(Object polygonData); @@ -224,7 +219,7 @@ public interface GLUtesselatorCallback { * <i>data</i> and <i>weight</i>, and return the new vertex pointer in * <i>outData</i>. This handle is supplied during rendering callbacks. The * user is responsible for freeing the memory some time after - * {@link net.java.games.jogl.GLU#gluTessEndPolygon gluTessEndPolygon} is + * {@link GLU#gluTessEndPolygon gluTessEndPolygon} is * called.<P> * * For example, if the polygon lies in an arbitrary plane in 3-space, and a @@ -268,19 +263,18 @@ public interface GLUtesselatorCallback { * @param outData * Reference user the put the coodinates of the new vertex. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#combineData combineData + * @see GLU#gluTessCallback gluTessCallback + * @see #combineData combineData */ public void combine(double[] coords, Object[] data, float[] weight, Object[] outData); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#combine - * combine} callback method except that it takes an additional reference - * argument. This reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #combine combine} callback method except + * that it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param coords * Specifics the location of the new vertex. @@ -293,8 +287,8 @@ public interface GLUtesselatorCallback { * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#combine combine + * @see GLU#gluTessCallback gluTessCallback + * @see #combine combine */ public void combineData(double[] coords, Object[] data, float[] weight, Object[] outData, @@ -309,7 +303,7 @@ public interface GLUtesselatorCallback { * <b>GLU_TESS_MISSING_END_CONTOUR</b>, <b>GLU_TESS_COORD_TOO_LARGE</b>, * <b>GLU_TESS_NEED_COMBINE_CALLBACK</b> or <b>GLU_OUT_OF_MEMORY</b>. * Character strings describing these errors can be retrieved with the - * {@link net.java.games.jogl.GLU#gluErrorString gluErrorString} call.<P> + * {@link GLU#gluErrorString gluErrorString} call.<P> * * The GLU library will recover from the first four errors by inserting the * missing call(s). <b>GLU_TESS_COORD_TOO_LARGE</b> indicates that some @@ -326,28 +320,27 @@ public interface GLUtesselatorCallback { * @param errnum * Specifics the error number code. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#errorData errorData + * @see GLU#gluTessCallback gluTessCallback + * @see #errorData errorData */ public void error(int errnum); /** - * The same as the {@link net.java.games.jogl.GLUtesselatorCallback#error - * error} callback method except that it takes an additional reference - * argument. This reference is identical to the opaque reference provided when - * {@link net.java.games.jogl.GLU#gluTessBeginPolygon gluTessBeginPolygon} was - * called. + * The same as the {@link #error error} callback method except that + * it takes an additional reference argument. This reference is + * identical to the opaque reference provided when {@link + * GLU#gluTessBeginPolygon gluTessBeginPolygon} was called. * * @param errnum * Specifics the error number code. * @param polygonData * Specifics a reference to user-defined data. * - * @see net.java.games.jogl.GLU#gluTessCallback gluTessCallback - * @see net.java.games.jogl.GLUtesselatorCallback#error error + * @see GLU#gluTessCallback gluTessCallback + * @see #error error */ public void errorData(int errnum, Object polygonData); - //void mesh(net.java.games.jogl.impl.tesselator.GLUmesh mesh); + //void mesh(com.sun.opengl.impl.tessellator.GLUmesh mesh); } diff --git a/src/net/java/games/jogl/GLUtesselatorCallbackAdapter.java b/src/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java index 162eaec93..eaccf0b15 100644..100755 --- a/src/net/java/games/jogl/GLUtesselatorCallbackAdapter.java +++ b/src/classes/javax/media/opengl/glu/GLUtessellatorCallbackAdapter.java @@ -40,13 +40,11 @@ ** Java Port: Pepijn Van Eeckhoudt, July 2003 ** Java Port: Nathan Parker Burg, August 2003 */ -package net.java.games.jogl; - -import net.java.games.jogl.GLUtesselatorCallback; +package javax.media.opengl.glu; /** - * The <b>GLUtesselatorCallbackAdapter</b> provides a default implementation of - * {@link net.java.games.jogl.GLUtesselatorCallback GLUtesselatorCallback} + * The <b>GLUtessellatorCallbackAdapter</b> provides a default implementation of + * {@link GLUtessellatorCallback GLUtessellatorCallback} * with empty callback methods. This class can be extended to provide user * defined callback methods. * @@ -55,12 +53,12 @@ import net.java.games.jogl.GLUtesselatorCallback; * @author Java Port: Nathan Parker Burg, August 2003 */ -public class GLUtesselatorCallbackAdapter implements GLUtesselatorCallback { +public class GLUtessellatorCallbackAdapter implements GLUtessellatorCallback { public void begin(int type) {} public void edgeFlag(boolean boundaryEdge) {} public void vertex(Object vertexData) {} public void end() {} -// public void mesh(net.java.games.jogl.impl.tesselator.GLUmesh mesh) {} +// public void mesh(com.sun.opengl.impl.tessellator.GLUmesh mesh) {} public void error(int errnum) {} public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {} diff --git a/src/native/jogl/InternalBufferUtils.c b/src/native/jogl/InternalBufferUtils.c index 73c52011f..083f51b42 100644 --- a/src/native/jogl/InternalBufferUtils.c +++ b/src/native/jogl/InternalBufferUtils.c @@ -49,6 +49,6 @@ #endif JNIEXPORT jobject JNICALL -Java_net_java_games_jogl_impl_InternalBufferUtils_newDirectByteBuffer(JNIEnv* env, jclass unused, jlong address, jint capacity) { +Java_com_sun_opengl_impl_InternalBufferUtils_newDirectByteBuffer(JNIEnv* env, jclass unused, jlong address, jint capacity) { return (*env)->NewDirectByteBuffer(env, (void*) (intptr_t) address, capacity); } diff --git a/src/native/jogl/JAWT_DrawingSurfaceInfo.c b/src/native/jogl/JAWT_DrawingSurfaceInfo.c index 59c575f0c..2b64ec858 100644 --- a/src/native/jogl/JAWT_DrawingSurfaceInfo.c +++ b/src/native/jogl/JAWT_DrawingSurfaceInfo.c @@ -41,13 +41,13 @@ #ifdef WIN32 #define PLATFORM_DSI_SIZE sizeof(JAWT_Win32DrawingSurfaceInfo) - static const char* platformDSIClassName = "net/java/games/jogl/impl/windows/JAWT_Win32DrawingSurfaceInfo"; + static const char* platformDSIClassName = "com/sun/opengl/impl/windows/JAWT_Win32DrawingSurfaceInfo"; #elif defined(linux) || defined(__sun) || defined(__FreeBSD__) #define PLATFORM_DSI_SIZE sizeof(JAWT_X11DrawingSurfaceInfo) - static const char* platformDSIClassName = "net/java/games/jogl/impl/x11/JAWT_X11DrawingSurfaceInfo"; + static const char* platformDSIClassName = "com/sun/opengl/impl/x11/JAWT_X11DrawingSurfaceInfo"; #elif defined(macosx) #define PLATFORM_DSI_SIZE sizeof(JAWT_MacOSXDrawingSurfaceInfo) - static const char* platformDSIClassName = "net/java/games/jogl/impl/macosx/JAWT_MacOSXDrawingSurfaceInfo"; + static const char* platformDSIClassName = "com/sun/opengl/impl/macosx/JAWT_MacOSXDrawingSurfaceInfo"; #else ERROR: port JAWT_DrawingSurfaceInfo.c to your platform #endif @@ -56,7 +56,7 @@ static jclass platformDSIClass = NULL; static jmethodID constructor = NULL; JNIEXPORT jobject JNICALL -Java_net_java_games_jogl_impl_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { +Java_com_sun_opengl_impl_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { JAWT_DrawingSurfaceInfo* dsi; jobject dirbuf; jclass clazz; diff --git a/src/native/jogl/MacOSXWindowSystemInterface.m b/src/native/jogl/MacOSXWindowSystemInterface.m index 516bda0db..125f6abb4 100644 --- a/src/native/jogl/MacOSXWindowSystemInterface.m +++ b/src/native/jogl/MacOSXWindowSystemInterface.m @@ -43,7 +43,19 @@ void* createContext(void* shareContext, void* view, NSView *nsView = (NSView*)view; if (nsView != NULL) { + Bool viewReady = true; + if ([nsView lockFocusIfCanDraw] == NO) { + viewReady = false; + } else { + NSRect frame = [nsView frame]; + if ((frame.size.width == 0) || (frame.size.height == 0)) { + [nsView unlockFocus]; + viewReady = false; + } + } + + if (!viewReady) { if (viewNotReady != NULL) { *viewNotReady = 1; } @@ -163,13 +175,17 @@ void* createPBuffer(int renderTarget, int internalFormat, int width, int height) } Bool destroyPBuffer(void* context, void* buffer) { - NSOpenGLContext *nsContext = (NSOpenGLContext*)context; + /* FIXME: not clear whether we need to perform the clearDrawable below */ + /* FIXME: remove the context argument -- don't need it any more */ + /* NSOpenGLContext *nsContext = (NSOpenGLContext*)context; */ NSOpenGLPixelBuffer *pBuffer = (NSOpenGLPixelBuffer*)buffer; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + /* if (nsContext != NULL) { [nsContext clearDrawable]; } + */ [pBuffer release]; [pool release]; diff --git a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingEmitter.java deleted file mode 100644 index 72d349356..000000000 --- a/src/net/java/games/gluegen/JavaMethodBindingEmitter.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.gluegen; - -import java.util.*; -import java.io.*; - -import net.java.games.gluegen.cgram.types.*; -import net.java.games.gluegen.cgram.*; - -/** - * An emitter that emits only the interface for a Java<->C JNI binding. - */ -public class JavaMethodBindingEmitter extends FunctionEmitter -{ - public static final EmissionModifier PUBLIC = new EmissionModifier("public"); - public static final EmissionModifier PROTECTED = new EmissionModifier("protected"); - public static final EmissionModifier PRIVATE = new EmissionModifier("private"); - public static final EmissionModifier ABSTRACT = new EmissionModifier("abstract"); - public static final EmissionModifier FINAL = new EmissionModifier("final"); - public static final EmissionModifier NATIVE = new EmissionModifier("native"); - public static final EmissionModifier SYNCHRONIZED = new EmissionModifier("synchronized"); - - protected static final CommentEmitter defaultJavaCommentEmitter = new DefaultCommentEmitter(); - protected static final CommentEmitter defaultInterfaceCommentEmitter = - new InterfaceCommentEmitter(); - - // Exception type raised in the generated code if runtime checks fail - private String runtimeExceptionType; - - private MethodBinding binding; - private boolean forImplementingMethodCall; - - // A non-null value indicates that rather than returning a compound - // type accessor we are returning an array of such accessors; this - // expression is a MessageFormat string taking the names of the - // incoming Java arguments as parameters and computing as an int the - // number of elements of the returned array. - private String returnedArrayLengthExpression; - - public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType) - { - this(binding, output, runtimeExceptionType, false); - } - - public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType, boolean forImplementingMethodCall) - { - super(output); - this.binding = binding; - this.forImplementingMethodCall = forImplementingMethodCall; - this.runtimeExceptionType = runtimeExceptionType; - setCommentEmitter(defaultInterfaceCommentEmitter); - } - - public JavaMethodBindingEmitter(JavaMethodBindingEmitter arg) { - super(arg); - runtimeExceptionType = arg.runtimeExceptionType; - binding = arg.binding; - forImplementingMethodCall = arg.forImplementingMethodCall; - returnedArrayLengthExpression = arg.returnedArrayLengthExpression; - } - - public final MethodBinding getBinding() { return binding; } - - public boolean isForImplementingMethodCall() { return forImplementingMethodCall; } - - public String getName() { - return binding.getName(); - } - - - /** The type of exception (must subclass - <code>java.lang.RuntimeException</code>) raised if runtime - checks fail in the generated code. */ - public String getRuntimeExceptionType() { - return runtimeExceptionType; - } - - /** If the underlying function returns an array (currently only - arrays of compound types are supported) as opposed to a pointer - to an object, this method should be called to provide a - MessageFormat string containing an expression that computes the - number of elements of the returned array. The parameters to the - MessageFormat expression are the names of the incoming Java - arguments. */ - public void setReturnedArrayLengthExpression(String expr) { - returnedArrayLengthExpression = expr; - } - - protected void emitReturnType(PrintWriter writer) - { - writer.print(getReturnTypeString(false)); - } - - protected String getReturnTypeString(boolean skipArray) { - if (skipArray || (getReturnedArrayLengthExpression() == null && !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers())) { - return binding.getJavaReturnType().getName(); - } - return binding.getJavaReturnType().getName() + "[]"; - } - - protected void emitName(PrintWriter writer) - { - if (forImplementingMethodCall) { - writer.print(getImplMethodName()); - } else { - writer.print(getName()); - } - } - - protected int emitArguments(PrintWriter writer) - { - boolean needComma = false; - int numEmitted = 0; - - if (forImplementingMethodCall && binding.hasContainingType()) { - // Always emit outgoing "this" argument - writer.print("java.nio.Buffer "); - writer.print(javaThisArgumentName()); - ++numEmitted; - needComma = true; - } - - for (int i = 0; i < binding.getNumArguments(); i++) { - JavaType type = binding.getJavaArgumentType(i); - if (type.isVoid()) { - // Make sure this is the only param to the method; if it isn't, - // there's something wrong with our parsing of the headers. - if (binding.getNumArguments() != 1) { - throw new InternalError( - "\"void\" argument type found in " + - "multi-argument function \"" + binding + "\""); - } - continue; - } - - if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { - // Don't need to expose these at the Java level - continue; - } - - if (needComma) { - writer.print(", "); - } - - writer.print(type.getName()); - writer.print(" "); - writer.print(binding.getArgumentName(i)); - ++numEmitted; - needComma = true; - } - return numEmitted; - } - - protected String getImplMethodName() - { - return binding.getName() + "0"; - } - - protected void emitBody(PrintWriter writer) - { - writer.println(';'); - } - - protected static String javaThisArgumentName() { - return "jthis0"; - } - - protected String getCommentStartString() { return "/** "; } - - protected String getBaseIndentString() { return " "; } - - protected String getReturnedArrayLengthExpression() { - return returnedArrayLengthExpression; - } - - /** - * Class that emits a generic comment for JavaMethodBindingEmitters; the comment - * includes the C signature of the native method that is being bound by the - * emitter java method. - */ - protected static class DefaultCommentEmitter implements CommentEmitter { - public void emit(FunctionEmitter emitter, PrintWriter writer) { - emitBeginning(emitter, writer); - emitBindingCSignature(((JavaMethodBindingEmitter)emitter).getBinding(), writer); - emitEnding(emitter, writer); - } - protected void emitBeginning(FunctionEmitter emitter, PrintWriter writer) { - writer.print("Entry point to C language function: <br> "); - } - protected void emitBindingCSignature(MethodBinding binding, PrintWriter writer) { - writer.print("<code> "); - writer.print(binding.getCSymbol()); - writer.print(" </code> "); - } - protected void emitEnding(FunctionEmitter emitter, PrintWriter writer) { - // If argument type is a named enum, then emit a comment detailing the - // acceptable values of that enum. - MethodBinding binding = ((JavaMethodBindingEmitter)emitter).getBinding(); - for (int i = 0; i < binding.getNumArguments(); i++) { - Type type = binding.getCArgumentType(i); - // don't emit param comments for anonymous enums, since we can't - // distinguish between the values found within multiple anonymous - // enums in the same C translation unit. - if (type.isEnum() && type.getName() != HeaderParser.ANONYMOUS_ENUM_NAME) { - EnumType enumType = (EnumType)type; - writer.println(); - writer.print(emitter.getBaseIndentString()); - writer.print(" "); - writer.print("@param "); - writer.print(binding.getArgumentName(i)); - writer.print(" valid values are: <code>"); - for (int j = 0; j < enumType.getNumEnumerates(); ++j) { - if (j>0) writer.print(", "); - writer.print(enumType.getEnumName(j)); - } - writer.println("</code>"); - } - } - } - } - - protected static class InterfaceCommentEmitter - extends JavaMethodBindingEmitter.DefaultCommentEmitter - { - protected void emitBeginning(FunctionEmitter emitter, - PrintWriter writer) { - writer.print("Interface to C language function: <br> "); - } - } -} - diff --git a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java b/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java deleted file mode 100644 index a3d35f912..000000000 --- a/src/net/java/games/gluegen/JavaMethodBindingImplEmitter.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.gluegen; - -import java.io.*; -import java.util.*; -import java.text.MessageFormat; - -import net.java.games.gluegen.cgram.types.*; - -/** Emits the Java-side component of the Java<->C JNI binding. */ -public class JavaMethodBindingImplEmitter extends JavaMethodBindingEmitter -{ - private boolean isUnimplemented; - - public JavaMethodBindingImplEmitter(MethodBinding binding, PrintWriter output, String runtimeExceptionType) - { - this(binding, output, runtimeExceptionType, false); - } - - public JavaMethodBindingImplEmitter(MethodBinding binding, - PrintWriter output, - String runtimeExceptionType, - boolean isUnimplemented) - { - super(binding, output, runtimeExceptionType); - setCommentEmitter(defaultJavaCommentEmitter); - this.isUnimplemented = isUnimplemented; - } - - public JavaMethodBindingImplEmitter(JavaMethodBindingEmitter arg) { - super(arg); - if (arg instanceof JavaMethodBindingImplEmitter) { - this.isUnimplemented = ((JavaMethodBindingImplEmitter) arg).isUnimplemented; - } - } - - protected void emitBody(PrintWriter writer) - { - MethodBinding binding = getBinding(); - if (needsBody()) { - writer.println(); - writer.println(" {"); - if (isUnimplemented) { - writer.println(" throw new " + getRuntimeExceptionType() + "(\"Unimplemented\");"); - } else { - emitPreCallSetup(binding, writer); - emitReturnVariableSetup(binding, writer); - emitCall(binding, writer); - } - writer.println(" }"); - } else { - writer.println(";"); - } - } - - protected boolean isUnimplemented() { - return isUnimplemented; - } - - protected boolean needsBody() { - return (isUnimplemented || - getBinding().signatureUsesNIO() || - getBinding().signatureUsesCArrays() || - getBinding().hasContainingType()); - } - - protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { - emitArrayLengthAndNIOBufferChecks(binding, writer); - } - - protected void emitArrayLengthAndNIOBufferChecks(MethodBinding binding, PrintWriter writer) { - // Check lengths of any incoming arrays if necessary - for (int i = 0; i < binding.getNumArguments(); i++) { - Type type = binding.getCArgumentType(i); - if (type.isArray()) { - ArrayType arrayType = type.asArray(); - writer.println(" if (" + binding.getArgumentName(i) + ".length < " + arrayType.getLength() + ")"); - writer.println(" throw new " + getRuntimeExceptionType() + "(\"Length of array \\\"" + binding.getArgumentName(i) + - "\\\" was less than the required " + arrayType.getLength() + "\");"); - } else { - JavaType javaType = binding.getJavaArgumentType(i); - if (javaType.isNIOBuffer()) { - writer.println(" if (!BufferFactory.isDirect(" + binding.getArgumentName(i) + "))"); - writer.println(" throw new " + getRuntimeExceptionType() + "(\"Argument \\\"" + - binding.getArgumentName(i) + "\\\" was not a direct buffer\");"); - } else if (javaType.isNIOBufferArray()) { - String argName = binding.getArgumentName(i); - // Check direct buffer properties of all buffers within - writer.println(" if (" + argName + " != null) {"); - writer.println(" for (int _ctr = 0; _ctr < " + argName + ".length; _ctr++) {"); - writer.println(" if (!BufferFactory.isDirect(" + argName + "[_ctr])) {"); - writer.println(" throw new " + getRuntimeExceptionType() + "(\"Element \" + _ctr + \" of argument \\\"" + - binding.getArgumentName(i) + "\\\" was not a direct buffer\");"); - writer.println(" }"); - writer.println(" }"); - writer.println(" }"); - } - } - } - } - - protected void emitReturnVariableSetup(MethodBinding binding, PrintWriter writer) { - writer.print(" "); - JavaType returnType = binding.getJavaReturnType(); - if (!returnType.isVoid()) { - if (returnType.isCompoundTypeWrapper() || - returnType.isNIOByteBuffer()) { - writer.println("ByteBuffer _res;"); - writer.print(" _res = "); - } else if (returnType.isArrayOfCompoundTypeWrappers()) { - writer.println("ByteBuffer[] _res;"); - writer.print(" _res = "); - } else { - writer.print("return "); - } - } - } - - protected void emitCall(MethodBinding binding, PrintWriter writer) { - writer.print(getImplMethodName()); - writer.print("("); - emitCallArguments(binding, writer); - writer.print(")"); - emitCallResultReturn(binding, writer); - } - - protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { - boolean needComma = false; - int numArgsEmitted = 0; - if (binding.hasContainingType()) { - // Emit this pointer - assert(binding.getContainingType().isCompoundTypeWrapper()); - writer.print("getBuffer()"); - needComma = true; - ++numArgsEmitted; - } - for (int i = 0; i < binding.getNumArguments(); i++) { - JavaType type = binding.getJavaArgumentType(i); - if (type.isJNIEnv() || binding.isArgumentThisPointer(i)) { - // Don't need to expose these at the Java level - continue; - } - - if (type.isVoid()) { - // Make sure this is the only param to the method; if it isn't, - // there's something wrong with our parsing of the headers. - assert(binding.getNumArguments() == 1); - continue; - } - - if (needComma) { - writer.print(", "); - } - - if (type.isCompoundTypeWrapper()) { - writer.print("(("); - } - writer.print(binding.getArgumentName(i)); - if (type.isCompoundTypeWrapper()) { - writer.print(" == null) ? null : "); - writer.print(binding.getArgumentName(i)); - writer.print(".getBuffer())"); - } - needComma = true; - ++numArgsEmitted; - } - return numArgsEmitted; - } - - protected void emitCallResultReturn(MethodBinding binding, PrintWriter writer) { - JavaType returnType = binding.getJavaReturnType(); - if (returnType.isCompoundTypeWrapper()) { - writer.println(";"); - String fmt = getReturnedArrayLengthExpression(); - writer.println(" if (_res == null) return null;"); - if (fmt == null) { - writer.print(" return new " + returnType.getName() + "(_res.order(ByteOrder.nativeOrder()))"); - } else { - writer.println(" _res.order(ByteOrder.nativeOrder());"); - String[] argumentNames = new String[binding.getNumArguments()]; - for (int i = 0; i < binding.getNumArguments(); i++) { - argumentNames[i] = binding.getArgumentName(i); - } - String expr = new MessageFormat(fmt).format(argumentNames); - PointerType cReturnTypePointer = binding.getCReturnType().asPointer(); - CompoundType cReturnType = null; - if (cReturnTypePointer != null) { - cReturnType = cReturnTypePointer.getTargetType().asCompound(); - } - if (cReturnType == null) { - throw new RuntimeException("ReturnedArrayLength directive currently only supported for pointers to compound types " + - "(error occurred while generating Java glue code for " + binding.getName() + ")"); - } - writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[" + expr + "];"); - writer.println(" for (int _count = 0; _count < " + expr + "; _count++) {"); - // Create temporary ByteBuffer slice - // FIXME: probably need Type.getAlignedSize() for arrays of - // compound types (rounding up to machine-dependent alignment) - writer.println(" _res.position(_count * " + cReturnType.getSize() + ");"); - writer.println(" _res.limit ((1 + _count) * " + cReturnType.getSize() + ");"); - writer.println(" ByteBuffer _tmp = _res.slice();"); - writer.println(" _tmp.order(ByteOrder.nativeOrder());"); - writer.println(" _res.position(0);"); - writer.println(" _res.limit(_res.capacity());"); - writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_tmp);"); - writer.println(" }"); - writer.print (" return _retarray"); - } - } else if (returnType.isNIOBuffer()) { - writer.println(";"); - writer.println(" if (_res == null) return null;"); - writer.print(" return _res.order(ByteOrder.nativeOrder())"); - } else if (returnType.isArrayOfCompoundTypeWrappers()) { - writer.println(";"); - writer.println(" if (_res == null) return null;"); - writer.println(" " + getReturnTypeString(false) + " _retarray = new " + getReturnTypeString(true) + "[_res.length];"); - writer.println(" for (int _count = 0; _count < _res.length; _count++) {"); - writer.println(" _retarray[_count] = new " + getReturnTypeString(true) + "(_res[_count]);"); - writer.println(" }"); - writer.print (" return _retarray"); - } - writer.println(";"); - } -} - diff --git a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java b/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java deleted file mode 100644 index aa853711a..000000000 --- a/src/net/java/games/gluegen/opengl/JavaGLPAWrapperEmitter.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.gluegen.opengl; - -import java.io.*; -import java.util.*; -import net.java.games.gluegen.*; -import net.java.games.gluegen.cgram.types.*; - -public class JavaGLPAWrapperEmitter extends JavaMethodBindingImplEmitter -{ - private static final CommentEmitter commentEmitterForWrappedMethod = - new WrappedMethodCommentEmitter(); - - private JavaMethodBindingEmitter emitterBeingWrapped; - private String getProcAddressTableExpr; - - public JavaGLPAWrapperEmitter(JavaMethodBindingEmitter methodToWrap, String getProcAddressTableExpr) - { - super(methodToWrap.getBinding(), methodToWrap.getDefaultOutput(), methodToWrap.getRuntimeExceptionType()); - this.getProcAddressTableExpr = getProcAddressTableExpr; - - if (methodToWrap.getBinding().hasContainingType()) - { - throw new IllegalArgumentException( - "Cannot create OpenGL proc. address wrapper; method has containing type: \"" + - methodToWrap.getBinding() + "\""); - } - - // make a new emitter that will emit the original method's binding, but - // with WRAP_PREFIX before its name. If a body is needed (for array - // length checking, unwrapping of wrapper objects to java.nio.Buffers, - // etc.) then it will be generated; therefore the emitter being wrapped - // should be an "NIO buffer variant" (i.e., after all unpacking has - // occurred). - emitterBeingWrapped = - new JavaMethodBindingEmitter(methodToWrap.getBinding().createNIOBufferVariant(), - methodToWrap.getDefaultOutput(), - methodToWrap.getRuntimeExceptionType()) - { - protected void emitName(PrintWriter writer) - { - writer.print(GLEmitter.WRAP_PREFIX); - super.emitName(writer); - } - protected int emitArguments(PrintWriter writer) - { - int numEmitted = super.emitArguments(writer); - if (numEmitted > 0) - { - writer.print(", "); - } - writer.print("long glProcAddress"); - ++numEmitted; - - return numEmitted; - } - }; - - // copy the modifiers from the original emitter - emitterBeingWrapped.addModifiers(methodToWrap.getModifiers()); - - // Change the access of the method we're wrapping to PRIVATE - EmissionModifier origAccess = null; // null is equivalent if package access - if (emitterBeingWrapped.hasModifier(PUBLIC)) - { - origAccess = PUBLIC; - } - else if (emitterBeingWrapped.hasModifier(PROTECTED)) - { - origAccess = PROTECTED; - } - else if (emitterBeingWrapped.hasModifier(PRIVATE)) - { - origAccess = PRIVATE; - } - - if (origAccess != null) - { - emitterBeingWrapped.removeModifier(origAccess); - } - emitterBeingWrapped.addModifier(PRIVATE); - emitterBeingWrapped.addModifier(NATIVE); - - // Now make our binding use the original access of the wrapped method - this.addModifier(origAccess); - if (emitterBeingWrapped.hasModifier(STATIC)) { - this.addModifier(STATIC); - } - } - - protected boolean needsBody() { - return true; - } - - protected String getImplMethodName() { - return GLEmitter.WRAP_PREFIX + getBinding().getName(); - } - - public void emit(PrintWriter writer) - { - // Emit a wrapper that will call the method we want to wrap - //writer.println(" // Emitter being wrapped = " + emitterBeingWrapped.getClass().getName()); - super.emit(writer); - writer.println(); - - // emit the wrapped method - CommentEmitter origComment = emitterBeingWrapped.getCommentEmitter(); - emitterBeingWrapped.setCommentEmitter(commentEmitterForWrappedMethod); - emitterBeingWrapped.emit(writer); - emitterBeingWrapped.setCommentEmitter(origComment); - writer.println(); - } - - protected void emitPreCallSetup(MethodBinding binding, PrintWriter writer) { - super.emitPreCallSetup(binding, writer); - - MethodBinding wrappedBinding = emitterBeingWrapped.getBinding(); - String procAddressVariable = - GLEmitter.PROCADDRESS_VAR_PREFIX + wrappedBinding.getName(); - - writer.println(" final long __addr_ = " + getProcAddressTableExpr + "." + procAddressVariable + ";"); - writer.println(" if (__addr_ == 0) {"); - writer.println(" throw new GLException(\"Method \\\"" + binding.getName() + "\\\" not available\");"); - writer.println(" }"); - } - - protected int emitCallArguments(MethodBinding binding, PrintWriter writer) { - int numEmitted = super.emitCallArguments(binding, writer); - if (numEmitted > 0) { - writer.print(", "); - } - writer.print("__addr_"); - return 1 + numEmitted; - } - - /** This class emits the comment for the wrapper method */ - private static class WrappedMethodCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter { - protected void emitBeginning(FunctionEmitter methodEmitter, PrintWriter writer) { - writer.print("Encapsulates function pointer for OpenGL function <br>: "); - } - } -} // end class JavaGLPAWrapperEmitter diff --git a/src/net/java/games/jogl/Animator.java b/src/net/java/games/jogl/Animator.java deleted file mode 100644 index ebb6d9aed..000000000 --- a/src/net/java/games/jogl/Animator.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl; - -import java.awt.EventQueue; -import net.java.games.jogl.impl.SingleThreadedWorkaround; - -/** <P> An Animator can be attached to a GLDrawable to drive its - display() method in a loop. For efficiency, it sets up the - rendering thread for the drawable to be its own internal thread, - so it can not be combined with manual repaints of the - surface. </P> - - <P> The Animator currently contains a workaround for a bug in - NVidia's drivers (80174). The current semantics are that once an - Animator is created with a given GLDrawable as a target, repaints - will likely be suspended for that GLDrawable until the Animator is - started. This prevents multithreaded access to the context (which - can be problematic) when the application's intent is for - single-threaded access within the Animator. It is not guaranteed - that repaints will be prevented during this time and applications - should not rely on this behavior for correctness. </P> -*/ - -public class Animator { - private GLDrawable drawable; - private Runnable runnable; - private Thread thread; - private boolean shouldStop; - - /** Creates a new Animator for a particular drawable. */ - public Animator(GLDrawable drawable) { - this.drawable = drawable; - - // Workaround for NVidia driver bug 80174 - if (drawable instanceof GLCanvas) { - ((GLCanvas) drawable).willSetRenderingThread(); - } - } - - /** Starts this animator. */ - public synchronized void start() { - if (thread != null) { - throw new GLException("Already started"); - } - if (runnable == null) { - runnable = new Runnable() { - public void run() { - boolean noException = false; - try { - // Try to get OpenGL context optimization since we know we - // will be rendering this one drawable continually from - // this thread; make the context current once instead of - // making it current and freeing it each frame. - drawable.setRenderingThread(Thread.currentThread()); - - // Since setRenderingThread is currently advisory (because - // of the poor JAWT implementation in the Motif AWT, which - // performs excessive locking) we also prevent repaint(), - // which is called from the AWT thread, from having an - // effect for better multithreading behavior. This call is - // not strictly necessary, but if end users write their - // own animation loops which update multiple drawables per - // tick then it may be necessary to enforce the order of - // updates. - drawable.setNoAutoRedrawMode(true); - - while (!shouldStop) { - noException = false; - drawable.display(); - noException = true; - } - } finally { - shouldStop = false; - drawable.setNoAutoRedrawMode(false); - try { - // The surface is already unlocked and rendering - // thread is already null if an exception occurred - // during display(), so don't disable the rendering - // thread again. - if (noException) { - // Destruction of the underlying GLContext may have - // disabled the setRenderingThread optimization out - // from under us - if (drawable.getRenderingThread() != null) { - drawable.setRenderingThread(null); - } - } - } finally { - synchronized (Animator.this) { - thread = null; - Animator.this.notify(); - } - } - } - } - }; - } - thread = new Thread(runnable); - thread.start(); - } - - /** Stops this animator, blocking until the animation thread has - finished. */ - public synchronized void stop() { - shouldStop = true; - // It's hard to tell whether the thread which calls stop() has - // dependencies on the Animator's internal thread. Currently we - // use a couple of heuristics to determine whether we should do - // the blocking wait(). - if ((Thread.currentThread() == thread) || EventQueue.isDispatchThread()) { - return; - } - while (shouldStop && thread != null) { - try { - wait(); - } catch (InterruptedException ie) { - } - } - } -} diff --git a/src/net/java/games/jogl/GLDrawable.java b/src/net/java/games/jogl/GLDrawable.java deleted file mode 100644 index 9ca86ca79..000000000 --- a/src/net/java/games/jogl/GLDrawable.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl; - -import java.awt.Dimension; - -// FIXME: We need some way to tell when the device upon which the canvas is -// being displayed has changed (e.g., the user drags the canvas's parent -// window from one screen on multi-screen environment to another, when the -// user changes the display bit depth or screen resolution, etc). When this -// occurs, we need the canvas to reset the gl function pointer tables for the -// canvas, because the new device may have different capabilities (e.g., -// doesn't support as many opengl extensions) from the original device. This -// hook would also be useful in other GLDrawables (for example, offscreen -// buffers such as pbuffers, whose contents may or may not be invalidated when -// the display mode changes, depending on the vendor's GL implementation). -// -// Right now I'm not sure how hook into when this change occurs. There isn't -// any AWT event corresponding to a device change (as far as I can -// tell). We could constantly check the GraphicsConfiguration of the canvas's top-level -// parent to see if it has changed, but this would be very slow (we'd have to -// do it every time the context is made current). There has got to be a better -// solution, but I'm not sure what it is. - -// FIXME: Subclasses need to call resetGLFunctionAvailability() on their -// context whenever the displayChanged() function is called on our -// GLEventListeners - -/** Abstracts common functionality among the OpenGL components {@link - GLCanvas} and {@link GLJPanel}. */ - -public interface GLDrawable extends ComponentEvents { - /** Adds a {@link GLEventListener} to this drawable. If multiple - listeners are added to a given drawable, they are notified of - events in an arbitrary order. */ - public void addGLEventListener(GLEventListener listener); - - /** Removes a {@link GLEventListener} from this drawable. Note that - if this is done from within a particular drawable's {@link - GLEventListener} handler (reshape, display, etc.) that it is not - guaranteed that all other listeners will be evaluated properly - during this update cycle. */ - public void removeGLEventListener(GLEventListener listener); - - /** Sets the size of this GLDrawable. */ - public void setSize(int width, int height); - - /** Sets the size of this GLDrawable. */ - public void setSize(Dimension d); - - /** Returns the size of this GLDrawable as a newly-created Dimension - object. */ - public Dimension getSize(); - - /** Stores the size of this GLDrawable into the user-provided - Dimension object, returning that object. If the provided - Dimension is null a new one will be allocated and returned. */ - public Dimension getSize(Dimension d); - - /** Returns the {@link GL} pipeline object this GLDrawable uses. If - this method is called outside of the {@link GLEventListener}'s - callback methods (init, display, etc.) it may return null. Users - should not rely on the identity of the returned GL object; for - example, users should not maintain a hash table with the GL - object as the key. Additionally, the GL object should not be - cached in client code, but should be re-fetched from the - GLDrawable at the beginning of each call to init, display, - etc. */ - public GL getGL(); - - /** Sets the {@link GL} pipeline object this GLDrawable uses. This - should only be called from within the GLEventListener's callback - methods, and usually only from within the init() method, in - order to install a composable pipeline. See the JOGL demos for - examples. */ - public void setGL(GL gl); - - /** Returns the {@link GLU} pipeline object this GLDrawable uses. */ - public GLU getGLU(); - - /** Sets the {@link GLU} pipeline object this GLDrawable uses. */ - public void setGLU(GLU glu); - - /** Causes OpenGL rendering to be performed for this GLDrawable by - calling {@link GLEventListener#display} for all registered - {@link GLEventListener}s. Called automatically by the window - system toolkit upon receiving a repaint() request. When used in - conjunction with {@link - net.java.games.jogl.GLDrawable#setRenderingThread}, this routine - may be called manually by the application's main loop for higher - performance and better control over the rendering process. It is - legal to call another GLDrawable's display method from within - {@link GLEventListener#display}. */ - public void display(); - - /** <P> Changes this GLDrawable to allow OpenGL rendering only from - the supplied thread, which must either be the current thread or - null. Attempts by other threads to perform OpenGL operations - like rendering or resizing the window will be ignored as long as - the thread is set. Setting up the rendering thread is not - required but enables the system to perform additional - optimizations, in particular when the application requires - control over the rendering loop. Before exiting, - <code>setRenderingThread(null)</code> must be called or other - threads will be unable to perform OpenGL rendering to this - drawable. Throws {@link GLException} if the rendering thread for - this drawable has been set and attempts are made to set or clear - the rendering thread from another thread, or if the passed - thread is not equal to the current thread or null. Also throws - {@link GLException} if the current thread attempts to call - <code>setRenderingThread</code> on more than one drawable. </P> - - <P> <B>NOTE:</B> Currently this routine is only advisory, which - means that on some platforms the underlying optimizations are - disabled and setting the rendering thread has no effect. - Applications should not rely on setRenderingThread to prevent - rendering from other threads. <P> - - @throws GLException if the rendering thread for this drawable has - been set by another thread or if the passed thread is not equal - to the current thread or null - */ - public void setRenderingThread(Thread currentThreadOrNull) throws GLException; - - /** Returns the rendering thread for this drawable, or null if none - has been set. */ - public Thread getRenderingThread(); - - /** Disables automatic redraws of this drawable if possible. This is - provided as an overriding mechanism for applications which - perform animation on the drawable and for which the (currently - advisory) {@link #setRenderingThread} does not provide strict - enough guarantees. Its sole purpose is to avoid deadlocks that - are unfortunately all too easy to run into when both animating a - drawable from a given thread as well as having updates performed - by the AWT event thread (repaints, etc.). When it is enabled, - repaint requests driven by the AWT will not result in the OpenGL - event listeners' display methods being called from the AWT - thread, unless (as with GLJPanel) this is the only mechanism by - which repaints are done. The necessity of this API may be - rethought in a future release. Defaults to false. */ - public void setNoAutoRedrawMode(boolean noAutoRedraws); - - /** Returns whether automatic redraws are disabled for this - drawable. Defaults to false. */ - public boolean getNoAutoRedrawMode(); - - /** Enables or disables automatic buffer swapping for this drawable. - By default this property is set to true; when true, after all - GLEventListeners have been called for a display() event, the - front and back buffers are swapped, displaying the results of - the render. When disabled, the user is responsible for calling - {@link #swapBuffers} manually. */ - public void setAutoSwapBufferMode(boolean onOrOff); - - /** Indicates whether automatic buffer swapping is enabled for this - drawable. See {@link #setAutoSwapBufferMode}. */ - public boolean getAutoSwapBufferMode(); - - /** Swaps the front and back buffers of this drawable. When - automatic buffer swapping is enabled (as is the default), it is - not necessary to call this method and doing so may have - undefined results. */ - public void swapBuffers(); - - /** Indicates whether this drawable is capable of fabricating a - subordinate offscreen drawable for advanced rendering techniques - which require offscreen hardware-accelerated surfaces. Note that - this method is only guaranteed to return a correct result once - your GLEventListener's init() method has been called. */ - public boolean canCreateOffscreenDrawable(); - - /** Creates a subordinate offscreen drawable (pbuffer) for this - drawable. This routine should only be called if {@link - #canCreateOffscreenDrawable} returns true. The passed - capabilities are matched according to the platform-dependent - pbuffer format selection algorithm, which currently can not be - overridden. */ - public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight); -} diff --git a/src/net/java/games/jogl/GLDrawableFactory.java b/src/net/java/games/jogl/GLDrawableFactory.java deleted file mode 100644 index 8204fde7d..000000000 --- a/src/net/java/games/jogl/GLDrawableFactory.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl; - -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import net.java.games.jogl.impl.*; - -/** <P> Provides a virtual machine- and operating system-independent - mechanism for creating {@link net.java.games.jogl.GLCanvas} and {@link - net.java.games.jogl.GLJPanel} objects. </P> - - <P> The {@link net.java.games.jogl.GLCapabilities} objects passed in to the - various factory methods are used as a hint for the properties of - the returned drawable. The default capabilities selection - algorithm (equivalent to passing in a null {@link - GLCapabilitiesChooser}) is described in {@link - DefaultGLCapabilitiesChooser}. Sophisticated applications needing - to change the selection algorithm may pass in their own {@link - GLCapabilitiesChooser} which can select from the available pixel - formats. </P> - - <P> Because of the multithreaded nature of the Java platform's - window system toolkit, it is typically not possible to immediately - reject a given {@link GLCapabilities} as being unsupportable by - either returning <code>null</code> from the creation routines or - raising a {@link GLException}. The semantics of the rejection - process are (unfortunately) left unspecified for now. The current - implementation will cause a {@link GLException} to be raised - during the first repaint of the {@link GLCanvas} or {@link - GLJPanel} if the capabilities can not be met. </P> -*/ - -public class GLDrawableFactory { - private static GLDrawableFactory factory = new GLDrawableFactory(); - - private GLDrawableFactory() {} - - /** Returns the sole GLDrawableFactory instance. */ - public static GLDrawableFactory getFactory() { - return factory; - } - - /** Creates a {@link GLCanvas} on the default graphics device with - the specified capabilities using the default capabilities - selection algorithm. */ - public GLCanvas createGLCanvas(GLCapabilities capabilities) { - return createGLCanvas(capabilities, null, null); - } - - /** Creates a {@link GLCanvas} on the default graphics device with - the specified capabilities using the default capabilities - selection algorithm. The canvas will share textures and display - lists with the specified {@link GLDrawable}; the drawable must - either be null or have been fabricated from this factory or by - classes in this package. A null drawable indicates no - sharing. */ - public GLCanvas createGLCanvas(GLCapabilities capabilities, GLDrawable shareWith) { - return createGLCanvas(capabilities, null, shareWith); - } - - /** Creates a {@link GLCanvas} on the default graphics device with - the specified capabilities using the supplied capabilities - selection algorithm. A null chooser is equivalent to using the - {@link DefaultGLCapabilitiesChooser}. */ - public GLCanvas createGLCanvas(GLCapabilities capabilities, GLCapabilitiesChooser chooser) { - return createGLCanvas(capabilities, chooser, null); - } - - /** Creates a {@link GLCanvas} on the default graphics device with - the specified capabilities using the supplied capabilities - selection algorithm. A null chooser is equivalent to using the - {@link DefaultGLCapabilitiesChooser}. The canvas will share - textures and display lists with the specified {@link - GLDrawable}; the drawable must either be null or have been - fabricated from this factory or by classes in this package. A - null drawable indicates no sharing. */ - public GLCanvas createGLCanvas(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLDrawable shareWith) { - return createGLCanvas(capabilities, chooser, shareWith, null); - } - - /** Creates a {@link GLCanvas} on the specified graphics device with - the specified capabilities using the supplied capabilities - selection algorithm. A null chooser is equivalent to using the - {@link DefaultGLCapabilitiesChooser}. The canvas will share - textures and display lists with the specified {@link - GLDrawable}; the drawable must either be null or have been - fabricated from this factory or by classes in this package. A - null drawable indicates no sharing. A null GraphicsDevice is - equivalent to using that returned from - <code>GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()</code>. */ - public GLCanvas createGLCanvas(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLDrawable shareWith, - GraphicsDevice device) { - if (chooser == null) { - chooser = new DefaultGLCapabilitiesChooser(); - } - if (device == null) { - device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); - } - // The platform-specific GLContextFactory will only provide a - // non-null GraphicsConfiguration on platforms where this is - // necessary (currently only X11, as Windows allows the pixel - // format of the window to be set later and Mac OS X seems to - // handle this very differently than all other platforms). On - // other platforms this method returns null; it is the case (at - // least in the Sun AWT implementation) that this will result in - // equivalent behavior to calling the no-arg super() constructor - // for Canvas. - return new GLCanvas(GLContextFactory.getFactory(). - chooseGraphicsConfiguration(capabilities, chooser, device), - capabilities, - chooser, - shareWith); - } - - /** Creates a {@link GLJPanel} with the specified capabilities using - the default capabilities selection algorithm. */ - public GLJPanel createGLJPanel(GLCapabilities capabilities) { - return createGLJPanel(capabilities, null, null); - } - - /** Creates a {@link GLJPanel} with the specified capabilities using - the default capabilities selection algorithm. The panel will - share textures and display lists with the specified {@link - GLDrawable}; the drawable must either be null or have been - fabricated from this factory or by classes in this package. A - null drawable indicates no sharing. */ - public GLJPanel createGLJPanel(GLCapabilities capabilities, GLDrawable shareWith) { - return createGLJPanel(capabilities, null, shareWith); - } - - /** Creates a {@link GLJPanel} with the specified capabilities using - the supplied capabilities selection algorithm. A null chooser is - equivalent to using the {@link DefaultGLCapabilitiesChooser}. */ - public GLJPanel createGLJPanel(GLCapabilities capabilities, GLCapabilitiesChooser chooser) { - return createGLJPanel(capabilities, chooser, null); - } - - /** Creates a {@link GLJPanel} with the specified capabilities using - the supplied capabilities selection algorithm. A null chooser is - equivalent to using the {@link DefaultGLCapabilitiesChooser}. - The panel will share textures and display lists with the - specified {@link GLDrawable}; the drawable must either be null - or have been fabricated from this factory or by classes in this - package. A null drawable indicates no sharing. */ - public GLJPanel createGLJPanel(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLDrawable shareWith) { - if (chooser == null) { - chooser = new DefaultGLCapabilitiesChooser(); - } - return new GLJPanel(capabilities, chooser, shareWith); - } -} diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java deleted file mode 100644 index e9b58bdae..000000000 --- a/src/net/java/games/jogl/GLJPanel.java +++ /dev/null @@ -1,730 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl; - -import java.awt.Component; -import java.awt.EventQueue; -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; -import java.awt.Rectangle; -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferByte; -import java.awt.image.DataBufferInt; -import java.security.*; -import javax.swing.JComponent; -import javax.swing.JPanel; -import net.java.games.jogl.impl.*; - -// FIXME: Subclasses need to call resetGLFunctionAvailability() on their -// context whenever the displayChanged() function is called on their -// GLEventListeners - -/** A lightweight Swing component which provides OpenGL rendering - support. Provided for compatibility with Swing user interfaces - when adding a heavyweight doesn't work either because of - Z-ordering or LayoutManager problems. This component attempts to - use hardware-accelerated rendering via pbuffers and falls back on - to software rendering if problems occur. This class can not be - instantiated directly; use {@link GLDrawableFactory} to construct - them. <P> - - Note that because this component attempts to use pbuffers for - rendering, and because pbuffers can not be resized, somewhat - surprising behavior may occur during resize operations; the {@link - GLEventListener#init} method may be called multiple times as the - pbuffer is resized to be able to cover the size of the GLJPanel. - This behavior is correct, as the textures and display lists for - the GLJPanel will have been lost during the resize operation. The - application should attempt to make its GLEventListener.init() - methods as side-effect-free as possible. -*/ - -public final class GLJPanel extends JPanel implements GLDrawable { - protected static final boolean DEBUG = Debug.debug("GLJPanel"); - - private GLDrawableHelper drawableHelper = new GLDrawableHelper(); - private volatile boolean isInitialized; - - // Data used for either pbuffers or pixmap-based offscreen surfaces - private GLCapabilities offscreenCaps; - private GLCapabilitiesChooser chooser; - private GLDrawable shareWith; - // This image is exactly the correct size to render into the panel - private BufferedImage offscreenImage; - // One of these is used to store the read back pixels before storing - // in the BufferedImage - private byte[] readBackBytes; - private int[] readBackInts; - private int readBackWidthInPixels; - private int readBackHeightInPixels; - // Width of the actual GLJPanel - private int panelWidth = 0; - private int panelHeight = 0; - private Updater updater; - private int awtFormat; - private int glFormat; - private int glType; - - // Implementation using pbuffers - private static boolean hardwareAccelerationDisabled = - Debug.isPropertyDefined("jogl.gljpanel.nohw"); - private boolean pbufferInitializationCompleted; - private GLPbuffer pbuffer; - private int pbufferWidth = 256; - private int pbufferHeight = 256; - private GLCanvas heavyweight; - private Frame toplevel; - - // Implementation using software rendering - private GLContext offscreenContext; - - // For saving/restoring of OpenGL state during ReadPixels - private int[] swapbytes = new int[1]; - private int[] rowlength = new int[1]; - private int[] skiprows = new int[1]; - private int[] skippixels = new int[1]; - private int[] alignment = new int[1]; - - GLJPanel(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLDrawable shareWith) { - super(); - - // Works around problems on many vendors' cards; we don't need a - // back buffer for the offscreen surface anyway - offscreenCaps = (GLCapabilities) capabilities.clone(); - offscreenCaps.setDoubleBuffered(false); - this.chooser = chooser; - this.shareWith = shareWith; - } - - public void display() { - if (!isInitialized) { - return; - } - - if (EventQueue.isDispatchThread()) { - // Want display() to be synchronous, so call paintImmediately() - paintImmediately(0, 0, getWidth(), getHeight()); - } else { - // Multithreaded redrawing of Swing components is not allowed, - // so do everything on the event dispatch thread - try { - EventQueue.invokeAndWait(paintImmediatelyAction); - } catch (Exception e) { - throw new GLException(e); - } - } - } - - /** Overridden from JComponent; calls {@link - GLEventListener#display}. Should not be invoked by applications - directly. */ - public void paintComponent(Graphics g) { - if (!isInitialized) { - return; - } - - updater.setGraphics(g); - if (!hardwareAccelerationDisabled) { - if (!pbufferInitializationCompleted) { - try { - heavyweight.display(); - pbuffer.display(); - } catch (GLException e) { - if (DEBUG) { - e.printStackTrace(); - } - // We consider any exception thrown during updating of the - // heavyweight or pbuffer during the initialization phases - // to be an indication that there was a problem - // instantiating the pbuffer, regardless of whether the - // exception originated in the user's GLEventListener. In - // these cases we immediately back off and use software - // rendering. - disableHardwareRendering(); - } - } else { - pbuffer.display(); - } - } else { - offscreenContext.invokeGL(displayAction, false, initAction); - } - } - - public void addNotify() { - super.addNotify(); - initialize(); - if (DEBUG) { - System.err.println("GLJPanel.addNotify()"); - } - } - - /** Overridden from JPanel; used to indicate that it's no longer - safe to have an OpenGL context for the component. */ - public void removeNotify() { - if (DEBUG) { - System.err.println("GLJPanel.removeNotify()"); - } - if (!hardwareAccelerationDisabled) { - if (pbuffer != null) { - pbuffer.destroy(); - } - if (toplevel != null) { - toplevel.dispose(); - } - pbuffer = null; - heavyweight = null; - toplevel = null; - } else { - offscreenContext.destroy(); - } - isInitialized = false; - super.removeNotify(); - } - - /** Overridden from Canvas; causes {@link GLDrawableHelper#reshape} - to be called on all registered {@link GLEventListener}s. Called - automatically by the AWT; should not be invoked by applications - directly. */ - public void reshape(int x, int y, int width, int height) { - super.reshape(x, y, width, height); - - if (!isInitialized) { - return; - } - - // Move all reshape requests onto AWT EventQueue thread - final int fx = x; - final int fy = y; - final int fwidth = width; - final int fheight = height; - - Runnable r = new Runnable() { - public void run() { - GLContext context = null; - readBackWidthInPixels = 0; - readBackHeightInPixels = 0; - - if (!hardwareAccelerationDisabled) { - // Use factor larger than 2 during shrinks for some hysteresis - float shrinkFactor = 2.5f; - if ((fwidth > pbufferWidth ) || (fheight > pbufferHeight) || - (fwidth < (pbufferWidth / shrinkFactor)) || (fheight < (pbufferWidth / shrinkFactor))) { - if (DEBUG) { - System.err.println("Resizing pbuffer from (" + pbufferWidth + ", " + pbufferHeight + ") " + - " to fit (" + fwidth + ", " + fheight + ")"); - } - // Must destroy and recreate pbuffer to fit - if (pbuffer != null) { - pbuffer.destroy(); - } - if (toplevel != null) { - toplevel.dispose(); - } - pbuffer = null; - isInitialized = false; - pbufferWidth = getNextPowerOf2(fwidth); - pbufferHeight = getNextPowerOf2(fheight); - if (DEBUG) { - System.err.println("New pbuffer size is (" + pbufferWidth + ", " + pbufferHeight + ")"); - } - initialize(); - } - GLPbufferImpl pbufferImpl = (GLPbufferImpl) pbuffer; - context = pbufferImpl.getContext(); - // It looks like NVidia's drivers (at least the ones on my - // notebook) are buggy and don't allow a rectangle of less than - // the pbuffer's width to be read...this doesn't really matter - // because it's the Graphics.drawImage() calls that are the - // bottleneck. Should probably make the size of the offscreen - // image be the exact size of the pbuffer to save some work on - // resize operations... - readBackWidthInPixels = pbufferWidth; - readBackHeightInPixels = fheight; - } else { - offscreenContext.resizeOffscreenContext(fwidth, fheight); - context = offscreenContext; - readBackWidthInPixels = fwidth; - readBackHeightInPixels = fheight; - } - - if (offscreenImage != null) { - offscreenImage.flush(); - offscreenImage = null; - } - - panelWidth = fwidth; - panelHeight = fheight; - - context.invokeGL(new Runnable() { - public void run() { - getGL().glViewport(0, 0, panelWidth, panelHeight); - drawableHelper.reshape(GLJPanel.this, 0, 0, panelWidth, panelHeight); - } - }, true, initAction); - } - }; - if (EventQueue.isDispatchThread()) { - r.run(); - } else { - // Avoid blocking EventQueue thread due to possible deadlocks - // during component creation - EventQueue.invokeLater(r); - } - } - - public void setOpaque(boolean opaque) { - if (opaque != isOpaque()) { - if (offscreenImage != null) { - offscreenImage.flush(); - offscreenImage = null; - } - } - super.setOpaque(opaque); - } - - public void addGLEventListener(GLEventListener listener) { - drawableHelper.addGLEventListener(listener); - } - - public void removeGLEventListener(GLEventListener listener) { - drawableHelper.removeGLEventListener(listener); - } - - public GL getGL() { - if (!hardwareAccelerationDisabled) { - if (pbuffer == null) { - return null; - } - return pbuffer.getGL(); - } else { - if (offscreenContext == null) { - return null; - } - return offscreenContext.getGL(); - } - } - - public void setGL(GL gl) { - if (!hardwareAccelerationDisabled) { - if (pbuffer != null) { - pbuffer.setGL(gl); - } - } else { - if (offscreenContext != null) { - offscreenContext.setGL(gl); - } - } - } - - public GLU getGLU() { - if (!hardwareAccelerationDisabled) { - return pbuffer.getGLU(); - } else { - return offscreenContext.getGLU(); - } - } - - public void setGLU(GLU glu) { - if (!hardwareAccelerationDisabled) { - pbuffer.setGLU(glu); - } else { - offscreenContext.setGLU(glu); - } - } - - public void setRenderingThread(Thread currentThreadOrNull) throws GLException { - // Not supported for GLJPanel because all repaint requests must be - // handled by the AWT thread - } - - public Thread getRenderingThread() { - return null; - } - - public void setNoAutoRedrawMode(boolean noAutoRedraws) { - } - - public boolean getNoAutoRedrawMode() { - return false; - } - - public void setAutoSwapBufferMode(boolean onOrOff) { - if (!hardwareAccelerationDisabled) { - pbuffer.setAutoSwapBufferMode(onOrOff); - } else { - offscreenContext.setAutoSwapBufferMode(onOrOff); - } - } - - public boolean getAutoSwapBufferMode() { - if (!hardwareAccelerationDisabled) { - return pbuffer.getAutoSwapBufferMode(); - } else { - return offscreenContext.getAutoSwapBufferMode(); - } - } - - public void swapBuffers() { - if (!hardwareAccelerationDisabled) { - pbuffer.swapBuffers(); - } else { - offscreenContext.invokeGL(swapBuffersAction, false, initAction); - } - } - - public boolean canCreateOffscreenDrawable() { - // For now let's say no, although we could using the heavyweight - // if hardware acceleration is still enabled - return false; - } - - public GLPbuffer createOffscreenDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - GLContext getContext() { - if (!hardwareAccelerationDisabled) { - return ((GLPbufferImpl) pbuffer).getContext(); - } else { - return offscreenContext; - } - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private void disableHardwareRendering() { - if (Debug.verbose()) { - System.err.println("GLJPanel: Falling back on software rendering due to pbuffer problems"); - } - hardwareAccelerationDisabled = true; - pbufferInitializationCompleted = false; - EventQueue.invokeLater(new Runnable() { - public void run() { - toplevel.setVisible(false); - // Should dispose of this -- not sure about stability on - // various cards -- should test (FIXME) - // toplevel.dispose(); - } - }); - initialize(); - } - - private void initialize() { - // Initialize either the hardware-accelerated rendering path or - // the lightweight rendering path - if (!hardwareAccelerationDisabled) { - boolean firstTime = false; - if (heavyweight == null) { - // Make the heavyweight share with the "shareWith" parameter. - // The pbuffer shares textures and display lists with the - // heavyweight, so by transitivity the pbuffer will share with - // it as well. - heavyweight = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities(), shareWith); - firstTime = true; - } - if (heavyweight.canCreateOffscreenDrawable()) { - if (firstTime) { - toplevel = new Frame(); - toplevel.setUndecorated(true); - } - pbuffer = heavyweight.createOffscreenDrawable(offscreenCaps, pbufferWidth, pbufferHeight); - updater = new Updater(); - pbuffer.addGLEventListener(updater); - pbufferInitializationCompleted = false; - if (firstTime) { - toplevel.add(heavyweight); - toplevel.setSize(1, 1); - } - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - toplevel.setVisible(true); - } catch (GLException e) { - if (DEBUG) { - e.printStackTrace(); - } - disableHardwareRendering(); - } - } - }); - isInitialized = true; - return; - } else { - // If the heavyweight reports that it can't create an - // offscreen drawable (pbuffer), don't try again the next - // time, and fall through to the software rendering path - hardwareAccelerationDisabled = true; - } - } - - // Create an offscreen context instead - offscreenContext = GLContextFactory.getFactory().createGLContext(null, offscreenCaps, chooser, - GLContextHelper.getContext(shareWith)); - offscreenContext.resizeOffscreenContext(panelWidth, panelHeight); - updater = new Updater(); - if (panelWidth > 0 && panelHeight > 0) { - offscreenContext.invokeGL(new Runnable() { - public void run() { - getGL().glViewport(0, 0, panelWidth, panelHeight); - drawableHelper.reshape(GLJPanel.this, 0, 0, panelWidth, panelHeight); - } - }, true, initAction); - } - - isInitialized = true; - } - - class Updater implements GLEventListener { - private Graphics g; - - public void setGraphics(Graphics g) { - this.g = g; - } - - public void init(GLDrawable drawable) { - if (!hardwareAccelerationDisabled) { - if (DEBUG) { - System.err.println("GLJPanel$Updater.init(): pbufferInitializationCompleted = true"); - } - pbufferInitializationCompleted = true; - EventQueue.invokeLater(new Runnable() { - public void run() { - // Race conditions might dispose of this before now - if (toplevel != null) { - toplevel.setVisible(false); - } - } - }); - } - drawableHelper.init(GLJPanel.this); - } - - public void display(GLDrawable drawable) { - drawableHelper.display(GLJPanel.this); - - // Must now copy pixels from offscreen context into surface - if (offscreenImage == null) { - if (panelWidth > 0 && panelHeight > 0) { - // It looks like NVidia's drivers (at least the ones on my - // notebook) are buggy and don't allow a sub-rectangle to be - // read from a pbuffer...this doesn't really matter because - // it's the Graphics.drawImage() calls that are the - // bottleneck - - int awtFormat = 0; - int hwGLFormat = 0; - if (!hardwareAccelerationDisabled) { - // This seems to be a good choice on all platforms - hwGLFormat = GL.GL_UNSIGNED_INT_8_8_8_8_REV; - } - - // Should be more flexible in these BufferedImage formats; - // perhaps see what the preferred image types are on the - // given platform - if (isOpaque()) { - awtFormat = BufferedImage.TYPE_INT_RGB; - } else { - awtFormat = BufferedImage.TYPE_INT_ARGB; - } - - offscreenImage = new BufferedImage(panelWidth, - panelHeight, - awtFormat); - switch (awtFormat) { - case BufferedImage.TYPE_3BYTE_BGR: - glFormat = GL.GL_BGR; - glType = GL.GL_UNSIGNED_BYTE; - readBackBytes = new byte[readBackWidthInPixels * readBackHeightInPixels * 3]; - break; - - case BufferedImage.TYPE_INT_RGB: - case BufferedImage.TYPE_INT_ARGB: - glFormat = GL.GL_BGRA; - glType = (hardwareAccelerationDisabled - ? offscreenContext.getOffscreenContextPixelDataType() - : hwGLFormat); - readBackInts = new int[readBackWidthInPixels * readBackHeightInPixels]; - break; - - default: - // FIXME: Support more off-screen image types (current - // offscreen context implementations don't use others, and - // some of the OpenGL formats aren't supported in the 1.1 - // headers, which we're currently using) - throw new GLException("Unsupported offscreen image type " + awtFormat); - } - } - } - - if (offscreenImage != null) { - GL gl = getGL(); - // Save current modes - gl.glGetIntegerv(GL.GL_PACK_SWAP_BYTES, swapbytes); - gl.glGetIntegerv(GL.GL_PACK_ROW_LENGTH, rowlength); - gl.glGetIntegerv(GL.GL_PACK_SKIP_ROWS, skiprows); - gl.glGetIntegerv(GL.GL_PACK_SKIP_PIXELS, skippixels); - gl.glGetIntegerv(GL.GL_PACK_ALIGNMENT, alignment); - - gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, GL.GL_FALSE); - gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, readBackWidthInPixels); - gl.glPixelStorei(GL.GL_PACK_SKIP_ROWS, 0); - gl.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, 0); - gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); - - // Actually read the pixels. - gl.glReadBuffer(GL.GL_FRONT); - if (readBackBytes != null) { - gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackBytes); - } else if (readBackInts != null) { - gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackInts); - } - - // Restore saved modes. - gl.glPixelStorei(GL.GL_PACK_SWAP_BYTES, swapbytes[0]); - gl.glPixelStorei(GL.GL_PACK_ROW_LENGTH, rowlength[0]); - gl.glPixelStorei(GL.GL_PACK_SKIP_ROWS, skiprows[0]); - gl.glPixelStorei(GL.GL_PACK_SKIP_PIXELS, skippixels[0]); - gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, alignment[0]); - - if (readBackBytes != null || readBackInts != null) { - // Copy temporary data into raster of BufferedImage for faster - // blitting Note that we could avoid this copy in the cases - // where !offscreenContext.offscreenImageNeedsVerticalFlip(), - // but that's the software rendering path which is very slow - // anyway - Object src = null; - Object dest = null; - int srcIncr = 0; - int destIncr = 0; - - if (readBackBytes != null) { - src = readBackBytes; - dest = ((DataBufferByte) offscreenImage.getRaster().getDataBuffer()).getData(); - srcIncr = readBackWidthInPixels * 3; - destIncr = offscreenImage.getWidth() * 3; - } else { - src = readBackInts; - dest = ((DataBufferInt) offscreenImage.getRaster().getDataBuffer()).getData(); - srcIncr = readBackWidthInPixels; - destIncr = offscreenImage.getWidth(); - } - - if (!hardwareAccelerationDisabled || - offscreenContext.offscreenImageNeedsVerticalFlip()) { - int srcPos = 0; - int destPos = (offscreenImage.getHeight() - 1) * destIncr; - for (; destPos >= 0; srcPos += srcIncr, destPos -= destIncr) { - System.arraycopy(src, srcPos, dest, destPos, destIncr); - } - } else { - int srcPos = 0; - int destEnd = destIncr * offscreenImage.getHeight(); - for (int destPos = 0; destPos < destEnd; srcPos += srcIncr, destPos += destIncr) { - System.arraycopy(src, srcPos, dest, destPos, destIncr); - } - } - - // Draw resulting image in one shot - g.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), GLJPanel.this); - } - } - } - - public void reshape(GLDrawable drawable, int x, int y, int width, int height) { - // This is handled above and dispatched directly to the appropriate context - } - - public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) { - } - } - - class InitAction implements Runnable { - public void run() { - updater.init(GLJPanel.this); - } - } - private InitAction initAction = new InitAction(); - - class DisplayAction implements Runnable { - public void run() { - updater.display(GLJPanel.this); - } - } - private DisplayAction displayAction = new DisplayAction(); - - // This one is used exclusively in the non-hardware-accelerated case - class SwapBuffersAction implements Runnable { - public void run() { - offscreenContext.swapBuffers(); - } - } - private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); - - class PaintImmediatelyAction implements Runnable { - public void run() { - paintImmediately(0, 0, getWidth(), getHeight()); - } - } - private PaintImmediatelyAction paintImmediatelyAction = new PaintImmediatelyAction(); - - private int getNextPowerOf2(int number) { - // Workaround for problems where 0 width or height are transiently - // seen during layout - if (number == 0) { - return 2; - } - - if (((number-1) & number) == 0) { - //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 - return number; - } - int power = 0; - while (number > 0) { - number = number>>1; - power++; - } - return (1<<power); - } -} diff --git a/src/net/java/games/jogl/impl/GLContext.java b/src/net/java/games/jogl/impl/GLContext.java deleted file mode 100644 index 41fa98c4b..000000000 --- a/src/net/java/games/jogl/impl/GLContext.java +++ /dev/null @@ -1,764 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl; - -import java.awt.Component; -import net.java.games.jogl.*; -import net.java.games.gluegen.runtime.*; - -public abstract class GLContext { - protected static final boolean DEBUG = Debug.debug("GLContext"); - protected static final boolean VERBOSE = Debug.verbose(); - protected static final boolean NO_FREE = Debug.isPropertyDefined("jogl.GLContext.nofree"); - - static { - NativeLibLoader.load(); - } - - protected Component component; - - // Indicates whether the component (if an onscreen context) has been - // realized. Plausibly, before the component is realized the JAWT - // should return an error or NULL object from some of its - // operations; this appears to be the case on Win32 but is not true - // at least with Sun's current X11 implementation (1.4.x), which - // crashes with no other error reported if the DrawingSurfaceInfo is - // fetched from a locked DrawingSurface during the validation as a - // result of calling show() on the main thread. To work around this - // we prevent any JAWT or OpenGL operations from being done until - // addNotify() is called on the component. - protected boolean realized; - - protected GLCapabilities capabilities; - protected GLCapabilitiesChooser chooser; - protected GL gl; - protected static final GLUProcAddressTable gluProcAddressTable = new GLUProcAddressTable(); - protected static boolean haveResetGLUProcAddressTable; - protected GLU glu = new GLUImpl(gluProcAddressTable); - protected Thread renderingThread; - protected Runnable deferredReshapeAction; - // Support for OpenGL context destruction and recreation in the face - // of the setRenderingThread optimization, which makes the context - // permanently current on the animation thread. FIXME: should make - // this more uniform and general, possibly by implementing in terms - // of Runnables; however, necessary sequence of operations in - // invokeGL makes this tricky. - protected boolean deferredDestroy; - protected boolean deferredSetRealized; - - // Error checking for setRenderingThread to ensure that one thread - // doesn't attempt to call setRenderingThread on more than one - // drawable - protected static final ThreadLocal perThreadRenderingContext = new ThreadLocal(); - - // This is a workaround for a bug in NVidia's drivers where - // vertex_array_range is only safe for single-threaded use; a bug - // has been filed, ID 80174. When an Animator is created for a - // GLDrawable, the expectation is that the Animator will be started - // shortly and that the user doesn't want rendering to occur from - // the AWT thread. However, there is a small window between when the - // Animator is created and attached to the GLDrawable and when it's - // started (and sets the rendering thread) when repaint events can - // be issued by the AWT thread if the component is realized. To work - // around this problem, we currently specify in the Animator's API - // that between the time it's created and started no redraws will - // occur. - protected volatile boolean willSetRenderingThread; - - // Flag for disabling all repaint and resize processing on the AWT - // thread to avoid application-level deadlocks; only really used for - // GLCanvas - protected boolean noAutoRedraw; - - // Flag for enabling / disabling automatic swapping of the front and - // back buffers - protected boolean autoSwapBuffers = true; - - // Offscreen context handling. Offscreen contexts should handle - // these resize requests in makeCurrent and clear the - // pendingOffscreenResize flag. - protected boolean pendingOffscreenResize; - protected int pendingOffscreenWidth; - protected int pendingOffscreenHeight; - - // Cache of the functions that are available to be called at the current - // moment in time - protected FunctionAvailabilityCache functionAvailability; - - // Support for recursive makeCurrent() calls as well as calling - // other drawables' display() methods from within another one's - protected static final ThreadLocal perThreadContextStack = new ThreadLocal() { - protected synchronized Object initialValue() { - return new GLContextStack(); - } - }; - // This thread-local variable helps implement setRenderingThread()'s - // optimized context handling. When the bottommost invokeGL() on the - // execution stack finishes for the rendering thread for that - // context, we pop the context off the context stack but do not free - // it, instead storing it in this thread-local variable. This gives - // us enough information to recover the context stack state in - // subsequent invokeGL() calls. - protected static final ThreadLocal perThreadSavedCurrentContext = new ThreadLocal() { - protected synchronized Object initialValue() { - return new GLContextInitActionPair(null, null); - } - }; - - public GLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - this.component = component; - this.capabilities = (GLCapabilities) capabilities.clone(); - this.chooser = chooser; - setGL(createGL()); - functionAvailability = new FunctionAvailabilityCache(this); - if (shareWith != null) { - GLContextShareSet.registerSharing(this, shareWith); - } - } - - /** Runs the given runnable with this OpenGL context valid. */ - public synchronized void invokeGL(Runnable runnable, boolean isReshape, Runnable initAction) throws GLException { - // Could be more clever about not calling this every time, but - // Thread.currentThread() is very fast and this makes the logic simpler - Thread currentThread = Thread.currentThread(); - - // Defer JAWT and OpenGL operations until onscreen components are - // realized - if (!isRealized() || - willSetRenderingThread || - (renderingThread != null && - renderingThread != currentThread)) { - // Support for removeNotify()/addNotify() when the - // setRenderingThread optimization is in effect and before the - // animation thread gets a chance to handle either request - if (!isRealized() && deferredSetRealized) { - setRealized(); - deferredSetRealized = false; - } else { - if (isReshape) { - deferredReshapeAction = runnable; - } - return; - } - } - - if (isReshape && noAutoRedraw && !SingleThreadedWorkaround.doWorkaround()) { - // Don't process reshape requests on the AWT thread - deferredReshapeAction = runnable; - return; - } - - if (deferredDestroy) { - deferredDestroy = false; - if (renderingThread != null) { - // Need to disable the setRenderingThread optimization to free - // up the context - setRenderingThread(null, initAction); - } - destroy(); - return; - } - - // The goal of this code is to optimize OpenGL context handling as - // much as possible. In particular: - // - // - setRenderingThread() works by making the "bottommost" OpenGL - // context current once and not freeing it until the rendering - // thread has been unset. Note that subsequent pushes of other - // contexts will still necessarily cause them to be made current - // and freed. - // - // - If the same context is pushed on the per-thread context stack - // more than once back-to-back, the subsequent pushes will not - // actually cause a makeCurrent/free to occur. - // - // Complexities occur because setRenderingThread() can be called - // at any time. Currently we implement the rendering thread - // optimization by popping it off the OpenGL context stack and - // storing it in a thread-local variable. - - GLContextStack ctxStack = getPerThreadContextStack(); - GLContext savedPerThreadContext = getPerThreadSavedCurrentContext(); - Runnable savedPerThreadInitAction = getPerThreadSavedInitAction(); - setPerThreadSavedCurrentContext(null, null); - if (ctxStack.size() == 0 && - savedPerThreadContext != null) { - // The setRenderingThread optimization moved the current context - // into thread-local storage. Put it back on the context stack, - // because we might need to free it later. - ctxStack.push(savedPerThreadContext, savedPerThreadInitAction); - } - - GLContext curContext = ctxStack.peekContext(); - Runnable curInitAction = ctxStack.peekInitAction(); - boolean mustDoMakeCurrent = true; - - if (curContext == this) { - mustDoMakeCurrent = false; - } - - if (mustDoMakeCurrent) { - if (curContext != null) { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": Freeing context " + curContext + " due to recursive makeCurrent"); - } - curContext.free(); - } - - if (!makeCurrent(initAction)) { - // Couldn't make the thread current because the component has not yet - // been visualized, and therefore the context cannot be created. - // We'll defer any actions until invokeGL() is called again at a time - // when the component has been visualized. - if (isReshape) { - deferredReshapeAction = runnable; - } - - // Clean up after ourselves on the way out. - // NOTE that this is an abbreviated version of the code below - // and should probably be refactored/cleaned up -- this bug - // fix was done without a lot of intense thought about the - // situation - if (curContext != null) { - curContext.makeCurrent(curInitAction); - } - return; - } - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": Making context " + this + " current"); - } - } - ctxStack.push(this, initAction); - - // At this point the OpenGL context is current. Offscreen contexts - // handle resizing the backing bitmap in makeCurrent. Therefore we - // may need to free and make the context current again if we - // didn't actually make it current above. - if (pendingOffscreenResize && renderingThread != null) { - ctxStack.pop(); - free(); - if (!makeCurrent(initAction)) { - throw new GLException("Error while resizing offscreen context"); - } - ctxStack.push(this, initAction); - } - - RuntimeException userException = null; - GLException internalException = null; - - try { - if (deferredReshapeAction != null) { - deferredReshapeAction.run(); - deferredReshapeAction = null; - } - runnable.run(); - if (autoSwapBuffers && !isReshape) { - swapBuffers(); - } - } catch (RuntimeException e) { - userException = e; - throw(userException); - } finally { - if (userException != null) { - // Disallow setRenderingThread if display action is throwing exceptions - renderingThread = null; - } - - boolean mustSkipFreeForRenderingThread = false; - if (currentThread == renderingThread && curContext == null) { - mustSkipFreeForRenderingThread = true; - setPerThreadSavedCurrentContext(this, initAction); - } - - // Always pop myself off the per-thread context stack - ctxStack.pop(); - - // Free the context unless the setRenderingThread optimization - // kicks in. - if (mustDoMakeCurrent && !mustSkipFreeForRenderingThread) { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": Freeing context " + this); - } - - try { - free(); - } catch (GLException e) { - internalException = e; - } - - if (curContext != null) { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": Making context " + curContext + " current again"); - } - try { - curContext.makeCurrent(curInitAction); - } catch (GLException e) { - internalException = e; - } - } - } - - // Check to see whether we pushed any remaining entry on the - // per-thread context stack. If so, put it back in thread-local - // storage unless the rendering thread optimization was recently - // disabled. - if (savedPerThreadContext != null) { - assert(savedPerThreadContext == curContext); - ctxStack.pop(); - if (savedPerThreadContext.getRenderingThread() == null) { - try { - savedPerThreadContext.free(); - } catch (GLException e) { - internalException = e; - } - } else { - setPerThreadSavedCurrentContext(savedPerThreadContext, savedPerThreadInitAction); - } - } - - // Make sure the end user's exception shows up in any stack - // traces; the rethrow of the userException above should take - // precedence if the internalException will otherwise squelch it - if (internalException != null) { - if (userException != null && - internalException.getCause() == null) { - internalException.initCause(userException); - throw(internalException); - } else if (userException == null) { - throw(internalException); - } - } - } - } - - public GL getGL() { - return gl; - } - - public void setGL(GL gl) { - this.gl = gl; - // Also reset the GL object for the pure-Java GLU implementation - ((GLUImpl) glu).setGL(gl); - } - - public GLU getGLU() { - return glu; - } - - public void setGLU(GLU glu) { - this.glu = glu; - } - - /** Gives a hint to the context that setRenderingThread will be - called in the near future; causes redraws to be halted. This is - a workaround for bugs in NVidia's drivers and is used only by - the Animator class. */ - public synchronized void willSetRenderingThread() { - this.willSetRenderingThread = true; - } - - public synchronized void setRenderingThread(Thread currentThreadOrNull, Runnable initAction) { - if (SingleThreadedWorkaround.doWorkaround()) { - willSetRenderingThread = false; - return; - } - - Thread currentThread = Thread.currentThread(); - if (currentThreadOrNull != null && currentThreadOrNull != currentThread) { - throw new GLException("Argument must be either the current thread or null"); - } - if (renderingThread != null && currentThreadOrNull != null) { - throw new GLException("Attempt to re-set or change rendering thread"); - } - if (renderingThread == null && currentThreadOrNull == null) { - throw new GLException("Attempt to clear rendering thread when already cleared"); - } - - Object currentThreadRenderingContext = perThreadRenderingContext.get(); - if (currentThreadOrNull != null && - currentThreadRenderingContext != null && - currentThreadRenderingContext != this) { - throw new GLException("Attempt to call setRenderingThread on more than one drawable in this thread"); - } - - this.willSetRenderingThread = false; - if (currentThreadOrNull == null) { - renderingThread = null; - perThreadRenderingContext.set(null); - // Just in case the end user wasn't planning on drawing the - // drawable even once more (which would give us a chance to free - // the context), try to free the context now by performing an - // invokeGL with a do-nothing action - invokeGL(new Runnable() { - public void run() { - } - }, false, initAction); - } else { - renderingThread = currentThreadOrNull; - perThreadRenderingContext.set(this); - } - } - - public Thread getRenderingThread() { - return renderingThread; - } - - public void setNoAutoRedrawMode(boolean noAutoRedraw) { - this.noAutoRedraw = noAutoRedraw; - } - - public boolean getNoAutoRedrawMode() { - return noAutoRedraw; - } - - public void setAutoSwapBufferMode(boolean autoSwapBuffers) { - this.autoSwapBuffers = autoSwapBuffers; - } - - public boolean getAutoSwapBufferMode() { - return autoSwapBuffers; - } - - /** Swaps the buffers of the OpenGL context if necessary. All error - conditions cause a GLException to be thrown. */ - public abstract void swapBuffers() throws GLException; - - /** Routine needed only for offscreen contexts in order to resize - the underlying bitmap. Called by GLJPanel. */ - public void resizeOffscreenContext(int newWidth, int newHeight) { - if (!isOffscreen()) { - throw new GLException("Should only call for offscreen OpenGL contexts"); - } - pendingOffscreenResize = true; - pendingOffscreenWidth = newWidth; - pendingOffscreenHeight = newHeight; - } - - /** Indicates which floating-point pbuffer implementation is in - use. Returns one of GLPbuffer.APPLE_FLOAT, GLPbuffer.ATI_FLOAT, - or GLPbuffer.NV_FLOAT. */ - public int getFloatingPointMode() throws GLException { - throw new GLException("Not supported on non-pbuffer contexts"); - } - - /** Returns a non-null (but possibly empty) string containing the - space-separated list of available platform-dependent (e.g., WGL, - GLX) extensions. Can only be called while this context is - current. */ - public abstract String getPlatformExtensionsString(); - - /** - * Resets the cache of which GL functions are available for calling through this - * context. See {@link #isFunctionAvailable(String)} for more information on - * the definition of "available". - */ - protected void resetGLFunctionAvailability() { - // In order to be able to allow the user to uniformly install the - // debug and trace pipelines in their GLEventListener.init() - // method (for both GLCanvas and GLJPanel), we need to reset the - // actual GL object in the GLDrawable as well - setGL(createGL()); - - functionAvailability.flush(); - if (!haveResetGLUProcAddressTable) { - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Initializing GLU extension address table"); - } - resetProcAddressTable(gluProcAddressTable); - haveResetGLUProcAddressTable = true; // Only need to do this once globally - } - recomputeSingleThreadedWorkaround(); - } - - /** - * Returns true if the specified OpenGL core- or extension-function can be - * successfully called using this GL context given the current host (OpenGL - * <i>client</i>) and display (OpenGL <i>server</i>) configuration. - * - * See {@link GL#isFunctionAvailable(String)} for more details. - * - * @param glFunctionName the name of the OpenGL function (e.g., use - * "glPolygonOffsetEXT" to check if the {@link - * net.java.games.jogl.GL#glPolygonOffsetEXT(float,float)} is available). - */ - protected boolean isFunctionAvailable(String glFunctionName) { - return functionAvailability.isFunctionAvailable(mapToRealGLFunctionName(glFunctionName)); - } - - /** - * Returns true if the specified OpenGL extension can be - * successfully called using this GL context given the current host (OpenGL - * <i>client</i>) and display (OpenGL <i>server</i>) configuration. - * - * See {@link GL#isExtensionAvailable(String)} for more details. - * - * @param glExtensionName the name of the OpenGL extension (e.g., - * "GL_VERTEX_PROGRAM_ARB"). - */ - public boolean isExtensionAvailable(String glExtensionName) { - return functionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); - } - - /** - * Pbuffer support; indicates whether this context is capable of - * creating a subordinate pbuffer context (distinct from an - * "offscreen context", which is typically software-rendered on all - * platforms). - */ - public abstract boolean canCreatePbufferContext(); - - /** - * Pbuffer support; creates a subordinate GLContext for a pbuffer - * associated with this context. - */ - public abstract GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight); - - /** - * Pbuffer support; given that this is a GLContext associated with a - * pbuffer, binds this pbuffer to its texture target. - */ - public abstract void bindPbufferToTexture(); - - /** - * Pbuffer support; given that this is a GLContext associated with a - * pbuffer, releases this pbuffer from its texture target. - */ - public abstract void releasePbufferFromTexture(); - - /* - * Sets the swap interval for onscreen OpenGL contexts. Has no - * effect for offscreen contexts. - */ - public void setSwapInterval(final int interval) { - } - - /** Maps the given "platform-independent" function name to a real function - name. Currently this is only used to map "glAllocateMemoryNV" and - associated routines to wglAllocateMemoryNV / glXAllocateMemoryNV. */ - protected abstract String mapToRealGLFunctionName(String glFunctionName); - - /** Maps the given "platform-independent" extension name to a real - function name. Currently this is only used to map - "GL_ARB_pbuffer" and "GL_ARB_pixel_format" to "WGL_ARB_pbuffer" - and "WGL_ARB_pixel_format" (not yet mapped to X11). */ - protected abstract String mapToRealGLExtensionName(String glExtensionName); - - /** Create the GL for this context. */ - protected abstract GL createGL(); - - /** Hook indicating whether the concrete GLContext implementation is - offscreen and therefore whether we need to process resize - requests. */ - protected abstract boolean isOffscreen(); - - /** Only called for offscreen contexts; returns the buffer from - which to read pixels (GL.GL_FRONT or GL.GL_BACK). */ - public abstract int getOffscreenContextReadBuffer(); - - /** Only called for offscreen contexts; needed by glReadPixels */ - public abstract int getOffscreenContextWidth(); - - /** Only called for offscreen contexts; needed by glReadPixels */ - public abstract int getOffscreenContextHeight(); - - /** Only called for offscreen contexts; needed by glReadPixels */ - public abstract int getOffscreenContextPixelDataType(); - - /** On some platforms the mismatch between OpenGL's coordinate - system (origin at bottom left) and the window system's - coordinate system (origin at top left) necessitates a vertical - flip of pixels read from offscreen contexts. */ - public abstract boolean offscreenImageNeedsVerticalFlip(); - - /** Attempts to make the GL context current. If necessary, creates a - context and calls the initAction once the context is current. - Most error conditions cause an exception to be thrown, except - for the case where the context can not be created because the - component has not yet been visualized. In this case makeCurrent - returns false and the caller should abort any OpenGL event - processing and instead return immediately. */ - protected abstract boolean makeCurrent(Runnable initAction) throws GLException; - - /** Frees the OpenGL context. All error conditions cause a - GLException to be thrown. */ - protected abstract void free() throws GLException; - - /** Inform the system that the associated heavyweight widget has - been realized and that it is safe to create an associated OpenGL - context. If the widget is later destroyed then destroy() should - be called, which will cause the underlying OpenGL context to be - destroyed as well as the realized bit to be set to false. */ - public void setRealized() { - if (getRenderingThread() != null && - Thread.currentThread() != getRenderingThread()) { - deferredSetRealized = true; - return; - } - setRealized(true); - } - - /** Sets only the "realized" bit. Should be called by subclasses - from within the destroy() implementation. */ - protected synchronized void setRealized(boolean realized) { - this.realized = realized; - if (DEBUG) { - System.err.println(getThreadName() + ": GLContext.setRealized(" + realized + ") for context " + this); - } - } - - /** Indicates whether the component associated with this context has - been realized. */ - public synchronized boolean getRealized() { - return realized; - } - - /** Destroys the underlying OpenGL context and changes the realized - state to false. This should be called when the widget is being - destroyed. */ - public synchronized void destroy() throws GLException { - if (getRenderingThread() != null && - Thread.currentThread() != getRenderingThread()) { - if (DEBUG) { - System.err.println(getThreadName() + ": Deferred destroy for context " + this); - } - deferredDestroy = true; - return; - } - setRealized(false); - GLContextShareSet.contextDestroyed(this); - destroyImpl(); - } - - /** Destroys the underlying OpenGL context. */ - protected abstract void destroyImpl() throws GLException; - - public synchronized boolean isRealized() { - return (component == null || getRealized()); - } - - /** Helper routine which resets a ProcAddressTable generated by the - GLEmitter by looking up anew all of its function pointers. */ - protected void resetProcAddressTable(Object table) { - Class tableClass = table.getClass(); - java.lang.reflect.Field[] fields = tableClass.getDeclaredFields(); - - for (int i = 0; i < fields.length; ++i) { - String addressFieldName = fields[i].getName(); - if (!addressFieldName.startsWith(ProcAddressHelper.PROCADDRESS_VAR_PREFIX)) { - // not a proc address variable - continue; - } - int startOfMethodName = ProcAddressHelper.PROCADDRESS_VAR_PREFIX.length(); - String glFuncName = addressFieldName.substring(startOfMethodName); - try { - java.lang.reflect.Field addressField = tableClass.getDeclaredField(addressFieldName); - assert(addressField.getType() == Long.TYPE); - long newProcAddress = dynamicLookupFunction(glFuncName); - // set the current value of the proc address variable in the table object - addressField.setLong(table, newProcAddress); - if (DEBUG) { - // System.err.println(glFuncName + " = 0x" + Long.toHexString(newProcAddress)); - } - } catch (Exception e) { - throw new GLException("Cannot get GL proc address for method \"" + - glFuncName + "\": Couldn't set value of field \"" + addressFieldName + - "\" in class " + tableClass.getName(), e); - } - } - } - - /** Dynamically looks up the given function. */ - protected abstract long dynamicLookupFunction(String glFuncName); - - /** Indicates whether the underlying OpenGL context has been - created. This is used to manage sharing of display lists and - textures between contexts. */ - public abstract boolean isCreated(); - - /** Support for recursive makeCurrent() calls as well as calling - other drawables' display() methods from within another one's */ - protected static GLContextStack getPerThreadContextStack() { - return (GLContextStack) perThreadContextStack.get(); - } - - /** Support for setRenderingThread()'s optimized context handling */ - protected static GLContext getPerThreadSavedCurrentContext() { - return ((GLContextInitActionPair) perThreadSavedCurrentContext.get()).getContext(); - } - - /** Support for setRenderingThread()'s optimized context handling */ - protected static Runnable getPerThreadSavedInitAction() { - return ((GLContextInitActionPair) perThreadSavedCurrentContext.get()).getInitAction(); - } - - /** Support for setRenderingThread()'s optimized context handling */ - protected static void setPerThreadSavedCurrentContext(GLContext context, Runnable initAction) { - perThreadSavedCurrentContext.set(new GLContextInitActionPair(context, initAction)); - } - - /** Support for automatic detection of whether we need to enable the - single-threaded workaround for ATI and other vendors' cards. - Should be called by subclasses for onscreen rendering inside - their makeCurrent() implementation once the context is - current. */ - private void recomputeSingleThreadedWorkaround() { - GL gl = getGL(); - String str = gl.glGetString(GL.GL_VENDOR); - if (str != null && str.indexOf("ATI") >= 0) { - // Doing this instead of calling setRenderingThread(null) should - // be OK since we are doing this very early in the maintenance - // of the per-thread context stack, before we are actually - // pushing any GLContext objects on it - SingleThreadedWorkaround.shouldDoWorkaround(); - if( SingleThreadedWorkaround.doWorkaround() ) { - renderingThread = null; - } - } - } - - protected static String getThreadName() { - return Thread.currentThread().getName(); - } -} diff --git a/src/net/java/games/jogl/impl/GLContextFactory.java b/src/net/java/games/jogl/impl/GLContextFactory.java deleted file mode 100644 index 40a90f883..000000000 --- a/src/net/java/games/jogl/impl/GLContextFactory.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl; - -import java.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import net.java.games.jogl.*; - -public abstract class GLContextFactory { - private static GLContextFactory factory; - - public static GLContextFactory getFactory() { - if (factory == null) { - try { - String osName = System.getProperty("os.name"); - String osNameLowerCase = osName.toLowerCase(); - Class factoryClass = null; - - // Because there are some complications with generating all - // platforms' Java glue code on all platforms (among them that we - // would have to include jawt.h and jawt_md.h in the jogl - // sources, which we currently don't have to do) we break the only - // static dependencies with platform-specific code here using reflection. - - if (osNameLowerCase.startsWith("wind")) { - factoryClass = Class.forName("net.java.games.jogl.impl.windows.WindowsGLContextFactory"); - } else if (osNameLowerCase.startsWith("mac os x")) { - factoryClass = Class.forName("net.java.games.jogl.impl.macosx.MacOSXGLContextFactory"); - } else { - // Assume Linux, Solaris, etc. Should probably test for these explicitly. - factoryClass = Class.forName("net.java.games.jogl.impl.x11.X11GLContextFactory"); - } - - if (factoryClass == null) { - throw new GLException("OS " + osName + " not yet supported"); - } - - factory = (GLContextFactory) factoryClass.newInstance(); - } catch (ClassNotFoundException e) { - throw new GLException(e); - } catch (InstantiationException e) { - throw new GLException(e); - } catch (IllegalAccessException e) { - throw new GLException(e); - } - } - - return factory; - } - - /** Selects a GraphicsConfiguration on the specified GraphicsDevice - that matches the desired GLCapabilities according to the - specified GLCapabilitiesChooser's selection algorithm and any - hints provided by the underlying window system. This routine is - currently only implemented on X11, where it is necessary to - choose the desired visual before creating the underlying AWT - Canvas; on other platforms it returns null, yielding the default - behavior. */ - public abstract GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GraphicsDevice device); - - public abstract GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith); -} diff --git a/src/net/java/games/jogl/impl/GLContextStack.java b/src/net/java/games/jogl/impl/GLContextStack.java deleted file mode 100755 index 089d53525..000000000 --- a/src/net/java/games/jogl/impl/GLContextStack.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl; - -import java.util.*; - -/** Implements a stack of GLContext objects along with the initActions - that need to be run if their creation is necessary. This is used - to detect redundant makeCurrent() calls and to allow one drawable - to call display() of another from within the first drawable's - display() method. */ - -public class GLContextStack { - private ArrayList data = new ArrayList(); - - /** Pushes this GLContext on the stack. The passed context must be non-null. */ - public void push(GLContext ctx, Runnable initAction) { - if (ctx == null) { - throw new IllegalArgumentException("Null contexts are not allowed here"); - } - - data.add(new GLContextInitActionPair(ctx, initAction)); - } - - /** Removes and returns the top GLContext and associated - initialization action, or null if there is none. */ - public GLContextInitActionPair pop() { - if (data.size() == 0) { - return null; - } - - return (GLContextInitActionPair) data.remove(data.size() - 1); - } - - /** Returns the top GLContext and associated initialization action - without removing it, or null if there is none. */ - public GLContextInitActionPair peek() { - return peek(0); - } - - /** Returns the <i>i</i>th GLContext and associated initialization - action from the top without removing it, or null if there is - none. */ - public GLContextInitActionPair peek(int i) { - if (data.size() - i <= 0) { - return null; - } - - return (GLContextInitActionPair) data.get(data.size() - i - 1); - } - - /** Returns the top GLContext without removing it, or null if there - is none. */ - public GLContext peekContext() { - return peekContext(0); - } - - /** Returns the <i>i</i>th GLContext from the top without removing - it, or null if there is none. */ - public GLContext peekContext(int i) { - GLContextInitActionPair pair = peek(i); - if (pair == null) { - return null; - } - - return pair.getContext(); - } - - /** Returns the top initialization action without removing it, or - null if there is none. */ - public Runnable peekInitAction() { - return peekInitAction(0); - } - - /** Returns the <i>i</i>th initialization action from the top - without removing it, or null if there is none. */ - public Runnable peekInitAction(int i) { - GLContextInitActionPair pair = peek(i); - if (pair == null) { - return null; - } - - return pair.getInitAction(); - } - - /** Returns the number of entries on the GLContext stack. */ - public int size() { - return data.size(); - } -} diff --git a/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java b/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java deleted file mode 100755 index f19c1fb67..000000000 --- a/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl; - -import java.security.AccessController; -import java.security.PrivilegedAction; - -/** Encapsulates the workaround of running all display operations on - the AWT event queue thread for the purposes of working around - problems seen primarily on ATI cards when rendering into a surface - that is simultaneously being resized by the event queue thread. - <p> - - As of JOGL 1.1 b10, this property defaults to true. Problems have - been seen on Windows, Linux and Mac OS X platforms that are solved - by switching all OpenGL work to a single thread, which this - workaround provides. The forthcoming JSR-231 work will rethink how - such a mechanism is implemented, but the core result of needing to - perform all OpenGL work on a single thread for best compatibility - will remain. -*/ - -public class SingleThreadedWorkaround { - private static boolean singleThreadedWorkaround = true; - // If the user specified the workaround's system property (either - // true or false), don't let the automatic detection have any effect - private static boolean systemPropertySpecified = false; - - static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String workaround = System.getProperty("jogl.1thread"); - if (workaround == null) { - // Old system property (for compatibility) - workaround = System.getProperty("JOGL_SINGLE_THREADED_WORKAROUND"); - } - if (workaround == null) { - // Older system property (for compatibility) - workaround = System.getProperty("ATI_WORKAROUND"); - } - if (workaround != null && (!workaround.equals("auto"))) { - systemPropertySpecified = true; - singleThreadedWorkaround = Boolean.valueOf(workaround).booleanValue(); - } - printWorkaroundNotice(); - return null; - } - }); - } - - /** Public method for users to disable the single-threaded - workaround in application code. Should perhaps eventually - promote this method to the public API. */ - public static void disableWorkaround() { - systemPropertySpecified = true; - singleThreadedWorkaround = false; - if (Debug.verbose()) { - System.err.println("Application forced disabling of single-threaded workaround of dispatching display() on event thread"); - } - } - - public static void shouldDoWorkaround() { - if (!systemPropertySpecified) { - singleThreadedWorkaround = true; - printWorkaroundNotice(); - } - } - - public static boolean doWorkaround() { - return singleThreadedWorkaround; - } - - private static void printWorkaroundNotice() { - if (singleThreadedWorkaround && Debug.verbose()) { - System.err.println("Using single-threaded workaround of dispatching display() on event thread"); - } - } -} diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java deleted file mode 100644 index ba4eee0ef..000000000 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.macosx; - -import java.awt.Component; -import java.util.*; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -import java.security.*; - -public class MacOSXOnscreenGLContext extends MacOSXGLContext { - // Variables for lockSurface/unlockSurface - private JAWT_DrawingSurface ds; - private JAWT_DrawingSurfaceInfo dsi; - private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; - - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); - - // Workaround for instance of 4796548 - private boolean firstLock = true; - - public MacOSXOnscreenGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected boolean isOffscreen() { - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - public boolean canCreatePbufferContext() { - return true; - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - MacOSXPbufferGLContext ctx = new MacOSXPbufferGLContext(capabilities, initialWidth, initialHeight); - GLContextShareSet.registerSharing(this, ctx); - pbuffersToInstantiate.add(ctx); - return ctx; - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - public synchronized void setRenderingThread(Thread currentThreadOrNull, Runnable initAction) { - this.willSetRenderingThread = false; - // FIXME: the JAWT in the Panther developer release - // requires all JAWT operations to be done on the AWT - // thread. This means that setRenderingThread won't work - // yet on this platform. This method can be deleted once - // the update for that release ships. - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - try { - if (!lockSurface()) { - return false; - } - boolean ret = super.makeCurrent(initAction); - if (ret) { - // Assume the canvas might have been resized or moved and tell the OpenGL - // context to update itself. This used to be done only upon receiving a - // reshape event but that doesn't appear to be sufficient. An experiment - // was also done to add a HierarchyBoundsListener to the GLCanvas and - // do this updating only upon reshape of this component or reshape or movement - // of an ancestor, but this also wasn't sufficient and left garbage on the - // screen in some situations. - CGL.updateContext(nsContext, nsView); - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - MacOSXPbufferGLContext ctx = - (MacOSXPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - ctx.createPbuffer(nsView, nsContext); - } - } else { - // View might not have been ready - unlockSurface(); - } - return ret; - } catch (RuntimeException e) { - try { - unlockSurface(); - } catch (Exception e2) { - // do nothing if unlockSurface throws - } - throw(e); - } - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - unlockSurface(); - } - } - - public synchronized void swapBuffers() throws GLException { - if (!CGL.flushBuffer(nsContext, nsView)) { - throw new GLException("Error swapping buffers"); - } - } - - private boolean lockSurface() throws GLException { - if (nsView != 0) { - throw new GLException("Surface already locked"); - } - - ds = getJAWT().GetDrawingSurface(component); - if (ds == null) { - // Widget not yet realized - return false; - } - - int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new GLException("Unable to lock surface"); - } - - // See whether the surface changed and if so destroy the old - // OpenGL nsContext so it will be recreated - if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { - if (nsContext != 0) { - //CGL.updateContextUnregister(nsContext, nsView, updater); // gznote: not thread safe yet! - if (!CGL.deleteContext(nsContext, nsView)) { - throw new GLException("Unable to delete old GL nsContext after surface changed"); - } - } - } - - if (firstLock) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - dsi = ds.GetDrawingSurfaceInfo(); - return null; - } - }); - } else { - dsi = ds.GetDrawingSurfaceInfo(); - } - if (dsi == null) { - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - - // Widget not yet realized - return false; - } - - firstLock = false; - - macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); - if (macosxdsi == null) { - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - - // Widget not yet realized - return false; - } - - nsView = macosxdsi.cocoaViewRef(); - if (nsView == 0) { - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - macosxdsi = null; - - // Widget not yet realized - return false; - } - - return true; - } - - private void unlockSurface() throws GLException { - if (nsView == 0) { - throw new GLException("Surface already unlocked"); - } - - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - macosxdsi = null; - nsView = 0; - } -} diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java deleted file mode 100644 index 93bde269b..000000000 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ /dev/null @@ -1,203 +0,0 @@ -package net.java.games.jogl.impl.macosx; - -import java.security.*; -import java.util.*; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class MacOSXPbufferGLContext extends MacOSXGLContext { - private static final boolean DEBUG = Debug.debug("MacOSXPbufferGLContext"); - private static boolean isTigerOrLater; - - static { - String osVersion = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("os.version"); - } - }); - StringTokenizer tok = new StringTokenizer(osVersion, ". "); - int major = Integer.parseInt(tok.nextToken()); - int minor = Integer.parseInt(tok.nextToken()); - isTigerOrLater = ((major > 10) || (minor > 3)); - } - - protected int initWidth; - protected int initHeight; - - private long pBuffer; - - protected int width; - protected int height; - - // State for render-to-texture and render-to-texture-rectangle support - private boolean created; - private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV - private int texture; // actual texture object - - public MacOSXPbufferGLContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - super(null, capabilities, null, null); - this.initWidth = initialWidth; - this.initHeight = initialHeight; - } - - public boolean canCreatePbufferContext() { - return false; - } - - public GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - GL gl = getGL(); - gl.glBindTexture(textureTarget, texture); - // FIXME: not clear whether this is really necessary, but since - // the API docs seem to imply it is and since it doesn't seem to - // impact performance, leaving it in - CGL.setContextTextureImageToPBuffer(nsContext, pBuffer, GL.GL_FRONT); - } - - public void releasePbufferFromTexture() { - } - - public void createPbuffer(long parentView, long parentContext) { - GL gl = getGL(); - // Must initally grab OpenGL function pointers while parent's - // context is current because otherwise we don't have the cgl - // extensions available to us - resetGLFunctionAvailability(); - - int renderTarget; - if (capabilities.getOffscreenRenderToTextureRectangle()) { - width = initWidth; - height = initHeight; - renderTarget = GL.GL_TEXTURE_RECTANGLE_EXT; - } else { - width = getNextPowerOf2(initWidth); - height = getNextPowerOf2(initHeight); - renderTarget = GL.GL_TEXTURE_2D; - } - - int internalFormat = GL.GL_RGBA; - if (capabilities.getOffscreenFloatingPointBuffers()) { - if (!gl.isExtensionAvailable("GL_APPLE_float_pixels")) { - throw new GLException("Floating-point support (GL_APPLE_float_pixels) not available"); - } - switch (capabilities.getRedBits()) { - case 16: internalFormat = GL.GL_RGBA_FLOAT16_APPLE; break; - case 32: internalFormat = GL.GL_RGBA_FLOAT32_APPLE; break; - default: throw new GLException("Invalid floating-point bit depth (only 16 and 32 supported)"); - } - } - - pBuffer = CGL.createPBuffer(renderTarget, internalFormat, width, height); - if (pBuffer == 0) { - throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); - } - - if (DEBUG) { - System.err.println("Created pbuffer 0x" + Long.toHexString(pBuffer) + ", " + width + " x " + height + " for " + this); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - created = false; - - if (pBuffer == 0) { - if (DEBUG) { - System.err.println("Pbuffer not instantiated yet for " + this); - } - // pbuffer not instantiated yet - return false; - } - - boolean res = super.makeCurrent(initAction); - if (created) { - // Initialize render-to-texture support if requested - boolean rect = capabilities.getOffscreenRenderToTextureRectangle(); - GL gl = getGL(); - if (rect) { - if (!gl.isExtensionAvailable("GL_EXT_texture_rectangle")) { - System.err.println("MacOSXPbufferGLContext: WARNING: GL_EXT_texture_rectangle extension not " + - "supported; skipping requested render_to_texture_rectangle support for pbuffer"); - rect = false; - } - } - textureTarget = (rect ? GL.GL_TEXTURE_RECTANGLE_EXT : GL.GL_TEXTURE_2D); - int[] tmp = new int[1]; - gl.glGenTextures(1, tmp); - texture = tmp[0]; - gl.glBindTexture(textureTarget, texture); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); - gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, width, height, 0); - } - return res; - } - - public void destroyPBuffer() { - if (this.pBuffer != 0) { - CGL.destroyPBuffer(nsContext, pBuffer); - } - this.pBuffer = 0; - - if (DEBUG) { - System.err.println("Destroyed pbuffer " + width + " x " + height); - } - } - - public void handleModeSwitch(long parentView, long parentContext) { - throw new GLException("Not yet implemented"); - } - - protected boolean isOffscreen() { - // FIXME: currently the only caller of this won't cause proper - // resizing of the pbuffer anyway. - return false; - } - - protected void destroyImpl() throws GLException { - destroyPBuffer(); - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - } - - public int getFloatingPointMode() { - return GLPbuffer.APPLE_FLOAT; - } - - private int getNextPowerOf2(int number) { - if (((number-1) & number) == 0) { - //ex: 8 -> 0b1000; 8-1=7 -> 0b0111; 0b1000&0b0111 == 0 - return number; - } - int power = 0; - while (number > 0) { - number = number>>1; - power++; - } - return (1<<power); - } - - protected boolean create() { - if (capabilities.getOffscreenFloatingPointBuffers() && - !isTigerOrLater) { - throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); - } - if (!super.create(true, capabilities.getOffscreenFloatingPointBuffers())) { - return false; - } - created = true; - // Must now associate the pbuffer with our newly-created context - CGL.setContextPBuffer(nsContext, pBuffer); - return true; - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java deleted file mode 100644 index e838c68aa..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ /dev/null @@ -1,717 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.windows; - -import java.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public abstract class WindowsGLContext extends GLContext { - private static JAWT jawt; - protected long hglrc; - protected long hdc; - private boolean wglGetExtensionsStringEXTInitialized; - private boolean wglGetExtensionsStringEXTAvailable; - private static final Map/*<String, String>*/ functionNameMap; - private static final Map/*<String, String>*/ extensionNameMap; - // Table that holds the addresses of the native C-language entry points for - // OpenGL functions. - private GLProcAddressTable glProcAddressTable; - // Handle to GLU32.dll - private long hglu32; - private boolean haveWGLARBPbuffer = true; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - static { - functionNameMap = new HashMap(); - functionNameMap.put("glAllocateMemoryNV", "wglAllocateMemoryNV"); - functionNameMap.put("glFreeMemoryNV", "wglFreeMemoryNV"); - - extensionNameMap = new HashMap(); - extensionNameMap.put("GL_ARB_pbuffer", "WGL_ARB_pbuffer"); - extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format"); - } - - public WindowsGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new WindowsGLImpl(this); - } - - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) { - String lookup = (String) extensionNameMap.get(glExtensionName); - if (lookup != null) { - return lookup; - } - return glExtensionName; - } - - protected abstract boolean isOffscreen(); - - public int getOffscreenContextWidth() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextHeight() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - - /** - * Creates and initializes an appropriate OpenGL context. Should only be - * called by {@link #makeCurrent(Runnable)}. - */ - protected abstract void create(); - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - boolean created = false; - if (hglrc == 0) { - create(); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); - } - created = true; - } - - boolean skipMakeCurrent = false; - if (NO_FREE) { - if (WGL.wglGetCurrentContext() == hglrc) { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": skipping wglMakeCurrent because context already current"); - } - skipMakeCurrent = true; - } - } - - if (!skipMakeCurrent) { - if (!WGL.wglMakeCurrent(hdc, hglrc)) { - throw new GLException("Error making context current: " + WGL.GetLastError()); - } else { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + hdcToString(hdc) + - ", hglrc " + hdcToString(hglrc) + ") succeeded"); - } - } - } - - if (created) { - resetGLFunctionAvailability(); - haveWGLARBPbuffer = (isExtensionAvailable("WGL_ARB_pbuffer") && - isExtensionAvailable("WGL_ARB_pixel_format")); - // Windows can set up sharing of display lists after creation time - WindowsGLContext other = (WindowsGLContext) GLContextShareSet.getShareContext(this); - if (other != null) { - long hglrc2 = other.getHGLRC(); - if (hglrc2 == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - if (!WGL.wglShareLists(hglrc2, hglrc)) { - throw new GLException("wglShareLists(0x" + Long.toHexString(hglrc2) + - ", 0x" + Long.toHexString(hglrc) + ") failed: error code " + - WGL.GetLastError()); - } - } - GLContextShareSet.contextCreated(this); - - initAction.run(); - } - return true; - } - - protected synchronized void free() throws GLException { - if (!NO_FREE) { - if (!WGL.wglMakeCurrent(0, 0)) { - throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError()); - } - } - } - - protected void destroyImpl() throws GLException { - if (hglrc != 0) { - if (!WGL.wglDeleteContext(hglrc)) { - throw new GLException("Unable to delete OpenGL context"); - } - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + hglrc); - } - hglrc = 0; - } - } - - public abstract void swapBuffers() throws GLException; - - protected long dynamicLookupFunction(String glFuncName) { - long res = WGL.wglGetProcAddress(glFuncName); - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - if (hglu32 == 0) { - hglu32 = WGL.LoadLibraryA("GLU32"); - if (hglu32 == 0) { - throw new GLException("Error loading GLU32.DLL"); - } - } - res = WGL.GetProcAddress(hglu32, glFuncName); - } - return res; - } - - public boolean isCreated() { - return (hglrc != 0); - } - - protected void resetGLFunctionAvailability() { - super.resetGLFunctionAvailability(); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Initializing OpenGL extension address table"); - } - resetProcAddressTable(getGLProcAddressTable()); - } - - public GLProcAddressTable getGLProcAddressTable() { - if (glProcAddressTable == null) { - // FIXME: cache ProcAddressTables by capability bits so we can - // share them among contexts with the same capabilities - glProcAddressTable = new GLProcAddressTable(); - } - return glProcAddressTable; - } - - public String getPlatformExtensionsString() { - if (!wglGetExtensionsStringEXTInitialized) { - wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); - wglGetExtensionsStringEXTInitialized = true; - } - if (wglGetExtensionsStringEXTAvailable) { - return gl.wglGetExtensionsStringEXT(); - } else { - return ""; - } - } - - protected boolean isFunctionAvailable(String glFunctionName) - { - boolean available = super.isFunctionAvailable(glFunctionName); - - // Sanity check for implementations that use proc addresses for run-time - // linking: if the function IS available, then make sure there's a proc - // address for it if it's an extension or not part of the OpenGL 1.1 core - // (post GL 1.1 functions are run-time linked on windows). - assert(!available || - (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || - FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) - ); - - return available; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - protected JAWT getJAWT() { - if (jawt == null) { - JAWT j = new JAWT(); - j.version(JAWTFactory.JAWT_VERSION_1_4); - if (!JAWTFactory.JAWT_GetAWT(j)) { - throw new RuntimeException("Unable to initialize JAWT"); - } - jawt = j; - } - return jawt; - } - - // Helper routine for the overridden create() to call - protected void choosePixelFormatAndCreateContext(boolean onscreen) { - PIXELFORMATDESCRIPTOR pfd = null; - int pixelFormat = 0; - if (onscreen) { - GLCapabilities[] availableCaps = null; - int numFormats = 0; - pfd = newPixelFormatDescriptor(); - GraphicsConfiguration config = component.getGraphicsConfiguration(); - GraphicsDevice device = config.getDevice(); - // Produce a recommended pixel format selection for the GLCapabilitiesChooser. - // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available - GL dummyGL = null; - if (capabilities.getSampleBuffers()) { - dummyGL = WindowsGLContextFactory.getDummyGL(device); - } - int recommendedPixelFormat = -1; - boolean haveWGLChoosePixelFormatARB = false; - boolean haveWGLARBMultisample = false; - if (dummyGL != null) { - String availableWGLExtensions = WindowsGLContextFactory.getDummyGLExtensions(device); - if (availableWGLExtensions.indexOf("WGL_ARB_pixel_format") >= 0) { - haveWGLChoosePixelFormatARB = true; - if (availableWGLExtensions.indexOf("WGL_ARB_multisample") >= 0) { - haveWGLARBMultisample = true; - } - } - } - Rectangle rect = config.getBounds(); - long dc = 0; - long rc = 0; - boolean freeWGLC = false; - if( dummyGL != null ) { - dc = WindowsGLContextFactory.getDummyGLContext( device ).hdc; - rc = WindowsGLContextFactory.getDummyGLContext( device ).hglrc; - if( !WGL.wglMakeCurrent( dc, rc ) ) { - System.err.println(getThreadName() + ": Error Making WGLC Current: " + WGL.GetLastError() ); - } else { - freeWGLC = true; - } - } - // Fallback path for older cards, in particular Intel Extreme motherboard graphics - boolean gotAvailableCaps = false; - if (dummyGL != null && haveWGLChoosePixelFormatARB) { - int[] iattributes = new int [2 * MAX_ATTRIBS]; - int[] iresults = new int [2 * MAX_ATTRIBS]; - float[] fattributes = new float[2 * MAX_ATTRIBS]; - int niattribs = 0; - int nfattribs = 0; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - if (capabilities.getStereo()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = capabilities.getDepthBits(); - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getRedBits(); - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getGreenBits(); - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getBlueBits(); - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAlphaBits(); - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = capabilities.getStencilBits(); - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0 || - capabilities.getAccumAlphaBits() > 0) { - iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; - iattributes[niattribs++] = (capabilities.getAccumRedBits() + - capabilities.getAccumGreenBits() + - capabilities.getAccumBlueBits() + - capabilities.getAccumAlphaBits()); - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumRedBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumGreenBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumBlueBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumAlphaBits(); - } - if (haveWGLARBMultisample) { - if (capabilities.getSampleBuffers()) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - iattributes[niattribs++] = capabilities.getNumSamples(); - } - } - - int[] pformats = new int[MAX_PFORMATS]; - int[] numFormatsTmp = new int[1]; - if (dummyGL.wglChoosePixelFormatARB(hdc, - iattributes, - fattributes, - MAX_PFORMATS, - pformats, - numFormatsTmp)) { - numFormats = numFormatsTmp[0]; - if (numFormats > 0) { - // Remove one-basing of pixel format (added on later) - recommendedPixelFormat = pformats[0] - 1; - if (DEBUG) { - System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); - } - } - } else { - if (DEBUG) { - System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); - Thread.dumpStack(); - } - } - if (DEBUG) { - if (recommendedPixelFormat < 0) { - System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); - if (capabilities.getSampleBuffers()) { - System.err.print(" for multisampled GLCapabilities"); - } - System.err.println(); - } - } - - // Produce a list of GLCapabilities to give to the - // GLCapabilitiesChooser. - // Use wglGetPixelFormatAttribivARB instead of - // DescribePixelFormat to get higher-precision information - // about the pixel format (should make the GLCapabilities - // more precise as well...i.e., remove the - // "HardwareAccelerated" bit, which is basically - // meaningless, and put in whether it can render to a - // window, to a pbuffer, or to a pixmap) - niattribs = 0; - iattributes[0] = GL.WGL_NUMBER_PIXEL_FORMATS_ARB; - if (dummyGL.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, iresults)) { - numFormats = iresults[0]; - // Should we be filtering out the pixel formats which aren't - // applicable, as we are doing here? - // We don't have enough information in the GLCapabilities to - // represent those that aren't... - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.WGL_ACCELERATION_ARB; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - if (haveWGLARBMultisample) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - } - - availableCaps = new GLCapabilities[numFormats]; - for (int i = 0; i < numFormats; i++) { - if (!dummyGL.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, iresults)) { - throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); - } - availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); - } - if( freeWGLC ) { - WGL.wglMakeCurrent( 0, 0 ); - } - gotAvailableCaps = true; - } else { - int lastErr = WGL.GetLastError(); - // Intel Extreme graphics fails with a zero error code - if (lastErr != 0) { - throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError()); - } - } - } - - if (!gotAvailableCaps) { - if (DEBUG) { - if (!capabilities.getSampleBuffers()) { - System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested"); - } else { - System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB: dummyGL = " + dummyGL); - } - } - pfd = glCapabilities2PFD(capabilities, onscreen); - // Remove one-basing of pixel format (added on later) - recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd) - 1; - - numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null); - if (numFormats == 0) { - throw new GLException("Unable to enumerate pixel formats of window for GLCapabilitiesChooser"); - } - availableCaps = new GLCapabilities[numFormats]; - for (int i = 0; i < numFormats; i++) { - if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) { - throw new GLException("Error describing pixel format " + (1 + i) + " of device context"); - } - availableCaps[i] = pfd2GLCapabilities(pfd); - } - } - - // Supply information to chooser - pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat); - if ((pixelFormat < 0) || (pixelFormat >= numFormats)) { - throw new GLException("Invalid result " + pixelFormat + - " from GLCapabilitiesChooser (should be between 0 and " + - (numFormats - 1) + ")"); - } - if (DEBUG) { - System.err.println(getThreadName() + ": Chosen pixel format (" + pixelFormat + "):"); - System.err.println(availableCaps[pixelFormat]); - } - pixelFormat += 1; // one-base the index - if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) { - throw new GLException("Error re-describing the chosen pixel format: " + WGL.GetLastError()); - } - } else { - // For now, use ChoosePixelFormat for offscreen surfaces until - // we figure out how to properly choose an offscreen- - // compatible pixel format - pfd = glCapabilities2PFD(capabilities, onscreen); - pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); - } - if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) { - int lastError = WGL.GetLastError(); - if (DEBUG) { - System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() + - ", current DC = " + WGL.wglGetCurrentDC()); - System.err.println(getThreadName() + ": GetPixelFormat(hdc " + hdcToString(hdc) + ") returns " + WGL.GetPixelFormat(hdc)); - } - throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + hdcToString(hdc) + ": error code " + lastError); - } - hglrc = WGL.wglCreateContext(hdc); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created OpenGL context " + hglrc + " for device context " + hdcToString(hdc) + " using pixel format " + pixelFormat); - } - if (hglrc == 0) { - throw new GLException("Unable to create OpenGL context"); - } - } - - protected long getHGLRC() { - return hglrc; - } - - static PIXELFORMATDESCRIPTOR glCapabilities2PFD(GLCapabilities caps, boolean onscreen) { - int colorDepth = (caps.getRedBits() + - caps.getGreenBits() + - caps.getBlueBits()); - if (colorDepth < 15) { - throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); - } - PIXELFORMATDESCRIPTOR pfd = newPixelFormatDescriptor(); - int pfdFlags = (WGL.PFD_SUPPORT_OPENGL | - WGL.PFD_GENERIC_ACCELERATED); - if (caps.getDoubleBuffered()) { - pfdFlags |= WGL.PFD_DOUBLEBUFFER; - } - if (onscreen) { - pfdFlags |= WGL.PFD_DRAW_TO_WINDOW; - } else { - pfdFlags |= WGL.PFD_DRAW_TO_BITMAP; - } - pfd.dwFlags(pfdFlags); - pfd.iPixelType((byte) WGL.PFD_TYPE_RGBA); - pfd.cColorBits((byte) colorDepth); - pfd.cRedBits ((byte) caps.getRedBits()); - pfd.cGreenBits((byte) caps.getGreenBits()); - pfd.cBlueBits ((byte) caps.getBlueBits()); - pfd.cAlphaBits((byte) caps.getAlphaBits()); - int accumDepth = (caps.getAccumRedBits() + - caps.getAccumGreenBits() + - caps.getAccumBlueBits()); - pfd.cAccumBits ((byte) accumDepth); - pfd.cAccumRedBits ((byte) caps.getAccumRedBits()); - pfd.cAccumGreenBits((byte) caps.getAccumGreenBits()); - pfd.cAccumBlueBits ((byte) caps.getAccumBlueBits()); - pfd.cAccumAlphaBits((byte) caps.getAccumAlphaBits()); - pfd.cDepthBits((byte) caps.getDepthBits()); - pfd.cStencilBits((byte) caps.getStencilBits()); - pfd.iLayerType((byte) WGL.PFD_MAIN_PLANE); - return pfd; - } - - static PIXELFORMATDESCRIPTOR newPixelFormatDescriptor() { - PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR(); - pfd.nSize((short) pfd.size()); - pfd.nVersion((short) 1); - return pfd; - } - - static GLCapabilities pfd2GLCapabilities(PIXELFORMATDESCRIPTOR pfd) { - if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) { - return null; - } - GLCapabilities res = new GLCapabilities(); - res.setRedBits (pfd.cRedBits()); - res.setGreenBits (pfd.cGreenBits()); - res.setBlueBits (pfd.cBlueBits()); - res.setAlphaBits (pfd.cAlphaBits()); - res.setAccumRedBits (pfd.cAccumRedBits()); - res.setAccumGreenBits(pfd.cAccumGreenBits()); - res.setAccumBlueBits (pfd.cAccumBlueBits()); - res.setAccumAlphaBits(pfd.cAccumAlphaBits()); - res.setDepthBits (pfd.cDepthBits()); - res.setStencilBits (pfd.cStencilBits()); - res.setDoubleBuffered((pfd.dwFlags() & WGL.PFD_DOUBLEBUFFER) != 0); - res.setStereo ((pfd.dwFlags() & WGL.PFD_STEREO) != 0); - res.setHardwareAccelerated(((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) || - ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0)); - return res; - } - - static GLCapabilities iattributes2GLCapabilities(int[] iattribs, - int[] iresults, - int niattribs, - boolean requireRenderToWindow) { - GLCapabilities res = new GLCapabilities(); - for (int i = 0; i < niattribs; i++) { - switch (iattribs[i]) { - case GL.WGL_DRAW_TO_WINDOW_ARB: - if (iresults[i] != GL.GL_TRUE) - return null; - break; - - case GL.WGL_ACCELERATION_ARB: - res.setHardwareAccelerated(iresults[i] == GL.WGL_FULL_ACCELERATION_ARB); - break; - - case GL.WGL_SUPPORT_OPENGL_ARB: - if (iresults[i] != GL.GL_TRUE) - return null; - break; - - case GL.WGL_DEPTH_BITS_ARB: - res.setDepthBits(iresults[i]); - break; - - case GL.WGL_STENCIL_BITS_ARB: - res.setStencilBits(iresults[i]); - break; - - case GL.WGL_DOUBLE_BUFFER_ARB: - res.setDoubleBuffered(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_STEREO_ARB: - res.setStereo(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_PIXEL_TYPE_ARB: - if (iresults[i] != GL.WGL_TYPE_RGBA_ARB) - return null; - break; - - case GL.WGL_RED_BITS_ARB: - res.setRedBits(iresults[i]); - break; - - case GL.WGL_GREEN_BITS_ARB: - res.setGreenBits(iresults[i]); - break; - - case GL.WGL_BLUE_BITS_ARB: - res.setBlueBits(iresults[i]); - break; - - case GL.WGL_ALPHA_BITS_ARB: - res.setAlphaBits(iresults[i]); - break; - - case GL.WGL_ACCUM_RED_BITS_ARB: - res.setAccumRedBits(iresults[i]); - break; - - case GL.WGL_ACCUM_GREEN_BITS_ARB: - res.setAccumGreenBits(iresults[i]); - break; - - case GL.WGL_ACCUM_BLUE_BITS_ARB: - res.setAccumBlueBits(iresults[i]); - break; - - case GL.WGL_ACCUM_ALPHA_BITS_ARB: - res.setAccumAlphaBits(iresults[i]); - break; - - case GL.WGL_SAMPLE_BUFFERS_ARB: - res.setSampleBuffers(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_SAMPLES_ARB: - res.setNumSamples(iresults[i]); - break; - - default: - throw new GLException("Unknown pixel format attribute " + iattribs[i]); - } - } - return res; - } - - protected static String hdcToString(long hdc) { - return "0x" + Long.toHexString(hdc); - } - - protected boolean haveWGLARBPbuffer() { - return haveWGLARBPbuffer; - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java b/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java deleted file mode 100644 index dd6f8daca..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.windows; - -import java.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.io.File; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.Collection; -import java.util.Iterator; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsGLContextFactory extends GLContextFactory { - private static final boolean DEBUG = Debug.debug("WindowsGLContextFactory"); - private static final boolean VERBOSE = Debug.verbose(); - - // On Windows we want to be able to use some extension routines like - // wglChoosePixelFormatARB during the creation of the user's first - // GLContext. However, this and other routines' function pointers - // aren't loaded by the driver until the first OpenGL context is - // created. The standard way of working around this chicken-and-egg - // problem is to create a dummy window, show it, send it a paint - // message, create an OpenGL context, fetch the needed function - // pointers, and then destroy the dummy window and context. It turns - // out that ATI cards need the dummy context to be current while - // wglChoosePixelFormatARB is called, so we cache the extension - // strings the dummy context reports as being available. - private static Map/*<GraphicsDevice, GL>*/ dummyContextMap = new HashMap(); - private static Map/*<GraphicsDevice, String>*/ dummyExtensionsMap = new HashMap(); - private static Set/*<GraphicsDevice >*/ pendingContextSet = new HashSet(); - - public WindowsGLContextFactory() { - AccessController.doPrivileged( new PrivilegedAction() { - public Object run() { - Runtime.getRuntime().addShutdownHook( new ShutdownHook() ); - - // Test for whether we should enable the single-threaded - // workaround for ATI cards. It appears that if we make any - // OpenGL context current on more than one thread on ATI cards - // on Windows then we see random failures like the inability - // to create more OpenGL contexts, or having just the next - // OpenGL SetPixelFormat operation fail with a GetNextError() - // code of 0 (but subsequent ones on subsequently-created - // windows succeed). These kinds of failures are obviously due - // to bugs in ATI's OpenGL drivers. Through trial and error it - // was found that specifying - // -DJOGL_SINGLE_THREADED_WORKAROUND=true on the command line - // caused these problems to completely disappear. Therefore at - // least on Windows we try to enable the single-threaded - // workaround before creating any OpenGL contexts. In the - // future, if problems are encountered on other platforms and - // -DJOGL_SINGLE_THREADED_WORKAROUND=true works around them, - // we may want to implement a workaround like this on other - // platforms. - - // The algorithm here is to try to find the system directory - // (assuming it is on the same drive as TMPDIR, exposed - // through the system property java.io.tmpdir) and see whether - // a known file in the ATI drivers is present; if it is, we - // enable the single-threaded workaround. - - // If any path down this code fails, we simply bail out -- we - // don't go to great lengths to figure out if the ATI drivers - // are present. We could add more checks here in the future if - // these appear to be insufficient. - - String tmpDirProp = System.getProperty("java.io.tmpdir"); - if (tmpDirProp != null) { - File file = new File(tmpDirProp); - if (file.isAbsolute()) { - File parent = null; - do { - parent = file.getParentFile(); - if (parent != null) { - file = parent; - } - } while (parent != null); - // Now the file contains just the drive letter - file = new File(new File(new File(file, "windows"), "system32"), "atioglxx.dll"); - if (file.exists()) { - SingleThreadedWorkaround.shouldDoWorkaround(); - } - } - } - - return( null ); - } - }); - } - - public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GraphicsDevice device) { - return null; - } - - public GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - if (component != null) { - return new WindowsOnscreenGLContext(component, capabilities, chooser, shareWith); - } else { - return new WindowsOffscreenGLContext(capabilities, chooser, shareWith); - } - } - - // Return cached GL context - public static WindowsGLContext getDummyGLContext( final GraphicsDevice device ) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return nws.getWindowsContext(); - } - - // Return cached extension string - public static String getDummyGLExtensions(final GraphicsDevice device) { - checkForDummyContext( device ); - String exts = (String) dummyExtensionsMap.get(device); - return (exts == null) ? "" : exts; - } - - // Return cached GL function pointers - public static GL getDummyGL(final GraphicsDevice device) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return( nws.getWindowsContext().getGL() ); - } - - /* - * Locate a cached native window, if one doesn't exist create one amd - * cache it. - */ - private static void checkForDummyContext( final GraphicsDevice device ) { - if (!pendingContextSet.contains(device) && !dummyContextMap.containsKey( device ) ) { - if (DEBUG) { - System.err.println("WindowsGLContextFactory.checkForDummyContext() called on thread " + - Thread.currentThread().getName()); - } - - pendingContextSet.add(device); - GraphicsConfiguration config = device.getDefaultConfiguration(); - Rectangle rect = config.getBounds(); - GLCapabilities caps = new GLCapabilities(); - caps.setDepthBits( 16 ); - // Create a context that we use to query pixel formats - WindowsOnscreenGLContext context = new WindowsOnscreenGLContext( null, caps, null, null ); - // Start a native thread and grab native screen resources from the thread - NativeWindowThread nwt = new NativeWindowThread( rect ); - nwt.start(); - long hWnd = 0; - long tempHDC = 0; - while( (hWnd = nwt.getHWND()) == 0 || (tempHDC = nwt.getHDC()) == 0 ) { - Thread.yield(); - } - // Choose a hardware accelerated pixel format - PIXELFORMATDESCRIPTOR pfd = context.glCapabilities2PFD( caps, true ); - int pixelFormat = WGL.ChoosePixelFormat( tempHDC, pfd ); - if( pixelFormat == 0 ) { - System.err.println("Pixel Format is Zero"); - pendingContextSet.remove(device); - return; - } - // Set the hardware accelerated pixel format - if (!WGL.SetPixelFormat(tempHDC, pixelFormat, pfd)) { - System.err.println("SetPixelFormat Failed"); - pendingContextSet.remove( device ); - return; - } - // Create a rendering context - long tempHGLRC = WGL.wglCreateContext( tempHDC ); - if( hWnd == 0 || tempHDC == 0 || tempHGLRC == 0 ) { - pendingContextSet.remove( device ); - return; - } - // Store native handles for later use - NativeWindowStruct nws = new NativeWindowStruct(); - nws.setHWND( hWnd ); - nws.setWindowsContext( context ); - nws.setWindowThread( nwt ); - long currentHDC = WGL.wglGetCurrentDC(); - long currentHGLRC = WGL.wglGetCurrentContext(); - // Make the new hardware accelerated context current - if( !WGL.wglMakeCurrent( tempHDC, tempHGLRC ) ) { - pendingContextSet.remove( device ); - return; - } - // Grab function pointers - context.hdc = tempHDC; - context.hglrc = tempHGLRC; - context.resetGLFunctionAvailability(); - context.createGL(); - pendingContextSet.remove( device ); - dummyContextMap.put( device, nws ); - String availableGLExtensions = ""; - String availableWGLExtensions = ""; - String availableEXTExtensions = ""; - try { - availableWGLExtensions = context.getGL().wglGetExtensionsStringARB( currentHDC ); - } catch( GLException e ) { - } - try { - availableEXTExtensions = context.getGL().wglGetExtensionsStringEXT(); - } catch( GLException e ) { - } - availableGLExtensions = context.getGL().glGetString( GL.GL_EXTENSIONS ); - dummyExtensionsMap.put(device, availableGLExtensions + " " + availableEXTExtensions + " " + availableWGLExtensions); - WGL.wglMakeCurrent( currentHDC, currentHGLRC ); - } - } - - /* - * This class stores handles to native resources that need to be destroyed - * at JVM shutdown. - */ - static class NativeWindowStruct { - private long HWND; - private WindowsGLContext windowsContext; - private Thread windowThread; - - public NativeWindowStruct() { - } - - public long getHDC() { - return( windowsContext.hdc ); - } - - public long getHGLRC() { - return( windowsContext.hglrc ); - } - - public void setHWND( long hwnd ) { - HWND = hwnd; - } - - public long getHWND() { - return( HWND ); - } - - public void setWindowsContext( WindowsGLContext context ) { - windowsContext = context; - } - - public WindowsGLContext getWindowsContext() { - return( windowsContext ); - } - - public void setWindowThread( Thread thread ) { - windowThread = thread; - } - - public Thread getWindowThread() { - return( windowThread ); - } - } - - /* - * Native HWDN and HDC handles must be created and destroyed on the same - * thread. - */ - - static class NativeWindowThread extends Thread { - private long HWND = 0; - private long HDC = 0; - private Rectangle rectangle; - - public NativeWindowThread( Rectangle rect ) { - rectangle = rect; - } - - public synchronized long getHWND() { - return( HWND ); - } - - public synchronized long getHDC() { - return( HDC ); - } - - public void run() { - // Create a native window and device context - synchronized (WindowsGLContextFactory.class) { - HWND = WGL.CreateDummyWindow( rectangle.x, rectangle.y, rectangle.width, rectangle.height ); - } - HDC = WGL.GetDC( HWND ); - - // Start the message pump at shutdown - WGL.NativeEventLoop(); - } - } - - /* - * This class is registered with the JVM to destroy all cached redering - * contexts, device contexts, and window handles. - */ - - class ShutdownHook extends Thread { - public void run() { - // Collect all saved screen resources - Collection c = dummyContextMap.values(); - Iterator iter = c.iterator(); - while( iter.hasNext() ) { - // NativeWindowStruct holds refs to native resources that need to be destroyed - NativeWindowStruct struct = (NativeWindowStruct)iter.next(); - // Restart native window threads to respond to window closing events - synchronized( struct.getWindowThread() ) { - struct.getWindowThread().notifyAll(); - } - // Destroy OpenGL rendering context - if( !WGL.wglDeleteContext( struct.getHGLRC() ) ) { - System.err.println( "Error Destroying NativeWindowStruct RC: " + WGL.GetLastError() ); - } - // Send context handles to native method for deletion - WGL.DestroyDummyWindow( struct.getHWND(), struct.getHDC() ); - } - } - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java deleted file mode 100644 index 0dc1818fb..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.windows; - -import java.awt.Component; -import java.util.*; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsOnscreenGLContext extends WindowsGLContext { - // Variables for lockSurface/unlockSurface - JAWT_DrawingSurface ds; - JAWT_DrawingSurfaceInfo dsi; - JAWT_Win32DrawingSurfaceInfo win32dsi; - - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); - - public WindowsOnscreenGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - public void invokeGL(Runnable runnable, boolean isReshape, Runnable initAction) throws GLException { - // Unfortunately, invokeGL can be called with the AWT tree lock - // held, and the Windows onscreen implementation of - // choosePixelFormatAndCreateContext calls - // Component.getGraphicsConfiguration(), which grabs the tree - // lock. To avoid deadlock we have to lock the tree lock before - // grabbing the GLContext's lock if we're going to create an - // OpenGL context during this call. This code might not be - // completely correct, and we might need to uniformly grab the AWT - // tree lock, which might become a performance issue... - if (hglrc == 0) { - synchronized(component.getTreeLock()) { - super.invokeGL(runnable, isReshape, initAction); - } - } else { - super.invokeGL(runnable, isReshape, initAction); - } - } - - protected GL createGL() - { - return new WindowsGLImpl(this); - } - - protected boolean isOffscreen() { - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - public boolean canCreatePbufferContext() { - return haveWGLARBPbuffer(); - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - WindowsPbufferGLContext ctx = new WindowsPbufferGLContext(capabilities, initialWidth, initialHeight); - pbuffersToInstantiate.add(ctx); - return ctx; - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - try { - if (!lockSurface()) { - return false; - } - boolean ret = super.makeCurrent(initAction); - if (ret) { - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - WindowsPbufferGLContext ctx = - (WindowsPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - ctx.createPbuffer(hdc, hglrc); - } - } - return ret; - } catch (RuntimeException e) { - try { - unlockSurface(); - } catch (Exception e2) { - // do nothing if unlockSurface throws - } - throw(e); - } - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - unlockSurface(); - } - } - - public synchronized void swapBuffers() throws GLException { - if (!WGL.SwapBuffers(hdc) && (WGL.GetLastError() != 0)) { - throw new GLException("Error swapping buffers"); - } - } - - private boolean lockSurface() throws GLException { - if (hdc != 0) { - throw new GLException("Surface already locked"); - } - ds = getJAWT().GetDrawingSurface(component); - if (ds == null) { - // Widget not yet realized - return false; - } - int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new GLException("Unable to lock surface"); - } - // See whether the surface changed and if so destroy the old - // OpenGL context so it will be recreated (NOTE: removeNotify - // should handle this case, but it may be possible that race - // conditions can cause this code to be triggered -- should test - // more) - if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { - if (hglrc != 0) { - if (!WGL.wglDeleteContext(hglrc)) { - throw new GLException("Unable to delete old GL context after surface changed"); - } - GLContextShareSet.contextDestroyed(this); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + hglrc + " due to JAWT_LOCK_SURFACE_CHANGED"); - } - hglrc = 0; - } - } - dsi = ds.GetDrawingSurfaceInfo(); - if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - return false; - } - win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); - hdc = win32dsi.hdc(); - if (hdc == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - win32dsi = null; - return false; - } - return true; - } - - private void unlockSurface() { - if (hdc == 0) { - throw new GLException("Surface already unlocked"); - } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - win32dsi = null; - hdc = 0; - } - - protected void create() { - choosePixelFormatAndCreateContext(true); - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java deleted file mode 100644 index 1d5d78296..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.windows; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsPbufferGLContext extends WindowsGLContext { - private static final boolean DEBUG = Debug.debug("WindowsPbufferGLContext"); - - private int initWidth; - private int initHeight; - - private long buffer; // pbuffer handle - private int width; - private int height; - - // FIXME: kept around because we create the OpenGL context lazily to - // better integrate with the WindowsGLContext framework - private long parentHglrc; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - // State for render-to-texture and render-to-texture-rectangle support - private boolean created; - private boolean rtt; // render-to-texture? - private boolean hasRTT; // render-to-texture extension available? - private boolean rect; // render-to-texture-rectangle? - private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV - private int texture; // actual texture object - private int floatMode; - - public WindowsPbufferGLContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - super(null, capabilities, null, null); - this.initWidth = initialWidth; - this.initHeight = initialHeight; - if (initWidth <= 0 || initHeight <= 0) { - throw new GLException("Initial width and height of pbuffer must be positive (were (" + - initWidth + ", " + initHeight + "))"); - } - - if (DEBUG) { - System.out.println("Pbuffer caps on init: " + capabilities + - (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + - (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + - (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); - } - } - - public boolean canCreatePbufferContext() { - return false; - } - - public GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - if (!rtt) { - throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its GLCapabilities"); - } - GL gl = getGL(); - gl.glBindTexture(textureTarget, texture); - if (rtt && hasRTT) { - if (!gl.wglBindTexImageARB(buffer, GL.WGL_FRONT_LEFT_ARB)) { - throw new GLException("Binding of pbuffer to texture failed: " + wglGetLastError()); - } - } - // Note that if the render-to-texture extension is not supported, - // we perform a glCopyTexImage2D in swapBuffers(). - } - - public void releasePbufferFromTexture() { - if (!rtt) { - throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its GLCapabilities"); - } - if (rtt && hasRTT) { - GL gl = getGL(); - if (!gl.wglReleaseTexImageARB(buffer, GL.WGL_FRONT_LEFT_ARB)) { - throw new GLException("Releasing of pbuffer from texture failed: " + wglGetLastError()); - } - } - } - - public void createPbuffer(long parentHdc, long parentHglrc) { - GL gl = getGL(); - // Must initally grab OpenGL function pointers while parent's - // context is current because otherwise we don't have the wgl - // extensions available to us - resetGLFunctionAvailability(); - - int[] iattributes = new int [2*MAX_ATTRIBS]; - float[] fattributes = new float[2*MAX_ATTRIBS]; - int nfattribs = 0; - int niattribs = 0; - - if (DEBUG) { - System.out.println("Pbuffer caps: " + capabilities + - (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + - (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + - (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); - } - - rtt = capabilities.getOffscreenRenderToTexture(); - rect = capabilities.getOffscreenRenderToTextureRectangle(); - boolean useFloat = capabilities.getOffscreenFloatingPointBuffers(); - boolean ati = false; - - // Since we are trying to create a pbuffer, the pixel format we - // request (and subsequently use) must be "p-buffer capable". - iattributes[niattribs++] = GL.WGL_DRAW_TO_PBUFFER_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - - if (rtt && !rect) { - throw new GLException("Render-to-texture-rectangle requires render-to-texture to be specified"); - } - - if (rect) { - if (!gl.isExtensionAvailable("GL_NV_texture_rectangle")) { - throw new GLException("Render-to-texture-rectangle requires GL_NV_texture_rectangle extension"); - } - } - - if (useFloat) { - if (!gl.isExtensionAvailable("WGL_ATI_pixel_format_float") && - !gl.isExtensionAvailable("WGL_NV_float_buffer")) { - throw new GLException("Floating-point pbuffers not supported by this hardware"); - } - - // Prefer NVidia extension over ATI - if (gl.isExtensionAvailable("WGL_NV_float_buffer")) { - ati = false; - floatMode = GLPbuffer.NV_FLOAT; - } else { - ati = true; - floatMode = GLPbuffer.ATI_FLOAT; - } - if (DEBUG) { - System.err.println("Using " + (ati ? "ATI" : "NVidia") + " floating-point extension"); - } - } - - if (useFloat && ati) { - if (rtt) { - throw new GLException("Render-to-floating-point-texture not supported on ATI hardware"); - } else { - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_FLOAT_ATI; - } - } else { - if (!rtt) { - // Currently we don't support non-truecolor visuals in the - // GLCapabilities, so we don't offer the option of making - // color-index pbuffers. - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; - } - } - - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = capabilities.getDepthBits(); - - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getRedBits(); - - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getGreenBits(); - - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getBlueBits(); - - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAlphaBits(); - - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - if (capabilities.getStencilBits() > 0) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0) { - iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - } - - if (useFloat && !ati) { - iattributes[niattribs++] = GL.WGL_FLOAT_COMPONENTS_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } - - if (rtt) { - if (useFloat) { - assert(!ati); - if (!rect) { - throw new GLException("Render-to-floating-point-texture only supported on NVidia hardware with render-to-texture-rectangle"); - } - iattributes[niattribs++] = GL.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = rect ? GL.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : GL.WGL_BIND_TO_TEXTURE_RGB_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - } - } - - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - - int[] pformats = new int[MAX_PFORMATS]; - int nformats; - int[] nformatsTmp = new int[1]; - if (!gl.wglChoosePixelFormatARB(parentHdc, - iattributes, - fattributes, - MAX_PFORMATS, - pformats, - nformatsTmp)) { - throw new GLException("pbuffer creation error: wglChoosePixelFormatARB() failed"); - } - nformats = nformatsTmp[0]; - if (nformats <= 0) { - throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); - } - - if (DEBUG) { - System.err.println("" + nformats + " suitable pixel formats found"); - // query pixel format - iattributes[0] = GL.WGL_RED_BITS_ARB; - iattributes[1] = GL.WGL_GREEN_BITS_ARB; - iattributes[2] = GL.WGL_BLUE_BITS_ARB; - iattributes[3] = GL.WGL_ALPHA_BITS_ARB; - iattributes[4] = GL.WGL_DEPTH_BITS_ARB; - iattributes[5] = (useFloat ? (ati ? GL.WGL_PIXEL_TYPE_ARB : GL.WGL_FLOAT_COMPONENTS_NV) : GL.WGL_RED_BITS_ARB); - iattributes[6] = GL.WGL_SAMPLE_BUFFERS_EXT; - iattributes[7] = GL.WGL_SAMPLES_EXT; - iattributes[8] = GL.WGL_DRAW_TO_PBUFFER_ARB; - int[] ivalues = new int[9]; - for (int i = 0; i < nformats; i++) { - if (!gl.wglGetPixelFormatAttribivARB(parentHdc, pformats[i], 0, 9, iattributes, ivalues)) { - throw new GLException("Error while querying pixel format " + pformats[i] + - "'s (index " + i + "'s) capabilities for debugging"); - } - System.err.print("pixel format " + pformats[i] + " (index " + i + "): "); - System.err.print( "r: " + ivalues[0]); - System.err.print(" g: " + ivalues[1]); - System.err.print(" b: " + ivalues[2]); - System.err.print(" a: " + ivalues[3]); - System.err.print(" depth: " + ivalues[4]); - System.err.print(" multisample: " + ivalues[6]); - System.err.print(" samples: " + ivalues[7]); - if (useFloat) { - if (ati) { - if (ivalues[5] == GL.WGL_TYPE_RGBA_FLOAT_ATI) { - System.err.print(" [ati float]"); - } else if (ivalues[5] != GL.WGL_TYPE_RGBA_ARB) { - System.err.print(" [unknown pixel type " + ivalues[5] + "]"); - } - } else { - if (ivalues[5] != 0) { - System.err.print(" [float]"); - } - } - } - - if (ivalues[8] != 0) { - System.err.print(" [pbuffer]"); - } - System.err.println(); - } - } - - long tmpBuffer = 0; - int whichFormat = 0; - // Loop is a workaround for bugs in NVidia's recent drivers - do { - int format = pformats[whichFormat]; - - // Create the p-buffer. - niattribs = 0; - - if (rtt) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FORMAT_ARB; - if (useFloat) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FLOAT_RGB_NV; - } else { - iattributes[niattribs++] = GL.WGL_TEXTURE_RGBA_ARB; - } - - iattributes[niattribs++] = GL.WGL_TEXTURE_TARGET_ARB; - iattributes[niattribs++] = rect ? GL.WGL_TEXTURE_RECTANGLE_NV : GL.WGL_TEXTURE_2D_ARB; - - iattributes[niattribs++] = GL.WGL_MIPMAP_TEXTURE_ARB; - iattributes[niattribs++] = GL.GL_FALSE; - - iattributes[niattribs++] = GL.WGL_PBUFFER_LARGEST_ARB; - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = 0; - - tmpBuffer = gl.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes); - ++whichFormat; - } while ((tmpBuffer == 0) && (whichFormat < nformats)); - - if (tmpBuffer == 0) { - throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: tried " + nformats + - " pixel formats, last error was: " + wglGetLastError()); - } - - // Get the device context. - long tmpHdc = gl.wglGetPbufferDCARB(tmpBuffer); - if (tmpHdc == 0) { - throw new GLException("pbuffer creation error: wglGetPbufferDCARB() failed"); - } - - this.parentHglrc = parentHglrc; - - // Set up instance variables - buffer = tmpBuffer; - hdc = tmpHdc; - - // Determine the actual width and height we were able to create. - int[] tmp = new int[1]; - gl.wglQueryPbufferARB( buffer, GL.WGL_PBUFFER_WIDTH_ARB, tmp ); - width = tmp[0]; - gl.wglQueryPbufferARB( buffer, GL.WGL_PBUFFER_HEIGHT_ARB, tmp ); - height = tmp[0]; - - if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - created = false; - - if (buffer == 0) { - // pbuffer not instantiated yet - if (DEBUG) { - System.err.println("pbuffer not instantiated yet"); - } - return false; - } - - boolean res = super.makeCurrent(initAction); - if (DEBUG) { - System.err.println("super.makeCurrent() = " + res + ", created = " + created); - } - if (created) { - // Initialize render-to-texture support if requested - rtt = capabilities.getOffscreenRenderToTexture(); - rect = capabilities.getOffscreenRenderToTextureRectangle(); - - if (rtt) { - if (DEBUG) { - System.err.println("Initializing render-to-texture support"); - } - - if (!gl.isExtensionAvailable("WGL_ARB_render_texture")) { - System.err.println("WindowsPbufferGLContext: WARNING: WGL_ARB_render_texture extension not " + - "supported; implementing render_to_texture support using slow texture readback"); - } else { - hasRTT = true; - GL gl = getGL(); - - if (rect && !gl.isExtensionAvailable("GL_NV_texture_rectangle")) { - System.err.println("WindowsPbufferGLContext: WARNING: GL_NV_texture_rectangle extension not " + - "supported; skipping requested render_to_texture_rectangle support for pbuffer"); - rect = false; - } - if (rect) { - if (DEBUG) { - System.err.println(" Using render-to-texture-rectangle"); - } - textureTarget = GL.GL_TEXTURE_RECTANGLE_NV; - } else { - if (DEBUG) { - System.err.println(" Using vanilla render-to-texture"); - } - textureTarget = GL.GL_TEXTURE_2D; - } - int[] tmp = new int[1]; - gl.glGenTextures(1, tmp); - texture = tmp[0]; - gl.glBindTexture(textureTarget, texture); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); - gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, width, height, 0); - } - } - } - return res; - } - - public void handleModeSwitch(long parentHdc, long parentHglrc) { - throw new GLException("Not yet implemented"); - } - - protected boolean isOffscreen() { - // FIXME: currently the only caller of this won't cause proper - // resizing of the pbuffer anyway. - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - protected void create() { - created = true; - // Create a gl context for the p-buffer. - hglrc = WGL.wglCreateContext(hdc); - if (hglrc == 0) { - throw new GLException("pbuffer creation error: wglCreateContext() failed"); - } - - // FIXME: provide option to not share display lists with subordinate pbuffer? - if (!WGL.wglShareLists(parentHglrc, hglrc)) { - throw new GLException("pbuffer: wglShareLists() failed"); - } - } - - protected void destroyImpl() throws GLException { - if (hglrc != 0) { - super.destroyImpl(); - // Must release DC and pbuffer - // NOTE that since the context is not current, glGetError() can - // not be called here, so we skip the use of any composable - // pipelines - GL gl = createGL(); - if (gl.wglReleasePbufferDCARB(buffer, hdc) == 0) { - throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); - } - hdc = 0; - if (!gl.wglDestroyPbufferARB(buffer)) { - throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); - } - buffer = 0; - } - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - // For now, just grab the pixels for the render-to-texture support. - if (rtt && !hasRTT) { - if (DEBUG) { - System.err.println("Copying pbuffer data to GL_TEXTURE_2D state"); - } - - GL gl = getGL(); - gl.glCopyTexSubImage2D(textureTarget, 0, 0, 0, 0, 0, width, height); - } - } - - public int getFloatingPointMode() { - return floatMode; - } - - private String wglGetLastError() { - int err = WGL.GetLastError(); - String detail = null; - switch (err) { - case WGL.ERROR_INVALID_PIXEL_FORMAT: detail = "ERROR_INVALID_PIXEL_FORMAT"; break; - case WGL.ERROR_NO_SYSTEM_RESOURCES: detail = "ERROR_NO_SYSTEM_RESOURCES"; break; - case WGL.ERROR_INVALID_DATA: detail = "ERROR_INVALID_DATA"; break; - case WGL.ERROR_PROC_NOT_FOUND: detail = "ERROR_PROC_NOT_FOUND"; break; - case WGL.ERROR_INVALID_WINDOW_HANDLE:detail = "ERROR_INVALID_WINDOW_HANDLE"; break; - default: detail = "(Unknown error code " + err + ")"; break; - } - return detail; - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java deleted file mode 100644 index 53f44101f..000000000 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.x11; - -import java.awt.Component; -import java.security.*; -import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public abstract class X11GLContext extends GLContext { - protected long display; - protected long drawable; - protected long visualID; - protected long context; - private boolean glXQueryExtensionsStringInitialized; - private boolean glXQueryExtensionsStringAvailable; - private static final Map/*<String, String>*/ functionNameMap; - private boolean isGLX13; - // Table that holds the addresses of the native C-language entry points for - // OpenGL functions. - private GLProcAddressTable glProcAddressTable; - private static boolean haveResetGLXProcAddressTable; - // Cache the most recent value of the "display" variable (which we - // only guarantee to be valid in between makeCurrent / free pairs) - // so that we can implement displayImpl() (which must be done when - // the context is not current) - protected long mostRecentDisplay; - // There is currently a bug on Linux/AMD64 distributions in glXGetProcAddressARB - protected static boolean isLinuxAMD64; - - static { - functionNameMap = new HashMap(); - functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); - functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); - - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String os = System.getProperty("os.name").toLowerCase(); - String arch = System.getProperty("os.arch").toLowerCase(); - if (os.startsWith("linux") && arch.equals("amd64")) { - isLinuxAMD64 = true; - } - return null; - } - }); - } - - public X11GLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } - - protected abstract boolean isOffscreen(); - - public int getOffscreenContextWidth() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextHeight() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - - public synchronized void setRenderingThread(Thread currentThreadOrNull, Runnable initAction) { - this.willSetRenderingThread = false; - // FIXME: the JAWT on X11 grabs the AWT lock while the - // DrawingSurface is locked, which means that no other events can - // be processed. Currently we handle this by preventing the - // effects of setRenderingThread. We should figure out a better - // solution that is reasonably robust. Must file a bug to be fixed - // in the 1.5 JAWT. - } - - /** - * Creates and initializes an appropriate OpenGl context. Should only be - * called by {@link makeCurrent(Runnable)}. - */ - protected abstract void create(); - - public boolean isExtensionAvailable(String glExtensionName) { - if (glExtensionName.equals("GL_ARB_pbuffer") || - glExtensionName.equals("GL_ARB_pixel_format")) { - return isGLX13; - } - return super.isExtensionAvailable(glExtensionName); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - boolean created = false; - if (context == 0) { - create(); - if (DEBUG) { - System.err.println("!!! Created GL context for " + getClass().getName()); - } - created = true; - } - if (drawable == 0) { - throw new GLException("Unable to make context current; drawable was null"); - } - - // FIXME: this cast to int would be wrong on 64-bit platforms - // where the argument type to glXMakeCurrent would change (should - // probably make GLXDrawable, and maybe XID, Opaque as long) - if (!GLX.glXMakeCurrent(display, (int) drawable, context)) { - throw new GLException("Error making context current"); - } - - if (created) { - resetGLFunctionAvailability(); - initAction.run(); - } - return true; - } - - protected synchronized void free() throws GLException { - if (!GLX.glXMakeCurrent(display, 0, 0)) { - throw new GLException("Error freeing OpenGL context"); - } - } - - protected void destroyImpl() throws GLException { - lockAWT(); - if (context != 0) { - GLX.glXDestroyContext(mostRecentDisplay, context); - if (DEBUG) { - System.err.println("!!! Destroyed OpenGL context " + context); - } - context = 0; - } - unlockAWT(); - } - - public abstract void swapBuffers() throws GLException; - - protected long dynamicLookupFunction(String glFuncName) { - long res = 0; - if (!isLinuxAMD64) { - res = GLX.glXGetProcAddressARB(glFuncName); - } - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - res = GLX.dlsym(glFuncName); - } - return res; - } - - public boolean isCreated() { - return (context != 0); - } - - protected void resetGLFunctionAvailability() { - super.resetGLFunctionAvailability(); - if (DEBUG) { - System.err.println("!!! Initializing OpenGL extension address table"); - } - resetProcAddressTable(getGLProcAddressTable()); - - if (!haveResetGLXProcAddressTable) { - resetProcAddressTable(GLX.getGLXProcAddressTable()); - } - - // Figure out whether we are running GLX version 1.3 or above and - // therefore have pbuffer support - if (display == 0) { - throw new GLException("Expected non-null DISPLAY for querying GLX version"); - } - int[] major = new int[1]; - int[] minor = new int[1]; - if (!GLX.glXQueryVersion(display, major, minor)) { - throw new GLException("glXQueryVersion failed"); - } - if (DEBUG) { - System.err.println("!!! GLX version: major " + major[0] + - ", minor " + minor[0]); - } - - // Work around bugs in ATI's Linux drivers where they report they - // only implement GLX version 1.2 but actually do support pbuffers - if (major[0] == 1 && minor[0] == 2) { - GL gl = getGL(); - String str = gl.glGetString(GL.GL_VENDOR); - if (str != null && str.indexOf("ATI") >= 0) { - isGLX13 = true; - return; - } - } - - isGLX13 = ((major[0] > 1) || (minor[0] > 2)); - } - - public GLProcAddressTable getGLProcAddressTable() { - if (glProcAddressTable == null) { - // FIXME: cache ProcAddressTables by capability bits so we can - // share them among contexts with the same capabilities - glProcAddressTable = new GLProcAddressTable(); - } - return glProcAddressTable; - } - - public synchronized String getPlatformExtensionsString() { - if (display == 0) { - throw new GLException("Context not current"); - } - if (!glXQueryExtensionsStringInitialized) { - glXQueryExtensionsStringAvailable = (dynamicLookupFunction("glXQueryExtensionsString") != 0); - glXQueryExtensionsStringInitialized = true; - } - if (glXQueryExtensionsStringAvailable) { - lockAWT(); - try { - String ret = GLX.glXQueryExtensionsString(display, GLX.DefaultScreen(display)); - if (DEBUG) { - System.err.println("!!! GLX extensions: " + ret); - } - return ret; - } finally { - unlockAWT(); - } - } else { - return ""; - } - } - - protected boolean isFunctionAvailable(String glFunctionName) - { - boolean available = super.isFunctionAvailable(glFunctionName); - - // Sanity check for implementations that use proc addresses for run-time - // linking: if the function IS available, then make sure there's a proc - // address for it if it's an extension or not part of the OpenGL 1.1 core - // (post GL 1.1 functions are run-time linked on windows). - assert(!available || - (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || - FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) - ); - - return available; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - protected JAWT getJAWT() { - return X11GLContextFactory.getJAWT(); - } - - protected XVisualInfo chooseVisual() { - if (!isOffscreen()) { - // The visual has already been chosen by the time we get here; - // it's specified by the GraphicsConfiguration of the - // GLCanvas. Fortunately, the JAWT supplies the visual ID for - // the component in a portable fashion, so all we have to do is - // use XGetVisualInfo with a VisualIDMask to get the - // corresponding XVisualInfo to pass into glXChooseVisual. - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - // FIXME: probably not 64-bit clean - template.visualid((int) visualID); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count); - if (infos == null || infos.length == 0) { - throw new GLException("Error while getting XVisualInfo for visual ID " + visualID); - } - // FIXME: the storage for the infos array is leaked (should - // clean it up somehow when we're done with the visual we're - // returning) - return infos[0]; - } else { - // It isn't clear to me whether we need this much code to handle - // the offscreen case, where we're creating a pixmap into which - // to render...this is what we (incorrectly) used to do for the - // onscreen case - - int screen = 0; // FIXME: provide way to specify this? - XVisualInfo vis = null; - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - template.screen(screen); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); - if (infos == null) { - throw new GLException("Error while enumerating available XVisualInfos"); - } - GLCapabilities[] caps = new GLCapabilities[infos.length]; - for (int i = 0; i < infos.length; i++) { - caps[i] = X11GLContextFactory.xvi2GLCapabilities(display, infos[i]); - } - int chosen = chooser.chooseCapabilities(capabilities, caps, -1); - if (chosen < 0 || chosen >= caps.length) { - throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); - } - if (DEBUG) { - System.err.println("Chosen visual (" + chosen + "):"); - System.err.println(caps[chosen]); - } - vis = infos[chosen]; - if (vis == null) { - throw new GLException("GLCapabilitiesChooser chose an invalid visual"); - } - // FIXME: the storage for the infos array is leaked (should - // clean it up somehow when we're done with the visual we're - // returning) - - return vis; - } - } - - protected long createContext(XVisualInfo vis, boolean onscreen) { - X11GLContext other = (X11GLContext) GLContextShareSet.getShareContext(this); - long share = 0; - if (other != null) { - share = other.getContext(); - if (share == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - } - long res = GLX.glXCreateContext(display, vis, share, onscreen); - if (res != 0) { - GLContextShareSet.contextCreated(this); - } - return res; - } - - // Helper routine for the overridden create() to call - protected void chooseVisualAndCreateContext(boolean onscreen) { - XVisualInfo vis = chooseVisual(); - context = createContext(vis, onscreen); - if (context == 0) { - throw new GLException("Unable to create OpenGL context"); - } - } - - protected long getContext() { - return context; - } - - // These synchronization primitives prevent the AWT from making - // requests from the X server asynchronously to this code. - protected void lockAWT() { - X11GLContextFactory.lockAWT(); - } - - protected void unlockAWT() { - X11GLContextFactory.unlockAWT(); - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java deleted file mode 100644 index 8f0aa06a5..000000000 --- a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.x11; - -import java.awt.image.BufferedImage; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11OffscreenGLContext extends X11GLContext { - private long pixmap; - private boolean isDoubleBuffered; - // Width and height of the underlying bitmap - private int width; - private int height; - - public X11OffscreenGLContext(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(null, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - - protected boolean isOffscreen() { - return true; - } - - public int getOffscreenContextWidth() { - return width; - } - - public int getOffscreenContextHeight() { - return height; - } - - public int getOffscreenContextPixelDataType() { - return GL.GL_UNSIGNED_BYTE; - } - - public int getOffscreenContextReadBuffer() { - if (isDoubleBuffered) { - return GL.GL_BACK; - } - return GL.GL_FRONT; - } - - public boolean offscreenImageNeedsVerticalFlip() { - // There doesn't seem to be a way to do this in the construction - // of the Pixmap or GLXPixmap - return true; - } - - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - display = X11GLContextFactory.getDisplayConnection(); - if (pendingOffscreenResize) { - if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - if (context != 0) { - destroy(); - } - width = pendingOffscreenWidth; - height = pendingOffscreenHeight; - pendingOffscreenResize = false; - } - } - mostRecentDisplay = display; - return super.makeCurrent(initAction); - } - - public synchronized void swapBuffers() throws GLException { - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - display = 0; - } - } - - protected void create() { - XVisualInfo vis = chooseVisual(); - int bitsPerPixel = vis.depth(); - - if (display == 0) { - throw new GLException("No active display"); - } - int screen = GLX.DefaultScreen(display); - pixmap = GLX.XCreatePixmap(display, (int) GLX.RootWindow(display, screen), width, height, bitsPerPixel); - if (pixmap == 0) { - throw new GLException("XCreatePixmap failed"); - } - drawable = GLX.glXCreateGLXPixmap(display, vis, pixmap); - if (drawable == 0) { - throw new GLException("glXCreateGLXPixmap failed"); - } - context = createContext(vis, false); - if (context == 0) { - throw new GLException("Unable to create OpenGL context"); - } - isDoubleBuffered = (X11GLContextFactory.glXGetConfig(display, vis, GLX.GLX_DOUBLEBUFFER, new int[1]) != 0); - } - - protected void destroyImpl() { - if (context != 0) { - super.destroyImpl(); - // Must destroy OpenGL context, pixmap and GLXPixmap - GLX.glXDestroyContext(display, context); - GLX.glXDestroyGLXPixmap(display, (int) drawable); - GLX.XFreePixmap(display, pixmap); - context = 0; - drawable = 0; - pixmap = 0; - GLContextShareSet.contextDestroyed(this); - } - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java deleted file mode 100644 index d9f18a760..000000000 --- a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.impl.x11; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11PbufferGLContext extends X11GLContext { - private static final boolean DEBUG = Debug.debug("X11PbufferGLContext"); - - private int initWidth; - private int initHeight; - - private long buffer; // GLXPbuffer - private GLXFBConfig fbConfig; - private int width; - private int height; - - // FIXME: kept around because we create the OpenGL context lazily to - // better integrate with the X11GLContext framework - private long parentContext; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - public X11PbufferGLContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - super(null, capabilities, null, null); - this.initWidth = initialWidth; - this.initHeight = initialHeight; - if (initWidth <= 0 || initHeight <= 0) { - throw new GLException("Initial width and height of pbuffer must be positive (were (" + - initWidth + ", " + initHeight + "))"); - } - } - - public boolean canCreatePbufferContext() { - return false; - } - - public GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - // FIXME: figure out how to implement this - throw new GLException("Not yet implemented"); - } - - public void releasePbufferFromTexture() { - // FIXME: figure out how to implement this - throw new GLException("Not yet implemented"); - } - - public void createPbuffer(long display, long parentContext, GL gl) { - if (display == 0) { - throw new GLException("Null display"); - } - - if (parentContext == 0) { - throw new GLException("Null parentContext"); - } - - if (capabilities.getOffscreenRenderToTexture()) { - throw new GLException("Render-to-texture pbuffers not supported yet on X11"); - } - - if (capabilities.getOffscreenRenderToTextureRectangle()) { - throw new GLException("Render-to-texture-rectangle pbuffers not supported yet on X11"); - } - - int[] iattributes = new int [2*MAX_ATTRIBS]; - float[] fattributes = new float[2*MAX_ATTRIBS]; - int nfattribs = 0; - int niattribs = 0; - - // Since we are trying to create a pbuffer, the GLXFBConfig we - // request (and subsequently use) must be "p-buffer capable". - iattributes[niattribs++] = GL.GLX_DRAWABLE_TYPE; - iattributes[niattribs++] = GL.GLX_PBUFFER_BIT; - - iattributes[niattribs++] = GL.GLX_RENDER_TYPE; - iattributes[niattribs++] = GL.GLX_RGBA_BIT; - - iattributes[niattribs++] = GLX.GLX_DOUBLEBUFFER; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = GLX.GLX_DEPTH_SIZE; - iattributes[niattribs++] = capabilities.getDepthBits(); - - iattributes[niattribs++] = GLX.GLX_RED_SIZE; - iattributes[niattribs++] = capabilities.getRedBits(); - - iattributes[niattribs++] = GLX.GLX_GREEN_SIZE; - iattributes[niattribs++] = capabilities.getGreenBits(); - - iattributes[niattribs++] = GLX.GLX_BLUE_SIZE; - iattributes[niattribs++] = capabilities.getBlueBits(); - - iattributes[niattribs++] = GLX.GLX_ALPHA_SIZE; - iattributes[niattribs++] = capabilities.getAlphaBits(); - - if (capabilities.getStencilBits() > 0) { - iattributes[niattribs++] = GLX.GLX_STENCIL_SIZE; - iattributes[niattribs++] = capabilities.getStencilBits(); - } - - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0) { - iattributes[niattribs++] = GLX.GLX_ACCUM_RED_SIZE; - iattributes[niattribs++] = capabilities.getAccumRedBits(); - iattributes[niattribs++] = GLX.GLX_ACCUM_GREEN_SIZE; - iattributes[niattribs++] = capabilities.getAccumGreenBits(); - iattributes[niattribs++] = GLX.GLX_ACCUM_BLUE_SIZE; - iattributes[niattribs++] = capabilities.getAccumBlueBits(); - } - - if (capabilities.getOffscreenFloatingPointBuffers()) { - if (!gl.isExtensionAvailable("GLX_NV_float_buffer")) { - throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware"); - } - iattributes[niattribs++] = GLX.GLX_FLOAT_COMPONENTS_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } - - // FIXME: add FSAA support? Don't want to get into a situation - // where we have to retry the glXChooseFBConfig call if it fails - // due to a lack of an antialiased visual... - - iattributes[niattribs++] = 0; // null-terminate - - int screen = 0; // FIXME: provide way to specify this? - int[] nelementsTmp = new int[1]; - GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, nelementsTmp); - if (fbConfigs == null || fbConfigs.length == 0 || fbConfigs[0] == null) { - throw new GLException("pbuffer creation error: glXChooseFBConfig() failed"); - } - // Note that we currently don't allow selection of anything but - // the first GLXFBConfig in the returned list - GLXFBConfig fbConfig = fbConfigs[0]; - int nelements = nelementsTmp[0]; - if (nelements <= 0) { - throw new GLException("pbuffer creation error: couldn't find a suitable frame buffer configuration"); - } - - if (DEBUG) { - System.err.println("Found " + fbConfigs.length + " matching GLXFBConfigs"); - System.err.println("Parameters of default one:"); - System.err.println("render type: 0x" + Integer.toHexString(queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE))); - System.err.println("rgba: " + ((queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE) & GLX.GLX_RGBA_BIT) != 0)); - System.err.println("r: " + queryFBConfig(display, fbConfig, GLX.GLX_RED_SIZE)); - System.err.println("g: " + queryFBConfig(display, fbConfig, GLX.GLX_GREEN_SIZE)); - System.err.println("b: " + queryFBConfig(display, fbConfig, GLX.GLX_BLUE_SIZE)); - System.err.println("a: " + queryFBConfig(display, fbConfig, GLX.GLX_ALPHA_SIZE)); - System.err.println("depth: " + queryFBConfig(display, fbConfig, GLX.GLX_DEPTH_SIZE)); - System.err.println("double buffered: " + queryFBConfig(display, fbConfig, GLX.GLX_DOUBLEBUFFER)); - } - - // Create the p-buffer. - niattribs = 0; - - iattributes[niattribs++] = GL.GLX_PBUFFER_WIDTH; - iattributes[niattribs++] = initWidth; - iattributes[niattribs++] = GL.GLX_PBUFFER_HEIGHT; - iattributes[niattribs++] = initHeight; - - iattributes[niattribs++] = 0; - - long tmpBuffer = GLX.glXCreatePbuffer(display, fbConfig, iattributes); - if (tmpBuffer == 0) { - // FIXME: query X error code for detail error message - throw new GLException("pbuffer creation error: glXCreatePbuffer() failed"); - } - - // Set up instance variables - this.display = display; - mostRecentDisplay = display; - this.parentContext = parentContext; - buffer = tmpBuffer; - this.fbConfig = fbConfig; - - // Determine the actual width and height we were able to create. - int[] tmp = new int[1]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_WIDTH, tmp); - width = tmp[0]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_HEIGHT, tmp); - height = tmp[0]; - - if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (buffer == 0) { - // pbuffer not instantiated yet - return false; - } - - lockAWT(); - try { - boolean created = false; - if (context == 0) { - create(); - if (DEBUG) { - System.err.println("!!! Created GL context for " + getClass().getName()); - } - created = true; - } - - if (!GLX.glXMakeContextCurrent(display, buffer, buffer, context)) { - throw new GLException("Error making context current"); - } - - if (created) { - resetGLFunctionAvailability(); - initAction.run(); - } - return true; - } finally { - unlockAWT(); - } - } - - protected synchronized void free() throws GLException { - lockAWT(); - try { - if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) { - throw new GLException("Error freeing OpenGL context"); - } - } finally { - unlockAWT(); - } - } - - public void handleModeSwitch(long parentHdc, long parentHglrc) { - throw new GLException("Not yet implemented"); - } - - protected boolean isOffscreen() { - // FIXME: currently the only caller of this won't cause proper - // resizing of the pbuffer anyway. - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - protected void create() { - if (DEBUG) { - System.err.println("Creating context for pbuffer " + width + " x " + height); - } - - // Create a gl context for the p-buffer. - // FIXME: provide option to not share display lists with subordinate pbuffer? - context = GLX.glXCreateNewContext(display, fbConfig, GL.GLX_RGBA_TYPE, parentContext, true); - if (context == 0) { - throw new GLException("pbuffer creation error: glXCreateNewContext() failed"); - } - - if (DEBUG) { - System.err.println("Created context for pbuffer " + width + " x " + height); - } - } - - protected void destroyImpl() throws GLException { - lockAWT(); - try { - if (context != 0) { - super.destroyImpl(); - GLX.glXDestroyPbuffer(display, buffer); - buffer = 0; - } - } finally { - unlockAWT(); - } - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - } - - public int getFloatingPointMode() { - // Floating-point pbuffers currently require NVidia hardware on X11 - return GLPbuffer.NV_FLOAT; - } - - private int queryFBConfig(long display, GLXFBConfig fbConfig, int attrib) { - int[] tmp = new int[1]; - if (GLX.glXGetFBConfigAttrib(display, fbConfig, attrib, tmp) != 0) { - throw new GLException("glXGetFBConfigAttrib failed"); - } - return tmp[0]; - } -} diff --git a/src/net/java/games/jogl/util/BufferUtils.java b/src/net/java/games/jogl/util/BufferUtils.java deleted file mode 100644 index 903a27366..000000000 --- a/src/net/java/games/jogl/util/BufferUtils.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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 - * MICROSYSTEMS, 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. - */ - -package net.java.games.jogl.util; - -import java.nio.*; -import java.util.*; - -/** Utility routines for dealing with direct buffers. */ - -public class BufferUtils { - public static final int SIZEOF_DOUBLE = 8; - public static final int SIZEOF_FLOAT = 4; - public static final int SIZEOF_INT = 4; - - public static DoubleBuffer newDoubleBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); - return bb.asDoubleBuffer(); - } - - public static FloatBuffer newFloatBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); - return bb.asFloatBuffer(); - } - - public static IntBuffer newIntBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); - return bb.asIntBuffer(); - } - - public static ByteBuffer newByteBuffer(int numElements) { - ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - bb.order(ByteOrder.nativeOrder()); - return bb; - } - - public static DoubleBuffer copyDoubleBuffer(DoubleBuffer orig) { - DoubleBuffer dest = newDoubleBuffer(orig.capacity()); - orig.rewind(); - dest.put(orig); - return dest; - } - - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - FloatBuffer dest = newFloatBuffer(orig.capacity()); - orig.rewind(); - dest.put(orig); - return dest; - } - - public static IntBuffer copyIntBuffer(IntBuffer orig) { - IntBuffer dest = newIntBuffer(orig.capacity()); - orig.rewind(); - dest.put(orig); - return dest; - } - - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.capacity()); - orig.rewind(); - dest.put(orig); - return dest; - } - - private static Map bufferOffsetCache = Collections.synchronizedMap(new HashMap()); - - /** 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 ByteBuffer bufferOffset(int offset) { - Integer key = new Integer(offset); - ByteBuffer buf = (ByteBuffer) bufferOffsetCache.get(key); - if (buf == null) { - buf = bufferOffset0(offset); - bufferOffsetCache.put(key, buf); - } - return buf; - } - - private static native ByteBuffer bufferOffset0(int offset); -} |