From 908d0fbb2ea26226165cd42f12abf0d27e4a3f53 Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Fri, 29 Sep 2006 18:04:13 +0000 Subject: Merged dev-1_5 branch back to MAIN trunk git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@701 ba19aa83-45c5-6ac9-afd3-db810772062c --- .cvsignore | 3 + LICENSE-SPEC.html | 227 +- LICENSE.txt | 12 +- README-FIRST.txt | 8 + README-build.html | 4 +- build-tools/VersionInfo.java | 2 +- build.xml | 73 +- docs/ChangeLog-1_5.html | 244 + docs/api-changes-1_5.txt | 133 + nbproject/.cvsignore | 1 + nbproject/project.xml | 86 + release-info/pre-release/0-USAGE.txt | 39 + release-info/pre-release/HOW-TO-INSTALL.txt | 58 - release-info/pre-release/LICENSE-JRL.rtf | 111 + release-info/pre-release/LICENSE-JRL.txt | 157 + release-info/pre-release/README-download.html | 85 + release-info/pre-release/README-unzip.html | 124 + release-info/pre-release/README.html | 573 ++ release-info/pre-release/README.txt | 19 +- src/classes/J3dVersion | 2 +- src/classes/build.xml | 69 +- .../jogl/javax/media/j3d/JoglCgShaderInfo.java | 32 + .../javax/media/j3d/JoglCgShaderParameter.java | 29 + .../javax/media/j3d/JoglCgShaderProgramInfo.java | 38 + src/classes/jogl/javax/media/j3d/JoglContext.java | 231 + src/classes/jogl/javax/media/j3d/JoglDrawable.java | 30 + .../javax/media/j3d/JoglDrawingSurfaceObject.java | 60 + .../javax/media/j3d/JoglGraphicsConfiguration.java | 103 + src/classes/jogl/javax/media/j3d/JoglPipeline.java | 9279 ++++++++++++++++++++ .../jogl/javax/media/j3d/JoglShaderObject.java | 25 + .../linux/javax/media/j3d/J3dGraphicsConfig.java | 44 - .../javax/media/j3d/NativeConfigTemplate3D.java | 295 - .../linux/javax/media/j3d/NativeScreenInfo.java | 78 - .../linux/javax/media/j3d/NativeWSInfo.java | 64 - .../media/j3d/AlternateAppearanceRetained.java | 6 +- .../javax/media/j3d/AmbientLightRetained.java | 2 +- src/classes/share/javax/media/j3d/Appearance.java | 72 +- .../share/javax/media/j3d/AppearanceRetained.java | 20 +- .../share/javax/media/j3d/AttributeBin.java | 19 +- .../share/javax/media/j3d/BHInternalNode.java | 3 - src/classes/share/javax/media/j3d/BHNode.java | 3 - src/classes/share/javax/media/j3d/BHTree.java | 6 +- src/classes/share/javax/media/j3d/Background.java | 44 +- .../share/javax/media/j3d/BackgroundRetained.java | 161 +- .../share/javax/media/j3d/BehaviorRetained.java | 9 +- .../share/javax/media/j3d/BehaviorScheduler.java | 7 + .../share/javax/media/j3d/BehaviorStructure.java | 2 +- src/classes/share/javax/media/j3d/Billboard.java | 13 +- .../javax/media/j3d/BoundingLeafRetained.java | 2 +- .../share/javax/media/j3d/BoundingPolytope.java | 4 +- .../share/javax/media/j3d/BranchGroupRetained.java | 8 +- src/classes/share/javax/media/j3d/Canvas3D.java | 1734 ++-- .../share/javax/media/j3d/CanvasViewCache.java | 3 +- .../javax/media/j3d/CgShaderProgramRetained.java | 409 +- .../share/javax/media/j3d/ClipRetained.java | 2 +- .../media/j3d/ColoringAttributesRetained.java | 24 +- .../media/j3d/CompressedGeometryRenderMethod.java | 16 +- .../media/j3d/CompressedGeometryRetained.java | 9 +- src/classes/share/javax/media/j3d/Context.java | 22 + .../share/javax/media/j3d/DefaultRenderMethod.java | 16 +- .../share/javax/media/j3d/DetailTextureImage.java | 219 - .../javax/media/j3d/DirectionalLightRetained.java | 14 +- .../javax/media/j3d/DisplayListRenderMethod.java | 22 +- src/classes/share/javax/media/j3d/DistanceLOD.java | 5 +- src/classes/share/javax/media/j3d/Drawable.java | 22 + .../javax/media/j3d/DrawingSurfaceObjectAWT.java | 39 +- .../share/javax/media/j3d/EnvironmentSet.java | 3 - .../javax/media/j3d/ExceptionStrings.properties | 64 +- .../javax/media/j3d/ExponentialFogRetained.java | 10 +- src/classes/share/javax/media/j3d/FogRetained.java | 6 +- .../share/javax/media/j3d/FreeListManager.java | 51 +- .../javax/media/j3d/GLSLShaderProgramRetained.java | 418 +- .../share/javax/media/j3d/GeometryArray.java | 63 +- .../javax/media/j3d/GeometryArrayRetained.java | 992 +-- .../share/javax/media/j3d/GeometryAtom.java | 4 +- .../share/javax/media/j3d/GeometryRetained.java | 20 +- .../share/javax/media/j3d/GeometryStructure.java | 6 +- .../share/javax/media/j3d/GraphicsConfigInfo.java | 33 +- .../javax/media/j3d/GraphicsConfigTemplate3D.java | 13 +- .../share/javax/media/j3d/GraphicsContext3D.java | 867 +- .../share/javax/media/j3d/GroupRetained.java | 28 +- .../media/j3d/IllegalRenderingStateException.java | 4 +- .../share/javax/media/j3d/ImageComponent.java | 64 +- .../share/javax/media/j3d/ImageComponent2D.java | 219 +- .../javax/media/j3d/ImageComponent2DRetained.java | 1553 +--- .../share/javax/media/j3d/ImageComponent3D.java | 337 +- .../javax/media/j3d/ImageComponent3DRetained.java | 298 +- .../javax/media/j3d/ImageComponentRetained.java | 4040 ++++++--- .../javax/media/j3d/IndexedGeometryArray.java | 133 +- .../media/j3d/IndexedGeometryArrayRetained.java | 362 +- .../javax/media/j3d/InputDeviceBlockingThread.java | 36 +- src/classes/share/javax/media/j3d/J3DBuffer.java | 7 +- .../share/javax/media/j3d/J3DGraphics2DImpl.java | 159 +- src/classes/share/javax/media/j3d/J3dClock.java | 20 +- src/classes/share/javax/media/j3d/J3dMessage.java | 3 +- .../share/javax/media/j3d/J3dNotification.java | 2 + src/classes/share/javax/media/j3d/J3dThread.java | 81 +- src/classes/share/javax/media/j3d/LightBin.java | 3 +- .../share/javax/media/j3d/LightRetained.java | 10 +- .../javax/media/j3d/LineAttributesRetained.java | 21 +- .../share/javax/media/j3d/LinearFogRetained.java | 14 +- src/classes/share/javax/media/j3d/Locale.java | 36 +- .../share/javax/media/j3d/MasterControl.java | 1021 +-- .../share/javax/media/j3d/MaterialRetained.java | 19 +- .../javax/media/j3d/MediaContainerRetained.java | 6 +- .../share/javax/media/j3d/ModelClipRetained.java | 17 +- .../share/javax/media/j3d/MorphRetained.java | 20 +- .../share/javax/media/j3d/NativeAPIInfo.java | 32 - .../share/javax/media/j3d/NativeContext.java | 31 + .../share/javax/media/j3d/NativeDrawable.java | 32 + .../share/javax/media/j3d/NativePipeline.java | 3325 +++++++ .../share/javax/media/j3d/NativeShaderObject.java | 31 + .../share/javax/media/j3d/NioImageBuffer.java | 379 + .../share/javax/media/j3d/NodeComponent.java | 25 + .../javax/media/j3d/NodeComponentRetained.java | 12 +- .../share/javax/media/j3d/NodeRetained.java | 3 +- .../javax/media/j3d/NoopDrawingSurfaceObject.java | 57 + .../share/javax/media/j3d/NoopPipeline.java | 1561 ++++ .../share/javax/media/j3d/NotificationThread.java | 3 + .../javax/media/j3d/OrderedGroupRetained.java | 2 +- .../media/j3d/OrientedShape3DRenderMethod.java | 20 +- .../javax/media/j3d/OrientedShape3DRetained.java | 2 +- src/classes/share/javax/media/j3d/Pipeline.java | 1403 +++ .../javax/media/j3d/PointAttributesRetained.java | 13 +- .../share/javax/media/j3d/PointLightRetained.java | 20 +- .../javax/media/j3d/PolygonAttributesRetained.java | 21 +- .../share/javax/media/j3d/QuadArrayRetained.java | 21 +- src/classes/share/javax/media/j3d/Raster.java | 33 +- .../share/javax/media/j3d/RasterRetained.java | 502 +- src/classes/share/javax/media/j3d/RenderBin.java | 417 +- .../share/javax/media/j3d/RenderMethod.java | 2 +- .../share/javax/media/j3d/RenderMolecule.java | 123 +- src/classes/share/javax/media/j3d/Renderer.java | 1049 +-- .../media/j3d/RenderingAttributesRetained.java | 21 +- .../share/javax/media/j3d/RenderingError.java | 253 + .../javax/media/j3d/RenderingErrorListener.java | 29 + src/classes/share/javax/media/j3d/Screen3D.java | 14 +- .../share/javax/media/j3d/SetLiveState.java | 5 + .../javax/media/j3d/ShaderAppearanceRetained.java | 18 +- .../share/javax/media/j3d/ShaderAttrLoc.java | 22 + .../media/j3d/ShaderAttributeObjectRetained.java | 24 +- .../media/j3d/ShaderAttributeSetRetained.java | 24 +- src/classes/share/javax/media/j3d/ShaderBin.java | 2 - src/classes/share/javax/media/j3d/ShaderId.java | 22 + .../share/javax/media/j3d/ShaderProgramId.java | 22 + .../javax/media/j3d/ShaderProgramRetained.java | 220 +- .../share/javax/media/j3d/ShaderRetained.java | 2 +- .../share/javax/media/j3d/Shape3DRetained.java | 26 +- .../share/javax/media/j3d/SoundRetained.java | 4 +- .../share/javax/media/j3d/SoundScheduler.java | 12 + .../share/javax/media/j3d/SoundscapeRetained.java | 2 +- .../share/javax/media/j3d/SpotLightRetained.java | 60 +- .../share/javax/media/j3d/SwitchRetained.java | 2 +- .../media/j3d/TexCoordGenerationRetained.java | 27 +- .../share/javax/media/j3d/Text3DRenderMethod.java | 21 +- .../share/javax/media/j3d/Text3DRetained.java | 19 +- src/classes/share/javax/media/j3d/Texture.java | 174 +- src/classes/share/javax/media/j3d/Texture2D.java | 130 +- .../share/javax/media/j3d/Texture2DRetained.java | 188 +- src/classes/share/javax/media/j3d/Texture3D.java | 42 +- .../share/javax/media/j3d/Texture3DRetained.java | 196 +- .../javax/media/j3d/TextureAttributesRetained.java | 116 +- src/classes/share/javax/media/j3d/TextureBin.java | 158 +- .../share/javax/media/j3d/TextureCubeMap.java | 27 +- .../javax/media/j3d/TextureCubeMapRetained.java | 170 +- .../share/javax/media/j3d/TextureRetained.java | 617 +- .../share/javax/media/j3d/TextureUnitState.java | 42 + .../javax/media/j3d/TextureUnitStateRetained.java | 12 +- src/classes/share/javax/media/j3d/TimerThread.java | 38 +- src/classes/share/javax/media/j3d/Transform3D.java | 374 +- .../share/javax/media/j3d/TransformGroup.java | 3 +- .../javax/media/j3d/TransformGroupRetained.java | 8 +- .../share/javax/media/j3d/TransformStructure.java | 2 - .../media/j3d/TransparencyAttributesRetained.java | 19 +- .../javax/media/j3d/TriangleArrayRetained.java | 18 +- .../javax/media/j3d/TriangleFanArrayRetained.java | 18 +- .../media/j3d/TriangleStripArrayRetained.java | 19 +- .../javax/media/j3d/VertexArrayRenderMethod.java | 22 +- src/classes/share/javax/media/j3d/View.java | 83 +- .../javax/media/j3d/ViewPlatformRetained.java | 8 +- .../javax/media/j3d/ViewSpecificGroupRetained.java | 16 +- .../share/javax/media/j3d/VirtualUniverse.java | 177 +- .../share/javax/media/j3d/WakeupCondition.java | 2 +- .../solaris/javax/media/j3d/J3dGraphicsConfig.java | 40 - .../javax/media/j3d/NativeConfigTemplate3D.java | 283 - .../solaris/javax/media/j3d/NativeScreenInfo.java | 71 - .../solaris/javax/media/j3d/NativeWSInfo.java | 58 - .../win32/javax/media/j3d/J3dGraphicsConfig.java | 41 - .../javax/media/j3d/NativeConfigTemplate3D.java | 32 +- .../win32/javax/media/j3d/NativeScreenInfo.java | 25 +- .../win32/javax/media/j3d/NativeWSInfo.java | 69 - .../javax/media/j3d/NativeConfigTemplate3D.java | 281 + .../x11/javax/media/j3d/NativeScreenInfo.java | 67 + src/native/build.xml | 71 +- src/native/d3d/Attributes.cpp | 661 +- src/native/d3d/Canvas3D.cpp | 432 +- src/native/d3d/D3dCtx.cpp | 5 + src/native/d3d/D3dDriverInfo.cpp | 2 + src/native/d3d/D3dImageComponent.hpp | 7 +- src/native/d3d/D3dUtil.cpp | 58 +- src/native/d3d/D3dUtil.hpp | 1 - src/native/d3d/GeometryArrayRetained.cpp | 531 +- src/native/d3d/GraphicsContext3D.cpp | 18 +- src/native/d3d/Lights.cpp | 12 +- src/native/d3d/NativeAPIInfo.c | 23 - src/native/d3d/NativeWSInfo.cpp | 92 - src/native/d3d/RasterRetained.cpp | 255 - src/native/d3d/build-windows-amd64-vc.xml | 64 + src/native/d3d/build-windows-i586-vc.xml | 4 +- src/native/ogl/Attributes.c | 1656 ++-- src/native/ogl/Canvas3D.c | 1791 ++-- src/native/ogl/CgShaderProgram.c | 200 +- src/native/ogl/DrawingSurfaceObjectAWT.c | 4 +- src/native/ogl/GLSLInfo.h | 2 + src/native/ogl/GLSLShaderProgram.c | 229 +- src/native/ogl/GeometryArrayRetained.c | 509 +- src/native/ogl/GraphicsContext3D.c | 188 +- src/native/ogl/Lights.c | 12 +- src/native/ogl/MasterControl.c | 163 +- src/native/ogl/NativeAPIInfo.c | 39 - src/native/ogl/NativeConfigTemplate3D.c | 17 - src/native/ogl/NativeWSInfo.c | 78 - src/native/ogl/RasterRetained.c | 398 - src/native/ogl/build-linux-amd64.xml | 4 +- src/native/ogl/build-linux-i586.xml | 4 +- src/native/ogl/build-linux-ia64.xml | 5 +- src/native/ogl/build-linux-ppc.xml | 6 +- src/native/ogl/build-solaris-sparc-forte.xml | 8 +- src/native/ogl/build-solaris-sparc-gcc.xml | 8 +- src/native/ogl/build-solaris-x86-forte.xml | 8 +- src/native/ogl/build-solaris-x86-gcc.xml | 8 +- src/native/ogl/build-windows-amd64-vc.xml | 108 + src/native/ogl/build-windows-i586-gcc.xml | 4 +- src/native/ogl/build-windows-i586-vc.xml | 4 +- src/native/ogl/gldefs.h | 183 +- src/native/share/build-linux-amd64.xml | 54 - src/native/share/build-linux-i586.xml | 54 - src/native/share/build-linux-ia64.xml | 56 - src/native/share/build-linux-ppc.xml | 54 - src/native/share/build-solaris-sparc-forte.xml | 79 - src/native/share/build-solaris-sparc-gcc.xml | 79 - src/native/share/build-solaris-x86-forte.xml | 86 - src/native/share/build-solaris-x86-gcc.xml | 86 - src/native/share/build-windows-i586-gcc.xml | 63 - src/native/share/build-windows-i586-vc.xml | 62 - 245 files changed, 32386 insertions(+), 16113 deletions(-) create mode 100644 .cvsignore create mode 100644 docs/ChangeLog-1_5.html create mode 100644 docs/api-changes-1_5.txt create mode 100644 nbproject/.cvsignore create mode 100644 nbproject/project.xml create mode 100644 release-info/pre-release/0-USAGE.txt delete mode 100644 release-info/pre-release/HOW-TO-INSTALL.txt create mode 100644 release-info/pre-release/LICENSE-JRL.rtf create mode 100644 release-info/pre-release/LICENSE-JRL.txt create mode 100644 release-info/pre-release/README-download.html create mode 100644 release-info/pre-release/README-unzip.html create mode 100644 release-info/pre-release/README.html create mode 100755 src/classes/jogl/javax/media/j3d/JoglCgShaderInfo.java create mode 100755 src/classes/jogl/javax/media/j3d/JoglCgShaderParameter.java create mode 100755 src/classes/jogl/javax/media/j3d/JoglCgShaderProgramInfo.java create mode 100644 src/classes/jogl/javax/media/j3d/JoglContext.java create mode 100755 src/classes/jogl/javax/media/j3d/JoglDrawable.java create mode 100644 src/classes/jogl/javax/media/j3d/JoglDrawingSurfaceObject.java create mode 100755 src/classes/jogl/javax/media/j3d/JoglGraphicsConfiguration.java create mode 100644 src/classes/jogl/javax/media/j3d/JoglPipeline.java create mode 100755 src/classes/jogl/javax/media/j3d/JoglShaderObject.java delete mode 100644 src/classes/linux/javax/media/j3d/J3dGraphicsConfig.java delete mode 100644 src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java delete mode 100644 src/classes/linux/javax/media/j3d/NativeScreenInfo.java delete mode 100644 src/classes/linux/javax/media/j3d/NativeWSInfo.java create mode 100644 src/classes/share/javax/media/j3d/Context.java delete mode 100644 src/classes/share/javax/media/j3d/DetailTextureImage.java create mode 100644 src/classes/share/javax/media/j3d/Drawable.java delete mode 100644 src/classes/share/javax/media/j3d/NativeAPIInfo.java create mode 100644 src/classes/share/javax/media/j3d/NativeContext.java create mode 100644 src/classes/share/javax/media/j3d/NativeDrawable.java create mode 100644 src/classes/share/javax/media/j3d/NativePipeline.java create mode 100644 src/classes/share/javax/media/j3d/NativeShaderObject.java create mode 100644 src/classes/share/javax/media/j3d/NioImageBuffer.java create mode 100644 src/classes/share/javax/media/j3d/NoopDrawingSurfaceObject.java create mode 100644 src/classes/share/javax/media/j3d/NoopPipeline.java create mode 100644 src/classes/share/javax/media/j3d/Pipeline.java create mode 100644 src/classes/share/javax/media/j3d/RenderingError.java create mode 100644 src/classes/share/javax/media/j3d/RenderingErrorListener.java create mode 100644 src/classes/share/javax/media/j3d/ShaderAttrLoc.java create mode 100644 src/classes/share/javax/media/j3d/ShaderId.java create mode 100644 src/classes/share/javax/media/j3d/ShaderProgramId.java delete mode 100644 src/classes/solaris/javax/media/j3d/J3dGraphicsConfig.java delete mode 100644 src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java delete mode 100644 src/classes/solaris/javax/media/j3d/NativeScreenInfo.java delete mode 100644 src/classes/solaris/javax/media/j3d/NativeWSInfo.java delete mode 100644 src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java delete mode 100644 src/classes/win32/javax/media/j3d/NativeWSInfo.java create mode 100644 src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java create mode 100644 src/classes/x11/javax/media/j3d/NativeScreenInfo.java delete mode 100644 src/native/d3d/NativeAPIInfo.c delete mode 100644 src/native/d3d/NativeWSInfo.cpp delete mode 100644 src/native/d3d/RasterRetained.cpp create mode 100644 src/native/d3d/build-windows-amd64-vc.xml delete mode 100644 src/native/ogl/NativeAPIInfo.c delete mode 100644 src/native/ogl/NativeWSInfo.c delete mode 100644 src/native/ogl/RasterRetained.c create mode 100644 src/native/ogl/build-windows-amd64-vc.xml delete mode 100644 src/native/share/build-linux-amd64.xml delete mode 100644 src/native/share/build-linux-i586.xml delete mode 100644 src/native/share/build-linux-ia64.xml delete mode 100644 src/native/share/build-linux-ppc.xml delete mode 100644 src/native/share/build-solaris-sparc-forte.xml delete mode 100644 src/native/share/build-solaris-sparc-gcc.xml delete mode 100644 src/native/share/build-solaris-x86-forte.xml delete mode 100644 src/native/share/build-solaris-x86-gcc.xml delete mode 100644 src/native/share/build-windows-i586-gcc.xml delete mode 100644 src/native/share/build-windows-i586-vc.xml diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..80629f0 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,3 @@ +build +dist +staging diff --git a/LICENSE-SPEC.html b/LICENSE-SPEC.html index 82ab4da..1e68067 100644 --- a/LICENSE-SPEC.html +++ b/LICENSE-SPEC.html @@ -6,231 +6,8 @@ Java 3D API Specification -

-Specification: JSR-000926 Java(TM) 3D 1.4 ("Specification") -

-

-Version: 1.4 -

-

-Status: Maintenance Release -

-

-Release: 7 February 2006 -

-

-Copyright 2006 SUN MICROSYSTEMS, INC. -

-

-4150 Network Circle, Santa Clara, California 95054, U.S.A -

-

-All rights reserved. -

-

-LIMITED LICENSE GRANTS -

-

-1. License for Evaluation Purposes. Sun hereby grants you a -fully-paid, non-exclusive, non-transferable, worldwide, limited -license (without the right to sublicense), under Sun's applicable -intellectual property rights to view, download, use and reproduce the -Specification only for the purpose of internal evaluation. This -includes (i) developing applications intended to run on an -implementation of the Specification, provided that such applications -do not themselves implement any portion(s) of the Specification, and -(ii) discussing the Specification with any third party; and (iii) -excerpting brief portions of the Specification in oral or written -communications which discuss the Specification provided that such -excerpts do not in the aggregate constitute a significant portion of -the Specification. -

-

-2. License for the Distribution of Compliant Implementations. Sun also -grants you a perpetual, non-exclusive, non-transferable, worldwide, -fully paid-up, royalty free, limited license (without the right to -sublicense) under any applicable copyrights or, subject to the -provisions of subsection 4 below, patent rights it may have covering -the Specification to create and/or distribute an Independent -Implementation of the Specification that: (a) fully implements the -Specification including all its required interfaces and functionality; -(b) does not modify, subset, superset or otherwise extend the Licensor -Name Space, or include any public or protected packages, classes, Java -interfaces, fields or methods within the Licensor Name Space other -than those required/authorized by the Specification or Specifications -being implemented; and (c) passes the Technology Compatibility Kit -(including satisfying the requirements of the applicable TCK Users -Guide) for such Specification ("Compliant Implementation"). In -addition, the foregoing license is expressly conditioned on your not -acting outside its scope. No license is granted hereunder for any -other purpose (including, for example, modifying the Specification, -other than to the extent of your fair use rights, or distributing the -Specification to third parties). Also, no right, title, or interest in -or to any trademarks, service marks, or trade names of Sun or Sun's -licensors, Sun or the Sun's licensors is granted hereunder. Java, and -Java-related logos, marks and names are trademarks or registered -trademarks of Sun Microsystems, Inc. in the U.S. and other countries. -

-

-3. Pass-through Conditions. You need not include limitations (a)-(c) -from the previous paragraph or any other particular "pass through" -requirements in any license You grant concerning the use of your -Independent Implementation or products derived from it. However, -except with respect to Independent Implementations (and products -derived from them) that satisfy limitations (a)-(c) from the previous -paragraph, You may neither: (a) grant or otherwise pass through to -your licensees any licenses under Sun's applicable intellectual -property rights; nor (b) authorize your licensees to make any claims -concerning their implementation's compliance with the Spec in -question. -

-

-4. Reciprocity Concerning Patent Licenses. -

-

-a. With respect to any patent claims covered by the license granted -under subparagraph 2 above that would be infringed by all technically -feasible implementations of the Specification, such license is -conditioned upon your offering on fair, reasonable and -non-discriminatory terms, to any party seeking it from You, a -perpetual, non-exclusive, non-transferable, worldwide license under -Your patent rights which are or would be infringed by all technically -feasible implementations of the Specification to develop, distribute -and use a Compliant Implementation. -

-

-b. With respect to any patent claims owned by Sun and covered by the -license granted under subparagraph 2, whether or not their -infringement can be avoided in a technically feasible manner when -implementing the Specification, such license shall terminate with -respect to such claims if You initiate a claim against Sun that it -has, in the course of performing its responsibilities as the Sun, -induced any other entity to infringe Your patent rights. -

-

-c. Also with respect to any patent claims owned by Sun and covered by -the license granted under subparagraph, where the infringement of such -claims can be avoided in a technically feasible manner when -implementing the Specification such license, with respect to such -claims, shall terminate if You initiate a claim against Sun that its -making, having made, using, offering to sell, selling or importing a -Compliant Implementation infringes Your patent rights. -

-

-5. Definitions. For the purposes of this Agreement: "Independent -Implementation" shall mean an implementation of the Specification that -neither derives from any of Sun's source code or binary code materials -nor, except with an appropriate and separate license from Sun, -includes any of Sun's source code or binary code materials; "Licensor -Name Space" shall mean the public class or interface declarations -whose names begin with "java", "javax", "com.sun" or their equivalents -in any subsequent naming convention adopted by Sun through the Java -Community Process, or any recognized successors or replacements -thereof; and "Technology Compatibility Kit" or "TCK" shall mean the -test suite and accompanying TCK User's Guide provided by Sun which -corresponds to the Specification and that was available either (i) -from Sun's 120 days before the first release of Your Independent -Implementation that allows its use for commercial purposes, or (ii) -more recently than 120 days from such release but against which You -elect to test Your implementation of the Specification. -

-

-This Agreement will terminate immediately without notice from Sun if -you breach the Agreement or act outside the scope of the licenses -granted above. -

-

-DISCLAIMER OF WARRANTIES -

-

-THE SPECIFICATION IS PROVIDED "AS IS". SUN MAKES NO REPRESENTATIONS OR -WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, -WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, -NON-INFRINGEMENT (INCLUDING AS A CONSEQUENCE OF ANY PRACTICE OR -IMPLEMENTATION OF THE SPECIFICATION), OR THAT THE CONTENTS OF THE -SPECIFICATION ARE SUITABLE FOR ANY PURPOSE. This document does not -represent any commitment to release or implement any portion of the -Specification in any product. In addition, the Specification could -include technical inaccuracies or typographical errors. -

-

-LIMITATION OF LIABILITY -

-

-TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS -LICENSORS BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION, -LOST REVENUE, PROFITS OR DATA, OR FOR SPECIAL, INDIRECT, -CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND -REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED IN -ANY WAY TO YOUR HAVING, IMPELEMENTING OR OTHERWISE USING USING THE -SPECIFICATION, EVEN IF SUN AND/OR ITS LICENSORS HAVE BEEN ADVISED OF -THE POSSIBILITY OF SUCH DAMAGES. -

-

-You will indemnify, hold harmless, and defend Sun and its licensors -from any claims arising or resulting from: (i) your use of the -Specification; (ii) the use or distribution of your Java application, -applet and/or implementation; and/or (iii) any claims that later -versions or releases of any Specification furnished to you are -incompatible with the Specification provided to you under this -license. -

-

-RESTRICTED RIGHTS LEGEND -

-

-U.S. Government: If this Specification is being acquired by or on -behalf of the U.S. Government or by a U.S. Government prime contractor -or subcontractor (at any tier), then the Government's rights in the -Software and accompanying documentation shall be only as set forth in -this license; this is in accordance with 48 C.F.R. 227.7201 through -227.7202-4 (for Department of Defense (DoD) acquisitions) and with 48 -C.F.R. 2.101 and 12.212 (for non-DoD acquisitions). -

-

-REPORT -

-

-If you provide Sun with any comments or suggestions concerning the -Specification ("Feedback"), you hereby: (i) agree that such Feedback -is provided on a non-proprietary and non-confidential basis, and (ii) -grant Sun a perpetual, non-exclusive, worldwide, fully paid-up, -irrevocable license, with the right to sublicense through multiple -levels of sublicensees, to incorporate, disclose, and use without -limitation the Feedback for any purpose. -

-

-GENERAL TERMS -

-

-Any action related to this Agreement will be governed by California -law and controlling U.S. federal law. The U.N. Convention for the -International Sale of Goods and the choice of law rules of any -jurisdiction will not apply. -

-

-The Specification is subject to U.S. export control laws and may be -subject to export or import regulations in other countries. Licensee -agrees to comply strictly with all such laws and regulations and -acknowledges that it has the responsibility to obtain such licenses to -export, re-export or import as may be required after delivery to -Licensee. -

-

-This Agreement is the parties' entire agreement relating to its -subject matter. It supersedes all prior or contemporaneous oral or -written communications, proposals, conditions, representations and -warranties and prevails over any conflicting or additional terms of -any quote, order, acknowledgment, or other communication between the -parties relating to its subject matter during the term of this -Agreement. No modification to this Agreement will be binding, unless -in writing and signed by an authorized representative of each party. -

-

-Rev. January, 2006 -

-

-Sun/Final/Full +

Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. +Use is subject to license terms.

diff --git a/LICENSE.txt b/LICENSE.txt index 930cc77..8b293be 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -2,8 +2,12 @@ This software is licensed by Sun: i) for research use under terms of the Java Research License (JRL) as specified in the LICENSE-JRL.txt file and on the web at -"http://java3d.dev.java.net/jrl.html"; or +"http://java3d.dev.java.net/jrl.html" -ii) for commercial use under the terms of the Java Distribution License -(JDL) as specified in the LICENSE-JDL.txt file and on the web at -"http://java3d.dev.java.net/jdl-java3d.pdf". +NOTE: The main trunk of the Java 3D core source code (j3d-core +project) contains proposed API changes for an eventual 1.5 version of +the Java 3D API. THESE API CHANGES ARE NOT YET APPROVED AS PART OF +A JAVA SPECIFICATION REQUEST (JSR) UNDER THE JAVA COMMUNITY PROCESS +(JCP). UNTIL SUCH TIME AS THEY ARE ADOPTED AND APPROVED BY A JSR, +THE 1.5-EXPERIMENTAL VERSION OF THE JAVA 3D API MAY ONLY BE USED FOR +RESEARCH UNDER THE TERMS OF THE JAVA RESEARCH LICENSE (JRL). diff --git a/README-FIRST.txt b/README-FIRST.txt index b6dd53b..ecc1adc 100644 --- a/README-FIRST.txt +++ b/README-FIRST.txt @@ -1,3 +1,11 @@ +NOTE: The main trunk of the Java 3D core source code (j3d-core +project) contains proposed API changes for an eventual 1.5 version of +the Java 3D API. THESE API CHANGES ARE NOT YET APPROVED AS PART OF +A JAVA SPECIFICATION REQUEST (JSR) UNDER THE JAVA COMMUNITY PROCESS +(JCP). UNTIL SUCH TIME AS THEY ARE ADOPTED AND APPROVED BY A JSR, +THE 1.5-EXPERIMENTAL VERSION OF THE JAVA 3D API MAY ONLY BE USED FOR +RESEARCH UNDER THE TERMS OF THE JAVA RESEARCH LICENSE (JRL). + The source code for the j3d-core project is copyrighted code that is licensed to individuals or companies who download or otherwise access the code. diff --git a/README-build.html b/README-build.html index d5e2376..7c1f4fa 100644 --- a/README-build.html +++ b/README-build.html @@ -69,9 +69,9 @@ comes with MinGW version 3.1.0-1

The following software must be installed:

* * @@ -3621,6 +3509,18 @@ public class Canvas3D extends Canvas { * layer, and an attempt to set anisotropic filter degree will be ignored. * * + + *
  • + * textureNonPowerOfTwoAvailable + * + *
  • * *
  • * vertexAttrsMax @@ -3661,18 +3561,23 @@ public class Canvas3D extends Canvas { boolean createDummyCtx = false; synchronized (VirtualUniverse.mc.contextCreationLock) { - if (ctx == 0) { + if (ctx == null) { createDummyCtx = true; } } - + if (createDummyCtx) { GraphicsConfigTemplate3D.setQueryProps(this); - } + //create query Properties createQueryProps(); } + + if (fatalError) { + throw new IllegalStateException(J3dI18N.getString("Canvas3D29")); + } + return queryProps; } @@ -3681,7 +3586,7 @@ public class Canvas3D extends Canvas { // extensions, the context will destroy immediately // inside the native code after setting the various // fields in this object - createQueryContext(screen.display, window, vid, + createQueryContext(screen.display, drawable, fbConfig, offScreen, 1, 1, VirtualUniverse.mc.glslLibraryAvailable, VirtualUniverse.mc.cgLibraryAvailable); @@ -3717,8 +3622,13 @@ public class Canvas3D extends Canvas { values.add(new Integer(pass)); keys.add("stencilSize"); - // Return the actual stencil size. - values.add(new Integer(actualStencilSize)); + // Return the actual stencil size if the user owns it, otherwise + // return 0 + if (userStencilAvailable) { + values.add(new Integer(actualStencilSize)); + } else { + values.add(new Integer(0)); + } keys.add("compressedGeometry.majorVersionNumber"); values.add(new Integer(GeometryDecompressor.majorVersionNumber)); @@ -3791,6 +3701,14 @@ public class Canvas3D extends Canvas { values.add(new Boolean( (textureExtendedFeatures & TEXTURE_LOD_OFFSET) != 0)); + keys.add("textureNonPowerOfTwoAvailable"); + if (VirtualUniverse.mc.enforcePowerOfTwo) { + values.add(Boolean.FALSE); + } else { + values.add(new Boolean( + (textureExtendedFeatures & TEXTURE_NON_POWER_OF_TWO) != 0)); + } + keys.add("textureCoordSetsMax"); values.add(new Integer(maxTexCoordSets)); @@ -3831,16 +3749,6 @@ public class Canvas3D extends Canvas { } - // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or - // FIELD_RIGHT. Note that it is up to the caller to ensure that - // stereo is available before setting the mode to FIELD_LEFT or - // FIELD_RIGHT. The boolean isTRUE for double buffered mode, FALSE - // foe single buffering. - native void setRenderMode(long ctx, int mode, boolean doubleBuffer); - - // Set glDepthMask. - native void setDepthBufferWriteEnable(long ctx, boolean mode); - /** * Update the view cache associated with this canvas. */ @@ -3885,7 +3793,7 @@ public class Canvas3D extends Canvas { } - void resetTexture(long ctx, int texUnitIndex) { + void resetTexture(Context ctx, int texUnitIndex) { // D3D also need to reset texture attributes this.resetTextureNative(ctx, texUnitIndex); @@ -3906,7 +3814,6 @@ public class Canvas3D extends Canvas { void resetTextureBin() { Object obj; TextureRetained tex; - DetailTextureImage detailTex; // We don't use rdr.objectId for background texture in D3D // so there is no need to handle rdr.objectId @@ -3923,18 +3830,14 @@ public class Canvas3D extends Canvas { if (obj instanceof TextureRetained) { tex = (TextureRetained) obj; tex.resourceCreationMask &= ~canvasBit; - } else { - detailTex = (DetailTextureImage) obj; - for (int i=0; i < detailTex.resourceCreationMask.length; i++) { - detailTex.resourceCreationMask[i] &= ~canvasBit; - } - } + } } } } void d3dResize() { + assert VirtualUniverse.mc.isD3D(); int status = resizeD3DCanvas(ctx); antialiasingSet = false; @@ -3947,6 +3850,7 @@ public class Canvas3D extends Canvas { } void d3dToggle() { + assert VirtualUniverse.mc.isD3D(); int status = toggleFullScreenMode(ctx); antialiasingSet = false; @@ -3957,6 +3861,7 @@ public class Canvas3D extends Canvas { // use by D3D only void notifyD3DPeer(int cmd) { + assert VirtualUniverse.mc.isD3D(); if (active) { if (isRunning) { if ((view != null) && @@ -3969,7 +3874,7 @@ public class Canvas3D extends Canvas { while (isRunningStatus) { MasterControl.threadYield(); } - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); + J3dMessage renderMessage = new J3dMessage(); renderMessage.threads = J3dThread.RENDER_THREAD; if (cmd == RESIZE) { renderMessage.type = J3dMessage.RESIZE_CANVAS; @@ -4017,8 +3922,6 @@ public class Canvas3D extends Canvas { void reset() { int i; - - byteBuffer = new byte[1]; currentAppear = new AppearanceRetained(); currentMaterial = new MaterialRetained(); viewFrustum = new CachedFrustum(); @@ -4247,12 +4150,20 @@ public class Canvas3D extends Canvas { } } } - - void setModelViewMatrix(long ctx, double[] viewMatrix, Transform3D mTrans) { + + void setProjectionMatrix(Context ctx, Transform3D projTrans) { + this.projTrans = projTrans; + setProjectionMatrix(ctx, projTrans.mat); + } + + void setModelViewMatrix(Context ctx, double[] viewMatrix, Transform3D mTrans) { setModelViewMatrix(ctx, viewMatrix, mTrans.mat); if (!useStereo) { this.modelMatrix = mTrans; } else { + // TODO : This seems wrong to do only for the right eye. + // A possible approach is to invalidate the cache at begin of + // each eye. if (rightStereoPass) { // Only set cache in right stereo pass, otherwise // if the left stereo pass set the cache value, @@ -4294,41 +4205,17 @@ public class Canvas3D extends Canvas { } } - // Create the texture unit state map - void createTexUnitStateMap() { - // Create the texture unit state map array, which is a mapping from - // texture unit state to the actual underlying texture unit - // NOTE: since this is now required to be a 1-to-1 mapping, we will - // initialize it as such - - texUnitStateMap = new int[maxAvailableTextureUnits]; - for (int t = 0; t < maxAvailableTextureUnits; t++) { - texUnitStateMap[t] = t; - } - } - - // update the underlying layer of the current texture unit state map - void updateTexUnitStateMap() { - updateTexUnitStateMap(ctx, numActiveTexUnit, texUnitStateMap); - } - boolean supportGlobalAlpha() { return ((extensionsSupported & SUN_GLOBAL_ALPHA) != 0); } - boolean supportVideoResize() { - return ((extensionsSupported & SUN_VIDEO_RESIZE) != 0); - } - - /** enable separate specular color if the functionality - * is availabe for this canvas and it is not overriden by the - * property j3d.disableSeparateSpecular. + /** + * Enable separate specular color if it is not overriden by the + * property j3d.disableSeparateSpecular. */ void enableSeparateSpecularColor() { - if (((extensionsSupported & EXT_SEPARATE_SPECULAR_COLOR) != 0) && - !VirtualUniverse.mc.disableSeparateSpecularColor) { - updateSeparateSpecularColorEnable(ctx, true); - } + boolean enable = !VirtualUniverse.mc.disableSeparateSpecularColor; + updateSeparateSpecularColorEnable(ctx, enable); } final void beginScene() { @@ -4387,12 +4274,12 @@ public class Canvas3D extends Canvas { if ((screen != null) && (screen.renderer != null) && - (ctx != 0)) { + (ctx != null)) { VirtualUniverse.mc.postRequest(MasterControl.FREE_CONTEXT, new Object[]{this, new Long(screen.display), - new Integer(window), - new Long(ctx)}); + drawable, + ctx}); // Fix for Issue 19 // Wait for the context to be freed unless called from // a Behavior or from a Rendering thread @@ -4402,9 +4289,8 @@ public class Canvas3D extends Canvas { while (ctxTimeStamp != 0) { MasterControl.threadYield(); } - } - ctx = 0; + ctx = null; } } @@ -4491,7 +4377,7 @@ public class Canvas3D extends Canvas { /** * update state if neccessary according to the stateUpdatedMask */ - void updateState(int pass, int dirtyBits) { + void updateState( int dirtyBits) { if (stateUpdateMask == 0) @@ -4501,7 +4387,7 @@ public class Canvas3D extends Canvas { if ((stateUpdateMask & (1 << TEXTUREBIN_BIT)) != 0) { ((TextureBin) - curStateToUpdate[TEXTUREBIN_BIT]).updateAttributes(this, pass); + curStateToUpdate[TEXTUREBIN_BIT]).updateAttributes(this); } if ((stateUpdateMask & (1 << RENDERMOLECULE_BIT)) != 0) { @@ -4520,6 +4406,245 @@ public class Canvas3D extends Canvas { stateUpdateMask = 0; } + + // This method updates this Texture2D for raster. + // Note : No multi-texture is not used. + void updateTextureForRaster(Texture2DRetained texture) { + + // Setup texture and texture attributes for texture unit 0. + Pipeline.getPipeline().updateTextureUnitState(ctx, 0, true); + setLastActiveTexUnit(0); + setNumActiveTexUnit(1); + + texture.updateNative(this); + resetTextureAttributes(ctx); + + for(int i=1; i < maxTextureUnits; i++) { + resetTexture(ctx, i); + } + + // set the active texture unit back to 0 + activeTextureUnit(ctx, 0); + + // Force the next textureBin to reload. + canvasDirty |= Canvas3D.TEXTUREBIN_DIRTY | Canvas3D.TEXTUREATTRIBUTES_DIRTY; + } + + void restoreTextureBin() { + + // Need to check TextureBin's shaderBin for null + // TextureBin can get clear() if there isn't any RM under it. + if((textureBin != null) && (textureBin.shaderBin != null)) { + textureBin.updateAttributes(this); + } + } + + void textureFill(RasterRetained raster, Point2d winCoord, + float mapZ, float alpha) { + + int winWidth = canvasViewCache.getCanvasWidth(); + int winHeight = canvasViewCache.getCanvasHeight(); + + int rasterImageWidth = raster.image.width; + int rasterImageHeight = raster.image.height; + + float texMinU = 0, texMinV = 0, texMaxU = 0, texMaxV = 0; + float mapMinX = 0, mapMinY = 0, mapMaxX = 0, mapMaxY = 0; + + Point rasterSrcOffset = new Point(); + raster.getSrcOffset(rasterSrcOffset); + + Dimension rasterSize = new Dimension(); + raster.getSize(rasterSize); + + // System.err.println("rasterSrcOffset " + rasterSrcOffset + " rasterSize " + rasterSize); + + int rasterMinX = rasterSrcOffset.x; + int rasterMaxX = rasterSrcOffset.x + rasterSize.width; + int rasterMinY = rasterSrcOffset.y; + int rasterMaxY = rasterSrcOffset.y + rasterSize.height; + + if ((rasterMinX >= rasterImageWidth) || (rasterMinY >= rasterImageHeight) || + (rasterMaxX <= 0) || (rasterMaxY <= 0)) { + return; + } + + if (rasterMinX < 0) { + rasterMinX = 0; + } + if (rasterMinY < 0) { + rasterMinY = 0; + } + + if (rasterMaxX > rasterImageWidth) { + rasterMaxX = rasterImageWidth; + } + + if (rasterMaxY > rasterImageHeight) { + rasterMaxY = rasterImageHeight; + } + + texMinU = (float) rasterMinX / (float) rasterImageWidth; + texMaxU = (float) rasterMaxX / (float) rasterImageWidth; + mapMinX = (float) winCoord.x / (float) winWidth; + mapMaxX = (float) (winCoord.x + (rasterMaxX - rasterMinX)) / (float) winWidth; + + if (raster.image.isYUp()) { + texMinV = (float) rasterMinY / (float) rasterImageHeight; + texMaxV = (float) rasterMaxY / (float) rasterImageHeight; + } else { + // System.err.println("In yUp is false case"); + texMinV = 1.0f - (float) rasterMaxY / (float) rasterImageHeight; + texMaxV = 1.0f - (float) rasterMinY / (float) rasterImageHeight; + } + + mapMinY = 1.0f - ((float) (winCoord.y + (rasterMaxY - rasterMinY)) / (float) winHeight); + mapMaxY = 1.0f - ((float) winCoord.y / (float) winHeight); + + textureFillRaster(ctx, texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY, mapZ, alpha); + + } + + void textureFill(BackgroundRetained bg, int winWidth, int winHeight) { + + ImageComponentRetained.ImageData imageData = + bg.image.getImageData(bg.texture.isUseAsRaster()); + + int maxX = imageData.getWidth(); + int maxY = imageData.getHeight(); + int width = bg.image.width; + int height = bg.image.height; + + float xzoom = (float)winWidth / maxX; + float yzoom = (float)winHeight / maxY; + float zoom = 0; + float texMinU = 0, texMinV = 0, texMaxU = 0, texMaxV = 0, adjustV = 0; + float mapMinX = 0, mapMinY = 0, mapMaxX = 0, mapMaxY = 0; + float halfWidth = 0, halfHeight = 0; + int i = 0, j = 0; + switch (bg.imageScaleMode) { + case Background.SCALE_NONE: + texMinU = 0.0f; + texMinV = 0.0f; + texMaxU = 1.0f; + texMaxV = 1.0f; + halfWidth = (float)winWidth/2.0f; + halfHeight = (float)winHeight/2.0f; + mapMinX = (float) ((0 - halfWidth)/halfWidth); + mapMinY = (float) ((0 - halfHeight)/halfHeight); + mapMaxX = (float) ((maxX - halfWidth)/halfWidth); + mapMaxY = (float) ((maxY - halfHeight)/halfHeight); + adjustV = ((float)winHeight - (float)maxY)/halfHeight; + mapMinY += adjustV; + mapMaxY += adjustV; + break; + case Background.SCALE_FIT_MIN: + zoom = Math.min(xzoom, yzoom); + texMinU = 0.0f; + texMinV = 0.0f; + texMaxU = 1.0f; + texMaxV = 1.0f; + mapMinX = -1.0f; + mapMaxY = 1.0f; + if (xzoom < yzoom) { + mapMaxX = 1.0f; + mapMinY = -1.0f + 2.0f * ( 1.0f - zoom * (float)maxY/(float) winHeight ); + } else { + mapMaxX = -1.0f + zoom * (float)maxX/winWidth * 2; + mapMinY = -1.0f; + } + break; + case Background.SCALE_FIT_MAX: + zoom = Math.max(xzoom, yzoom); + mapMinX = -1.0f; + mapMinY = -1.0f; + mapMaxX = 1.0f; + mapMaxY = 1.0f; + if (xzoom < yzoom) { + texMinU = 0.0f; + texMinV = 0.0f; + texMaxU = (float)winWidth/maxX/zoom; + texMaxV = 1.0f; + } else { + texMinU = 0.0f; + texMinV = 1.0f - (float)winHeight/maxY/zoom; + texMaxU = 1.0f; + texMaxV = 1.0f; + } + break; + case Background.SCALE_FIT_ALL: + texMinU = 0.0f; + texMinV = 0.0f; + texMaxU = 1.0f; + texMaxV = 1.0f; + mapMinX = -1.0f; + mapMinY = -1.0f; + mapMaxX = 1.0f; + mapMaxY = 1.0f; + break; + case Background.SCALE_REPEAT: + i = winWidth/width; + j = winHeight/height; + texMinU = 0.0f; + texMinV = (float)(j + 1) - yzoom; + texMaxU = xzoom; + texMaxV = (float)(j + 1); + mapMinX = -1.0f; + mapMinY = -1.0f; + mapMaxX = 1.0f; + mapMaxY = 1.0f; + break; + case Background.SCALE_NONE_CENTER: + // TODO : Why is there a zoom ? + if(xzoom >= 1.0f){ + texMinU = 0.0f; + texMaxU = 1.0f; + mapMinX = -(float)maxX/winWidth; + mapMaxX = (float)maxX/winWidth; + } else { + texMinU = 0.5f - (float)winWidth/maxX/2; + texMaxU = 0.5f + (float)winWidth/maxX/2; + mapMinX = -1.0f; + mapMaxX = 1.0f; + } + if (yzoom >= 1.0f) { + texMinV = 0.0f; + texMaxV = 1.0f; + mapMinY = -(float)maxY/winHeight; + mapMaxY = (float)maxY/winHeight; + } else { + texMinV = 0.5f - (float)winHeight/maxY/2; + texMaxV = 0.5f + (float)winHeight/maxY/2; + mapMinY = -1.0f; + mapMaxY = 1.0f; + } + break; + } + + textureFillBackground(ctx, texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY); + + } + + + void clear(BackgroundRetained bg, int winWidth, int winHeight) { + + clear( ctx, bg.color.x, bg.color.y, bg.color.z); + + // TODO : This is a bug on not mirror bg. Will fix this as a bug after 1.5 beta. + // For now, as a workaround, we will check bg.image and bg.image.imageData not null. + if((bg.image != null) && (bg.image.imageData != null)) { + // setup Texture pipe. + updateTextureForRaster(bg.texture); + + textureFill(bg, winWidth, winHeight); + + // Restore texture pipe. + restoreTextureBin(); + } + } + /** * obj is either TextureRetained or DetailTextureImage * if obj is DetailTextureImage then we just clear @@ -4554,7 +4679,7 @@ public class Canvas3D extends Canvas { } // handle free resource in the FreeList - void freeResourcesInFreeList(long ctx) { + void freeResourcesInFreeList(Context ctx) { Iterator it; ArrayList list; int i, val; @@ -4573,64 +4698,61 @@ public class Canvas3D extends Canvas { displayListResourceFreeList.clear(); } - if (textureIdResourceFreeList.size() > 0) { - for (it = textureIdResourceFreeList.iterator(); it.hasNext();) { - val = ((Integer) it.next()).intValue(); - if (val <= 0) { - continue; - } - if (val >= textureIDResourceTable.size()) { - System.out.println("Error in freeResourcesInFreeList : ResourceIDTableSize = " + - textureIDResourceTable.size() + - " val = " + val); - } else { - textureIDResourceTable.set(val, null); - } - freeTexture(ctx, val); - } - textureIdResourceFreeList.clear(); - } + if (textureIdResourceFreeList.size() > 0) { + for (it = textureIdResourceFreeList.iterator(); it.hasNext();) { + val = ((Integer) it.next()).intValue(); + if (val <= 0) { + continue; + } + if (val >= textureIDResourceTable.size()) { + System.out.println("Error in freeResourcesInFreeList : ResourceIDTableSize = " + + textureIDResourceTable.size() + + " val = " + val); + } else { + Object obj = textureIDResourceTable.get(val); + if (obj instanceof TextureRetained) { + TextureRetained tex = (TextureRetained) obj; + synchronized (tex.resourceLock) { + tex.resourceCreationMask &= ~canvasBit; + if (tex.resourceCreationMask == 0) { + tex.freeTextureId(val); + } + } + } + + textureIDResourceTable.set(val, null); + } + freeTexture(ctx, val); + } + textureIdResourceFreeList.clear(); + } } void freeContextResources(Renderer rdr, boolean freeBackground, - long ctx) { + Context ctx) { Object obj; TextureRetained tex; - DetailTextureImage detailTex; // Just return if we don't have a valid renderer or context - if (rdr == null || ctx == 0) { + if (rdr == null || ctx == null) { return; } if (freeBackground) { - // Free Background Texture - // Note that we use non-shared ctx to create - // it so there is no need to do so in - // Renderer.freeContextResources() - if (rdr.objectId > 0) { - freeTexture(ctx, rdr.objectId); - VirtualUniverse.mc.freeTexture2DId(rdr.objectId); - rdr.objectId = -1; - - } - // Free Graphics2D Texture - if ((graphics2D != null) && - (graphics2D.objectId != -1)) { - freeTexture(ctx, graphics2D.objectId); - VirtualUniverse.mc.freeTexture2DId(graphics2D.objectId); - graphics2D.objectId = -1; - } + // Dispose of Graphics2D Texture + if (graphics2D != null) { + graphics2D.dispose(); + } } - for (int id = textureIDResourceTable.size()-1; id > 0; id--) { obj = textureIDResourceTable.get(id); if (obj == null) { continue; } + assert id == ((TextureRetained)obj).objectId; freeTexture(ctx, id); if (obj instanceof TextureRetained) { tex = (TextureRetained) obj; @@ -4641,19 +4763,16 @@ public class Canvas3D extends Canvas { tex.freeTextureId(id); } } - } else if (obj instanceof DetailTextureImage) { - detailTex = ((DetailTextureImage) obj); - detailTex.freeDetailTextureId(id, canvasBit); } } textureIDResourceTable.clear(); - freeAllDisplayListResources(); + freeAllDisplayListResources(ctx); } - void freeAllDisplayListResources() { + void freeAllDisplayListResources(Context ctx) { if ((view != null) && (view.renderBin != null)) { - view.renderBin.freeAllDisplayListResources(this); + view.renderBin.freeAllDisplayListResources(this, ctx); if (useSharedCtx) { // We need to rebuild all other Canvas3D resource // shared by this Canvas3D. Since we didn't @@ -4665,4 +4784,383 @@ public class Canvas3D extends Canvas { } } + + + // ***************************************************************** + // Wrappers for native methods go below here + // ***************************************************************** + + // This is the native method for creating the underlying graphics context. + private Context createNewContext(long display, Drawable drawable, + long fbConfig, Context shareCtx, boolean isSharedCtx, + boolean offScreen, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + return Pipeline.getPipeline().createNewContext(this, display, drawable, + fbConfig, shareCtx, isSharedCtx, + offScreen, + glslLibraryAvailable, + cgLibraryAvailable); + } + + private void createQueryContext(long display, Drawable drawable, + long fbConfig, boolean offScreen, int width, int height, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + Pipeline.getPipeline().createQueryContext(this, display, drawable, + fbConfig, offScreen, width, height, + glslLibraryAvailable, + cgLibraryAvailable); + } + + // This is the native for creating offscreen buffer + Drawable createOffScreenBuffer(Context ctx, long display, long fbConfig, int width, int height) { + return Pipeline.getPipeline().createOffScreenBuffer(this, + ctx, display, fbConfig, width, height); + } + + void destroyOffScreenBuffer(Context ctx, long display, long fbConfig, Drawable drawable) { + assert drawable != null; + Pipeline.getPipeline().destroyOffScreenBuffer(this, ctx, display, fbConfig, drawable); + } + + // This is the native for reading the image from the offscreen buffer + private void readOffScreenBuffer(Context ctx, int format, int type, Object data, int width, int height) { + Pipeline.getPipeline().readOffScreenBuffer(this, ctx, format, type, data, width, height); + } + + // The native method for swapBuffers + int swapBuffers(Context ctx, long dpy, Drawable drawable) { + return Pipeline.getPipeline().swapBuffers(this, ctx, dpy, drawable); + } + + // notify D3D that Canvas is resize + private int resizeD3DCanvas(Context ctx) { + return Pipeline.getPipeline().resizeD3DCanvas(this, ctx); + } + + // notify D3D to toggle between FullScreen and window mode + private int toggleFullScreenMode(Context ctx) { + return Pipeline.getPipeline().toggleFullScreenMode(this, ctx); + } + + // ----------------------------------------------------------------------------- + + // native method for setting Material when no material is present + void updateMaterial(Context ctx, float r, float g, float b, float a) { + Pipeline.getPipeline().updateMaterialColor(ctx, r, g, b, a); + } + + static void destroyContext(long display, Drawable drawable, Context ctx) { + Pipeline.getPipeline().destroyContext(display, drawable, ctx); + } + + // This is the native method for doing accumulation. + void accum(Context ctx, float value) { + Pipeline.getPipeline().accum(ctx, value); + } + + // This is the native method for doing accumulation return. + void accumReturn(Context ctx) { + Pipeline.getPipeline().accumReturn(ctx); + } + + // This is the native method for clearing the accumulation buffer. + void clearAccum(Context ctx) { + Pipeline.getPipeline().clearAccum(ctx); + } + + // This is the native method for getting the number of lights the underlying + // native library can support. + int getNumCtxLights(Context ctx) { + return Pipeline.getPipeline().getNumCtxLights(ctx); + } + + // Native method for decal 1st child setup + boolean decal1stChildSetup(Context ctx) { + return Pipeline.getPipeline().decal1stChildSetup(ctx); + } + + // Native method for decal nth child setup + void decalNthChildSetup(Context ctx) { + Pipeline.getPipeline().decalNthChildSetup(ctx); + } + + // Native method for decal reset + void decalReset(Context ctx, boolean depthBufferEnable) { + Pipeline.getPipeline().decalReset(ctx, depthBufferEnable); + } + + // Native method for decal reset + void ctxUpdateEyeLightingEnable(Context ctx, boolean localEyeLightingEnable) { + Pipeline.getPipeline().ctxUpdateEyeLightingEnable(ctx, localEyeLightingEnable); + } + + // The following three methods are used in multi-pass case + + // native method for setting blend color + void setBlendColor(Context ctx, float red, float green, + float blue, float alpha) { + Pipeline.getPipeline().setBlendColor(ctx, red, green, + blue, alpha); + } + + // native method for setting blend func + void setBlendFunc(Context ctx, int src, int dst) { + Pipeline.getPipeline().setBlendFunc(ctx, src, dst); + } + + // native method for setting fog enable flag + void setFogEnableFlag(Context ctx, boolean enableFlag) { + Pipeline.getPipeline().setFogEnableFlag(ctx, enableFlag); + } + + // Setup the full scene antialising in D3D and ogl when GL_ARB_multisamle supported + void setFullSceneAntialiasing(Context ctx, boolean enable) { + Pipeline.getPipeline().setFullSceneAntialiasing(ctx, enable); + } + + void setGlobalAlpha(Context ctx, float alpha) { + Pipeline.getPipeline().setGlobalAlpha(ctx, alpha); + } + + // Native method to update separate specular color control + void updateSeparateSpecularColorEnable(Context ctx, boolean control) { + Pipeline.getPipeline().updateSeparateSpecularColorEnable(ctx, control); + } + + // Initialization for D3D when scene begin + private void beginScene(Context ctx) { + Pipeline.getPipeline().beginScene(ctx); + } + private void endScene(Context ctx) { + Pipeline.getPipeline().endScene(ctx); + } + + // True under Solaris, + // False under windows when display mode <= 8 bit + private boolean validGraphicsMode() { + return Pipeline.getPipeline().validGraphicsMode(); + } + + // native method for setting light enables + void setLightEnables(Context ctx, long enableMask, int maxLights) { + Pipeline.getPipeline().setLightEnables(ctx, enableMask, maxLights); + } + + // native method for setting scene ambient + void setSceneAmbient(Context ctx, float red, float green, float blue) { + Pipeline.getPipeline().setSceneAmbient(ctx, red, green, blue); + } + + // native method for disabling fog + void disableFog(Context ctx) { + Pipeline.getPipeline().disableFog(ctx); + } + + // native method for disabling modelClip + void disableModelClip(Context ctx) { + Pipeline.getPipeline().disableModelClip(ctx); + } + + // native method for setting default RenderingAttributes + void resetRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride) { + Pipeline.getPipeline().resetRenderingAttributes(ctx, + depthBufferWriteEnableOverride, + depthBufferEnableOverride); + } + + // native method for setting default texture + void resetTextureNative(Context ctx, int texUnitIndex) { + Pipeline.getPipeline().resetTextureNative(ctx, texUnitIndex); + } + + // native method for activating a particular texture unit + void activeTextureUnit(Context ctx, int texUnitIndex) { + Pipeline.getPipeline().activeTextureUnit(ctx, texUnitIndex); + } + + // native method for setting default TexCoordGeneration + void resetTexCoordGeneration(Context ctx) { + Pipeline.getPipeline().resetTexCoordGeneration(ctx); + } + + // native method for setting default TextureAttributes + void resetTextureAttributes(Context ctx) { + Pipeline.getPipeline().resetTextureAttributes(ctx); + } + + // native method for setting default PolygonAttributes + void resetPolygonAttributes(Context ctx) { + Pipeline.getPipeline().resetPolygonAttributes(ctx); + } + + // native method for setting default LineAttributes + void resetLineAttributes(Context ctx) { + Pipeline.getPipeline().resetLineAttributes(ctx); + } + + // native method for setting default PointAttributes + void resetPointAttributes(Context ctx) { + Pipeline.getPipeline().resetPointAttributes(ctx); + } + + // native method for setting default TransparencyAttributes + void resetTransparency(Context ctx, int geometryType, + int polygonMode, boolean lineAA, + boolean pointAA) { + Pipeline.getPipeline().resetTransparency(ctx, geometryType, + polygonMode, lineAA, + pointAA); + } + + // native method for setting default ColoringAttributes + void resetColoringAttributes(Context ctx, + float r, float g, + float b, float a, + boolean enableLight) { + Pipeline.getPipeline().resetColoringAttributes(ctx, + r, g, + b, a, + enableLight); + } + + /** + * This native method makes sure that the rendering for this canvas + * gets done now. + */ + void syncRender(Context ctx, boolean wait) { + Pipeline.getPipeline().syncRender(ctx, wait); + } + + // The native method that sets this ctx to be the current one + static boolean useCtx(Context ctx, long display, Drawable drawable) { + return Pipeline.getPipeline().useCtx(ctx, display, drawable); + } + + // Give the Pipeline a chance to release the context. The return + // value indicates whether the context was released. + private boolean releaseCtx(Context ctx, long dpy) { + return Pipeline.getPipeline().releaseCtx(ctx, dpy); + } + + void clear(Context ctx, float r, float g, float b) { + Pipeline.getPipeline().clear(ctx, r, g, b); + } + + void textureFillBackground(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY) { + Pipeline.getPipeline().textureFillBackground(ctx, texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY); + } + + void textureFillRaster(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha) { + Pipeline.getPipeline().textureFillRaster(ctx, texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY, mapZ, alpha); + } + + void executeRasterDepth(Context ctx, float posX, float posY, float posZ, + int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight, + int depthWidth, int depthHeight, int depthType, Object depthData) { + Pipeline.getPipeline().executeRasterDepth(ctx, posX, posY, posZ, + srcOffsetX, srcOffsetY, rasterWidth, rasterHeight, depthWidth, depthHeight, depthType, depthData); + } + + // The native method for setting the ModelView matrix. + void setModelViewMatrix(Context ctx, double[] viewMatrix, double[] modelMatrix) { + Pipeline.getPipeline().setModelViewMatrix(ctx, viewMatrix, modelMatrix); + } + + // The native method for setting the Projection matrix. + void setProjectionMatrix(Context ctx, double[] projMatrix) { + Pipeline.getPipeline().setProjectionMatrix(ctx, projMatrix); + } + + // The native method for setting the Viewport. + void setViewport(Context ctx, int x, int y, int width, int height) { + Pipeline.getPipeline().setViewport(ctx, x, y, width, height); + } + + // used for display Lists + void newDisplayList(Context ctx, int displayListId) { + Pipeline.getPipeline().newDisplayList(ctx, displayListId); + } + void endDisplayList(Context ctx) { + Pipeline.getPipeline().endDisplayList(ctx); + } + void callDisplayList(Context ctx, int id, boolean isNonUniformScale) { + Pipeline.getPipeline().callDisplayList(ctx, id, isNonUniformScale); + } + + static void freeDisplayList(Context ctx, int id) { + Pipeline.getPipeline().freeDisplayList(ctx, id); + } + static void freeTexture(Context ctx, int id) { + Pipeline.getPipeline().freeTexture(ctx, id); + } + + void texturemapping(Context ctx, + int px, int py, + int xmin, int ymin, int xmax, int ymax, + int texWidth, int texHeight, + int rasWidth, + int format, int objectId, + byte[] image, + int winWidth, int winHeight) { + Pipeline.getPipeline().texturemapping(ctx, + px, py, + xmin, ymin, xmax, ymax, + texWidth, texHeight, + rasWidth, + format, objectId, + image, + winWidth, winHeight); + } + + boolean initTexturemapping(Context ctx, int texWidth, + int texHeight, int objectId) { + return Pipeline.getPipeline().initTexturemapping(ctx, texWidth, + texHeight, objectId); + } + + + // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or + // FIELD_RIGHT. Note that it is up to the caller to ensure that + // stereo is available before setting the mode to FIELD_LEFT or + // FIELD_RIGHT. The boolean isTRUE for double buffered mode, FALSE + // foe single buffering. + void setRenderMode(Context ctx, int mode, boolean doubleBuffer) { + Pipeline.getPipeline().setRenderMode(ctx, mode, doubleBuffer); + } + + // Set glDepthMask. + void setDepthBufferWriteEnable(Context ctx, boolean mode) { + Pipeline.getPipeline().setDepthBufferWriteEnable(ctx, mode); + } + + // Methods to get actual capabilities from Canvas3D + + boolean hasDoubleBuffer() { + return Pipeline.getPipeline().hasDoubleBuffer(this); + } + + boolean hasStereo() { + return Pipeline.getPipeline().hasStereo(this); + } + + int getStencilSize() { + return Pipeline.getPipeline().getStencilSize(this); + } + + boolean hasSceneAntialiasingMultisample() { + return Pipeline.getPipeline().hasSceneAntialiasingMultisample(this); + } + + boolean hasSceneAntialiasingAccum() { + return Pipeline.getPipeline().hasSceneAntialiasingAccum(this); + } + } diff --git a/src/classes/share/javax/media/j3d/CanvasViewCache.java b/src/classes/share/javax/media/j3d/CanvasViewCache.java index 53e2b58..935dbb2 100644 --- a/src/classes/share/javax/media/j3d/CanvasViewCache.java +++ b/src/classes/share/javax/media/j3d/CanvasViewCache.java @@ -434,7 +434,8 @@ class CanvasViewCache extends Object { // XXXX: Peeking at the dirty flag is a hack. Need to revisit this. boolean vprNotDirty = (viewCache.vpRetained.vprDirtyMask == 0); - if(!canvas.offScreen && + // Issue 131: If not manual, it has to be considered as an onscreen canvas. + if(!canvas.manualRendering && (vprNotDirty) && (cvcDirtyMask == 0) && (scrvcDirtyMask == 0) && diff --git a/src/classes/share/javax/media/j3d/CgShaderProgramRetained.java b/src/classes/share/javax/media/j3d/CgShaderProgramRetained.java index 0eceed3..90893b1 100644 --- a/src/classes/share/javax/media/j3d/CgShaderProgramRetained.java +++ b/src/classes/share/javax/media/j3d/CgShaderProgramRetained.java @@ -35,138 +35,250 @@ class CgShaderProgramRetained extends ShaderProgramRetained { initMirrorObject(); } - // ShaderAttributeValue methods + // ShaderAttributeValue methods - native ShaderError setUniform1i(long ctx, - long shaderProgramId, - long uniformLocation, - int value); - - native ShaderError setUniform1f(long ctx, - long shaderProgramId, - long uniformLocation, - float value); - - native ShaderError setUniform2i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform2f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniform3i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform3f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniform4i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform4f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniformMatrix3f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); + ShaderError setUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + + return Pipeline.getPipeline().setCgUniform1i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + + return Pipeline.getPipeline().setCgUniform1f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setCgUniform2i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setCgUniform2f(ctx, + shaderProgramId, + uniformLocation, + value); + } - native ShaderError setUniformMatrix4f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); + ShaderError setUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setCgUniform3i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setCgUniform3f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setCgUniform4i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setCgUniform4f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setCgUniformMatrix3f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setCgUniformMatrix4f(ctx, + shaderProgramId, + uniformLocation, + value); + } // ShaderAttributeArray methods - native ShaderError setUniform1iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform1fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform2iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform2fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform3iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform3fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform4iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform4fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniformMatrix3fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); + ShaderError setUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { - native ShaderError setUniformMatrix4fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); + return Pipeline.getPipeline().setCgUniform1iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + ShaderError setUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniform1fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setCgUniform2iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniform2fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setCgUniform3iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniform3fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setCgUniform4iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniform4fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniformMatrix3fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setCgUniformMatrix4fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } - - /* New native interfaces */ - private native ShaderError createNativeShader(long ctx, int shaderType, long[] shaderId); - private native ShaderError destroyNativeShader(long ctx, long shaderId); - private native ShaderError compileNativeShader(long ctx, long shaderId, String program); - - private native ShaderError createNativeShaderProgram(long ctx, long[] shaderProgramId); - private native ShaderError destroyNativeShaderProgram(long ctx, long shaderProgramId); - private native ShaderError linkNativeShaderProgram(long ctx, long shaderProgramId, - long[] shaderId); - private native void lookupNativeVertexAttrNames(long ctx, long shaderProgramId, - int numAttrNames, String[] attrNames, boolean[] errArr); - private native void lookupNativeShaderAttrNames(long ctx, long shaderProgramId, - int numAttrNames, String[] attrNames, long[] locArr, - int[] typeArr, int[] sizeArr, boolean[] isArrayArr); - - private native ShaderError useShaderProgram(long ctx, long shaderProgramId); /** * Method to return a flag indicating whether this @@ -179,70 +291,65 @@ class CgShaderProgramRetained extends ShaderProgramRetained { /** * Method to create the native shader. */ - ShaderError createShader(long ctx, ShaderRetained shader, long[] shaderIdArr) { - return createNativeShader(ctx, shader.shaderType, shaderIdArr); + ShaderError createShader(Context ctx, ShaderRetained shader, ShaderId[] shaderIdArr) { + return Pipeline.getPipeline().createCgShader(ctx, shader.shaderType, shaderIdArr); } /** * Method to destroy the native shader. */ - ShaderError destroyShader(long ctx, long shaderId) { - return destroyNativeShader(ctx, shaderId); + ShaderError destroyShader(Context ctx, ShaderId shaderId) { + return Pipeline.getPipeline().destroyCgShader(ctx, shaderId); } /** * Method to compile the native shader. */ - ShaderError compileShader(long ctx, long shaderId, String source) { - return compileNativeShader(ctx, shaderId, source ); + ShaderError compileShader(Context ctx, ShaderId shaderId, String source) { + return Pipeline.getPipeline().compileCgShader(ctx, shaderId, source ); } /** * Method to create the native shader program. */ - ShaderError createShaderProgram(long ctx, long[] shaderProgramIdArr) { - return createNativeShaderProgram(ctx, shaderProgramIdArr); + ShaderError createShaderProgram(Context ctx, ShaderProgramId[] shaderProgramIdArr) { + return Pipeline.getPipeline().createCgShaderProgram(ctx, shaderProgramIdArr); } /** * Method to destroy the native shader program. */ - ShaderError destroyShaderProgram(long ctx, long shaderProgramId) { - return destroyNativeShaderProgram(ctx, shaderProgramId); + ShaderError destroyShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return Pipeline.getPipeline().destroyCgShaderProgram(ctx, shaderProgramId); } /** * Method to link the native shader program. */ - ShaderError linkShaderProgram(long ctx, long shaderProgramId, long[] shaderIds) { - return linkNativeShaderProgram(ctx, shaderProgramId, shaderIds); + ShaderError linkShaderProgram(Context ctx, ShaderProgramId shaderProgramId, ShaderId[] shaderIds) { + return Pipeline.getPipeline().linkCgShaderProgram(ctx, shaderProgramId, shaderIds); } - ShaderError bindVertexAttrName(long ctx, long shaderProgramId, String attrName, int attrIndex) { + ShaderError bindVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, String attrName, int attrIndex) { // This is a no-op for Cg return null; } - void lookupVertexAttrNames(long ctx, long shaderProgramId, String[] attrNames, boolean[] errArr) { - lookupNativeVertexAttrNames(ctx, shaderProgramId, attrNames.length, attrNames, errArr); + void lookupVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, boolean[] errArr) { + Pipeline.getPipeline().lookupCgVertexAttrNames(ctx, shaderProgramId, attrNames.length, attrNames, errArr); } - void lookupShaderAttrNames(long ctx, long shaderProgramId, + void lookupShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, AttrNameInfo[] attrNameInfoArr) { int numAttrNames = attrNames.length; - long[] locArr = new long[numAttrNames]; + ShaderAttrLoc[] locArr = new ShaderAttrLoc[numAttrNames]; int[] typeArr = new int[numAttrNames]; int[] sizeArr = new int[numAttrNames]; // currently unused boolean[] isArrayArr = new boolean[numAttrNames]; - // Initialize loc array to -1 (indicating no location) - for (int i = 0; i < numAttrNames; i++) { - locArr[i] = -1; - } - - lookupNativeShaderAttrNames(ctx, shaderProgramId, + Pipeline.getPipeline().lookupCgShaderAttrNames(ctx, shaderProgramId, numAttrNames, attrNames, locArr, typeArr, sizeArr, isArrayArr); for (int i = 0; i < numAttrNames; i++) { @@ -263,15 +370,15 @@ class CgShaderProgramRetained extends ShaderProgramRetained { /** * Method to enable the native shader program. */ - ShaderError enableShaderProgram(long ctx, long shaderProgramId) { - return useShaderProgram(ctx, shaderProgramId); + ShaderError enableShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return Pipeline.getPipeline().useCgShaderProgram(ctx, shaderProgramId); } /** * Method to disable the native shader program. */ - ShaderError disableShaderProgram(long ctx) { - return useShaderProgram(ctx, 0); + ShaderError disableShaderProgram(Context ctx) { + return Pipeline.getPipeline().useCgShaderProgram(ctx, null); } diff --git a/src/classes/share/javax/media/j3d/ClipRetained.java b/src/classes/share/javax/media/j3d/ClipRetained.java index 73a0385..ee18e8b 100644 --- a/src/classes/share/javax/media/j3d/ClipRetained.java +++ b/src/classes/share/javax/media/j3d/ClipRetained.java @@ -361,7 +361,7 @@ class ClipRetained extends LeafRetained { } final void sendMessage(int attrMask, Object attr, Object attr2) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.CLIP_CHANGED; createMessage.universe = universe; diff --git a/src/classes/share/javax/media/j3d/ColoringAttributesRetained.java b/src/classes/share/javax/media/j3d/ColoringAttributesRetained.java index 4507f9c..d21e01d 100644 --- a/src/classes/share/javax/media/j3d/ColoringAttributesRetained.java +++ b/src/classes/share/javax/media/j3d/ColoringAttributesRetained.java @@ -141,22 +141,14 @@ class ColoringAttributesRetained extends NodeComponentRetained { ((ColoringAttributesRetained) mirror).set(this); } } - /** - * These two native methods update the native context - */ - native void updateNative(long ctx, - float dRed, float dGreen, float dBlue, - float red, float green, float blue, - float alpha, - boolean lEnable, - int shadeModel); - - void updateNative(long ctx, + + void updateNative(Context ctx, float dRed, float dGreen, float dBlue, float alpha, boolean lEnable) { - updateNative(ctx, dRed, dBlue, dGreen, color.x, color.y, - color.z, alpha, - lEnable, shadeModel); + Pipeline.getPipeline().updateColoringAttributes(ctx, + dRed, dBlue, dGreen, color.x, color.y, + color.z, alpha, + lEnable, shadeModel); } /** @@ -213,7 +205,7 @@ class ColoringAttributesRetained extends NodeComponentRetained { ArrayList gaList = Shape3DRetained.getGeomAtomsList(mirror.users, univList); // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.COLORINGATTRIBUTES_CHANGED; createMessage.universe = null; @@ -226,7 +218,7 @@ class ColoringAttributesRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; i 0) { - for (Enumeration e = Screen3D.deviceRendererMap.elements(); - e.hasMoreElements(); ) { - Renderer rdr = (Renderer) e.nextElement(); - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); - renderMessage.threads = J3dThread.RENDER_THREAD; - renderMessage.type = J3dMessage.RENDER_IMMEDIATE; - renderMessage.universe = null; - renderMessage.view = null; - renderMessage.args[0] = null; - renderMessage.args[1] = new Integer(objectIds[i]); - renderMessage.args[2] = "2D"; - rdr.rendererStructure.addMessage(renderMessage); - } - objectIds[i] = -1; - found = true; - } - } - if (found) { - VirtualUniverse.mc.setWorkForRequestRenderer(); - } - } - } - } - - void notifyImageComponentImageChanged(ImageComponentRetained image, - Object value) { - if (resourceCreationMask != null) { - synchronized(resourceLock) { - for (int i = 0; i < NFORMAT; i++) { - resourceCreationMask[i] = 0; - } - } - } - } - - void bindTexture(Canvas3D cv, int format) { - synchronized(resourceLock) { - if (objectIds == null) { - objectIds = new int[NFORMAT]; - for (int i = 0; i < NFORMAT; i++) { - objectIds[i] = -1; - } - } - - if (objectIds[format] == -1) { - objectIds[format] = VirtualUniverse.mc.getTexture2DId(); - } - cv.addTextureResource(objectIds[format], this); - } - - bindTexture(cv.ctx, objectIds[format]); - } - - - void updateNative(Canvas3D cv, int format) { - if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_DETAIL) == 0) { - return; - } - - boolean reloadTexture = false; - - // bind the detail texture - - bindTexture(cv, format); - - if (cv.useSharedCtx && cv.screen.renderer.sharedCtx != 0) { - if ((resourceCreationMask[format] & cv.screen.renderer.rendererBit) - == 0) { - reloadTexture = true; - cv.makeCtxCurrent(cv.screen.renderer.sharedCtx); - bindTexture(cv, format); - } - } else { - if ((resourceCreationMask[format] & cv.canvasBit) == 0) { - reloadTexture = true; - } - } - - // No D3D support yet - - if (reloadTexture) { - - updateTextureImage(cv.ctx, 1, 0, format, image.storedYupFormat, - image.width, image.height, 0, image.imageYup); - - - // Rendered image - - } - - if (cv.useSharedCtx) { - cv.makeCtxCurrent(cv.ctx); - synchronized(resourceLock) { - resourceCreationMask[format] |= cv.screen.renderer.rendererBit; - } - } else { - synchronized(resourceLock) { - resourceCreationMask[format] |= cv.canvasBit; - } - } - } -} - - - diff --git a/src/classes/share/javax/media/j3d/DirectionalLightRetained.java b/src/classes/share/javax/media/j3d/DirectionalLightRetained.java index 79c7bf6..9c3f681 100644 --- a/src/classes/share/javax/media/j3d/DirectionalLightRetained.java +++ b/src/classes/share/javax/media/j3d/DirectionalLightRetained.java @@ -55,7 +55,7 @@ class DirectionalLightRetained extends LightRetained */ void setDirection(Vector3f direction) { initDirection(direction); - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.LIGHT_CHANGED; createMessage.universe = universe; @@ -168,13 +168,11 @@ class DirectionalLightRetained extends LightRetained } - native void updateLight(long ctx, - int lightSlot, float red, float green, - float blue, float x, float y, float z); - void update(long ctx, int lightSlot, double scale) { - updateLight(ctx, lightSlot, color.x, color.y, color.z, - xformDirection.x, xformDirection.y, - xformDirection.z); + void update(Context ctx, int lightSlot, double scale) { + Pipeline.getPipeline().updateDirectionalLight(ctx, + lightSlot, color.x, color.y, color.z, + xformDirection.x, xformDirection.y, + xformDirection.z); } // Clones only the retained side, internal use only diff --git a/src/classes/share/javax/media/j3d/DisplayListRenderMethod.java b/src/classes/share/javax/media/j3d/DisplayListRenderMethod.java index b452528..d6aeb76 100644 --- a/src/classes/share/javax/media/j3d/DisplayListRenderMethod.java +++ b/src/classes/share/javax/media/j3d/DisplayListRenderMethod.java @@ -29,19 +29,17 @@ class DisplayListRenderMethod implements RenderMethod { */ int[] buffer = new int[bufferSize]; - native void callDisplayLists(int size, int[] buffer); - /** * The actual rendering code for this RenderMethod */ - public boolean render(RenderMolecule rm, Canvas3D cv, int pass, + public boolean render(RenderMolecule rm, Canvas3D cv, RenderAtomListInfo ra, int dirtyBits) { if (rm.doInfinite || !VirtualUniverse.mc.viewFrustumCulling || rm.vwcBounds.intersect(cv.viewFrustum)) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.callDisplayList(cv.ctx, rm.displayListId, rm.isNonUniformScale); return true; @@ -51,11 +49,10 @@ class DisplayListRenderMethod implements RenderMethod { public boolean renderSeparateDlists(RenderMolecule rm, Canvas3D cv, - int pass, RenderAtomListInfo r, int dirtyBits) { if (rm.doInfinite) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); while (r != null) { cv.callDisplayList(cv.ctx, ((GeometryArrayRetained)r.geometry()).dlistId, @@ -70,7 +67,7 @@ class DisplayListRenderMethod implements RenderMethod { while (r != null) { if (cv.ra == r.renderAtom) { if (cv.raIsVisible) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.callDisplayList(cv.ctx, ((GeometryArrayRetained)r.geometry()).dlistId, rm.isNonUniformScale); @@ -79,7 +76,7 @@ class DisplayListRenderMethod implements RenderMethod { } else { if (r.renderAtom.localeVwcBounds.intersect(cv.viewFrustum)) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.raIsVisible = true; cv.callDisplayList(cv.ctx, ((GeometryArrayRetained)r.geometry()).dlistId, @@ -101,12 +98,11 @@ class DisplayListRenderMethod implements RenderMethod { public boolean renderSeparateDlistPerRinfo(RenderMolecule rm, Canvas3D cv, - int pass, RenderAtomListInfo r, int dirtyBits) { if (rm.doInfinite) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); while (r != null) { cv.callDisplayList(cv.ctx,r.renderAtom.dlistIds[r.index], rm.isNonUniformScale); @@ -118,7 +114,7 @@ class DisplayListRenderMethod implements RenderMethod { while (r != null) { if (cv.ra == r.renderAtom) { if (cv.raIsVisible) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.callDisplayList(cv.ctx, r.renderAtom.dlistIds[r.index], rm.isNonUniformScale); isVisible = true; @@ -126,7 +122,7 @@ class DisplayListRenderMethod implements RenderMethod { } else { if (r.renderAtom.localeVwcBounds.intersect(cv.viewFrustum)) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.raIsVisible = true; cv.callDisplayList(cv.ctx, r.renderAtom.dlistIds[r.index], rm.isNonUniformScale); @@ -190,7 +186,7 @@ class DisplayListRenderMethod implements RenderMethod { } void buildIndividualDisplayList(RenderAtomListInfo ra, Canvas3D cv, - long ctx) { + Context ctx) { GeometryArrayRetained geo; geo = (GeometryArrayRetained)ra.geometry(); diff --git a/src/classes/share/javax/media/j3d/DistanceLOD.java b/src/classes/share/javax/media/j3d/DistanceLOD.java index 2598eb8..948558b 100644 --- a/src/classes/share/javax/media/j3d/DistanceLOD.java +++ b/src/classes/share/javax/media/j3d/DistanceLOD.java @@ -177,7 +177,7 @@ public class DistanceLOD extends LOD { double viewDistance = 0.0; int nSwitches,i,index=0; - Transform3D localToWorldTrans = VirtualUniverse.mc.getTransform3D(null); + Transform3D localToWorldTrans = new Transform3D(); localToWorldTrans.set(((NodeRetained)this.retained).getCurrentLocalToVworld()); @@ -220,9 +220,6 @@ public class DistanceLOD extends LOD { sw.setWhichChild(index); } } - - VirtualUniverse.mc.addToTransformFreeList(localToWorldTrans); - // Insert wakeup condition into queue wakeupOn(wakeupFrame); diff --git a/src/classes/share/javax/media/j3d/Drawable.java b/src/classes/share/javax/media/j3d/Drawable.java new file mode 100644 index 0000000..77e9f5a --- /dev/null +++ b/src/classes/share/javax/media/j3d/Drawable.java @@ -0,0 +1,22 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Tagging interface for drawable (window) objects. The rendering pipelines + * will define concrete classes that implement this interface. All code that + * uses the tagged objects will be in the pipelines. + */ +interface Drawable { + // No methods or constants defined at this time +} diff --git a/src/classes/share/javax/media/j3d/DrawingSurfaceObjectAWT.java b/src/classes/share/javax/media/j3d/DrawingSurfaceObjectAWT.java index d4dfa23..71d8167 100644 --- a/src/classes/share/javax/media/j3d/DrawingSurfaceObjectAWT.java +++ b/src/classes/share/javax/media/j3d/DrawingSurfaceObjectAWT.java @@ -21,27 +21,29 @@ import java.awt.Point; class DrawingSurfaceObjectAWT extends DrawingSurfaceObject { // drawing surface - long nativeDS = 0; - long dsi = 0; + private long nativeDS = 0; + private long dsi = 0; - boolean doLastUnlock = false; - boolean xineramaDisabled = false; + private boolean doLastUnlock = false; + private boolean xineramaDisabled = false; - long display = 0; - int screenID = 0; + private long display = 0; + private int screenID = 0; - static long nativeAWT = 0; + private static long nativeAWT = 0; - native boolean lockAWT(long ds); - native void unlockAWT(long ds); - static native void lockGlobal(long awt); - static native void unlockGlobal(long awt); - native long getDrawingSurfaceAWT(Canvas3D cv, long awt); - native long getDrawingSurfaceInfo(long ds); - static native void freeResource(long awt, long ds, long dsi); - native int getDrawingSurfaceWindowIdAWT(Canvas3D cv, long ds, long dsi, - long display, int screenID, - boolean xineramaDisabled); + private native boolean lockAWT(long ds); + private native void unlockAWT(long ds); + private static native void lockGlobal(long awt); + private static native void unlockGlobal(long awt); + private native long getDrawingSurfaceAWT(Canvas3D cv, long awt); + private native long getDrawingSurfaceInfo(long ds); + private static native void freeResource(long awt, long ds, long dsi); + + // TODO: long window + private native int getDrawingSurfaceWindowIdAWT(Canvas3D cv, long ds, long dsi, + long display, int screenID, + boolean xineramaDisabled); DrawingSurfaceObjectAWT(Canvas3D cv, long awt, long display, int screenID, @@ -110,9 +112,10 @@ class DrawingSurfaceObjectAWT extends DrawingSurfaceObject { if (nativeDS != 0) { dsi = getDrawingSurfaceInfo(nativeDS); if (dsi != 0) { - canvas.window = getDrawingSurfaceWindowIdAWT + long nativeDrawable = getDrawingSurfaceWindowIdAWT (canvas, nativeDS, dsi, display, screenID, xineramaDisabled); + canvas.drawable = new NativeDrawable(nativeDrawable); } } } diff --git a/src/classes/share/javax/media/j3d/EnvironmentSet.java b/src/classes/share/javax/media/j3d/EnvironmentSet.java index 200c1ae..35c6cac 100644 --- a/src/classes/share/javax/media/j3d/EnvironmentSet.java +++ b/src/classes/share/javax/media/j3d/EnvironmentSet.java @@ -366,9 +366,6 @@ class EnvironmentSet extends Object implements ObjectUpdate{ a.definingRenderingAttributes = null; a.onUpdateList &= ~AttributeBin.ON_CHANGED_FREQUENT_UPDATE_LIST; - // Add this attributebin to the free list - renderBin.attrBinFreelist.add(a); - if (attributeBinList == null && addAttributeBins.size() == 0) { // Now remove this environment set from all the lights and fogs // that use this diff --git a/src/classes/share/javax/media/j3d/ExceptionStrings.properties b/src/classes/share/javax/media/j3d/ExceptionStrings.properties index b1541ba..8d13787 100644 --- a/src/classes/share/javax/media/j3d/ExceptionStrings.properties +++ b/src/classes/share/javax/media/j3d/ExceptionStrings.properties @@ -42,6 +42,8 @@ Background8=Background: no capability to get application bounds Background9=Background: no capability to set image scale mode Background10=Background: no capability to get image scale mode Background11=Background: illegal image scale mode +Background12=Background: Live Background with an ImageComponent2D that is being used by a Canvas3D as an off-screen buffer. +Background13=Background: In Immediate mode context with an ImageComponent2D that is being used by a Canvas3D as an off-screen buffer. AlternateAppearance0=AlternateAppearance: no capability to write appearance AlternateAppearance2=AlternateAppearance: no capability to read appearance AlternateAppearance3=AlternateAppearance: no capability to write influencing bounds @@ -121,7 +123,7 @@ Canvas3D0=Canvas3D: Cannot swap buffers when the renderer is running Canvas3D1=Canvas3D: Not in off-screen mode Canvas3D2=Canvas3D: Off-screening rendering is in progress Canvas3D3=Canvas3D: The specified ImageComponent2D is used by more than on Canvas3D -Canvas3D7=*** ERROR: Canvas3D constructed with a null GraphicsConfiguration +Canvas3D7=WARNING: Canvas3D constructed with null GraphicsConfiguration; Canvas3D8=Canvas3D: The width of the associated Screen3D's size is <= 0 Canvas3D9=Canvas3D: The height of the associated Screen3D's size is <= 0 Canvas3D10=Canvas3D: Off-screen buffer is null @@ -130,14 +132,19 @@ Canvas3D12=Canvas3D: The physical width of the associated Screen3D is <= 0 Canvas3D13=Canvas3D: The physical height of the associated Screen3D is <= 0 Canvas3D14=Canvas3D: Illegal operation in off-screen mode Canvas3D15=Canvas3D: For offscreen rendering, byReference image should be an instance of BufferedImage -Canvas3D16=Canvas3D: Offscreen rendering does not support FORMAT_CHANNEL8 +Canvas3D16=Canvas3D: Offscreen rendering has to be a 3-component or 4-component format. Canvas3D17=Canvas3D: GraphicsConfiguration is not compatible with Canvas3D -Canvas3D18=*** This will cause a NullPointerException in a subsequent release +Canvas3D18=will attempt to use a default GraphicsConfiguration Canvas3D19=Canvas3D: null GraphicsConfiguration Canvas3D20=Canvas3D does not support serialization -Canvas3D21=*** ERROR: GraphicsConfiguration not created with GraphicsConfigTemplate3D -Canvas3D22=*** This will cause an IllegalArgumentException in a subsequent release Canvas3D23=Unable to get FBConfig from GraphicsConfiguration +Canvas3D24=Canvas3D: Can't force render of offscreen buffer because it is an automatic one. +Canvas3D25=Canvas3D: AutoOffscreenCanvas3D must be used as off-screen Canvas3D. +Canvas3D26=Canvas3D: ImageComponent2D is already part of a live scene graph. +Canvas3D27=Canvas3D: ImageComponent2D is already being used by an immediate mode context. +Canvas3D28=Canvas3D: ImageComponent2D is already being used by by another Canvas3D as an off-screen buffer. +Canvas3D29=Canvas3D: Non-recoverable graphics configuration error +Canvas3D30=Canvas3D: Non-recoverable off-screen rendering error BoundingPolytope0=BoundingPolytope( Bounds) unrecognized bounds object BoundingPolytope1=BoundingPolytope( Bounds) unrecognized bounds type BoundingPolytope2=set( Bounds) unrecognized bounds type @@ -303,6 +310,9 @@ GeometryArray132=GeometryArray: vertexAttrCount != vertexAttrSizes.length GeometryArray133=GeometryArray: vertexAttrSize value out of range GeometryArray134=GeometryArray: vertexAttrSize invalid for this method GeometryArray135=GeometryArray: USE_COORD_INDEX_ONLY bit cannot be set for non-indexed geometry +GeometryArray136=GeometryArray: BY_REFERENCE_INDICES bit can be set only for indexed geometry +GeometryArray137=GeometryArray: BY_REFERENCE_INDICES bit can be set only if BY_REFERENCE bit is also set +GeometryArray138=GeometryArray: BY_REFERENCE_INDICES bit can be set only if USE_COORD_INDEX_ONLY bit is also set GeometryDecompressor0=GeometryDecompressor: start+length > data array size GeometryDecompressor1=GeometryDecompressor: bad delta normal in compressed buffer GeometryDecompressorRetained0=GeometryDecompressorRetained: bad buffer data type @@ -328,6 +338,7 @@ Light8=Light: no capability to read scopes Light9=Light: no capability to append scope Light11=Light: no capability to write influencing bounds Light12=Light: no capability to read influencing bounds +GeometryStripArrayRetained0=Illegal stripVertexCounts GeometryStripArray0=GeometryStripArray: no capability to get number of strips GeometryStripArray1=GeometryStripArray: no capability to get strip vertex counts GeometryStripArray2=GeometryStripArray: no capability to set strip vertex counts @@ -349,16 +360,30 @@ GraphicsContext3D25=ModelClip: Scene Graph ModelClip may not be in immediate mod GraphicsContext3D26=Shape3D: Scene Graph Shape3D may not be in immediate mode GraphicsContext3D27=ImageComponent2D size is smaller than read Raster size GraphicsContext3D28=DepthComponent size is smaller than read Raster size +GraphicsContext3D29=GraphicsContext3D: For readRaster, byReference image should be an instance of BufferedImage +GraphicsContext3D30=GraphicsContext3D: Appearance has an ImageComponent2D used by an OffScreen Canvas3D. +GraphicsContext3D31=GraphicsContext3D: Background's ImageComponent2D is already being used as an OffScreen Canvas3D. +GraphicsContext3D32=GraphicsContext3D: Raster's ImageComponent2D is already being used as an OffScreen Canvas3D. +GraphicsContext3D33=GraphicsContext3D: Raster's ImageComponent2D is not of ImageClass.BUFFERED_IMAGE. +GraphicsContext3D34=GraphicsContext3D: Raster's ImageComponent2D is in by-reference mode and its RenderedImage is null. +GraphicsContext3D35=GraphicsContext3D: Raster's ImageComponent2D format is not a 3-component format or a 4-component format. +GraphicsContext3D36=GraphicsContext3D: Raster and Raster's ImageComponent2D are part of a live scene graph. +GraphicsContext3D37=GraphicsContext3D: Raster's ImageComponent2D is being used by an immediate mode context, or by a Canvas3D as an off-screen buffer. ImageComponent0=ImageComponent: no capability to get width ImageComponent1=ImageComponent: no capability to get height ImageComponent2=ImageComponent: no capability to get format -GeometryStripArrayRetained0=Illegal stripVertexCounts +ImageComponent3=ImageComponent: This image is being used by a Canvas3D as an off-screen buffer. +ImageComponent4=ImageComponent: The image class of this object is ImageClass.NIO_IMAGE_BUFFER. ImageComponent2D0=ImageComponent2D: no capability to get image ImageComponent2D1=ImageComponent2D: no capability to set image ImageComponent2D2=ImageComponent2D: must be in BY_REFERENCE mode to use this method ImageComponent2D3=ImageComponent2D: illegal dimension ImageComponent2D4=ImageComponent2D: must be in BY_COPY mode to use this method ImageComponent2D5=ImageComponent2D: image is not an instanceof of BufferedImage +ImageComponent2D6=ImageComponent2D: type mismatch between sub-image and existing image. +ImageComponent2D7=ImageComponent2D: Nio buffer image must be byReference is true. +ImageComponent2D8=ImageComponent2D: Nio buffer image must be yUp is true. +ImageComponent2D9=ImageComponent2D: The image class is not ImageClass.NIO_IMAGE_BUFFER. ImageComponent3D0=ImageComponent3D: no capability to get depth ImageComponent3D1=ImageComponent3D - incompatible depth ImageComponent3D2=ImageComponent3D - incompatible width @@ -408,6 +433,9 @@ IndexedGeometryArray27=IndexedGeometryArray: index value less than zero IndexedGeometryArray28=IndexedGeometryArray: no capability to set vertex attribute index IndexedGeometryArray29=IndexedGeometryArray: no capability to get vertex attribute index IndexedGeometryArray30=IndexedGeometryArray: index vertexAttr value greater than the array length +IndexedGeometryArray31=IndexedGeometryArray: cannot access indices directly in BY_REFERENCE_INDICES mode +IndexedGeometryArray32=IndexedGeometryArray: can access indices by reference only in BY_REFERENCE_INDICES mode +IndexedGeometryArray33=IndexedGeometryArray: coordIndices array length < initial index index + valid index count IndexedLineArray0=IndexedLineArray: illegal vertexCount IndexedLineArray1=IndexedLineArray: illegal indexCount IndexedGeometryStripArray0=IndexedGeometryStripArray: no capability to get number of strips @@ -490,6 +518,12 @@ MorphRetained5=Invalid SceneGraphPath encountered : localToVworld is null. MorphRetained7=Morph: number of weights not same as number of GeometryArrays MorphRetained8=Morph: sum of all weights is NOT 1.0 MorphRetained9=Morph: vertex attributes are not supported +NioImageBuffer0=NioImageBuffer: image width is not positive +NioImageBuffer1=NioImageBuffer: image height is not positive +NioImageBuffer2=NioImageBuffer: unsupported image type +NioImageBuffer3=NioImageBuffer: NIO buffer limit is incorrect +NioImageBuffer4=NioImageBuffer: NIO buffer type does not match image type +NioImageBuffer5=NioImageBuffer: NIO buffer does not match native byte order of underlying platform Node0=Node: no capability to read parent Node1=Node: no capability to set bounds Node2=Node: no capability to read user bounds @@ -518,6 +552,8 @@ Picking0=Cannot call picking under a SharedGroup node Picking2=Picking: Node has no parent and locale. This is illegal! NodeComponent0=NodeComponent:cloneNodeComponent must be defined in subclass NodeComponent1=Cannot duplicate a Compiled NodeComponent object +NodeComponent2=Live NodeComponent with an ImageComponent2D that is being used by a Canvas3D as an off-screen buffer. +NodeComponent3=In Immediate mode context with an ImageComponent2D that is being used by a Canvas3D as an off-screen buffer. NodeRetained0=Not supported in a Shared Graph NodeRetained1=Only supported in a Shared Graph NodeRetained2=invalid scene graph path @@ -570,6 +606,7 @@ Raster8=Raster: no capability to get offset Raster9=Raster: no capability to set size Raster10=Raster: no capability to set clip mode Raster11=Raster: no capability to get clip mode +Raster12=Raster: Live Raster with an ImageComponent2D that is being used by a Canvas3D as an off-screen buffer. PointArrayRetained0=PickPoint doesn't make sense for geometry-based picking. Java 3D doesn't have spatial information of the surface. Should use PickBounds with BoundingSphere and set radius to a epsilon tolerance. PointAttributes0=PointAttributes: no capability to set point size PointAttributes1=PointAttributes: no capability to get point size @@ -590,6 +627,15 @@ PolygonAttributes12=PolygonAttributes: illegal cull face QuadArray0=QuadArray: illegal vertexCount QuadArrayRetained0=PickPoint doesn't make sense for geometry-based picking. Java 3D doesn't have spatial information of the surface. Should use PickBounds with BoundingSphere and set radius to a epsilon tolerance. PositionPathInterpolator0=PositionPathInterpolator: length of knots and positions must be equal +Renderer0=Renderer: Unexpected RuntimeException caught during buffer swap +Renderer1=Renderer: Error initializing GraphicsConfiguration properties +Renderer2=Renderer: Error creating Canvas3D graphics context for queryProperties() +Renderer3=Renderer: Error in GraphicsConfigTemplate3D.getBestConfiguration() +Renderer4=Renderer: Error in GraphicsConfigTemplate3D.isConfigSupported() +Renderer5=Renderer: Error creating Canvas3D off-screen buffer +Renderer6=Renderer: Error creating immediate mode Canvas3D graphics context +Renderer7=Renderer: Error creating Canvas3D graphics context +Renderer8=Renderer: Unexpected RuntimeException caught during rendering RenderingAttributes0=RenderingAttributes: no capability to set depth buffer mode RenderingAttributes1=RenderingAttributes: no capability to get depth buffer mode RenderingAttributes2=RenderingAttributes: no capability to set depth buffer write mode @@ -748,7 +794,7 @@ Texture26=Texture: no capability to get anisotropic filter information Texture27=Texture: Illegal anisotropic filter degree Texture28=Texture: Illegal minification filter Texture29=Texture: Illegal magnification filter -Texture30=Texture: boundary width < 0 +Texture30=Texture: illegal boundary width Texture31=Texture: illegal boundary mode value Texture32=Texture: no capability to set base level Texture33=Texture: no capability to set maximum level @@ -764,6 +810,8 @@ Texture42=Texture: minimumLOD > maximumLOD Texture43=Texture: maximumLOD < minimumLOD Texture44=Texture: no capability to set lod offset Texture45=Texture: no capability to get lod offset +Texture46=Texture: illegal width < 1 +Texture47=Texture: illegal height < 1 Texture2D0=Texture: no capability to get detail texture information Texture2D1=Texture: Illegal detail texture mode value Texture2D2=Texture: Illegal detail texture level @@ -926,12 +974,12 @@ ModelClip13=ModelClip: no capability to write influencing bounding leaf ModelClip14=ModelClip: no capability to read influencing bounding leaf ModelClipRetained1=ModelClip: illegal node under SharedGroup Branch MasterControl0=OpenGL is not MT safe -MasterControl1=Green threads are not supported MasterControl2=NOTE: simulated multi-texture will not work for programmable shaders MasterControl3=and will be removed entirely in the next release of Java 3D J3DBuffer0=Native access to NIO buffer not supported J3DBuffer1=NIO buffer must be a direct buffer J3DBuffer2=NIO buffer must match native byte order of underlying platform +J3DGraphics2D0=Cannot use Graphics2D object after dispose() is called GLSLShaderProgram0=GLSLShaderProgram: no capability to read names GLSLShaderProgram1=GLSLShaderProgram: no capability to read shaders GLSLShaderProgram2=GLSLShaderProgram: Shader has incompatible shading language diff --git a/src/classes/share/javax/media/j3d/ExponentialFogRetained.java b/src/classes/share/javax/media/j3d/ExponentialFogRetained.java index 48d9a64..367929c 100644 --- a/src/classes/share/javax/media/j3d/ExponentialFogRetained.java +++ b/src/classes/share/javax/media/j3d/ExponentialFogRetained.java @@ -46,7 +46,7 @@ class ExponentialFogRetained extends FogRetained { */ void setDensity(float density){ this.density = density; - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.FOG_CHANGED; createMessage.universe = universe; @@ -70,7 +70,7 @@ class ExponentialFogRetained extends FogRetained { // Initialize the mirror object, this needs to be done, when // renderBin is not accessing any of the fields - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.FOG_CHANGED; @@ -108,12 +108,10 @@ class ExponentialFogRetained extends FogRetained { * This method and its native counterpart update the native context * fog values. */ - native void update(long ctx, float red, float green, float blue, float density); - - void update(long ctx, double scale) { + void update(Context ctx, double scale) { // Issue 144: recompute the density in EC, and send it to native code validateDistancesInEc(scale); - update(ctx, color.x, color.y, color.z, densityInEc); + Pipeline.getPipeline().updateExponentialFog(ctx, color.x, color.y, color.z, densityInEc); } diff --git a/src/classes/share/javax/media/j3d/FogRetained.java b/src/classes/share/javax/media/j3d/FogRetained.java index 75ce250..ab1350e 100644 --- a/src/classes/share/javax/media/j3d/FogRetained.java +++ b/src/classes/share/javax/media/j3d/FogRetained.java @@ -452,7 +452,7 @@ abstract class FogRetained extends LeafRetained{ * This abstract method is used to update the current native * context fog values. */ - abstract void update(long ctx, double scale); + abstract void update(Context ctx, double scale); void updateImmediateMirrorObject(Object[] objs) { @@ -715,7 +715,7 @@ abstract class FogRetained extends LeafRetained{ if (scopes.size() > 0) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.FOG_CHANGED; @@ -771,7 +771,7 @@ abstract class FogRetained extends LeafRetained{ } final void sendMessage(int attrMask, Object attr) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.universe = universe; createMessage.type = J3dMessage.FOG_CHANGED; diff --git a/src/classes/share/javax/media/j3d/FreeListManager.java b/src/classes/share/javax/media/j3d/FreeListManager.java index 15fa177..3c8df81 100644 --- a/src/classes/share/javax/media/j3d/FreeListManager.java +++ b/src/classes/share/javax/media/j3d/FreeListManager.java @@ -18,46 +18,26 @@ class FreeListManager { private static final boolean DEBUG = false; // constants that represent the freelists managed by the Manager - static final int MESSAGE = 0; - static final int BHLEAF = 1; - static final int TRANSFORM3D = 2; - static final int BHINTERNAL = 3; - static final int DISPLAYLIST = 4; - static final int TEXTURE2D = 5; - static final int TEXTURE3D = 6; - static final int VECTOR3D = 7; - static final int POINT3D = 8; - static int MAXINT = 8; + static final int DISPLAYLIST = 0; + static final int TEXTURE2D = 1; + static final int TEXTURE3D = 2; + + private static int maxFreeListNum = 2; // what list we are going to shrink next private static int currlist = 0; - // the freelists managed by the manager - static MemoryFreeList[] freelist = new MemoryFreeList[MAXINT+1]; - + static MemoryFreeList[] freelist = null; + static void createFreeLists() { - freelist[MESSAGE] = new MemoryFreeList("javax.media.j3d.J3dMessage"); - freelist[BHLEAF] = new MemoryFreeList("javax.media.j3d.BHLeafNode"); - freelist[TRANSFORM3D] = new MemoryFreeList("javax.media.j3d.Transform3D"); - freelist[BHINTERNAL] = new MemoryFreeList("javax.media.j3d.BHInternalNode"); - freelist[DISPLAYLIST] = new IntegerFreeList(); - freelist[TEXTURE2D] = new IntegerFreeList(); - freelist[TEXTURE3D] = new IntegerFreeList(); - freelist[POINT3D] = new MemoryFreeList("javax.vecmath.Point3d"); - freelist[VECTOR3D] = new MemoryFreeList("javax.vecmath.Vector3d"); + maxFreeListNum = 2; + freelist = new MemoryFreeList[maxFreeListNum+1]; + freelist[DISPLAYLIST] = new IntegerFreeList(); + freelist[TEXTURE2D] = new IntegerFreeList(); + freelist[TEXTURE3D] = new IntegerFreeList(); + } - // allows list to be created. The listId for the new list is returned. - static int createNewFreeList(String className) { - MAXINT++; - MemoryFreeList[] temp = freelist; - freelist = new MemoryFreeList[MAXINT+1]; - System.arraycopy(temp, 0, freelist, 0, MAXINT+1); - freelist[MAXINT] = new MemoryFreeList(className); - return MAXINT; - } - - // see if the current list can be shrunk static void manageLists() { // System.out.println("manageLists"); @@ -66,12 +46,12 @@ class FreeListManager { } currlist++; - if (currlist > MAXINT) currlist = 0; + if (currlist > maxFreeListNum) currlist = 0; } // return the freelist specified by the list param static MemoryFreeList getFreeList(int list) { - if (list < 0 || list > MAXINT) { + if (list < 0 || list > maxFreeListNum) { if (DEBUG) System.out.println("illegal list"); return null; } @@ -92,5 +72,4 @@ class FreeListManager { freelist[listId].clear(); } - } diff --git a/src/classes/share/javax/media/j3d/GLSLShaderProgramRetained.java b/src/classes/share/javax/media/j3d/GLSLShaderProgramRetained.java index 651d15d..81e7a44 100644 --- a/src/classes/share/javax/media/j3d/GLSLShaderProgramRetained.java +++ b/src/classes/share/javax/media/j3d/GLSLShaderProgramRetained.java @@ -29,8 +29,8 @@ class GLSLShaderProgramRetained extends ShaderProgramRetained { // System.out.println("GLSLShaderProgramRetained : createMirrorObject"); // This method should only call by setLive(). if (mirror == null) { - GLSLShaderProgramRetained mirrorGLSLSP = new GLSLShaderProgramRetained(); - mirror = mirrorGLSLSP; + GLSLShaderProgramRetained mirrorGLSLSP = new GLSLShaderProgramRetained(); + mirror = mirrorGLSLSP; mirror.source = source; } initMirrorObject(); @@ -38,134 +38,247 @@ class GLSLShaderProgramRetained extends ShaderProgramRetained { // ShaderAttributeValue methods - native ShaderError setUniform1i(long ctx, - long shaderProgramId, - long uniformLocation, - int value); - - native ShaderError setUniform1f(long ctx, - long shaderProgramId, - long uniformLocation, - float value); - - native ShaderError setUniform2i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform2f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniform3i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform3f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniform4i(long ctx, - long shaderProgramId, - long uniformLocation, - int[] value); - - native ShaderError setUniform4f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniformMatrix3f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - - native ShaderError setUniformMatrix4f(long ctx, - long shaderProgramId, - long uniformLocation, - float[] value); - + ShaderError setUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + + return Pipeline.getPipeline().setGLSLUniform1i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + + return Pipeline.getPipeline().setGLSLUniform1f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform2i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform2f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform3i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform3f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform4i(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform4f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniformMatrix3f(ctx, + shaderProgramId, + uniformLocation, + value); + } + + ShaderError setUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniformMatrix4f(ctx, + shaderProgramId, + uniformLocation, + value); + } + // ShaderAttributeArray methods - native ShaderError setUniform1iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform1fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform2iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform2fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform3iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform3fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniform4iArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - int[] value); - - native ShaderError setUniform4fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniformMatrix3fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - native ShaderError setUniformMatrix4fArray(long ctx, - long shaderProgramId, - long uniformLocation, - int numElements, - float[] value); - - /* New native interfaces */ - private native ShaderError createNativeShader(long ctx, int shaderType, long[] shaderId); - private native ShaderError destroyNativeShader(long ctx, long shaderId); - private native ShaderError compileNativeShader(long ctx, long shaderId, String program); - - private native ShaderError createNativeShaderProgram(long ctx, long[] shaderProgramId); - private native ShaderError destroyNativeShaderProgram(long ctx, long shaderProgramId); - private native ShaderError linkNativeShaderProgram(long ctx, long shaderProgramId, - long[] shaderId); - private native ShaderError bindNativeVertexAttrName(long ctx, long shaderProgramId, - String attrName, int attrIndex); - private native void lookupNativeShaderAttrNames(long ctx, long shaderProgramId, - int numAttrNames, String[] attrNames, long[] locArr, - int[] typeArr, int[] sizeArr, boolean[] isArrayArr); - - private native ShaderError useShaderProgram(long ctx, long shaderProgramId); + ShaderError setUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform1iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform1fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform2iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform2fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform3iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform3fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + + return Pipeline.getPipeline().setGLSLUniform4iArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniform4fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniformMatrix3fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } + + ShaderError setUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + + return Pipeline.getPipeline().setGLSLUniformMatrix4fArray(ctx, + shaderProgramId, + uniformLocation, + numElements, + value); + } /** * Method to return a flag indicating whether this @@ -178,69 +291,64 @@ class GLSLShaderProgramRetained extends ShaderProgramRetained { /** * Method to create the native shader. */ - ShaderError createShader(long ctx, ShaderRetained shader, long[] shaderIdArr) { - return createNativeShader(ctx, shader.shaderType, shaderIdArr); + ShaderError createShader(Context ctx, ShaderRetained shader, ShaderId[] shaderIdArr) { + return Pipeline.getPipeline().createGLSLShader(ctx, shader.shaderType, shaderIdArr); } /** * Method to destroy the native shader. */ - ShaderError destroyShader(long ctx, long shaderId) { - return destroyNativeShader(ctx, shaderId); + ShaderError destroyShader(Context ctx, ShaderId shaderId) { + return Pipeline.getPipeline().destroyGLSLShader(ctx, shaderId); } /** * Method to compile the native shader. */ - ShaderError compileShader(long ctx, long shaderId, String source) { - return compileNativeShader(ctx, shaderId, source ); + ShaderError compileShader(Context ctx, ShaderId shaderId, String source) { + return Pipeline.getPipeline().compileGLSLShader(ctx, shaderId, source ); } /** * Method to create the native shader program. */ - ShaderError createShaderProgram(long ctx, long[] shaderProgramIdArr) { - return createNativeShaderProgram(ctx, shaderProgramIdArr); + ShaderError createShaderProgram(Context ctx, ShaderProgramId[] shaderProgramIdArr) { + return Pipeline.getPipeline().createGLSLShaderProgram(ctx, shaderProgramIdArr); } /** * Method to destroy the native shader program. */ - ShaderError destroyShaderProgram(long ctx, long shaderProgramId) { - return destroyNativeShaderProgram(ctx, shaderProgramId); + ShaderError destroyShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return Pipeline.getPipeline().destroyGLSLShaderProgram(ctx, shaderProgramId); } /** * Method to link the native shader program. */ - ShaderError linkShaderProgram(long ctx, long shaderProgramId, long[] shaderIds) { - return linkNativeShaderProgram(ctx, shaderProgramId, shaderIds); + ShaderError linkShaderProgram(Context ctx, ShaderProgramId shaderProgramId, ShaderId[] shaderIds) { + return Pipeline.getPipeline().linkGLSLShaderProgram(ctx, shaderProgramId, shaderIds); } - ShaderError bindVertexAttrName(long ctx, long shaderProgramId, String attrName, int attrIndex) { - return bindNativeVertexAttrName(ctx, shaderProgramId, attrName, attrIndex); + ShaderError bindVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, String attrName, int attrIndex) { + return Pipeline.getPipeline().bindGLSLVertexAttrName(ctx, shaderProgramId, attrName, attrIndex); } - void lookupVertexAttrNames(long ctx, long shaderProgramId, String[] attrNames, boolean[] errArr) { + void lookupVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, boolean[] errArr) { // This method is a no-op for GLSL } - void lookupShaderAttrNames(long ctx, long shaderProgramId, + void lookupShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, AttrNameInfo[] attrNameInfoArr) { int numAttrNames = attrNames.length; - long[] locArr = new long[numAttrNames]; + ShaderAttrLoc[] locArr = new ShaderAttrLoc[numAttrNames]; int[] typeArr = new int[numAttrNames]; int[] sizeArr = new int[numAttrNames]; // currently unused boolean[] isArrayArr = new boolean[numAttrNames]; - // Initialize loc array to -1 (indicating no location) - for (int i = 0; i < numAttrNames; i++) { - locArr[i] = -1; - } - - lookupNativeShaderAttrNames(ctx, shaderProgramId, + Pipeline.getPipeline().lookupGLSLShaderAttrNames(ctx, shaderProgramId, numAttrNames, attrNames, locArr, typeArr, sizeArr, isArrayArr); for (int i = 0; i < numAttrNames; i++) { @@ -259,15 +367,15 @@ class GLSLShaderProgramRetained extends ShaderProgramRetained { /** * Method to enable the native shader program. */ - ShaderError enableShaderProgram(long ctx, long shaderProgramId) { - return useShaderProgram(ctx, shaderProgramId); + ShaderError enableShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return Pipeline.getPipeline().useGLSLShaderProgram(ctx, shaderProgramId); } /** * Method to disable the native shader program. */ - ShaderError disableShaderProgram(long ctx) { - return useShaderProgram(ctx, 0); + ShaderError disableShaderProgram(Context ctx) { + return Pipeline.getPipeline().useGLSLShaderProgram(ctx, null); } diff --git a/src/classes/share/javax/media/j3d/GeometryArray.java b/src/classes/share/javax/media/j3d/GeometryArray.java index e1ca8d6..e2e8ec6 100644 --- a/src/classes/share/javax/media/j3d/GeometryArray.java +++ b/src/classes/share/javax/media/j3d/GeometryArray.java @@ -327,10 +327,20 @@ public abstract class GeometryArray extends Geometry { */ public static final int VERTEX_ATTRIBUTES = 0x1000; + //NVaidya + /** + * Specifies that the indices in this GeometryArray + * are accessed by reference. This flag is only valid for + * indexed geometry arrays (subclasses of IndexedGeometryArray) and only + * when used in conjunction with the BY_REFERENCE and + * USE_COORD_INDEX_ONLY flags. + * + * @since Java 3D 1.5 + */ + public static final int BY_REFERENCE_INDICES = 0x2000; // Used to keep track of the last bit (for adding new bits only) - private static final int LAST_FORMAT_BIT = 0x1000; - + private static final int LAST_FORMAT_BIT = 0x2000; // Scratch arrays for converting Point[234]f to TexCoord[234]f private TexCoord2f [] texCoord2fArray = null; @@ -360,7 +370,7 @@ public abstract class GeometryArray extends Geometry { setDefaultReadCapabilities(readCapabilities); } - + //NVaidya /** * Constructs an empty GeometryArray object with the specified * number of vertices and vertex format. Defaults are used @@ -404,7 +414,10 @@ public abstract class GeometryArray extends Geometry { * is accessed via a J3DBuffer object that wraps an NIO buffer; * USE_COORD_INDEX_ONLY, * to indicate that only the coordinate indices are used for indexed - * geometry arrays. + * geometry arrays; + * BY_REFERENCE_INDICES, to indicate + * that the indices are accessed by reference in indexed + * geometry arrays.

    * * @exception IllegalArgumentException if vertexCount < 0 * @@ -412,7 +425,8 @@ public abstract class GeometryArray extends Geometry { * include COORDINATES * * @exception IllegalArgumentException if the USE_COORD_INDEX_ONLY - * bit is set for non-indexed geometry arrays (that is, GeometryArray objects + * bit or the BY_REFERENCE_INDICES bit is set for + * non-indexed geometry arrays (that is, GeometryArray objects * that are not a subclass of IndexedGeometryArray) * * @exception IllegalArgumentException if the INTERLEAVED @@ -423,6 +437,11 @@ public abstract class GeometryArray extends Geometry { * * @exception IllegalArgumentException if the INTERLEAVED * bit and the VERTEX_ATTRIBUTES bit are both set + * + * @exception IllegalArgumentException if the + * BY_REFERENCE_INDICES + * bit is set without the BY_REFERENCE and + * USE_COORD_INDEX_ONLY bits being set */ public GeometryArray(int vertexCount, int vertexFormat) { this(vertexCount, vertexFormat, @@ -431,6 +450,7 @@ public abstract class GeometryArray extends Geometry { } + //NVaidya /** * Constructs an empty GeometryArray object with the specified * number of vertices, vertex format, number of texture coordinate @@ -462,6 +482,9 @@ public abstract class GeometryArray extends Geometry { * is accessed via a J3DBuffer object that wraps an NIO buffer; * USE_COORD_INDEX_ONLY, * to indicate that only the coordinate indices are used for indexed + * geometry arrays; + * BY_REFERENCE_INDICES, to indicate + * that the indices are accessed by reference in indexed * geometry arrays.

    * * @param texCoordSetCount the number of texture coordinate sets @@ -536,7 +559,8 @@ public abstract class GeometryArray extends Geometry { * include COORDINATES * * @exception IllegalArgumentException if the USE_COORD_INDEX_ONLY - * bit is set for non-indexed geometry arrays (that is, GeometryArray objects + * bit or the BY_REFERENCE_INDICES bit is set for + * non-indexed geometry arrays (that is, GeometryArray objects * that are not a subclass of IndexedGeometryArray) * * @exception IllegalArgumentException if the INTERLEAVED @@ -548,6 +572,11 @@ public abstract class GeometryArray extends Geometry { * @exception IllegalArgumentException if the INTERLEAVED * bit and the VERTEX_ATTRIBUTES bit are both set * + * @exception IllegalArgumentException if the + * BY_REFERENCE_INDICES + * bit is set without the BY_REFERENCE and + * USE_COORD_INDEX_ONLY bits being set + * * @exception IllegalArgumentException if * texCoordSetCount < 0 * @@ -564,6 +593,7 @@ public abstract class GeometryArray extends Geometry { } + //NVaidya /** * Constructs an empty GeometryArray object with the specified * number of vertices, vertex format, number of texture coordinate @@ -597,6 +627,9 @@ public abstract class GeometryArray extends Geometry { * is accessed via a J3DBuffer object that wraps an NIO buffer; * USE_COORD_INDEX_ONLY, * to indicate that only the coordinate indices are used for indexed + * geometry arrays; + * BY_REFERENCE_INDICES, to indicate + * that the indices are accessed by reference in indexed * geometry arrays.

    * * @param texCoordSetCount the number of texture coordinate sets @@ -681,7 +714,8 @@ public abstract class GeometryArray extends Geometry { * include COORDINATES * * @exception IllegalArgumentException if the USE_COORD_INDEX_ONLY - * bit is set for non-indexed geometry arrays (that is, GeometryArray objects + * bit or the BY_REFERENCE_INDICES bit is set for + * non-indexed geometry arrays (that is, GeometryArray objects * that are not a subclass of IndexedGeometryArray) * * @exception IllegalArgumentException if the INTERLEAVED @@ -693,6 +727,11 @@ public abstract class GeometryArray extends Geometry { * @exception IllegalArgumentException if the INTERLEAVED * bit and the VERTEX_ATTRIBUTES bit are both set * + * @exception IllegalArgumentException if the + * BY_REFERENCE_INDICES + * bit is set without the BY_REFERENCE and + * USE_COORD_INDEX_ONLY bits being set + * * @exception IllegalArgumentException if * texCoordSetCount < 0 * @@ -748,6 +787,16 @@ public abstract class GeometryArray extends Geometry { throw new IllegalArgumentException(J3dI18N.getString("GeometryArray135")); } + //NVaidya + if ((vertexFormat & BY_REFERENCE_INDICES) != 0) { + if (!(this instanceof IndexedGeometryArray)) + throw new IllegalArgumentException(J3dI18N.getString("GeometryArray136")); + if ((vertexFormat & BY_REFERENCE) == 0) + throw new IllegalArgumentException(J3dI18N.getString("GeometryArray137")); + if ((vertexFormat & USE_COORD_INDEX_ONLY) == 0) + throw new IllegalArgumentException(J3dI18N.getString("GeometryArray138")); + } + if ((vertexFormat & USE_NIO_BUFFER) != 0 && (vertexFormat & BY_REFERENCE) == 0) throw new IllegalArgumentException(J3dI18N.getString("GeometryArray117")); diff --git a/src/classes/share/javax/media/j3d/GeometryArrayRetained.java b/src/classes/share/javax/media/j3d/GeometryArrayRetained.java index f50a9e1..5a82c09 100644 --- a/src/classes/share/javax/media/j3d/GeometryArrayRetained.java +++ b/src/classes/share/javax/media/j3d/GeometryArrayRetained.java @@ -62,7 +62,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // vertex data in packed format for each screen in multi-screen situation // if alpha values of each vertex are to be updated - float mvertexData[][]; + private float mvertexData[][]; // // The following offset/stride values are internally computed @@ -94,14 +94,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ int vertexAttrStride; // alpha value for transparency and texture blending - float[] lastAlpha = new float[1]; + private float[] lastAlpha = new float[1]; float lastScreenAlpha = -1; int colorChanged = 0; - // true if alpha value from transparencyAttrubute has changed - boolean alphaChanged = false; - // byte to float scale factor static final float ByteToFloatScale = 1.0f/255.0f; @@ -162,7 +159,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ static final int P3D = 0x8; static final int VERTEX_DEFINED = PF | PD | P3F | P3D; - static final int CF = 0x10; static final int CUB = 0x20; static final int C3F = 0x40; @@ -170,19 +166,19 @@ abstract class GeometryArrayRetained extends GeometryRetained{ static final int C3UB = 0x100; static final int C4UB = 0x200; static final int COLOR_DEFINED = CF | CUB | C3F | C4F| C3UB | C4UB; - + static final int NF = 0x400; static final int N3F = 0x800; static final int NORMAL_DEFINED = NF | N3F; - + static final int TF = 0x1000; static final int T2F = 0x2000; static final int T3F = 0x4000; static final int TEXCOORD_DEFINED = TF | T2F | T3F; - + static final int AF = 0x8000; static final int VATTR_DEFINED = AF; - + // Flag word indicating the type of by-ref texCoord. We will copy this to // the vertexType field only when the references for all texture coordinate // sets are set to non-null values. @@ -340,12 +336,12 @@ abstract class GeometryArrayRetained extends GeometryRetained{ IndexedGeometryArrayRetained cloneSourceArray = null; -// private MemoryFreeList pickVectorFreelist = -// FreeListManager.getFreeList(FreeListManager.PICKVECTOR); - static final double EPS = 1.0e-13; - native void freeD3DArray(boolean deleteVB); + void freeD3DArray(boolean deleteVB) { + assert VirtualUniverse.mc.isD3D(); + Pipeline.getPipeline().freeD3DArray(this, deleteVB); + } GeometryArrayRetained() { dirtyFlag = INDEX_CHANGED|VERTEX_CHANGED; @@ -363,7 +359,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (this.refCount > 1) { // Send to rendering attribute structure, /* - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.GEOMETRYARRAY_CHANGED; createMessage.universe = null; @@ -378,7 +374,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // otherwise, set mirrorGeometry to null (from previous clearLive) if (this instanceof IndexedGeometryArrayRetained) { // Send to rendering attribute structure, - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.GEOMETRY_CHANGED; createMessage.universe = null; @@ -396,7 +392,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (this.refCount <= 0) { if (pVertexBuffers != 0) { - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); + J3dMessage renderMessage = new J3dMessage(); renderMessage.threads = J3dThread.RENDER_THREAD; renderMessage.type = J3dMessage.RENDER_IMMEDIATE; renderMessage.universe = null; @@ -1644,93 +1640,15 @@ abstract class GeometryArrayRetained extends GeometryRetained{ } - // used for GeometryArrays by Copy or interleaved - private native void execute(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean useAlpha, - boolean multiScreen, - boolean ignoreVertexColors, - int startVIndex, int vcount, int vformat, - int texCoordSetCount, int texCoordSetMap[], - int texCoordSetMapLen, - int[] texCoordSetOffset, - int numActiveTexUnitState, - int[] texUnitStateMap, - int vertexAttrCount, int[] vertexAttrSizes, - float[] varray, float[] cdata, int texUnitIndex, int cdirty); - - // used by GeometryArray by Reference with java arrays - private native void executeVA(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean multiScreen, - boolean ignoreVertexColors, - int vcount, - int vformat, - int vdefined, - int coordIndex, float[] vfcoords, double[] vdcoords, - int colorIndex, float[] cfdata, byte[] cbdata, - int normalIndex, float[] ndata, - int vertexAttrCount, int[] vertexAttrSizes, - int[] vertexAttrIndex, float[][] vertexAttrData, - int pass, int texcoordmaplength, - int[] texcoordoffset, - int numActiveTexUnitState, int[] texunitstatemap, - int[] texIndex, int texstride, Object[] texCoords, - int cdirty); - - // used by GeometryArray by Reference with NIO buffer - private native void executeVABuffer(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean multiScreen, - boolean ignoreVertexColors, - int vcount, - int vformat, - int vdefined, - int coordIndex, - Object vcoords, - int colorIndex, - Object cdataBuffer, - float[] cfdata, byte[] cbdata, - int normalIndex, Object ndata, - int vertexAttrCount, int[] vertexAttrSizes, - int[] vertexAttrIndex, Object[] vertexAttrData, - int pass, int texcoordmaplength, - int[] texcoordoffset, - int numActiveTexUnitState, int[] texunitstatemap, - int[] texIndex, int texstride, Object[] texCoords, - int cdirty); - - // used by GeometryArray by Reference in interleaved format with NIO buffer - private native void executeInterleavedBuffer(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean useAlpha, - boolean multiScreen, - boolean ignoreVertexColors, - int startVIndex, int vcount, int vformat, - int texCoordSetCount, int texCoordSetMap[], - int texCoordSetMapLen, - int[] texCoordSetOffset, - int numActiveTexUnitState, - int[] texUnitStateMap, - Object varray, float[] cdata, int texUnitIndex, int cdirty); - - private native void setVertexFormat(long ctx, - int vformat, boolean useAlpha, boolean ignoreVertexColors); - - private native void disableGlobalAlpha(long ctx, int vformat, - boolean useAlpha, boolean ignoreVertexColors); - - void setVertexFormat(boolean useAlpha, boolean ignoreVC, long ctx) { - setVertexFormat(ctx, vertexFormat, useAlpha, ignoreVC); + void setVertexFormat(boolean useAlpha, boolean ignoreVC, Context ctx) { + Pipeline.getPipeline().setVertexFormat(ctx, + this, vertexFormat, useAlpha, ignoreVC); } - void disableGlobalAlpha(long ctx, boolean useAlpha, boolean ignoreVC) { + void disableGlobalAlpha(Context ctx, boolean useAlpha, boolean ignoreVC) { // If global alpha was turned on, then disable it - disableGlobalAlpha(ctx, vertexFormat, useAlpha, ignoreVC); + Pipeline.getPipeline().disableGlobalAlpha(ctx, + this, vertexFormat, useAlpha, ignoreVC); } @@ -1745,12 +1663,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ return mirrorFloatRefColors[0]; } - // Issue 113 - // TODO: Fix this for screen > 0, for now just ignore transparency - if (screen > 0) { - return mirrorFloatRefColors[0]; - } - // update alpha only if vertex format includes alpha if (((vertexFormat | c4fAllocated) & GeometryArray.WITH_ALPHA) == 0) return mirrorFloatRefColors[0]; @@ -1762,17 +1674,18 @@ abstract class GeometryArrayRetained extends GeometryRetained{ alpha = (float)EPSILON; } - // allocate an entry for the last alpha of the screen if needed - if (lastAlpha == null) { - lastAlpha = new float[screen + 1]; - lastAlpha[screen] = 1.0f; - } else if (lastAlpha.length <= screen) { + assert lastAlpha != null; + assert mirrorFloatRefColors != null; + assert mirrorFloatRefColors.length == lastAlpha.length; + + // Issue 113 - reallocate lastAlpha array if needed, but no need to + // update the values here + if (lastAlpha.length <= screen) { float[] la = new float[screen + 1]; for (int i = 0; i < lastAlpha.length; i++) { la[i] = lastAlpha[i]; } lastAlpha = la; - lastAlpha[screen] = 1.0f; } //System.out.println("updateAlphaInFloatRefColors screen is " + screen @@ -1780,48 +1693,30 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // mirrorFloatRefColors.length); // allocate a copy of the color data for the screen if needed. - // this piece of code is mainly for multi-screens case + // this piece of code is only for multi-screens case if (mirrorFloatRefColors.length <= screen) { float[][] cfData = new float[screen + 1][]; - float[] cdata; - int refScreen = -1; for (int i = 0; i < mirrorFloatRefColors.length; i++) { cfData[i] = mirrorFloatRefColors[i]; - if (Math.abs(lastAlpha[i] - alpha) < EPSILON) { - refScreen = i; - } } - cdata = cfData[screen] = new float[4 * vertexCount]; - // copy the data from a reference screen which has the closest - // alpha values - if (refScreen >= 0) { - System.arraycopy(cfData[refScreen], 0, cdata, 0, - 4 * vertexCount); - lastAlpha[screen] = lastAlpha[refScreen]; - } else { - float m = alpha / lastAlpha[0]; - float[] sdata = cfData[0]; + // Issue 113 - allocate entries for [oldSize..screen]; + // copy cfData[0] to cfData[oldsize..screen-1] and + // lastAlpha[0] to lastAlpha[oldsize..screen-1]. + for (int i = mirrorFloatRefColors.length; i < screen+1; i++) { + cfData[i] = new float[4 * vertexCount]; + System.arraycopy(cfData[0], 0, cfData[i], 0, 4 * vertexCount); + lastAlpha[i] = lastAlpha[0]; + } - int j = initialColorIndex * 4; - for (int i = initialColorIndex; i < validVertexCount; i++) { - cdata[j] = sdata[j++]; - cdata[j] = sdata[j++]; - cdata[j] = sdata[j++]; - cdata[j] = sdata[j++] * m; - } - lastAlpha[screen] = alpha; - } - mirrorFloatRefColors = cfData; + mirrorFloatRefColors = cfData; - // reset the colorChanged bit - colorChanged &= ~(1 << screen); - dirtyFlag |= COLOR_CHANGED; - - return cdata; + // Issue 113 - since we copied the data from screen 0, we don't need + // to do any further special processing. } + assert lastAlpha[screen] >= 0.0; /* System.out.println("updateAlphaInFloatRefColors ** : lastAlpha[screen] " + lastAlpha[screen]); @@ -1832,7 +1727,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if ((colorChanged & (1< 0, for now just ignore transparency - if (screen > 0) { - return mirrorUnsignedByteRefColors[0]; - } - // update alpha only if vertex format includes alpha if (((vertexFormat | c4fAllocated) & GeometryArray.WITH_ALPHA) == 0) return mirrorUnsignedByteRefColors[0]; @@ -1936,59 +1825,45 @@ abstract class GeometryArrayRetained extends GeometryRetained{ alpha = (float)EPSILON; } - // allocate an entry for the last alpha of the screen if needed - if (lastAlpha == null) { - lastAlpha = new float[screen + 1]; - lastAlpha[screen] = -1.0f; - } else if (lastAlpha.length <= screen) { + assert lastAlpha != null; + assert mirrorUnsignedByteRefColors != null; + assert mirrorUnsignedByteRefColors.length == lastAlpha.length; + + // Issue 113 - reallocate lastAlpha array if needed, but no need to + // update the values here + if (lastAlpha.length <= screen) { float[] la = new float[screen + 1]; for (int i = 0; i < lastAlpha.length; i++) { la[i] = lastAlpha[i]; } lastAlpha = la; - lastAlpha[screen] = -1.0f; } // allocate a copy of the color data for the screen if needed. - // this piece of code is mainly for multi-screens case + // this piece of code is only for multi-screens case if (mirrorUnsignedByteRefColors.length <= screen) { - byte[][] cfData = new byte[screen + 1][]; - byte[] cdata; - int refScreen = -1; + byte[][] cbData = new byte[screen + 1][]; for (int i = 0; i < mirrorUnsignedByteRefColors.length; i++) { - cfData[i] = mirrorUnsignedByteRefColors[i]; - if (Math.abs(lastAlpha[i] - alpha) < EPSILON) { - refScreen = i; - } + cbData[i] = mirrorUnsignedByteRefColors[i]; } - cdata = cfData[screen] = new byte[4 * vertexCount]; - // copy the data from a reference screen which has the closest - // alpha values - if (refScreen >= 0) { - System.arraycopy(cfData[refScreen], 0, cdata, 0, - 4 * vertexCount); - lastAlpha[screen] = lastAlpha[refScreen]; - } else { - float m = alpha / lastAlpha[0]; - byte[] sdata = cfData[0]; + // Issue 113 - allocate entries for [oldSize..screen]; + // copy cbData[0] to cbData[oldsize..screen-1] and + // lastAlpha[0] to lastAlpha[oldsize..screen-1]. + for (int i = mirrorUnsignedByteRefColors.length; i < screen+1; i++) { + cbData[i] = new byte[4 * vertexCount]; + System.arraycopy(cbData[0], 0, cbData[i], 0, 4 * vertexCount); + lastAlpha[i] = lastAlpha[0]; + } - int j = initialColorIndex * 4; - for (int i = initialColorIndex; i < validVertexCount; i++) { - cdata[j] = sdata[j++]; - cdata[j] = sdata[j++]; - cdata[j] = sdata[j++]; - cdata[j] = (byte)(((int)sdata[j++]& 0xff) * m); - } - lastAlpha[screen] = alpha; - } - mirrorUnsignedByteRefColors = cfData; - colorChanged &= ~(1 << screen); - dirtyFlag |= COLOR_CHANGED; - return cdata; + mirrorUnsignedByteRefColors = cbData; + + // Issue 113 - since we copied the data from screen 0, we don't need + // to do any further special processing. } - /* + assert lastAlpha[screen] >= 0.0; + /* System.out.println("updateAlphaInByteRefColors ## : lastAlpha[screen] " + lastAlpha[screen]); @@ -1998,7 +1873,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if ((colorChanged & (1< 0, for now just ignore transparency - if (screen > 0) { - retVal[1] = vertexData; - return retVal; - } - // update alpha only if vertex format includes alpha if ((vertexFormat & GeometryArray.COLOR) == 0) { retVal[1] = vertexData; @@ -2101,81 +1969,61 @@ abstract class GeometryArrayRetained extends GeometryRetained{ } retVal[0] = Boolean.TRUE; - // allocate an entry for the last alpha of the screen if needed - if (lastAlpha == null) { - lastAlpha = new float[screen + 1]; - lastAlpha[screen] = 1.0f; - } else if (lastAlpha.length <= screen) { + assert lastAlpha != null; + assert mvertexData == null || mvertexData.length == lastAlpha.length; + + // Issue 113 - reallocate lastAlpha array if needed, but no need to + // update the values here + if (lastAlpha.length <= screen) { float[] la = new float[screen + 1]; for (int i = 0; i < lastAlpha.length; i++) { la[i] = lastAlpha[i]; } lastAlpha = la; - lastAlpha[screen] = 1.0f; } // allocate a copy of the vertex data for the screen if needed. - // this piece of code is mainly for multi-screens case - // NOTE: this might not too much data for just to update alpha + // Note that a copy operation only happens in the multi-screens case. + // We always use the existing vertexData for screen 0. if (mvertexData == null || mvertexData.length <= screen) { float[][] cfData = new float[screen + 1][]; - float[] cdata; - int refScreen = -1; + int oldSize = 1; if (mvertexData != null) { + oldSize = mvertexData.length; for (int i = 0; i < mvertexData.length; i++) { cfData[i] = mvertexData[i]; - if (Math.abs(lastAlpha[i] - alpha) < EPSILON) { - refScreen = i; - } } } if (cfData[0] == null) { - cfData[screen] = vertexData; - } - - if (screen > 0) - cfData[screen] = new float[stride * vertexCount]; - - cdata = cfData[screen]; - - // copy the data from a reference screen which has the closest - // alpha values - if (refScreen >= 0) { - System.arraycopy(cfData[refScreen], 0, cdata, 0, - stride * vertexCount); - lastAlpha[screen] = lastAlpha[refScreen]; - } else { - float m = alpha / lastAlpha[0]; - float[] sdata = cfData[0]; + cfData[0] = vertexData; + } + + // Issue 113 - allocate entries for [oldSize..screen]; + // copy cfData[0] to cfData[oldsize..screen-1] and + // lastAlpha[0] to lastAlpha[oldsize..screen-1]. + if (screen > 0) { + for (int i = oldSize; i < screen+1; i++) { + cfData[i] = new float[stride * vertexCount]; + System.arraycopy(cfData[0], 0, cfData[i], 0, + stride * vertexCount); + lastAlpha[i] = lastAlpha[0]; + } + } - /* - // screen 0 data is always up-to-date - if (screen > 0) { - System.arraycopy(cfData[0], 0, cdata, 0, - stride * vertexCount); - } - */ + mvertexData = cfData; - for (int i = 0, j = colorOffset; i < vertexCount; - i++, j+=stride) { - cdata[j+3] = sdata[j+3] * m; - } - lastAlpha[screen] = alpha; - } - mvertexData = cfData; - dirtyFlag |= COLOR_CHANGED; - // reset the colorChanged bit - colorChanged &= ~(1 << screen); - retVal[1] = cdata; - return retVal; + // Issue 113 - since we copied the data from screen 0, we don't need + // to do any further special processing. } + + assert lastAlpha[screen] >= 0.0; if ((colorChanged & (1< 0, for now just ignore transparency - if (screen > 0) { - retVal[1] = null; - return retVal; - } - // update alpha only if vertex format includes alpha - if (((vertexFormat | c4fAllocated) & GeometryArray.COLOR) == 0) { + if (((vertexFormat | c4fAllocated) & GeometryArray.WITH_ALPHA) == 0) { retVal[1] = mirrorInterleavedColorPointer[0]; return retVal; } @@ -2259,66 +2100,50 @@ abstract class GeometryArrayRetained extends GeometryRetained{ } retVal[0] = Boolean.TRUE; - // allocate an entry for the last alpha of the screen if needed - if (lastAlpha == null) { - lastAlpha = new float[screen + 1]; - lastAlpha[screen] = 1.0f; - } else if (lastAlpha.length <= screen) { + assert lastAlpha != null; + assert mirrorInterleavedColorPointer != null; + assert mirrorInterleavedColorPointer.length == lastAlpha.length; + + // Issue 113 - reallocate lastAlpha array if needed, but no need to + // update the values here + if (lastAlpha.length <= screen) { float[] la = new float[screen + 1]; for (int i = 0; i < lastAlpha.length; i++) { la[i] = lastAlpha[i]; } lastAlpha = la; - lastAlpha[screen] = 1.0f; } // allocate a copy of the vertex data for the screen if needed. - // this piece of code is mainly for multi-screens case - // NOTE: this might not too much data for just to update alpha + // this piece of code is only for multi-screens case if (mirrorInterleavedColorPointer.length <= screen) { float[][] cfData = new float[screen + 1][]; - float[] cdata; - int refScreen = -1; for (int i = 0; i < mirrorInterleavedColorPointer.length; i++) { cfData[i] = mirrorInterleavedColorPointer[i]; - if (Math.abs(lastAlpha[i] - alpha) < EPSILON) { - refScreen = i; - } } - //cdata = cfData[screen] = new float[stride * vertexCount]; - cdata = cfData[screen] = new float[4 * vertexCount]; - - // copy the data from a reference screen which has the closest - // alpha values - if (refScreen >= 0) { - System.arraycopy(cfData[refScreen], 0, cdata, 0, - 4 * vertexCount); - lastAlpha[screen] = lastAlpha[refScreen]; - } else { - float m = alpha / lastAlpha[0]; - float[] sdata = cfData[0]; - - for (int i = coffset; i < coffset + (vertexCount << 2); i+=4) { - cdata[i+3] = sdata[i+3] * m; - } + // Issue 113 - allocate entries for [oldSize..screen]; + // copy cfData[0] to cfData[oldsize..screen-1] and + // lastAlpha[0] to lastAlpha[oldsize..screen-1]. + for (int i = mirrorInterleavedColorPointer.length; i < screen+1; i++) { + cfData[i] = new float[4 * vertexCount]; + System.arraycopy(cfData[0], 0, cfData[i], 0, 4 * vertexCount); + lastAlpha[i] = lastAlpha[0]; + } - lastAlpha[screen] = alpha; - } mirrorInterleavedColorPointer = cfData; - // reset the colorChanged bit - colorChanged &= ~(1 << screen); - dirtyFlag |= COLOR_CHANGED; - retVal[1] = cdata; - return retVal; + // Issue 113 - since we copied the data from screen 0, we don't need + // to do any further special processing. } - if ((colorChanged & (1<= 0.0; + + if ((colorChanged & (1< sphere.radius) { - freeVector3d(tempV3D); - freeVector3d(vec0); - freeVector3d(vec1); - freeVector3d(pNrm); - freeVector3d(pa); - freePoint3d(q); return false; } @@ -6595,20 +6348,8 @@ abstract class GeometryArrayRetained extends GeometryRetained{ pNrm, dist, iPnt); } - freeVector3d(tempV3D); - freeVector3d(vec0); - freeVector3d(vec1); - freeVector3d(pNrm); - freeVector3d(pa); - freePoint3d(q); return true; } - freeVector3d(tempV3D); - freeVector3d(vec0); - freeVector3d(vec1); - freeVector3d(pNrm); - freeVector3d(pa); - freePoint3d(q); return false; } @@ -6945,8 +6686,8 @@ abstract class GeometryArrayRetained extends GeometryRetained{ Point3d end) { double abLenSq, acLenSq, apLenSq, abDotAp, radiusSq; - Vector3d ab = getVector3d(); - Vector3d ap = getVector3d(); + Vector3d ab = new Vector3d(); + Vector3d ap = new Vector3d(); ab.x = end.x - start.x; ab.y = end.y - start.y; @@ -6959,8 +6700,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ abDotAp = ab.dot(ap); if(abDotAp < 0.0) { - freeVector3d(ab); - freeVector3d(ap); return false; // line segment points away from sphere. } @@ -6968,8 +6707,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ acLenSq = abDotAp * abDotAp / abLenSq; if(acLenSq < abLenSq) { - freeVector3d(ab); - freeVector3d(ap); return false; // C doesn't lies between end points of edge. } @@ -6977,13 +6714,9 @@ abstract class GeometryArrayRetained extends GeometryRetained{ apLenSq = ap.lengthSquared(); if((apLenSq - acLenSq) <= radiusSq) { - freeVector3d(ab); - freeVector3d(ap); return true; } - freeVector3d(ab); - freeVector3d(ap); return false; } @@ -7095,8 +6828,8 @@ abstract class GeometryArrayRetained extends GeometryRetained{ Point3d end, Point3d iPnt) { - Vector3d tempV3d = getVector3d(); - Vector3d direction = getVector3d(); + Vector3d tempV3d = new Vector3d(); + Vector3d direction = new Vector3d(); double pD, pNrmDotrDir, tr; // Compute plane D. @@ -7112,8 +6845,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // edge is parallel to plane. if(pNrmDotrDir== 0.0) { // System.out.println("Edge is parallel to plane."); - freeVector3d(tempV3d); - freeVector3d(direction); return false; } @@ -7125,8 +6856,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // or exceed the edge's length. if((tr < 0.0 ) || (tr > 1.0 )) { // System.out.println("Edge intersects the plane behind the start or exceed end."); - freeVector3d(tempV3d); - freeVector3d(direction); return false; } @@ -7134,8 +6863,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ iPnt.y = start.y + tr * direction.y; iPnt.z = start.z + tr * direction.z; - freeVector3d(tempV3d); - freeVector3d(direction); return true; } @@ -7470,10 +7197,10 @@ abstract class GeometryArrayRetained extends GeometryRetained{ boolean intersectTriPnt(Point3d v0, Point3d v1, Point3d v2, Point3d u) { - Vector3d e1 = getVector3d(); - Vector3d e2 = getVector3d(); - Vector3d n1 = getVector3d(); - Vector3d tempV3d = getVector3d(); + Vector3d e1 = new Vector3d(); + Vector3d e2 = new Vector3d(); + Vector3d n1 = new Vector3d(); + Vector3d tempV3d = new Vector3d(); double d1, du; @@ -7490,10 +7217,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if(n1.length() == 0.0) { // System.out.println("(1) Degenerate triangle."); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(tempV3d); return false; // Degenerate triangle. } @@ -7509,10 +7232,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // no intersection occurs if(du != 0.0) { - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(tempV3d); return false; } @@ -7549,17 +7268,9 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // finally, test if u is totally contained in tri. if(pointInTri(u, v0, v1, v2, i0, i1)) { - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(tempV3d); return true; } - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(tempV3d); return false; } @@ -7585,11 +7296,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ Point3d u0, Point3d u1, Point3d u2) { // System.out.println("In intersectTriTri ..."); - Vector3d e1 = getVector3d(); - Vector3d e2 = getVector3d(); - Vector3d n1 = getVector3d(); - Vector3d n2 = getVector3d(); - Vector3d tempV3d = getVector3d(); + Vector3d e1 = new Vector3d(); + Vector3d e2 = new Vector3d(); + Vector3d n1 = new Vector3d(); + Vector3d n2 = new Vector3d(); + Vector3d tempV3d = new Vector3d(); double d1, d2; double du0, du1, du2, dv0, dv1, dv2; @@ -7612,11 +7323,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if(n1.length() == 0.0) { // System.out.println("(1) Degenerate triangle."); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return false; // Degenerate triangle. } @@ -7644,11 +7350,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // no intersection occurs if(du0du1>0.0 && du0du2>0.0) { // System.out.println("In intersectTriTri : du0du1>0.0 && du0du2>0.0"); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return false; } @@ -7665,11 +7366,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if(n2.length() == 0.0) { // System.out.println("(2) Degenerate triangle."); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return false; // Degenerate triangle. } @@ -7697,11 +7393,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // no intersection occurs if(dv0dv1>0.0 && dv0dv2>0.0) { // System.out.println("In intersectTriTri : dv0dv1>0.0 && dv0dv2>0.0"); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return false; } // compute direction of intersection line. @@ -7782,11 +7473,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ else { // triangles are coplanar boolean toreturn = coplanarTriTri(n1, v0, v1, v2, u0, u1, u2); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return toreturn; } @@ -7821,11 +7507,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // triangles are coplanar // System.out.println("In intersectTriTri : coplanarTriTri test 2"); boolean toreturn = coplanarTriTri(n2, v0, v1, v2, u0, u1, u2); - freeVector3d(e1); - freeVector3d(e2); - freeVector3d(n1); - freeVector3d(n2); - freeVector3d(tempV3d); return toreturn; } @@ -7859,20 +7540,10 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if(isect1E 1.0+EPS))) { // Ray intersects the plane behind the ray's origin // or intersect point not fall in Segment - freeVector3d(vec0); - freeVector3d(vec1); - freeVector3d(pNrm); - freeVector3d(tempV3d); return false; } @@ -8288,10 +7927,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (isIntersect) { dist[0] *= direction.length(); } - freeVector3d(vec0); - freeVector3d(vec1); - freeVector3d(pNrm); - freeVector3d(tempV3d); return isIntersect; } @@ -8428,7 +8063,7 @@ abstract class GeometryArrayRetained extends GeometryRetained{ // System.out.println("start " + start + " end " + end ); // System.out.println("ori " + ori + " dir " + dir); - lDir = getVector3d(); + lDir = new Vector3d(); lDir.x = (end.x - start.x); lDir.y = (end.y - start.y); lDir.z = (end.z - start.z); @@ -8449,7 +8084,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ iPnt.set(start); } } - freeVector3d(lDir); return isIntersect; } // Find the inverse. @@ -8468,12 +8102,10 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if(s<0.0) { // Before the origin of ray. // System.out.println("Before the origin of ray " + s); - freeVector3d(lDir); return false; } if((t<0)||(t>1.0)) {// Before or after the end points of line. // System.out.println("Before or after the end points of line. " + t); - freeVector3d(lDir); return false; } @@ -8482,7 +8114,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if((tmp1 < (tmp2 - EPS)) || (tmp1 > (tmp2 + EPS))) { // System.out.println("No intersection : tmp1 " + tmp1 + " tmp2 " + tmp2); - freeVector3d(lDir); return false; } @@ -8496,7 +8127,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ } // System.out.println("Intersected : tmp1 " + tmp1 + " tmp2 " + tmp2); - freeVector3d(lDir); return true; } @@ -8507,11 +8137,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ boolean intersectCylinder(Point3d coordinates[], PickCylinder cyl, double dist[], Point3d iPnt) { - Point3d origin = getPoint3d(); - Point3d end = getPoint3d(); - Vector3d direction = getVector3d(); - Point3d iPnt1 = getPoint3d(); - Vector3d originToIpnt = getVector3d(); + Point3d origin = new Point3d(); + Point3d end = new Point3d(); + Vector3d direction = new Vector3d(); + Point3d iPnt1 = new Point3d(); + Vector3d originToIpnt = new Vector3d(); if (iPnt == null) { iPnt = new Point3d(); @@ -8532,24 +8162,12 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (cyl instanceof PickCylinderRay) { if (intersectRay(coordinates, new PickRay(origin, direction), - dist, iPnt)) { - - freePoint3d(origin); - freePoint3d(end); - freeVector3d(direction); - freeVector3d(originToIpnt); - freePoint3d(iPnt1); - + dist, iPnt)) { return true; } } else { if (intersectSegment(coordinates, origin, end, dist, iPnt)) { - freePoint3d(origin); - freePoint3d(end); - freeVector3d(direction); - freeVector3d(originToIpnt); - freePoint3d(iPnt1); return true; } } @@ -8575,19 +8193,9 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (sqDistToEdge <= radius*radius) { originToIpnt.sub (iPnt1, origin); dist[0] = originToIpnt.length(); - freePoint3d(origin); - freePoint3d(end); - freeVector3d(direction); - freeVector3d(originToIpnt); - freePoint3d(iPnt1); return true; } } - freePoint3d(origin); - freePoint3d(end); - freeVector3d(direction); - freeVector3d(originToIpnt); - freePoint3d(iPnt1); return false; } @@ -8598,14 +8206,14 @@ abstract class GeometryArrayRetained extends GeometryRetained{ boolean intersectCone(Point3d coordinates[], PickCone cone, double[] dist, Point3d iPnt) { - Point3d origin = getPoint3d(); - Point3d end = getPoint3d(); - Vector3d direction = getVector3d(); - Vector3d originToIpnt = getVector3d(); + Point3d origin = new Point3d(); + Point3d end = new Point3d(); + Vector3d direction = new Vector3d(); + Vector3d originToIpnt = new Vector3d(); double distance; - Point3d iPnt1 = getPoint3d(); - Vector3d vector = getVector3d(); + Point3d iPnt1 = new Point3d(); + Vector3d vector = new Vector3d(); if (iPnt == null) { iPnt = new Point3d(); @@ -8626,23 +8234,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (intersectRay(coordinates, new PickRay (origin, direction), dist, iPnt)) { - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt1); - freeVector3d(direction); - freeVector3d(originToIpnt); - freeVector3d(vector); return true; } } else { if (intersectSegment(coordinates, origin, end, dist, iPnt)) { - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt1); - freeVector3d(direction); - freeVector3d(originToIpnt); - freeVector3d(vector); return true; } } @@ -8671,21 +8267,9 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (sqDistToEdge <= radius*radius) { // System.out.println ("intersectCone: edge "+i+" intersected"); dist[0] = distance; - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt1); - freeVector3d(direction); - freeVector3d(originToIpnt); - freeVector3d(vector); return true; } } - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt1); - freeVector3d(direction); - freeVector3d(originToIpnt); - freeVector3d(vector); return false; } @@ -8697,11 +8281,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ boolean intersectCylinder(Point3d pt, PickCylinder cyl, double[] dist) { - Point3d origin = getPoint3d(); - Point3d end = getPoint3d(); - Vector3d direction = getVector3d(); - Point3d iPnt = getPoint3d(); - Vector3d originToIpnt = getVector3d(); + Point3d origin = new Point3d(); + Point3d end = new Point3d(); + Vector3d direction = new Vector3d(); + Point3d iPnt = new Point3d(); + Vector3d originToIpnt = new Vector3d(); // Get cylinder information cyl.getOrigin (origin); @@ -8719,18 +8303,8 @@ abstract class GeometryArrayRetained extends GeometryRetained{ if (sqDist <= radius*radius) { originToIpnt.sub (iPnt, origin); dist[0] = originToIpnt.length(); - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt); - freeVector3d(originToIpnt); - freeVector3d(direction); return true; } - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt); - freeVector3d(originToIpnt); - freeVector3d(direction); return false; } @@ -8740,11 +8314,11 @@ abstract class GeometryArrayRetained extends GeometryRetained{ */ boolean intersectCone(Point3d pt, PickCone cone, double[] dist) { - Point3d origin = getPoint3d(); - Point3d end = getPoint3d(); - Vector3d direction = getVector3d(); - Point3d iPnt = getPoint3d(); - Vector3d originToIpnt = getVector3d(); + Point3d origin = new Point3d(); + Point3d end = new Point3d(); + Vector3d direction = new Vector3d(); + Point3d iPnt = new Point3d(); + Vector3d originToIpnt = new Vector3d(); // Get cone information cone.getOrigin (origin); @@ -8769,11 +8343,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ radius = Math.tan (cone.getSpreadAngle()) * distance; if (sqDist <= radius*radius) { dist[0] = distance; - freePoint3d(origin); - freePoint3d(end); - freePoint3d(iPnt); - freeVector3d(direction); - freeVector3d(originToIpnt); return true; } return false; @@ -10713,18 +10282,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ } } - protected void finalize() { - // For Pure immediate mode, there is no clearLive so - // surface will free when JVM do GC - if (pVertexBuffers != 0) { - // memory not yet free for immediate mode rendering - // It is thread safe since D3D only free surface in - // the next swapBuffer() call which must be in the - // same renderer threads - freeD3DArray(true); - } - } - void freeDlistId() { if (dlistId != -1) { VirtualUniverse.mc.freeDisplayListId(dlistObj); @@ -11115,28 +10672,26 @@ abstract class GeometryArrayRetained extends GeometryRetained{ boolean intersect(Transform3D thisLocalToVworld, Transform3D otherLocalToVworld, GeometryRetained geom) { - Transform3D tg = VirtualUniverse.mc.getTransform3D(null); + Transform3D t3d = new Transform3D(); boolean isIntersect = false; if (geom instanceof GeometryArrayRetained ) { GeometryArrayRetained geomArray = (GeometryArrayRetained) geom; if (geomArray.validVertexCount >= validVertexCount) { - tg.invert(otherLocalToVworld); - tg.mul(thisLocalToVworld); - isIntersect = intersect(tg, geom); + t3d.invert(otherLocalToVworld); + t3d.mul(thisLocalToVworld); + isIntersect = intersect(t3d, geom); } else { - tg.invert(thisLocalToVworld); - tg.mul(otherLocalToVworld); - isIntersect = geomArray.intersect(tg, this); + t3d.invert(thisLocalToVworld); + t3d.mul(otherLocalToVworld); + isIntersect = geomArray.intersect(t3d, this); } } else { - tg.invert(thisLocalToVworld); - tg.mul(otherLocalToVworld); - isIntersect = geom.intersect(tg, this); + t3d.invert(thisLocalToVworld); + t3d.mul(otherLocalToVworld); + isIntersect = geom.intersect(t3d, this); } - - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, tg); return isIntersect; } @@ -11525,23 +11080,6 @@ abstract class GeometryArrayRetained extends GeometryRetained{ dist[0] = Math.sqrt(dist[0]); } - Vector3d getVector3d() { - return (Vector3d)FreeListManager.getObject(FreeListManager.VECTOR3D); - } - - void freeVector3d(Vector3d v) { - FreeListManager.freeObject(FreeListManager.VECTOR3D, v); - } - - Point3d getPoint3d() { - return (Point3d)FreeListManager.getObject(FreeListManager.POINT3D); - } - - void freePoint3d(Point3d p) { - FreeListManager.freeObject(FreeListManager.POINT3D, p); - } - - void handleFrequencyChange(int bit) { int mask = 0; if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) { diff --git a/src/classes/share/javax/media/j3d/GeometryAtom.java b/src/classes/share/javax/media/j3d/GeometryAtom.java index 087ebdf..659230b 100644 --- a/src/classes/share/javax/media/j3d/GeometryAtom.java +++ b/src/classes/share/javax/media/j3d/GeometryAtom.java @@ -177,7 +177,7 @@ class GeometryAtom extends Object implements BHLeafInterface, NnuId { ra.rListInfo[j] = new RenderAtomListInfo(); ra.rListInfo[j].renderAtom = ra; ra.rListInfo[j].index = j; - ra.rListInfo[j].localToVworld = VirtualUniverse.mc.getTransform3D(null); + ra.rListInfo[j].localToVworld = new Transform3D(); } } @@ -213,7 +213,7 @@ class GeometryAtom extends Object implements BHLeafInterface, NnuId { ra.rListInfo[j] = new RenderAtomListInfo(); ra.rListInfo[j].renderAtom = ra; ra.rListInfo[j].index = j; - ra.rListInfo[j].localToVworld = VirtualUniverse.mc.getTransform3D(null); + ra.rListInfo[j].localToVworld = new Transform3D(); } } } diff --git a/src/classes/share/javax/media/j3d/GeometryRetained.java b/src/classes/share/javax/media/j3d/GeometryRetained.java index 183dba4..3c93e37 100644 --- a/src/classes/share/javax/media/j3d/GeometryRetained.java +++ b/src/classes/share/javax/media/j3d/GeometryRetained.java @@ -213,9 +213,7 @@ abstract class GeometryRetained extends NodeComponentRetained { abstract void execute(Canvas3D cv, RenderAtom ra, boolean isNonUniformScale, boolean updateAlpha, float alpha, - boolean multiScreen, int screen, - boolean ignoreVertexColors, - int pass); + int screen, boolean ignoreVertexColors); /** * This method should return an int indicating the format of the vertices, @@ -274,21 +272,19 @@ abstract class GeometryRetained extends NodeComponentRetained { boolean intersect(Transform3D thisLocalToVworld, Transform3D otherLocalToVworld, GeometryRetained geom) { - Transform3D tg = VirtualUniverse.mc.getTransform3D(null); - tg.invert(otherLocalToVworld); - tg.mul(thisLocalToVworld); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, tg); - return intersect(tg, geom); + Transform3D t3d = new Transform3D(); + t3d.invert(otherLocalToVworld); + t3d.mul(thisLocalToVworld); + return intersect(t3d, geom); } boolean intersect(Transform3D thisLocalToVworld, Bounds targetBound) { Bounds transBound = (Bounds) targetBound.clone(); - Transform3D tg = VirtualUniverse.mc.getTransform3D(null); - tg.invert(thisLocalToVworld); - transBound.transform(tg); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, tg); + Transform3D t3d = new Transform3D(); + t3d.invert(thisLocalToVworld); + transBound.transform(t3d); return intersect(transBound); } diff --git a/src/classes/share/javax/media/j3d/GeometryStructure.java b/src/classes/share/javax/media/j3d/GeometryStructure.java index a0ea460..bddfac0 100644 --- a/src/classes/share/javax/media/j3d/GeometryStructure.java +++ b/src/classes/share/javax/media/j3d/GeometryStructure.java @@ -306,8 +306,7 @@ class GeometryStructure extends J3dStructure { addBgGeometryAtomList(geomAtom); continue; } - BHLeafNode bhLeafNode = (BHLeafNode) - VirtualUniverse.mc.getBHNode(BHNode.BH_TYPE_LEAF); + BHLeafNode bhLeafNode = new BHLeafNode(); bhLeafNode.leafIF = geomAtom; geomAtom.bhLeafNode = bhLeafNode; bhLeafNode.computeBoundingHull(); @@ -317,8 +316,7 @@ class GeometryStructure extends J3dStructure { } else if (node instanceof GroupRetained) { synchronized (node) { GroupRetained group = (GroupRetained) node; - BHLeafNode bhLeafNode = (BHLeafNode) - VirtualUniverse.mc.getBHNode(BHNode.BH_TYPE_LEAF); + BHLeafNode bhLeafNode = new BHLeafNode(); bhLeafNode.leafIF = group; group.bhLeafNode = bhLeafNode; bhLeafNode.computeBoundingHull(); diff --git a/src/classes/share/javax/media/j3d/GraphicsConfigInfo.java b/src/classes/share/javax/media/j3d/GraphicsConfigInfo.java index 56711dc..a6bbcbb 100644 --- a/src/classes/share/javax/media/j3d/GraphicsConfigInfo.java +++ b/src/classes/share/javax/media/j3d/GraphicsConfigInfo.java @@ -12,24 +12,33 @@ package javax.media.j3d; +/** + * Container for the GraphicsTemplate3D and other private data about a selected + * GraphicsConfiguration. An instance of this class is created along with an + * instance of GrahpicsConfiguration, whenever getBestConfiguration is called. + */ class GraphicsConfigInfo { - private int reqStencilSize = 0; - private long fbConfig = 0L; + private GraphicsConfigTemplate3D graphicsConfigTemplate3D = null; + private Object privateData = null; - int getRequestedStencilSize() { - return reqStencilSize; + GraphicsConfigInfo(GraphicsConfigTemplate3D graphicsConfigTemplate3D) { + setGraphicsConfigTemplate3D(graphicsConfigTemplate3D); } - void setRequestedStencilSize(int reqSS) { - reqStencilSize = reqSS; + GraphicsConfigTemplate3D getGraphicsConfigTemplate3D() { + return graphicsConfigTemplate3D; } - - long getFBConfig() { - return fbConfig; + + void setGraphicsConfigTemplate3D(GraphicsConfigTemplate3D graphicsConfigTemplate3D) { + this.graphicsConfigTemplate3D = graphicsConfigTemplate3D; } - - void setFBConfig(long fbC) { - fbConfig = fbC; + + Object getPrivateData() { + return privateData; + } + + void setPrivateData(Object privateData) { + this.privateData = privateData; } } diff --git a/src/classes/share/javax/media/j3d/GraphicsConfigTemplate3D.java b/src/classes/share/javax/media/j3d/GraphicsConfigTemplate3D.java index 99536cc..a09d879 100644 --- a/src/classes/share/javax/media/j3d/GraphicsConfigTemplate3D.java +++ b/src/classes/share/javax/media/j3d/GraphicsConfigTemplate3D.java @@ -46,15 +46,7 @@ public class GraphicsConfigTemplate3D extends GraphicsConfigTemplate { static Object globalLock = new Object(); static Object monitorLock = new Object(); - static boolean threadWaiting = false; - - /** - * The platform dependent template. Since there is no - * template-specific instance data in the NativeConfigTemplate3D - * class, we can create one statically. - */ - static NativeConfigTemplate3D nativeTemplate = - new NativeConfigTemplate3D(); + static volatile boolean threadWaiting = false; /** * Constructs a GraphicsConfigTemplate3D object with default parameters. @@ -387,7 +379,8 @@ public class GraphicsConfigTemplate3D extends GraphicsConfigTemplate { synchronized (monitorLock) { switch (action) { case J3dThread.WAIT: - if (threadWaiting) { + // Issue 279 - loop until ready + while (threadWaiting) { try { monitorLock.wait(); } catch (InterruptedException e) { diff --git a/src/classes/share/javax/media/j3d/GraphicsContext3D.java b/src/classes/share/javax/media/j3d/GraphicsContext3D.java index 1369f32..8bfd972 100644 --- a/src/classes/share/javax/media/j3d/GraphicsContext3D.java +++ b/src/classes/share/javax/media/j3d/GraphicsContext3D.java @@ -12,6 +12,8 @@ package javax.media.j3d; +import java.awt.Point; +import java.awt.image.BufferedImage; import javax.vecmath.*; import java.util.Vector; import java.util.Enumeration; @@ -100,8 +102,6 @@ public class GraphicsContext3D extends Object { */ Canvas3D canvas3d = null; - int objectId = -1; - // // Graphics state // @@ -281,7 +281,8 @@ public class GraphicsContext3D extends Object { static final int FLUSH2D = 23; static final int DRAWANDFLUSH2D = 24; static final int SET_MODELCLIP = 25; - static final int NCOMMANDS = 26; // needs to be incremented + static final int DISPOSE2D = 26; + static final int NCOMMANDS = 27; // needs to be incremented // when a new command is to be // added to the list @@ -296,11 +297,9 @@ public class GraphicsContext3D extends Object { private static final int BUFFER_MODE = 0x1; private int dirtyMask = 0; - // multi-texture private int numActiveTexUnit = 0; private int lastActiveTexUnitIndex = 0; - private boolean toSimulateMultiTex = false; // for read raster private volatile boolean readRasterReady = false; @@ -341,17 +340,62 @@ public class GraphicsContext3D extends Object { * If the Appearance object is null, default values will be used * for all appearance attributes - it is as if an * Appearance node were created using the default constructor. + * * @param appearance the new Appearance object + * + * @exception IllegalSharingException if the specified appearance refers + * to an ImageComponent2D that is being used by a Canvas3D as + * an off-screen buffer. */ public void setAppearance(Appearance appearance) { - - if(appearance == null) { - if(defaultAppearance == null) { - defaultAppearance = new Appearance(); - } - appearance = defaultAppearance; - } - + + if(appearance == null) { + if(defaultAppearance == null) { + defaultAppearance = new Appearance(); + } + appearance = defaultAppearance; + } else { + // Check whether any ImageComponent2D referred to by + // the new appearance is being used as an off-screen buffer and throw + // IllegalSharingException if it is. + TextureRetained texRetained; + ImageComponent[] images; + AppearanceRetained appRetained = (AppearanceRetained)appearance.retained; + if(appRetained.texture != null) { + assert (appRetained.texUnitState == null); + texRetained = appRetained.texture; + images = texRetained.getImages(); + if(images != null) { + for(int i=0; i 1), canvas3d.screen.screen, - ignoreVertexColors, - -1); - } else { - // NOTE: we really should leverage the code in textureBin - boolean startToSimulate = false; - - // simulate multiple texture units - AppearanceRetained app = - (AppearanceRetained)appearance.retained; - - assert VirtualUniverse.mc.allowSimulatedMultiTexture; - assert numActiveTexUnit > 1; - assert app.texUnitState != null; - assert app.texUnitState.length > 1; - - // first turn off fog - if (fog != null) - canvas3d.setFogEnableFlag(canvas3d.ctx, false); - - for (i = 0; i < app.texUnitState.length; i++) { - if (app.texUnitState[i] != null && - app.texUnitState[i].isTextureEnabled()) { - - // turn on fog for the last pass - if (i == lastActiveTexUnitIndex) - canvas3d.setFogEnableFlag(canvas3d.ctx, true); - - app.texUnitState[i].updateNative(-1, canvas3d, - false, startToSimulate); - - startToSimulate = true; - drawGeo.execute(canvas3d, null, - isNonUniformScale, false, alpha, - ((canvas3d.view.getScreens()).length > 1), - canvas3d.screen.screen, - ignoreVertexColors, - i); - } - } + ignoreVertexColors); - // adjust the depth test back to what it was - // and adjust the blend func to what it it was - if (startToSimulate) { - if (app.transparencyAttributes != null) { - app.transparencyAttributes.updateNative( - canvas3d.ctx, alpha, geometryType, - polygonMode, lineAA, pointAA); - } else { - canvas3d.resetTransparency(canvas3d.ctx, geometryType, - polygonMode, lineAA, pointAA); - } + if (geoRetained != null) { + if (geoRetained.pVertexBuffers != 0) { + // Issue 121: always free D3D vertex buffer memory + // after immediate mode rendering + geoRetained.freeD3DArray(true); } - if (fog != null) { - canvas3d.setFogEnableFlag(canvas3d.ctx, true); - } - } - if (geoRetained != null) - geoRetained.geomLock.unLock(); + geoRetained.geomLock.unLock(); + } - canvas3d.drawingSurfaceObject.unLock(); + canvas3d.drawingSurfaceObject.unLock(); } } catch (NullPointerException ne) { canvas3d.drawingSurfaceObject.unLock(); @@ -2145,8 +2111,25 @@ public class GraphicsContext3D extends Object { /** * Draw the specified Geometry component object. * @param geometry the Geometry object to draw. + * + * @exception IllegalSharingException if the specified geometry is a + * Raster that refers to an ImageComponent2D that is being used by a + * Canvas3D as an off-screen buffer. */ public void draw(Geometry geometry) { + // do illegalSharing check + if((geometry != null) && (geometry instanceof Raster)) { + RasterRetained rasRetained = (RasterRetained) geometry.retained; + ImageComponent2D image = rasRetained.getImage(); + if(image != null) { + ImageComponentRetained imageRetained = (ImageComponentRetained) image.retained; + // Do illegal sharing check + if(imageRetained.getUsedByOffScreen()) { + throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D32")); + } + } + } + if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active)) { return; @@ -2170,10 +2153,16 @@ public class GraphicsContext3D extends Object { * setAppearance(Appearance) and draw(Geometry) methods * passing the appearance and geometry component objects of * the specified shape node as arguments. + * * @param shape the Shape3D node containing the Appearance component * object to set and Geometry component object to draw + * * @exception IllegalSharingException if the Shape3D node * is part of or is subsequently made part of a live scene graph. + * + * @exception IllegalSharingException if the Shape3D node's Appearance + * refers to an ImageComponent2D that is being used by a + * Canvas3D as an off-screen buffer. */ public void draw(Shape3D shape) { if (shape.isLive()) { @@ -2184,16 +2173,6 @@ public class GraphicsContext3D extends Object { draw(shape.getGeometry()); } - /** - * Native method for readRaster - */ - native void readRasterNative(long d3dctx, - int type, int xSrcOffset, int ySrcOffset, - int width, int height, int hCanvas, int format, - ImageComponentRetained image, - DepthComponentRetained depth, - GraphicsContext3D ctx); - /** * Read an image from the frame buffer and copy it into the * ImageComponent and/or DepthComponent @@ -2208,18 +2187,52 @@ public class GraphicsContext3D extends Object { * @param raster the Raster object used to read the * contents of the frame buffer * - * @exception IllegalArgumentException if the Raster's - * ImageComponent2D is in by-reference mode and its RenderedImage - * is not an instance of a BufferedImage. + * @exception IllegalArgumentException if the image class of the specified + * Raster's ImageComponent2D is not ImageClass.BUFFERED_IMAGE. * - * @exception IllegalSharingException if the Raster object - * is part of a live scene graph. + * @exception IllegalArgumentException if the specified Raster's + * ImageComponent2D is in by-reference mode and its + * RenderedImage is null. + * + * @exception IllegalArgumentException if the the Raster's + * ImageComponent2D format + * is not a 3-component format (e.g., FORMAT_RGB) + * or a 4-component format (e.g., FORMAT_RGBA). + * + * @exception IllegalSharingException if the Raster object is + * part of a live scene graph, or if the Raster's ImageComponent2D is + * part of a live scene graph. + * + * @exception IllegalSharingException if the Raster's ImageComponent2D is + * being used by an immediate mode context, or by a Canvas3D as + * an off-screen buffer. * * @see #flush * @see ImageComponent * @see DepthComponent */ public void readRaster(Raster raster) { + if ((raster != null) && raster.isLive()) { + ImageComponent2D image = raster.getImage(); + if (image != null){ + ImageComponent2DRetained imageRetained = (ImageComponent2DRetained)image.retained; + if (image.getImageClass() != ImageComponent.ImageClass.BUFFERED_IMAGE) { + throw new IllegalArgumentException(J3dI18N.getString("GraphicsContext3D33")); + } + if (image.isByReference() && (image.getImage() == null)) { + throw new IllegalArgumentException(J3dI18N.getString("GraphicsContext3D34")); + } + if (imageRetained.getNumberOfComponents() < 3) { + throw new IllegalArgumentException(J3dI18N.getString("GraphicsContext3D35")); + } + if (image.isLive()) { + throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D36")); + } + if (imageRetained.getInImmCtx() || imageRetained.getUsedByOffScreen()) { + throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D37")); + } + } + } if ((canvas3d.view == null) || (canvas3d.view.universe == null) || (!canvas3d.view.active)) { return; @@ -2242,122 +2255,119 @@ public class GraphicsContext3D extends Object { } } - - void doReadRaster(Raster raster) { - - - if (!canvas3d.firstPaintCalled) { - readRasterReady = true; - return; - } - - RasterRetained ras = (RasterRetained)raster.retained; - Dimension canvasSize = canvas3d.getSize(); - int format = 0; // Not use in case of DepthComponent read - - if (raster.isLive()) { - readRasterReady = true; - throw new IllegalSharingException(J3dI18N.getString("GraphicsContext3D21")); + if (!canvas3d.firstPaintCalled) { + readRasterReady = true; + return; } - // XXXX: implement illegal argument exception - /* - if (ras.image.byReference && - !(ras.image.imageReference instanceof BufferedImage)) { + RasterRetained ras = (RasterRetained)raster.retained; + Dimension canvasSize = canvas3d.getSize(); + Dimension rasterSize = new Dimension(); + ImageComponent2DRetained image = ras.image; - throw new IllegalArgumentException(...); - } - */ + int format = 0; // Not use in case of DepthComponent read - if (canvas3d.ctx == 0) { - // Force an initial clear if one has not yet been done - doClear(); - } + if (canvas3d.ctx == null) { + // Force an initial clear if one has not yet been done + doClear(); + } if (J3dDebug.devPhase && J3dDebug.debug) { - J3dDebug.doAssert(canvas3d.ctx != 0, "canvas3d.ctx != 0"); + J3dDebug.doAssert(canvas3d.ctx != null, "canvas3d.ctx != null"); } - - // allocate read buffer space + ras.getSize(rasterSize); + // allocate read buffer space if ( (ras.type & Raster.RASTER_COLOR) != 0) { - int bpp = ras.image.getEffectiveBytesPerPixel(); - int size = ras.image.height * ras.image.width - * bpp; - format = ras.image.getEffectiveFormat(); - if ((ras.width > ras.image.width) || - (ras.height > ras.image.height)) { - throw new RuntimeException(J3dI18N.getString("GraphicsContext3D27")); - } - if (byteBuffer.length < size) - byteBuffer = new byte[size]; + if ((rasterSize.width > ras.image.width) || + (rasterSize.height > ras.image.height)) { + throw new RuntimeException(J3dI18N.getString("GraphicsContext3D27")); + } } if ( (ras.type & Raster.RASTER_DEPTH) != 0) { int size = ras.depthComponent.height * ras.depthComponent.width; - if (ras.depthComponent.type - == DepthComponentRetained.DEPTH_COMPONENT_TYPE_FLOAT) { + if (ras.depthComponent.type + == DepthComponentRetained.DEPTH_COMPONENT_TYPE_FLOAT) { if (floatBuffer.length < size) floatBuffer = new float[size]; } else { // type INT or NATIVE if (intBuffer.length < size) intBuffer = new int[size]; } - if ((ras.width > ras.depthComponent.width) || - (ras.height > ras.depthComponent.height)) { - throw new RuntimeException(J3dI18N.getString("GraphicsContext3D28")); - } + if ((rasterSize.width > ras.depthComponent.width) || + (rasterSize.height > ras.depthComponent.height)) { + throw new RuntimeException(J3dI18N.getString("GraphicsContext3D28")); + } } - + if ( (ras.type & Raster.RASTER_COLOR) != 0) { - // If by reference, check if a copy needs to be made - // and also evaluate the storedFormat .. - if (ras.image.isByReference()) { - ras.image.geomLock.getLock(); - ras.image.evaluateExtensions(canvas3d.extensionsSupported); - ras.image.geomLock.unLock(); - } - } + + // If by reference, check if a copy needs to be made + // and also evaluate the storedFormat .. + if (image.isByReference()) { + image.geomLock.getLock(); + image.evaluateExtensions(canvas3d); + image.geomLock.unLock(); + } else { + // If image has a null buffer ( BufferedImage) + if (image.imageData == null) { + image.createBlankImageData(); + } + // Check for possible format conversion in imageData + else { + // Format convert imageData if format is unsupported. + image.evaluateExtensions(canvas3d); + } + } + } // We need to catch NullPointerException when the dsi // gets yanked from us during a remove. try { - if (canvas3d.drawingSurfaceObject.renderLock()) { - // Make the context current and read the raster information - canvas3d.makeCtxCurrent(); - canvas3d.syncRender(canvas3d.ctx, true); - readRasterNative(canvas3d.ctx, - ras.type, ras.xSrcOffset, ras.ySrcOffset, - ras.width, ras.height, canvasSize.height, format, - ras.image, ras.depthComponent, this); - canvas3d.drawingSurfaceObject.unLock(); - } - } catch (NullPointerException ne) { - canvas3d.drawingSurfaceObject.unLock(); - throw ne; - } - - // flip color image: yUp -> yDown and convert to BufferedImage - if ( (ras.type & Raster.RASTER_COLOR) != 0) { - ras.image.retrieveImage(byteBuffer, ras.width, ras.height); + if (canvas3d.drawingSurfaceObject.renderLock()) { + // Make the context current and read the raster information + canvas3d.makeCtxCurrent(); + canvas3d.syncRender(canvas3d.ctx, true); + Point rasterSrcOffset = new Point(); + ras.getDstOffset(rasterSrcOffset); + + DepthComponentRetained depthComp = ras.depthComponent; + int depthType = 0; + if(depthComp != null) { + depthType = depthComp.type; + } + Pipeline.getPipeline().readRaster(canvas3d.ctx, + ras.type, rasterSrcOffset.x, rasterSrcOffset.y, + rasterSize.width, rasterSize.height, canvasSize.height, + image.getImageDataTypeIntValue(), + image.getImageFormatTypeIntValue(false), + image.imageData.get(), + depthType, depthComp); + + canvas3d.drawingSurfaceObject.unLock(); + } + } catch (NullPointerException ne) { + canvas3d.drawingSurfaceObject.unLock(); + throw ne; } if ( (ras.type & Raster.RASTER_DEPTH) != 0) { - if (ras.depthComponent.type == - DepthComponentRetained.DEPTH_COMPONENT_TYPE_FLOAT) + if (ras.depthComponent.type == + DepthComponentRetained.DEPTH_COMPONENT_TYPE_FLOAT) ((DepthComponentFloatRetained)ras.depthComponent).retrieveDepth( - floatBuffer, ras.width, ras.height); - else if (ras.depthComponent.type == - DepthComponentRetained.DEPTH_COMPONENT_TYPE_INT) + floatBuffer, rasterSize.width, rasterSize.height); + else if (ras.depthComponent.type == + DepthComponentRetained.DEPTH_COMPONENT_TYPE_INT) ((DepthComponentIntRetained)ras.depthComponent).retrieveDepth( - intBuffer, ras.width, ras.height); - else if (ras.depthComponent.type == - DepthComponentRetained.DEPTH_COMPONENT_TYPE_NATIVE) - ((DepthComponentNativeRetained)ras.depthComponent).retrieveDepth( - intBuffer, ras.width, ras.height); + intBuffer, rasterSize.width, rasterSize.height); + else if (ras.depthComponent.type == + DepthComponentRetained.DEPTH_COMPONENT_TYPE_NATIVE) + ((DepthComponentNativeRetained)ras.depthComponent).retrieveDepth( + intBuffer, rasterSize.width, rasterSize.height); } - readRasterReady = true; + readRasterReady = true; } /** @@ -2386,8 +2396,9 @@ public class GraphicsContext3D extends Object { sendRenderMessage(true, GraphicsContext3D.FLUSH, waitArg, null); } + // Issue 131: AutomaticOffscreen canvases must be treated as onscreen ones. if (wait && canvas3d.active && canvas3d.isRunningStatus && - !canvas3d.offScreen) { + !canvas3d.manualRendering ) { // No need to wait if renderer thread is not schedule runMonitor(J3dThread.WAIT); } @@ -2514,7 +2525,6 @@ public class GraphicsContext3D extends Object { boolean updateState(RenderBin rb, int geometryType) { boolean useAlpha = false; - toSimulateMultiTex = false; numActiveTexUnit = 0; lastActiveTexUnitIndex = 0; @@ -2623,24 +2633,8 @@ public class GraphicsContext3D extends Object { // set the number active texture unit in Canvas3D canvas3d.setNumActiveTexUnit(numActiveTexUnit); - } else if (!useShaders && VirtualUniverse.mc.allowSimulatedMultiTexture) { - // Simulated (multi-pass) multi-texture rendering - - toSimulateMultiTex = true; - - // will fall back to the multi-pass case; - // reset all the texture units first - for (int i = 0; i < prevNumActiveTexUnit; i++) { - canvas3d.resetTexture(canvas3d.ctx, i); - } - - // set the number active texture unit in Canvas3D - canvas3d.setNumActiveTexUnit(1); - } - else { - // Exceeded limit, and not using simulated multi-texture - - // disable all the texture units + } else { + // Exceeded limit, disable all the texture units for (int i = 0; i < prevNumActiveTexUnit; i++) { canvas3d.resetTexture(canvas3d.ctx, i); } @@ -2674,15 +2668,6 @@ public class GraphicsContext3D extends Object { // If the image is by reference, check if the image // should be processed if (app.texture != null) { - for (int f = 0; f < app.texture.numFaces; f++) { - for (int k = 0; k < app.texture.maxLevels; k++) { - if (app.texture.images[f][k].isByReference()) { - app.texture.images[f][k].geomLock.getLock(); - app.texture.images[f][k].evaluateExtensions(canvas3d.extensionsSupported); - app.texture.images[f][k].geomLock.unLock(); - } - } - } app.texture.updateNative(canvas3d); canvas3d.canvasDirty |= Canvas3D.TEXTUREBIN_DIRTY|Canvas3D.TEXTUREATTRIBUTES_DIRTY; numActiveTexUnit = 1; @@ -3008,7 +2993,7 @@ public class GraphicsContext3D extends Object { // send a message to the request renderer - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); + J3dMessage renderMessage = new J3dMessage(); renderMessage.threads = J3dThread.RENDER_THREAD; renderMessage.type = J3dMessage.RENDER_IMMEDIATE; renderMessage.universe = null; @@ -3041,7 +3026,7 @@ public class GraphicsContext3D extends Object { return; } // send a message to the request sound scheduling - J3dMessage soundMessage = VirtualUniverse.mc.getMessage(); + J3dMessage soundMessage = new J3dMessage(); soundMessage.threads = J3dThread.SOUND_SCHEDULER; soundMessage.type = J3dMessage.RENDER_IMMEDIATE; soundMessage.universe = canvas3d.view.universe; diff --git a/src/classes/share/javax/media/j3d/GroupRetained.java b/src/classes/share/javax/media/j3d/GroupRetained.java index 3861c1c..e27ff91 100644 --- a/src/classes/share/javax/media/j3d/GroupRetained.java +++ b/src/classes/share/javax/media/j3d/GroupRetained.java @@ -155,7 +155,7 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { } if (source.isLive()) { - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.COLLISION_BOUND_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY; @@ -231,14 +231,16 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { messages = new J3dMessage[numMessages]; for (int i = 0; i < numMessages; i++) { - messages[i] = VirtualUniverse.mc.getMessage(); + messages[i] = new J3dMessage(); } } if(oldchildr != null) { oldchildr.setParent(null); checkClearLive(oldchildr, messages, 0, index, null); - universe.notifyStructureChangeListeners(false, this.source, (BranchGroup)oldchildr.source); + if (this.source.isLive()) { + universe.notifyStructureChangeListeners(false, this.source, (BranchGroup)oldchildr.source); + } } removeChildrenData(index); @@ -250,7 +252,9 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { return; } - universe.notifyStructureChangeListeners(true, this.source, (BranchGroup)child); + if (this.source.isLive()) { + universe.notifyStructureChangeListeners(true, this.source, (BranchGroup)child); + } NodeRetained childr = (NodeRetained) child.retained; childr.setParent(this); children.set(index, childr); @@ -558,7 +562,7 @@ class GroupRetained extends NodeRetained implements BHLeafInterface { } messages = new J3dMessage[numMessages]; for (int i=0; inot a BufferedImage. Note that the image class + * of an ImageComponent following a call to set(RenderedImage image) + * will be RENDERED_IMAGE, if and only if the image is not an instance + * of BufferedImage and the ImageComponent is in by-reference mode. + */ + RENDERED_IMAGE, + + /** + * Indicates that this ImageComponent object wraps an NioImageBuffer + * object. Note that an ImageComponent in this state must not be used + * as the off-screen buffer of a Canvas3D nor as the target of a + * readRaster operation. + */ + NIO_IMAGE_BUFFER, + } + + /** * Specifies that this ImageComponent object allows reading its * size component information (width, height, and depth). @@ -335,10 +370,21 @@ public abstract class ImageComponent extends NodeComponent { * @exception RestrictedAccessException if the method is called * when this object is part of live or compiled scene graph. * + * @exception IllegalStateException if the image class of this object + * is ImageClass.NIO_IMAGE_BUFFER. + * + * @deprecated as of Java 3D 1.5, the yUp flag should only be set at object + * construction time. + * * @since Java 3D 1.2 */ public void setYUp(boolean yUp) { checkForLiveOrCompiled(); + + // check for illegal image class + if (((ImageComponentRetained)this.retained).getImageClass() == ImageClass.NIO_IMAGE_BUFFER) { + throw new IllegalStateException("ImageComponent4"); + } ((ImageComponentRetained)this.retained).setYUp(yUp); } @@ -357,4 +403,18 @@ public abstract class ImageComponent extends NodeComponent { return ((ImageComponentRetained)this.retained).isYUp(); } + + /** + * Retrieves the image class of this ImageComponent object. + * + * @return the image class of this ImageComponent, + * one of: ImageClass.BUFFERED_IMAGE, + * ImageClass.RENDERED_IMAGE, or ImageClass.NIO_IMAGE_BUFFER. + * + * @since Java 3D 1.5 + */ + public ImageClass getImageClass() { + return ((ImageComponentRetained)this.retained).getImageClass(); + } + } diff --git a/src/classes/share/javax/media/j3d/ImageComponent2D.java b/src/classes/share/javax/media/j3d/ImageComponent2D.java index d46db4b..9bb31ef 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent2D.java +++ b/src/classes/share/javax/media/j3d/ImageComponent2D.java @@ -42,6 +42,9 @@ import java.awt.image.RenderedImage; * * * + *

    + * As of Java 3D 1.5, an ImageComponent2D accepts an NioImageBuffer object + * as an alternative to a RenderedImage. */ public class ImageComponent2D extends ImageComponent { @@ -51,7 +54,12 @@ public class ImageComponent2D extends ImageComponent { /** * Constructs a 2D image component object using the specified - * format, width, and height, and a null image. + * format, width, and height. Default values are used for + * all other parameters. The default values are as follows: + *

      + * image : null
      + * imageClass : ImageClass.BUFFERED_IMAGE
      + *
    * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -72,6 +80,8 @@ public class ImageComponent2D extends ImageComponent { /** * Constructs a 2D image component object using the specified format * and BufferedImage. A copy of the BufferedImage is made. + * The image class is set to ImageClass.BUFFERED_IMAGE. + * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -81,13 +91,15 @@ public class ImageComponent2D extends ImageComponent { */ public ImageComponent2D(int format, BufferedImage image) { - ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(null), image.getHeight(null), 1); + ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified format * and RenderedImage. A copy of the RenderedImage is made. + * The image class is set to ImageClass.BUFFERED_IMAGE. + * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -106,8 +118,8 @@ public class ImageComponent2D extends ImageComponent { /** * Constructs a 2D image component object using the specified - * format, width, height, byReference flag, and yUp flag, and - * a null image. + * format, width, height, byReference flag, and yUp flag. + * Default values are used for all other parameters. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -132,7 +144,6 @@ public class ImageComponent2D extends ImageComponent { boolean byReference, boolean yUp) { - ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); ((ImageComponent2DRetained)this.retained).processParams(format, width, height, 1); @@ -141,6 +152,7 @@ public class ImageComponent2D extends ImageComponent { /** * Constructs a 2D image component object using the specified format, * BufferedImage, byReference flag, and yUp flag. + * The image class is set to ImageClass.BUFFERED_IMAGE. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -161,16 +173,19 @@ public class ImageComponent2D extends ImageComponent { boolean byReference, boolean yUp) { - ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); - ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(null), image.getHeight(null), 1); + ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); ((ImageComponent2DRetained)this.retained).set(image); } /** * Constructs a 2D image component object using the specified format, * RenderedImage, byReference flag, and yUp flag. + * The image class is set to ImageClass.RENDERED_IMAGE if the byReferece + * flag is true and the specified RenderedImage is not an instance + * of BufferedImage. In all other cases, the image class is set to + * ImageClass.BUFFERED_IMAGE. * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA, etc. @@ -187,32 +202,72 @@ public class ImageComponent2D extends ImageComponent { * @since Java 3D 1.2 */ public ImageComponent2D(int format, - RenderedImage image, - boolean byReference, - boolean yUp) { - + RenderedImage image, + boolean byReference, + boolean yUp) { + + ((ImageComponentRetained)this.retained).setByReference(byReference); + ((ImageComponentRetained)this.retained).setYUp(yUp); + ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); + ((ImageComponent2DRetained)this.retained).set(image); + } - ((ImageComponentRetained)this.retained).setByReference(byReference); - ((ImageComponentRetained)this.retained).setYUp(yUp); - ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); - ((ImageComponent2DRetained)this.retained).set(image); + /** + * Constructs a 2D image component object using the specified format, + * NioImageBuffer, byReference flag, and yUp flag. + * The image class is set to ImageClass.NIO_IMAGE_BUFFER. + * + * @param format the image component format, one of: FORMAT_RGB, + * FORMAT_RGBA, etc. + * @param image the NioImageBuffer used to create this 2D image component + * @param byReference a flag that indicates whether the data is copied + * into this image component object or is accessed by reference. + * @param yUp a flag that indicates the y-orientation of this image + * component. If yUp is set to true, the origin of the image is + * the lower left; otherwise, the origin of the image is the upper + * left. + * + * @exception IllegalArgumentException if format is invalid, or if + * the width or height of the image are not positive. + * + * @exception IllegalArgumentException if the byReference flag is false. + * + * @exception IllegalArgumentException if the yUp flag is false. + * + * @since Java 3D 1.5 + */ + public ImageComponent2D(int format, + NioImageBuffer image, + boolean byReference, + boolean yUp) { + + ((ImageComponentRetained)this.retained).setByReference(byReference); + ((ImageComponentRetained)this.retained).setYUp(yUp); + ((ImageComponent2DRetained)this.retained).processParams(format, image.getWidth(), image.getHeight(), 1); + ((ImageComponent2DRetained)this.retained).set(image); } /** * Sets this image component to the specified BufferedImage - * object. If the data access mode is not by-reference, then the + * object. + * If the data access mode is not by-reference, then the * BufferedImage data is copied into this object. If * the data access mode is by-reference, then a reference to the * BufferedImage is saved, but the data is not necessarily * copied. + *

    + * The image class is set to ImageClass.BUFFERED_IMAGE. * * @param image BufferedImage object containing the image. - * The format and size must be the same as the current format in this + * Its size must be the same as the current size of this * ImageComponent2D object. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalArgumentException if the width and height of the + * specified image is not equal to the width and height of this + * ImageComponent object. */ public void set(BufferedImage image) { if (isLiveOrCompiled()) { @@ -231,14 +286,23 @@ public class ImageComponent2D extends ImageComponent { * the data access mode is by-reference, a reference to the * RenderedImage is saved, but the data is not necessarily * copied. + *

    + * The image class is set to ImageClass.RENDERED_IMAGE if the the + * data access mode is by-reference and the specified + * RenderedImage is not an instance of BufferedImage. In all + * other cases, the image class is set to ImageClass.BUFFERED_IMAGE. * * @param image RenderedImage object containing the image. - * The format and size must be the same as the current format in this + * Its size must be the same as the current size of this * ImageComponent2D object. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalArgumentException if the width and height of the + * specified image is not equal to the width and height of this + * ImageComponent object. + * * @since Java 3D 1.2 */ public void set(RenderedImage image) { @@ -251,6 +315,43 @@ public class ImageComponent2D extends ImageComponent { ((ImageComponent2DRetained)this.retained).set(image); } + /** + * Sets this image component to the specified NioImageBuffer + * object. If the data access mode is not by-reference, the + * NioImageBuffer data is copied into this object. If + * the data access mode is by-reference, a reference to the + * NioImageBuffer is saved, but the data is not necessarily + * copied. + *

    + * The image class is set to ImageClass.NIO_IMAGE_BUFFER. + * + * @param image NioImageBuffer object containing the image. + * Its size must be the same as the current size of this + * ImageComponent2D object. + * + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalStateException if this ImageComponent object + * is not yUp. + * + * @exception IllegalArgumentException if the width and height of the + * specified image is not equal to the width and height of this + * ImageComponent object. + * + * @since Java 3D 1.5 + */ + public void set(NioImageBuffer image) { + if (isLiveOrCompiled()) { + if(!this.getCapability(ALLOW_IMAGE_WRITE)) { + throw new CapabilityNotSetException( + J3dI18N.getString("ImageComponent2D1")); + } + } + + ((ImageComponent2DRetained)this.retained).set(image); + } + /** * Retrieves the image from this ImageComponent2D object. If the * data access mode is not by-reference, a copy of the image @@ -264,9 +365,8 @@ public class ImageComponent2D extends ImageComponent { * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * - * @exception IllegalStateException if the data access mode is - * by-reference and the image referenced by this ImageComponent2D - * object is not an instance of BufferedImage. + * @exception IllegalStateException if the image class is not + * ImageClass.BUFFERED_IMAGE. */ public BufferedImage getImage() { if (isLiveOrCompiled()) { @@ -296,6 +396,9 @@ public class ImageComponent2D extends ImageComponent { * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalStateException if the image class is not one of: + * ImageClass.BUFFERED_IMAGE or ImageClass.RENDERED_IMAGE. + * * @since Java 3D 1.2 */ public RenderedImage getRenderedImage() { @@ -306,6 +409,35 @@ public class ImageComponent2D extends ImageComponent { return ((ImageComponent2DRetained)this.retained).getImage(); } + /** + * Retrieves the image from this ImageComponent2D object. If the + * data access mode is not by-reference, a copy of the image + * is made. If the data access mode is by-reference, the + * reference is returned. + * + * @return either a new NioImageBuffer object created from the data + * in this image component, or the NioImageBuffer object referenced + * by this image component. + * + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalStateException if the image class is not + * ImageClass.NIO_IMAGE_BUFFER. + * + * @since Java 3D 1.5 + */ + public NioImageBuffer getNioImage() { + + if (isLiveOrCompiled()) { + if (!this.getCapability(ImageComponent.ALLOW_IMAGE_READ)) { + throw new CapabilityNotSetException(J3dI18N.getString("ImageComponent2D0")); + } + } + return ((ImageComponent2DRetained)this.retained).getNioImage(); + + } + /** * Modifies a contiguous subregion of the image component. @@ -313,8 +445,8 @@ public class ImageComponent2D extends ImageComponent { * starting at the offset (srcX, srcY) of the specified * RenderedImage object will be copied into the image component * starting at the offset (dstX, dstY) of the ImageComponent2D object. - * The RenderedImage object must be of the same format as the current - * format of this object. + * The specified RenderedImage object must be of the same format as + * the current RenderedImage object in this image component. * This method can only be used if the data access mode is * by-copy. If it is by-reference, see updateData(). * @@ -332,15 +464,19 @@ public class ImageComponent2D extends ImageComponent { * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph + * * @exception IllegalStateException if the data access mode is * BY_REFERENCE. + * * @exception IllegalArgumentException if width or * height of * the subregion exceeds the dimension of the image of this object. + * * @exception IllegalArgumentException if dstX < 0, or * (dstX + width) > width of this object, or * dstY < 0, or * (dstY + height) > height of this object. + * * @exception IllegalArgumentException if srcX < 0, or * (srcX + width) > width of the RenderedImage * object containing the subimage, or @@ -348,6 +484,12 @@ public class ImageComponent2D extends ImageComponent { * (srcY + height) > height of the * RenderedImage object containing the subimage. * + * @exception IllegalArgumentException if the specified RenderedImage + * is not compatible with the existing RenderedImage. + * + * @exception IllegalStateException if the image class is not one of: + * ImageClass.BUFFERED_IMAGE or ImageClass.RENDERED_IMAGE. + * * @since Java 3D 1.3 */ public void setSubImage(RenderedImage image, int width, int height, @@ -457,7 +599,7 @@ public class ImageComponent2D extends ImageComponent { public NodeComponent cloneNodeComponent() { ImageComponent2DRetained rt = (ImageComponent2DRetained) retained; - ImageComponent2D img = new ImageComponent2D(rt.format, + ImageComponent2D img = new ImageComponent2D(rt.getFormat(), rt.width, rt.height, rt.byReference, @@ -485,15 +627,26 @@ public class ImageComponent2D extends ImageComponent { * @see NodeComponent#setDuplicateOnCloneTree */ void duplicateAttributes(NodeComponent originalNodeComponent, - boolean forceDuplicate) { - super.duplicateAttributes(originalNodeComponent, forceDuplicate); - - RenderedImage img = ((ImageComponent2DRetained) - originalNodeComponent.retained).getImage(); - - if (img != null) { - ((ImageComponent2DRetained) retained).set(img); - } + boolean forceDuplicate) { + super.duplicateAttributes(originalNodeComponent, forceDuplicate); + + ImageComponent.ImageClass imageClass = + ((ImageComponentRetained)originalNodeComponent.retained).getImageClass(); + if(imageClass == ImageComponent.ImageClass.NIO_IMAGE_BUFFER) { + NioImageBuffer nioImg = ((ImageComponent2DRetained) + originalNodeComponent.retained).getNioImage(); + + if(nioImg != null) { + ((ImageComponent2DRetained) retained).set(nioImg); + } + } else { + RenderedImage img = ((ImageComponent2DRetained) + originalNodeComponent.retained).getImage(); + + if (img != null) { + ((ImageComponent2DRetained) retained).set(img); + } + } } /** diff --git a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java index 50680bf..b754b36 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java @@ -22,1238 +22,243 @@ import java.awt.color.ColorSpace; */ class ImageComponent2DRetained extends ImageComponentRetained { - private int rasterRefCnt = 0; // number of raster using this object - private int textureRefCnt = 0; // number of texture using this object - private DetailTextureImage detailTexture = null; // will reference a - // DetailTexture object if - // this image is being - // referenced as a detail image - - // use in D3D to map object to surface pointer - int hashId; - native void freeD3DSurface(int hashId); - - float[] lastAlpha = new float[1]; - - static final double EPSILON = 1.0e-6; - - // dirty mask to track if the image has been changed since the last - // alpha update. The nth bit in the mask represents the dirty bit - // of the image for screen nth. If nth bit is set, then the image - // needs to be updated with the current alpha values. - int imageChanged = 0; + // used in D3D to map object to surface pointer + int hashId; ImageComponent2DRetained() { hashId = hashCode(); } - + /** - * Copies the specified BufferedImage to this 2D image component object. - * @param image BufferedImage object containing the image. + * This method handles NioImageBuffer + * Refers or copies the specified NioImageBuffer to this 2D image component object. + * @param image NioImageBuffer object containing the image. * The format and size must be the same as the current format in this * ImageComponent2D object. */ - final void set(BufferedImage image) { - int width = image.getWidth(null); - int height = image.getHeight(null); + void set(NioImageBuffer image) { - if (width != this.width) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained0")); + int width = image.getWidth(); + int height = image.getHeight(); - if (height != this.height) + if (!byReference) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2D7")); + } + if (!yUp) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2D8")); + } + + if (width != this.width) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained0")); + } + if (height != this.height) { throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained1")); + } + + geomLock.getLock(); - int imageBytes; - // Note, currently only EXT_ABGR and EXT_BGR are not copied, if - // its going to be copied, do it at set time (at this time, the - // renderer is running in parallel), if we delay it until - // renderBin:updateObject time (when it calls evaluateExtension), - // we are stalling the renderer - geomLock.getLock(); - if (!byReference || (byReference && willBeCopied(image))) { - imageBytes = height * width * bytesPerPixelIfStored; - if (usedByTexture || ! usedByRaster) { - // ==> (usedByTexture) || (! usedByTexture && ! usedByRaster) - - if (imageYup == null || imageYup.length < imageBytes) { - imageYup = new byte[imageBytes]; - imageYupAllocated = true; - } - - // buffered image -> imageYup - storedYupFormat = internalFormat; - bytesPerYupPixelStored = getBytesStored(storedYupFormat); - copyImage(image, imageYup, true, 0, storedYupFormat, - bytesPerYupPixelStored); - imageYupClass = BUFFERED_IMAGE; - } - - if (usedByRaster) { - imageYdownClass = BUFFERED_IMAGE; - storedYdownFormat = internalFormat; - bytesPerYdownPixelStored = getBytesStored(storedYdownFormat); - - if (imageYdown[0] == null || imageYdown[0].length < imageBytes) { - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - - if (imageYup != null){ - //imageYup -> imageYdown - setImageYdown(imageYup, imageYdown[0]); - } else { - // buffered image -> imageYdown - copyImage(image, imageYdown[0], false, 0, - storedYdownFormat, bytesPerYdownPixelStored); - } - } - // If its byRef case, but we copied because we know that - // the underlying native API cannot support this case! - if (byReference) { - bImage[0] = image; - if (usedByTexture || !usedByRaster) - imageYupCacheDirty = false; - else - imageYupCacheDirty = true; - - if (usedByRaster) - imageYdownCacheDirty = false; - else - imageYdownCacheDirty = true; - - } - else { - imageDirty[0] = true; - } - - } - // If its by reference, then make a copy only if necessary - else { - imageYupCacheDirty = true; - imageYdownCacheDirty = true; - bImage[0] = image; - } - imageChanged = 0xffff; - lastAlpha[0] = 1.0f; - geomLock.unLock(); - - if (source.isLive()) { - freeSurface(); - - // send a IMAGE_CHANGED message in order to - // notify all the users of the change - sendMessage(IMAGE_CHANGED, null); - } - } - - - boolean willBeCopied(RenderedImage image) { - return shouldImageBeCopied(getImageType(image), - (Canvas3D.EXT_ABGR|Canvas3D.EXT_BGR), image); - } - - - - // NOTE, IMPORTANT: any additions to the biType tested , should be added to - // the willBeCopied() function - final boolean shouldImageBeCopied(int biType, int ext, RenderedImage ri) { - - if (!byReference) - return true; - - if ((((ext & Canvas3D.EXT_ABGR) != 0) && - ((biType == BufferedImage.TYPE_4BYTE_ABGR) && - (format == ImageComponent.FORMAT_RGBA8))) || - (((ext & Canvas3D.EXT_BGR) != 0) && - ((biType == BufferedImage.TYPE_3BYTE_BGR) && - (format == ImageComponent.FORMAT_RGB))) || - ((biType == BufferedImage.TYPE_BYTE_GRAY) && - (format == ImageComponent.FORMAT_CHANNEL8)) || - (is4ByteRGBAOr3ByteRGB(ri))) { - /* ||XXXX: Don't do short for now! - ((biType == BufferedImage.TYPE_USHORT_GRAY) && - (format == ImageComponent.FORMAT_CHANNEL8) - */ - - return false; - } - return true; - } - - final int getStoredFormat(int biType, RenderedImage ri) { - int f = 0; - switch(biType) { - case BufferedImage.TYPE_4BYTE_ABGR: - f= BYTE_ABGR; - break; - case BufferedImage.TYPE_BYTE_GRAY: - f= BYTE_GRAY; - break; - case BufferedImage.TYPE_USHORT_GRAY: - f = USHORT_GRAY; - break; - case BufferedImage.TYPE_3BYTE_BGR: - f = BYTE_BGR; - break; - case BufferedImage.TYPE_CUSTOM: - if (is4ByteRGBAOr3ByteRGB(ri)) { - SampleModel sm = ri.getSampleModel(); - if (sm.getNumBands() == 3) { - f = BYTE_RGB; - } - else { - f = BYTE_RGBA; - } - } - break; - default: - // Should never come here - } - return f; - } - - final void set(RenderedImage image) { + setImageClass(image); - if (image instanceof BufferedImage) { - set(((BufferedImage)image)); - } - else { - /* - // Create a buffered image from renderImage - ColorModel cm = image.getColorModel(); - WritableRaster wRaster = image.copyData(null); - BufferedImage bi = new BufferedImage(cm, - wRaster, - cm.isAlphaPremultiplied() - ,null); - set(bi); - } - */ - int width = image.getWidth(); - int height = image.getHeight(); + // This is a byRef image. + setRefImage(image,0); - if (width != this.width) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained0")); - - if (height != this.height) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained1")); - - int imageBytes; - // Note, currently only EXT_ABGR and EXT_BGR are not copied, if - // its going to be copied, do it at set time (at this time, the - // renderer is running in parallel), if we delay it until - // renderBin:updateObject time (when it calls evaluateExtension), - // we are stalling the renderer - geomLock.getLock(); - if (!byReference ||(byReference && willBeCopied(image))) { - imageBytes = height * width * bytesPerPixelIfStored; - if (usedByTexture || ! usedByRaster) { - if (imageYup == null || imageYup.length < imageBytes) { - imageYup = new byte[imageBytes]; - imageYupAllocated = true; - } - - // buffered image -> imageYup - storedYupFormat = internalFormat; - bytesPerYupPixelStored = getBytesStored(storedYupFormat); - copyImage(image, imageYup, true, 0, storedYupFormat, - bytesPerYupPixelStored); - imageYupClass = BUFFERED_IMAGE; - } - - if (usedByRaster) { + // Reset this flag to true, incase it was set to false due to + // the previous image type. + abgrSupported = true; - imageYdownClass = BUFFERED_IMAGE; - storedYdownFormat = internalFormat; - bytesPerYdownPixelStored = getBytesStored(storedYdownFormat); + imageTypeIsSupported = isImageTypeSupported(image); - if (imageYdown[0] == null || imageYdown[0].length < imageBytes) { - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - - if (imageYup != null) - //imageYup -> imageYdown - setImageYdown(imageYup, imageYdown[0]); - else - // buffered image -> imageYdown - copyImage(image, imageYdown[0], false, 0, - storedYdownFormat, bytesPerYdownPixelStored); - } - if (byReference) { - bImage[0] = image; - if (usedByTexture || !usedByRaster) - imageYupCacheDirty = false; - else - imageYupCacheDirty = true; - - if (usedByRaster) - imageYdownCacheDirty = false; - else - imageYdownCacheDirty = true; - } - else { - imageDirty[0] = true; - } - } - // If its by reference, then make a copy only if necessary - else { - imageYupCacheDirty = true; - imageYdownCacheDirty = true; - bImage[0] = image; - } + if (imageTypeIsSupported) { + + /* Use reference when ( format is OK, Yup is true, and byRef is true). */ + // Create image data object with the byRef image. */ + imageData = createNioImageBufferDataObject(image); + + } else { + // Handle abgrSupported is false case. + imageData = createNioImageBufferDataObject(null); + copyUnsupportedNioImageToImageData(image, 0, 0, 0, 0, width, height, imageData); - } - imageChanged = 0xffff; - lastAlpha[0] = 1.0f; - geomLock.unLock(); - if (source.isLive()) { - freeSurface(); + } + + geomLock.unLock(); + + if (source.isLive()) { + freeSurface(); + + // send a IMAGE_CHANGED message in order to + // notify all the users of the change sendMessage(IMAGE_CHANGED, null); - } + } } - - /** - * Retrieves a copy of the image in this ImageComponent2D object. - * @return a new BufferedImage object created from the image in this - * ImageComponent2D object + + /** + * This method handles both BufferedImage and RenderedImage + * Copies the specified RenderedImage to this 2D image component object. + * @param image RenderedImage object containing the image. + * The format and size must be the same as the current format in this + * ImageComponent2D object. */ - final RenderedImage getImage() { - if (!byReference && imageDirty[0]) { - imageDirty[0] = false; - retrieveBufferedImage(0); - } - return bImage[0]; - } - - // allocate storage for imageYdown - // set imageYdown and free imageYup if necessary - final void setRasterRef() { - // Ref case will be handled by evaluateExtension(); - if (usedByRaster) - return; - - usedByRaster = true; - - if (format == ImageComponent.FORMAT_CHANNEL8) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained2")); - - if (!byReference) { - if (imageYdown[0] == null && imageYup != null) { - imageYdown[0] = new byte[height * width * bytesPerYupPixelStored]; - imageYdownAllocated = true; - - // imageYup -> imageYdown - imageYdownClass = BUFFERED_IMAGE; - storedYdownFormat = storedYupFormat; - bytesPerYdownPixelStored = bytesPerYupPixelStored; - setImageYdown(imageYup, imageYdown[0]); - } - if (usedByTexture == false) { - imageYup = null; - imageYupAllocated = false; - } - - } - else { - if (willBeCopied(bImage[0])) { - geomLock.getLock(); - if (imageYdownCacheDirty) { - if (imageYdown[0] == null) { - - if (imageYup != null) { - storedYdownFormat = storedYupFormat; - bytesPerYdownPixelStored = bytesPerYupPixelStored; - imageYdown[0] =new byte[height*width *bytesPerYdownPixelStored]; - setImageYdown(imageYup, imageYdown[0]); - } - else { - imageYdown[0] = new byte[height * width * bytesPerPixelIfStored]; - bytesPerYdownPixelStored = bytesPerPixelIfStored; - storedYdownFormat = internalFormat; - - if (bImage[0] instanceof BufferedImage) { - copyImage(((BufferedImage)bImage[0]), - imageYdown[0], false, 0, - storedYdownFormat, - bytesPerYdownPixelStored); - } - else { - copyImage(bImage[0], imageYdown[0], false, 0, - storedYdownFormat, - bytesPerYdownPixelStored); - } - } - imageYdownClass = BUFFERED_IMAGE; - imageYdownAllocated = true; - } - imageYdownCacheDirty = false; - } - geomLock.unLock(); - } - else { - geomLock.getLock(); - imageYdownCacheDirty = true; - geomLock.unLock(); - } - /* - // Can't do this - since I don't know which extension - // will be supported, if Ydown is going away then - // this code will be useful - else if (yUp) { - geomLock.getLock(); - if (imageYdownCacheDirty) { - storeRasterImageWithFlip(bImage[0]); - imageYdownCacheDirty = false; - } - geomLock.unLock(); - } - */ - } - } - - // allocate storage for imageYup - // set imageYup and free imageYdown if necessary - final void setTextureRef() { - // Ref case will be handled by evaluateExtension(); - if (usedByTexture) - return; - - usedByTexture = true; - - if (!byReference) { - - if (imageYup == null && imageYdown[0] != null) { - storedYupFormat = storedYdownFormat; - bytesPerYupPixelStored = bytesPerYdownPixelStored; - imageYup = new byte[height * width * bytesPerYupPixelStored]; - // imageYdown -> imageYup - setImageYup(imageYdown[0], imageYup); - imageYupClass = BUFFERED_IMAGE; - imageYupAllocated = true; - } - if (usedByRaster == false) { - imageYdown[0] = null; - imageYdownAllocated = false; - } - - } - // If the image will not be stored by reference, because - // the format is not supported by the underlying API - else { - if (willBeCopied(bImage[0])) { - geomLock.getLock(); - if (imageYupCacheDirty) { - if (imageYup == null) { - if (imageYdown[0] != null) { - // imageYdown -> imageYup - storedYupFormat = storedYdownFormat; - bytesPerYupPixelStored = bytesPerYdownPixelStored; - imageYup = new byte[height * width * bytesPerYupPixelStored]; - setImageYup(imageYdown[0], imageYup); - } - else { - imageYup = new byte[height * width * bytesPerPixelIfStored]; - bytesPerYupPixelStored = bytesPerPixelIfStored; - storedYupFormat = internalFormat; - - if (bImage[0] instanceof BufferedImage) { - copyImage(((BufferedImage)bImage[0]), imageYup, - true, 0, storedYupFormat, - bytesPerYupPixelStored); - } - else { - copyImage(bImage[0], imageYup, true, 0, - storedYupFormat, - bytesPerYupPixelStored); - } - } - imageYupClass = BUFFERED_IMAGE; - imageYupAllocated = true; - } - imageYupCacheDirty = false; - } - geomLock.unLock(); - } - else { - geomLock.getLock(); - imageYupCacheDirty = true; - geomLock.unLock(); - } - /* - // Can't do this - since I don't know which extension - // will be supported, if Ydown is going away then - // this code will be useful - - // If Image will not be stored by reference because - // of wrong orienetation - else if (!yUp) { - geomLock.getLock(); - if (imageYupCacheDirty) { - storeTextureImageWithFlip(bImage[0]); - imageYupCacheDirty = false; - } - geomLock.unLock(); - } - */ - } - - } - - - // copy imageYup to imageYdown in reverse scanline order - final void setImageYdown(byte[] src, byte[] dst) { - int scanLineSize = width * bytesPerYdownPixelStored; - int srcOffset, dstOffset, i; - - for (srcOffset = (height - 1) * scanLineSize, dstOffset = 0, - i = 0; i < height; i++, - srcOffset -= scanLineSize, dstOffset += scanLineSize) { - - System.arraycopy(src, srcOffset, dst, dstOffset, - scanLineSize); + void set(RenderedImage image) { + + int width = image.getWidth(); + int height = image.getHeight(); + + if (width != this.width) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained0")); } - - } - - // Preserve the incoming format of thre renderImage, but maybe - // flip the image or make a plain copy - // Used only for raster - final void copyRImage(RenderedImage image, byte[] dst, boolean flip, - int bPerPixel) { - - int numX = image.getNumXTiles(); - int numY = image.getNumYTiles(); - int tilew = image.getTileWidth(); - int tileh = image.getTileHeight(); - int i, j, h; - java.awt.image.Raster ras; - int tileLineBytes = tilew * bPerPixel; - int x = image.getMinTileX(); - int y = image.getMinTileY(); - int srcOffset, dstOffset; - int dstLineBytes = 0; - int tileStart; - int tileBytes = tileh * tilew * numX * bPerPixel; - int dstStart; - int tmph, tmpw, curw, curh; - int rowOffset, colOffset; - int sign; - - if (flip) { - dstLineBytes =width * bPerPixel; - tileStart = (height - 1) * dstLineBytes; - dstLineBytes = -(dstLineBytes); - } - else { - tileStart = 0; - dstLineBytes = width * bPerPixel; - } - // convert from Ydown to Yup for texture - int minX = image.getMinX(); - int minY = image.getMinY(); - int xoff = image.getTileGridXOffset(); - int yoff = image.getTileGridYOffset(); - int endXTile = x * tilew + xoff+tilew; - int endYTile = y * tileh + yoff+tileh; - tmpw = width; - tmph = height; - // Check if the width is less than the tile itself .. - curw = (endXTile - minX); - curh = (endYTile - minY); - - if (tmpw < curw) { - curw = tmpw; - } - - if (tmph < curh) { - curh = tmph; - } - int startw = curw ; - - rowOffset = (tilew - curw) * bPerPixel; - colOffset = tilew * (tileh - curh) * bPerPixel; - int bytesCopied = 0; - srcOffset = rowOffset + colOffset; - - - for (i = y; i < y+numY; i++) { - dstStart = tileStart; - curw = startw; - tmpw = width; - for (j = x; j < x+numX; j++) { - ras = image.getTile(j,i); - byte[] src = ((DataBufferByte)ras.getDataBuffer()).getData(); - dstOffset = dstStart; - bytesCopied = curw * bPerPixel; - for (h = 0;h < curh; h++) { - System.arraycopy(src, srcOffset, dst, dstOffset, - bytesCopied); - srcOffset += tileLineBytes; - dstOffset += dstLineBytes; - } - srcOffset = colOffset; - dstStart += curw * bPerPixel; - tmpw -= curw; - if (tmpw < tilew) - curw = tmpw; - else - curw = tilew; - } - srcOffset = rowOffset; - colOffset = 0; - tileStart += curh * dstLineBytes; - tmph -= curh; - if (tmph < tileh) - curh = tmph; - else - curh = tileh; - } - } - - // copy imageYdown to imageYup in reverse scanline order - final void setImageYup(byte[] src, byte[] dst) { - int scanLineSize = width * bytesPerYupPixelStored; - int srcOffset, dstOffset, i; - - for (srcOffset = 0, dstOffset = (height - 1) * scanLineSize, - i = 0; i < height; i++, - srcOffset += scanLineSize, dstOffset -= scanLineSize) { - - System.arraycopy(src, srcOffset, dst, dstOffset, - scanLineSize); + if (height != this.height) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent2DRetained1")); + } + + setImageClass(image); + + geomLock.getLock(); + + if (byReference) { + setRefImage(image,0); + } + + // Reset this flag to true, incase it was set to false due to + // the previous image type. + abgrSupported = true; + + imageTypeIsSupported = isImageTypeSupported(image); + + if (imageTypeIsSupported) { + + if (byReference && yUp) { + /* Use reference when ( format is OK, Yup is true, and byRef is true). */ + // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported && byReference && yUp) --- (1)"); + if (image instanceof BufferedImage) { + // Create image data object with the byRef image. */ + imageData = createRenderedImageDataObject(image); + } + else { + // System.err.println("byRef and not BufferedImage !!!"); + imageData = null; + } + + } else { + // Either not byRef or not yUp or not both + // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported && ((!byReference && yUp) || (imageTypeSupported && !yUp)) --- (2)"); + + // Create image data object with buffer for image. */ + imageData = createRenderedImageDataObject(null); + copySupportedImageToImageData(image, 0, imageData); + } + + } else { + // image type is unsupported, need to create a supported local copy. + // TODO : borrow code from JAI to convert to right format. + // System.err.println("ImageComponent2DRetained.set() : (imageTypeSupported == false) --- (4)"); + /* Will use the code segment in copy() method */ + + // Create image data object with buffer for image. */ + imageData = createRenderedImageDataObject(null); + copyUnsupportedImageToImageData(image, 0, imageData); + + } + + geomLock.unLock(); + + if (source.isLive()) { + freeSurface(); + + // send a IMAGE_CHANGED message in order to + // notify all the users of the change + sendMessage(IMAGE_CHANGED, null); } } - // Lock out user thread from modifying usedByRaster and - // usedByTexture variables by using synchronized routines - final void evaluateExtensions(int ext) { - int i; - int imageBytes; - RenderedImage image = bImage[0]; - - // System.out.println("!!!!!!!!!!!!!imageYupCacheDirty = "+imageYupCacheDirty); - // System.out.println("!!!!!!!!!!!!!imageYdownCacheDirty = "+imageYdownCacheDirty); - // System.out.println("!!!!!!!!!!!!!usedByTexture = "+usedByTexture); - // System.out.println("!!!!!!!!!!!!!usedByRaster = "+usedByRaster); - - - if (!imageYupCacheDirty && !imageYdownCacheDirty) { - return; - } - - int riType = getImageType(image); - - // Thread.dumpStack(); - if (usedByTexture == true || ! usedByRaster) { - // If the image is already allocated, then return - // nothing to do! - // Since this is a new image, the app may have changed the image - // when it was not live, so re-compute, until the image is allocated - // for this pass! - // System.out.println("!!!!!!!!!!!!!imageYupCacheDirty = "+imageYupCacheDirty); - if (!imageYupCacheDirty) { - evaluateRaster(riType, ext); - return; - } - if (shouldImageBeCopied(riType, ext, image)) { - - imageBytes = height * width * bytesPerPixelIfStored; - if (imageYup == null || !imageYupAllocated) { - imageYup = new byte[imageBytes]; - imageYupAllocated = true; - } - // buffered image -> imageYup - bytesPerYupPixelStored = bytesPerPixelIfStored; - storedYupFormat = internalFormat; - copyImage(image, imageYup, true, 0, - storedYupFormat, bytesPerYupPixelStored); - imageYupClass = BUFFERED_IMAGE; - imageYupCacheDirty = false; - } - else { - // This image is already valid .. - if (!imageYupCacheDirty) { - evaluateRaster(riType, ext); - return; - } - storedYupFormat = getStoredFormat(riType, image); - bytesPerYupPixelStored = getBytesStored(storedYupFormat); - - // It does not have to be copied, but we - // have to copy because the incoming image is - // ydown - if (!yUp) { - storeTextureImageWithFlip(image); - } - else { - if (image instanceof BufferedImage) { - byte[] tmpImage = ((DataBufferByte)((BufferedImage)image).getRaster().getDataBuffer()).getData(); - imageYup = tmpImage; - imageYupAllocated = false; - imageYupClass = BUFFERED_IMAGE; - } - else { - numXTiles = image.getNumXTiles(); - numYTiles = image.getNumYTiles(); - tilew = image.getTileWidth(); - tileh = image.getTileHeight(); - minTileX = image.getMinTileX(); - minTileY = image.getMinTileY(); - minX = image.getMinX(); - minY = image.getMinY(); - tileGridXOffset =image.getTileGridXOffset(); - tileGridYOffset = image.getTileGridYOffset(); - imageYupAllocated = false; - imageYupClass = RENDERED_IMAGE; - imageYup = null; - } - } - - } - if (usedByRaster == false) { - imageYdown[0] = null; - imageYdownAllocated = false; - } - } - evaluateRaster(riType, ext); - } - - void evaluateRaster(int riType, int ext) { - int i; - int imageBytes; - RenderedImage image = bImage[0]; - - if (usedByRaster) { - // If the image is already allocated, then return - // nothing to do! - if (!imageYdownCacheDirty) { - return; - } - if (shouldImageBeCopied(riType, ext, image)) { - // System.out.println("Raster Image is copied"); - imageBytes = height * width * bytesPerPixelIfStored; - if (imageYdown[0] == null || !imageYdownAllocated || imageYdown[0].length < imageBytes){ - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - if (imageYup != null) { - storedYdownFormat = storedYupFormat; - bytesPerYdownPixelStored = bytesPerYupPixelStored; - setImageYdown(imageYup, imageYdown[0]); - } - else { - // buffered image -> imageYup - storedYdownFormat = internalFormat; - bytesPerYdownPixelStored = bytesPerPixelIfStored; - copyImage(image, imageYdown[0], false, 0, - storedYdownFormat, bytesPerYdownPixelStored); - } - imageYdownCacheDirty = false; - imageYdownClass = BUFFERED_IMAGE; - } - else { - // This image is already valid .. - if (!imageYdownCacheDirty) { - return; - } - storedYdownFormat = getStoredFormat(riType, image); - bytesPerYdownPixelStored = getBytesStored(storedYdownFormat); - if (yUp) { - storeRasterImageWithFlip(image); - } - else { - if (image instanceof BufferedImage) { - byte[] tmpImage = ((DataBufferByte)((BufferedImage)image).getRaster().getDataBuffer()).getData(); - imageYdown[0] = tmpImage; - imageYdownAllocated = false; - imageYdownClass = BUFFERED_IMAGE; - // System.out.println("Raster Image is stored by ref"); - } - else { - // Right now, always copy since opengl rasterpos is - // too restrictive - imageBytes = width*height*bytesPerYdownPixelStored; - if (imageYdown[0] == null || !imageYdownAllocated ||imageYdown[0].length < imageBytes){ - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - imageYdownClass = BUFFERED_IMAGE; - copyRImage(image,imageYdown[0], false, bytesPerYdownPixelStored); - // System.out.println("Copying by ref RImage"); - - /* - numXTiles = image.getNumXTiles(); - numYTiles = image.getNumYTiles(); - tilew = image.getTileWidth(); - tileh = image.getTileHeight(); - minTileX = image.getMinTileX(); - minTileY = image.getMinTileY(); - imageYdownAllocated = false; - imageYdownClass = RENDERED_IMAGE; - imageYdown = null; - */ - } - imageYdownCacheDirty = false; - } - - - } - if (usedByTexture == false) { - imageYup = null; - imageYupAllocated = false; - } - } - } - - void storeRasterImageWithFlip(RenderedImage image) { - int imageBytes; - - if (image instanceof BufferedImage) { - imageBytes = width*height*bytesPerYdownPixelStored; - if (imageYdown[0] == null || !imageYdownAllocated ||imageYdown[0].length < imageBytes){ - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - imageYdownClass = BUFFERED_IMAGE; - imageYdownCacheDirty = false; - byte[] tmpImage = ((DataBufferByte)((BufferedImage)image).getRaster().getDataBuffer()).getData(); - setImageYdown(tmpImage, imageYdown[0]); - } - else { - // Right now, always copy since opengl rasterpos is - // too restrictive - - imageBytes = width*height*bytesPerYdownPixelStored; - if (imageYdown[0] == null || !imageYdownAllocated ||imageYdown[0].length < imageBytes){ - imageYdown[0] = new byte[imageBytes]; - imageYdownAllocated = true; - } - imageYdownClass = BUFFERED_IMAGE; - imageYdownCacheDirty = false; - copyRImage(image, imageYdown[0], true, bytesPerYdownPixelStored); - } - } - - void storeTextureImageWithFlip(RenderedImage image) { - int imageBytes; - - if (image instanceof BufferedImage) { - byte[] tmpImage = ((DataBufferByte)((BufferedImage)image).getRaster().getDataBuffer()).getData(); - - if (imageYup == null || !imageYupAllocated) { - imageBytes = width*height*bytesPerYupPixelStored; - imageYup = new byte[imageBytes]; - imageYupAllocated = true; - } - imageYupClass = BUFFERED_IMAGE; - setImageYup(tmpImage, imageYup); - imageYupCacheDirty = false; - - } - else { - if (imageYup == null || !imageYupAllocated) { - imageBytes = width*height*bytesPerYupPixelStored; - imageYup = new byte[imageBytes]; - imageYupAllocated = true; - } - imageYupClass = BUFFERED_IMAGE; - copyRImage(image, imageYup, true, bytesPerYupPixelStored); - imageYupCacheDirty = false; - } - } - - void setLive(boolean inBackgroundGroup, int refCount) { - super.setLive(inBackgroundGroup, refCount); - } - - void clearLive(int refCount) { - super.clearLive(refCount); - if (this.refCount <= 0) { - freeSurface(); - } - } - - void freeSurface() { - if (VirtualUniverse.mc.isD3D()) { - freeD3DSurface(hashId); - } - } - - protected void finalize() { - // For Pure immediate mode, there is no clearLive so - // surface will free when JVM do GC - freeSurface(); - } - void updateAlpha(Canvas3D cv, int screen, float alpha) { - // if alpha is smaller than EPSILON, set it to EPSILON, so that - // even if alpha is equal to 0, we will not completely lose - int i, j; - byte byteAlpha; - float rndoff = 0.0f; - - // the original alpha value - if (alpha <= EPSILON) { - alpha = (float)EPSILON; - } - // System.out.println("========> updateAlpha, this = "+this); - // Lock out the other renderers .. - synchronized (this) { - // If by reference, the image has been copied, but aset has occured - // or if the format is not RGBA, then copy - // Thread.dumpStack(); - if (isByReference() && ((storedYdownFormat != internalFormat) || ((imageChanged & 1) != 0))) { - int imageBytes = height * width * bytesPerPixelIfStored; - if (imageYdown[0] == null || !imageYdownAllocated|| imageYdown[0].length < imageBytes) - imageYdown[0] = new byte[imageBytes]; - bytesPerYdownPixelStored = bytesPerPixelIfStored; - storedYdownFormat = internalFormat; - copyImage(bImage[0],imageYdown[0], false, 0, - storedYdownFormat, bytesPerYdownPixelStored); - imageYdownCacheDirty = false; - imageYdownClass = BUFFERED_IMAGE; - imageYdownAllocated = true; - imageChanged &= ~1; - freeSurface(); - } - - // allocate an entry for the last alpha of the screen if needed - if (lastAlpha == null) { - lastAlpha = new float[screen+1]; - lastAlpha[screen] = 1.0f; - } - else if (lastAlpha.length <= screen) { - float[] la = new float[screen+1]; - for (i = 0; i < lastAlpha.length; i++) { - la[i] = lastAlpha[i]; - } - lastAlpha = la; - lastAlpha[screen] = 1.0f; - } - // allocate a copy of the color data for the screen if needed. - // this piece of code is mainly for multi-screens case - if (imageYdown.length <= screen) { - byte[][] bdata = new byte[screen+1][]; - byte[] idata; - int refScreen = -1; - - int imageBytes = height * width * bytesPerYdownPixelStored; - idata = bdata[screen] = new byte[imageBytes]; - for (i = 0; i < imageYdown.length; i++) { - bdata[i] = imageYdown[i]; - if (Math.abs(lastAlpha[i] - alpha) < EPSILON) { - refScreen = i; - } - } - - if (noAlpha) { - byteAlpha = (byte) (alpha * 255.0f + 0.5); - for (j=3,i=0; i< width * height; i++,j+=4) { - idata[j] = byteAlpha; - } - } - else { - - // copy the data from a reference screen which has the closest - // alpha values - if (refScreen >= 0) { - System.arraycopy(imageYdown[refScreen], 0, idata, 0, imageBytes); - lastAlpha[screen] = lastAlpha[refScreen]; - } - else { - float m = alpha/lastAlpha[0]; - if (m < 1.0f) - rndoff = 0.5f; - else - rndoff = -0.5f; - - byte[] srcData = imageYdown[0]; - for (i = 0, j = 0; i < width * height; i++, j+= 4) { - System.arraycopy(srcData, j, idata, j, 3); - idata[j+3] =(byte)( ((int)srcData[j+3] & 0xff) * m + rndoff); - } - lastAlpha[screen] = alpha; - } - } - imageYdown = bdata; - - imageChanged &= ~(1 << screen); - freeSurface(); - return; - } + void setSubImage(RenderedImage image, int width, int height, + int srcX, int srcY, int dstX, int dstY) { - if ((imageChanged & (1<< screen)) == 0) { - // color data is not modified - // if alpha is different, update the alpha values - int val = -1; - if (Math.abs(lastAlpha[screen] - alpha) > EPSILON) { - byte[] idata = imageYdown[screen]; - if (noAlpha) { - byteAlpha = (byte) (alpha * 255.0f + 0.5); - for (j=3,i=0; i< width * height; i++,j+=4) { - idata[j] = byteAlpha; - } - } - else { - float m = alpha/lastAlpha[screen]; - if (m < 1.0f) - rndoff = 0.5f; - else - rndoff = -0.5f; - - for (i = 0, j = 3; i < width * height; i++, j+= 4) { - idata[j] =(byte)( ((int)idata[j] & 0xff) * m + rndoff); - } - } - freeSurface(); - } - } - else { - // color data is modified - if (screen == 0) { - // just update alpha values since screen 0 data is - // already updated in copyImage() - byte[] idata = imageYdown[0]; - if (noAlpha) { - byteAlpha = (byte) (alpha * 255.0f + 0.5); - for (j=3,i=0; i< width * height; i++,j+=4) { - idata[j] = byteAlpha; - } - } - else { - for (i = 0, j = 3; i < width * height; i++, j+= 4) { - idata[j] =(byte)( ((int)idata[j] & 0xff) * alpha + 0.5); - } - } - - } - else { - // update color values from screen 0 data - float m; - byte[] ddata = imageYdown[screen]; - if (noAlpha) { - byteAlpha = (byte) (alpha * 255.0f + 0.5); - for (j=3,i=0; i< width * height; i++,j+=4) { - ddata[j] = byteAlpha; - } - } - else { - if ((imageChanged & 1) == 0) { - // alpha is up to date in screen 0 - m = alpha / lastAlpha[0]; - } - else { - m = alpha; - } + if (!isSubImageTypeEqual(image)) { + throw new IllegalStateException( + J3dI18N.getString("ImageComponent2D6")); + } - if (m < 1.0f) - rndoff = 0.5f; - else - rndoff = -0.5f; + // Can't be byReference + assert (!byReference); + assert (imageData != null); + + geomLock.getLock(); + + if (imageTypeIsSupported) { + // Either not byRef or not yUp or not both + // System.err.println("ImageComponent2DRetained.setSubImage() : (imageTypeSupported ) --- (1)"); + if (image instanceof BufferedImage) { + copyImageLineByLine((BufferedImage)image, srcX, srcY, dstX, dstY, 0, width, height, imageData); + } + else { + copySupportedImageToImageData(image, srcX, srcY, dstX, dstY, 0, width, height, imageData); + } + } else { + // image type is unsupported, need to create a supported local copy. + // TODO : Should look into borrow code from JAI to convert to right format. + // System.err.println("ImageComponent2DRetained.setSubImage() : (imageTypeSupported == false) --- (2)"); + if (image instanceof BufferedImage) { + copyUnsupportedImageToImageData((BufferedImage)image, srcX, srcY, dstX, dstY, 0, width, height, imageData); + } + else { + copyUnsupportedImageToImageData(image, srcX, srcY, dstX, dstY, 0, width, height, imageData); + } + } + geomLock.unLock(); - byte[] sdata = imageYdown[0]; + if (source.isLive()) { - for (i = 0, j = 0; i < width * height; i++, j+= 4) { - System.arraycopy(sdata, j, ddata, j, 3); - ddata[j+3] =(byte)( ((int)sdata[j+3] & 0xff) * m + rndoff); - } - } - } - freeSurface(); - } - lastAlpha[screen] = alpha; - imageChanged &= ~(1 << screen); - } - } + // XXXX: check whether this is needed + freeSurface(); + // send a SUBIMAGE_CHANGED message in order to + // notify all the users of the change - int getEffectiveBytesPerPixel() { - if (byReference) { - if (usedByTexture || !usedByRaster) - return bytesPerYupPixelStored; - else - return bytesPerYdownPixelStored; - } - else { - return bytesPerPixelIfStored; - } - } + ImageComponentUpdateInfo info; + info = new ImageComponentUpdateInfo(); + info.x = dstX; + info.y = dstY; + info.z = 0; + info.width = width; + info.height = height; - int getEffectiveFormat() { - if (byReference) { - if (usedByTexture || !usedByRaster) - return storedYupFormat; - else - return storedYdownFormat; - } - else { - return internalFormat; - } - } + sendMessage(SUBIMAGE_CHANGED, info); + } + } /** - * retrieve image data from read buffer to ImageComponent's - * internal representation - */ - final void retrieveImage(byte[] buf, int wRead, int hRead) { - retrieveImage(buf, 0, 0, wRead, hRead); + * Retrieves a copy of the image in this ImageComponent2D object. + * @return a new RenderedImage object created from the image in this + * ImageComponent2D object + */ + RenderedImage getImage() { + + if (isByReference()) { + return (RenderedImage) getRefImage(0); + } + + if(imageData != null) { + return imageData.createBufferedImage(0); + } + + return null; } - /** - * retrieve a subimage data from read buffer to ImageComponent's - * internal representation - */ - final void retrieveImage(byte[] buf, int xRead, int yRead, int - wRead, int hRead) { - - int srcOffset, dstOffset, h,w,i,j; - int dstWidth; - - byte[] bdata; - - - // If byReference, then copy to the reference image immediately after - // readRaster or offscreenbuffer - - // In the by reference case, they should have set and image, before - // calling readRaster, so there should be a valid imageYup or imageYdown - // as used by texture or raster - - // Note the format of the glReadPixels is based on storedFormat - // so, we can do a direct copy - - int bpp = getEffectiveBytesPerPixel(); - int format = getEffectiveFormat(); - - if (!byReference) { - - dstWidth = width * bytesPerPixelIfStored; - if ((usedByTexture || !usedByRaster)&& (imageYup == null)) { - imageYup = new byte[height * dstWidth]; - bytesPerYupPixelStored = bytesPerPixelIfStored; - storedYupFormat = internalFormat; - imageYupAllocated = true; - } - if (usedByRaster && imageYdown[0] == null) { - imageYdown[0] = new byte[height * dstWidth]; - bytesPerYdownPixelStored = bytesPerPixelIfStored; - storedYdownFormat = internalFormat; - imageYdownAllocated = true; - } - } - - - int srcWidth = wRead * bpp; - int srcLineBytes = width * bpp; - - /* - System.out.println("bytesPerYdownPixelStored = "+bytesPerYdownPixelStored+" bpp = "+bpp); - System.out.println("storedYdownFormat = "+storedYdownFormat+" format = "+format); - System.out.println("bytesPerPixelIfStored = "+bytesPerPixelIfStored+" internalformat = "+internalFormat); - System.out.println("imageYup = "+imageYup+" imageYdown = "+imageYdown[0]); - System.out.println("===> usedByRaster = "+usedByRaster); - */ - - // array copy by scanline - - //position of a raster specifies the upper-left corner - // copy yUp -> yDown - imageDirty [0] = true; - - if (usedByRaster) { - dstWidth = width * bytesPerYdownPixelStored; - srcOffset = (yRead * srcLineBytes) + (xRead * bpp); - - dstOffset = ((height - yRead - 1)) * dstWidth + - (xRead * bytesPerYdownPixelStored); - // If by Reference and a copy has not been made ... - if (byReference && storedYdownFormat != internalFormat) { - bdata =((DataBufferByte) ((BufferedImage)bImage[0]).getRaster().getDataBuffer()).getData(); - imageDirty [0] = false; - } - else { - bdata = imageYdown[0]; - } - if (storedYdownFormat == format) { - for (h = 0; h < hRead; h++, - srcOffset += srcLineBytes, dstOffset -= dstWidth) { - System.arraycopy(buf, srcOffset, bdata, dstOffset, srcWidth); - } - } - else { // Would be one of the stored formats to RGBA - // Convert from one of the byRef formats to RGBA - switch(format) { - case BYTE_ABGR: - for (h = 0; h < hRead; h++, - srcOffset += srcLineBytes, dstOffset -= dstWidth) { - int offset = dstOffset; - for (w = 0; w < srcWidth; w +=bpp) { - bdata[offset++] = buf[srcOffset+w+3]; - bdata[offset++] = buf[srcOffset+w+2]; - bdata[offset++] = buf[srcOffset+w+1]; - bdata[offset++] = buf[srcOffset+w]; - - } - } - break; - case BYTE_BGR: - - for (h = 0; h < hRead; h++, - srcOffset += srcLineBytes, dstOffset -= dstWidth) { - int offset = dstOffset; - for (w = 0; w < srcWidth; w +=bpp) { - bdata[offset++] = buf[srcOffset+w+2]; - bdata[offset++] = buf[srcOffset+w+1]; - bdata[offset++] = buf[srcOffset+w]; - bdata[offset++] = (byte)0xff; - - } - } - break; - - } - } - } - - if (usedByTexture || !usedByRaster) { - imageYupCacheDirty = true; - dstWidth = width * bytesPerYupPixelStored; - srcOffset = (yRead * srcLineBytes) + (xRead * bpp); + * Retrieves the reference of the nio image in this ImageComponent2D object. + */ + NioImageBuffer getNioImage() { - // If by Reference and a copy has not been made ... - if (byReference && storedYupFormat != internalFormat) { - bdata =((DataBufferByte) ((BufferedImage)bImage[0]).getRaster().getDataBuffer()).getData(); - imageDirty [0] = false; - } - else { - bdata = imageYup; - } - // If used by texture, then storedYupFormat is always equal to format - if (storedYupFormat == format) { - for (dstOffset = srcOffset, - h = 0; h < hRead; h++, - srcOffset += srcLineBytes, dstOffset += dstWidth) { - System.arraycopy(buf, srcOffset, bdata, dstOffset, srcWidth); - } - } - } - // If its by reference and a copy has been made, make the user's copy - // up-to-date - - if (byReference && imageDirty[0]) { - imageDirty [0] = false; - if (usedByTexture || !usedByRaster) { - copyBufferedImageWithFormatConversion(true, 0); - } - else { - copyBufferedImageWithFormatConversion(false, 0); - } - } - imageChanged = 0xffff; - lastAlpha[0] = 1.0f; + if (getImageClass() != ImageComponent.ImageClass.NIO_IMAGE_BUFFER) { + throw new IllegalStateException(J3dI18N.getString("ImageComponent2D9")); + } + + assert (byReference == true); + + return (NioImageBuffer) getRefImage(0); } /** @@ -1265,29 +270,41 @@ class ImageComponent2DRetained extends ImageComponentRetained { int x, int y, int width, int height) { geomLock.getLock(); - // call the user supplied updateData method to update the data updater.updateData((ImageComponent2D)source, x, y, width, height); - // update the internal copy of the image data if a copy has been - // made - if (imageYupAllocated) { - copyImage(bImage[0], (x + bImage[0].getMinX()), - (y + bImage[0].getMinY()), imageYup, x, y, - true, 0, width, height, storedYupFormat, - bytesPerYupPixelStored); - } - - - if (imageYdownAllocated) { - copyImage(bImage[0], (x + bImage[0].getMinX()), - (y + bImage[0].getMinY()), imageYdown[0], x, y, - false, 0, width, height, storedYdownFormat, - bytesPerYdownPixelStored); - } - - imageDirty[0] = true; - + Object refImage = getRefImage(0); + assert (refImage != null); + assert (imageData != null); + + // Check is data copied internally. + if(!imageData.isDataByRef()) { + // update the internal copy of the image data if a copy has been + // made + if (imageTypeIsSupported) { + assert !(refImage instanceof NioImageBuffer); + + if (refImage instanceof BufferedImage) { + copyImageLineByLine((BufferedImage)refImage, x, y, x, y, 0, width, height, imageData); + } else { + RenderedImage ri = (RenderedImage)refImage; + copySupportedImageToImageData(ri, (x + ri.getMinX()), (y + ri.getMinY()), x, y, 0, width, height, imageData); + } + } else { + // image type is unsupported, need to create a supported local copy. + // TODO : Should look into borrow code from JAI to convert to right format. + if (refImage instanceof BufferedImage) { + copyUnsupportedImageToImageData((BufferedImage)refImage, x, y, x, y, 0, width, height, imageData); + } else if (refImage instanceof RenderedImage) { + RenderedImage ri = (RenderedImage)refImage; + copyUnsupportedImageToImageData(ri, (x + ri.getMinX()), (y + ri.getMinY()), x, y, 0, width, height, imageData); + } else if (refImage instanceof NioImageBuffer) { + copyUnsupportedNioImageToImageData((NioImageBuffer)refImage, x, y, x, y, width, height, imageData); + } else { + assert false; + } + } + } geomLock.unLock(); @@ -1301,7 +318,7 @@ class ImageComponent2DRetained extends ImageComponentRetained { ImageComponentUpdateInfo info; - info = VirtualUniverse.mc.getFreeImageUpdateInfo(); + info = new ImageComponentUpdateInfo(); info.x = x; info.y = y; info.z = 0; @@ -1311,74 +328,58 @@ class ImageComponent2DRetained extends ImageComponentRetained { sendMessage(SUBIMAGE_CHANGED, info); } } + + ImageComponentRetained createNextLevelMipMapImage() { + + int xScale, yScale, newWidth, newHeight; + + if (width > 1) { + newWidth = width >> 1; + xScale = 2; + } else { + newWidth = 1; + xScale = 1; + } + if (height > 1) { + newHeight = height >> 1; + yScale = 2; + } else { + newHeight = 1; + yScale = 1; + } + + ImageComponent2DRetained newImage = new ImageComponent2DRetained(); + newImage.processParams(getFormat(), newWidth, newHeight, 1); + newImage.setImageFormatType(getImageFormatType()); + newImage.setUnitsPerPixel(getUnitsPerPixel()); + newImage.imageData = newImage.createRenderedImageDataObject(null); + + newImage.scaleImage(xScale, yScale, 0, this); + + return newImage; + } - void setSubImage(RenderedImage image, int width, int height, - int srcX, int srcY, int dstX, int dstY) { - - geomLock.getLock(); - - if (imageYupAllocated) { - copyImage(image, srcX, srcY, imageYup, dstX, dstY, - true, 0, width, height, storedYupFormat, - bytesPerYupPixelStored); - } - - if (imageYdownAllocated) { - copyImage(image, srcX, srcY, imageYdown[0], - dstX, dstY, false, 0, width, height, - storedYdownFormat, bytesPerYdownPixelStored); + void clearLive(int refCount) { + super.clearLive(refCount); + if (this.refCount <= 0) { + freeSurface(); } - - imageDirty[0] = true; - - geomLock.unLock(); - - - if (source.isLive()) { - - // XXXX: check whether this is needed - freeSurface(); - - // send a SUBIMAGE_CHANGED message in order to - // notify all the users of the change - - ImageComponentUpdateInfo info; - - info = VirtualUniverse.mc.getFreeImageUpdateInfo(); - info.x = dstX; - info.y = dstY; - info.z = 0; - info.width = width; - info.height = height; - - sendMessage(SUBIMAGE_CHANGED, info); - } } - synchronized void updateMirrorObject(int component, Object value) { - - super.updateMirrorObject(component, value); - - if (detailTexture != null) { - if (((component & IMAGE_CHANGED) != 0) || - ((component & SUBIMAGE_CHANGED) != 0)) { - - // notify detailTexture of image change - - detailTexture.notifyImageComponentImageChanged(this, value); - } + void freeSurface() { + if (VirtualUniverse.mc.isD3D()) { + Pipeline.getPipeline().freeD3DSurface(this, hashId); } } + // TODO KCR ISSUE 121 : REPLACE THIS WITH A WEAK REFERENCE OR OTHER SCHEME + // Issue 121 : Stop using finalize() to clean up state + // Use similar approach as in handling ogl Texture resource cleanup. +// protected void finalize() { +// System.err.println("finalize: " + this); +//// // For Pure immediate mode, there is no clearLive so +//// // surface will free when JVM do GC +//// freeSurface(); +// } - synchronized void setDetailTexture(DetailTextureImage tex) { - detailTexture = tex; - } - - synchronized DetailTextureImage getDetailTexture() { - if (detailTexture == null) { - detailTexture = new DetailTextureImage(this); - } - return detailTexture; - } } diff --git a/src/classes/share/javax/media/j3d/ImageComponent3D.java b/src/classes/share/javax/media/j3d/ImageComponent3D.java index 9127277..6c0238c 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent3D.java +++ b/src/classes/share/javax/media/j3d/ImageComponent3D.java @@ -41,6 +41,7 @@ import java.awt.image.RenderedImage; * ic.set(0, ri);
    * * + * */ public class ImageComponent3D extends ImageComponent { @@ -53,6 +54,7 @@ public class ImageComponent3D extends ImageComponent { * all other parameters. The default values are as follows: *

      * array of images : null
      + * imageClass : ImageClass.BUFFERED_IMAGE
      *
    * * @param format the image component format, one of: FORMAT_RGB, @@ -71,25 +73,26 @@ public class ImageComponent3D extends ImageComponent { int depth) { ((ImageComponent3DRetained)this.retained).processParams(format, width, height, depth); - ((ImageComponent3DRetained)this.retained).setDepth(depth); } /** * Constructs a 3D image component object using the specified format, * and the BufferedImage array. + * The image class is set to ImageClass.BUFFERED_IMAGE. * Default values are used for all other parameters. + * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA etc. * @param images an array of BufferedImage objects. The * first image in the array determines the width and height of this * ImageComponent3D. + * * @exception IllegalArgumentException if format is invalid, or if * the width or height of the first image are not positive. */ public ImageComponent3D(int format, BufferedImage[] images) { ((ImageComponent3DRetained)this.retained).processParams(format, images[0].getWidth(null), images[0].getHeight(null), images.length); - ((ImageComponent3DRetained)this.retained).setDepth(images.length); for (int i=0; inot an + * instance of BufferedImage. In all other cases, the image class is set to + * ImageClass.BUFFERED_IMAGE. + * * @param format the image component format, one of: FORMAT_RGB, * FORMAT_RGBA etc. * @param images an array of RenderedImage objects. The @@ -216,19 +226,67 @@ public class ImageComponent3D extends ImageComponent { boolean byReference, boolean yUp) { - ((ImageComponentRetained)this.retained).setByReference(byReference); ((ImageComponentRetained)this.retained).setYUp(yUp); - ((ImageComponent3DRetained)this.retained).processParams(format, images[0].getWidth(), images[0].getHeight(), images.length); - ((ImageComponent3DRetained)this.retained).setDepth(images.length); + ((ImageComponent3DRetained)this.retained).processParams(format, + images[0].getWidth(), images[0].getHeight(), images.length); + for (int i=0; i + * The image class is set to ImageClass.BUFFERED_IMAGE. * * @param images array of BufferedImage objects containing the image. - * The format and size must be the same as the current format in the - * image component. + * The size (width and height) of each image must be the same as the + * size of the image component, and the length of the images array + * must equal the depth of the image component. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalArgumentException if the length of the images array is + * not equal to the depth of this ImageComponent object. + * + * @exception IllegalArgumentException if the width and height of each + * image in the images array is not equal to the width and height of this + * ImageComponent object. */ public void set(BufferedImage[] images) { checkForLiveOrCompiled(); @@ -275,14 +342,27 @@ public class ImageComponent3D extends ImageComponent { * then a shallow copy of the array of references to the * RenderedImage objects is made, but the RenderedImage * data is not necessarily copied. + *

    + * The image class is set to ImageClass.RENDERED_IMAGE if the data access + * mode is by-reference and any of the specified RenderedImages + * is not an instance of BufferedImage. In all other cases, + * the image class is set to ImageClass.BUFFERED_IMAGE. * * @param images array of RenderedImage objects containing the image. - * The format and size must be the same as the current format in the - * image component. + * The size (width and height) of each image must be the same as the + * size of the image component, and the length of the images array + * must equal the depth of the image component. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalArgumentException if the length of the images array is + * not equal to the depth of this ImageComponent object. + * + * @exception IllegalArgumentException if the width and height of each + * image in the images array is not equal to the width and height of this + * ImageComponent object. + * * @since Java 3D 1.2 */ public void set(RenderedImage[] images) { @@ -297,6 +377,55 @@ public class ImageComponent3D extends ImageComponent { } } + /** + * Sets the array of images in this image component to the + * specified array of NioImageBuffer objects. If the data access + * mode is not by-reference, then the NioImageBuffer data is copied + * into this object. If the data access mode is by-reference, + * then a shallow copy of the array of references to the + * NioImageBuffer objects is made, but the NioImageBuffer + * data is not necessarily copied. + *

    + * The image class is set to ImageClass.NIO_IMAGE_BUFFER. + * + * @param images array of NioImageBuffer objects containing the image. + * The size (width and height) of each image must be the same as the + * size of the image component, and the length of the images array + * must equal the depth of the image component. + * + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalStateException if this ImageComponent object + * is not yUp. + * + * @exception IllegalArgumentException if the length of the images array is + * not equal to the depth of this ImageComponent object. + * + * @exception IllegalArgumentException if the width and height of each + * image in the images array is not equal to the width and height of this + * ImageComponent object. + * + * @exception UnsupportedOperationException this method is not supported + * for Java 3D 1.5. + * + * @since Java 3D 1.5 + */ + public void set(NioImageBuffer[] images) { + + throw new UnsupportedOperationException(); + /* + checkForLiveOrCompiled(); + int depth = ((ImageComponent3DRetained)this.retained).getDepth(); + + if (depth != images.length) + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent3D1")); + for (int i=0; iBY_REFERENCE. + * * @exception IllegalArgumentException if width or * height of * the subregion exceeds the dimension of the image in this object. + * * @exception IllegalArgumentException if dstX < 0, or * (dstX + width) > width of this object, or * dstY < 0, or * (dstY + height) > height of this object. + * * @exception IllegalArgumentException if srcX < 0, or * (srcX + width) > width of the RenderedImage * object containing the subimage, or @@ -501,6 +746,12 @@ public class ImageComponent3D extends ImageComponent { * (srcY + height) > height of the * RenderedImage object containing the subimage. * + * @exception IllegalArgumentException if the specified RenderedImage + * is not compatible with the existing RenderedImage. + * + * @exception IllegalStateException if the image class is not one of: + * ImageClass.BUFFERED_IMAGE or ImageClass.RENDERED_IMAGE. + * * @since Java 3D 1.3 */ public void setSubImage(int index, RenderedImage image, @@ -550,8 +801,8 @@ public class ImageComponent3D extends ImageComponent { *

    * @param updater object whose updateData callback method will be * called to update the data referenced by this ImageComponent3D object. - * @param index index of the image to be modified. The index must - * not exceed the depth of this object. + * @param index index of the image to be modified. + * The index must be less than the depth of this ImageComponent3D object. * @param x starting X offset of the subregion. * @param y starting Y offset of the subregion. * @param width width of the subregion. @@ -617,7 +868,7 @@ public class ImageComponent3D extends ImageComponent { public NodeComponent cloneNodeComponent() { ImageComponent3DRetained rt = (ImageComponent3DRetained) retained; - ImageComponent3D img = new ImageComponent3D(rt.format, + ImageComponent3D img = new ImageComponent3D(rt.getFormat(), rt.width, rt.height, rt.depth); @@ -656,7 +907,7 @@ public class ImageComponent3D extends ImageComponent { void duplicateAttributes(NodeComponent originalNodeComponent, boolean forceDuplicate) { super.duplicateAttributes(originalNodeComponent, forceDuplicate); - + // TODO : Handle NioImageBuffer if its supported. RenderedImage imgs[] = ((ImageComponent3DRetained) originalNodeComponent.retained).getImage(); diff --git a/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java b/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java index 21813f8..91947bb 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java @@ -20,7 +20,6 @@ import java.awt.image.*; */ class ImageComponent3DRetained extends ImageComponentRetained { - int depth; // Depth of 3D image void setDepth(int depth) { this.depth = depth; @@ -30,7 +29,7 @@ class ImageComponent3DRetained extends ImageComponentRetained { * Retrieves the depth of this 3D image component object. * @return the format of this 3D image component object */ - final int getDepth() { + int getDepth() { return depth; } @@ -43,19 +42,135 @@ class ImageComponent3DRetained extends ImageComponentRetained { * ImageComponent3D object. The index must not exceed the depth of this * ImageComponent3D object. */ - final void set(int index, BufferedImage image) { - if (imageYup == null) - imageYup = new byte[height * width * depth * bytesPerPixelIfStored]; - imageDirty[index] = true; - storedYupFormat = internalFormat; - bytesPerYupPixelStored = bytesPerPixelIfStored; - copyImage(image, imageYup, true, index, storedYupFormat, - bytesPerYupPixelStored); - if (byReference) - bImage[index] = image; - } + void set(int index, BufferedImage image) { + + geomLock.getLock(); + + if(byReference) { + setRefImage(image,0); + } - final void set(int index, RenderedImage image) { + if(imageData == null) { + // Only do this once, on the first image + // Reset this flag to true, incase it was set to false due to + // the previous image type. + abgrSupported = true; + imageTypeIsSupported = isImageTypeSupported(image); + imageData = createRenderedImageDataObject(null); + } + else { + if(getImageType() != evaluateImageType(image)) { + // TODO need to throw illegal state exception + } + } + + if (imageTypeIsSupported) { + copySupportedImageToImageData(image, index, imageData); + } else { + // image type is unsupported, need to create a supported local copy. + // TODO : borrow code from JAI to convert to right format. + copyUnsupportedImageToImageData(image, index, imageData); + + } + + geomLock.unLock(); + + if (source.isLive()) { + // freeSurface(); + + // send a IMAGE_CHANGED message in order to + // notify all the users of the change + sendMessage(IMAGE_CHANGED, null); + } + } + + /** + * Copies the specified BufferedImage to this 3D image component + * object at the specified index. + * @param index the image index + * @param images BufferedImage object containing the image. + * The format and size must be the same as the current format in this + * ImageComponent3D object. The index must not exceed the depth of this + * ImageComponent3D object. + * + void set(int index, NioImageBuffer nioImage) { + + int width = nioImage.getWidth(); + int height = nioImage.getHeight(); + + if (!byReference) { + throw new IllegalArgumentException(J3dI18N.getString("Need_New_Message_XXXXXImageComponent2D7")); + } + if (!yUp) { + throw new IllegalArgumentException(J3dI18N.getString("Need_New_Message_XXXXXImageComponent2D8")); + } + + if (width != this.width) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent3D2")); + } + if (height != this.height) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent3D4")); + } + + geomLock.getLock(); + + setImageClass(nioImage); + + // This is a byRef image. + setRefImage(nioImage,0); + + if(imageData == null) { + // Only do this once, on the first image + // Reset this flag to true, incase it was set to false due to + // the previous image type. + abgrSupported = true; + + imageTypeIsSupported = isImageTypeSupported(nioImage); + + + // TODO : Need to handle null .... + imageData = createNioImageBufferDataObject(null); + } + else { + + //if(getImageType() != evaluateImageType(image)) { + // TODO need to throw illegal state exception + //} + + } + + if (imageTypeIsSupported) { + // TODO : Need to handle this ..... case .... + // copySupportedImageToImageData(image, index, imageData); + } else { + // System.err.println("Image format is unsupported -- illogical case"); + throw new AssertionError(); + } + + geomLock.unLock(); + + if (source.isLive()) { + // freeSurface(); + + // send a IMAGE_CHANGED message in order to + // notify all the users of the change + sendMessage(IMAGE_CHANGED, null); + } + } + */ + + void set(int index, RenderedImage image) { + + int width = image.getWidth(); + int height = image.getHeight(); + + if (width != this.width) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent3D2")); + } + if (height != this.height) { + throw new IllegalArgumentException(J3dI18N.getString("ImageComponent3D4")); + } + if (image instanceof BufferedImage) { set(index, ((BufferedImage)image)); } @@ -76,20 +191,21 @@ class ImageComponent3DRetained extends ImageComponentRetained { * @return a new array of new BufferedImage objects created from the * images in this ImageComponent3D object */ - final RenderedImage[] getRenderedImage() { + RenderedImage[] getRenderedImage() { int i; - RenderedImage bi[] = new RenderedImage[bImage.length]; + RenderedImage bi[] = new RenderedImage[depth]; + if (!byReference) { for (i=0; i 1) { + newWidth = width >> 1; + xScale = 2; + } else { + newWidth = 1; + xScale = 1; + } + if (height > 1) { + newHeight = height >> 1; + yScale = 2; + } else { + newHeight = 1; + yScale = 1; + } + + ImageComponent3DRetained newImage = new ImageComponent3DRetained(); + newImage.processParams(getFormat(), newWidth, newHeight, depth); + newImage.imageData = newImage.createRenderedImageDataObject(null); + + for (int i = 0; i < depth; i++) { + newImage.scaleImage(xScale, yScale, depth, this); + } + + return newImage; + + } } diff --git a/src/classes/share/javax/media/j3d/ImageComponentRetained.java b/src/classes/share/javax/media/j3d/ImageComponentRetained.java index c62ca24..2279b89 100644 --- a/src/classes/share/javax/media/j3d/ImageComponentRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponentRetained.java @@ -12,10 +12,17 @@ package javax.media.j3d; +import java.nio.Buffer; import java.util.*; import java.awt.image.*; import java.awt.color.ColorSpace; -import java.awt.Transparency; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.RenderedImage; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; + /** * Abstract class that is used to define 2D or 3D ImageComponent classes @@ -25,1535 +32,2702 @@ import java.awt.Transparency; */ abstract class ImageComponentRetained extends NodeComponentRetained { - int format; // PixelArray format (RGB, RGBA, ALPHA, etc.) + + // change flag + static final int IMAGE_CHANGED = 0x01; + static final int SUBIMAGE_CHANGED = 0x02; + + static final int TYPE_BYTE_BGR = 0x1; + static final int TYPE_BYTE_RGB = 0x2; + static final int TYPE_BYTE_ABGR = 0x4; + static final int TYPE_BYTE_RGBA = 0x8; + static final int TYPE_BYTE_LA = 0x10; + static final int TYPE_BYTE_GRAY = 0x20; + static final int TYPE_USHORT_GRAY = 0x40; + static final int TYPE_INT_BGR = 0x80; + static final int TYPE_INT_RGB = 0x100; + static final int TYPE_INT_ARGB = 0x200; + + enum ImageFormatType { + TYPE_UNKNOWN, + TYPE_BYTE_BGR, + TYPE_BYTE_RGB, + TYPE_BYTE_ABGR, + TYPE_BYTE_RGBA, + TYPE_BYTE_LA, + TYPE_BYTE_GRAY, + TYPE_USHORT_GRAY, + TYPE_INT_BGR, + TYPE_INT_RGB, + TYPE_INT_ARGB + } + + static final int IMAGE_DATA_TYPE_BYTE_ARRAY = 0x1000; + static final int IMAGE_DATA_TYPE_INT_ARRAY = 0x2000; + static final int IMAGE_DATA_TYPE_BYTE_BUFFER = 0x4000; + static final int IMAGE_DATA_TYPE_INT_BUFFER = 0x8000; + + enum ImageDataType { + TYPE_NULL, + TYPE_BYTE_ARRAY, + TYPE_INT_ARRAY, + TYPE_BYTE_BUFFER, + TYPE_INT_BUFFER + } + + private int apiFormat; // The format set by user. int width; // Width of PixelArray int height; // Height of PixelArray - byte[][] imageYdown = new byte[1][]; // 2D array of pixel values in - // one of various formats - Y downwards - byte[] imageYup; // 2D or 3D array of pixel values in - // one of various formats - Y upwards - - int bytesPerPixel; // computed from input format - boolean usedByRaster = false; // used by a raster object? - boolean usedByTexture = false; // used by a texture object? - - boolean byReference = false; // Is the imageComponent by reference - boolean yUp = false; - - // array of Buffered image - // This will store the refImage array, if the imagecomponent - // is by reference - RenderedImage[] bImage; - boolean[] imageDirty; // array of image dirty flag - - boolean noAlpha = false; - - // Format of the Yup and Ydown image - // in the case of "by Copy" it is RGBA - // In the case of "by ref" it may be one of the original - // formats supported by OpenGL - /* - int storedFormat; - */ - int bytesPerPixelIfStored; // Number of bytes if a copy is made - int storedYupFormat; - int storedYdownFormat; - - int bytesPerYupPixelStored; - int bytesPerYdownPixelStored; + int depth; // Depth of PixelArray + boolean byReference = false; // Is the imageComponent by reference + boolean yUp = false; + boolean imageTypeIsSupported; + boolean abgrSupported = true; + boolean npotSupported = true; + private int unitsPerPixel; + private int numberOfComponents; - int internalFormat; // Used when a copy is made, RGBA, LA, L - boolean imageYupAllocated = false; - boolean imageYdownAllocated = false; - - // If cache is dirty (clearLive, setLive has occureed), then - // extension based cache needs to be re-evaluated - boolean imageYupCacheDirty = false; - boolean imageYdownCacheDirty = false; + // Note : This is unuse for NioImageBuffer. + // The image type of the input image. Using the constant in BufferedImage + private int imageType; - - static final int BYTE_RGBA = 0x1; - static final int BYTE_ABGR = 0x2; - static final int BYTE_GRAY = 0x4; - static final int USHORT_GRAY = 0x8; - static final int BYTE_LA = 0x10; - static final int BYTE_BGR = 0x20; - static final int BYTE_RGB = 0x40; - - int imageYupClass = 0; - int imageYdownClass = 0; - static final int BUFFERED_IMAGE = 0x1; - static final int RENDERED_IMAGE = 0x2; + private ImageFormatType imageFormatType = ImageFormatType.TYPE_UNKNOWN; + ImageData imageData; + private ImageComponent.ImageClass imageClass = ImageComponent.ImageClass.BUFFERED_IMAGE; - // change flag - static final int IMAGE_CHANGED = 0x01; - static final int SUBIMAGE_CHANGED = 0x02; + // To support Non power of 2 (NPOT) image + // if enforceNonPowerOfTwoSupport is true (for examples Raster and Background) + // and imageData is a non power of 2 image + // and graphics driver doesn't support NPOT extension. + private ImageData imageDataPowerOfTwo; + private AffineTransformOp powerOfTwoATOp; + private boolean enforceNonPowerOfTwoSupport = false; + private boolean usedByOffScreenCanvas = false; + + // This will store the referenced Images for reference case. + // private RenderedImage refImage[] = null; + private Object refImage[] = null; // Lock used in the "by ref case" GeometryLock geomLock = new GeometryLock(); - - int minTileX = 0; - int minTileY = 0; - int minTileZ = 0; - + int tilew = 0; int tileh = 0; - int tiled = 0; - int numXTiles = 0; int numYTiles = 0; - int numZTiles = 0; - - int tileGridXOffset = 0; - int tileGridYOffset = 0; - - - int minX = 0; - int minY = 0; // lists of Node Components that are referencing this ImageComponent // object. This list is used to notify the referencing node components // of any changes of this ImageComponent. - ArrayList userList = new ArrayList(); - + + abstract ImageComponentRetained createNextLevelMipMapImage(); + /** * Retrieves the width of this image component object. * @return the width of this image component object - */ - final int getWidth() { + */ + int getWidth() { return width; } - + /** * Retrieves the height of this image component object. * @return the height of this image component object - */ - final int getHeight() { + */ + int getHeight() { return height; } - + /** - * Retrieves the format of this image component object. - * @return the format of this image component object - */ - final int getFormat() { - return format; + * Retrieves the apiFormat of this image component object. + * + * @return the apiFormat of this image component object + */ + int getFormat() { + return apiFormat; } - + + void setFormat(int format) { + this.apiFormat = format; + } + + void setByReference(boolean byReference) { + this.byReference = byReference; + } + + boolean isByReference() { + return byReference; + } + + void setYUp( boolean yUp) { + this.yUp = yUp; + } + + boolean isYUp() { + return yUp; + } + + int getUnitsPerPixel() { + return unitsPerPixel; + } + + void setUnitsPerPixel(int ipp) { + unitsPerPixel = ipp; + } + + ImageComponent.ImageClass getImageClass() { + return imageClass; + } + + void setImageClass(RenderedImage image) { + if(image instanceof BufferedImage) { + imageClass = ImageComponent.ImageClass.BUFFERED_IMAGE; + } else { + imageClass = ImageComponent.ImageClass.RENDERED_IMAGE; + } + } + + void setImageClass(NioImageBuffer image) { + imageClass = ImageComponent.ImageClass.NIO_IMAGE_BUFFER; + } + + void setEnforceNonPowerOfTwoSupport(boolean npot) { + this.enforceNonPowerOfTwoSupport = npot; + } + + void setUsedByOffScreen(boolean used) { + usedByOffScreenCanvas = used; + } + + boolean getUsedByOffScreen() { + return usedByOffScreenCanvas; + } + + int getNumberOfComponents() { + return numberOfComponents; + } + + void setNumberOfComponents(int numberOfComponents) { + this.numberOfComponents = numberOfComponents; + } + + int getImageDataTypeIntValue() { + int idtValue = -1; + switch(imageData.imageDataType) { + case TYPE_BYTE_ARRAY: + idtValue = IMAGE_DATA_TYPE_BYTE_ARRAY; + break; + case TYPE_INT_ARRAY: + idtValue = IMAGE_DATA_TYPE_INT_ARRAY; + break; + case TYPE_BYTE_BUFFER: + idtValue = IMAGE_DATA_TYPE_BYTE_BUFFER; + break; + case TYPE_INT_BUFFER: + idtValue = IMAGE_DATA_TYPE_INT_BUFFER; + break; + default : + assert false; + } + return idtValue; + + } + + int getImageFormatTypeIntValue(boolean powerOfTwoData) { + int iftValue = -1; + switch(imageFormatType) { + case TYPE_BYTE_BGR: + iftValue = TYPE_BYTE_BGR; + break; + case TYPE_BYTE_RGB: + iftValue = TYPE_BYTE_RGB; + break; + case TYPE_BYTE_ABGR: + iftValue = TYPE_BYTE_ABGR; + break; + case TYPE_BYTE_RGBA: + if((imageDataPowerOfTwo != null) && (powerOfTwoData)) { + iftValue = TYPE_BYTE_ABGR; + } + else { + iftValue = TYPE_BYTE_RGBA; + } + break; + case TYPE_BYTE_LA: + iftValue = TYPE_BYTE_LA; + break; + case TYPE_BYTE_GRAY: + iftValue = TYPE_BYTE_GRAY; + break; + case TYPE_USHORT_GRAY: + iftValue = TYPE_USHORT_GRAY; + break; + case TYPE_INT_BGR: + iftValue = TYPE_INT_BGR; + break; + case TYPE_INT_RGB: + iftValue = TYPE_INT_RGB; + break; + case TYPE_INT_ARGB: + iftValue = TYPE_INT_ARGB; + break; + default: + throw new AssertionError(); + } + return iftValue; + } + + // Note: This method for RenderedImage, can't be used by NioImageBuffer. + int getImageType() { + return imageType; + } + + void setImageFormatType(ImageFormatType ift) { + this.imageFormatType = ift; + } + + ImageFormatType getImageFormatType() { + return this.imageFormatType; + } + + void setRefImage(Object image, int index) { + this.refImage[index] = image; + } + + Object getRefImage(int index) { + return this.refImage[index]; + } + + ImageData getImageData(boolean npotSupportNeeded) { + if(npotSupportNeeded) { + assert enforceNonPowerOfTwoSupport; + if(imageDataPowerOfTwo != null) { + return imageDataPowerOfTwo; + } + } + return imageData; + } + + boolean isImageTypeSupported() { + return imageTypeIsSupported; + } + /** - * Check if ImageComponent parameters have valid values.. + * Check if ImageComponent parameters have valid values. */ - void processParams(int format, int width, int height, int depth) { - if (width < 1) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained0")); - + void processParams(int format, int width, int height, int depth) { + if (width < 1) + throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained0")); + if (height < 1) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained1")); - + throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained1")); + if (depth < 1) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained2")); - - if (format < 1 || format > ImageComponent.FORMAT_TOTAL) - throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained3")); - this.format = format; + throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained2")); + + // If the format is 8bit per component, we may send it down + // to OpenGL directly if its by ref case + switch (format) { + case ImageComponent.FORMAT_RGB:// same as ImageComponent.FORMAT_RGB8 + case ImageComponent.FORMAT_RGB4: // Need to be Deprecated + case ImageComponent.FORMAT_RGB5: // Need to be Deprecated + case ImageComponent.FORMAT_R3_G3_B2: // Need to be Deprecated + numberOfComponents = 3; + break; + case ImageComponent.FORMAT_RGBA:// same as ImageComponent.FORMAT_RGBA8 + case ImageComponent.FORMAT_RGB5_A1: // Need to be Deprecated + case ImageComponent.FORMAT_RGBA4: // Need to be Deprecated + numberOfComponents = 4; + break; + case ImageComponent.FORMAT_LUM4_ALPHA4: // Need to be Deprecated + case ImageComponent.FORMAT_LUM8_ALPHA8: + numberOfComponents = 2; + break; + case ImageComponent.FORMAT_CHANNEL8: + numberOfComponents = 1; + break; + default: + throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained3")); + } + + this.setFormat(format); this.width = width; this.height = height; - imageDirty = new boolean[depth]; - for (int i=0; i< depth; i++) - imageDirty[i] = false; - bImage = new RenderedImage[depth]; - - noAlpha = (format == ImageComponent.FORMAT_RGB || - format == ImageComponent.FORMAT_RGB4 || - format == ImageComponent.FORMAT_R3_G3_B2 || - format == ImageComponent.FORMAT_RGB5); - - // If the format is 8bit per component, we may send it down - // to OpenGL directly if its by ref case - switch (format) { - case ImageComponent.FORMAT_RGB:// same as ImageComponent.FORMAT_RGB8 - bytesPerPixel = 3; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_RGBA:// same as ImageComponent.FORMAT_RGBA8 - bytesPerPixel = 4; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_RGB5: - bytesPerPixel = 2; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_RGB5_A1: - bytesPerPixel = 2; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_RGB4: - bytesPerPixel = 2; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_RGBA4: - bytesPerPixel = 2; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_R3_G3_B2: - bytesPerPixel = 1; - bytesPerPixelIfStored = 4; - internalFormat = BYTE_RGBA; - break; - case ImageComponent.FORMAT_LUM4_ALPHA4: - bytesPerPixel = 1; - bytesPerPixelIfStored = 2; - internalFormat = BYTE_LA; - break; - case ImageComponent.FORMAT_LUM8_ALPHA8: - bytesPerPixel = 2; - bytesPerPixelIfStored = 2; - internalFormat = BYTE_LA; - break; - case ImageComponent.FORMAT_CHANNEL8: - bytesPerPixel = 1; - bytesPerPixelIfStored = 1; - internalFormat = BYTE_GRAY; - break; - default: - // ERROR + this.depth = depth; + refImage = new Object[depth]; + } + + int evaluateImageType(RenderedImage ri) { + int imageType = BufferedImage.TYPE_CUSTOM; + + if (ri instanceof BufferedImage) { + imageType = ((BufferedImage)ri).getType(); + + if(imageType != BufferedImage.TYPE_CUSTOM) { + return imageType; + } + } + + // System.err.println("This is a RenderedImage or BufferedImage with TYPE_CUSTOM. It imageType classification may not be correct."); + + ColorModel cm = ri.getColorModel(); + ColorSpace cs = cm.getColorSpace(); + SampleModel sm = ri.getSampleModel(); + + int csType = cs.getType(); + boolean isAlphaPre = cm.isAlphaPremultiplied(); + + + if (csType == ColorSpace.TYPE_GRAY && cm instanceof ComponentColorModel) { + if (sm.getDataType() == DataBuffer.TYPE_BYTE) { + imageType = BufferedImage.TYPE_BYTE_GRAY; + } else if (sm.getDataType() == DataBuffer.TYPE_USHORT) { + imageType = BufferedImage.TYPE_USHORT_GRAY; + } + } + + // RGB , only interested in BYTE ABGR and BGR for now + // all others will be copied to a buffered image + else if(csType == ColorSpace.TYPE_RGB) { + int comparedBit = 0; + int smDataType = sm.getDataType(); + if(smDataType == DataBuffer.TYPE_BYTE) { + comparedBit = 8; + } else if(smDataType == DataBuffer.TYPE_INT) { + comparedBit = 32; + } + + if(comparedBit != 0) { + int numBands = sm.getNumBands(); + if (cm instanceof ComponentColorModel && + sm instanceof PixelInterleavedSampleModel) { + PixelInterleavedSampleModel csm = + (PixelInterleavedSampleModel) sm; + int[] offs = csm.getBandOffsets(); + ComponentColorModel ccm = (ComponentColorModel)cm; + int[] nBits = ccm.getComponentSize(); + boolean isNBit = true; + for (int i=0; i < numBands; i++) { + if (nBits[i] != comparedBit) { + isNBit = false; + break; + } + } + + // Handle TYPE_BYTE + if( comparedBit == 8) { + if (isNBit && + offs[0] == numBands-1 && + offs[1] == numBands-2 && + offs[2] == numBands-3) { + if (numBands == 3) { + imageType = BufferedImage.TYPE_3BYTE_BGR; + } else if (offs[3] == 0) { + imageType = (isAlphaPre + ? BufferedImage.TYPE_4BYTE_ABGR_PRE + : BufferedImage.TYPE_4BYTE_ABGR); + } + } + } + //Handle TYPE_INT + else { + if (isNBit) { + if (numBands == 3) { + if(offs[0] == numBands-1 && + offs[1] == numBands-2 && + offs[2] == numBands-3) { + imageType = BufferedImage.TYPE_INT_BGR; + } else if(offs[0] == 0 && + offs[1] == 1 && + offs[2] == 2) { + imageType = BufferedImage.TYPE_INT_RGB; + } + } else if(offs[0] == 3 && + offs[1] == 0 && + offs[2] == 1 && + offs[3] == 2) { + imageType = (isAlphaPre + ? BufferedImage.TYPE_INT_ARGB_PRE + : BufferedImage.TYPE_INT_ARGB); + } + } + } + } + } } + + return imageType; } - - void setTextureRef() { - usedByTexture = true; + + // Assume ri's imageType is BufferedImage.TYPE_CUSTOM + boolean is3ByteRGB(RenderedImage ri) { + boolean value = false; + int i; + ColorModel cm = ri.getColorModel(); + ColorSpace cs = cm.getColorSpace(); + SampleModel sm = ri.getSampleModel(); + boolean isAlphaPre = cm.isAlphaPremultiplied(); + int csType = cs.getType(); + if ( csType == ColorSpace.TYPE_RGB) { + int numBands = sm.getNumBands(); + if ((numBands == 3) && (sm.getDataType() == DataBuffer.TYPE_BYTE)) { + if (cm instanceof ComponentColorModel && + sm instanceof PixelInterleavedSampleModel) { + PixelInterleavedSampleModel csm = + (PixelInterleavedSampleModel) sm; + int[] offs = csm.getBandOffsets(); + ComponentColorModel ccm = (ComponentColorModel)cm; + int[] nBits = ccm.getComponentSize(); + boolean is8Bit = true; + for (i=0; i < numBands; i++) { + if (nBits[i] != 8) { + is8Bit = false; + break; + } + } + if (is8Bit && + offs[0] == 0 && + offs[1] == 1 && + offs[2] == 2) { + value = true; + } + } + } + } + return value; } - - void setRasterRef() { - usedByRaster = true; + + // Assume ri's imageType is BufferedImage.TYPE_CUSTOM + boolean is4ByteRGBA(RenderedImage ri) { + boolean value = false; + int i; + ColorModel cm = ri.getColorModel(); + ColorSpace cs = cm.getColorSpace(); + SampleModel sm = ri.getSampleModel(); + boolean isAlphaPre = cm.isAlphaPremultiplied(); + int csType = cs.getType(); + if ( csType == ColorSpace.TYPE_RGB) { + int numBands = sm.getNumBands(); + if ((numBands == 4) && (sm.getDataType() == DataBuffer.TYPE_BYTE)) { + if (cm instanceof ComponentColorModel && + sm instanceof PixelInterleavedSampleModel) { + PixelInterleavedSampleModel csm = + (PixelInterleavedSampleModel) sm; + int[] offs = csm.getBandOffsets(); + ComponentColorModel ccm = (ComponentColorModel)cm; + int[] nBits = ccm.getComponentSize(); + boolean is8Bit = true; + for (i=0; i < numBands; i++) { + if (nBits[i] != 8) { + is8Bit = false; + break; + } + } + if (is8Bit && + offs[0] == 0 && + offs[1] == 1 && + offs[2] == 2 && + offs[3] == 3 && !isAlphaPre) { + value = true; + } + } + } + } + return value; } - - - boolean formatMatches(int format, RenderedImage ri) { - - // there is no RenderedImage format that matches BYTE_LA - if (format == BYTE_LA) { - return false; - } - - int riFormat = getImageType(ri); - - if ((format == BYTE_ABGR && riFormat == BufferedImage.TYPE_4BYTE_ABGR) - || (format == BYTE_BGR && riFormat == BufferedImage.TYPE_3BYTE_BGR) - || (format == BYTE_GRAY && riFormat == BufferedImage.TYPE_BYTE_GRAY) - || (format == USHORT_GRAY && riFormat == - BufferedImage.TYPE_USHORT_GRAY)) { - return true; - } - - if (riFormat == BufferedImage.TYPE_CUSTOM) { - if (is4ByteRGBAOr3ByteRGB(ri)) { - int numBands = ri.getSampleModel().getNumBands(); - if (numBands == 3 && format == BYTE_RGB) { - return true; - } else if (numBands == 4 && format == BYTE_RGBA) { - return true; - } - } - } - - return false; + + // Note: This method for RenderedImage, can't be used by NioImageBuffer. + /* Check if sub-image type matches image type */ + boolean isSubImageTypeEqual(RenderedImage ri) { + int subImageType = evaluateImageType(ri); + + // This test is likely too loose, but the specification isn't clear either. + // Assuming TYPE_CUSTOM of sub-image == the TYPE_CUSTOM of existing image. + if(imageType == subImageType) { + return true; + } else { + return false; + } + } - - /** - * copy complete region of a RenderedImage - */ - final void copyImage(RenderedImage ri, byte[] image, - boolean usedByTexture, int depth, - int imageFormat, int imageBytesPerPixel) { - - if (ri instanceof BufferedImage) { - copyImage((BufferedImage)ri, 0, 0, image, 0, 0, - usedByTexture, depth, width, height, - imageFormat, imageBytesPerPixel); - } else { - copyImage(ri, ri.getMinX(), ri.getMinY(), - image, 0, 0, usedByTexture, depth, width, height, - imageFormat, imageBytesPerPixel); - } + + // This method only support caller of offScreenBuffer and readRaster. + void createBlankImageData() { + + assert (imageData == null); + + switch(numberOfComponents) { + case 4: + imageType = BufferedImage.TYPE_INT_ARGB; + imageFormatType = ImageFormatType.TYPE_INT_ARGB; + unitsPerPixel = 1; + break; + + case 3: + imageType = BufferedImage.TYPE_INT_RGB; + imageFormatType = ImageFormatType.TYPE_INT_RGB; + unitsPerPixel = 1; + break; + default: + // Only valid for 3 and 4 channel case. ( Read back from framebuffer ) + assert false; + } + + imageTypeIsSupported = true; + imageData = createRenderedImageDataObject(null); + } - - - /** - * copy subregion of a RenderedImage - */ - final void copyImage(RenderedImage ri, int srcX, int srcY, - byte[] image, int dstX, int dstY, - boolean usedByTexture, int depth, - int copywidth, int copyheight, - int imageFormat, int imageBytesPerPixel) { - - if (ri instanceof BufferedImage) { - copyImage((BufferedImage)ri, srcX, srcY, image, dstX, dstY, - usedByTexture, depth, copywidth, copyheight, - imageFormat, imageBytesPerPixel); - return; - } - - - int w, h, i, j, m, n; - int dstBegin; - Object pixel = null; - java.awt.image.Raster ras; - int lineBytes = width * imageBytesPerPixel; // nbytes per line in - // dst image buffer - int sign; // -1 for going down - int dstLineBytes; // sign * lineBytes - int tileStart; // destination buffer offset - // at the next left most tile - - int offset; - - ColorModel cm = ri.getColorModel(); - - int xoff = ri.getTileGridXOffset(); // tile origin x offset - int yoff = ri.getTileGridYOffset(); // tile origin y offset - int minTileX = ri.getMinTileX(); // min tile x index - int minTileY = ri.getMinTileY(); // min tile y index - tilew = ri.getTileWidth(); // tile width in pixels - tileh = ri.getTileHeight(); // tile height in pixels - - - // determine the first tile of the image - - float mt; - - mt = (float)(srcX - xoff) / (float)tilew; - if (mt < 0) { - minTileX = (int)(mt - 1); - } else { - minTileX = (int)mt; - } - - mt = (float)(srcY - yoff) / (float)tileh; - if (mt < 0) { - minTileY = (int)(mt - 1); - } else { - minTileY = (int)mt; - } - - - // determine the pixel offset of the upper-left corner of the - // first tile - - int startXTile = minTileX * tilew + xoff; - int startYTile = minTileY * tileh + yoff; - - - // image dimension in the first tile - - int curw = (startXTile + tilew - srcX); - int curh = (startYTile + tileh - srcY); - - - // check if the to-be-copied region is less than the tile image - // if so, update the to-be-copied dimension of this tile - - if (curw > copywidth) { - curw = copywidth; - } - - if (curh > copyheight) { - curh = copyheight; - } - - - // save the to-be-copied width of the left most tile - - int startw = curw; - - - // temporary variable for dimension of the to-be-copied region - - int tmpw = copywidth; - int tmph = copyheight; - - - // offset of the first pixel of the tile to be copied; offset is + + // This method will set imageType, imageFormatType, and unitsPerPixel + // as it evaluates NioImageBuffer is supported. It will also reset + // abgrSupported. + boolean isImageTypeSupported(NioImageBuffer nioImgBuf) { + + boolean isSupported = true; + NioImageBuffer.ImageType nioImageType = nioImgBuf.getImageType(); + + switch(numberOfComponents) { + case 4: + if(nioImageType == NioImageBuffer.ImageType.TYPE_4BYTE_ABGR) { + // TODO : This approach will lead to a very slow path + // for unsupported case. + if(abgrSupported) { + imageFormatType = ImageFormatType.TYPE_BYTE_ABGR; + } else { + // Unsupported format on HW, switch to slow copy. + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + isSupported = false; + } + unitsPerPixel = 4; + } else if(nioImageType == NioImageBuffer.ImageType.TYPE_4BYTE_RGBA) { + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + unitsPerPixel = 4; + } else if(nioImageType == NioImageBuffer.ImageType.TYPE_INT_ARGB) { + imageFormatType = ImageFormatType.TYPE_INT_ARGB; + unitsPerPixel = 1; + } else { + throw new RuntimeException("Not yet implemented"); + } + break; + + case 3: + if(nioImageType == NioImageBuffer.ImageType.TYPE_3BYTE_BGR) { + imageFormatType = ImageFormatType.TYPE_BYTE_BGR; + unitsPerPixel = 3; + } else if(nioImageType == NioImageBuffer.ImageType.TYPE_3BYTE_RGB) { + imageFormatType = ImageFormatType.TYPE_BYTE_RGB; + unitsPerPixel = 3; + } else if(nioImageType == NioImageBuffer.ImageType.TYPE_INT_BGR) { + imageFormatType = ImageFormatType.TYPE_INT_BGR; + unitsPerPixel = 1; + } else if(nioImageType == NioImageBuffer.ImageType.TYPE_INT_RGB) { + imageFormatType = ImageFormatType.TYPE_INT_RGB; + unitsPerPixel = 1; + } else { + throw new RuntimeException("Not yet implemented"); + } + break; + + case 2: + throw new RuntimeException("Not yet implemented"); + case 1: + if(nioImageType == NioImageBuffer.ImageType.TYPE_BYTE_GRAY) { + imageFormatType = ImageFormatType.TYPE_BYTE_GRAY; + unitsPerPixel = 1; + } else { + throw new RuntimeException("Not yet implemented"); + } + break; + + default: + throw new AssertionError(); + } + + return isSupported; + } + + // This method will set imageType, imageFormatType, and unitsPerPixel + // as it evaluates RenderedImage is supported. It will also reset + // abgrSupported. + boolean isImageTypeSupported(RenderedImage ri) { + + boolean isSupported = true; + imageType = evaluateImageType(ri); + + switch(numberOfComponents) { + case 4: + if(imageType == BufferedImage.TYPE_4BYTE_ABGR) { + + // TODO : This approach will lead to a very slow path + // for unsupported case. + if(abgrSupported) { + imageFormatType = ImageFormatType.TYPE_BYTE_ABGR; + } else { + // Unsupported format on HW, switch to slow copy. + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + isSupported = false; + } + unitsPerPixel = 4; + } else if(imageType == BufferedImage.TYPE_INT_ARGB) { + imageFormatType = ImageFormatType.TYPE_INT_ARGB; + unitsPerPixel = 1; + } else if(is4ByteRGBA(ri)) { + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + unitsPerPixel = 4; + } else { + // System.err.println("Image format is unsupported --- Case 4"); + // Convert unsupported format to TYPE_BYTE_RGBA. + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + isSupported = false; + unitsPerPixel = 4; + } + break; + + case 3: + if(imageType == BufferedImage.TYPE_3BYTE_BGR) { + imageFormatType = ImageFormatType.TYPE_BYTE_BGR; + unitsPerPixel = 3; + } else if(imageType == BufferedImage.TYPE_INT_BGR) { + imageFormatType = ImageFormatType.TYPE_INT_BGR; + unitsPerPixel = 1; + } else if(imageType == BufferedImage.TYPE_INT_RGB) { + imageFormatType = ImageFormatType.TYPE_INT_RGB; + unitsPerPixel = 1; + } else if(is3ByteRGB(ri)) { + imageFormatType = ImageFormatType.TYPE_BYTE_RGB; + unitsPerPixel = 3; + } else { + // System.err.println("Image format is unsupported --- Case 3"); + // Convert unsupported format to TYPE_BYTE_RGB. + imageFormatType = ImageFormatType.TYPE_BYTE_RGB; + isSupported = false; + unitsPerPixel = 3; + } + break; + + case 2: + // System.err.println("Image format is unsupported --- Case 2"); + // Convert unsupported format to TYPE_BYTE_LA. + imageFormatType = ImageFormatType.TYPE_BYTE_LA; + isSupported = false; + unitsPerPixel = 2; + break; + + case 1: + if(imageType == BufferedImage.TYPE_BYTE_GRAY) { + imageFormatType = ImageFormatType.TYPE_BYTE_GRAY; + unitsPerPixel = 1; + } else { + // System.err.println("Image format is unsupported --- Case 1"); + // Convert unsupported format to TYPE_BYTE_GRAY. + imageFormatType = ImageFormatType.TYPE_BYTE_GRAY; + isSupported = false; + unitsPerPixel = 1; + } + break; + + default: + throw new AssertionError(); + } + + return isSupported; + } + + /* + * This method assume that the following members have been initialized : + * width, height, depth, imageFormatType, and unitsPerPixel. + */ + ImageData createNioImageBufferDataObject(NioImageBuffer nioImageBuffer) { + + switch(imageFormatType) { + case TYPE_BYTE_GRAY: + case TYPE_BYTE_LA: + case TYPE_BYTE_RGB: + case TYPE_BYTE_BGR: + case TYPE_BYTE_RGBA: + case TYPE_BYTE_ABGR: + if(nioImageBuffer != null) { + return new ImageData(ImageDataType.TYPE_BYTE_BUFFER, + width * height * depth * unitsPerPixel, + width, height, nioImageBuffer); + } else { + // This is needed only if abgr is unsupported. + return new ImageData(ImageDataType.TYPE_BYTE_BUFFER, + width * height * depth * unitsPerPixel, + width, height); + } + case TYPE_INT_RGB: + case TYPE_INT_BGR: + case TYPE_INT_ARGB: + return new ImageData(ImageDataType.TYPE_INT_BUFFER, + width * height * depth * unitsPerPixel, + width, height, nioImageBuffer); + default: + throw new AssertionError(); + } + } + + /* + * This method assume that the following members have been initialized : + * depth, imageType, imageFormatType, and unitsPerPixel. + */ + ImageData createRenderedImageDataObject(RenderedImage byRefImage, int dataWidth, int dataHeight) { + switch(imageFormatType) { + case TYPE_BYTE_GRAY: + case TYPE_BYTE_LA: + case TYPE_BYTE_RGB: + case TYPE_BYTE_BGR: + case TYPE_BYTE_RGBA: + case TYPE_BYTE_ABGR: + if(byRefImage != null) { + return new ImageData(ImageDataType.TYPE_BYTE_ARRAY, + dataWidth * dataHeight * depth * unitsPerPixel, + dataWidth, dataHeight, byRefImage); + } else { + return new ImageData(ImageDataType.TYPE_BYTE_ARRAY, + dataWidth * dataHeight * depth * unitsPerPixel, + dataWidth, dataHeight); + } + case TYPE_INT_RGB: + case TYPE_INT_BGR: + case TYPE_INT_ARGB: + if(byRefImage != null) { + return new ImageData(ImageDataType.TYPE_INT_ARRAY, + dataWidth * dataHeight * depth * unitsPerPixel, + dataWidth, dataHeight, byRefImage); + } else { + return new ImageData(ImageDataType.TYPE_INT_ARRAY, + dataWidth * dataHeight * depth * unitsPerPixel, + dataWidth, dataHeight); + } + default: + throw new AssertionError(); + } + } + + private void updateImageDataPowerOfTwo(int depthIndex) { + assert enforceNonPowerOfTwoSupport; + BufferedImage bufImage = imageData.createBufferedImage(depthIndex); + BufferedImage scaledImg = powerOfTwoATOp.filter(bufImage, null); + copySupportedImageToImageData(scaledImg, 0, imageDataPowerOfTwo); + } + + /* + * This method assume that the following members have been initialized : + * width, height, depth, imageType, imageFormatType, and bytesPerPixel. + */ + ImageData createRenderedImageDataObject(RenderedImage byRefImage) { + + return createRenderedImageDataObject(byRefImage, width, height); + + } + + + /** + * Copy specified region of image data from RenderedImage to + * ImageComponent's imageData object + */ + void copySupportedImageToImageData(RenderedImage ri, int srcX, int srcY, + int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { + + assert (data != null); + + ColorModel cm = ri.getColorModel(); + + int xoff = ri.getTileGridXOffset(); // tile origin x offset + int yoff = ri.getTileGridYOffset(); // tile origin y offset + int minTileX = ri.getMinTileX(); // min tile x index + int minTileY = ri.getMinTileY(); // min tile y index + tilew = ri.getTileWidth(); // tile width in pixels + tileh = ri.getTileHeight(); // tile height in pixels + + // determine the first tile of the image + float mt; + + mt = (float)(srcX - xoff) / (float)tilew; + if (mt < 0) { + minTileX = (int)(mt - 1); + } else { + minTileX = (int)mt; + } + + mt = (float)(srcY - yoff) / (float)tileh; + if (mt < 0) { + minTileY = (int)(mt - 1); + } else { + minTileY = (int)mt; + } + + // determine the pixel offset of the upper-left corner of the + // first tile + int startXTile = minTileX * tilew + xoff; + int startYTile = minTileY * tileh + yoff; + + // image dimension in the first tile + int curw = (startXTile + tilew - srcX); + int curh = (startYTile + tileh - srcY); + + // check if the to-be-copied region is less than the tile image + // if so, update the to-be-copied dimension of this tile + if (curw > copyWidth) { + curw = copyWidth; + } + + if (curh > copyHeight) { + curh = copyHeight; + } + + // save the to-be-copied width of the left most tile + int startw = curw; + + // temporary variable for dimension of the to-be-copied region + int tmpw = copyWidth; + int tmph = copyHeight; + + // offset of the first pixel of the tile to be copied; offset is // relative to the upper left corner of the title - - int x = srcX - startXTile; - int y = srcY - startYTile; - - - // determine the number of tiles in each direction that the - // image spans - - numXTiles = (copywidth + x) / tilew; - numYTiles = (copyheight + y) / tileh; - - if (((float)(copywidth + x ) % (float)tilew) > 0) { - numXTiles += 1; - } - - if (((float)(copyheight + y ) % (float)tileh) > 0) { - numYTiles += 1; - } - + int x = srcX - startXTile; + int y = srcY - startYTile; + + // determine the number of tiles in each direction that the + // image spans + numXTiles = (copyWidth + x) / tilew; + numYTiles = (copyHeight + y) / tileh; + + if (((float)(copyWidth + x ) % (float)tilew) > 0) { + numXTiles += 1; + } + + if (((float)(copyHeight + y ) % (float)tileh) > 0) { + numYTiles += 1; + } + + int offset; + int w, h, i, j, m, n; + int dstBegin; + Object pixel = null; + java.awt.image.Raster ras; + int lineUnits; // nbytes per line in dst image buffer + int sign; // -1 for going down + int dstLineUnits; // sign * lineUnits + int tileStart; // destination buffer offset + // at the next left most tile + + byte[] dstByteBuffer = null; + int[] dstIntBuffer = null; + + switch(data.getType()) { + case TYPE_BYTE_ARRAY: + dstByteBuffer = data.getAsByteArray(); + break; + case TYPE_INT_ARRAY: + dstIntBuffer = data.getAsIntArray(); + break; + default: + assert false; + } + + int dataWidth = data.dataWidth; + int dataHeight = data.dataHeight; + + lineUnits = dataWidth * unitsPerPixel; + if (yUp) { + // destination buffer offset + tileStart = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; + sign = 1; + dstLineUnits = lineUnits; + } else { + // destination buffer offset + tileStart = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; + sign = -1; + dstLineUnits = -lineUnits; + } + /* - System.out.println("-----------------------------------------------"); - System.out.println("minTileX= " + minTileX + " minTileY= " + minTileY); - System.out.println("numXTiles= " + numXTiles + " numYTiles= " + numYTiles); - System.out.println("tilew= " + tilew + " tileh= " + tileh); - System.out.println("xoff= " + xoff + " yoff= " + yoff); - System.out.println("startXTile= " + startXTile + " startYTile= " + startYTile); - System.out.println("srcX= " + srcX + " srcY= " + srcY); - System.out.println("copywidth= " + copywidth + " copyheight= " + copyheight); - - System.out.println("rminTileX= " + ri.getMinTileX() + " rminTileY= " + ri.getMinTileY()); - System.out.println("rnumXTiles= " + ri.getNumXTiles() + " rnumYTiles= " + ri.getNumYTiles()); -*/ - - if ((!yUp && usedByTexture) || - (yUp && !usedByTexture)) { - - // destination buffer offset - - tileStart = ((height - dstY - 1) * width + dstX) - * imageBytesPerPixel; - - sign = -1; - dstLineBytes = -lineBytes; - } else { - - // destination buffer offset - - tileStart = (dstY * width + dstX) * imageBytesPerPixel; - sign = 1; - dstLineBytes = lineBytes; - } - + System.err.println("tileStart= " + tileStart + " dstLineUnits= " + dstLineUnits); + System.err.println("startw= " + startw); + */ + + // allocate memory for a pixel + ras = ri.getTile(minTileX,minTileY); + pixel = getDataElementBuffer(ras); + + int srcOffset, dstOffset; + int tileLineUnits = tilew * unitsPerPixel; + int copyUnits; + + for (n = minTileY; n < minTileY+numYTiles; n++) { + + dstBegin = tileStart; // destination buffer offset + tmpw = copyWidth; // reset the width to be copied + curw = startw; // reset the width to be copied of + // the left most tile + x = srcX - startXTile; // reset the starting x offset of + // the left most tile + + for (m = minTileX; m < minTileX+numXTiles; m++) { + + // retrieve the raster for the next tile + ras = ri.getTile(m,n); + + srcOffset = (y * tilew + x) * unitsPerPixel; + dstOffset = dstBegin; + + copyUnits = curw * unitsPerPixel; + + //System.err.println("curh = "+curh+" curw = "+curw); + //System.err.println("x = "+x+" y = "+y); + + switch(data.getType()) { + case TYPE_BYTE_ARRAY: + byte[] srcByteBuffer = ((DataBufferByte)ras.getDataBuffer()).getData(); + for (h = 0; h < curh; h++) { + System.arraycopy(srcByteBuffer, srcOffset, dstByteBuffer, dstOffset, + copyUnits); + srcOffset += tileLineUnits; + dstOffset += dstLineUnits; + } + break; + case TYPE_INT_ARRAY: + int[] srcIntBuffer = ((DataBufferInt)ras.getDataBuffer()).getData(); + for (h = 0; h < curh; h++) { + System.arraycopy(srcIntBuffer, srcOffset, dstIntBuffer, dstOffset, + copyUnits); + srcOffset += tileLineUnits; + dstOffset += dstLineUnits; + } + break; + default: + assert false; + } + + // advance the destination buffer offset + dstBegin += curw * unitsPerPixel; + + // move to the next tile in x direction + x = 0; + + // determine the width of copy region of the next tile + + tmpw -= curw; + if (tmpw < tilew) { + curw = tmpw; + } else { + curw = tilew; + } + } + + // we are done copying an array of tiles in the x direction + // advance the tileStart offset + tileStart += dataWidth * unitsPerPixel * curh * sign; + + // move to the next set of tiles in y direction + y = 0; + + // determine the height of copy region for the next set + // of tiles + tmph -= curh; + if (tmph < tileh) { + curh = tmph; + } else { + curh = tileh; + } + } + + if((imageData == data) && (imageDataPowerOfTwo != null)) { + updateImageDataPowerOfTwo(depthIndex); + } + } + + // Quick line by line copy + void copyImageLineByLine(BufferedImage bi, int srcX, int srcY, + int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { + + assert (data != null); + + int h; + int rowBegin, // src begin row index + srcBegin, // src begin offset + dstBegin; // dst begin offset + + int dataWidth = data.dataWidth; + int dataHeight = data.dataHeight; + int dstUnitsPerRow = dataWidth * unitsPerPixel; // bytes per row in dst image + rowBegin = srcY; + + if (yUp) { + dstBegin = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; + } else { + dstBegin = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; + dstUnitsPerRow = - 1 * dstUnitsPerRow; + } + + int copyUnits = copyWidth * unitsPerPixel; + int srcWidth = bi.getWidth(); + int srcUnitsPerRow = srcWidth * unitsPerPixel; + srcBegin = (rowBegin * srcWidth + srcX) * unitsPerPixel; + + switch(data.getType()) { + case TYPE_BYTE_ARRAY: + byte[] srcByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] dstByteBuffer = data.getAsByteArray(); + for (h = 0; h < copyHeight; h++) { + System.arraycopy(srcByteBuffer, srcBegin, dstByteBuffer, dstBegin, copyUnits); + dstBegin += dstUnitsPerRow; + srcBegin += srcUnitsPerRow; + } + break; + + case TYPE_INT_ARRAY: + int[] srcIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + int[] dstIntBuffer = data.getAsIntArray(); + for (h = 0; h < copyHeight; h++) { + System.arraycopy(srcIntBuffer, srcBegin, dstIntBuffer, dstBegin, copyUnits); + dstBegin += dstUnitsPerRow; + srcBegin += srcUnitsPerRow; + } + break; + default: + assert false; + } + + if((imageData == data) && (imageDataPowerOfTwo != null)) { + updateImageDataPowerOfTwo(depthIndex); + } + } + + // Quick block copy for yUp image + void copyImageByBlock(BufferedImage bi, int depthIndex, ImageData data) { + + assert ((data != null) && yUp); + + int dataWidth = data.dataWidth; + int dataHeight = data.dataHeight; + + int dstBegin; // dst begin offset + dstBegin = depthIndex * dataWidth * dataHeight * unitsPerPixel; + + switch(imageData.getType()) { + case TYPE_BYTE_ARRAY: + byte[] srcByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] dstByteBuffer = data.getAsByteArray(); + System.arraycopy(srcByteBuffer, 0, dstByteBuffer, dstBegin, (dataWidth * dataHeight * unitsPerPixel)); + break; + case TYPE_INT_ARRAY: + int[] srcIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + int[] dstIntBuffer = data.getAsIntArray(); + System.arraycopy(srcIntBuffer, 0, dstIntBuffer, dstBegin, (dataWidth * dataHeight * unitsPerPixel)); + break; + default: + assert false; + } + + if((imageData == data) && (imageDataPowerOfTwo != null)) { + updateImageDataPowerOfTwo(depthIndex); + } + + } + + /** + * copy complete region of a RenderedImage to ImageComponent's imageData object. + */ + void copySupportedImageToImageData(RenderedImage ri, int depthIndex, ImageData data) { + + if (ri instanceof BufferedImage) { + if(yUp) { + /* Use quick block copy when ( format is OK, Yup is true, and byRef is false). */ + // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !byReference && yUp) --- (2 BI)"); + copyImageByBlock((BufferedImage)ri, depthIndex, data); + } else { + /* Use quick inverse line by line copy when (format is OK and Yup is false). */ + // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !yUp) --- (3 BI)"); + copyImageLineByLine((BufferedImage)ri, 0, 0, 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); + } + } else { + // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !byReference ) --- (2 RI)"); + copySupportedImageToImageData(ri, ri.getMinX(), ri.getMinY(), 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); + + /* + * An alternative approach. + * + // Create a buffered image from renderImage + ColorModel cm = ri.getColorModel(); + WritableRaster wRaster = ri.copyData(null); + BufferedImage bi = new BufferedImage(cm, + wRaster, + cm.isAlphaPremultiplied() + ,null); + + copySupportedImageToImageData((BufferedImage)ri, 0, 0, 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); + + * + * + */ + } + } + + /* + * copy the complete unsupported NioImageBuffer into a supported BYTE_BUFFER format + */ + void copyUnsupportedNioImageToImageData(NioImageBuffer nioImage, int srcX, int srcY, + int dstX, int dstY, int copyWidth, int copyHeight, ImageData iData) { + + assert (iData.getType() == ImageDataType.TYPE_BYTE_BUFFER); + assert (getImageFormatType() == ImageFormatType.TYPE_BYTE_RGBA); + + int length = copyWidth * copyHeight; + ByteBuffer srcBuffer = (ByteBuffer) nioImage.getDataBuffer(); + srcBuffer.rewind(); + ByteBuffer dstBuffer = iData.getAsByteBuffer(); + dstBuffer.rewind(); + + // Do copy and swap. + for(int i = 0; i < length; i +=4) { + dstBuffer.put(i, srcBuffer.get(i+3)); + dstBuffer.put(i+1, srcBuffer.get(i+2)); + dstBuffer.put(i+2, srcBuffer.get(i+1)); + dstBuffer.put(i+3, srcBuffer.get(i)); + } + } + + /* + * copy the complete unsupported image into a supported BYTE_ARRAY format + */ + void copyUnsupportedImageToImageData(RenderedImage ri, int depthIndex, ImageData data) { + + assert (data.getType() == ImageDataType.TYPE_BYTE_ARRAY); + + if (ri instanceof BufferedImage) { + copyUnsupportedImageToImageData((BufferedImage)ri, 0, 0, 0, 0, + depthIndex, data.dataWidth, data.dataHeight, data); + } else { + copyUnsupportedImageToImageData(ri, ri.getMinX(), ri.getMinY(), + 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); + } + } + + void copyUnsupportedImageToImageData(BufferedImage bi, int srcX, int srcY, + int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { + + int w, h, i, j; + int rowBegin, // src begin row index + srcBegin, // src begin offset + dstBegin, // dst begin offset + rowInc, // row increment + // -1 --- ydown + // 1 --- yup + row; + + rowBegin = srcY; + rowInc = 1; + + assert (data != null); + + int dataWidth = data.dataWidth; + int dataHeight = data.dataHeight; + int dstBytesPerRow = dataWidth * unitsPerPixel; // bytes per row in dst image + + if (yUp) { + dstBegin = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; + } else { + dstBegin = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; + dstBytesPerRow = - 1 * dstBytesPerRow; + } + + WritableRaster ras = bi.getRaster(); + ColorModel cm = bi.getColorModel(); + Object pixel = getDataElementBuffer(ras); + + byte[] dstBuffer = data.getAsByteArray(); + + switch(numberOfComponents) { + case 4: { + for (row = rowBegin, h = 0; + h < copyHeight; h++, row += rowInc) { + j = dstBegin; + for (w = srcX; w < (copyWidth + srcX); w++) { + ras.getDataElements(w, row, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getGreen(pixel); + dstBuffer[j++] = (byte)cm.getBlue(pixel); + dstBuffer[j++] = (byte)cm.getAlpha(pixel); + } + dstBegin += dstBytesPerRow; + } + } + break; + + case 3: { + for (row = rowBegin, h = 0; + h < copyHeight; h++, row += rowInc) { + j = dstBegin; + for (w = srcX; w < (copyWidth + srcX); w++) { + ras.getDataElements(w, row, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getGreen(pixel); + dstBuffer[j++] = (byte)cm.getBlue(pixel); + } + dstBegin += dstBytesPerRow; + } + } + break; + + case 2: { + for (row = rowBegin, h = 0; + h < copyHeight; h++, row += rowInc) { + j = dstBegin; + for (w = srcX; w < (copyWidth + srcX); w++) { + ras.getDataElements(w, row, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getAlpha(pixel); + } + dstBegin += dstBytesPerRow; + } + } + break; + + case 1: { + for (row = rowBegin, h = 0; + h < copyHeight; h++, row += rowInc) { + j = dstBegin; + for (w = srcX; w < (copyWidth + srcX); w++) { + ras.getDataElements(w, row, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + } + dstBegin += dstBytesPerRow; + } + } + break; + default: + assert false; + } + + if((imageData == data) && (imageDataPowerOfTwo != null)) { + updateImageDataPowerOfTwo(depthIndex); + } + } + + void copyUnsupportedImageToImageData(RenderedImage ri, int srcX, int srcY, + int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { + + int w, h, i, j, m, n; + int dstBegin; + Object pixel = null; + java.awt.image.Raster ras; + // dst image buffer + int sign; // -1 for going down + int dstLineBytes; // sign * lineBytes + int tileStart; // destination buffer offset + // at the next left most tile + + int offset; + + ColorModel cm = ri.getColorModel(); + + int xoff = ri.getTileGridXOffset(); // tile origin x offset + int yoff = ri.getTileGridYOffset(); // tile origin y offset + int minTileX = ri.getMinTileX(); // min tile x index + int minTileY = ri.getMinTileY(); // min tile y index + tilew = ri.getTileWidth(); // tile width in pixels + tileh = ri.getTileHeight(); // tile height in pixels + + // determine the first tile of the image + + float mt; + + mt = (float)(srcX - xoff) / (float)tilew; + if (mt < 0) { + minTileX = (int)(mt - 1); + } else { + minTileX = (int)mt; + } + + mt = (float)(srcY - yoff) / (float)tileh; + if (mt < 0) { + minTileY = (int)(mt - 1); + } else { + minTileY = (int)mt; + } + + // determine the pixel offset of the upper-left corner of the + // first tile + int startXTile = minTileX * tilew + xoff; + int startYTile = minTileY * tileh + yoff; + + + // image dimension in the first tile + int curw = (startXTile + tilew - srcX); + int curh = (startYTile + tileh - srcY); + + // check if the to-be-copied region is less than the tile image + // if so, update the to-be-copied dimension of this tile + if (curw > copyWidth) { + curw = copyWidth; + } + + if (curh > copyHeight) { + curh = copyHeight; + } + + // save the to-be-copied width of the left most tile + int startw = curw; + + + // temporary variable for dimension of the to-be-copied region + int tmpw = copyWidth; + int tmph = copyHeight; + + + // offset of the first pixel of the tile to be copied; offset is + // relative to the upper left corner of the title + int x = srcX - startXTile; + int y = srcY - startYTile; + + + // determine the number of tiles in each direction that the + // image spans + + numXTiles = (copyWidth + x) / tilew; + numYTiles = (copyHeight + y) / tileh; + + if (((float)(copyWidth + x ) % (float)tilew) > 0) { + numXTiles += 1; + } + + if (((float)(copyHeight + y ) % (float)tileh) > 0) { + numYTiles += 1; + } + + assert (data != null); + int dataWidth = data.dataWidth; + int dataHeight = data.dataHeight; + int lineBytes = dataWidth * unitsPerPixel; // nbytes per line in + + if (yUp) { + // destination buffer offset + tileStart = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; + sign = 1; + dstLineBytes = lineBytes; + } else { + // destination buffer offset + tileStart = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; + sign = -1; + dstLineBytes = -lineBytes; + } + /* - System.out.println("tileStart= " + tileStart + " dstLineBytes= " + dstLineBytes); - System.out.println("startw= " + startw); -*/ - - // allocate memory for a pixel - - ras = ri.getTile(minTileX,minTileY); - pixel = getDataElementBuffer(ras); - - if (formatMatches(imageFormat, ri)) { - byte[] src; - int srcOffset, dstOffset; - int tileLineBytes= tilew * imageBytesPerPixel; - int copyBytes; - - for (n = minTileY; n < minTileY+numYTiles; n++) { - - dstBegin = tileStart; // destination buffer offset - tmpw = copywidth; // reset the width to be copied - curw = startw; // reset the width to be copied of - // the left most tile - x = srcX - startXTile; // reset the starting x offset of - // the left most tile - - for (m = minTileX; m < minTileX+numXTiles; m++) { - - // retrieve the raster for the next tile - ras = ri.getTile(m,n); - src = ((DataBufferByte)ras.getDataBuffer()).getData(); - - srcOffset = (y * tilew + x) * imageBytesPerPixel; - dstOffset = dstBegin; - - copyBytes = curw * imageBytesPerPixel; - - //System.out.println("curh = "+curh+" curw = "+curw); - //System.out.println("x = "+x+" y = "+y); - - for (h = 0; h < curh; h++) { - System.arraycopy(src, srcOffset, image, dstOffset, - copyBytes); - srcOffset += tileLineBytes; - dstOffset += dstLineBytes; - } - - // advance the destination buffer offset - dstBegin += curw * imageBytesPerPixel; - - // move to the next tile in x direction - x = 0; - - // determine the width of copy region of the next tile - - tmpw -= curw; - if (tmpw < tilew) { - curw = tmpw; - } else { - curw = tilew; - } - } - - - // we are done copying an array of tiles in the x direction - // advance the tileStart offset - - tileStart += width * imageBytesPerPixel * curh * sign; - - - // move to the next set of tiles in y direction - y = 0; - - // determine the height of copy region for the next set - // of tiles - tmph -= curh; - if (tmph < tileh) { - curh = tmph; - } else { - curh = tileh; - } - } - return; - } - - switch(format) { - case ImageComponent.FORMAT_RGBA8: - case ImageComponent.FORMAT_RGB5_A1: - case ImageComponent.FORMAT_RGBA4: { - // System.out.println("Case 1: byReference = "+byReference); - for (n = minTileY; n < minTileY+numYTiles; n++) { - - dstBegin = tileStart; // destination buffer offset - tmpw = copywidth; // reset the width to be copied - curw = startw; // reset the width to be copied of - // the left most tile - x = srcX - startXTile; // reset the starting x offset of - // the left most tile - - for (m = minTileX; m < minTileX+numXTiles; m++) { - - // retrieve the raster for the next tile - ras = ri.getTile(m,n); - - j = dstBegin; - offset = 0; - - //System.out.println("curh = "+curh+" curw = "+curw); - //System.out.println("x = "+x+" y = "+y); - - for (h = y; h < (y + curh); h++) { - // System.out.println("j = "+j); - for (w = x; w < (x + curw); w++) { - ras.getDataElements(w, h, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getGreen(pixel); - image[j++] = (byte)cm.getBlue(pixel); - image[j++] = (byte)cm.getAlpha(pixel); - } - offset += dstLineBytes; - j = dstBegin + offset; - } - - // advance the destination buffer offset - dstBegin += curw * imageBytesPerPixel; - - // move to the next tile in x direction - x = 0; - - // determine the width of copy region of the next tile - - tmpw -= curw; - if (tmpw < tilew) { - curw = tmpw; - } else { - curw = tilew; - } - } - - - // we are done copying an array of tiles in the x direction - // advance the tileStart offset - - tileStart += width * imageBytesPerPixel * curh * sign; - - - // move to the next set of tiles in y direction - y = 0; - - // determine the height of copy region for the next set - // of tiles - tmph -= curh; - if (tmph < tileh) { - curh = tmph; - } else { - curh = tileh; - } - } - } - break; - case ImageComponent.FORMAT_RGB8: - case ImageComponent.FORMAT_RGB5: - case ImageComponent.FORMAT_RGB4: - case ImageComponent.FORMAT_R3_G3_B2: { - for (n = minTileY; n < minTileY+numYTiles; n++) { - - dstBegin = tileStart; // destination buffer offset - tmpw = copywidth; // reset the width to be copied - curw = startw; // reset the width to be copied of - // the left most tile - x = srcX - startXTile; // reset the starting x offset of - // the left most tile - - for (m = minTileX; m < minTileX+numXTiles; m++) { - - // retrieve the raster for the next tile - ras = ri.getTile(m,n); - - j = dstBegin; - offset = 0; - - //System.out.println("curh = "+curh+" curw = "+curw); - //System.out.println("x = "+x+" y = "+y); - - for (h = y; h < (y + curh); h++) { - // System.out.println("j = "+j); - for (w = x; w < (x + curw); w++) { - ras.getDataElements(w, h, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getGreen(pixel); - image[j++] = (byte)cm.getBlue(pixel); - image[j++] = (byte)255; - } - offset += dstLineBytes; - j = dstBegin + offset; - } - - // advance the destination buffer offset - dstBegin += curw * imageBytesPerPixel; - - // move to the next tile in x direction - x = 0; - - // determine the width of copy region of the next tile - - tmpw -= curw; - if (tmpw < tilew) { - curw = tmpw; - } else { - curw = tilew; - } - } - - - // we are done copying an array of tiles in the x direction - // advance the tileStart offset - - tileStart += width * imageBytesPerPixel * curh * sign; - - - // move to the next set of tiles in y direction - y = 0; - - // determine the height of copy region for the next set - // of tiles - tmph -= curh; - if (tmph < tileh) { - curh = tmph; - } else { - curh = tileh; - } - } - } - break; - case ImageComponent.FORMAT_LUM8_ALPHA8: - case ImageComponent.FORMAT_LUM4_ALPHA4: { - for (n = minTileY; n < minTileY+numYTiles; n++) { - - dstBegin = tileStart; // destination buffer offset - tmpw = copywidth; // reset the width to be copied - curw = startw; // reset the width to be copied of - // the left most tile - x = srcX - startXTile; // reset the starting x offset of - // the left most tile - - for (m = minTileX; m < minTileX+numXTiles; m++) { - - // retrieve the raster for the next tile - ras = ri.getTile(m,n); - - j = dstBegin; - offset = 0; - - //System.out.println("curh = "+curh+" curw = "+curw); - //System.out.println("x = "+x+" y = "+y); - - for (h = y; h < (y + curh); h++) { - // System.out.println("j = "+j); - for (w = x; w < (x + curw); w++) { - ras.getDataElements(w, h, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getAlpha(pixel); - } - offset += dstLineBytes; - j = dstBegin + offset; - } - - // advance the destination buffer offset - dstBegin += curw * imageBytesPerPixel; - - // move to the next tile in x direction - x = 0; - - // determine the width of copy region of the next tile - - tmpw -= curw; - if (tmpw < tilew) { - curw = tmpw; - } else { - curw = tilew; - } - } - - - // we are done copying an array of tiles in the x direction - // advance the tileStart offset - - tileStart += width * imageBytesPerPixel * curh * sign; - - - // move to the next set of tiles in y direction - y = 0; - - // determine the height of copy region for the next set - // of tiles - tmph -= curh; - if (tmph < tileh) { - curh = tmph; - } else { - curh = tileh; - } - } - } - break; - case ImageComponent.FORMAT_CHANNEL8: { - for (n = minTileY; n < minTileY+numYTiles; n++) { - - dstBegin = tileStart; // destination buffer offset - tmpw = copywidth; // reset the width to be copied - curw = startw; // reset the width to be copied of - // the left most tile - x = srcX - startXTile; // reset the starting x offset of - // the left most tile - - for (m = minTileX; m < minTileX+numXTiles; m++) { - - // retrieve the raster for the next tile - ras = ri.getTile(m,n); - - j = dstBegin; - offset = 0; - - //System.out.println("curh = "+curh+" curw = "+curw); - //System.out.println("x = "+x+" y = "+y); - - for (h = y; h < (y + curh); h++) { - // System.out.println("j = "+j); - for (w = x; w < (x + curw); w++) { - ras.getDataElements(w, h, pixel); - image[j++] = (byte)cm.getRed(pixel); - } - offset += dstLineBytes; - j = dstBegin + offset; - } - - // advance the destination buffer offset - dstBegin += curw * imageBytesPerPixel; - - // move to the next tile in x direction - x = 0; - - // determine the width of copy region of the next tile - - tmpw -= curw; - if (tmpw < tilew) { - curw = tmpw; - } else { - curw = tilew; - } - } - - - // we are done copying an array of tiles in the x direction - // advance the tileStart offset - - tileStart += width * imageBytesPerPixel * curh * sign; - - - // move to the next set of tiles in y direction - y = 0; - - // determine the height of copy region for the next set - // of tiles - tmph -= curh; - if (tmph < tileh) { - curh = tmph; - } else { - curh = tileh; - } - } - } - break; - default: - break; - } + System.err.println("tileStart= " + tileStart + " dstLineBytes= " + dstLineBytes); + System.err.println("startw= " + startw); + */ + + // allocate memory for a pixel + ras = ri.getTile(minTileX,minTileY); + pixel = getDataElementBuffer(ras); + byte[] dstBuffer = imageData.getAsByteArray(); + + switch(numberOfComponents) { + case 4: { + // System.err.println("Case 1: byReference = "+byReference); + for (n = minTileY; n < minTileY+numYTiles; n++) { + + dstBegin = tileStart; // destination buffer offset + tmpw = copyWidth; // reset the width to be copied + curw = startw; // reset the width to be copied of + // the left most tile + x = srcX - startXTile; // reset the starting x offset of + // the left most tile + + for (m = minTileX; m < minTileX+numXTiles; m++) { + + // retrieve the raster for the next tile + ras = ri.getTile(m,n); + + j = dstBegin; + offset = 0; + + //System.err.println("curh = "+curh+" curw = "+curw); + //System.err.println("x = "+x+" y = "+y); + + for (h = y; h < (y + curh); h++) { + // System.err.println("j = "+j); + for (w = x; w < (x + curw); w++) { + ras.getDataElements(w, h, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getGreen(pixel); + dstBuffer[j++] = (byte)cm.getBlue(pixel); + dstBuffer[j++] = (byte)cm.getAlpha(pixel); + } + offset += dstLineBytes; + j = dstBegin + offset; + } + + // advance the destination buffer offset + dstBegin += curw * unitsPerPixel; + + // move to the next tile in x direction + x = 0; + + // determine the width of copy region of the next tile + + tmpw -= curw; + if (tmpw < tilew) { + curw = tmpw; + } else { + curw = tilew; + } + } + + // we are done copying an array of tiles in the x direction + // advance the tileStart offset + + tileStart += dataWidth * unitsPerPixel * curh * sign; + + // move to the next set of tiles in y direction + y = 0; + + // determine the height of copy region for the next set + // of tiles + tmph -= curh; + if (tmph < tileh) { + curh = tmph; + } else { + curh = tileh; + } + } + } + break; + case 3: { + for (n = minTileY; n < minTileY+numYTiles; n++) { + + dstBegin = tileStart; // destination buffer offset + tmpw = copyWidth; // reset the width to be copied + curw = startw; // reset the width to be copied of + // the left most tile + x = srcX - startXTile; // reset the starting x offset of + // the left most tile + + for (m = minTileX; m < minTileX+numXTiles; m++) { + + // retrieve the raster for the next tile + ras = ri.getTile(m,n); + + j = dstBegin; + offset = 0; + + //System.err.println("curh = "+curh+" curw = "+curw); + //System.err.println("x = "+x+" y = "+y); + + for (h = y; h < (y + curh); h++) { + // System.err.println("j = "+j); + for (w = x; w < (x + curw); w++) { + ras.getDataElements(w, h, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getGreen(pixel); + dstBuffer[j++] = (byte)cm.getBlue(pixel); + } + offset += dstLineBytes; + j = dstBegin + offset; + } + + // advance the destination buffer offset + dstBegin += curw * unitsPerPixel; + + // move to the next tile in x direction + x = 0; + + // determine the width of copy region of the next tile + + tmpw -= curw; + if (tmpw < tilew) { + curw = tmpw; + } else { + curw = tilew; + } + } + + // we are done copying an array of tiles in the x direction + // advance the tileStart offset + + tileStart += dataWidth * unitsPerPixel * curh * sign; + + // move to the next set of tiles in y direction + y = 0; + + // determine the height of copy region for the next set + // of tiles + tmph -= curh; + if (tmph < tileh) { + curh = tmph; + } else { + curh = tileh; + } + } + } + break; + case 2: { + for (n = minTileY; n < minTileY+numYTiles; n++) { + + dstBegin = tileStart; // destination buffer offset + tmpw = copyWidth; // reset the width to be copied + curw = startw; // reset the width to be copied of + // the left most tile + x = srcX - startXTile; // reset the starting x offset of + // the left most tile + + for (m = minTileX; m < minTileX+numXTiles; m++) { + + // retrieve the raster for the next tile + ras = ri.getTile(m,n); + + j = dstBegin; + offset = 0; + + //System.err.println("curh = "+curh+" curw = "+curw); + //System.err.println("x = "+x+" y = "+y); + + for (h = y; h < (y + curh); h++) { + // System.err.println("j = "+j); + for (w = x; w < (x + curw); w++) { + ras.getDataElements(w, h, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + dstBuffer[j++] = (byte)cm.getAlpha(pixel); + } + offset += dstLineBytes; + j = dstBegin + offset; + } + + // advance the destination buffer offset + dstBegin += curw * unitsPerPixel; + + // move to the next tile in x direction + x = 0; + + // determine the width of copy region of the next tile + + tmpw -= curw; + if (tmpw < tilew) { + curw = tmpw; + } else { + curw = tilew; + } + } + + + // we are done copying an array of tiles in the x direction + // advance the tileStart offset + + tileStart += dataWidth * unitsPerPixel * curh * sign; + + + // move to the next set of tiles in y direction + y = 0; + + // determine the height of copy region for the next set + // of tiles + tmph -= curh; + if (tmph < tileh) { + curh = tmph; + } else { + curh = tileh; + } + } + } + break; + case 1: { + for (n = minTileY; n < minTileY+numYTiles; n++) { + + dstBegin = tileStart; // destination buffer offset + tmpw = copyWidth; // reset the width to be copied + curw = startw; // reset the width to be copied of + // the left most tile + x = srcX - startXTile; // reset the starting x offset of + // the left most tile + + for (m = minTileX; m < minTileX+numXTiles; m++) { + + // retrieve the raster for the next tile + ras = ri.getTile(m,n); + + j = dstBegin; + offset = 0; + + //System.err.println("curh = "+curh+" curw = "+curw); + //System.err.println("x = "+x+" y = "+y); + + for (h = y; h < (y + curh); h++) { + // System.err.println("j = "+j); + for (w = x; w < (x + curw); w++) { + ras.getDataElements(w, h, pixel); + dstBuffer[j++] = (byte)cm.getRed(pixel); + } + offset += dstLineBytes; + j = dstBegin + offset; + } + + // advance the destination buffer offset + dstBegin += curw * unitsPerPixel; + + // move to the next tile in x direction + x = 0; + + // determine the width of copy region of the next tile + + tmpw -= curw; + if (tmpw < tilew) { + curw = tmpw; + } else { + curw = tilew; + } + } + + // we are done copying an array of tiles in the x direction + // advance the tileStart offset + tileStart += dataWidth * unitsPerPixel * curh * sign; + + // move to the next set of tiles in y direction + y = 0; + + // determine the height of copy region for the next set + // of tiles + tmph -= curh; + if (tmph < tileh) { + curh = tmph; + } else { + curh = tileh; + } + } + } + break; + + default: + assert false; + } + + if((imageData == data) && (imageDataPowerOfTwo != null)) { + updateImageDataPowerOfTwo(depthIndex); + } } + + // Lock out user thread from modifying variables by using synchronized routines + void evaluateExtensions(Canvas3D canvas) { + // For performance reason the ordering of the following 2 statements is intentional. + // So that we only need to do format conversion for imageData only + evaluateExtABGR(canvas.extensionsSupported); + evaluateExtNonPowerOfTwo(canvas.textureExtendedFeatures); + + } + + + void evaluateExtABGR(int ext) { + + + // If abgrSupported is false, a copy has been created so + // we don't have to check again. + if(!abgrSupported) { + return; + } + + if(getImageFormatType() != ImageFormatType.TYPE_BYTE_ABGR) { + return; + } + + if((ext & Canvas3D.EXT_ABGR) != 0) { + return; + } + + // ABGR is unsupported, set flag to false. + abgrSupported = false; + convertImageDataFromABGRToRGBA(); + + } + + private int getClosestPowerOf2(int value) { + + if (value < 1) + return value; + + int powerValue = 1; + for (;;) { + powerValue *= 2; + if (value < powerValue) { + // Found max bound of power, determine which is closest + int minBound = powerValue/2; + if ((powerValue - value) > + (value - minBound)) + return minBound; + else + return powerValue; + } + } + } + + void evaluateExtNonPowerOfTwo(int ext) { + + // If npotSupported is false, a copy power of two image has been created + // so we don't have to check again. + if(!npotSupported) { + return; + } + if (imageData == null && !isByReference()) { + return; + } + if((ext & Canvas3D.TEXTURE_NON_POWER_OF_TWO) != 0) { + return; + } + + // NPOT is unsupported, set flag to false. + npotSupported = false; + + // scale to power of 2 for texture mapping + //xmax and ymax are in BackgroundRetained. + /* xmax = width; + ymax = height; */ + int npotWidth = getClosestPowerOf2(width); + int npotHeight = getClosestPowerOf2(height); + float xScale = (float)npotWidth/(float)width; + float yScale = (float)npotHeight/(float)height; + + // scale if scales aren't 1.0 + if (!(xScale == 1.0f && yScale == 1.0f)) { + RenderedImage ri = null; + + if (imageData == null) { + // This is a byRef, support format and is a RenderedImage case. + // See ImageComponent2DRetained.set(RenderedImage image) + ri = (RenderedImage) getRefImage(0); + if(!(ri instanceof BufferedImage)) { + // Create a buffered image from renderImage + ColorModel cm = ri.getColorModel(); + WritableRaster wRaster = ri.copyData(null); + ri = new BufferedImage(cm, + wRaster, + cm.isAlphaPremultiplied() + ,null); + + // Create image data object with buffer for image. */ + imageData = createRenderedImageDataObject(null); + copySupportedImageToImageData(ri, 0, imageData); + } + } + + assert imageData != null; + ri = imageData.createBufferedImage(0); + + AffineTransform at = AffineTransform.getScaleInstance(xScale, + yScale); + powerOfTwoATOp = new AffineTransformOp(at, + AffineTransformOp.TYPE_NEAREST_NEIGHBOR); + BufferedImage scaledImg = powerOfTwoATOp.filter((BufferedImage)ri, null); + + imageDataPowerOfTwo = createRenderedImageDataObject(null, npotWidth, npotHeight); + // Since ri is created from imageData, it's imageType is supported. + copySupportedImageToImageData(scaledImg, 0, imageDataPowerOfTwo); + + } else { + imageDataPowerOfTwo = null; + } + } + + void convertImageDataFromABGRToRGBA() { + + // Unsupported format on HW, switch to slow copy. + imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; + imageTypeIsSupported = false; + + // Only need to convert imageData + imageData.convertFromABGRToRGBA(); + + } + /** - * Copy entire image data from Buffered Image to - * ImageComponent's internal representation - */ - final void copyImage(BufferedImage bi, byte[] image, - boolean usedByTexture, int depth, - int imageFormat, int imageBytesPerPixel) { - copyImage(bi, 0, 0, image, 0, 0, usedByTexture, depth, - width, height, imageFormat, imageBytesPerPixel); + * Copy supported ImageType from ImageData to the user defined bufferedImage + */ + void copyToRefImage(int depth) { + int h; + int rowBegin, // src begin row index + srcBegin, // src begin offset + dstBegin; // dst begin offset + + // refImage has to be a BufferedImage for off screen and read raster + assert refImage[depth] != null; + assert (refImage[depth] instanceof BufferedImage); + + BufferedImage bi = (BufferedImage)refImage[depth]; + int dstUnitsPerRow = width * unitsPerPixel; // bytes per row in dst image + rowBegin = 0; + + if (yUp) { + dstBegin = (depth * width * height) * unitsPerPixel; + } else { + dstBegin = (depth * width * height + (height - 1) * width ) * unitsPerPixel; + dstUnitsPerRow = - 1 * dstUnitsPerRow; + } + + int scanline = width * unitsPerPixel; + srcBegin = (rowBegin * width ) * unitsPerPixel; + + switch(imageData.getType()) { + case TYPE_BYTE_ARRAY: + byte[] dstByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] srcByteBuffer = imageData.getAsByteArray(); + for (h = 0; h < height; h++) { + System.arraycopy(srcByteBuffer, srcBegin, dstByteBuffer, dstBegin, scanline); + dstBegin += dstUnitsPerRow; + srcBegin += scanline; + } + break; + + case TYPE_INT_ARRAY: + int[] dstIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + int[] srcIntBuffer = imageData.getAsIntArray(); + for (h = 0; h < height; h++) { + System.arraycopy(srcIntBuffer, srcBegin, dstIntBuffer, dstBegin, scanline); + dstBegin += dstUnitsPerRow; + srcBegin += scanline; + } + break; + default: + assert false; + } + } - + /** - * Copy specified region of image data from Buffered Image to - * ImageComponent's internal representation - */ - final void copyImage(BufferedImage bi, int srcX, int srcY, - byte[] image, int dstX, int dstY, boolean usedByTexture, - int depth, int copywidth, int copyheight, - int imageFormat, int imageBytesPerPixel) { - - int w, h, i, j; - int rowBegin, // src begin row index - srcBegin, // src begin offset - dstBegin, // dst begin offset - rowInc, // row increment - // -1 --- ydown - // 1 --- yup - row; - Object pixel = null; - - rowBegin = srcY; - rowInc = 1; - - int dstBytesPerRow = width * imageBytesPerPixel; // bytes per row - // in dst image - - if ((!yUp && usedByTexture) || (yUp && !usedByTexture)) { - dstBegin = (depth * width * height + - (height - dstY - 1) * width + dstX) * - imageBytesPerPixel; - - dstBytesPerRow = - 1 * dstBytesPerRow; - - } else { - dstBegin = (dstY * width + dstX) * imageBytesPerPixel; - } - - // if the image format matches the format of the incoming - // buffered image, then do a straight copy, else do the - // format conversion while copying the data - - if (formatMatches(imageFormat, bi)) { - byte[] byteData = - ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); - int copyBytes = copywidth * imageBytesPerPixel; - int scanline = width * imageBytesPerPixel; - - srcBegin = (rowBegin * width + srcX) * imageBytesPerPixel; - for (h = 0; h < copyheight; h++) { - System.arraycopy(byteData, srcBegin, image, dstBegin, copyBytes); - dstBegin += dstBytesPerRow; - srcBegin += scanline; - } + * Copy Image from RGBA to the user defined bufferedImage + */ + void copyToRefImageWithFormatConversion(int depth) { + int w, h, i, j; + int dstBegin, dstInc, dstIndex, dstIndexInc; + // refImage has to be a BufferedImage for off screen and read raster + assert refImage[depth] != null; + assert (refImage[depth] instanceof BufferedImage); + + BufferedImage bi = (BufferedImage)refImage[depth]; + int biType = bi.getType(); + byte[] buf = imageData.getAsByteArray(); + + // convert from Ydown to Yup for texture + if (!yUp) { + dstInc = -1 * width; + dstBegin = (height - 1) * width; + dstIndex = height -1; + dstIndexInc = -1; } else { - - int biType = bi.getType(); - if ((biType == BufferedImage.TYPE_INT_ARGB || - biType == BufferedImage.TYPE_INT_RGB) && - (format == ImageComponent.FORMAT_RGBA8 || - format == ImageComponent.FORMAT_RGB8)) { - - // optimized cases - + dstInc = width; + dstBegin = 0; + dstIndex = 0; + dstIndexInc = 1; + } + + switch (biType) { + case BufferedImage.TYPE_INT_ARGB: int[] intData = - ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); - int rowOffset = rowInc * width; - int intPixel; - - srcBegin = rowBegin * width + srcX; - - if (biType == BufferedImage.TYPE_INT_ARGB && - format == ImageComponent.FORMAT_RGBA8) { - for (h = 0; h < copyheight; h++) { - i = srcBegin; - j = dstBegin; - for (w = 0; w < copywidth; w++, i++) { - intPixel = intData[i]; - image[j++] = (byte)((intPixel >> 16) & 0xff); - image[j++] = (byte)((intPixel >> 8) & 0xff); - image[j++] = (byte)(intPixel & 0xff); - image[j++] = (byte)((intPixel >> 24) & 0xff); - } - srcBegin += rowOffset; - dstBegin += dstBytesPerRow; + ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + // Multiply by 4 to get the byte incr and start point + j = 0; + for(h = 0; h < height; h++, dstBegin += dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4, i++) { + intData[i] = (((buf[j+3] &0xff) << 24) | // a + ((buf[j] &0xff) << 16) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)); // b + + } - } else { // format == ImageComponent.FORMAT_RGB8 - for (h = 0; h < copyheight; h++) { - i = srcBegin; - j = dstBegin; - for (w = 0; w < copywidth; w++, i++) { - intPixel = intData[i]; - image[j++] = (byte)((intPixel >> 16) & 0xff); - image[j++] = (byte)((intPixel >> 8) & 0xff); - image[j++] = (byte)(intPixel & 0xff); - image[j++] = (byte)255; - } - srcBegin += rowOffset; - dstBegin += dstBytesPerRow; + } + break; + + case BufferedImage.TYPE_INT_RGB: + intData = + ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + // Multiply by 4 to get the byte incr and start point + j = 0; + for(h = 0; h < height; h++, dstBegin += dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4, i++) { + intData[i] = (0xff000000 | // a + ((buf[j] &0xff) << 16) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)); // b + + } } - - } else if ((biType == BufferedImage.TYPE_BYTE_GRAY) && - (format == ImageComponent.FORMAT_CHANNEL8)) { - + break; + + case BufferedImage.TYPE_4BYTE_ABGR: byte[] byteData = - ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); - int rowOffset = rowInc * width; - - j = dstBegin; - srcBegin = rowBegin * width + srcX; - - for (h = 0; h < copyheight; - h++, j += width, srcBegin += rowOffset) { - System.arraycopy(byteData, srcBegin, image, j, copywidth); - } - } else { - // non-optimized cases - - WritableRaster ras = bi.getRaster(); - ColorModel cm = bi.getColorModel(); - pixel = getDataElementBuffer(ras); - - switch(format) { - case ImageComponent.FORMAT_RGBA8: - case ImageComponent.FORMAT_RGB5_A1: - case ImageComponent.FORMAT_RGBA4: { - for (row = rowBegin, h = 0; - h < copyheight; h++, row += rowInc) { - j = dstBegin; - for (w = srcX; w < (copywidth + srcX); w++) { - ras.getDataElements(w, row, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getGreen(pixel); - image[j++] = (byte)cm.getBlue(pixel); - image[j++] = (byte)cm.getAlpha(pixel); - } - dstBegin += dstBytesPerRow; + ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + // Multiply by 4 to get the byte incr and start point + j = 0; + for(h = 0; h < height; h++, dstBegin += (dstInc << 2)) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4) { + + byteData[i++] = buf[j+3]; // a + byteData[i++] = buf[j+2]; // b + byteData[i++] = buf[j+1];// g + byteData[i++] = buf[j]; // r } } break; - - case ImageComponent.FORMAT_RGB8: - case ImageComponent.FORMAT_RGB5: - case ImageComponent.FORMAT_RGB4: - case ImageComponent.FORMAT_R3_G3_B2: { - for (row = rowBegin, h = 0; - h < copyheight; h++, row += rowInc) { - j = dstBegin; - for (w = srcX; w < (copywidth + srcX); w++) { - ras.getDataElements(w, row, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getGreen(pixel); - image[j++] = (byte)cm.getBlue(pixel); - image[j++] = (byte)255; - } - dstBegin += dstBytesPerRow; - } + case BufferedImage.TYPE_INT_BGR: + intData = + ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + // Multiply by 4 to get the byte incr and start point + j = 0; + + for(h = 0; h < height; h++, dstBegin += dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, j+=4, i++) { + intData[i] = (0xff000000 | // a + ((buf[j] &0xff) ) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)<< 16); // b + + + } } break; - - case ImageComponent.FORMAT_LUM8_ALPHA8: - case ImageComponent.FORMAT_LUM4_ALPHA4: { - for (row = rowBegin, h = 0; - h < copyheight; h++, row += rowInc) { - j = dstBegin; - for (w = srcX; w < (copywidth + srcX); w++) { - ras.getDataElements(w, row, pixel); - image[j++] = (byte)cm.getRed(pixel); - image[j++] = (byte)cm.getAlpha(pixel); - } - dstBegin += dstBytesPerRow; - } - } - break; - - case ImageComponent.FORMAT_CHANNEL8: { - for (row = rowBegin, h = 0; - h < copyheight; h++, row += rowInc) { - j = dstBegin; - for (w = srcX; w < (copywidth + srcX); w++) { - ras.getDataElements(w, row, pixel); - image[j++] = (byte)cm.getRed(pixel); - } - dstBegin += dstBytesPerRow; - } + case BufferedImage.TYPE_BYTE_GRAY: + byteData = + ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + j = 0; + for( h = 0; h < height; h++, dstBegin += dstInc) { + System.arraycopy(byteData, dstBegin, buf, j, width); + j += width; } - break; + break; + case BufferedImage.TYPE_USHORT_GRAY: + int pixel; + j = 0; + short[] shortData = + ((DataBufferShort)bi.getRaster().getDataBuffer()).getData(); + // Multiply by 4 to get the byte incr and start point + for(h = 0; h < height; h++, dstBegin+= dstInc) { + i = dstBegin; + for (w = 0; w < width; w++, i++, j++) { + shortData[i] = (short)buf[j]; + } } - } - } - } - + break; + + default: + j = 0; + for( h = 0; h < height; h++, dstIndex += dstIndexInc) { + i = dstIndex; + for (w = 0; w < width; w++, j+=4) { + pixel = (((buf[j+3] &0xff) << 24) | // a + ((buf[j] &0xff) << 16) | // r + ((buf[j+1] &0xff) << 8) | // g + (buf[j+2] & 0xff)); // b + bi.setRGB(w, i, pixel); + + } + } + break; + } + + } - - - final int getBytesStored(int f) { - int val = 0; - switch(f) { - case BYTE_RGBA: - val = 4; - break; - case BYTE_ABGR: - val = 4; - break; - case BYTE_GRAY: - val = 1; - break; - case USHORT_GRAY: - val = 2; - break; - case BYTE_LA: - val = 2; - break; - case BYTE_BGR:; - val = 3; - break; - case BYTE_RGB:; - val = 3; - break; - } - return val; + void scaleImage(int xScale, int yScale, int depthIndex, ImageComponentRetained origImage) { + + byte[] dstByteBuffer = null; + byte[] srcByteBuffer = null; + int[] dstIntBuffer = null; + int[] srcIntBuffer = null; + int dStart, sStart; + + switch(imageData.getType()) { + case TYPE_BYTE_ARRAY: + dstByteBuffer = imageData.getAsByteArray(); + srcByteBuffer = origImage.imageData.getAsByteArray(); + dStart = depthIndex * width * height * unitsPerPixel; + sStart = depthIndex * origImage.width * origImage.height * unitsPerPixel; + scaleImage(xScale, yScale, dStart, sStart, origImage, dstByteBuffer, srcByteBuffer); + break; + case TYPE_INT_ARRAY: + dstIntBuffer = imageData.getAsIntArray(); + srcIntBuffer = origImage.imageData.getAsIntArray(); + dStart = depthIndex * width * height * unitsPerPixel; + sStart = depthIndex * origImage.width * origImage.height * unitsPerPixel; + scaleImage(xScale, yScale, dStart, sStart, origImage, dstIntBuffer, srcIntBuffer); + break; + default: + assert false; + } + } - - - boolean is4ByteRGBAOr3ByteRGB(RenderedImage ri) { - boolean value = false; - int i; - int biType = getImageType(ri); - if (biType != BufferedImage.TYPE_CUSTOM) - return false; - ColorModel cm = ri.getColorModel(); - ColorSpace cs = cm.getColorSpace(); - SampleModel sm = ri.getSampleModel(); - boolean isAlphaPre = cm.isAlphaPremultiplied(); - int csType = cs.getType(); - if ( csType == ColorSpace.TYPE_RGB) { - int numBands = sm.getNumBands(); - if (sm.getDataType() == DataBuffer.TYPE_BYTE) { - if (cm instanceof ComponentColorModel && - sm instanceof PixelInterleavedSampleModel) { - PixelInterleavedSampleModel csm = - (PixelInterleavedSampleModel) sm; - int[] offs = csm.getBandOffsets(); - ComponentColorModel ccm = (ComponentColorModel)cm; - int[] nBits = ccm.getComponentSize(); - boolean is8Bit = true; - for (i=0; i < numBands; i++) { - if (nBits[i] != 8) { - is8Bit = false; - break; - } - } - if (is8Bit && - offs[0] == 0 && - offs[1] == 1 && - offs[2] == 2) { - if (numBands == 3) { - if (format == ImageComponent.FORMAT_RGB) - value = true; - } - else if (offs[3] == 3 && !isAlphaPre) { - if (format == ImageComponent.FORMAT_RGBA) - value = true; - } + + void scaleImage(int xScale, int yScale, int dStart, int sStart, ImageComponentRetained origImage, + byte[] dData, byte[] sData) { + + int dOffset = 0; + int sOffset = 0; + int sLineIncr = unitsPerPixel * origImage.width; + int sPixelIncr = unitsPerPixel << 1; + + assert ((xScale != 1) || (yScale != 1)); + + if (yScale == 1) { + for (int x = 0; x < width; x++) { + for (int k = 0; k < unitsPerPixel; k++) { + dData[dStart + dOffset + k] = (byte) + (((int)(sData[sStart + sOffset + k] & 0xff) + + (int)(sData[sStart + sOffset + k + + unitsPerPixel] & 0xff) + 1) >> 1); + } + dOffset += unitsPerPixel; + sOffset += sPixelIncr; + } + } else if (xScale == 1) { + for (int y = 0; y < height; y++) { + for (int k = 0; k < unitsPerPixel; k++) { + dData[dStart + dOffset + k] = (byte) + (((int)(sData[sStart + sOffset + k] & 0xff) + + (int)(sData[sStart + sOffset + k + + sLineIncr] & 0xff) + 1) >> 1); + } + dOffset += unitsPerPixel; + sOffset += sLineIncr; + } + } else { + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + for (int k = 0; k < unitsPerPixel; k++) { + dData[dStart + dOffset + k] = (byte) + (((int)(sData[sStart + sOffset + k] & 0xff) + + (int)(sData[sStart + sOffset + k + + unitsPerPixel] & 0xff) + + (int)(sData[sStart + sOffset + k + + sLineIncr] & 0xff) + + (int)(sData[sStart + sOffset + k + sLineIncr + + + unitsPerPixel] & 0xff) + 2) >> 2); } + dOffset += unitsPerPixel; + sOffset += sPixelIncr; } + sOffset += sLineIncr; } } - return value; } - - final int getImageType(RenderedImage ri) { - int imageType = BufferedImage.TYPE_CUSTOM; - int i; - - if (ri instanceof BufferedImage) { - return ((BufferedImage)ri).getType(); - } - ColorModel cm = ri.getColorModel(); - ColorSpace cs = cm.getColorSpace(); - SampleModel sm = ri.getSampleModel(); - int csType = cs.getType(); - boolean isAlphaPre = cm.isAlphaPremultiplied(); - if ( csType != ColorSpace.TYPE_RGB) { - if (csType == ColorSpace.TYPE_GRAY && - cm instanceof ComponentColorModel) { - if (sm.getDataType() == DataBuffer.TYPE_BYTE) { - imageType = BufferedImage.TYPE_BYTE_GRAY; - } else if (sm.getDataType() == DataBuffer.TYPE_USHORT) { - imageType = BufferedImage.TYPE_USHORT_GRAY; + + void scaleImage(int xScale, int yScale, int dStart, int sStart, ImageComponentRetained origImage, + int[] dData, int[] sData) { + + int dOffset = 0; + int sOffset = 0; + int sLineIncr = origImage.width; + int sPixelIncr = 2; + + assert ((xScale != 1) || (yScale != 1)); + + int sTemp1, sTemp2; + int[] comp = new int[4]; + if (yScale == 1) { + for (int x = 0; x < width; x++) { + sTemp1 = sData[sStart + sOffset]; + sTemp2 = sData[sStart + sOffset + 1]; + // Unpack and compute + for (int k = 0; k < numberOfComponents; k++) { + comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + 1) >> 1; + sTemp1 = sTemp1 >> 8; + sTemp2 = sTemp2 >> 8; + } + // Pack back computed value. + sTemp1 = comp[numberOfComponents - 1]; + if(numberOfComponents > 1) { + for (int k = numberOfComponents - 2; k >= 0; k--) { + sTemp1 = (sTemp1 << 8) + comp[k]; + } } + dData[dStart + dOffset] = sTemp1; + + dOffset += 1; + sOffset += sPixelIncr; } - } - // RGB , only interested in BYTE ABGR and BGR for now - // all others will be copied to a buffered image - else { - int numBands = sm.getNumBands(); - if (sm.getDataType() == DataBuffer.TYPE_BYTE) { - if (cm instanceof ComponentColorModel && - sm instanceof PixelInterleavedSampleModel) { - PixelInterleavedSampleModel csm = - (PixelInterleavedSampleModel) sm; - int[] offs = csm.getBandOffsets(); - ComponentColorModel ccm = (ComponentColorModel)cm; - int[] nBits = ccm.getComponentSize(); - boolean is8Bit = true; - for (i=0; i < numBands; i++) { - if (nBits[i] != 8) { - is8Bit = false; - break; - } + } else if (xScale == 1) { + for (int y = 0; y < height; y++) { + sTemp1 = sData[sStart + sOffset]; + sTemp2 = sData[sStart + sOffset + sLineIncr]; + // Unpack and compute + for (int k = 0; k < numberOfComponents; k++) { + comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + 1) >> 1; + sTemp1 = sTemp1 >> 8; + sTemp2 = sTemp2 >> 8; + } + // Pack back computed value. + sTemp1 = comp[numberOfComponents - 1]; + if(numberOfComponents > 1) { + for (int k = numberOfComponents - 2; k >= 0; k--) { + sTemp1 = (sTemp1 << 8) + comp[k]; } - if (is8Bit && - offs[0] == numBands-1 && - offs[1] == numBands-2 && - offs[2] == numBands-3) { - if (numBands == 3) { - imageType = BufferedImage.TYPE_3BYTE_BGR; - } - else if (offs[3] == 0) { - imageType = (isAlphaPre - ? BufferedImage.TYPE_4BYTE_ABGR_PRE - : BufferedImage.TYPE_4BYTE_ABGR); + } + dData[dStart + dOffset] = sTemp1; + + dOffset += 1; + sOffset += sLineIncr; + } + } else { + int sTemp3, sTemp4; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + sTemp1 = sData[sStart + sOffset]; + sTemp2 = sData[sStart + sOffset + 1]; + sTemp3 = sData[sStart + sOffset + sLineIncr]; + sTemp4 = sData[sStart + sOffset + sLineIncr + 1]; + // Unpack and compute + for (int k = 0; k < numberOfComponents; k++) { + comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + + (sTemp3 & 0xff) + (sTemp4 & 0xff) + 2) >> 2; + sTemp1 = sTemp1 >> 8; + sTemp2 = sTemp2 >> 8; + sTemp3 = sTemp3 >> 8; + sTemp4 = sTemp4 >> 8; + } + // Pack back computed value. + sTemp1 = comp[numberOfComponents - 1]; + if(numberOfComponents > 1) { + for (int k = numberOfComponents - 2; k >= 0; k--) { + sTemp1 = (sTemp1 << 8) + comp[k]; } } + dData[dStart + dOffset] = sTemp1; + + dOffset += 1; + sOffset += sPixelIncr; } + sOffset += sLineIncr; } } - return imageType; } - - - - /** - * Retrieves the bufferedImage at the specified depth level - */ - final void retrieveBufferedImage(int depth) { - - // create BufferedImage if one doesn't exist - if (bImage[depth] == null) { - if (format == ImageComponent.FORMAT_RGBA || - format == ImageComponent.FORMAT_RGBA4 || - format == ImageComponent.FORMAT_RGB5_A1 || - format == ImageComponent.FORMAT_LUM4_ALPHA4 || - format == ImageComponent.FORMAT_LUM8_ALPHA8) { - bImage[depth] = new BufferedImage(width, height, - BufferedImage.TYPE_INT_ARGB); - } - else - bImage[depth] = new BufferedImage(width, height, - BufferedImage.TYPE_INT_RGB); + + // Add a user to the userList + synchronized void addUser(NodeComponentRetained node) { + userList.add(node); + } + + // Add a user to the userList + synchronized void removeUser(NodeComponentRetained node) { + int i = userList.indexOf(node); + if (i >= 0) { + userList.remove(i); } - - if (usedByTexture || !usedByRaster) { - copyToBufferedImage(imageYup, depth, true); - } else { - copyToBufferedImage(imageYdown[0], depth, false); - } - imageDirty[depth] = false; - } - - /** - * Copy Image from RGBA to the user defined bufferedImage + + /* + * + * @exception IllegalSharingException if this image is + * being used by a Canvas3D as an off-screen buffer. */ - final void copyBufferedImageWithFormatConversion(boolean usedByTexture, int depth) { - int w, h, i, j; - int dstBegin, dstInc, dstIndex, dstIndexInc; - // Note that if a copy has been made, then its always a bufferedImage - // and not a renderedImage - BufferedImage bi = (BufferedImage)bImage[depth]; - int biType = bi.getType(); - byte[] buf; - - // convert from Ydown to Yup for texture - if (!yUp) { - if (usedByTexture == true) { - dstInc = -1 * width; - dstBegin = (height - 1) * width; - dstIndex = height -1; - dstIndexInc = -1; - buf = imageYup; - } else { - dstInc = width; - dstBegin = 0; - dstIndex = 0; - dstIndexInc = 1; - buf = imageYdown[0]; - } - } - else { - if (usedByTexture == true) { - dstInc = width; - dstBegin = 0; - dstIndex = 0; - dstIndexInc = 1; - buf = imageYup; - } - else { - dstInc = -1 * width; - dstBegin = (height - 1) * width; - dstIndex = height -1; - dstIndexInc = -1; - buf = imageYdown[0]; - } - } - - switch (biType) { - case BufferedImage.TYPE_INT_ARGB: - int[] intData = - ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - j = 0; - for(h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = (((buf[j+3] &0xff) << 24) | // a - ((buf[j] &0xff) << 16) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)); // b - - - } - } - break; - - case BufferedImage.TYPE_INT_RGB: - intData = - ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - j = 0; - for(h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = (0xff000000 | // a - ((buf[j] &0xff) << 16) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)); // b - - - } - } - break; - - case BufferedImage.TYPE_4BYTE_ABGR: - byte[] byteData = - ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - j = 0; - for(h = 0; h < height; h++, dstBegin += (dstInc << 2)) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4) { - - byteData[i++] = buf[j+3]; // a - byteData[i++] = buf[j+2]; // b - byteData[i++] = buf[j+1];// g - byteData[i++] = buf[j]; // r - } - } - break; - case BufferedImage.TYPE_INT_BGR: - intData = - ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - j = 0; - - for(h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = (0xff000000 | // a - ((buf[j] &0xff) ) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)<< 16); // b - - - } - } - break; - case BufferedImage.TYPE_BYTE_GRAY: - byteData = - ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); - j = 0; - for( h = 0; h < height; h++, dstBegin += dstInc) { - System.arraycopy(byteData, dstBegin, buf, j, width); - j += width; - } - break; - case BufferedImage.TYPE_USHORT_GRAY: - int pixel; - j = 0; - short[] shortData = - ((DataBufferShort)bi.getRaster().getDataBuffer()).getData(); - // Multiply by 4 to get the byte incr and start point - for(h = 0; h < height; h++, dstBegin+= dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, i++, j++) { - shortData[i] = (short)buf[j]; - } - } - break; - - default: - j = 0; - for( h = 0; h < height; h++, dstIndex += dstIndexInc) { - i = dstIndex; - for (w = 0; w < width; w++, j+=4) { - pixel = (((buf[j+3] &0xff) << 24) | // a - ((buf[j] &0xff) << 16) | // r - ((buf[j+1] &0xff) << 8) | // g - (buf[j+2] & 0xff)); // b - bi.setRGB(w, i, pixel); - - } - } - break; - } - + void setLive(boolean inBackgroundGroup, int refCount) { + // Do illegalSharing check. + if(getUsedByOffScreen()) { + throw new IllegalSharingException(J3dI18N.getString("ImageComponent3")); + } + super.setLive(inBackgroundGroup, refCount); } /** - * Copy image data from ImageComponent's internal representation - * to Buffered Image - */ - final void copyToBufferedImage(byte[] buf, int depth, - boolean usedByTexture) { - - int w, h, i, j; - int dstBegin, dstInc, srcBegin; - - - // convert from Ydown to Yup for texture - if (!yUp) { - if (usedByTexture == true) { - srcBegin = depth * width * height * bytesPerYupPixelStored; - dstInc = -1 * width; - dstBegin = (height - 1) * width; - } else { - srcBegin = 0; - dstInc = width; - dstBegin = 0; - } - } - else { - if (usedByTexture == true) { - srcBegin = 0; - dstInc = width; - dstBegin = 0; - } - else { - srcBegin = depth * width * height * bytesPerYdownPixelStored; - dstInc = -1 * width; - dstBegin = (height - 1) * width; - } - } - - // Note that if a copy has been made, then its always a bufferedImage - // and not a renderedImage - int[] intData = ((DataBufferInt) - ((BufferedImage)bImage[depth]).getRaster().getDataBuffer()).getData(); - - switch(format) { - case ImageComponent.FORMAT_RGBA8: - case ImageComponent.FORMAT_RGB5_A1: - case ImageComponent.FORMAT_RGBA4: - - for (j = srcBegin, h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = ((buf[j+3] & 0xff) << 24) | - ((buf[j] & 0xff) << 16) | - ((buf[j+1] & 0xff) << 8) | - (buf[j+2] & 0xff); + * ImageComponent object doesn't really have mirror object. + * But it's using the updateMirrorObject interface to propagate + * the changes to the users + */ + synchronized void updateMirrorObject(int component, Object value) { + + //System.err.println("ImageComponent.updateMirrorObject"); + + Object user; + + if (((component & IMAGE_CHANGED) != 0) || + ((component & SUBIMAGE_CHANGED) != 0)) { + synchronized(userList) { + for (int i = userList.size()-1; i >=0; i--) { + user = userList.get(i); + if (user != null) { + if (user instanceof TextureRetained) { + ((TextureRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); + } else if (user instanceof RasterRetained) { + ((RasterRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); + } else if (user instanceof BackgroundRetained) { + ((BackgroundRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); + } + } } } - break; - - - case ImageComponent.FORMAT_RGB8: - case ImageComponent.FORMAT_RGB5: - case ImageComponent.FORMAT_RGB4: - case ImageComponent.FORMAT_R3_G3_B2: - for (j = srcBegin, h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=4, i++) { - intData[i] = ((buf[j] & 0xff) << 16) | - ((buf[j+1] & 0xff) << 8) | - (buf[j+2] & 0xff); - } - } - break; - - case ImageComponent.FORMAT_LUM8_ALPHA8: - case ImageComponent.FORMAT_LUM4_ALPHA4: - for (j = srcBegin, h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j+=2, i++) { - intData[i] = ((buf[j+1] & 0xff) << 24) | - ((buf[j] & 0xff) << 16); - } - } - break; - - case ImageComponent.FORMAT_CHANNEL8: - for (j = srcBegin, h = 0; h < height; h++, dstBegin += dstInc) { - i = dstBegin; - for (w = 0; w < width; w++, j++, i++) { - intData[i] = ((buf[j] & 0xff) << 16); - } - } - break; - } - } - - Object getData(DataBuffer buffer) { - Object data = null; - switch (buffer.getDataType()) { - case DataBuffer.TYPE_BYTE: - data = ((DataBufferByte)buffer).getData(); - break; - case DataBuffer.TYPE_INT: - data = ((DataBufferInt)buffer).getData(); - break; - case DataBuffer.TYPE_SHORT: - data = ((DataBufferShort)buffer).getData(); - break; - } - return data; + } } - - final void setByReference(boolean byReference) { - this.byReference = byReference; - } - - final boolean isByReference() { - return byReference; - } - - final void setYUp( boolean yUp) { - this.yUp = yUp; - } - - final boolean isYUp() { - return yUp; - } - - // Add a user to the userList - synchronized void addUser(NodeComponentRetained node) { - userList.add(node); - } - - // Add a user to the userList - synchronized void removeUser(NodeComponentRetained node) { - int i = userList.indexOf(node); - if (i >= 0) { - userList.remove(i); - } - } - - /** - * ImageComponent object doesn't really have mirror object. - * But it's using the updateMirrorObject interface to propagate - * the changes to the users - */ - synchronized void updateMirrorObject(int component, Object value) { - - //System.out.println("ImageComponent.updateMirrorObject"); - - Object user; - - if (((component & IMAGE_CHANGED) != 0) || - ((component & SUBIMAGE_CHANGED) != 0)) { - synchronized(userList) { - for (int i = userList.size()-1; i >=0; i--) { - user = userList.get(i); - if (user != null) { - if (user instanceof TextureRetained) { - ((TextureRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); - } else if (user instanceof RasterRetained) { - ((RasterRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); - } else if (user instanceof BackgroundRetained) { - ((BackgroundRetained)user).notifyImageComponentImageChanged(this, (ImageComponentUpdateInfo)value); - } - } - } - } - - // return the subimage update info to the free list - if (value != null) { - VirtualUniverse.mc.addFreeImageUpdateInfo( - (ImageComponentUpdateInfo)value); - } - } - } - - final void sendMessage(int attrMask, Object attr) { - - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + + final void sendMessage(int attrMask, Object attr) { + + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES | - J3dThread.UPDATE_RENDER; + J3dThread.UPDATE_RENDER; createMessage.type = J3dMessage.IMAGE_COMPONENT_CHANGED; createMessage.universe = null; createMessage.args[0] = this; createMessage.args[1]= new Integer(attrMask); createMessage.args[2] = attr; - createMessage.args[3] = new Integer(changedFrequent); + createMessage.args[3] = new Integer(changedFrequent); VirtualUniverse.mc.processMessage(createMessage); - } - + } + void handleFrequencyChange(int bit) { - if (bit == ImageComponent.ALLOW_IMAGE_WRITE) { - setFrequencyChangeMask(ImageComponent.ALLOW_IMAGE_WRITE, 0x1); - } + if (bit == ImageComponent.ALLOW_IMAGE_WRITE) { + setFrequencyChangeMask(ImageComponent.ALLOW_IMAGE_WRITE, 0x1); + } } - + static Object getDataElementBuffer(java.awt.image.Raster ras) { - int nc = ras.getNumDataElements(); - + int nc = ras.getNumDataElements(); + switch (ras.getTransferType()) { - case DataBuffer.TYPE_INT: - return new int[nc]; - case DataBuffer.TYPE_BYTE: - return new byte[nc]; - case DataBuffer.TYPE_USHORT: - case DataBuffer.TYPE_SHORT: - return new short[nc]; - case DataBuffer.TYPE_FLOAT: - return new float[nc]; - case DataBuffer.TYPE_DOUBLE: - return new double[nc]; - } - // Should not happen - return null; - } -} + case DataBuffer.TYPE_INT: + return new int[nc]; + case DataBuffer.TYPE_BYTE: + return new byte[nc]; + case DataBuffer.TYPE_USHORT: + case DataBuffer.TYPE_SHORT: + return new short[nc]; + case DataBuffer.TYPE_FLOAT: + return new float[nc]; + case DataBuffer.TYPE_DOUBLE: + return new double[nc]; + } + // Should not happen + return null; + } + + /** + * Wrapper class for image data. + * Currently supports byte array and int array. + * Will eventually support NIO ByteBuffer and IntBuffer. + */ + class ImageData { + + private Object data = null; + private ImageDataType imageDataType = ImageDataType.TYPE_NULL; + private int length = 0; + private boolean dataIsByRef = false; + private int dataWidth, dataHeight; + + /** + * Constructs a new ImageData buffer of the specified type with the + * specified length. + */ + ImageData(ImageDataType imageDataType, int length, int dataWidth, int dataHeight) { + this.imageDataType = imageDataType; + this.length = length; + this.dataWidth = dataWidth; + this.dataHeight = dataHeight; + this.dataIsByRef = false; + + switch (imageDataType) { + case TYPE_BYTE_ARRAY: + data = new byte[length]; + break; + case TYPE_INT_ARRAY: + data = new int[length]; + break; + case TYPE_BYTE_BUFFER: + ByteOrder order = ByteOrder.nativeOrder(); + data = ByteBuffer.allocateDirect(length).order(order); + break; + case TYPE_INT_BUFFER: + default: + throw new AssertionError(); + } + } + + /** + * Constructs a new ImageData buffer of the specified type with the + * specified length and the specified byRefImage as data. + */ + ImageData(ImageDataType imageDataType, int length, int dataWidth, int dataHeight, + Object byRefImage) { + BufferedImage bi; + NioImageBuffer nio; + + this.imageDataType = imageDataType; + this.length = length; + this.dataWidth = dataWidth; + this.dataHeight = dataHeight; + this.dataIsByRef = true; + + switch (imageDataType) { + case TYPE_BYTE_ARRAY: + bi = (BufferedImage) byRefImage; + data = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + break; + case TYPE_INT_ARRAY: + bi = (BufferedImage) byRefImage; + data = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + break; + case TYPE_BYTE_BUFFER: + case TYPE_INT_BUFFER: + nio = (NioImageBuffer) byRefImage; + data = nio.getDataBuffer(); + break; + default: + throw new AssertionError(); + } + } + + /** + * Constructs a new ImageData buffer from the specified + * object. This object stores a reference to the input image data. + */ + ImageData(Object data, boolean isByRef) { + this.data = data; + dataIsByRef = isByRef; + dataWidth = ((ImageData) data).dataWidth; + dataHeight = ((ImageData) data).dataHeight; + + if (data == null) { + imageDataType = ImageDataType.TYPE_NULL; + length = 0; + } else if (data instanceof byte[]) { + imageDataType = ImageDataType.TYPE_BYTE_ARRAY; + length = ((byte[]) data).length; + } else if (data instanceof int[]) { + imageDataType = ImageDataType.TYPE_INT_ARRAY; + length = ((int[]) data).length; + } else if (data instanceof ByteBuffer) { + imageDataType = ImageDataType.TYPE_BYTE_BUFFER; + length = ((ByteBuffer) data).limit(); + } else if (data instanceof IntBuffer) { + imageDataType = ImageDataType.TYPE_INT_BUFFER; + length = ((IntBuffer) data).limit(); + } else { + assert false; + } + } + + /** + * Returns the type of this DataBuffer. + */ + ImageDataType getType() { + return imageDataType; + } + + /** + * Returns the number of elements in this DataBuffer. + */ + int length() { + return length; + } + + /** + * Returns the width of this DataBuffer. + */ + int getWidth() { + return dataWidth; + } + + /** + * Returns the height of this DataBuffer. + */ + int getHeight() { + return dataHeight; + } + + /** + * Returns this DataBuffer as an Object. + */ + Object get() { + return data; + } + + /** + * Returns is this data is byRef. No internal data is made. + */ + boolean isDataByRef() { + return dataIsByRef; + } + + + /** + * Returns this DataBuffer as a byte array. + */ + byte[] getAsByteArray() { + return (byte[]) data; + } + + /** + * Returns this DataBuffer as an int array. + */ + int[] getAsIntArray() { + return (int[]) data; + } + + /** + * Returns this DataBuffer as an nio ByteBuffer. + */ + ByteBuffer getAsByteBuffer() { + return (ByteBuffer) data; + } + + /** + * Returns this DataBuffer as an nio IntBuffer. + */ + IntBuffer getAsIntBuffer() { + return (IntBuffer) data; + } + + // Handle TYPE_BYTE_LA only + void copyByLineAndExpand(BufferedImage bi, int depthIndex) { + int h; + int srcBegin, // src begin offset + dstBegin; // dst begin offset + + assert (imageData.getType() == ImageDataType.TYPE_BYTE_ARRAY); + assert (imageFormatType == ImageFormatType.TYPE_BYTE_LA); + + int unitsPerRow = width * unitsPerPixel; // bytes per row + int scanline = unitsPerRow; + if (yUp) { + srcBegin = (depthIndex * width * height) * unitsPerPixel; + } else { + srcBegin = (depthIndex * width * height + (height - 1) * width) * unitsPerPixel; + unitsPerRow = - 1 * unitsPerRow; + } + + dstBegin = 0; + // ABGR is 4 bytes per pixel + int dstUnitsPerRow = width * 4; + + byte[] dstByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] srcByteBuffer = imageData.getAsByteArray(); + for (h = 0; h < height; h++) { + for( int v = 0, w = 0; w < scanline; w += unitsPerPixel, v += 4) { + dstByteBuffer[dstBegin+v] = srcByteBuffer[srcBegin+w+1]; // Alpha + dstByteBuffer[dstBegin+v+1] = 0; + dstByteBuffer[dstBegin+v+2] = 0; + dstByteBuffer[dstBegin+v+3] = srcByteBuffer[srcBegin+w]; // Red + } + + dstBegin += dstUnitsPerRow; + srcBegin += unitsPerRow; + } + + } + + // Quick line by line copy + void copyByLine(BufferedImage bi, int depthIndex, boolean swapNeeded) { + + int h; + int srcBegin, // src begin offset + dstBegin; // dst begin offset + + int unitsPerRow = width * unitsPerPixel; // bytes per row + int copyUnits = unitsPerRow; + if (yUp) { + srcBegin = (depthIndex * width * height) * unitsPerPixel; + } else { + srcBegin = (depthIndex * width * height + (height - 1) * width) * unitsPerPixel; + unitsPerRow = - 1 * unitsPerRow; + } + + dstBegin = 0; + + switch(imageData.getType()) { + case TYPE_BYTE_ARRAY: + byte[] dstByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] srcByteBuffer = imageData.getAsByteArray(); + for (h = 0; h < height; h++) { + if(!swapNeeded) { + System.arraycopy(srcByteBuffer, srcBegin, + dstByteBuffer, dstBegin, copyUnits); + } else { + if(imageFormatType == ImageFormatType.TYPE_BYTE_RGB) { + assert (unitsPerPixel == 3); + for(int w = 0; w < copyUnits; w += unitsPerPixel) { + dstByteBuffer[dstBegin+w] = srcByteBuffer[srcBegin+w+2]; + dstByteBuffer[dstBegin+w+1] = srcByteBuffer[srcBegin+w+1]; + dstByteBuffer[dstBegin+w+2] = srcByteBuffer[srcBegin+w]; + } + } else if(imageFormatType == ImageFormatType.TYPE_BYTE_RGBA) { + assert (unitsPerPixel == 4); + for(int w = 0; w < copyUnits; w += unitsPerPixel) { + dstByteBuffer[dstBegin+w] = srcByteBuffer[srcBegin+w+3]; + dstByteBuffer[dstBegin+w+1] = srcByteBuffer[srcBegin+w+2]; + dstByteBuffer[dstBegin+w+2] = srcByteBuffer[srcBegin+w+1]; + dstByteBuffer[dstBegin+w+3] = srcByteBuffer[srcBegin+w]; + } + } else { + assert false; + } + } + dstBegin += copyUnits; + srcBegin += unitsPerRow; + } + break; + + // INT case doesn't required to handle swapNeeded + case TYPE_INT_ARRAY: + assert (!swapNeeded); + int[] dstIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + int[] srcIntBuffer = imageData.getAsIntArray(); + for (h = 0; h < height; h++) { + System.arraycopy(srcIntBuffer, srcBegin, dstIntBuffer, dstBegin, copyUnits); + dstBegin += copyUnits; + srcBegin += unitsPerRow; + } + break; + default: + assert false; + } + } + + void copyByBlock(BufferedImage bi, int depthIndex) { + // src begin offset + int srcBegin = depthIndex * width * height * unitsPerPixel; + + switch(imageData.getType()) { + case TYPE_BYTE_ARRAY: + byte[] dstByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); + byte[] srcByteBuffer = imageData.getAsByteArray(); + System.arraycopy(srcByteBuffer, srcBegin, dstByteBuffer, 0, (height * width * unitsPerPixel)); + break; + case TYPE_INT_ARRAY: + int[] dstIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); + int[] srcIntBuffer = imageData.getAsIntArray(); + System.arraycopy(srcIntBuffer, srcBegin, dstIntBuffer, 0, (height * width * unitsPerPixel)); + break; + default: + assert false; + } + } + + // Need to check for imageData is null. if it is null return null. + BufferedImage createBufferedImage(int depthIndex) { + if(data != null) { + int bufferType = BufferedImage.TYPE_CUSTOM; + boolean swapNeeded = false; + + switch(imageFormatType) { + case TYPE_BYTE_BGR: + bufferType = BufferedImage.TYPE_3BYTE_BGR; + break; + case TYPE_BYTE_RGB: + bufferType = BufferedImage.TYPE_3BYTE_BGR; + swapNeeded = true; + break; + case TYPE_BYTE_ABGR: + bufferType = BufferedImage.TYPE_4BYTE_ABGR; + break; + case TYPE_BYTE_RGBA: + bufferType = BufferedImage.TYPE_4BYTE_ABGR; + swapNeeded = true; + break; + // This is a special case. Need to handle separately. + case TYPE_BYTE_LA: + bufferType = BufferedImage.TYPE_4BYTE_ABGR; + break; + case TYPE_BYTE_GRAY: + bufferType = BufferedImage.TYPE_BYTE_GRAY; + break; + case TYPE_INT_BGR: + bufferType = BufferedImage.TYPE_INT_BGR; + break; + case TYPE_INT_RGB: + bufferType = BufferedImage.TYPE_INT_RGB; + break; + case TYPE_INT_ARGB: + bufferType = BufferedImage.TYPE_INT_ARGB; + break; + // Unsupported case, so shouldn't be here. + case TYPE_USHORT_GRAY: + bufferType = BufferedImage.TYPE_USHORT_GRAY; + default: + assert false; + + } + + BufferedImage bi = new BufferedImage(width, height, bufferType); + if((!swapNeeded) && (imageFormatType != ImageFormatType.TYPE_BYTE_LA)) { + if(yUp) { + copyByBlock(bi, depthIndex); + } else { + copyByLine(bi, depthIndex, false); + } + } else if(swapNeeded) { + copyByLine(bi, depthIndex, swapNeeded); + } else if(imageFormatType == ImageFormatType.TYPE_BYTE_LA) { + copyByLineAndExpand(bi, depthIndex); + } else { + assert false; + } + + return bi; + + } + return null; + } + + void convertFromABGRToRGBA() { + int i; + + if(imageDataType == ImageComponentRetained.ImageDataType.TYPE_BYTE_ARRAY) { + // Note : Highly inefficient for depth > 0 case. + // This method doesn't take into account of depth, it is assuming that + // depth == 0, which is true for ImageComponent2D. + byte[] srcBuffer, dstBuffer; + srcBuffer = getAsByteArray(); + + if(dataIsByRef) { + dstBuffer = new byte[length]; + // Do copy and swap. + for(i = 0; i < length; i +=4) { + dstBuffer[i] = srcBuffer[i+3]; + dstBuffer[i+1] = srcBuffer[i+2]; + dstBuffer[i+2] = srcBuffer[i+1]; + dstBuffer[i+3] = srcBuffer[i]; + } + data = dstBuffer; + dataIsByRef = false; + + } else { + byte a, b; + // Do swap in place. + for(i = 0; i < length; i +=4) { + a = srcBuffer[i]; + b = srcBuffer[i+1]; + srcBuffer[i] = srcBuffer[i+3]; + srcBuffer[i+1] = srcBuffer[i+2]; + srcBuffer[i+2] = b; + srcBuffer[i+3] = a; + } + } + } + else if(imageDataType == ImageComponentRetained.ImageDataType.TYPE_BYTE_BUFFER) { + + assert dataIsByRef; + ByteBuffer srcBuffer, dstBuffer; + + srcBuffer = getAsByteBuffer(); + srcBuffer.rewind(); + + ByteOrder order = ByteOrder.nativeOrder(); + dstBuffer = ByteBuffer.allocateDirect(length).order(order); + dstBuffer.rewind(); + + // Do copy and swap. + for(i = 0; i < length; i +=4) { + dstBuffer.put(i, srcBuffer.get(i+3)); + dstBuffer.put(i+1, srcBuffer.get(i+2)); + dstBuffer.put(i+2, srcBuffer.get(i+1)); + dstBuffer.put(i+3, srcBuffer.get(i)); + } + + dataIsByRef = false; + + } + } + } +} \ No newline at end of file diff --git a/src/classes/share/javax/media/j3d/IndexedGeometryArray.java b/src/classes/share/javax/media/j3d/IndexedGeometryArray.java index 67f8914..ae51edc 100644 --- a/src/classes/share/javax/media/j3d/IndexedGeometryArray.java +++ b/src/classes/share/javax/media/j3d/IndexedGeometryArray.java @@ -286,6 +286,10 @@ public abstract class IndexedGeometryArray extends GeometryArray { * than or equal to the number of vertices actually defined for * the particular component's array. * + * @exception ArrayIndexOutOfBoundsException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES and + * coordIndices.length < (initialIndexIndex + validIndexCount). + * * @since Java 3D 1.3 */ public void setValidIndexCount(int validIndexCount) { @@ -341,6 +345,10 @@ public abstract class IndexedGeometryArray extends GeometryArray { * than or equal to the number of vertices actually defined for * the particular component's array. * + * @exception ArrayIndexOutOfBoundsException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES and + * coordIndices.length < (initialIndexIndex + validIndexCount). + * * @since Java 3D 1.3 */ public void setInitialIndexIndex(int initialIndexIndex) { @@ -470,6 +478,7 @@ public abstract class IndexedGeometryArray extends GeometryArray { } + //NVaidya /** * Sets the coordinate index associated with the vertex at * the specified index for this object. @@ -488,15 +497,25 @@ public abstract class IndexedGeometryArray extends GeometryArray { * coordinateIndex is out of range if it is less than 0 or is * greater than or equal to the number of vertices actually * defined for the coordinate array. + * + * @exception IllegalStateException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES. */ public void setCoordinateIndex(int index, int coordinateIndex) { if (isLiveOrCompiled()) if(!this.getCapability(ALLOW_COORDINATE_INDEX_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("IndexedGeometryArray1")); + + //NVaidya + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) != 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray31")); ((IndexedGeometryArrayRetained)this.retained).setCoordinateIndex(index, coordinateIndex); } + + //NVaidya /** * Sets the coordinate indices associated with the vertices starting at * the specified index for this object. @@ -515,15 +534,64 @@ public abstract class IndexedGeometryArray extends GeometryArray { * is out of range. An element is out of range if it is less than 0 * or is greater than or equal to the number of vertices actually * defined for the coordinate array. + * + * @exception IllegalStateException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES. */ public void setCoordinateIndices(int index, int coordinateIndices[]) { if (isLiveOrCompiled()) if(!this.getCapability(ALLOW_COORDINATE_INDEX_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("IndexedGeometryArray1")); + + //NVaidya + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) != 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray31")); ((IndexedGeometryArrayRetained)this.retained).setCoordinateIndices(index, coordinateIndices); } + //NVaidya + /** + * Sets the coordinate indices array reference to the specified array. + * If the coordinate indices array reference is null, the entire + * geometry array object is treated as if it were null--any + * Shape3D or Morph node that uses this geometry array will not be drawn. + * + * @param coordIndices an array of indices to which a reference + * will be set. + * + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalStateException if the data mode for this geometry + * array object is not BY_REFERENCE_INDICES. + * + * @exception ArrayIndexOutOfBoundsException if any element of the + * coordIndices array whose destination position is in the range + * [initialIndexIndex, initialIndexIndex+validIndexCount-1] + * is out of range. An element is out of range if it is less than 0 + * or is greater than or equal to the number of vertices actually + * defined for the coordinate array. + * + * @exception ArrayIndexOutOfBoundsException if + * coordIndices.length < (initialIndexIndex + validIndexCount). + * + * @since Java 3D 1.5 + */ + public void setCoordIndicesRef(int coordIndices[]) { + if (isLiveOrCompiled()) + if (!this.getCapability(ALLOW_REF_DATA_WRITE)) + throw new CapabilityNotSetException(J3dI18N.getString("GeometryArray86")); + + //NVaidya + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) == 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray32")); + + ((IndexedGeometryArrayRetained)this.retained).setCoordIndicesRef(coordIndices); + } + /** * Sets the color index associated with the vertex at * the specified index for this object. @@ -816,38 +884,81 @@ public abstract class IndexedGeometryArray extends GeometryArray { ((IndexedGeometryArrayRetained)this.retained).setVertexAttrIndices(vertexAttrNum, index, vertexAttrIndices); } + //NVaidya /** - * Retrieves the coordinate index associated with the vertex at - * the specified index for this object. - * @param index the vertex index - * @return the coordinate index + * Retrieves the coordinate index associated with the vertex at + * the specified index for this object. + * @param index the vertex index + * @return the coordinate index * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph - */ + * + * @exception IllegalStateException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES. + */ public int getCoordinateIndex(int index) { if (isLiveOrCompiled()) if(!this.getCapability(ALLOW_COORDINATE_INDEX_READ)) throw new CapabilityNotSetException(J3dI18N.getString("IndexedGeometryArray9")); + + //NVaidya + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) != 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray31")); return ((IndexedGeometryArrayRetained)this.retained).getCoordinateIndex(index); } - /** - * Retrieves the coordinate indices associated with the vertices starting at - * the specified index for this object. - * @param index the vertex index - * @param coordinateIndices array that will receive the coordinate indices + //NVaidya + /** + * Retrieves the coordinate indices associated with the vertices starting at + * the specified index for this object. + * @param index the vertex index + * @param coordinateIndices array that will receive the coordinate indices * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph - */ + * + * @exception IllegalStateException if the data mode for this geometry + * array object is BY_REFERENCE_INDICES. + */ public void getCoordinateIndices(int index, int coordinateIndices[]) { if (isLiveOrCompiled()) if(!this.getCapability(ALLOW_COORDINATE_INDEX_READ)) throw new CapabilityNotSetException(J3dI18N.getString("IndexedGeometryArray9")); + + //NVaidya + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) != 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray31")); ((IndexedGeometryArrayRetained)this.retained).getCoordinateIndices(index, coordinateIndices); } + //NVaidya + /** + * Returns a reference to the coordinate indices associated with + * the vertices + * @return the coordinate indices array + * @exception CapabilityNotSetException if appropriate capability is + * not set and this object is part of live or compiled scene graph + * + * @exception IllegalStateException if the data mode for this geometry + * array object is not BY_REFERENCE_INDICES. + * + * @since Java 3D 1.5 + */ + public int[] getCoordIndicesRef() { + if (isLiveOrCompiled()) + if (!this.getCapability(ALLOW_REF_DATA_READ)) + throw new CapabilityNotSetException(J3dI18N.getString("GeometryArray87")); + + int format = ((IndexedGeometryArrayRetained)this.retained).vertexFormat; + if ((format & BY_REFERENCE_INDICES) == 0) + throw new IllegalStateException(J3dI18N.getString("IndexedGeometryArray32")); + + return ((IndexedGeometryArrayRetained)this.retained).getCoordIndicesRef(); + } + /** * Retrieves the color index associated with the vertex at * the specified index for this object. diff --git a/src/classes/share/javax/media/j3d/IndexedGeometryArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedGeometryArrayRetained.java index 5fb7ba7..e53565b 100644 --- a/src/classes/share/javax/media/j3d/IndexedGeometryArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedGeometryArrayRetained.java @@ -13,13 +13,8 @@ package javax.media.j3d; import javax.vecmath.*; -import java.util.Vector; import java.util.ArrayList; -import com.sun.j3d.internal.ByteBufferWrapper; -import com.sun.j3d.internal.BufferWrapper; import com.sun.j3d.internal.FloatBufferWrapper; -import com.sun.j3d.internal.DoubleBufferWrapper; - /** * The IndexedGeometryArray object contains arrays of positional coordinates, @@ -60,7 +55,10 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { // index arrays if USE_COORD_INDEX_ONLY is not set boolean notUCIO = (this.vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0; - if((this.vertexFormat & GeometryArray.COORDINATES) != 0) + //NVaidya + // Only allocate indexCoord if BY_REFERENCE_INDICES not set + if(((this.vertexFormat & GeometryArray.COORDINATES) != 0) && + ((this.vertexFormat & GeometryArray.BY_REFERENCE_INDICES) == 0)) this.indexCoord = new int[indexCount]; if(((this.vertexFormat & GeometryArray.NORMALS) != 0) && notUCIO) @@ -626,6 +624,120 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { } } + //NVaidya + /** + * Sets the coordinate indices by reference to the specified array + * @param coordinateIndices an array of coordinate indices + */ + final void setCoordIndicesRef(int coordinateIndices[]) { + int newMax = 0; + + if (coordinateIndices != null) { + if (coordinateIndices.length < initialIndexIndex + validIndexCount) { + throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray33")); + } + + // + // option 1: could fake the args to "re-use" doIndicesCheck() + //NVaidya + // newMax = doIndicesCheck(0, maxCoordIndex, coordinateIndices, coordinateIndices); + // if (newMax > maxCoordIndex) { + // doErrorCheck(newMax); + // } + // + // option 2: same logic as in setInitialIndexIndex: Better, I Think ? + // computeMaxIndex() doesn't check for index < 0 while doIndicesCheck() does. + // So, a new method computeMaxIndexWithCheck + //NVaidya + newMax = computeMaxIndexWithCheck(initialIndexIndex, validIndexCount, coordinateIndices); + if (newMax > maxCoordIndex) { + doErrorCheck(newMax); + } + } + + if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) { + if ((vertexFormat & GeometryArray.COLOR) != 0) { + maxColorIndex = newMax; + } + if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) { + for (int i = 0; i < texCoordSetCount; i++) { + maxTexCoordIndices[i] = newMax; + } + } + if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) { + for (int i = 0; i < vertexAttrCount; i++) { + maxVertexAttrIndices[i] = newMax; + } + } + if ((vertexFormat & GeometryArray.NORMALS) != 0) { + maxNormalIndex = newMax; + } + } + + geomLock.getLock(); + dirtyFlag |= INDEX_CHANGED; + maxCoordIndex = newMax; + this.indexCoord = coordinateIndices; + geomLock.unLock(); + if (!inUpdater && source != null && source.isLive()) { + sendDataChangedMessage(true); + } + } + + //NVaidya + /** + * trigger from GeometryArrayRetained#updateData() + * to recompute maxCoordIndex and perform index integrity checks + */ + final void doPostUpdaterUpdate() { + // user may have called setCoordIndicesRef and/or + // changed contents of indexCoord array. Thus, need to + // recompute maxCoordIndex unconditionally (and redundantly + // if user had only invoked setCoordIndicesRef but not also + // changed contents). geomLock is currently locked. + + // Option 1: + // simply call setCoordIndicesRef(indexCoord); but this seems to cause + // deadlock or freeze - probably because the !inUpdater branch sends + // out too many sendDataChangedMessage(true) - occurs if updateData + // method is called rapidly. + // setCoordIndicesRef(indexCoord); + + // Option 2: + // use only necessary code from setCoordIndicesRef + // System.out.println("IndexedGeometryArrayretained#doUpdaterUpdate"); + int newMax = 0; + + if (indexCoord != null) { + newMax = computeMaxIndexWithCheck(initialIndexIndex, validIndexCount, indexCoord); + if (newMax > maxCoordIndex) { + doErrorCheck(newMax); + } + } + + if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0) { + if ((vertexFormat & GeometryArray.COLOR) != 0) { + maxColorIndex = newMax; + } + if ((vertexFormat & GeometryArray.TEXTURE_COORDINATE) != 0) { + for (int i = 0; i < texCoordSetCount; i++) { + maxTexCoordIndices[i] = newMax; + } + } + if ((vertexFormat & GeometryArray.VERTEX_ATTRIBUTES) != 0) { + for (int i = 0; i < vertexAttrCount; i++) { + maxVertexAttrIndices[i] = newMax; + } + } + if ((vertexFormat & GeometryArray.NORMALS) != 0) { + maxNormalIndex = newMax; + } + } + + dirtyFlag |= INDEX_CHANGED; + maxCoordIndex = newMax; + } + /** * Sets the color index associated with the vertex at * the specified index for this object. @@ -781,9 +893,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { * the specified index for the specified vertex attribute number * for this object. */ - public void setVertexAttrIndex(int vertexAttrNum, - int index, - int vertexAttrIndex) { + void setVertexAttrIndex(int vertexAttrNum, + int index, + int vertexAttrIndex) { int newMax; int [] indices = this.indexVertexAttr[vertexAttrNum]; @@ -806,9 +918,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { * starting at the specified index for the specified vertex attribute number * for this object. */ - public void setVertexAttrIndices(int vertexAttrNum, - int index, - int[] vertexAttrIndices) { + void setVertexAttrIndices(int vertexAttrNum, + int index, + int[] vertexAttrIndices) { int i, j, num = vertexAttrIndices.length; int [] indices = this.indexVertexAttr[vertexAttrNum]; @@ -854,6 +966,15 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { } } + //NVaidya + /** + * Returns a reference to the coordinate indices associated + * with the vertices + */ + final int[] getCoordIndicesRef() { + return this.indexCoord; + } + /** * Retrieves the color index associated with the vertex at * the specified index for this object. @@ -936,8 +1057,8 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { * the specified index for the specified vertex attribute number * for this object. */ - public int getVertexAttrIndex(int vertexAttrNum, - int index) { + int getVertexAttrIndex(int vertexAttrNum, + int index) { int [] indices = this.indexVertexAttr[vertexAttrNum]; @@ -949,9 +1070,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { * starting at the specified index for the specified vertex attribute number * for this object. */ - public void getVertexAttrIndices(int vertexAttrNum, - int index, - int[] vertexAttrIndices) { + void getVertexAttrIndices(int vertexAttrNum, + int index, + int[] vertexAttrIndices) { int i, j, num = vertexAttrIndices.length; int [] indices = this.indexVertexAttr[vertexAttrNum]; @@ -961,124 +1082,26 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { } } - // by-copy or interleaved, by reference, Java arrays - private native void executeIndexedGeometry(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean useAlpha, - boolean multiScreen, - boolean ignoreVertexColors, - int initialIndexIndex, - int indexCount, - int vertexCount, int vformat, - int vertexAttrCount, int[] vertexAttrSizes, - int texCoordSetCount, int texCoordSetMap[], - int texCoordSetMapLen, - int[] texCoordSetOffset, - int numActiveTexUnitState, - int[] texUnitStateMap, - float[] varray, float[] cdata, - int texUnitIndex, int cdirty, - int[] indexCoord); - - // interleaved, by reference, nio buffer - private native void executeIndexedGeometryBuffer(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean useAlpha, - boolean multiScreen, - boolean ignoreVertexColors, - int initialIndexIndex, - int indexCount, - int vertexCount, int vformat, - int texCoordSetCount, int texCoordSetMap[], - int texCoordSetMapLen, - int[] texCoordSetOffset, - int numActiveTexUnitState, - int[] texUnitStateMap, - Object varray, float[] cdata, - int texUnitIndex, int cdirty, - int[] indexCoord); - - // non interleaved, by reference, Java arrays - private native void executeIndexedGeometryVA(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean multiScreen, - boolean ignoreVertexColors, - int initialIndexIndex, - int validIndexCount, - int vertexCount, - int vformat, - int vdefined, - float[] vfcoords, double[] vdcoords, - float[] cfdata, byte[] cbdata, - float[] ndata, - int vertexAttrCount, int[] vertexAttrSizes, - float[][] vertexAttrData, - int pass, int texcoordmaplength, - int[] texcoordoffset, - int numActiveTexUnitState, int[] texunitstatemap, - int texstride, Object[] texCoords, - int cdirty, - int[] indexCoord); - - // non interleaved, by reference, nio buffer - private native void executeIndexedGeometryVABuffer(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, - boolean multiScreen, - boolean ignoreVertexColors, - int initialIndexIndex, - int validIndexCount, - int vertexCount, - int vformat, - int vdefined, - Object vcoords, - Object cdataBuffer, - float[] cfdata, byte[] cbdata, - Object normal, - int vertexAttrCount, int[] vertexAttrSizes, - Object[] vertexAttrData, - int pass, int texcoordmaplength, - int[] texcoordoffset, - int numActiveTexUnitState, int[] texunitstatemap, - int texstride, Object[] texCoords, - int cdirty, - int[] indexCoord); - - // by-copy geometry - private native void buildIndexedGeometry(long ctx, - GeometryArrayRetained geo, int geo_type, - boolean isNonUniformScale, boolean updateAlpha, - float alpha, - boolean ignoreVertexColors, - int initialIndexIndex, - int validIndexCount, - int vertexCount, - int vformat, - int vertexAttrCount, int[] vertexAttrSizes, - int texCoordSetCount, int texCoordSetMap[], - int texCoordSetMapLen, - int[] texCoordSetMapOffset, - double[] xform, double[] nxform, - float[] varray, int[] indexCoord); - void execute(Canvas3D cv, RenderAtom ra, boolean isNonUniformScale, boolean updateAlpha, float alpha, - boolean multiScreen, int screen, - boolean ignoreVertexColors, int pass) { + int screen, boolean ignoreVertexColors) { + int cdirty; boolean useAlpha = false; Object[] retVal; if (mirrorGeometry != null) { mirrorGeometry.execute(cv, ra, isNonUniformScale, updateAlpha, alpha, - multiScreen, screen, - ignoreVertexColors, pass); + screen, ignoreVertexColors); return; } - //By reference with java array + + // Check if index array is null; if yes, don't draw anything + if (indexCoord == null) { + return; + } + + //By reference with java array if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) == 0) { if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) { float[] vdata; @@ -1111,9 +1134,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { dirtyFlag = 0; } - executeIndexedGeometry(cv.ctx, this, geoType, isNonUniformScale, + Pipeline.getPipeline().executeIndexedGeometry(cv.ctx, + this, geoType, isNonUniformScale, useAlpha, - multiScreen, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -1124,16 +1147,16 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { texCoordSetCount, texCoordSetMap, (texCoordSetMap == null) ? 0 : texCoordSetMap.length, texCoordSetMapOffset, - cv.numActiveTexUnit, cv.texUnitStateMap, + cv.numActiveTexUnit, vdata, null, - pass, cdirty, indexCoord); + cdirty, indexCoord); } // end of non by reference else if ((vertexFormat & GeometryArray.INTERLEAVED) != 0) { if(interLeavedVertexData == null) return; - + float[] cdata = null; synchronized (this) { @@ -1157,9 +1180,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { dirtyFlag = 0; } - executeIndexedGeometry(cv.ctx, this, geoType, isNonUniformScale, + Pipeline.getPipeline().executeIndexedGeometry(cv.ctx, + this, geoType, isNonUniformScale, useAlpha, - multiScreen, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -1169,9 +1192,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { texCoordSetCount, texCoordSetMap, (texCoordSetMap == null) ? 0 : texCoordSetMap.length, texCoordSetMapOffset, - cv.numActiveTexUnit, cv.texUnitStateMap, + cv.numActiveTexUnit, interLeavedVertexData, cdata, - pass, cdirty, indexCoord); + cdirty, indexCoord); } //end of interleaved else { // Check if a vertexformat is set, but the array is null @@ -1252,8 +1275,8 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { if((vertexType & TEXCOORD_DEFINED) != 0) vdefined |= TEXCOORD_FLOAT; - executeIndexedGeometryVA(cv.ctx, this, geoType, isNonUniformScale, - multiScreen, + Pipeline.getPipeline().executeIndexedGeometryVA(cv.ctx, + this, geoType, isNonUniformScale, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -1265,11 +1288,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { mirrorFloatRefNormals, vertexAttrCount, vertexAttrSizes, mirrorFloatRefVertexAttrs, - pass, ((texCoordSetMap == null) ? 0:texCoordSetMap.length), texCoordSetMap, cv.numActiveTexUnit, - cv.texUnitStateMap, texCoordStride, mirrorRefTexCoords, cdirty, indexCoord); } @@ -1304,20 +1325,20 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { dirtyFlag = 0; } - executeIndexedGeometryBuffer(cv.ctx, this, geoType, isNonUniformScale, - useAlpha, - multiScreen, - ignoreVertexColors, - initialIndexIndex, - validIndexCount, - maxCoordIndex + 1, - vertexFormat, - texCoordSetCount, texCoordSetMap, - (texCoordSetMap == null) ? 0 : texCoordSetMap.length, - texCoordSetMapOffset, - cv.numActiveTexUnit, cv.texUnitStateMap, - interleavedFloatBufferImpl.getBufferAsObject(), cdata, - pass, cdirty, indexCoord); + Pipeline.getPipeline().executeIndexedGeometryBuffer(cv.ctx, + this, geoType, isNonUniformScale, + useAlpha, + ignoreVertexColors, + initialIndexIndex, + validIndexCount, + maxCoordIndex + 1, + vertexFormat, + texCoordSetCount, texCoordSetMap, + (texCoordSetMap == null) ? 0 : texCoordSetMap.length, + texCoordSetMapOffset, + cv.numActiveTexUnit, + interleavedFloatBufferImpl.getBufferAsObject(), cdata, + cdirty, indexCoord); } //end of interleaved else { // Check if a vertexformat is set, but the array is null @@ -1417,9 +1438,8 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { vdefined |= TEXCOORD_FLOAT; } - executeIndexedGeometryVABuffer(cv.ctx, + Pipeline.getPipeline().executeIndexedGeometryVABuffer(cv.ctx, this, geoType, isNonUniformScale, - multiScreen, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -1432,11 +1452,9 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { normal, vertexAttrCount, vertexAttrSizes, nioFloatBufferRefVertexAttrs, - pass, ((texCoordSetMap == null) ? 0:texCoordSetMap.length), texCoordSetMap, cv.numActiveTexUnit, - cv.texUnitStateMap, texCoordStride, refTexCoords, cdirty, indexCoord); @@ -1488,7 +1506,8 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { dirtyFlag = 0; } - buildIndexedGeometry(cv.ctx, this, geoType, isNonUniformScale, + Pipeline.getPipeline().buildIndexedGeometry(cv.ctx, + this, geoType, isNonUniformScale, updateAlpha, alpha, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -1601,6 +1620,22 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { } + //NVaidya + // same as computeMaxIndex method but checks for index < 0 + int computeMaxIndexWithCheck(int initial, int count, int[] indices) { + int maxIndex = 0; + for (int i = initial; i < (initial+count); i++) { + // Throw an exception, since index is negative + if (indices[i] < 0) + throw new ArrayIndexOutOfBoundsException(J3dI18N.getString("IndexedGeometryArray27")); + if (indices[i] > maxIndex) { + maxIndex = indices[i]; + } + } + return maxIndex; + + } + void setValidIndexCount(int validIndexCount) { if (validIndexCount < 0) { throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray21")); @@ -1608,6 +1643,11 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { if ((initialIndexIndex + validIndexCount) > indexCount) { throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray22")); } + if ((vertexFormat & GeometryArray.BY_REFERENCE_INDICES) != 0) { + if (indexCoord != null && indexCoord.length < initialIndexIndex + validIndexCount) { + throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray33")); + } + } int newCoordMax =0; int newColorIndex=0; int newNormalIndex=0; @@ -1688,12 +1728,18 @@ abstract class IndexedGeometryArrayRetained extends GeometryArrayRetained { if ((initialIndexIndex + validIndexCount) > indexCount) { throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray22")); } + if ((vertexFormat & GeometryArray.BY_REFERENCE_INDICES) != 0) { + if (indexCoord != null && indexCoord.length < initialIndexIndex + validIndexCount) { + throw new IllegalArgumentException(J3dI18N.getString("IndexedGeometryArray33")); + } + } + int newCoordMax =0; int newColorIndex=0; int newNormalIndex=0; int[] newTexCoordIndex = null; int[] newVertexAttrIndex = null; - + newCoordMax = computeMaxIndex(initialIndexIndex, validIndexCount, indexCoord); doErrorCheck(newCoordMax); if ((vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) == 0) { diff --git a/src/classes/share/javax/media/j3d/InputDeviceBlockingThread.java b/src/classes/share/javax/media/j3d/InputDeviceBlockingThread.java index f0fdd26..b96e824 100644 --- a/src/classes/share/javax/media/j3d/InputDeviceBlockingThread.java +++ b/src/classes/share/javax/media/j3d/InputDeviceBlockingThread.java @@ -21,9 +21,10 @@ class InputDeviceBlockingThread extends Thread { // blocking device that this thread manages private InputDevice device; - private boolean running = true; - private boolean waiting = false; + private volatile boolean running = true; private volatile boolean stop = false; + private boolean waiting = false; + private boolean ready = false; private static int numInstances = 0; private int instanceNum = -1; @@ -69,30 +70,35 @@ class InputDeviceBlockingThread extends Thread { } void finish() { - stop = true; - while (!waiting) { - MasterControl.threadYield(); - } - - runMonitor(STOP); + stop = true; + runMonitor(STOP); } synchronized void runMonitor(int action) { switch (action) { case WAIT: - try { - waiting = true; - wait(); - } catch (InterruptedException e) {} - waiting = false; + // Issue 279 - loop until ready + while (running && !ready) { + waiting = true; + try { + wait(); + } catch (InterruptedException e) {} + waiting = false; + } + ready = false; break; case NOTIFY: - notify(); + ready = true; + if (waiting) { + notify(); + } break; case STOP: running = false; - notify(); + if (waiting) { + notify(); + } break; } } diff --git a/src/classes/share/javax/media/j3d/J3DBuffer.java b/src/classes/share/javax/media/j3d/J3DBuffer.java index 7cd5bf9..27f70ed 100644 --- a/src/classes/share/javax/media/j3d/J3DBuffer.java +++ b/src/classes/share/javax/media/j3d/J3DBuffer.java @@ -207,13 +207,8 @@ public class J3DBuffer { return bufferImpl; } - // Native method to verify that we can access a direct NIO buffer - // from native code - private native static long getNativeAddress(java.nio.Buffer buffer); - private static boolean checkNativeBufferAccess(java.nio.Buffer buffer) { - // TODO: uncomment out the call to getNativeAddress and implement it - if (buffer == null /*|| getNativeAddress(buffer) == 0L*/) { + if (buffer == null /*|| !Pipeline.getPipeline().checkNativeBufferAccess(buffer)*/) { return false; } else { diff --git a/src/classes/share/javax/media/j3d/J3DGraphics2DImpl.java b/src/classes/share/javax/media/j3d/J3DGraphics2DImpl.java index d52381c..7521434 100644 --- a/src/classes/share/javax/media/j3d/J3DGraphics2DImpl.java +++ b/src/classes/share/javax/media/j3d/J3DGraphics2DImpl.java @@ -28,6 +28,7 @@ import java.awt.font.*; */ final class J3DGraphics2DImpl extends J3DGraphics2D { + private boolean hasBeenDisposed = false; private Graphics2D offScreenGraphics2D; private BufferedImage g3dImage = null; private byte[] data = null; @@ -45,9 +46,8 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { private Point2D.Float ptDst2 = new Point2D.Float(); private Color xOrModeColor = null; private volatile boolean initCtx = false; - private boolean threadWaiting = false; + private volatile boolean threadWaiting = false; static final Color blackTransparent = new Color(0,0,0,0); - private boolean useDrawPixel = VirtualUniverse.mc.isJ3dG2dDrawPixel; int objectId = -1; // Package scope contructor @@ -55,7 +55,7 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { canvas3d = c; synchronized (VirtualUniverse.mc.contextCreationLock) { - if (c.ctx == 0) { + if (c.ctx == null) { // create a dummy bufferImage width = 1; height = 1; @@ -117,6 +117,10 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { * rendering to be complete before returning from this call. */ public void flush(boolean waiting) { + + if (hasBeenDisposed) { + throw new IllegalStateException(J3dI18N.getString("J3DGraphics2D0")); + } if (!isFlushed) { // Composite g3dImage into Canvas3D @@ -162,8 +166,10 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { // copy the data into a byte buffer that will be passed to opengl void doFlush() { + assert !hasBeenDisposed; + // clip to offscreen buffer size - if (canvas3d.ctx == 0) { + if (canvas3d.ctx == null) { canvas3d.getGraphicsContext3D().doClear(); } @@ -208,7 +214,10 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { final void copyImage(BufferedImage bi, byte[] image, int width, int height, int x1, int y1, int x2, int y2) { - int biType = bi.getType(); + + assert !hasBeenDisposed; + + int biType = bi.getType(); int w, h, i, j; int row, rowBegin, rowInc, dstBegin; @@ -286,7 +295,7 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { void sendRenderMessage(boolean renderRun, int command, Object arg1, Object arg2, Object arg3) { // send a message to the request renderer - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); + J3dMessage renderMessage = new J3dMessage(); renderMessage.threads = J3dThread.RENDER_THREAD; renderMessage.type = J3dMessage.RENDER_IMMEDIATE; renderMessage.universe = null; @@ -575,10 +584,6 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { offScreenGraphics2D.copyArea(x, y, width, height, dx, dy); } - public final void dispose() { - offScreenGraphics2D.dispose(); - } - public final void draw(Shape s) { Rectangle rect = s.getBounds(); validate(rect.x, rect.y, @@ -867,17 +872,52 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { offScreenGraphics2D.fillRect(x, y, width, height); } - public void finalize() { - if (objectId >= 0) { - VirtualUniverse.mc.freeTexture2DId(objectId); - } - offScreenGraphics2D.finalize(); + // Issue 121 - release all resources, mark as disposed + public void dispose() { + + if (Thread.currentThread() == canvas3d.screen.renderer) { + doDispose(); + } else { + // Behavior Scheduler or other threads + // XXXX: may not be legal for behaviorScheduler + // May cause deadlock if it is in behaviorScheduler + // and we wait for Renderer to finish + boolean renderRun = (Thread.currentThread() != + canvas3d.view.universe.behaviorScheduler); + sendRenderMessage(renderRun, GraphicsContext3D.DISPOSE2D, + null, null, null); + } + + + } + + public void doDispose() { + + if (hasBeenDisposed) { + return; + } + + if (objectId != -1) { + canvas3d.freeTexture(canvas3d.ctx, objectId); + VirtualUniverse.mc.freeTexture2DId(objectId); + objectId = -1; + } + + // Dispose of the underlying Graphics2D + offScreenGraphics2D.dispose(); + + // Mark as disposed + hasBeenDisposed = true; } public void drawAndFlushImage(BufferedImage img, int x, int y, ImageObserver observer) { - if (!(initCtx && abgr && + if (hasBeenDisposed) { + throw new IllegalStateException(J3dI18N.getString("J3DGraphics2D0")); + } + + if (!(initCtx && abgr && (img.getType() == BufferedImage.TYPE_4BYTE_ABGR))) { drawImage(img, x, y, observer); flush(false); @@ -900,11 +940,14 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { void doDrawAndFlushImage(BufferedImage img, int x, int y, ImageObserver observer) { - int imgWidth = img.getWidth(observer); + + assert !hasBeenDisposed; + + int imgWidth = img.getWidth(observer); int imgHeight = img.getHeight(observer); int px, py, x1, y1, x2, y2; - if (canvas3d.ctx == 0) { + if (canvas3d.ctx == null) { canvas3d.getGraphicsContext3D().doClear(); } @@ -961,50 +1004,41 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { try { if (!canvas3d.drawingSurfaceObject.renderLock()) { return; - } + } + + if (!initTexMap) { + if (objectId == -1) { + objectId = VirtualUniverse.mc.getTexture2DId(); + } + texWidth = getGreaterPowerOf2(w); + texHeight = getGreaterPowerOf2(h); + + // Canvas got resize, need to init texture map again + // in Renderer thread + if (!canvas3d.initTexturemapping(canvas3d.ctx, + texWidth, texHeight, + objectId)) { + // Fail to get the texture surface, most likely + // there is not enough texture memory + initTexMap = false; + VirtualUniverse.mc.freeTexture2DId(objectId); + objectId = -1; + // TODO : Need to find a better way to report no resource problem --- Chien. + System.err.println("J3DGraphics2DImpl.copyDataToCanvas() : Fail to get texture resources ..."); + + } else { + initTexMap = true; + } + } + if (initTexMap) { + canvas3d.texturemapping(canvas3d.ctx, px, py, + x1, y1, x2, y2, + texWidth, texHeight, w, + (abgr ? ImageComponentRetained.TYPE_BYTE_ABGR: + ImageComponentRetained.TYPE_BYTE_RGBA), + objectId, data, width, height); + } - if (useDrawPixel) { - canvas3d.composite(canvas3d.ctx, px, py, - x1, y1, x2, y2, w, data, width, height); - } else { - if (!initTexMap) { - if (objectId == -1) { - objectId = VirtualUniverse.mc.getTexture2DId(); - } - texWidth = getGreaterPowerOf2(w); - texHeight = getGreaterPowerOf2(h); - - // Canvas got resize, need to init texture map again - // in Renderer thread - if (!canvas3d.initTexturemapping(canvas3d.ctx, - texWidth, texHeight, - objectId)) { - // Fail to get the texture surface, most likely - // there is not enough texture memory - initTexMap = false; - VirtualUniverse.mc.freeTexture2DId(objectId); - objectId = -1; - // Use DrawPixel next time - useDrawPixel = true; - } else { - initTexMap = true; - } - } - if (initTexMap) { - canvas3d.texturemapping(canvas3d.ctx, px, py, - x1, y1, x2, y2, - texWidth, texHeight, w, - (abgr ? ImageComponentRetained.BYTE_ABGR: - ImageComponentRetained.BYTE_RGBA), - objectId, data, width, height); - } else { - // Fall back to composite for this round - canvas3d.composite(canvas3d.ctx, px, py, - x1, y1, x2, y2, w, data, - width, height); - - } - } canvas3d.drawingSurfaceObject.unLock(); } catch (NullPointerException ne) { canvas3d.drawingSurfaceObject.unLock(); @@ -1043,7 +1077,8 @@ final class J3DGraphics2DImpl extends J3DGraphics2D { */ synchronized void runMonitor(int action) { if (action == J3dThread.WAIT) { - if (threadWaiting) { + // Issue 279 - loop until ready + while (threadWaiting) { try { wait(); } catch (InterruptedException e){} diff --git a/src/classes/share/javax/media/j3d/J3dClock.java b/src/classes/share/javax/media/j3d/J3dClock.java index 307f988..438b945 100644 --- a/src/classes/share/javax/media/j3d/J3dClock.java +++ b/src/classes/share/javax/media/j3d/J3dClock.java @@ -27,16 +27,6 @@ class J3dClock { private J3dClock() { } - /** - * Method to return a high-resolution timer value. - * - * NOTE: when we no longer support JDK 1.4.2 we can replace this - * method with System.nanoTime(). - */ - private static long getHiResTimerValue() { - return MasterControl.getNativeTimerValue(); - } - /** * Returns the current time in milliseconds. This is a more * accurate version of System.currentTimeMillis and should be used in @@ -45,19 +35,15 @@ class J3dClock { * @return the current time in milliseconds. */ static long currentTimeMillis() { - return (getHiResTimerValue() / nsecPerMsec) + deltaTime; + return (System.nanoTime() / nsecPerMsec) + deltaTime; } static { - // Ensure that the native libraries are loaded (this can be removed - // once we switch to using System.nanoTime() - VirtualUniverse.loadLibraries(); - // Call time methods once without using their values to ensure that // the methods are "warmed up". We need to make sure that the actual // calls that we use take place as close together as possible in time. System.currentTimeMillis(); - getHiResTimerValue(); + System.nanoTime(); // Compute deltaTime between System.currentTimeMillis() // and the high-res timer, use a synchronized block to force both calls @@ -65,7 +51,7 @@ class J3dClock { long baseTime, baseTimerValue; synchronized (J3dClock.class) { baseTime = System.currentTimeMillis(); - baseTimerValue = getHiResTimerValue(); + baseTimerValue = System.nanoTime(); } deltaTime = baseTime - (baseTimerValue / nsecPerMsec); } diff --git a/src/classes/share/javax/media/j3d/J3dMessage.java b/src/classes/share/javax/media/j3d/J3dMessage.java index 41fa2bc..0838c54 100644 --- a/src/classes/share/javax/media/j3d/J3dMessage.java +++ b/src/classes/share/javax/media/j3d/J3dMessage.java @@ -160,8 +160,7 @@ class J3dMessage extends Object { final synchronized void decRefcount() { if (--refcount == 0) { clear(); - FreeListManager.freeObject(FreeListManager.MESSAGE, this); - } + } } final synchronized int getRefcount() { diff --git a/src/classes/share/javax/media/j3d/J3dNotification.java b/src/classes/share/javax/media/j3d/J3dNotification.java index 807cadf..34ba699 100644 --- a/src/classes/share/javax/media/j3d/J3dNotification.java +++ b/src/classes/share/javax/media/j3d/J3dNotification.java @@ -22,6 +22,7 @@ class J3dNotification extends Object { */ static final int INVALID_TYPE = -1; static final int SHADER_ERROR = 0; + static final int RENDERING_ERROR = 1; /** * This holds the type of this message @@ -39,4 +40,5 @@ class J3dNotification extends Object { static final int MAX_ARGS = 6; Object[] args = new Object[MAX_ARGS]; + } diff --git a/src/classes/share/javax/media/j3d/J3dThread.java b/src/classes/share/javax/media/j3d/J3dThread.java index c585d62..a650ded 100644 --- a/src/classes/share/javax/media/j3d/J3dThread.java +++ b/src/classes/share/javax/media/j3d/J3dThread.java @@ -76,7 +76,13 @@ abstract class J3dThread extends Thread { /** * This indicates that this thread is alive and running */ - private boolean running = true; + private volatile boolean running = true; + + /** + * This flag is set by the RUN action of runMonitor to indicate that the + * waiting thread has work to do. + */ + private volatile boolean ready = false; /** * The thread data for this thread @@ -84,7 +90,7 @@ abstract class J3dThread extends Thread { private J3dThreadData[] data = null; /** - * This indicates that this thread is ready + * This indicates that this thread is started and able to accept work */ private volatile boolean started = false; @@ -121,7 +127,7 @@ abstract class J3dThread extends Thread { /** * Flag to indicate that this thread is waiting to be notify */ - volatile boolean waiting = false; + private volatile boolean waiting = false; /** * Some variables used to name threads correctly @@ -220,7 +226,7 @@ abstract class J3dThread extends Thread { /** * This initializes this thread. Once this method returns, the thread is - * ready to do work. + * able to accept work. */ void initialize() { this.start(); @@ -233,11 +239,11 @@ abstract class J3dThread extends Thread { * This causes the threads run method to exit. */ void finish() { + // NOTE: This spin loop is probably not necessary. while (!waiting) { MasterControl.threadYield(); } runMonitor(STOP, 0,null); - } /** @@ -257,36 +263,52 @@ abstract class J3dThread extends Thread { synchronized void runMonitor(int action, long referenceTime, Object[] args) { switch (action) { - case WAIT: - try { - started = true; - waiting = true; - wait(); - } catch (InterruptedException e) { - System.err.println(e); + case WAIT: + started = true; + // Issue 279 - loop until ready + while (!ready && running) { + waiting = true; + try { + wait(); + } catch (InterruptedException e) { + System.err.println(e); + } + waiting = false; } - waiting = false; + ready = false; break; - case NOTIFY_AND_WAIT: + + case NOTIFY_AND_WAIT: VirtualUniverse.mc.runMonitor(MasterControl.THREAD_DONE, null, - null, null, this); - try { - waiting = true; - wait(); - } catch (InterruptedException e) { - System.err.println(e); + null, null, this); + // Issue 279 - loop until ready + while (!ready && running) { + waiting = true; + try { + wait(); + } catch (InterruptedException e) { + System.err.println(e); + } + waiting = false; } - waiting = false; + ready = false; break; - case RUN: - this.referenceTime = referenceTime; - this.args = args; - notify(); + + case RUN: + this.referenceTime = referenceTime; + this.args = args; + ready = true; + if (waiting) { + notify(); + } + break; + + case STOP: + running = false; + if (waiting) { + notify(); + } break; - case STOP: - running = false; - notify(); - break; } } @@ -303,6 +325,7 @@ abstract class J3dThread extends Thread { void cleanup() { active = false; running = true; + ready = false; data = null; started = true; lastWaitTimestamp = 0; diff --git a/src/classes/share/javax/media/j3d/LightBin.java b/src/classes/share/javax/media/j3d/LightBin.java index a92e638..51d4aab 100644 --- a/src/classes/share/javax/media/j3d/LightBin.java +++ b/src/classes/share/javax/media/j3d/LightBin.java @@ -338,8 +338,7 @@ class LightBin extends Object implements ObjectUpdate { } e.prev = null; e.next = null; - renderBin.envSetFreelist.add(e); - + if (environmentSetList == null && insertEnvSet.size() == 0) { renderBin.removeLightBin(this); geometryBackground = null; diff --git a/src/classes/share/javax/media/j3d/LightRetained.java b/src/classes/share/javax/media/j3d/LightRetained.java index 9126311..e4b7766 100644 --- a/src/classes/share/javax/media/j3d/LightRetained.java +++ b/src/classes/share/javax/media/j3d/LightRetained.java @@ -209,7 +209,7 @@ abstract class LightRetained extends LeafRetained { initScope(scope, index); - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); scopeInfo[0] = addScopeList; scopeInfo[1] = removeScopeList; scopeInfo[2] = (scopes.size() > 0 ? Boolean.TRUE: Boolean.FALSE); @@ -560,7 +560,7 @@ abstract class LightRetained extends LeafRetained { * This method is implemented by each light for rendering * context updates. This default one does nothing. */ - abstract void update(long ctx, int lightSlot, double scale); + abstract void update(Context ctx, int lightSlot, double scale); // This routine is called when rendering Env structure @@ -847,7 +847,7 @@ abstract class LightRetained extends LeafRetained { } J3dMessage initMessage(int num) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.LIGHT_CHANGED; @@ -952,7 +952,7 @@ abstract class LightRetained extends LeafRetained { if (scopes.size() > 0) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); LightRetained[] mlts = new LightRetained[newlyAddedMirrorLights.size()]; for (int i = 0; i < mlts.length; i++) { mlts[i] = (LightRetained)newlyAddedMirrorLights.get(i); @@ -1036,7 +1036,7 @@ abstract class LightRetained extends LeafRetained { } void sendMessage(int attrMask, Object attr) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.LIGHT_CHANGED; createMessage.universe = universe; diff --git a/src/classes/share/javax/media/j3d/LineAttributesRetained.java b/src/classes/share/javax/media/j3d/LineAttributesRetained.java index a82228a..5765db9 100644 --- a/src/classes/share/javax/media/j3d/LineAttributesRetained.java +++ b/src/classes/share/javax/media/j3d/LineAttributesRetained.java @@ -214,22 +214,13 @@ class LineAttributesRetained extends NodeComponentRetained { } - /** - * This (native) method updates the native context. - */ - native void updateNative(long ctx, - float lineWidth, int linePattern, - int linePatternMask, - int linePatternScaleFactor, - boolean lineAntialiasing); - /** * This method updates the native context. */ - void updateNative(long ctx) { - updateNative(ctx, - lineWidth, linePattern, linePatternMask, - linePatternScaleFactor, lineAntialiasing); + void updateNative(Context ctx) { + Pipeline.getPipeline().updateLineAttributes(ctx, + lineWidth, linePattern, linePatternMask, + linePatternScaleFactor, lineAntialiasing); } @@ -292,7 +283,7 @@ class LineAttributesRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.LINEATTRIBUTES_CHANGED; createMessage.universe = null; @@ -305,7 +296,7 @@ class LineAttributesRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; ibefore * the MasterControl object is created. */ static void loadLibraries() { assert !librariesLoaded; - // This works around a native load library bug - try { - java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); - toolkit = null; // just making sure GC collects this - } catch (java.awt.AWTError e) { - } - - // Load the JAWT native library - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - System.loadLibrary("jawt"); - return null; - } - }); - - // Load the native J3D library - final String oglLibraryName = "j3dcore-ogl"; - final String d3dLibraryName = "j3dcore-d3d"; - final String libraryName = (String) - java.security.AccessController.doPrivileged(new - java.security.PrivilegedAction() { - public Object run() { - String libName = oglLibraryName; - - // If it is a Windows OS, we want to support dynamic native library selection (ogl, d3d) - String osName = System.getProperty("os.name"); - if (osName != null && osName.startsWith("Windows")) { - // XXXX : Should eventually support a more flexible dynamic - // selection scheme via an API call. - String str = System.getProperty("j3d.rend"); - if (str != null && str.equals("d3d")) { - libName = d3dLibraryName; - } - } + // Set global flags indicating whether we are running on Windows or MacOS + String osName = getProperty("os.name"); + isWindowsOs = osName != null && osName.startsWith("Windows"); + isMacOs = osName != null && osName.startsWith("Mac"); + +//KCR: System.err.println("MasterControl.loadLibraries()"); +//KCR: System.err.println(" osName = \"" + osName + "\"" + +//KCR: ", isWindowsOs = " + isWindowsOs + +//KCR: ", isMacOs = " + isMacOs); + + // Initialize the Pipeline object associated with the + // renderer specified by the "j3d.rend" system property. + // + // XXXX : We should consider adding support for a more flexible, + // dynamic selection scheme via an API call. + + // Default rendering pipeline is the JOGL pipeline on MacOS and the + // native OpenGL pipeline on all other platforms. + Pipeline.Type pipelineType = + isMacOs ? Pipeline.Type.JOGL : Pipeline.Type.NATIVE_OGL; + + String rendStr = getProperty("j3d.rend"); + if (rendStr == null) { + // Use default pipeline + } else if (rendStr.equals("ogl") && !isMacOs) { + pipelineType = Pipeline.Type.NATIVE_OGL; + } else if (rendStr.equals("d3d") && isWindowsOs) { + pipelineType = Pipeline.Type.NATIVE_D3D; + } else if (rendStr.equals("jogl")) { + pipelineType = Pipeline.Type.JOGL; + } else if (rendStr.equals("noop")) { + pipelineType = Pipeline.Type.NOOP; + } else { + System.err.println("Java 3D: Unrecognized renderer: " + rendStr); + // Use default pipeline + } - System.loadLibrary(libName); - return libName; - } - }); +//KCR: System.err.println(" using " + pipelineType + " pipeline"); + + // Construct the singleton Pipeline instance + Pipeline.createPipeline(pipelineType); + + // Get the global j3d.shadingLanguage system property + final String slStr = getProperty("j3d.shadingLanguage"); + if (slStr != null) { + boolean found = false; + if (slStr.equals("GLSL")) { + globalShadingLanguage = Shader.SHADING_LANGUAGE_GLSL; + found = true; + } else if (slStr.equals("Cg")) { + globalShadingLanguage = Shader.SHADING_LANGUAGE_CG; + found = true; + } - // Get the global j3d.shadingLanguage property - final String slStr = getProperty("j3d.shadingLanguage"); - if (slStr != null) { - boolean found = false; - if (slStr.equals("GLSL")) { - globalShadingLanguage = Shader.SHADING_LANGUAGE_GLSL; - found = true; - } - else if (slStr.equals("Cg")) { - globalShadingLanguage = Shader.SHADING_LANGUAGE_CG; - found = true; - } + if (found) { + System.err.println("Java 3D: Setting global shading language to " + slStr); + } else { + System.err.println("Java 3D: Unrecognized shading language: " + slStr); + } + } - if (found) { - System.err.println("Java 3D: Setting global shading language to " + slStr); - } - else { - System.err.println("Java 3D: Unrecognized shading language: " + slStr); - } - } + // Load all required libraries + Pipeline.getPipeline().loadLibraries(globalShadingLanguage); // Check whether the Cg library is available if (globalShadingLanguage == Shader.SHADING_LANGUAGE_CG) { - String cgLibraryName = libraryName + "-cg"; - String[] libpath = setupLibPath(systemPathProps, cgLibraryName); - if (loadNativeCgLibrary(libpath)) { - cgLibraryAvailable = true; - } + cgLibraryAvailable = Pipeline.getPipeline().isCgLibraryAvailable(); } - + // Check whether the GLSL library is available if (globalShadingLanguage == Shader.SHADING_LANGUAGE_GLSL) { - if (libraryName == oglLibraryName) { - // No need to verify that GLSL is available, since GLSL is part - // of OpenGL as an extension (or part of core in 2.0) - glslLibraryAvailable = true; - } + glslLibraryAvailable = Pipeline.getPipeline().isGLSLLibraryAvailable(); } assert !(glslLibraryAvailable && cgLibraryAvailable) : @@ -878,46 +801,6 @@ class MasterControl { } - /** - * Parse the specified System properties containing a PATH and return an - * array of Strings, where each element is an absolute filename consisting of - * the individual component of the path concatenated with the (relative) - * library file name. Only those absolute filenames that exist are included. - * If no absolute filename is found, we will try the relative library name. - */ - private static String[] setupLibPath(String[] props, String libName) { - ArrayList pathList = new ArrayList(); - - String filename = System.mapLibraryName(libName); - for (int n = 0; n < props.length; n++) { - String pathString = getProperty(props[n]); - boolean done = false; - int posStart = 0; - while (!done) { - int posEnd = pathString.indexOf(File.pathSeparator, posStart); - if (posEnd == -1) { - posEnd = pathString.length(); - done = true; - } - String pathDir = pathString.substring(posStart, posEnd); - File pathFile = new File(pathDir, filename); - if (pathFile.exists()) { - pathList.add(pathFile.getAbsolutePath()); - } - - posStart = posEnd + 1; - } - } - - // If no absolute path names exist, add in the relative library name - if (pathList.size() == 0) { - pathList.add(filename); - } - - return (String[])pathList.toArray(new String[0]); - } - - /** * Invoke from InputDeviceScheduler to create an * InputDeviceBlockingThread. @@ -997,8 +880,7 @@ class MasterControl { * This returns the a unused displayListId */ Integer getDisplayListId() { - return (Integer) - FreeListManager.getObject(FreeListManager.DISPLAYLIST); + return (Integer) FreeListManager.getObject(FreeListManager.DISPLAYLIST); } void freeDisplayListId(Integer id) { @@ -1017,11 +899,12 @@ class MasterControl { synchronized (textureIdLock) { if (textureIds.size() > 0) { - return ((Integer)FreeListManager. + id = ((Integer)FreeListManager. getObject(FreeListManager.TEXTURE2D)).intValue(); } else { - return (++textureIdCount); + id = (++textureIdCount); } + return id; } } @@ -1079,72 +962,6 @@ class MasterControl { } } } - - Transform3D getTransform3D(Transform3D val) { - Transform3D t; - t = (Transform3D) - FreeListManager.getObject(FreeListManager.TRANSFORM3D); - if (val != null) t.set(val); - return t; - } - - void addToTransformFreeList(Transform3D t) { - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t); - } - - - ImageComponentUpdateInfo getFreeImageUpdateInfo() { - ImageComponentUpdateInfo info; - - synchronized (imageUpdateInfoList) { - if (numFreeImageUpdateInfo > 0) { - numFreeImageUpdateInfo--; - info = (ImageComponentUpdateInfo) - imageUpdateInfoList[numFreeImageUpdateInfo]; - } else { - info = new ImageComponentUpdateInfo(); - } - } - return (info); - } - - void addFreeImageUpdateInfo(ImageComponentUpdateInfo info) { - synchronized (imageUpdateInfoList) { - if (imageUpdateInfoList.length == numFreeImageUpdateInfo) { - ImageComponentUpdateInfo[] newFreeList = - new ImageComponentUpdateInfo[numFreeImageUpdateInfo * 2]; - System.arraycopy(imageUpdateInfoList, 0, newFreeList, 0, - numFreeImageUpdateInfo); - newFreeList[numFreeImageUpdateInfo++] = info; - imageUpdateInfoList = newFreeList; - } else { - imageUpdateInfoList[numFreeImageUpdateInfo++] = info; - } - } - } - - void addFreeImageUpdateInfo(ArrayList freeList) { - ImageComponentUpdateInfo info; - - synchronized (imageUpdateInfoList) { - int len = numFreeImageUpdateInfo + freeList.size(); - - if (imageUpdateInfoList.length <= len) { - ImageComponentUpdateInfo[] newFreeList = - new ImageComponentUpdateInfo[len * 2]; - System.arraycopy(imageUpdateInfoList, 0, newFreeList, 0, - numFreeImageUpdateInfo); - imageUpdateInfoList = newFreeList; - } - - for (int i = 0; i < freeList.size(); i++) { - info = (ImageComponentUpdateInfo) freeList.get(i); - if (info != null) { - imageUpdateInfoList[numFreeImageUpdateInfo++] = info; - } - } - } - } /** @@ -1270,77 +1087,29 @@ class MasterControl { } /** - * Returns the native rendering layer we are using + * Returns whether we are using D3D. + * TODO: most code that cares about this should move into the pipeline */ - final int getRenderingAPI() { - return renderingAPI; - } - final boolean isD3D() { - return isD3DAPI; + return Pipeline.getPipeline().getPipelineType() == Pipeline.Type.NATIVE_D3D; } /** - * This method increments and returns the next time value - * timeLock must get before this procedure is invoked + * Returns whether we are running on Windows + * TODO: most code that cares about this should move into the pipeline */ - final long getTime() { - return (time++); + final boolean isWindows() { + return isWindowsOs; } - - - /** - * This adds a BHNode to one of the list of BHNodes - */ - void addBHNodeToFreelists(BHNode bH) { - bH.parent = null; - bH.mark = false; - - if (bH.nodeType == BHNode.BH_TYPE_INTERNAL) { - ((BHInternalNode)bH).lChild = null; - ((BHInternalNode)bH).rChild = null; - FreeListManager.freeObject(FreeListManager.BHINTERNAL, bH); - } - else if (bH.nodeType == BHNode.BH_TYPE_LEAF) { - ((BHLeafNode)(bH)).leafIF = null; - FreeListManager.freeObject(FreeListManager.BHLEAF, bH); - } - } - /** - * This gets a message from the free list. If there isn't any, - * it creates one. + * This method increments and returns the next time value + * timeLock must get before this procedure is invoked */ - BHNode getBHNode(int type) { - - if (type == BHNode.BH_TYPE_LEAF) { - return (BHNode) FreeListManager.getObject(FreeListManager.BHLEAF); - } - - if (type == BHNode.BH_TYPE_INTERNAL) { - return (BHNode) - FreeListManager.getObject(FreeListManager.BHINTERNAL); - } - return null; + final long getTime() { + return (time++); } - - /** - * This adds a message to the list of messages - */ - final void addMessageToFreelists(J3dMessage m) { - FreeListManager.freeObject(FreeListManager.MESSAGE, m); - } - - /** - * This gets a message from the free list. If there isn't any, - * it creates one. - */ - final J3dMessage getMessage() { - return (J3dMessage) FreeListManager.getObject(FreeListManager.MESSAGE); - } - /** * This takes a given message and parses it out to the structures and @@ -1493,7 +1262,6 @@ class MasterControl { if (message.getRefcount() == 0) { message.clear(); - addMessageToFreelists(message); } } } @@ -1685,183 +1453,189 @@ class MasterControl { } /** - * This snapshots the time values to be used for this iteration + * This snapshots the time values to be used for this iteration. + * Note that this method is called without the timeLock held. + * We must synchronize on timeLock to prevent updating + * thread.lastUpdateTime from user thread in sendMessage() + * or sendRunMessage(). */ private void updateTimeValues() { - int i=0; - J3dThreadData lastThread=null; - J3dThreadData thread=null; - long lastTime = currentTime; - - currentTime = getTime(); - - J3dThreadData threads[] = (J3dThreadData []) - stateWorkThreads.toArray(false); - int size = stateWorkThreads.arraySize(); - - while (i thread.lastRunTime) && - !thread.thread.userStop) { - lastThread = thread; - thread.needsRun = true; - thread.threadOpts = J3dThreadData.CONT_THREAD; - thread.lastRunTime = currentTime; - } else { - thread.needsRun = false; - } - } - - if (lastThread != null) { - lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; - lastThread = null; - } - - while (i thread.lastRunTime) && - !thread.thread.userStop) { - lastThread = thread; - thread.needsRun = true; - thread.threadOpts = J3dThreadData.CONT_THREAD; - thread.lastRunTime = currentTime; - } else { - thread.needsRun = false; - } - } - if (lastThread != null) { - lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; - lastThread = null; - } - - while (i thread.lastRunTime) && - !thread.thread.userStop) { - lastThread = thread; - thread.needsRun = true; - thread.threadOpts = J3dThreadData.CONT_THREAD; - thread.lastRunTime = currentTime; - } else { - thread.needsRun = false; - } - } - if (lastThread != null) { - lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; - lastThread = null; - } - + synchronized (timeLock) { + int i=0; + J3dThreadData lastThread=null; + J3dThreadData thread=null; + long lastTime = currentTime; + + currentTime = getTime(); + + J3dThreadData threads[] = (J3dThreadData []) + stateWorkThreads.toArray(false); + int size = stateWorkThreads.arraySize(); + + while (i thread.lastRunTime) && + !thread.thread.userStop) { + lastThread = thread; + thread.needsRun = true; + thread.threadOpts = J3dThreadData.CONT_THREAD; + thread.lastRunTime = currentTime; + } else { + thread.needsRun = false; + } + } - threads = (J3dThreadData []) renderWorkThreads.toArray(false); - size = renderWorkThreads.arraySize(); - View v; - J3dThreadData lastRunThread = null; - waitTimestamp++; - sleepTime = 0L; - - boolean threadToRun = false; // Not currently used - - // Fix for Issue 12: loop through the list of threads, calling - // computeCycleTime() exactly once per view. This ensures that - // all threads for a given view see consistent values for - // isMinCycleTimeAchieve and sleepTime. - v = null; - for (i=0; i sleepTime) { - sleepTime = thread.view.sleepTime; - } - } - v = thread.view; - } + if (lastThread != null) { + lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; + lastThread = null; + } - v = null; - for (i=0; i thread.lastRunTime) && - !thread.thread.userStop) { - - if (thread.thread.lastWaitTimestamp == waitTimestamp) { - // This renderer thread is repeated. We must wait - // until all previous renderer threads done before - // allowing this thread to continue. Note that - // lastRunThread can't be null in this case. - waitTimestamp++; - if (thread.view != v) { - // A new View is start - v = thread.view; - threadToRun = true; - lastRunThread.threadOpts = - (J3dThreadData.STOP_TIMER | - J3dThreadData.WAIT_ALL_THREADS); - ((Object []) lastRunThread.threadArgs)[3] = lastRunThread.view; - thread.threadOpts = (J3dThreadData.START_TIMER | - J3dThreadData.CONT_THREAD); - } else { - if ((lastRunThread.threadOpts & - J3dThreadData.START_TIMER) != 0) { - lastRunThread.threadOpts = - (J3dThreadData.START_TIMER | - J3dThreadData.WAIT_ALL_THREADS); - - } else { - lastRunThread.threadOpts = - J3dThreadData.WAIT_ALL_THREADS; - } - thread.threadOpts = J3dThreadData.CONT_THREAD; - - } - } else { - if (thread.view != v) { - v = thread.view; - threadToRun = true; - // Although the renderer thread is not - // repeated. We still need to wait all - // previous renderer threads if new View - // start. - if (lastRunThread != null) { - lastRunThread.threadOpts = - (J3dThreadData.STOP_TIMER | - J3dThreadData.WAIT_ALL_THREADS); - ((Object []) lastRunThread.threadArgs)[3] - = lastRunThread.view; - } - thread.threadOpts = (J3dThreadData.START_TIMER | - J3dThreadData.CONT_THREAD); - } else { - thread.threadOpts = J3dThreadData.CONT_THREAD; - } - } - thread.thread.lastWaitTimestamp = waitTimestamp; - thread.needsRun = true; - thread.lastRunTime = currentTime; - lastRunThread = thread; - } else { - thread.needsRun = false; - } - } + while (i thread.lastRunTime) && + !thread.thread.userStop) { + lastThread = thread; + thread.needsRun = true; + thread.threadOpts = J3dThreadData.CONT_THREAD; + thread.lastRunTime = currentTime; + } else { + thread.needsRun = false; + } + } + if (lastThread != null) { + lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; + lastThread = null; + } + while (i thread.lastRunTime) && + !thread.thread.userStop) { + lastThread = thread; + thread.needsRun = true; + thread.threadOpts = J3dThreadData.CONT_THREAD; + thread.lastRunTime = currentTime; + } else { + thread.needsRun = false; + } + } + if (lastThread != null) { + lastThread.threadOpts = J3dThreadData.WAIT_ALL_THREADS; + lastThread = null; + } - if (lastRunThread != null) { - lastRunThread.threadOpts = - (J3dThreadData.STOP_TIMER | - J3dThreadData.WAIT_ALL_THREADS| - J3dThreadData.LAST_STOP_TIMER); - lockGeometry = true; - ((Object []) lastRunThread.threadArgs)[3] = lastRunThread.view; - } else { - lockGeometry = false; - } - + threads = (J3dThreadData []) renderWorkThreads.toArray(false); + size = renderWorkThreads.arraySize(); + View v; + J3dThreadData lastRunThread = null; + waitTimestamp++; + sleepTime = 0L; + + boolean threadToRun = false; // Not currently used + + // Fix for Issue 12: loop through the list of threads, calling + // computeCycleTime() exactly once per view. This ensures that + // all threads for a given view see consistent values for + // isMinCycleTimeAchieve and sleepTime. + v = null; + for (i=0; i sleepTime) { + sleepTime = thread.view.sleepTime; + } + } + v = thread.view; + } + + v = null; + for (i=0; i thread.lastRunTime) && + !thread.thread.userStop) { + + if (thread.thread.lastWaitTimestamp == waitTimestamp) { + // This renderer thread is repeated. We must wait + // until all previous renderer threads done before + // allowing this thread to continue. Note that + // lastRunThread can't be null in this case. + waitTimestamp++; + if (thread.view != v) { + // A new View is start + v = thread.view; + threadToRun = true; + lastRunThread.threadOpts = + (J3dThreadData.STOP_TIMER | + J3dThreadData.WAIT_ALL_THREADS); + ((Object []) lastRunThread.threadArgs)[3] = lastRunThread.view; + thread.threadOpts = (J3dThreadData.START_TIMER | + J3dThreadData.CONT_THREAD); + } else { + if ((lastRunThread.threadOpts & + J3dThreadData.START_TIMER) != 0) { + lastRunThread.threadOpts = + (J3dThreadData.START_TIMER | + J3dThreadData.WAIT_ALL_THREADS); + + } else { + lastRunThread.threadOpts = + J3dThreadData.WAIT_ALL_THREADS; + } + thread.threadOpts = J3dThreadData.CONT_THREAD; + + } + } else { + if (thread.view != v) { + v = thread.view; + threadToRun = true; + // Although the renderer thread is not + // repeated. We still need to wait all + // previous renderer threads if new View + // start. + if (lastRunThread != null) { + lastRunThread.threadOpts = + (J3dThreadData.STOP_TIMER | + J3dThreadData.WAIT_ALL_THREADS); + ((Object []) lastRunThread.threadArgs)[3] + = lastRunThread.view; + } + thread.threadOpts = (J3dThreadData.START_TIMER | + J3dThreadData.CONT_THREAD); + } else { + thread.threadOpts = J3dThreadData.CONT_THREAD; + } + } + thread.thread.lastWaitTimestamp = waitTimestamp; + thread.needsRun = true; + thread.lastRunTime = currentTime; + lastRunThread = thread; + } else { + thread.needsRun = false; + } + } + + + if (lastRunThread != null) { + lastRunThread.threadOpts = + (J3dThreadData.STOP_TIMER | + J3dThreadData.WAIT_ALL_THREADS| + J3dThreadData.LAST_STOP_TIMER); + lockGeometry = true; + ((Object []) lastRunThread.threadArgs)[3] = lastRunThread.view; + } else { + lockGeometry = false; + } + } + + // Issue 275 - go to sleep without holding timeLock // Sleep for the amount of time needed to satisfy the minimum // cycle time for all views. if (sleepTime > 0) { @@ -1873,7 +1647,6 @@ class MasterControl { } // System.err.println("MasterControl: done sleeping"); } - } private void createUpdateThread(J3dStructure structure) { @@ -2162,7 +1935,6 @@ class MasterControl { } rdr.onScreen = null; rdr.offScreen = null; - } // cleanup ThreadData corresponds to the view in renderer @@ -2290,9 +2062,7 @@ class MasterControl { synchronized (VirtualUniverse.mc.deviceScreenMap) { deviceScreenMap.clear(); } - FreeListManager.clearList(FreeListManager.MESSAGE); - FreeListManager.clearList(FreeListManager.BHLEAF); - FreeListManager.clearList(FreeListManager.BHINTERNAL); + mirrorObjects.clear(); // Note: We should not clear the DISPLAYLIST/TEXTURE // list here because other structure may release them @@ -2306,7 +2076,6 @@ class MasterControl { renderOnceList.clear(); timestampUpdateList.clear(); - FreeListManager.clearList(FreeListManager.TRANSFORM3D); defaultRenderMethod = null; text3DRenderMethod = null; vertexArrayRenderMethod = null; @@ -2395,7 +2164,15 @@ class MasterControl { // offScreen canvases will be handled by the // request renderer, so don't add offScreen canvas // the render list - if (!cv.offScreen) { + // + // Issue 131: Automatic offscreen canvases need to + // be added to onscreen list. Special case. + // + // TODO KCR Issue 131: this should probably be + // changed to a list of screens since multiple + // off-screen canvases (either auto or manual) can + // be used by the same renderer + if (!cv.manualRendering) { screen.renderer.onScreen = screen; } else { screen.renderer.offScreen = screen; @@ -2866,7 +2643,8 @@ class MasterControl { for (int k=0; k < canvasList.length; k++) { if (j < canvasList[k].length) { Canvas3D cv = canvasList[k][j]; - if (cv.active && cv.isRunningStatus && !cv.offScreen) { + // Issue 131: setup renderer unless manualRendering + if (cv.active && cv.isRunningStatus && !cv.manualRendering ) { if (cv.screen.renderer == null) { continue; } @@ -2887,7 +2665,8 @@ class MasterControl { Canvas3D cv = canvasList[j][k]; // create swap thread only if there is at // least one active canvas - if (cv.active && cv.isRunningStatus && !cv.offScreen) { + // Issue 131: only if not manualRendering + if (cv.active && cv.isRunningStatus && !cv.manualRendering) { if (cv.screen.renderer == null) { // Should not happen continue; @@ -2988,7 +2767,7 @@ class MasterControl { void sendRenderMessage(GraphicsConfiguration gc, Object arg, Integer mtype) { Renderer rdr = createRenderer(gc); - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); + J3dMessage renderMessage = new J3dMessage(); renderMessage.threads = J3dThread.RENDER_THREAD; renderMessage.type = J3dMessage.RENDER_IMMEDIATE; renderMessage.universe = null; @@ -3011,12 +2790,16 @@ class MasterControl { // Assert the master control thread is created. J3dDebug.doAssert((mcThread != null), "mcThread != null"); Renderer rdr = createRenderer(c.graphicsConfiguration); - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.RENDER_THREAD; createMessage.type = J3dMessage.DESTROY_CTX_AND_OFFSCREENBUFFER; createMessage.universe = null; createMessage.view = null; createMessage.args[0] = c; + // Fix for issue 340: send display, drawable & ctx in msg + createMessage.args[1] = new Long(c.screen.display); + createMessage.args[2] = c.drawable; + createMessage.args[3] = c.ctx; rdr.rendererStructure.addMessage(createMessage); synchronized (requestObjList) { setWorkForRequestRenderer(); @@ -3051,7 +2834,7 @@ class MasterControl { // Fix for Issue 72 : call createRenderer rather than getting // the renderer from the canvas.screen object Renderer rdr = createRenderer(c.graphicsConfiguration); - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.RENDER_THREAD; createMessage.type = J3dMessage.CREATE_OFFSCREENBUFFER; createMessage.universe = null; @@ -3195,7 +2978,10 @@ class MasterControl { threadListsChanged = true; } } else if (type == START_RENDERER) { - ((Canvas3D) o).isRunningStatus = true; + Canvas3D c3d = (Canvas3D) o; + if (!c3d.isFatalError()) { + c3d.isRunningStatus = true; + } threadListsChanged = true; } else if (type == STOP_RENDERER) { if (o instanceof Canvas3D) { @@ -3225,7 +3011,7 @@ class MasterControl { } rendererRun = true; } else if (type == FREE_DRAWING_SURFACE) { - DrawingSurfaceObjectAWT.freeDrawingSurface(o); + Pipeline.getPipeline().freeDrawingSurfaceNative(o); } else if (type == GETBESTCONFIG) { GraphicsConfiguration gc = ((GraphicsConfiguration []) ((GraphicsConfigTemplate3D) o).testCfg)[0]; @@ -3569,22 +3355,27 @@ class MasterControl { } } break; + case THREAD_DONE: if (state != WAITING_FOR_RENDERER_CLEANUP) { + threadPending--; - if (nthread.type == J3dThread.RENDER_THREAD) { + assert threadPending >= 0 : ("threadPending = " + threadPending); + if (nthread.type == J3dThread.RENDER_THREAD) { View v = (View) nthread.args[3]; if (v != null) { // STOP_TIMER v.stopTime = J3dClock.currentTimeMillis(); } - + if (--renderPending == 0) { renderWaiting = false; } + assert renderPending >= 0 : ("renderPending = " + renderPending); } else { if (--statePending == 0) { stateWaiting = false; } + assert statePending >= 0 : ("statePending = " + statePending); } if (state == WAITING_FOR_CPU || state == WAITING_FOR_THREADS) { notify(); @@ -3594,19 +3385,12 @@ class MasterControl { state = RUNNING; } break; - case WAIT_FOR_ALL: - while (threadPending != 0) { - state = WAITING_FOR_THREADS; - try { - wait(); - } catch (InterruptedException e) { - System.err.println(e); - } - } - break; + case CHECK_FOR_WORK: if (!workToDo) { state = SLEEPING; + // NOTE: this could wakeup spuriously (see issue 279), but it + // will not cause any problems. try { wait(); } catch (InterruptedException e) { @@ -3616,12 +3400,14 @@ class MasterControl { } workToDo = false; break; + case SET_WORK: workToDo = true; if (state == SLEEPING) { notify(); } break; + case SET_WORK_FOR_REQUEST_RENDERER: requestRenderWorkToDo = true; workToDo = true; @@ -3630,45 +3416,29 @@ class MasterControl { notify(); } break; + case RUN_RENDERER_CLEANUP: nthread.runMonitor(J3dThread.RUN, currentTime, rendererCleanupArgs); state = WAITING_FOR_RENDERER_CLEANUP; - try { - wait(); - } catch (InterruptedException e) { - System.err.println(e); - } + // Issue 279 - loop until state is set to running + while (state != RUNNING) { + try { + wait(); + } catch (InterruptedException e) { + System.err.println(e); + } + } break; - case SLEEP: - state = SLEEPING; - try { - wait(sleepTime); - } catch (InterruptedException e) { - System.err.println(e); - } + + default: + // Should never get here + assert false : "missing case in switch statement"; } } // Static initializer static { - /* - // Determine whether the JVM is version JDK1.5 or later. - // XXXX: replace this with code that checks for the existence - // of a class or method that is defined in 1.5, but not in 1.4 - String versionString = - (String) java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - return System.getProperty("java.version"); - } - }); - jvm15OrBetter = !(versionString.startsWith("1.4") || - versionString.startsWith("1.3") || - versionString.startsWith("1.2") || - versionString.startsWith("1.1")); - */ - // create ThreadGroup java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { @@ -3828,4 +3598,9 @@ class MasterControl { // even whether) we sleep } } + + // Return the number of available processors + private int getNumberOfProcessors() { + return Runtime.getRuntime().availableProcessors(); + } } diff --git a/src/classes/share/javax/media/j3d/MaterialRetained.java b/src/classes/share/javax/media/j3d/MaterialRetained.java index 06ddef8..4417aaa 100644 --- a/src/classes/share/javax/media/j3d/MaterialRetained.java +++ b/src/classes/share/javax/media/j3d/MaterialRetained.java @@ -409,21 +409,10 @@ class MaterialRetained extends NodeComponentRetained { /** * Updates the native context. */ - native void updateNative(long ctx, - float red, float green, float blue, float alpha, - float ared, float agreen, float ablue, - float ered, float egreen, float eblue, - float dred, float dgreen, float dblue, - float sred, float sgreen, float sblue, - float shininess, int colorTarget, boolean enable); - - /** - * Updates the native context. - */ - void updateNative(long ctx, + void updateNative(Context ctx, float red, float green, float blue, float alpha, boolean enableLighting) { - updateNative(ctx, red, green, blue, alpha, + Pipeline.getPipeline().updateMaterial(ctx, red, green, blue, alpha, ambientColor.x, ambientColor.y, ambientColor.z, emissiveColor.x, emissiveColor.y, emissiveColor.z, diffuseColor.x, diffuseColor.y, diffuseColor.z, @@ -516,7 +505,7 @@ class MaterialRetained extends NodeComponentRetained { ArrayList gaList = Shape3DRetained.getGeomAtomsList(mirror.users, univList); // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.MATERIAL_CHANGED; createMessage.universe = null; @@ -528,7 +517,7 @@ class MaterialRetained extends NodeComponentRetained { int size = univList.size(); for(int i=0; i 0) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.MODELCLIP_CHANGED; @@ -1026,7 +1023,7 @@ class ModelClipRetained extends LeafRetained { } final void sendMessage(int attrMask, Object attr1, Object attr2) { - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.MODELCLIP_CHANGED; createMessage.universe = universe; diff --git a/src/classes/share/javax/media/j3d/MorphRetained.java b/src/classes/share/javax/media/j3d/MorphRetained.java index a91567e..b063fb2 100644 --- a/src/classes/share/javax/media/j3d/MorphRetained.java +++ b/src/classes/share/javax/media/j3d/MorphRetained.java @@ -138,7 +138,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { if (source.isLive()) { // Notify Geometry Structure to set mirror shape collision // bound and check for collision - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.COLLISION_BOUND_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM; message.universe = universe; @@ -154,7 +154,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { void setBounds(Bounds bounds) { super.setBounds(bounds); if (source.isLive() && !boundsAutoCompute) { - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.REGION_BOUND_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | targetThreads; @@ -297,7 +297,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { shape.setMorphGeometry(morphedGeometryArray, mirrorShape3D); J3dMessage mChangeMessage = null; - mChangeMessage = VirtualUniverse.mc.getMessage(); + mChangeMessage = new J3dMessage(); mChangeMessage.type = J3dMessage.MORPH_CHANGED; mChangeMessage.threads = (J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_TRANSFORM); @@ -377,7 +377,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { else size = 1; J3dMessage[] createMessage = new J3dMessage[size]; - createMessage[0] = VirtualUniverse.mc.getMessage(); + createMessage[0] = new J3dMessage(); createMessage[0].threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT | J3dThread.UPDATE_RENDER; createMessage[0].type = J3dMessage.MORPH_CHANGED; @@ -398,7 +398,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { createMessage[0].args[3] = obj; createMessage[0].args[4] = Shape3DRetained.getGeomAtomsArray(mirrorShape3D); if(visibleIsDirty) { - createMessage[1] = VirtualUniverse.mc.getMessage(); + createMessage[1] = new J3dMessage(); createMessage[1].threads = J3dThread.UPDATE_GEOMETRY; createMessage[1].type = J3dMessage.SHAPE3D_CHANGED; createMessage[1].universe = universe; @@ -431,7 +431,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { if (((Morph)this.source).isLive()) { // Send a message - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT | J3dThread.UPDATE_RENDER;; createMessage.type = J3dMessage.MORPH_CHANGED; @@ -568,7 +568,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { if (source.isLive()) { ((GeometryArrayRetained)morphedGeometryArray.retained).updateData(this); J3dMessage mChangeMessage = null; - mChangeMessage = VirtualUniverse.mc.getMessage(); + mChangeMessage = new J3dMessage(); mChangeMessage.type = J3dMessage.MORPH_CHANGED; mChangeMessage.threads = (J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_TRANSFORM); @@ -1447,7 +1447,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { // Need to clone the geometry , if its indexed ... if (refCount == 1 && this.geometryArrays[0] instanceof IndexedGeometryArrayRetained) { - J3dMessage mChangeMessage = VirtualUniverse.mc.getMessage(); + J3dMessage mChangeMessage = new J3dMessage(); mChangeMessage.type = J3dMessage.MORPH_CHANGED; mChangeMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; mChangeMessage.args[0] = this; @@ -1650,7 +1650,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { localBounds = getBounds(); super.setBoundsAutoCompute(autoCompute); if (source.isLive()) { - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.BOUNDS_AUTO_COMPUTE_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY | @@ -1666,7 +1666,7 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { void updateBounds() { localBounds = getEffectiveBounds(); if (source.isLive()) { - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.BOUNDS_AUTO_COMPUTE_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY | diff --git a/src/classes/share/javax/media/j3d/NativeAPIInfo.java b/src/classes/share/javax/media/j3d/NativeAPIInfo.java deleted file mode 100644 index 62b1f69..0000000 --- a/src/classes/share/javax/media/j3d/NativeAPIInfo.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - * Portions of this code were derived from work done by the Blackdown - * group (www.blackdown.org), who did the initial Linux implementation - * of the Java 3D API. - */ - -package javax.media.j3d; - -class NativeAPIInfo { - - /** - * Returns the rendering API being used. - * @return the rendering API, one of: - * MasterControl.RENDER_OPENGL_LINUX, - * MasterControl.RENDER_OPENGL_SOLARIS, - * MasterControl.RENDER_OPENGL_WIN32, - * or MasterControl.RENDER_DIRECT3D - */ - native int getRenderingAPI(); -} diff --git a/src/classes/share/javax/media/j3d/NativeContext.java b/src/classes/share/javax/media/j3d/NativeContext.java new file mode 100644 index 0000000..62a3e0b --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativeContext.java @@ -0,0 +1,31 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Graphics context objects for native rendering pipeline. + */ +class NativeContext implements Context { + + // Native context pointer + private long nativeCtx; + + NativeContext(long nativeCtx) { + this.nativeCtx = nativeCtx; + } + + long getNativeCtx() { + return nativeCtx; + } + +} diff --git a/src/classes/share/javax/media/j3d/NativeDrawable.java b/src/classes/share/javax/media/j3d/NativeDrawable.java new file mode 100644 index 0000000..73fb9d3 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativeDrawable.java @@ -0,0 +1,32 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Graphics Drawable objects for native rendering pipeline. + */ +class NativeDrawable implements Drawable { + + // Native drawable pointer. On Windows it is the native HDC. + // On X11 it is the handle to the native X11 drawable. + private long nativeDrawable; + + NativeDrawable(long nativeDrawable) { + this.nativeDrawable = nativeDrawable; + } + + long getNativeDrawable() { + return nativeDrawable; + } + +} diff --git a/src/classes/share/javax/media/j3d/NativePipeline.java b/src/classes/share/javax/media/j3d/NativePipeline.java new file mode 100644 index 0000000..1a3288f --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativePipeline.java @@ -0,0 +1,3325 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.io.File; +import java.util.ArrayList; + +/** + * Concrete implementation of Pipeline class for native OGL and D3D rendering + * pipeline. + */ +class NativePipeline extends Pipeline { + + // System properties containing the native library search PATH + // The order listed is the order in which they will be searched + private static final String[] systemPathProps = { + "sun.boot.library.path", + "java.library.path" + }; + + // Prefix for native libraries + private static final String libPrefix = "j3dcore"; + + // Boolean indicating whether we are using D3D or OGL + private boolean isD3D; + + // Renderer name, either "ogl" or "d3d" + private String rendererName; + + // Flags indicating whether the Cg or GLSL libraries are available. + private boolean cgLibraryAvailable = false; + private boolean glslLibraryAvailable = false; + + /** + * The platform dependent template. Since there is no + * template-specific instance data in the NativeConfigTemplate3D + * class, we can create one statically. + */ + private static NativeConfigTemplate3D nativeTemplate = new NativeConfigTemplate3D(); + + /** + * Constructor for singleton NativePipeline instance + */ + protected NativePipeline() { + } + + /** + * Initialize the pipeline + */ + void initialize(Pipeline.Type pipelineType) { + super.initialize(pipelineType); + + // This works around a native load library bug + try { + java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); + toolkit = null; // just making sure GC collects this + } catch (java.awt.AWTError e) { + } + + switch (pipelineType) { + case NATIVE_OGL: + isD3D = false; + rendererName = "ogl"; + break; + case NATIVE_D3D: + isD3D = true; + rendererName = "d3d"; + break; + default: + assert false; // Should never get here + } + } + + /** + * Load all of the required libraries + */ + void loadLibraries(int globalShadingLanguage) { + // Load the native JAWT library + loadLibrary("jawt"); + + // Load the native rendering library + String libraryName = libPrefix + "-" + rendererName; + loadLibrary(libraryName); + + // Check whether the Cg library is available + if (globalShadingLanguage == Shader.SHADING_LANGUAGE_CG) { + String cgLibraryName = libPrefix + "-" + rendererName + "-cg"; + String[] libpath = setupLibPath(cgLibraryName); + cgLibraryAvailable = loadNativeCgLibrary(libpath); + } + + // Check whether the GLSL library is available + if (globalShadingLanguage == Shader.SHADING_LANGUAGE_GLSL) { + if (getPipelineType() == Pipeline.Type.NATIVE_OGL) { + // No need to verify that GLSL is available, since GLSL is part + // of OpenGL as an extension (or part of core in 2.0) + glslLibraryAvailable = true; + } + } + } + + /** + * Returns true if the Cg library is loaded and available. Note that this + * does not necessarily mean that Cg is supported by the graphics card. + */ + boolean isCgLibraryAvailable() { + return cgLibraryAvailable; + } + + /** + * Returns true if the GLSL library is loaded and available. Note that this + * does not necessarily mean that GLSL is supported by the graphics card. + */ + boolean isGLSLLibraryAvailable() { + return glslLibraryAvailable; + } + + /** + * Load the specified native library. + */ + private void loadLibrary(String libName) { + final String libraryName = libName; + java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + System.loadLibrary(libraryName); + return null; + } + }); + } + + /** + * Parse the specified System properties containing a PATH and return an + * array of Strings, where each element is an absolute filename consisting of + * the individual component of the path concatenated with the (relative) + * library file name. Only those absolute filenames that exist are included. + * If no absolute filename is found, we will try the relative library name. + */ + private String[] setupLibPath(String libName) { + final String libraryName = libName; + return (String[]) + java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + ArrayList pathList = new ArrayList(); + + String filename = System.mapLibraryName(libraryName); + for (int n = 0; n < systemPathProps.length; n++) { + String pathString = System.getProperty(systemPathProps[n]); + boolean done = false; + int posStart = 0; + while (!done) { + int posEnd = pathString.indexOf(File.pathSeparator, posStart); + if (posEnd == -1) { + posEnd = pathString.length(); + done = true; + } + String pathDir = pathString.substring(posStart, posEnd); + File pathFile = new File(pathDir, filename); + if (pathFile.exists()) { + pathList.add(pathFile.getAbsolutePath()); + } + + posStart = posEnd + 1; + } + } + + // If no absolute path names exist, add in the relative library name + if (pathList.size() == 0) { + pathList.add(filename); + } + + return (String[])pathList.toArray(new String[0]); + } + }); + } + + // Method to verify whether the native Cg library is available + private native boolean loadNativeCgLibrary(String[] libpath); + + + // + // Methods to box/unbox various native objects + // + + private long unbox(Context ctx) { + if (ctx == null) { + return 0; + } else { + return ((NativeContext)ctx).getNativeCtx(); + } + } + + private Context boxContext(long nativeCtx) { + if (nativeCtx == 0) { + return null; + } else { + return new NativeContext(nativeCtx); + } + } + + private long unbox(Drawable drawable) { + if (drawable == null) { + return 0; + } else { + return ((NativeDrawable)drawable).getNativeDrawable(); + } + } + + private Drawable boxDrawable(long nativeDrawable) { + if (nativeDrawable == 0) { + return null; + } else { + return new NativeDrawable(nativeDrawable); + } + } + + private long unbox(ShaderProgramId shaderProgramId) { + if (shaderProgramId == null) { + return 0; + } else { + return ((NativeShaderObject)shaderProgramId).getNativeId(); + } + } + + private ShaderProgramId boxShaderProgramId(long nativeId) { + if (nativeId == 0) { + return null; + } else { + return new NativeShaderObject(nativeId); + } + } + + private long unbox(ShaderId shaderId) { + if (shaderId == null) { + return 0; + } else { + return ((NativeShaderObject)shaderId).getNativeId(); + } + } + + private ShaderId boxShaderId(long nativeId) { + if (nativeId == 0) { + return null; + } else { + return new NativeShaderObject(nativeId); + } + } + + private long unbox(ShaderAttrLoc attrLoc) { + if (attrLoc == null) { + return -1; + } else { + return ((NativeShaderObject)attrLoc).getNativeId(); + } + } + + private ShaderAttrLoc boxShaderAttrLoc(long nativeId) { + if (nativeId == -1) { + return null; + } else { + return new NativeShaderObject(nativeId); + } + } + + // --------------------------------------------------------------------- + + // + // GeometryArrayRetained methods + // + + // Used by D3D to free vertex buffer + native void freeD3DArray(GeometryArrayRetained geo, boolean deleteVB); + + // used for GeometryArrays by Copy or interleaved + native void execute(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + int vertexAttrCount, int[] vertexAttrSizes, + float[] varray, float[] cdata, int cdirty); + + void execute(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + int vertexAttrCount, int[] vertexAttrSizes, + float[] varray, float[] cdata, int cdirty) { + execute(unbox(ctx), + geo, geo_type, + isNonUniformScale, + useAlpha, + ignoreVertexColors, + startVIndex, vcount, vformat, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, + texCoordSetOffset, + numActiveTexUnitState, + vertexAttrCount, vertexAttrSizes, + varray, cdata, cdirty); + } + + // used by GeometryArray by Reference with java arrays + native void executeVA(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty); + + void executeVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty) { + executeVA(unbox(ctx), + geo, geo_type, + isNonUniformScale, + ignoreVertexColors, + vcount, + vformat, + vdefined, + coordIndex, vfcoords, vdcoords, + colorIndex, cfdata, cbdata, + normalIndex, ndata, + vertexAttrCount, vertexAttrSizes, + vertexAttrIndex, vertexAttrData, + texcoordmaplength, + texcoordoffset, + numActiveTexUnitState, + texIndex, texstride, texCoords, + cdirty); + } + + // used by GeometryArray by Reference with NIO buffer + native void executeVABuffer(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, + Object vcoords, + int colorIndex, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + int normalIndex, Object ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty); + + void executeVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, + Object vcoords, + int colorIndex, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + int normalIndex, Object ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty) { + executeVABuffer(unbox(ctx), + geo, geo_type, + isNonUniformScale, + ignoreVertexColors, + vcount, + vformat, + vdefined, + coordIndex, + vcoords, + colorIndex, + cdataBuffer, + cfdata, cbdata, + normalIndex, ndata, + vertexAttrCount, vertexAttrSizes, + vertexAttrIndex, vertexAttrData, + texcoordmaplength, + texcoordoffset, + numActiveTexUnitState, + texIndex, texstride, texCoords, + cdirty); + } + + // used by GeometryArray by Reference in interleaved format with NIO buffer + native void executeInterleavedBuffer(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, int cdirty); + + void executeInterleavedBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, int cdirty) { + executeInterleavedBuffer(unbox(ctx), + geo, geo_type, + isNonUniformScale, + useAlpha, + ignoreVertexColors, + startVIndex, vcount, vformat, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, + texCoordSetOffset, + numActiveTexUnitState, + varray, cdata, cdirty); + } + + native void setVertexFormat(long ctx, GeometryArrayRetained geo, + int vformat, boolean useAlpha, boolean ignoreVertexColors); + + void setVertexFormat(Context ctx, GeometryArrayRetained geo, + int vformat, boolean useAlpha, boolean ignoreVertexColors) { + setVertexFormat(unbox(ctx), geo, + vformat, useAlpha, ignoreVertexColors); + } + + native void disableGlobalAlpha(long ctx, GeometryArrayRetained geo, int vformat, + boolean useAlpha, boolean ignoreVertexColors); + + void disableGlobalAlpha(Context ctx, GeometryArrayRetained geo, int vformat, + boolean useAlpha, boolean ignoreVertexColors) { + disableGlobalAlpha(unbox(ctx), geo, vformat, + useAlpha, ignoreVertexColors); + } + + // used for GeometryArrays + native void buildGA(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int startVIndex, + int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, int[] texCoordSetMapOffset, + int vertexAttrCount, int[] vertexAttrSizes, + double[] xform, double[] nxform, + float[] varray); + + void buildGA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int startVIndex, + int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, int[] texCoordSetMapOffset, + int vertexAttrCount, int[] vertexAttrSizes, + double[] xform, double[] nxform, + float[] varray) { + buildGA(unbox(ctx), + geo, geo_type, + isNonUniformScale, updateAlpha, + alpha, + ignoreVertexColors, + startVIndex, + vcount, vformat, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, texCoordSetMapOffset, + vertexAttrCount, vertexAttrSizes, + xform, nxform, + varray); + } + + // used to Build Dlist GeometryArray by Reference with java arrays + native void buildGAForByRef(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int[] texIndex, int texstride, Object[] texCoords, + double[] xform, double[] nxform); + + void buildGAForByRef(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int[] texIndex, int texstride, Object[] texCoords, + double[] xform, double[] nxform) { + buildGAForByRef(unbox(ctx), + geo, geo_type, + isNonUniformScale, updateAlpha, + alpha, + ignoreVertexColors, + vcount, + vformat, + vdefined, + coordIndex, vfcoords, vdcoords, + colorIndex, cfdata, cbdata, + normalIndex, ndata, + vertexAttrCount, vertexAttrSizes, + vertexAttrIndex, vertexAttrData, + texcoordmaplength, + texcoordoffset, + texIndex, texstride, texCoords, + xform, nxform); + } + + // --------------------------------------------------------------------- + + // + // IndexedGeometryArrayRetained methods + // + + // by-copy or interleaved, by reference, Java arrays + native void executeIndexedGeometry(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + float[] varray, float[] cdata, + int cdirty, + int[] indexCoord); + + void executeIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + float[] varray, float[] cdata, + int cdirty, + int[] indexCoord) { + executeIndexedGeometry(unbox(ctx), + geo, geo_type, + isNonUniformScale, + useAlpha, + ignoreVertexColors, + initialIndexIndex, + indexCount, + vertexCount, vformat, + vertexAttrCount, vertexAttrSizes, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, + texCoordSetOffset, + numActiveTexUnitState, + varray, cdata, + cdirty, + indexCoord); + } + + // interleaved, by reference, nio buffer + native void executeIndexedGeometryBuffer(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, + int cdirty, + int[] indexCoord); + + void executeIndexedGeometryBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, + int cdirty, + int[] indexCoord) { + executeIndexedGeometryBuffer(unbox(ctx), + geo, geo_type, + isNonUniformScale, + useAlpha, + ignoreVertexColors, + initialIndexIndex, + indexCount, + vertexCount, vformat, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, + texCoordSetOffset, + numActiveTexUnitState, + varray, cdata, + cdirty, + indexCoord); + } + + // non interleaved, by reference, Java arrays + native void executeIndexedGeometryVA(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + float[] vfcoords, double[] vdcoords, + float[] cfdata, byte[] cbdata, + float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord); + + void executeIndexedGeometryVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + float[] vfcoords, double[] vdcoords, + float[] cfdata, byte[] cbdata, + float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord) { + executeIndexedGeometryVA(unbox(ctx), + geo, geo_type, + isNonUniformScale, + ignoreVertexColors, + initialIndexIndex, + validIndexCount, + vertexCount, + vformat, + vdefined, + vfcoords, vdcoords, + cfdata, cbdata, + ndata, + vertexAttrCount, vertexAttrSizes, + vertexAttrData, + texcoordmaplength, + texcoordoffset, + numActiveTexUnitState, + texstride, texCoords, + cdirty, + indexCoord); + } + + // non interleaved, by reference, nio buffer + native void executeIndexedGeometryVABuffer(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + Object vcoords, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + Object normal, + int vertexAttrCount, int[] vertexAttrSizes, + Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord); + + void executeIndexedGeometryVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + Object vcoords, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + Object normal, + int vertexAttrCount, int[] vertexAttrSizes, + Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord) { + executeIndexedGeometryVABuffer(unbox(ctx), + geo, geo_type, + isNonUniformScale, + ignoreVertexColors, + initialIndexIndex, + validIndexCount, + vertexCount, + vformat, + vdefined, + vcoords, + cdataBuffer, + cfdata, cbdata, + normal, + vertexAttrCount, vertexAttrSizes, + vertexAttrData, + texcoordmaplength, + texcoordoffset, + numActiveTexUnitState, + texstride, texCoords, + cdirty, + indexCoord); + } + + // by-copy geometry + native void buildIndexedGeometry(long ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetMapOffset, + double[] xform, double[] nxform, + float[] varray, int[] indexCoord); + + void buildIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetMapOffset, + double[] xform, double[] nxform, + float[] varray, int[] indexCoord) { + buildIndexedGeometry(unbox(ctx), + geo, geo_type, + isNonUniformScale, updateAlpha, + alpha, + ignoreVertexColors, + initialIndexIndex, + validIndexCount, + vertexCount, + vformat, + vertexAttrCount, vertexAttrSizes, + texCoordSetCount, texCoordSetMap, + texCoordSetMapLen, + texCoordSetMapOffset, + xform, nxform, + varray, indexCoord); + } + + + // --------------------------------------------------------------------- + + // + // GraphicsContext3D methods + // + + native void readRaster(long ctx, + int type, int xSrcOffset, int ySrcOffset, + int width, int height, int hCanvas, + int imageDataType, + int imageFormat, + Object imageBuffer, + int depthFormat, + Object depthBuffer); + + void readRaster(Context ctx, + int type, int xSrcOffset, int ySrcOffset, + int width, int height, int hCanvas, + int imageDataType, + int imageFormat, + Object imageBuffer, + int depthFormat, + Object depthBuffer) { + readRaster(unbox(ctx), + type, xSrcOffset, ySrcOffset, + width, height, hCanvas, + imageDataType, + imageFormat, imageBuffer, + depthFormat, depthBuffer); + } + + // --------------------------------------------------------------------- + + // + // CgShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + native ShaderError setCgUniform1i(long ctx, + long shaderProgramId, + long uniformLocation, + int value); + + ShaderError setCgUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + return setCgUniform1i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform1f(long ctx, + long shaderProgramId, + long uniformLocation, + float value); + + ShaderError setCgUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + return setCgUniform1f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform2i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setCgUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setCgUniform2i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform2f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setCgUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setCgUniform2f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform3i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setCgUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setCgUniform3i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform3f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setCgUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setCgUniform3f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform4i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setCgUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setCgUniform4i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniform4f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setCgUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setCgUniform4f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniformMatrix3f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setCgUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setCgUniformMatrix3f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setCgUniformMatrix4f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setCgUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setCgUniformMatrix4f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + // ShaderAttributeArray methods + + native ShaderError setCgUniform1iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setCgUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setCgUniform1iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform1fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniform1fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform2iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setCgUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setCgUniform2iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform2fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniform2fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform3iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setCgUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setCgUniform3iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform3fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniform3fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform4iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setCgUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setCgUniform4iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniform4fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniform4fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniformMatrix3fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniformMatrix3fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setCgUniformMatrix4fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setCgUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setCgUniformMatrix4fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + // Native interfaces for shader compilation, etc. + native ShaderError createCgShader(long ctx, int shaderType, long[] shaderId); + + ShaderError createCgShader(Context ctx, int shaderType, ShaderId[] shaderId) { + long[] nativeId = new long[1]; + ShaderError err = createCgShader(unbox(ctx), shaderType, nativeId); + shaderId[0] = boxShaderId(nativeId[0]); + return err; + } + + native ShaderError destroyCgShader(long ctx, long shaderId); + + ShaderError destroyCgShader(Context ctx, ShaderId shaderId) { + return destroyCgShader(unbox(ctx), unbox(shaderId)); + } + + native ShaderError compileCgShader(long ctx, long shaderId, String program); + + ShaderError compileCgShader(Context ctx, ShaderId shaderId, String program) { + return compileCgShader(unbox(ctx), unbox(shaderId), program); + } + + native ShaderError createCgShaderProgram(long ctx, long[] shaderProgramId); + + ShaderError createCgShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId) { + long[] nativeId = new long[1]; + ShaderError err = createCgShaderProgram(unbox(ctx), nativeId); + shaderProgramId[0] = boxShaderProgramId(nativeId[0]); + return err; + } + + native ShaderError destroyCgShaderProgram(long ctx, long shaderProgramId); + + ShaderError destroyCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return destroyCgShaderProgram(unbox(ctx), unbox(shaderProgramId)); + } + + native ShaderError linkCgShaderProgram(long ctx, long shaderProgramId, + long[] shaderIds); + + ShaderError linkCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds) { + + assert shaderIds != null; + long[] nativeIds = new long[shaderIds.length]; + for (int i = 0; i < shaderIds.length; i++) { + nativeIds[i] = unbox(shaderIds[i]); + } + return linkCgShaderProgram(unbox(ctx), unbox(shaderProgramId), + nativeIds); + } + + native void lookupCgVertexAttrNames(long ctx, long shaderProgramId, + int numAttrNames, String[] attrNames, boolean[] errArr); + + void lookupCgVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, boolean[] errArr) { + lookupCgVertexAttrNames(unbox(ctx), unbox(shaderProgramId), + numAttrNames, attrNames, errArr); + } + + native void lookupCgShaderAttrNames(long ctx, long shaderProgramId, + int numAttrNames, String[] attrNames, long[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr); + + void lookupCgShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr) { + + assert numAttrNames == locArr.length; + long[] nativeLocArr = new long[numAttrNames]; + for (int i = 0; i < numAttrNames; i++) { + // Initialize to invalid native location + nativeLocArr[i] = -1; + } + lookupCgShaderAttrNames(unbox(ctx), unbox(shaderProgramId), + numAttrNames, attrNames, nativeLocArr, + typeArr, sizeArr, isArrayArr); + for (int i = 0; i < numAttrNames; i++) { + locArr[i] = boxShaderAttrLoc(nativeLocArr[i]); + } + } + + native ShaderError useCgShaderProgram(long ctx, long shaderProgramId); + + ShaderError useCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return useCgShaderProgram(unbox(ctx), unbox(shaderProgramId)); + } + + // --------------------------------------------------------------------- + + // + // GLSLShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + native ShaderError setGLSLUniform1i(long ctx, + long shaderProgramId, + long uniformLocation, + int value); + + ShaderError setGLSLUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + return setGLSLUniform1i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform1f(long ctx, + long shaderProgramId, + long uniformLocation, + float value); + + ShaderError setGLSLUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + return setGLSLUniform1f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform2i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setGLSLUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setGLSLUniform2i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform2f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setGLSLUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setGLSLUniform2f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform3i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setGLSLUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setGLSLUniform3i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform3f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setGLSLUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setGLSLUniform3f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform4i(long ctx, + long shaderProgramId, + long uniformLocation, + int[] value); + + ShaderError setGLSLUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return setGLSLUniform4i(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniform4f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setGLSLUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setGLSLUniform4f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniformMatrix3f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setGLSLUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setGLSLUniformMatrix3f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + native ShaderError setGLSLUniformMatrix4f(long ctx, + long shaderProgramId, + long uniformLocation, + float[] value); + + ShaderError setGLSLUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return setGLSLUniformMatrix4f(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + value); + } + + // ShaderAttributeArray methods + + native ShaderError setGLSLUniform1iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setGLSLUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setGLSLUniform1iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform1fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniform1fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform2iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setGLSLUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setGLSLUniform2iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform2fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniform2fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform3iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setGLSLUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setGLSLUniform3iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform3fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniform3fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform4iArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + int[] value); + + ShaderError setGLSLUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return setGLSLUniform4iArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniform4fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniform4fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniformMatrix3fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniformMatrix3fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + native ShaderError setGLSLUniformMatrix4fArray(long ctx, + long shaderProgramId, + long uniformLocation, + int numElements, + float[] value); + + ShaderError setGLSLUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return setGLSLUniformMatrix4fArray(unbox(ctx), + unbox(shaderProgramId), + unbox(uniformLocation), + numElements, + value); + } + + // native interfaces for shader compilation, etc. + native ShaderError createGLSLShader(long ctx, int shaderType, long[] shaderId); + + ShaderError createGLSLShader(Context ctx, int shaderType, ShaderId[] shaderId) { + long[] nativeId = new long[1]; + ShaderError err = createGLSLShader(unbox(ctx), shaderType, nativeId); + shaderId[0] = boxShaderId(nativeId[0]); + return err; + } + native ShaderError destroyGLSLShader(long ctx, long shaderId); + + ShaderError destroyGLSLShader(Context ctx, ShaderId shaderId) { + return destroyGLSLShader(unbox(ctx), unbox(shaderId)); + } + native ShaderError compileGLSLShader(long ctx, long shaderId, String program); + + ShaderError compileGLSLShader(Context ctx, ShaderId shaderId, String program) { + return compileGLSLShader(unbox(ctx), unbox(shaderId), program); + } + + native ShaderError createGLSLShaderProgram(long ctx, long[] shaderProgramId); + + ShaderError createGLSLShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId) { + long[] nativeId = new long[1]; + ShaderError err = createGLSLShaderProgram(unbox(ctx), nativeId); + shaderProgramId[0] = boxShaderProgramId(nativeId[0]); + return err; + } + native ShaderError destroyGLSLShaderProgram(long ctx, long shaderProgramId); + + ShaderError destroyGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return destroyGLSLShaderProgram(unbox(ctx), unbox(shaderProgramId)); + } + native ShaderError linkGLSLShaderProgram(long ctx, long shaderProgramId, + long[] shaderId); + + ShaderError linkGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds) { + assert shaderIds != null; + long[] nativeIds = new long[shaderIds.length]; + for (int i = 0; i < shaderIds.length; i++) { + nativeIds[i] = unbox(shaderIds[i]); + } + return linkGLSLShaderProgram(unbox(ctx), unbox(shaderProgramId), + nativeIds); + } + native ShaderError bindGLSLVertexAttrName(long ctx, long shaderProgramId, + String attrName, int attrIndex); + + ShaderError bindGLSLVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, + String attrName, int attrIndex) { + return bindGLSLVertexAttrName(unbox(ctx), unbox(shaderProgramId), + attrName, attrIndex); + } + native void lookupGLSLShaderAttrNames(long ctx, long shaderProgramId, + int numAttrNames, String[] attrNames, long[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr); + + void lookupGLSLShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr) { + + assert numAttrNames == locArr.length; + long[] nativeLocArr = new long[numAttrNames]; + for (int i = 0; i < numAttrNames; i++) { + // Initialize to invalid native location + nativeLocArr[i] = -1; + } + lookupGLSLShaderAttrNames(unbox(ctx), unbox(shaderProgramId), + numAttrNames, attrNames, nativeLocArr, + typeArr, sizeArr, isArrayArr); + for (int i = 0; i < numAttrNames; i++) { + locArr[i] = boxShaderAttrLoc(nativeLocArr[i]); + } + } + + native ShaderError useGLSLShaderProgram(long ctx, long shaderProgramId); + + ShaderError useGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return useGLSLShaderProgram(unbox(ctx), unbox(shaderProgramId)); + } + + + // --------------------------------------------------------------------- + + // + // ImageComponent2DRetained methods + // + + // free d3d surface referred to by id + native void freeD3DSurface(ImageComponent2DRetained image, int hashId); + + + // --------------------------------------------------------------------- + + // + // Renderer methods + // + + native void cleanupRenderer(); + + + // --------------------------------------------------------------------- + + // + // ColoringAttributesRetained methods + // + + native void updateColoringAttributes(long ctx, + float dRed, float dGreen, float dBlue, + float red, float green, float blue, + float alpha, + boolean lEnable, + int shadeModel); + + void updateColoringAttributes(Context ctx, + float dRed, float dGreen, float dBlue, + float red, float green, float blue, + float alpha, + boolean lEnable, + int shadeModel) { + updateColoringAttributes(unbox(ctx), + dRed, dGreen, dBlue, + red, green, blue, + alpha, + lEnable, + shadeModel); + } + + + // --------------------------------------------------------------------- + + // + // DirectionalLightRetained methods + // + + native void updateDirectionalLight(long ctx, + int lightSlot, float red, float green, + float blue, float x, float y, float z); + + void updateDirectionalLight(Context ctx, + int lightSlot, float red, float green, + float blue, float x, float y, float z) { + updateDirectionalLight(unbox(ctx), + lightSlot, red, green, + blue, x, y, z); + } + + + // --------------------------------------------------------------------- + + // + // PointLightRetained methods + // + + native void updatePointLight(long ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz); + + void updatePointLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz) { + updatePointLight(unbox(ctx), + lightSlot, red, green, + blue, ax, ay, az, + px, py, pz); + } + + + // --------------------------------------------------------------------- + + // + // SpotLightRetained methods + // + + native void updateSpotLight(long ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz, float spreadAngle, + float concentration, float dx, float dy, + float dz); + + void updateSpotLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz, float spreadAngle, + float concentration, float dx, float dy, + float dz) { + updateSpotLight(unbox(ctx), + lightSlot, red, green, + blue, ax, ay, az, + px, py, pz, spreadAngle, + concentration, dx, dy, + dz); + } + + + // --------------------------------------------------------------------- + + // + // ExponentialFogRetained methods + // + + native void updateExponentialFog(long ctx, + float red, float green, float blue, + float density); + + void updateExponentialFog(Context ctx, + float red, float green, float blue, + float density) { + updateExponentialFog(unbox(ctx), + red, green, blue, + density); + } + + + // --------------------------------------------------------------------- + + // + // LinearFogRetained methods + // + + native void updateLinearFog(long ctx, + float red, float green, float blue, + double fdist, double bdist); + + void updateLinearFog(Context ctx, + float red, float green, float blue, + double fdist, double bdist) { + updateLinearFog(unbox(ctx), + red, green, blue, + fdist, bdist); + } + + + // --------------------------------------------------------------------- + + // + // LineAttributesRetained methods + // + + native void updateLineAttributes(long ctx, + float lineWidth, int linePattern, + int linePatternMask, + int linePatternScaleFactor, + boolean lineAntialiasing); + + void updateLineAttributes(Context ctx, + float lineWidth, int linePattern, + int linePatternMask, + int linePatternScaleFactor, + boolean lineAntialiasing) { + updateLineAttributes(unbox(ctx), + lineWidth, linePattern, + linePatternMask, + linePatternScaleFactor, + lineAntialiasing); + } + + + // --------------------------------------------------------------------- + + // + // MaterialRetained methods + // + + native void updateMaterial(long ctx, + float red, float green, float blue, float alpha, + float ared, float agreen, float ablue, + float ered, float egreen, float eblue, + float dred, float dgreen, float dblue, + float sred, float sgreen, float sblue, + float shininess, int colorTarget, boolean enable); + + void updateMaterial(Context ctx, + float red, float green, float blue, float alpha, + float ared, float agreen, float ablue, + float ered, float egreen, float eblue, + float dred, float dgreen, float dblue, + float sred, float sgreen, float sblue, + float shininess, int colorTarget, boolean enable) { + updateMaterial(unbox(ctx), + red, green, blue, alpha, + ared, agreen, ablue, + ered, egreen, eblue, + dred, dgreen, dblue, + sred, sgreen, sblue, + shininess, colorTarget, enable); + } + + + // --------------------------------------------------------------------- + + // + // ModelClipRetained methods + // + + native void updateModelClip(long ctx, int planeNum, boolean enableFlag, + double A, double B, double C, double D); + + void updateModelClip(Context ctx, int planeNum, boolean enableFlag, + double A, double B, double C, double D) { + updateModelClip(unbox(ctx), planeNum, enableFlag, + A, B, C, D); + } + + + // --------------------------------------------------------------------- + + // + // PointAttributesRetained methods + // + + native void updatePointAttributes(long ctx, float pointSize, boolean pointAntialiasing); + + void updatePointAttributes(Context ctx, float pointSize, boolean pointAntialiasing) { + updatePointAttributes(unbox(ctx), pointSize, pointAntialiasing); + } + + + // --------------------------------------------------------------------- + + // + // PolygonAttributesRetained methods + // + + native void updatePolygonAttributes(long ctx, + int polygonMode, int cullFace, + boolean backFaceNormalFlip, + float polygonOffset, + float polygonOffsetFactor); + + void updatePolygonAttributes(Context ctx, + int polygonMode, int cullFace, + boolean backFaceNormalFlip, + float polygonOffset, + float polygonOffsetFactor) { + updatePolygonAttributes(unbox(ctx), + polygonMode, cullFace, + backFaceNormalFlip, + polygonOffset, + polygonOffsetFactor); + } + + + // --------------------------------------------------------------------- + + // + // RenderingAttributesRetained methods + // + + // TODO : Need to handle stencil operation on the native side -- Chien + native void updateRenderingAttributes(long ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride, + boolean depthBufferEnable, + boolean depthBufferWriteEnable, + int depthTestFunction, + float alphaTestValue, int alphaTestFunction, + boolean ignoreVertexColors, + boolean rasterOpEnable, int rasterOp, + boolean userStencilAvailable, boolean stencilEnable, + int stencilFailOp, int stencilZFailOp, int stencilZPassOp, + int stencilFunction, int stencilReferenceValue, + int stencilCompareMask, int stencilWriteMask ); + + void updateRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride, + boolean depthBufferEnable, + boolean depthBufferWriteEnable, + int depthTestFunction, + float alphaTestValue, int alphaTestFunction, + boolean ignoreVertexColors, + boolean rasterOpEnable, int rasterOp, + boolean userStencilAvailable, boolean stencilEnable, + int stencilFailOp, int stencilZFailOp, int stencilZPassOp, + int stencilFunction, int stencilReferenceValue, + int stencilCompareMask, int stencilWriteMask ) { + updateRenderingAttributes(unbox(ctx), + depthBufferWriteEnableOverride, + depthBufferEnableOverride, + depthBufferEnable, + depthBufferWriteEnable, + depthTestFunction, + alphaTestValue, alphaTestFunction, + ignoreVertexColors, + rasterOpEnable, rasterOp, + userStencilAvailable, stencilEnable, + stencilFailOp, stencilZFailOp, stencilZPassOp, + stencilFunction, stencilReferenceValue, + stencilCompareMask, stencilWriteMask ); + } + + + // --------------------------------------------------------------------- + + // + // TexCoordGenerationRetained methods + // + + /** + * This method updates the native context: + * trans contains eyeTovworld transform in d3d + * trans contains vworldToEye transform in ogl + */ + native void updateTexCoordGeneration(long ctx, + boolean enable, int genMode, int format, + float planeSx, float planeSy, float planeSz, float planeSw, + float planeTx, float planeTy, float planeTz, float planeTw, + float planeRx, float planeRy, float planeRz, float planeRw, + float planeQx, float planeQy, float planeQz, float planeQw, + double[] trans); + + void updateTexCoordGeneration(Context ctx, + boolean enable, int genMode, int format, + float planeSx, float planeSy, float planeSz, float planeSw, + float planeTx, float planeTy, float planeTz, float planeTw, + float planeRx, float planeRy, float planeRz, float planeRw, + float planeQx, float planeQy, float planeQz, float planeQw, + double[] trans) { + updateTexCoordGeneration(unbox(ctx), + enable, genMode, format, + planeSx, planeSy, planeSz, planeSw, + planeTx, planeTy, planeTz, planeTw, + planeRx, planeRy, planeRz, planeRw, + planeQx, planeQy, planeQz, planeQw, + trans); + } + + + // --------------------------------------------------------------------- + + // + // TransparencyAttributesRetained methods + // + + native void updateTransparencyAttributes(long ctx, + float alpha, int geometryType, + int polygonMode, + boolean lineAA, boolean pointAA, + int transparencyMode, + int srcBlendFunction, + int dstBlendFunction); + + void updateTransparencyAttributes(Context ctx, + float alpha, int geometryType, + int polygonMode, + boolean lineAA, boolean pointAA, + int transparencyMode, + int srcBlendFunction, + int dstBlendFunction) { + updateTransparencyAttributes(unbox(ctx), + alpha, geometryType, + polygonMode, + lineAA, pointAA, + transparencyMode, + srcBlendFunction, + dstBlendFunction); + } + + + // --------------------------------------------------------------------- + + // + // TextureAttributesRetained methods + // + + native void updateTextureAttributes(long ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat); + + void updateTextureAttributes(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat) { + updateTextureAttributes(unbox(ctx), + transform, isIdentity, textureMode, + perspCorrectionMode, red, + green, blue, alpha, + textureFormat); + } + + native void updateRegisterCombiners(long ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale); + + void updateRegisterCombiners(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale) { + updateRegisterCombiners(unbox(ctx), + transform, isIdentity, textureMode, + perspCorrectionMode, red, + green, blue, alpha, + textureFormat, + combineRgbMode, combineAlphaMode, + combineRgbSrc, combineAlphaSrc, + combineRgbFcn, combineAlphaFcn, + combineRgbScale, combineAlphaScale); + } + + native void updateTextureColorTable(long ctx, int numComponents, + int colorTableSize, + int[] colorTable); + + void updateTextureColorTable(Context ctx, int numComponents, + int colorTableSize, + int[] colorTable) { + updateTextureColorTable(unbox(ctx), numComponents, + colorTableSize, + colorTable); + } + + native void updateCombiner(long ctx, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale); + + void updateCombiner(Context ctx, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale) { + updateCombiner(unbox(ctx), + combineRgbMode, combineAlphaMode, + combineRgbSrc, combineAlphaSrc, + combineRgbFcn, combineAlphaFcn, + combineRgbScale, combineAlphaScale); + } + + + // --------------------------------------------------------------------- + + // + // TextureUnitStateRetained methods + // + + native void updateTextureUnitState(long ctx, int unitIndex, boolean enableFlag); + + void updateTextureUnitState(Context ctx, int unitIndex, boolean enableFlag) { + updateTextureUnitState(unbox(ctx), unitIndex, enableFlag); + } + + + // --------------------------------------------------------------------- + + // + // TextureRetained methods + // Texture2DRetained methods + // + + native void bindTexture2D(long ctx, int objectId, boolean enable); + + void bindTexture2D(Context ctx, int objectId, boolean enable) { + bindTexture2D(unbox(ctx), objectId, enable); + } + + native void updateTexture2DImage(long ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object data); + + void updateTexture2DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object data) { + updateTexture2DImage(unbox(ctx), + numLevels, level, + textureFormat, imageFormat, + width, height, + boundaryWidth, + imageDataType, data); + } + + native void updateTexture2DSubImage(long ctx, + int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object data); + + void updateTexture2DSubImage(Context ctx, + int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object data) { + updateTexture2DSubImage(unbox(ctx), + level, xoffset, yoffset, + textureFormat, imageFormat, + imgXOffset, imgYOffset, + tilew, width, height, + imageDataType, data); + } + + native void updateTexture2DLodRange(long ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + void updateTexture2DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + updateTexture2DLodRange(unbox(ctx), + baseLevel, maximumLevel, + minimumLod, maximumLod); + } + + native void updateTexture2DLodOffset(long ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + void updateTexture2DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + updateTexture2DLodOffset(unbox(ctx), + lodOffsetX, lodOffsetY, + lodOffsetZ); + } + + native void updateTexture2DBoundary(long ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha); + + void updateTexture2DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha) { + updateTexture2DBoundary(unbox(ctx), + boundaryModeS, boundaryModeT, + boundaryRed, boundaryGreen, + boundaryBlue, boundaryAlpha); + } + + native void updateTexture2DFilterModes(long ctx, + int minFilter, int magFilter); + + void updateTexture2DFilterModes(Context ctx, + int minFilter, int magFilter) { + updateTexture2DFilterModes(unbox(ctx), + minFilter, magFilter); + } + + native void updateTexture2DSharpenFunc(long ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + void updateTexture2DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + updateTexture2DSharpenFunc(unbox(ctx), + numSharpenTextureFuncPts, + sharpenTextureFuncPts); + } + + native void updateTexture2DFilter4Func(long ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + void updateTexture2DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + updateTexture2DFilter4Func(unbox(ctx), + numFilter4FuncPts, + filter4FuncPts); + } + + native void updateTexture2DAnisotropicFilter(long ctx, float degree); + + void updateTexture2DAnisotropicFilter(Context ctx, float degree) { + updateTexture2DAnisotropicFilter(unbox(ctx), degree); + } + + + // --------------------------------------------------------------------- + + // + // Texture3DRetained methods + // + + native void bindTexture3D(long ctx, int objectId, boolean enable); + + void bindTexture3D(Context ctx, int objectId, boolean enable) { + bindTexture3D(unbox(ctx), objectId, enable); + } + + native void updateTexture3DImage(long ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, int depth, + int boundaryWidth, + int imageDataType, Object imageData); + + void updateTexture3DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, int depth, + int boundaryWidth, + int imageDataType, Object imageData) { + updateTexture3DImage(unbox(ctx), + numLevels, level, + textureFormat, imageFormat, + width, height, depth, + boundaryWidth, + imageDataType, imageData); + } + + native void updateTexture3DSubImage(long ctx, + int level, + int xoffset, int yoffset, int zoffset, + int textureFormat, int imageFormat, + int imgXoffset, int imgYoffset, int imgZoffset, + int tilew, int tileh, + int width, int height, int depth, + int imageDataType, Object imageData); + + void updateTexture3DSubImage(Context ctx, + int level, + int xoffset, int yoffset, int zoffset, + int textureFormat, int imageFormat, + int imgXoffset, int imgYoffset, int imgZoffset, + int tilew, int tileh, + int width, int height, int depth, + int imageDataType, Object imageData) { + updateTexture3DSubImage(unbox(ctx), + level, + xoffset, yoffset, zoffset, + textureFormat, imageFormat, + imgXoffset, imgYoffset, imgZoffset, + tilew, tileh, + width, height, depth, + imageDataType, imageData); + } + + native void updateTexture3DLodRange(long ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + void updateTexture3DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + updateTexture3DLodRange(unbox(ctx), + baseLevel, maximumLevel, + minimumLod, maximumLod); + } + + native void updateTexture3DLodOffset(long ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + void updateTexture3DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + updateTexture3DLodOffset(unbox(ctx), + lodOffsetX, lodOffsetY, + lodOffsetZ); + } + + native void updateTexture3DBoundary(long ctx, + int boundaryModeS, int boundaryModeT, + int boundaryModeR, float boundaryRed, + float boundaryGreen, float boundaryBlue, + float boundaryAlpha); + + + void updateTexture3DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + int boundaryModeR, float boundaryRed, + float boundaryGreen, float boundaryBlue, + float boundaryAlpha) { + updateTexture3DBoundary(unbox(ctx), + boundaryModeS, boundaryModeT, + boundaryModeR, boundaryRed, + boundaryGreen, boundaryBlue, + boundaryAlpha); + } + + native void updateTexture3DFilterModes(long ctx, + int minFilter, int magFilter); + + void updateTexture3DFilterModes(Context ctx, + int minFilter, int magFilter) { + updateTexture3DFilterModes(unbox(ctx), + minFilter, magFilter); + } + + native void updateTexture3DSharpenFunc(long ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + void updateTexture3DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + updateTexture3DSharpenFunc(unbox(ctx), + numSharpenTextureFuncPts, + sharpenTextureFuncPts); + } + + native void updateTexture3DFilter4Func(long ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + void updateTexture3DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + updateTexture3DFilter4Func(unbox(ctx), + numFilter4FuncPts, + filter4FuncPts); + } + + native void updateTexture3DAnisotropicFilter(long ctx, float degree); + + void updateTexture3DAnisotropicFilter(Context ctx, float degree) { + updateTexture3DAnisotropicFilter(unbox(ctx), degree); + } + + + // --------------------------------------------------------------------- + + // + // TextureCubeMapRetained methods + // + + native void bindTextureCubeMap(long ctx, int objectId, boolean enable); + + void bindTextureCubeMap(Context ctx, int objectId, boolean enable) { + bindTextureCubeMap(unbox(ctx), objectId, enable); + } + + native void updateTextureCubeMapImage(long ctx, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object imageData); + + void updateTextureCubeMapImage(Context ctx, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object imageData) { + updateTextureCubeMapImage(unbox(ctx), + face, numLevels, level, + textureFormat, imageFormat, + width, height, + boundaryWidth, + imageDataType, imageData); + } + + native void updateTextureCubeMapSubImage(long ctx, + int face, int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object imageData); + + void updateTextureCubeMapSubImage(Context ctx, + int face, int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object imageData) { + updateTextureCubeMapSubImage(unbox(ctx), + face, level, xoffset, yoffset, + textureFormat, imageFormat, + imgXOffset, imgYOffset, + tilew, width, height, + imageDataType, imageData); + } + + native void updateTextureCubeMapLodRange(long ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + void updateTextureCubeMapLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + updateTextureCubeMapLodRange(unbox(ctx), + baseLevel, maximumLevel, + minimumLod, maximumLod); + } + + native void updateTextureCubeMapLodOffset(long ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + void updateTextureCubeMapLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + updateTextureCubeMapLodOffset(unbox(ctx), + lodOffsetX, lodOffsetY, + lodOffsetZ); + } + + native void updateTextureCubeMapBoundary(long ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha); + + void updateTextureCubeMapBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha) { + updateTextureCubeMapBoundary(unbox(ctx), + boundaryModeS, boundaryModeT, + boundaryRed, boundaryGreen, + boundaryBlue, boundaryAlpha); + } + + native void updateTextureCubeMapFilterModes(long ctx, + int minFilter, int magFilter); + + void updateTextureCubeMapFilterModes(Context ctx, + int minFilter, int magFilter) { + updateTextureCubeMapFilterModes(unbox(ctx), + minFilter, magFilter); + } + + native void updateTextureCubeMapSharpenFunc(long ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + void updateTextureCubeMapSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + updateTextureCubeMapSharpenFunc(unbox(ctx), + numSharpenTextureFuncPts, + sharpenTextureFuncPts); + } + + native void updateTextureCubeMapFilter4Func(long ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + void updateTextureCubeMapFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + updateTextureCubeMapFilter4Func(unbox(ctx), + numFilter4FuncPts, + filter4FuncPts); + } + + native void updateTextureCubeMapAnisotropicFilter(long ctx, float degree); + + void updateTextureCubeMapAnisotropicFilter(Context ctx, float degree) { + updateTextureCubeMapAnisotropicFilter(unbox(ctx), degree); + } + + // --------------------------------------------------------------------- + + // + // MasterControl methods + // + + // Method to return the AWT object + native long getAWT(); + + // Method to initialize the native J3D library + native boolean initializeJ3D(boolean disableXinerama); + + // Maximum lights supported by the native API + native int getMaximumLights(); + + + // --------------------------------------------------------------------- + + // + // Canvas3D methods + // + + // This is the native method for creating the underlying graphics context. + native long createNewContext(Canvas3D cv, long display, long drawable, + long fbConfig, long shareCtx, boolean isSharedCtx, + boolean offScreen, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable); + + // This is the native method for creating the underlying graphics context. + Context createNewContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, Context shareCtx, boolean isSharedCtx, + boolean offScreen, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + + long nativeCtx = createNewContext(cv, display, unbox(drawable), + fbConfig, unbox(shareCtx), isSharedCtx, + offScreen, + glslLibraryAvailable, + cgLibraryAvailable); + + return boxContext(nativeCtx); + } + + native void createQueryContext(Canvas3D cv, long display, long drawable, + long fbConfig, boolean offScreen, int width, int height, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable); + + void createQueryContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, boolean offScreen, int width, int height, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + + createQueryContext(cv, display, unbox(drawable), + fbConfig, offScreen, width, height, + glslLibraryAvailable, + cgLibraryAvailable); + } + + // This is the native for creating offscreen buffer + native long createOffScreenBuffer(Canvas3D cv, long ctx, long display, long fbConfig, int width, int height); + + Drawable createOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, int width, int height) { + long nativeDrawable = createOffScreenBuffer(cv, unbox(ctx), display, fbConfig, width, height); + return boxDrawable(nativeDrawable); + } + + native void destroyOffScreenBuffer(Canvas3D cv, long ctx, long display, long fbConfig, long drawable); + + void destroyOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, Drawable drawable) { + destroyOffScreenBuffer(cv, unbox(ctx), display, fbConfig, unbox(drawable)); + } + + // This is the native for reading the image from the offscreen buffer + native void readOffScreenBuffer(Canvas3D cv, long ctx, int format, int type, Object data, int width, int height); + + void readOffScreenBuffer(Canvas3D cv, Context ctx, int format, int type, Object data, int width, int height) { + readOffScreenBuffer(cv, unbox(ctx), format, type, data, width, height); + } + + // The native method for swapBuffers + native int swapBuffers(Canvas3D cv, long ctx, long dpy, long drawable); + + int swapBuffers(Canvas3D cv, Context ctx, long dpy, Drawable drawable) { + return swapBuffers(cv, unbox(ctx), dpy, unbox(drawable)); + } + + + // notify D3D that Canvas is resize + native int resizeD3DCanvas(Canvas3D cv, long ctx); + + int resizeD3DCanvas(Canvas3D cv, Context ctx) { + return resizeD3DCanvas(cv, unbox(ctx)); + } + + + // notify D3D to toggle between FullScreen and window mode + native int toggleFullScreenMode(Canvas3D cv, long ctx); + + int toggleFullScreenMode(Canvas3D cv, Context ctx) { + return toggleFullScreenMode(cv, unbox(ctx)); + } + + + // native method for setting Material when no material is present + native void updateMaterialColor(long ctx, float r, float g, float b, float a); + + void updateMaterialColor(Context ctx, float r, float g, float b, float a) { + updateMaterialColor(unbox(ctx), r, g, b, a); + } + + + native void destroyContext(long display, long drawable, long ctx); + + void destroyContext(long display, Drawable drawable, Context ctx) { + assert display != 0 || VirtualUniverse.mc.isWindows(); + assert ctx != null; + assert drawable != null; + destroyContext(display, unbox(drawable), unbox(ctx)); + } + + + // This is the native method for doing accumulation. + native void accum(long ctx, float value); + + void accum(Context ctx, float value) { + accum(unbox(ctx), value); + } + + + // This is the native method for doing accumulation return. + native void accumReturn(long ctx); + + void accumReturn(Context ctx) { + accumReturn(unbox(ctx)); + } + + + // This is the native method for clearing the accumulation buffer. + native void clearAccum(long ctx); + + void clearAccum(Context ctx) { + clearAccum(unbox(ctx)); + } + + + // This is the native method for getting the number of lights the underlying + // native library can support. + native int getNumCtxLights(long ctx); + + int getNumCtxLights(Context ctx) { + return getNumCtxLights(unbox(ctx)); + } + + + // Native method for decal 1st child setup + native boolean decal1stChildSetup(long ctx); + + boolean decal1stChildSetup(Context ctx) { + return decal1stChildSetup(unbox(ctx)); + } + + + // Native method for decal nth child setup + native void decalNthChildSetup(long ctx); + + void decalNthChildSetup(Context ctx) { + decalNthChildSetup(unbox(ctx)); + } + + + // Native method for decal reset + native void decalReset(long ctx, boolean depthBufferEnable); + + void decalReset(Context ctx, boolean depthBufferEnable) { + decalReset(unbox(ctx), depthBufferEnable); + } + + + // Native method for decal reset + native void ctxUpdateEyeLightingEnable(long ctx, boolean localEyeLightingEnable); + + void ctxUpdateEyeLightingEnable(Context ctx, boolean localEyeLightingEnable) { + ctxUpdateEyeLightingEnable(unbox(ctx), localEyeLightingEnable); + } + + + // The following three methods are used in multi-pass case + + // native method for setting blend color + native void setBlendColor(long ctx, float red, float green, + float blue, float alpha); + + void setBlendColor(Context ctx, float red, float green, + float blue, float alpha) { + setBlendColor(unbox(ctx), red, green, + blue, alpha); + } + + + // native method for setting blend func + native void setBlendFunc(long ctx, int src, int dst); + + void setBlendFunc(Context ctx, int src, int dst) { + setBlendFunc(unbox(ctx), src, dst); + } + + + // native method for setting fog enable flag + native void setFogEnableFlag(long ctx, boolean enableFlag); + + void setFogEnableFlag(Context ctx, boolean enableFlag) { + setFogEnableFlag(unbox(ctx), enableFlag); + } + + + // Setup the full scene antialising in D3D and ogl when GL_ARB_multisamle supported + native void setFullSceneAntialiasing(long ctx, boolean enable); + + void setFullSceneAntialiasing(Context ctx, boolean enable) { + setFullSceneAntialiasing(unbox(ctx), enable); + } + + + native void setGlobalAlpha(long ctx, float alpha); + + void setGlobalAlpha(Context ctx, float alpha) { + setGlobalAlpha(unbox(ctx), alpha); + } + + + // Native method to update separate specular color control + native void updateSeparateSpecularColorEnable(long ctx, boolean control); + + void updateSeparateSpecularColorEnable(Context ctx, boolean control) { + updateSeparateSpecularColorEnable(unbox(ctx), control); + } + + + // Initialization for D3D when scene begin + native void beginScene(long ctx); + + void beginScene(Context ctx) { + beginScene(unbox(ctx)); + } + + native void endScene(long ctx); + + void endScene(Context ctx) { + endScene(unbox(ctx)); + } + + + // True under Solaris, + // False under windows when display mode <= 8 bit + native boolean validGraphicsMode(); + + // native method for setting light enables + native void setLightEnables(long ctx, long enableMask, int maxLights); + + void setLightEnables(Context ctx, long enableMask, int maxLights) { + setLightEnables(unbox(ctx), enableMask, maxLights); + } + + + // native method for setting scene ambient + native void setSceneAmbient(long ctx, float red, float green, float blue); + + void setSceneAmbient(Context ctx, float red, float green, float blue) { + setSceneAmbient(unbox(ctx), red, green, blue); + } + + + // native method for disabling fog + native void disableFog(long ctx); + + void disableFog(Context ctx) { + disableFog(unbox(ctx)); + } + + + // native method for disabling modelClip + native void disableModelClip(long ctx); + + void disableModelClip(Context ctx) { + disableModelClip(unbox(ctx)); + } + + + // native method for setting default RenderingAttributes + native void resetRenderingAttributes(long ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride); + + void resetRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride) { + resetRenderingAttributes(unbox(ctx), + depthBufferWriteEnableOverride, + depthBufferEnableOverride); + } + + + // native method for setting default texture + native void resetTextureNative(long ctx, int texUnitIndex); + + void resetTextureNative(Context ctx, int texUnitIndex) { + resetTextureNative(unbox(ctx), texUnitIndex); + } + + + // native method for activating a particular texture unit + native void activeTextureUnit(long ctx, int texUnitIndex); + + void activeTextureUnit(Context ctx, int texUnitIndex) { + activeTextureUnit(unbox(ctx), texUnitIndex); + } + + + // native method for setting default TexCoordGeneration + native void resetTexCoordGeneration(long ctx); + + void resetTexCoordGeneration(Context ctx) { + resetTexCoordGeneration(unbox(ctx)); + } + + + // native method for setting default TextureAttributes + native void resetTextureAttributes(long ctx); + + void resetTextureAttributes(Context ctx) { + resetTextureAttributes(unbox(ctx)); + } + + + // native method for setting default PolygonAttributes + native void resetPolygonAttributes(long ctx); + + void resetPolygonAttributes(Context ctx) { + resetPolygonAttributes(unbox(ctx)); + } + + + // native method for setting default LineAttributes + native void resetLineAttributes(long ctx); + + void resetLineAttributes(Context ctx) { + resetLineAttributes(unbox(ctx)); + } + + + // native method for setting default PointAttributes + native void resetPointAttributes(long ctx); + + void resetPointAttributes(Context ctx) { + resetPointAttributes(unbox(ctx)); + } + + + // native method for setting default TransparencyAttributes + native void resetTransparency(long ctx, int geometryType, + int polygonMode, boolean lineAA, + boolean pointAA); + + void resetTransparency(Context ctx, int geometryType, + int polygonMode, boolean lineAA, + boolean pointAA) { + resetTransparency(unbox(ctx), geometryType, + polygonMode, lineAA, + pointAA); + } + + + // native method for setting default ColoringAttributes + native void resetColoringAttributes(long ctx, + float r, float g, + float b, float a, + boolean enableLight); + + void resetColoringAttributes(Context ctx, + float r, float g, + float b, float a, + boolean enableLight) { + resetColoringAttributes(unbox(ctx), + r, g, + b, a, + enableLight); + } + + /** + * This native method makes sure that the rendering for this canvas + * gets done now. + */ + native void syncRender(long ctx, boolean wait); + + void syncRender(Context ctx, boolean wait) { + syncRender(unbox(ctx), wait); + } + + + // The native method that sets this ctx to be the current one + native boolean useCtx(long ctx, long display, long drawable); + + boolean useCtx(Context ctx, long display, Drawable drawable) { + assert display != 0 || VirtualUniverse.mc.isWindows(); + return useCtx(unbox(ctx), display, unbox(drawable)); + } + + native void clear(long ctx, float r, float g, float b); + + void clear(Context ctx, float r, float g, float b) { + clear(unbox(ctx), r, g, b); + + } + + native void textureFillBackground(long ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY); + + void textureFillBackground(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY) { + textureFillBackground(unbox(ctx), texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY); + } + + native void textureFillRaster(long ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha); + + void textureFillRaster(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha) { + textureFillRaster(unbox(ctx), texMinU, texMaxU, texMinV, texMaxV, + mapMinX, mapMaxX, mapMinY, mapMaxY, mapZ, alpha); + } + + native void executeRasterDepth(long ctx, float posX, float posY, float posZ, + int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight, + int depthWidth, int depthHeight, int depthType, Object depthData); + + void executeRasterDepth(Context ctx, float posX, float posY, float posZ, + int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight, + int depthWidth, int depthHeight, int depthType, Object depthData) { + executeRasterDepth(unbox(ctx), posX, posY, posZ, srcOffsetX, srcOffsetY, + rasterWidth, rasterHeight, depthWidth, depthHeight, depthType, depthData); + } + + // The native method for setting the ModelView matrix. + native void setModelViewMatrix(long ctx, double[] viewMatrix, double[] modelMatrix); + + void setModelViewMatrix(Context ctx, double[] viewMatrix, double[] modelMatrix) { + setModelViewMatrix(unbox(ctx), viewMatrix, modelMatrix); + } + + + // The native method for setting the Projection matrix. + native void setProjectionMatrix(long ctx, double[] projMatrix); + + void setProjectionMatrix(Context ctx, double[] projMatrix) { + setProjectionMatrix(unbox(ctx), projMatrix); + } + + + // The native method for setting the Viewport. + native void setViewport(long ctx, int x, int y, int width, int height); + + void setViewport(Context ctx, int x, int y, int width, int height) { + setViewport(unbox(ctx), x, y, width, height); + } + + + // used for display Lists + native void newDisplayList(long ctx, int displayListId); + + void newDisplayList(Context ctx, int displayListId) { + newDisplayList(unbox(ctx), displayListId); + } + + native void endDisplayList(long ctx); + + void endDisplayList(Context ctx) { + endDisplayList(unbox(ctx)); + } + + native void callDisplayList(long ctx, int id, boolean isNonUniformScale); + + void callDisplayList(Context ctx, int id, boolean isNonUniformScale) { + callDisplayList(unbox(ctx), id, isNonUniformScale); + } + + + native void freeDisplayList(long ctx, int id); + + void freeDisplayList(Context ctx, int id) { + freeDisplayList(unbox(ctx), id); + } + + native void freeTexture(long ctx, int id); + + void freeTexture(Context ctx, int id) { + freeTexture(unbox(ctx), id); + } + + native void texturemapping(long ctx, + int px, int py, + int xmin, int ymin, int xmax, int ymax, + int texWidth, int texHeight, + int rasWidth, + int format, int objectId, + byte[] image, + int winWidth, int winHeight); + + void texturemapping(Context ctx, + int px, int py, + int xmin, int ymin, int xmax, int ymax, + int texWidth, int texHeight, + int rasWidth, + int format, int objectId, + byte[] image, + int winWidth, int winHeight) { + texturemapping(unbox(ctx), + px, py, + xmin, ymin, xmax, ymax, + texWidth, texHeight, + rasWidth, + format, objectId, + image, + winWidth, winHeight); + } + + + native boolean initTexturemapping(long ctx, int texWidth, + int texHeight, int objectId); + + boolean initTexturemapping(Context ctx, int texWidth, + int texHeight, int objectId) { + return initTexturemapping(unbox(ctx), texWidth, + texHeight, objectId); + } + + + + // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or + // FIELD_RIGHT. Note that it is up to the caller to ensure that + // stereo is available before setting the mode to FIELD_LEFT or + // FIELD_RIGHT. The boolean isTRUE for double buffered mode, FALSE + // foe single buffering. + native void setRenderMode(long ctx, int mode, boolean doubleBuffer); + + void setRenderMode(Context ctx, int mode, boolean doubleBuffer) { + setRenderMode(unbox(ctx), mode, doubleBuffer); + } + + + // Set glDepthMask. + native void setDepthBufferWriteEnable(long ctx, boolean mode); + + void setDepthBufferWriteEnable(Context ctx, boolean mode) { + setDepthBufferWriteEnable(unbox(ctx), mode); + } + + + + // --------------------------------------------------------------------- + + // + // Canvas3D / GraphicsConfigTemplate3D methods - logic dealing with + // native graphics configuration or drawing surface + // + + // Return a graphics config based on the one passed in. Note that we can + // assert that the input config is non-null and was created from a + // GraphicsConfigTemplate3D. + // This method must return a valid GraphicsConfig, or else it must throw + // an exception if one cannot be returned. + GraphicsConfiguration getGraphicsConfig(GraphicsConfiguration gconfig) { +//KCR: System.err.println("NativePipeline.getGraphicsConfig()"); + + // Just return the input graphics config + return gconfig; + } + + // Get the native FBconfig pointer + long getFbConfig(GraphicsConfigInfo gcInfo) { + long fbConfig = ((Long)gcInfo.getPrivateData()).longValue(); + if (fbConfig == 0L) { + throw new IllegalArgumentException(J3dI18N.getString("Canvas3D23")); + } + + return fbConfig; + } + + // Get best graphics config from pipeline + GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D gct, + GraphicsConfiguration[] gc) { + return nativeTemplate.getBestConfiguration(gct, gc); + } + + // Determine whether specified graphics config is supported by pipeline + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D gct, + GraphicsConfiguration gc) { + return nativeTemplate.isGraphicsConfigSupported(gct, gc); + } + + // Methods to get actual capabilities from Canvas3D + boolean hasDoubleBuffer(Canvas3D cv) { + return nativeTemplate.hasDoubleBuffer(cv); + } + + boolean hasStereo(Canvas3D cv) { + return nativeTemplate.hasStereo(cv); + } + + int getStencilSize(Canvas3D cv) { + return nativeTemplate.getStencilSize(cv); + } + + boolean hasSceneAntialiasingMultisample(Canvas3D cv) { + return nativeTemplate.hasSceneAntialiasingMultisample(cv); + } + + boolean hasSceneAntialiasingAccum(Canvas3D cv) { + return nativeTemplate.hasSceneAntialiasingAccum(cv); + } + + // Methods to get native WS display and screen + long getDisplay() { + return NativeScreenInfo.getDisplay(); + } + int getScreen(GraphicsDevice graphicsDevice) { + return NativeScreenInfo.getScreen(graphicsDevice); + } + + // --------------------------------------------------------------------- + + // + // DrawingSurfaceObject methods + // + + // Method to construct a new DrawingSurfaceObject + DrawingSurfaceObject createDrawingSurfaceObject(Canvas3D cv) { + return new DrawingSurfaceObjectAWT(cv, + VirtualUniverse.mc.awt, cv.screen.display, cv.screen.screen, + VirtualUniverse.mc.xineramaDisabled); + } + + + // Method to free the drawing surface object + // (called from Canvas3D.removeNotify) + void freeDrawingSurface(Canvas3D cv, DrawingSurfaceObject drawingSurfaceObject) { + synchronized (drawingSurfaceObject) { + DrawingSurfaceObjectAWT dso = + (DrawingSurfaceObjectAWT)drawingSurfaceObject; + // get nativeDS before it is set to 0 in invalidate() + long ds = dso.getDS(); + long ds_struct[] = {ds, dso.getDSI()}; + if (ds != 0) { + VirtualUniverse.mc.postRequest( + MasterControl.FREE_DRAWING_SURFACE, + ds_struct); + } + + drawingSurfaceObject.invalidate(); + } + } + + // Method to free the native drawing surface object + void freeDrawingSurfaceNative(Object o) { + DrawingSurfaceObjectAWT.freeDrawingSurface(o); + } + +} diff --git a/src/classes/share/javax/media/j3d/NativeShaderObject.java b/src/classes/share/javax/media/j3d/NativeShaderObject.java new file mode 100644 index 0000000..050fb37 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativeShaderObject.java @@ -0,0 +1,31 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Shader objects for native rendering pipeline. + */ +class NativeShaderObject implements ShaderProgramId, ShaderId, ShaderAttrLoc { + + // Native shader object; + private long nativeId; + + NativeShaderObject(long nativeId) { + this.nativeId = nativeId; + } + + long getNativeId() { + return nativeId; + } + +} diff --git a/src/classes/share/javax/media/j3d/NioImageBuffer.java b/src/classes/share/javax/media/j3d/NioImageBuffer.java new file mode 100644 index 0000000..91ebe92 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NioImageBuffer.java @@ -0,0 +1,379 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; + +/** + * The NioImageBuffer class is a container for an image whose DataBuffer + * is specified via a java.nio.Buffer. An an NioImageBuffer can be wrapped by + * an ImageComponent and used for texture mapping, or for rendering Raster + * objects or background images. An NioImageBuffer must not be used as the + * buffer of an off-screen Canvas3D, or for reading back a raster image. + * + * @see ImageComponent2D + * @see ImageComponent3D + * + * @since Java 3D 1.5 + */ +public class NioImageBuffer { + + /** + * Used to specify the type of the image. + */ + public enum ImageType { + /** + * Represents an image with 8-bit RGB color components, + * corresponding to a Windows-style BGR color model, with the + * colors Blue, Green, and Red stored in 3 consecutive + * bytes for each pixel. + * The data buffer must be a ByteBuffer when using this imageType. + */ + TYPE_3BYTE_BGR, + + /** + * Represents an image with 8-bit RGB color components with + * Red, Green, and Blue, stored in 3 consecutive + * bytes for each pixel. + * The data buffer must be a ByteBuffer when using this imageType. + */ + TYPE_3BYTE_RGB, + + /** + * Represents an image with 8-bit RGBA color components with + * Alpha, Blue, Green, and Red stored in 4 consecutive + * bytes for each pixel. + * The data buffer must be a ByteBuffer when using this imageType. + */ + TYPE_4BYTE_ABGR, + + /** + * Represents an image with 8-bit RGBA color components with + * Red, Green, Blue, and Alpha stored in 4 consecutive + * bytes for each pixel. + * The data buffer must be a ByteBuffer when using this imageType. + */ + TYPE_4BYTE_RGBA, + + /** + * Represents a unsigned byte grayscale image, non-indexed. + * The data buffer must be a ByteBuffer when using this imageType. + */ + TYPE_BYTE_GRAY, + + /** + * Represents an image with 8-bit RGBA color components packed + * into integer pixels. + * The data buffer must be an IntBuffer when using this imageType. + */ + TYPE_INT_ARGB, + + /** + * Represents an image with 8-bit RGB color components, + * corresponding to a Windows- or Solaris- style BGR color model, + * with the colors Blue, Green, and Red packed into integer + * pixels. + * The data buffer must be an IntBuffer when using this imageType. + */ + TYPE_INT_BGR, + + /** + * Represents an image with 8-bit RGB color components packed into + * integer pixels. + * The data buffer must be an IntBuffer when using this imageType. + */ + TYPE_INT_RGB, + + } + + + /** + * Enum for type of buffer + */ + enum BufferType { + BYTE_BUFFER, + INT_BUFFER, + } + + + // Width and height of image + int width; + int height; + + // TYpe of image + ImageType imageType; + + // Cached buffer + Buffer buffer; + + // Type of NIO Buffer: byte or int + BufferType bufferType; + + // Number of bytes allocated per pixel + int bytesPerPixel; + + // Number of byte or int elements per pixel + int elementsPerPixel; + + /** + * Constructs an NIO image buffer of the specified size and type. + * A direct NIO buffer of the correct type (ByteBuffer or IntBuffer) + * and size to match the input parameters + * is allocated. + * + * @param width width of the image + * @param height height of the image + * @param imageType type of the image. + * + * @exception IllegalArgumentException if width < 1 or height < 1 + * @exception NullPointerException if imageType is null + */ + public NioImageBuffer(int width, int height, ImageType imageType) { + + processParams(width, height, imageType); + + ByteBuffer tmpBuffer = ByteBuffer.allocateDirect(width * height * bytesPerPixel); + switch (bufferType) { + case BYTE_BUFFER: + buffer = tmpBuffer; + break; + + case INT_BUFFER: + buffer = tmpBuffer.order(ByteOrder.nativeOrder()).asIntBuffer(); + break; + + default: + // We should never get here + throw new AssertionError("missing case statement"); + } + } + + /** + * Constructs an NIO image buffer of the specified size and type, using + * the specified dataBuffer. + * The the byte order of the specified dataBuffer must match the native + * byte order of the underlying platform. + * For best performance, the NIO buffer should be a direct buffer. + * + * @param width width of the image + * @param height height of the image + * @param imageType type of the image. + * @param dataBuffer an NIO buffer of the correct type (ByteBuffer or + * IntBuffer) to match the specified imageType. + * This constructor will create a new view of + * the buffer, and will call rewind on that view, + * such that elements 0 through dataBuffer.limit()-1 + * will be available internally. The number of elements in + * the buffer must be exactly width*height*numElementsPerPixel, + * where numElementsPerPixel is + * 3 for TYPE_3BYTE_BGR and TYPE_3BYTE_RGB, + * 4 for TYPE_4BYTE_ABGR and TYPE_4BYTE_RGBA, + * and 1 for all other types. + * + * @exception IllegalArgumentException if width < 1 or height < 1 + * @exception NullPointerException if imageType or dataBuffer is null + * @exception IllegalArgumentException if the type of the dataBuffer does + * not match the imageType + * @exception IllegalArgumentException if dataBuffer.limit() != + * width*height*numElementsPerPixel + * @exception IllegalArgumentException if the byte order of the specified + * dataBuffer does not match the native byte order of the underlying + * platform. + */ + public NioImageBuffer(int width, int height, ImageType imageType, + Buffer dataBuffer) { + + processParams(width, height, imageType); + setDataBuffer(dataBuffer); + } + + /** + * Gets the width of this data buffer. + * + * @return the width of this data buffer. + */ + public int getWidth() { + return width; + } + + /** + * Gets the height of this data buffer. + * + * @return the width of this data buffer. + */ + public int getHeight() { + return height; + } + + /** + * Gets the image type of this data buffer. + * + * @return the image type of this data buffer. + */ + public ImageType getImageType() { + return imageType; + } + + /** + * Sets the data buffer to the specified input data buffer. + * The the byte order of the specified dataBuffer must match the native + * byte order of the underlying platform. + * For best performance, the NIO buffer should be a direct buffer. + * + * @param dataBuffer an NIO buffer of the correct type (ByteBuffer or + * IntBuffer) to match the imageType of this + * NioImageBuffer. This method will create a new view of + * the buffer, and will call rewind on that view, + * such that elements 0 through dataBuffer.limit()-1 + * will be available internally. The number of elements in + * the buffer must be exactly width*height*numElementsPerPixel, + * where numElementsPerPixel is + * 3 for TYPE_3BYTE_BGR and TYPE_3BYTE_RGB, + * 4 for TYPE_4BYTE_ABGR and TYPE_4BYTE_RGBA, + * and 1 for all other types. + * + * @exception NullPointerException if dataBuffer is null + * @exception IllegalArgumentException if the type of the dataBuffer does + * not match the imageType + * @exception IllegalArgumentException if dataBuffer.limit() != + * width*height*numElementsPerPixel + * @exception IllegalArgumentException if the byte order of the specified + * dataBuffer does not match the native byte order of the underlying + * platform. + */ + public void setDataBuffer(Buffer dataBuffer) { + if (dataBuffer == null) { + throw new NullPointerException(); + } + + if (dataBuffer.limit() != width*height*elementsPerPixel) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer3")); + } + + switch (bufferType) { + case BYTE_BUFFER: + if (!(dataBuffer instanceof ByteBuffer)) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer4")); + } + buffer = ((ByteBuffer)dataBuffer).duplicate().rewind(); + break; + + case INT_BUFFER: + if (!(dataBuffer instanceof IntBuffer)) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer4")); + } + + if (((IntBuffer)dataBuffer).order() != ByteOrder.nativeOrder()) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer5")); + } + buffer = ((IntBuffer)dataBuffer).duplicate().rewind(); + break; + + default: + // We should never get here + throw new AssertionError("missing case statement"); + } + } + + /** + * Gets the data buffer to the specified input data buffer. + * + * @return a view of the current data buffer for this NIO image buffer. + * This view will be rewound such that elements 0 + * through dataBuffer.limit()-1 are available. + */ + public Buffer getDataBuffer() { + Buffer tmpBuffer = null; + + switch (bufferType) { + case BYTE_BUFFER: + tmpBuffer = ((ByteBuffer)buffer).duplicate(); + break; + + case INT_BUFFER: + tmpBuffer = ((IntBuffer)buffer).duplicate(); + break; + + default: + // We should never get here + throw new AssertionError("missing case statement"); + } + + return tmpBuffer.rewind(); + } + + + // Sanity check the input parameters, calculate the buffer type and + // the number of bytes per pixel + private void processParams(int width, int height, ImageType imageType) { + if (width < 1) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer0")); + } + + if (height < 1) { + throw new IllegalArgumentException(J3dI18N.getString("NioImageBuffer1")); + } + + switch (imageType) { + case TYPE_3BYTE_BGR: + bufferType = BufferType.BYTE_BUFFER; + bytesPerPixel = 3; + elementsPerPixel = 3; + break; + + case TYPE_3BYTE_RGB: + bufferType = BufferType.BYTE_BUFFER; + bytesPerPixel = 3; + elementsPerPixel = 3; + break; + + case TYPE_4BYTE_ABGR: + bufferType = BufferType.BYTE_BUFFER; + bytesPerPixel = 4; + elementsPerPixel = 4; + break; + + case TYPE_4BYTE_RGBA: + bufferType = BufferType.BYTE_BUFFER; + bytesPerPixel = 4; + elementsPerPixel = 4; + break; + + case TYPE_BYTE_GRAY: + bufferType = BufferType.BYTE_BUFFER; + bytesPerPixel = 1; + elementsPerPixel = 1; + break; + + case TYPE_INT_ARGB: + case TYPE_INT_BGR: + case TYPE_INT_RGB: + bufferType = BufferType.INT_BUFFER; + bytesPerPixel = 4; + elementsPerPixel = 1; + break; + + default: + // We should never get here + throw new AssertionError("missing case statement"); + } + + this.width = width; + this.height = height; + this.imageType = imageType; + } + +} diff --git a/src/classes/share/javax/media/j3d/NodeComponent.java b/src/classes/share/javax/media/j3d/NodeComponent.java index 524814e..0498ae5 100644 --- a/src/classes/share/javax/media/j3d/NodeComponent.java +++ b/src/classes/share/javax/media/j3d/NodeComponent.java @@ -265,4 +265,29 @@ public abstract class NodeComponent extends SceneGraphObject { boolean duplicateChild() { return getDuplicateOnCloneTree(); } + + /* + * @exception IllegalSharingException if this NodeComponent is live and + * the specified image is being used by a Canvas3D as an off-screen buffer. + * + * @exception IllegalSharingException if this NodeComponent is + * being used by an immediate mode context and + * the specified image is being used by a Canvas3D as an off-screen buffer. + */ + void validateImageIllegalSharing(ImageComponent image) { + // Do illegal sharing check + if(image != null) { + ImageComponentRetained imageRetained = (ImageComponentRetained) image.retained; + NodeComponentRetained ncRetained = (NodeComponentRetained)this.retained; + if(imageRetained.getUsedByOffScreen()) { + if(isLive()) { + throw new IllegalSharingException(J3dI18N.getString("NodeComponent2")); + } + if(ncRetained.getInImmCtx()) { + throw new IllegalSharingException(J3dI18N.getString("NodeComponent3")); + } + } + } + } + } diff --git a/src/classes/share/javax/media/j3d/NodeComponentRetained.java b/src/classes/share/javax/media/j3d/NodeComponentRetained.java index 8b25c27..5af65a0 100644 --- a/src/classes/share/javax/media/j3d/NodeComponentRetained.java +++ b/src/classes/share/javax/media/j3d/NodeComponentRetained.java @@ -43,7 +43,7 @@ class NodeComponentRetained extends SceneGraphObjectRetained { // In the case of Appearance, its a bitmask of all components int changedFrequent = 0; int compChanged = 0; - + // Increment the refcount. If this is the first, mark it as live. void doSetLive(boolean inBackgroundGroup, int refCount) { int oldRefCount = this.refCount; @@ -212,21 +212,13 @@ class NodeComponentRetained extends SceneGraphObjectRetained { mirror = null; } - // Evaluate state based on the following extensions - void evaluateExtensions(int extensions) { - } - - - - void setFrequencyChangeMask(int bit, int mask) { - // Record only the inf->frequent change if (source.getCapabilityIsFrequent(bit)) changedFrequent |= mask; else if (!source.isLive()) { + // Record the freq->infreq change only for non-live node components changedFrequent &= ~mask; } - } protected Object clone() { diff --git a/src/classes/share/javax/media/j3d/NodeRetained.java b/src/classes/share/javax/media/j3d/NodeRetained.java index 7742891..bb833a4 100644 --- a/src/classes/share/javax/media/j3d/NodeRetained.java +++ b/src/classes/share/javax/media/j3d/NodeRetained.java @@ -363,10 +363,9 @@ abstract class NodeRetained extends SceneGraphObjectRetained implements NnuId { } if((nodeR instanceof TransformGroupRetained) && (nodeR != caller)) { - Transform3D t1 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t1 = new Transform3D(); ((TransformGroupRetained)(nodeR)).transform.getWithLock(t1); l2Vw.mul(t1); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t1); } else if ((nodeR == caller) && (staticTransform != null)) { l2Vw.mul(staticTransform.transform); } diff --git a/src/classes/share/javax/media/j3d/NoopDrawingSurfaceObject.java b/src/classes/share/javax/media/j3d/NoopDrawingSurfaceObject.java new file mode 100644 index 0000000..5fb3c01 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NoopDrawingSurfaceObject.java @@ -0,0 +1,57 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * The DrawingSurfaceObject class is used to manage native drawing surface + */ +class NoopDrawingSurfaceObject extends DrawingSurfaceObject { + + NoopDrawingSurfaceObject(Canvas3D cv) { + super(cv); + + System.err.println("NoopDrawingSurfaceObject constructed"); + } + + synchronized boolean renderLock() { + System.err.println("NoopDrawingSurfaceObject.renderLock()"); + gotDsiLock = true; + return true; + } + + synchronized void unLock() { + System.err.println("NoopDrawingSurfaceObject.unLock()"); + gotDsiLock = false; + } + + synchronized void getDrawingSurfaceObjectInfo() { + if (canvas.drawable == null) { + System.err.println( + "NoopDrawingSurfaceObject.getDrawingSurfaceObjectInfo: window = " + + canvas.drawable); + + canvas.drawable = new NoopDrawable(); + } + } + + synchronized void invalidate() { + System.err.println("NoopDrawingSurfaceObject.invalidate()"); + } + + /** + * Dummy drawable for noop pipeline + */ + static class NoopDrawable implements Drawable { + } + +} diff --git a/src/classes/share/javax/media/j3d/NoopPipeline.java b/src/classes/share/javax/media/j3d/NoopPipeline.java new file mode 100644 index 0000000..09e7b04 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NoopPipeline.java @@ -0,0 +1,1561 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; + +/** + * Concrete implementation of Pipeline class for the noop rendering + * pipeline. + */ +class NoopPipeline extends Pipeline { + + // Flags indicating whether the Cg or GLSL libraries are available. + private boolean cgLibraryAvailable = false; + + /** + * Constructor for singleton NoopPipeline instance + */ + protected NoopPipeline() { + } + + /** + * Initialize the pipeline + */ + void initialize(Pipeline.Type pipelineType) { + super.initialize(pipelineType); + + assert pipelineType == Pipeline.Type.NOOP; + } + + /** + * Load all of the required libraries + */ + void loadLibraries(int globalShadingLanguage) { + } + + /** + * Returns true if the Cg library is loaded and available. Note that this + * does not necessarily mean that Cg is supported by the graphics card. + */ + boolean isCgLibraryAvailable() { + return cgLibraryAvailable; + } + + /** + * Returns true if the GLSL library is loaded and available. Note that this + * does not necessarily mean that GLSL is supported by the graphics card. + */ + boolean isGLSLLibraryAvailable() { + return true; + } + + + // --------------------------------------------------------------------- + + // + // GeometryArrayRetained methods + // + + // Used by D3D to free vertex buffer + void freeD3DArray(GeometryArrayRetained geo, boolean deleteVB) { + } + + // used for GeometryArrays by Copy or interleaved + void execute(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + int vertexAttrCount, int[] vertexAttrSizes, + float[] varray, float[] cdata, int cdirty) { + } + + // used by GeometryArray by Reference with java arrays + void executeVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty) { + } + + // used by GeometryArray by Reference with NIO buffer + void executeVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, + Object vcoords, + int colorIndex, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + int normalIndex, Object ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty) { + } + + // used by GeometryArray by Reference in interleaved format with NIO buffer + void executeInterleavedBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, int cdirty) { + } + + void setVertexFormat(Context ctx, GeometryArrayRetained geo, + int vformat, boolean useAlpha, boolean ignoreVertexColors) { + } + + void disableGlobalAlpha(Context ctx, GeometryArrayRetained geo, int vformat, + boolean useAlpha, boolean ignoreVertexColors) { + } + + // used for GeometryArrays + void buildGA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int startVIndex, + int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, int[] texCoordSetMapOffset, + int vertexAttrCount, int[] vertexAttrSizes, + double[] xform, double[] nxform, + float[] varray) { + } + + // used to Build Dlist GeometryArray by Reference with java arrays + void buildGAForByRef(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int[] texIndex, int texstride, Object[] texCoords, + double[] xform, double[] nxform) { + } + + + // --------------------------------------------------------------------- + + // + // IndexedGeometryArrayRetained methods + // + + // by-copy or interleaved, by reference, Java arrays + void executeIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + float[] varray, float[] cdata, + int cdirty, + int[] indexCoord) { + } + + // interleaved, by reference, nio buffer + void executeIndexedGeometryBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, + int cdirty, + int[] indexCoord) { + } + + // non interleaved, by reference, Java arrays + void executeIndexedGeometryVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + float[] vfcoords, double[] vdcoords, + float[] cfdata, byte[] cbdata, + float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord) { + } + + // non interleaved, by reference, nio buffer + void executeIndexedGeometryVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + Object vcoords, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + Object normal, + int vertexAttrCount, int[] vertexAttrSizes, + Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord) { + } + + // by-copy geometry + void buildIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetMapOffset, + double[] xform, double[] nxform, + float[] varray, int[] indexCoord) { + } + + + // --------------------------------------------------------------------- + + // + // GraphicsContext3D methods + // + + void readRaster(Context ctx, + int type, int xSrcOffset, int ySrcOffset, + int width, int height, int hCanvas, + int imageDataType, int imageFormat, + Object imageBuffer, + int depthFormat, + Object depthBuffer) { + + } + + // --------------------------------------------------------------------- + + // + // CgShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + ShaderError setCgUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + return null; + } + + ShaderError setCgUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + return null; + } + + ShaderError setCgUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setCgUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setCgUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setCgUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setCgUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setCgUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setCgUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setCgUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + // ShaderAttributeArray methods + + ShaderError setCgUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setCgUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setCgUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setCgUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setCgUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setCgUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setCgUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setCgUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setCgUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setCgUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + // interfaces for shader compilation, etc. + ShaderError createCgShader(Context ctx, int shaderType, ShaderId[] shaderId) { + return null; + } + ShaderError destroyCgShader(Context ctx, ShaderId shaderId) { + return null; + } + ShaderError compileCgShader(Context ctx, ShaderId shaderId, String program) { + return null; + } + + ShaderError createCgShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId) { + return null; + } + ShaderError destroyCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return null; + } + ShaderError linkCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds) { + return null; + } + void lookupCgVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, boolean[] errArr) { + } + void lookupCgShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr) { + } + + ShaderError useCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return null; + } + + + // --------------------------------------------------------------------- + + // + // GLSLShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + ShaderError setGLSLUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value) { + return null; + } + + ShaderError setGLSLUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value) { + return null; + } + + ShaderError setGLSLUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setGLSLUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setGLSLUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setGLSLUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setGLSLUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value) { + return null; + } + + ShaderError setGLSLUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setGLSLUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + ShaderError setGLSLUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value) { + return null; + } + + // ShaderAttributeArray methods + + ShaderError setGLSLUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setGLSLUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setGLSLUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setGLSLUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setGLSLUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setGLSLUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setGLSLUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value) { + return null; + } + + ShaderError setGLSLUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setGLSLUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + ShaderError setGLSLUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value) { + return null; + } + + // interfaces for shader compilation, etc. + ShaderError createGLSLShader(Context ctx, int shaderType, ShaderId[] shaderId) { + return null; + } + ShaderError destroyGLSLShader(Context ctx, ShaderId shaderId) { + return null; + } + ShaderError compileGLSLShader(Context ctx, ShaderId shaderId, String program) { + return null; + } + + ShaderError createGLSLShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId) { + return null; + } + ShaderError destroyGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return null; + } + ShaderError linkGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds) { + return null; + } + ShaderError bindGLSLVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, + String attrName, int attrIndex) { + return null; + } + void lookupGLSLShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr) { + } + + ShaderError useGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId) { + return null; + } + + + // --------------------------------------------------------------------- + + // + // ImageComponent2DRetained methods + // + + // free d3d surface referred to by id + void freeD3DSurface(ImageComponent2DRetained image, int hashId) { + } + + + + // --------------------------------------------------------------------- + + // + // Renderer methods + // + + void cleanupRenderer() { + } + + + // --------------------------------------------------------------------- + + // + // ColoringAttributesRetained methods + // + + void updateColoringAttributes(Context ctx, + float dRed, float dGreen, float dBlue, + float red, float green, float blue, + float alpha, + boolean lEnable, + int shadeModel) { + } + + + // --------------------------------------------------------------------- + + // + // DirectionalLightRetained methods + // + + void updateDirectionalLight(Context ctx, + int lightSlot, float red, float green, + float blue, float x, float y, float z) { + } + + + // --------------------------------------------------------------------- + + // + // PointLightRetained methods + // + + void updatePointLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz) { + } + + + // --------------------------------------------------------------------- + + // + // SpotLightRetained methods + // + + void updateSpotLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz, float spreadAngle, + float concentration, float dx, float dy, + float dz) { + } + + + // --------------------------------------------------------------------- + + // + // ExponentialFogRetained methods + // + + void updateExponentialFog(Context ctx, + float red, float green, float blue, + float density) { + } + + + // --------------------------------------------------------------------- + + // + // LinearFogRetained methods + // + + void updateLinearFog(Context ctx, + float red, float green, float blue, + double fdist, double bdist) { + } + + + // --------------------------------------------------------------------- + + // + // LineAttributesRetained methods + // + + void updateLineAttributes(Context ctx, + float lineWidth, int linePattern, + int linePatternMask, + int linePatternScaleFactor, + boolean lineAntialiasing) { + } + + + // --------------------------------------------------------------------- + + // + // MaterialRetained methods + // + + void updateMaterial(Context ctx, + float red, float green, float blue, float alpha, + float ared, float agreen, float ablue, + float ered, float egreen, float eblue, + float dred, float dgreen, float dblue, + float sred, float sgreen, float sblue, + float shininess, int colorTarget, boolean enable) { + } + + + // --------------------------------------------------------------------- + + // + // ModelClipRetained methods + // + + void updateModelClip(Context ctx, int planeNum, boolean enableFlag, + double A, double B, double C, double D) { + } + + + // --------------------------------------------------------------------- + + // + // PointAttributesRetained methods + // + + void updatePointAttributes(Context ctx, float pointSize, boolean pointAntialiasing) { + } + + + // --------------------------------------------------------------------- + + // + // PolygonAttributesRetained methods + // + + void updatePolygonAttributes(Context ctx, + int polygonMode, int cullFace, + boolean backFaceNormalFlip, + float polygonOffset, + float polygonOffsetFactor) { + } + + + // --------------------------------------------------------------------- + + // + // RenderingAttributesRetained methods + // + + void updateRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride, + boolean depthBufferEnable, + boolean depthBufferWriteEnable, + int depthTestFunction, + float alphaTestValue, int alphaTestFunction, + boolean ignoreVertexColors, + boolean rasterOpEnable, int rasterOp, + boolean userStencilAvailable, boolean stencilEnable, + int stencilFailOp, int stencilZFailOp, int stencilZPassOp, + int stencilFunction, int stencilReferenceValue, + int stencilCompareMask, int stencilWriteMask ) { + } + + + // --------------------------------------------------------------------- + + // + // TexCoordGenerationRetained methods + // + + /** + * This method updates the native context: + * trans contains eyeTovworld transform in d3d + * trans contains vworldToEye transform in ogl + */ + void updateTexCoordGeneration(Context ctx, + boolean enable, int genMode, int format, + float planeSx, float planeSy, float planeSz, float planeSw, + float planeTx, float planeTy, float planeTz, float planeTw, + float planeRx, float planeRy, float planeRz, float planeRw, + float planeQx, float planeQy, float planeQz, float planeQw, + double[] trans) { + } + + + // --------------------------------------------------------------------- + + // + // TransparencyAttributesRetained methods + // + + void updateTransparencyAttributes(Context ctx, + float alpha, int geometryType, + int polygonMode, + boolean lineAA, boolean pointAA, + int transparencyMode, + int srcBlendFunction, + int dstBlendFunction) { + } + + + // --------------------------------------------------------------------- + + // + // TextureAttributesRetained methods + // + + void updateTextureAttributes(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat) { + } + + void updateRegisterCombiners(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale) { + } + + void updateTextureColorTable(Context ctx, int numComponents, + int colorTableSize, + int[] colorTable) { + } + + void updateCombiner(Context ctx, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale) { + } + + + // --------------------------------------------------------------------- + + // + // TextureUnitStateRetained methods + // + + void updateTextureUnitState(Context ctx, int unitIndex, boolean enableFlag) { + } + + + // --------------------------------------------------------------------- + + // + // TextureRetained methods + // Texture2DRetained methods + // + + void bindTexture2D(Context ctx, int objectId, boolean enable) { + } + + void updateTexture2DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object data) { + } + + void updateTexture2DSubImage(Context ctx, + int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object data) { + } + + void updateTexture2DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + } + + void updateTexture2DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + } + + void updateTexture2DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha) { + } + + void updateTexture2DFilterModes(Context ctx, + int minFilter, int magFilter) { + } + + void updateTexture2DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + } + + void updateTexture2DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + } + + void updateTexture2DAnisotropicFilter(Context ctx, float degree) { + } + + + // --------------------------------------------------------------------- + + // + // Texture3DRetained methods + // + + void bindTexture3D(Context ctx, int objectId, boolean enable) { + } + + void updateTexture3DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, int depth, + int boundaryWidth, + int imageDataType, Object imageData) { + } + + void updateTexture3DSubImage(Context ctx, + int level, + int xoffset, int yoffset, int zoffset, + int textureFormat, int imageFormat, + int imgXoffset, int imgYoffset, int imgZoffset, + int tilew, int tileh, + int width, int height, int depth, + int imageTypeData, Object imageData) { + } + + void updateTexture3DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + } + + void updateTexture3DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + } + + void updateTexture3DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + int boundaryModeR, float boundaryRed, + float boundaryGreen, float boundaryBlue, + float boundaryAlpha) { + } + + void updateTexture3DFilterModes(Context ctx, + int minFilter, int magFilter) { + } + + void updateTexture3DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + } + + void updateTexture3DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + } + + void updateTexture3DAnisotropicFilter(Context ctx, float degree) { + } + + + // --------------------------------------------------------------------- + + // + // TextureCubeMapRetained methods + // + + void bindTextureCubeMap(Context ctx, int objectId, boolean enable) { + } + + void updateTextureCubeMapImage(Context ctx, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object imageData) { + } + + void updateTextureCubeMapSubImage(Context ctx, + int face, int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object imageData) { + } + + void updateTextureCubeMapLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + } + + void updateTextureCubeMapLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + } + + void updateTextureCubeMapBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha) { + } + + void updateTextureCubeMapFilterModes(Context ctx, + int minFilter, int magFilter) { + } + + void updateTextureCubeMapSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + } + + void updateTextureCubeMapFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + } + + void updateTextureCubeMapAnisotropicFilter(Context ctx, float degree) { + } + + // --------------------------------------------------------------------- + + // + // MasterControl methods + // + + // Method to return the AWT object + long getAWT() { + return 0L; + } + + // Method to initialize the native J3D library + boolean initializeJ3D(boolean disableXinerama) { + return true; + } + + // Maximum lights supported by the native API + int getMaximumLights() { + return 8; + } + + + // --------------------------------------------------------------------- + + // + // Canvas3D methods - native wrappers + // + + // This is the native method for creating the underlying graphics context. + Context createNewContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, Context shareCtx, boolean isSharedCtx, + boolean offScreen, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + return new NoopContext(); + } + + void createQueryContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, boolean offScreen, int width, int height, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable) { + } + + // This is the native for creating offscreen buffer + Drawable createOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, int width, int height) { + return null; + } + + void destroyOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, Drawable drawable) { + } + + // This is the native for reading the image from the offscreen buffer + void readOffScreenBuffer(Canvas3D cv, Context ctx, int format, int type, Object data, int width, int height) { + } + + // The native method for swapBuffers + int swapBuffers(Canvas3D cv, Context ctx, long dpy, Drawable drawable) { + return 0; + } + + // notify D3D that Canvas is resize + int resizeD3DCanvas(Canvas3D cv, Context ctx) { + return 0; + } + + // notify D3D to toggle between FullScreen and window mode + int toggleFullScreenMode(Canvas3D cv, Context ctx) { + return 0; + } + + // native method for setting Material when no material is present + void updateMaterialColor(Context ctx, float r, float g, float b, float a) { + } + + void destroyContext(long display, Drawable drawable, Context ctx) { + } + + // This is the native method for doing accumulation. + void accum(Context ctx, float value) { + } + + // This is the native method for doing accumulation return. + void accumReturn(Context ctx) { + } + + // This is the native method for clearing the accumulation buffer. + void clearAccum(Context ctx) { + } + + // This is the native method for getting the number of lights the underlying + // native library can support. + int getNumCtxLights(Context ctx) { + return 0; + } + + // Native method for decal 1st child setup + boolean decal1stChildSetup(Context ctx) { + return false; + } + + // Native method for decal nth child setup + void decalNthChildSetup(Context ctx) { + } + + // Native method for decal reset + void decalReset(Context ctx, boolean depthBufferEnable) { + } + + // Native method for decal reset + void ctxUpdateEyeLightingEnable(Context ctx, boolean localEyeLightingEnable) { + } + + // The following three methods are used in multi-pass case + + // native method for setting blend color + void setBlendColor(Context ctx, float red, float green, + float blue, float alpha) { + } + + // native method for setting blend func + void setBlendFunc(Context ctx, int src, int dst) { + } + + // native method for setting fog enable flag + void setFogEnableFlag(Context ctx, boolean enableFlag) { + } + + // Setup the full scene antialising in D3D and ogl when GL_ARB_multisamle supported + void setFullSceneAntialiasing(Context ctx, boolean enable) { + } + + void setGlobalAlpha(Context ctx, float alpha) { + } + + // Native method to update separate specular color control + void updateSeparateSpecularColorEnable(Context ctx, boolean control) { + } + + // Initialization for D3D when scene begin + void beginScene(Context ctx) { + } + void endScene(Context ctx) { + } + + // True under Solaris, + // False under windows when display mode <= 8 bit + boolean validGraphicsMode() { + return true; + } + + // native method for setting light enables + void setLightEnables(Context ctx, long enableMask, int maxLights) { + } + + // native method for setting scene ambient + void setSceneAmbient(Context ctx, float red, float green, float blue) { + } + + // native method for disabling fog + void disableFog(Context ctx) { + } + + // native method for disabling modelClip + void disableModelClip(Context ctx) { + } + + // native method for setting default RenderingAttributes + void resetRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride) { + } + + // native method for setting default texture + void resetTextureNative(Context ctx, int texUnitIndex) { + } + + // native method for activating a particular texture unit + void activeTextureUnit(Context ctx, int texUnitIndex) { + } + + // native method for setting default TexCoordGeneration + void resetTexCoordGeneration(Context ctx) { + } + + // native method for setting default TextureAttributes + void resetTextureAttributes(Context ctx) { + } + + // native method for setting default PolygonAttributes + void resetPolygonAttributes(Context ctx) { + } + + // native method for setting default LineAttributes + void resetLineAttributes(Context ctx) { + } + + // native method for setting default PointAttributes + void resetPointAttributes(Context ctx) { + } + + // native method for setting default TransparencyAttributes + void resetTransparency(Context ctx, int geometryType, + int polygonMode, boolean lineAA, + boolean pointAA) { + } + + // native method for setting default ColoringAttributes + void resetColoringAttributes(Context ctx, + float r, float g, + float b, float a, + boolean enableLight) { + } + + /** + * This native method makes sure that the rendering for this canvas + * gets done now. + */ + void syncRender(Context ctx, boolean wait) { + } + + // The native method that sets this ctx to be the current one + boolean useCtx(Context ctx, long display, Drawable drawable) { + return true; + } + + void clear(Context ctx, float r, float g, float b) { + + } + + void textureFillBackground(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY) { + + } + + void textureFillRaster(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha) { + + } + + void executeRasterDepth(Context ctx, float posX, float posY, float posZ, + int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight, + int depthWidth, int depthHeight, int depthType, Object depthData) { + + } + + // The native method for setting the ModelView matrix. + void setModelViewMatrix(Context ctx, double[] viewMatrix, double[] modelMatrix) { + } + + // The native method for setting the Projection matrix. + void setProjectionMatrix(Context ctx, double[] projMatrix) { + } + + // The native method for setting the Viewport. + void setViewport(Context ctx, int x, int y, int width, int height) { + } + + // used for display Lists + void newDisplayList(Context ctx, int displayListId) { + } + void endDisplayList(Context ctx) { + } + void callDisplayList(Context ctx, int id, boolean isNonUniformScale) { + } + + void freeDisplayList(Context ctx, int id) { + } + void freeTexture(Context ctx, int id) { + } + + void texturemapping(Context ctx, + int px, int py, + int xmin, int ymin, int xmax, int ymax, + int texWidth, int texHeight, + int rasWidth, + int format, int objectId, + byte[] image, + int winWidth, int winHeight) { + } + + boolean initTexturemapping(Context ctx, int texWidth, + int texHeight, int objectId) { + return true; + } + + + // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or + // FIELD_RIGHT. Note that it is up to the caller to ensure that + // stereo is available before setting the mode to FIELD_LEFT or + // FIELD_RIGHT. The boolean isTRUE for double buffered mode, FALSE + // foe single buffering. + void setRenderMode(Context ctx, int mode, boolean doubleBuffer) { + } + + // Set glDepthMask. + void setDepthBufferWriteEnable(Context ctx, boolean mode) { + } + + + // --------------------------------------------------------------------- + + // + // Canvas3D / GraphicsConfigTemplate3D methods - logic dealing with + // native graphics configuration or drawing surface + // + + // Return a graphics config based on the one passed in. Note that we can + // assert that the input config is non-null and was created from a + // GraphicsConfigTemplate3D. + // This method must return a valid GraphicsConfig, or else it must throw + // an exception if one cannot be returned. + GraphicsConfiguration getGraphicsConfig(GraphicsConfiguration gconfig) { + System.err.println("NoopPipeline.getGraphicsConfig()"); + return gconfig; + } + + // Get the native FBconfig pointer + long getFbConfig(GraphicsConfigInfo gcInfo) { + return 0L; + } + + + // Get best graphics config from pipeline + GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D gct, + GraphicsConfiguration[] gc) { + + GraphicsConfiguration gc1 = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(); + // We need to cache the GraphicsTemplate3D + synchronized (Canvas3D.graphicsConfigTable) { + if (Canvas3D.graphicsConfigTable.get(gc1) == null) { + GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(gct); +// gcInfo.setPrivateData(privateData); + Canvas3D.graphicsConfigTable.put(gc1, gcInfo); + } + } + return gc1; + } + + // Determine whether specified graphics config is supported by pipeline + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D gct, + GraphicsConfiguration gc) { + return true; + } + + // Methods to get actual capabilities from Canvas3D + boolean hasDoubleBuffer(Canvas3D cv) { + return true; + } + + boolean hasStereo(Canvas3D cv) { + return false; + } + + int getStencilSize(Canvas3D cv) { + return 0; + } + + boolean hasSceneAntialiasingMultisample(Canvas3D cv) { + return false; + } + + boolean hasSceneAntialiasingAccum(Canvas3D cv) { + return false; + } + + // Methods to get native WS display and screen + long getDisplay() { + return 0L; + } + + int getScreen(GraphicsDevice graphicsDevice) { + return 0; + } + + + // --------------------------------------------------------------------- + + // + // DrawingSurfaceObject methods + // + + // Method to construct a new DrawingSurfaceObject + DrawingSurfaceObject createDrawingSurfaceObject(Canvas3D cv) { + return new NoopDrawingSurfaceObject(cv); + } + + // Method to free the drawing surface object + void freeDrawingSurface(Canvas3D cv, DrawingSurfaceObject drawingSurfaceObject) { + // This method is a no-op + } + + // Method to free the native drawing surface object + void freeDrawingSurfaceNative(Object o) { + // This method is a no-op + } + + /** + * Dummy context for noop pipeline + */ + static class NoopContext implements Context { + } + +} diff --git a/src/classes/share/javax/media/j3d/NotificationThread.java b/src/classes/share/javax/media/j3d/NotificationThread.java index ac0598a..321213d 100644 --- a/src/classes/share/javax/media/j3d/NotificationThread.java +++ b/src/classes/share/javax/media/j3d/NotificationThread.java @@ -67,6 +67,9 @@ class NotificationThread extends Thread { case J3dNotification.SHADER_ERROR: n.universe.notifyShaderErrorListeners((ShaderError)n.args[0]); break; + case J3dNotification.RENDERING_ERROR: + VirtualUniverse.notifyRenderingErrorListeners((RenderingError)n.args[0]); + break; default: System.err.println("J3dNotification.processNotifications: unrecognized type = " + n.type); } diff --git a/src/classes/share/javax/media/j3d/OrderedGroupRetained.java b/src/classes/share/javax/media/j3d/OrderedGroupRetained.java index 5548178..f1bb2b9 100644 --- a/src/classes/share/javax/media/j3d/OrderedGroupRetained.java +++ b/src/classes/share/javax/media/j3d/OrderedGroupRetained.java @@ -74,7 +74,7 @@ class OrderedGroupRetained extends GroupRetained { System.arraycopy(cIOArr, 0, newArr, 0, newArr.length); J3dMessage m; - m = VirtualUniverse.mc.getMessage(); + m = new J3dMessage(); m.threads = J3dThread.UPDATE_RENDER; m.type = J3dMessage.ORDERED_GROUP_TABLE_CHANGED; m.universe = universe; diff --git a/src/classes/share/javax/media/j3d/OrientedShape3DRenderMethod.java b/src/classes/share/javax/media/j3d/OrientedShape3DRenderMethod.java index 945f974..8153e13 100644 --- a/src/classes/share/javax/media/j3d/OrientedShape3DRenderMethod.java +++ b/src/classes/share/javax/media/j3d/OrientedShape3DRenderMethod.java @@ -21,7 +21,7 @@ package javax.media.j3d; class OrientedShape3DRenderMethod implements RenderMethod { - public boolean render(RenderMolecule rm, Canvas3D cv, int pass, + public boolean render(RenderMolecule rm, Canvas3D cv, RenderAtomListInfo ra, int dirtyBits) { boolean useAlpha; boolean isNonUniformScale; @@ -35,7 +35,7 @@ class OrientedShape3DRenderMethod implements RenderMethod { rm.textureBin.attributeBin.ignoreVertexColors, cv.ctx); if (rm.doInfinite) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); while (ra != null) { trans = ra.infLocalToVworld; isNonUniformScale = !trans.isCongruent(); @@ -44,10 +44,8 @@ class OrientedShape3DRenderMethod implements RenderMethod { ra.geometry().execute(cv, ra.renderAtom, isNonUniformScale, (useAlpha && ra.geometry().noAlpha), rm.alpha, - rm.renderBin.multiScreen, cv.screen.screen, - rm.textureBin.attributeBin.ignoreVertexColors, - pass); + rm.textureBin.attributeBin.ignoreVertexColors); ra = ra.next; } return true; @@ -57,7 +55,7 @@ class OrientedShape3DRenderMethod implements RenderMethod { while (ra != null) { if (cv.ra == ra.renderAtom) { if (cv.raIsVisible) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); trans = ra.localToVworld; isNonUniformScale = !trans.isCongruent(); @@ -65,18 +63,16 @@ class OrientedShape3DRenderMethod implements RenderMethod { ra.geometry().execute(cv, ra.renderAtom, isNonUniformScale, (useAlpha && ra.geometry().noAlpha), rm.alpha, - rm.renderBin.multiScreen, cv.screen.screen, rm.textureBin.attributeBin. - ignoreVertexColors, - pass); + ignoreVertexColors); isVisible = true; } } else { if (!VirtualUniverse.mc.viewFrustumCulling || ra.renderAtom.localeVwcBounds.intersect(cv.viewFrustum)) { - cv.updateState(pass, dirtyBits); + cv.updateState(dirtyBits); cv.raIsVisible = true; trans = ra.localToVworld; isNonUniformScale = !trans.isCongruent(); @@ -85,11 +81,9 @@ class OrientedShape3DRenderMethod implements RenderMethod { ra.geometry().execute(cv, ra.renderAtom, isNonUniformScale, (useAlpha && ra.geometry().noAlpha), rm.alpha, - rm.renderBin.multiScreen, cv.screen.screen, rm.textureBin.attributeBin. - ignoreVertexColors, - pass); + ignoreVertexColors); isVisible = true; } else { diff --git a/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java b/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java index 7c007b9..044876f 100644 --- a/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java +++ b/src/classes/share/javax/media/j3d/OrientedShape3DRetained.java @@ -228,7 +228,7 @@ class OrientedShape3DRetained extends Shape3DRetained { } void sendChangedMessage(int component, Object attr) { - J3dMessage changeMessage = VirtualUniverse.mc.getMessage(); + J3dMessage changeMessage = new J3dMessage(); changeMessage.type = J3dMessage.ORIENTEDSHAPE3D_CHANGED; changeMessage.threads = targetThreads ; changeMessage.universe = universe; diff --git a/src/classes/share/javax/media/j3d/Pipeline.java b/src/classes/share/javax/media/j3d/Pipeline.java new file mode 100644 index 0000000..d06532a --- /dev/null +++ b/src/classes/share/javax/media/j3d/Pipeline.java @@ -0,0 +1,1403 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; + +/** + * Abstract pipeline class for rendering pipeline methods. All rendering + * pipeline methods are defined here. + */ +abstract class Pipeline { + // Singleton pipeline instance + private static Pipeline pipeline; + + // Supported rendering pipelines + enum Type { + // Native rendering pipelines using OGL or D3D library + NATIVE_OGL, + NATIVE_D3D, + + // Java rendering pipeline using Java Bindings for OpenGL + JOGL, + + // No-op rendering pipeline + NOOP, + } + + // Type of rendering pipeline (as defined above) + private Type pipelineType = null; + + protected Pipeline() { + } + + /** + * Initialize the Pipeline. Called exactly once by + * MasterControl.loadLibraries() to create the singleton + * Pipeline object. + */ + static void createPipeline(Type pipelineType) { + String className = null; + switch (pipelineType) { + case NATIVE_OGL: + case NATIVE_D3D: + className = "javax.media.j3d.NativePipeline"; + break; + case JOGL: + className = "javax.media.j3d.JoglPipeline"; + break; + case NOOP: + className = "javax.media.j3d.NoopPipeline"; + break; + default: + // Should not get here + throw new AssertionError("missing case statement"); + } + + final String pipelineClassName = className; + pipeline = (Pipeline) + java.security.AccessController.doPrivileged(new + java.security.PrivilegedAction() { + public Object run() { + try { + Class pipelineClass = Class.forName(pipelineClassName); + return pipelineClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + + pipeline.initialize(pipelineType); + } + + /** + * Returns the singleton Pipeline object. + */ + static Pipeline getPipeline() { + return pipeline; + } + + /** + * Initializes the pipeline object. Only called by initPipeline. + * Pipeline subclasses may override this, but must call + * super.initialize(pipelineType); + */ + void initialize(Type pipelineType) { + setPipelineType(pipelineType); + } + + /** + * Sets the pipeline type. Only called by initialize. + */ + private void setPipelineType(Type pipelineType) { + this.pipelineType = pipelineType; + } + + /** + * Returns the pipeline type + */ + Type getPipelineType() { + return pipelineType; + } + + /** + * Returns the pipeline name + */ + String getPipelineName() { + switch (pipelineType) { + case NATIVE_OGL: + return "NATIVE_OGL"; + case NATIVE_D3D: + return "NATIVE_D3D"; + case JOGL: + return "JOGL"; + case NOOP: + return "NOOP"; + default: + // Should not get here + throw new AssertionError("missing case statement"); + } + } + + /** + * Returns the renderer name + */ + String getRendererName() { + switch (pipelineType) { + case NATIVE_OGL: + case JOGL: + return "OpenGL"; + case NATIVE_D3D: + return "DirectX"; + case NOOP: + return "None"; + default: + // Should not get here + throw new AssertionError("missing case statement"); + } + } + + + // --------------------------------------------------------------------- + + // + // Methods to initialize and load required libraries (from MasterControl) + // + + /** + * Load all of the required libraries + */ + abstract void loadLibraries(int globalShadingLanguage); + + /** + * Returns true if the Cg library is loaded and available. Note that this + * does not necessarily mean that Cg is supported by the graphics card. + */ + abstract boolean isCgLibraryAvailable(); + + /** + * Returns true if the GLSL library is loaded and available. Note that this + * does not necessarily mean that GLSL is supported by the graphics card. + */ + abstract boolean isGLSLLibraryAvailable(); + + + // --------------------------------------------------------------------- + + // + // GeometryArrayRetained methods + // + + // Used by D3D to free vertex buffer + abstract void freeD3DArray(GeometryArrayRetained geo, boolean deleteVB); + + // used for GeometryArrays by Copy or interleaved + abstract void execute(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + int vertexAttrCount, int[] vertexAttrSizes, + float[] varray, float[] cdata, int cdirty); + + // used by GeometryArray by Reference with java arrays + abstract void executeVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty); + + // used by GeometryArray by Reference with NIO buffer + abstract void executeVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, + Object vcoords, + int colorIndex, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + int normalIndex, Object ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int[] texIndex, int texstride, Object[] texCoords, + int cdirty); + + // used by GeometryArray by Reference in interleaved format with NIO buffer + abstract void executeInterleavedBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int startVIndex, int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, int cdirty); + + abstract void setVertexFormat(Context ctx, GeometryArrayRetained geo, + int vformat, boolean useAlpha, boolean ignoreVertexColors); + + abstract void disableGlobalAlpha(Context ctx, GeometryArrayRetained geo, int vformat, + boolean useAlpha, boolean ignoreVertexColors); + + // used for GeometryArrays + abstract void buildGA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int startVIndex, + int vcount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, int[] texCoordSetMapOffset, + int vertexAttrCount, int[] vertexAttrSizes, + double[] xform, double[] nxform, + float[] varray); + + // used to Build Dlist GeometryArray by Reference with java arrays + abstract void buildGAForByRef(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, float[] vfcoords, double[] vdcoords, + int colorIndex, float[] cfdata, byte[] cbdata, + int normalIndex, float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + int[] vertexAttrIndex, float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int[] texIndex, int texstride, Object[] texCoords, + double[] xform, double[] nxform); + + // used to Build Dlist GeometryArray by Reference with NIO buffer + // NOTE: NIO buffers are no longer supported in display lists. We + // have no plans to add this support. + /* + abstract void buildGAForBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int vcount, + int vformat, + int vdefined, + int coordIndex, Object vcoords, + int colorIndex, Object cdata, + int normalIndex, Object ndata, + int texcoordmaplength, + int[] texcoordoffset, + int[] texIndex, int texstride, Object[] texCoords, + double[] xform, double[] nxform); + */ + + + // --------------------------------------------------------------------- + + // + // IndexedGeometryArrayRetained methods + // + + // by-copy or interleaved, by reference, Java arrays + abstract void executeIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + float[] varray, float[] cdata, + int cdirty, + int[] indexCoord); + + // interleaved, by reference, nio buffer + abstract void executeIndexedGeometryBuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean useAlpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int indexCount, + int vertexCount, int vformat, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetOffset, + int numActiveTexUnitState, + Object varray, float[] cdata, + int cdirty, + int[] indexCoord); + + // non interleaved, by reference, Java arrays + abstract void executeIndexedGeometryVA(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + float[] vfcoords, double[] vdcoords, + float[] cfdata, byte[] cbdata, + float[] ndata, + int vertexAttrCount, int[] vertexAttrSizes, + float[][] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord); + + // non interleaved, by reference, nio buffer + abstract void executeIndexedGeometryVABuffer(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vdefined, + Object vcoords, + Object cdataBuffer, + float[] cfdata, byte[] cbdata, + Object normal, + int vertexAttrCount, int[] vertexAttrSizes, + Object[] vertexAttrData, + int texcoordmaplength, + int[] texcoordoffset, + int numActiveTexUnitState, + int texstride, Object[] texCoords, + int cdirty, + int[] indexCoord); + + // by-copy geometry + abstract void buildIndexedGeometry(Context ctx, + GeometryArrayRetained geo, int geo_type, + boolean isNonUniformScale, boolean updateAlpha, + float alpha, + boolean ignoreVertexColors, + int initialIndexIndex, + int validIndexCount, + int vertexCount, + int vformat, + int vertexAttrCount, int[] vertexAttrSizes, + int texCoordSetCount, int[] texCoordSetMap, + int texCoordSetMapLen, + int[] texCoordSetMapOffset, + double[] xform, double[] nxform, + float[] varray, int[] indexCoord); + + + // --------------------------------------------------------------------- + + // + // GraphicsContext3D methods + // + + // Native method for readRaster + abstract void readRaster(Context ctx, + int type, int xSrcOffset, int ySrcOffset, + int width, int height, int hCanvas, + int imageDataType, + int imageFormat, + Object imageBuffer, + int depthFormat, + Object depthBuffer); + + // --------------------------------------------------------------------- + + // + // CgShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + abstract ShaderError setCgUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value); + + abstract ShaderError setCgUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value); + + abstract ShaderError setCgUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setCgUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setCgUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setCgUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setCgUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setCgUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setCgUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setCgUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + // ShaderAttributeArray methods + + abstract ShaderError setCgUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setCgUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setCgUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setCgUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setCgUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setCgUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setCgUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setCgUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setCgUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setCgUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + // abstract interfaces for shader compilation, etc. + abstract ShaderError createCgShader(Context ctx, int shaderType, ShaderId[] shaderId); + abstract ShaderError destroyCgShader(Context ctx, ShaderId shaderId); + abstract ShaderError compileCgShader(Context ctx, ShaderId shaderId, String program); + + abstract ShaderError createCgShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId); + abstract ShaderError destroyCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId); + abstract ShaderError linkCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds); + abstract void lookupCgVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, boolean[] errArr); + abstract void lookupCgShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr); + + abstract ShaderError useCgShaderProgram(Context ctx, ShaderProgramId shaderProgramId); + + + // --------------------------------------------------------------------- + + // + // GLSLShaderProgramRetained methods + // + + // ShaderAttributeValue methods + + abstract ShaderError setGLSLUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int value); + + abstract ShaderError setGLSLUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float value); + + abstract ShaderError setGLSLUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setGLSLUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setGLSLUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setGLSLUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setGLSLUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int[] value); + + abstract ShaderError setGLSLUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setGLSLUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + abstract ShaderError setGLSLUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + float[] value); + + // ShaderAttributeArray methods + + abstract ShaderError setGLSLUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setGLSLUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setGLSLUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setGLSLUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setGLSLUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setGLSLUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setGLSLUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + int[] value); + + abstract ShaderError setGLSLUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setGLSLUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + abstract ShaderError setGLSLUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, + int numElements, + float[] value); + + // abstract interfaces for shader compilation, etc. + abstract ShaderError createGLSLShader(Context ctx, int shaderType, ShaderId[] shaderId); + abstract ShaderError destroyGLSLShader(Context ctx, ShaderId shaderId); + abstract ShaderError compileGLSLShader(Context ctx, ShaderId shaderId, String program); + + abstract ShaderError createGLSLShaderProgram(Context ctx, ShaderProgramId[] shaderProgramId); + abstract ShaderError destroyGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId); + abstract ShaderError linkGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId, + ShaderId[] shaderIds); + abstract ShaderError bindGLSLVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, + String attrName, int attrIndex); + abstract void lookupGLSLShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, + int numAttrNames, String[] attrNames, ShaderAttrLoc[] locArr, + int[] typeArr, int[] sizeArr, boolean[] isArrayArr); + + abstract ShaderError useGLSLShaderProgram(Context ctx, ShaderProgramId shaderProgramId); + + + // --------------------------------------------------------------------- + + // + // ImageComponent2DRetained methods + // + + // free d3d surface referred to by id + abstract void freeD3DSurface(ImageComponent2DRetained image, int hashId); + + + // --------------------------------------------------------------------- + + // + // J3DBuffer methods + // + + // Method to verify that we can access a direct NIO buffer + // from native code + boolean checkNativeBufferAccess(java.nio.Buffer buffer) { + // Return true by default. Pipeline can override and implement, if + // we decide that it is necessary. + return true; + } + + // --------------------------------------------------------------------- + + // + // Renderer methods + // + + abstract void cleanupRenderer(); + + + // --------------------------------------------------------------------- + + // + // ColoringAttributesRetained methods + // + + abstract void updateColoringAttributes(Context ctx, + float dRed, float dGreen, float dBlue, + float red, float green, float blue, + float alpha, + boolean lEnable, + int shadeModel); + + + // --------------------------------------------------------------------- + + // + // DirectionalLightRetained methods + // + + abstract void updateDirectionalLight(Context ctx, + int lightSlot, float red, float green, + float blue, float x, float y, float z); + + + // --------------------------------------------------------------------- + + // + // PointLightRetained methods + // + + abstract void updatePointLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz); + + + // --------------------------------------------------------------------- + + // + // SpotLightRetained methods + // + + abstract void updateSpotLight(Context ctx, + int lightSlot, float red, float green, + float blue, float ax, float ay, float az, + float px, float py, float pz, float spreadAngle, + float concentration, float dx, float dy, + float dz); + + + // --------------------------------------------------------------------- + + // + // ExponentialFogRetained methods + // + + abstract void updateExponentialFog(Context ctx, + float red, float green, float blue, + float density); + + + // --------------------------------------------------------------------- + + // + // LinearFogRetained methods + // + + abstract void updateLinearFog(Context ctx, + float red, float green, float blue, + double fdist, double bdist); + + + // --------------------------------------------------------------------- + + // + // LineAttributesRetained methods + // + + abstract void updateLineAttributes(Context ctx, + float lineWidth, int linePattern, + int linePatternMask, + int linePatternScaleFactor, + boolean lineAntialiasing); + + + // --------------------------------------------------------------------- + + // + // MaterialRetained methods + // + + abstract void updateMaterial(Context ctx, + float red, float green, float blue, float alpha, + float ared, float agreen, float ablue, + float ered, float egreen, float eblue, + float dred, float dgreen, float dblue, + float sred, float sgreen, float sblue, + float shininess, int colorTarget, boolean enable); + + + // --------------------------------------------------------------------- + + // + // ModelClipRetained methods + // + + abstract void updateModelClip(Context ctx, int planeNum, boolean enableFlag, + double A, double B, double C, double D); + + + // --------------------------------------------------------------------- + + // + // PointAttributesRetained methods + // + + abstract void updatePointAttributes(Context ctx, float pointSize, boolean pointAntialiasing); + + + // --------------------------------------------------------------------- + + // + // PolygonAttributesRetained methods + // + + abstract void updatePolygonAttributes(Context ctx, + int polygonMode, int cullFace, + boolean backFaceNormalFlip, + float polygonOffset, + float polygonOffsetFactor); + + + // --------------------------------------------------------------------- + + // + // RenderingAttributesRetained methods + // + + abstract void updateRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride, + boolean depthBufferEnable, + boolean depthBufferWriteEnable, + int depthTestFunction, + float alphaTestValue, int alphaTestFunction, + boolean ignoreVertexColors, + boolean rasterOpEnable, int rasterOp, + boolean userStencilAvailable, boolean stencilEnable, + int stencilFailOp, int stencilZFailOp, int stencilZPassOp, + int stencilFunction, int stencilReferenceValue, + int stencilCompareMask, int stencilWriteMask ); + + + // --------------------------------------------------------------------- + + // + // TexCoordGenerationRetained methods + // + + /** + * This method updates the native context: + * trans contains eyeTovworld transform in d3d + * trans contains vworldToEye transform in ogl + */ + abstract void updateTexCoordGeneration(Context ctx, + boolean enable, int genMode, int format, + float planeSx, float planeSy, float planeSz, float planeSw, + float planeTx, float planeTy, float planeTz, float planeTw, + float planeRx, float planeRy, float planeRz, float planeRw, + float planeQx, float planeQy, float planeQz, float planeQw, + double[] trans); + + + // --------------------------------------------------------------------- + + // + // TransparencyAttributesRetained methods + // + + abstract void updateTransparencyAttributes(Context ctx, + float alpha, int geometryType, + int polygonMode, + boolean lineAA, boolean pointAA, + int transparencyMode, + int srcBlendFunction, + int dstBlendFunction); + + + // --------------------------------------------------------------------- + + // + // TextureAttributesRetained methods + // + + abstract void updateTextureAttributes(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat); + + abstract void updateRegisterCombiners(Context ctx, + double[] transform, boolean isIdentity, int textureMode, + int perspCorrectionMode, float red, + float green, float blue, float alpha, + int textureFormat, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale); + + abstract void updateTextureColorTable(Context ctx, int numComponents, + int colorTableSize, + int[] colorTable); + + abstract void updateCombiner(Context ctx, + int combineRgbMode, int combineAlphaMode, + int[] combineRgbSrc, int[] combineAlphaSrc, + int[] combineRgbFcn, int[] combineAlphaFcn, + int combineRgbScale, int combineAlphaScale); + + + // --------------------------------------------------------------------- + + // + // TextureUnitStateRetained methods + // + + abstract void updateTextureUnitState(Context ctx, int unitIndex, boolean enableFlag); + + + // --------------------------------------------------------------------- + + // + // TextureRetained methods + // Texture2DRetained methods + // + + abstract void bindTexture2D(Context ctx, int objectId, boolean enable); + + abstract void updateTexture2DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object data); + + abstract void updateTexture2DSubImage(Context ctx, + int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object data); + + abstract void updateTexture2DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + abstract void updateTexture2DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + abstract void updateTexture2DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha); + + abstract void updateTexture2DFilterModes(Context ctx, + int minFilter, int magFilter); + + abstract void updateTexture2DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + abstract void updateTexture2DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + abstract void updateTexture2DAnisotropicFilter(Context ctx, float degree); + + + // --------------------------------------------------------------------- + + // + // Texture3DRetained methods + // + + abstract void bindTexture3D(Context ctx, int objectId, boolean enable); + + abstract void updateTexture3DImage(Context ctx, + int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, int depth, + int boundaryWidth, + int imageDataType, Object imageData); + + abstract void updateTexture3DSubImage(Context ctx, + int level, + int xoffset, int yoffset, int zoffset, + int textureFormat, int imageFormat, + int imgXoffset, int imgYoffset, int imgZoffset, + int tilew, int tileh, + int width, int height, int depth, + int imageDataType, Object imageData); + + abstract void updateTexture3DLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + abstract void updateTexture3DLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + abstract void updateTexture3DBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + int boundaryModeR, float boundaryRed, + float boundaryGreen, float boundaryBlue, + float boundaryAlpha); + + abstract void updateTexture3DFilterModes(Context ctx, + int minFilter, int magFilter); + + abstract void updateTexture3DSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + abstract void updateTexture3DFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + abstract void updateTexture3DAnisotropicFilter(Context ctx, float degree); + + + // --------------------------------------------------------------------- + + // + // TextureCubeMapRetained methods + // + + abstract void bindTextureCubeMap(Context ctx, int objectId, boolean enable); + + abstract void updateTextureCubeMapImage(Context ctx, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object imageData); + + abstract void updateTextureCubeMapSubImage(Context ctx, + int face, int level, int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object imageData); + + abstract void updateTextureCubeMapLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod); + + abstract void updateTextureCubeMapLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ); + + abstract void updateTextureCubeMapBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha); + + abstract void updateTextureCubeMapFilterModes(Context ctx, + int minFilter, int magFilter); + + abstract void updateTextureCubeMapSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts); + + abstract void updateTextureCubeMapFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts); + + abstract void updateTextureCubeMapAnisotropicFilter(Context ctx, float degree); + + // --------------------------------------------------------------------- + + // + // MasterControl methods + // + + // Method to return the AWT object + abstract long getAWT(); + + // Method to initialize the native J3D library + abstract boolean initializeJ3D(boolean disableXinerama); + + // Maximum lights supported by the native API + abstract int getMaximumLights(); + + + // --------------------------------------------------------------------- + + // + // Canvas3D methods - native wrappers + // + + // This is the native method for creating the underlying graphics context. + abstract Context createNewContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, Context shareCtx, boolean isSharedCtx, + boolean offScreen, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable); + + abstract void createQueryContext(Canvas3D cv, long display, Drawable drawable, + long fbConfig, boolean offScreen, int width, int height, + boolean glslLibraryAvailable, + boolean cgLibraryAvailable); + + // This is the native for creating offscreen buffer + abstract Drawable createOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, int width, int height); + + abstract void destroyOffScreenBuffer(Canvas3D cv, Context ctx, long display, long fbConfig, Drawable drawable); + + // This is the native for reading the image from the offscreen buffer + abstract void readOffScreenBuffer(Canvas3D cv, Context ctx, int format, int type, Object data, int width, int height); + + // The native method for swapBuffers + abstract int swapBuffers(Canvas3D cv, Context ctx, long dpy, Drawable drawable); + + // notify D3D that Canvas is resize + abstract int resizeD3DCanvas(Canvas3D cv, Context ctx); + + // notify D3D to toggle between FullScreen and window mode + abstract int toggleFullScreenMode(Canvas3D cv, Context ctx); + + // native method for setting Material when no material is present + abstract void updateMaterialColor(Context ctx, float r, float g, float b, float a); + + abstract void destroyContext(long display, Drawable drawable, Context ctx); + + // This is the native method for doing accumulation. + abstract void accum(Context ctx, float value); + + // This is the native method for doing accumulation return. + abstract void accumReturn(Context ctx); + + // This is the native method for clearing the accumulation buffer. + abstract void clearAccum(Context ctx); + + // This is the native method for getting the number of lights the underlying + // native library can support. + abstract int getNumCtxLights(Context ctx); + + // Native method for decal 1st child setup + abstract boolean decal1stChildSetup(Context ctx); + + // Native method for decal nth child setup + abstract void decalNthChildSetup(Context ctx); + + // Native method for decal reset + abstract void decalReset(Context ctx, boolean depthBufferEnable); + + // Native method for decal reset + abstract void ctxUpdateEyeLightingEnable(Context ctx, boolean localEyeLightingEnable); + + // The following three methods are used in multi-pass case + + // native method for setting blend color + abstract void setBlendColor(Context ctx, float red, float green, + float blue, float alpha); + + // native method for setting blend func + abstract void setBlendFunc(Context ctx, int src, int dst); + + // native method for setting fog enable flag + abstract void setFogEnableFlag(Context ctx, boolean enableFlag); + + // Setup the full scene antialising in D3D and ogl when GL_ARB_multisamle supported + abstract void setFullSceneAntialiasing(Context ctx, boolean enable); + + abstract void setGlobalAlpha(Context ctx, float alpha); + + // Native method to update separate specular color control + abstract void updateSeparateSpecularColorEnable(Context ctx, boolean control); + + // Initialization for D3D when scene begin + abstract void beginScene(Context ctx); + abstract void endScene(Context ctx); + + // True under Solaris, + // False under windows when display mode <= 8 bit + abstract boolean validGraphicsMode(); + + // native method for setting light enables + abstract void setLightEnables(Context ctx, long enableMask, int maxLights); + + // native method for setting scene ambient + abstract void setSceneAmbient(Context ctx, float red, float green, float blue); + + // native method for disabling fog + abstract void disableFog(Context ctx); + + // native method for disabling modelClip + abstract void disableModelClip(Context ctx); + + // native method for setting default RenderingAttributes + abstract void resetRenderingAttributes(Context ctx, + boolean depthBufferWriteEnableOverride, + boolean depthBufferEnableOverride); + + // native method for setting default texture + abstract void resetTextureNative(Context ctx, int texUnitIndex); + + // native method for activating a particular texture unit + abstract void activeTextureUnit(Context ctx, int texUnitIndex); + + // native method for setting default TexCoordGeneration + abstract void resetTexCoordGeneration(Context ctx); + + // native method for setting default TextureAttributes + abstract void resetTextureAttributes(Context ctx); + + // native method for setting default PolygonAttributes + abstract void resetPolygonAttributes(Context ctx); + + // native method for setting default LineAttributes + abstract void resetLineAttributes(Context ctx); + + // native method for setting default PointAttributes + abstract void resetPointAttributes(Context ctx); + + // native method for setting default TransparencyAttributes + abstract void resetTransparency(Context ctx, int geometryType, + int polygonMode, boolean lineAA, + boolean pointAA); + + // native method for setting default ColoringAttributes + abstract void resetColoringAttributes(Context ctx, + float r, float g, + float b, float a, + boolean enableLight); + + /** + * This native method makes sure that the rendering for this canvas + * gets done now. + */ + abstract void syncRender(Context ctx, boolean wait); + + // The native method that sets this ctx to be the current one + abstract boolean useCtx(Context ctx, long display, Drawable drawable); + + // Optionally release the context. A pipeline may override this and + // returns true if the context was released. + boolean releaseCtx(Context ctx, long dpy) { + return false; + } + + abstract void clear(Context ctx, float r, float g, float b); + + abstract void textureFillBackground(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY); + + abstract void textureFillRaster(Context ctx, float texMinU, float texMaxU, float texMinV, float texMaxV, + float mapMinX, float mapMaxX, float mapMinY, float mapMaxY, float mapZ, float alpha); + + abstract void executeRasterDepth(Context ctx, float posX, float posY, float posZ, + int srcOffsetX, int srcOffsetY, int rasterWidth, int rasterHeight, int depthWidth, int depthHeight, + int depthType, Object depthData); + + // The native method for setting the ModelView matrix. + abstract void setModelViewMatrix(Context ctx, double[] viewMatrix, double[] modelMatrix); + + // The native method for setting the Projection matrix. + abstract void setProjectionMatrix(Context ctx, double[] projMatrix); + + // The native method for setting the Viewport. + abstract void setViewport(Context ctx, int x, int y, int width, int height); + + // used for display Lists + abstract void newDisplayList(Context ctx, int displayListId); + abstract void endDisplayList(Context ctx); + abstract void callDisplayList(Context ctx, int id, boolean isNonUniformScale); + + abstract void freeDisplayList(Context ctx, int id); + abstract void freeTexture(Context ctx, int id); + + abstract void texturemapping(Context ctx, + int px, int py, + int xmin, int ymin, int xmax, int ymax, + int texWidth, int texHeight, + int rasWidth, + int format, int objectId, + byte[] image, + int winWidth, int winHeight); + + abstract boolean initTexturemapping(Context ctx, int texWidth, + int texHeight, int objectId); + + + // Set internal render mode to one of FIELD_ALL, FIELD_LEFT or + // FIELD_RIGHT. Note that it is up to the caller to ensure that + // stereo is available before setting the mode to FIELD_LEFT or + // FIELD_RIGHT. The boolean isTRUE for double buffered mode, FALSE + // foe single buffering. + abstract void setRenderMode(Context ctx, int mode, boolean doubleBuffer); + + // Set glDepthMask. + abstract void setDepthBufferWriteEnable(Context ctx, boolean mode); + + + // --------------------------------------------------------------------- + + // + // Canvas3D / GraphicsConfigTemplate3D methods - logic dealing with + // native graphics configuration or drawing surface + // + + // Return a graphics config based on the one passed in. Note that we can + // assert that the input config is non-null and was created from a + // GraphicsConfigTemplate3D. + // This method must return a valid GraphicsConfig, or else it must throw + // an exception if one cannot be returned. + abstract GraphicsConfiguration getGraphicsConfig(GraphicsConfiguration gconfig); + + // Get the native FBconfig pointer + abstract long getFbConfig(GraphicsConfigInfo gcInfo); + + // Get best graphics config from pipeline + abstract GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D gct, + GraphicsConfiguration[] gc); + + // Determine whether specified graphics config is supported by pipeline + abstract boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D gct, + GraphicsConfiguration gc); + + // Methods to get actual capabilities from Canvas3D + abstract boolean hasDoubleBuffer(Canvas3D cv); + abstract boolean hasStereo(Canvas3D cv); + abstract int getStencilSize(Canvas3D cv); + abstract boolean hasSceneAntialiasingMultisample(Canvas3D cv); + abstract boolean hasSceneAntialiasingAccum(Canvas3D cv); + + // Methods to get native WS display and screen + abstract long getDisplay(); + abstract int getScreen(GraphicsDevice graphicsDevice); + + + // --------------------------------------------------------------------- + + // + // DrawingSurfaceObject methods + // + + // Method to construct a new DrawingSurfaceObject + abstract DrawingSurfaceObject createDrawingSurfaceObject(Canvas3D cv); + + // Method to free the drawing surface object + abstract void freeDrawingSurface(Canvas3D cv, DrawingSurfaceObject drawingSurfaceObject); + + // Method to free the native drawing surface object + abstract void freeDrawingSurfaceNative(Object o); + +} diff --git a/src/classes/share/javax/media/j3d/PointAttributesRetained.java b/src/classes/share/javax/media/j3d/PointAttributesRetained.java index b5d7536..207119b 100644 --- a/src/classes/share/javax/media/j3d/PointAttributesRetained.java +++ b/src/classes/share/javax/media/j3d/PointAttributesRetained.java @@ -112,13 +112,8 @@ class PointAttributesRetained extends NodeComponentRetained { /** * Update the native context */ - native void updateNative(long ctx, float pointSize, boolean pointAntialiasing); - - /** - * Update the native context - */ - void updateNative(long ctx) { - updateNative(ctx, pointSize, pointAntialiasing); + void updateNative(Context ctx) { + Pipeline.getPipeline().updatePointAttributes(ctx, pointSize, pointAntialiasing); } @@ -167,7 +162,7 @@ class PointAttributesRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.POINTATTRIBUTES_CHANGED; createMessage.universe = null; @@ -180,7 +175,7 @@ class PointAttributesRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; i tilew) { - tileX++; - xo -= tilew; - } - - while (yo > tileh) { - tileY++; - yo -= tileh; - } - int initTileY = image.minTileY+tileY; - int initTileX = image.minTileX+tileX; - int m,n; - int deltaw, deltah = 0; - curh = tileh - yo; - for (m = initTileY; m < image.minTileY+image.numYTiles; m++) { - curw = tilew - xo; - deltaw = 0; - w = width; - for (n = initTileX; n < image.minTileX+image.numXTiles; n++) { - java.awt.image.Raster ras; - ras = image.bImage[0].getTile(n,m); - byte[] tmpImage = ((DataBufferByte)ras.getDataBuffer()).getData(); - if (w 0) && (winCoord.y > 0)) { - objCoord.x = x; - objCoord.y = y; - objCoord.z = z; - return; // no need to clip - } - } else { - if ((winCoord.x > 0) && (winCoord.y > 0)) { - return; - } - } - - + private void clipImage(Canvas3D canvas, RenderAtom ra, Point2d winCoord, Point2i srcOffset) { + + if ((winCoord.x > 0) && (winCoord.y > 0)) { + return; + } + // Check if the Raster point will be culled // Note that w use 1 instead of 0, because when hardware // tranform the coordinate back to winCoord it may get @@ -595,37 +512,32 @@ class RasterRetained extends GeometryRetained { // (see bug 4732965) if(winCoord.x < 1) { // Negate the window position and use this as the offset - xOffset = (int)-winCoord.x+1; + srcOffset.x = (int)-winCoord.x+1; winCoord.x = 1; } if(winCoord.y < 1) { // Negate the window position and use this as the offset - yOffset = (int)-winCoord.y+1; + srcOffset.y = (int)-winCoord.y+1; winCoord.y = 1; } //check if user-specified subimage is smaller than the clipped image - if (xOffset < xSrcOffset) - xOffset = xSrcOffset; - if(yOffset < ySrcOffset) - yOffset = ySrcOffset; - // back transform to object coords - if(xDstOffset == 0 && yDstOffset == 0) - // Image plate to local Xform needs to be computed - computeObjCoord(canvas, winCoord, objCoord); - else { - // vwip should contain the Imageplate to Local transform - // (it was computed by computeObjCoord). - // We can simply use the previously computed value here - canvas.getPixelLocationInImagePlate(winCoord.x, winCoord.y, - objCoord.z, objCoord); - vwip.transform(objCoord); - } + if (srcOffset.x < xSrcOffset) + srcOffset.x = xSrcOffset; + if(srcOffset.y < ySrcOffset) + srcOffset.y = ySrcOffset; + + } + + private boolean isRasterClipPositionInside(Point3d clipCoord) { + return (clipCoord.x >= -1.0) && (clipCoord.x <= 1.0) && + (clipCoord.y >= -1.0) && (clipCoord.y <= 1.0); } - private void computeObjCoord(Canvas3D canvas, Point2d winCoord, Point3d objCoord) { + private void computeObjCoord(Canvas3D canvas, Point2d winCoord, Point3d objCoord, + Transform3D localToImagePlate) { // Back transform this pt. from window to object coordinates // Assumes this method is ALWAYS called after computeWinCoord has been // called. computeWinCoord calculates the Vworld to Image Plate Xform. @@ -635,29 +547,52 @@ class RasterRetained extends GeometryRetained { objCoord); // Get image plate to object coord transform // inv(P x M) - vwip.invert(); - vwip.transform(objCoord); + localToImagePlate.invert(); + localToImagePlate.transform(objCoord); } - private void computeWinCoord(Canvas3D canvas, RenderAtom ra, - Point2d winCoord, Point3d objCoord) { + private Point3d computeWinCoord(Canvas3D canvas, RenderAtom ra, + Point2d winCoord, Point3d objCoord, + Transform3D localToImagePlate) { // Get local to Vworld transform RenderMolecule rm = ra.renderMolecule; if (rm == null) { // removeRenderAtom() may set ra.renderMolecule to null // in RenderBin before this renderer thread run. - validVwip = false; - return; - } - // MT safe issue: We can't reference ra.renderMolecule below since + return null; + } + + // MT safe issue: We can't reference ra.renderMolecule below since // RenderBin thread may set it to null anytime. Use rm instead. Transform3D lvw = rm.localToVworld[rm.localToVworldIndex[ NodeRetained.LAST_LOCAL_TO_VWORLD]]; - + + + Point3d clipCoord3 = new Point3d(); + clipCoord3.set(objCoord); + Point4d clipCoord4 = new Point4d(); + + // Transform point from local coord. to clipping coord. + lvw.transform(clipCoord3); + canvas.vworldToEc.transform(clipCoord3); + canvas.projTrans.transform(clipCoord3, clipCoord4); + + // clip check in Z + if((clipCoord4.w <= 0.0) || + (clipCoord4.z > clipCoord4.w) || (-clipCoord4.z > clipCoord4.w)) { + + return null; + } + double invW = 1.0 / clipCoord4.w; + + clipCoord3.x = clipCoord4.x * invW; + clipCoord3.y = clipCoord4.y * invW; + clipCoord3.z = clipCoord4.z * invW; + // Get Vworld to image plate Xform - canvas.getLastVworldToImagePlate(vwip); + canvas.getLastVworldToImagePlate(localToImagePlate); // v' = vwip x lvw x v // where v' = transformed vertex, @@ -666,13 +601,16 @@ class RasterRetained extends GeometryRetained { // v = vertex // Compute composite local to image plate Xform - vwip.mul(lvw); + localToImagePlate.mul(lvw); // Transform the Raster's position from object to world coordinates - vwip.transform(objCoord); + localToImagePlate.transform(objCoord); + // Get the window coordinates of this point canvas.getPixelLocationFromImagePlate(objCoord, winCoord); + + return clipCoord3; } int getClassType() { diff --git a/src/classes/share/javax/media/j3d/RenderBin.java b/src/classes/share/javax/media/j3d/RenderBin.java index a9cfe36..81cc46a 100644 --- a/src/classes/share/javax/media/j3d/RenderBin.java +++ b/src/classes/share/javax/media/j3d/RenderBin.java @@ -94,18 +94,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { */ ArrayList positionDirtyList = new ArrayList(5); - - /** - * A set of freelists for RenderBin type objects - */ - ArrayList lightBinFreelist = new ArrayList(5); - ArrayList envSetFreelist = new ArrayList(5); - ArrayList attrBinFreelist = new ArrayList(5); - ArrayList shaderBinFreelist = new ArrayList(5); - ArrayList textureBinFreelist = new ArrayList(5); - ArrayList renderMoleculeFreelist = new ArrayList(5); - ArrayList transparentInfoFreeList = new ArrayList(5); - /** * Used when ColoringAttributes is null */ @@ -176,9 +164,8 @@ class RenderBin extends J3dStructure implements ObjectUpdate { private Comparator transparencySortComparator = null; - ArrayList toBeAddedTextureResourceFreeList = new ArrayList(5); - ArrayList displayListResourceFreeList = new ArrayList(5); - boolean resourceToFree = false; + private ArrayList toBeAddedTextureResourceFreeList = new ArrayList(5); + private ArrayList displayListResourceFreeList = new ArrayList(5); // a list of top level OrderedGroups ArrayList orderedBins = new ArrayList(5); @@ -197,7 +184,8 @@ class RenderBin extends J3dStructure implements ObjectUpdate { int envDirty = 0; - boolean reEvaluateBg = true; + private boolean reEvaluateBg = true; + private boolean reloadBgTexture = true; boolean reEvaluateClip = true; @@ -305,13 +293,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { */ ArrayList dirtyReferenceGeomList = new ArrayList(5); - - /** - * used by geometry execute routines to determine if the - * alpha values can be zapped - */ - boolean multiScreen = false; - // list of all Oriented RenderAtoms ArrayList orientedRAs = new ArrayList(5); @@ -411,7 +392,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { TextureRetained tex; Integer texIdObj; int size; - DetailTextureImage dtex; // System.out.println("dirtyRenderMoleculeList.size = "+dirtyRenderMoleculeList.size()); // System.out.println("reEvaluateBg = "+reEvaluateBg); @@ -704,23 +684,31 @@ class RenderBin extends J3dStructure implements ObjectUpdate { //System.out.println("newNodeComponentlist.size= " + size); Canvas3D canvases[] = view.getCanvases(); for (i = 0; i < size; i++) { - // Evaluate the nodeComponentList for all the canvases - ImageComponentRetained nc = (ImageComponentRetained)newNodeComponentList.get(i); - // Only evalaute extension for by-ref Images - if (nc.isByReference()) { - nc.geomLock.getLock(); - for (j = 0; j 1); + + // Issue 113 - multiScreen no longer used +// multiScreen = ((view.getScreens()).length > 1); // renderBin is ready now, so send the offScreen message size = offScreenMessage.size(); @@ -1089,7 +1086,7 @@ class RenderBin extends J3dStructure implements ObjectUpdate { ra = arr[i]; GeometryArrayRetained geo = (GeometryArrayRetained) ra.geometry(); - if ((cv.ctx != 0) && + if ((cv.ctx != null) && ((geo.resourceCreationMask & cv.canvasBit) == 0) || (geo.getDlistTimeStamp(cv.canvasBit) != cv.ctxTimeStamp)) { @@ -1107,7 +1104,7 @@ class RenderBin extends J3dStructure implements ObjectUpdate { // add this geometry's dlist to be freed if (geo.isDlistUserSetEmpty(this)) { - if (cv.ctx != 0) { + if (cv.ctx != null) { canvases[j].displayListResourceFreeList.add(geo.dlistObj); } geo.resourceCreationMask &= ~canvases[j].canvasBit; @@ -1153,6 +1150,7 @@ class RenderBin extends J3dStructure implements ObjectUpdate { dirtyRenderMoleculeList.clear(); dirtyReferenceGeomList.clear(); reEvaluateBg = false; + reloadBgTexture = false; textureBinList.clear(); newNodeComponentList.clear(); removeNodeComponentList.clear(); @@ -1174,7 +1172,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { RenderMolecule rm; TextureRetained tex; Integer texIdObj; - DetailTextureImage dtex; if (rdr == null) return; @@ -1235,25 +1232,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { rdr.textureIdResourceFreeList.add(texIdObj); tex.resourceCreationMask &= ~rdr.rendererBit; } - if (tex instanceof Texture2DRetained) { - dtex = ((Texture2DRetained) tex).detailTexture; - if ((dtex != null) && - ((dtex.resourceCreationMask[tex.format] & rdr.rendererBit) != 0)) { - id = dtex.objectIds[tex.format]; - if ((id >= rdr.textureIDResourceTable.size()) || - (rdr.textureIDResourceTable.get(id) != dtex)) { - id = rdr.textureIDResourceTable.indexOf(dtex); - if (id <= 0) { - continue; - } - } - texIdObj = new Integer(id); - if (!rdr.textureIdResourceFreeList.contains(texIdObj)) { - rdr.textureIdResourceFreeList.add(texIdObj); - dtex.resourceCreationMask[tex.format] &= ~rdr.rendererBit; - } - } - } } } @@ -1282,7 +1260,6 @@ class RenderBin extends J3dStructure implements ObjectUpdate { RenderMolecule rm; TextureRetained tex; Integer texIdObj; - DetailTextureImage dtex; // update dirtyRenderMoleculeList for each canvas for (i = 0; i < canvases.length; i++) { @@ -1330,35 +1307,11 @@ class RenderBin extends J3dStructure implements ObjectUpdate { } } - if ((tex.resourceCreationMask & cv.canvasBit) != 0) { texIdObj = new Integer(id); cv.textureIdResourceFreeList.add(texIdObj); tex.resourceCreationMask &= ~cv.canvasBit; } - if (tex instanceof Texture2DRetained) { - dtex = ((Texture2DRetained) tex).detailTexture; - if ((dtex != null) && - ((dtex.resourceCreationMask[tex.format] & cv.canvasBit) != 0)) { - id = dtex.objectIds[tex.format]; - if ((id >= cv.textureIDResourceTable.size()) || - (cv.textureIDResourceTable.get(id) != dtex)) { - id = cv.textureIDResourceTable.indexOf(dtex); - if (id <= 0) { - continue; - } - } - texIdObj = new Integer(id); - // XXXX: The following code seems wrong -- why add it to - // the list if it is already there? Maybe one is for the - // texture and the other (idential value) is for the - // detail texture? - if (cv.textureIdResourceFreeList.contains(texIdObj)) { - cv.textureIdResourceFreeList.add(texIdObj); - dtex.resourceCreationMask[tex.format] &= ~cv.canvasBit; - } - } - } } // Take care of display list that should be freed size = displayListResourceFreeList.size(); @@ -1427,8 +1380,10 @@ class RenderBin extends J3dStructure implements ObjectUpdate { break; case J3dMessage.BACKGROUND_CHANGED: BackgroundRetained bg = (BackgroundRetained)m.args[0]; - if (universe.renderingEnvironmentStructure.isBgScopedToThisView(bg, view)) + if (universe.renderingEnvironmentStructure.isBgScopedToThisView(bg, view)) { reEvaluateBg = true; + reloadBgTexture = true; + } m.decRefcount(); break; case J3dMessage.CLIP_CHANGED: @@ -3167,19 +3122,26 @@ System.out.println("......tb.soleUser= " + addGeometryDlist(ra); // Raster send this message only for setImage() - if (g instanceof RasterRetained) { - Object[] objs = (Object[]) args[2]; - ImageComponentRetained oldImage = (ImageComponentRetained) objs[0]; - ImageComponentRetained newImage = (ImageComponentRetained) objs[1]; - - RasterRetained geo = (RasterRetained)ra.geometry(); - if (oldImage != null && oldImage.isByReference()) { - removeNodeComponent(oldImage); - } - if (newImage != null && newImage.isByReference()) { - addNodeComponent(newImage); - } - } + if (g instanceof RasterRetained) { + Object[] objs = (Object[]) args[2]; + Texture2DRetained oldTex = (Texture2DRetained) objs[0]; + Texture2DRetained newTex = (Texture2DRetained) objs[1]; + + RasterRetained geo = (RasterRetained)ra.geometry(); + if (oldTex != null) { + addTextureResourceFreeList(oldTex); + ImageComponentRetained oldImage = oldTex.images[0][0]; + if (oldImage != null) { + removeNodeComponent(oldImage); + } + } + if (newTex != null) { + ImageComponentRetained newImage = newTex.images[0][0]; + if (newImage != null) { + addNodeComponent(newImage); + } + } + } } @@ -3223,7 +3185,8 @@ System.out.println("......tb.soleUser= " + ArrayList rmList, ArrayList dlistPerRinfoList, ArrayList raList, boolean useSharedCtx ) { int size, i, bitMask; - long ctx, timeStamp; + Context ctx; + long timeStamp; if (useSharedCtx) { ctx = cv.screen.renderer.sharedCtx; @@ -3285,10 +3248,9 @@ System.out.println("......tb.soleUser= " + } void removeRenderMolecule(RenderMolecule rm) { - renderMoleculeFreelist.add(rm); - if ((rm.primaryMoleculeType &(RenderMolecule.DLIST_MOLECULE|RenderMolecule.SEPARATE_DLIST_PER_RINFO_MOLECULE)) != 0) - renderMoleculeList.remove(rm); + if ((rm.primaryMoleculeType &(RenderMolecule.DLIST_MOLECULE|RenderMolecule.SEPARATE_DLIST_PER_RINFO_MOLECULE)) != 0) + renderMoleculeList.remove(rm); } void updateAllRenderMolecule(Canvas3D cv) { @@ -3422,7 +3384,7 @@ System.out.println("......tb.soleUser= " + for(int k = 0; k < ra.rListInfo.length; k++) { if (ra.rListInfo[k].localToVworld == null) { - ra.rListInfo[k].localToVworld = VirtualUniverse.mc.getTransform3D(null); + ra.rListInfo[k].localToVworld = new Transform3D(); } } @@ -4474,7 +4436,7 @@ System.out.println("......tb.soleUser= " + ra.dirtyMask |= RenderAtom.IS_ORIENTED; for(int k = 0; k < ra.rListInfo.length; k++) { if (ra.rListInfo[k].localToVworld == null) { - ra.rListInfo[k].localToVworld = VirtualUniverse.mc.getTransform3D(null); + ra.rListInfo[k].localToVworld = new Transform3D(); } } } @@ -4702,18 +4664,12 @@ System.out.println("......tb.soleUser= " + * This gets a new EnviornmentSet. It creates one if there are none * on the freelist. */ - private EnvironmentSet getEnvironmentSet(RenderAtom ra, LightRetained[] lights, - FogRetained fog, ModelClipRetained modelClip) { - EnvironmentSet envSet; - - if (envSetFreelist.size() > 0) { - envSet = (EnvironmentSet)envSetFreelist.remove( - envSetFreelist.size()-1); - envSet.reset(ra, lights, fog, modelClip); - } else { - envSet = new EnvironmentSet(ra, lights, fog, modelClip, this); - } - return (envSet); + private EnvironmentSet getEnvironmentSet(RenderAtom ra, LightRetained[] lights, + FogRetained fog, ModelClipRetained modelClip) { + EnvironmentSet envSet; + + envSet = new EnvironmentSet(ra, lights, fog, modelClip, this); + return (envSet); } /** @@ -4925,14 +4881,7 @@ System.out.println("......tb.soleUser= " + * on the freelist. */ private ShaderBin getShaderBin(ShaderAppearanceRetained sApp) { - ShaderBin shaderBin; - if (shaderBinFreelist.size() > 0) { - shaderBin = (ShaderBin)shaderBinFreelist.remove(shaderBinFreelist.size()-1); - shaderBin.reset(sApp, this); - } else { - shaderBin = new ShaderBin( sApp, this); - } - return (shaderBin); + return new ShaderBin( sApp, this); } /** @@ -4940,17 +4889,7 @@ System.out.println("......tb.soleUser= " + * on the freelist. */ private AttributeBin getAttributeBin(AppearanceRetained app, RenderingAttributesRetained ra) { - AttributeBin attrBin; - if (attrBinFreelist.size() > 0) { - attrBin = (AttributeBin)attrBinFreelist.remove( - attrBinFreelist.size()-1); - attrBin.reset(app, ra, this); - } else { - - - attrBin = new AttributeBin(app, ra, this); - } - return (attrBin); + return new AttributeBin(app, ra, this); } /** @@ -4958,17 +4897,12 @@ System.out.println("......tb.soleUser= " + * on the freelist. */ private LightBin getLightBin(int maxLights, BackgroundRetained bg, boolean inOpaque) { - LightBin lightBin; - - if (lightBinFreelist.size() > 0) { - lightBin = (LightBin)lightBinFreelist.remove( - lightBinFreelist.size()-1); - lightBin.reset(inOpaque); - } else { - lightBin = new LightBin(maxLights, this, inOpaque); - } - lightBin.geometryBackground = bg; - return (lightBin); + LightBin lightBin; + + lightBin = new LightBin(maxLights, this, inOpaque); + + lightBin.geometryBackground = bg; + return (lightBin); } /** @@ -4976,49 +4910,30 @@ System.out.println("......tb.soleUser= " + * on the freelist. */ private TextureBin getTextureBin(TextureUnitStateRetained texUnitState[], - AppearanceRetained app) { - TextureBin textureBin; - - if (textureBinFreelist.size() > 0) { - textureBin = (TextureBin)textureBinFreelist.remove( - textureBinFreelist.size()-1); - textureBin.reset(texUnitState, app); - } else { - textureBin = new TextureBin(texUnitState, app, this); - } - - return (textureBin); + AppearanceRetained app) { + return new TextureBin(texUnitState, app, this); } /** * This gets a new RenderMolecule. It creates one if there are none * on the freelist. */ - private RenderMolecule getRenderMolecule(GeometryAtom ga, - PolygonAttributesRetained polya, - LineAttributesRetained linea, - PointAttributesRetained pointa, - MaterialRetained material, - ColoringAttributesRetained cola, - TransparencyAttributesRetained transa, - RenderingAttributesRetained ra, - TextureUnitStateRetained[] texUnits, - Transform3D[] transform, - int[] transformIndex) { - RenderMolecule renderMolecule; - - if (renderMoleculeFreelist.size() > 0) { - renderMolecule = (RenderMolecule)renderMoleculeFreelist.remove( - renderMoleculeFreelist.size()-1); - renderMolecule.reset(ga, polya, linea, pointa, material, - cola, transa, ra, texUnits, transform, transformIndex); - } else { - renderMolecule = new RenderMolecule(ga, polya, linea, pointa, - material, cola, transa, ra, - texUnits, - transform, transformIndex, this); - } - return (renderMolecule); + private RenderMolecule getRenderMolecule(GeometryAtom ga, + PolygonAttributesRetained polya, + LineAttributesRetained linea, + PointAttributesRetained pointa, + MaterialRetained material, + ColoringAttributesRetained cola, + TransparencyAttributesRetained transa, + RenderingAttributesRetained ra, + TextureUnitStateRetained[] texUnits, + Transform3D[] transform, + int[] transformIndex) { + + return new RenderMolecule(ga, polya, linea, pointa, + material, cola, transa, ra, + texUnits, + transform, transformIndex, this); } @@ -5197,7 +5112,6 @@ System.out.println("......tb.soleUser= " + // gotten from the freelist from one frame to another canvases[i].lightBin = null; } - lightBinFreelist.add(lbin); lbin.prev = null; lbin.next = null; } @@ -5358,41 +5272,50 @@ System.out.println("......tb.soleUser= " + * Sets the new background color. */ void setBackground(BackgroundRetained back) { - - boolean cvDirty = false; - BackgroundRetained oldGeomBack = geometryBackground; - geometryBackground = null; - - if (back != null) { - background.initColor(back.color); - background.initImageScaleMode(back.imageScaleMode); - background.geometryBranch = back.geometryBranch; + + boolean cvDirty = false; + BackgroundRetained oldGeomBack = geometryBackground; + geometryBackground = null; + + if (back != null) { + background.initColor(back.color); + background.initImageScaleMode(back.imageScaleMode); + background.geometryBranch = back.geometryBranch; if (background.geometryBranch != null) { geometryBackground = back; } - if (background.image != null) { - if (background.image.isByReference()) - removeNodeComponent(background.image); - } - if (back.image != null) { - // May need to optimize later - background.initImage((ImageComponent2D)back.image.source); - if (back.image.isByReference()) { - addNodeComponent(back.image); - } - } else { - background.initImage(null); - } - if (oldGeomBack == null) { - cvDirty = true; - } - } else { - background.initColor(black); - background.geometryBranch = null; - background.initImage(null); - if (oldGeomBack != null) { - cvDirty = true; - } + // Release resources associated with old BG and initialize new BG + // if the old and new BG images are different or if the + // reloadBgTexture flag is set. + if (background.image != back.image || reloadBgTexture) { + if (background.image != null) { + assert background.texture != null; + addTextureResourceFreeList(background.texture); + removeNodeComponent(background.image); + } + if (back.image != null) { + // May need to optimize later + background.initImage((ImageComponent2D)back.image.source); + addNodeComponent(back.image); + } else { + background.initImage(null); + } + } + if (oldGeomBack == null) { + cvDirty = true; + } + } else { + background.initColor(black); + background.geometryBranch = null; + if (background.image != null) { + assert background.texture != null; + addTextureResourceFreeList(background.texture); + removeNodeComponent(background.image); + } + background.initImage(null); + if (oldGeomBack != null) { + cvDirty = true; + } } // Need to reEvaluate View cache since doInfinite @@ -6005,12 +5928,6 @@ System.out.println("......tb.soleUser= " + nodeComponentList.clear(); orientedRAs.clear(); bhTreesArrList.clear(); - lightBinFreelist.clear(); - envSetFreelist.clear(); - attrBinFreelist.clear(); - shaderBinFreelist.clear(); - textureBinFreelist.clear(); - renderMoleculeFreelist.clear(); // clean up any messages that are queued up, since they are // irrelevant @@ -6142,7 +6059,6 @@ System.out.println("......tb.soleUser= " + } t.prev = null; t.next = null; - transparentInfoFreeList.add(t); tb.parentTInfo = null; } else { @@ -6168,7 +6084,6 @@ System.out.println("......tb.soleUser= " + } t.prev = null; t.next = null; - transparentInfoFreeList.add(t); tb.parentTInfo = null; } @@ -6202,7 +6117,6 @@ System.out.println("......tb.soleUser= " + } t.prev = null; t.next = null; - transparentInfoFreeList.add(t); nElements--; r.parentTInfo[i] = null; } @@ -6261,15 +6175,7 @@ System.out.println("......tb.soleUser= " + } TransparentRenderingInfo getTransparentInfo() { - TransparentRenderingInfo tinfo; - - if (transparentInfoFreeList.size() > 0) { - tinfo = (TransparentRenderingInfo)transparentInfoFreeList.remove(transparentInfoFreeList.size()-1); - } else { - tinfo = new TransparentRenderingInfo(); - } - return (tinfo); - + return new TransparentRenderingInfo(); } TransparentRenderingInfo computeDirtyAcrossTransparentBins(TextureBin tb, TransparentRenderingInfo startinfo) { @@ -6370,7 +6276,6 @@ System.out.println("......tb.soleUser= " + for (i = 0; i < size; i++) { TextureBin tb = (TextureBin)allTransparentObjects.get(i); - transparentInfoFreeList.add(tb.parentTInfo); tb.parentTInfo = null; RenderMolecule r = tb.transparentRMList; // For each renderMolecule @@ -6429,7 +6334,6 @@ System.out.println("......tb.soleUser= " + if (r.parentTInfo[j] == null) continue; - transparentInfoFreeList.add(r.parentTInfo[j]); r.parentTInfo[j] = null; } if (r.renderMolecule.textureBin.parentTInfo == null) { @@ -6919,6 +6823,15 @@ System.out.println("......tb.soleUser= " + renderAtoms.remove(renderAtoms.indexOf(ra)); removeARenderAtom(ra); } + + // This code segment is to handle the texture resource cleanup + // for Raster object. + GeometryAtom geomAtom = (GeometryAtom) nodes[n]; + GeometryRetained geomRetained = geomAtom.geometryArray[0]; + if ((geomRetained != null) && + (geomRetained instanceof RasterRetained )) { + addTextureResourceFreeList(((RasterRetained)geomRetained).texture); + } } else if (nodes[n] instanceof AlternateAppearanceRetained) { altAppearanceDirty = true; @@ -6978,7 +6891,9 @@ System.out.println("......tb.soleUser= " + } - void freeAllDisplayListResources(Canvas3D cv) { + void freeAllDisplayListResources(Canvas3D cv, Context ctx) { + + assert ctx != null; int i; int size = renderMoleculeList.size(); @@ -6989,7 +6904,7 @@ System.out.println("......tb.soleUser= " + renderMoleculeList.toArray(false); for (i = 0 ; i < size; i++) { - rmArr[i].releaseAllPrimaryDisplayListResources(cv); + rmArr[i].releaseAllPrimaryDisplayListResources(cv, ctx); } } @@ -7012,7 +6927,7 @@ System.out.println("......tb.soleUser= " + // Canvas in the renderer. However, since the // display lists will be recreated, it doesn't // really matter. - cv.freeDisplayList(cv.ctx, geo.dlistId); + cv.freeDisplayList(ctx, geo.dlistId); geo.resourceCreationMask &= ~mask; } } diff --git a/src/classes/share/javax/media/j3d/RenderMethod.java b/src/classes/share/javax/media/j3d/RenderMethod.java index 8641375..a714cfd 100644 --- a/src/classes/share/javax/media/j3d/RenderMethod.java +++ b/src/classes/share/javax/media/j3d/RenderMethod.java @@ -22,6 +22,6 @@ interface RenderMethod { /** * The actual rendering code for this RenderMethod */ - abstract boolean render(RenderMolecule rm, Canvas3D cv, int pass, + abstract boolean render(RenderMolecule rm, Canvas3D cv, RenderAtomListInfo ra, int dirtyBits); } diff --git a/src/classes/share/javax/media/j3d/RenderMolecule.java b/src/classes/share/javax/media/j3d/RenderMolecule.java index 2bc58a6..a0c24b9 100644 --- a/src/classes/share/javax/media/j3d/RenderMolecule.java +++ b/src/classes/share/javax/media/j3d/RenderMolecule.java @@ -390,14 +390,16 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen geo = ga.geometryArray[k]; k++; } - - if (ga.source.appearance != null) { - soleUser = ((ga.source.appearance.changedFrequent & RM_COMPONENTS) != 0); - } - else { - soleUser = false; + + // Issue 249 - check for sole user only if property is set + soleUser = false; + if (VirtualUniverse.mc.allowSoleUser) { + if (ga.source.appearance != null) { + soleUser = ((ga.source.appearance.changedFrequent & RM_COMPONENTS) != 0); + } } - // Set the appearance only for soleUser case + + // Set the appearance only for soleUser case if (soleUser) appHandle = ga.source.appearance; else @@ -674,8 +676,8 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen if (localeLocalToVworld == null) { localeLocalToVworld = new Transform3D[2]; } - localeLocalToVworld[0] = VirtualUniverse.mc.getTransform3D(null); - localeLocalToVworld[1] = VirtualUniverse.mc.getTransform3D(null); + localeLocalToVworld[0] = new Transform3D(); + localeLocalToVworld[1] = new Transform3D(); localeTranslation = new Vector3d(); ga.locale.hiRes.difference(renderBin.locale.hiRes, localeTranslation); translate(); @@ -1072,16 +1074,9 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen rinfo.next.prev = rinfo.prev; } } - // If this renderAtom has localTransform, - // return transform to freelist - if (primaryMoleculeType == RenderMolecule.TEXT3D_MOLECULE) { - if (!rinfo.renderAtom.inRenderBin()) { - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, rinfo.localToVworld); - - } - } + // If the molecule type is Raster, then add it to the lock list - else if (primaryMoleculeType == RASTER) { + if (primaryMoleculeType == RASTER) { RasterRetained geo = (RasterRetained)rinfo.geometry(); renderBin.removeGeometryFromLockList(geo); if (geo.image != null) @@ -1161,10 +1156,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen displayListId = 0; displayListIdObj = null; } - // If the locale is different, return xform to freelist if (locale != renderBin.locale) { - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - localeLocalToVworld[0]); localeLocalToVworld = null; } textureBin.removeRenderMolecule(this); @@ -1297,18 +1289,16 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen ((geo.vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0)) { renderBin.addGeometryToLockList(geo); // Add the geometry to the dirty list only if the geometry is by - // refernce and there is color and we need to use alpha and its - // not multiScreen + // refernce and there is color and we need to use alpha + // Issue 113 - ignore multiScreen if ((( geo.vertexFormat & GeometryArray.BY_REFERENCE)!=0) && (geo.c4fAllocated == 0) && ((geo.vertexFormat & GeometryArray.COLOR) != 0) && - useAlpha && - !renderBin.multiScreen) { + useAlpha) { renderBin.addDirtyReferenceGeometry(geo); } } } - } addRAs = addRAs.nextAdd; renderAtom.nextAdd = null; @@ -1749,13 +1739,12 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen ((geo.vertexFormat & GeometryArray.USE_COORD_INDEX_ONLY) != 0)) { renderBin.addGeometryToLockList(geo); // Add the geometry to the dirty list only if the geometry is by - // refernce and there is color and we need to use alpha and its - // not multiScreen + // reference and there is color and we need to use alpha + // Issue 113 - ignore multiScreen if ((( geo.vertexFormat & GeometryArray.BY_REFERENCE)!=0) && (geo.c4fAllocated == 0) && ((geo.vertexFormat & GeometryArray.COLOR) != 0) && - useAlpha && - !renderBin.multiScreen) { + useAlpha) { renderBin.addDirtyReferenceGeometry(geo); } } @@ -1791,6 +1780,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen * Renders this RenderMolecule */ boolean render(Canvas3D cv, int pass, int dirtyBits) { + assert pass < 0; boolean isVisible = isSwitchOn(); @@ -1847,24 +1837,16 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen modeSupportDL) { if (primaryMoleculeType != SEPARATE_DLIST_PER_RINFO_MOLECULE) { - - if ((primaryRenderMethod != VirtualUniverse.mc.getDisplayListRenderMethod()) && - (pass == TextureBin.USE_DISPLAYLIST)) { - pass = TextureBin.USE_VERTEXARRAY; - } - if (primaryRenderMethod.render(this, cv, pass, primaryRenderAtomList,dirtyBits)) + if (primaryRenderMethod.render(this, cv, primaryRenderAtomList,dirtyBits)) isVisible = true; } else { - if (renderBin.dlistRenderMethod.renderSeparateDlistPerRinfo(this, cv, pass,primaryRenderAtomList,dirtyBits)) + if (renderBin.dlistRenderMethod.renderSeparateDlistPerRinfo(this, cv, primaryRenderAtomList,dirtyBits)) isVisible = true; } } else { - if (pass == TextureBin.USE_DISPLAYLIST) { - pass = TextureBin.USE_VERTEXARRAY; - } - if(cachedVertexArrayRenderMethod.render(this, cv, pass, + if(cachedVertexArrayRenderMethod.render(this, cv, primaryRenderAtomList, dirtyBits)) { isVisible = true; @@ -1875,10 +1857,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen else { // TEXT3D or ORIENTEDSHAPE3D if (primaryRenderAtomList != null) { - if (pass == TextureBin.USE_DISPLAYLIST) { - pass = TextureBin.USE_VERTEXARRAY; - } - if(primaryRenderMethod.render(this, cv, pass, primaryRenderAtomList, + if(primaryRenderMethod.render(this, cv, primaryRenderAtomList, dirtyBits)) { isVisible = true; } @@ -1886,19 +1865,15 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen } if (separateDlistRenderAtomList != null) { - if (modeSupportDL) { - if(renderBin.dlistRenderMethod. - renderSeparateDlists(this, cv, pass, - separateDlistRenderAtomList, - dirtyBits)) { - isVisible = true; - } + if (modeSupportDL) { + if(renderBin.dlistRenderMethod.renderSeparateDlists(this, cv, + separateDlistRenderAtomList, + dirtyBits)) { + isVisible = true; + } } else { - if (pass == TextureBin.USE_DISPLAYLIST) { - pass = TextureBin.USE_VERTEXARRAY; - } - if(cachedVertexArrayRenderMethod.render(this, cv, pass, + if(cachedVertexArrayRenderMethod.render(this, cv, separateDlistRenderAtomList, dirtyBits)) { isVisible = true; @@ -1910,10 +1885,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen // XXXX: In the case of independent primitives such as quads, // it would still be better to call multi draw arrays if (vertexArrayRenderAtomList != null) { - if (pass == TextureBin.USE_DISPLAYLIST) { - pass = TextureBin.USE_VERTEXARRAY; - } - if(cachedVertexArrayRenderMethod.render(this, cv, pass, + if(cachedVertexArrayRenderMethod.render(this, cv, vertexArrayRenderAtomList, dirtyBits)) { isVisible = true; @@ -2121,6 +2093,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen } void transparentSortRender(Canvas3D cv, int pass, TransparentRenderingInfo tinfo) { + assert pass < 0; Transform3D modelMatrix = trans[localToVworldIndex[NodeRetained.LAST_LOCAL_TO_VWORLD]]; @@ -2169,12 +2142,12 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen // System.out.println("cachedVertexArrayRenderMethod = "+cachedVertexArrayRenderMethod); // System.out.println("tinfo.rInfo = "+tinfo.rInfo); if (modeSupportDL) { - renderBin.dlistRenderMethod.renderSeparateDlistPerRinfo(this, cv, pass, + renderBin.dlistRenderMethod.renderSeparateDlistPerRinfo(this, cv, tinfo.rInfo, ALL_DIRTY_BITS); } else { - cachedVertexArrayRenderMethod.render(this, cv, pass, tinfo.rInfo,ALL_DIRTY_BITS); + cachedVertexArrayRenderMethod.render(this, cv, tinfo.rInfo,ALL_DIRTY_BITS); } tinfo.rInfo.next = save; } @@ -2184,7 +2157,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen tinfo.rInfo.next = null; // System.out.println("cachedVertexArrayRenderMethod = "+cachedVertexArrayRenderMethod); // System.out.println("tinfo.rInfo = "+tinfo.rInfo); - cachedVertexArrayRenderMethod.render(this, cv, pass, tinfo.rInfo, + cachedVertexArrayRenderMethod.render(this, cv, tinfo.rInfo, ALL_DIRTY_BITS); tinfo.rInfo.next = save; } @@ -2194,19 +2167,19 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen RenderAtomListInfo save= tinfo.rInfo.next; tinfo.rInfo.next = null; if (modeSupportDL) { - renderBin.dlistRenderMethod.renderSeparateDlists(this, cv, pass, + renderBin.dlistRenderMethod.renderSeparateDlists(this, cv, tinfo.rInfo, ALL_DIRTY_BITS); } else { - cachedVertexArrayRenderMethod.render(this, cv, pass, tinfo.rInfo, + cachedVertexArrayRenderMethod.render(this, cv, tinfo.rInfo, ALL_DIRTY_BITS); } tinfo.rInfo.next = save; } else { RenderAtomListInfo save= tinfo.rInfo.next; - primaryRenderMethod.render(this, cv, pass, primaryRenderAtomList, + primaryRenderMethod.render(this, cv, primaryRenderAtomList, ALL_DIRTY_BITS); tinfo.rInfo.next = save; } @@ -2264,7 +2237,7 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen } - void releaseAllPrimaryDisplayListResources(Canvas3D cv) { + void releaseAllPrimaryDisplayListResources(Canvas3D cv, Context ctx) { if (primaryRenderAtomList != null) { if (primaryMoleculeType == SEPARATE_DLIST_PER_RINFO_MOLECULE) { RenderAtomListInfo ra = primaryRenderAtomList; @@ -2272,14 +2245,14 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen while (ra != null) { id = ra.renderAtom.dlistIds[ra.index]; if (id > 0) { - cv.freeDisplayList(cv.ctx, id); + cv.freeDisplayList(ctx, id); } ra = ra.next; } } else if (primaryMoleculeType == DLIST_MOLECULE) { if (displayListId > 0) { - cv.freeDisplayList(cv.ctx, displayListId); + cv.freeDisplayList(ctx, displayListId); } } } @@ -2985,13 +2958,6 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen void handleLocaleChange() { if (locale == renderBin.locale) { if (localToVworld != localeLocalToVworld) { - if (localeTranslation != null) { - // return to the freelist; - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - localeLocalToVworld[0]); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - localeLocalToVworld[1]); - } localeLocalToVworld = localToVworld; localeTranslation = null; } @@ -3000,11 +2966,6 @@ class RenderMolecule extends IndexedObject implements ObjectUpdate, NodeComponen // Using the localToVworl then, go back to making a new copy if (localeTranslation == null) { localeLocalToVworld = new Transform3D[2]; - /* - localeLocalToVworld[0] = VirtualUniverse.mc.getTransform3D(null); - localeLocalToVworld[1] = VirtualUniverse.mc.getTransform3D(null); - */ - localeLocalToVworld[0] = new Transform3D(); localeLocalToVworld[1] = new Transform3D(); diff --git a/src/classes/share/javax/media/j3d/Renderer.java b/src/classes/share/javax/media/j3d/Renderer.java index db0d8b3..3c73a7e 100644 --- a/src/classes/share/javax/media/j3d/Renderer.java +++ b/src/classes/share/javax/media/j3d/Renderer.java @@ -25,7 +25,7 @@ import java.util.*; class Renderer extends J3dThread { - int objectId = -1; + // This action causes this thread to wait static final int WAIT = 0; @@ -78,26 +78,26 @@ class Renderer extends J3dThread { boolean sharedStereoZBuffer; // This is the id for the underlying sharable graphics context - long sharedCtx = 0; + Context sharedCtx = null; // since the sharedCtx id can be the same as the previous one, // we need to keep a time stamp to differentiate the contexts with the // same id long sharedCtxTimeStamp = 0; - // display id - to free shared context - long display; - int window; + // display and drawable, used to free shared context + private long sharedCtxDisplay = 0; + private Drawable sharedCtxDrawable = null; /** * This is the id of the current rendering context */ - long currentCtx = -1; + Context currentCtx = null; /** - * This is the id of the current rendering window + * This is the id of the current rendering drawable */ - long currentWindow = 0; + Drawable currentDrawable = null; // an unique bit to identify this renderer int rendererBit = 0; @@ -132,22 +132,21 @@ class Renderer extends J3dThread { Screen3D onScreen; Screen3D offScreen; - // full screen anti-aliasing projection matrices - double accumLeftProjMat[] = new double[16]; - double accumRightProjMat[] = new double[16]; - double accumInfLeftProjMat[] = new double[16]; - double accumInfRightProjMat[] = new double[16]; + // full screen anti-aliasing projection matrices + Transform3D accumLeftProj = new Transform3D(); + Transform3D accumRightProj = new Transform3D(); + Transform3D accumInfLeftProj = new Transform3D(); + Transform3D accumInfRightProj = new Transform3D(); // rendering messages J3dMessage m[]; int nmesg = 0; // List of contexts created - ArrayList listOfCtxs = new ArrayList(); + ArrayList listOfCtxs = new ArrayList(); // Parallel list of canvases - ArrayList listOfCanvases = new ArrayList(); - + ArrayList listOfCanvases = new ArrayList(); boolean needToRebuildDisplayList = false; boolean needToResendTextureDown = false; @@ -161,8 +160,6 @@ class Renderer extends J3dThread { // It is used when sharedCtx = true; ArrayList textureIDResourceTable = new ArrayList(5); - native void D3DCleanUp(); - private synchronized int newInstanceNum() { return (++numInstances); } @@ -215,112 +212,133 @@ class Renderer extends J3dThread { opArg = ((Integer)args[0]).intValue(); try { - if (opArg == SWAP) { - - Object [] swapArray = (Object[])args[2]; - - view = (View)args[3]; - - for (i=0; i 0; c.userStencilAvailable = @@ -404,35 +426,53 @@ class Renderer extends J3dThread { c.systemStencilAvailable = (!userOwnsStencil && (c.actualStencilSize > 0)); - /* - System.out.println("Renderer :check for nct configuration"); - System.out.println("-- userStencilAvailable " + - c.userStencilAvailable); - System.out.println("-- systemStencilAvailable " + - c.systemStencilAvailable); - */ - c.sceneAntialiasingMultiSamplesAvailable = - nct.hasSceneAntialiasingMultisample(c); + c.hasSceneAntialiasingMultisample(); if (c.sceneAntialiasingMultiSamplesAvailable) { c.sceneAntialiasingAvailable = true; } else { c.sceneAntialiasingAvailable = - nct.hasSceneAntialiasingAccum(c); + c.hasSceneAntialiasingAccum(); } + } catch (RuntimeException ex) { + ex.printStackTrace(); + + // Issue 260 : indicate fatal error and notify error listeners + c.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.GRAPHICS_CONFIG_ERROR, + J3dI18N.getString("Renderer1")); + err.setCanvas3D(c); + err.setGraphicsDevice(c.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + } GraphicsConfigTemplate3D.runMonitor(J3dThread.NOTIFY); } else if (reqType == MasterControl.SET_QUERYPROPERTIES){ - c.createQueryContext(); + try { + c.createQueryContext(); + } catch (RuntimeException ex) { + ex.printStackTrace(); + + // Issue 260 : indicate fatal error and notify error listeners + c.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.CONTEXT_CREATION_ERROR, + J3dI18N.getString("Renderer2")); + err.setCanvas3D(c); + err.setGraphicsDevice(c.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + } // currentCtx change after we create a new context GraphicsConfigTemplate3D.runMonitor(J3dThread.NOTIFY); - currentCtx = -1; - currentWindow = 0; + currentCtx = null; + currentDrawable = null; } } else if (secondArg instanceof Integer) { - // message from TextureRetained finalize() method - // to free texture id - freeTextureID(((Integer) secondArg).intValue(), (String)m[nmesg].args[2]); + // Issue 121 - This was formerly used as a message from + // the now-nonexistant TextureRetained finalize() method + // to free the texture id + throw new AssertionError(); } else if (secondArg instanceof GeometryArrayRetained) { // message from GeometryArrayRetained // clearLive() to free D3D array @@ -441,20 +481,49 @@ class Renderer extends J3dThread { GraphicsConfigTemplate3D gct = (GraphicsConfigTemplate3D) secondArg; Integer reqType = (Integer) m[nmesg].args[2]; - if (reqType == MasterControl.GETBESTCONFIG) { - gct.testCfg = - gct.nativeTemplate.getBestConfiguration(gct, - (GraphicsConfiguration []) gct.testCfg); + if (reqType == MasterControl.GETBESTCONFIG) { + GraphicsConfiguration gcfg = null; + GraphicsConfiguration [] gcList = (GraphicsConfiguration []) gct.testCfg; + try { + gcfg = Pipeline.getPipeline().getBestConfiguration(gct, gcList); + } catch (NullPointerException npe) { + npe.printStackTrace(); + } catch (RuntimeException ex) { + ex.printStackTrace(); + + // Issue 260 : notify error listeners + RenderingError err = + new RenderingError(RenderingError.GRAPHICS_CONFIG_ERROR, + J3dI18N.getString("Renderer3")); + err.setGraphicsDevice(gcList[0].getDevice()); + notifyErrorListeners(err); + } + + gct.testCfg = gcfg; } else if (reqType == MasterControl.ISCONFIGSUPPORT) { - if (gct.nativeTemplate.isGraphicsConfigSupported(gct, - (GraphicsConfiguration) gct.testCfg)) { - gct.testCfg = Boolean.TRUE; - } else { - gct.testCfg = Boolean.FALSE; - } - } + boolean rval = false; + GraphicsConfiguration gc = (GraphicsConfiguration) gct.testCfg; + try { + if (Pipeline.getPipeline().isGraphicsConfigSupported(gct, gc)) { + rval = true; + } + } catch (NullPointerException npe) { + npe.printStackTrace(); + } catch (RuntimeException ex) { + ex.printStackTrace(); + + // Issue 260 : notify error listeners + RenderingError err = + new RenderingError(RenderingError.GRAPHICS_CONFIG_ERROR, + J3dI18N.getString("Renderer4")); + err.setGraphicsDevice(gc.getDevice()); + notifyErrorListeners(err); + } + + gct.testCfg = Boolean.valueOf(rval); + } gct.runMonitor(J3dThread.NOTIFY); - } + } m[nmesg++].decRefcount(); continue; @@ -467,28 +536,45 @@ class Renderer extends J3dThread { if (renderType == J3dMessage.CREATE_OFFSCREENBUFFER) { // Fix for issue 18. // Fix for issue 20. - canvas.window = - canvas.createOffScreenBuffer(canvas.ctx, - canvas.screen.display, - canvas.vid, - canvas.fbConfig, - canvas.offScreenCanvasSize.width, - canvas.offScreenCanvasSize.height); + + canvas.drawable = null; + try { + canvas.drawable = + canvas.createOffScreenBuffer(canvas.ctx, + canvas.screen.display, + canvas.fbConfig, + canvas.offScreenCanvasSize.width, + canvas.offScreenCanvasSize.height); + } catch (RuntimeException ex) { + ex.printStackTrace(); + } + + if (canvas.drawable == null) { + // Issue 260 : indicate fatal error and notify error listeners + canvas.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.OFF_SCREEN_BUFFER_ERROR, + J3dI18N.getString("Renderer5")); + err.setCanvas3D(canvas); + err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + } + canvas.offScreenBufferPending = false; m[nmesg++].decRefcount(); continue; } else if (renderType == J3dMessage.DESTROY_CTX_AND_OFFSCREENBUFFER) { - // Fix for issue 175. - // destroy ctx. - // Should be able to collaspe both call into one. Will do this in 1.5, - // it is a little risky for 1.4 beta3. - removeCtx(canvas, canvas.screen.display, canvas.window, canvas.ctx, - false, !canvas.offScreen, false); - // destroy offScreenBuffer. - removeCtx(canvas, canvas.screen.display, canvas.window, 0, - false, !canvas.offScreen, true); - + Object[] obj = m[nmesg].args; + + // Fix for issue 175: destroy ctx & off-screen buffer + // Fix for issue 340: get display, drawable & ctx from msg + removeCtx(canvas, + ((Long) obj[1]).longValue(), + (Drawable) obj[2], + (Context) obj[3], + false, !canvas.offScreen, true); + canvas.offScreenBufferPending = false; m[nmesg++].decRefcount(); continue; @@ -525,8 +611,13 @@ class Renderer extends J3dThread { VirtualUniverse.mc.resendTexTimestamp++; needToResendTextureDown = false; } - - if (canvas.ctx != 0) { + + if (canvas.isFatalError()) { + continue; + } + + try { + if (canvas.ctx != null) { // ctx may not construct until doClear(); canvas.beginScene(); } @@ -583,17 +674,11 @@ class Renderer extends J3dThread { case GraphicsContext3D.SET_MODEL_TRANSFORM: t3d = (Transform3D)m[nmesg].args[2]; canvas.graphicsContext3D.doSetModelTransform(t3d); - // return t3d to freelist. t3d was gotten from GraphicsContext3D - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - t3d); break; case GraphicsContext3D.MULTIPLY_MODEL_TRANSFORM: - t3d = (Transform3D)m[nmesg].args[2]; - canvas.graphicsContext3D.doMultiplyModelTransform(t3d); - // return t3d to freelist. t3d was gotten from GraphicsContext3D - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - t3d); - break; + t3d = (Transform3D)m[nmesg].args[2]; + canvas.graphicsContext3D.doMultiplyModelTransform(t3d); + break; case GraphicsContext3D.SET_SOUND: canvas.graphicsContext3D.doSetSound( (Sound)m[nmesg].args[2], @@ -643,6 +728,9 @@ class Renderer extends J3dThread { ((Point) ar[3]).y, (ImageObserver) ar[4]); break; + case GraphicsContext3D.DISPOSE2D: + canvas.graphics2D.doDispose(); + break; case GraphicsContext3D.SET_MODELCLIP: canvas.graphicsContext3D.doSetModelClip( (ModelClip)m[nmesg].args[2]); @@ -651,30 +739,53 @@ class Renderer extends J3dThread { break; } - if (canvas.ctx != 0) { + if (canvas.ctx != null) { canvas.endScene(); } + } catch (RuntimeException ex) { + ex.printStackTrace(); + + // Issue 260 : indicate fatal error and notify error listeners + canvas.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.CONTEXT_CREATION_ERROR, + J3dI18N.getString("Renderer6")); + err.setCanvas3D(canvas); + err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + } + m[nmesg++].decRefcount(); } else { // retained mode rendering m[nmesg++].decRefcount(); + + if (canvas.isFatalError()) { + continue; + } ImageComponent2DRetained offBufRetained = null; if (renderType == J3dMessage.RENDER_OFFSCREEN) { - if (canvas.window == 0 || !canvas.active) { + // Issue 131: set offScreenRendering flag here, since it + // otherwise won't be set for auto-off-screen rendering + // (which doesn't use renderOffScreenBuffer) + canvas.offScreenRendering = true; + if (canvas.drawable == null || !canvas.active) { canvas.offScreenRendering = false; continue; } else { offBufRetained = (ImageComponent2DRetained) canvas.offScreenBuffer.retained; - if (offBufRetained.isByReference()) { - offBufRetained.geomLock.getLock(); - offBufRetained.evaluateExtensions( - canvas.extensionsSupported); - } + if (offBufRetained.isByReference()) { + offBufRetained.geomLock.getLock(); + } + + offBufRetained.evaluateExtensions(canvas); + } + } else if (!canvas.active) { continue; } @@ -687,8 +798,6 @@ class Renderer extends J3dThread { canvas.drawingSurfaceObject.getDrawingSurfaceObjectInfo(); } - boolean background_image_update = false; - renderBin = canvas.view.renderBin; // setup rendering context @@ -698,8 +807,9 @@ class Renderer extends J3dThread { if (canvas.useSharedCtx) { - if (sharedCtx == 0) { - display = canvas.screen.display; + if (sharedCtx == null) { + sharedCtxDisplay = canvas.screen.display; + sharedCtxDrawable = canvas.drawable; // Always lock for context create if (!canvas.drawingSurfaceObject.renderLock()) { @@ -707,17 +817,35 @@ class Renderer extends J3dThread { offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } synchronized (VirtualUniverse.mc.contextCreationLock) { - sharedCtx = canvas.createNewContext(0, true); - if (sharedCtx == 0) { + sharedCtx = null; + try { + sharedCtx = canvas.createNewContext(null, true); + } catch (RuntimeException ex) { + ex.printStackTrace(); + } + + if (sharedCtx == null) { canvas.drawingSurfaceObject.unLock(); if ((offBufRetained != null) && offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; + + // Issue 260 : indicate fatal error and notify error listeners + canvas.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.CONTEXT_CREATION_ERROR, + J3dI18N.getString("Renderer7")); + err.setCanvas3D(canvas); + err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + break doneRender; } sharedCtxTimeStamp = @@ -730,9 +858,7 @@ class Renderer extends J3dThread { } } - if (canvas.ctx == 0) { - - display = canvas.screen.display; + if (canvas.ctx == null) { // Always lock for context create if (!canvas.drawingSurfaceObject.renderLock()) { @@ -740,19 +866,36 @@ class Renderer extends J3dThread { offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } synchronized (VirtualUniverse.mc.contextCreationLock) { - canvas.ctx = canvas.createNewContext(sharedCtx, false); + canvas.ctx = null; + try { + canvas.ctx = canvas.createNewContext(sharedCtx, false); + } catch (RuntimeException ex) { + ex.printStackTrace(); + } - if (canvas.ctx == 0) { + if (canvas.ctx == null) { canvas.drawingSurfaceObject.unLock(); if ((offBufRetained != null) && offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } - break doneRender; + canvas.offScreenRendering = false; + + // Issue 260 : indicate fatal error and notify error listeners + canvas.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.CONTEXT_CREATION_ERROR, + J3dI18N.getString("Renderer7")); + err.setCanvas3D(canvas); + err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); + notifyErrorListeners(err); + + break doneRender; } if (canvas.graphics2D != null) { @@ -761,13 +904,15 @@ class Renderer extends J3dThread { canvas.ctxTimeStamp = VirtualUniverse.mc.getContextTimeStamp(); - listOfCtxs.add(new Long(canvas.ctx)); + listOfCtxs.add(canvas.ctx); listOfCanvases.add(canvas); if (renderBin.nodeComponentList.size() > 0) { for (i = 0; i < renderBin.nodeComponentList.size(); i++) { NodeComponentRetained nc = (NodeComponentRetained)renderBin.nodeComponentList.get(i); - nc.evaluateExtensions(canvas.extensionsSupported); + if(nc instanceof ImageComponent2DRetained) { + ((ImageComponent2DRetained)nc).evaluateExtensions(canvas); + } } } @@ -781,11 +926,6 @@ class Renderer extends J3dThread { canvas.createTexUnitState(); } - // Create the texture unit state map - if (canvas.texUnitStateMap == null) { - canvas.createTexUnitStateMap(); - } - canvas.resetImmediateRendering(Canvas3D.NOCHANGE); canvas.drawingSurfaceObject.contextValidated(); @@ -808,6 +948,7 @@ class Renderer extends J3dThread { offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } @@ -822,13 +963,6 @@ class Renderer extends J3dThread { canvas.freeResourcesInFreeList(canvas.ctx); } - // save the BACKGROUND_IMAGE_DIRTY before canvas.updateViewCache - // clean it - synchronized (canvas.dirtyMaskLock) { - background_image_update = - ((canvas.cvDirtyMask[Canvas3D.RENDERER_DIRTY_IDX] & Canvas3D.BACKGROUND_IMAGE_DIRTY) != 0); - } - if (VirtualUniverse.mc.doDsiRenderLock) { canvas.drawingSurfaceObject.unLock(); } @@ -848,6 +982,7 @@ class Renderer extends J3dThread { offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } @@ -933,14 +1068,14 @@ class Renderer extends J3dThread { canvas.sceneAntialiasingAvailable) { if (!VirtualUniverse.mc.isD3D() && - ((canvas.extensionsSupported & Canvas3D.ARB_MULTISAMPLE) == 0) || + ((canvas.extensionsSupported & Canvas3D.MULTISAMPLE) == 0) || !canvas.sceneAntialiasingMultiSamplesAvailable) { doAccum = true; num_accum_passes = NUM_ACCUMULATION_SAMPLES; System.arraycopy( cvCache.getLeftProjection().mat, - 0, accumLeftProjMat, 0, 16); + 0, accumLeftProj.mat, 0, 16); accumDxFactor = ( @@ -952,29 +1087,29 @@ class Renderer extends J3dThread { canvas.canvasViewCache.getCanvasHeight())*canvas.view.fieldOfView; - accumLeftX = accumLeftProjMat[3]; - accumLeftY = accumLeftProjMat[7]; + accumLeftX = accumLeftProj.mat[3]; + accumLeftY = accumLeftProj.mat[7]; if (useStereo) { System.arraycopy( cvCache.getRightProjection().mat, - 0, accumRightProjMat, 0, 16); - accumRightX = accumRightProjMat[3]; - accumRightY = accumRightProjMat[7]; + 0, accumRightProj.mat, 0, 16); + accumRightX = accumRightProj.mat[3]; + accumRightY = accumRightProj.mat[7]; } if (renderBin.geometryBackground != null) { System.arraycopy( cvCache.getInfLeftProjection().mat, - 0, accumInfLeftProjMat, 0, 16); - accumInfLeftX = accumInfLeftProjMat[3]; - accumInfLeftY = accumInfLeftProjMat[7]; + 0, accumInfLeftProj.mat, 0, 16); + accumInfLeftX = accumInfLeftProj.mat[3]; + accumInfLeftY = accumInfLeftProj.mat[7]; if (useStereo) { System.arraycopy( cvCache.getInfRightProjection().mat, - 0, accumInfRightProjMat, 0, 16); - accumInfRightX = accumInfRightProjMat[3]; - accumInfRightY = accumInfRightProjMat[7]; + 0, accumInfRightProj.mat, 0, 16); + accumInfRightX = accumInfRightProj.mat[3]; + accumInfRightY = accumInfRightProj.mat[7]; } } } else { @@ -1005,39 +1140,6 @@ class Renderer extends J3dThread { Canvas3D.FIELD_ALL, canvas.useDoubleBuffer); - // Support DVR - /* - System.out.println("canvas.supportVideoResize() is " + - canvas.supportVideoResize()); - */ - if(canvas.supportVideoResize()) { - if(canvas.view.dvrResizeCompensation != - canvas.cachedDvrResizeCompensation) { - /* - System.out.println("Renderer : dvrResizeComp " + - canvas.view.dvrResizeCompensation); - */ - canvas.videoResizeCompensation(canvas.ctx, - canvas.view.dvrResizeCompensation); - canvas.cachedDvrResizeCompensation = - canvas.view.dvrResizeCompensation; - - } - if(canvas.view.dvrFactor != canvas.cachedDvrFactor) { - /* - System.out.println("Renderer : dvrFactor is " + - canvas.view.dvrFactor); - */ - canvas.videoResize(canvas.ctx, - canvas.screen.display, - canvas.window, - canvas.view.dvrFactor); - canvas.cachedDvrFactor = canvas.view.dvrFactor; - - } - - } - canvas.beginScene(); // this is if the background image resizes with the canvas @@ -1049,41 +1151,9 @@ class Renderer extends J3dThread { // and not in stereo mode if (!doAccum && !sharedStereoZBuffer) { BackgroundRetained bg = renderBin.background; - if (!VirtualUniverse.mc.isBackgroundTexture) { - canvas.clear(canvas.ctx, - bg.color.x, - bg.color.y, - bg.color.z, - winWidth, - winHeight, - bg.image, - bg.imageScaleMode, - (bg.image != null? - bg.image.imageYdown[0]:null)); - } else { - if ((bg.texImage != null) && - (objectId == -1)) { - objectId = VirtualUniverse.mc. - getTexture2DId(); - } - canvas.textureclear(canvas.ctx, - bg.xmax, - bg.ymax, - bg.color.x, - bg.color.y, - bg.color.z, - winWidth, - winHeight, - objectId, - bg.imageScaleMode, - bg.texImage, - background_image_update); - } -// canvas.clear(canvas.ctx, -// bg.color.x, -// bg.color.y, -// bg.color.z, -// bg.image); + + canvas.clear(bg, winWidth, winHeight); + } // handle preRender callback @@ -1095,18 +1165,22 @@ class Renderer extends J3dThread { try { canvas.preRender(); } catch (RuntimeException e) { - System.err.println("Exception occurred " + - "during Canvas3D callback:"); + System.err.println("Exception occurred during Canvas3D callback:"); e.printStackTrace(); + } catch (Error e) { + // Issue 264 - catch Error so Renderer doesn't die + System.err.println("Error occurred during Canvas3D callback:"); + e.printStackTrace(); } canvas.view.inCanvasCallback = false; - + if ((VirtualUniverse.mc.doDsiRenderLock) && (!canvas.drawingSurfaceObject.renderLock())) { if ((offBufRetained != null) && offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } @@ -1130,82 +1204,54 @@ class Renderer extends J3dThread { accumDy = ACCUM_SAMPLES_Y[apass] * accumDyFactor; - accumLeftProjMat[3] = accumLeftX + - accumLeftProjMat[0] * accumDx + - accumLeftProjMat[1] * accumDy; + accumLeftProj.mat[3] = accumLeftX + + accumLeftProj.mat[0] * accumDx + + accumLeftProj.mat[1] * accumDy; - accumLeftProjMat[7] = accumLeftY + - accumLeftProjMat[4] * accumDx + - accumLeftProjMat[5] * accumDy; + accumLeftProj.mat[7] = accumLeftY + + accumLeftProj.mat[4] * accumDx + + accumLeftProj.mat[5] * accumDy; if (useStereo) { - accumRightProjMat[3] = accumRightX + - accumRightProjMat[0] * accumDx + - accumRightProjMat[1] * accumDy; + accumRightProj.mat[3] = accumRightX + + accumRightProj.mat[0] * accumDx + + accumRightProj.mat[1] * accumDy; - accumRightProjMat[7] = accumRightY + - accumRightProjMat[4] * accumDx + - accumRightProjMat[5] * accumDy; + accumRightProj.mat[7] = accumRightY + + accumRightProj.mat[4] * accumDx + + accumRightProj.mat[5] * accumDy; } if (renderBin.geometryBackground != null) { - accumInfLeftProjMat[3] = accumInfLeftX + - accumInfLeftProjMat[0] * accumDx + - accumInfLeftProjMat[1] * accumDy; + accumInfLeftProj.mat[3] = accumInfLeftX + + accumInfLeftProj.mat[0] * accumDx + + accumInfLeftProj.mat[1] * accumDy; - accumInfLeftProjMat[7] = accumInfLeftY + - accumInfLeftProjMat[4] * accumDx + - accumInfLeftProjMat[5] * accumDy; + accumInfLeftProj.mat[7] = accumInfLeftY + + accumInfLeftProj.mat[4] * accumDx + + accumInfLeftProj.mat[5] * accumDy; if (useStereo) { - accumInfRightProjMat[3] = + accumInfRightProj.mat[3] = accumInfRightX + - accumInfRightProjMat[0] * accumDx + - accumInfRightProjMat[1] * accumDy; + accumInfRightProj.mat[0] * accumDx + + accumInfRightProj.mat[1] * accumDy; - accumInfRightProjMat[7] = + accumInfRightProj.mat[7] = accumInfRightY + - accumInfRightProjMat[4] * accumDx + - accumInfRightProjMat[5] * accumDy; + accumInfRightProj.mat[4] * accumDx + + accumInfRightProj.mat[5] * accumDy; } - } + } } // clear background for stereo and // accumulation buffer cases if (doAccum || sharedStereoZBuffer) { BackgroundRetained bg = renderBin.background; - if (!VirtualUniverse.mc.isBackgroundTexture) { - canvas.clear(canvas.ctx, - bg.color.x, - bg.color.y, - bg.color.z, - winWidth, - winHeight, - bg.image, - bg.imageScaleMode, - (bg.image != null?bg.image.imageYdown[0]:null)); - } - else { - if ((bg.texImage != null) && - (objectId == -1)) { - objectId = VirtualUniverse.mc. - getTexture2DId(); - } - - canvas.textureclear(canvas.ctx, - bg.xmax, - bg.ymax, - bg.color.x, - bg.color.y, - bg.color.z, - winWidth, - winHeight, - objectId, - bg.imageScaleMode, - bg.texImage, - background_image_update); - } + + canvas.clear(bg, winWidth, winHeight); + } // render background geometry @@ -1217,24 +1263,22 @@ class Renderer extends J3dThread { cvCache.getInfLeftVpcToEc(); if (doAccum) { canvas.setProjectionMatrix( - canvas.ctx, - accumInfLeftProjMat); + canvas.ctx, accumInfLeftProj); } else { canvas.setProjectionMatrix( canvas.ctx, - cvCache.getInfLeftProjection().mat); + cvCache.getInfLeftProjection()); } } else { canvas.vpcToEc = cvCache.getInfRightVpcToEc(); if (doAccum) { canvas.setProjectionMatrix( - canvas.ctx, - accumInfRightProjMat); + canvas.ctx, accumInfRightProj); } else { canvas.setProjectionMatrix( canvas.ctx, - cvCache.getInfRightProjection().mat); + cvCache.getInfRightProjection()); } } canvas.vworldToEc.mul(canvas.vpcToEc, @@ -1248,20 +1292,19 @@ class Renderer extends J3dThread { if (pass == 0) { canvas.vpcToEc = cvCache.getLeftVpcToEc(); if (doAccum) { - canvas.setProjectionMatrix( - canvas.ctx, accumLeftProjMat); + canvas.setProjectionMatrix(canvas.ctx, accumLeftProj); } else { canvas.setProjectionMatrix(canvas.ctx, - cvCache.getLeftProjection().mat); + cvCache.getLeftProjection()); } } else { canvas.vpcToEc = cvCache.getRightVpcToEc(); if (doAccum) { canvas.setProjectionMatrix( - canvas.ctx, accumRightProjMat); + canvas.ctx, accumRightProj); } else { canvas.setProjectionMatrix(canvas.ctx, - cvCache.getRightProjection().mat); + cvCache.getRightProjection()); } } canvas.vworldToEc.mul(canvas.vpcToEc, @@ -1295,9 +1338,12 @@ class Renderer extends J3dThread { try { canvas.renderField(stereo_mode); } catch (RuntimeException e) { - System.err.println("Exception occurred during " + - "Canvas3D callback:"); - e.printStackTrace(); + System.err.println("Exception occurred during Canvas3D callback:"); + e.printStackTrace(); + } catch (Error e) { + // Issue 264 - catch Error so Renderer doesn't die + System.err.println("Error occurred during Canvas3D callback:"); + e.printStackTrace(); } canvas.view.inCanvasCallback = false; if ((VirtualUniverse.mc.doDsiRenderLock) && @@ -1306,6 +1352,7 @@ class Renderer extends J3dThread { offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } + canvas.offScreenRendering = false; break doneRender; } @@ -1340,8 +1387,11 @@ class Renderer extends J3dThread { try { canvas.postRender(); } catch (RuntimeException e) { - System.err.println("Exception occurred during " + - "Canvas3D callback:"); + System.err.println("Exception occurred during Canvas3D callback:"); + e.printStackTrace(); + } catch (Error e) { + // Issue 264 - catch Error so Renderer doesn't die + System.err.println("Error occurred during Canvas3D callback:"); e.printStackTrace(); } canvas.view.inCanvasCallback = false; @@ -1351,6 +1401,7 @@ class Renderer extends J3dThread { canvas.syncRender(canvas.ctx, true); canvas.endOffScreenRendering(); + canvas.offScreenRendering = false; // do the postSwap for offscreen here canvas.view.inCanvasCallback = true; @@ -1359,16 +1410,20 @@ class Renderer extends J3dThread { } catch (RuntimeException e) { System.err.println("Exception occurred during Canvas 3D callback:"); e.printStackTrace(); + } catch (Error e) { + // Issue 264 - catch Error so Renderer doesn't die + System.err.println("Error occurred during Canvas3D callback:"); + e.printStackTrace(); } if (offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } - canvas.offScreenRendering = false; canvas.view.inCanvasCallback = false; - } + canvas.releaseCtx(); + } canvas.endScene(); @@ -1425,10 +1480,11 @@ class Renderer extends J3dThread { Arrays.fill(m, 0, totalMessages, null); } } - } catch (NullPointerException ne) { + } catch (NullPointerException ne) { + // Print NPE, but otherwise ignore it ne.printStackTrace(); if (canvas != null) { - if (canvas.ctx != 0) { + if (canvas.ctx != null) { canvas.endScene(); } // drawingSurfaceObject will safely ignore @@ -1436,16 +1492,35 @@ class Renderer extends J3dThread { canvas.drawingSurfaceObject.unLock(); } - } + } catch (RuntimeException ex) { + ex.printStackTrace(); + + if (canvas != null) { + if (canvas.ctx != null) { + canvas.endScene(); + } + // drawingSurfaceObject will safely ignore + // this request if this is not lock before + canvas.drawingSurfaceObject.unLock(); + } + + // Issue 260 : indicate fatal error and notify error listeners + canvas.setFatalError(); + RenderingError err = + new RenderingError(RenderingError.UNEXPECTED_RENDERING_ERROR, + J3dI18N.getString("Renderer8")); + err.setCanvas3D(canvas); + if (canvas != null) { + err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); + } + notifyErrorListeners(err); + } } // resource clean up void shutdown() { removeAllCtxs(); - - if (VirtualUniverse.mc.isD3D()) { - D3DCleanUp(); - } + Pipeline.getPipeline().cleanupRenderer(); } void cleanup() { @@ -1454,8 +1529,10 @@ class Renderer extends J3dThread { rendererStructure = new RendererStructure(); bgVworldToVpc = new Transform3D(); numframes = 0.0f; - sharedCtx = 0; + sharedCtx = null; sharedCtxTimeStamp = 0; + sharedCtxDisplay = 0; + sharedCtxDrawable = null; dirtyRenderMoleculeList.clear(); dirtyRenderAtomList.clear(); dirtyDlistPerRinfoList.clear(); @@ -1467,24 +1544,22 @@ class Renderer extends J3dThread { nmesg = 0; lasttime = 0; currtime = 0; - display = 0; } - // This is only invoked from removeCtx()/removeAllCtxs() // with drawingSurface already lock - final void makeCtxCurrent(long sharedCtx, long display, int window) { - if (sharedCtx != currentCtx || window != currentWindow) { - Canvas3D.useCtx(sharedCtx, display, window); + final void makeCtxCurrent(Context sharedCtx, long display, Drawable drawable) { + if (sharedCtx != currentCtx || drawable != currentDrawable) { + Canvas3D.useCtx(sharedCtx, display, drawable); /* - if(!Canvas3D.useCtx(sharedCtx, display, window)) { + if(!Canvas3D.useCtx(sharedCtx, display, drawable)) { Thread.dumpStack(); System.err.println("useCtx Fail"); } */ currentCtx = sharedCtx; - currentWindow = window; + currentDrawable = drawable; } } @@ -1492,67 +1567,65 @@ class Renderer extends J3dThread { // Canvas3D postRequest() offScreen rendering since the // user thread will not wait for it. Also we can just // reuse it as Canvas3D did not destroy. - private void removeCtx(Canvas3D cv, long display, int window, long ctx, + private void removeCtx(Canvas3D cv, long display, Drawable drawable, Context ctx, boolean resetCtx, boolean freeBackground, boolean destroyOffScreenBuffer) { - synchronized (VirtualUniverse.mc.contextCreationLock) { - // Fix for issue 18. - // Since we are now the renderer thread, - // we can safely execute destroyOffScreenBuffer. - if(destroyOffScreenBuffer) { - cv.destroyOffScreenBuffer(ctx, display, cv.fbConfig, window); - cv.offScreenBufferPending = false; - } - - if (ctx != 0) { - int idx = listOfCtxs.indexOf(new Long(ctx)); + if (ctx != null) { + int idx = listOfCtxs.indexOf(ctx); if (idx >= 0) { listOfCtxs.remove(idx); listOfCanvases.remove(idx); - // display is always 0 under windows - if ((MasterControl.isWin32 || (display != 0)) && - (window != 0) && cv.added) { + // Issue 326 : don't check display variable here + if ((drawable != null) && cv.added) { // cv.ctx may reset to -1 here so we // always use the ctx pass in. if (cv.drawingSurfaceObject.renderLock()) { // if it is the last one, free shared resources - if (sharedCtx != 0) { + if (sharedCtx != null) { if (listOfCtxs.isEmpty()) { - makeCtxCurrent(sharedCtx, display, window); + makeCtxCurrent(sharedCtx, sharedCtxDisplay, sharedCtxDrawable); freeResourcesInFreeList(null); freeContextResources(); - Canvas3D.destroyContext(display, window, sharedCtx); - currentCtx = -1; - currentWindow = 0; + Canvas3D.destroyContext(sharedCtxDisplay, sharedCtxDrawable, sharedCtx); + currentCtx = null; + currentDrawable = null; } else { freeResourcesInFreeList(cv); } - cv.makeCtxCurrent(ctx, display, window); + cv.makeCtxCurrent(ctx, display, drawable); } else { - cv.makeCtxCurrent(ctx, display, window); + cv.makeCtxCurrent(ctx, display, drawable); cv.freeResourcesInFreeList(ctx); } cv.freeContextResources(this, freeBackground, ctx); - Canvas3D.destroyContext(display, window, ctx); - currentCtx = -1; - currentWindow = 0; + Canvas3D.destroyContext(display, drawable, ctx); + currentCtx = null; + currentDrawable = null; cv.drawingSurfaceObject.unLock(); } } } if (resetCtx) { - cv.ctx = 0; + cv.ctx = null; } - if ((sharedCtx != 0) && listOfCtxs.isEmpty()) { - sharedCtx = 0; + if ((sharedCtx != null) && listOfCtxs.isEmpty()) { + sharedCtx = null; sharedCtxTimeStamp = 0; } cv.ctxTimeStamp = 0; } + + // Fix for issue 18. + // Since we are now the renderer thread, + // we can safely execute destroyOffScreenBuffer. + if(destroyOffScreenBuffer) { + cv.destroyOffScreenBuffer(ctx, display, cv.fbConfig, drawable); + cv.offScreenBufferPending = false; + } } } @@ -1564,41 +1637,41 @@ class Renderer extends J3dThread { for (int i=listOfCanvases.size()-1; i >=0; i--) { cv = (Canvas3D) listOfCanvases.get(i); - if ((cv.screen != null) && (cv.ctx != 0)) { - if ((MasterControl.isWin32 || (display != 0)) && - (cv.window != 0) && cv.added) { + if ((cv.screen != null) && (cv.ctx != null)) { + // Issue 326 : don't check display variable here + if ((cv.drawable != null) && cv.added) { if (cv.drawingSurfaceObject.renderLock()) { // We need to free sharedCtx resource // first before last non-sharedCtx to // workaround Nvidia driver bug under Linux // that crash on freeTexture ID:4685156 - if ((i == 0) && (sharedCtx != 0)) { - makeCtxCurrent(sharedCtx, display, window); + if ((i == 0) && (sharedCtx != null)) { + makeCtxCurrent(sharedCtx, sharedCtxDisplay, sharedCtxDrawable); freeResourcesInFreeList(null); freeContextResources(); - Canvas3D.destroyContext(display, window, sharedCtx); - currentCtx = -1; - currentWindow = 0; + Canvas3D.destroyContext(sharedCtxDisplay, sharedCtxDrawable, sharedCtx); + currentCtx = null; + currentDrawable = null; } cv.makeCtxCurrent(); cv.freeResourcesInFreeList(cv.ctx); cv.freeContextResources(this, true, cv.ctx); Canvas3D.destroyContext(cv.screen.display, - cv.window, + cv.drawable, cv.ctx); - currentCtx = -1; - currentWindow = 0; + currentCtx = null; + currentDrawable = null; cv.drawingSurfaceObject.unLock(); } } } - cv.ctx = 0; + cv.ctx = null; cv.ctxTimeStamp = 0; } - if (sharedCtx != 0) { - sharedCtx = 0; + if (sharedCtx != null) { + sharedCtx = null; sharedCtxTimeStamp = 0; } listOfCanvases.clear(); @@ -1606,49 +1679,6 @@ class Renderer extends J3dThread { } } - void freeTextureID(int texId, String texture) { - Canvas3D currentCanvas = null; - - // get the current canvas - for (int i=listOfCtxs.size()-1; i >= 0; i--) { - Canvas3D c = (Canvas3D) listOfCanvases.get(i); - if (c.ctx == currentCtx) { - currentCanvas = c; - break; - } - } - - if (currentCanvas == null) { - return; - } - - synchronized (VirtualUniverse.mc.contextCreationLock) { - if (sharedCtx != 0) { - currentCanvas.makeCtxCurrent(sharedCtx); - // OGL share context is used - Canvas3D.freeTexture(sharedCtx, texId); - } else { - for (int i=listOfCtxs.size()-1; i >= 0; i--) { - Canvas3D c = (Canvas3D) listOfCanvases.get(i); - c.makeCtxCurrent(); - Canvas3D.freeTexture(c.ctx, texId); - } - } - // restore current context - currentCanvas.makeCtxCurrent(); - } - // Issue 162: TEMPORARY FIX -- don't free the texture ID, since it will - // be freed once per canvas / screen and will subsequently cause the ID - // to be used for multiple textures. -// if (texture.equals("2D")){ -// VirtualUniverse.mc.freeTexture2DId(texId); -// } -// else if(texture.equals("3D")){ -// VirtualUniverse.mc.freeTexture3DId(texId); -// } - } - - // handle free resource in the FreeList void freeResourcesInFreeList(Canvas3D cv) { Iterator it; @@ -1684,7 +1714,18 @@ class Renderer extends J3dThread { textureIDResourceTable.size() + " val = " + val); } else { - textureIDResourceTable.set(val, null); + Object obj = textureIDResourceTable.get(val); + if (obj instanceof TextureRetained) { + TextureRetained tex = (TextureRetained) obj; + synchronized (tex.resourceLock) { + tex.resourceCreationMask &= ~rendererBit; + if (tex.resourceCreationMask == 0) { + tex.freeTextureId(val); + } + } + } + + textureIDResourceTable.set(val, null); } Canvas3D.freeTexture(sharedCtx, val); } @@ -1711,7 +1752,6 @@ class Renderer extends J3dThread { void freeContextResources() { Object obj; TextureRetained tex; - DetailTextureImage detailTex; for (int id = textureIDResourceTable.size()-1; id > 0; id--) { obj = textureIDResourceTable.get(id); @@ -1727,17 +1767,44 @@ class Renderer extends J3dThread { tex.freeTextureId(id); } } - } else if (obj instanceof DetailTextureImage) { - detailTex = (DetailTextureImage) obj; - detailTex.freeDetailTextureId(id, rendererBit); } - } textureIDResourceTable.clear(); // displayList is free in Canvas.freeContextResources() } + + /** + * Send a message to the notification thread, which will call the + * shader error listeners. + */ + static void notifyErrorListeners(RenderingError err) { + J3dNotification notification = new J3dNotification(); + notification.type = J3dNotification.RENDERING_ERROR; + notification.universe = null;//cv.view.universe; + notification.args[0] = err; + VirtualUniverse.mc.sendNotification(notification); + } -} + // Default rendering error listener class + private static RenderingErrorListener defaultErrorListener = null; + synchronized static RenderingErrorListener getDefaultErrorListener() { + if (defaultErrorListener == null) { + defaultErrorListener = new DefaultErrorListener(); + } + + return defaultErrorListener; + } + + static class DefaultErrorListener implements RenderingErrorListener { + public void errorOccurred(RenderingError error) { + System.err.println(); + System.err.println("DefaultRenderingErrorListener.errorOccurred:"); + error.printVerbose(); + System.exit(1); + } + } + +} diff --git a/src/classes/share/javax/media/j3d/RenderingAttributesRetained.java b/src/classes/share/javax/media/j3d/RenderingAttributesRetained.java index 0558b83..c7c80a0 100644 --- a/src/classes/share/javax/media/j3d/RenderingAttributesRetained.java +++ b/src/classes/share/javax/media/j3d/RenderingAttributesRetained.java @@ -491,28 +491,13 @@ class RenderingAttributesRetained extends NodeComponentRetained { * Updates the native context. */ - // TODO : Need to handle stencil operation on the native side -- Chien - native void updateNative(long ctx, - boolean depthBufferWriteEnableOverride, - boolean depthBufferEnableOverride, - boolean depthBufferEnable, - boolean depthBufferWriteEnable, - int depthTestFunction, - float alphaTestValue, int alphaTestFunction, - boolean ignoreVertexColors, - boolean rasterOpEnable, int rasterOp, - boolean userStencilAvailable, boolean stencilEnable, - int stencilFailOp, int stencilZFailOp, int stencilZPassOp, - int stencilFunction, int stencilReferenceValue, - int stencilCompareMask, int stencilWriteMask ); - /** * Updates the native context. */ void updateNative(Canvas3D c3d, boolean depthBufferWriteEnableOverride, boolean depthBufferEnableOverride) { - updateNative(c3d.ctx, + Pipeline.getPipeline().updateRenderingAttributes(c3d.ctx, depthBufferWriteEnableOverride, depthBufferEnableOverride, depthBufferEnable, depthBufferWriteEnable, depthTestFunction, alphaTestValue, alphaTestFunction, ignoreVertexColors, @@ -658,7 +643,7 @@ class RenderingAttributesRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.RENDERINGATTRIBUTES_CHANGED; createMessage.universe = null; @@ -671,7 +656,7 @@ class RenderingAttributesRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; iNO_ERROR. All other fields + * are initialized to null, including the error message. + */ + public RenderingError() { + } + + /** + * Constructs a new RenderingError object with the given error code + * and message. All other fields are initialized to null. + * + * @param errorCode the error code for this rendering error. + * @param errorMessage a short error message describing this + * rendering error. + */ + public RenderingError(int errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + /** + * Prints a verbose error report to System.err. This verbose + * output includes the error code, error message, detail message, + * and all relevant Java 3D objects. + */ + public void printVerbose() { + printVerbose(System.err); + } + + /** + * Prints a verbose error report to the specified PrintStream. + * This verbose output includes the error code, error message, + * detail message, and all relevant Java 3D objects. + * + * @param printStream the print stream on which to print the error + * report. + */ + public void printVerbose(PrintStream printStream) { + printStream.println(this); + if (graphicsDevice != null) { + printStream.println("graphicsDevice = " + graphicsDevice); + } + if (canvas != null) { + printStream.println("canvas = " + canvas); + } + + if (detailMessage != null) { + printStream.println(); + printStream.println("Detail Message"); + printStream.println("--------------"); + printStream.println(detailMessage); + } + } + + /** + * Sets the error code for this rendering error. This represents the + * type of error that occurred. + * + * @param errorCode the error code for this rendering error. + */ + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + /** + * Returns the error code for this rendering error. + * + * @return the error code. + */ + public int getErrorCode() { + return errorCode; + } + + /** + * Sets the error message for this rendering error. This is a short + * message describing the error, and is included as part of + * toString(). + * + * @param errorMessage a short error message describing this + * rendering error. + */ + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + /** + * Returns the error message for this rendering error. + * + * @return a short error message describing this rendering error. + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Sets the detail message for this rendering error. This is a more + * detailed error message that is not included as part of toString(). + * + * @param detailMessage a detailed message describing this + * error in more detail. + */ + public void setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + } + + /** + * Returns the detail message for this rendering error. + * + * @return the detail message for this rendering error. + */ + public String getDetailMessage() { + return detailMessage; + } + + /** + * Sets the graphics device associated with this rendering error. + * + * @param graphicsDevice the graphics device associated with this rendering error. + */ + public void setGraphicsDevice(GraphicsDevice graphicsDevice) { + this.graphicsDevice = graphicsDevice; + } + + /** + * Returns the graphics device associated with this rendering error. + * + * @return the graphics device associated with this rendering error. + */ + public GraphicsDevice getGraphicsDevice() { + return this.graphicsDevice; + } + + /** + * Sets the canvas associated with this rendering error. + * + * @param canvas the canvas associated with this rendering error. + */ + public void setCanvas3D(Canvas3D canvas) { + this.canvas = canvas; + } + + /** + * Returns the canvas associated with this rendering error. + * + * @return the canvas associated with this rendering error. + */ + public Canvas3D getCanvas3D() { + return this.canvas; + } + + + /** + * Returns a short string that describes this rendering error. The + * string is composed of the textual description of the errorCode, + * a ": ", and the errorMessage field. If the errorMessage is + * null then the ": " and the errorMessage are omitted. + * + * @return a string representation of this rendering error. + */ + public String toString() { + // Concatenate string representation of error code with error message + String errorCodeStr; + switch (errorCode) { + case NO_ERROR: + errorCodeStr = "NO_ERROR"; + break; + case UNEXPECTED_RENDERING_ERROR: + errorCodeStr = "UNEXPECTED_RENDERING_ERROR"; + break; + case GRAPHICS_CONFIG_ERROR: + errorCodeStr = "GRAPHICS_CONFIG_ERROR"; + break; + case CONTEXT_CREATION_ERROR: + errorCodeStr = "CONTEXT_CREATION_ERROR"; + break; + case OFF_SCREEN_BUFFER_ERROR: + errorCodeStr = "OFF_SCREEN_BUFFER_ERROR"; + break; + + default: + errorCodeStr = "UNKNOWN ERROR CODE (" + errorCode + ")"; + } + + if (errorMessage == null) { + return errorCodeStr; + } + + return errorCodeStr + ": " + errorMessage; + } +} diff --git a/src/classes/share/javax/media/j3d/RenderingErrorListener.java b/src/classes/share/javax/media/j3d/RenderingErrorListener.java new file mode 100644 index 0000000..b621775 --- /dev/null +++ b/src/classes/share/javax/media/j3d/RenderingErrorListener.java @@ -0,0 +1,29 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Listener interface for monitoring Java 3D rendering errors. + * + * @see VirtualUniverse#addRenderingErrorListener + * + * @since Java 3D 1.5 + */ +public interface RenderingErrorListener { + /** + * Invoked when an error occurs in the Java 3D rendering system. + * + * @param error object that contains the details of the error. + */ + public void errorOccurred(RenderingError error); +} diff --git a/src/classes/share/javax/media/j3d/Screen3D.java b/src/classes/share/javax/media/j3d/Screen3D.java index 6633b99..017947b 100644 --- a/src/classes/share/javax/media/j3d/Screen3D.java +++ b/src/classes/share/javax/media/j3d/Screen3D.java @@ -97,8 +97,10 @@ public class Screen3D extends Object { // an off-screen Canvas3D or with one or more on-screen Canvas3Ds boolean offScreen; - // The display connection (X11 only) and the screen ID + // The display connection (native OGL pipeline on X11 only) long display; + + // Screen number int screen; // The width and height of the screen in meters. @@ -353,18 +355,14 @@ public class Screen3D extends Object { * associated with an off-screen Canvas3D */ Screen3D(GraphicsConfiguration graphicsConfiguration, boolean offScreen) { - NativeScreenInfo nativeScreenInfo; - this.offScreen = offScreen; this.graphicsDevice = graphicsConfiguration.getDevice(); screenViewCache = new ScreenViewCache(this); - nativeScreenInfo = new NativeScreenInfo(graphicsDevice); - // Get the display from the native code (X11 only) and the - // screen ID - display = nativeScreenInfo.getDisplay(); - screen = nativeScreenInfo.getScreen(); + // Get the display handle and the screen number from the Pipeline + display = Pipeline.getPipeline().getDisplay(); + screen = Pipeline.getPipeline().getScreen(graphicsDevice); if (debug) System.out.println("Screen3D: display " + display + diff --git a/src/classes/share/javax/media/j3d/SetLiveState.java b/src/classes/share/javax/media/j3d/SetLiveState.java index bffd18f..d7b0000 100644 --- a/src/classes/share/javax/media/j3d/SetLiveState.java +++ b/src/classes/share/javax/media/j3d/SetLiveState.java @@ -248,5 +248,10 @@ class SetLiveState extends Object { //transformTargetThreads = 0; hashkeyIndex = null; + + // Fix for issue 75 + parentBranchGroupPaths = null; + branchGroupPaths = null; + orderedPaths = null; } } diff --git a/src/classes/share/javax/media/j3d/ShaderAppearanceRetained.java b/src/classes/share/javax/media/j3d/ShaderAppearanceRetained.java index 9815827..b5dc6f9 100644 --- a/src/classes/share/javax/media/j3d/ShaderAppearanceRetained.java +++ b/src/classes/share/javax/media/j3d/ShaderAppearanceRetained.java @@ -281,7 +281,7 @@ class ShaderAppearanceRetained extends AppearanceRetained { ArrayList gaList = Shape3DRetained.getGeomAtomsList(mirror.users, univList); // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.SHADER_APPEARANCE_CHANGED; createMessage.universe = null; @@ -294,7 +294,7 @@ class ShaderAppearanceRetained extends AppearanceRetained { //System.out.println("univList.size is " + univList.size()); for(int i=0; iinfreq change only for non-live node components + changedFrequent &= ~mask; + } + } + + void handleFrequencyChange(int bit) { + if (bit == ShaderAttributeObject.ALLOW_VALUE_WRITE) { + setFrequencyChangeMask(bit, 0x1); + } + } + } diff --git a/src/classes/share/javax/media/j3d/ShaderAttributeSetRetained.java b/src/classes/share/javax/media/j3d/ShaderAttributeSetRetained.java index 88952d9..ce03357 100644 --- a/src/classes/share/javax/media/j3d/ShaderAttributeSetRetained.java +++ b/src/classes/share/javax/media/j3d/ShaderAttributeSetRetained.java @@ -319,7 +319,7 @@ class ShaderAttributeSetRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.SHADER_ATTRIBUTE_SET_CHANGED; createMessage.universe = null; @@ -332,7 +332,7 @@ class ShaderAttributeSetRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; iinfreq change only for non-live node components + changedFrequent &= ~mask; + } + } + + void handleFrequencyChange(int bit) { + if (bit == ShaderAttributeSet.ALLOW_ATTRIBUTES_WRITE) { + setFrequencyChangeMask(bit, 0x1); + } + } + } diff --git a/src/classes/share/javax/media/j3d/ShaderBin.java b/src/classes/share/javax/media/j3d/ShaderBin.java index 83ca00f..056b9f4 100644 --- a/src/classes/share/javax/media/j3d/ShaderBin.java +++ b/src/classes/share/javax/media/j3d/ShaderBin.java @@ -270,8 +270,6 @@ class ShaderBin implements ObjectUpdate { t.clear(); - renderBin.textureBinFreelist.add(t); - if (textureBinList == null && addTextureBins.size() == 0 ) { // Note: Removal of this shaderBin as a user of the rendering // atttrs is done during removeRenderAtom() in RenderMolecule.java diff --git a/src/classes/share/javax/media/j3d/ShaderId.java b/src/classes/share/javax/media/j3d/ShaderId.java new file mode 100644 index 0000000..f5ca3c7 --- /dev/null +++ b/src/classes/share/javax/media/j3d/ShaderId.java @@ -0,0 +1,22 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Tagging interface for shader objects. The rendering pipelines + * will define concrete classes that implement this interface. All code that + * uses the tagged objects will be in the pipelines. + */ +interface ShaderId { + // No methods or constants defined at this time +} diff --git a/src/classes/share/javax/media/j3d/ShaderProgramId.java b/src/classes/share/javax/media/j3d/ShaderProgramId.java new file mode 100644 index 0000000..b3dd88c --- /dev/null +++ b/src/classes/share/javax/media/j3d/ShaderProgramId.java @@ -0,0 +1,22 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +/** + * Tagging interface for shader program objects. The rendering pipelines + * will define concrete classes that implement this interface. All code that + * uses the tagged objects will be in the pipelines. + */ +interface ShaderProgramId { + // No methods or constants defined at this time +} diff --git a/src/classes/share/javax/media/j3d/ShaderProgramRetained.java b/src/classes/share/javax/media/j3d/ShaderProgramRetained.java index 6d926bf..9524d4b 100644 --- a/src/classes/share/javax/media/j3d/ShaderProgramRetained.java +++ b/src/classes/share/javax/media/j3d/ShaderProgramRetained.java @@ -195,176 +195,176 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { } return shads; } - } - + } + /** * Method to create the native shader. */ - abstract ShaderError createShader(long ctx, ShaderRetained shader, long[] shaderIdArr); + abstract ShaderError createShader(Context ctx, ShaderRetained shader, ShaderId[] shaderIdArr); /** * Method to destroy the native shader. */ - abstract ShaderError destroyShader(long ctx, long shaderId); + abstract ShaderError destroyShader(Context ctx, ShaderId shaderId); /** * Method to compile the native shader. */ - abstract ShaderError compileShader(long ctx, long shaderId, String source); + abstract ShaderError compileShader(Context ctx, ShaderId shaderId, String source); /** * Method to create the native shader program. */ - abstract ShaderError createShaderProgram(long ctx, long[] shaderProgramIdArr); + abstract ShaderError createShaderProgram(Context ctx, ShaderProgramId[] shaderProgramIdArr); /** * Method to destroy the native shader program. */ - abstract ShaderError destroyShaderProgram(long ctx, long shaderProgramId); + abstract ShaderError destroyShaderProgram(Context ctx, ShaderProgramId shaderProgramId); /** * Method to link the native shader program. */ - abstract ShaderError linkShaderProgram(long ctx, long shaderProgramId, long[] shaderIds); + abstract ShaderError linkShaderProgram(Context ctx, ShaderProgramId shaderProgramId, ShaderId[] shaderIds); /** * Method to bind a vertex attribute name to the specified index. */ - abstract ShaderError bindVertexAttrName(long ctx, long shaderProgramId, String attrName, int attrIndex); + abstract ShaderError bindVertexAttrName(Context ctx, ShaderProgramId shaderProgramId, String attrName, int attrIndex); /** * Method to lookup a list of (uniform) shader attribute names and return * information about the attributes. */ - abstract void lookupShaderAttrNames(long ctx, long shaderProgramId, String[] attrNames, AttrNameInfo[] attrNameInfoArr); + abstract void lookupShaderAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, AttrNameInfo[] attrNameInfoArr); /* * Method to lookup a list of vertex attribute names. */ - abstract void lookupVertexAttrNames(long ctx, long shaderProgramId, String[] attrNames, boolean[] errArr); + abstract void lookupVertexAttrNames(Context ctx, ShaderProgramId shaderProgramId, String[] attrNames, boolean[] errArr); /** * Method to use the native shader program. */ - abstract ShaderError enableShaderProgram(long ctx, long shaderProgramId); + abstract ShaderError enableShaderProgram(Context ctx, ShaderProgramId shaderProgramId); /** * Method to disable the native shader program. */ - abstract ShaderError disableShaderProgram(long ctx); + abstract ShaderError disableShaderProgram(Context ctx); // ShaderAttributeValue methods - abstract ShaderError setUniform1i(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform1i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int value); - abstract ShaderError setUniform1f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform1f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float value); - abstract ShaderError setUniform2i(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform2i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int[] value); - abstract ShaderError setUniform2f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform2f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float[] value); - abstract ShaderError setUniform3i(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform3i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int[] value); - abstract ShaderError setUniform3f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float[] value); - abstract ShaderError setUniform4i(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform4i(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int[] value); - abstract ShaderError setUniform4f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float[] value); - abstract ShaderError setUniformMatrix3f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniformMatrix3f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float[] value); - abstract ShaderError setUniformMatrix4f(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniformMatrix4f(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, float[] value); // ShaderAttributeArray methods - abstract ShaderError setUniform1iArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform1iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, int[] value); - abstract ShaderError setUniform1fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform1fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); - abstract ShaderError setUniform2iArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform2iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, int[] value); - abstract ShaderError setUniform2fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform2fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); - abstract ShaderError setUniform3iArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform3iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, int[] value); - abstract ShaderError setUniform3fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); - abstract ShaderError setUniform4iArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform4iArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, int[] value); - abstract ShaderError setUniform4fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniform4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); - abstract ShaderError setUniformMatrix3fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniformMatrix3fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); - abstract ShaderError setUniformMatrix4fArray(long ctx, - long shaderProgramId, - long uniformLocation, + abstract ShaderError setUniformMatrix4fArray(Context ctx, + ShaderProgramId shaderProgramId, + ShaderAttrLoc uniformLocation, int numElements, float[] value); @@ -505,9 +505,9 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { private ShaderError createShaderProgram(Canvas3D cv, int cvRdrIndex) { // Create shaderProgram resources if it has not been done. synchronized(resourceLock) { - assert(shaderProgramData[cvRdrIndex].getShaderProgramId() == 0); + assert shaderProgramData[cvRdrIndex].getShaderProgramId() == null; - long[] spIdArr = new long[1]; + ShaderProgramId[] spIdArr = new ShaderProgramId[1]; ShaderError err = createShaderProgram(cv.ctx, spIdArr); if(err != null) { return err; @@ -524,7 +524,7 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { private ShaderError linkShaderProgram(Canvas3D cv, int cvRdrIndex, ShaderRetained[] shaders) { synchronized(resourceLock) { - long[] shaderIds = new long[shaders.length]; + ShaderId[] shaderIds = new ShaderId[shaders.length]; for(int i=0; i 0) { - m = VirtualUniverse.mc.getMessage(); + m = new J3dMessage(); m.type = J3dMessage.SWITCH_CHANGED; m.universe = universe; m.threads = threads; diff --git a/src/classes/share/javax/media/j3d/TexCoordGenerationRetained.java b/src/classes/share/javax/media/j3d/TexCoordGenerationRetained.java index 408c30f..3a5089d 100644 --- a/src/classes/share/javax/media/j3d/TexCoordGenerationRetained.java +++ b/src/classes/share/javax/media/j3d/TexCoordGenerationRetained.java @@ -255,20 +255,6 @@ class TexCoordGenerationRetained extends NodeComponentRetained { } } - /** - * These two methods update the native context, - * trans contains eyeTovworld transform in d3d - * trans contains vworldToEye transform in ogl - */ - native void updateNative(long ctx, - boolean enable, int genMode, int format, - float planeSx, float planeSy, float planeSz, float planeSw, - float planeTx, float planeTy, float planeTz, float planeTw, - float planeRx, float planeRy, float planeRz, float planeRw, - float planeQx, float planeQy, float planeQz, float planeQw, - double[] trans); - - void updateNative(Canvas3D cv) { int gMode = genMode; Transform3D trans = null; @@ -282,22 +268,17 @@ class TexCoordGenerationRetained extends NodeComponentRetained { if (VirtualUniverse.mc.isD3D() && (gMode == TexCoordGeneration.EYE_LINEAR)) { - trans = VirtualUniverse.mc.getTransform3D(cv.vworldToEc); + trans = new Transform3D(cv.vworldToEc); trans.invert(); m = trans; } - updateNative(cv.ctx, + Pipeline.getPipeline().updateTexCoordGeneration(cv.ctx, enable, gMode, format, planeS.x, planeS.y, planeS.z, planeS.w, planeT.x, planeT.y, planeT.z, planeT.w, planeR.x, planeR.y, planeR.z, planeR.w, planeQ.x, planeQ.y, planeQ.z, planeQ.w, m.mat); - - if (trans != null) { - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - trans); - } } /** @@ -379,7 +360,7 @@ class TexCoordGenerationRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.TEXCOORDGENERATION_CHANGED; createMessage.universe = null; @@ -392,7 +373,7 @@ class TexCoordGenerationRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; i

    - *

  • Boundary Width - the texture boundary width. If the texture boundary - * width is > 0, then all images for all mipmap levels will include boundary - * texels. The actual texture image for level 0, for example, will be of - * dimension (width + 2*boundaryWidth) * (height + 2*boundaryWidth). + *
  • Boundary Width - the texture boundary width, which must be 0 or 1. + * If the texture boundary + * width is 1, then all images for all mipmap levels will include a border. + * The actual texture image for level 0, for example, will be of + * dimension (width + 2*boundaryWidth) * (height + 2*boundaryWidth). * The boundary texels will be used when linear filtering is to be applied. *
  • *

  • Boundary ModeS and Boundary ModeT - the boundary mode for the @@ -549,7 +550,7 @@ public abstract class Texture extends NodeComponent { ALLOW_SHARPEN_TEXTURE_READ, ALLOW_SIZE_READ }; - + /** * Constructs a Texture object with default parameters. * The default values are as follows: @@ -610,6 +611,9 @@ public abstract class Texture extends NodeComponent { int width, int height) { + // set default read capabilities + setDefaultReadCapabilities(readCapabilities); + if ((mipMapMode != BASE_LEVEL) && (mipMapMode != MULTI_LEVEL_MIPMAP)) throw new IllegalArgumentException(J3dI18N.getString("Texture0")); @@ -619,19 +623,32 @@ public abstract class Texture extends NodeComponent { throw new IllegalArgumentException(J3dI18N.getString("Texture1")); } - // set default read capabilities - setDefaultReadCapabilities(readCapabilities); + if (width < 1) { + throw new IllegalArgumentException(J3dI18N.getString("Texture46")); + } - int widPower = getPowerOf2(width); - if (widPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture2")); + if (height < 1) { + throw new IllegalArgumentException(J3dI18N.getString("Texture47")); + } - int heiPower = getPowerOf2(height); - if (heiPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture3")); + int widthLevels; + int heightLevels; - ((TextureRetained)this.retained).initialize(format, width, widPower, - height, heiPower, mipMapMode, 0); + if (VirtualUniverse.mc.enforcePowerOfTwo) { + widthLevels = getPowerOf2(width); + if (widthLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture2")); + + heightLevels = getPowerOf2(height); + if (heightLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture3")); + } else { + widthLevels = getLevelsNPOT(width); + heightLevels = getLevelsNPOT(height); + } + + ((TextureRetained)this.retained).initialize(format, width, widthLevels, + height, heightLevels, mipMapMode, 0); } /** @@ -653,10 +670,10 @@ public abstract class Texture extends NodeComponent { * does not include the width of the boundary. * @param height height of image at level 0. Must be power of 2. This * does not include the width of the boundary. - * @param boundaryWidth width of the boundary. + * @param boundaryWidth width of the boundary, which must be 0 or 1. * @exception IllegalArgumentException if width or height are not a * power of 2, if an invalid format or mipMapMode is specified, or - * if the boundaryWidth < 0 + * if the boundaryWidth is < 0 or > 1 * * @since Java 3D 1.3 */ @@ -666,6 +683,9 @@ public abstract class Texture extends NodeComponent { int height, int boundaryWidth) { + // set default read capabilities + setDefaultReadCapabilities(readCapabilities); + if ((mipMapMode != BASE_LEVEL) && (mipMapMode != MULTI_LEVEL_MIPMAP)) throw new IllegalArgumentException(J3dI18N.getString("Texture0")); @@ -675,22 +695,35 @@ public abstract class Texture extends NodeComponent { throw new IllegalArgumentException(J3dI18N.getString("Texture1")); } - // set default read capabilities - setDefaultReadCapabilities(readCapabilities); + if (width < 1) { + throw new IllegalArgumentException(J3dI18N.getString("Texture46")); + } + + if (height < 1) { + throw new IllegalArgumentException(J3dI18N.getString("Texture47")); + } - int widPower = getPowerOf2(width); - if (widPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture2")); + int widthLevels; + int heightLevels; - int heiPower = getPowerOf2(height); - if (heiPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture3")); + if (VirtualUniverse.mc.enforcePowerOfTwo) { + widthLevels = getPowerOf2(width); + if (widthLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture2")); - if (boundaryWidth < 0) + heightLevels = getPowerOf2(height); + if (heightLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture3")); + } else { + widthLevels = getLevelsNPOT(width); + heightLevels = getLevelsNPOT(height); + } + + if (boundaryWidth < 0 || boundaryWidth > 1) throw new IllegalArgumentException(J3dI18N.getString("Texture30")); - ((TextureRetained)this.retained).initialize(format, width, widPower, - height, heiPower, mipMapMode, boundaryWidth); + ((TextureRetained)this.retained).initialize(format, width, widthLevels, + height, heightLevels, mipMapMode, boundaryWidth); } /** @@ -869,26 +902,45 @@ public abstract class Texture extends NodeComponent { } /** - * Sets the image for a specified mipmap level. + * Sets the image for a specified mipmap level. Note that the image size + * must be the correct size for the specified mipmap level. The image size + * of the base level image, that is level 0, must be the same size + * in each dimension (width, height, depth) as this + * texture, excluding the border, if any. + * Each successive mipmap level must be 1/2 the size of the previous level, + * such that size[n] = floor(size[n-1]/2), exluding + * the border. + * * @param level mipmap level to set: 0 is the base level * @param image ImageComponent object containing the texture image * for the specified mipmap level + * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @exception IllegalArgumentException if an ImageComponent3D is - * used in a Texture2D object; if an ImageComponent2D is used in a - * Texture3D object; or if this object is part of a live - * scene graph and the image being set at this level is not the - * same size (width, height, depth) as the old image at this - * level. + * used in a Texture2D object or if an ImageComponent2D is used in a + * Texture3D object. + * + * @exception IllegalArgumentException if the image being set at this + * level is not the correct size for this level. + * + * @exception IllegalSharingException if this Texture is live and + * the specified image is being used by a Canvas3D as an off-screen buffer. + * + * @exception IllegalSharingException if this Texture is + * being used by an immediate mode context and + * the specified image is being used by a Canvas3D as an off-screen buffer. */ public void setImage(int level, ImageComponent image) { if (isLiveOrCompiled()) { if(!this.getCapability(ALLOW_IMAGE_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Texture15")); } - + + // Do illegal sharing check + validateImageIllegalSharing(image); + if (isLive()) ((TextureRetained)this.retained).setImage(level, image); else @@ -913,20 +965,38 @@ public abstract class Texture extends NodeComponent { } /** - * Sets the array of images for all mipmap levels. + * Sets the array of images for all mipmap levels. Note that the image size + * of the base level image, images[0], must be the same size + * in each dimension (width, height, depth) as this + * texture, excluding the border, if any. + * Each successive mipmap level must be 1/2 the size of the previous level, + * such that size[n] = floor(size[n-1]/2), exluding + * the border. + * * @param images array of ImageComponent objects * containing the texture images for all mipmap levels * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @exception IllegalArgumentException if an ImageComponent3D is - * used in a Texture2D object; if an ImageComponent2D is used in a - * Texture3D object; if images.length is not equal to - * the total number of mipmap levels; or if this object is part of - * a live scene graph and the size of each dimension (width, - * height, depth) of the image at a given level in the - * images array is not half the dimension of the - * previous level. + * used in a Texture2D object or if an ImageComponent2D is used in a + * Texture3D object. + * + * @exception IllegalArgumentException if images.length is + * not equal to the total number of mipmap levels. + * + * @exception IllegalArgumentException if the size of each dimension + * of the image at a given level in the + * images array is not the correct size. + * + * @exception IllegalSharingException if this Texture is live and + * any of the specified images are being used by a Canvas3D as an + * off-screen buffer. + * + * @exception IllegalSharingException if this Texture is + * being used by an immediate mode context and + * any of the specified images are being used by a Canvas3D as an + * off-screen buffer. * * @since Java 3D 1.2 */ @@ -936,6 +1006,11 @@ public abstract class Texture extends NodeComponent { throw new CapabilityNotSetException(J3dI18N.getString("Texture15")); } + // Do illegal sharing check + for(int i=0; i 1) { + tmp = tmp / 2; + levels++; + } + return levels; + } /** * Sets the texture boundary color for this texture object. The @@ -1771,4 +1858,5 @@ public abstract class Texture extends NodeComponent { } return false; } + } diff --git a/src/classes/share/javax/media/j3d/Texture2D.java b/src/classes/share/javax/media/j3d/Texture2D.java index 766a396..ca20be6 100644 --- a/src/classes/share/javax/media/j3d/Texture2D.java +++ b/src/classes/share/javax/media/j3d/Texture2D.java @@ -11,68 +11,20 @@ */ package javax.media.j3d; -import javax.vecmath.*; +import javax.vecmath.*; /** * Texture2D is a subclass of Texture class. It extends Texture * class by adding a constructor and a mutator method for * setting a 2D texture image. - *

    - * Each Texture2D object has the following properties:

    - *

      - *
    • Magnification filter - the magnification filter function. - * Used when the pixel being rendered maps to an area less than or - * equal to one texel. In addition to the magnification filter functions - * defined in the base Texture class, the following values are - * supported:
    • - *

        - *
      • LINEAR_DETAIL - performs linear sampling in both the base level - * texture image and the detail texture image, and combines the two - * texture values according to the detail texture mode.
      • - *

      • LINEAR_DETAIL_RGB - performs linear detail for the rgb - * components only. The alpha component is computed using BASE_LEVEL_LINEAR - * filter.
      • - *

      • LINEAR_DETAIL_ALPHA - performs linear detail for the alpha - * component only. The rgb components are computed using BASE_LEVEL_LINEAR - * filter.
      • - *

      - *
    • Detail Texture Image - Detail texture image to be used when the texture - * magnification filter mode specifies LINEAR_DETAIL, LINEAR_DETAIL_ALPHA, or - * LINEAR_DETAIL_RGB; if the detail texture images is null, then - * the texture magnification filter mode will fall back to BASE_LEVEL_LINEAR. - *
    • - *

    • Detail Texture Mode - specifies how the texture image is combined - * with the detail image. The detail texture modes are as follows:
    • - *

        - *
      • DETAIL_ADD
      • - *

          - * T' = Ttexture + DetailFunc(LOD) * (2 * Tdetail - 1)

          - *

        - *
      • DETAIL_MODULATE
      • - *

          - * T' = Ttexture * (1 + DetailFunc(LOD) * (2 * Tdetail - 1))

          - *

        - *
      - * where Ttexture is the texture value computed from the base level - * texture image, and Tdetail is the texture value computed from the - * detail texture image.

      - *

    • Detail Texture Function - specifies the function of level-of-detail - * used in combining the detail texture with the base level texture of this object.
    • - *

    • Detail Texture Level - specifies the number of levels that - * separate the base level image of this texture object and the detail - * texture image. This value is used in the linear filter - * calculation of the detail texture image. Note, detail texture will only - * be applied to the level 0 of the texture image. Hence, for detail texture - * to work, base level has to be set to 0.
    • - *

    - * - * @see Canvas3D#queryProperties */ public class Texture2D extends Texture { /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Specifies that this Texture object allows reading its detail * texture information (e.g., detail texture image, detail texture mode, * detail texture function, detail texture function points count, @@ -84,6 +36,8 @@ public class Texture2D extends Texture { ALLOW_DETAIL_TEXTURE_READ = CapabilityBits.TEXTURE2D_ALLOW_DETAIL_TEXTURE_READ; /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Performs linear sampling in both the base level * texture image and the detail texture image, and combines the two * texture values according to the detail texture mode. @@ -94,6 +48,8 @@ public class Texture2D extends Texture { public static final int LINEAR_DETAIL = 6; /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Performs linear detail for the rgb * components only. The alpha component is computed using * BASE_LEVEL_LINEAR filter. @@ -104,6 +60,8 @@ public class Texture2D extends Texture { public static final int LINEAR_DETAIL_RGB = 7; /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Performs linear detail for the alpha * component only. The rgb components are computed using * BASE_LEVEL_LINEAR filter. @@ -114,6 +72,8 @@ public class Texture2D extends Texture { public static final int LINEAR_DETAIL_ALPHA = 8; /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Adds the detail texture image to the level 0 image of this texture * object * @@ -123,6 +83,8 @@ public class Texture2D extends Texture { public static final int DETAIL_ADD = 0; /** + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * Modulates the detail texture image with the level 0 image of this * texture object * @@ -167,10 +129,10 @@ public class Texture2D extends Texture { * BASE_LEVEL, MULTI_LEVEL_MIPMAP. * @param format data format of Textures saved in this object. * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA. - * @param width width of image at level 0. Must be power of 2. - * @param height height of image at level 0. Must be power of 2. + * @param width width of image at level 0. Must be greater than 0 + * @param height height of image at level 0. Must be greater than 0 * @exception IllegalArgumentException if width or height are NOT - * power of 2 OR invalid format/mipmapMode is specified. + * greater than 0 OR invalid format/mipmapMode is specified. */ public Texture2D( int mipMapMode, @@ -200,14 +162,14 @@ public class Texture2D extends Texture { * BASE_LEVEL, MULTI_LEVEL_MIPMAP * @param format data format of Textures saved in this object. * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA - * @param width width of image at level 0. Must be power of 2. This + * @param width width of image at level 0. Must be greater than 0. This * does not include the width of the boundary. - * @param height height of image at level 0. Must be power of 2. This + * @param height height of image at level 0. Must be greater than 0. This * does not include the width of the boundary. - * @param boundaryWidth width of the boundary. - * @exception IllegalArgumentException if width or height are not a - * power of 2, if an invalid format or mipMapMode is specified, or - * if the boundaryWidth < 0 + * @param boundaryWidth width of the boundary, which must be 0 or 1. + * @exception IllegalArgumentException if width or height are not greater + * than 0, if an invalid format or mipMapMode is specified, or + * if the boundaryWidth is < 0 or > 1 * * @since Java 3D 1.3 */ @@ -271,7 +233,9 @@ public class Texture2D extends Texture { } /** - * Sets the detail texture image for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @param detailTexture ImageComponent2D object containing the * detail texture image. * @exception RestrictedAccessException if the method is called @@ -286,7 +250,9 @@ public class Texture2D extends Texture { } /** - * Retrieves the detail texture image for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @return ImageComponent2D object containing the detail texture image. * * @exception CapabilityNotSetException if appropriate capability is @@ -305,7 +271,9 @@ public class Texture2D extends Texture { } /** - * Sets the detail texture mode for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @param mode detail texture mode. One of: DETAIL_ADD or DETAIL_MODULATE * * @exception IllegalArgumentException if @@ -327,7 +295,9 @@ public class Texture2D extends Texture { } /** - * Retrieves the detail texture mode for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @return the detail texture mode. * * @exception CapabilityNotSetException if appropriate capability is @@ -346,7 +316,9 @@ public class Texture2D extends Texture { } /** - * Sets the detail texture level for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @param level the detail texture level. * * @exception IllegalArgumentException if level < 0 @@ -366,7 +338,9 @@ public class Texture2D extends Texture { } /** - * Retrieves the detail texture level for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @return the detail texture level. * * @exception CapabilityNotSetException if appropriate capability is @@ -385,7 +359,9 @@ public class Texture2D extends Texture { } /** - * sets the detail texture LOD function for this texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. + * * @param lod array containing the level-of-detail values. * @param pts array containing the function values for the corresponding * level-of-detail values. @@ -409,9 +385,8 @@ public class Texture2D extends Texture { } /** - * sets the detail texture LOD function for this texture object. - * The Point2f x,y values are defined as follows: x is the lod value, - * y is the corresponding function value. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * * @param pts array of Point2f containing the lod as well as the * corresponding function value. @@ -428,8 +403,8 @@ public class Texture2D extends Texture { } /** - * Gets the number of points in the detail texture LOD function for this - * texture object. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * * @return the number of points in the detail texture LOD function. * @@ -449,9 +424,8 @@ public class Texture2D extends Texture { } /** - * Copies the array of detail texture LOD function points into the - * specified arrays. The arrays must be large enough to hold all the - * points. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * * @param lod the array to receive the level-of-detail values. * @param pts the array to receive the function values for the @@ -473,10 +447,8 @@ public class Texture2D extends Texture { } /** - * Copies the array of detail texture LOD function points including - * the lod values and the corresponding function values into the - * specified array. The array must be large enough to hold all the points. - * The individual array elements must be allocated by the caller as well. + * @deprecated As of Java 3D 1.5 the optional detail texture feature is no + * longer supported. * * @param pts the array to receive the detail texture LOD function points * diff --git a/src/classes/share/javax/media/j3d/Texture2DRetained.java b/src/classes/share/javax/media/j3d/Texture2DRetained.java index 991c6ee..4957680 100644 --- a/src/classes/share/javax/media/j3d/Texture2DRetained.java +++ b/src/classes/share/javax/media/j3d/Texture2DRetained.java @@ -22,17 +22,18 @@ import javax.vecmath.*; */ class Texture2DRetained extends TextureRetained { + // Note : There is hardly any HW vendor supports detail Image. + // Detail Image operation is simply no-op in 1.5. + // currently detail image is only applicable to 2D texture - // detail texture info - - int detailTextureId = -1; - ImageComponent2DRetained detailImage = null; - DetailTextureImage detailTexture = null; - int detailTextureMode = Texture2D.DETAIL_MODULATE; - int detailTextureLevel = 2; - int numDetailTextureFuncPts = 0; - float detailTextureFuncPts[] = null; // array of pairs of floats + + // These members are unused except for public set and get methods. + private ImageComponent2DRetained detailImage = null; + private int detailTextureMode = Texture2D.DETAIL_MODULATE; + private int detailTextureLevel = 2; + private int numDetailTextureFuncPts = 0; + private float detailTextureFuncPts[] = null; // array of pairs of floats // first value for LOD // second value for the fcn value @@ -44,7 +45,6 @@ class Texture2DRetained extends TextureRetained { detailImage = null; } else { detailImage = (ImageComponent2DRetained)image.retained; - detailImage.setTextureRef(); } } @@ -184,174 +184,6 @@ class Texture2DRetained extends TextureRetained { return detailTextureFuncPts; } - synchronized void initMirrorObject() { - - super.initMirrorObject(); - - Texture2DRetained mirrorTexture = (Texture2DRetained)mirror; - - // detail texture info - mirrorTexture.detailImage = detailImage; - mirrorTexture.detailTextureMode = detailTextureMode; - mirrorTexture.detailTextureLevel = detailTextureLevel; - mirrorTexture.detailTexture = null; - mirrorTexture.numDetailTextureFuncPts = numDetailTextureFuncPts; - - if (detailTextureFuncPts == null) { - mirrorTexture.detailTextureFuncPts = null; - } else { - if ((mirrorTexture.detailTextureFuncPts == null) || - (mirrorTexture.detailTextureFuncPts.length != - detailTextureFuncPts.length)) { - mirrorTexture.detailTextureFuncPts = - new float[detailTextureFuncPts.length]; - } - for (int i = 0; i < detailTextureFuncPts.length; i++) { - mirrorTexture.detailTextureFuncPts[i] = - detailTextureFuncPts[i]; - } - - // add detail texture to the user list of the image - // only if detail texture is to be used - if ((mirrorTexture.detailImage != null) && - (mirrorTexture.magFilter >= Texture2D.LINEAR_DETAIL) && - (mirrorTexture.magFilter <= Texture2D.LINEAR_DETAIL_ALPHA)) { - mirrorTexture.detailImage.addUser(mirrorTexture); - } - } - } - - void clearLive(int refCount) { - super.clearLive(refCount); - - // remove detail texture from the user list of the image - if ((detailImage != null) && - (magFilter >= Texture2D.LINEAR_DETAIL) && - (magFilter <= Texture2D.LINEAR_DETAIL_ALPHA)) { - detailImage.removeUser(mirror); - } - } - - // overload the incTextureBinRefCount method to take care - // of detail texture ref as well - // This method is called from RenderBin when a new TextureBin - // is created. And all the referenced textures in that TextureBin - // will be notified to increment the TextureBin reference count. - - void incTextureBinRefCount(TextureBin tb) { - super.incTextureBinRefCount(tb); - - // increment detail texture ref count - - if ((detailImage != null) && - (magFilter >= Texture2D.LINEAR_DETAIL) && - (magFilter <= Texture2D.LINEAR_DETAIL_ALPHA)) { - if (detailTexture == null) { - detailTexture = detailImage.getDetailTexture(); - } - - detailTexture.incTextureBinRefCount(format, tb); - } - } - - // This method is called from AttributeBin when a TextureBin - // is to be removed. And all the referenced textures in that TextureBin - // will be notified to decrement the TextureBin reference count. - // And if detail texture exists, we need to decrement the - // TextureBin reference count of the detail texture as well. - - void decTextureBinRefCount(TextureBin tb) { - super.decTextureBinRefCount(tb); - - // decrement detail texture ref count - - if (detailTexture != null) { - detailTexture.decTextureBinRefCount(format, tb); - } - } - - - native void bindDetailTexture(long ctx, int objectId); - - native void updateTextureImage(long ctx, - int numLevels, - int level, - int internalFormat, int format, - int width, int height, - int boundaryWidth, byte[] imageYup); - - native void updateTextureSubImage(long ctx, - int level, int xoffset, int yoffset, - int internalFormat,int format, - int imgXOffset, int imgYOffset, - int tilew, - int width, int height, - byte[] image); - - native void updateDetailTextureParameters(long ctx, - int detailTextureMode, - int detailTextureLevel, - int nPts, float[] pts); - // wrapper to the native call - - void updateTextureImage(Canvas3D cv, int face, - int numLevels, int level, - int format, int storedFormat, - int width, int height, - int boundaryWidth, - byte[] data) { - - updateTextureImage(cv.ctx, numLevels, level, format, - storedFormat, width, height, - boundaryWidth, data); - } - - - - // wrapper to the native call - - void updateTextureSubImage(Canvas3D cv, int face, int level, - int xoffset, int yoffset, int format, - int storedFormat, int imgXOffset, - int imgYOffset, int tileWidth, - int width, int height, byte[] data) { - - updateTextureSubImage(cv.ctx, level, xoffset, yoffset, format, - storedFormat, imgXOffset, imgYOffset, - tileWidth, width, height, data); - } - - - void updateNative(Canvas3D cv) { - - // update mipmap texture - - super.updateNative(cv); - - - // update detail texture if exists - - if (detailTexture != null) { - detailTexture.updateNative(cv, format); - } - } - - - // update texture parameters - - void updateTextureFields(Canvas3D cv) { - - super.updateTextureFields(cv); - - // update detail texture parameters if applicable - - if (detailTexture != null) { - - updateDetailTextureParameters(cv.ctx, detailTextureMode, - detailTextureLevel, numDetailTextureFuncPts, - detailTextureFuncPts); - } - } } diff --git a/src/classes/share/javax/media/j3d/Texture3D.java b/src/classes/share/javax/media/j3d/Texture3D.java index 69f007d..024a2d8 100644 --- a/src/classes/share/javax/media/j3d/Texture3D.java +++ b/src/classes/share/javax/media/j3d/Texture3D.java @@ -24,6 +24,8 @@ package javax.media.j3d; public class Texture3D extends Texture { + // TODO KCR : NPOT + /** * Constructs a Texture3D object with default parameters. * The default values are as follows: @@ -62,10 +64,20 @@ public class Texture3D extends Texture { int depth) { super(mipmapMode, format, width, height); - int depthPower = getPowerOf2(depth); - if (depthPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture3D1")); + int depthLevels = -1; + if (VirtualUniverse.mc.enforcePowerOfTwo) { + depthLevels = getPowerOf2(depth); + if (depthLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture3D1")); + + } else { + depthLevels = getLevelsNPOT(depth); + } + + // TODO : Need to verify whether this is a bug. Why depthLevels isn't + // use to determine maxMipMapLevels ? See also Texture.java + ((Texture3DRetained)this.retained).setDepth(depth); } @@ -83,10 +95,10 @@ public class Texture3D extends Texture { * @param width width of image at level 0. Must be power of 2. * @param height height of image at level 0. Must be power of 2. * @param depth depth of image at level 0. Must be power of 2. - * @param boundaryWidth width of the boundary. + * @param boundaryWidth width of the boundary, which must be 0 or 1. * @exception IllegalArgumentException if width or height are NOT * power of 2 OR invalid format/mipmapMode is specified, or - * if the boundaryWidth < 0 + * if the boundaryWidth is < 0 or > 1 * * @since Java 3D 1.3 */ @@ -98,10 +110,22 @@ public class Texture3D extends Texture { int boundaryWidth) { super(mipmapMode, format, width, height, boundaryWidth); - int depthPower = getPowerOf2(depth); - if (depthPower == -1) - throw new IllegalArgumentException(J3dI18N.getString("Texture3D1")); - + int depthLevels = -1; + + if (VirtualUniverse.mc.enforcePowerOfTwo) { + depthLevels = getPowerOf2(depth); + + if (depthLevels == -1) + throw new IllegalArgumentException(J3dI18N.getString("Texture3D1")); + } + else { + depthLevels = getLevelsNPOT(depth); + + } + + // TODO : Need to verify whether this is a bug. Why depthLevels isn't + // use to determine maxMipMapLevels ? See also Texture.java + ((Texture3DRetained)this.retained).setDepth(depth); } diff --git a/src/classes/share/javax/media/j3d/Texture3DRetained.java b/src/classes/share/javax/media/j3d/Texture3DRetained.java index 6128325..5e4f667 100644 --- a/src/classes/share/javax/media/j3d/Texture3DRetained.java +++ b/src/classes/share/javax/media/j3d/Texture3DRetained.java @@ -57,42 +57,84 @@ class Texture3DRetained extends TextureRetained { /** * This method updates the native context. */ - native void bindTexture(long ctx, int objectId, boolean enable); + void bindTexture(Context ctx, int objectId, boolean enable) { + Pipeline.getPipeline().bindTexture3D(ctx, objectId, enable); + } - native void updateTextureBoundary(long ctx, - int boundaryModeS, int boundaryModeT, - int boundaryModeR, float boundaryRed, - float boundaryGreen, float boundaryBlue, - float boundaryAlpha); - - native void updateTextureFilterModes(long ctx, - int minFilter, int magFilter); + void updateTextureBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + int boundaryModeR, float boundaryRed, + float boundaryGreen, float boundaryBlue, + float boundaryAlpha) { - native void updateTextureSharpenFunc(long ctx, - int numSharpenTextureFuncPts, - float[] sharpenTextureFuncPts); + Pipeline.getPipeline().updateTexture3DBoundary(ctx, + boundaryModeS, boundaryModeT, boundaryModeR, + boundaryRed, boundaryGreen, + boundaryBlue, boundaryAlpha); + } - native void updateTextureFilter4Func(long ctx, - int numFilter4FuncPts, - float[] filter4FuncPts); + void updateTextureFilterModes(Context ctx, + int minFilter, int magFilter) { - native void updateTextureAnisotropicFilter(long ctx, float degree); + Pipeline.getPipeline().updateTexture3DFilterModes(ctx, + minFilter, magFilter); + } + void updateTextureSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { + + Pipeline.getPipeline().updateTexture3DSharpenFunc(ctx, + numSharpenTextureFuncPts, sharpenTextureFuncPts); + } - native void updateTextureImage(long ctx, int numLevels, int level, - int format, int internalFormat, int width, - int height, int depth, - int boundaryWidth, byte[] imageYup); + void updateTextureFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { + + Pipeline.getPipeline().updateTexture3DFilter4Func(ctx, + numFilter4FuncPts, filter4FuncPts); + } + + void updateTextureAnisotropicFilter(Context ctx, float degree) { + Pipeline.getPipeline().updateTexture3DAnisotropicFilter(ctx, degree); + } - native void updateTextureSubImage(long ctx, int level, - int xoffset, int yoffset, int zoffset, - int internalFormat, int format, - int imgXoffset, int imgYoffset, int imgZoffset, - int tilew, int tileh, - int width, int height, int depth, - byte[] imageYup); + // Wrapper around the native call for 3D textures + void updateTextureImage(Canvas3D cv, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, int depth, + int boundaryWidth, int imageDataType, + Object imageData) { + + Pipeline.getPipeline().updateTexture3DImage(cv.ctx, + numLevels, level, + textureFormat, imageFormat, + width, height, depth, + boundaryWidth, imageDataType, imageData); + } + + // Wrapper around the native call for 3D textures + void updateTextureSubImage(Canvas3D cv, + int face, int level, + int xoffset, int yoffset, int zoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, int imgZOffset, + int tilew, int tileh, int width, int height, int depth, + int imageDataType, Object imageData) { + + Pipeline.getPipeline().updateTexture3DSubImage(cv.ctx, + level, xoffset, yoffset, zoffset, + textureFormat, imageFormat, + imgXOffset, imgYOffset, imgZOffset, + tilew, tileh, width, height, depth, + imageDataType, imageData); + } + + // get an ID for Texture3D int getTextureId() { @@ -116,18 +158,36 @@ class Texture3DRetained extends TextureRetained { // mipmapping when level 0 is not the base level void updateTextureDimensions(Canvas3D cv) { - updateTextureImage(cv.ctx, maxLevels, 0, - format, ImageComponentRetained.BYTE_RGBA, - width, height, depth, boundaryWidth, null); + if(images[0][0] != null) { + updateTextureImage(cv, maxLevels, 0, 0, + format, images[0][0].getImageFormatTypeIntValue(false), + width, height, depth, boundaryWidth, + images[0][0].getImageDataTypeIntValue(), null); + } } void updateTextureBoundary(Canvas3D cv) { - updateTextureBoundary(cv.ctx, - boundaryModeS, boundaryModeT, boundaryModeR, - boundaryColor.x, boundaryColor.y, - boundaryColor.z, boundaryColor.w); - + updateTextureBoundary(cv.ctx, + boundaryModeS, boundaryModeT, boundaryModeR, + boundaryColor.x, boundaryColor.y, + boundaryColor.z, boundaryColor.w); + } + + void updateTextureLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + + Pipeline.getPipeline().updateTexture3DLodRange(ctx, baseLevel, maximumLevel, + minimumLod, maximumLod); + } + + void updateTextureLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + + Pipeline.getPipeline().updateTexture3DLodOffset(ctx, + lodOffsetX, lodOffsetY, lodOffsetZ); } void reloadTextureImage(Canvas3D cv, int face, int level, @@ -139,13 +199,16 @@ class Texture3DRetained extends TextureRetained { " h= " + image.height + " d= " + depth + " numLevels= " + numLevels); */ - - - updateTextureImage(cv.ctx, numLevels, level, format, - image.storedYupFormat, - image.width, image.height, depth, - boundaryWidth, image.imageYup); - + + // Texture3D does not need to support Raster + ImageComponentRetained.ImageData imageData = image.getImageData(false); + + updateTextureImage(cv, + 0, numLevels, level, format, + image.getImageFormatTypeIntValue(false), + image.width, image.height, depth, + boundaryWidth, image.getImageDataTypeIntValue(), + imageData.get()); } void reloadTextureSubImage(Canvas3D cv, int level, int face, @@ -157,43 +220,18 @@ class Texture3DRetained extends TextureRetained { width = info.width, height = info.height; - int xoffset = x - image.minX; - int yoffset = y - image.minY; - - updateTextureSubImage(cv.ctx, level, xoffset, yoffset, z, - format, image.storedYupFormat, - xoffset, yoffset, z, - image.width, image.height, - width, height, 1, image.imageYup); - } - - - - protected void finalize() { - - if (objectId > 0) { - // memory not yet free - // send a message to the request renderer - synchronized (VirtualUniverse.mc.contextCreationLock) { - boolean found = false; - - for (Enumeration e = Screen3D.deviceRendererMap.elements(); - e.hasMoreElements(); ) { - Renderer rdr = (Renderer) e.nextElement(); - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); - renderMessage.threads = J3dThread.RENDER_THREAD; - renderMessage.type = J3dMessage.RENDER_IMMEDIATE; - renderMessage.universe = null; - renderMessage.view = null; - renderMessage.args[0] = null; - renderMessage.args[1] = new Integer(objectId); - renderMessage.args[2] = "3D"; - rdr.rendererStructure.addMessage(renderMessage); - } - objectId = -1; - } - VirtualUniverse.mc.setWorkForRequestRenderer(); - } + int xoffset = x; + int yoffset = y; + // Texture3D does not need to support Raster + ImageComponentRetained.ImageData imageData = image.getImageData(false); + + updateTextureSubImage(cv, + 0, level, xoffset, yoffset, z, + format, image.getImageFormatTypeIntValue(false), + xoffset, yoffset, z, + image.width, image.height, + width, height, 1, image.getImageDataTypeIntValue(), + imageData.get()); } } diff --git a/src/classes/share/javax/media/j3d/TextureAttributesRetained.java b/src/classes/share/javax/media/j3d/TextureAttributesRetained.java index 3b58d95..aaba553 100644 --- a/src/classes/share/javax/media/j3d/TextureAttributesRetained.java +++ b/src/classes/share/javax/media/j3d/TextureAttributesRetained.java @@ -220,8 +220,7 @@ class TextureAttributesRetained extends NodeComponentRetained { */ final void setTextureTransform(Transform3D transform) { this.transform.set(transform); - sendMessage(TRANSFORM_CHANGED, - VirtualUniverse.mc.getTransform3D(transform), null); + sendMessage(TRANSFORM_CHANGED, new Transform3D(transform), null); } @@ -498,39 +497,6 @@ class TextureAttributesRetained extends NodeComponentRetained { return combineAlphaScale; } - // These methods update the native context. - native void updateNative(long ctx, - double[] transform, boolean isIdentity, int textureMode, - int perspCorrectionMode, float red, - float green, float blue, float alpha, - int textureFormat); - - native void updateNativeRegisterCombiners(long ctx, - double[] transform, boolean isIdentity, int textureMode, - int perspCorrectionMode, float red, - float green, float blue, float alpha, - int textureFormat, - int combineRgbMode, int combineAlphaMode, - int[] combineRgbSrc, int[] combineAlphaSrc, - int[] combineRgbFcn, int[] combineAlphaFcn, - int combineRgbScale, int combineAlphaScale); - - native void updateTextureColorTableNative(long ctx, int numComponents, - int colorTableSize, - int[] colorTable); - - native void updateCombinerNative(long ctx, - int combineRgbMode, int combineAlphaMode, - int[] combineRgbSrc, int[] combineAlphaSrc, - int[] combineRgbFcn, int[] combineAlphaFcn, - int combineRgbScale, int combineAlphaScale); - - // NOTE: the following native methods are not used any more, since - // we no longer do simulated multi-pass by default - // (and with shaders, this won't work anyway) -// native void restoreBlend1Pass(long ctx); -// native void updateBlend2Pass(long ctx); - void updateNative(Canvas3D cv, boolean simulate, int textureFormat) { //System.out.println("TextureAttributes/updateNative: simulate= " + simulate + " " + this); @@ -548,14 +514,14 @@ class TextureAttributesRetained extends NodeComponentRetained { if (VirtualUniverse.mc.useCombiners && (cv.textureExtendedFeatures & Canvas3D.TEXTURE_REGISTER_COMBINERS) != 0) { - updateNativeRegisterCombiners(cv.ctx, - transform.mat, isIdentity, textureMode, perspCorrectionMode, - textureBlendColor.x, textureBlendColor.y, - textureBlendColor.z, textureBlendColor.w, - textureFormat, combineRgbMode, combineAlphaMode, - combineRgbSrc, combineAlphaSrc, - combineRgbFcn, combineAlphaFcn, - combineRgbScale, combineAlphaScale); + Pipeline.getPipeline().updateRegisterCombiners(cv.ctx, + transform.mat, isIdentity, textureMode, perspCorrectionMode, + textureBlendColor.x, textureBlendColor.y, + textureBlendColor.z, textureBlendColor.w, + textureFormat, combineRgbMode, combineAlphaMode, + combineRgbSrc, combineAlphaSrc, + combineRgbFcn, combineAlphaFcn, + combineRgbScale, combineAlphaScale); } else { if (textureMode == TextureAttributes.COMBINE) { @@ -567,11 +533,12 @@ class TextureAttributesRetained extends NodeComponentRetained { int _combineRgbMode = combineRgbMode; int _combineAlphaMode = combineAlphaMode; - updateNative(cv.ctx, transform.mat, isIdentity, textureMode, - perspCorrectionMode, - textureBlendColor.x, textureBlendColor.y, - textureBlendColor.z, textureBlendColor.w, - textureFormat); + Pipeline.getPipeline().updateTextureAttributes(cv.ctx, + transform.mat, isIdentity, textureMode, + perspCorrectionMode, + textureBlendColor.x, textureBlendColor.y, + textureBlendColor.z, textureBlendColor.w, + textureFormat); if (((combineRgbMode == TextureAttributes.COMBINE_DOT3) && @@ -600,30 +567,32 @@ class TextureAttributesRetained extends NodeComponentRetained { _combineAlphaMode = TextureAttributes.COMBINE_REPLACE; } - updateCombinerNative(cv.ctx, - _combineRgbMode, _combineAlphaMode, - combineRgbSrc, combineAlphaSrc, - combineRgbFcn, combineAlphaFcn, - combineRgbScale, combineAlphaScale); + Pipeline.getPipeline().updateCombiner(cv.ctx, + _combineRgbMode, _combineAlphaMode, + combineRgbSrc, combineAlphaSrc, + combineRgbFcn, combineAlphaFcn, + combineRgbScale, combineAlphaScale); } else { // Texture COMBINE is not supported by the underlying // layer, fallback to REPLACE - updateNative(cv.ctx, transform.mat, isIdentity, - TextureAttributes.REPLACE, - perspCorrectionMode, - textureBlendColor.x, textureBlendColor.y, - textureBlendColor.z, textureBlendColor.w, - textureFormat); + Pipeline.getPipeline().updateTextureAttributes(cv.ctx, + transform.mat, isIdentity, + TextureAttributes.REPLACE, + perspCorrectionMode, + textureBlendColor.x, textureBlendColor.y, + textureBlendColor.z, textureBlendColor.w, + textureFormat); } } else { - updateNative(cv.ctx, transform.mat, isIdentity, textureMode, - perspCorrectionMode, - textureBlendColor.x, textureBlendColor.y, - textureBlendColor.z, textureBlendColor.w, - textureFormat); + Pipeline.getPipeline().updateTextureAttributes(cv.ctx, + transform.mat, isIdentity, textureMode, + perspCorrectionMode, + textureBlendColor.x, textureBlendColor.y, + textureBlendColor.z, textureBlendColor.w, + textureFormat); } } @@ -631,7 +600,7 @@ class TextureAttributesRetained extends NodeComponentRetained { if (((cv.textureExtendedFeatures & Canvas3D.TEXTURE_COLOR_TABLE) != 0) && textureColorTable != null) { - updateTextureColorTableNative(cv.ctx, + Pipeline.getPipeline().updateTextureColorTable(cv.ctx, numTextureColorTableComponents, textureColorTableSize, textureColorTable); } @@ -639,15 +608,16 @@ class TextureAttributesRetained extends NodeComponentRetained { // we are in the multi-pass mode, // in this case, set the texture Mode to replace and use // blending to simulate the original textureMode - updateNative(cv.ctx, transform.mat, isIdentity, TextureAttributes.REPLACE, - perspCorrectionMode, - textureBlendColor.x, textureBlendColor.y, - textureBlendColor.z, textureBlendColor.w, textureFormat); + Pipeline.getPipeline().updateTextureAttributes(cv.ctx, + transform.mat, isIdentity, TextureAttributes.REPLACE, + perspCorrectionMode, + textureBlendColor.x, textureBlendColor.y, + textureBlendColor.z, textureBlendColor.w, textureFormat); if (((cv.textureExtendedFeatures & Canvas3D.TEXTURE_COLOR_TABLE) != 0) && textureColorTable != null) { - updateTextureColorTableNative(cv.ctx, numTextureColorTableComponents, + Pipeline.getPipeline().updateTextureColorTable(cv.ctx, numTextureColorTableComponents, textureColorTableSize, textureColorTable); } @@ -727,8 +697,6 @@ class TextureAttributesRetained extends NodeComponentRetained { if ((component & TRANSFORM_CHANGED) != 0) { mirrorTa.transform.set((Transform3D)value); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - (Transform3D)value); } else if ((component & MODE_CHANGED) != 0) { mirrorTa.textureMode = ((Integer)value).intValue(); @@ -969,7 +937,7 @@ class TextureAttributesRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.TEXTUREATTRIBUTES_CHANGED; createMessage.universe = null; @@ -983,7 +951,7 @@ class TextureAttributesRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; i availableTextureUnits) { + if (numActiveTexUnit > availableTextureUnits) { disableTexture = true; // System.err.println("*** TextureBin : number of texture units exceeded"); } @@ -1148,7 +1153,7 @@ class TextureBin extends Object implements ObjectUpdate { } cv.setLastActiveTexUnit(-1); } - } else if (pass < 0) { + } else { int j = 0; @@ -1194,28 +1199,10 @@ class TextureBin extends Object implements ObjectUpdate { } cv.setLastActiveTexUnit(lastActiveTexUnitIdx); - // tell the underlying library the texture unit mapping - - if ((pass == USE_DISPLAYLIST) && - (cv.numActiveTexUnit > 0)) { - cv.updateTexUnitStateMap(); - } // set the active texture unit back to 0 cv.activeTextureUnit(cv.ctx, 0); - } else { - // update the last active texture unit state - if (dirty || cv.texUnitState[0].mirror == null || - cv.texUnitState[0].mirror != - texUnitState[lastActiveTexUnitIndex].mirror) { - texUnitState[lastActiveTexUnitIndex].updateNative( - -1, cv, false, false); - cv.texUnitState[0].mirror = - texUnitState[lastActiveTexUnitIndex].mirror; - - cv.setLastActiveTexUnit(0); - } } cv.canvasDirty &= ~Canvas3D.TEXTUREBIN_DIRTY; } @@ -1256,20 +1243,7 @@ class TextureBin extends Object implements ObjectUpdate { } } - // If shaders are not being used, and if allowSimulatedMultiTexture - // property is set, then we will use simulated (multi-pass) - // multi-texture when the requested number of texture units exceeds - // the available number of texture units - boolean useShaders = (shaderBin.shaderProgram != null); - int availableTextureUnits = - useShaders ? cv.maxTextureImageUnits : cv.maxTextureUnits; - - if (!useShaders && (numActiveTexUnit > availableTextureUnits) && - VirtualUniverse.mc.allowSimulatedMultiTexture) { - multiPassRender(cv, rlist); - } else { - renderList(cv, USE_DISPLAYLIST, rlist); - } + renderList(cv, USE_DISPLAYLIST, rlist); } @@ -1277,6 +1251,7 @@ class TextureBin extends Object implements ObjectUpdate { * render a render list */ void renderList(Canvas3D cv, int pass, Object rlist) { + assert pass < 0; if (rlist instanceof RenderMolecule) { renderList(cv, pass, (RenderMolecule) rlist); @@ -1290,6 +1265,7 @@ class TextureBin extends Object implements ObjectUpdate { * render list of RenderMolecule */ void renderList(Canvas3D cv, int pass, RenderMolecule rlist) { + assert pass < 0; // bit mask of all attr fields that are equivalent across // renderMolecules thro. ORing of invisible RMs. @@ -1323,6 +1299,7 @@ class TextureBin extends Object implements ObjectUpdate { * render sorted transparent list */ void renderList(Canvas3D cv, int pass, TransparentRenderingInfo tinfo) { + assert pass < 0; RenderMolecule rm = tinfo.rm; if (rm.isSwitchOn()) { @@ -1331,87 +1308,6 @@ class TextureBin extends Object implements ObjectUpdate { } - - /** - * multi rendering pass to simulate multiple texture units - */ - private void multiPassRender(Canvas3D cv, Object rlist) { - - assert VirtualUniverse.mc.allowSimulatedMultiTexture; - - boolean startToSimulate = false; - boolean isFogEnabled = false; - - // No lazy download of texture for multi-pass, - // update the texture states here now - - // update the environment state - - // no need to update the texture state in updateAttributes(), the state - // will be explicitly updated in the multi-pass - cv.setStateIsUpdated(Canvas3D.TEXTUREBIN_BIT); - cv.textureBin = this; - cv.canvasDirty &= ~Canvas3D.TEXTUREBIN_DIRTY; - cv.updateEnvState(); - - - // first reset those texture units that are currently enabled - - if (cv.multiTexAccelerated) { - int activeTexUnit = cv.getNumActiveTexUnit(); - for (int i = 0; i < activeTexUnit; i++) { - cv.resetTexture(cv.ctx, i); - } - // set the active texture unit back to 0 - cv.activeTextureUnit(cv.ctx, 0); - } - - // only texture unit 0 will be used in multi-pass case - cv.setNumActiveTexUnit(1); - cv.setLastActiveTexUnit(0); - - // first check if there is fog in the path - // if there is, then turn off fog now and turn it back on - // for the last pass only - isFogEnabled = (environmentSet.fog != null); - - TextureUnitStateRetained tus; - - for (int i = 0; i < texUnitState.length; i++) { - tus = texUnitState[i]; - - if (tus != null && tus.isTextureEnabled()) { - - - // update the canvas texture unit state cache - cv.texUnitState[0].mirror = tus.mirror; - - tus.updateNative(-1, cv, false, startToSimulate); - - if (!startToSimulate) { - startToSimulate = true; - if (isFogEnabled) { - cv.setFogEnableFlag(cv.ctx, false); - } - } - - // turn on fog again in the last pass - - if (i == lastActiveTexUnitIndex && isFogEnabled) { - cv.setFogEnableFlag(cv.ctx, true); - } - renderList(cv, i, rlist); - } - } - - // adjust the depth test back to what it was - // and adjust the blend func to what it was - if (startToSimulate) { - cv.setStateToUpdate(Canvas3D.TRANSPARENCY_BIT); - } - } - - void changeLists(RenderMolecule r) { RenderMolecule renderMoleculeList, rmlist = null, head; HashMap allMap = null; @@ -1680,5 +1576,3 @@ class TextureBin extends Object implements ObjectUpdate { numEditingRenderMolecules++; } } - - diff --git a/src/classes/share/javax/media/j3d/TextureCubeMap.java b/src/classes/share/javax/media/j3d/TextureCubeMap.java index 9c6f608..f3facec 100644 --- a/src/classes/share/javax/media/j3d/TextureCubeMap.java +++ b/src/classes/share/javax/media/j3d/TextureCubeMap.java @@ -44,6 +44,8 @@ import javax.vecmath.*; */ public class TextureCubeMap extends Texture { + // TODO KCR : NPOT + /** * Specifies the face of the cube that is pierced by the positive x axis */ @@ -123,7 +125,7 @@ public class TextureCubeMap extends Texture { * @param format data format of Textures saved in this object. * One of INTENSITY, LUMINANCE, ALPHA, LUMINANCE_ALPHA, RGB, RGBA. * @param width width of image at level 0. Must be power of 2. - * @param boundaryWidth width of the boundary. + * @param boundaryWidth width of the boundary, which must be 0 or 1. * * @exception IllegalArgumentException if width is NOT * power of 2 OR invalid format/mipmapMode is specified. @@ -157,6 +159,12 @@ public class TextureCubeMap extends Texture { * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalSharingException if this TextureCubeMap is live and + * the specified image is being used by a Canvas3D as an off-screen buffer. + * + * @exception IllegalSharingException if this TextureCubeMap is + * being used by an immediate mode context and + * the specified image is being used by a Canvas3D as an off-screen buffer. */ public void setImage(int level, int face, ImageComponent2D image) { if (isLiveOrCompiled()) { @@ -164,7 +172,9 @@ public class TextureCubeMap extends Texture { throw new CapabilityNotSetException( J3dI18N.getString("TextureCubeMap1")); } - + + validateImageIllegalSharing(image); + if (isLive()) ((TextureCubeMapRetained)this.retained).setImage(level, face, image); else @@ -190,6 +200,14 @@ public class TextureCubeMap extends Texture { * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * + * @exception IllegalSharingException if this TextureCubeMap is live and + * any of the specified images are being used by a Canvas3D as an + * off-screen buffer. + * + * @exception IllegalSharingException if this TextureCubeMap is + * being used by an immediate mode context and + * any of the specified images are being used by a Canvas3D as an + * off-screen buffer. */ public void setImages(int face, ImageComponent2D[] images) { if (isLiveOrCompiled()) { @@ -198,6 +216,11 @@ public class TextureCubeMap extends Texture { J3dI18N.getString("TextureCubeMap1")); } + // Do illegal sharing check + for(int i=0; i heiPower) { - maxMipMapLevels = widPower + 1; + if (widLevels > heiLevels) { + maxMipMapLevels = widLevels + 1; } else { - maxMipMapLevels = heiPower + 1; + maxMipMapLevels = heiLevels + 1; } @@ -331,6 +332,10 @@ abstract class TextureRetained extends NodeComponentRetained { * power of 2 OR invalid format/mipmapMode is specified. */ void initImage(int level, ImageComponent image) { + + // Issue 172 : call checkImageSize even for non-live setImage calls + checkImageSize(level, image); + if (this.images == null) { throw new IllegalArgumentException(J3dI18N.getString("TextureRetained0")); } @@ -359,12 +364,6 @@ abstract class TextureRetained extends NodeComponentRetained { } } - if (this instanceof Texture2DRetained) { - ((ImageComponent2DRetained)image.retained).setTextureRef(); - } else { - ((ImageComponent3DRetained)image.retained).setTextureRef(); - } - if (image != null) { this.images[0][level] = (ImageComponentRetained)image.retained; @@ -375,17 +374,21 @@ abstract class TextureRetained extends NodeComponentRetained { final void checkImageSize(int level, ImageComponent image) { if (image != null) { - int imgHeight = ((ImageComponentRetained)image.retained).height; int imgWidth = ((ImageComponentRetained)image.retained).width; - int i, tmp = 1; - // calculate tmp = 2**level - for (i=0; i < level; i++,tmp *= 2); + int imgHeight = ((ImageComponentRetained)image.retained).height; + + int wdh = width; + int hgt = height; + for (int i = 0; i < level; i++) { + wdh >>= 1; + hgt >>= 1; + } - int hgt = height/tmp, wdh = width / tmp; - if (hgt < 1) hgt = 1; if (wdh < 1) wdh = 1; + if (hgt < 1) hgt = 1; - if ((hgt != imgHeight) || (wdh != imgWidth)) { + if ((wdh != (imgWidth - 2*boundaryWidth)) || + (hgt != (imgHeight - 2*boundaryWidth))) { throw new IllegalArgumentException( J3dI18N.getString("TextureRetained1")); } @@ -393,36 +396,31 @@ abstract class TextureRetained extends NodeComponentRetained { } final void checkSizes(ImageComponentRetained images[]) { - // check that the image at each level is w/2 h/2 of the image at the - // previous level + // Issue 172 : this method is now redundant + + // Assertion check that the image at each level is the correct size + // This shouldn't be needed since we already should have checked the + // size at each level, and verified that all levels are set. if (images != null) { - - // only need to check if there is more than 1 level - if (images.length > 1) { - int compareW = images[0].width/2; - int compareH = images[0].height/2; - int w, h; - for (int i = 1; i < images.length; i++) { - w = images[i].width; - h = images[i].height; - if (compareW < 1) compareW = 1; - if (compareH < 1) compareH = 1; - if ((w != compareW) && (h != compareH)) { - throw new IllegalArgumentException( - J3dI18N.getString("TextureRetained1")); - } - compareW = w/2; - compareH = h/2; - } - } - } + int hgt = height; + int wdh = width; + for (int level = 0; level < images.length; level++) { + int imgWidth = images[level].width; + int imgHeight = images[level].height; + + assert (wdh == (imgWidth - 2*boundaryWidth)) && + (hgt == (imgHeight - 2*boundaryWidth)); + + wdh /= 2; + hgt /= 2; + if (wdh < 1) wdh = 1; + if (hgt < 1) hgt = 1; + } + } } final void setImage(int level, ImageComponent image) { - - checkImageSize(level, image); - - initImage(level, image); + initImage(level, image); Object arg[] = new Object[3]; arg[0] = new Integer(level); @@ -438,12 +436,12 @@ abstract class TextureRetained extends NodeComponentRetained { if (image != null && level >= baseLevel && level <= maximumLevel) { ImageComponentRetained img= (ImageComponentRetained)image.retained; if (img.isByReference()) { - if (img.bImage[0] == null) { + if (img.getRefImage(0) == null) { enable = false; } } else { - if (img.imageYup == null) { + if (img.getImageData(isUseAsRaster()).get() == null) { enable = false; } } @@ -466,14 +464,8 @@ abstract class TextureRetained extends NodeComponentRetained { final void setImages(ImageComponent[] images) { int i; - ImageComponentRetained[] imagesRet = - new ImageComponentRetained[images.length]; - for (i = 0; i < images.length; i++) { - imagesRet[i] = (ImageComponentRetained)images[i].retained; - } - checkSizes(imagesRet); - initImages(images); + initImages(images); ImageComponent [] imgs = new ImageComponent[images.length]; for (i = 0; i < images.length; i++) { @@ -496,12 +488,12 @@ abstract class TextureRetained extends NodeComponentRetained { ImageComponentRetained img= (ImageComponentRetained)images[i].retained; if (img.isByReference()) { - if (img.bImage[0] == null) { + if (img.getRefImage(0) == null) { enable = false; } } else { - if (img.imageYup == null) { + if (img.getImageData(isUseAsRaster()).get() == null) { enable = false; } } @@ -629,11 +621,11 @@ abstract class TextureRetained extends NodeComponentRetained { for (int j = 0; j < numFaces && enable; j++) { for (int i = baseLevel; i <= maximumLevel && enable; i++) { if (images[j][i].isByReference()) { - if (images[j][i].bImage[0] == null) { + if (images[j][i].getRefImage(0) == null) { enable = false; } } else { - if (images[j][i].imageYup == null) { + if (images[j][i].getImageData(isUseAsRaster()).get() == null) { enable = false; } } @@ -936,13 +928,6 @@ abstract class TextureRetained extends NodeComponentRetained { void setLive(boolean backgroundGroup, int refCount) { - // check the sizes of the images - if (images != null) { - for (int j = 0; j < numFaces; j++) { - checkSizes(images[j]); - } - } - // This line should be assigned before calling doSetLive, so that // the mirror object's enable is assigned correctly! enable = userSpecifiedEnable; @@ -967,8 +952,16 @@ abstract class TextureRetained extends NodeComponentRetained { } } + // Issue 172 : assertion check the sizes of the images after we have + // checked for all mipmap levels being set + if (images != null) { + for (int j = 0; j < numFaces; j++) { + checkSizes(images[j]); + } + } + // Send a message to Rendering Attr stucture to update the resourceMask - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.TEXTURE_CHANGED; createMessage.args[0] = this; @@ -984,11 +977,11 @@ abstract class TextureRetained extends NodeComponentRetained { for (int j = 0; j < numFaces && enable; j++) { for (int i = baseLevel; i <= maximumLevel && enable; i++){ if (images[j][i].isByReference()) { - if (images[j][i].bImage[0] == null) { + if (images[j][i].getRefImage(0) == null) { enable = false; } } else { - if (images[j][i].imageYup == null) { + if (images[j][i].getImageData(isUseAsRaster()).get() == null) { enable = false; } } @@ -1017,52 +1010,69 @@ abstract class TextureRetained extends NodeComponentRetained { } } - // Simply pass along to the NodeComponents - /** - * This method updates the native context. The implementation for 2D - * texture mapping happens here. Texture3D implements its own version - * of this. + /* + * The following methods update the native context. + * The implementation for Texture2D happens here. + * Texture3D and TextureCubeMap implement their own versions. */ - native void bindTexture(long ctx, int objectId, boolean enable); - native void updateTextureFilterModes(long ctx, - int minFilter, int magFilter); + void bindTexture(Context ctx, int objectId, boolean enable) { + Pipeline.getPipeline().bindTexture2D(ctx, objectId, enable); + } - native void updateTextureLodRange(long ctx, - int baseLevel, int maximumLevel, - float minimumLod, float maximumLod); + void updateTextureBoundary(Context ctx, + int boundaryModeS, int boundaryModeT, + float boundaryRed, float boundaryGreen, + float boundaryBlue, float boundaryAlpha) { - native void updateTextureLodOffset(long ctx, - float lodOffsetX, float lodOffsetY, - float lodOffsetZ); + Pipeline.getPipeline().updateTexture2DBoundary(ctx, + boundaryModeS, boundaryModeT, + boundaryRed, boundaryGreen, + boundaryBlue, boundaryAlpha); + } + void updateTextureFilterModes(Context ctx, + int minFilter, int magFilter) { - native void updateTextureBoundary(long ctx, - int boundaryModeS, int boundaryModeT, - float boundaryRed, float boundaryGreen, - float boundaryBlue, float boundaryAlpha); + Pipeline.getPipeline().updateTexture2DFilterModes(ctx, + minFilter, magFilter); + } - native void updateTextureSharpenFunc(long ctx, - int numSharpenTextureFuncPts, - float[] sharpenTextureFuncPts); + void updateTextureSharpenFunc(Context ctx, + int numSharpenTextureFuncPts, + float[] sharpenTextureFuncPts) { - native void updateTextureFilter4Func(long ctx, - int numFilter4FuncPts, - float[] filter4FuncPts); + Pipeline.getPipeline().updateTexture2DSharpenFunc(ctx, + numSharpenTextureFuncPts, sharpenTextureFuncPts); + } - native void updateTextureAnisotropicFilter(long ctx, float degree); + void updateTextureFilter4Func(Context ctx, + int numFilter4FuncPts, + float[] filter4FuncPts) { - native void updateTextureImage(long ctx, - int numLevels, int level, - int format, int storedFormat, - int width, int height, - int boundaryWidth, byte[] data); + Pipeline.getPipeline().updateTexture2DFilter4Func(ctx, + numFilter4FuncPts, filter4FuncPts); + } - native void updateTextureSubImage(long ctx, int level, - int xoffset, int yoffset, int format, - int storedFormat, int imgXOffset, - int imgYOffset, int tileWidth, - int width, int height, byte[] data); + void updateTextureAnisotropicFilter(Context ctx, float degree) { + Pipeline.getPipeline().updateTexture2DAnisotropicFilter(ctx, degree); + } + + void updateTextureLodRange(Context ctx, + int baseLevel, int maximumLevel, + float minimumLod, float maximumLod) { + + Pipeline.getPipeline().updateTexture2DLodRange(ctx, baseLevel, maximumLevel, + minimumLod, maximumLod); + } + + void updateTextureLodOffset(Context ctx, + float lodOffsetX, float lodOffsetY, + float lodOffsetZ) { + + Pipeline.getPipeline().updateTexture2DLodOffset(ctx, + lodOffsetX, lodOffsetY, lodOffsetZ); + } // get an ID for Texture 2D @@ -1100,23 +1110,26 @@ abstract class TextureRetained extends NodeComponentRetained { * mipmapping when level 0 is not the base level */ void updateTextureDimensions(Canvas3D cv) { - updateTextureImage(cv.ctx, maxLevels, 0, - format, ImageComponentRetained.BYTE_RGBA, - width, height, boundaryWidth, null); + if(images[0][0] != null) { + updateTextureImage(cv, 0, maxLevels, 0, + format, images[0][0].getImageFormatTypeIntValue(false), + width, height, boundaryWidth, + images[0][0].getImageDataTypeIntValue(), null); + } } - + void updateTextureLOD(Canvas3D cv) { if ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_RANGE) != 0 ) { - updateTextureLodRange(cv.ctx, baseLevel, maximumLevel, - minimumLod, maximumLod); + updateTextureLodRange(cv.ctx, baseLevel, maximumLevel, + minimumLod, maximumLod); } - if ((lodOffset != null) && - ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_OFFSET) != 0)) { - updateTextureLodOffset(cv.ctx, - lodOffset.x, lodOffset.y, lodOffset.z); + if ((lodOffset != null) && + ((cv.textureExtendedFeatures & Canvas3D.TEXTURE_LOD_OFFSET) != 0)) { + updateTextureLodOffset(cv.ctx, + lodOffset.x, lodOffset.y, lodOffset.z); } } @@ -1218,38 +1231,40 @@ abstract class TextureRetained extends NodeComponentRetained { } - - // wrapper of the native call - - void updateTextureImage(Canvas3D cv, int face, - int numLevels, int level, - int format, int storedFormat, - int width, int height, - int boundaryWidth, byte[] data) { - - updateTextureImage(cv.ctx, maxLevels, level, - format, storedFormat, - width, height, boundaryWidth, data); - } - - - - // wrapper of the native call - - void updateTextureSubImage(Canvas3D cv, int face, int level, - int xoffset, int yoffset, int format, - int storedFormat, int imgXOffset, - int imgYOffset, int tileWidth, - int width, int height, byte[] data) { - - updateTextureSubImage(cv.ctx, level, - xoffset, yoffset, format, - storedFormat, imgXOffset, - imgYOffset, tileWidth, - width, height, data); + // Wrapper around the native call for 2D textures; overridden for + // Texture3D and TextureCureMap + void updateTextureImage(Canvas3D cv, + int face, int numLevels, int level, + int textureFormat, int imageFormat, + int width, int height, + int boundaryWidth, + int imageDataType, Object data) { + + Pipeline.getPipeline().updateTexture2DImage(cv.ctx, + numLevels, level, + textureFormat, imageFormat, + width, height, boundaryWidth, + imageDataType, data); + } + + // Wrapper around the native call for 2D textures; overridden for + // Texture3D and TextureCureMap + void updateTextureSubImage(Canvas3D cv, + int face, int level, + int xoffset, int yoffset, + int textureFormat, int imageFormat, + int imgXOffset, int imgYOffset, + int tilew, int width, int height, + int imageDataType, Object data) { + + Pipeline.getPipeline().updateTexture2DSubImage(cv.ctx, + level, xoffset, yoffset, + textureFormat, imageFormat, + imgXOffset, imgYOffset, + tilew, width, height, + imageDataType, data); } - - + /** * reloadTextureImage is used to load a particular level of image @@ -1257,33 +1272,31 @@ abstract class TextureRetained extends NodeComponentRetained { * BufferedImage */ void reloadTextureImage(Canvas3D cv, int face, int level, - ImageComponentRetained image, int numLevels) { - - //System.out.println("Texture.reloadTextureImage: face= " + face + " level= " + level); - - //System.out.println("...image = "+image+" image.storedFormat = "+image.storedYupFormat+" image.imageYup = "+image.imageYup+" texture - "+this); - - //System.out.println("....imageYupAllocated= " + image.imageYupAllocated); - - updateTextureImage(cv, face, numLevels, level, format, - image.storedYupFormat, - image.width, image.height, - boundaryWidth, image.imageYup); - - // Now take care of the RenderedImage case. Note, if image - // is a RenderedImage, then imageYup will be null - - if (image.imageYupClass == ImageComponentRetained.RENDERED_IMAGE) { - - // System.out.println("==========. subImage"); + ImageComponentRetained image, int numLevels) { + + boolean useAsRaster = isUseAsRaster(); + ImageComponentRetained.ImageData imageData = image.getImageData(useAsRaster); + + updateTextureImage(cv, + face, numLevels, level, + format, image.getImageFormatTypeIntValue(useAsRaster), + imageData.getWidth(), imageData.getHeight(), + boundaryWidth, image.getImageDataTypeIntValue(), + imageData.get()); + + // Now take care of the RenderedImage (byRef and yUp) case. Note, if image + // is a RenderedImage ( byRef and yUp), then imageData will be null + + if (imageData == null) { + // System.out.println("==========. subImage"); // Download all the tiles for this texture int xoffset = 0, yoffset = 0; int tmpw = image.width; int tmph = image.height; - int endXTile = image.minTileX * image.tilew + image.tileGridXOffset+image.tilew; - int endYTile = image.minTileY * image.tileh + image.tileGridYOffset+image.tileh; - int curw = (endXTile - image.minX); - int curh = (endYTile - image.minY); + int endXTile = image.tilew; + int endYTile = image.tileh; + int curw = endXTile; + int curh = endYTile; if (tmpw < curw) { curw = tmpw; @@ -1296,23 +1309,23 @@ abstract class TextureRetained extends NodeComponentRetained { int startw = curw; int imageXOffset = image.tilew - curw; int imageYOffset = image.tileh - curh; - for (int m = image.minTileY; m < image.minTileY+image.numYTiles; m++) { + for (int m = 0; m < image.numYTiles; m++) { xoffset = 0; tmpw = width; curw = startw; imageXOffset = image.tilew - curw; - for (int n = image.minTileX; - n < image.minTileX+image.numXTiles; n++) { + for (int n = 0; n < image.numXTiles; n++) { java.awt.image.Raster ras; - ras = image.bImage[0].getTile(n,m); - byte[] tmpImage = ((DataBufferByte)ras.getDataBuffer()).getData(); - updateTextureSubImage(cv, face, - level, xoffset, yoffset, format, - image.storedYupFormat, - imageXOffset, imageYOffset, - image.tilew, - curw, curh, - tmpImage); + ras = ((RenderedImage)image.getRefImage(0)).getTile(n,m); + byte[] data = ((DataBufferByte)ras.getDataBuffer()).getData(); + updateTextureSubImage(cv, face, + level, xoffset, yoffset, format, + image.getImageFormatTypeIntValue(false), + imageXOffset, imageYOffset, + image.tilew, + curw, curh, + ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY, + (Object) data); xoffset += curw; imageXOffset = 0; tmpw -= curw; @@ -1354,57 +1367,43 @@ abstract class TextureRetained extends NodeComponentRetained { // " width= " + width + " height= " + height + // " format= " + format); - - if (image.imageYupClass == ImageComponentRetained.BUFFERED_IMAGE) { - - int xoffset = x - image.minX; - int yoffset = y - image.minY; - - byte[] imageData; - if (image.imageYupAllocated) { - imageData = image.imageYup; - yoffset = image.height - yoffset - height; - - } else { - // Fix issue 132 - imageData = ((DataBufferByte) - ((BufferedImage)image.bImage[0]).getRaster().getDataBuffer()).getData(); - - // based on the yUp flag in the associated ImageComponent, - // adjust the yoffset - - if (!image.yUp) { - yoffset = image.height - yoffset - height; - } - } - - updateTextureSubImage(cv, face, level, - xoffset, yoffset, - format, image.storedYupFormat, - xoffset, yoffset, - image.width, width, height, imageData); - } else { + ImageComponentRetained.ImageData imageData = image.getImageData(isUseAsRaster()); + if(imageData != null) { + int xoffset = x; + int yoffset = y; + + // TODO Check this logic : If !yUp adjust yoffset --- Chien + if (!image.yUp) { + yoffset = image.height - yoffset - height; + } + + updateTextureSubImage(cv, face, level, + xoffset, yoffset, + format, image.getImageFormatTypeIntValue(false), + xoffset, yoffset, + image.width, width, height, + image.getImageDataTypeIntValue(), + imageData.get()); + + } else { // System.out.println("RenderedImage subImage update"); - // determine the first tile of the image float mt; - int xoff = image.tileGridXOffset; - int yoff = image.tileGridYOffset; int minTileX, minTileY; - int rx = x + image.minX; // x offset in RenderedImage - int ry = y + image.minY; // y offset in RenderedImage + int rx = x; + int ry = y; - mt = (float)(rx - xoff) / (float)image.tilew; + mt = (float)(rx) / (float)image.tilew; if (mt < 0) { minTileX = (int)(mt - 1); } else { minTileX = (int)mt; } - mt = (float)(ry - yoff) / (float)image.tileh; + mt = (float)(ry) / (float)image.tileh; if (mt < 0) { minTileY = (int)(mt - 1); } else { @@ -1413,8 +1412,8 @@ abstract class TextureRetained extends NodeComponentRetained { // determine the pixel offset of the upper-left corner of the // first tile - int startXTile = minTileX * image.tilew + xoff; - int startYTile = minTileY * image.tilew + yoff; + int startXTile = minTileX * image.tilew; + int startYTile = minTileY * image.tilew; // image dimension in the first tile @@ -1466,7 +1465,6 @@ abstract class TextureRetained extends NodeComponentRetained { } java.awt.image.Raster ras; - byte[] imageData; int textureX = x; // x offset in the texture int textureY = y; // y offset in the texture @@ -1480,14 +1478,16 @@ abstract class TextureRetained extends NodeComponentRetained { for (int xTile = minTileX; xTile < minTileX + numXTiles; xTile++) { - ras = image.bImage[0].getTile(xTile, yTile); - imageData = ((DataBufferByte)ras.getDataBuffer()).getData(); - - updateTextureSubImage(cv, face, level, - textureX, textureY, - format, image.storedYupFormat, - imgX, imgY, image.tilew, curw, curh, imageData); + ras = ((RenderedImage)image.getRefImage(0)).getTile(xTile, yTile); + byte[] data = ((DataBufferByte)ras.getDataBuffer()).getData(); + updateTextureSubImage(cv, face, level, + textureX, textureY, + format, image.getImageFormatTypeIntValue(false), + imgX, imgY, + image.tilew, curw, curh, + ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY, + (Object)data); // move to the next tile in x direction @@ -1690,7 +1690,7 @@ abstract class TextureRetained extends NodeComponentRetained { return; } - if (cv.useSharedCtx && cv.screen.renderer.sharedCtx != 0) { + if (cv.useSharedCtx && cv.screen.renderer.sharedCtx != null) { if ((resourceCreationMask & cv.screen.renderer.rendererBit) == 0) { reloadTexture = true; @@ -1845,7 +1845,7 @@ abstract class TextureRetained extends NodeComponentRetained { width, height, boundaryWidth); - mirror = (Texture2DRetained)tex.retained;; + mirror = (Texture2DRetained)tex.retained; } ((TextureRetained)mirror).objectId = -1; @@ -1950,9 +1950,9 @@ abstract class TextureRetained extends NodeComponentRetained { images[j][0].addUser(mirrorTexture); } - for (int i = 1; i < mirrorTexture.maxLevels; i++) { - mirrorTexture.images[j][i] = createNextLevelImage( - (mirrorTexture.images[j][i-1])); + for (int i = 1; i < mirrorTexture.maxLevels; i++) { + mirrorTexture.images[j][i] = + mirrorTexture.images[j][i-1].createNextLevelMipMapImage(); } } } @@ -1995,7 +1995,6 @@ abstract class TextureRetained extends NodeComponentRetained { if (info.updateMask == 0) { // this update info is done, remove it // from the update list - VirtualUniverse.mc.addFreeImageUpdateInfo(info); imageUpdateInfo[k][i].remove(j); } } @@ -2025,8 +2024,7 @@ abstract class TextureRetained extends NodeComponentRetained { imageUpdateInfo[face][level] = new ArrayList(); } - //info = mirrorTa.getFreeImageUpdateInfo(); - info = VirtualUniverse.mc.getFreeImageUpdateInfo(); + info = new ImageComponentUpdateInfo(); if (arg == null) { @@ -2045,8 +2043,6 @@ abstract class TextureRetained extends NodeComponentRetained { if (info.entireImage) { // the entire image update supercedes all the subimage update; // hence, remove all the existing updates from the list - VirtualUniverse.mc.addFreeImageUpdateInfo( - imageUpdateInfo[face][level]); imageUpdateInfo[face][level].clear(); // reset the update prune mask for this level @@ -2308,8 +2304,6 @@ abstract class TextureRetained extends NodeComponentRetained { for (int face = 0; face < numFaces; face++) { for (int level = 0; level < maxLevels; level++) { if (imageUpdateInfo[face][level] != null) { - VirtualUniverse.mc.addFreeImageUpdateInfo( - imageUpdateInfo[face][level]); imageUpdateInfo[face][level].clear(); } } @@ -2358,110 +2352,6 @@ abstract class TextureRetained extends NodeComponentRetained { resourceCreationMask = 0x0; } - final ImageComponentRetained createNextLevelImage( - ImageComponentRetained oImage) { - - int xScale, yScale, nWidth, nHeight; - ImageComponentRetained nImage = null; - - if (oImage.width > 1) { - nWidth = oImage.width >> 1; - xScale = 2; - } else { - nWidth = 1; - xScale = 1; - } - if (oImage.height > 1) { - nHeight = oImage.height >> 1; - yScale = 2; - } else { - nHeight = 1; - yScale = 1; - } - - int bytesPerPixel = oImage.bytesPerYupPixelStored; - - if (oImage instanceof ImageComponent2DRetained) { - - nImage = new ImageComponent2DRetained(); - nImage.processParams(oImage.format, nWidth, nHeight, 1); - nImage.imageYup = new byte[nWidth * nHeight * bytesPerPixel]; - nImage.storedYupFormat = nImage.internalFormat; - nImage.bytesPerYupPixelStored = bytesPerPixel; - scaleImage(nWidth, nHeight, xScale, yScale, oImage.width, 0, 0, - bytesPerPixel, nImage.imageYup, oImage.imageYup); - - } else { //oImage instanceof ImageComponent3DRetained - - int depth = ((ImageComponent3DRetained)oImage).depth; - nImage = new ImageComponent3DRetained(); - nImage.processParams(oImage.format, nWidth, nHeight, depth); - nImage.imageYup = new byte[nWidth * nHeight * bytesPerPixel]; - nImage.storedYupFormat = nImage.internalFormat; - nImage.bytesPerYupPixelStored = bytesPerPixel; - - for (int i = 0; i < depth; i++) { - scaleImage(nWidth, nHeight, xScale, yScale, oImage.width, - i * nWidth * nHeight * bytesPerPixel, - i * oImage.width * oImage.height * bytesPerPixel, - bytesPerPixel, nImage.imageYup, oImage.imageYup); - } - } - return nImage; - } - - final void scaleImage(int nWidth, int nHeight, int xScale, int yScale, - int oWidth, int nStart, int oStart, int bytesPerPixel, - byte[] nData, byte[] oData) { - - int nOffset = 0; - int oOffset = 0; - int oLineIncr = bytesPerPixel * oWidth; - int oPixelIncr = bytesPerPixel << 1; - - if (yScale == 1) { - for (int x = 0; x < nWidth; x++) { - for (int k = 0; k < bytesPerPixel; k++) { - nData[nStart + nOffset + k] = (byte) - (((int)(oData[oStart + oOffset + k] & 0xff) + - (int)(oData[oStart + oOffset + k - + bytesPerPixel] & 0xff) + 1) >> 1); - } - nOffset += bytesPerPixel; - oOffset += oPixelIncr; - } - } else if (xScale == 1) { - for (int y = 0; y < nHeight; y++) { - for (int k = 0; k < bytesPerPixel; k++) { - nData[nStart + nOffset + k] = (byte) - (((int)(oData[oStart + oOffset + k] & 0xff) + - (int)(oData[oStart + oOffset + k - + oLineIncr] & 0xff) + 1) >> 1); - } - nOffset += bytesPerPixel; - oOffset += oLineIncr; - } - } else { - for (int y = 0; y < nHeight; y++) { - for (int x = 0; x < nWidth; x++) { - for (int k = 0; k < bytesPerPixel; k++) { - nData[nStart + nOffset + k] = (byte) - (((int)(oData[oStart + oOffset + k] & 0xff) + - (int)(oData[oStart + oOffset + k - + bytesPerPixel] & 0xff) + - (int)(oData[oStart + oOffset + k - + oLineIncr] & 0xff) + - (int)(oData[oStart + oOffset + k + oLineIncr + - + bytesPerPixel] & 0xff) + 2) >> 2); - } - nOffset += bytesPerPixel; - oOffset += oPixelIncr; - } - oOffset += oLineIncr; - } - } - } - void incTextureBinRefCount(TextureBin tb) { ImageComponentRetained image; @@ -2523,7 +2413,7 @@ abstract class TextureRetained extends NodeComponentRetained { // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) - J3dMessage createMessage = VirtualUniverse.mc.getMessage(); + J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.TEXTURE_CHANGED; createMessage.universe = null; @@ -2535,7 +2425,7 @@ abstract class TextureRetained extends NodeComponentRetained { // System.out.println("univList.size is " + univList.size()); for(int i=0; i 0) { - // memory not yet free - // send a message to the request renderer - synchronized (VirtualUniverse.mc.contextCreationLock) { - boolean found = false; - - for (Enumeration e = Screen3D.deviceRendererMap.elements(); - e.hasMoreElements(); ) { - Renderer rdr = (Renderer) e.nextElement(); - J3dMessage renderMessage = VirtualUniverse.mc.getMessage(); - renderMessage.threads = J3dThread.RENDER_THREAD; - renderMessage.type = J3dMessage.RENDER_IMMEDIATE; - renderMessage.universe = null; - renderMessage.view = null; - renderMessage.args[0] = null; - renderMessage.args[1] = new Integer(objectId); - renderMessage.args[2] = "2D"; - rdr.rendererStructure.addMessage(renderMessage); - } - objectId = -1; - } - - VirtualUniverse.mc.setWorkForRequestRenderer(); - } - - } - void handleFrequencyChange(int bit) { switch (bit) { case Texture.ALLOW_ENABLE_WRITE: @@ -2594,5 +2455,13 @@ abstract class TextureRetained extends NodeComponentRetained { break; } } -} + + void setUseAsRaster(boolean useAsRaster) { + this.useAsRaster = useAsRaster; + } + + boolean isUseAsRaster() { + return this.useAsRaster; + } +} diff --git a/src/classes/share/javax/media/j3d/TextureUnitState.java b/src/classes/share/javax/media/j3d/TextureUnitState.java index ced1e88..162a301 100644 --- a/src/classes/share/javax/media/j3d/TextureUnitState.java +++ b/src/classes/share/javax/media/j3d/TextureUnitState.java @@ -126,6 +126,15 @@ public class TextureUnitState extends NodeComponent { * texture attributes * @param texCoordGeneration object that specifies the texture coordinate * generation parameters + * + * @exception IllegalSharingException if this TextureUnitState is live and + * the specified texture refers to an ImageComponent2D that is being used + * by a Canvas3D as an off-screen buffer. + * + * @exception IllegalSharingException if this TextureUnitState is + * being used by an immediate mode context and + * the specified texture refers to an ImageComponent2D that is being used + * by a Canvas3D as an off-screen buffer. */ public void set(Texture texture, TextureAttributes textureAttributes, @@ -135,6 +144,17 @@ public class TextureUnitState extends NodeComponent { if (!this.getCapability(ALLOW_STATE_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("TextureUnitState0")); + // Do illegal sharing check + if(texture != null) { + TextureRetained texRetained = (TextureRetained)texture.retained; + ImageComponent[] images = texRetained.getImages(); + if(images != null) { + for(int i=0; i -EPSILON_ABSOLUTE)); } @@ -576,17 +599,6 @@ public class Transform3D { } } - // Fix for Issue 167 -- don't classify matrices with Infinity or NaN values - // as affine - private final boolean isInfOrNaN() { - for (int i = 0; i < 16; i++) { - if (Double.isNaN(mat[i]) || Double.isInfinite(mat[i])) { - return true; - } - } - return false; - } - private final void classifyAffine() { if (!isInfOrNaN() && almostZero(mat[12]) && @@ -774,7 +786,7 @@ public class Transform3D { mat[i] += t1.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -792,7 +804,7 @@ public class Transform3D { mat[i] = t1.mat[i] + t2.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -810,7 +822,7 @@ public class Transform3D { mat[i] -= t1.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -829,7 +841,7 @@ public class Transform3D { mat[i] = t1.mat[i] - t2.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -868,7 +880,7 @@ public class Transform3D { mat[14] = mat[11]; mat[11] = temp; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -900,7 +912,7 @@ public class Transform3D { mat[14] = t1.mat[11]; mat[15] = t1.mat[15]; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -940,6 +952,11 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(q1)) { + dirtyBits = ALL_DIRTY; + return; + } dirtyBits = CLASSIFY_BIT | SCALE_BIT | ROTATION_BIT; type = RIGID | CONGRUENT | AFFINE | ORTHO; @@ -974,6 +991,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(q1)) { + dirtyBits = ALL_DIRTY; + return; + } + dirtyBits = CLASSIFY_BIT | SCALE_BIT | ROTATION_BIT; type = RIGID | CONGRUENT | AFFINE | ORTHO; } @@ -1002,11 +1025,8 @@ public class Transform3D { mat[9] = m1.m21*scales[1]; mat[10]= m1.m22*scales[2]; - // only affine bit is preserved - // SCALE_BIT is clear in the above computeScales() so - // there is no need to set it dirty again. - dirtyBits |= (RIGID_BIT | CONGRUENT_BIT| ORTHO_BIT| - CLASSIFY_BIT | ROTSCALESVD_DIRTY); + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { // the matrix pass in may not normalize @@ -1038,8 +1058,8 @@ public class Transform3D { mat[9] = m1.m21*scales[1]; mat[10]= m1.m22*scales[2]; - dirtyBits |= (RIGID_BIT | CONGRUENT_BIT| ORTHO_BIT| - CLASSIFY_BIT | ROTSCALESVD_DIRTY); + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1072,7 +1092,13 @@ public class Transform3D { mat[6] = (2.0*(q1.y*q1.z - q1.w*q1.x))*scales[2]; mat[10] = (1.0 - 2.0*q1.x*q1.x - 2.0*q1.y*q1.y)*scales[2]; - dirtyBits |= CLASSIFY_BIT | ROTATION_BIT; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(q1)) { + dirtyBits = ALL_DIRTY; + return; + } + + dirtyBits |= CLASSIFY_BIT | ROTATION_BIT; dirtyBits &= ~ORTHO_BIT; type |= ORTHO; type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); @@ -1104,10 +1130,16 @@ public class Transform3D { mat[6] = (2.0*(q1.y*q1.z - q1.w*q1.x))*scales[2]; mat[10] = (1.0 - 2.0*q1.x*q1.x - 2.0*q1.y*q1.y)*scales[2]; - dirtyBits |= CLASSIFY_BIT | ROTATION_BIT; - dirtyBits &= ~ORTHO_BIT; - type |= ORTHO; - type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(q1)) { + dirtyBits = ALL_DIRTY; + return; + } + + dirtyBits |= CLASSIFY_BIT | ROTATION_BIT; + dirtyBits &= ~ORTHO_BIT; + type |= ORTHO; + type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); } @@ -1157,7 +1189,13 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = CONGRUENT | AFFINE | RIGID | ORTHO; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(a1)) { + dirtyBits = ALL_DIRTY; + return; + } + + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } } @@ -1209,6 +1247,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(a1)) { + dirtyBits = ALL_DIRTY; + return; + } + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } @@ -1267,6 +1311,11 @@ public class Transform3D { mat[10] = (t * az * az + cosTheta)*scales[2]; } + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(a1)) { + dirtyBits = ALL_DIRTY; + return; + } // Rigid remain rigid, congruent remain congruent after // set rotation @@ -1329,6 +1378,11 @@ public class Transform3D { mat[10] = (t * az * az + cosTheta)*scales[2]; } + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(a1)) { + dirtyBits = ALL_DIRTY; + return; + } // Rigid remain rigid, congruent remain congruent after // set rotation @@ -1369,6 +1423,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(angle)) { + dirtyBits = ALL_DIRTY; + return; + } + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } @@ -1403,6 +1463,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(angle)) { + dirtyBits = ALL_DIRTY; + return; + } + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } @@ -1438,6 +1504,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(angle)) { + dirtyBits = ALL_DIRTY; + return; + } + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } @@ -1455,6 +1527,12 @@ public class Transform3D { mat[8] = 0.0; mat[9] = 0.0; mat[10] = 1.0; mat[11] = trans.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(trans)) { + dirtyBits = ALL_DIRTY; + return; + } + type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } @@ -1471,6 +1549,11 @@ public class Transform3D { mat[8] = 0.0; mat[9] = 0.0; mat[10] = 1.0; mat[11] = trans.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(trans)) { + dirtyBits = ALL_DIRTY; + return; + } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; @@ -1498,6 +1581,12 @@ public class Transform3D { mat[9] = rot[7]*scale; mat[10] = rot[8]*scale; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(scale)) { + dirtyBits = ALL_DIRTY; + return; + } + dirtyBits |= (CLASSIFY_BIT | RIGID_BIT | CONGRUENT_BIT | SVD_BIT); dirtyBits &= ~SCALE_BIT; } @@ -1528,6 +1617,13 @@ public class Transform3D { mat[8] = rot[6]*scale.x; mat[9] = rot[7]*scale.y; mat[10] = rot[8]*scale.z; + + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(scale)) { + dirtyBits = ALL_DIRTY; + return; + } + dirtyBits |= (CLASSIFY_BIT | RIGID_BIT | CONGRUENT_BIT | SVD_BIT); dirtyBits &= ~SCALE_BIT; } @@ -1568,9 +1664,8 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = AFFINE | ORTHO; - dirtyBits = CLASSIFY_BIT | CONGRUENT_BIT | RIGID_BIT | - ROTATION_BIT; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } /** @@ -1583,6 +1678,13 @@ public class Transform3D { mat[3] = trans.x; mat[7] = trans.y; mat[11] = trans.z; + + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(trans)) { + dirtyBits = ALL_DIRTY; + return; + } + // Only preserve CONGRUENT, RIGID, ORTHO type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); dirtyBits |= CLASSIFY_BIT; @@ -1599,6 +1701,13 @@ public class Transform3D { mat[3] = trans.x; mat[7] = trans.y; mat[11] = trans.z; + + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(trans)) { + dirtyBits = ALL_DIRTY; + return; + } + type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); dirtyBits |= CLASSIFY_BIT; } @@ -1636,8 +1745,9 @@ public class Transform3D { mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; - type = CONGRUENT | AFFINE | ORTHO; - dirtyBits = CLASSIFY_BIT | ROTATION_BIT | RIGID_BIT; + + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } /** @@ -1673,8 +1783,8 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = CONGRUENT | AFFINE | ORTHO; - dirtyBits = CLASSIFY_BIT | ROTATION_BIT| RIGID_BIT; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } /** @@ -1710,8 +1820,8 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = CONGRUENT | AFFINE | ORTHO; - dirtyBits = CLASSIFY_BIT | ROTATION_BIT | RIGID_BIT; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } /** @@ -1742,9 +1852,8 @@ public class Transform3D { mat[14]=0.0; mat[15]=1.0; - type = AFFINE; - dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { // input matrix may not normalize @@ -1780,9 +1889,8 @@ public class Transform3D { mat[14]=0.0; mat[15]=1.0; - type = AFFINE; - dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1817,9 +1925,8 @@ public class Transform3D { mat[14]=0.0; mat[15]=1.0; - type = AFFINE; - dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1849,7 +1956,7 @@ public class Transform3D { } } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1920,7 +2027,7 @@ public class Transform3D { mat[14] = matrix[14]; mat[15] = matrix[15]; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1952,7 +2059,7 @@ public class Transform3D { mat[14] = matrix[14]; mat[15] = matrix[15]; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -1984,7 +2091,7 @@ public class Transform3D { mat[14] = m1.m32; mat[15] = m1.m33; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -2016,7 +2123,7 @@ public class Transform3D { mat[14] = m1.m32; mat[15] = m1.m33; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -2049,9 +2156,8 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = AFFINE; - dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -2084,9 +2190,8 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; - type = AFFINE; - dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -2139,6 +2244,12 @@ public class Transform3D { mat[14] = 0.0; mat[15] = 1.0; + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(euler)) { + dirtyBits = ALL_DIRTY; + return; + } + type = AFFINE | CONGRUENT | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | SCALE_BIT | ROTATION_BIT; } @@ -2968,7 +3079,7 @@ public class Transform3D { luBacksubstitution(tmp, row_perm, this.mat); type = 0; - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; } @@ -3314,6 +3425,12 @@ public class Transform3D { scales = new double[3]; scales[0] = scales[1] = scales[2] = scale; + + // Issue 253: set all dirty bits if input is infinity or NaN + if (isInfOrNaN(x) || isInfOrNaN(y) || isInfOrNaN(z) || isInfOrNaN(scale)) { + dirtyBits = ALL_DIRTY; + return; + } type = AFFINE | CONGRUENT | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | RIGID_BIT; @@ -3329,7 +3446,7 @@ public class Transform3D { for (int i=0 ; i<16 ; i++) { mat[i] *= scalar; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; } /** @@ -3342,7 +3459,7 @@ public class Transform3D { for (int i=0 ; i<16 ; i++) { mat[i] = t1.mat[i] * scalar; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -3465,7 +3582,7 @@ public class Transform3D { dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | CLASSIFY_BIT | ROTSCALESVD_DIRTY; } else { - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; } } @@ -3668,7 +3785,7 @@ public class Transform3D { dirtyBits = ORTHO_BIT | CONGRUENT_BIT | RIGID_BIT | CLASSIFY_BIT | ROTSCALESVD_DIRTY; } else { - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; } } @@ -3683,11 +3800,10 @@ public class Transform3D { * @param t1 the matrix whose inverse is computed. */ public final void mulInverse(Transform3D t1) { - Transform3D t2 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t2 = new Transform3D(); t2.autoNormalize = false; t2.invert(t1); this.mul(t2); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t2); } @@ -3698,11 +3814,10 @@ public class Transform3D { * @param t2 the transform whose inverse is computed. */ public final void mulInverse(Transform3D t1, Transform3D t2) { - Transform3D t3 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t3 = new Transform3D(); t3.autoNormalize = false; t3.invert(t2); this.mul(t1,t3); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t3); } /** @@ -3712,11 +3827,10 @@ public class Transform3D { * @param t2 the transform whose transpose is computed */ public final void mulTransposeRight(Transform3D t1, Transform3D t2) { - Transform3D t3 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t3 = new Transform3D(); t3.autoNormalize = false; t3.transpose(t2); mul(t1, t3); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t3); } @@ -3727,11 +3841,10 @@ public class Transform3D { * @param t2 the transform on the right hand side of the multiplication */ public final void mulTransposeLeft(Transform3D t1, Transform3D t2){ - Transform3D t3 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t3 = new Transform3D(); t3.autoNormalize = false; t3.transpose(t1); mul(t3, t2); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t3); } @@ -3743,15 +3856,13 @@ public class Transform3D { * @param t2 the transform on the right hand side of the multiplication */ public final void mulTransposeBoth(Transform3D t1, Transform3D t2) { - Transform3D t3 = VirtualUniverse.mc.getTransform3D(null); - Transform3D t4 = VirtualUniverse.mc.getTransform3D(null); + Transform3D t3 = new Transform3D(); + Transform3D t4 = new Transform3D(); t3.autoNormalize = false; t4.autoNormalize = false; t3.transpose(t1); t4.transpose(t2); mul(t3, t4); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t3); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t4); } @@ -3765,6 +3876,10 @@ public class Transform3D { * Note that the scale of the matrix is not altered by this method. */ public final void normalize() { + // Issue 253: Unable to normalize matrices with infinity or NaN + if (!isAffine() && isInfOrNaN()) { + return; + } if ((dirtyBits & (ROTATION_BIT|SVD_BIT)) != 0) { computeScaleRotation(true); @@ -3813,6 +3928,11 @@ public class Transform3D { * Note that the scale of the matrix is not altered by this method. */ public final void normalizeCP() { + // Issue 253: Unable to normalize matrices with infinity or NaN + if (!isAffine() && isInfOrNaN()) { + return; + } + if ((dirtyBits & SCALE_BIT) != 0) { computeScales(false); } @@ -4189,9 +4309,9 @@ public class Transform3D { mat[4] = m1.m10; mat[5] = m1.m11; mat[6] = m1.m12; mat[8] = m1.m20; mat[9] = m1.m21; mat[10] = m1.m22; - // keep affine bit - dirtyBits |= (RIGID_BIT | CONGRUENT_BIT | ORTHO_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY); + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; + if (autoNormalize) { normalize(); } @@ -4208,9 +4328,10 @@ public class Transform3D { mat[4] = m1.m10; mat[5] = m1.m11; mat[6] = m1.m12; mat[8] = m1.m20; mat[9] = m1.m21; mat[10] = m1.m22; - dirtyBits |= (RIGID_BIT | CONGRUENT_BIT | ORTHO_BIT | - CLASSIFY_BIT | ROTSCALESVD_DIRTY); - if (autoNormalize) { + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; + + if (autoNormalize) { normalize(); } } @@ -4227,7 +4348,7 @@ public class Transform3D { mat[i] = s*t1.mat[i] + t2.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -4246,7 +4367,7 @@ public class Transform3D { mat[i] = s*mat[i] + t1.mat[i]; } - dirtyBits = CLASSIFY_ALL_DIRTY | ROTSCALESVD_DIRTY; + dirtyBits = ALL_DIRTY; if (autoNormalize) { normalize(); @@ -4354,8 +4475,8 @@ public class Transform3D { mat[12] = mat[13] = mat[14] = 0; mat[15] = 1; - type = AFFINE | CONGRUENT | RIGID | ORTHO; - dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } @@ -4407,7 +4528,8 @@ public class Transform3D { // Matrix is a projection transform type = 0; - dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } @@ -4454,7 +4576,8 @@ public class Transform3D { // Matrix is a projection transform type = 0; - dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } @@ -4497,10 +4620,9 @@ public class Transform3D { mat[1] = mat[2] = mat[4] = mat[6] = mat[8] = mat[9] = mat[12] = mat[13] = mat[14] = 0; mat[15] = 1; - // Matrix is a projection transform - type = AFFINE; - dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY | CONGRUENT_BIT | - RIGID_BIT | ORTHO_BIT; + + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; } /** @@ -5641,18 +5763,72 @@ public class Transform3D { t.mat[9] = rot[7]; t.mat[10] = rot[8]; - t.type = ORTHOGONAL | RIGID | CONGRUENT| AFFINE | ORTHO; - if ((dirtyBits & SVD_BIT) != 0) { - t.dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY; - } else { - t.dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; - } + // Issue 253: set all dirty bits + t.dirtyBits = ALL_DIRTY; } // somehow CanvasViewCache will directly modify mat[] // instead of calling ortho(). So we need to reset dirty bit final void setOrthoDirtyBit() { - dirtyBits = CLASSIFY_BIT | ROTSCALESVD_DIRTY; + // Issue 253: set all dirty bits + dirtyBits = ALL_DIRTY; type = 0; } + + // Fix for Issue 167 -- don't classify matrices with Infinity or NaN values + // as affine + private final boolean isInfOrNaN() { + for (int i = 0; i < 16; i++) { + if (Double.isNaN(mat[i]) || Double.isInfinite(mat[i])) { + return true; + } + } + return false; + } + + // Fix for Issue 253 + // Methods to check input parameters for Infinity or NaN values + private final boolean isInfOrNaN(Quat4f q) { + return (Float.isNaN(q.x) || Float.isInfinite(q.x) || + Float.isNaN(q.y) || Float.isInfinite(q.y) || + Float.isNaN(q.z) || Float.isInfinite(q.z) || + Float.isNaN(q.w) || Float.isInfinite(q.w)); + } + + private boolean isInfOrNaN(Quat4d q) { + return (Double.isNaN(q.x) || Double.isInfinite(q.x) || + Double.isNaN(q.y) || Double.isInfinite(q.y) || + Double.isNaN(q.z) || Double.isInfinite(q.z) || + Double.isNaN(q.w) || Double.isInfinite(q.w)); + } + + private boolean isInfOrNaN(AxisAngle4f a) { + return (Float.isNaN(a.x) || Float.isInfinite(a.x) || + Float.isNaN(a.y) || Float.isInfinite(a.y) || + Float.isNaN(a.z) || Float.isInfinite(a.z) || + Float.isNaN(a.angle) || Float.isInfinite(a.angle)); + } + + private boolean isInfOrNaN(AxisAngle4d a) { + return (Double.isNaN(a.x) || Double.isInfinite(a.x) || + Double.isNaN(a.y) || Double.isInfinite(a.y) || + Double.isNaN(a.z) || Double.isInfinite(a.z) || + Double.isNaN(a.angle) || Double.isInfinite(a.angle)); + } + + private boolean isInfOrNaN(double val) { + return Double.isNaN(val) || Double.isInfinite(val); + } + + private boolean isInfOrNaN(Vector3f v) { + return (Float.isNaN(v.x) || Float.isInfinite(v.x) || + Float.isNaN(v.y) || Float.isInfinite(v.y) || + Float.isNaN(v.z) || Float.isInfinite(v.z)); + } + + private boolean isInfOrNaN(Vector3d v) { + return (Double.isNaN(v.x) || Double.isInfinite(v.x) || + Double.isNaN(v.y) || Double.isInfinite(v.y) || + Double.isNaN(v.z) || Double.isInfinite(v.z)); + } } diff --git a/src/classes/share/javax/media/j3d/TransformGroup.java b/src/classes/share/javax/media/j3d/TransformGroup.java index 9290c03..6bf078c 100644 --- a/src/classes/share/javax/media/j3d/TransformGroup.java +++ b/src/classes/share/javax/media/j3d/TransformGroup.java @@ -182,9 +182,8 @@ public class TransformGroup extends Group { void duplicateAttributes(Node originalNode, boolean forceDuplicate) { super.duplicateAttributes(originalNode, forceDuplicate); - Transform3D t = VirtualUniverse.mc.getTransform3D(null); + Transform3D t = new Transform3D(); ((TransformGroupRetained) originalNode.retained).getTransform(t); ((TransformGroupRetained) retained).setTransform(t); - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, t); } } diff --git a/src/classes/share/javax/media/j3d/TransformGroupRetained.java b/src/classes/share/javax/media/j3d/TransformGroupRetained.java index 7ede29f..bca8aa4 100644 --- a/src/classes/share/javax/media/j3d/TransformGroupRetained.java +++ b/src/classes/share/javax/media/j3d/TransformGroupRetained.java @@ -117,13 +117,13 @@ class TransformGroupRetained extends GroupRetained implements TargetsInterface // this writeable transformGroup has a static transform // merged into this node - trans = VirtualUniverse.mc.getTransform3D(staticTransform.transform); + trans = new Transform3D(staticTransform.transform); trans.mul(t1); transform.setWithLock(trans); } else { - trans = VirtualUniverse.mc.getTransform3D(t1); + trans = new Transform3D(t1); transform.setWithLock(t1); } @@ -137,7 +137,7 @@ class TransformGroupRetained extends GroupRetained implements TargetsInterface throw new BadTransformException(J3dI18N.getString("ViewPlatformRetained0")); } - tchangeMessage = VirtualUniverse.mc.getMessage(); + tchangeMessage = new J3dMessage(); tchangeMessage.type = J3dMessage.TRANSFORM_CHANGED; tchangeMessage.threads = targetThreads; tchangeMessage.args[1] = this; @@ -534,7 +534,7 @@ class TransformGroupRetained extends GroupRetained implements TargetsInterface // This is needed b/c super.setlive is called after inSharedGroup check. inSharedGroup = s.inSharedGroup; - trans = VirtualUniverse.mc.getTransform3D(null); + trans = new Transform3D(); transform.getWithLock(trans); currentTransform.set(trans); diff --git a/src/classes/share/javax/media/j3d/TransformStructure.java b/src/classes/share/javax/media/j3d/TransformStructure.java index 5c16942..8320a6c 100644 --- a/src/classes/share/javax/media/j3d/TransformStructure.java +++ b/src/classes/share/javax/media/j3d/TransformStructure.java @@ -216,8 +216,6 @@ class TransformStructure extends J3dStructure implements ObjectUpdate { for (i=0; iVIRTUAL_EYE - specifies that the associated distance is from * the eye and in units of virtual distance.
  • *

  • PHYSICAL_EYE - specifies that the associated distance is from - * the eye and in units of physical distance (in meters).
  • + * the eye and in units of physical distance (in meters). + * This is the default policy for both front and back clipping.

    *

  • VIRTUAL_SCREEN - specifies that the associated distance is * from the screen and in units of virtual distance.
  • *

  • PHYSICAL_SCREEN - specifies that the associated distance is * from the screen and in units of physical distance (in meters). - * This is the default policy for both front and back clipping.
  • + *

    * *

  • Visibility policy - specifies how visible and invisible objects * are drawn. There are three visibility policies:
  • @@ -491,6 +490,7 @@ public class View extends Object { * from the eye in meters. * Policy for interpreting clip plane distances. * Used in specifying the policy in frontClipPolicy and backClipPolicy. + * This is the default policy for both front and back clipping. * @see #setFrontClipPolicy * @see #setBackClipPolicy */ @@ -722,8 +722,8 @@ public class View extends Object { // Support dynamic video resize -- DVR. Viewer viewer = null; // Cached the associate viewer of this view. boolean firstTime = true; - float dvrFactor = 1.0f; - boolean dvrResizeCompensation = true; +// float dvrFactor = 1.0f; +// boolean dvrResizeCompensation = true; // User adjustable minimum frame cycle time long minFrameCycleTime; @@ -982,7 +982,6 @@ public class View extends Object { private Canvas3D[][] cachedCanvasList; private Canvas3D[] cachedCanvases; - private Canvas3D[] cachedOffScreenCanvases; private Screen3D[] cachedScreens; private int longestScreenList = 0; private boolean canvasesDirty = true; @@ -1912,7 +1911,7 @@ public class View extends Object { if (activeStatus && isRunning) { - J3dMessage vpMessage = VirtualUniverse.mc.getMessage(); + J3dMessage vpMessage = new J3dMessage(); vpMessage.universe = universe; vpMessage.view = this; vpMessage.type = J3dMessage.UPDATE_VIEW; @@ -1973,7 +1972,7 @@ public class View extends Object { transparencySortingPolicy = policy; if (activeStatus && isRunning) { - J3dMessage vpMessage = VirtualUniverse.mc.getMessage(); + J3dMessage vpMessage = new J3dMessage(); vpMessage.universe = universe; vpMessage.view = this; vpMessage.type = J3dMessage.UPDATE_VIEW; @@ -2416,22 +2415,14 @@ public class View extends Object { synchronized (canvasList) { ArrayList cv; int len = canvases.size(); - int numOffScreenCanvases = 0; Canvas3D newCachedCanvases[] = new Canvas3D[len]; for (int i=0; i < len; i++) { newCachedCanvases[i] = (Canvas3D) canvases.get(i); - if (newCachedCanvases[i].offScreen) - numOffScreenCanvases++; } // Do this in one instruction so there is no need to // synchronized getCanvases() - if (numOffScreenCanvases > 0) { - cachedOffScreenCanvases = new Canvas3D[numOffScreenCanvases]; - numOffScreenCanvases = 0; - } - cachedCanvases = newCachedCanvases; len = 0; longestScreenList = 0; @@ -2444,13 +2435,6 @@ public class View extends Object { cachedCanvasList[i][j] = (Canvas3D) cv.get(j); } - if (cachedCanvasList[i][0].offScreen) { - for (int j = 0; j < len; j++) { - cachedOffScreenCanvases[numOffScreenCanvases++]= - cachedCanvasList[i][j]; - } - } - if (len > longestScreenList) { longestScreenList = len; } @@ -2491,10 +2475,6 @@ public class View extends Object { return cachedCanvases; } - Canvas3D[] getOffScreenCanvases() { - return cachedOffScreenCanvases; - } - // assume getCanvasList is called before Screen3D[] getScreens() { return cachedScreens; @@ -3089,7 +3069,10 @@ public class View extends Object { final void updateViewCache() { - // DVR support + // TODO KCR : remove obsolete DVR code (but make sure we don't end + // up with a leak in the Viewer Map object). + + // DVR support // This is a back door in j3d to provide DVR support. // A better place to put this code segment is in // ViewCache.snapshot(). Since it consists of some @@ -3104,24 +3087,24 @@ public class View extends Object { firstTime = false; } - if(viewer != null) { - if(viewer.isDvrEnabled()) { - dvrFactor = viewer.getDvrFactor(); - dvrResizeCompensation = - viewer.getDvrResizeCompensationEnable(); - /* - System.out.println("View : dvrFactor is " + dvrFactor); - System.out.println("View : dvrResizeCompensation is " + - dvrResizeCompensation); - */ - } - else { - // Reset back to default. - dvrFactor = 1.0f; - dvrResizeCompensation = true; - - } - } +// if(viewer != null) { +// if(viewer.isDvrEnabled()) { +// dvrFactor = viewer.getDvrFactor(); +// dvrResizeCompensation = +// viewer.getDvrResizeCompensationEnable(); +// /* +// System.out.println("View : dvrFactor is " + dvrFactor); +// System.out.println("View : dvrResizeCompensation is " + +// dvrResizeCompensation); +// */ +// } +// else { +// // Reset back to default. +// dvrFactor = 1.0f; +// dvrResizeCompensation = true; +// +// } +// } // End of back door -- DVR. synchronized(this) { @@ -3286,7 +3269,7 @@ public class View extends Object { soundScheduler.reset(); } - J3dMessage vpMessage = VirtualUniverse.mc.getMessage(); + J3dMessage vpMessage = new J3dMessage(); vpMessage.universe = universe; vpMessage.view = this; vpMessage.type = J3dMessage.UPDATE_VIEW; @@ -3325,7 +3308,7 @@ public class View extends Object { } - J3dMessage vpMessage = VirtualUniverse.mc.getMessage(); + J3dMessage vpMessage = new J3dMessage(); vpMessage.universe = universe; vpMessage.view = this; vpMessage.type = J3dMessage.UPDATE_VIEW; diff --git a/src/classes/share/javax/media/j3d/ViewPlatformRetained.java b/src/classes/share/javax/media/j3d/ViewPlatformRetained.java index d80341b..b9756e4 100644 --- a/src/classes/share/javax/media/j3d/ViewPlatformRetained.java +++ b/src/classes/share/javax/media/j3d/ViewPlatformRetained.java @@ -141,7 +141,7 @@ class ViewPlatformRetained extends LeafRetained { } // Notify behavior scheduler & RenderBin if (source.isLive()) { - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.UPDATE_VIEWPLATFORM; message.threads = J3dThread.UPDATE_RENDER|J3dThread.UPDATE_BEHAVIOR; message.universe = universe; @@ -184,7 +184,7 @@ class ViewPlatformRetained extends LeafRetained { Transform3D getVworldToVpc() { if (vworldToVpc == null) - vworldToVpc = VirtualUniverse.mc.getTransform3D(null); + vworldToVpc = new Transform3D(); vworldToVpc.set(getCurrentLocalToVworld(null)); vworldToVpc.invert(); return vworldToVpc; @@ -197,10 +197,6 @@ class ViewPlatformRetained extends LeafRetained { void evaluateViewPlatformTransform() { - if (vworldToVpc != null) { - FreeListManager.freeObject(FreeListManager.TRANSFORM3D, - vworldToVpc); - } // clear cache so that next time getVworldToVpc() can recompute vworldToVpc = null; } diff --git a/src/classes/share/javax/media/j3d/ViewSpecificGroupRetained.java b/src/classes/share/javax/media/j3d/ViewSpecificGroupRetained.java index 113e4d8..5f6b963 100644 --- a/src/classes/share/javax/media/j3d/ViewSpecificGroupRetained.java +++ b/src/classes/share/javax/media/j3d/ViewSpecificGroupRetained.java @@ -78,7 +78,7 @@ class ViewSpecificGroupRetained extends GroupRetained { objAry[3] = super.processViewSpecificInfo(ADD_VIEW, (HashKey)key, view, addVsgList, addKeyList, addLeafList); - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -120,7 +120,7 @@ class ViewSpecificGroupRetained extends GroupRetained { } */ - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -184,7 +184,7 @@ class ViewSpecificGroupRetained extends GroupRetained { objAry[3] = super.processViewSpecificInfo(ADD_VIEW, (HashKey)key, view, addVsgList, addKeyList, addLeafList); } - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -230,7 +230,7 @@ class ViewSpecificGroupRetained extends GroupRetained { objAry[3] = super.processViewSpecificInfo(ADD_VIEW, (HashKey)tempKey, view, addVsgList, addKeyList, addLeafList); } - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -337,7 +337,7 @@ class ViewSpecificGroupRetained extends GroupRetained { objAry[3] = super.processViewSpecificInfo(ADD_VIEW, (HashKey)key, view, addVsgList, addKeyList, addLeafList); - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -379,7 +379,7 @@ class ViewSpecificGroupRetained extends GroupRetained { } */ - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -427,7 +427,7 @@ class ViewSpecificGroupRetained extends GroupRetained { removeVsgList, removeKeyList, removeLeafList); - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | @@ -468,7 +468,7 @@ class ViewSpecificGroupRetained extends GroupRetained { System.out.println("n = "+n+" keyValue = "+removeKeyList.get(n)); } */ - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.VIEWSPECIFICGROUP_CHANGED; message.threads = (J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER | diff --git a/src/classes/share/javax/media/j3d/VirtualUniverse.java b/src/classes/share/javax/media/j3d/VirtualUniverse.java index a38302c..dcedfcb 100644 --- a/src/classes/share/javax/media/j3d/VirtualUniverse.java +++ b/src/classes/share/javax/media/j3d/VirtualUniverse.java @@ -163,13 +163,20 @@ public class VirtualUniverse extends Object { boolean isSceneGraphLock = false; private Object waitLock = new Object(); - - private HashSet structureChangeListenerSet = null; - private HashSet shaderErrorListenerSet = null; + // Set of scene graph structure change listeners + private HashSet structureChangeListenerSet = null; + + // Set of shader error listeners + private HashSet shaderErrorListenerSet = null; private ShaderErrorListener defaultShaderErrorListener = ShaderProgram.getDefaultErrorListener(); + // Set of rendering error listeners + private static HashSet renderingErrorListenerSet = null; + private static RenderingErrorListener defaultRenderingErrorListener = + Renderer.getDefaultErrorListener(); + /** * Constructs a new VirtualUniverse. */ @@ -255,24 +262,8 @@ public class VirtualUniverse extends Object { // Print out debugging information for debug builds if(VersionInfo.isDebug) { System.err.println("Java 3D system initialized"); - System.err.print(" graphics library = "); - switch (mc.getRenderingAPI()) { - case MasterControl.RENDER_OPENGL_SOLARIS: - System.err.println("Solaris OpenGL"); - break; - case MasterControl.RENDER_OPENGL_LINUX: - System.err.println("Linux OpenGL"); - break; - case MasterControl.RENDER_OPENGL_WIN32: - System.err.print("Windows OpenGL"); - break; - case MasterControl.RENDER_DIRECT3D: - System.err.println("Windows Direct3D"); - break; - default: - System.err.println("UNKNOWN"); - break; - } + System.err.println(" rendering pipeline = " + + Pipeline.getPipeline().getPipelineName()); System.err.println(); } } @@ -439,6 +430,10 @@ public class VirtualUniverse extends Object { * String * * + * j3d.pipeline + * String + * + * * j3d.renderer * String * @@ -514,10 +509,20 @@ public class VirtualUniverse extends Object { *

    * *

  • + * j3d.pipeline + * + *
  • + *

    + * + *

  • * j3d.renderer * *
  • *

    @@ -549,7 +554,10 @@ public class VirtualUniverse extends Object { values.add(VersionInfo.getSpecificationVendor()); keys.add("j3d.renderer"); - values.add(mc.isD3D() ? "DirectX" : "OpenGL"); + values.add(Pipeline.getPipeline().getRendererName()); + + keys.add("j3d.pipeline"); + values.add(Pipeline.getPipeline().getPipelineName()); // Now Create read-only properties object properties = @@ -1058,9 +1066,9 @@ public class VirtualUniverse extends Object { } synchronized(structureChangeListenerSet) { - Iterator it = structureChangeListenerSet.iterator(); + Iterator it = structureChangeListenerSet.iterator(); while(it.hasNext()) { - GraphStructureChangeListener listener = (GraphStructureChangeListener)it.next(); + GraphStructureChangeListener listener = it.next(); try { if (add) { listener.branchGroupAdded(parent, child); @@ -1072,6 +1080,11 @@ public class VirtualUniverse extends Object { System.err.println("Exception occurred in GraphStructureChangeListener:"); e.printStackTrace(); } + catch (Error e) { + // Issue 264 - catch Error + System.err.println("Error occurred in GraphStructureChangeListener:"); + e.printStackTrace(); + } } } } @@ -1086,9 +1099,9 @@ public class VirtualUniverse extends Object { } synchronized(structureChangeListenerSet) { - Iterator it = structureChangeListenerSet.iterator(); + Iterator it = structureChangeListenerSet.iterator(); while(it.hasNext()) { - GraphStructureChangeListener listener = (GraphStructureChangeListener)it.next(); + GraphStructureChangeListener listener = it.next(); try { listener.branchGroupMoved(oldParent, newParent, child); } @@ -1096,6 +1109,11 @@ public class VirtualUniverse extends Object { System.err.println("Exception occurred in GraphStructureChangeListener:"); e.printStackTrace(); } + catch (Error e) { + // Issue 264 - catch Error + System.err.println("Error occurred in GraphStructureChangeListener:"); + e.printStackTrace(); + } } } } @@ -1163,9 +1181,9 @@ public class VirtualUniverse extends Object { // Notify all error listeners in the set if (shaderErrorListenerSet != null) { synchronized(shaderErrorListenerSet) { - Iterator it = shaderErrorListenerSet.iterator(); + Iterator it = shaderErrorListenerSet.iterator(); while(it.hasNext()) { - ShaderErrorListener listener = (ShaderErrorListener)it.next(); + ShaderErrorListener listener = it.next(); try { listener.errorOccurred(error); } @@ -1173,15 +1191,108 @@ public class VirtualUniverse extends Object { System.err.println("Exception occurred in ShaderErrorListener:"); e.printStackTrace(); } + catch (Error e) { + // Issue 264 - catch Error + System.err.println("Error occurred in ShaderErrorListener:"); + e.printStackTrace(); + } errorReported = true; } } } - // Notify the default error listener if the set is null or empty - if (!errorReported) { - defaultShaderErrorListener.errorOccurred(error); + // Notify the default error listener if the set is null or empty + if (!errorReported) { + defaultShaderErrorListener.errorOccurred(error); + } + } + + + // Issue 260 : rendering error listeners. + + /** + * Adds the specified RenderingErrorListener to the set of listeners + * that will be notified when a rendering error is detected. + * If the specifed listener is null no action is taken and no exception + * is thrown. + * If a rendering error occurs, the listeners will be called + * asynchronously from a separate notification thread. If the set + * of listeners is empty, a default listener is notified. The + * default listener prints the error information to System.err and + * then calls System.exit(). + * + * @param listener the listener to add to the set. + * + * @since Java 3D 1.5 + */ + public static void addRenderingErrorListener(RenderingErrorListener listener) { + if (listener == null) { + return; + } + + if (renderingErrorListenerSet == null) { + renderingErrorListenerSet = new HashSet(); + } + + synchronized(renderingErrorListenerSet) { + renderingErrorListenerSet.add(listener); + } + } + + /** + * Removes the specified RenderingErrorListener from the set of + * listeners. This method performs no function, nor does it throw + * an exception if the specified listener is not currently in the + * set or is null. + * + * @param listener the listener to remove from the set. + * + * @since Java 3D 1.5 + */ + public static void removeRenderingErrorListener(RenderingErrorListener listener) { + if (renderingErrorListenerSet == null) { + return; } + + synchronized(renderingErrorListenerSet) { + renderingErrorListenerSet.remove(listener); + } + } + + /** + * Notifies all listeners of a rendering error. If no listeners exist, + * a default listener is notified. + */ + static void notifyRenderingErrorListeners(RenderingError error) { + boolean errorReported = false; + + // Notify all error listeners in the set + if (renderingErrorListenerSet != null) { + synchronized(renderingErrorListenerSet) { + Iterator it = renderingErrorListenerSet.iterator(); + while(it.hasNext()) { + RenderingErrorListener listener = it.next(); + try { + listener.errorOccurred(error); + } + catch (RuntimeException e) { + System.err.println("Exception occurred in RenderingErrorListener:"); + e.printStackTrace(); + } + catch (Error e) { + // Issue 264 - catch Error + System.err.println("Error occurred in RenderingErrorListener:"); + e.printStackTrace(); + } + errorReported = true; + } + } + } + + // Notify the default error listener if the set is null or empty + if (!errorReported) { + defaultRenderingErrorListener.errorOccurred(error); + } } } diff --git a/src/classes/share/javax/media/j3d/WakeupCondition.java b/src/classes/share/javax/media/j3d/WakeupCondition.java index d0491dd..f419376 100644 --- a/src/classes/share/javax/media/j3d/WakeupCondition.java +++ b/src/classes/share/javax/media/j3d/WakeupCondition.java @@ -91,7 +91,7 @@ public abstract class WakeupCondition extends Object { if (!conditionMet) { conditionMet = true; - J3dMessage message = VirtualUniverse.mc.getMessage(); + J3dMessage message = new J3dMessage(); message.type = J3dMessage.COND_MET; message.threads = J3dThread.UPDATE_BEHAVIOR; message.universe = behav.universe; diff --git a/src/classes/solaris/javax/media/j3d/J3dGraphicsConfig.java b/src/classes/solaris/javax/media/j3d/J3dGraphicsConfig.java deleted file mode 100644 index c242a77..0000000 --- a/src/classes/solaris/javax/media/j3d/J3dGraphicsConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import sun.awt.*; -import java.awt.*; - -class J3dGraphicsConfig { - - static native boolean isValidVisualID(long display, int vid); - - J3dGraphicsConfig(GraphicsDevice gd, int pixelFormat) { - // a dummy class which this constructor should - // never invoke under Solaris - } - - static boolean isValidPixelFormat(GraphicsConfiguration gc) { - return isValidVisualID(NativeScreenInfo.getStaticDisplay(), - ((X11GraphicsConfig) gc).getVisual()); - } - - static boolean isValidConfig(GraphicsConfiguration gc) { - // Check to see if a valid FBConfig pointer has been cached. - Object fbConfigObject = Canvas3D.fbConfigTable.get(gc); - return ((fbConfigObject != null) && - (fbConfigObject instanceof GraphicsConfigInfo)); - } - - -} diff --git a/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java deleted file mode 100644 index 6f116cf..0000000 --- a/src/classes/solaris/javax/media/j3d/NativeConfigTemplate3D.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import java.awt.GraphicsDevice; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsConfigTemplate; -import java.awt.Rectangle; -import sun.awt.X11GraphicsDevice; -import sun.awt.X11GraphicsConfig; - -class NativeConfigTemplate3D { - private final static boolean debug = false; - - NativeConfigTemplate3D() { - } - - // These definitions should match those in win32 NativeConfigTemplate3D.java - final static int RED_SIZE = 0; - final static int GREEN_SIZE = 1; - final static int BLUE_SIZE = 2; - final static int ALPHA_SIZE = 3; - final static int ACCUM_BUFFER = 4; - final static int DEPTH_SIZE = 5; - final static int DOUBLEBUFFER = 6; - final static int STEREO = 7; - final static int ANTIALIASING = 8; - final static int STENCIL_SIZE = 9; - final static int NUM_ITEMS = 10; - - // Native method to get an OpenGL visual id and a pointer to the - // GLXFBConfig structure list itself. - native int chooseOglVisual(long display, int screen, - int[] attrList, long[] fbConfig); - - // Native method to free an GLXFBConfig struct. This is static since it - // may need to be called to clean up the Canvas3D fbConfigTable after the - // NativeConfigTemplate3D has been disposed of. - static native void freeFBConfig(long fbConfig); - - // Native methods to return whether a particular attribute is available - native boolean isStereoAvailable(long display, int screen, int vid); - native boolean isDoubleBufferAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); - native int getStencilSize(long display, int screen, int vid); - - /* - * Chooses the best FBConfig for Java 3D apps. - */ - GraphicsConfiguration - getBestConfiguration(GraphicsConfigTemplate3D template, - GraphicsConfiguration[] gc) { - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc[0]).getDevice(); - - if (!NativeScreenInfo.isGLX13()) { - return null; - } - - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - - if (debug) { - System.out.println(" NativeConfigTemplate3D: using device " + gd); - System.out.println(" display " + display + " screen " + screen); - System.out.println(" configuration count: " + gc.length); - for (int i = 0 ; i < gc.length ; i++) { - System.out.println(" visual id at index " + i + ": " + - ((X11GraphicsConfig)gc[i]).getVisual()); - } - } - - Rectangle bounds = gc[0].getBounds(); - if ((bounds.x != 0 || bounds.y != 0) && - (! VirtualUniverse.mc.xineramaDisabled)) { - // Xinerama is being used. The screen needs to be set to 0 since - // glxChooseFBConfig will not return a valid visual otherwise. - screen = 0; - if (debug) { - System.out.println(" Non-primary Xinerama screen:"); - System.out.println(" bounds = " + bounds); - System.out.println(" using screen 0 visual"); - } - } - - int[] attrList; // holds the list of attributes to be translated - // for glxChooseFBConfig call - - attrList = new int[NUM_ITEMS]; - - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - long[] fbConfig = new long[1]; - int visID = chooseOglVisual(display, screen, attrList, fbConfig); - if (debug) { - System.out.println(" chooseOglVisual() returns " + visID); - System.out.println(" pointer to GLXFBConfig is " + fbConfig[0]); - System.out.println(); - } - - if (visID == 0 || fbConfig[0] == 0) { - return null; // no valid visual was found - } - - // search list of graphics configurations for config - // with matching visualId - GraphicsConfiguration gc1 = null; - for (int i = 0; i < gc.length; i++) - if (((X11GraphicsConfig)gc[i]).getVisual() == visID) { - gc1 = gc[i]; - break; - } - - // To support disabling Solaris OpenGL Xinerama mode, we need to cache - // the pointer to the actual GLXFBConfig that glXChooseFBConfig() - // returns, since this is not cached with X11GraphicsConfig and there - // are no public constructors to allow us to extend it. - synchronized (Canvas3D.fbConfigTable) { - if (Canvas3D.fbConfigTable.get(gc1) == null) { - GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(); - gcInfo.setFBConfig(fbConfig[0]); - gcInfo.setRequestedStencilSize(attrList[STENCIL_SIZE]); - Canvas3D.fbConfigTable.put(gc1, gcInfo); - } else { - freeFBConfig(fbConfig[0]); - } - } - return gc1; - } - - /* - * Determine if a given GraphicsConfiguration object can be used - * by Java 3D. - */ - boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, - GraphicsConfiguration gc) { - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - if (!NativeScreenInfo.isGLX13()) { - return false; - } - - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - - int[] attrList; // holds the list of attributes to be tramslated - // for glxChooseVisual call - - attrList = new int[NUM_ITEMS]; - - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - long[] fbConfig = new long[1]; - int visID = chooseOglVisual(display, screen, attrList, fbConfig); - - if (visID == 0 || fbConfig[0] == 0) - return false; // no valid visual was found - else - return true; - } - - - // Return whether stereo is available. - boolean hasStereo(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isStereoAvailable(display, screen, vid); - } - - // Return the stencil of this canvas. - int getStencilSize(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return getStencilSize(display, screen, vid); - } - - // Return whether a double buffer is available. - boolean hasDoubleBuffer(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isDoubleBufferAvailable(display, screen, vid); - } - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isSceneAntialiasingAccumAvailable(display, screen, vid); - } - - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - - long display = nativeScreenInfo.getDisplay(); - int screen = nativeScreenInfo.getScreen(); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isSceneAntialiasingMultisampleAvailable(display, screen, vid); - } - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/solaris/javax/media/j3d/NativeScreenInfo.java b/src/classes/solaris/javax/media/j3d/NativeScreenInfo.java deleted file mode 100644 index c84e8fe..0000000 --- a/src/classes/solaris/javax/media/j3d/NativeScreenInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import java.awt.GraphicsDevice; -import sun.awt.X11GraphicsDevice; - -class NativeScreenInfo { - private int screen; - private static long display = 0; - private static boolean glxChecked = false; - private static boolean isGLX13; - - private native static long openDisplay(); - private native static int getDefaultScreen(long display); - private native static boolean queryGLX13(long display); - - // Fix for issue 20. - // This method will return true if glx version is 1.3 or higher, - // else return false. - synchronized static boolean isGLX13() { - if (!glxChecked) { - // Open a new static display connection if one is not already opened. - getStaticDisplay(); - // Query for glx1.3 support. - isGLX13 = queryGLX13(display); - glxChecked = true; - } - - return isGLX13; - } - - synchronized static long getStaticDisplay() { - if (display == 0) { - display = openDisplay(); - } - return display; - } - - NativeScreenInfo(GraphicsDevice graphicsDevice) { - // Open a new static display connection if one is not already opened - getStaticDisplay(); - - // Get the screen number - screen = ((X11GraphicsDevice)graphicsDevice).getScreen(); - } - - long getDisplay() { - return display; - } - - int getScreen() { - return screen; - } - - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/solaris/javax/media/j3d/NativeWSInfo.java b/src/classes/solaris/javax/media/j3d/NativeWSInfo.java deleted file mode 100644 index 2e0da2a..0000000 --- a/src/classes/solaris/javax/media/j3d/NativeWSInfo.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import java.awt.*; -import java.awt.event.*; -import sun.awt.*; -import java.lang.reflect.Method; - -class NativeWSInfo { - - //X11DrawingSurface xds; - Object xds; - - void getCanvasWSParameters(Canvas3D canvas) { - try { - Class x11DSclass = Class.forName("sun.awt.X11DrawingSurface"); - Method getDrawable = x11DSclass.getDeclaredMethod("getDrawable", null ); - Method getVisualID = x11DSclass.getDeclaredMethod("getVisualID", null ); - - //canvas.window = xds.getDrawable(); - //canvas.vid = xds.getVisualID(); - - canvas.window = ((Integer)getDrawable.invoke( xds, null )).intValue(); - canvas.vid = ((Integer)getVisualID.invoke( xds, null )).intValue(); - } catch( Exception e ) { - e.printStackTrace(); - } - } - - void getWSDrawingSurface( Object dsi) { - try { - //xds = (X11DrawingSurface)dsi.getSurface(); - Class drawingSurfaceInfoClass = Class.forName("sun.awt.DrawingSurfaceInfo"); - Method getSurface = drawingSurfaceInfoClass.getDeclaredMethod( "getSurface", null); - - //xds = dsi.getSurface(); - xds = getSurface.invoke( dsi, null ); - } catch( Exception e ) { - e.printStackTrace(); - } - } - - int getCanvasVid(GraphicsConfiguration gcfg) { - return (((X11GraphicsConfig)gcfg).getVisual()); - } -} - diff --git a/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java b/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java deleted file mode 100644 index 72340e5..0000000 --- a/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import sun.awt.Win32GraphicsConfig; -import java.awt.*; - -class J3dGraphicsConfig extends Win32GraphicsConfig { - - private int pixelFormat; - - J3dGraphicsConfig(GraphicsDevice gd, int pixelFormat) - { - super(gd, pixelFormat); - this.pixelFormat = pixelFormat; - } - - static boolean isValidPixelFormat(GraphicsConfiguration gc) { - return (gc instanceof J3dGraphicsConfig); - } - - static boolean isValidConfig(GraphicsConfiguration gc) { - return isValidPixelFormat(gc); - } - - int getPixelFormat() { - return pixelFormat; - } - - -} diff --git a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java index 7253c5a..c198e31 100644 --- a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java +++ b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java @@ -44,7 +44,7 @@ class NativeConfigTemplate3D { choosePixelFormat(long ctx, int screen, int[] attrList, long[] pFormatInfo); // Native method to free an PixelFormatInfo struct. This is static since it - // may need to be called to clean up the Canvas3D fbConfigTable after the + // may need to be called to clean up the Canvas3D graphicsConfigTable after the // NativeConfigTemplate3D has been disposed of. static native void freePixelFormatInfo(long pFormatInfo); @@ -91,8 +91,8 @@ class NativeConfigTemplate3D { attrList[STENCIL_SIZE] = template.getStencilSize(); // System.out.println("NativeConfigTemplate3D : getStencilSize " + // attrList[STENCIL_SIZE]); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int screen = nativeScreenInfo.getScreen(); + + int screen = NativeScreenInfo.getScreen(gd); long[] pFormatInfo = new long[1]; @@ -118,17 +118,15 @@ class NativeConfigTemplate3D { // Fix to issue 104 -- // Pass in 0 for pixel format to the AWT. // ATI driver will lockup pixelFormat, if it is passed to AWT. - GraphicsConfiguration gc1 = new J3dGraphicsConfig(gd, 0); - - // We need to cache the offScreen pixelformat that glXChoosePixelFormat() - // returns, since this is not cached with J3dGraphicsConfig and there - // are no public constructors to allow us to extend it. - synchronized (Canvas3D.fbConfigTable) { - if (Canvas3D.fbConfigTable.get(gc1) == null) { - GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(); - gcInfo.setFBConfig(pFormatInfo[0]); - gcInfo.setRequestedStencilSize(attrList[STENCIL_SIZE]); - Canvas3D.fbConfigTable.put(gc1, gcInfo); + GraphicsConfiguration gc1 = Win32GraphicsConfig.getConfig(gd, 0); + + // We need to cache the GraphicsTemplate3D and the private + // pixel format info. + synchronized (Canvas3D.graphicsConfigTable) { + if (Canvas3D.graphicsConfigTable.get(gc1) == null) { + GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); + gcInfo.setPrivateData(new Long(pFormatInfo[0])); + Canvas3D.graphicsConfigTable.put(gc1, gcInfo); } else { freePixelFormatInfo(pFormatInfo[0]); } @@ -174,8 +172,7 @@ class NativeConfigTemplate3D { // System.out.println("NativeConfigTemplate3D : getStencilSize " + // attrList[STENCIL_SIZE]); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int screen = nativeScreenInfo.getScreen(); + int screen = NativeScreenInfo.getScreen(gd); long[] pFormatInfo = new long[1]; @@ -220,8 +217,7 @@ class NativeConfigTemplate3D { Win32GraphicsDevice gd = (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); - int screen = nativeScreenInfo.getScreen(); + int screen = NativeScreenInfo.getScreen(gd); /* Fix to issue 77 */ return isSceneAntialiasingMultisampleAvailable(c3d.fbConfig, c3d.offScreen, screen); } diff --git a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java index 2156b8f..9652b7a 100644 --- a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java +++ b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java @@ -16,18 +16,20 @@ import java.awt.GraphicsDevice; import sun.awt.Win32GraphicsDevice; class NativeScreenInfo { - private int display = 0; - private int screen = 0; - + private static final long display = 0; // unused for Win32 private static boolean wglARBChecked = false; private static boolean isWglARB; - private native static boolean queryWglARB(); + private static native boolean queryWglARB(); + + private NativeScreenInfo() { + throw new AssertionError("constructor should never be called"); + } // This method will return true if wglGetExtensionsStringARB is supported, // else return false - synchronized static boolean isWglARB() { + static synchronized boolean isWglARB() { if (!wglARBChecked) { // Query for wglGetExtensionsStringARB support. @@ -37,21 +39,14 @@ class NativeScreenInfo { return isWglARB; } - NativeScreenInfo(GraphicsDevice graphicsDevice) { - // Get the screen number - screen = ((sun.awt.Win32GraphicsDevice)graphicsDevice).getScreen(); - display = screen; - } - - int getDisplay() { + static long getDisplay() { return display; } - int getScreen() { - return screen; + static int getScreen(GraphicsDevice graphicsDevice) { + return ((Win32GraphicsDevice)graphicsDevice).getScreen(); } - // Ensure that the native libraries are loaded static { VirtualUniverse.loadLibraries(); diff --git a/src/classes/win32/javax/media/j3d/NativeWSInfo.java b/src/classes/win32/javax/media/j3d/NativeWSInfo.java deleted file mode 100644 index aca9c26..0000000 --- a/src/classes/win32/javax/media/j3d/NativeWSInfo.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package javax.media.j3d; - -import java.awt.*; -import java.awt.event.*; -import sun.awt.*; -import java.lang.reflect.Method; - -class NativeWSInfo { - - //Win32DrawingSurface wds; - Object wds; - - void getCanvasWSParameters(Canvas3D canvas) { - //canvas.window = wds.getHDC(); - try { - Class win32DSclass = Class.forName("sun.awt.Win32DrawingSurface"); - Method getHDC = win32DSclass.getDeclaredMethod("getHDC", null ); - - canvas.window = ((Integer)getHDC.invoke( wds, null )).intValue(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - void getWSDrawingSurface(Object dsi) { - //wds = (Win32DrawingSurface)dsi.getSurface(); - int hwnd =0; - - try { - Class drawingSurfaceInfoClass = Class.forName("sun.awt.DrawingSurfaceInfo"); - Method getSurface = drawingSurfaceInfoClass.getDeclaredMethod( "getSurface", null); - - wds = getSurface.invoke( dsi, null ); - - Class win32DSclass = Class.forName("sun.awt.Win32DrawingSurface"); - Method getHWnd = win32DSclass.getDeclaredMethod("getHWnd", null ); - hwnd = ((Integer)getHWnd.invoke( wds, null )).intValue(); - } catch( Exception e ) { - e.printStackTrace(); - } - - // note: dsi lock is called from the caller of this method - // Workaround for bug 4169320 - //dsi.lock(); - //subclass(wds.getHWnd()); - subclass(hwnd); - //dsi.unlock(); - } - - // Used in workaround for bug 4169320: Resizing a Java 3D canvas - // on Win95 crashes the application - private native void subclass(int hWnd); - - int getCanvasVid(GraphicsConfiguration gcfg) { - return ((J3dGraphicsConfig) gcfg).getPixelFormat(); - } -} diff --git a/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java new file mode 100644 index 0000000..cbd3713 --- /dev/null +++ b/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java @@ -0,0 +1,281 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsDevice; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsConfigTemplate; +import java.awt.Rectangle; +import sun.awt.X11GraphicsDevice; +import sun.awt.X11GraphicsConfig; + +class NativeConfigTemplate3D { + private final static boolean debug = false; + + NativeConfigTemplate3D() { + } + + // These definitions should match those in win32 NativeConfigTemplate3D.java + final static int RED_SIZE = 0; + final static int GREEN_SIZE = 1; + final static int BLUE_SIZE = 2; + final static int ALPHA_SIZE = 3; + final static int ACCUM_BUFFER = 4; + final static int DEPTH_SIZE = 5; + final static int DOUBLEBUFFER = 6; + final static int STEREO = 7; + final static int ANTIALIASING = 8; + final static int STENCIL_SIZE = 9; + final static int NUM_ITEMS = 10; + + // Native method to get an OpenGL visual id and a pointer to the + // GLXFBConfig structure list itself. + native int chooseOglVisual(long display, int screen, + int[] attrList, long[] fbConfig); + + // Native method to free an GLXFBConfig struct. This is static since it + // may need to be called to clean up the Canvas3D graphicsConfigTable + // after the NativeConfigTemplate3D has been disposed of. + static native void freeFBConfig(long fbConfig); + + // Native methods to return whether a particular attribute is available + native boolean isStereoAvailable(long display, int screen, int vid); + native boolean isDoubleBufferAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); + native int getStencilSize(long display, int screen, int vid); + + /* + * Chooses the best FBConfig for Java 3D apps. + */ + GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D template, + GraphicsConfiguration[] gc) { + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc[0]).getDevice(); + + if (!NativeScreenInfo.isGLX13()) { + return null; + } + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + + if (debug) { + System.out.println(" NativeConfigTemplate3D: using device " + gd); + System.out.println(" display " + display + " screen " + screen); + System.out.println(" configuration count: " + gc.length); + for (int i = 0 ; i < gc.length ; i++) { + System.out.println(" visual id at index " + i + ": " + + ((X11GraphicsConfig)gc[i]).getVisual()); + } + } + + Rectangle bounds = gc[0].getBounds(); + if ((bounds.x != 0 || bounds.y != 0) && + (! VirtualUniverse.mc.xineramaDisabled)) { + // Xinerama is being used. The screen needs to be set to 0 since + // glxChooseFBConfig will not return a valid visual otherwise. + screen = 0; + if (debug) { + System.out.println(" Non-primary Xinerama screen:"); + System.out.println(" bounds = " + bounds); + System.out.println(" using screen 0 visual"); + } + } + + int[] attrList; // holds the list of attributes to be translated + // for glxChooseFBConfig call + + attrList = new int[NUM_ITEMS]; + + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + long[] fbConfig = new long[1]; + int visID = chooseOglVisual(display, screen, attrList, fbConfig); + if (debug) { + System.out.println(" chooseOglVisual() returns " + visID); + System.out.println(" pointer to GLXFBConfig is " + fbConfig[0]); + System.out.println(); + } + + if (visID == 0 || fbConfig[0] == 0) { + return null; // no valid visual was found + } + + // search list of graphics configurations for config + // with matching visualId + X11GraphicsConfig gc0 = null; + for (int i = 0; i < gc.length; i++) { + if (((X11GraphicsConfig)gc[i]).getVisual() == visID) { + gc0 = (X11GraphicsConfig)gc[i]; + break; + } + } + + // Just return if we didn't find a match + if (gc0 == null) { + return null; + } + + // Create a new GraphicsConfig object based on the one we found + X11GraphicsConfig gc1 = + X11GraphicsConfig.getConfig(gd, gc0.getVisual(), + gc0.getDepth(), gc0.getColormap(), false); + + // We need to cache the GraphicsTemplate3D and the private + // fbconfig info. + synchronized (Canvas3D.graphicsConfigTable) { + if (Canvas3D.graphicsConfigTable.get(gc1) == null) { + GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); + gcInfo.setPrivateData(new Long(fbConfig[0])); + Canvas3D.graphicsConfigTable.put(gc1, gcInfo); + } else { + freeFBConfig(fbConfig[0]); + } + } + return gc1; + } + + /* + * Determine if a given GraphicsConfiguration object can be used + * by Java 3D. + */ + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, + GraphicsConfiguration gc) { + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + if (!NativeScreenInfo.isGLX13()) { + return false; + } + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + + int[] attrList; // holds the list of attributes to be tramslated + // for glxChooseVisual call + + attrList = new int[NUM_ITEMS]; + + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + long[] fbConfig = new long[1]; + int visID = chooseOglVisual(display, screen, attrList, fbConfig); + + if (visID == 0 || fbConfig[0] == 0) + return false; // no valid visual was found + else + return true; + } + + + // Return whether stereo is available. + boolean hasStereo(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isStereoAvailable(display, screen, vid); + } + + // Return the stencil of this canvas. + int getStencilSize(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return getStencilSize(display, screen, vid); + } + + // Return whether a double buffer is available. + boolean hasDoubleBuffer(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isDoubleBufferAvailable(display, screen, vid); + } + + // Return whether scene antialiasing is available. + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isSceneAntialiasingAccumAvailable(display, screen, vid); + } + + + // Return whether scene antialiasing is available. + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getDisplay(); + int screen = NativeScreenInfo.getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isSceneAntialiasingMultisampleAvailable(display, screen, vid); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/x11/javax/media/j3d/NativeScreenInfo.java b/src/classes/x11/javax/media/j3d/NativeScreenInfo.java new file mode 100644 index 0000000..85d2d3c --- /dev/null +++ b/src/classes/x11/javax/media/j3d/NativeScreenInfo.java @@ -0,0 +1,67 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsDevice; +import sun.awt.X11GraphicsDevice; + +class NativeScreenInfo { + private static long display = 0; + private static boolean glxChecked = false; + private static boolean isGLX13; + + private static native long openDisplay(); + private static native boolean queryGLX13(long display); + + private NativeScreenInfo() { + throw new AssertionError("constructor should never be called"); + } + + // Fix for issue 20. + // This method will return true if glx version is 1.3 or higher, + // else return false. + static synchronized boolean isGLX13() { + if (!glxChecked) { + // Open a new static display connection if one is not already opened. + getStaticDisplay(); + + // Query for glx1.3 support. + isGLX13 = queryGLX13(getDisplay()); + glxChecked = true; + } + + return isGLX13; + } + + private static synchronized long getStaticDisplay() { + if (display == 0) { + display = openDisplay(); + } + return display; + } + + static long getDisplay() { + // Open a new static display connection if one is not already opened + return getStaticDisplay(); + } + + static int getScreen(GraphicsDevice graphicsDevice) { + // Get the screen number + return ((X11GraphicsDevice)graphicsDevice).getScreen(); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/native/build.xml b/src/native/build.xml index 9203b95..de87ff4 100644 --- a/src/native/build.xml +++ b/src/native/build.xml @@ -20,112 +20,102 @@ - - - - - - - - + + + + + + - - - - - - - - - - + + + + + + - - @@ -151,9 +141,6 @@ - @@ -212,10 +199,10 @@ srcfile="${javahCoreSrc}/ModelClipRetained.java" targetfile="${javahCoreTarget}/javax_media_j3d_ModelClipRetained.h"/> + srcfile="${javahCoreSrc}/NativePipeline.java" + targetfile="${javahCoreTarget}/javax_media_j3d_NativePipeline.h"/> - @@ -324,11 +308,6 @@ - - - - @@ -338,7 +317,6 @@ - @@ -353,7 +331,6 @@ - @@ -373,7 +350,7 @@ - + @@ -408,31 +385,19 @@ - - - - - - - - - - - - diff --git a/src/native/d3d/Attributes.cpp b/src/native/d3d/Attributes.cpp index a55c13f..8461c66 100644 --- a/src/native/d3d/Attributes.cpp +++ b/src/native/d3d/Attributes.cpp @@ -73,7 +73,7 @@ BOOL isLinePatternMessOutput = false; BOOL isTexBorderMessOutput = false; extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_LinearFogRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateLinearFog( JNIEnv *env, jobject obj, jlong ctx, @@ -104,7 +104,7 @@ void JNICALL Java_javax_media_j3d_LinearFogRetained_update( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_ExponentialFogRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateExponentialFog( JNIEnv *env, jobject obj, jlong ctx, @@ -129,7 +129,7 @@ void JNICALL Java_javax_media_j3d_ExponentialFogRetained_update( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_ModelClipRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateModelClip( JNIEnv *env, jobject obj, jlong ctx, @@ -164,7 +164,7 @@ void JNICALL Java_javax_media_j3d_ModelClipRetained_update( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setModelViewMatrix( +void JNICALL Java_javax_media_j3d_NativePipeline_setModelViewMatrix( JNIEnv * env, jobject obj, jlong ctx, @@ -206,7 +206,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setModelViewMatrix( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( +void JNICALL Java_javax_media_j3d_NativePipeline_setProjectionMatrix( JNIEnv * env, jobject obj, jlong ctx, @@ -291,7 +291,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setViewport( +void JNICALL Java_javax_media_j3d_NativePipeline_setViewport( JNIEnv *env, jobject obj, jlong ctx, @@ -313,7 +313,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setViewport( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setSceneAmbient( +void JNICALL Java_javax_media_j3d_NativePipeline_setSceneAmbient( JNIEnv *env, jobject obj, jlong ctx, @@ -333,7 +333,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setSceneAmbient( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setLightEnables( +void JNICALL Java_javax_media_j3d_NativePipeline_setLightEnables( JNIEnv *env, jobject obj, jlong ctx, @@ -351,7 +351,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setLightEnables( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setLightingEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_setLightingEnable( JNIEnv *env, jobject obj, jlong ctx, @@ -365,7 +365,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setLightingEnable( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_disableFog( +void JNICALL Java_javax_media_j3d_NativePipeline_disableFog( JNIEnv *env, jobject obj, jlong ctx) @@ -375,7 +375,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_disableFog( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_disableModelClip( +void JNICALL Java_javax_media_j3d_NativePipeline_disableModelClip( JNIEnv *env, jobject obj, jlong ctx) @@ -491,7 +491,7 @@ DWORD getDepthFunc(jint func) extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetRenderingAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetRenderingAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -535,7 +535,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetRenderingAttributes( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_RenderingAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateRenderingAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -670,7 +670,7 @@ void JNICALL Java_javax_media_j3d_RenderingAttributesRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetPolygonAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetPolygonAttributes( JNIEnv *env, jobject obj, jlong ctx) @@ -687,7 +687,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetPolygonAttributes( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_PolygonAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePolygonAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -782,7 +782,7 @@ void printDepthFunc(jint func) */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetLineAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetLineAttributes( JNIEnv *env, jobject obj, jlong ctx) @@ -807,7 +807,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetLineAttributes( // Note that some graphics card don't support it. // In this case use RGB Emulation. extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_LineAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateLineAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -877,7 +877,7 @@ void JNICALL Java_javax_media_j3d_LineAttributesRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetPointAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetPointAttributes( JNIEnv *env, jobject obj, jlong ctx) @@ -891,7 +891,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetPointAttributes( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_PointAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePointAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -919,7 +919,7 @@ void JNICALL Java_javax_media_j3d_PointAttributesRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTexCoordGeneration( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTexCoordGeneration( JNIEnv *env, jobject obj, jlong ctx) @@ -947,7 +947,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTexCoordGeneration( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TexCoordGenerationRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexCoordGeneration( JNIEnv *env, jobject obj, jlong ctx, @@ -1110,7 +1110,7 @@ void JNICALL Java_javax_media_j3d_TexCoordGenerationRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTextureAttributes( JNIEnv *env, jobject obj, jlong ctx) @@ -1143,7 +1143,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureAttributes( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -1408,54 +1408,54 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNative( } -// This procedure is invoked after Blend2Pass to restore the original value -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_restoreBlend1Pass( - JNIEnv *env, - jobject obj, - jlong ctx) -{ - GetDevice(); +// // This procedure is invoked after Blend2Pass to restore the original value +// extern "C" JNIEXPORT +// void JNICALL Java_javax_media_j3d_NativePipeline_restoreBlend1Pass( +// JNIEnv *env, +// jobject obj, +// jlong ctx) +// { +// GetDevice(); - device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); - device->SetTextureStageState(0, D3DTSS_COLORARG1, - D3DTA_TEXTURE|D3DTA_COMPLEMENT); - device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); +// device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); +// device->SetTextureStageState(0, D3DTSS_COLORARG1, +// D3DTA_TEXTURE|D3DTA_COMPLEMENT); +// device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); - device->SetRenderState(D3DRS_SRCBLEND, - d3dCtx->srcBlendFunc); - device->SetRenderState(D3DRS_DESTBLEND, - d3dCtx->dstBlendFunc); - device->SetRenderState(D3DRS_ALPHABLENDENABLE, - d3dCtx->blendEnable); -} +// device->SetRenderState(D3DRS_SRCBLEND, +// d3dCtx->srcBlendFunc); +// device->SetRenderState(D3DRS_DESTBLEND, +// d3dCtx->dstBlendFunc); +// device->SetRenderState(D3DRS_ALPHABLENDENABLE, +// d3dCtx->blendEnable); +// } -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateBlend2Pass( - JNIEnv *env, - jobject obj, - jlong ctx) -{ - GetDevice(); - device->GetRenderState(D3DRS_SRCBLEND, - &d3dCtx->srcBlendFunc); - device->GetRenderState(D3DRS_DESTBLEND, - &d3dCtx->dstBlendFunc); - device->GetRenderState(D3DRS_ALPHABLENDENABLE, - &d3dCtx->blendEnable); +// extern "C" JNIEXPORT +// void JNICALL Java_javax_media_j3d_NativePipeline_updateBlend2Pass( +// JNIEnv *env, +// jobject obj, +// jlong ctx) +// { +// GetDevice(); +// device->GetRenderState(D3DRS_SRCBLEND, +// &d3dCtx->srcBlendFunc); +// device->GetRenderState(D3DRS_DESTBLEND, +// &d3dCtx->dstBlendFunc); +// device->GetRenderState(D3DRS_ALPHABLENDENABLE, +// &d3dCtx->blendEnable); - device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); - device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); - device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); - device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); - device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR); -} +// device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); +// device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); +// device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); +// device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); +// device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); +// device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR); +// } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateCombinerNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateCombiner( JNIEnv *env, jobject obj, jlong ctx, @@ -1524,7 +1524,7 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateCombinerNative } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateTextureColorTableNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureColorTable( JNIEnv *env, jobject obj, jlong ctx, @@ -1537,7 +1537,7 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateTextureColorTa extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateMaterial( +void JNICALL Java_javax_media_j3d_NativePipeline_updateMaterialColor( JNIEnv *env, jobject obj, jlong ctx, @@ -1569,7 +1569,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_updateMaterial( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_MaterialRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateMaterial( JNIEnv *env, jobject obj, jlong ctx, @@ -1661,7 +1661,7 @@ void JNICALL Java_javax_media_j3d_MaterialRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTransparency( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTransparency( JNIEnv *env, jobject obj, jlong ctx, @@ -1690,7 +1690,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTransparency( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TransparencyAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTransparencyAttributes( JNIEnv *env, jobject tr, jlong ctx, @@ -1736,7 +1736,7 @@ void JNICALL Java_javax_media_j3d_TransparencyAttributesRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetColoringAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetColoringAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -1761,7 +1761,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetColoringAttributes( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_ColoringAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateColoringAttributes( JNIEnv *env, jobject obj, jlong ctx, @@ -1799,9 +1799,9 @@ void JNICALL Java_javax_media_j3d_ColoringAttributesRetained_updateNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureNative( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTextureNative( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint texUnitIndex) { @@ -1841,9 +1841,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureNative( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_bindTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTexture2D( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint objectId, jboolean enable) @@ -1893,9 +1893,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_bindTexture( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint minFilter, jint magFilter) @@ -1960,9 +1960,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilterModes( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint baseLevel, jint maximumLevel, @@ -1971,11 +1971,10 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodRange( { } - extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat lodOffsetS, jfloat lodOffsetT, @@ -1985,7 +1984,7 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodOffset( } void updateTextureBoundary(JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint boundaryModeS, jint boundaryModeT, @@ -2083,9 +2082,9 @@ void updateTextureBoundary(JNIEnv *env, } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint boundaryModeS, jint boundaryModeT, @@ -2094,7 +2093,7 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureBoundary( jfloat boundaryBlue, jfloat boundaryAlpha) { - updateTextureBoundary(env, texture, ctx, boundaryModeS, + updateTextureBoundary(env, obj, ctx, boundaryModeS, boundaryModeT, -1, boundaryRed, boundaryGreen, boundaryBlue, boundaryAlpha); @@ -2103,9 +2102,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureBoundary( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSharpenFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSharpenFunc( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint numPts, jfloatArray pts) @@ -2113,9 +2112,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSharpenFunc( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilter4Func( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DFilter4Func( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint numPts, jfloatArray pts) @@ -2156,9 +2155,9 @@ void updateTextureAnisotropicFilter( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat degree) { @@ -2167,9 +2166,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureAnisotropicFilter extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat degree) { @@ -2182,9 +2181,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureAnisotropicFilt } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat degree) { @@ -2193,21 +2192,22 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureAnisotropi extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint level, jint xoffset, jint yoffset, - jint internalFormat, - jint storedFormat, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint tilew, jint width, jint height, - jbyteArray image) + jint dataType, + jobject data) { GetDevice(); @@ -2232,44 +2232,60 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSubImage( return; } + // TODO --- Need to re-write. Chien + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + // update Image data - if (storedFormat != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToSurface(storedFormat, internalFormat, xoffset, yoffset, + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToSurface(imageFormat, textureFormat, xoffset, yoffset, imgXOffset, imgYOffset, width, height, tilew, byteData, surf, level); - env->ReleasePrimitiveArrayCritical(image, byteData, 0); - } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToSurface(storedFormat, internalFormat, xoffset, yoffset, + copyDataToSurface(imageFormat, textureFormat, xoffset, yoffset, imgXOffset, imgYOffset, width, height, tilew, shortData, surf, level); env->ReleasePrimitiveArrayCritical(image, shortData, 0); + */ + } + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); } } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { GetDevice(); - - if (d3dCtx->texUnitStage >= d3dCtx->bindTextureIdLen) { if (debug) { printf("Internal Error: texUnitState %d, bindTextureIDLen %d\n", @@ -2304,7 +2320,7 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureImage( if (surf == NULL) { // Need to create surface - surf = createTextureSurface(d3dCtx, numLevels, internalFormat, + surf = createTextureSurface(d3dCtx, numLevels, textureFormat, width, height); if (surf == NULL) { @@ -2326,99 +2342,48 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureImage( return; } + // TODO --- Need to re-write. Chien // update Image data - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToSurface(format, internalFormat, 0, 0, 0, 0, + if (data != NULL) { + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToSurface(imageFormat, textureFormat, 0, 0, 0, 0, width, height, width, byteData, surf, level); - env->ReleasePrimitiveArrayCritical(imageYup, byteData, 0); - } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToSurface(format, internalFormat, 0, 0, 0, 0, + copyDataToSurface(imageFormat, textureFormat, 0, 0, 0, 0, width, height, width, shortData, surf, level); env->ReleasePrimitiveArrayCritical(imageYup, shortData, 0); + */ } - } - + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); + } + } device->SetTexture(d3dCtx->texUnitStage, surf); } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_bindTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTexture3D( JNIEnv *env, - jobject texture, - jlong ctx, - jint objectId, - jboolean enable) -{ - Java_javax_media_j3d_TextureRetained_bindTexture(env, texture, - ctx, objectId, enable); -} - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateTextureSubImage( - JNIEnv *env, - jobject texture, - jlong ctx, - jint level, - jint xoffset, - jint yoffset, - jint internalFormat, - jint storedFormat, - jint imgXOffset, - jint imgYOffset, - jint tilew, - jint width, - jint height, - jbyteArray image) -{ - Java_javax_media_j3d_TextureRetained_updateTextureSubImage( - env, texture, ctx, level, xoffset, yoffset, internalFormat, - storedFormat, imgXOffset, imgYOffset, tilew, width, height, image); -} - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateTextureImage( - JNIEnv *env, - jobject texture, - jlong ctx, - jint numLevels, - jint level, - jint internalFormat, - jint format, - jint width, - jint height, - jint boundaryWidth, - jbyteArray imageYup) -{ - Java_javax_media_j3d_TextureRetained_updateTextureImage(env, texture, - ctx, numLevels, level, internalFormat, format, - width, height, boundaryWidth, imageYup); -} - - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateDetailTextureParameters( - JNIEnv *env, - jobject texture, - jlong ctx, - jint detailTextureMode, - jint detailTextureLevel, - jint numPts, - jfloatArray funcPts) -{ - // Not support -} - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_bindTexture( - JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint objectId, jboolean enable) @@ -2471,9 +2436,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_bindTexture( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint minFilter, jint magFilter) @@ -2481,15 +2446,15 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilterModes( GetCtx(); if (d3dCtx->deviceInfo->maxTextureDepth > 0) { - Java_javax_media_j3d_TextureRetained_updateTextureFilterModes( - env, texture, ctx, minFilter, magFilter); + Java_javax_media_j3d_NativePipeline_updateTexture2DFilterModes( + env, obj, ctx, minFilter, magFilter); } } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint baseLevel, jint maximumLevel, @@ -2501,9 +2466,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodRange( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat lodOffsetS, jfloat lodOffsetT, @@ -2514,9 +2479,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodOffset( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint boundaryModeS, jint boundaryModeT, @@ -2532,7 +2497,7 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureBoundary( if (d3dCtx->deviceInfo->maxTextureDepth > 0) { updateTextureBoundary( - env, texture, ctx, + env, obj, ctx, boundaryModeS, boundaryModeT, boundaryModeR, @@ -2546,19 +2511,20 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureBoundary( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint depth, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { GetDevice(); @@ -2600,7 +2566,7 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureImage( } if (surf == NULL) { - surf = createVolumeTexture(d3dCtx, numLevels, internalFormat, + surf = createVolumeTexture(d3dCtx, numLevels, textureFormat, width, height, depth); if (surf == NULL) { return; @@ -2621,21 +2587,40 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureImage( return; } + // TODO --- Need to re-write. Chien // update Image data - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToVolume(format, internalFormat, 0, 0, 0, 0, 0, 0, + if (data != NULL) { + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToVolume(imageFormat, textureFormat, 0, 0, 0, 0, 0, 0, width, height, depth, width, height, byteData, surf, level); - env->ReleasePrimitiveArrayCritical(imageYup, byteData, 0); } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToVolume(format, internalFormat, 0, 0, 0, 0, 0, 0, + copyDataToVolume(imageFormat, textureFormat, 0, 0, 0, 0, 0, 0, width, height, depth, width, height, shortData, surf, level); env->ReleasePrimitiveArrayCritical(imageYup, shortData, 0); + */ + } + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); } } device->SetTexture(d3dCtx->texUnitStage, surf); @@ -2643,16 +2628,16 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureImage( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint level, jint xoffset, jint yoffset, jint zoffset, - jint internalFormat, - jint storedFormat, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint imgZOffset, @@ -2661,7 +2646,8 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSubImage( jint width, jint height, jint depth, - jbyteArray image) + jint dataType, + jobject data) { GetDevice(); @@ -2687,32 +2673,49 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSubImage( return; } + // TODO --- Need to re-write. Chien + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + // update Image data - if (storedFormat != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToVolume(storedFormat, internalFormat, xoffset, + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToVolume(imageFormat, textureFormat, xoffset, yoffset, zoffset, imgXOffset, imgYOffset, imgZOffset, width, height, depth, tilew, tileh, byteData, surf, level); - env->ReleasePrimitiveArrayCritical(image, byteData, 0); - } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToVolume(storedFormat, internalFormat, xoffset, + copyDataToVolume(imageFormat, textureFormat, xoffset, yoffset, zoffset, imgXOffset, imgYOffset, imgZOffset, width, height, depth, tilew, tileh, shortData, surf, level); env->ReleasePrimitiveArrayCritical(image, shortData, 0); + */ + } + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); } } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_bindTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTextureCubeMap( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint objectId, jboolean enable) @@ -2764,22 +2767,22 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_bindTexture( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint minFilter, jint magFilter) { - Java_javax_media_j3d_TextureRetained_updateTextureFilterModes(env, - texture, ctx, minFilter, magFilter); + Java_javax_media_j3d_NativePipeline_updateTexture2DFilterModes(env, + obj, ctx, minFilter, magFilter); } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint baseLevel, jint maximumLevel, @@ -2791,9 +2794,9 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodRange( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jfloat lodOffsetS, jfloat lodOffsetT, @@ -2804,9 +2807,9 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodOffset( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint boundaryModeS, jint boundaryModeT, @@ -2815,7 +2818,7 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureBoundary( jfloat boundaryBlue, jfloat boundaryAlpha) { - updateTextureBoundary(env, texture, ctx, boundaryModeS, + updateTextureBoundary(env, obj, ctx, boundaryModeS, boundaryModeT, -1, boundaryRed, boundaryGreen, boundaryBlue, boundaryAlpha); @@ -2823,22 +2826,23 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureBoundary( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint face, jint level, jint xoffset, jint yoffset, - jint internalFormat, - jint storedFormat, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint tilew, jint width, jint height, - jbyteArray image) + jint dataType, + jobject data) { GetDevice(); @@ -2863,43 +2867,63 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureSubImage( return; } + // TODO --- Need to re-write. Chien + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + // update Image data - if (storedFormat != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToCubeMap(storedFormat, internalFormat, + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToCubeMap(imageFormat, textureFormat, xoffset, yoffset, imgXOffset, imgYOffset, width, height, tilew, byteData, surf, level, face); - env->ReleasePrimitiveArrayCritical(image, byteData, 0); } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(image, NULL); - copyDataToCubeMap(storedFormat, internalFormat, + copyDataToCubeMap(imageFormat, textureFormat, xoffset, yoffset, imgXOffset, imgYOffset, width, height, tilew, shortData, surf, level, face); env->ReleasePrimitiveArrayCritical(image, shortData, 0); + */ } + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); + } + } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctx, jint face, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { GetDevice(); @@ -2937,7 +2961,7 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureImage( if (surf == NULL) { // Need to create surface - surf = createCubeMapTexture(d3dCtx, numLevels, internalFormat, + surf = createCubeMapTexture(d3dCtx, numLevels, textureFormat, width, height); if (surf == NULL) { return; @@ -2958,22 +2982,41 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureImage( return; } + // TODO --- Need to re-write. Chien // update Image data - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToCubeMap(format, internalFormat, 0, 0, 0, 0, + if (data != NULL) { + void *imageObjPtr; + + /* Need to support INT, and NIO buffers -- Chien */ + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL); + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + } + + if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) { + jbyte *byteData = (jbyte *) imageObjPtr; + copyDataToCubeMap(imageFormat, textureFormat, 0, 0, 0, 0, width, height, width, byteData, surf, level, face); - env->ReleasePrimitiveArrayCritical(imageYup, byteData, 0); } else { + /* jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(imageYup, NULL); - copyDataToCubeMap(format, internalFormat, 0, 0, 0, 0, + copyDataToCubeMap(imageFormat, textureFormat, 0, 0, 0, 0, width, height, width, shortData, surf, level, face); env->ReleasePrimitiveArrayCritical(imageYup, shortData, 0); + */ + } + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || + (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); } + } device->SetTexture(d3dCtx->texUnitStage, surf); @@ -2981,34 +3024,7 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureImage( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_DetailTextureImage_bindTexture( - JNIEnv *env, - jobject texture, - jlong ctx, - jint objectId) -{ - // NOT SUPPORTED -} - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_DetailTextureImage_updateTextureImage( - JNIEnv *env, - jobject texture, - jlong ctx, - jint numLevels, - jint level, - jint internalFormat, - jint format, - jint width, - jint height, - jint boundaryWidth, - jbyteArray imageYup) -{ - // NOT SUPPORTED -} - -extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_decal1stChildSetup( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_decal1stChildSetup( JNIEnv *env, jobject obj, jlong ctx) @@ -3030,7 +3046,7 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_decal1stChildSetup( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_decalNthChildSetup( +void JNICALL Java_javax_media_j3d_NativePipeline_decalNthChildSetup( JNIEnv *env, jobject obj, jlong ctx) @@ -3052,7 +3068,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_decalNthChildSetup( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_decalReset( +void JNICALL Java_javax_media_j3d_NativePipeline_decalReset( JNIEnv *env, jobject obj, jlong ctx, @@ -3069,7 +3085,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_decalReset( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_ctxUpdateEyeLightingEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_ctxUpdateEyeLightingEnable( JNIEnv *env, jobject obj, jlong ctx, @@ -3080,7 +3096,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_ctxUpdateEyeLightingEnable( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_activeTextureUnit( +void JNICALL Java_javax_media_j3d_NativePipeline_activeTextureUnit( JNIEnv *env, jobject obj, jlong ctx, @@ -3097,7 +3113,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_activeTextureUnit( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureUnitStateRetained_updateTextureUnitState( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureUnitState( JNIEnv *env, jobject obj, jlong ctx, @@ -3120,7 +3136,7 @@ void JNICALL Java_javax_media_j3d_TextureUnitStateRetained_updateTextureUnitStat } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setDepthFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_setDepthFunc( JNIEnv * env, jobject obj, jlong ctx, @@ -3140,7 +3156,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setDepthFunc( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setBlendColor( +void JNICALL Java_javax_media_j3d_NativePipeline_setBlendColor( JNIEnv *env, jobject obj, jlong ctx, @@ -3154,7 +3170,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setBlendColor( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setBlendFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_setBlendFunc( JNIEnv * env, jobject obj, jlong ctx, @@ -3171,7 +3187,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setBlendFunc( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setFogEnableFlag( +void JNICALL Java_javax_media_j3d_NativePipeline_setFogEnableFlag( JNIEnv * env, jobject obj, jlong ctx, @@ -3183,7 +3199,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setFogEnableFlag( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateSeparateSpecularColorEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_updateSeparateSpecularColorEnable( JNIEnv *env, jobject obj, jlong ctx, @@ -3191,39 +3207,18 @@ void JNICALL Java_javax_media_j3d_Canvas3D_updateSeparateSpecularColorEnable( { } -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateTexUnitStateMap( - JNIEnv *env, - jobject obj, - jlong ctx, - jint numActiveTexUnit, - jintArray texUnitStateMapArray) -{ - if ((texUnitStateMapArray != NULL) && (numActiveTexUnit > 0)) { - GetDevice(); - - jint* texUnitStateMap = (jint *) env->GetPrimitiveArrayCritical( - texUnitStateMapArray, NULL); - int genMode; - int ts; - for (int i = 0; i < numActiveTexUnit; i++) { - genMode = setTextureStage(d3dCtx, device, i, texUnitStateMap[i]); - if (genMode != TEX_GEN_AUTO) { - ts = d3dCtx->texStride[i]; - if (ts == 0) { - /* - In multiTexture case when no tex defined in non object - linear mode. - */ - ts = d3dCtx->texCoordFormat[i]; - } - } else { - ts = d3dCtx->texCoordFormat[i]; - } - setTexTransformStageFlag(d3dCtx, device, i, ts, genMode); - } - env->ReleasePrimitiveArrayCritical(texUnitStateMapArray, - texUnitStateMap, 0); - } +// Fix issue 221 : Temporary stub until Cg is implemented +/* + * Class: javax_media_j3d_NativePipeline + * Method: loadNativeCgLibrary + * Signature: ([Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_javax_media_j3d_NativePipeline_loadNativeCgLibrary( + JNIEnv *env, + jobject thiz, + jobjectArray libpath) +{ + return JNI_FALSE; } diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp index faeafbf..ba9c918 100644 --- a/src/native/d3d/Canvas3D.cpp +++ b/src/native/d3d/Canvas3D.cpp @@ -14,7 +14,7 @@ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setDrawActive( +void JNICALL Java_javax_media_j3d_NativePipeline_setDrawActive( JNIEnv *env, jobject obj, jint fd) @@ -24,7 +24,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setDrawActive( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_widSync( +void JNICALL Java_javax_media_j3d_NativePipeline_widSync( JNIEnv *env, jobject obj, jint fd, @@ -36,7 +36,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_widSync( extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_useSharedCtx( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_useSharedCtx( JNIEnv *env, jobject obj) { @@ -46,12 +46,12 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_useSharedCtx( extern "C" JNIEXPORT -jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( +jlong JNICALL Java_javax_media_j3d_NativePipeline_createNewContext( JNIEnv *env, jobject obj, + jobject cv, jlong display, - jint window, - jint vid, + jlong window, jlong fbConfigListPtr, jlong sharedCtx, jboolean isSharedCtx, @@ -59,10 +59,11 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( jboolean glslLibraryAvailable, jboolean cgLibraryAvailable) { - HWND hwnd = WindowFromDC(reinterpret_cast(jlong(window))); + HWND hwnd = WindowFromDC(reinterpret_cast(window)); lock(); - D3dCtx* ctx = new D3dCtx(env, obj, hwnd, offScreen, vid); + int vid = 0; // TODO: get needed info from fbConfigListPtr + D3dCtx* ctx = new D3dCtx(env, cv, hwnd, offScreen, vid); if (ctx == NULL) { printf("%s", getErrorMessage(OUTOFMEMORY)); unlock(); @@ -71,11 +72,11 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( if (offScreen) { - jclass cls = (jclass) env->GetObjectClass(obj); + jclass cls = (jclass) env->GetObjectClass(cv); jfieldID fieldId = env->GetFieldID(cls, "offScreenCanvasSize", "Ljava/awt/Dimension;"); - jobject dimObj = env->GetObjectField(obj, fieldId); + jobject dimObj = env->GetObjectField(cv, fieldId); if (dimObj == NULL) { // user invoke queryProperties() @@ -92,7 +93,7 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( } } - if (!ctx->initialize(env, obj)) + if (!ctx->initialize(env, cv)) { delete ctx; unlock(); @@ -106,12 +107,12 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( +void JNICALL Java_javax_media_j3d_NativePipeline_createQueryContext( JNIEnv *env, jobject obj, + jobject cv, jlong display, - jint window, - jint vid, + jlong window, jlong fbConfigListPtr, jboolean offScreen, jint width, @@ -119,7 +120,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( jboolean glslLibraryAvailable, jboolean cgLibraryAvailable) { - HWND hwnd = WindowFromDC(reinterpret_cast(jlong(window))); + HWND hwnd = WindowFromDC(reinterpret_cast(window)); lock(); // always use offscreen for property since it @@ -128,7 +129,8 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( // instead of current window width/height to create // context. - D3dCtx* ctx = new D3dCtx(env, obj, hwnd, true, vid); + int vid = 0; // TODO: get needed info from fbConfigListPtr + D3dCtx* ctx = new D3dCtx(env, cv, hwnd, true, vid); if (ctx == NULL) { printf("%s", getErrorMessage(OUTOFMEMORY)); unlock(); @@ -138,18 +140,18 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( ctx->offScreenWidth = width; ctx->offScreenHeight = height; - ctx->initialize(env, obj); + ctx->initialize(env, cv); delete ctx; unlock(); } extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_useCtx( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_useCtx( JNIEnv *env, - jclass cl, + jobject obj, jlong ctx, jlong display, - jint window) + jlong window) { return JNI_TRUE; // D3D doesn't have notation of current context @@ -157,7 +159,7 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_useCtx( extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_getNumCtxLights( +jint JNICALL Java_javax_media_j3d_NativePipeline_getNumCtxLights( JNIEnv *env, jobject obj, jlong ctx) @@ -173,43 +175,8 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_getNumCtxLights( return nlight; } - extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_composite( - JNIEnv *env, - jobject obj, - jlong ctx, - jint px, - jint py, - jint minX, - jint minY, - jint maxX, - jint maxY, - jint rasWidth, - jbyteArray imageYdown, - jint winWidth, - jint winHeight) - -{ - GetDevice(); - - // However we use the following texturemapping function instead - // so this will not invoke. - if (d3dCtx->backSurface == NULL) { - device->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO,//iSwapChain is 0 - &d3dCtx->backSurface); - } - jbyte *byteData = (jbyte *) (env->GetPrimitiveArrayCritical( - imageYdown, NULL)); - compositeDataToSurface(px, py, - minX, minY, maxX-minX, maxY-minY, - rasWidth, - byteData, d3dCtx->backSurface); - env->ReleasePrimitiveArrayCritical(imageYdown, byteData, 0); -} - -extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_initTexturemapping( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_initTexturemapping( JNIEnv *env, jobject texture, jlong ctx, @@ -225,24 +192,29 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_initTexturemapping( (d3dCtx->textureTable[objectId] != NULL)) { // delete the previous texture reference // when canvas resize - Java_javax_media_j3d_Canvas3D_freeTexture(env, + Java_javax_media_j3d_NativePipeline_freeTexture(env, NULL, ctx, objectId); } - Java_javax_media_j3d_TextureRetained_bindTexture( + Java_javax_media_j3d_NativePipeline_bindTexture2D( env, texture, ctx, objectId, TRUE); - Java_javax_media_j3d_TextureRetained_updateTextureImage( - env, texture, ctx, 1, 0, J3D_RGBA, 0, texWidth, texHeight, 0, NULL); - + /* TODO : This need to rewrite -- Chien. */ + /* + Java_javax_media_j3d_NativePipeline_updateTexture2DImage( + env, texture, ctx, 1, 0, J3D_RGBA, 0, texWidth, texHeight, 0, NULL); + */ + Java_javax_media_j3d_NativePipeline_updateTexture2DImage(env, texture, ctx, 1, 0, + J3D_RGBA, 0, texWidth, + texHeight, 0, 0, NULL); return (d3dCtx->textureTable[objectId] != NULL); } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( +void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping( JNIEnv *env, jobject texture, jlong ctx, @@ -263,13 +235,14 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( { GetDevice(); - Java_javax_media_j3d_TextureRetained_bindTexture( + Java_javax_media_j3d_NativePipeline_bindTexture2D( env, texture, ctx, objectId, TRUE); - - Java_javax_media_j3d_Texture2DRetained_updateTextureSubImage( + // TODO --- Need to re-write. Chien + Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage( env, texture, ctx, 0, minX, minY, J3D_RGBA, format, - minX, minY, rasWidth, maxX-minX, maxY-minY, imageYdown); + minX, minY, rasWidth, maxX-minX, maxY-minY, IMAGE_DATA_TYPE_BYTE_ARRAY, + imageYdown); LPDIRECT3DTEXTURE9 surf = d3dCtx->textureTable[objectId]; @@ -312,7 +285,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( minX, minY, maxX, maxY, maxX - minX, maxY - minY, false); - Java_javax_media_j3d_TextureRetained_bindTexture( + Java_javax_media_j3d_NativePipeline_bindTexture2D( env, texture, ctx, objectId, FALSE); device->SetRenderState(D3DRS_ALPHABLENDENABLE, blendEnable); @@ -325,19 +298,142 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_clear( - JNIEnv *env, - jobject obj, - jlong ctx, - jfloat r, - jfloat g, - jfloat b, - jint winWidth, - jint winHeight, - jobject pa2d, - jint imageScaleMode, - jbyteArray pixels_obj) +void JNICALL Java_javax_media_j3d_NativePipeline_clear( + JNIEnv *env, + jobject obj, + jlong ctx, + jfloat r, + jfloat g, + jfloat b) +{ + + GetDevice(); + + /* Java 3D always clears the Z-buffer */ + /* @TODO check same operation for stencil */ + + if (!d3dCtx->zWriteEnable) { + device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); + } + + /* clear stencil, if in used */ + if (d3dCtx->stencilWriteEnable ) { + // clear stencil and ZBuffer + HRESULT hr = device->Clear(0, NULL, + D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, + D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0); + if (hr == D3DERR_INVALIDCALL) { + printf("[Java3D] Error cleaning Canvas3D stencil & ZBuffer\n"); + } + // printf("canvas3D clear stencil & ZBuffer\n"); + } + else { + // clear ZBuffer only + HRESULT hr = device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, + D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0); + if (hr == D3DERR_INVALIDCALL) { + printf("[Java3D] Error cleaning Canvas3D ZBuffer\n"); + } + // printf("canvas3D clear ZBuffer\n"); + } + + if (!d3dCtx->zWriteEnable) { + device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); + } + // disable stencil + if (d3dCtx->stencilEnable && !d3dCtx->stencilWriteEnable) { + device->SetRenderState(D3DRS_STENCILENABLE, FALSE); + } + +} + +extern "C" JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_textureFill( + JNIEnv *env, + jobject obj, + jlong ctx, + jfloat texMinU, + jfloat texMaxU, + jfloat texMinV, + jfloat texMaxV, + jfloat mapMinX, + jfloat mapMaxX, + jfloat mapMinY, + jfloat mapMaxY) +{ + GetDevice(); + /* printf("Canvas3D.textureFill()\n"); */ + /* TODO : Implement textureFill() */ + printf("[Java3D] D3D : textureFill is not implemented yet.\n"); + + +} + +extern "C" JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, + jobject obj, + jlong ctx, + jfloat texMinU, + jfloat texMaxU, + jfloat texMinV, + jfloat texMaxV, + jfloat mapMinX, + jfloat mapMaxX, + jfloat mapMinY, + jfloat mapMaxY, + jfloat mapZ, + jfloat alpha) +{ + GetDevice(); + /* printf("Canvas3D.textureFillRaster()\n"); */ + /* TODO : Implement textureFillRaster() */ + printf("[Java3D] D3D : textureFillRaster is not implemented yet.\n"); + +} + + +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_executeRasterDepth(JNIEnv *env, + jobject obj, + jlong ctx, + jfloat posX, + jfloat posY, + jfloat posZ, + jint srcOffsetX, + jint srcOffsetY, + jint rasterWidth, + jint rasterHeight, + jint depthWidth, + jint depthHeight, + jint depthFormat, + jobject depthData) +{ + GetDevice(); + /* printf("Canvas3D.executeRasterDepth()\n"); */ + /* TODO : Implement executeRasterDepth() */ + printf("[Java3D] D3D : executeRasterDepth is not implemented yet.\n"); + +} + +/* TODO : This method will be replaced by clear() and textureFill() */ +extern "C" JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_textureclear( + JNIEnv *env, + jobject obj, + jlong ctx, + jint maxX, + jint maxY, + jfloat r, + jfloat g, + jfloat b, + jint winWidth, + jint winHeight, + jint objectId, + jint imageScaleMode, + jobject pa2d, + jboolean update) { + GetDevice(); @@ -371,15 +467,10 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( // printf("canvas3D clear ZBuffer\n"); } - + if (pa2d) { - jclass pa2d_class = env->GetObjectClass(pa2d); /* - jfieldID id = env->GetFieldID(pa2d_class, "surfaceDirty", "I"); - if (env->GetIntField(pa2d, id) == NOTLIVE) { - return; - } - */ + jclass pa2d_class = env->GetObjectClass(pa2d); // It is possible that (1) Another user thread will free this // image. (2) Another Renderer thread in case of multiple screen // will invoke clear() at the same time. @@ -392,6 +483,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( D3dImageComponent *d3dImage = D3dImageComponent::find(&BackgroundImageList, d3dCtx, hashCode); + id = env->GetFieldID(pa2d_class, "imageYup", "[B"); + jbyteArray pixels_obj = (jbyteArray) env->GetObjectField(pa2d, id); + id = env->GetFieldID(pa2d_class, "width", "I"); int width = env->GetIntField(pa2d, id); id = env->GetFieldID(pa2d_class, "height", "I"); @@ -523,25 +617,24 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( device->SetRenderState(D3DRS_STENCILENABLE, d3dCtx->stencilWriteEnable); } unlockBackground(); + */ } else { - if (!d3dCtx->zWriteEnable) { - device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); - } - // disable stencil - if (d3dCtx->stencilEnable && !d3dCtx->stencilWriteEnable) { - device->SetRenderState(D3DRS_STENCILENABLE, FALSE); - } - } - + if (!d3dCtx->zWriteEnable) { + device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); + } + // disable stencil + if (d3dCtx->stencilEnable && !d3dCtx->stencilWriteEnable) { + device->SetRenderState(D3DRS_STENCILENABLE, FALSE); + } + } } - extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setRenderMode( +void JNICALL Java_javax_media_j3d_NativePipeline_setRenderMode( JNIEnv *env, jobject obj, jlong ctx, @@ -554,7 +647,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setRenderMode( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_clearAccum( +void JNICALL Java_javax_media_j3d_NativePipeline_clearAccum( JNIEnv *env, jobject obj, jlong ctx) @@ -566,7 +659,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clearAccum( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_accum( +void JNICALL Java_javax_media_j3d_NativePipeline_accum( JNIEnv *env, jobject obj, jlong ctx, @@ -577,7 +670,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_accum( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_accumReturn( +void JNICALL Java_javax_media_j3d_NativePipeline_accumReturn( JNIEnv *env, jobject obj, jlong ctx) @@ -587,7 +680,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_accumReturn( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setDepthBufferWriteEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_setDepthBufferWriteEnable( JNIEnv *env, jobject obj, jlong ctx, @@ -632,12 +725,13 @@ VOID freePointerList() extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_swapBuffers( +jint JNICALL Java_javax_media_j3d_NativePipeline_swapBuffers( JNIEnv *env, jobject obj, + jobject cv, jlong ctx, jlong display, - jint win) + jlong window) { GetDevice2(); @@ -655,7 +749,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_swapBuffers( printf("Buffer swap error %s, try Reset() the surface... \n", DXGetErrorString9(hr)); } - retCode = d3dCtx->resetSurface(env, obj); + retCode = d3dCtx->resetSurface(env, cv); GetDevice2(); hr = device->Present(NULL, NULL, NULL, NULL); if (FAILED(hr)) { @@ -674,7 +768,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_swapBuffers( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_syncRender( +void JNICALL Java_javax_media_j3d_NativePipeline_syncRender( JNIEnv *env, jobject obj, jlong ctx, @@ -685,7 +779,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_syncRender( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_newDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_newDisplayList( JNIEnv *env, jobject obj, jlong ctx, @@ -737,7 +831,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_newDisplayList( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_endDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_endDisplayList( JNIEnv *env, jobject obj, jlong ctx) @@ -748,7 +842,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_endDisplayList( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_callDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_callDisplayList( JNIEnv *env, jobject obj, jlong ctx, @@ -785,9 +879,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_callDisplayList( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_freeDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_freeDisplayList( JNIEnv *env, - jclass cl, + jobject obj, jlong ctx, jint id) { @@ -810,9 +904,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_freeDisplayList( has been deleted by java garbage collector. */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_freeTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_freeTexture( JNIEnv *env, - jclass cls, + jobject obj, jlong ctx, jint id) { @@ -839,28 +933,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_freeTexture( extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_isTexture3DAvailable( - JNIEnv *env, - jobject obj, - jlong ctx) -{ - return JNI_FALSE; -} - - -extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_getTextureColorTableSize( - JNIEnv *env, - jobject obj, - jlong ctx) -{ - // Not support by D3D - return 0; -} - - -extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_getTextureUnitCount( +jint JNICALL Java_javax_media_j3d_NativePipeline_getTextureUnitCount( JNIEnv *env, jobject obj, jlong ctx) @@ -871,12 +944,12 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_getTextureUnitCount( extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( +jlong JNICALL Java_javax_media_j3d_NativePipeline_createOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctx, jlong display, - jint window, jlong fbConfigListPtr, jint width, jint height) @@ -890,18 +963,18 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( GetCtx2(); d3dCtx->d3dPresent.BackBufferWidth = width; d3dCtx->d3dPresent.BackBufferHeight = height; - return SUCCEEDED(d3dCtx->resetSurface(env, obj)); + return SUCCEEDED(d3dCtx->resetSurface(env, cv)); } } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_destroyContext( +void JNICALL Java_javax_media_j3d_NativePipeline_destroyContext( JNIEnv *env, - jclass cl, + jobject obj, jlong display, - jint window, + jlong window, jlong ctx) { GetDevice(); @@ -911,36 +984,45 @@ void JNICALL Java_javax_media_j3d_Canvas3D_destroyContext( delete d3dCtx; unlock(); - Java_javax_media_j3d_Renderer_D3DCleanUp(env, cl); + Java_javax_media_j3d_NativePipeline_cleanupRenderer(env, obj); } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_destroyOffScreenBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_destroyOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctx, jlong display, jlong fbConfigListPtr, - jint window) + jlong window) { // do nothing, since the old buffer will destory // in createOffScreenBuffer + + // TODO : this means that we will hold onto the last off-screen buffer; + // we should clean this up at some point } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_readOffScreenBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_readOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctx, jint format, + jint dataType, + jobject data, jint width, jint height) { + void *imageObjPtr; + GetDevice(); - if (format == FORMAT_USHORT_GRAY) { - printf("[Java 3D] readOffScreenBuffer not support FORMAT_USHORT_GRAY\n"); + if (format == IMAGE_FORMAT_USHORT_GRAY) { + printf("[Java 3D] readOffScreenBuffer not support IMAGE_FORMAT_USHORT_GRAY\n"); return; } @@ -954,32 +1036,43 @@ void JNICALL Java_javax_media_j3d_Canvas3D_readOffScreenBuffer( } } - jclass cv_class = env->GetObjectClass(obj); + /* TODO : Need to re-write --- Chien. */ + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)env->GetPrimitiveArrayCritical((jarray)data, NULL); + + /* TODO : Can't assume it is a byte array */ + copyDataFromSurface(format, 0, 0, width, height, (jbyte *)imageObjPtr, + d3dCtx->backSurface); + + + } + else { + imageObjPtr = (void *)env->GetDirectBufferAddress(data); + + /* TODO --- Do something .... */ + } - jfieldID byteData_field = env->GetFieldID(cv_class, "byteBuffer", "[B"); - jbyteArray byteData_array = (jbyteArray) env->GetObjectField(obj, byteData_field); - jbyte *byteData = (jbyte *) env->GetPrimitiveArrayCritical( - byteData_array, NULL); - copyDataFromSurface(format, 0, 0, width, height, byteData, - d3dCtx->backSurface); - env->ReleasePrimitiveArrayCritical(byteData_array, byteData, 0); - return; + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0); + } + return; } extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_resizeD3DCanvas( +jint JNICALL Java_javax_media_j3d_NativePipeline_resizeD3DCanvas( JNIEnv *env, jobject obj, + jobject cv, jlong ctx) { int status; GetCtx2(); lock(); - status = d3dCtx->resize(env, obj); + status = d3dCtx->resize(env, cv); unlock(); return status; @@ -987,16 +1080,17 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_resizeD3DCanvas( extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_toggleFullScreenMode( +jint JNICALL Java_javax_media_j3d_NativePipeline_toggleFullScreenMode( JNIEnv *env, jobject obj, + jobject cv, jlong ctx) { int status; GetCtx2(); lock(); - status = d3dCtx->toggleMode(!d3dCtx->bFullScreen, env, obj); + status = d3dCtx->toggleMode(!d3dCtx->bFullScreen, env, cv); unlock(); if (status == RECREATEDFAIL) { return RECREATEDDRAW; @@ -1005,7 +1099,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_toggleFullScreenMode( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setFullSceneAntialiasing( +void JNICALL Java_javax_media_j3d_NativePipeline_setFullSceneAntialiasing( JNIEnv *env, jobject obj, jlong ctx, @@ -1019,7 +1113,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setFullSceneAntialiasing( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Renderer_D3DCleanUp( +void JNICALL Java_javax_media_j3d_NativePipeline_cleanupRenderer( JNIEnv *env, jobject obj) { @@ -1035,24 +1129,26 @@ void JNICALL Java_javax_media_j3d_Renderer_D3DCleanUp( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_ImageComponent2DRetained_freeD3DSurface( +void JNICALL Java_javax_media_j3d_NativePipeline_freeD3DSurface( JNIEnv *env, + jobject obj, jobject image, jint hashCode) { - + /* lockImage(); D3dImageComponent::remove(&RasterList, hashCode); unlockImage(); lockBackground(); D3dImageComponent::remove(&BackgroundImageList, hashCode); unlockBackground(); + */ } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_beginScene( +void JNICALL Java_javax_media_j3d_NativePipeline_beginScene( JNIEnv *env, jobject obj, jlong ctx) @@ -1063,7 +1159,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_beginScene( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_endScene( +void JNICALL Java_javax_media_j3d_NativePipeline_endScene( JNIEnv *env, jobject obj, jlong ctx) @@ -1074,7 +1170,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_endScene( extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_validGraphicsMode( JNIEnv *env, jobject obj) { @@ -1082,4 +1178,4 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode( EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode); return (devMode.dmBitsPerPel > 8); -} \ No newline at end of file +} diff --git a/src/native/d3d/D3dCtx.cpp b/src/native/d3d/D3dCtx.cpp index 32776c4..8ad3b2f 100644 --- a/src/native/d3d/D3dCtx.cpp +++ b/src/native/d3d/D3dCtx.cpp @@ -65,6 +65,7 @@ D3dCtx::D3dCtx(JNIEnv* env, jobject obj, HWND _hwnd, BOOL _offScreen, zWriteEnable = TRUE; zEnable = TRUE; + // TODO: THIS NEEDS TO BE REDONE WITH INFO FROM THE FBCONFIG PTR // this is the pixelFormat return from NativeConfigTemplate. minZDepth = vid & 0x3fffffff; if (vid & 0x80000000) @@ -269,6 +270,7 @@ VOID D3dCtx::releaseTexture() cubeMapTableLen = 0; unlockSurfaceList(); + /* lockImage(); D3dImageComponent::remove(&RasterList, this); unlockImage(); @@ -276,6 +278,7 @@ VOID D3dCtx::releaseTexture() lockBackground(); D3dImageComponent::remove(&BackgroundImageList, this); unlockBackground(); + */ // free list0 freeList(); @@ -346,8 +349,10 @@ VOID D3dCtx::releaseVB() VOID D3dCtx::release() { + /* D3dImageComponent::removeAll(&BackgroundImageList); D3dImageComponent::removeAll(&RasterList); + */ releaseTexture(); SafeFree(bindTextureId); bindTextureIdLen = 0; diff --git a/src/native/d3d/D3dDriverInfo.cpp b/src/native/d3d/D3dDriverInfo.cpp index fdad7a9..57d7b8a 100644 --- a/src/native/d3d/D3dDriverInfo.cpp +++ b/src/native/d3d/D3dDriverInfo.cpp @@ -362,8 +362,10 @@ VOID D3dDriverInfo::initialize(JNIEnv *env) D3dCtx::setImplicitMultisamplingProperty(env); + /* RasterList.init(); BackgroundImageList.init(); + */ // Setup Global constant Ambient light ambientLight.Type = D3DLIGHT_DIRECTIONAL; diff --git a/src/native/d3d/D3dImageComponent.hpp b/src/native/d3d/D3dImageComponent.hpp index fef2ed8..8226d30 100644 --- a/src/native/d3d/D3dImageComponent.hpp +++ b/src/native/d3d/D3dImageComponent.hpp @@ -46,7 +46,8 @@ public: static VOID removeAll(D3dImageComponent *list); }; -extern D3dImageComponent RasterList; -extern D3dImageComponent BackgroundImageList; - +/* + extern D3dImageComponent RasterList; + extern D3dImageComponent BackgroundImageList; +*/ #endif diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp index 236827a..12ff9d6 100644 --- a/src/native/d3d/D3dUtil.cpp +++ b/src/native/d3d/D3dUtil.cpp @@ -966,8 +966,8 @@ void copyDataFromSurface(jint internalFormat, (yoffset*lockedRect.Pitch); - if ((internalFormat == FORMAT_BYTE_RGBA) || - (internalFormat == FORMAT_BYTE_RGB)) { + if ((internalFormat == IMAGE_FORMAT_BYTE_RGBA) || + (internalFormat == IMAGE_FORMAT_BYTE_RGB)) { dstPitch = subWidth << 2; destRow += (subHeight-1)*dstPitch; @@ -1208,7 +1208,7 @@ void copyDataFromSurface(jint internalFormat, } } } - } else if (internalFormat == FORMAT_BYTE_LA) { + } else if (internalFormat == IMAGE_FORMAT_BYTE_LA) { int gshift = firstBit(ddpf.dwGBitMask) + ucountBits(ddpf.dwGBitMask) - 8; int ashift = firstBit(ddpf.dwRGBAlphaBitMask) + @@ -1370,7 +1370,7 @@ void copyDataFromSurface(jint internalFormat, } } - } else if (internalFormat == FORMAT_BYTE_GRAY) { + } else if (internalFormat == IMAGE_FORMAT_BYTE_GRAY) { int gshift = firstBit(ddpf.dwGBitMask) + ucountBits(ddpf.dwGBitMask) - 8; dstPitch = subWidth; @@ -1482,7 +1482,7 @@ void copyDataFromSurface(jint internalFormat, } } else { - // FORMAT_USHORT_GRAY + // IMAGE_FORMAT_USHORT_GRAY printf("[Java 3D] copyDataFromSurface: Format not support %d\n", internalFormat); } @@ -8997,7 +8997,7 @@ void copyDataToSurface(jint storedFormat, } int offset = tilew*imgYOffset + imgXOffset; switch (storedFormat) { - case FORMAT_BYTE_RGBA : + case IMAGE_FORMAT_BYTE_RGBA : // This is the one we use when byReference = false copyDataToSurfaceRGBA(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, @@ -9006,7 +9006,7 @@ void copyDataToSurface(jint storedFormat, xoffset, yoffset, xlimit, ylimit, tilew); break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: copyDataToSurfaceRGB(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, lockedRect.Pitch, @@ -9014,7 +9014,7 @@ void copyDataToSurface(jint storedFormat, xoffset, yoffset, xlimit, ylimit, tilew); break; - case FORMAT_BYTE_ABGR: + case IMAGE_FORMAT_BYTE_ABGR: copyDataToSurfaceABGR(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, lockedRect.Pitch, @@ -9022,7 +9022,7 @@ void copyDataToSurface(jint storedFormat, xoffset, yoffset, xlimit, ylimit, tilew); break; - case FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_BGR: copyDataToSurfaceBGR(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, lockedRect.Pitch, @@ -9030,7 +9030,7 @@ void copyDataToSurface(jint storedFormat, xoffset, yoffset, xlimit, ylimit, tilew); break; - case FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_LA: copyDataToSurfaceLA(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, lockedRect.Pitch, @@ -9038,7 +9038,7 @@ void copyDataToSurface(jint storedFormat, xoffset, yoffset, xlimit, ylimit, tilew); break; - case FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_BYTE_GRAY: copyDataToSurfaceGray(internalFormat, &ddpf, (unsigned char *) lockedRect.pBits, lockedRect.Pitch, @@ -10839,7 +10839,7 @@ void copyDataToVolume(jint storedFormat, switch (storedFormat) { - case FORMAT_BYTE_RGBA : + case IMAGE_FORMAT_BYTE_RGBA : // This is the one we use when byReference = false data += (imgOffset << 2); srcSlicePitch <<= 2; @@ -10857,7 +10857,7 @@ void copyDataToVolume(jint storedFormat, } break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: data += (imgOffset*3); srcSlicePitch *= 3; @@ -10873,7 +10873,7 @@ void copyDataToVolume(jint storedFormat, data += srcSlicePitch; } break; - case FORMAT_BYTE_ABGR: + case IMAGE_FORMAT_BYTE_ABGR: data += (imgOffset << 2); srcSlicePitch <<= 2; @@ -10889,7 +10889,7 @@ void copyDataToVolume(jint storedFormat, data += srcSlicePitch; } break; - case FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_BGR: data += (imgOffset*3); srcSlicePitch *= 3; @@ -10905,7 +10905,7 @@ void copyDataToVolume(jint storedFormat, data += srcSlicePitch; } break; - case FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_LA: data += (imgOffset << 1); srcSlicePitch <<= 1; @@ -10921,7 +10921,7 @@ void copyDataToVolume(jint storedFormat, data += srcSlicePitch; } break; - case FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_BYTE_GRAY: data += imgOffset; for (i = zoffset; i < zlimit; i++) { @@ -11044,17 +11044,17 @@ LPDIRECT3DTEXTURE9 createSurfaceFromImage(JNIEnv *env, switch (internalFormat) { - case FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_RGBA: internalFormat = J3D_RGBA; break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: internalFormat = J3D_RGB; break; - case FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_LA: internalFormat = LUMINANCE_ALPHA; break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: internalFormat = LUMINANCE; break; default: @@ -11073,7 +11073,7 @@ LPDIRECT3DTEXTURE9 createSurfaceFromImage(JNIEnv *env, } if (imageYdown != NULL) { - if (storedFormat != FORMAT_USHORT_GRAY) { + if (storedFormat != IMAGE_FORMAT_USHORT_GRAY) { jbyte *byteData = (jbyte *) (env->GetPrimitiveArrayCritical( imageYdown, NULL)); copyDataToSurface(storedFormat, internalFormat, 0, 0, 0, 0, @@ -11367,7 +11367,7 @@ void copyDataToCubeMap(jint storedFormat, int offset = tilew*imgYOffset + imgXOffset; switch (storedFormat) { - case FORMAT_BYTE_RGBA : + case IMAGE_FORMAT_BYTE_RGBA : // This is the one we use when byReference = false if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { @@ -11391,7 +11391,7 @@ void copyDataToCubeMap(jint storedFormat, xlimit, ylimit, tilew); } break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { copyDataToSurfaceRGB(internalFormat, &ddpf, @@ -11410,7 +11410,7 @@ void copyDataToCubeMap(jint storedFormat, xlimit, ylimit, tilew); } break; - case FORMAT_BYTE_ABGR: + case IMAGE_FORMAT_BYTE_ABGR: if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { copyDataToSurfaceABGR(internalFormat, &ddpf, @@ -11429,7 +11429,7 @@ void copyDataToCubeMap(jint storedFormat, xlimit, ylimit, tilew); } break; - case FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_BGR: if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { copyDataToSurfaceBGR(internalFormat, &ddpf, @@ -11448,7 +11448,7 @@ void copyDataToCubeMap(jint storedFormat, xlimit, ylimit, tilew); } break; - case FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_LA: if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { copyDataToSurfaceLA(internalFormat, &ddpf, @@ -11467,7 +11467,7 @@ void copyDataToCubeMap(jint storedFormat, xlimit, ylimit, tilew); } break; - case FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_BYTE_GRAY: if ((face == D3DCUBEMAP_FACE_NEGATIVE_Y) || (face == D3DCUBEMAP_FACE_POSITIVE_Y)) { copyDataToSurfaceGray(internalFormat, &ddpf, diff --git a/src/native/d3d/D3dUtil.hpp b/src/native/d3d/D3dUtil.hpp index 0117e47..c0961a4 100644 --- a/src/native/d3d/D3dUtil.hpp +++ b/src/native/d3d/D3dUtil.hpp @@ -142,7 +142,6 @@ extern VOID unlockSurfaceList(); extern VOID freeSurface(LPDIRECT3DBASETEXTURE9 surf); extern VOID freePointer(void* surf); extern VOID freePointerList(); -extern VOID setWindowCallback(HWND topHwnd, HWND hwnd); extern char* getErrorMessage(int idx); extern HWND getTopWindow(HWND hwnd); diff --git a/src/native/d3d/GeometryArrayRetained.cpp b/src/native/d3d/GeometryArrayRetained.cpp index fcafd4b..2d947a7 100644 --- a/src/native/d3d/GeometryArrayRetained.cpp +++ b/src/native/d3d/GeometryArrayRetained.cpp @@ -3195,7 +3195,6 @@ void setTextureCoordPointers(JNIEnv *env, D3dCtx* d3dCtx, LPDIRECT3DDEVICE9 device, D3DDRAWPRIMITIVESTRIDEDDATA *strideData, - jint pass, jint texoff, jint texStride, jint ts, @@ -3204,7 +3203,6 @@ void setTextureCoordPointers(JNIEnv *env, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, DWORD* vertexFormat, // Used by executeGeometryArray() & // executeIndexedGeometryArray() only @@ -3216,7 +3214,6 @@ void setTextureCoordPointers(JNIEnv *env, jintArray texindices) { - jint *texUnitStateMap = NULL; jint *texCoordSetMapOffset = NULL; jint *initialTexIndices = NULL; jint *texCoordSetMap = NULL; @@ -3226,6 +3223,9 @@ void setTextureCoordPointers(JNIEnv *env, BOOL nonVAGeom = (verts != NULL); int texSetInVB = 0; + // TODO : + int pass = -1; + /* * In case of automatic texture generation, * (vformat & GA_TEXTURE_COORDINATE) may equal to zero so we @@ -3256,259 +3256,167 @@ void setTextureCoordPointers(JNIEnv *env, initialTexIndices = (jint *) env->GetPrimitiveArrayCritical(texindices, NULL); } - if (pass >= 0) { - /* - * Single texture coordinate used or in multi-pass mode. - * In multi-pass mode, texture stage 0 is set so we - * should not use - * setTextureStage(d3dCtx, device, 0, pass); - */ - - genMode = setTextureStage(d3dCtx, device, 0, 0); - -#ifdef TEXDEBUG - printf("*** Single Pass *** %d, nonVAGeom %d, buildDL %d, numActiveTexUnit, texCoordMapLength %d, texDef %d, genMode %d \n", pass, nonVAGeom, (d3dCtx->currDisplayListID > 0), numActiveTexUnit, texCoordMapLength, textureDefined, genMode); -#endif - - if ((texCoordMapLength > 0) && - (pass < texCoordMapLength)) { - offsetOrTexset = (nonVAGeom ? - texCoordSetMapOffset[pass] : texCoordSetMap[pass]); - } else { - // TexUnitState is not used or disable, - // so by default we use texUnitIndex 0 - offsetOrTexset = 0; - } - - if (genMode != TEX_OBJ_LINEAR) { - // Only Object Linear Mode will not use DisplayList at - // all. That mean genMode must be correctly set before - // enter this Geometry execute() function/ - // In non displaylist mode genMode may not set correctly - // when so we can't rely on it. - if (textureDefined) { - if (offsetOrTexset != -1) { - if (nonVAGeom) { - // In executeGeometryArray() or executeIndexedGeometryArray() - strideData->textureCoordsPtr[0] = - &verts[texoff + offsetOrTexset]; - } else if (initialTexIndices != NULL) { - // executeGeometryArrayVA() - strideData->textureCoordsPtr[0] = - &(texCoordPointer[offsetOrTexset][initialTexIndices[offsetOrTexset]*texStride]); - } else { // executeIndexedGeometryArrayVA() - strideData->textureCoordsPtr[0] = - &(texCoordPointer[offsetOrTexset][0]); - } - - strideData->textureCoordsStride[0] = texStride; - *vertexFormat |= (TexFormatSizeTable[ts] << 16); - d3dCtx->texSetUsed = 1; - strideData->texCoordPosition[0] = offsetOrTexset; - d3dCtx->texStride[0] = ts; - setTexTransformStageFlag(d3dCtx, device, 0, ts, genMode); -#ifdef TEXDEBUG - printf("[pass 0] Non Object Linear, texDefined, ts=%d\n", ts); -#endif - } - } else { - // may be automatic texture generation used - // TexSetUsed remain unchange i.e. 0 since we will not - // allocate VB space for texture coords. - setTexTransformStageFlag(d3dCtx, device, 0, - d3dCtx->texCoordFormat[0], genMode); -#ifdef TEXDEBUG - printf("[pass 0] Non Object Linear, No texDefined, ts=%d\n", - d3dCtx->texCoordFormat[0]); -#endif - } - } else { - // Automatic texture generation Object Linear - // strideData->textureCoordsPtr[0] & - // strideData->textureCoordsStride[0] - // are not use in VertexBuffer texture copy so - // it doesn't matter to set them using default. - setDefaultTextureCoordPointers(d3dCtx, strideData, - vertexFormat, - d3dCtx->texCoordFormat[0], - genMode, 0); - setTexTransformStageFlag(d3dCtx, device, 0, - d3dCtx->texCoordFormat[0], genMode); - d3dCtx->texSetUsed = 1; -#ifdef TEXDEBUG - printf("[pass 0] Object Linear, ts=%d\n", d3dCtx->texCoordFormat[0]); -#endif - } - texSetInVB = d3dCtx->texSetUsed; - - } else { - // DisplayList is used for multiple texture single pass mode - // Or when go through the VertexArray in OGL, pass = -1 - int tus; + // DisplayList is used for multiple texture single pass mode + // Or when go through the VertexArray in OGL, pass = -1 + int tus; #ifdef TEXDEBUG - printf("*** Multiple Pass *** %d, nonVAGeom %d, buildDL %d, numActiveTexUnit %d, texCoordMapLength %d, texDef %d\n", pass, + printf("*** Multiple Pass *** %d, nonVAGeom %d, buildDL %d, numActiveTexUnit %d, texCoordMapLength %d, texDef %d\n", pass, nonVAGeom, (d3dCtx->currDisplayListID > 0), numActiveTexUnit, texCoordMapLength, textureDefined); #endif - if (tunitstatemap != NULL) { - texUnitStateMap = (jint *) env->GetPrimitiveArrayCritical(tunitstatemap, NULL); - } - for (textureUnitIndex = 0; textureUnitIndex < numActiveTexUnit; - textureUnitIndex++) { - tus = (texUnitStateMap != NULL ? - texUnitStateMap[textureUnitIndex]: textureUnitIndex); + for (textureUnitIndex = 0; textureUnitIndex < numActiveTexUnit; + textureUnitIndex++) { - if (d3dCtx->currDisplayListID > 0) { - genMode = setTextureStage(d3dCtx, device, - textureUnitIndex, tus); - } else { - // This happen when we switch from displayList to - // vertexArray mode. The displayList is already - // built with 1-1 mapping so we can't use the - // textureUnitIndex Mapping - genMode = setTextureStage(d3dCtx, device, - textureUnitIndex, - textureUnitIndex); - } + tus = textureUnitIndex; + + if (d3dCtx->currDisplayListID > 0) { + genMode = setTextureStage(d3dCtx, device, + textureUnitIndex, tus); + } else { + // This happen when we switch from displayList to + // vertexArray mode. The displayList is already + // built with 1-1 mapping so we can't use the + // textureUnitIndex Mapping + genMode = setTextureStage(d3dCtx, device, + textureUnitIndex, + textureUnitIndex); + } #ifdef TEXDEBUG - printf("[pass %d] genMode %d, tus %d\n", textureUnitIndex, - genMode, tus); -#endif - if (genMode != TEX_OBJ_LINEAR) { - if (textureDefined) { - if (tus < texCoordMapLength) { - offsetOrTexset = (nonVAGeom ? - texCoordSetMapOffset[tus]:texCoordSetMap[tus]); - - if (offsetOrTexset != -1) { - if (nonVAGeom) { - strideData->textureCoordsPtr[textureUnitIndex] = - &verts[texoff + offsetOrTexset]; - } else if (initialTexIndices != NULL) { - strideData->textureCoordsPtr[textureUnitIndex] = - &(texCoordPointer[offsetOrTexset][initialTexIndices[offsetOrTexset]*texStride]); - } else { - strideData->textureCoordsPtr[textureUnitIndex] = - &(texCoordPointer[offsetOrTexset][0]); - } - strideData->textureCoordsStride[textureUnitIndex] = texStride; - strideData->texCoordPosition[textureUnitIndex] - = offsetOrTexset; - *vertexFormat |= (TexFormatSizeTable[ts] << (textureUnitIndex*2 + 16)); - d3dCtx->texStride[textureUnitIndex] = ts; - setTexTransformStageFlag(d3dCtx, device, - textureUnitIndex, - ts, genMode); - texSetInVB++; -#ifdef TEXDEBUG - printf("[pass %d] Non Object Linear, texDefined, ts=%d, tus %d\n", textureUnitIndex, ts, tus); + printf("[pass %d] genMode %d, tus %d\n", textureUnitIndex, + genMode, tus); #endif + if (genMode != TEX_OBJ_LINEAR) { + if (textureDefined) { + if (tus < texCoordMapLength) { + offsetOrTexset = (nonVAGeom ? + texCoordSetMapOffset[tus]:texCoordSetMap[tus]); + + if (offsetOrTexset != -1) { + if (nonVAGeom) { + strideData->textureCoordsPtr[textureUnitIndex] = + &verts[texoff + offsetOrTexset]; + } else if (initialTexIndices != NULL) { + strideData->textureCoordsPtr[textureUnitIndex] = + &(texCoordPointer[offsetOrTexset][initialTexIndices[offsetOrTexset]*texStride]); } else { - // This texture status is disable, this - // should not happen in D3D since - // TextureBin always compact unused state - // - unless when DisplayList is build and - // automatic texture generation - // used. Since if DL use - // updateAttributes() not yet invoke to - // set genMode correctly. - if (debug && (d3dCtx->currDisplayListID <= 0)) { - printf("[Java3D] TextureBin not compact textureUnitState correctly, numActiveTex %d, disableUnit %d, current mapped Texture Unit %d\n", numActiveTexUnit, tus, textureUnitIndex); - } - setDefaultTextureCoordPointers(d3dCtx, strideData, - vertexFormat, ts, - genMode, - textureUnitIndex); - setTexTransformStageFlag(d3dCtx, device, - textureUnitIndex, - ts, genMode); - texSetInVB++; + strideData->textureCoordsPtr[textureUnitIndex] = + &(texCoordPointer[offsetOrTexset][0]); + } + strideData->textureCoordsStride[textureUnitIndex] = texStride; + strideData->texCoordPosition[textureUnitIndex] + = offsetOrTexset; + *vertexFormat |= (TexFormatSizeTable[ts] << (textureUnitIndex*2 + 16)); + d3dCtx->texStride[textureUnitIndex] = ts; + setTexTransformStageFlag(d3dCtx, device, + textureUnitIndex, + ts, genMode); + texSetInVB++; #ifdef TEXDEBUG - printf("[pass %d] Non Object Linear, texDefined, ts=%d\n", textureUnitIndex, ts); + printf("[pass %d] Non Object Linear, texDefined, ts=%d, tus %d\n", textureUnitIndex, ts, tus); #endif - } } else { - // Internal error, should not happen. - if (debug) { - printf("[Java3D] TextureCoordMapLength length %d, is smaller than texture unit %d, map texture unit %d\n", texCoordMapLength, tus, textureUnitIndex); + // This texture status is disable, this + // should not happen in D3D since + // TextureBin always compact unused state + // - unless when DisplayList is build and + // automatic texture generation + // used. Since if DL use + // updateAttributes() not yet invoke to + // set genMode correctly. + if (debug && (d3dCtx->currDisplayListID <= 0)) { + printf("[Java3D] TextureBin not compact textureUnitState correctly, numActiveTex %d, disableUnit %d, current mapped Texture Unit %d\n", numActiveTexUnit, tus, textureUnitIndex); } setDefaultTextureCoordPointers(d3dCtx, strideData, vertexFormat, ts, - TEX_GEN_INVALID, + genMode, textureUnitIndex); setTexTransformStageFlag(d3dCtx, device, - textureUnitIndex, ts, - genMode); - + textureUnitIndex, + ts, genMode); texSetInVB++; #ifdef TEXDEBUG - printf("[pass %d] Non Object Linear, texDefined, offset/texset = -1, ts=%d\n", textureUnitIndex, ts); + printf("[pass %d] Non Object Linear, texDefined, ts=%d\n", textureUnitIndex, ts); #endif } } else { - // May be in automatically texture coordinate - // generation mode. - // May have trouble if automatically texture - // coordinate not used. Note that we pass ts = 0 - // so that copyVertexToVB() will not inc. the - // stride for this unused tex stage. - - // It is also the case in buildGA() case when - // numActiveTexUnit is 1 by default even though - // texture is not used. - /* - if ((d3dCtx->currDisplayListID <= 0) && - (genMode == TEX_GEN_NONE)) { - // application error, use default TexCoord - setDefaultTextureCoordPointers(d3dCtx, strideData, - vertexFormat, - ts, - TEX_GEN_NONE, - textureUnitIndex); - texSetInVB++; - } - */ - + // Internal error, should not happen. + if (debug) { + printf("[Java3D] TextureCoordMapLength length %d, is smaller than texture unit %d, map texture unit %d\n", texCoordMapLength, tus, textureUnitIndex); + } setDefaultTextureCoordPointers(d3dCtx, strideData, - vertexFormat, - 0, - // This must be < 0 - TEX_GEN_AUTO, + vertexFormat, ts, + TEX_GEN_INVALID, textureUnitIndex); - setTexTransformStageFlag(d3dCtx, device, textureUnitIndex, - d3dCtx->texCoordFormat[textureUnitIndex], genMode); - - + setTexTransformStageFlag(d3dCtx, device, + textureUnitIndex, ts, + genMode); + + texSetInVB++; #ifdef TEXDEBUG - printf("[pass %d] Non Object Linear, No texDefined, ts=0\n", textureUnitIndex); + printf("[pass %d] Non Object Linear, texDefined, offset/texset = -1, ts=%d\n", textureUnitIndex, ts); #endif } } else { - // Automatic Texture generation Object Linear is used + // May be in automatically texture coordinate + // generation mode. + // May have trouble if automatically texture + // coordinate not used. Note that we pass ts = 0 + // so that copyVertexToVB() will not inc. the + // stride for this unused tex stage. + + // It is also the case in buildGA() case when + // numActiveTexUnit is 1 by default even though + // texture is not used. + /* + if ((d3dCtx->currDisplayListID <= 0) && + (genMode == TEX_GEN_NONE)) { + // application error, use default TexCoord + setDefaultTextureCoordPointers(d3dCtx, strideData, + vertexFormat, + ts, + TEX_GEN_NONE, + textureUnitIndex); + texSetInVB++; + } + */ + setDefaultTextureCoordPointers(d3dCtx, strideData, vertexFormat, - d3dCtx->texCoordFormat[textureUnitIndex], - genMode, + 0, + // This must be < 0 + TEX_GEN_AUTO, textureUnitIndex); setTexTransformStageFlag(d3dCtx, device, textureUnitIndex, d3dCtx->texCoordFormat[textureUnitIndex], genMode); - texSetInVB++; + + #ifdef TEXDEBUG - printf("[pass %d] Object Linear, No texDefined, ts=%d\n", textureUnitIndex, d3dCtx->texCoordFormat[textureUnitIndex]); + printf("[pass %d] Non Object Linear, No texDefined, ts=0\n", textureUnitIndex); #endif } - } - d3dCtx->texSetUsed = numActiveTexUnit; + } else { + // Automatic Texture generation Object Linear is used + setDefaultTextureCoordPointers(d3dCtx, strideData, + vertexFormat, + d3dCtx->texCoordFormat[textureUnitIndex], + genMode, + textureUnitIndex); + setTexTransformStageFlag(d3dCtx, device, textureUnitIndex, + d3dCtx->texCoordFormat[textureUnitIndex], genMode); + texSetInVB++; #ifdef TEXDEBUG - printf("No of texSetInVB %d, numActiveTexUnit %d\n", - texSetInVB, numActiveTexUnit); + printf("[pass %d] Object Linear, No texDefined, ts=%d\n", textureUnitIndex, d3dCtx->texCoordFormat[textureUnitIndex]); #endif - if (texUnitStateMap != NULL) { - env->ReleasePrimitiveArrayCritical(tunitstatemap, texUnitStateMap, NULL); } } + d3dCtx->texSetUsed = numActiveTexUnit; +#ifdef TEXDEBUG + printf("No of texSetInVB %d, numActiveTexUnit %d\n", + texSetInVB, numActiveTexUnit); +#endif + if (texCoordSetMapOffset != NULL) { env->ReleasePrimitiveArrayCritical(texUnitOffset, @@ -3540,7 +3448,6 @@ void executeGeometryArrayVA( jboolean isNonUniformScale, jboolean modAlpha, float alpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -3553,11 +3460,9 @@ void executeGeometryArrayVA( jbyte* bclrs, jint initialNormalIndex, jfloat* norms, - int pass, // or texUnitIndex int texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jintArray texindices, jint texStride, jfloat** texCoordPointer, @@ -3645,13 +3550,12 @@ void executeGeometryArrayVA( // setup texture pointer setTextureCoordPointers(env, d3dCtx, device, &strideData, - pass, 0, texStride, ts, + 0, texStride, ts, textureDefined, tcoordsetmap, texCoordMapLength, NULL, numActiveTexUnit, - tunitstatemap, &vertexFormat, NULL, texCoordPointer, texindices); @@ -3688,14 +3592,13 @@ void executeGeometryArrayVA( /* execute geometry array with java array format */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_executeVABuffer( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -3712,11 +3615,9 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffer( jintArray vertexAttrSizes, jintArray vertexAttrIndices, jobjectArray vertexAttrData, - jint pass, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jintArray texindices, jint texStride, jobjectArray texCoords, @@ -3788,13 +3689,13 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffer( } executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, false, 0, multiScreen, ignoreVertexColors, + isNonUniformScale, false, 0, ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, norms, - pass, texCoordMapLength, - tcoordsetmap,numActiveTexUnit, tunitstatemap, + texCoordMapLength, + tcoordsetmap,numActiveTexUnit, texindices,texStride,texCoordPointer, NULL, NULL, cdirty); @@ -3806,14 +3707,13 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffer( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVA( +void JNICALL Java_javax_media_j3d_NativePipeline_executeVA( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -3829,12 +3729,10 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVA( jint vertexAttrCount, jintArray vertexAttrSizes, jintArray vertexAttrIndices, - jobjectArray vertexAttrData, - jint pass, + jobjectArray vertexAttrData, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jintArray texindices, jint texStride, jobjectArray texCoords, @@ -3899,12 +3797,12 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVA( } executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, isNonUniformScale, false, 0, - multiScreen, ignoreVertexColors, + ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, - norms, pass, texCoordMapLength, - tcoordsetmap,numActiveTexUnit, tunitstatemap, + norms, texCoordMapLength, + tcoordsetmap,numActiveTexUnit, texindices,texStride,texCoordPointer, NULL, NULL, cdirty); @@ -3936,57 +3834,38 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVA( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_setGlobalAlpha( - JNIEnv *env, - jobject obj, - jlong ctx, - jfloat alpha) -{ - // not use in D3D -} - - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_disableGlobalAlpha( +void JNICALL Java_javax_media_j3d_NativePipeline_disableGlobalAlpha( JNIEnv *env, jobject obj, jlong ctx, + jobject geo, jint vformat, jboolean useAlpha, jboolean ignoreVertexColors) { - // not use in D3D + // not used in D3D } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_setVertexFormat( +void JNICALL Java_javax_media_j3d_NativePipeline_setVertexFormat( JNIEnv *env, jobject obj, jlong ctxInfo, + jobject geo, jint vformat, jboolean useAlpha, jboolean ignoreVertexColors) { - // not use in D3D + // not used in D3D } -extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_GeometryArrayRetained_globalAlphaSUN - (JNIEnv *env, jobject obj, jlong ctx) -{ - return JNI_FALSE; -} - - - void executeGeometryArray(JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean modAlpha, // buildGA, should alpha be mode jfloat alpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, jint texCoordSetCount, @@ -3994,8 +3873,7 @@ void executeGeometryArray(JNIEnv *env, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, - jfloat* verts, jfloatArray carray, jint pass, + jfloat* verts, jfloatArray carray, jdoubleArray xform, jdoubleArray nxform, jint cDirty, jboolean useAlpha) // Should alpha be sent down @@ -4108,13 +3986,12 @@ void executeGeometryArray(JNIEnv *env, // setup texture pointer setTextureCoordPointers(env, d3dCtx, device, &strideData, - pass, texoff, stride, ts, + texoff, stride, ts, (vformat & GA_TEXTURE_COORDINATE), NULL, texCoordMapLength, texUnitOffset, numActiveTexUnit, - tunitstatemap, &vertexFormat, verts, NULL, NULL); @@ -4151,12 +4028,12 @@ void executeGeometryArray(JNIEnv *env, /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: buildGA * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZFZIIII[II[II[I[D[D[F)V */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGA(JNIEnv *env, +void JNICALL Java_javax_media_j3d_NativePipeline_buildGA(JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean updateAlpha, float alpha, @@ -4193,7 +4070,6 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGA(JNIEnv *env, obj, ctx, geo, geo_type, isNonUniformScale, updateAlpha, alpha, - false, ignoreVertexColors, startVIndex, vcount, @@ -4203,9 +4079,7 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGA(JNIEnv *env, texCoordMapLength, texUnitOffset, texCoordMapLength, - NULL, verts, NULL, - -1, xform, nxform, javax_media_j3d_GeometryArrayRetained_VERTEX_CHANGED, false); @@ -4216,20 +4090,17 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGA(JNIEnv *env, extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, +void JNICALL Java_javax_media_j3d_NativePipeline_execute(JNIEnv *env, jobject obj, jlong ctx,jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, jint texCoordSetCount, jintArray texCoordSetMapArray, jint texCoordMapLength, jintArray texUnitOffset, - jint numActiveTexUnit, - jintArray tunitstatemap, - jint vertexAttrCount, jintArray vertexAttrSizes, - jfloatArray varray, jfloatArray carray, - jint texUnitIndex, jint cDirty) + jint numActiveTexUnit, + jint vertexAttrCount, jintArray vertexAttrSizes, + jfloatArray varray, jfloatArray carray, jint cDirty) { jfloat *verts = NULL; @@ -4244,13 +4115,12 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, executeGeometryArray(env, obj, ctx, geo, geo_type, isNonUniformScale, false, - 0, multiScreen, - ignoreVertexColors, startVIndex, + 0, ignoreVertexColors, startVIndex, vcount, vformat, texCoordSetCount, texCoordSetMapArray, texCoordMapLength, texUnitOffset, - numActiveTexUnit, tunitstatemap, - verts, carray, texUnitIndex, NULL, NULL, cDirty,useAlpha); + numActiveTexUnit, + verts, carray, NULL, NULL, cDirty,useAlpha); env->ReleasePrimitiveArrayCritical( varray, verts, 0); @@ -4259,10 +4129,9 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, /* interleaved data with nio buffer as data format */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer(JNIEnv *env, +void JNICALL Java_javax_media_j3d_NativePipeline_executeInterleavedBuffer(JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, - jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, + jboolean isNonUniformScale, jboolean useAlpha, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, @@ -4270,9 +4139,7 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer jintArray texCoordSetMapArray, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, - jobject varray, jfloatArray carray, - jint texUnitIndex, jint cDirty) { + jobject varray, jfloatArray carray, jint cDirty) { jfloat *verts = NULL; @@ -4289,20 +4156,22 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer executeGeometryArray(env, obj, ctx, geo, geo_type, isNonUniformScale, false, - 0, multiScreen, - ignoreVertexColors, startVIndex, + 0, ignoreVertexColors, startVIndex, vcount, vformat, texCoordSetCount, texCoordSetMapArray, texCoordMapLength, texUnitOffset, - numActiveTexUnit, tunitstatemap, - verts, carray, texUnitIndex, NULL, NULL, cDirty,useAlpha); + numActiveTexUnit, + verts, carray, NULL, NULL, cDirty,useAlpha); } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_freeD3DArray - (JNIEnv *env, jobject geo, jboolean deleteVB) +void JNICALL Java_javax_media_j3d_NativePipeline_freeD3DArray( + JNIEnv *env, + jobject obj, + jobject geo, + jboolean deleteVB) { lockGeometry(); @@ -4340,7 +4209,6 @@ void executeIndexedGeometryArray(JNIEnv *env, jboolean isNonUniformScale, jboolean modAlpha, // buildGA, should alpha be mode jfloat alpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -4349,8 +4217,7 @@ void executeIndexedGeometryArray(JNIEnv *env, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, - jfloat* verts, jfloatArray carray, jint pass, + jfloat* verts, jfloatArray carray, jdoubleArray xform, jdoubleArray nxform, jint cDirty, jboolean useAlpha, @@ -4463,13 +4330,12 @@ void executeIndexedGeometryArray(JNIEnv *env, // setup texture pointer setTextureCoordPointers(env, d3dCtx, device, &strideData, - pass, texoff, stride, ts, + texoff, stride, ts, (vformat & GA_TEXTURE_COORDINATE), NULL, texCoordMapLength, texUnitOffset, numActiveTexUnit, - tunitstatemap, &vertexFormat, verts, NULL, NULL); @@ -4514,12 +4380,11 @@ void executeIndexedGeometryArray(JNIEnv *env, extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometry( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometry( JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -4530,9 +4395,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jintArray texCoordSetMapArray, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, - jfloatArray varray, jfloatArray carray, - jint texUnitIndex, jint cDirty, + jfloatArray varray, jfloatArray carray, jint cDirty, jintArray indexCoord) { jfloat *verts = NULL; @@ -4547,7 +4410,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo executeIndexedGeometryArray(env, obj, ctx, geo, geo_type, isNonUniformScale, - false, 0, multiScreen, + false, 0, ignoreVertexColors, vcount, vformat, texCoordSetCount, @@ -4555,10 +4418,8 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo texCoordMapLength, texUnitOffset, numActiveTexUnit, - tunitstatemap, verts, carray, - texUnitIndex, NULL, NULL, cDirty, useAlpha, @@ -4570,12 +4431,11 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometryBuffer( JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -4584,9 +4444,8 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jintArray texCoordSetMapArray, jint texCoordMapLength, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray tunitstatemap, jobject varray, jfloatArray carray, - jint texUnitIndex, jint cDirty, + jint cDirty, jintArray indexCoord) { jfloat *verts = NULL; @@ -4601,7 +4460,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo executeIndexedGeometryArray(env, obj, ctx, geo, geo_type, isNonUniformScale, - false, 0, multiScreen, + false, 0, ignoreVertexColors, vcount, vformat, texCoordSetCount, @@ -4609,10 +4468,8 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo texCoordMapLength, texUnitOffset, numActiveTexUnit, - tunitstatemap, verts, carray, - texUnitIndex, NULL, NULL, cDirty, useAlpha, @@ -4623,7 +4480,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeometry( +void JNICALL Java_javax_media_j3d_NativePipeline_buildIndexedGeometry( JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, @@ -4661,7 +4518,6 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeome executeIndexedGeometryArray(env, obj, ctx, geo, geo_type, isNonUniformScale, updateAlpha, alpha, - false, ignoreVertexColors, vertexCount, vformat, @@ -4669,10 +4525,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeome texCoordSetMapArray, texCoordMapLength, texUnitOffset, - texCoordMapLength, - NULL, + texCoordMapLength, verts, - NULL, -1, + NULL, xform, nxform, javax_media_j3d_GeometryArrayRetained_VERTEX_CHANGED| javax_media_j3d_GeometryArrayRetained_INDEX_CHANGED, @@ -4694,7 +4549,6 @@ void executeIndexedGeometryArrayVA( jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -4705,12 +4559,10 @@ void executeIndexedGeometryArrayVA( jdouble* dverts, jfloat* fclrs, jbyte* bclrs, - jfloat* norms, - jint pass, + jfloat* norms, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jfloat** texCoordPointer, jint cDirty, @@ -4789,14 +4641,13 @@ void executeIndexedGeometryArrayVA( // setup texture pointer setTextureCoordPointers(env, d3dCtx, device, &strideData, - pass, 0, + 0, texStride, ts, textureDefined, tcoordsetmap, texCoordMapLength, NULL, numActiveTexUnit, - tunitstatemap, &vertexFormat, NULL, texCoordPointer, NULL); @@ -4816,14 +4667,13 @@ void executeIndexedGeometryArrayVA( } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryVA( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometryVA( JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -4838,11 +4688,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jint vertexAttrCount, jintArray vertexAttrSizes, jobjectArray vertexAttrData, - jint pass, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jobjectArray texCoords, jint cDirty, @@ -4914,7 +4762,6 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo geo, geo_type, isNonUniformScale, - multiScreen, ignoreVertexColors, initialIndexIndex, indexCount, @@ -4926,11 +4773,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo fclrs, bclrs, norms, - pass, texCoordMapLength, tcoordsetmap, numActiveTexUnit, - tunitstatemap, texStride, texCoordPointer, cDirty, @@ -4963,14 +4808,13 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryVABuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometryVABuffer( JNIEnv *env, jobject obj, jlong ctx, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -4985,11 +4829,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jint vertexAttrCount, jintArray vertexAttrSizes, jobjectArray vertexAttrData, - jint pass, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jobjectArray texCoords, jint cDirty, @@ -5067,7 +4909,6 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo geo, geo_type, isNonUniformScale, - multiScreen, ignoreVertexColors, initialIndexIndex, indexCount, @@ -5079,11 +4920,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo fclrs, bclrs, norms, - pass, texCoordMapLength, tcoordsetmap, numActiveTexUnit, - tunitstatemap, texStride, texCoordPointer, cDirty, @@ -5097,7 +4936,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo } extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_buildGAForBuffer( JNIEnv *env, jobject obj, jlong ctx, @@ -5181,12 +5020,12 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( executeGeometryArrayVA(env, obj, ctx, geo, geo_type, isNonUniformScale, updateAlpha, alpha, - false, ignoreVertexColors, + ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, - norms, -1, texCoordMapLength, - tcoordsetmap,texCoordMapLength, NULL, + norms, texCoordMapLength, + tcoordsetmap,texCoordMapLength, texindices,texStride,texCoordPointer, xform, nxform, javax_media_j3d_GeometryArrayRetained_VERTEX_CHANGED); @@ -5194,13 +5033,13 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( /* execute geometry array with java array format */ /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: buildGAForByRef * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZFZIIII[F[DI[F[BI[FI[I[I[[FI[I[II[Ljava/lang/Object;[D[D)V */ extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRef( +void JNICALL Java_javax_media_j3d_NativePipeline_buildGAForByRef( JNIEnv *env, jobject obj, jlong ctx, @@ -5294,12 +5133,12 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRef( executeGeometryArrayVA(env, obj, ctx, geo, geo_type, isNonUniformScale, updateAlpha, alpha, - false, ignoreVertexColors, + ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, - norms, -1, texCoordMapLength, - tcoordsetmap,texCoordMapLength, NULL, + norms, texCoordMapLength, + tcoordsetmap,texCoordMapLength, texindices,texStride,texCoordPointer, xform, nxform, javax_media_j3d_GeometryArrayRetained_VERTEX_CHANGED); diff --git a/src/native/d3d/GraphicsContext3D.cpp b/src/native/d3d/GraphicsContext3D.cpp index 427cd33..22ead53 100644 --- a/src/native/d3d/GraphicsContext3D.cpp +++ b/src/native/d3d/GraphicsContext3D.cpp @@ -13,7 +13,21 @@ #include "StdAfx.h" extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( +void JNICALL Java_javax_media_j3d_NativePipeline_readRaster( + JNIEnv *env, jobject obj, jlong ctx, + jint type, jint xOffset, jint yOffset, + jint wRaster, jint hRaster, jint hCanvas, + jint imageDataType, + jint imageFormat, jobject imageBuffer, + jint depthFormat, jobject depthBuffer) +{ + printf("[Java3D] D3D : readRaster is not implemented yet.\n"); + +} + +#if 0 +extern "C" JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( JNIEnv *env, jobject obj, jlong ctx, jint type, jint xOffset, jint yOffset, jint wRaster, jint hRaster, jint hCanvas, jint format, @@ -152,3 +166,5 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( } } } + +#endif diff --git a/src/native/d3d/Lights.cpp b/src/native/d3d/Lights.cpp index 270e52a..5d0f030 100644 --- a/src/native/d3d/Lights.cpp +++ b/src/native/d3d/Lights.cpp @@ -15,9 +15,9 @@ #define D3DLIGHT_RANGE_MAX sqrt(FLT_MAX) extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_DirectionalLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updateDirectionalLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctx, jint lightSlot, jfloat red, @@ -56,9 +56,9 @@ void JNICALL Java_javax_media_j3d_DirectionalLightRetained_updateLight( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_PointLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePointLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctx, jint lightSlot, jfloat red, @@ -99,9 +99,9 @@ void JNICALL Java_javax_media_j3d_PointLightRetained_updateLight( extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_SpotLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updateSpotLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctx, jint lightSlot, jfloat red, diff --git a/src/native/d3d/NativeAPIInfo.c b/src/native/d3d/NativeAPIInfo.c deleted file mode 100644 index b5a5bde..0000000 --- a/src/native/d3d/NativeAPIInfo.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -#include - -#include "javax_media_j3d_MasterControl.h" -#include "javax_media_j3d_NativeAPIInfo.h" - -JNIEXPORT -jint JNICALL Java_javax_media_j3d_NativeAPIInfo_getRenderingAPI( - JNIEnv *env, jobject obj) -{ - return (jint)javax_media_j3d_MasterControl_RENDER_DIRECT3D; -} diff --git a/src/native/d3d/NativeWSInfo.cpp b/src/native/d3d/NativeWSInfo.cpp deleted file mode 100644 index e1af6e5..0000000 --- a/src/native/d3d/NativeWSInfo.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -#include "StdAfx.h" - - - -#ifdef STRICT -typedef WNDPROC PROC_TYPE; -#else -typedef FARPROC PROC_TYPE; -#endif - - -static PROC_TYPE g_lpDefWindowProcChild; -static long oldWindowHandle = 0; - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_NativeWSInfo_subclass( - JNIEnv * env, - jobject obj, - jint hwnd) -{ - // For some reason, setting the callback before - // setCooperative level will cause setCooperative level - // to hang when start in fullscreen mode - // So we delay it later. -} - -// Handle child move request -static LRESULT CALLBACK canvas3dWndProcChild( - HWND hwnd, - UINT message, - WPARAM wParam, - LPARAM lParam) -{ - /* - switch (message) { - case WM_NCPAINT: - // handle switch mode from 256 back to >= 16 bits color mode - DWORD status; - if (hSema != NULL) { - status = WaitForSingleObject(hSema, 0); - if (status == WAIT_OBJECT_0) { - // This prevent deadlock, otherwise the window event - // thread will hangs if lock already acquired - // during window resize/toggle. - D3dCtx *ctx = findCtx(hwnd); - if (ctx != NULL) { - ctx->retryRestoreSurface = true; - } - unlock(); - } - } - break; - } - */ - return CallWindowProc(g_lpDefWindowProcChild, hwnd, message, - wParam, lParam); -} - - -VOID setWindowCallback(HWND topHwnd, HWND hwnd) -{ - // For some reasons, setting proc for the same handle - // will crash the application. So we work around this - // by checking the old window handle before setting the - // new one. - // long newWindowHandle; - /* - if (oldWindowHandle == 0) { - oldWindowHandle = GetWindowLong((HWND) hwnd, GWL_WNDPROC); - } - - newWindowHandle = GetWindowLong((HWND) hwnd, GWL_WNDPROC); - if (newWindowHandle == oldWindowHandle) { - g_lpDefWindowProcChild = (PROC_TYPE) - SetWindowLong((HWND) hwnd, GWL_WNDPROC, - (LONG) canvas3dWndProcChild); - } - */ -} - diff --git a/src/native/d3d/RasterRetained.cpp b/src/native/d3d/RasterRetained.cpp deleted file mode 100644 index 9cd3750..0000000 --- a/src/native/d3d/RasterRetained.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -#include "StdAfx.h" - -D3dImageComponent RasterList; -D3dImageComponent BackgroundImageList; - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_RasterRetained_execute(JNIEnv *env, - jobject obj, jlong ctx, jobject geo, - jboolean updateAlpha, jfloat alpha, - jint type, jint w_raster, jint h_raster, - jint x_offset, jint y_offset, jfloat x, jfloat y, jfloat z, - jbyteArray imageYdown) -{ - jfieldID id; - int width, height; - int hashCode; - D3DVERTEX worldCoord; - D3DTLVERTEX screenCoord; - - GetDevice(); - - int startx = x_offset; - int starty = y_offset; - int endx = x_offset + w_raster; - int endy = y_offset + h_raster; - - jclass geo_class = env->GetObjectClass(geo); - - if ((type == javax_media_j3d_Raster_RASTER_COLOR) || - (type == javax_media_j3d_Raster_RASTER_COLOR_DEPTH)) { - - int alphaChanged = 0; // used so we can get alpha data from - // JNI before using it so we can use - // GetPrimitiveArrayCritical - - id = env->GetFieldID(geo_class, "image", - "Ljavax/media/j3d/ImageComponent2DRetained;"); - jobject image = env->GetObjectField(geo, id); - - - jclass image_class = env->GetObjectClass(image); - - if (image_class == NULL) { - return; - } - /* - id = env->GetFieldID(image_class, "surfaceDirty", "I"); - if (env->GetIntField(image, id) == NOTLIVE) { - return; - } - */ - id = env->GetFieldID(image_class, "width", "I"); - width = env->GetIntField(image, id); - id = env->GetFieldID(image_class, "height", "I"); - height = env->GetIntField(image, id); - - id = env->GetFieldID(image_class, "hashId", "I"); - hashCode = env->GetIntField(image, id); - - // clipping - if (startx > width) { - startx = width; - } else if (startx < 0) { - startx = 0; - } - if (starty > height) { - starty = height; - } else if (starty < 0) { - starty = 0; - } - if (endx > width) { - endx = width; - } else if (endx < 0) { - endx = 0; - } - if (endy > height) { - endy = height; - } else if (endy < 0) { - endy = 0; - } - - // raster position is upper left corner, default for Java3D - // ImageComponent currently has the data reverse in Y - worldCoord.x = x; - worldCoord.y = y; - worldCoord.z = z; - - lockImage(); - - D3dImageComponent* d3dImage = - D3dImageComponent::find(&RasterList, d3dCtx, hashCode); - - LPDIRECT3DTEXTURE9 surf = NULL ; - - if ((d3dImage == NULL) || (d3dImage->surf == NULL)) { - - surf = createSurfaceFromImage(env, image, ctx, - width, height, imageYdown); - - if (surf == NULL) { - if (d3dImage != NULL) { - D3dImageComponent::remove(&RasterList, d3dImage); - } - unlockImage(); - return; - } - if (d3dImage == NULL) { - d3dImage = D3dImageComponent::add(&RasterList, d3dCtx, hashCode, surf); - - if (d3dImage == NULL) { - return; - } - - } else { - d3dImage->surf = surf; - } - } - - d3dCtx->transform(&worldCoord, &screenCoord); - if ((screenCoord.sz >= 0) && (screenCoord.sz <= 1)) { - screenCoord.sx -= 0.5f; - screenCoord.sy -= 0.5f; - drawTextureRect(d3dCtx, device, d3dImage->surf, screenCoord, - startx, starty, endx, endy, - endx - startx, endy - starty, false); - } - unlockImage(); - - } - - if ((type == javax_media_j3d_Raster_RASTER_DEPTH) || - (type == javax_media_j3d_Raster_RASTER_COLOR_DEPTH)) { - id = env->GetFieldID(geo_class, "depthComponent", - "Ljavax/media/j3d/DepthComponentRetained;"); - - jobject depth = env->GetObjectField(geo, id); - jclass depth_class = env->GetObjectClass(depth); - - if (depth_class == NULL) { - return; - } - id = env->GetFieldID(depth_class, "type", "I"); - int depth_type = env->GetIntField(depth, id); - id = env->GetFieldID(depth_class, "width", "I"); - width = env->GetIntField(depth, id); - id = env->GetFieldID(depth_class, "height", "I"); - height = env->GetIntField(depth, id); - - - - // clipping - if (startx > width) { - startx = width; - } else if (startx < 0) { - startx = 0; - } - if (starty > height) { - starty = height; - } else if (starty < 0) { - starty = 0; - } - if (endx > width) { - endx = width; - } else if (endx < 0) { - endx = 0; - } - if (endy > height) { - endy = height; - } else if (endy < 0) { - endy = 0; - } - - int h = endy - starty; - int w = endx - startx; - - // raster position is upper left corner, default for Java3D - // ImageComponent currently has the data reverse in Y - if ((h > 0) && (w > 0)) { - worldCoord.x = x; - worldCoord.y = y; - worldCoord.z = z; - - d3dCtx->transform(&worldCoord, &screenCoord); - - if (d3dCtx->depthStencilSurface == NULL) { - HRESULT hr = - device->GetDepthStencilSurface(&d3dCtx->depthStencilSurface); - if (FAILED(hr)) { - if (debug) { - printf("[Java3D] Fail to get depth stencil surface %s\n", - DXGetErrorString9(hr)); - } - return; - } - } - - if (depth_type == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { - id = env->GetFieldID(depth_class, "depthData","[I"); - jintArray intData_array = (jintArray) env->GetObjectField(depth, id); - jint * intData = (jint *) env->GetPrimitiveArrayCritical( - intData_array, NULL); - copyDepthToSurface(d3dCtx, - device, - (int)(screenCoord.sx), - (int)(screenCoord.sy), - x_offset, y_offset, - w, h,width, height, - intData, d3dCtx->depthStencilSurface); - env->ReleasePrimitiveArrayCritical(intData_array, - intData, 0); - } else { // javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT - - id = env->GetFieldID(depth_class, "depthData","[F"); - jfloatArray floatData_array = (jfloatArray) - env->GetObjectField(depth, id); - - jfloat *floatData = (jfloat *) env->GetPrimitiveArrayCritical( - floatData_array, NULL); - copyDepthToSurface(d3dCtx, - device, - (jint)(screenCoord.sx), - (jint)(screenCoord.sy), - x_offset, y_offset, - w, h, width, height, - floatData, d3dCtx->depthStencilSurface); - env->ReleasePrimitiveArrayCritical(floatData_array, - floatData, 0); - } - } - } -} - - - -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_RasterRetained_executeTiled(JNIEnv *env, - jobject obj, jlong ctx, jobject geo, - jint format, jint w_raster, jint h_raster, - jint x_offset, jint y_offset, jint deltaw, jint deltah, - jfloat x, jfloat y, jfloat z, jbyteArray tile) -{ - // This is is not used by both OGL and D3D -} diff --git a/src/native/d3d/build-windows-amd64-vc.xml b/src/native/d3d/build-windows-amd64-vc.xml new file mode 100644 index 0000000..7182711 --- /dev/null +++ b/src/native/d3d/build-windows-amd64-vc.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/native/d3d/build-windows-i586-vc.xml b/src/native/d3d/build-windows-i586-vc.xml index a1ad3b0..f432e0b 100644 --- a/src/native/d3d/build-windows-i586-vc.xml +++ b/src/native/d3d/build-windows-i586-vc.xml @@ -36,13 +36,13 @@ - + - + diff --git a/src/native/ogl/Attributes.c b/src/native/ogl/Attributes.c index bb35990..db87e70 100644 --- a/src/native/ogl/Attributes.c +++ b/src/native/ogl/Attributes.c @@ -217,18 +217,25 @@ const unsigned int screen_door[17][32] = { }, }; +void +throwAssert(JNIEnv *env, char *str) +{ + jclass rte; + if ((rte = (*env)->FindClass(env, "java/lang/AssertionError")) != NULL) { + (*env)->ThrowNew(env, rte, str); + } +} - JNIEXPORT -void JNICALL Java_javax_media_j3d_LinearFogRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateLinearFog( JNIEnv *env, - jobject fog, + jobject obj, jlong ctxInfo, jfloat red, jfloat green, jfloat blue, jdouble fdist, - jdouble bdist) + jdouble bdist) { float color[3]; @@ -248,9 +255,9 @@ void JNICALL Java_javax_media_j3d_LinearFogRetained_update( } JNIEXPORT -void JNICALL Java_javax_media_j3d_ExponentialFogRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateExponentialFog( JNIEnv *env, - jobject fog, + jobject obj, jlong ctxInfo, jfloat red, jfloat green, @@ -274,9 +281,9 @@ void JNICALL Java_javax_media_j3d_ExponentialFogRetained_update( } JNIEXPORT -void JNICALL Java_javax_media_j3d_ModelClipRetained_update( +void JNICALL Java_javax_media_j3d_NativePipeline_updateModelClip( JNIEnv *env, - jobject modelClip, + jobject obj, jlong ctxInfo, jint planeNum, jboolean enableFlag, @@ -308,7 +315,7 @@ void JNICALL Java_javax_media_j3d_ModelClipRetained_update( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setModelViewMatrix( +void JNICALL Java_javax_media_j3d_NativePipeline_setModelViewMatrix( JNIEnv * env, jobject obj, jlong ctxInfo, @@ -327,11 +334,10 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setModelViewMatrix( glMatrixMode(GL_MODELVIEW); - - if (ctxProperties->arb_transpose_matrix) { - ctxProperties->glLoadTransposeMatrixdARB(vmatrix_pointer); - ctxProperties->glMultTransposeMatrixdARB(mmatrix_pointer); + if (ctxProperties->gl13) { + ctxProperties->glLoadTransposeMatrixd(vmatrix_pointer); + ctxProperties->glMultTransposeMatrixd(mmatrix_pointer); } else { double v[16]; double m[16]; @@ -364,7 +370,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setModelViewMatrix( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( +void JNICALL Java_javax_media_j3d_NativePipeline_setProjectionMatrix( JNIEnv * env, jobject obj, jlong ctxInfo, @@ -379,7 +385,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( glMatrixMode(GL_PROJECTION); - if (ctxProperties->arb_transpose_matrix) { + if (ctxProperties->gl13) { /* * Invert the Z value in clipping coordinates because OpenGL uses * left-handed clipping coordinates, while Java3D defines right-handed @@ -389,7 +395,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( matrix_pointer[9] *= -1.0; matrix_pointer[10] *= -1.0; matrix_pointer[11] *= -1.0; - ctxProperties->glLoadTransposeMatrixdARB(matrix_pointer); + ctxProperties->glLoadTransposeMatrixd(matrix_pointer); matrix_pointer[8] *= -1.0; matrix_pointer[9] *= -1.0; matrix_pointer[10] *= -1.0; @@ -427,7 +433,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setProjectionMatrix( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setViewport( +void JNICALL Java_javax_media_j3d_NativePipeline_setViewport( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -445,7 +451,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setViewport( #endif JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setSceneAmbient( +void JNICALL Java_javax_media_j3d_NativePipeline_setSceneAmbient( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -463,7 +469,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setSceneAmbient( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setLightEnables( +void JNICALL Java_javax_media_j3d_NativePipeline_setLightEnables( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -489,7 +495,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setLightEnables( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setLightingEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_setLightingEnable( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -509,7 +515,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setLightingEnable( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_disableFog( +void JNICALL Java_javax_media_j3d_NativePipeline_disableFog( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -521,7 +527,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_disableFog( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_disableModelClip( +void JNICALL Java_javax_media_j3d_NativePipeline_disableModelClip( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -540,7 +546,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_disableModelClip( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetRenderingAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetRenderingAttributes( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -618,9 +624,9 @@ GLenum getStencilOpValue(jint op) { } JNIEXPORT -void JNICALL Java_javax_media_j3d_RenderingAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateRenderingAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jboolean db_write_enable_override, jboolean db_enable_override, @@ -750,7 +756,7 @@ void JNICALL Java_javax_media_j3d_RenderingAttributesRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetPolygonAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetPolygonAttributes( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -769,9 +775,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetPolygonAttributes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_PolygonAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePolygonAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jint polygonMode, jint cullFace, @@ -834,7 +840,7 @@ void JNICALL Java_javax_media_j3d_PolygonAttributesRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetLineAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetLineAttributes( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -852,9 +858,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetLineAttributes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_LineAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateLineAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jfloat lineWidth, jint linePattern, @@ -888,7 +894,7 @@ void JNICALL Java_javax_media_j3d_LineAttributesRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetPointAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetPointAttributes( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -900,9 +906,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetPointAttributes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_PointAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePointAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jfloat pointSize, jboolean pointAntialiasing) @@ -918,7 +924,7 @@ void JNICALL Java_javax_media_j3d_PointAttributesRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTexCoordGeneration( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTexCoordGeneration( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -930,9 +936,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTexCoordGeneration( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TexCoordGenerationRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexCoordGeneration( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jboolean enable, jint genMode, @@ -1016,8 +1022,8 @@ void JNICALL Java_javax_media_j3d_TexCoordGenerationRetained_updateNative( glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (ctxProperties->arb_transpose_matrix) { - ctxProperties->glLoadTransposeMatrixdARB(mat); + if (ctxProperties->gl13) { + ctxProperties->glLoadTransposeMatrixd(mat); } else { jdouble v[16]; COPY_TRANSPOSE(mat, v); @@ -1084,7 +1090,7 @@ void JNICALL Java_javax_media_j3d_TexCoordGenerationRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTextureAttributes( JNIEnv *env, jobject cv, jlong ctxInfo) @@ -1110,9 +1116,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureAttributes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jdoubleArray transform, jboolean isIdentity, @@ -1144,8 +1150,8 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNative( NULL); if (isIdentity) { glLoadIdentity(); - } else if (ctxProperties->arb_transpose_matrix) { - ctxProperties->glLoadTransposeMatrixdARB(mx_ptr); + } else if (ctxProperties->gl13) { + ctxProperties->glLoadTransposeMatrixd(mx_ptr); } else { double mx[16]; COPY_TRANSPOSE(mx_ptr, mx); @@ -1215,9 +1221,9 @@ GLenum getCombinerArg(jint arg, GLenum textureUnit, GLenum combUnit) { } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNativeRegisterCombiners( +void JNICALL Java_javax_media_j3d_NativePipeline_updateRegisterCombiners( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jdoubleArray transform, jboolean isIdentity, @@ -1262,8 +1268,8 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateNativeRegister NULL); if (isIdentity) { glLoadIdentity(); - } else if (ctxProperties->arb_transpose_matrix) { - ctxProperties->glLoadTransposeMatrixdARB(mx_ptr); + } else if (ctxProperties->gl13) { + ctxProperties->glLoadTransposeMatrixd(mx_ptr); } else { double mx[16]; COPY_TRANSPOSE(mx_ptr, mx); @@ -1564,9 +1570,9 @@ jint _gl_combineFcn[] = { JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateCombinerNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateCombiner( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxProperties, jint combineRgbMode, jint combineAlphaMode, @@ -1642,9 +1648,9 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateCombinerNative JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateTextureColorTableNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureColorTable( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jint numComponents, jint colorTableSize, @@ -1672,9 +1678,9 @@ void JNICALL Java_javax_media_j3d_TextureAttributesRetained_updateTextureColorTa } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateMaterial( +void JNICALL Java_javax_media_j3d_NativePipeline_updateMaterialColor( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jfloat colorRed, jfloat colorGreen, @@ -1692,9 +1698,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_updateMaterial( } JNIEXPORT -void JNICALL Java_javax_media_j3d_MaterialRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateMaterial( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jfloat colorRed, jfloat colorGreen, @@ -1762,7 +1768,7 @@ void JNICALL Java_javax_media_j3d_MaterialRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTransparency( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTransparency( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -1787,7 +1793,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetTransparency( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TransparencyAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTransparencyAttributes( JNIEnv *env, jobject tr, jlong ctxInfo, @@ -1826,7 +1832,7 @@ void JNICALL Java_javax_media_j3d_TransparencyAttributesRetained_updateNative( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetColoringAttributes( +void JNICALL Java_javax_media_j3d_NativePipeline_resetColoringAttributes( JNIEnv *env, jobject cv, jlong ctxInfo, @@ -1849,9 +1855,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_resetColoringAttributes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_ColoringAttributesRetained_updateNative( +void JNICALL Java_javax_media_j3d_NativePipeline_updateColoringAttributes( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jfloat dRed, jfloat dGreen, @@ -1883,32 +1889,25 @@ void JNICALL Java_javax_media_j3d_ColoringAttributesRetained_updateNative( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_resetTextureNative( +void JNICALL Java_javax_media_j3d_NativePipeline_resetTextureNative( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint texUnitIndex) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if(ctxProperties->arb_multitexture) { - - if (texUnitIndex >= 0) { - ctxProperties->glActiveTextureARB(texUnitIndex + GL_TEXTURE0_ARB); - ctxProperties->glClientActiveTextureARB(texUnitIndex + GL_TEXTURE0_ARB); - } + if(ctxProperties->gl13) { + if (texUnitIndex >= 0) { + ctxProperties->glActiveTexture(texUnitIndex + GL_TEXTURE0); + ctxProperties->glClientActiveTexture(texUnitIndex + GL_TEXTURE0); + } } glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); - - if(ctxProperties->texture3DAvailable) { - glDisable(ctxProperties->texture_3D_ext_enum); - } - - if(ctxProperties->textureCubeMapAvailable) { - glDisable(ctxProperties->texture_cube_map_ext_enum); - } + glDisable(GL_TEXTURE_3D); + glDisable(GL_TEXTURE_CUBE_MAP); } @@ -2048,7 +2047,7 @@ void updateTextureBoundary( break; case javax_media_j3d_Texture_CLAMP_TO_EDGE: glTexParameteri(target, GL_TEXTURE_WRAP_S, - ctxProperties->texture_clamp_to_edge_enum); + GL_CLAMP_TO_EDGE); break; case javax_media_j3d_Texture_CLAMP_TO_BOUNDARY: glTexParameteri(target, GL_TEXTURE_WRAP_S, @@ -2065,7 +2064,7 @@ void updateTextureBoundary( break; case javax_media_j3d_Texture_CLAMP_TO_EDGE: glTexParameteri(target, GL_TEXTURE_WRAP_T, - ctxProperties->texture_clamp_to_edge_enum); + GL_CLAMP_TO_EDGE); break; case javax_media_j3d_Texture_CLAMP_TO_BOUNDARY: glTexParameteri(target, GL_TEXTURE_WRAP_T, @@ -2078,21 +2077,21 @@ void updateTextureBoundary( switch (boundaryModeR) { case javax_media_j3d_Texture_WRAP: glTexParameteri(target, - ctxProperties->texture_wrap_r_ext_enum, GL_REPEAT); + GL_TEXTURE_WRAP_R, GL_REPEAT); break; case javax_media_j3d_Texture_CLAMP: glTexParameteri(target, - ctxProperties->texture_wrap_r_ext_enum, GL_CLAMP); + GL_TEXTURE_WRAP_R, GL_CLAMP); break; case javax_media_j3d_Texture_CLAMP_TO_EDGE: glTexParameteri(target, - ctxProperties->texture_wrap_r_ext_enum, - ctxProperties->texture_clamp_to_edge_enum); + GL_TEXTURE_WRAP_R, + GL_CLAMP_TO_EDGE); break; case javax_media_j3d_Texture_CLAMP_TO_BOUNDARY: glTexParameteri(target, - ctxProperties->texture_wrap_r_ext_enum, + GL_TEXTURE_WRAP_R, ctxProperties->texture_clamp_to_border_enum); break; } @@ -2181,6 +2180,21 @@ void updateTextureAnisotropicFilter( degree); } +static int +isPowerOfTwo(int size) +{ + int i; + if (size == 0) { + return 1; + } else { + for (i = 0; i < 32; i++) { + if (size == (1 << i)) { + return 1; + } + } + return 0; + } +} /* * common function to define 2D texture image for different target @@ -2191,130 +2205,159 @@ void updateTexture2DImage( jint target, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { - GLenum oglFormat = 0, oglInternalFormat=0; + void *imageObjPtr; + GLenum format = 0, internalFormat = 0, type = GL_UNSIGNED_INT_8_8_8_8; JNIEnv table = *env; - jbyte *byteData; - jshort *shortData; + GLboolean forceAlphaToOne = GL_FALSE; - switch (internalFormat) { + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)data, NULL); + } + else { + imageObjPtr = (void *)(*(table->GetDirectBufferAddress))(env, data); + } + + /* check if we are trying to draw NPOT on a system that doesn't support it */ + if ((!ctxProperties->textureNonPowerOfTwoAvailable) && + (!isPowerOfTwo(width) || !isPowerOfTwo(height))) { + /* disable texture by setting width and height to 0 */ + width = height = 0; + } + + switch (textureFormat) { case INTENSITY: - oglInternalFormat = GL_INTENSITY; + internalFormat = GL_INTENSITY; break; case LUMINANCE: - oglInternalFormat = GL_LUMINANCE; + internalFormat = GL_LUMINANCE; break; case ALPHA: - oglInternalFormat = GL_ALPHA; + internalFormat = GL_ALPHA; break; case LUMINANCE_ALPHA: - oglInternalFormat = GL_LUMINANCE_ALPHA; + internalFormat = GL_LUMINANCE_ALPHA; break; case J3D_RGB: - oglInternalFormat = GL_RGB; + internalFormat = GL_RGB; break; case J3D_RGBA: - oglInternalFormat = GL_RGBA; + internalFormat = GL_RGBA; break; + default: + throwAssert(env, "updateTexture2DImage : textureFormat illegal format"); + return; } - switch (format) { - case FORMAT_BYTE_RGBA: - /* all RGB types are stored as RGBA */ - oglFormat = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - oglFormat = GL_RGB; - break; - - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - oglFormat = GL_ABGR_EXT; - } - break; - - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - oglFormat = ctxProperties->bgr_ext_enum; - } - break; - - case FORMAT_BYTE_LA: + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_BYTE_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + format = GL_BGR; + break; + case IMAGE_FORMAT_BYTE_RGB: + format = GL_RGB; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + format = GL_ABGR_EXT; + } + else { + throwAssert(env, "updateTexture2DImage : GL_ABGR_EXT format is unsupported"); + return; + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + format = GL_RGBA; + break; + case IMAGE_FORMAT_BYTE_LA: /* all LA types are stored as LA8 */ - oglFormat = GL_LUMINANCE_ALPHA; + format = GL_LUMINANCE_ALPHA; break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; + case IMAGE_FORMAT_BYTE_GRAY: + if (internalFormat == GL_ALPHA) { + format = GL_ALPHA; } else { - oglFormat = GL_LUMINANCE; + format = GL_LUMINANCE; } break; + + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "updateTexture2DImage : imageFormat illegal format"); + return; + } + + glTexImage2D(target, level, internalFormat, + width, height, boundaryWidth, + format, GL_UNSIGNED_BYTE, imageObjPtr); + } - /* - fprintf(stderr,"native updateTextureImage\n"); - fprintf(stderr,"internalFormat = %x\n",internalFormat); - fprintf(stderr,"format = %x\n",format); - fprintf(stderr,"oglFormat = %x\n",oglFormat); - fprintf(stderr,"oglInternalFormat = %x\n",oglInternalFormat); - fprintf(stderr,"boundaryWidth= %d\n", boundaryWidth); - */ - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - imageYup, - NULL); - /* - { - jbyte *c = byteData; - int i, j; - for (i = 0; i < 1; i++) { - for (j = 0; j < 8; j++, c++) { - fprintf(stderr, "%x ",*c); - } - fprintf(stderr, "\n"); - } - } - */ - } - else { /* unsigned short */ - shortData = (jshort *)(*(table->GetPrimitiveArrayCritical))(env, - imageYup, - NULL); + else if((dataType == IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + format = GL_RGBA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + format = GL_BGRA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "updateTexture2DImage : imageFormat illegal format"); + return; + } + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); } - } - else { - byteData = NULL; - shortData = NULL; - } - if (format != FORMAT_USHORT_GRAY) { - glTexImage2D(target, level, oglInternalFormat, + + glTexImage2D(target, level, internalFormat, width, height, boundaryWidth, - oglFormat, GL_UNSIGNED_BYTE, (GLvoid *)byteData); + format, type, imageObjPtr); + + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); + } } else { - glTexImage2D(target, level, oglInternalFormat, - width, height, boundaryWidth, - oglFormat, GL_UNSIGNED_SHORT, (GLvoid *)shortData); + throwAssert(env, "updateTexture2DImage : illegal image data type"); + return; } - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - (*(table->ReleasePrimitiveArrayCritical))(env, imageYup, byteData, 0); - } - else { - (*(table->ReleasePrimitiveArrayCritical))(env, imageYup, shortData, 0); - } - } - /* No idea why we need following call. */ - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + (*(table->ReleasePrimitiveArrayCritical))(env, data, imageObjPtr, 0); + } + } @@ -2329,158 +2372,210 @@ void updateTexture2DSubImage( jint level, jint xoffset, jint yoffset, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint tilew, jint width, jint height, - jbyteArray image) { + jint dataType, + jobject data) { - GLenum oglFormat = 0, oglInternalFormat=0; + void *imageObjPtr; + GLenum format = 0, internalFormat = 0, type = GL_UNSIGNED_INT_8_8_8_8; JNIEnv table = *env; - jbyte *byteData, *tmpByte; - jshort *shortData, *tmpShort; + GLboolean forceAlphaToOne = GL_FALSE; + jbyte *tmpByte; + jint *tmpInt; jint numBytes = 0; jboolean pixelStore = JNI_FALSE; + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)data, NULL); + } + else { + imageObjPtr = (void *)(*(table->GetDirectBufferAddress))(env, data); + } + + if (imgXOffset > 0 || (width < tilew)) { + pixelStore = JNI_TRUE; + glPixelStorei(GL_UNPACK_ROW_LENGTH, tilew); + } + /* if NPOT textures are not supported, check if h=w=0, if so we have been + * disabled due to a NPOT texture being sent to a context that doesn't + * support it: disable the glTexSubImage as well + */ + if (!ctxProperties->textureNonPowerOfTwoAvailable) { + int texWidth, texHeight; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texWidth); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texHeight); + if ((texWidth == 0) && (texHeight == 0)) { + /* disable the sub-image by setting it's width and height to 0 */ + width = height = 0; + } + } - switch (internalFormat) { + switch (textureFormat) { case INTENSITY: - oglInternalFormat = GL_INTENSITY; + internalFormat = GL_INTENSITY; break; case LUMINANCE: - oglInternalFormat = GL_LUMINANCE; + internalFormat = GL_LUMINANCE; break; case ALPHA: - oglInternalFormat = GL_ALPHA; + internalFormat = GL_ALPHA; break; case LUMINANCE_ALPHA: - oglInternalFormat = GL_LUMINANCE_ALPHA; + internalFormat = GL_LUMINANCE_ALPHA; break; case J3D_RGB: - oglInternalFormat = GL_RGB; + internalFormat = GL_RGB; break; case J3D_RGBA: - oglInternalFormat = GL_RGBA; + internalFormat = GL_RGBA; break; + default: + throwAssert(env, "updateTexture2DSubImage : textureFormat illegal format"); + return; } - - switch (format) { - case FORMAT_BYTE_RGBA: - /* all RGB types are stored as RGBA */ - oglFormat = GL_RGBA; - numBytes = 4; - break; - case FORMAT_BYTE_RGB: - oglFormat = GL_RGB; - numBytes = 3; - break; - - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - oglFormat = GL_ABGR_EXT; + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_BYTE_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + format = GL_BGR; + numBytes = 3; + break; + case IMAGE_FORMAT_BYTE_RGB: + format = GL_RGB; + numBytes = 3; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + format = GL_ABGR_EXT; numBytes = 4; - } - break; - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - oglFormat = ctxProperties->bgr_ext_enum; - numBytes = 3; - } - break; - - case FORMAT_BYTE_LA: + } + else { + throwAssert(env, "updateTexture2DSubImage : GL_ABGR_EXT format is unsupported"); + return; + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + format = GL_RGBA; + numBytes = 4; + break; + case IMAGE_FORMAT_BYTE_LA: /* all LA types are stored as LA8 */ - oglFormat = GL_LUMINANCE_ALPHA; - numBytes = 2; - break; - case FORMAT_BYTE_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; - } else { - oglFormat = GL_LUMINANCE; - } - numBytes = 1; - case FORMAT_USHORT_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; - } else { - oglFormat = GL_LUMINANCE; + numBytes = 2; + format = GL_LUMINANCE_ALPHA; + break; + case IMAGE_FORMAT_BYTE_GRAY: + if (internalFormat == GL_ALPHA) { + format = GL_ALPHA; + numBytes = 1; + } else { + format = GL_LUMINANCE; + numBytes = 1; } - numBytes = 2; break; - } - /* - fprintf(stderr,"format = %x\n",format); - fprintf(stderr,"oglFormat = %x\n",oglFormat); - fprintf(stderr, "imgXOffset = %d\n",imgXOffset); - fprintf(stderr, "imgYOffset = %d\n",imgYOffset); - fprintf(stderr, "xoffset = %d\n",xoffset); - fprintf(stderr, "yoffset = %d\n",yoffset); - fprintf(stderr, "tilew = %d\n",tilew); - fprintf(stderr, "numBytes = %d\n",numBytes); - fprintf(stderr, "width = %d\n",width); - fprintf(stderr, "height = %d\n",height); - */ - if (imgXOffset > 0 || (width < tilew)) { - pixelStore = JNI_TRUE; - glPixelStorei(GL_UNPACK_ROW_LENGTH, tilew); - } - - if (format != FORMAT_USHORT_GRAY) { - int off = 0; - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - image, - NULL); - /* offset by the imageOffset */ - off = (tilew * imgYOffset + imgXOffset) * numBytes; - tmpByte = byteData+(off); -/* -printf("tmpByte: %x %x %x %x\n", *(tmpByte), *(tmpByte+1), - *(tmpByte+2), *(tmpByte+3)); -*/ + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "updateTexture2DSubImage : imageFormat illegal format"); + return; + } + tmpByte = (jbyte*)imageObjPtr + + (tilew * imgYOffset + imgXOffset) * numBytes; + + glTexSubImage2D(target, level, xoffset, yoffset, width, height, - oglFormat, GL_UNSIGNED_BYTE, (GLvoid *)tmpByte); - (*(table->ReleasePrimitiveArrayCritical))(env, image, byteData, 0); - } else { /* unsigned short */ - shortData = (jshort *)(*(table->GetPrimitiveArrayCritical))(env, - image, - NULL); - tmpShort = (jshort*)((jbyte*)shortData+ - (tilew * imgYOffset + imgXOffset)*numBytes); + format, GL_UNSIGNED_BYTE, (GLvoid *)tmpByte); + + } + else if((dataType == IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + format = GL_RGBA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + format = GL_BGRA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "updateTexture2DSubImage : imageFormat illegal format"); + return; + } + + numBytes = 4; + + tmpInt = (jint*)((jbyte*)imageObjPtr + + (tilew * imgYOffset + imgXOffset)*numBytes); + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); + } + glTexSubImage2D(target, level, xoffset, yoffset, width, height, - oglFormat, GL_UNSIGNED_SHORT, (GLvoid *)tmpShort); - (*(table->ReleasePrimitiveArrayCritical))(env, image, shortData, 0); + format, type, (GLvoid *)tmpInt); + + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); + } } + else { + throwAssert(env, "updateTexture2DImage : illegal image data type"); + return; + } + + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + (*(table->ReleasePrimitiveArrayCritical))(env, data, imageObjPtr, 0); + } + if (pixelStore) { - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_bindTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTexture2D( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint objectId, jboolean enable) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - glDisable(ctxProperties->texture_cube_map_ext_enum); - } - if (ctxProperties->texture3DAvailable) { - glDisable(ctxProperties->texture_3D_ext_enum); - } + glDisable(GL_TEXTURE_CUBE_MAP); + glDisable(GL_TEXTURE_3D); if (enable == JNI_FALSE) { glDisable(GL_TEXTURE_2D); - } else { glBindTexture(GL_TEXTURE_2D, objectId); glEnable(GL_TEXTURE_2D); @@ -2488,9 +2583,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_bindTexture( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint minFilter, jint magFilter) @@ -2502,16 +2597,15 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilterModes( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint baseLevel, jint maximumLevel, jfloat minimumLOD, jfloat maximumLOD) { - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTextureLodRange(ctxProperties, GL_TEXTURE_2D, @@ -2519,10 +2613,11 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodRange( minimumLOD, maximumLOD); } + JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat lodOffsetS, jfloat lodOffsetT, @@ -2536,9 +2631,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureLodOffset( JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint boundaryModeS, jint boundaryModeT, @@ -2556,9 +2651,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureBoundary( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSharpenFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSharpenFunc( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) @@ -2569,9 +2664,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureSharpenFunc( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilter4Func( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DFilter4Func( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) @@ -2582,9 +2677,9 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureFilter4Func( } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat degree) { @@ -2594,193 +2689,81 @@ void JNICALL Java_javax_media_j3d_TextureRetained_updateTextureAnisotropicFilter } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint level, jint xoffset, jint yoffset, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint tilew, jint width, jint height, - jbyteArray image) { + jint dataType, + jobject data) +{ GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTexture2DSubImage(env, ctxProperties, GL_TEXTURE_2D, - level, xoffset, yoffset, - internalFormat, format, - imgXOffset, imgYOffset, tilew, width, height, - image); + level, xoffset, yoffset, + textureFormat, imageFormat, + imgXOffset, imgYOffset, tilew, width, height, + dataType, data); } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTexture2DImage(env, ctxProperties, GL_TEXTURE_2D, - numLevels, level, internalFormat, format, - width, height, boundaryWidth, imageYup); -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture2DRetained_updateDetailTextureParameters( - JNIEnv *env, - jobject texture, - jlong ctxInfo, - jint mode, - jint level, - jint nPts, - jfloatArray funcPts) -{ - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - float *pts = NULL; - JNIEnv table = *env; - - if (ctxProperties->textureDetailAvailable) { - switch (mode) { - case javax_media_j3d_Texture2D_DETAIL_ADD: - glTexParameterf(GL_TEXTURE_2D, - ctxProperties->texture_detail_mode_enum, GL_ADD); - break; - case javax_media_j3d_Texture2D_DETAIL_MODULATE: - glTexParameterf(GL_TEXTURE_2D, - ctxProperties->texture_detail_mode_enum, GL_MODULATE); - break; - } - - glTexParameteri(GL_TEXTURE_2D, - ctxProperties->texture_detail_level_enum, -level); - - if (nPts > 0) { - pts = (jfloat *)(*(table->GetPrimitiveArrayCritical))(env, - funcPts, NULL); - } - ctxProperties->glDetailTexFuncSGIS(GL_TEXTURE_2D, nPts, pts); - - if (pts != NULL) { - (*(table->ReleasePrimitiveArrayCritical))(env, funcPts, pts, 0); - } - } -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_DetailTextureImage_bindTexture( - JNIEnv *env, - jobject texture, - jlong ctxInfo, - jint objectId) -{ - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if (ctxProperties->textureDetailAvailable) { - glBindTexture(ctxProperties->texture_detail_ext_enum, objectId); - } -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_DetailTextureImage_updateTextureSubImage( - JNIEnv *env, - jobject texture, - jlong ctxInfo, - jint level, - jint xoffset, - jint yoffset, - jint internalFormat, - jint format, - jint imgXOffset, - jint imgYOffset, - jint tilew, - jint width, - jint height, - jbyteArray image) { - - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if (ctxProperties->textureDetailAvailable) { - updateTexture2DSubImage(env, ctxProperties, - ctxProperties->texture_detail_ext_enum, - level, xoffset, yoffset, - internalFormat, format, - imgXOffset, imgYOffset, tilew, width, height, - image); - } + numLevels, level, textureFormat, imageFormat, + width, height, boundaryWidth, dataType, data); } JNIEXPORT -void JNICALL Java_javax_media_j3d_DetailTextureImage_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTexture3D( JNIEnv *env, - jobject texture, - jlong ctxInfo, - jint numLevels, - jint level, - jint internalFormat, - jint format, - jint width, - jint height, - jint boundaryWidth, - jbyteArray imageYup) -{ - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if (ctxProperties->textureDetailAvailable) { - updateTexture2DImage(env, ctxProperties, - ctxProperties->texture_detail_ext_enum, - numLevels, level, internalFormat, format, - width, height, boundaryWidth, imageYup); - } -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_bindTexture( - JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint objectId, jboolean enable) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - /* textureCubeMap will take precedure over 3D Texture */ - glDisable(ctxProperties->texture_cube_map_ext_enum); - } + /* textureCubeMap will take precedure over 3D Texture */ + glDisable(GL_TEXTURE_CUBE_MAP); if (enable == JNI_FALSE) { - if(ctxProperties->texture3DAvailable) { - glDisable(ctxProperties->texture_3D_ext_enum); - } - + glDisable(GL_TEXTURE_3D); } else { - if(ctxProperties->texture3DAvailable){ - glBindTexture(ctxProperties->texture_3D_ext_enum, objectId); - glEnable(ctxProperties->texture_3D_ext_enum); - } + glBindTexture(GL_TEXTURE_3D, objectId); + glEnable(GL_TEXTURE_3D); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint minFilter, jint magFilter) @@ -2794,9 +2777,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilterModes( JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint baseLevel, jint maximumLevel, @@ -2812,9 +2795,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodRange( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat lodOffsetS, jfloat lodOffsetT, @@ -2828,9 +2811,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureLodOffset( JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint boundaryModeS, jint boundaryModeT, @@ -2849,9 +2832,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureBoundary( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSharpenFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DSharpenFunc( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) @@ -2862,9 +2845,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSharpenFunc( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilter4Func( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DFilter4Func( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) @@ -2875,9 +2858,9 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureFilter4Func( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat degree) { @@ -2888,147 +2871,184 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureAnisotropicFilt JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint depth, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if(ctxProperties->texture3DAvailable) { + void *imageObjPtr; + GLenum format = 0, internalFormat = 0, type = GL_UNSIGNED_INT_8_8_8_8; + JNIEnv table = *env; + GLboolean forceAlphaToOne = GL_FALSE; - GLenum oglFormat = 0, oglInternalFormat=0; - JNIEnv table = *env; - jbyte *byteData; - jshort *shortData; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)data, NULL); + } + else { + imageObjPtr = (void *)(*(table->GetDirectBufferAddress))(env, data); + } - switch (internalFormat) { + /* check if we are trying to draw NPOT on a system that doesn't support it */ + if ((!ctxProperties->textureNonPowerOfTwoAvailable) && + (!isPowerOfTwo(width) || !isPowerOfTwo(height) || !isPowerOfTwo(depth))) { + /* disable texture by setting width, height and depth to 0 */ + width = height = depth = 0; + } + + switch (textureFormat) { case INTENSITY: - oglInternalFormat = GL_INTENSITY; + internalFormat = GL_INTENSITY; break; case LUMINANCE: - oglInternalFormat = GL_LUMINANCE; + internalFormat = GL_LUMINANCE; break; case ALPHA: - oglInternalFormat = GL_ALPHA; + internalFormat = GL_ALPHA; break; case LUMINANCE_ALPHA: - oglInternalFormat = GL_LUMINANCE_ALPHA; + internalFormat = GL_LUMINANCE_ALPHA; break; case J3D_RGB: - oglInternalFormat = GL_RGB; + internalFormat = GL_RGB; break; case J3D_RGBA: - oglInternalFormat = GL_RGBA; - break; - } - - switch (format) { - case FORMAT_BYTE_RGBA: - /* all RGB types are stored as RGBA */ - oglFormat = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - oglFormat = GL_RGB; + internalFormat = GL_RGBA; break; + default: + throwAssert(env, "updateTexture3DImage : textureFormat illegal format"); + return; + } - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - oglFormat = GL_ABGR_EXT; - } - break; - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - oglFormat = ctxProperties->bgr_ext_enum; - } - break; - case FORMAT_BYTE_LA: + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_BYTE_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + format = GL_BGR; + break; + case IMAGE_FORMAT_BYTE_RGB: + format = GL_RGB; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + format = GL_ABGR_EXT; + } + else { + throwAssert(env, "updateTexture3DImage : GL_ABGR_EXT format is unsupported"); + return; + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + format = GL_RGBA; + break; + case IMAGE_FORMAT_BYTE_LA: /* all LA types are stored as LA8 */ - oglFormat = GL_LUMINANCE_ALPHA; + format = GL_LUMINANCE_ALPHA; break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; + case IMAGE_FORMAT_BYTE_GRAY: + if (internalFormat == GL_ALPHA) { + format = GL_ALPHA; } else { - oglFormat = GL_LUMINANCE; + format = GL_LUMINANCE; } break; - } - /* - fprintf(stderr,"internalFormat = %x\n",internalFormat); - fprintf(stderr,"format = %x\n",format); - fprintf(stderr,"oglFormat = %x\n",oglFormat); - fprintf(stderr,"oglInternalFormat = %x\n",oglInternalFormat); - */ - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - imageYup, - NULL); - } - else { /* unsigned short */ - shortData = (jshort *)(*(table->GetPrimitiveArrayCritical))(env, - imageYup, - NULL); + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "updateTexture3DImage : imageFormat illegal format"); + return; + } - } - } else { - byteData = NULL; - shortData = NULL; + ctxProperties->glTexImage3DEXT(GL_TEXTURE_3D, + level, internalFormat, + width, height, depth, boundaryWidth, + format, GL_UNSIGNED_BYTE, + imageObjPtr); + + } + else if((dataType == IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + format = GL_RGBA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + format = GL_BGRA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "updateTexture3DImage : imageFormat illegal format"); + return; + } + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); + } + + ctxProperties->glTexImage3DEXT(GL_TEXTURE_3D, + level, internalFormat, + width, height, depth, boundaryWidth, + format, type, imageObjPtr); + + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); } + } + else { + throwAssert(env, "updateTexture3DImage : illegal image data type"); + } - if (format != FORMAT_USHORT_GRAY) { - ctxProperties->glTexImage3DEXT(ctxProperties->texture_3D_ext_enum, - level, oglInternalFormat, - width, height, depth, boundaryWidth, - oglFormat, GL_UNSIGNED_BYTE, - (GLvoid *)byteData); - } - else { - ctxProperties->glTexImage3DEXT(ctxProperties->texture_3D_ext_enum, - level, oglInternalFormat, - width, height, depth, boundaryWidth, - oglFormat, GL_UNSIGNED_SHORT, - (GLvoid *)shortData); - } - if (imageYup != NULL) { - if (format != FORMAT_USHORT_GRAY) { - (*(table->ReleasePrimitiveArrayCritical))(env, imageYup, byteData, 0); - } else { /* unsigned short */ - (*(table->ReleasePrimitiveArrayCritical))(env, imageYup, shortData, 0); - - } - } - - /* No idea why we need following call. */ - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + (*(table->ReleasePrimitiveArrayCritical))(env, data, imageObjPtr, 0); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture3DSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint level, jint xoffset, jint yoffset, jint zoffset, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint imgZOffset, @@ -3037,139 +3057,195 @@ void JNICALL Java_javax_media_j3d_Texture3DRetained_updateTextureSubImage( jint width, jint height, jint depth, - jbyteArray image) { + jint dataType, + jobject data) { + void *imageObjPtr; + GLenum format = 0, internalFormat = 0, type = GL_UNSIGNED_INT_8_8_8_8; + JNIEnv table = *env; + GLboolean forceAlphaToOne = GL_FALSE; + jbyte *tmpByte; + jint *tmpInt; + jint numBytes = 0; + jboolean pixelStore = JNI_FALSE; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if (ctxProperties->texture3DAvailable) { - GLenum oglFormat = 0, oglInternalFormat=0; - JNIEnv table = *env; - jbyte *byteData, *tmpByte; - jshort *shortData, *tmpShort; - jint numBytes = 0; - jboolean pixelStore = JNI_FALSE; - - switch (internalFormat) { - case INTENSITY: - oglInternalFormat = GL_INTENSITY; - break; - case LUMINANCE: - oglInternalFormat = GL_LUMINANCE; - break; - case ALPHA: - oglInternalFormat = GL_ALPHA; - break; - case LUMINANCE_ALPHA: - oglInternalFormat = GL_LUMINANCE_ALPHA; - break; - case J3D_RGB: - oglInternalFormat = GL_RGB; - break; - case J3D_RGBA: - oglInternalFormat = GL_RGBA; - break; - } - - switch (format) { - case FORMAT_BYTE_RGBA: - /* all RGB types are stored as RGBA */ - oglFormat = GL_RGBA; - numBytes = 4; - break; - case FORMAT_BYTE_RGB: - oglFormat = GL_RGB; - numBytes = 3; - break; + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)data, NULL); + } + else { + imageObjPtr = (void *)(*(table->GetDirectBufferAddress))(env, data); + } - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - oglFormat = GL_ABGR_EXT; - numBytes = 4; - } - break; - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - oglFormat = ctxProperties->bgr_ext_enum; - numBytes = 3; - } - break; + if (imgXOffset > 0 || (width < tilew)) { + pixelStore = JNI_TRUE; + glPixelStorei(GL_UNPACK_ROW_LENGTH, tilew); + } + + /* if NPOT textures are not supported, check if h=w=0, if so we have been + * disabled due to a NPOT texture being sent to a context that doesn't + * support it: disable the glTexSubImage as well + */ + if (!ctxProperties->textureNonPowerOfTwoAvailable) { + int texWidth, texHeight, texDepth; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texWidth); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texHeight); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH, &texDepth); + if ((texWidth == 0) && (texHeight == 0) && (texDepth == 0)) { + /* disable the sub-image by setting it's width, height and depth to 0 */ + width = height = depth = 0; + } + } + + switch (textureFormat) { + case INTENSITY: + internalFormat = GL_INTENSITY; + break; + case LUMINANCE: + internalFormat = GL_LUMINANCE; + break; + case ALPHA: + internalFormat = GL_ALPHA; + break; + case LUMINANCE_ALPHA: + internalFormat = GL_LUMINANCE_ALPHA; + break; + case J3D_RGB: + internalFormat = GL_RGB; + break; + case J3D_RGBA: + internalFormat = GL_RGBA; + break; + default: + throwAssert(env, "updateTexture3DSubImage : textureFormat illegal format"); + break; + } - case FORMAT_BYTE_LA: - /* all LA types are stored as LA8 */ - oglFormat = GL_LUMINANCE_ALPHA; - numBytes = 2; - break; - case FORMAT_BYTE_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; - } else { - oglFormat = GL_LUMINANCE; - } - numBytes = 1; - case FORMAT_USHORT_GRAY: - if (oglInternalFormat == GL_ALPHA) { - oglFormat = GL_ALPHA; - } else { - oglFormat = GL_LUMINANCE; - } - numBytes = 2; - break; - } - /* - fprintf(stderr,"format = %x\n",format); - fprintf(stderr,"oglFormat = %x\n",oglFormat); - fprintf(stderr, "imgXOffset = %d\n",imgXOffset); - fprintf(stderr, "imgYOffset = %d\n",imgYOffset); - fprintf(stderr, "imgZOffset = %d\n",imgZOffset); - fprintf(stderr, "xoffset = %d\n",xoffset); - fprintf(stderr, "yoffset = %d\n",yoffset); - fprintf(stderr, "zoffset = %d\n",zoffset); - fprintf(stderr, "tilew = %d\n",tilew); - fprintf(stderr, "tileh = %d\n",tilew); - fprintf(stderr, "numBytes = %d\n",numBytes); - fprintf(stderr, "width = %d\n",width); - fprintf(stderr, "height = %d\n",height); - fprintf(stderr, "depth = %d\n",depth); - */ - if (imgXOffset > 0 || (width < tilew)) { - pixelStore = JNI_TRUE; - glPixelStorei(GL_UNPACK_ROW_LENGTH, tilew); + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_BYTE_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + format = GL_BGR; + numBytes = 3; + break; + case IMAGE_FORMAT_BYTE_RGB: + format = GL_RGB; + numBytes = 3; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + format = GL_ABGR_EXT; + numBytes = 4; + } + else { + throwAssert(env, "updateTexture3DSubImage : GL_ABGR_EXT format is unsupported"); + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + format = GL_RGBA; + numBytes = 4; + break; + case IMAGE_FORMAT_BYTE_LA: + /* all LA types are stored as LA8 */ + format = GL_LUMINANCE_ALPHA; + numBytes = 2; + break; + case IMAGE_FORMAT_BYTE_GRAY: + if (internalFormat == GL_ALPHA) { + format = GL_ALPHA; + numBytes = 1; + } else { + format = GL_LUMINANCE; + numBytes = 1; + } + break; + + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "updateTexture3DSubImage : imageFormat illegal format"); + break; } - - if (format != FORMAT_USHORT_GRAY) { - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - image, NULL); - - tmpByte = byteData + - (tilew * tileh * imgZOffset + - tilew * imgYOffset + imgXOffset) * numBytes; - - ctxProperties->glTexSubImage3DEXT( - ctxProperties->texture_3D_ext_enum, - level, xoffset, yoffset, zoffset, - width, height, depth, - oglFormat, GL_UNSIGNED_BYTE, - (GLvoid *)tmpByte); - - (*(table->ReleasePrimitiveArrayCritical))(env, image, byteData, 0); - } else { /* unsigned short */ - shortData = (jshort *)(*(table->GetPrimitiveArrayCritical))(env, - image, NULL); - tmpShort = (jshort*)((jbyte*)shortData+ - (tilew * tileh * imgZOffset + - tilew * imgYOffset + imgXOffset)*numBytes); + + tmpByte = (jbyte*)imageObjPtr + + (tilew * tileh * imgZOffset + tilew * imgYOffset + imgXOffset) * + numBytes; + + ctxProperties->glTexSubImage3DEXT(GL_TEXTURE_3D, + level, xoffset, yoffset, zoffset, + width, height, depth, + format, GL_UNSIGNED_BYTE, + (GLvoid *)tmpByte); + + + } + else if((dataType == IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_BUFFER)) { + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + format = GL_RGBA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + format = GL_BGRA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "updateTexture3DSubImage : imageFormat illegal format"); + break; + } + + numBytes = 4; + + tmpInt = (jint*)((jbyte*)imageObjPtr + + (tilew * tileh * imgZOffset + + tilew * imgYOffset + imgXOffset)*numBytes); + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); + } + + ctxProperties->glTexSubImage3DEXT(GL_TEXTURE_3D, + level, xoffset, yoffset, zoffset, + width, height, depth, + format, type, + (GLvoid *)tmpInt); + + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); + } + } + else { + throwAssert(env, "updateTexture3DImage : illegal image data type"); + return; + } + + + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + (*(table->ReleasePrimitiveArrayCritical))(env, data, imageObjPtr, 0); + } - ctxProperties->glTexSubImage3DEXT( - ctxProperties->texture_3D_ext_enum, - level, xoffset, yoffset, zoffset, - width, height, depth, - oglFormat, GL_UNSIGNED_SHORT, - (GLvoid *)tmpShort); - (*(table->ReleasePrimitiveArrayCritical))(env, image, shortData, 0); - } - if (pixelStore) { - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - } + if (pixelStore) { + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } } @@ -3189,9 +3265,9 @@ jint _gl_textureCubeMapFace[] = { JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_bindTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_bindTextureCubeMap( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint objectId, jboolean enable) @@ -3202,39 +3278,33 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_bindTexture( * TextureCubeMap will take precedure over 3D Texture so * there is no need to disable 3D Texture here. */ - if (ctxProperties->textureCubeMapAvailable) { - if (enable == JNI_FALSE) { - glDisable(ctxProperties->texture_cube_map_ext_enum); - } else { - glBindTexture(ctxProperties->texture_cube_map_ext_enum, objectId); - glEnable(ctxProperties->texture_cube_map_ext_enum); - } + if (enable == JNI_FALSE) { + glDisable(GL_TEXTURE_CUBE_MAP); + } else { + glBindTexture(GL_TEXTURE_CUBE_MAP, objectId); + glEnable(GL_TEXTURE_CUBE_MAP); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureFilterModes( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapFilterModes( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint minFilter, jint magFilter) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - updateTextureFilterModes(ctxProperties, - ctxProperties->texture_cube_map_ext_enum, - minFilter, magFilter); - } + updateTextureFilterModes(ctxProperties, + GL_TEXTURE_CUBE_MAP, + minFilter, magFilter); } - - JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodRange( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapLodRange( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint baseLevel, jint maximumLevel, @@ -3245,15 +3315,15 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodRange( GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTextureLodRange(ctxProperties, - ctxProperties->texture_cube_map_ext_enum, + GL_TEXTURE_CUBE_MAP, baseLevel, maximumLevel, minimumLOD, maximumLOD); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodOffset( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapLodOffset( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat lodOffsetS, jfloat lodOffsetT, @@ -3262,15 +3332,15 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureLodOffset( GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTextureLodOffset(ctxProperties, - ctxProperties->texture_cube_map_ext_enum, + GL_TEXTURE_CUBE_MAP, lodOffsetS, lodOffsetT, lodOffsetR); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureBoundary( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapBoundary( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint boundaryModeS, jint boundaryModeT, @@ -3281,117 +3351,110 @@ void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureBoundary( { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - updateTextureBoundary(ctxProperties, - ctxProperties->texture_cube_map_ext_enum, - boundaryModeS, boundaryModeT, -1, - boundaryRed, boundaryGreen, - boundaryBlue, boundaryAlpha); - } + updateTextureBoundary(ctxProperties, + GL_TEXTURE_CUBE_MAP, + boundaryModeS, boundaryModeT, -1, + boundaryRed, boundaryGreen, + boundaryBlue, boundaryAlpha); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureSharpenFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapSharpenFunc( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - updateTextureSharpenFunc(env, ctxProperties, - ctxProperties->texture_cube_map_ext_enum, - numPts, pts); - } + updateTextureSharpenFunc(env, ctxProperties, + GL_TEXTURE_CUBE_MAP, + numPts, pts); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureFilter4Func( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapFilter4Func( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint numPts, jfloatArray pts) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - updateTextureFilter4Func(env, ctxProperties, - ctxProperties->texture_cube_map_ext_enum, - numPts, pts); - } + updateTextureFilter4Func(env, ctxProperties, + GL_TEXTURE_CUBE_MAP, + numPts, pts); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureAnisotropicFilter( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapAnisotropicFilter( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jfloat degree) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if (ctxProperties->textureCubeMapAvailable) { - updateTextureAnisotropicFilter(env, ctxProperties, - ctxProperties->texture_cube_map_ext_enum, - degree); - } + updateTextureAnisotropicFilter(env, ctxProperties, + GL_TEXTURE_CUBE_MAP, + degree); } - + JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureSubImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapSubImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint face, jint level, jint xoffset, jint yoffset, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint imgXOffset, jint imgYOffset, jint tilew, jint width, jint height, - jbyteArray image) { - + jint dataType, + jobject data) +{ GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTexture2DSubImage(env, ctxProperties, _gl_textureCubeMapFace[face], - level, xoffset, yoffset, internalFormat, - format, imgXOffset, imgYOffset, tilew, - width, height, image); + level, xoffset, yoffset, textureFormat, + imageFormat, imgXOffset, imgYOffset, tilew, + width, height, dataType, data); } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureCubeMapRetained_updateTextureImage( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureCubeMapImage( JNIEnv *env, - jobject texture, + jobject obj, jlong ctxInfo, jint face, jint numLevels, jint level, - jint internalFormat, - jint format, + jint textureFormat, + jint imageFormat, jint width, jint height, jint boundaryWidth, - jbyteArray imageYup) + jint dataType, + jobject data) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; updateTexture2DImage(env, ctxProperties, _gl_textureCubeMapFace[face], - numLevels, level, internalFormat, format, - width, height, boundaryWidth, imageYup); + numLevels, level, textureFormat, imageFormat, + width, height, boundaryWidth, dataType, data); } - JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_decal1stChildSetup( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_decal1stChildSetup( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -3408,7 +3471,7 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_decal1stChildSetup( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_decalNthChildSetup( +void JNICALL Java_javax_media_j3d_NativePipeline_decalNthChildSetup( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -3419,7 +3482,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_decalNthChildSetup( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_decalReset( +void JNICALL Java_javax_media_j3d_NativePipeline_decalReset( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -3431,7 +3494,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_decalReset( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_ctxUpdateEyeLightingEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_ctxUpdateEyeLightingEnable( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -3445,69 +3508,50 @@ void JNICALL Java_javax_media_j3d_Canvas3D_ctxUpdateEyeLightingEnable( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateSeparateSpecularColorEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_updateSeparateSpecularColorEnable( JNIEnv *env, jobject obj, jlong ctxInfo, jboolean enable) { - /* - * This method will not be called if the rendering layer does not support - * separate specular color control. The checking of the availability - * of the functionality is done in Renderer at rendering time - */ - - /* 1.2 feature only */ - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if(ctxProperties->seperate_specular_color) { - if (enable == JNI_TRUE) { - glLightModeli(ctxProperties->light_model_color_control_enum, - ctxProperties->seperate_specular_color_enum); - } else { - glLightModeli(ctxProperties->light_model_color_control_enum, ctxProperties->single_color_enum); - } + if (enable) { + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); + } else { + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_TextureUnitStateRetained_updateTextureUnitState( +void JNICALL Java_javax_media_j3d_NativePipeline_updateTextureUnitState( JNIEnv *env, - jobject cv, + jobject obj, jlong ctxInfo, jint index, jboolean enable) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - - if(ctxProperties->arb_multitexture) { - if (index >= 0) { - ctxProperties->glActiveTextureARB(index + GL_TEXTURE0_ARB); - ctxProperties->glClientActiveTextureARB(GL_TEXTURE0_ARB + index); - if (ctxProperties->textureRegisterCombinersAvailable) { - ctxProperties->currentTextureUnit = index + GL_TEXTURE0_ARB; - ctxProperties->currentCombinerUnit = index + GL_COMBINER0_NV; - if (ctxProperties->glCombinerParameteriNV!=NULL) - ctxProperties->glCombinerParameteriNV( - GL_NUM_GENERAL_COMBINERS_NV, index + 1); - } - } - } /* GL_ARB_multitexture */ + if (ctxProperties->gl13 && index >= 0) { + ctxProperties->glActiveTexture(index + GL_TEXTURE0); + ctxProperties->glClientActiveTexture(GL_TEXTURE0 + index); + if (ctxProperties->textureRegisterCombinersAvailable) { + ctxProperties->currentTextureUnit = index + GL_TEXTURE0; + ctxProperties->currentCombinerUnit = index + GL_COMBINER0_NV; + if (ctxProperties->glCombinerParameteriNV != NULL) + ctxProperties->glCombinerParameteriNV( + GL_NUM_GENERAL_COMBINERS_NV, index + 1); + } + } if (enable == JNI_FALSE) { /* if not enabled, then don't enable any tex mapping */ glDisable(GL_TEXTURE_1D); glDisable(GL_TEXTURE_2D); - - if(ctxProperties->texture3DAvailable) - glDisable(ctxProperties->texture_3D_ext_enum); - - if(ctxProperties->textureCubeMapAvailable) - glDisable(ctxProperties->texture_cube_map_ext_enum); - } + glDisable(GL_TEXTURE_3D); + glDisable(GL_TEXTURE_CUBE_MAP); + } /* * if it is enabled, the enable flag will be taken care of @@ -3517,7 +3561,7 @@ void JNICALL Java_javax_media_j3d_TextureUnitStateRetained_updateTextureUnitStat JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setBlendColor( +void JNICALL Java_javax_media_j3d_NativePipeline_setBlendColor( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -3541,7 +3585,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setBlendColor( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setBlendFunc( +void JNICALL Java_javax_media_j3d_NativePipeline_setBlendFunc( JNIEnv * env, jobject obj, jlong ctxInfo, @@ -3555,7 +3599,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setBlendFunc( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setFogEnableFlag( +void JNICALL Java_javax_media_j3d_NativePipeline_setFogEnableFlag( JNIEnv * env, jobject obj, jlong ctxInfo, @@ -3568,7 +3612,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setFogEnableFlag( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_activeTextureUnit( +void JNICALL Java_javax_media_j3d_NativePipeline_activeTextureUnit( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -3576,28 +3620,12 @@ void JNICALL Java_javax_media_j3d_Canvas3D_activeTextureUnit( { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if(ctxProperties->arb_multitexture){ - ctxProperties->glActiveTextureARB(GL_TEXTURE0_ARB + index); - ctxProperties->glClientActiveTextureARB(GL_TEXTURE0_ARB + index); - /* GL_ARB_multitexture */ + if (ctxProperties->gl13) { + ctxProperties->glActiveTexture(GL_TEXTURE0 + index); + ctxProperties->glClientActiveTexture(GL_TEXTURE0 + index); } } -JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_updateTexUnitStateMap( - JNIEnv *env, - jobject obj, - jlong ctxInfo, - jint numActiveTexUnit, - jintArray texUnitStateMapArray) -{ - /* - * texture unit state map is explicitly handled in - * execute; for display list, texture unit has to match - * texture unit state. - */ -} - /* * strJavaToC @@ -3699,13 +3727,3 @@ createShaderError( return shaderError; } - - -void -throwAssert(JNIEnv *env, char *str) -{ - jclass rte; - if ((rte = (*env)->FindClass(env, "java/lang/AssertionError")) != NULL) { - (*env)->ThrowNew(env, rte, str); - } -} diff --git a/src/native/ogl/Canvas3D.c b/src/native/ogl/Canvas3D.c index 9c15e92..b6cb469 100644 --- a/src/native/ogl/Canvas3D.c +++ b/src/native/ogl/Canvas3D.c @@ -43,19 +43,18 @@ extern void throwAssert(JNIEnv *env, char *str); static void initializeCtxInfo(JNIEnv *env, GraphicsContextPropertiesInfo* ctxInfo); static void cleanupCtxInfo(GraphicsContextPropertiesInfo* ctxInfo); static void disableAttribFor2D(GraphicsContextPropertiesInfo *ctxProperties); +static void disableAttribForRaster(GraphicsContextPropertiesInfo *ctxProperties); /* * Class: javax_media_j3d_Canvas3D * Method: getTextureColorTableSize * Signature: ()I */ -extern int getTextureColorTableSize( +static int getTextureColorTableSize( JNIEnv *env, jobject obj, - jlong ctxInfo, - char *extensionStr, - int minorVersion); - + GraphicsContextPropertiesInfo *ctxInfo, + char *extensionStr); extern void checkGLSLShaderExtensions( JNIEnv *env, @@ -138,26 +137,25 @@ checkTextureExtensions( JNIEnv *env, jobject obj, char *tmpExtensionStr, - int versionNumber, GraphicsContextPropertiesInfo* ctxInfo) { - if (isExtensionSupported(tmpExtensionStr, "GL_ARB_multitexture")) { - ctxInfo->arb_multitexture = JNI_TRUE; + if (ctxInfo->gl13) { ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_MULTI_TEXTURE; - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &ctxInfo->maxTextureUnits); + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ctxInfo->maxTextureUnits); ctxInfo->maxTexCoordSets = ctxInfo->maxTextureUnits; if (isExtensionSupported(tmpExtensionStr, "GL_ARB_vertex_shader")) { glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &ctxInfo->maxTexCoordSets); } } - + if(isExtensionSupported(tmpExtensionStr,"GL_SGI_texture_color_table" )){ ctxInfo->textureColorTableAvailable = JNI_TRUE; ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_COLOR_TABLE; /* get texture color table size */ /* need to check later */ - ctxInfo->textureColorTableSize = getTextureColorTableSize(env, obj, (jlong)ctxInfo, tmpExtensionStr, versionNumber); + ctxInfo->textureColorTableSize = getTextureColorTableSize(env, obj, + ctxInfo, tmpExtensionStr); if (ctxInfo->textureColorTableSize <= 0) { ctxInfo->textureColorTableAvailable = JNI_FALSE; ctxInfo->textureExtMask &= ~javax_media_j3d_Canvas3D_TEXTURE_COLOR_TABLE; @@ -289,13 +287,7 @@ checkTextureExtensions( ctxInfo->combine_dot3_rgba_enum = GL_DOT3_RGBA_EXT; } - if (isExtensionSupported(tmpExtensionStr, "GL_ARB_texture_cube_map")) { - ctxInfo->texture_cube_map_ext_enum = GL_TEXTURE_CUBE_MAP_ARB; - ctxInfo->textureCubeMapAvailable = JNI_TRUE; - ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_CUBE_MAP; - } else if (isExtensionSupported(tmpExtensionStr, "GL_EXT_texture_cube_map")) { - ctxInfo->texture_cube_map_ext_enum = GL_TEXTURE_CUBE_MAP_EXT; - ctxInfo->textureCubeMapAvailable = JNI_TRUE; + if (ctxInfo->gl13) { ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_CUBE_MAP; } @@ -374,22 +366,26 @@ checkTextureExtensions( javax_media_j3d_Canvas3D_TEXTURE_ANISOTROPIC_FILTER; } - if (isExtensionSupported(tmpExtensionStr, - "GL_ARB_texture_border_clamp")) { - ctxInfo->texture_clamp_to_border_enum = GL_CLAMP_TO_BORDER_ARB; - } else if (isExtensionSupported(tmpExtensionStr, - "GL_SGIS_texture_border_clamp")) { - ctxInfo->texture_clamp_to_border_enum = GL_CLAMP_TO_BORDER_SGIS; + if (ctxInfo->gl13) { + ctxInfo->texture_clamp_to_border_enum = GL_CLAMP_TO_BORDER; } else { ctxInfo->texture_clamp_to_border_enum = GL_CLAMP; } - + if (isExtensionSupported(tmpExtensionStr, "GL_SGIX_texture_lod_bias")) { ctxInfo->textureLodBiasAvailable = JNI_TRUE; ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_LOD_OFFSET; } + + if (isExtensionSupported(tmpExtensionStr, + "GL_ARB_texture_non_power_of_two")) { + ctxInfo->textureNonPowerOfTwoAvailable = JNI_TRUE; + ctxInfo->textureExtMask |= + javax_media_j3d_Canvas3D_TEXTURE_NON_POWER_OF_TWO; + } + } jboolean @@ -433,6 +429,47 @@ getJavaBoolEnv(JNIEnv *env, char* envStr) return (*(table->GetBooleanField))(env, obj, fieldID); } +jint +getJavaIntEnv(JNIEnv *env, char* envStr) +{ + JNIEnv table = *env; + jclass cls; + jfieldID fieldID; + jobject obj; + + cls = (jclass) (*(table->FindClass))(env, "javax/media/j3d/VirtualUniverse"); + + if (cls == NULL) { + return JNI_FALSE; + } + + fieldID = (jfieldID) (*(table->GetStaticFieldID))(env, cls, "mc", + "Ljavax/media/j3d/MasterControl;"); + if (fieldID == NULL) { + return JNI_FALSE; + } + + obj = (*(table->GetStaticObjectField))(env, cls, fieldID); + + if (obj == NULL) { + return JNI_FALSE; + } + + cls = (jclass) (*(table->FindClass))(env, "javax/media/j3d/MasterControl"); + + if (cls == NULL) { + return JNI_FALSE; + } + + fieldID = (jfieldID) (*(table->GetFieldID))(env, cls, envStr, "I"); + + if (fieldID == NULL ) { + return JNI_FALSE; + } + + return (*(table->GetIntField))(env, obj, fieldID); +} + /* * Dummy functions for language-independent vertex attribute functions */ @@ -536,88 +573,96 @@ getPropertiesFromCurrentContext( /* find out the version, major and minor version number */ extractVersionInfo(tmpVersionStr, versionNumbers); + /* *********************************************************/ /* setup the graphics context properties */ - /* NOTE : At some point we will want to require OpenGL 1.3 */ - /* Check for OpenGL 1.2 core or better */ - if ((versionNumbers[0] > 1) || - (versionNumbers[0] == 1 && versionNumbers[1] >= 2)) { + /* + * NOTE: Java 3D now requires OpenGL 1.3 for full functionality. + * For backwards compatibility with certain older graphics cards and + * drivers (e.g., the Linux DRI driver for older ATI cards), + * we will try to run on OpenGL 1.2 in an unsupported manner. However, + * we will not attempt to use OpenGL extensions for any features that + * are available in OpenGL 1.3, specifically multitexture, multisample, + * and cube map textures. + */ + if (versionNumbers[0] < 1 || + (versionNumbers[0] == 1 && versionNumbers[1] < 2)) { + jclass rte; - if (versionNumbers[0] == 1 && versionNumbers[1] == 2) { - fprintf(stderr, - "Java 3D WARNING : OpenGL 1.3 will be required in the near future (GL_VERSION=%d.%d)\n", + fprintf(stderr, + "Java 3D ERROR : OpenGL 1.2 or better is required (GL_VERSION=%d.%d)\n", versionNumbers[0], versionNumbers[1]); + if ((rte = (*(table->FindClass))(env, "javax/media/j3d/IllegalRenderingStateException")) != NULL) { + (*(table->ThrowNew))(env, rte, "GL_VERSION"); } + return JNI_FALSE; + } - ctxInfo->rescale_normal_ext = JNI_TRUE; - ctxInfo->rescale_normal_ext_enum = GL_RESCALE_NORMAL; - ctxInfo->bgr_ext = JNI_TRUE; - ctxInfo->bgr_ext_enum = GL_BGR; - ctxInfo->texture3DAvailable = JNI_TRUE; - ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_3D; + if (versionNumbers[0] > 1) { + /* OpenGL 2.x -- set flags for 1.3 and 2.0 or greater */ + ctxInfo->gl20 = JNI_TRUE; + ctxInfo->gl13 = JNI_TRUE; + } + else { + if (versionNumbers[1] == 2) { + fprintf(stderr, + "*********************************************************\n"); + fprintf(stderr, + "*** JAVA 3D: WARNING OpenGL 1.2 is no longer supported.\n"); + fprintf(stderr, + "*** Will attempt to run with reduced functionality.\n"); + fprintf(stderr, + "*********************************************************\n"); + } else { + // OpenGL 1.x (1.3 or greater) + ctxInfo->gl13 = JNI_TRUE; + } + } + + + /* Setup function pointers for core OpenGL 1.3 features */ + + ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_3D; #if defined(UNIX) - ctxInfo->glTexImage3DEXT = (MYPFNGLTEXIMAGE3DPROC )dlsym(RTLD_DEFAULT, "glTexImage3D"); - ctxInfo->glTexSubImage3DEXT = (MYPFNGLTEXSUBIMAGE3DPROC )dlsym(RTLD_DEFAULT, "glTexSubImage3D"); + ctxInfo->glTexImage3DEXT = (MYPFNGLTEXIMAGE3DPROC )dlsym(RTLD_DEFAULT, "glTexImage3D"); + ctxInfo->glTexSubImage3DEXT = (MYPFNGLTEXSUBIMAGE3DPROC )dlsym(RTLD_DEFAULT, "glTexSubImage3D"); #endif #ifdef WIN32 - ctxInfo->glTexImage3DEXT = (MYPFNGLTEXIMAGE3DPROC )wglGetProcAddress("glTexImage3D"); - ctxInfo->glTexSubImage3DEXT = (MYPFNGLTEXSUBIMAGE3DPROC )wglGetProcAddress("glTexSubImage3D"); - if ((ctxInfo->glTexImage3DEXT == NULL) || (ctxInfo->glTexSubImage3DEXT == NULL)) { - ctxInfo->textureExtMask &= ~javax_media_j3d_Canvas3D_TEXTURE_3D; - ctxInfo->texture3DAvailable = JNI_FALSE; - } + ctxInfo->glTexImage3DEXT = (MYPFNGLTEXIMAGE3DPROC )wglGetProcAddress("glTexImage3D"); + ctxInfo->glTexSubImage3DEXT = (MYPFNGLTEXSUBIMAGE3DPROC )wglGetProcAddress("glTexSubImage3D"); #endif - ctxInfo->texture_3D_ext_enum = GL_TEXTURE_3D; - ctxInfo->texture_wrap_r_ext_enum = GL_TEXTURE_WRAP_R; - ctxInfo->texture_clamp_to_edge_enum = GL_CLAMP_TO_EDGE; - if(isExtensionSupported(tmpExtensionStr, "GL_ARB_imaging")){ - ctxInfo->blend_color_ext = JNI_TRUE; - - ctxInfo->blendFunctionTable[BLEND_CONSTANT_COLOR] = GL_CONSTANT_COLOR; + if(isExtensionSupported(tmpExtensionStr, "GL_ARB_imaging")){ + ctxInfo->blend_color_ext = JNI_TRUE; + + ctxInfo->blendFunctionTable[BLEND_CONSTANT_COLOR] = GL_CONSTANT_COLOR; #if defined(UNIX) - ctxInfo->glBlendColor = (MYPFNGLBLENDCOLORPROC )dlsym(RTLD_DEFAULT, "glBlendColor"); + ctxInfo->glBlendColor = (MYPFNGLBLENDCOLORPROC )dlsym(RTLD_DEFAULT, "glBlendColor"); #endif #ifdef WIN32 - ctxInfo->glBlendColor = (MYPFNGLBLENDCOLORPROC )wglGetProcAddress("glBlendColor"); - if (ctxInfo->glBlendColor == NULL) { - ctxInfo->blend_color_ext = JNI_FALSE; - } + ctxInfo->glBlendColor = (MYPFNGLBLENDCOLORPROC )wglGetProcAddress("glBlendColor"); + if (ctxInfo->glBlendColor == NULL) { + ctxInfo->blend_color_ext = JNI_FALSE; + } #endif - } - - ctxInfo->seperate_specular_color = JNI_TRUE; - ctxInfo->light_model_color_control_enum = GL_LIGHT_MODEL_COLOR_CONTROL; - ctxInfo->single_color_enum = GL_SINGLE_COLOR; - ctxInfo->seperate_specular_color_enum = GL_SEPARATE_SPECULAR_COLOR; + } - ctxInfo->textureLodAvailable = JNI_TRUE; - ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_LOD_RANGE; - ctxInfo->texture_min_lod_enum = GL_TEXTURE_MIN_LOD; - ctxInfo->texture_max_lod_enum = GL_TEXTURE_MAX_LOD; - ctxInfo->texture_base_level_enum = GL_TEXTURE_BASE_LEVEL; - ctxInfo->texture_max_level_enum = GL_TEXTURE_MAX_LEVEL; + ctxInfo->textureLodAvailable = JNI_TRUE; + ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_LOD_RANGE; + ctxInfo->texture_min_lod_enum = GL_TEXTURE_MIN_LOD; + ctxInfo->texture_max_lod_enum = GL_TEXTURE_MAX_LOD; + ctxInfo->texture_base_level_enum = GL_TEXTURE_BASE_LEVEL; + ctxInfo->texture_max_level_enum = GL_TEXTURE_MAX_LEVEL; - /* ... */ - } - else { - jclass rte; - fprintf(stderr, - "Java 3D ERROR : OpenGL 1.2 or better is required (GL_VERSION=%d.%d)\n", - versionNumbers[0], versionNumbers[1]); - if ((rte = (*(table->FindClass))(env, "java/lang/IllegalStateException")) != NULL) { - (*(table->ThrowNew))(env, rte, "GL_VERSION"); - } - return JNI_FALSE; + /* look for OpenGL 2.0 features */ + if (ctxInfo->gl20) { + ctxInfo->textureNonPowerOfTwoAvailable = JNI_TRUE; + ctxInfo->textureExtMask |= + javax_media_j3d_Canvas3D_TEXTURE_NON_POWER_OF_TWO; } - /* - * TODO: Remove extension checks for those features that are core - * in OpenGL 1.2 and just use the core feature. - */ - /* check extensions for remaining of 1.1 and 1.2 */ if(isExtensionSupported(tmpExtensionStr, "GL_EXT_multi_draw_arrays")){ ctxInfo->multi_draw_arrays_ext = JNI_TRUE; @@ -632,45 +677,29 @@ getPropertiesFromCurrentContext( ctxInfo->compiled_vertex_array_ext = JNI_TRUE; } - - if(isExtensionSupported(tmpExtensionStr, "GLX_SUN_video_resize")){ - ctxInfo->videoResizeAvailable = JNI_TRUE; - ctxInfo->extMask |= javax_media_j3d_Canvas3D_SUN_VIDEO_RESIZE; - } - if(isExtensionSupported(tmpExtensionStr, "GL_SUN_global_alpha")){ ctxInfo->global_alpha_sun = JNI_TRUE; } - if(isExtensionSupported(tmpExtensionStr, "GL_SUNX_constant_data")){ - ctxInfo->constant_data_sun = JNI_TRUE; - } - if(isExtensionSupported(tmpExtensionStr, "GL_EXT_abgr")) { ctxInfo->abgr_ext = JNI_TRUE; } - - if(isExtensionSupported(tmpExtensionStr, "GL_ARB_transpose_matrix")) { - ctxInfo->arb_transpose_matrix = JNI_TRUE; - } -#if defined(UNIX) /* - * setup ARB_multisample, under windows this is setup in + * Setup ctxInfo->multisample; under windows this is setup in * NativeConfigTemplate when pixel format is choose */ - if (isExtensionSupported(tmpExtensionStr, "GL_ARB_multisample")){ - ctxInfo->arb_multisample = JNI_TRUE; - } +#if defined(UNIX) + ctxInfo->multisample = ctxInfo->gl13; #endif #ifdef WIN32 if(offScreen) { - ctxInfo->arb_multisample = PixelFormatInfoPtr->offScreenHasMultisample; + ctxInfo->multisample = PixelFormatInfoPtr->offScreenHasMultisample; } else { - ctxInfo->arb_multisample = PixelFormatInfoPtr->onScreenHasMultisample; + ctxInfo->multisample = PixelFormatInfoPtr->onScreenHasMultisample; } /* @@ -678,8 +707,8 @@ getPropertiesFromCurrentContext( PixelFormatInfoPtr->onScreenHasMultisample, PixelFormatInfoPtr->offScreenHasMultisample); - fprintf(stderr, "Canvas3D - ctxInfo->arb_multisample = %d, offScreen = %d\n", - ctxInfo->arb_multisample, offScreen); + fprintf(stderr, "Canvas3D - ctxInfo->multisample = %d, offScreen = %d\n", + ctxInfo->multisample, offScreen); */ #endif @@ -688,75 +717,43 @@ getPropertiesFromCurrentContext( * Disable multisample by default since OpenGL will enable * it by default if the surface is multisample capable. */ - if (ctxInfo->arb_multisample && !ctxInfo->implicit_multisample) { - glDisable(GL_MULTISAMPLE_ARB); + if (ctxInfo->multisample && !ctxInfo->implicit_multisample) { + glDisable(GL_MULTISAMPLE); } /* Check texture extensions */ - checkTextureExtensions(env, obj, tmpExtensionStr, versionNumbers[1], - ctxInfo); + checkTextureExtensions(env, obj, tmpExtensionStr, ctxInfo); /* Check shader extensions */ - checkGLSLShaderExtensions(env, obj, tmpExtensionStr, ctxInfo, glslLibraryAvailable); - checkCgShaderExtensions(env, obj, tmpExtensionStr, ctxInfo, cgLibraryAvailable); - - /* ... */ - - /* *********************************************************/ - /* Set up rescale_normal if extension supported */ - if (ctxInfo->rescale_normal_ext ) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_RESCALE_NORMAL; + if (ctxInfo->gl13) { + checkGLSLShaderExtensions(env, obj, tmpExtensionStr, ctxInfo, glslLibraryAvailable); + checkCgShaderExtensions(env, obj, tmpExtensionStr, ctxInfo, cgLibraryAvailable); + } else { + /* Force shaders to be disabled, since no multitexture support */ + char *emptyExtStr = " "; + checkGLSLShaderExtensions(env, obj, emptyExtStr, ctxInfo, JNI_FALSE); + checkCgShaderExtensions(env, obj, emptyExtStr, ctxInfo, JNI_FALSE); } - /* Setup the multi_draw_array */ - if(ctxInfo->multi_draw_arrays_ext) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_MULTI_DRAW_ARRAYS; - } else if (ctxInfo->multi_draw_arrays_sun) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_SUN_MULTI_DRAW_ARRAYS; - } - if(ctxInfo->compiled_vertex_array_ext) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_COMPILED_VERTEX_ARRAYS; - } - + /* *********************************************************/ /* Setup GL_SUN_gloabl_alpha */ if (ctxInfo->global_alpha_sun) { ctxInfo->extMask |= javax_media_j3d_Canvas3D_SUN_GLOBAL_ALPHA; } - /* Setup GL_SUNX_constant_data */ - if (ctxInfo->constant_data_sun) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_SUN_CONSTANT_DATA; - } - /* Setup GL_EXT_abgr */ if (ctxInfo->abgr_ext) { ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_ABGR; } - /* Setup GL_BGR_EXT */ - if (ctxInfo->bgr_ext) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_BGR; - } + /* GL_BGR is always supported */ + ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_BGR; - /* Setup GL_ARB_transpose_matrix */ - if (ctxInfo->arb_transpose_matrix) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_ARB_TRANSPOSE_MATRIX; - } - - /* Setup GL_EXT_separate_specular_color */ - if(ctxInfo->seperate_specular_color) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_EXT_SEPARATE_SPECULAR_COLOR; - } - - if (ctxInfo->constant_data_sun) { - /* glPixelStorei(GL_UNPACK_CONSTANT_DATA_SUNX, GL_TRUE); */ + if(ctxInfo->multisample) { + ctxInfo->extMask |= javax_media_j3d_Canvas3D_MULTISAMPLE; } - - if(ctxInfo->arb_multisample) { - ctxInfo->extMask |= javax_media_j3d_Canvas3D_ARB_MULTISAMPLE; - } - + /* setup those functions pointers */ #ifdef WIN32 @@ -786,53 +783,15 @@ getPropertiesFromCurrentContext( } } - if (ctxInfo->arb_multitexture) { - ctxInfo->glClientActiveTextureARB = (MYPFNGLCLIENTACTIVETEXTUREARBPROC)wglGetProcAddress("glClientActiveTextureARB"); - ctxInfo->glMultiTexCoord2fvARB = (MYPFNGLMULTITEXCOORD2FVARBPROC)wglGetProcAddress("glMultiTexCoord2fvARB"); - ctxInfo->glMultiTexCoord3fvARB = (MYPFNGLMULTITEXCOORD3FVARBPROC)wglGetProcAddress("glMultiTexCoord3fvARB"); - ctxInfo->glMultiTexCoord4fvARB = (MYPFNGLMULTITEXCOORD4FVARBPROC)wglGetProcAddress("glMultiTexCoord4fvARB"); - ctxInfo->glActiveTextureARB = (MYPFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB"); - /* - if (ctxInfo->glClientActiveTextureARB == NULL) { - printf("ctxInfo->glClientActiveTextureARB == NULL\n"); - } - if (ctxInfo->glMultiTexCoord2fvARB == NULL) { - printf("ctxInfo->glMultiTexCoord2fvARB == NULL\n"); - } - if (ctxInfo->glMultiTexCoord3fvARB == NULL) { - printf("ctxInfo->glMultiTexCoord3fvARB == NULL\n"); - } - if (ctxInfo->glMultiTexCoord4fvARB == NULL) { - printf("ctxInfo->glMultiTexCoord4fvARB == NULL\n"); - } - if (ctxInfo->glActiveTextureARB == NULL) { - printf("ctxInfo->glActiveTextureARB == NULL\n"); - } - */ - if ((ctxInfo->glClientActiveTextureARB == NULL) || - (ctxInfo->glMultiTexCoord2fvARB == NULL) || - (ctxInfo->glMultiTexCoord3fvARB == NULL) || - (ctxInfo->glMultiTexCoord4fvARB == NULL) || - (ctxInfo->glActiveTextureARB == NULL)) { - ctxInfo->arb_multitexture = JNI_FALSE; - } - } - - if(ctxInfo->arb_transpose_matrix) { - ctxInfo->glLoadTransposeMatrixdARB = (MYPFNGLLOADTRANSPOSEMATRIXDARBPROC)wglGetProcAddress("glLoadTransposeMatrixdARB"); - ctxInfo->glMultTransposeMatrixdARB = (MYPFNGLMULTTRANSPOSEMATRIXDARBPROC)wglGetProcAddress("glMultTransposeMatrixdARB"); - /* - if (ctxInfo->glLoadTransposeMatrixdARB == NULL) { - printf("ctxInfo->glLoadTransposeMatrixdARB == NULL\n"); - } - if (ctxInfo->glMultTransposeMatrixdARB == NULL) { - printf("ctxInfo->glMultTransposeMatrixdARB == NULL\n"); - } - */ - if ((ctxInfo->glLoadTransposeMatrixdARB == NULL) || - (ctxInfo->glMultTransposeMatrixdARB == NULL)) { - ctxInfo->arb_transpose_matrix = JNI_FALSE; - } + if (ctxInfo->gl13) { + ctxInfo->glClientActiveTexture = (MYPFNGLCLIENTACTIVETEXTUREPROC)wglGetProcAddress("glClientActiveTexture"); + ctxInfo->glActiveTexture = (MYPFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTexture"); + ctxInfo->glMultiTexCoord2fv = (MYPFNGLMULTITEXCOORD2FVPROC)wglGetProcAddress("glMultiTexCoord2fv"); + ctxInfo->glMultiTexCoord3fv = (MYPFNGLMULTITEXCOORD3FVPROC)wglGetProcAddress("glMultiTexCoord3fv"); + ctxInfo->glMultiTexCoord4fv = (MYPFNGLMULTITEXCOORD4FVPROC)wglGetProcAddress("glMultiTexCoord4fv"); + + ctxInfo->glLoadTransposeMatrixd = (MYPFNGLLOADTRANSPOSEMATRIXDPROC)wglGetProcAddress("glLoadTransposeMatrixd"); + ctxInfo->glMultTransposeMatrixd = (MYPFNGLMULTTRANSPOSEMATRIXDPROC)wglGetProcAddress("glMultTransposeMatrixd"); } if (ctxInfo->global_alpha_sun) { @@ -878,35 +837,24 @@ getPropertiesFromCurrentContext( } } - if(ctxInfo->arb_multitexture){ - ctxInfo->glClientActiveTextureARB = - (MYPFNGLCLIENTACTIVETEXTUREARBPROC)dlsym(RTLD_DEFAULT, "glClientActiveTextureARB"); - ctxInfo->glMultiTexCoord2fvARB = - (MYPFNGLMULTITEXCOORD2FVARBPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord2fvARB"); - ctxInfo->glMultiTexCoord3fvARB = - (MYPFNGLMULTITEXCOORD3FVARBPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord3fvARB"); - ctxInfo->glMultiTexCoord4fvARB = - (MYPFNGLMULTITEXCOORD4FVARBPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord4fvARB"); - ctxInfo->glActiveTextureARB = - (MYPFNGLACTIVETEXTUREARBPROC)dlsym(RTLD_DEFAULT, "glActiveTextureARB"); - if ((ctxInfo->glClientActiveTextureARB == NULL) || - (ctxInfo->glMultiTexCoord2fvARB == NULL) || - (ctxInfo->glMultiTexCoord3fvARB == NULL) || - (ctxInfo->glMultiTexCoord4fvARB == NULL) || - (ctxInfo->glActiveTextureARB == NULL)) { - ctxInfo->arb_multitexture = JNI_FALSE; - } - } - if(ctxInfo->arb_transpose_matrix) { - ctxInfo->glLoadTransposeMatrixdARB = - (MYPFNGLLOADTRANSPOSEMATRIXDARBPROC)dlsym(RTLD_DEFAULT, "glLoadTransposeMatrixdARB"); - ctxInfo->glMultTransposeMatrixdARB = - (MYPFNGLMULTTRANSPOSEMATRIXDARBPROC)dlsym(RTLD_DEFAULT, "glMultTransposeMatrixdARB"); - if ((ctxInfo->glLoadTransposeMatrixdARB == NULL) || - (ctxInfo->glMultTransposeMatrixdARB == NULL)) { - ctxInfo->arb_transpose_matrix = JNI_FALSE; - } + if(ctxInfo->gl13){ + ctxInfo->glClientActiveTexture = + (MYPFNGLCLIENTACTIVETEXTUREPROC)dlsym(RTLD_DEFAULT, "glClientActiveTexture"); + ctxInfo->glMultiTexCoord2fv = + (MYPFNGLMULTITEXCOORD2FVPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord2fv"); + ctxInfo->glMultiTexCoord3fv = + (MYPFNGLMULTITEXCOORD3FVPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord3fv"); + ctxInfo->glMultiTexCoord4fv = + (MYPFNGLMULTITEXCOORD4FVPROC)dlsym(RTLD_DEFAULT, "glMultiTexCoord4fv"); + ctxInfo->glActiveTexture = + (MYPFNGLACTIVETEXTUREPROC)dlsym(RTLD_DEFAULT, "glActiveTexture"); + + ctxInfo->glLoadTransposeMatrixd = + (MYPFNGLLOADTRANSPOSEMATRIXDPROC)dlsym(RTLD_DEFAULT, "glLoadTransposeMatrixd"); + ctxInfo->glMultTransposeMatrixd = + (MYPFNGLMULTTRANSPOSEMATRIXDPROC)dlsym(RTLD_DEFAULT, "glMultTransposeMatrixd"); } + if(ctxInfo->global_alpha_sun) { ctxInfo->glGlobalAlphaFactorfSUN = (MYPFNGLGLOBALALPHAFACTORFSUNPROC)dlsym(RTLD_DEFAULT, "glGlobalAlphaFactorfSUN"); @@ -914,15 +862,6 @@ getPropertiesFromCurrentContext( ctxInfo->global_alpha_sun = JNI_FALSE; } } - - if(ctxInfo->videoResizeAvailable) { - ctxInfo->glXVideoResizeSUN = - (MYPFNGLXVIDEORESIZESUN)dlsym(RTLD_DEFAULT, "glXVideoResizeSUN"); - if (ctxInfo->glXVideoResizeSUN == NULL) { - ctxInfo->videoResizeAvailable = JNI_FALSE; - ctxInfo->extMask &= ~javax_media_j3d_Canvas3D_SUN_VIDEO_RESIZE; - } - } #endif /* UNIX */ @@ -950,22 +889,20 @@ void setupCanvasProperties( /* set the canvas.multiTexAccelerated flag */ rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "multiTexAccelerated", "Z"); - (*(table->SetBooleanField))(env, obj, rsc_field, ctxInfo->arb_multitexture); - - if (ctxInfo->arb_multitexture) { - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTextureUnits", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTextureUnits); - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTexCoordSets", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTexCoordSets); - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTextureImageUnits", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTextureImageUnits); - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxVertexTextureImageUnits", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxVertexTextureImageUnits); - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxCombinedTextureImageUnits", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxCombinedTextureImageUnits); - rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxVertexAttrs", "I"); - (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxVertexAttrs); - } + (*(table->SetBooleanField))(env, obj, rsc_field, ctxInfo->gl13); + + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTextureUnits", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTextureUnits); + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTexCoordSets", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTexCoordSets); + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxTextureImageUnits", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxTextureImageUnits); + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxVertexTextureImageUnits", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxVertexTextureImageUnits); + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxCombinedTextureImageUnits", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxCombinedTextureImageUnits); + rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "maxVertexAttrs", "I"); + (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->maxVertexAttrs); rsc_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "extensionsSupported", "I"); (*(table->SetIntField))(env, obj, rsc_field, ctxInfo->extMask); @@ -1025,11 +962,11 @@ void setupCanvasProperties( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_destroyContext( +void JNICALL Java_javax_media_j3d_NativePipeline_destroyContext( JNIEnv *env, - jclass cl, + jobject obj, jlong display, - jint window, + jlong window, jlong ctxInfo) { GraphicsContextPropertiesInfo* s = (GraphicsContextPropertiesInfo* )ctxInfo; @@ -1075,12 +1012,12 @@ LONG WINAPI WndProc( HWND hWnd, UINT msg, JNIEXPORT -jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( +jlong JNICALL Java_javax_media_j3d_NativePipeline_createNewContext( JNIEnv *env, jobject obj, + jobject cv, jlong display, - jint window, - jint vid, + jlong window, jlong fbConfigListPtr, jlong sharedCtxInfo, jboolean isSharedCtx, @@ -1092,9 +1029,6 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( jlong sharedCtx; int stencilSize=0; - static GLboolean first_time = GL_TRUE; - static GLboolean force_normalize = GL_FALSE; - GraphicsContextPropertiesInfo *ctxInfo = NULL; GraphicsContextPropertiesInfo *sharedCtxStructure; int PixelFormatID=0; @@ -1133,7 +1067,7 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( else if((fbConfigList == NULL) || (fbConfigList[0] == NULL)) { /* * fbConfig must be a valid pointer to an GLXFBConfig struct returned - * by glXChooseFBConfig() for a physical screen. The visual id in vid + * by glXChooseFBConfig() for a physical screen. The visual id * is not sufficient for handling OpenGL with Xinerama mode disabled: * it doesn't distinguish between the physical screens making up the * virtual screen when the X server is running in Xinerama mode. @@ -1186,7 +1120,7 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( /* fprintf(stderr, "Canvas3D_createNewContext: \n"); - fprintf(stderr, "vid %d window 0x%x\n", vid, window); + fprintf(stderr, "window 0x%x\n", window); */ if(sharedCtxInfo == 0) sharedCtx = 0; @@ -1198,11 +1132,7 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( hdc = (HDC) window; /* Need to handle onScreen and offScreen differently */ - /* vid is for onScreen and fbConfigListPtr is for offScreen */ - /* - * vid must be a PixelFormat returned - * by wglChoosePixelFormat() or wglChoosePixelFormatARB. - */ + /* fbConfigListPtr has both an on-screen and off-screen pixel format */ if(!offScreen) { /* Fix to issue 104 */ if ((PixelFormatInfoPtr == NULL) || (PixelFormatInfoPtr->onScreenPFormat <= 0)) { @@ -1268,53 +1198,41 @@ jlong JNICALL Java_javax_media_j3d_Canvas3D_createNewContext( initializeCtxInfo(env, ctxInfo); ctxInfo->context = gctx; - if (!getPropertiesFromCurrentContext(env, obj, ctxInfo, (jlong) hdc, PixelFormatID, + if (!getPropertiesFromCurrentContext(env, cv, ctxInfo, (jlong) hdc, PixelFormatID, fbConfigListPtr, offScreen, glslLibraryAvailable, cgLibraryAvailable)) { return 0; } - /* setup structure */ if(!isSharedCtx){ /* Setup field in Java side */ - setupCanvasProperties(env, obj, ctxInfo); - } - - /* Set up rescale_normal if extension supported */ - if (first_time && getJavaBoolEnv(env, "isForceNormalized")) { - force_normalize = GL_TRUE; - first_time = GL_FALSE; + setupCanvasProperties(env, cv, ctxInfo); } - if (force_normalize) { - /* Disable rescale normal */ - ctxInfo->rescale_normal_ext = GL_FALSE; - } - - if (ctxInfo->rescale_normal_ext ) { - glEnable(ctxInfo->rescale_normal_ext_enum); - } - else { - glEnable(GL_NORMALIZE); - } + /* Enable rescale normal */ + glEnable(GL_RESCALE_NORMAL); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glDepthFunc(GL_LEQUAL); glEnable(GL_COLOR_MATERIAL); glReadBuffer(GL_FRONT); + + /* Java 3D images are aligned to 1 byte */ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + return ((jlong)ctxInfo); } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_useCtx( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_useCtx( JNIEnv *env, - jclass cl, + jobject obj, jlong ctxInfo, jlong display, - jint window) + jlong window) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; @@ -1351,7 +1269,7 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_useCtx( } JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_getNumCtxLights( +jint JNICALL Java_javax_media_j3d_NativePipeline_getNumCtxLights( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -1362,112 +1280,8 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_getNumCtxLights( return((jint)nlights); } - - JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_composite( - JNIEnv *env, - jobject obj, - jlong ctxInfo, - jint px, - jint py, - jint minX, - jint minY, - jint maxX, - jint maxY, - jint rasWidth, - jbyteArray imageYdown, - jint winWidth, - jint winHeight) -{ - GLenum gltype; - JNIEnv table; - jbyte *byteData; - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - - table = *env; - -#ifdef VERBOSE - fprintf(stderr, "Canvas3D.composite()\n"); -#endif - /* Temporarily disable fragment and most 3D operations */ - /* XXXX: the GL_TEXTURE_BIT may not be necessary here */ - glPushAttrib(GL_ENABLE_BIT|GL_TEXTURE_BIT|GL_DEPTH_BUFFER_BIT); - disableAttribFor2D(ctxProperties); - - glEnable(GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - /* loaded identity modelview and projection matrix */ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0.0, (double)winWidth, 0.0, (double)winHeight, -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - /* start from upper left corner */ - glRasterPos2i(px + minX, winHeight-(py + minY)); - - glPixelZoom(1.0, -1.0); - - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - imageYdown, - NULL); - /* if abgr_ext is supported then the data will be in that format */ - if (ctxProperties->abgr_ext) { - gltype = GL_ABGR_EXT; - } else { - gltype = GL_RGBA; - } - - /* - * set the actual width of data which is the width of the canvas - * because what needs to be drawn may be smaller than the canvas - */ - glPixelStorei(GL_UNPACK_ROW_LENGTH, rasWidth); - - /* - * we only need to skip pixels if width of the area to draw is smaller - * than the width of the raster - */ - - /* - * skip this many rows in the data because the size of what - * needs to be drawn may be smaller than the canvas - */ - glPixelStorei(GL_UNPACK_SKIP_ROWS, minY); - /* - * skip this many pixels in the data before drawing because - * the size of what needs to be drawn may be smaller than the - * canvas - */ - glPixelStorei(GL_UNPACK_SKIP_PIXELS, minX); - - - glDrawPixels(maxX - minX, maxY - minY, - gltype, GL_UNSIGNED_BYTE, byteData); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - - glMatrixMode(GL_PROJECTION); - - glLoadIdentity(); - - (*(table->ReleasePrimitiveArrayCritical))(env, imageYdown, byteData, 0); - - /* Java 3D always clears the Z-buffer */ - glDepthMask(GL_TRUE); - glClear(GL_DEPTH_BUFFER_BIT); - - glPopAttrib(); -} - - -JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_initTexturemapping( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_initTexturemapping( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1505,7 +1319,7 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_initTexturemapping( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( +void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1545,7 +1359,6 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( /* glGetIntegerv(GL_TEXTURE_BINDING_2D,&binding); */ glDepthMask(GL_FALSE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, objectId); /* set up texture parameter */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -1581,10 +1394,10 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( gltype = GL_ABGR_EXT; } else { switch (format) { - case FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_RGBA: gltype = GL_RGBA; break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: gltype = GL_RGB; break; } @@ -1632,527 +1445,282 @@ void JNICALL Java_javax_media_j3d_Canvas3D_texturemapping( /* Java 3D always clears the Z-buffer */ glDepthMask(GL_TRUE); - glClear(GL_DEPTH_BUFFER_BIT); - glPopAttrib(); -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_clear( - JNIEnv *env, - jobject obj, - jlong ctxInfo, - jfloat r, - jfloat g, - jfloat b, - jint winWidth, - jint winHeight, - jobject pa2d, - jint imageScaleMode, - jbyteArray pixels_obj) - -{ - jclass pa2d_class; - jfieldID format_field, width_field, height_field; - int format, width, height; - GLubyte * pixels; - JNIEnv table; - GLenum gltype; - float xzoom, yzoom, zoom; - float rasterX, rasterY; - int repeatX, repeatY, i, j; - int row_length, skip_pixels, skip_rows, subwidth, subheight; - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - table = *env; - -#ifdef VERBOSE - fprintf(stderr, "Canvas3D.clear()\n"); -#endif - - if(!pa2d) { - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - else { - /* Do a cool image blit */ - pa2d_class = (jclass) (*(table->GetObjectClass))(env, pa2d); - format_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "storedYdownFormat", "I"); - width_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "width", "I"); - height_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "height", "I"); - - format = (int) (*(table->GetIntField))(env, pa2d, format_field); - width = (int) (*(table->GetIntField))(env, pa2d, width_field); - height = (int) (*(table->GetIntField))(env, pa2d, height_field); - - pixels = (GLubyte *) (*(table->GetPrimitiveArrayCritical))(env, - pixels_obj, NULL); - - /* Temporarily disable fragment and most 3D operations */ - /* XXXX: the GL_TEXTURE_BIT may not be necessary */ - glPushAttrib(GL_ENABLE_BIT|GL_TEXTURE_BIT); - disableAttribFor2D(ctxProperties); - - /* loaded identity modelview and projection matrix */ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - switch (format) { - case FORMAT_BYTE_RGBA: - gltype = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - gltype = GL_RGB; - break; - - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - gltype = GL_ABGR_EXT; - } - break; - - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - gltype = ctxProperties->bgr_ext_enum ; - } - break; - - case FORMAT_BYTE_LA: - gltype = GL_LUMINANCE_ALPHA; - break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; - } - - /* start from upper left corner */ - glRasterPos3f(-1.0, 1.0, 0.0); - - /* setup the pixel zoom */ - xzoom = (float)winWidth/width; - yzoom = (float)winHeight/height; - switch(imageScaleMode){ - case javax_media_j3d_Background_SCALE_NONE: - if(xzoom > 1.0f || yzoom > 1.0f) - { - /* else don't need to clear the background with background color */ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - glPixelZoom(1.0, -1.0); - glDrawPixels(width, height, gltype, GL_UNSIGNED_BYTE, - pixels); - - break; - case javax_media_j3d_Background_SCALE_FIT_MIN: - if(xzoom != yzoom ) { - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - zoom = xzoom < yzoom? xzoom:yzoom; - glPixelZoom(zoom, -zoom); - glDrawPixels(width, height, gltype, GL_UNSIGNED_BYTE, - pixels); + glClear(GL_DEPTH_BUFFER_BIT); + glPopAttrib(); +} - break; - case javax_media_j3d_Background_SCALE_FIT_MAX: - zoom = xzoom > yzoom? xzoom:yzoom; - glPixelZoom(zoom, -zoom); - glDrawPixels(width, height, gltype, GL_UNSIGNED_BYTE, - pixels); +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_clear(JNIEnv *env, + jobject obj, + jlong ctxInfo, + jfloat r, + jfloat g, + jfloat b) +{ + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; + jlong ctx = ctxProperties->context; + - break; - case javax_media_j3d_Background_SCALE_FIT_ALL: - glPixelZoom(xzoom, -yzoom); - glDrawPixels(width, height, gltype, GL_UNSIGNED_BYTE, - pixels); - break; - case javax_media_j3d_Background_SCALE_REPEAT: - glPixelZoom(1.0, -1.0); - /* get those raster positions */ - repeatX = winWidth/width; - if(repeatX * width < winWidth) - repeatX++; - repeatY = winHeight/height; - if(repeatY * height < winHeight) - repeatY++; - for(i = 0; i < repeatX; i++) - for(j = 0; j < repeatY; j++) { - rasterX = -1.0f + (float)width/winWidth * i * 2; - rasterY = 1.0f - (float)height/winHeight * j * 2; - glRasterPos3f(rasterX, rasterY, 0.0); - glDrawPixels(width, height, gltype, GL_UNSIGNED_BYTE, - pixels); - } - break; - - case javax_media_j3d_Background_SCALE_NONE_CENTER: - if(xzoom > 1.0f || yzoom > 1.0f){ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - if(xzoom >= 1.0f){ - rasterX = -(float)width/winWidth; - subwidth = width; - } - else { - rasterX = -1.0; - row_length = width; - glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length); - skip_pixels = (width-winWidth)/2; - glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); - subwidth = winWidth; - } - if(yzoom >= 1.0f){ - rasterY = (float)height/winHeight; - subheight = height; - } - else { - rasterY = 1.0f; - skip_rows = (height-winHeight)/2; - glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); - subheight = winHeight; - } - glRasterPos3f(rasterX, rasterY, 0.0); - glPixelZoom(1.0, -1.0); - glDrawPixels(subwidth, subheight, gltype, GL_UNSIGNED_BYTE, - pixels); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - break; - } +#ifdef VERBOSE + fprintf(stderr, "Canvas3D.clear()\n"); +#endif + + glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); + glClear(GL_COLOR_BUFFER_BIT); - /* Restore attributes */ - glPopAttrib(); - - (*(table->ReleasePrimitiveArrayCritical))(env, pixels_obj, - (jbyte *)pixels, 0); - } /* Java 3D always clears the Z-buffer */ glPushAttrib(GL_DEPTH_BUFFER_BIT); glDepthMask(GL_TRUE); glClear(GL_DEPTH_BUFFER_BIT); glPopAttrib(); + +#if 0 + + /* Java 3D always clears the Z-buffer */ + glPushAttrib(GL_DEPTH_BUFFER_BIT); + glDepthMask(GL_TRUE); + glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + glPopAttrib(); +#endif + + } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_textureclear(JNIEnv *env, +void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(JNIEnv *env, jobject obj, jlong ctxInfo, - jint maxX, - jint maxY, - jfloat r, - jfloat g, - jfloat b, - jint winWidth, - jint winHeight, - jint objectId, - jint imageScaleMode, - jobject pa2d, - jboolean update) + jfloat texMinU, + jfloat texMaxU, + jfloat texMinV, + jfloat texMaxV, + jfloat mapMinX, + jfloat mapMaxX, + jfloat mapMinY, + jfloat mapMaxY) { - jclass pa2d_class; - jfieldID pixels_field, format_field, width_field, height_field; - jbyteArray pixels_obj; - int format, width, height; - GLubyte * pixels; JNIEnv table; - GLenum gltype; - GLfloat texMinU, texMinV, texMaxU, texMaxV, adjustV; - GLfloat mapMinX, mapMinY, mapMaxX, mapMaxY; - GLfloat halfWidth, halfHeight; - float xzoom, yzoom, zoom; - int i, j; GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; - table = *env; - - /* update = 1; */ + table = *env; #ifdef VERBOSE - fprintf(stderr, "Canvas3D.textureclear()\n"); -#endif - if(!pa2d){ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - /* glPushAttrib(GL_DEPTH_BUFFER_BIT); */ - if (pa2d) { - /* Do a cool image blit */ - pa2d_class = (jclass) (*(table->GetObjectClass))(env, pa2d); - - pixels_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "imageYup", "[B"); - format_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "storedYupFormat", "I"); - pixels_obj = (jbyteArray)(*(table->GetObjectField))(env, pa2d, - pixels_field); - - width_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "width", "I"); - height_field = (jfieldID) (*(table->GetFieldID))(env, pa2d_class, - "height", "I"); + fprintf(stderr, "Canvas3D.textureFillBackground()\n"); +#endif + /* Temporarily disable fragment and most 3D operations */ + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_POLYGON_BIT); - format = (int) (*(table->GetIntField))(env, pa2d, format_field); - width = (int) (*(table->GetIntField))(env, pa2d, width_field); - height = (int) (*(table->GetIntField))(env, pa2d, height_field); - pixels = (GLubyte *) (*(table->GetPrimitiveArrayCritical))(env, - pixels_obj, NULL); + disableAttribFor2D(ctxProperties); + glDepthMask(GL_FALSE); + glEnable(GL_TEXTURE_2D); -#ifdef VERBOSE - fprintf(stderr, "width = %d height = %d \n", width, height); -#endif - - /* Temporarily disable fragment and most 3D operations */ - glPushAttrib(GL_ENABLE_BIT|GL_TEXTURE_BIT|GL_POLYGON_BIT); - disableAttribFor2D(ctxProperties); + /* reset the polygon mode */ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - Java_javax_media_j3d_Canvas3D_resetTexCoordGeneration(env, obj, ctxInfo); + /* loaded identity modelview and projection matrix */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); + +#ifdef VERBOSE + printf("(texMinU,texMinV,texMaxU,texMaxV) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + texMinU,texMinV,texMaxU,texMaxV); + printf("(mapMinX,mapMinY,mapMaxX,mapMaxY) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + mapMinX,mapMinY,mapMaxX,mapMaxY); +#endif + + glBegin(GL_QUADS); + glTexCoord2f((float) texMinU, (float) texMinV); + glVertex2f((float) mapMinX, (float) mapMinY); + glTexCoord2f((float) texMaxU, (float) texMinV); + glVertex2f((float) mapMaxX, (float) mapMinY); + glTexCoord2f((float) texMaxU, (float) texMaxV); + glVertex2f((float) mapMaxX, (float) mapMaxY); + glTexCoord2f((float) texMinU, (float) texMaxV); + glVertex2f((float) mapMinX, (float) mapMaxY); + glEnd(); + + /* Restore texture Matrix transform */ + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + /* Restore attributes */ + glPopAttrib(); +} - glEnable(GL_TEXTURE_2D); +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, + jobject obj, + jlong ctxInfo, + jfloat texMinU, + jfloat texMaxU, + jfloat texMinV, + jfloat texMaxV, + jfloat mapMinX, + jfloat mapMaxX, + jfloat mapMinY, + jfloat mapMaxY, + jfloat mapZ, + jfloat alpha) +{ + JNIEnv table; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; + jlong ctx = ctxProperties->context; + + table = *env; + +#ifdef VERBOSE + fprintf(stderr, "Canvas3D.textureFillRaster()\n"); +#endif + /* Temporarily disable fragment and most 3D operations */ + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_POLYGON_BIT | + GL_CURRENT_BIT); + + disableAttribForRaster(ctxProperties); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glColor4f(1.0f, 1.0f, 1.0f, (float) alpha); - /* reset the polygon mode */ - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + /* reset the polygon mode */ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glDepthMask(GL_FALSE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glBindTexture(GL_TEXTURE_2D, objectId); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - /* set up texture parameter */ - if(update){ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } + /* loaded identity modelview and projection matrix */ + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0); + #ifdef VERBOSE - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); -#endif - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - - - - if(update){ - switch (format) { - case FORMAT_BYTE_RGBA: - gltype = GL_RGBA; -#ifdef VERBOSE - fprintf(stderr, "FORMAT_BYTE_RGBA\n"); + printf("(texMinU,texMinV,texMaxU,texMaxV) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + texMinU,texMinV,texMaxU,texMaxV); + printf("(mapMinX,mapMinY,mapMaxX,mapMaxY) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + mapMinX,mapMinY,mapMaxX,mapMaxY); #endif - break; - case FORMAT_BYTE_RGB: - gltype = GL_RGB; -#ifdef VERBOSE - fprintf(stderr, "FORMAT_BYTE_RGB\n"); + + glBegin(GL_QUADS); + + glTexCoord2f((float) texMinU, (float) texMinV); + glVertex3f((float) mapMinX, (float) mapMinY, (float) mapZ); + glTexCoord2f((float) texMaxU, (float) texMinV); + glVertex3f((float) mapMaxX, (float) mapMinY, (float) mapZ); + glTexCoord2f((float) texMaxU, (float) texMaxV); + glVertex3f((float) mapMaxX, (float) mapMaxY, (float) mapZ); + glTexCoord2f((float) texMinU, (float) texMaxV); + glVertex3f((float) mapMinX, (float) mapMaxY, (float) mapZ); + + glEnd(); + + /* Restore matrices */ + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + /* Restore attributes */ + glPopAttrib(); +} + +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_executeRasterDepth(JNIEnv *env, + jobject obj, + jlong ctxInfo, + jfloat posX, + jfloat posY, + jfloat posZ, + jint srcOffsetX, + jint srcOffsetY, + jint rasterWidth, + jint rasterHeight, + jint depthWidth, + jint depthHeight, + jint depthFormat, + jobject depthData) +{ + GLint drawBuf; + void *depthObjPtr; + + JNIEnv table; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; + jlong ctx = ctxProperties->context; + + table = *env; + +#ifdef VERBOSE + fprintf(stderr, "Canvas3D.executeRasterDepth()\n"); #endif - break; - - /* GL_ABGR_EXT */ - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - gltype = GL_ABGR_EXT; - } - break; - - /* GL_BGR_EXT or GL_BGR */ - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - gltype = ctxProperties->bgr_ext_enum; - } - break; - - case FORMAT_BYTE_LA: - gltype = GL_LUMINANCE_ALPHA; - break; - - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; - } - - /* texture map here! */ - glTexImage2D(GL_TEXTURE_2D, 0, gltype, width, - height, 0, gltype, GL_UNSIGNED_BYTE, - pixels); - } - /* loaded identity modelview and projection matrix */ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - glLoadIdentity(); - - xzoom = (float)winWidth/maxX; - yzoom = (float)winHeight/maxY; - switch(imageScaleMode) { - case javax_media_j3d_Background_SCALE_NONE: - if(xzoom > 1.0f || yzoom > 1.0f){ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } - texMinU = 0.0f; - texMinV = 0.0f; - texMaxU = 1.0f; - texMaxV = 1.0f; - halfWidth = (GLfloat)winWidth/2.0f; - halfHeight = (GLfloat)winHeight/2.0f; - mapMinX = (float) ((0 - halfWidth)/halfWidth); - mapMinY = (float) ((0 - halfHeight)/halfHeight); - mapMaxX = (float) ((maxX - halfWidth)/halfWidth); - mapMaxY = (float) ((maxY - halfHeight)/halfHeight); - adjustV = ((float)winHeight - (float)maxY)/halfHeight; - mapMinY += adjustV; - mapMaxY += adjustV; - break; - case javax_media_j3d_Background_SCALE_FIT_MIN: - if(xzoom != yzoom){ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); - } + glRasterPos3f(posX, posY, posZ); - zoom = xzoom < yzoom? xzoom: yzoom; - texMinU = 0.0f; - texMinV = 0.0f; - texMaxU = 1.0f; - texMaxV = 1.0f; - mapMinX = -1.0f; - mapMaxY = 1.0f; - if(xzoom < yzoom){ - mapMaxX = 1.0f; - mapMinY = -1.0f + 2.0f * ( 1.0f - zoom * (float)maxY/(float) winHeight ); - } else { - mapMaxX = -1.0f + zoom * (float)maxX/winWidth * 2; - mapMinY = -1.0f; - } - break; - case javax_media_j3d_Background_SCALE_FIT_MAX: - zoom = xzoom > yzoom? xzoom: yzoom; - /*fprintf(stderr, "zoom: %f, xzoom: %f, yzoom: %f\n", zoom, xzoom, yzoom);*/ - mapMinX = -1.0f; - mapMinY = -1.0f; - mapMaxX = 1.0f; - mapMaxY = 1.0f; - if(xzoom < yzoom) { - texMinU = 0.0f; - texMinV = 0.0f; - texMaxU = (float)winWidth/maxX/zoom; - texMaxV = 1.0f; - } else { - texMinU = 0.0f; - texMinV = 1.0f - (float)winHeight/maxY/zoom; - texMaxU = 1.0f; - texMaxV = 1.0f; + glGetIntegerv(GL_DRAW_BUFFER, &drawBuf); + /* disable draw buffer */ + glDrawBuffer(GL_NONE); + + /* + * raster position is upper left corner, default for Java3D + * ImageComponent currently has the data reverse in Y + */ + glPixelZoom(1.0, -1.0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, depthWidth); + if (srcOffsetX >= 0) { + glPixelStorei(GL_UNPACK_SKIP_PIXELS, srcOffsetX); + if (srcOffsetX + rasterWidth > depthWidth) { + rasterWidth = depthWidth - srcOffsetX; } - break; - case javax_media_j3d_Background_SCALE_FIT_ALL: - texMinU = 0.0f; - texMinV = 0.0f; - texMaxU = 1.0f; - texMaxV = 1.0f; - mapMinX = -1.0f; - mapMinY = -1.0f; - mapMaxX = 1.0f; - mapMaxY = 1.0f; - break; - case javax_media_j3d_Background_SCALE_REPEAT: - /* glScalef(1.0f, -1.0f, 1.0f); */ - i = winWidth/width; - j = winHeight/height; - texMinU = 0.0f; - texMinV = (float)(j + 1) - yzoom; - texMaxU = xzoom; - texMaxV = (float)(j + 1); - mapMinX = -1.0f; - mapMinY = -1.0f; - mapMaxX = 1.0f; - mapMaxY = 1.0f; - break; - case javax_media_j3d_Background_SCALE_NONE_CENTER: - if(xzoom > 1.0f || yzoom > 1.0f){ - glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_COLOR_BUFFER_BIT); + } else { + rasterWidth += srcOffsetX; + if (rasterWidth > depthWidth) { + rasterWidth = depthWidth; } - if(xzoom >= 1.0f){ - texMinU = 0.0f; - texMaxU = 1.0f; - mapMinX = -(float)maxX/winWidth; - mapMaxX = (float)maxX/winWidth; - } else { - texMinU = 0.5f - (float)winWidth/maxX/2; - texMaxU = 0.5f + (float)winWidth/maxX/2; - mapMinX = -1.0f; - mapMaxX = 1.0f; + } + if (srcOffsetY >= 0) { + glPixelStorei(GL_UNPACK_SKIP_ROWS, srcOffsetY); + if (srcOffsetY + rasterHeight > depthHeight) { + rasterHeight = depthHeight - srcOffsetY; } - if(yzoom >= 1.0f) { - texMinV = 0.0f; - texMaxV = 1.0f; - mapMinY = -(float)maxY/winHeight; - mapMaxY = (float)maxY/winHeight; - }else { - texMinV = 0.5f - (float)winHeight/maxY/2; - texMaxV = 0.5f + (float)winHeight/maxY/2; - mapMinY = -1.0f; - mapMaxY = 1.0f; + } else { + rasterHeight += srcOffsetY; + if (rasterHeight > depthHeight) { + rasterHeight = depthHeight; } - break; } -#ifdef VERBOSE - printf("adjustV = %3.2f\n",adjustV); - printf("(texMinU,texMinV,texMaxU,texMaxV) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", - texMinU,texMinV,texMaxU,texMaxV); - printf("(mapMinX,mapMinY,mapMaxX,mapMaxY) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", - mapMinX,mapMinY,mapMaxX,mapMaxY); -#endif + + depthObjPtr = + (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)depthData, NULL); + + if (depthFormat == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { + glDrawPixels(rasterWidth, rasterHeight, GL_DEPTH_COMPONENT, + GL_UNSIGNED_INT, depthObjPtr); + } else { /* javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT */ + + glDrawPixels(rasterWidth, rasterHeight, GL_DEPTH_COMPONENT, + GL_FLOAT, depthObjPtr); + } + (*(table->ReleasePrimitiveArrayCritical))(env, depthData, depthObjPtr, 0); - glBegin(GL_QUADS); -#ifdef VERBOSE - /* glTexCoord2f(0.2, 0.2); glVertex2f(0.0,0.0); */ - /* glTexCoord2f(0.4, 0.2); glVertex2f(0.2,0.0); */ - /* glTexCoord2f(0.4, 0.4); glVertex2f(0.2,0.2); */ - /* glTexCoord2f(0.2, 0.4); glVertex2f(0.0,0.2); */ - glColor3f(1.0, 0.0, 0.0); -#endif - glTexCoord2f(texMinU, texMinV); glVertex2f(mapMinX,mapMinY); - glTexCoord2f(texMaxU, texMinV); glVertex2f(mapMaxX,mapMinY); - glTexCoord2f(texMaxU, texMaxV); glVertex2f(mapMaxX,mapMaxY); - glTexCoord2f(texMinU, texMaxV); glVertex2f(mapMinX,mapMaxY); - glEnd(); - - /* Restore texture Matrix transform */ - glPopMatrix(); + + /* re-enable draw buffer */ + glDrawBuffer(drawBuf); - glMatrixMode(GL_MODELVIEW); - /* Restore attributes */ - glPopAttrib(); - (*(table->ReleasePrimitiveArrayCritical))(env, pixels_obj, - (jbyte *)pixels, 0); - } - - /* Java 3D always clears the Z-buffer */ - glPushAttrib(GL_DEPTH_BUFFER_BIT); - glDepthMask(GL_TRUE); - glClear(GL_DEPTH_BUFFER_BIT); - glPopAttrib(); - + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setRenderMode( +void JNICALL Java_javax_media_j3d_NativePipeline_setRenderMode( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2221,7 +1789,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setRenderMode( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_clearAccum( +void JNICALL Java_javax_media_j3d_NativePipeline_clearAccum( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -2232,7 +1800,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clearAccum( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_accum( +void JNICALL Java_javax_media_j3d_NativePipeline_accum( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2248,7 +1816,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_accum( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_accumReturn( +void JNICALL Java_javax_media_j3d_NativePipeline_accumReturn( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -2259,7 +1827,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_accumReturn( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setDepthBufferWriteEnable( +void JNICALL Java_javax_media_j3d_NativePipeline_setDepthBufferWriteEnable( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2274,23 +1842,24 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setDepthBufferWriteEnable( JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_swapBuffers( +jint JNICALL Java_javax_media_j3d_NativePipeline_swapBuffers( JNIEnv *env, jobject obj, + jobject cv, jlong ctxInfo, jlong display, - jint win) + jlong window) { #if defined(UNIX) - glXSwapBuffers((Display *)display, (Window)win); + glXSwapBuffers((Display *)display, (Window)window); #endif #ifdef WIN32 HDC hdc; - hdc = (HDC) win; + hdc = (HDC) window; SwapBuffers(hdc); #endif @@ -2306,7 +1875,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_swapBuffers( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_syncRender( +void JNICALL Java_javax_media_j3d_NativePipeline_syncRender( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2321,7 +1890,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_syncRender( JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_newDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_newDisplayList( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2336,7 +1905,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_newDisplayList( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_endDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_endDisplayList( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -2346,7 +1915,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_endDisplayList( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_setGlobalAlpha( +void JNICALL Java_javax_media_j3d_NativePipeline_setGlobalAlpha( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2363,23 +1932,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setGlobalAlpha( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_disableGlobalAlpha( - JNIEnv *env, - jobject obj, - jlong ctxInfo) -{ - - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - - /* GL_GLOBAL_ALPHA_SUN */ - if(ctxProperties->global_alpha_sun){ - glDisable(GL_GLOBAL_ALPHA_SUN); - } -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_callDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_callDisplayList( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2402,22 +1955,23 @@ void JNICALL Java_javax_media_j3d_Canvas3D_callDisplayList( return; } - /* resale_normal_ext */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + /* Set normalization if non-uniform scale */ + if (isNonUniformScale) { glEnable(GL_NORMALIZE); } glCallList(id); - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + /* Turn normalization back off */ + if (isNonUniformScale) { glDisable(GL_NORMALIZE); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_freeDisplayList( +void JNICALL Java_javax_media_j3d_NativePipeline_freeDisplayList( JNIEnv *env, - jclass cl, + jobject obj, jlong ctxInfo, jint id) { @@ -2431,9 +1985,9 @@ void JNICALL Java_javax_media_j3d_Canvas3D_freeDisplayList( } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_freeTexture( +void JNICALL Java_javax_media_j3d_NativePipeline_freeTexture( JNIEnv *env, - jclass cl, + jobject obj, jlong ctxInfo, jint id) { @@ -2455,15 +2009,14 @@ void JNICALL Java_javax_media_j3d_Canvas3D_freeTexture( int getTextureColorTableSize( JNIEnv *env, jobject obj, - jlong ctxInfo, - char *extensionStr, - int minorVersion) + GraphicsContextPropertiesInfo *ctxInfo, + char *extensionStr) { - GraphicsContextPropertiesInfo* ctxProperties = (GraphicsContextPropertiesInfo* )ctxInfo; + GraphicsContextPropertiesInfo* ctxProperties = ctxInfo; int size; - - if(minorVersion >= 2 && isExtensionSupported(extensionStr, "GL_ARB_imaging")){ - + + if (isExtensionSupported(extensionStr, "GL_ARB_imaging")) { + #ifdef WIN32 ctxProperties->glColorTable = (MYPFNGLCOLORTABLEPROC)wglGetProcAddress("glColorTable"); ctxProperties->glGetColorTableParameteriv = @@ -2477,6 +2030,7 @@ int getTextureColorTableSize( #endif } else if(isExtensionSupported(extensionStr, "GL_SGI_color_table")) { + #ifdef WIN32 ctxProperties->glColorTable = (MYPFNGLCOLORTABLEPROC)wglGetProcAddress("glColorTableSGI"); ctxProperties->glGetColorTableParameteriv = @@ -2488,16 +2042,16 @@ int getTextureColorTableSize( ctxProperties->glGetColorTableParameteriv = (MYPFNGLGETCOLORTABLEPARAMETERIVPROC)dlsym(RTLD_DEFAULT, "glGetColorTableParameterivSGI"); #endif - + } else { return 0; } if ((ctxProperties->glColorTable == NULL) || - (ctxProperties->glGetColorTableParameteriv == NULL)) { + (ctxProperties->glGetColorTableParameteriv == NULL)) { return 0; } - + ctxProperties->glColorTable(GL_PROXY_TEXTURE_COLOR_TABLE_SGI, GL_RGBA, 256, GL_RGB, GL_INT, NULL); ctxProperties->glGetColorTableParameteriv(GL_PROXY_TEXTURE_COLOR_TABLE_SGI, @@ -2505,62 +2059,13 @@ int getTextureColorTableSize( return size; } -/* For dvr support */ -JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_videoResize( - JNIEnv *env, - jobject obj, - jlong ctxInfo, - jlong display, - jint win, - jfloat dvrFactor) -{ -#if defined(UNIX) - - GraphicsContextPropertiesInfo* ctxProperties = (GraphicsContextPropertiesInfo* )ctxInfo; - - /* Not need to do ext. supported checking. This check is done in java. */ - - /* fprintf(stderr, "Canvas3D.c -- glXVideoResize -- %d %f\n", win, dvrFactor); */ - ctxProperties->glXVideoResizeSUN((Display *)display, (Window)win, (float) dvrFactor); -#endif - -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_videoResizeCompensation( - JNIEnv *env, - jobject obj, - jlong ctxInfo, - jboolean enable) -{ - -#if defined(UNIX) - GraphicsContextPropertiesInfo *ctxProperties = - (GraphicsContextPropertiesInfo *)ctxInfo; - - if (ctxProperties->videoResizeAvailable) { - if(enable == JNI_TRUE) { - /* fprintf(stderr, "videoResizeCompensation - glEnable"); */ - glEnable(GL_VIDEO_RESIZE_COMPENSATION_SUN); - } - else { - /* fprintf(stderr, "videoResizeCompensation - glDisable"); */ - glDisable(GL_VIDEO_RESIZE_COMPENSATION_SUN); - } - } - -#endif - -} - JNIEXPORT -jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( +jlong JNICALL Java_javax_media_j3d_NativePipeline_createOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctxInfo, jlong display, - jint vid, jlong fbConfigListPtr, jint width, jint height) @@ -2586,7 +2091,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( */ - + /* Query DRAWABLE_TYPE. Will use Pbuffer if fbConfig support it, else will try for Pixmap. If neither one exists, flag error message and return None */ @@ -2616,7 +2121,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( fprintf(stderr, "Java 3D ERROR : glXCreateGLXPbuffer() returns None\n"); } - return pbuff; + return (jlong)pbuff; } else if((val & GLX_PIXMAP_BIT) != 0) { Pixmap pixmap; @@ -2666,11 +2171,11 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( } /* fprintf(stderr, "glxpixmap %d\n",(int) glxpixmap); */ - return glxpixmap; + return (jlong)glxpixmap; } else { fprintf(stderr, "Java 3D ERROR : FBConfig doesn't support pbuffer or pixmap returns None\n"); - return None; + return (jlong)None; } @@ -2710,7 +2215,7 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( (int) display, pFormatInfoPtr->offScreenPFormat, width, height); */ - cv_class = (jclass) (*(table->GetObjectClass))(env, obj); + cv_class = (jclass) (*(table->GetObjectClass))(env, cv); offScreenBuffer_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "offScreenBufferInfo", "J"); @@ -2801,9 +2306,9 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( offScreenBufferInfo->isPbuffer = GL_TRUE; offScreenBufferInfo->hpbuf = hpbuf; - (*(table->SetLongField))(env, obj, offScreenBuffer_field, (jlong)offScreenBufferInfo); + (*(table->SetLongField))(env, cv, offScreenBuffer_field, (jlong)offScreenBufferInfo); - return (jint) hpbufdc; + return (jlong) hpbufdc; } /* fprintf(stderr, "***** Use Bitmap for offscreen ******\n"); */ @@ -2856,21 +2361,23 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( offScreenBufferInfo->isPbuffer = GL_FALSE; offScreenBufferInfo->hpbuf = 0; - (*(table->SetLongField))(env, obj, offScreenBuffer_field, (jlong)offScreenBufferInfo); + (*(table->SetLongField))(env, cv, offScreenBuffer_field, (jlong)offScreenBufferInfo); + + return ((jlong)bitmapHdc); - return ((jint)bitmapHdc); - #endif /* WIN32 */ } + JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_destroyOffScreenBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_destroyOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctxInfo, jlong display, jlong fbConfigListPtr, - jint window) + jlong window) { jclass cv_class; jfieldID offScreenBuffer_field; @@ -2900,12 +2407,12 @@ void JNICALL Java_javax_media_j3d_Canvas3D_destroyOffScreenBuffer( OffScreenBufferInfo *offScreenBufferInfo = NULL; HDC hpbufdc = (HDC) window; - cv_class = (jclass) (*(table->GetObjectClass))(env, obj); + cv_class = (jclass) (*(table->GetObjectClass))(env, cv); offScreenBuffer_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, "offScreenBufferInfo", "J"); offScreenBufferInfo = - (OffScreenBufferInfo *) (*(table->GetLongField))(env, obj, offScreenBuffer_field); + (OffScreenBufferInfo *) (*(table->GetLongField))(env, cv, offScreenBuffer_field); /* fprintf(stderr,"Canvas3D_destroyOffScreenBuffer : offScreenBufferInfo 0x%x\n", @@ -2935,81 +2442,131 @@ void JNICALL Java_javax_media_j3d_Canvas3D_destroyOffScreenBuffer( } free(offScreenBufferInfo); - (*(table->SetLongField))(env, obj, offScreenBuffer_field, (jlong)0); + (*(table->SetLongField))(env, cv, offScreenBuffer_field, (jlong)0); #endif /* WIN32 */ } - JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_readOffScreenBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_readOffScreenBuffer( JNIEnv *env, jobject obj, + jobject cv, jlong ctxInfo, jint format, + jint dataType, + jobject data, jint width, jint height) { JNIEnv table = *env; - jclass cv_class; - jfieldID byteData_field; - jbyteArray byteData_array; - jbyte *byteData; int type; - + void *imageObjPtr; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; glPixelStorei(GL_PACK_ROW_LENGTH, width); glPixelStorei(GL_PACK_ALIGNMENT, 1); - cv_class = (jclass) (*(table->GetObjectClass))(env, obj); - byteData_field = (jfieldID) (*(table->GetFieldID))(env, cv_class, - "byteBuffer", "[B"); - byteData_array = (jbyteArray)(*(table->GetObjectField))(env, obj, - byteData_field); - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - byteData_array, NULL); + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + imageObjPtr = (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)data, NULL); + } + else { + imageObjPtr = (void *)(*(table->GetDirectBufferAddress))(env, data); + } - - switch (format) { - case FORMAT_BYTE_RGBA: - type = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - type = GL_RGB; - break; - - /* GL_ABGR_EXT */ - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - type = GL_ABGR_EXT; - } - break; + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_BYTE_BUFFER)) { + switch (format) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + type = GL_BGR; + break; + case IMAGE_FORMAT_BYTE_RGB: + type = GL_RGB; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + type = GL_ABGR_EXT; + } + else { + throwAssert(env, "GL_ABGR_EXT format is unsupported"); + return; + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + type = GL_RGBA; + break; + + /* This method only supports 3 and 4 components formats and BYTE types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "illegal format"); + return; + } + + glReadPixels(0, 0, width, height, type, GL_UNSIGNED_BYTE, imageObjPtr); + + } + else if((dataType == IMAGE_DATA_TYPE_INT_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_BUFFER)) { + GLenum intType = GL_UNSIGNED_INT_8_8_8_8; + GLboolean forceAlphaToOne = GL_FALSE; - /* GL_BGR_EXT */ - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - type = ctxProperties->bgr_ext_enum; + switch (format) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + type = GL_RGBA; + intType = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + type = GL_BGRA; + intType = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "illegal format"); + return; + } + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); } - break; - case FORMAT_BYTE_LA: - type = GL_LUMINANCE_ALPHA; - break; + glReadPixels(0, 0, width, height, type, intType, imageObjPtr); - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); + } + } + else { + throwAssert(env, "illegal image data type"); } - - glReadPixels(0, 0, width, height, type, GL_UNSIGNED_BYTE, byteData); + if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) { + (*(table->ReleasePrimitiveArrayCritical))(env, data, imageObjPtr, 0); + } - (*(table->ReleasePrimitiveArrayCritical))(env, byteData_array, - byteData, 0); } static void @@ -3023,17 +2580,12 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) ctxInfo->rendererStr = NULL; ctxInfo->extensionStr = NULL; ctxInfo->versionNumbers[0] = 1; - ctxInfo->versionNumbers[1] = 1; + ctxInfo->versionNumbers[1] = 1; + ctxInfo->gl13 = JNI_FALSE; + ctxInfo->gl20 = JNI_FALSE; - /* both in 1.2 core part and 1.1 extensions */ - ctxInfo->rescale_normal_ext = JNI_FALSE; - ctxInfo->bgr_ext = JNI_FALSE; - ctxInfo->texture3DAvailable = JNI_FALSE; - ctxInfo->seperate_specular_color = JNI_FALSE; - /* 1.2 and GL_ARB_imaging */ ctxInfo->blend_color_ext = JNI_FALSE; - ctxInfo->color_table_ext = JNI_FALSE; ctxInfo->blendFunctionTable[BLEND_ZERO] = GL_ZERO; ctxInfo->blendFunctionTable[BLEND_ONE] = GL_ONE; ctxInfo->blendFunctionTable[BLEND_SRC_ALPHA] = GL_SRC_ALPHA; @@ -3049,9 +2601,9 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) ctxInfo->multi_draw_arrays_sun = JNI_FALSE; ctxInfo->compiled_vertex_array_ext = JNI_FALSE; - ctxInfo->videoResizeAvailable = JNI_FALSE; + ctxInfo->texture_clamp_to_border_enum = GL_CLAMP; + ctxInfo->global_alpha_sun = JNI_FALSE; - ctxInfo->constant_data_sun = JNI_FALSE; /* EXT extensions */ ctxInfo->abgr_ext = JNI_FALSE; @@ -3063,11 +2615,9 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) /* by MIK OF CLASSX */ ctxInfo->alphaClearValue = (getJavaBoolEnv(env, "transparentOffScreen") ? 0.0f : 1.0f); - /* ARB extensions */ - ctxInfo->arb_transpose_matrix = JNI_FALSE; - ctxInfo->arb_multitexture = JNI_FALSE; + ctxInfo->multisample = JNI_FALSE; - ctxInfo->arb_multisample = JNI_FALSE; + /* Multitexture support */ ctxInfo->maxTexCoordSets = 1; ctxInfo->maxTextureUnits = 1; ctxInfo->maxTextureImageUnits = 0; @@ -3077,7 +2627,6 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) ctxInfo->textureEnvCombineAvailable = JNI_FALSE; ctxInfo->textureCombineDot3Available = JNI_FALSE; ctxInfo->textureCombineSubtractAvailable = JNI_FALSE; - ctxInfo->textureCubeMapAvailable = JNI_FALSE; /* NV extensions */ ctxInfo->textureRegisterCombinersAvailable = JNI_FALSE; @@ -3091,6 +2640,7 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) ctxInfo->textureColorTableSize = 0; ctxInfo->textureLodAvailable = JNI_FALSE; ctxInfo->textureLodBiasAvailable = JNI_FALSE; + ctxInfo->textureNonPowerOfTwoAvailable = JNI_FALSE; /* extension mask */ ctxInfo->extMask = 0; @@ -3105,17 +2655,17 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) ctxInfo->glGetColorTableParameteriv = NULL; ctxInfo->glTexImage3DEXT = NULL; ctxInfo->glTexSubImage3DEXT = NULL; - ctxInfo->glClientActiveTextureARB = NULL; + ctxInfo->glClientActiveTexture = NULL; ctxInfo->glMultiDrawArraysEXT = NULL; ctxInfo->glMultiDrawElementsEXT = NULL; ctxInfo->glLockArraysEXT = NULL; ctxInfo->glUnlockArraysEXT = NULL; - ctxInfo->glMultiTexCoord2fvARB = NULL; - ctxInfo->glMultiTexCoord3fvARB = NULL; - ctxInfo->glMultiTexCoord4fvARB = NULL; - ctxInfo->glLoadTransposeMatrixdARB = NULL; - ctxInfo->glMultTransposeMatrixdARB = NULL; - ctxInfo->glActiveTextureARB = NULL; + ctxInfo->glMultiTexCoord2fv = NULL; + ctxInfo->glMultiTexCoord3fv = NULL; + ctxInfo->glMultiTexCoord4fv = NULL; + ctxInfo->glLoadTransposeMatrixd = NULL; + ctxInfo->glMultTransposeMatrixd = NULL; + ctxInfo->glActiveTexture = NULL; ctxInfo->glGlobalAlphaFactorfSUN = NULL; ctxInfo->glCombinerInputNV = NULL; @@ -3148,10 +2698,6 @@ initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo) /* Initialize shader info pointers */ ctxInfo->glslCtxInfo = NULL; ctxInfo->cgCtxInfo = NULL; - -#if defined(UNIX) - ctxInfo->glXVideoResizeSUN = NULL; -#endif /* UNIX */ } static void @@ -3231,12 +2777,12 @@ HWND createDummyWindow(const char* szAppName) { #endif JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( +void JNICALL Java_javax_media_j3d_NativePipeline_createQueryContext( JNIEnv *env, jobject obj, + jobject cv, jlong display, - jint window, - jint vid, + jlong window, jlong fbConfigListPtr, jboolean offScreen, jint width, @@ -3247,7 +2793,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( JNIEnv table = *env; jlong gctx; int stencilSize=0; - jint newWin; + jlong newWin; int PixelFormatID=0; GraphicsContextPropertiesInfo* ctxInfo = (GraphicsContextPropertiesInfo *)malloc(sizeof(GraphicsContextPropertiesInfo)); @@ -3309,14 +2855,14 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( glWin = XCreateWindow((Display *)display, root, 0, 0, width, height, 0, vinfo->depth, InputOutput, vinfo->visual, win_mask, &win_attrs); - newWin = (jint)glWin; + newWin = (jlong)glWin; } } else if(window == 0 && offScreen){ - newWin = Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( env, obj, 0, - display, window, - fbConfigListPtr, - width, height); + newWin = Java_javax_media_j3d_NativePipeline_createOffScreenBuffer(env, + obj, cv, 0, display, + fbConfigListPtr, + width, height); } else if(window != 0) { newWin = window; @@ -3350,11 +2896,6 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( fprintf(stderr, "Canvas3D_createQueryContext:\n"); fprintf(stderr, "window is 0x%x, offScreen %d\n", window, offScreen); */ - - /* - * vid must be valid PixelFormat returned - * by wglChoosePixelFormat() or wglChoosePixelFormatARB. - */ /* Fix to issue 104 */ if(!offScreen) { @@ -3387,16 +2928,17 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( } else if(window == 0 && offScreen){ /* fprintf(stderr, "CreateQueryContext : window == 0 && offScreen\n"); */ - hdc = (HDC)Java_javax_media_j3d_Canvas3D_createOffScreenBuffer( env, obj, 0, display, - vid, fbConfigListPtr, - width, height); + hdc = (HDC)Java_javax_media_j3d_NativePipeline_createOffScreenBuffer(env, + obj, cv, 0, display, + fbConfigListPtr, + width, height); } else if(window != 0){ /* fprintf(stderr, "CreateQueryContext : window != 0 0x%x\n", window); */ hdc = (HDC) window; } - newWin = (jint)hdc; + newWin = (jlong)hdc; SetPixelFormat(hdc, PixelFormatID, NULL); @@ -3430,18 +2972,18 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( ctxInfo->context = gctx; /* get current context properties */ - if (getPropertiesFromCurrentContext(env, obj, ctxInfo, (jlong) hdc, PixelFormatID, + if (getPropertiesFromCurrentContext(env, cv, ctxInfo, (jlong) hdc, PixelFormatID, fbConfigListPtr, offScreen, glslLibraryAvailable, cgLibraryAvailable)) { /* put the properties to the Java side */ - setupCanvasProperties(env, obj, ctxInfo); + setupCanvasProperties(env, cv, ctxInfo); } /* clear up the context , colormap and window if appropriate */ if(window == 0 && !offScreen){ #if defined(UNIX) - Java_javax_media_j3d_Canvas3D_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); + Java_javax_media_j3d_NativePipeline_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); XDestroyWindow((Display *)display, glWin); XFreeColormap((Display *)display, cmap); #endif /* UNIX */ @@ -3450,33 +2992,33 @@ void JNICALL Java_javax_media_j3d_Canvas3D_createQueryContext( ReleaseDC(hDummyWnd, hdc); /* Destroy context */ /* This will free ctxInfo also */ - Java_javax_media_j3d_Canvas3D_destroyContext(env, obj, display,newWin, (jlong)ctxInfo); + Java_javax_media_j3d_NativePipeline_destroyContext(env, obj, display,newWin, (jlong)ctxInfo); DestroyWindow(hDummyWnd); UnregisterClass(szAppName, (HINSTANCE)NULL); #endif /* WIN32 */ } else if(window == 0 && offScreen) { - Java_javax_media_j3d_Canvas3D_destroyOffScreenBuffer(env, obj, gctx, display, fbConfigListPtr, newWin); - Java_javax_media_j3d_Canvas3D_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); + Java_javax_media_j3d_NativePipeline_destroyOffScreenBuffer(env, obj, cv, gctx, display, fbConfigListPtr, newWin); + Java_javax_media_j3d_NativePipeline_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); } else if(window != 0){ - Java_javax_media_j3d_Canvas3D_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); + Java_javax_media_j3d_NativePipeline_destroyContext(env, obj, display, newWin, (jlong)ctxInfo); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_beginScene( +void JNICALL Java_javax_media_j3d_NativePipeline_beginScene( JNIEnv *env, jobject obj, jlong ctxInfo) { - /* Not used by OGL version */ + /* Not used by OGL renderer */ } JNIEXPORT -void JNICALL Java_javax_media_j3d_Canvas3D_endScene( +void JNICALL Java_javax_media_j3d_NativePipeline_endScene( JNIEnv *env, jobject obj, jlong ctxInfo) @@ -3488,18 +3030,18 @@ void JNICALL Java_javax_media_j3d_Canvas3D_endScene( } /* Setup the multisampling for full scene antialiasing */ -JNIEXPORT void JNICALL Java_javax_media_j3d_Canvas3D_setFullSceneAntialiasing +JNIEXPORT void JNICALL Java_javax_media_j3d_NativePipeline_setFullSceneAntialiasing (JNIEnv *env, jobject obj, jlong ctxInfo, jboolean enable) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; - if (ctxProperties->arb_multisample && !ctxProperties->implicit_multisample) { + if (ctxProperties->multisample && !ctxProperties->implicit_multisample) { if(enable == JNI_TRUE) { - glEnable(GL_MULTISAMPLE_ARB); + glEnable(GL_MULTISAMPLE); } else { - glDisable(GL_MULTISAMPLE_ARB); + glDisable(GL_MULTISAMPLE); } } @@ -3511,7 +3053,7 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_Canvas3D_setFullSceneAntialiasing * Return false if <= 8 bit color under windows */ JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode( +jboolean JNICALL Java_javax_media_j3d_NativePipeline_validGraphicsMode( JNIEnv *env, jobject obj) { @@ -3528,9 +3070,18 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode( } +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_cleanupRenderer( + JNIEnv *env, + jobject obj) +{ + /* No-op for OGL pipeline */ +} + + /* * Function to disable most rendering attributes when doing a 2D - * clear, image copy, or image composite operation. Note that the + * clear, or image copy operation. Note that the * caller must save/restore the attributes with * pushAttrib(GL_ENABLE_BIT|...) and popAttrib() */ @@ -3560,13 +3111,8 @@ disableAttribFor2D(GraphicsContextPropertiesInfo *ctxProperties) glDisable(GL_CLIP_PLANE0 + i); } - if (ctxProperties->texture3DAvailable) { - glDisable(ctxProperties->texture_3D_ext_enum); - } - - if (ctxProperties->textureCubeMapAvailable) { - glDisable(ctxProperties->texture_cube_map_ext_enum); - } + glDisable(GL_TEXTURE_3D); + glDisable(GL_TEXTURE_CUBE_MAP); if (ctxProperties->textureRegisterCombinersAvailable) { glDisable(GL_REGISTER_COMBINERS_NV); @@ -3580,3 +3126,28 @@ disableAttribFor2D(GraphicsContextPropertiesInfo *ctxProperties) glDisable(GL_GLOBAL_ALPHA_SUN); } } + +/* + * Function to disable most rendering attributes when doing a Raster + * clear, or image copy operation. Note that the + * caller must save/restore the attributes with + * pushAttrib(GL_ENABLE_BIT|...) and popAttrib() + */ +static void +disableAttribForRaster(GraphicsContextPropertiesInfo *ctxProperties) +{ + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_POLYGON_STIPPLE); + + // TODO: Disable if Raster.CLIP_POSITION is true +// for (int i = 0; i < 6; i++) { +// glDisable(GL_CLIP_PLANE0 + i); +// } + + if (ctxProperties->global_alpha_sun) { + glDisable(GL_GLOBAL_ALPHA_SUN); + } +} diff --git a/src/native/ogl/CgShaderProgram.c b/src/native/ogl/CgShaderProgram.c index 04286e2..a4bfce0 100644 --- a/src/native/ogl/CgShaderProgram.c +++ b/src/native/ogl/CgShaderProgram.c @@ -56,14 +56,14 @@ static CgWrapperInfo *globalCgWrapperInfo = NULL; /* - * Class: javax_media_j3d_MasterControl + * Class: javax_media_j3d_NativePipeline * Method: loadNativeCgLibrary - * Signature: ()Z + * Signature: ([Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL -Java_javax_media_j3d_MasterControl_loadNativeCgLibrary( +Java_javax_media_j3d_NativePipeline_loadNativeCgLibrary( JNIEnv *env, - jclass clazz, + jobject thiz, jobjectArray libpath) { CgWrapperInfo *cgWrapperInfo; @@ -83,7 +83,7 @@ Java_javax_media_j3d_MasterControl_loadNativeCgLibrary( /* Assertion check that we don't get called more than once */ if (globalCgWrapperInfo != NULL) { - throwAssert(env, "MasterControl.loadNativeCgLibrary called more than once"); + throwAssert(env, "NativePipeline.loadNativeCgLibrary called more than once"); return JNI_FALSE; } @@ -403,12 +403,12 @@ checkCgShaderExtensions( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: createNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: createCgShader * Signature: (JI[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_createNativeShader( +Java_javax_media_j3d_NativePipeline_createCgShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -427,7 +427,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_createNativeShader( CgShaderInfo *cgShaderInfo; #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.createNativeShader\n"); + fprintf(stderr, "CgShaderProgramRetained.createCgShader\n"); #endif /* VERBOSE */ cgShaderInfo = (CgShaderInfo*)malloc(sizeof(CgShaderInfo)); @@ -470,12 +470,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_createNativeShader( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: destroyNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: destroyCgShader * Signature: (JJ)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShader( +Java_javax_media_j3d_NativePipeline_destroyCgShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -492,7 +492,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShader( CgShaderInfo *cgShaderInfo = (CgShaderInfo *)shaderId; #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.destroyNativeShader\n"); + fprintf(stderr, "CgShaderProgramRetained.destroyCgShader\n"); #endif /* VERBOSE */ if (cgShaderInfo != NULL) { @@ -517,12 +517,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShader( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: compileNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: compileCgShader * Signature: (JJLjava/lang/String;)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_compileNativeShader( +Java_javax_media_j3d_NativePipeline_compileCgShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -542,7 +542,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_compileNativeShader( GLcharARB *shaderString = NULL; #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.compileNativeShader\n"); + fprintf(stderr, "CgShaderProgramRetained.compileCgShader\n"); #endif /* VERBOSE */ /* Assertion check the cgShaderInfo pointer */ @@ -610,12 +610,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_compileNativeShader( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: createNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: createCgShaderProgram * Signature: (J[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_createNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_createCgShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -631,7 +631,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_createNativeShaderProgram( (CgShaderProgramInfo*)malloc(sizeof(CgShaderProgramInfo)); #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.createNativeShaderProgram\n"); + fprintf(stderr, "CgShaderProgramRetained.createCgShaderProgram\n"); #endif /* VERBOSE */ shaderProgramInfo->vShader = NULL; @@ -657,12 +657,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_createNativeShaderProgram( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: destroyNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: destroyCgShaderProgram * Signature: (JJ)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_destroyCgShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -675,7 +675,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShaderProgram( CgShaderProgramInfo *shaderProgramInfo = (CgShaderProgramInfo*)shaderProgramId; #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.destroyNativeShaderProgram\n"); + fprintf(stderr, "CgShaderProgramRetained.destroyCgShaderProgram\n"); #endif /* VERBOSE */ if (shaderProgramInfo != NULL) { @@ -700,12 +700,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_destroyNativeShaderProgram( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: linkNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: linkCgShaderProgram * Signature: (JJ[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_linkNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_linkCgShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -729,7 +729,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_linkNativeShaderProgram( CgShaderProgramInfo *shaderProgramInfo = (CgShaderProgramInfo*)shaderProgramId; #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.linkNativeShaderProgram\n"); + fprintf(stderr, "CgShaderProgramRetained.linkCgShaderProgram\n"); #endif /* VERBOSE */ /* @@ -789,12 +789,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_linkNativeShaderProgram( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: lookupNativeVertexAttrNames + * Class: javax_media_j3d_NativePipeline + * Method: lookupCgVertexAttrNames * Signature: (JJI[Ljava/lang/String;[Z)V */ JNIEXPORT void JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_lookupNativeVertexAttrNames( +Java_javax_media_j3d_NativePipeline_lookupCgVertexAttrNames( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -831,7 +831,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_lookupNativeVertexAttrNames( shaderProgramInfo->vtxAttrs = (CGparameter *)malloc(numAttrNames * sizeof(CGparameter)); #ifdef VERBOSE - fprintf(stderr, "CgShaderProgramRetained.lookupNativeVertexAttrNames()\n"); + fprintf(stderr, "CgShaderProgramRetained.lookupCgVertexAttrNames()\n"); #endif /* VERBOSE */ for (i = 0; i < numAttrNames; i++) { @@ -974,12 +974,12 @@ lookupParams( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: lookupNativeShaderAttrNames + * Class: javax_media_j3d_NativePipeline + * Method: lookupCgShaderAttrNames * Signature: (JJI[Ljava/lang/String;[J[I[I[Z)V */ JNIEXPORT void JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_lookupNativeShaderAttrNames( +Java_javax_media_j3d_NativePipeline_lookupCgShaderAttrNames( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1050,7 +1050,7 @@ Java_javax_media_j3d_CgShaderProgramRetained_lookupNativeShaderAttrNames( * same type and dimensionality, then a struct is allocated * containing the list of parameters. * - * When any of the setUniform methods are called, the attribute + * When any of the setCgUniform methods are called, the attribute * will be set for each parameter in the list. */ cgParamInfo = (CgParameterInfo *)malloc(sizeof(CgParameterInfo)); @@ -1150,12 +1150,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_lookupNativeShaderAttrNames( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: useShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: useCgShaderProgram * Signature: (JJ)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_useShaderProgram( +Java_javax_media_j3d_NativePipeline_useCgShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1201,12 +1201,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_useShaderProgram( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform1i + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform1i * Signature: (JJJI)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform1i( +Java_javax_media_j3d_NativePipeline_setCgUniform1i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1245,12 +1245,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform1i( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform1f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform1f * Signature: (JJJF)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform1f( +Java_javax_media_j3d_NativePipeline_setCgUniform1f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1289,12 +1289,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform1f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform2i + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform2i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform2i( +Java_javax_media_j3d_NativePipeline_setCgUniform2i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1345,12 +1345,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform2i( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform2f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform2f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform2f( +Java_javax_media_j3d_NativePipeline_setCgUniform2f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1401,12 +1401,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform2f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform3i + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform3i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform3i( +Java_javax_media_j3d_NativePipeline_setCgUniform3i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1459,12 +1459,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform3i( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform3f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform3f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform3f( +Java_javax_media_j3d_NativePipeline_setCgUniform3f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1517,12 +1517,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform3f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform4i + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform4i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform4i( +Java_javax_media_j3d_NativePipeline_setCgUniform4i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1577,12 +1577,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform4i( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform4f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform4f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform4f( +Java_javax_media_j3d_NativePipeline_setCgUniform4f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1637,12 +1637,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform4f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniformMatrix3f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniformMatrix3f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix3f( +Java_javax_media_j3d_NativePipeline_setCgUniformMatrix3f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1689,12 +1689,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix3f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniformMatrix4f + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniformMatrix4f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix4f( +Java_javax_media_j3d_NativePipeline_setCgUniformMatrix4f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1741,12 +1741,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix4f( /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform1iArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform1iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform1iArray( +Java_javax_media_j3d_NativePipeline_setCgUniform1iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1802,12 +1802,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform1iArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform1fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform1fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform1fArray( +Java_javax_media_j3d_NativePipeline_setCgUniform1fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1856,12 +1856,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform1fArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform2iArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform2iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform2iArray( +Java_javax_media_j3d_NativePipeline_setCgUniform2iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1917,12 +1917,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform2iArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform2fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform2fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform2fArray( +Java_javax_media_j3d_NativePipeline_setCgUniform2fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1971,12 +1971,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform2fArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform3iArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform3iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform3iArray( +Java_javax_media_j3d_NativePipeline_setCgUniform3iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2032,12 +2032,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform3iArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform3fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform3fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform3fArray( +Java_javax_media_j3d_NativePipeline_setCgUniform3fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2086,12 +2086,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform3fArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform4iArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform4iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform4iArray( +Java_javax_media_j3d_NativePipeline_setCgUniform4iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2147,12 +2147,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform4iArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniform4fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniform4fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniform4fArray( +Java_javax_media_j3d_NativePipeline_setCgUniform4fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2201,12 +2201,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniform4fArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniformMatrix3fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniformMatrix3fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix3fArray( +Java_javax_media_j3d_NativePipeline_setCgUniformMatrix3fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -2255,12 +2255,12 @@ Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix3fArray( } /* - * Class: javax_media_j3d_CgShaderProgramRetained - * Method: setUniformMatrix4fArray + * Class: javax_media_j3d_NativePipeline + * Method: setCgUniformMatrix4fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_CgShaderProgramRetained_setUniformMatrix4fArray( +Java_javax_media_j3d_NativePipeline_setCgUniformMatrix4fArray( JNIEnv *env, jobject obj, jlong ctxInfo, diff --git a/src/native/ogl/DrawingSurfaceObjectAWT.c b/src/native/ogl/DrawingSurfaceObjectAWT.c index 25f8bd1..867a78d 100644 --- a/src/native/ogl/DrawingSurfaceObjectAWT.c +++ b/src/native/ogl/DrawingSurfaceObjectAWT.c @@ -23,7 +23,7 @@ #include #include -#include "javax_media_j3d_MasterControl.h" +#include "javax_media_j3d_NativePipeline.h" #include "javax_media_j3d_DrawingSurfaceObjectAWT.h" #ifdef DEBUG @@ -47,7 +47,7 @@ JNIEXPORT jlong JNICALL -Java_javax_media_j3d_MasterControl_getAWT( +Java_javax_media_j3d_NativePipeline_getAWT( JNIEnv *env, jobject obj) { JAWT *awt; diff --git a/src/native/ogl/GLSLInfo.h b/src/native/ogl/GLSLInfo.h index 00b3368..e9accfa 100644 --- a/src/native/ogl/GLSLInfo.h +++ b/src/native/ogl/GLSLInfo.h @@ -17,6 +17,8 @@ /* Structure used to hold GLSL context information; stored in ctxInfo */ struct GLSLCtxInfoRec { + int vertexAttrOffset; + PFNGLATTACHOBJECTARBPROC pfnglAttachObjectARB; PFNGLCOMPILESHADERARBPROC pfnglCompileShaderARB; PFNGLCREATEPROGRAMOBJECTARBPROC pfnglCreateProgramObjectARB; diff --git a/src/native/ogl/GLSLShaderProgram.c b/src/native/ogl/GLSLShaderProgram.c index bbc29da..26c19f6 100644 --- a/src/native/ogl/GLSLShaderProgram.c +++ b/src/native/ogl/GLSLShaderProgram.c @@ -33,6 +33,7 @@ #endif /* DEBUG */ +extern jint getJavaIntEnv(JNIEnv *env, char* envStr); extern char *strJavaToC(JNIEnv *env, jstring str); extern void throwAssert(JNIEnv *env, char *str); extern jobject createShaderError(JNIEnv *env, @@ -265,10 +266,14 @@ checkGLSLShaderExtensions( glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &ctxInfo->maxTextureImageUnits); glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &ctxInfo->maxVertexTextureImageUnits); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &ctxInfo->maxCombinedTextureImageUnits); + + /* Initialize GLSL VertexAttr info */ + glslCtxInfo->vertexAttrOffset = getJavaIntEnv(env, "glslVertexAttrOffset"); glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &ctxInfo->maxVertexAttrs); - if (ctxInfo->maxVertexAttrs > 0) { - /* decr count, since vertexAttr[0] is reserved for position */ - ctxInfo->maxVertexAttrs -= 1; + /* decr count to allow for reserved vertex attrs */ + ctxInfo->maxVertexAttrs -= glslCtxInfo->vertexAttrOffset; + if (ctxInfo->maxVertexAttrs < 0) { + ctxInfo->maxVertexAttrs = 0; } if (glslCtxInfo->pfnglCreateShaderObjectARB != NULL) { @@ -319,12 +324,12 @@ getInfoLog( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: createNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: createGLSLShader * Signature: (JI[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_createNativeShader( +Java_javax_media_j3d_NativePipeline_createGLSLShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -369,12 +374,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_createNativeShader( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: destroyNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: destroyGLSLShader * Signature: (JJ)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_destroyNativeShader( +Java_javax_media_j3d_NativePipeline_destroyGLSLShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -389,12 +394,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_destroyNativeShader( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: compileNativeShader + * Class: javax_media_j3d_NativePipeline + * Method: compileGLSLShader * Signature: (JJLjava/lang/String;)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_compileNativeShader( +Java_javax_media_j3d_NativePipeline_compileGLSLShader( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -451,12 +456,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_compileNativeShader( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: createNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: createGLSLShaderProgram * Signature: (J[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_createNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_createGLSLShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -487,12 +492,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_createNativeShaderProgram( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: destroyNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: destroyGLSLShaderProgram * Signature: (JJ)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_destroyNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_destroyGLSLShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -507,12 +512,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_destroyNativeShaderProgram( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: linkNativeShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: linkGLSLShaderProgram * Signature: (JJ[J)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_linkNativeShaderProgram( +Java_javax_media_j3d_NativePipeline_linkGLSLShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -558,12 +563,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_linkNativeShaderProgram( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: bindNativeVertexAttrName + * Class: javax_media_j3d_NativePipeline + * Method: bindGLSLVertexAttrName * Signature: (JJLjava/lang/String;I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_bindNativeVertexAttrName( +Java_javax_media_j3d_NativePipeline_bindGLSLVertexAttrName( JNIEnv * env, jobject obj, jlong ctxInfo, @@ -578,12 +583,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_bindNativeVertexAttrName( /* fprintf(stderr, - "GLSLShaderProgramRetained.bindNativeVertexAttrName: %s\n", + "GLSLShaderProgramRetained.bindGLSLVertexAttrName: %s\n", attrNameString); */ glslCtxInfo->pfnglBindAttribLocationARB((GLhandleARB)shaderProgramId, - attrIndex + 1, + attrIndex + glslCtxInfo->vertexAttrOffset, attrNameString); /* No error checking needed, so just return */ @@ -651,12 +656,12 @@ glslToJ3dType(GLint type) /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: lookupNativeShaderAttrNames + * Class: javax_media_j3d_NativePipeline + * Method: lookupGLSLShaderAttrNames * Signature: (JJI[Ljava/lang/String;[J[I[I[Z)V */ JNIEXPORT void JNICALL -Java_javax_media_j3d_GLSLShaderProgramRetained_lookupNativeShaderAttrNames( +Java_javax_media_j3d_NativePipeline_lookupGLSLShaderAttrNames( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -686,7 +691,7 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_lookupNativeShaderAttrNames( JNIEnv table = *env; #ifdef VERBOSE - fprintf(stderr, "GLSLShaderProgramRetained.lookupNativeShaderAttrNames\n"); + fprintf(stderr, "GLSLShaderProgramRetained.lookupGLSLShaderAttrNames\n"); #endif locPtr = (*env)->GetLongArrayElements(env, locArr, NULL); @@ -736,6 +741,8 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_lookupNativeShaderAttrNames( #endif for (i = 0; i < numActiveUniforms; i++) { + int len; + glslCtxInfo->pfnglGetActiveUniformARB((GLhandleARB) shaderProgramId, i, maxStrLen, @@ -743,9 +750,27 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_lookupNativeShaderAttrNames( &size, &type, name); + + /* + * Issue 247 - we need to workaround an ATI bug where they erroneously + * report individual elements of arrays rather than the array itself + */ + len = strlen(name); + if (len >= 3 && name[len-1] == ']') { + if (strcmp(&name[len-3], "[0]") == 0) { + /* fprintf(stderr, "**** changing \"%s\" ", name); */ + name[len-3] = '\0'; + /* fprintf(stderr, "to \"%s\"\n", name); */ + } else { + /* Ignore this name */ + /* fprintf(stderr, "Uniform[%d] : %s ignored\n", i, name); */ + continue; + } + } + #ifdef VERBOSE fprintf(stderr, - "Uniform[%d] : name = %s, type = %d, size = %d\n", + "Uniform[%d] : name = %s ; type = %d ; size = %d\n", i, name, type, size); #endif @@ -794,12 +819,12 @@ Java_javax_media_j3d_GLSLShaderProgramRetained_lookupNativeShaderAttrNames( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: useShaderProgram + * Class: javax_media_j3d_NativePipeline + * Method: useGLSLShaderProgram * Signature: (JI)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_useShaderProgram( +JNICALL Java_javax_media_j3d_NativePipeline_useGLSLShaderProgram( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -816,12 +841,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_useShaderProgram( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform1i + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform1i * Signature: (JJJI)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1i( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform1i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -842,12 +867,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1i( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform1f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform1f * Signature: (JJJF)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1f( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform1f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -868,12 +893,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1f( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform2i + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform2i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2i( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform2i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -904,12 +929,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2i( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform2f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform2f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2f( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform2f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -942,12 +967,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2f( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform3i + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform3i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3i( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform3i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -978,12 +1003,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3i( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform3f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform3f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3f( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform3f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1014,12 +1039,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3f( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform4i + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform4i * Signature: (JJJ[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4i( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform4i( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1048,12 +1073,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4i( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform4f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform4f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4f( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform4f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1083,11 +1108,11 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4f( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniformMatrix3f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniformMatrix3f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ -JNIEXPORT jobject JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniformMatrix3f( +JNIEXPORT jobject JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniformMatrix3f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1117,11 +1142,11 @@ JNIEXPORT jobject JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUnif } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniformMatrix4f + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniformMatrix4f * Signature: (JJJ[F)Ljavax/media/j3d/ShaderError; */ -JNIEXPORT jobject JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniformMatrix4f( +JNIEXPORT jobject JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniformMatrix4f( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1151,12 +1176,12 @@ JNIEXPORT jobject JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUnif } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform1iArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform1iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1iArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform1iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1190,12 +1215,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1iArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform1fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform1fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1fArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform1fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1228,12 +1253,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform1fArray( } /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform2iArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform2iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2iArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform2iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1268,12 +1293,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2iArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform2fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform2fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2fArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform2fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1307,12 +1332,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform2fArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform3iArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform3iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3iArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform3iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1346,12 +1371,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3iArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform3fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform3fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3fArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform3fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1385,12 +1410,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform3fArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform4iArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform4iArray * Signature: (JJJI[I)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4iArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform4iArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1424,12 +1449,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4iArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniform4fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniform4fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4fArray( +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniform4fArray( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1463,12 +1488,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniform4fArray( /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniformMatrix3fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniformMatrix3fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniformMatrix3fArray +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniformMatrix3fArray ( JNIEnv *env, jobject obj, @@ -1504,12 +1529,12 @@ JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniformMatrix3fArray /* - * Class: javax_media_j3d_GLSLShaderProgramRetained - * Method: setUniformMatrix4fArray + * Class: javax_media_j3d_NativePipeline + * Method: setGLSLUniformMatrix4fArray * Signature: (JJJI[F)Ljavax/media/j3d/ShaderError; */ JNIEXPORT jobject -JNICALL Java_javax_media_j3d_GLSLShaderProgramRetained_setUniformMatrix4fArray +JNICALL Java_javax_media_j3d_NativePipeline_setGLSLUniformMatrix4fArray ( JNIEnv *env, jobject obj, @@ -1556,8 +1581,8 @@ glslVertexAttrPointer( { GLSLCtxInfo *glslCtxInfo = ctxProperties->glslCtxInfo; - glslCtxInfo->pfnglVertexAttribPointerARB(index+1, size, type, - GL_FALSE, stride, pointer); + glslCtxInfo->pfnglVertexAttribPointerARB(index+glslCtxInfo->vertexAttrOffset, + size, type, GL_FALSE, stride, pointer); } static void @@ -1567,7 +1592,7 @@ glslEnableVertexAttrArray( { GLSLCtxInfo *glslCtxInfo = ctxProperties->glslCtxInfo; - glslCtxInfo->pfnglEnableVertexAttribArrayARB(index+1); + glslCtxInfo->pfnglEnableVertexAttribArrayARB(index+glslCtxInfo->vertexAttrOffset); } static void @@ -1577,7 +1602,7 @@ glslDisableVertexAttrArray( { GLSLCtxInfo *glslCtxInfo = ctxProperties->glslCtxInfo; - glslCtxInfo->pfnglDisableVertexAttribArrayARB(index+1); + glslCtxInfo->pfnglDisableVertexAttribArrayARB(index+glslCtxInfo->vertexAttrOffset); } static void @@ -1590,7 +1615,7 @@ glslVertexAttr1fv( #ifdef VERBOSE fprintf(stderr, "glslVertexAttr1fv()\n"); #endif - glslCtxInfo->pfnglVertexAttrib1fvARB(index+1, v); + glslCtxInfo->pfnglVertexAttrib1fvARB(index+glslCtxInfo->vertexAttrOffset, v); } static void @@ -1603,7 +1628,7 @@ glslVertexAttr2fv( #ifdef VERBOSE fprintf(stderr, "glslVertexAttr2fv()\n"); #endif - glslCtxInfo->pfnglVertexAttrib2fvARB(index+1, v); + glslCtxInfo->pfnglVertexAttrib2fvARB(index+glslCtxInfo->vertexAttrOffset, v); } static void @@ -1616,7 +1641,7 @@ glslVertexAttr3fv( #ifdef VERBOSE fprintf(stderr, "glslVertexAttr3fv()\n"); #endif - glslCtxInfo->pfnglVertexAttrib3fvARB(index+1, v); + glslCtxInfo->pfnglVertexAttrib3fvARB(index+glslCtxInfo->vertexAttrOffset, v); } static void @@ -1629,6 +1654,6 @@ glslVertexAttr4fv( #ifdef VERBOSE fprintf(stderr, "glslVertexAttr4fv()\n"); #endif - glslCtxInfo->pfnglVertexAttrib4fvARB(index+1, v); + glslCtxInfo->pfnglVertexAttrib4fvARB(index+glslCtxInfo->vertexAttrOffset, v); } diff --git a/src/native/ogl/GeometryArrayRetained.c b/src/native/ogl/GeometryArrayRetained.c index fd638b7..c75ba72 100644 --- a/src/native/ogl/GeometryArrayRetained.c +++ b/src/native/ogl/GeometryArrayRetained.c @@ -55,16 +55,12 @@ static void enableTexCoordPointer(GraphicsContextPropertiesInfo *, int, int, static void disableTexCoordPointer(GraphicsContextPropertiesInfo *, int); static void clientActiveTextureUnit(GraphicsContextPropertiesInfo *, int); -/* - * texUnitIndex < 0 implies send all texture unit state info in one pass - * texUnitIndex >= 0 implies one texture unit state info in one pass using - * the underlying texture unit 0 - */ + static void -executeTexture(int texUnitIndex, int texCoordSetMapLen, +executeTexture(int texCoordSetMapLen, int texSize, int bstride, int texCoordoff, jint texCoordSetMapOffset[], - jint numActiveTexUnit, jint texUnitStateMap[], + jint numActiveTexUnit, float verts[], jlong ctxInfo) { int i; @@ -72,69 +68,24 @@ executeTexture(int texUnitIndex, int texCoordSetMapLen, GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; int tus; /* texture unit state index */ - - if (texUnitIndex < 0) { - if(ctxProperties->arb_multitexture) { - for (i = 0; i < numActiveTexUnit; i++) { - /* - * NULL texUnitStateMap means - * one to one mapping from texture unit to - * texture unit state. It is NULL in build display list, - * when the mapping is according to the texCoordSetMap - */ - if (texUnitStateMap != NULL) { - tus = texUnitStateMap[i]; - } else { - tus = i; - } - /* - * it's possible that texture unit state index (tus) - * is greater than the texCoordSetMapOffsetLen, in this - * case, just disable TexCoordPointer. - */ - if ((tus < texCoordSetMapLen) && - (texCoordSetMapOffset[tus] != -1)) { - enableTexCoordPointer(ctxProperties, i, - texSize, GL_FLOAT, bstride, - &(verts[texCoordoff + texCoordSetMapOffset[tus]])); - - } else { - disableTexCoordPointer(ctxProperties, i); - } - } - }/* GL_ARB_multitexture */ + for (i = 0; i < numActiveTexUnit; i++) { - else { + tus = i; -#ifdef VERBOSE - if (numActiveTexUnit > 1) { - fprintf(stderr, "No multi-texture support\n"); - } -#endif /* VERBOSE */ + /* + * it's possible that texture unit state index (tus) + * is greater than the texCoordSetMapOffsetLen, in this + * case, just disable TexCoordPointer. + */ + if ((tus < texCoordSetMapLen) && + (texCoordSetMapOffset[tus] != -1)) { + enableTexCoordPointer(ctxProperties, i, + texSize, GL_FLOAT, bstride, + &(verts[texCoordoff + texCoordSetMapOffset[tus]])); - if (texUnitStateMap != NULL) { - tus = texUnitStateMap[0]; - } else { - tus = 0; - } - if (texCoordSetMapOffset[tus] != -1) { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(texSize, GL_FLOAT, bstride, - &(verts[texCoordoff + texCoordSetMapOffset[tus]])); - - } else { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } - } else { - if ((texUnitIndex < texCoordSetMapLen) && - (texCoordSetMapOffset[texUnitIndex] != -1)) { - enableTexCoordPointer(ctxProperties, 0, - texSize, GL_FLOAT, bstride, - &(verts[texCoordoff + texCoordSetMapOffset[texUnitIndex]])); } else { - disableTexCoordPointer(ctxProperties, 0); + disableTexCoordPointer(ctxProperties, i); } } } @@ -146,16 +97,12 @@ resetTexture(jlong ctxInfo) GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - if(ctxProperties->arb_multitexture) { - /* Disable texture coordinate arrays for all texture units */ - for (i = 0; i < ctxProperties->maxTexCoordSets; i++) { - disableTexCoordPointer(ctxProperties, i); - } - /* Reset client active texture unit to 0 */ - clientActiveTextureUnit(ctxProperties, 0); - } else { - disableTexCoordPointer(ctxProperties, 0); + /* Disable texture coordinate arrays for all texture units */ + for (i = 0; i < ctxProperties->maxTexCoordSets; i++) { + disableTexCoordPointer(ctxProperties, i); } + /* Reset client active texture unit to 0 */ + clientActiveTextureUnit(ctxProperties, 0); } @@ -200,7 +147,6 @@ executeGeometryArray( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, @@ -208,10 +154,9 @@ executeGeometryArray( jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jint vertexAttrCount, jintArray vertexAttrSizes, jfloatArray varray, jobject varrayBuffer, jfloatArray carray, - jint texUnitIndex, jint cDirty) + jint cDirty) { jclass geo_class; JNIEnv table; @@ -231,8 +176,7 @@ executeGeometryArray( jfieldID strip_field; jarray sarray; - jint texSize, texStride, *texCoordSetMapOffset = NULL, - *texUnitStateMap = NULL; + jint texSize, texStride, *texCoordSetMapOffset = NULL; GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; @@ -358,12 +302,8 @@ executeGeometryArray( texCoordSetMapOffset = (jint *) (*(table->GetPrimitiveArrayCritical))(env, texUnitOffset, NULL); } - if (texUnitStateMapArray != NULL) { - texUnitStateMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env, texUnitStateMapArray, NULL); - } - /* Enable normalize for non-uniform scale (which rescale can't handle) */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glEnable(GL_NORMALIZE); } @@ -416,10 +356,10 @@ executeGeometryArray( if (vformat & GA_TEXTURE_COORDINATE) { - executeTexture(texUnitIndex, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - numActiveTexUnit, texUnitStateMap, + numActiveTexUnit, startVertex, ctxInfo); } @@ -509,10 +449,10 @@ executeGeometryArray( if (vformat & GA_TEXTURE_COORDINATE) { - executeTexture(texUnitIndex, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - numActiveTexUnit, texUnitStateMap, + numActiveTexUnit, startVertex, ctxInfo); } @@ -536,7 +476,7 @@ executeGeometryArray( } /* clean up if we turned on normalize */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glDisable(GL_NORMALIZE); } @@ -555,9 +495,6 @@ executeGeometryArray( (*(table->ReleasePrimitiveArrayCritical))(env, texUnitOffset, texCoordSetMapOffset, 0); - if (texUnitStateMap != NULL) - (*(table->ReleasePrimitiveArrayCritical))(env, texUnitStateMapArray, - texUnitStateMap, 0); if(varray != NULL) (*(table->ReleasePrimitiveArrayCritical))(env, varray, verts, 0); @@ -568,15 +505,14 @@ executeGeometryArray( /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: execute * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZZZIIII[II[II[II[I[F[FII)V */ JNIEXPORT void JNICALL -Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, +Java_javax_media_j3d_NativePipeline_execute(JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, @@ -584,10 +520,9 @@ Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jint vertexAttrCount, jintArray vertexAttrSizes, jfloatArray varray, jfloatArray carray, - jint texUnitIndex, jint cDirty) + jint cDirty) { #ifdef VERBOSE @@ -596,21 +531,20 @@ Java_javax_media_j3d_GeometryArrayRetained_execute(JNIEnv *env, /* call executeGeometryArray */ executeGeometryArray(env, obj, ctxInfo, geo, geo_type, isNonUniformScale, useAlpha, - multiScreen, ignoreVertexColors, startVIndex, vcount, vformat, + ignoreVertexColors, startVIndex, vcount, vformat, texCoordSetCount, texCoordSetMap, texCoordSetMapLen, - texUnitOffset, numActiveTexUnit, texUnitStateMapArray, + texUnitOffset, numActiveTexUnit, vertexAttrCount, vertexAttrSizes, - varray, NULL, carray, texUnitIndex, cDirty); + varray, NULL, carray, cDirty); } /* interleaved data with nio buffer as data format */ JNIEXPORT void JNICALL -Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer( +Java_javax_media_j3d_NativePipeline_executeInterleavedBuffer( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, - jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, + jboolean isNonUniformScale, jboolean useAlpha, jboolean ignoreVertexColors, jint startVIndex, jint vcount, jint vformat, @@ -618,9 +552,8 @@ Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer( jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jobject varray, jfloatArray carray, - jint texUnitIndex, jint cDirty) + jint cDirty) { #ifdef VERBOSE @@ -629,22 +562,22 @@ Java_javax_media_j3d_GeometryArrayRetained_executeInterleavedBuffer( /* call executeGeometryArray */ executeGeometryArray(env, obj, ctxInfo, geo, geo_type, isNonUniformScale, useAlpha, - multiScreen, ignoreVertexColors, startVIndex, vcount, vformat, + ignoreVertexColors, startVIndex, vcount, vformat, texCoordSetCount, texCoordSetMap, texCoordSetMapLen, - texUnitOffset, numActiveTexUnit, texUnitStateMapArray, + texUnitOffset, numActiveTexUnit, 0, NULL, - NULL, varray, carray, texUnitIndex, cDirty); + NULL, varray, carray, cDirty); } /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: buildGA * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZFZIIII[II[II[I[D[D[F)V */ JNIEXPORT - void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGA(JNIEnv *env, + void JNICALL Java_javax_media_j3d_NativePipeline_buildGA(JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean updateAlpha, float alpha, @@ -911,12 +844,12 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", if (texCoordSetMapLen > 0) { - if (ctxProperties->arb_multitexture) { + if (ctxProperties->gl13) { if (vformat & GA_TEXTURE_COORDINATE_2) { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord2fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord2fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } @@ -924,8 +857,8 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", } else if (vformat & GA_TEXTURE_COORDINATE_3) { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord3fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord3fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } @@ -933,15 +866,15 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", } else { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord4fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord4fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } } } } - else { /* GL_ARB_multitexture */ + else { /* no multitexture */ if (texCoordSetMapOffset[0] != -1) { if (vformat & GA_TEXTURE_COORDINATE_2) { @@ -955,7 +888,7 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", texCoordSetMapOffset[0]]); } } - } /* GL_ARB_multitexture */ + } /* no multitexture */ } /* * texCoordSetMapLen can't be 0 if texture coordinates @@ -1121,12 +1054,12 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", if (texCoordSetMapLen > 0) { - if(ctxProperties->arb_multitexture) { + if(ctxProperties->gl13) { if (vformat & GA_TEXTURE_COORDINATE_2) { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord2fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord2fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } @@ -1134,8 +1067,8 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", } else if (vformat & GA_TEXTURE_COORDINATE_3) { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord3fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord3fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } @@ -1143,15 +1076,15 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", } else { for (k = 0; k < texCoordSetMapLen; k++) { if (texCoordSetMapOffset[k] != -1) { - ctxProperties->glMultiTexCoord4fvARB( - GL_TEXTURE0_ARB + k, + ctxProperties->glMultiTexCoord4fv( + GL_TEXTURE0 + k, &verts[texCoordoff + texCoordSetMapOffset[k]]); } } } } - else { /* GL_ARB_multitexture */ + else { /* no multitexture */ if (texCoordSetMapOffset[0] != -1) { if (vformat & GA_TEXTURE_COORDINATE_2) { @@ -1165,7 +1098,7 @@ printf("orig: < %g %g %g > transformed: < %g %g %g >\n", texCoordSetMapOffset[0]]); } } - } /* GL_ARB_multitexture */ + } /* no multitexture */ } /* @@ -1265,8 +1198,8 @@ clientActiveTextureUnit( GraphicsContextPropertiesInfo *ctxProperties, int texUnit) { - if (ctxProperties->arb_multitexture) { - ctxProperties->glClientActiveTextureARB(texUnit + GL_TEXTURE0_ARB); + if (ctxProperties->gl13) { + ctxProperties->glClientActiveTexture(texUnit + GL_TEXTURE0); } } @@ -1279,7 +1212,6 @@ executeGeometryArrayVA( jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -1295,12 +1227,10 @@ executeGeometryArrayVA( jint vertexAttrCount, jintArray vertexAttrSizes, jintArray vertexAttrIndices, - jfloat ** vertexAttrPointer, - jint pass, + jfloat ** vertexAttrPointer, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jint* texUnitStateMap, jintArray texindices, jint texStride, jfloat** texCoordPointer, @@ -1341,7 +1271,7 @@ executeGeometryArrayVA( #endif /* VERBOSE */ /* Enable normalize for non-uniform scale (which rescale can't handle) */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glEnable(GL_NORMALIZE); } @@ -1405,42 +1335,21 @@ executeGeometryArrayVA( initialTexIndices = (jint *) (*(table->GetPrimitiveArrayCritical))(env,texindices, NULL); texCoordSetMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tcoordsetmap, NULL); - if (pass < 0) { - for (i = 0; i < numActiveTexUnit; i++) { - tus = texUnitStateMap[i]; - if ((tus < texCoordMapLength) && ( - ((texSet=texCoordSetMap[tus]) != -1))) { - - ptexCoords = texCoordPointer[texSet]; + for (i = 0; i < numActiveTexUnit; i++) { + if ((i < texCoordMapLength) && ( + ((texSet=texCoordSetMap[i]) != -1))) { - enableTexCoordPointer(ctxProperties, i, texStride, - GL_FLOAT, 0, - &ptexCoords[texStride * initialTexIndices[texSet]]); - - } else { - disableTexCoordPointer(ctxProperties, i); - } - } - } - else { - texUnitStateMap = NULL; - texSet = texCoordSetMap[pass]; - if (texSet != -1) { - ptexCoords = texCoordPointer[texSet]; - enableTexCoordPointer(ctxProperties, 0, texStride, - GL_FLOAT, 0, - &ptexCoords[texStride * initialTexIndices[texSet]]); + ptexCoords = texCoordPointer[texSet]; + + enableTexCoordPointer(ctxProperties, i, texStride, + GL_FLOAT, 0, + &ptexCoords[texStride * initialTexIndices[texSet]]); + + } else { + disableTexCoordPointer(ctxProperties, i); + } + } - /* - * in a non-multitexturing case, only the first texture - * unit is used, it will be the core library responsibility - * to disable all texture units before enabling "the" - * texture unit for multi-pass purpose - */ - } else { - disableTexCoordPointer(ctxProperties, 0); - } - } /* Reset client active texture unit to 0 */ clientActiveTextureUnit(ctxProperties, 0); } @@ -1494,7 +1403,7 @@ executeGeometryArrayVA( } } /* clean up if we turned on normalize */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glDisable(GL_NORMALIZE); } @@ -1513,19 +1422,18 @@ executeGeometryArrayVA( /* execute geometry array with java array format */ /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: executeVA * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZZIIII[F[DI[F[BI[FI[I[I[[FII[II[I[II[Ljava/lang/Object;I)V */ JNIEXPORT void JNICALL -Java_javax_media_j3d_GeometryArrayRetained_executeVA( +Java_javax_media_j3d_NativePipeline_executeVA( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -1541,12 +1449,10 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( jint vertexAttrCount, jintArray vertexAttrSizes, jintArray vertexAttrIndices, - jobjectArray vertexAttrData, - jint pass, + jobjectArray vertexAttrData, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jintArray texindices, jint texStride, jobjectArray texCoords, @@ -1570,7 +1476,6 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( jfloat **vertexAttrPointer = NULL; jfloat **texCoordPointer = NULL; jarray *texobjs = NULL; - jint* texUnitStateMap = NULL; int i; jboolean floatCoordDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COORD_FLOAT) != 0); @@ -1631,10 +1536,7 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( else texCoordPointer[i] = NULL; } - if (pass < 0) { - texUnitStateMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tunitstatemap, NULL); - } - } + } /* get coordinate array */ if (floatCoordDefined) { @@ -1660,15 +1562,15 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( #endif /* VERBOSE */ executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, multiScreen, ignoreVertexColors, + isNonUniformScale, ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, norms, vertexAttrCount, vertexAttrSizes, vertexAttrIndices, vertexAttrPointer, - pass, texCoordMapLength, - tcoordsetmap,numActiveTexUnit, texUnitStateMap, + texCoordMapLength, + tcoordsetmap,numActiveTexUnit, texindices,texStride,texCoordPointer,cdirty, sarray, strip_len, start_array); @@ -1691,9 +1593,6 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( (*(table->ReleasePrimitiveArrayCritical))(env, texobjs[i], texCoordPointer[i], 0); } } - if (texUnitStateMap != NULL) { - (*(table->ReleasePrimitiveArrayCritical))(env, tunitstatemap, texUnitStateMap, 0); - } } if (texobjs != NULL) { @@ -1726,18 +1625,17 @@ Java_javax_media_j3d_GeometryArrayRetained_executeVA( /* execute geometry array with java array format */ /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: executeVABuffer * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZZIIIILjava/lang/Object;ILjava/lang/Object;[F[BILjava/lang/Object;I[I[I[Ljava/lang/Object;II[II[I[II[Ljava/lang/Object;I)V */ -JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffer( +JNIEXPORT void JNICALL Java_javax_media_j3d_NativePipeline_executeVABuffer( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint vcount, jint vformat, @@ -1753,12 +1651,10 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe jint vertexAttrCount, jintArray vertexAttrSizes, jintArray vertexAttrIndices, - jobjectArray vertexAttrData, - jint pass, + jobjectArray vertexAttrData, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jintArray texindices, jint texStride, jobjectArray texCoords, @@ -1781,7 +1677,6 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe jfloat **vertexAttrPointer = NULL; jfloat **texCoordPointer = NULL; jarray *texobjs = NULL; - jint* texUnitStateMap = NULL; int i; jboolean floatCoordDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COORD_FLOAT) != 0); @@ -1872,9 +1767,6 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe else texCoordPointer[i] = NULL; } - if (pass < 0) { - texUnitStateMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tunitstatemap, NULL); - } } @@ -1883,15 +1775,15 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe #endif /* VERBOSE */ executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, multiScreen, ignoreVertexColors, + isNonUniformScale, ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fverts, dverts, initialColorIndex, fclrs, bclrs, initialNormalIndex, norms, vertexAttrCount, vertexAttrSizes, vertexAttrIndices, vertexAttrPointer, - pass, texCoordMapLength, - tcoordsetmap,numActiveTexUnit, texUnitStateMap, + texCoordMapLength, + tcoordsetmap,numActiveTexUnit, texindices,texStride,texCoordPointer,cdirty, sarray, strip_len, start_array); if (vaobjs != NULL) { @@ -1900,12 +1792,6 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe if (vertexAttrPointer != NULL) { free(vertexAttrPointer); } - - if (textureDefined) { - if (texUnitStateMap != NULL) { - (*(table->ReleasePrimitiveArrayCritical))(env, tunitstatemap, texUnitStateMap, 0); - } - } if (texobjs != NULL) { free(texobjs); @@ -1923,10 +1809,11 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_executeVABuffe JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_disableGlobalAlpha( +void JNICALL Java_javax_media_j3d_NativePipeline_disableGlobalAlpha( JNIEnv *env, jobject obj, - jlong ctxInfo, + jlong ctxInfo, + jobject geo, jint vformat, jboolean useAlpha, jboolean ignoreVertexColors) @@ -1945,15 +1832,16 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_disableGlobalAlpha( /* - * Class: javax_media_j3d_GeometryArrayRetained + * Class: javax_media_j3d_NativePipeline * Method: setVertexFormat * Signature: (JIZZI[I)V */ JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_setVertexFormat( +void JNICALL Java_javax_media_j3d_NativePipeline_setVertexFormat( JNIEnv *env, jobject obj, jlong ctxInfo, + jobject geo, jint vformat, jboolean useAlpha, jboolean ignoreVertexColors) @@ -1999,28 +1887,11 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_setVertexFormat( } } -JNIEXPORT jboolean JNICALL -Java_javax_media_j3d_GeometryArrayRetained_globalAlphaSUN( - JNIEnv *env, - jobject obj, - jlong ctxInfo) -{ - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - - if (ctxProperties->global_alpha_sun == 1) - return JNI_TRUE ; - else - return JNI_FALSE ; -} - - static void executeIndexedGeometryArray( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -2031,9 +1902,8 @@ executeIndexedGeometryArray( jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jfloatArray varray, jobject varrayBuffer, jfloatArray carray, - jint texUnitIndex, jint cDirty, + jint cDirty, jintArray indexCoord) { jclass geo_class; @@ -2060,8 +1930,7 @@ executeIndexedGeometryArray( jint** multiDrawElementsIndices = NULL; jint allocated = 0; - jint texSize, texStride, *texCoordSetMapOffset = NULL, - *texUnitStateMap = NULL; + jint texSize, texStride, *texCoordSetMapOffset = NULL; GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; @@ -2178,12 +2047,8 @@ executeIndexedGeometryArray( texCoordSetMapOffset = (jint *) (*(table->GetPrimitiveArrayCritical))(env, texUnitOffset, NULL); } - if (texUnitStateMapArray != NULL) { - texUnitStateMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env, texUnitStateMapArray, NULL); - } - /* Enable normalize for non-uniform scale (which rescale can't handle) */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glEnable(GL_NORMALIZE); } @@ -2233,10 +2098,10 @@ executeIndexedGeometryArray( if (vformat & GA_TEXTURE_COORDINATE) { /* XXXX: texCoordoff == 0 ???*/ - executeTexture(texUnitIndex, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - numActiveTexUnit, texUnitStateMap, + numActiveTexUnit, verts, ctxInfo); } @@ -2336,10 +2201,10 @@ executeIndexedGeometryArray( if (vformat & GA_TEXTURE_COORDINATE) { /* XXXX: texCoordoff == 0 ???*/ - executeTexture(texUnitIndex, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - numActiveTexUnit, texUnitStateMap, + numActiveTexUnit, verts, ctxInfo); } @@ -2377,7 +2242,7 @@ executeIndexedGeometryArray( /* clean up if we turned on normalize */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glDisable(GL_NORMALIZE); } if(varray != NULL) @@ -2392,20 +2257,16 @@ executeIndexedGeometryArray( (*(table->ReleasePrimitiveArrayCritical))(env, texUnitOffset, texCoordSetMapOffset, 0); - if (texUnitStateMap != NULL) - (*(table->ReleasePrimitiveArrayCritical))(env, texUnitStateMapArray, - texUnitStateMap, 0); if (vAttrSizesPtr != NULL) { table->ReleaseIntArrayElements(env, vertexAttrSizes, vAttrSizesPtr, JNI_ABORT); } } JNIEXPORT void JNICALL -Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometry( +Java_javax_media_j3d_NativePipeline_executeIndexedGeometry( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -2416,9 +2277,8 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometry( jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jfloatArray varray, jfloatArray carray, - jint texUnitIndex, jint cDirty, + jint cDirty, jintArray indexCoord) { @@ -2427,7 +2287,7 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometry( #endif /* VERBOSE */ executeIndexedGeometryArray(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, useAlpha, multiScreen, + isNonUniformScale, useAlpha, ignoreVertexColors, initialIndexIndex, indexCount, @@ -2438,18 +2298,16 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometry( texCoordSetMap, texCoordSetMapLen, texUnitOffset, numActiveTexUnit, - texUnitStateMapArray, varray, NULL, carray, - texUnitIndex, cDirty, + cDirty, indexCoord); } JNIEXPORT void JNICALL -Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryBuffer( +Java_javax_media_j3d_NativePipeline_executeIndexedGeometryBuffer( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, jboolean useAlpha, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint indexCount, @@ -2459,9 +2317,8 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryBuffer( jintArray texCoordSetMap, jint texCoordSetMapLen, jintArray texUnitOffset, jint numActiveTexUnit, - jintArray texUnitStateMapArray, jobject varray, jfloatArray carray, - jint texUnitIndex, jint cDirty, + jint cDirty, jintArray indexCoord) { @@ -2470,7 +2327,7 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryBuffer( #endif /* VERBOSE */ executeIndexedGeometryArray(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, useAlpha, multiScreen, + isNonUniformScale, useAlpha, ignoreVertexColors, initialIndexIndex, indexCount, @@ -2481,9 +2338,8 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryBuffer( texCoordSetMap, texCoordSetMapLen, texUnitOffset, numActiveTexUnit, - texUnitStateMapArray, NULL, varray, carray, - texUnitIndex, cDirty, + cDirty, indexCoord); } @@ -2496,7 +2352,6 @@ executeIndexedGeometryArrayVA( jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint validIndexCount, @@ -2510,12 +2365,10 @@ executeIndexedGeometryArrayVA( jfloat* norms, jint vertexAttrCount, jintArray vertexAttrSizes, - jfloat ** vertexAttrPointer, - jint pass, + jfloat ** vertexAttrPointer, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jfloat** texCoordPointer, jint cdirty, @@ -2543,7 +2396,7 @@ executeIndexedGeometryArrayVA( jlong ctx = ctxProperties->context; int texSet; - jint *texCoordSetMap, *texUnitStateMap; + jint *texCoordSetMap; GLsizei *countArray; jint* vAttrSizes; jint offset = 0; @@ -2557,7 +2410,7 @@ executeIndexedGeometryArrayVA( #endif /* VERBOSE */ /* Enable normalize for non-uniform scale (which rescale can't handle) */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glEnable(GL_NORMALIZE); } @@ -2608,43 +2461,23 @@ executeIndexedGeometryArrayVA( int tus = 0; float *ptexCoords; - texCoordSetMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tcoordsetmap, NULL); - if (pass < 0) { - texUnitStateMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tunitstatemap, NULL); - for (i = 0; i < numActiveTexUnit; i++) { - tus = texUnitStateMap[i]; - if ((tus < texCoordMapLength) && ( - ((texSet=texCoordSetMap[tus]) != -1))) { - - ptexCoords = texCoordPointer[texSet]; + texCoordSetMap = (jint *) (*(table->GetPrimitiveArrayCritical))(env,tcoordsetmap, NULL); + for (i = 0; i < numActiveTexUnit; i++) { + if ((i < texCoordMapLength) && ( + ((texSet=texCoordSetMap[i]) != -1))) { - enableTexCoordPointer(ctxProperties, i, texStride, - GL_FLOAT, 0, - ptexCoords); - - } else { + ptexCoords = texCoordPointer[texSet]; - disableTexCoordPointer(ctxProperties, i); - } - } - } - else { - texUnitStateMap = NULL; - texSet = texCoordSetMap[pass]; - if (texSet != -1) { - ptexCoords = texCoordPointer[texSet]; - enableTexCoordPointer(ctxProperties, 0, texStride, - GL_FLOAT, 0, - ptexCoords); + enableTexCoordPointer(ctxProperties, i, texStride, + GL_FLOAT, 0, + ptexCoords); + + } else { + + disableTexCoordPointer(ctxProperties, i); + } + } - /* - * in a non-multitexturing case, only the first texture - * unit is used, it will be the core library responsibility - * to disable all texture units before enabling "the" - * texture unit for multi-pass purpose - */ - } - } /* Reset client active texture unit to 0 */ clientActiveTextureUnit(ctxProperties, 0); } @@ -2714,7 +2547,7 @@ executeIndexedGeometryArrayVA( unlockArray(ctxProperties); /* clean up if we turned on normalize */ - if (ctxProperties->rescale_normal_ext && isNonUniformScale) { + if (isNonUniformScale) { glDisable(GL_NORMALIZE); } @@ -2728,21 +2561,18 @@ executeIndexedGeometryArrayVA( resetTexture(ctxInfo); (*(table->ReleasePrimitiveArrayCritical))(env, tcoordsetmap, texCoordSetMap, 0); - if (texUnitStateMap != NULL) - (*(table->ReleasePrimitiveArrayCritical))(env, tunitstatemap, texUnitStateMap, 0); } } JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryVA( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometryVA( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint validIndexCount, @@ -2756,12 +2586,10 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jfloatArray ndata, jint vertexAttrCount, jintArray vertexAttrSizes, - jobjectArray vertexAttrData, - jint pass, + jobjectArray vertexAttrData, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jobjectArray texCoords, jint cdirty, @@ -2871,7 +2699,6 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo geo, geo_type, isNonUniformScale, - multiScreen, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -2885,12 +2712,10 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo norms, vertexAttrCount, vertexAttrSizes, - vertexAttrPointer, - pass, + vertexAttrPointer, texCoordMapLength, tcoordsetmap, numActiveTexUnit, - tunitstatemap, texStride, texCoordPointer, cdirty, @@ -2946,14 +2771,13 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo } JNIEXPORT -void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeometryVABuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_executeIndexedGeometryVABuffer( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, jboolean isNonUniformScale, - jboolean multiScreen, jboolean ignoreVertexColors, jint initialIndexIndex, jint validIndexCount, @@ -2967,12 +2791,10 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo jobject ndata, jint vertexAttrCount, jintArray vertexAttrSizes, - jobjectArray vertexAttrData, - jint pass, + jobjectArray vertexAttrData, jint texCoordMapLength, jintArray tcoordsetmap, jint numActiveTexUnit, - jintArray tunitstatemap, jint texStride, jobjectArray texCoords, jint cdirty, @@ -3089,7 +2911,6 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo geo, geo_type, isNonUniformScale, - multiScreen, ignoreVertexColors, initialIndexIndex, validIndexCount, @@ -3104,11 +2925,9 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo vertexAttrCount, vertexAttrSizes, vertexAttrPointer, - pass, texCoordMapLength, tcoordsetmap, numActiveTexUnit, - tunitstatemap, texStride, texCoordPointer, cdirty, @@ -3137,7 +2956,7 @@ void JNICALL Java_javax_media_j3d_IndexedGeometryArrayRetained_executeIndexedGeo } JNIEXPORT void JNICALL -Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeometry( +Java_javax_media_j3d_NativePipeline_buildIndexedGeometry( JNIEnv *env, jobject obj, jlong ctxInfo, jobject geo, jint geo_type, @@ -3414,10 +3233,10 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeometry( if (vformat & GA_TEXTURE_COORDINATE) { - executeTexture(-1, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - texCoordSetMapLen, NULL, + texCoordSetMapLen, verts, ctxInfo); } @@ -3536,10 +3355,10 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeometry( } if (vformat & GA_TEXTURE_COORDINATE) { - executeTexture(-1, texCoordSetMapLen, + executeTexture(texCoordSetMapLen, texSize, bstride, texCoordoff, texCoordSetMapOffset, - texCoordSetMapLen, NULL, + texCoordSetMapLen, verts, ctxInfo); } @@ -3607,7 +3426,7 @@ Java_javax_media_j3d_IndexedGeometryArrayRetained_buildIndexedGeometry( * Method: buildGAForByRef * Signature: (JLjavax/media/j3d/GeometryArrayRetained;IZZFZIIII[F[DI[F[BI[FI[I[I[[FI[I[II[Ljava/lang/Object;[D[D)V */ -JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRef( +JNIEXPORT void JNICALL Java_javax_media_j3d_NativePipeline_buildGAForByRef( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -3665,7 +3484,6 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe jfloat **vertexAttrPointer = NULL; jfloat **texCoordPointer = NULL; jarray *texobjs = NULL; - jint *tunitstatemap = NULL; int offset = 0; jboolean floatCoordDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COORD_FLOAT) != 0); @@ -3741,14 +3559,11 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe /* get texture arrays */ if (textureDefined) { - tunitstatemap = (int *)malloc(texCoordMapLength * sizeof(int)); for (i = 0; i < texCoordMapLength; i++) { - tunitstatemap[i] = i; if (texobjs[i] != NULL) texCoordPointer[i] = (jfloat*)(*(table->GetPrimitiveArrayCritical))(env,texobjs[i], NULL); else - texCoordPointer[i] = NULL; - + texCoordPointer[i] = NULL; } } @@ -3917,17 +3732,14 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe fprintf(stderr, "GeometryArrayRetained.buildGAForByRef() -- calling executeGeometryArrayVA\n"); #endif /* VERBOSE */ - executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, JNI_FALSE, ignoreVertexColors, - vcount, vformat, vdefined, initialCoordIndex, - fvptr, dvptr, initialColorIndex, + executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, isNonUniformScale, + ignoreVertexColors, vcount, vformat, vdefined, + initialCoordIndex, fvptr, dvptr, initialColorIndex, fcptr, bcptr, initialNormalIndex, - nptr, - vertexAttrCount, vertexAttrSizes, - vertexAttrIndices, vertexAttrPointer, - -1, texCoordMapLength, - tcoordsetmap, texCoordMapLength, tunitstatemap, - texindices,texStride,texCoordPointer,0, sarray, + nptr, vertexAttrCount, vertexAttrSizes, + vertexAttrIndices, vertexAttrPointer, texCoordMapLength, + tcoordsetmap, texCoordMapLength, + texindices, texStride, texCoordPointer, 0, sarray, strip_len, start_array); if (vattrDefined) { @@ -3944,9 +3756,6 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe } if (textureDefined) { - if (tunitstatemap != NULL) { - free(tunitstatemap); - } for (i = 0; i < texCoordMapLength; i++) { if (texCoordPointer[i] != NULL) { (*(table->ReleasePrimitiveArrayCritical))(env, texobjs[i], texCoordPointer[i], 0); @@ -3992,7 +3801,7 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe else if (doubleCoordDefined) { (*env)->ReleasePrimitiveArrayCritical(env, vdcoords, dverts, 0); if (tmpDoubleCoordArray != NULL) { - free(tmpFloatCoordArray); + free(tmpDoubleCoordArray); } } } @@ -4002,7 +3811,7 @@ JNIEXPORT void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForByRe #if 0 /* execute geometry array with java array format */ JNIEXPORT -void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( +void JNICALL Java_javax_media_j3d_NativePipeline_buildGAForBuffer( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -4052,7 +3861,6 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( jbyte* bcptr = NULL; jfloat **texCoordPointer = NULL; jarray *texobjs = NULL; - jint *tunitstatemap = NULL; jboolean floatCoordDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COORD_FLOAT) != 0); jboolean doubleCoordDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COORD_DOUBLE) != 0); jboolean floatColorsDefined = ((vdefined & javax_media_j3d_GeometryArrayRetained_COLOR_FLOAT) != 0); @@ -4110,9 +3918,7 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( } /* get texture arrays */ if (textureDefined) { - tunitstatemap = (int *)malloc( texCoordMapLength * sizeof(int)); for (i = 0; i < texCoordMapLength; i++) { - tunitstatemap[i] = i; if (texobjs[i] != NULL) texCoordPointer[i] = (jfloat*)(*(table->GetPrimitiveArrayCritical))(env,texobjs[i], NULL); else @@ -4287,20 +4093,17 @@ void JNICALL Java_javax_media_j3d_GeometryArrayRetained_buildGAForBuffer( #endif /* VERBOSE */ executeGeometryArrayVA(env, obj, ctxInfo, geo, geo_type, - isNonUniformScale, JNI_FALSE, ignoreVertexColors, + isNonUniformScale, ignoreVertexColors, vcount, vformat, vdefined, initialCoordIndex, fvptr, dvptr, initialColorIndex, fcptr, bcptr, initialNormalIndex, nptr, /* TODO: vertexAttrCount, vertexAttrSizes, */ /* TODO: vertexAttrIndices, vertexAttrPointer, */ - -1, texCoordMapLength, - tcoordsetmap, texCoordMapLength, tunitstatemap, + texCoordMapLength, + tcoordsetmap, texCoordMapLength, texindices,texStride,texCoordPointer,0, sarray, strip_len, start_array); if (textureDefined) { - if (tunitstatemap != NULL) { - free(tunitstatemap); - } for (i = 0; i < texCoordMapLength; i++) { if (texCoordPointer[i] != NULL) { (*(table->ReleasePrimitiveArrayCritical))(env, texobjs[i], texCoordPointer[i], 0); diff --git a/src/native/ogl/GraphicsContext3D.c b/src/native/ogl/GraphicsContext3D.c index da656a6..50f73bf 100644 --- a/src/native/ogl/GraphicsContext3D.c +++ b/src/native/ogl/GraphicsContext3D.c @@ -17,21 +17,163 @@ extern void throwAssert(JNIEnv *env, char *str); +JNIEXPORT +void JNICALL Java_javax_media_j3d_NativePipeline_readRaster( + JNIEnv *env, jobject obj, jlong ctx, + jint type, jint xOffset, jint yOffset, + jint wRaster, jint hRaster, jint hCanvas, + jint imageDataType, + jint imageFormat, jobject imageBuffer, + jint depthFormat, jobject depthBuffer) +{ + JNIEnv table; + int yAdjusted; + GLenum oglFormat; + void *imageObjPtr; + void *depthObjPtr; + + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctx; + + table = *env; + + glPixelStorei(GL_PACK_ROW_LENGTH, wRaster); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + yAdjusted = hCanvas - hRaster - yOffset; + + if ((type & javax_media_j3d_Raster_RASTER_COLOR) != 0) { + + imageObjPtr = + (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)imageBuffer, NULL); + + if(imageDataType == IMAGE_DATA_TYPE_BYTE_ARRAY) { + + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_BYTE_BGR: + oglFormat = GL_BGR; + break; + case IMAGE_FORMAT_BYTE_RGB: + oglFormat = GL_RGB; + break; + /* GL_ABGR_EXT */ + case IMAGE_FORMAT_BYTE_ABGR: + if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ + oglFormat = GL_ABGR_EXT; + } + else { + throwAssert(env, "readRaster : GL_ABGR_EXT format is unsupported"); + return; + } + break; + case IMAGE_FORMAT_BYTE_RGBA: + oglFormat = GL_RGBA; + break; + case IMAGE_FORMAT_BYTE_LA: + /* all LA types are stored as LA8 */ + oglFormat = GL_LUMINANCE_ALPHA; + break; + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_INT_BGR: + case IMAGE_FORMAT_INT_RGB: + case IMAGE_FORMAT_INT_ARGB: + default: + throwAssert(env, "readRaster : imageFormat illegal format"); + return; + } + + glReadPixels(xOffset, yAdjusted, wRaster, hRaster, + oglFormat, GL_UNSIGNED_BYTE, imageObjPtr); + + } + else if(imageDataType == IMAGE_DATA_TYPE_INT_ARRAY) { + GLenum intType = GL_UNSIGNED_INT_8_8_8_8; + GLboolean forceAlphaToOne = GL_FALSE; + + switch (imageFormat) { + /* GL_BGR */ + case IMAGE_FORMAT_INT_BGR: /* Assume XBGR format */ + oglFormat = GL_RGBA; + intType = GL_UNSIGNED_INT_8_8_8_8_REV; + forceAlphaToOne = GL_TRUE; + break; + case IMAGE_FORMAT_INT_RGB: /* Assume XRGB format */ + forceAlphaToOne = GL_TRUE; + /* Fall through to next case */ + case IMAGE_FORMAT_INT_ARGB: + oglFormat = GL_BGRA; + intType = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + /* This method only supports 3 and 4 components formats and INT types. */ + case IMAGE_FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_BGR: + case IMAGE_FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_ABGR: + default: + throwAssert(env, "readRaster : imageFormat illegal format"); + return; + } + + /* Force Alpha to 1.0 if needed */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 0.0f); + glPixelTransferf(GL_ALPHA_BIAS, 1.0f); + } + + glReadPixels(xOffset, yAdjusted, wRaster, hRaster, + oglFormat, intType, imageObjPtr); + + /* Restore Alpha scale and bias */ + if(forceAlphaToOne) { + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + glPixelTransferf(GL_ALPHA_BIAS, 0.0f); + } + } + else { + throwAssert(env, "readRaster : illegal image data type"); + return; + } + + (*(table->ReleasePrimitiveArrayCritical))(env, imageBuffer, imageObjPtr, 0); + } + + if ((type & javax_media_j3d_Raster_RASTER_DEPTH) != 0) { + GLenum depthType = 0; + depthObjPtr = + (void *)(*(table->GetPrimitiveArrayCritical))(env, (jarray)depthBuffer, NULL); + + if (depthFormat == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { + depthType = GL_UNSIGNED_INT; + } else { /* javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT */ + depthType = GL_FLOAT; + } + + /* yOffset is adjusted for OpenGL - Y upward */ + glReadPixels(xOffset, yAdjusted, wRaster, hRaster, + GL_DEPTH_COMPONENT, depthType , depthObjPtr); + + (*(table->ReleasePrimitiveArrayCritical))(env, depthBuffer, depthObjPtr, 0); + } + +} + JNIEXPORT -void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( - JNIEnv *env, jobject obj, jlong ctxInfo, +void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( + JNIEnv *env, jobject obj, jlong ctx, jint type, jint xOffset, jint yOffset, jint wRaster, jint hRaster, jint hCanvas, - jint format, jobject image, jobject depth, jobject ctx) -{ + jint format, jobject image, jobject depth, jobject gc) +{ JNIEnv table; int yAdjusted; - jclass ctx_class; + jclass gc_class; GLenum gltype; - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong d3dctx = ctxProperties->context; + GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctx; table = *env; @@ -39,7 +181,7 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( glPixelStorei(GL_PACK_ALIGNMENT, 1); yAdjusted = hCanvas - hRaster - yOffset; - ctx_class = (jclass) (*(table->GetObjectClass))(env, ctx); + gc_class = (jclass) (*(table->GetObjectClass))(env, gc); if ((type & javax_media_j3d_Raster_RASTER_COLOR) != 0) { @@ -50,8 +192,8 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( jbyte *byteData; byteData_field = (jfieldID)(*(table->GetFieldID))(env, - ctx_class, "byteBuffer","[B"); - byteData_array = (jarray)(*(table->GetObjectField))(env, ctx, + gc_class, "byteBuffer","[B"); + byteData_array = (jarray)(*(table->GetObjectField))(env, gc, byteData_field); image_class = (jclass) (*(table->GetObjectClass))(env, image); @@ -61,30 +203,28 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( } switch (format) { - case FORMAT_BYTE_RGBA: + case IMAGE_FORMAT_BYTE_RGBA: gltype = GL_RGBA; break; - case FORMAT_BYTE_RGB: + case IMAGE_FORMAT_BYTE_RGB: gltype = GL_RGB; break; - case FORMAT_BYTE_ABGR: + case IMAGE_FORMAT_BYTE_ABGR: if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ gltype = GL_ABGR_EXT; } break; - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - gltype = ctxProperties->bgr_ext_enum; - } + case IMAGE_FORMAT_BYTE_BGR: + gltype = GL_BGR; break; - case FORMAT_BYTE_LA: + case IMAGE_FORMAT_BYTE_LA: gltype = GL_LUMINANCE_ALPHA; break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: + case IMAGE_FORMAT_BYTE_GRAY: + case IMAGE_FORMAT_USHORT_GRAY: default: throwAssert(env, "illegal format"); break; @@ -139,8 +279,8 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( jint *intData; intData_field = (jfieldID)(*(table->GetFieldID))(env, - ctx_class, "intBuffer","[I"); - intData_array = (jarray)(*(table->GetObjectField))(env, ctx, + gc_class, "intBuffer","[I"); + intData_array = (jarray)(*(table->GetObjectField))(env, gc, intData_field); intData = (jint *)(*(table->GetPrimitiveArrayCritical))(env, @@ -158,8 +298,8 @@ void JNICALL Java_javax_media_j3d_GraphicsContext3D_readRasterNative( jfloat *floatData; floatData_field = (jfieldID)(*(table->GetFieldID))(env, - ctx_class, "floatBuffer","[F"); - floatData_array = (jarray)(*(table->GetObjectField))(env, ctx, + gc_class, "floatBuffer","[F"); + floatData_array = (jarray)(*(table->GetObjectField))(env, gc, floatData_field); floatData = (jfloat *)(*(table->GetPrimitiveArrayCritical))(env, floatData_array, NULL); diff --git a/src/native/ogl/Lights.c b/src/native/ogl/Lights.c index db0c54f..2acece8 100644 --- a/src/native/ogl/Lights.c +++ b/src/native/ogl/Lights.c @@ -27,9 +27,9 @@ const float black[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; JNIEXPORT -void JNICALL Java_javax_media_j3d_DirectionalLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updateDirectionalLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctxInfo, jint lightSlot, jfloat red, @@ -70,9 +70,9 @@ void JNICALL Java_javax_media_j3d_DirectionalLightRetained_updateLight( } JNIEXPORT -void JNICALL Java_javax_media_j3d_PointLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updatePointLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctxInfo, jint lightSlot, jfloat red, @@ -114,9 +114,9 @@ void JNICALL Java_javax_media_j3d_PointLightRetained_updateLight( } JNIEXPORT -void JNICALL Java_javax_media_j3d_SpotLightRetained_updateLight( +void JNICALL Java_javax_media_j3d_NativePipeline_updateSpotLight( JNIEnv *env, - jobject light, + jobject obj, jlong ctxInfo, jint lightSlot, jfloat red, diff --git a/src/native/ogl/MasterControl.c b/src/native/ogl/MasterControl.c index 2ca2b08..027b640 100644 --- a/src/native/ogl/MasterControl.c +++ b/src/native/ogl/MasterControl.c @@ -72,7 +72,7 @@ extern int isExtensionSupported(const char *allExtensions, const char *extension); JNIEXPORT jboolean JNICALL -Java_javax_media_j3d_MasterControl_initializeJ3D( +Java_javax_media_j3d_NativePipeline_initializeJ3D( JNIEnv *env, jobject obj, jboolean disableXinerama) { jboolean glIsMTSafe = JNI_TRUE; @@ -164,84 +164,8 @@ DWORD countBits(DWORD mask) #endif /* WIN32 */ -/* - * Class: javax_media_j3d_MasterControl - * Method: getNumberOfProcessor - * Signature: ()I - * - * This function get the number of active processor in the system - */ -JNIEXPORT jint JNICALL Java_javax_media_j3d_MasterControl_getNumberOfProcessor - (JNIEnv *env, jobject obj) -{ -#if defined(UNIX) - return sysconf(_SC_NPROCESSORS_ONLN); -#endif /* UNIX_ */ - -#ifdef WIN32 - SYSTEM_INFO sysInfo; - - GetSystemInfo(&sysInfo); - return countBits(sysInfo.dwActiveProcessorMask); -#endif /* WIN32 */ -} - - -/* - * Class: javax_media_j3d_MasterControl - * Method: getThreadConcurrency - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_javax_media_j3d_MasterControl_getThreadConcurrency(JNIEnv *env, - jobject obj) -{ - /* - * Return the number of concurrent threads that can be run, - * -1 if unknown. - */ - -#ifdef SOLARIS - return (jint) thr_getconcurrency(); -#endif /* SOLARIS */ - -#ifdef LINUX - return -1; -#endif /* LINUX */ - -#ifdef WIN32 - return -1; -#endif /* WIN32 */ -} - - -/* - * Class: javax_media_j3d_MasterControl - * Method: setThreadConcurrency - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_javax_media_j3d_MasterControl_setThreadConcurrency(JNIEnv *env, - jobject obj, - jint newLevel) -{ -#ifdef SOLARIS - thr_setconcurrency((int)newLevel); -#endif /* SOLARIS */ - -#ifdef WIN32 - /* No-op on windows */ -#endif /* WIN32 */ - -#ifdef LINUX - /* No-op on linux */ -#endif /* LINUX */ -} - - - JNIEXPORT -jint JNICALL Java_javax_media_j3d_MasterControl_getMaximumLights( +jint JNICALL Java_javax_media_j3d_NativePipeline_getMaximumLights( JNIEnv *env, jobject obj ) { @@ -258,86 +182,3 @@ jint JNICALL Java_javax_media_j3d_MasterControl_getMaximumLights( return 8; #endif /* LINUX */ } - - -/* ======================================================================= */ - -/* - * The following method implements a high-resolution timer (based on the - * native code in the J3DTimer class). It will no longer be needed once - * we drop support for JDK 1.4.2, at which time it will be replaced by - * a call to System.nanoTime(). - */ - -#define NSEC_PER_SEC ((jlong)1000000000) - -#ifdef __linux__ -#include -#include -#include -#endif - -#ifdef SOLARIS -#include -#include -#include -#ifndef CLOCK_HIGHRES -#define CLOCK_HIGHRES 4 /* Solaris 7 does not define this */ -#endif /* constant. When run on Solaris 7 */ -#endif /* CLOCK_HIGHRES is not used. */ - -#ifdef WIN32 -#include -#include -static double timerScale = -1.0; -#endif - -/* - * Class: javax_media_j3d_MasterControl - * Method: getNativeTimerValue - * Signature: ()J - */ -JNIEXPORT jlong JNICALL -Java_javax_media_j3d_MasterControl_getNativeTimerValue(JNIEnv *env, jclass clazz) -{ - jlong timerNsec; - -#ifdef SOLARIS - /* - struct timespec tp; - clock_gettime( CLOCK_HIGHRES, &tp ); - - return (jlong)tp.tv_nsec + (jlong)tp.tv_sec * NSEC_PER_SEC; - */ - - timerNsec = (jlong)gethrtime(); -#endif /* SOLARIS */ - -#ifdef WIN32 - LARGE_INTEGER time; - LARGE_INTEGER freq; - - if (timerScale < 0.0) { - QueryPerformanceFrequency( &freq ); - if (freq.QuadPart <= 0) { - timerScale = 0.0; - } - else { - timerScale = (double) NSEC_PER_SEC / (double)freq.QuadPart; - } - } - - QueryPerformanceCounter(&time); - timerNsec = (jlong)((double)time.QuadPart * timerScale); - -#endif /* WIN32 */ - -#ifdef __linux__ - struct timeval t; - - gettimeofday(&t, 0); - timerNsec = ((jlong)t.tv_sec) * NSEC_PER_SEC + ((jlong)t.tv_usec) * ((jlong)1000); -#endif /* __linux__ */ - - return timerNsec; -} diff --git a/src/native/ogl/NativeAPIInfo.c b/src/native/ogl/NativeAPIInfo.c deleted file mode 100644 index 47dff76..0000000 --- a/src/native/ogl/NativeAPIInfo.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - * Portions of this code were derived from work done by the Blackdown - * group (www.blackdown.org), who did the initial Linux implementation - * of the Java 3D API. - */ - -#include - -#include "javax_media_j3d_MasterControl.h" -#include "javax_media_j3d_NativeAPIInfo.h" - -JNIEXPORT -jint JNICALL Java_javax_media_j3d_NativeAPIInfo_getRenderingAPI( - JNIEnv *env, jobject obj) -{ -#ifdef WIN32 - return (jint)javax_media_j3d_MasterControl_RENDER_OPENGL_WIN32; -#endif /* WIN32 */ - -#ifdef SOLARIS - return (jint)javax_media_j3d_MasterControl_RENDER_OPENGL_SOLARIS; -#endif /* SOLARIS */ - -#ifdef LINUX - return (jint)javax_media_j3d_MasterControl_RENDER_OPENGL_LINUX; -#endif /* LINUX */ -} diff --git a/src/native/ogl/NativeConfigTemplate3D.c b/src/native/ogl/NativeConfigTemplate3D.c index 9241c05..2d7ace7 100644 --- a/src/native/ogl/NativeConfigTemplate3D.c +++ b/src/native/ogl/NativeConfigTemplate3D.c @@ -617,23 +617,6 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing return JNI_FALSE; } - - -JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_J3dGraphicsConfig_isValidVisualID( - JNIEnv *env, - jclass cls, - jlong display, - jint vid) -{ - XVisualInfo template; - int nitems; - - template.visualid = vid; - XGetVisualInfo((Display *)display, VisualIDMask, &template, &nitems); - return (nitems == 1); - -} #endif /* UNIX_ */ diff --git a/src/native/ogl/NativeWSInfo.c b/src/native/ogl/NativeWSInfo.c deleted file mode 100644 index aa44776..0000000 --- a/src/native/ogl/NativeWSInfo.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - * Portions of this code were derived from work done by the Blackdown - * group (www.blackdown.org), who did the initial Linux implementation - * of the Java 3D API. - */ - -#include -#include - -#include "gldefs.h" - -#if defined(UNIX) -#include -#include -#include -#endif - -#ifdef WIN32 -#include -#endif - -#ifdef WIN32 - -/* - * Workaround for bug 4169320: Resizing a Java 3D canvas - * on Win95 crashes the application - */ - -#ifdef STRICT -static WNDPROC g_lpDefWindowProc; -#else -static FARPROC g_lpDefWindowProc; -#endif - -static -LRESULT CALLBACK canvas3dWndProc( - HWND hWnd, - UINT message, - WPARAM wParam, - LPARAM lParam) -{ - switch (message) { - case WM_WINDOWPOSCHANGED: - return 0; - default: - return CallWindowProc(g_lpDefWindowProc, hWnd, message, - wParam, lParam); - } -} - -JNIEXPORT -void JNICALL Java_javax_media_j3d_NativeWSInfo_subclass( - JNIEnv * env, - jobject obj, - jint hWnd) -{ -#ifdef STRICT - g_lpDefWindowProc = (WNDPROC) SetWindowLong((HWND) hWnd, GWL_WNDPROC, - (LONG) canvas3dWndProc); -#else - g_lpDefWindowProc = (FARPROC) SetWindowLong((HWND) hWnd, GWL_WNDPROC, - (LONG) canvas3dWndProc); -#endif -} - -#endif diff --git a/src/native/ogl/RasterRetained.c b/src/native/ogl/RasterRetained.c deleted file mode 100644 index 2f54146..0000000 --- a/src/native/ogl/RasterRetained.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Use is subject to license terms. - * - * $Revision$ - * $Date$ - * $State$ - */ - -#include -#include - -#include "gldefs.h" - -#ifdef DEBUG -/* Uncomment the following for VERBOSE debug messages */ -/* #define VERBOSE */ -#endif /* DEBUG */ - - -extern void throwAssert(JNIEnv *env, char *str); - - -JNIEXPORT -void JNICALL Java_javax_media_j3d_RasterRetained_execute(JNIEnv *env, - jobject obj, jlong ctxInfo, jobject geo, - jboolean updateAlpha, jfloat alpha, - jint type, jint w_raster, jint h_raster, - jint x_offset, jint y_offset, jfloat x, jfloat y, jfloat z, jbyteArray imageYdown) - - -{ - jclass geo_class; - JNIEnv table; - - jfieldID w_field, h_field; - int width, height; - - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - - table = *env; - - geo_class = (jclass) (*(table->GetObjectClass))(env, geo); - -#ifdef VERBOSE - fprintf(stderr, - "x %g ,y %g ,z %g ,w_raster %d,h_raster %d, x_offset %d, y_offset %d\n", - x,y,z,w_raster,h_raster,x_offset,y_offset); -#endif - - if ((type == javax_media_j3d_Raster_RASTER_COLOR) || - (type == javax_media_j3d_Raster_RASTER_COLOR_DEPTH)) { - jobject image; - jclass image_class; - jfieldID image_field, format_field; - jbyte *byteData; - int format; - int glformat; - - image_field = (jfieldID)(*(table->GetFieldID))(env, geo_class, - "image","Ljavax/media/j3d/ImageComponent2DRetained;"); - image = (jobject) (*(table->GetObjectField))(env, geo, image_field); - - if (image == NULL) { - return; - } - image_class = (jclass) (*(table->GetObjectClass))(env, image); - - format_field = (jfieldID) (*(table->GetFieldID))(env, image_class, - "storedYdownFormat", "I"); - format = (jint)(*(table->GetIntField))(env, image, format_field); - w_field = (jfieldID) (*(table->GetFieldID))(env, image_class, - "width", "I"); - width = (jint)(*(table->GetIntField))(env, image, w_field); - h_field = (jfieldID)(*(table->GetFieldID))(env, image_class, - "height", "I"); - height = (jint)(*(table->GetIntField))(env, image, h_field); - - - /* - * raster position is upper left corner, default for Java3D - * ImageComponent currently has the data reverse in Y - */ - glPixelZoom(1.0, -1.0); - glPixelStorei(GL_UNPACK_ROW_LENGTH, width); - if (x_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_PIXELS, x_offset); - if (x_offset + w_raster > width) { - w_raster = width - x_offset; - } - } else { - w_raster += x_offset; - if (w_raster > width) { - w_raster = width; - } - } - if (y_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_ROWS, y_offset); - if (y_offset + h_raster > height) { - h_raster = height - y_offset; - } - } else { - h_raster += y_offset; - if (h_raster > height) { - h_raster = height; - } - } - - - - glRasterPos3f(x, y, z); - - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - imageYdown, NULL); - -/* - { - int i, j, *intData; - - fprintf(stderr, "format = %d, w_raster = %d, h_raster = %d\n\n", format, w_raster, h_raster); - intData = (int*)byteData; - for (i = 0; i < w_raster; i++) { - for (j = 0; j < h_raster; j++, intData++) { - fprintf(stderr, " 0x%x", *intData); - } - fprintf(stderr, "\n"); - } - } - */ - switch (format) { - case FORMAT_BYTE_RGBA: - glformat = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - glformat = GL_RGB; - break; - - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - glformat = GL_ABGR_EXT; - } - break; - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - glformat = ctxProperties->bgr_ext_enum; - } - break; - case FORMAT_BYTE_LA: - glformat = GL_LUMINANCE_ALPHA; - break; - - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; - } - glDrawPixels(w_raster, h_raster, glformat, GL_UNSIGNED_BYTE, - byteData); - - (*(table->ReleasePrimitiveArrayCritical))(env, - imageYdown, byteData, 0); - } - - if ((type == javax_media_j3d_Raster_RASTER_DEPTH) || - (type == javax_media_j3d_Raster_RASTER_COLOR_DEPTH)) { - GLint draw_buf; - jobject depth; - jclass depth_class; - jfieldID depth_field, depth_type_field; - int depth_type; - - depth_field = (jfieldID)(*(table->GetFieldID))(env, geo_class, - "depthComponent","Ljavax/media/j3d/DepthComponentRetained;"); - - depth = (jobject) (*(table->GetObjectField))(env, geo, depth_field); - if (depth == NULL) { - return; - } - depth_class = (jclass) (*(table->GetObjectClass))(env, depth); - - depth_type_field = (jfieldID) (*(table->GetFieldID))(env, - depth_class, "type", "I"); - depth_type = (jint)(*(table->GetIntField))(env, depth, - depth_type_field); - - w_field = (jfieldID) (*(table->GetFieldID))(env, depth_class, - "width", "I"); - width = (jint)(*(table->GetIntField))(env, depth, w_field); - h_field = (jfieldID)(*(table->GetFieldID))(env, depth_class, - "height", "I"); - height = (jint)(*(table->GetIntField))(env, depth, h_field); - - - glGetIntegerv(GL_DRAW_BUFFER, &draw_buf); - /* disable draw buffer */ - glDrawBuffer(GL_NONE); - /* glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); */ - - /* - * raster position is upper left corner, default for Java3D - * ImageComponent currently has the data reverse in Y - */ - glPixelStorei(GL_UNPACK_ROW_LENGTH, width); - if (x_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_PIXELS, x_offset); - if (x_offset + w_raster > width) { - w_raster = width - x_offset; - } - } else { - w_raster += x_offset; - if (w_raster > width) { - w_raster = width; - } - } - if (y_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_ROWS, y_offset); - if (y_offset + h_raster > height) { - h_raster = height - y_offset; - } - } else { - h_raster += y_offset; - if (h_raster > height) { - h_raster = height; - } - } - - - if (depth_type == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { - jfieldID intData_field; - jintArray intData_array; - jint *intData; - - intData_field = (jfieldID)(*(table->GetFieldID))(env, - depth_class, "depthData","[I"); - - intData_array = (jintArray)(*(table->GetObjectField))(env, depth, - intData_field); - intData = (jint *)(*(table->GetPrimitiveArrayCritical))(env, - intData_array, NULL); - glDrawPixels(w_raster, h_raster, GL_DEPTH_COMPONENT, - GL_UNSIGNED_INT, intData); - (*(table->ReleasePrimitiveArrayCritical))(env, intData_array, - intData, 0); - } else { /* javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT */ - jfieldID floatData_field; - jfloatArray floatData_array; - jfloat *floatData; - - floatData_field = (jfieldID)(*(table->GetFieldID))(env, - depth_class, "depthData","[F"); - floatData_array = (jfloatArray)(*(table->GetObjectField))(env, depth, - floatData_field); - floatData = (jfloat *)(*(table->GetPrimitiveArrayCritical))(env, - floatData_array, NULL); - glDrawPixels(w_raster, h_raster, GL_DEPTH_COMPONENT, - GL_FLOAT, floatData); - (*(table->ReleasePrimitiveArrayCritical))(env, floatData_array, - floatData, 0); - } - - /* re-enable draw buffer */ - glDrawBuffer(draw_buf); - - } - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - -} - - -#if 0 - -JNIEXPORT -void JNICALL Java_javax_media_j3d_RasterRetained_executeTiled(JNIEnv *env, - jobject obj, jlong ctxInfo, jobject geo, - jint format, jint w_raster, jint h_raster, - jint x_offset, jint y_offset, jint deltaw, jint deltah, jfloat x, jfloat y, jfloat z, jbyteArray tile) - - -{ - jclass geo_class; - JNIEnv table; - jint j; - int alphaChanged = 0; /* used so we can get alpha data from */ - /* JNI before using it so we can use */ - /* GetPrimitiveArrayCritical */ - jobject image; - jclass image_class; - jfieldID byteData_field, image_field, format_field; - jbyteArray byteData_array; - jbyte *byteData; - int glformat; - float rasterPos[3]; - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; - jlong ctx = ctxProperties->context; - - table = *env; - - -#ifdef VERBOSE - fprintf(stderr, - "x %g ,y %g ,z %g ,w_raster %d,h_raster %d, x_offset %d, y_offset %d\n", - x,y,z,w_raster,h_raster,x_offset,y_offset); -#endif - - - /* - * raster position is upper left corner, default for Java3D - * ImageComponent currently has the data reverse in Y - */ - glPixelZoom(1.0, -1.0); - /* glPixelStorei(GL_UNPACK_ROW_LENGTH, width);*/ - if (x_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_PIXELS, x_offset); - if (x_offset + w_raster > width) { - w_raster = width - x_offset; - } - } else { - w_raster += x_offset; - if (w_raster > width) { - w_raster = width; - } - } - if (y_offset >= 0) { - glPixelStorei(GL_UNPACK_SKIP_ROWS, y_offset); - if (y_offset + h_raster > height) { - h_raster = height - y_offset; - } - } else { - h_raster += y_offset; - if (h_raster > height) { - h_raster = height; - } - } - - if (deltaw == 0 && deltah == 0) { - glRasterPos3f(x, y, z); - } - else { - glGetFloatv(GL_CURRENT_RASTER_POSITION,rasterPos); - rasterPos[0] += (float)deltaw; - rasterPos[1] += (float)deltah; - glRasterPos3f(rasterPos[0], rasterPos[1], rasterPos[2]); - } - - - - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - tile, NULL); - switch (format) { - case FORMAT_BYTE_RGBA: - glformat = GL_RGBA; - break; - case FORMAT_BYTE_RGB: - glformat = GL_RGB; - break; - - case FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - glformat = GL_ABGR_EXT; - } - break; - - - case FORMAT_BYTE_BGR: - if (ctxProperties->bgr_ext) { /* If its zero, should never come here! */ - glformat = ctxProperties->bgr_ext_enum; - } - break; - - case FORMAT_BYTE_LA: - glformat = GL_LUMINANCE_ALPHA; - break; - case FORMAT_BYTE_GRAY: - case FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; - } - fprintf(stderr, "w_raster = %d, h_raster = %d, glformat = %d\n",w_raster, h_raster, glformat); - glDrawPixels(w_raster, h_raster, glformat, GL_UNSIGNED_BYTE, - byteData); - - (*(table->ReleasePrimitiveArrayCritical))(env, - tile, byteData, 0); - - /* glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);*/ - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - -} -#endif diff --git a/src/native/ogl/build-linux-amd64.xml b/src/native/ogl/build-linux-amd64.xml index 9510591..c4a1e1a 100644 --- a/src/native/ogl/build-linux-amd64.xml +++ b/src/native/ogl/build-linux-amd64.xml @@ -38,12 +38,12 @@ - + - + diff --git a/src/native/ogl/build-linux-i586.xml b/src/native/ogl/build-linux-i586.xml index d47b155..a1d8c9f 100644 --- a/src/native/ogl/build-linux-i586.xml +++ b/src/native/ogl/build-linux-i586.xml @@ -38,12 +38,12 @@ - + - + diff --git a/src/native/ogl/build-linux-ia64.xml b/src/native/ogl/build-linux-ia64.xml index 28c924d..12903b5 100644 --- a/src/native/ogl/build-linux-ia64.xml +++ b/src/native/ogl/build-linux-ia64.xml @@ -35,15 +35,16 @@ - + - + + - + @@ -36,12 +36,12 @@ - + - + diff --git a/src/native/ogl/build-solaris-sparc-forte.xml b/src/native/ogl/build-solaris-sparc-forte.xml index 28f9bf6..7ef8c46 100644 --- a/src/native/ogl/build-solaris-sparc-forte.xml +++ b/src/native/ogl/build-solaris-sparc-forte.xml @@ -30,12 +30,12 @@ - + - + @@ -51,12 +51,12 @@ - + - + diff --git a/src/native/ogl/build-solaris-sparc-gcc.xml b/src/native/ogl/build-solaris-sparc-gcc.xml index d759268..e69ad28 100644 --- a/src/native/ogl/build-solaris-sparc-gcc.xml +++ b/src/native/ogl/build-solaris-sparc-gcc.xml @@ -30,12 +30,12 @@ - + - + @@ -51,12 +51,12 @@ - + - + diff --git a/src/native/ogl/build-solaris-x86-forte.xml b/src/native/ogl/build-solaris-x86-forte.xml index 7a36050..ac56d67 100644 --- a/src/native/ogl/build-solaris-x86-forte.xml +++ b/src/native/ogl/build-solaris-x86-forte.xml @@ -30,12 +30,12 @@ - + - + @@ -58,12 +58,12 @@ - + - + diff --git a/src/native/ogl/build-solaris-x86-gcc.xml b/src/native/ogl/build-solaris-x86-gcc.xml index cfa20ba..7676b5d 100644 --- a/src/native/ogl/build-solaris-x86-gcc.xml +++ b/src/native/ogl/build-solaris-x86-gcc.xml @@ -30,12 +30,12 @@ - + - + @@ -58,12 +58,12 @@ - + - + diff --git a/src/native/ogl/build-windows-amd64-vc.xml b/src/native/ogl/build-windows-amd64-vc.xml new file mode 100644 index 0000000..91d038b --- /dev/null +++ b/src/native/ogl/build-windows-amd64-vc.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/native/ogl/build-windows-i586-gcc.xml b/src/native/ogl/build-windows-i586-gcc.xml index 976bcc1..8307d92 100644 --- a/src/native/ogl/build-windows-i586-gcc.xml +++ b/src/native/ogl/build-windows-i586-gcc.xml @@ -52,12 +52,12 @@ - + - + diff --git a/src/native/ogl/build-windows-i586-vc.xml b/src/native/ogl/build-windows-i586-vc.xml index d1a49ac..8e62417 100644 --- a/src/native/ogl/build-windows-i586-vc.xml +++ b/src/native/ogl/build-windows-i586-vc.xml @@ -55,12 +55,12 @@ - + - + diff --git a/src/native/ogl/gldefs.h b/src/native/ogl/gldefs.h index 7112a79..e278f1d 100644 --- a/src/native/ogl/gldefs.h +++ b/src/native/ogl/gldefs.h @@ -109,7 +109,6 @@ #include "javax_media_j3d_ColoringAttributes.h" #include "javax_media_j3d_ColoringAttributesRetained.h" #include "javax_media_j3d_DepthComponentRetained.h" -#include "javax_media_j3d_DetailTextureImage.h" #include "javax_media_j3d_DirectionalLightRetained.h" #include "javax_media_j3d_DisplayListRenderMethod.h" #include "javax_media_j3d_DrawingSurfaceObjectAWT.h" @@ -129,8 +128,8 @@ #include "javax_media_j3d_Material.h" #include "javax_media_j3d_MaterialRetained.h" #include "javax_media_j3d_ModelClipRetained.h" -#include "javax_media_j3d_NativeAPIInfo.h" #include "javax_media_j3d_NativeConfigTemplate3D.h" +#include "javax_media_j3d_NativePipeline.h" #include "javax_media_j3d_NodeRetained.h" #include "javax_media_j3d_PointAttributesRetained.h" #include "javax_media_j3d_PointLightRetained.h" @@ -162,24 +161,6 @@ #include "javax_media_j3d_ShaderAttributeObjectRetained.h" #include "javax_media_j3d_ShaderError.h" -/* - * Define these constants here as a workaround for conflicting - * glext.h files between Mesa and Solaris - */ - -#ifndef GL_CLAMP_TO_BORDER_SGIS -#define GL_CLAMP_TO_BORDER_SGIS 0x812D -#endif - -#ifndef GL_VIDEO_RESIZE_COMPENSATION_SUN -#define GL_VIDEO_RESIZE_COMPENSATION_SUN 0x85CD -#endif - -/* - * End constant workaround - */ - - /* Used to compare floating point values close to 0.0 */ #define J3D_SMALL_FLOAT 0.00001f @@ -265,13 +246,21 @@ /* now the imagecomponent formats are reduced the ones below */ -#define FORMAT_BYTE_RGBA javax_media_j3d_ImageComponentRetained_BYTE_RGBA -#define FORMAT_BYTE_ABGR javax_media_j3d_ImageComponentRetained_BYTE_ABGR -#define FORMAT_BYTE_GRAY javax_media_j3d_ImageComponentRetained_BYTE_GRAY -#define FORMAT_USHORT_GRAY javax_media_j3d_ImageComponentRetained_USHORT_GRAY -#define FORMAT_BYTE_LA javax_media_j3d_ImageComponentRetained_BYTE_LA -#define FORMAT_BYTE_BGR javax_media_j3d_ImageComponentRetained_BYTE_BGR -#define FORMAT_BYTE_RGB javax_media_j3d_ImageComponentRetained_BYTE_RGB +#define IMAGE_FORMAT_BYTE_BGR javax_media_j3d_ImageComponentRetained_TYPE_BYTE_BGR +#define IMAGE_FORMAT_BYTE_RGB javax_media_j3d_ImageComponentRetained_TYPE_BYTE_RGB +#define IMAGE_FORMAT_BYTE_ABGR javax_media_j3d_ImageComponentRetained_TYPE_BYTE_ABGR +#define IMAGE_FORMAT_BYTE_RGBA javax_media_j3d_ImageComponentRetained_TYPE_BYTE_RGBA +#define IMAGE_FORMAT_BYTE_LA javax_media_j3d_ImageComponentRetained_TYPE_BYTE_LA +#define IMAGE_FORMAT_BYTE_GRAY javax_media_j3d_ImageComponentRetained_TYPE_BYTE_GRAY +#define IMAGE_FORMAT_USHORT_GRAY javax_media_j3d_ImageComponentRetained_TYPE_USHORT_GRAY +#define IMAGE_FORMAT_INT_BGR javax_media_j3d_ImageComponentRetained_TYPE_INT_BGR +#define IMAGE_FORMAT_INT_RGB javax_media_j3d_ImageComponentRetained_TYPE_INT_RGB +#define IMAGE_FORMAT_INT_ARGB javax_media_j3d_ImageComponentRetained_TYPE_INT_ARGB + +#define IMAGE_DATA_TYPE_BYTE_ARRAY javax_media_j3d_ImageComponentRetained_IMAGE_DATA_TYPE_BYTE_ARRAY +#define IMAGE_DATA_TYPE_INT_ARRAY javax_media_j3d_ImageComponentRetained_IMAGE_DATA_TYPE_INT_ARRAY +#define IMAGE_DATA_TYPE_BYTE_BUFFER javax_media_j3d_ImageComponentRetained_IMAGE_DATA_TYPE_BYTE_BUFFER +#define IMAGE_DATA_TYPE_INT_BUFFER javax_media_j3d_ImageComponentRetained_IMAGE_DATA_TYPE_INT_BUFFER /* These match the definitions in GeometryArray.java */ @@ -360,53 +349,7 @@ - #ifndef D3D -#if defined(UNIX) -extern void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); -extern void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, GLclampf); -extern void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -extern void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); -extern void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, GLint *); -extern void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, GLfloat *); -extern void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); -extern void APIENTRY glMultiDrawArraysSUN (GLenum, GLint *, GLsizei *, GLsizei); -extern void APIENTRY glMultiDrawElementsEXT (GLenum, GLsizei *, GLenum, const GLvoid**, GLsizei); -extern void APIENTRY glMultiDrawElementsSUN (GLenum, GLsizei *, GLenum, const GLvoid**, GLsizei); -extern void APIENTRY glLockArraysEXT (GLint first, GLsizei count); -extern void APIENTRY glUnlockArraysEXT (void); - - -extern void APIENTRY glClientActiveTextureARB (GLenum); -extern void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); -extern void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); -extern void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); -extern void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); -extern void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); -extern void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); -extern void APIENTRY glActiveTextureARB (GLenum); -extern void APIENTRY glSharpenTexFuncSGIS(GLenum, GLsizei, const GLfloat *); -extern void APIENTRY glDetailTexFuncSGIS(GLenum, GLsizei, const GLfloat *); -extern void APIENTRY glTexFilterFuncSGIS(GLenum, GLenum, GLsizei, const GLfloat *); -extern void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum); -extern void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean); -extern void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); -extern void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); -extern void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); -extern void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); -extern void APIENTRY glCombinerParameteriNV (GLenum, GLint); - -extern void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); -extern void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); - - - -#ifndef GLX_SUN_video_resize -#define GLX_SUN_video_resize 1 -extern int glXVideoResizeSUN( Display *, GLXDrawable, float); -#endif - -#endif /* UNIX_ */ #ifndef APIENTRY #define APIENTRY @@ -420,18 +363,18 @@ typedef void (APIENTRY * MYPFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green typedef void (APIENTRY * MYPFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); typedef void (APIENTRY * MYPFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); typedef void (APIENTRY * MYPFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); -typedef void (APIENTRY * MYPFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRY * MYPFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); typedef void (APIENTRY * MYPFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); typedef void (APIENTRY * MYPFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum, GLsizei *, GLenum, const GLvoid**, GLsizei); typedef void (APIENTRY * MYPFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); typedef void (APIENTRY * MYPFNGLUNLOCKARRAYSEXTPROC) (void); -typedef void (APIENTRY * MYPFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRY * MYPFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRY * MYPFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); -typedef void (APIENTRY * MYPFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); -typedef void (APIENTRY * MYPFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); -typedef void (APIENTRY * MYPFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRY * MYPFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRY * MYPFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRY * MYPFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRY * MYPFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRY * MYPFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRY * MYPFNGLACTIVETEXTUREPROC) (GLenum texture); typedef void (APIENTRY * MYPFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); typedef void (APIENTRY * MYPFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); @@ -450,7 +393,6 @@ typedef void (APIENTRY * MYPFNGLTEXFILTERFUNCSGI) (GLenum target, GLenum filter, #if defined(UNIX) typedef GLXFBConfig * (APIENTRY * MYPFNGLXCHOOSEFBCONFIG) (Display *dpy, int screen, const int *attrib_list, int *nelements); -typedef int (APIENTRY * MYPFNGLXVIDEORESIZESUN) (Display * dpy, GLXDrawable draw, float factor); #endif /* UNIX_ */ @@ -491,41 +433,15 @@ struct GraphicsContextPropertiesInfoRec { char *rendererStr; char *extensionStr; int versionNumbers[2]; - - /* both in 1.2 core part and 1.1 extensions */ - /* GL_EXT_rescale_normal or GL_RESCALE_NORMAL */ - jboolean rescale_normal_ext; - GLenum rescale_normal_ext_enum; - - /* GL_BGR_EXT or GL_BGR */ - jboolean bgr_ext; - GLenum bgr_ext_enum; - - /* GL_EXT_texture3D or GL_TEXTURE3D */ - jboolean texture3DAvailable; - GLenum texture_3D_ext_enum; - GLenum texture_wrap_r_ext_enum; + jboolean gl13; /* OpenGL 1.3 or greater */ + jboolean gl20; /* OpenGL 2.0 or greater */ /* GL_ARB_imaging subset */ /* GL_EXT_blend_color or GL_BLEND_COLOR */ jboolean blend_color_ext; GLenum blendFunctionTable[MAX_BLEND_FUNC_TABLE_SIZE]; - - /* GL_SGI_color_table or GL_COLOR_TABLE */ - jboolean color_table_ext; - - /* GL_EXT_separate_specular_color */ - jboolean seperate_specular_color; - GLenum light_model_color_control_enum; - GLenum single_color_enum; - GLenum seperate_specular_color_enum; - - /* GL_CLAMP_TO_EDGE or GL_EXT_texture_edge_clamp or - GL_SGIS_texture_edge_clamp */ - GLenum texture_clamp_to_edge_enum; - - /* GL_SGIS_texture_lod */ + /* texture_lod */ jboolean textureLodAvailable; GLenum texture_min_lod_enum; GLenum texture_max_lod_enum; @@ -533,22 +449,17 @@ struct GraphicsContextPropertiesInfoRec { GLenum texture_max_level_enum; - /* ***********1.1 extension or 1.2 extensions ********************/ + /* ***** GL extensions ***** */ - /* GL_ARB_texture_border_clamp or GL_SGIS_texture_border_clamp */ + /* GL_CLAMP_TO_BORDER or GL_CLAMP */ GLenum texture_clamp_to_border_enum; /* GL_SUN_multi_draw_arrays */ jboolean multi_draw_arrays_sun; - /* GLX_SUN_video_resize */ - jboolean videoResizeAvailable; - /* GL_SUN_global_alpha */ jboolean global_alpha_sun; - /* GL_SUNX_constant_data */ - jboolean constant_data_sun; - + /* GL_EXT_abgr */ jboolean abgr_ext; /* GL_EXT_multi_draw_arrays */ @@ -557,11 +468,7 @@ struct GraphicsContextPropertiesInfoRec { /* GL_EXT_compiled_vertex_array */ jboolean compiled_vertex_array_ext; - /* GL_ARB_transpose_matrix */ - jboolean arb_transpose_matrix; - - /* GL_ARB_multitexture */ - jboolean arb_multitexture; + /* Multitexture parameters */ int maxTexCoordSets; /* maximum number of texture coordinate sets */ int maxTextureUnits; /* number of fixed-function texture units */ int maxTextureImageUnits; /* number of fragment shader texture units */ @@ -593,13 +500,8 @@ struct GraphicsContextPropertiesInfoRec { GLenum combine_dot3_rgb_enum; GLenum combine_dot3_rgba_enum; - /* GL_ARB_texture_cube_map */ - /* GL_EXT_texture_cube_map */ - jboolean textureCubeMapAvailable; - GLenum texture_cube_map_ext_enum; - - /* GL_ARB_mulitsample */ - jboolean arb_multisample; + /* GL mulitsample functionality */ + jboolean multisample; /* By default, full scene antialiasing is disable if @@ -647,6 +549,9 @@ struct GraphicsContextPropertiesInfoRec { /* GL_SGIX_texture_lod_bias */ jboolean textureLodBiasAvailable; + /* GL_ARB_texture_non_power_of_two */ + jboolean textureNonPowerOfTwoAvailable; + /* extension mask */ jint extMask; jint textureExtMask; @@ -658,17 +563,17 @@ struct GraphicsContextPropertiesInfoRec { MYPFNGLGETCOLORTABLEPARAMETERIVPROC glGetColorTableParameteriv; MYPFNGLTEXIMAGE3DPROC glTexImage3DEXT; MYPFNGLTEXSUBIMAGE3DPROC glTexSubImage3DEXT; - MYPFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB; - MYPFNGLACTIVETEXTUREARBPROC glActiveTextureARB; + MYPFNGLCLIENTACTIVETEXTUREPROC glClientActiveTexture; + MYPFNGLACTIVETEXTUREPROC glActiveTexture; MYPFNGLMULTIDRAWARRAYSEXTPROC glMultiDrawArraysEXT; MYPFNGLMULTIDRAWELEMENTSEXTPROC glMultiDrawElementsEXT; MYPFNGLLOCKARRAYSEXTPROC glLockArraysEXT; MYPFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT; - MYPFNGLMULTITEXCOORD2FVARBPROC glMultiTexCoord2fvARB; - MYPFNGLMULTITEXCOORD3FVARBPROC glMultiTexCoord3fvARB; - MYPFNGLMULTITEXCOORD4FVARBPROC glMultiTexCoord4fvARB; - MYPFNGLLOADTRANSPOSEMATRIXDARBPROC glLoadTransposeMatrixdARB; - MYPFNGLMULTTRANSPOSEMATRIXDARBPROC glMultTransposeMatrixdARB; + MYPFNGLMULTITEXCOORD2FVPROC glMultiTexCoord2fv; + MYPFNGLMULTITEXCOORD3FVPROC glMultiTexCoord3fv; + MYPFNGLMULTITEXCOORD4FVPROC glMultiTexCoord4fv; + MYPFNGLLOADTRANSPOSEMATRIXDPROC glLoadTransposeMatrixd; + MYPFNGLMULTTRANSPOSEMATRIXDPROC glMultTransposeMatrixd; MYPFNGLGLOBALALPHAFACTORFSUNPROC glGlobalAlphaFactorfSUN; MYPFNGLCOMBINERINPUTNV glCombinerInputNV; @@ -683,10 +588,6 @@ struct GraphicsContextPropertiesInfoRec { MYPFNGLDETAILTEXFUNCSGI glDetailTexFuncSGIS; MYPFNGLTEXFILTERFUNCSGI glTexFilterFuncSGIS; -#if defined(UNIX) - MYPFNGLXVIDEORESIZESUN glXVideoResizeSUN; -#endif /* UNIX_ */ - /* Shading language support */ jboolean shadingLanguageGLSL; jboolean shadingLanguageCg; diff --git a/src/native/share/build-linux-amd64.xml b/src/native/share/build-linux-amd64.xml deleted file mode 100644 index 7380e32..0000000 --- a/src/native/share/build-linux-amd64.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-linux-i586.xml b/src/native/share/build-linux-i586.xml deleted file mode 100644 index 657f2b7..0000000 --- a/src/native/share/build-linux-i586.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-linux-ia64.xml b/src/native/share/build-linux-ia64.xml deleted file mode 100644 index 47e4677..0000000 --- a/src/native/share/build-linux-ia64.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-linux-ppc.xml b/src/native/share/build-linux-ppc.xml deleted file mode 100644 index bd9fa0a..0000000 --- a/src/native/share/build-linux-ppc.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-solaris-sparc-forte.xml b/src/native/share/build-solaris-sparc-forte.xml deleted file mode 100644 index 5bc0cfc..0000000 --- a/src/native/share/build-solaris-sparc-forte.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-solaris-sparc-gcc.xml b/src/native/share/build-solaris-sparc-gcc.xml deleted file mode 100644 index 5f0f790..0000000 --- a/src/native/share/build-solaris-sparc-gcc.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-solaris-x86-forte.xml b/src/native/share/build-solaris-x86-forte.xml deleted file mode 100644 index 44bd2ec..0000000 --- a/src/native/share/build-solaris-x86-forte.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-solaris-x86-gcc.xml b/src/native/share/build-solaris-x86-gcc.xml deleted file mode 100644 index e21142b..0000000 --- a/src/native/share/build-solaris-x86-gcc.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-windows-i586-gcc.xml b/src/native/share/build-windows-i586-gcc.xml deleted file mode 100644 index 2e1fbe5..0000000 --- a/src/native/share/build-windows-i586-gcc.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/native/share/build-windows-i586-vc.xml b/src/native/share/build-windows-i586-vc.xml deleted file mode 100644 index 4f730af..0000000 --- a/src/native/share/build-windows-i586-vc.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3