Skip to content

Commit

Permalink
From Wang Rui, "I've finally completed the static build support for d…
Browse files Browse the repository at this point in the history
…otosg wrapper and

serialization libraries. My submission mainly includes:
1. Add two new macros USE_DOTOSGWRAPPER_LIBRARY and
USE_SERIALIZER_WRAPPER_LIBRARY. Applications using static OSG must
include corresponding static-link libraries and use these two macros
to predefine native format wrappers. Please see osgstaticviewer and
present3D in the attachment for details.

2. Add a LibraryWrapper.cpp file in each
osgWrappers/deprecated-dotosg/... and osgWrappers/serializers/...
subfolder, which calls all USE_...WRAPPERS macros inside. The
LibraryWrapper file is automatically generated by the
wrapper_includer.cpp (with some slight fixes), which is also attached
for your reference. The deprecated-dotosg/osgAnimation is not included
because it doesn't us REGISTER_DOTOSGWRAPPER to define its wrappers.

3. Modify the ReaderWriterOSG.cpp to prevent calling loadWrappers()
when static build.

4. An uncorrelated fix to Serializer and ObjectWrapper.cpp, which
ensures version variables of serialziers are initialized, and
serializers out-of-version are not written to model files.
"
  • Loading branch information
robertosfield committed Nov 11, 2010
1 parent a27e048 commit ea7eaac
Show file tree
Hide file tree
Showing 29 changed files with 724 additions and 8 deletions.
13 changes: 13 additions & 0 deletions applications/present3D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ IF (NOT DYNAMIC_OPENSCENEGRAPH)
osgdb_openflight
osgdb_obj
)

SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_deprecated_osg osgdb_deprecated_osgparticle osgdb_deprecated_osganimation
osgdb_deprecated_osgfx osgdb_deprecated_osgsim osgdb_deprecated_osgtext
osgdb_deprecated_osgviewer osgdb_deprecated_osgshadow osgdb_deprecated_osgterrain
osgdb_deprecated_osgvolume osgdb_deprecated_osgwidget
)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_serializers_osg osgdb_serializers_osgparticle osgdb_serializers_osgtext
osgdb_serializers_osgterrain osgdb_serializers_osganimation osgdb_serializers_osgfx
osgdb_serializers_osgshadow osgdb_serializers_osgmanipulator osgdb_serializers_osgsim
osgdb_serializers_osgvolume
)

IF(JPEG_FOUND)
ADD_DEFINITIONS(-DUSE_JPEG)
Expand Down
23 changes: 23 additions & 0 deletions applications/present3D/present3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
// include the plugins we need
USE_OSGPLUGIN(ive)
USE_OSGPLUGIN(osg)
USE_OSGPLUGIN(osg2)
USE_OSGPLUGIN(p3d)
USE_OSGPLUGIN(paths)
USE_OSGPLUGIN(rgb)
Expand Down Expand Up @@ -91,6 +92,28 @@
USE_OSGPLUGIN(curl)
#endif

USE_DOTOSGWRAPPER_LIBRARY(osg)
USE_DOTOSGWRAPPER_LIBRARY(osgFX)
USE_DOTOSGWRAPPER_LIBRARY(osgParticle)
USE_DOTOSGWRAPPER_LIBRARY(osgShadow)
USE_DOTOSGWRAPPER_LIBRARY(osgSim)
USE_DOTOSGWRAPPER_LIBRARY(osgTerrain)
USE_DOTOSGWRAPPER_LIBRARY(osgText)
USE_DOTOSGWRAPPER_LIBRARY(osgViewer)
USE_DOTOSGWRAPPER_LIBRARY(osgVolume)
USE_DOTOSGWRAPPER_LIBRARY(osgWidget)

