Added support for setting the maximum number of graphics contexts that the
OSG has to maintian.
This commit is contained in:
parent
384b23ea62
commit
2973ca0a25
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 :
|
||||
|
@ -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<std::string>& commandLine);
|
||||
|
@ -3,9 +3,28 @@
|
||||
#include <algorithm>
|
||||
|
||||
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<std::string>& commandLine)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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<std::string>& commandLine)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user