diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 52f81172d..4ab5bd18d 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -19,6 +19,10 @@ class SG_EXPORT DisplaySettings : public osg::Referenced public: + /** Maintain a DisplaySettings singleton for objects to querry at runtime.*/ + static DisplaySettings* instance(); + + DisplaySettings() { setDefaults(); @@ -36,7 +40,10 @@ class SG_EXPORT DisplaySettings : public osg::Referenced virtual ~DisplaySettings(); + + DisplaySettings& operator = (const DisplaySettings& vs); + void merge(const DisplaySettings& vs); @@ -95,6 +102,11 @@ class SG_EXPORT DisplaySettings : public osg::Referenced const unsigned int getMinimumNumStencilBits() const { return _minimumNumberStencilBits; } const bool getStencilBuffer() const { return _minimumNumberStencilBits!=0; } + + void setMaxNumberOfGraphicsContexts(const int num) { _maxNumOfGraphicsContexts = num; } + const int getMaxNumberOfGraphicsContexts() const { return _maxNumOfGraphicsContexts; } + + protected: void copy(const DisplaySettings& vs); @@ -111,6 +123,7 @@ class SG_EXPORT DisplaySettings : public osg::Referenced unsigned int _minimumNumberAlphaBits; unsigned int _minimumNumberStencilBits; + int _maxNumOfGraphicsContexts; }; diff --git a/include/osg/Texture b/include/osg/Texture index 364f66d3d..d4d4dc727 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -248,13 +248,23 @@ class SG_EXPORT Texture : public StateAttribute inline GLuint& getHandle(const uint contextID) const { // pad out handle list if required. - while (_handleList.size()<=contextID) - _handleList.push_back(0); + if (_handleList.size()<=contextID) + _handleList.resize(contextID,0); // get the globj for the current contextID. return _handleList[contextID]; } + inline uint& getModifiedTag(const uint contextID) const + { + // pad out handle list if required. + if (_modifiedTag.size()<=contextID) + _modifiedTag.resize(contextID,0); + + // get the modified tag for the current contextID. + return _modifiedTag[contextID]; + } + /** Force a recompile on next apply() of associated OpenGL texture objects.*/ void dirtyTextureObject(); diff --git a/include/osg/Transform b/include/osg/Transform index 270fa2fcd..9d896cbb1 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -120,16 +120,16 @@ class SG_EXPORT Transform : public Group /** Set the transform's matrix.*/ - void setMatrix(const Matrix& mat) { (*_matrix) = mat; _inverseDirty=true; dirtyBound(); } + void setMatrix(const Matrix& mat) { (*_matrix) = mat; _inverseDirty=true; computeInverse(); dirtyBound(); } /** Get the transform's matrix. */ inline const Matrix& getMatrix() const { return *_matrix; } /** preMult transform.*/ - void preMult(const Matrix& mat) { _matrix->preMult(mat); _inverseDirty=true; dirtyBound(); } + void preMult(const Matrix& mat) { _matrix->preMult(mat); _inverseDirty=true; computeInverse(); dirtyBound(); } /** postMult transform.*/ - void postMult(const Matrix& mat) { _matrix->postMult(mat); _inverseDirty=true; dirtyBound(); } + void postMult(const Matrix& mat) { _matrix->postMult(mat); _inverseDirty=true; computeInverse(); dirtyBound(); } protected : diff --git a/include/osgDB/Registry b/include/osgDB/Registry index c5567cc5b..1ed528525 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -34,10 +34,10 @@ class OSGDB_EXPORT Registry { public: - ~Registry(); - static Registry* instance(); + ~Registry(); + /** read the command line string list, removing any matched control sequences.*/ void readCommandLine(std::vector& commandLine); diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 37546907e..05854eb1c 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -3,9 +3,28 @@ #include using namespace osg; - using namespace std; +class DisplaySettingsPtr +{ + public: + DisplaySettingsPtr() : _ptr(0L) {} + DisplaySettingsPtr(DisplaySettings* t): _ptr(t) {} + DisplaySettingsPtr(const DisplaySettingsPtr& rp):_ptr(rp._ptr) { } + ~DisplaySettingsPtr() { if (_ptr) delete _ptr; _ptr=0L; } + + inline DisplaySettings* get() { return _ptr; } + + DisplaySettings* _ptr; +}; + +DisplaySettings* DisplaySettings::instance() +{ + static DisplaySettingsPtr s_displaySettings = new DisplaySettings; + return s_displaySettings.get(); +} + + DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced() { copy(vs); @@ -15,7 +34,8 @@ DisplaySettings::~DisplaySettings() { } -DisplaySettings& DisplaySettings::operator = (const DisplaySettings& vs) + + DisplaySettings& DisplaySettings::operator = (const DisplaySettings& vs) { if (this==&vs) return *this; copy(vs); @@ -34,6 +54,8 @@ void DisplaySettings::copy(const DisplaySettings& vs) _depthBuffer = vs._depthBuffer; _minimumNumberAlphaBits = vs._minimumNumberAlphaBits; _minimumNumberStencilBits = vs._minimumNumberStencilBits; + + _maxNumOfGraphicsContexts = vs._maxNumOfGraphicsContexts; } void DisplaySettings::merge(const DisplaySettings& vs) @@ -63,6 +85,12 @@ void DisplaySettings::setDefaults() _depthBuffer = true; _minimumNumberAlphaBits = 0; _minimumNumberStencilBits = 0; + + #ifdef __sgi + _maxNumOfGraphicsContexts = 4; + #else + _maxNumOfGraphicsContexts = 1; + #endif } void DisplaySettings::readEnvironmentalVariables() @@ -118,6 +146,11 @@ void DisplaySettings::readEnvironmentalVariables() { _screenHeight = atof(ptr); } + + if( (ptr = getenv("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS")) != 0) + { + _maxNumOfGraphicsContexts = atof(ptr); + } } void DisplaySettings::readCommandLine(std::vector& commandLine) diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index dcdfdee06..bae04228b 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -15,6 +15,8 @@ Drawable::DeletedDisplayListCache Drawable::s_deletedDisplayListCache; Drawable::Drawable() { + _globjList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _bbox_computed = false; // Note, if your are defining a subclass from drawable which is diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index b1ea15925..ae734a447 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -18,6 +18,9 @@ Texture::DeletedTextureObjectCache Texture::s_deletedTextureObjectCache; Texture::Texture() { + _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _textureUnit = 0; _wrap_s = CLAMP; @@ -189,12 +192,10 @@ void Texture::apply(State& state) const } else if (_image.valid() && _image->data()) { - // pad out the modified tag list, if required. - while (_modifiedTag.size() <= contextID) - _modifiedTag.push_back(0); + uint& modifiedTag = getModifiedTag(contextID); if (_subloadMode == AUTO || - (_subloadMode == IF_DIRTY && _modifiedTag[contextID] != _image->getModifiedTag())) + (_subloadMode == IF_DIRTY && modifiedTag != _image->getModifiedTag())) { glBindTexture( GL_TEXTURE_2D, handle ); glTexSubImage2D(GL_TEXTURE_2D, 0, @@ -203,7 +204,7 @@ void Texture::apply(State& state) const (GLenum) _image->pixelFormat(), (GLenum) _image->dataType(), _image->data()); // update the modified flag to show that the image has been loaded. - _modifiedTag[contextID] = _image->getModifiedTag(); + modifiedTag = _image->getModifiedTag(); } } } @@ -240,12 +241,8 @@ void Texture::applyImmediateMode(State& state) const // current OpenGL context. const uint contextID = state.getContextID(); - // pad out the modified tag list, if required. - while (_modifiedTag.size() <= contextID) - _modifiedTag.push_back(0); - // update the modified tag to show that it is upto date. - _modifiedTag[contextID] = _image->getModifiedTag(); + getModifiedTag(contextID) = _image->getModifiedTag(); if (_subloadMode == OFF) diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index fcd044dac..957f3291b 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -32,6 +32,13 @@ class RegistryPtr Registry* _ptr; }; +Registry* Registry::instance() +{ + static RegistryPtr s_nodeFactory = new Registry; + return s_nodeFactory.get(); +} + + // definition of the Registry Registry::Registry() { @@ -63,11 +70,6 @@ Registry::~Registry() } -Registry* Registry::instance() -{ - static RegistryPtr s_nodeFactory = new Registry; - return s_nodeFactory.get(); -} void Registry::readCommandLine(std::vector& commandLine) {