USE_SERIALIZER_WRAPPER_LIBRARY(osg)
USE_SERIALIZER_WRAPPER_LIBRARY(osgAnimation)
USE_SERIALIZER_WRAPPER_LIBRARY(osgFX)
USE_SERIALIZER_WRAPPER_LIBRARY(osgManipulator)
USE_SERIALIZER_WRAPPER_LIBRARY(osgParticle)
USE_SERIALIZER_WRAPPER_LIBRARY(osgShadow)
USE_SERIALIZER_WRAPPER_LIBRARY(osgSim)
USE_SERIALIZER_WRAPPER_LIBRARY(osgTerrain)
USE_SERIALIZER_WRAPPER_LIBRARY(osgText)
USE_SERIALIZER_WRAPPER_LIBRARY(osgVolume)

// include the platform specific GraphicsWindow implementation.
USE_GRAPHICSWINDOW()

Expand Down
19 changes: 18 additions & 1 deletion examples/osgstaticviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#this file is automatically generated

SET(TARGET_ADDED_LIBRARIES osgdb_ive osgdb_freetype osgdb_openflight osgdb_osg osgdb_rgb)
SET(TARGET_ADDED_LIBRARIES osgdb_ive osgdb_openflight osgdb_osg osgdb_rgb)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_deprecated_osg osgdb_deprecated_osgparticle osgdb_deprecated_osganimation
osgdb_deprecated_osgfx osgdb_deprecated_osgsim osgdb_deprecated_osgtext
osgdb_deprecated_osgviewer osgdb_deprecated_osgshadow osgdb_deprecated_osgterrain
osgdb_deprecated_osgvolume osgdb_deprecated_osgwidget
)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_serializers_osg osgdb_serializers_osgparticle osgdb_serializers_osgtext
osgdb_serializers_osgterrain osgdb_serializers_osganimation osgdb_serializers_osgfx
osgdb_serializers_osgshadow osgdb_serializers_osgmanipulator osgdb_serializers_osgsim
osgdb_serializers_osgvolume
)

IF(FREETYPE_FOUND)
ADD_DEFINITIONS(-DUSE_FREETYPE)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES} osgdb_freetype)
ENDIF(FREETYPE_FOUND)

SET(TARGET_SRC osgstaticviewer.cpp )
#### end var setup ###
Expand Down
28 changes: 27 additions & 1 deletion examples/osgstaticviewer/osgstaticviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,37 @@

// include the plugins we need
USE_OSGPLUGIN(ive)
USE_OSGPLUGIN(freetype)
USE_OSGPLUGIN(osg)
USE_OSGPLUGIN(osg2)
USE_OSGPLUGIN(rgb)
USE_OSGPLUGIN(OpenFlight)

#ifdef USE_FREETYPE
USE_OSGPLUGIN(freetype)
#endif

USE_DOTOSGWRAPPER_LIBRARY(osg)
USE_DOTOSGWRAPPER_LIBRARY(osgFX)
USE_DOTOSGWRAPPER_LIBRARY(osgParticle)
USE_DOTOSGWRAPPER_LIBRARY(osgShadow)
USE_DOTOSGWRAPPER_LIBRARY(osgSim)
USE_DOTOSGWRAPPER_LIBRARY(osgTerrain)
USE_DOTOSGWRAPPER_LIBRARY(osgText)
USE_DOTOSGWRAPPER_LIBRARY(osgViewer)
USE_DOTOSGWRAPPER_LIBRARY(osgVolume)
USE_DOTOSGWRAPPER_LIBRARY(osgWidget)

USE_SERIALIZER_WRAPPER_LIBRARY(osg)
USE_SERIALIZER_WRAPPER_LIBRARY(osgAnimation)
USE_SERIALIZER_WRAPPER_LIBRARY(osgFX)
USE_SERIALIZER_WRAPPER_LIBRARY(osgManipulator)
USE_SERIALIZER_WRAPPER_LIBRARY(osgParticle)
USE_SERIALIZER_WRAPPER_LIBRARY(osgShadow)
USE_SERIALIZER_WRAPPER_LIBRARY(osgSim)
USE_SERIALIZER_WRAPPER_LIBRARY(osgTerrain)
USE_SERIALIZER_WRAPPER_LIBRARY(osgText)
USE_SERIALIZER_WRAPPER_LIBRARY(osgVolume)

// include the platform specific GraphicsWindow implementation.
USE_GRAPHICSWINDOW()

Expand Down
8 changes: 8 additions & 0 deletions include/osgDB/Registry
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,18 @@ struct PluginFunctionProxy
extern "C" void dotosgwrapper_##classname(void); \
static osgDB::PluginFunctionProxy proxy_dotosgwrapper_##classname(dotosgwrapper_##classname);

#define USE_DOTOSGWRAPPER_LIBRARY(libname) \
extern "C" void dotosgwrapper_library_##libname(void); \
static osgDB::PluginFunctionProxy proxy_dotosgwrapper_library_##libname(dotosgwrapper_library_##libname);

#define USE_SERIALIZER_WRAPPER(classname) \
extern "C" void wrapper_serializer_##classname(void); \
static osgDB::PluginFunctionProxy proxy_serializer_##classname(wrapper_serializer_##classname);

#define USE_SERIALIZER_WRAPPER_LIBRARY(libname) \
extern "C" void wrapper_serializer_library_##libname(void); \
static osgDB::PluginFunctionProxy proxy_serializer_library_##libname(wrapper_serializer_library_##libname);

#define USE_COMPRESSOR_WRAPPER(classname) \
extern "C" void wrapper_serializer_##classname(void); \
static osgDB::PluginFunctionProxy proxy_compressor_##classname(wrapper_compressor_##classname);
Expand Down
4 changes: 2 additions & 2 deletions include/osgDB/Serializer
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public:
typedef bool (*Writer)( OutputStream&, const C& );

UserSerializer( const char* name, Checker cf, Reader rf, Writer wf )
: _name(name), _checker(cf), _reader(rf), _writer(wf) {}
: BaseSerializer(), _name(name), _checker(cf), _reader(rf), _writer(wf) {}

virtual bool read( InputStream& is, osg::Object& obj )
{
Expand Down Expand Up @@ -198,7 +198,7 @@ class TemplateSerializer : public BaseSerializer
{
public:
TemplateSerializer( const char* name )
: _name(name) {}
: BaseSerializer(), _name(name) {}

virtual bool read( InputStream& is, osg::Object& obj ) = 0;
virtual bool write( OutputStream& os, const osg::Object& obj ) = 0;
Expand Down
20 changes: 16 additions & 4 deletions src/osgDB/ObjectWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
// Written by Wang Rui, (C) 2010

#include <osg/Version>
#include <osg/Notify>
#include <osg/BlendFunc>
#include <osg/ClampColor>
Expand Down Expand Up @@ -178,10 +179,21 @@ bool ObjectWrapper::write( OutputStream& os, const osg::Object& obj )
for ( SerializerList::iterator itr=_serializers.begin();
itr!=_serializers.end(); ++itr )
{
if ( (*itr)->write(os, obj) ) continue;
OSG_WARN << "ObjectWrapper::write(): Error writing property "
<< _name << "::" << (*itr)->getName() << std::endl;
writeOK = false;
BaseSerializer* serializer = itr->get();
if ( serializer->_firstVersion <= OPENSCENEGRAPH_SOVERSION &&
OPENSCENEGRAPH_SOVERSION <= serializer->_lastVersion)
{
if ( !serializer->write(os, obj) )
{
OSG_WARN << "ObjectWrapper::write(): Error writing property "
<< _name << "::" << (*itr)->getName() << std::endl;
writeOK = false;
}
}
else
{
// OSG_NOTICE<<"Ignoring serializer due to version mismatch"<<std::endl;
}
}
return writeOK;
}
Expand Down
4 changes: 4 additions & 0 deletions src/osgPlugins/osg/ReaderWriterOSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class OSGReaderWriter : public ReaderWriter

bool loadWrappers() const
{
#ifndef OSG_LIBRARY_STATIC
if (_wrappersLoaded) return true;

OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
Expand All @@ -146,6 +147,9 @@ class OSGReaderWriter : public ReaderWriter
_wrappersLoaded = true;
return false;
}
#else
return true;
#endif
}

virtual ReadResult readObject(const std::string& file, const Options* opt) const
Expand Down
98 changes: 98 additions & 0 deletions src/osgWrappers/deprecated-dotosg/osg/LibraryWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <osgDB/Registry>

USE_DOTOSGWRAPPER(AlphaFunc)
USE_DOTOSGWRAPPER(AnimationPath)
USE_DOTOSGWRAPPER(AnimationPathCallback_Proxy)
USE_DOTOSGWRAPPER(AutoTransform)
USE_DOTOSGWRAPPER(Billboard)
USE_DOTOSGWRAPPER(BlendColor)
USE_DOTOSGWRAPPER(BlendEquation)
USE_DOTOSGWRAPPER(Transparency)
USE_DOTOSGWRAPPER(BlendFunc)
USE_DOTOSGWRAPPER(Box)
USE_DOTOSGWRAPPER(Camera)
USE_DOTOSGWRAPPER(CameraNode)
USE_DOTOSGWRAPPER(CameraView)
USE_DOTOSGWRAPPER(Capsule)
USE_DOTOSGWRAPPER(EarthSky)
USE_DOTOSGWRAPPER(ClearNode)
USE_DOTOSGWRAPPER(ClipNode)
USE_DOTOSGWRAPPER(ClipPlane)
USE_DOTOSGWRAPPER(ClusterCullingCallback)
USE_DOTOSGWRAPPER(ColorMask)
USE_DOTOSGWRAPPER(ColorMatrix)
USE_DOTOSGWRAPPER(CompositeShape)
USE_DOTOSGWRAPPER(Cone)
USE_DOTOSGWRAPPER(ConvexPlanarOccluder)
USE_DOTOSGWRAPPER(CoordinateSystemNode)
USE_DOTOSGWRAPPER(CullFace)
USE_DOTOSGWRAPPER(Cylinder)
USE_DOTOSGWRAPPER(Depth)
USE_DOTOSGWRAPPER(Drawable)
USE_DOTOSGWRAPPER(EllipsoidModel)
USE_DOTOSGWRAPPER(Fog)
USE_DOTOSGWRAPPER(FragmentProgram)
USE_DOTOSGWRAPPER(FrontFace)
USE_DOTOSGWRAPPER(Geode)
USE_DOTOSGWRAPPER(Geometry)
USE_DOTOSGWRAPPER(Group)
USE_DOTOSGWRAPPER(HeightField)
USE_DOTOSGWRAPPER(Grid)
USE_DOTOSGWRAPPER(Image)
USE_DOTOSGWRAPPER(ImageSequence)
USE_DOTOSGWRAPPER(Light)
USE_DOTOSGWRAPPER(LightModel)
USE_DOTOSGWRAPPER(LightSource)
USE_DOTOSGWRAPPER(LineStipple)
USE_DOTOSGWRAPPER(LineWidth)
USE_DOTOSGWRAPPER(LOD)
USE_DOTOSGWRAPPER(Material)
USE_DOTOSGWRAPPER(MatrixTransform)
USE_DOTOSGWRAPPER(DCS)
USE_DOTOSGWRAPPER(Node)
USE_DOTOSGWRAPPER(NodeCallback)
USE_DOTOSGWRAPPER(Object)
USE_DOTOSGWRAPPER(OccluderNode)
USE_DOTOSGWRAPPER(OcclusionQueryNode)
USE_DOTOSGWRAPPER(PagedLOD)
USE_DOTOSGWRAPPER(Point)
USE_DOTOSGWRAPPER(PointSprite)
USE_DOTOSGWRAPPER(PolygonMode)
USE_DOTOSGWRAPPER(PolygonOffset)
USE_DOTOSGWRAPPER(PositionAttitudeTransform)
USE_DOTOSGWRAPPER(Program)
USE_DOTOSGWRAPPER(Projection)
USE_DOTOSGWRAPPER(ProxyNode)
USE_DOTOSGWRAPPER(Scissor)
USE_DOTOSGWRAPPER(Sequence)
USE_DOTOSGWRAPPER(ShadeModel)
USE_DOTOSGWRAPPER(Shader)
USE_DOTOSGWRAPPER(ShapeDrawable)
USE_DOTOSGWRAPPER(Sphere)
USE_DOTOSGWRAPPER(StateAttribute)
USE_DOTOSGWRAPPER(StateSet)
USE_DOTOSGWRAPPER(GeoState)
USE_DOTOSGWRAPPER(Stencil)
USE_DOTOSGWRAPPER(Switch)
USE_DOTOSGWRAPPER(TessellationHints)
USE_DOTOSGWRAPPER(TexEnv)
USE_DOTOSGWRAPPER(TexEnvCombine)
USE_DOTOSGWRAPPER(TexEnvFilter)
USE_DOTOSGWRAPPER(TexGen)
USE_DOTOSGWRAPPER(TexGenNode)
USE_DOTOSGWRAPPER(TexMat)
USE_DOTOSGWRAPPER(Texture)
USE_DOTOSGWRAPPER(Texture1D)
USE_DOTOSGWRAPPER(OldTexture)
USE_DOTOSGWRAPPER(Texture2D)
USE_DOTOSGWRAPPER(Texture3D)
USE_DOTOSGWRAPPER(TextureCubeMap)
USE_DOTOSGWRAPPER(TextureRectangle)
USE_DOTOSGWRAPPER(TransferFunction1D_Proxy)
USE_DOTOSGWRAPPER(Transform)
USE_DOTOSGWRAPPER(Uniform)
USE_DOTOSGWRAPPER(VertexProgram)
USE_DOTOSGWRAPPER(Viewport)

extern "C" void dotosgwrapper_library_osg(void) {}

13 changes: 13 additions & 0 deletions src/osgWrappers/deprecated-dotosg/osgFX/LibraryWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <osgDB/Registry>

USE_DOTOSGWRAPPER(AnisotropicLighting_Proxy)
USE_DOTOSGWRAPPER(BumpMapping_Proxy)
USE_DOTOSGWRAPPER(Cartoon_Proxy)
USE_DOTOSGWRAPPER(Effect_Proxy)
USE_DOTOSGWRAPPER(MultiTextureControl_Proxy)
USE_DOTOSGWRAPPER(Outline_Proxy)
USE_DOTOSGWRAPPER(Scribe_Proxy)
USE_DOTOSGWRAPPER(SpecularHighlights_Proxy)

extern "C" void dotosgwrapper_library_osgFX(void) {}

42 changes: 42 additions & 0 deletions src/osgWrappers/deprecated-dotosg/osgParticle/LibraryWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <osgDB/Registry>

USE_DOTOSGWRAPPER(AccelOperator_Proxy)
USE_DOTOSGWRAPPER(AngularAccelOperator_Proxy)
USE_DOTOSGWRAPPER(AngularDampingOperator_Proxy)
USE_DOTOSGWRAPPER(BounceOperator_Proxy)
USE_DOTOSGWRAPPER(BoxPlacer_Proxy)
USE_DOTOSGWRAPPER(CenteredPlacer_Proxy)
USE_DOTOSGWRAPPER(ConnectedParticleSystem_Proxy)
USE_DOTOSGWRAPPER(ConstantRateCounter_Proxy)
USE_DOTOSGWRAPPER(DampingOperator_Proxy)
USE_DOTOSGWRAPPER(DomainOperator_Proxy)
USE_DOTOSGWRAPPER(Emitter_Proxy)
USE_DOTOSGWRAPPER(ExplosionDebrisEffect_Proxy)
USE_DOTOSGWRAPPER(ExplosionEffect_Proxy)
USE_DOTOSGWRAPPER(ExplosionOperator_Proxy)
USE_DOTOSGWRAPPER(FireEffect_Proxy)
USE_DOTOSGWRAPPER(FluidFrictionOperator_Proxy)
USE_DOTOSGWRAPPER(FluidProgram_Proxy)
USE_DOTOSGWRAPPER(ForceOperator_Proxy)
USE_DOTOSGWRAPPER(LinearInterpolator_Proxy)
USE_DOTOSGWRAPPER(ModularEmitter_Proxy)
USE_DOTOSGWRAPPER(ModularProgram_Proxy)
USE_DOTOSGWRAPPER(MultiSegmentPlacer_Proxy)
USE_DOTOSGWRAPPER(OrbitOperator_Proxy)
USE_DOTOSGWRAPPER(ParticleEffect_Proxy)
USE_DOTOSGWRAPPER(ParticleProcessor_Proxy)
USE_DOTOSGWRAPPER(ParticleSystem_Proxy)
USE_DOTOSGWRAPPER(PSU_Proxy)
USE_DOTOSGWRAPPER(PointPlacer_Proxy)
USE_DOTOSGWRAPPER(g_IOProgramProxy)
USE_DOTOSGWRAPPER(RadialShooter_Proxy)
USE_DOTOSGWRAPPER(RandomRateCounter_Proxy)
USE_DOTOSGWRAPPER(SectorPlacer_Proxy)
USE_DOTOSGWRAPPER(SegmentPlacer_Proxy)
USE_DOTOSGWRAPPER(SinkOperator_Proxy)
USE_DOTOSGWRAPPER(SmokeEffect_Proxy)
USE_DOTOSGWRAPPER(SmokeTrailEffect_Proxy)
USE_DOTOSGWRAPPER(VariableRateCounter_Proxy)

extern "C" void dotosgwrapper_library_osgParticle(void) {}

10 changes: 10 additions & 0 deletions src/osgWrappers/deprecated-dotosg/osgShadow/LibraryWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <osgDB/Registry>

USE_DOTOSGWRAPPER(ShadowedScene_Proxy)
USE_DOTOSGWRAPPER(ShadowMap_Proxy)
USE_DOTOSGWRAPPER(ShadowTechnique_Proxy)
USE_DOTOSGWRAPPER(ShadowTexture_Proxy)
USE_DOTOSGWRAPPER(ShadowVolume_Proxy)

extern "C" void dotosgwrapper_library_osgShadow(void) {}

20 changes: 20 additions & 0 deletions src/osgWrappers/deprecated-dotosg/osgSim/LibraryWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <osgDB/Registry>

USE_DOTOSGWRAPPER(BlinkSequence_Proxy)
USE_DOTOSGWRAPPER(BlinkSequence_SequenceGroup_Proxy)
USE_DOTOSGWRAPPER(g_DOFTransformProxy)
USE_DOTOSGWRAPPER(g_ImpostorProxy)
USE_DOTOSGWRAPPER(LightPointNode_Proxy)
USE_DOTOSGWRAPPER(g_simSwitchProxy)
USE_DOTOSGWRAPPER(ObjectRecordData_Proxy)
USE_DOTOSGWRAPPER(g_OverlayNodeProxy)
USE_DOTOSGWRAPPER(AzimSector_Proxy)
USE_DOTOSGWRAPPER(ElevationSector_Proxy)
USE_DOTOSGWRAPPER(AzimElevationSector_Proxy)
USE_DOTOSGWRAPPER(ConeSector_Proxy)
USE_DOTOSGWRAPPER(DirectionalSector_Proxy)
USE_DOTOSGWRAPPER(ShapeAttributeList_Proxy)
USE_DOTOSGWRAPPER(g_VisibilityGroupProxy)

extern "C" void dotosgwrapper_library_osgSim(void) {}

Loading

0 comments on commit ea7eaac

Please sign in to comment.