Added support for setting the maximum number of graphics contexts that the

OSG has to maintian.
This commit is contained in:
Robert Osfield
2002-02-28 00:11:31 +00:00
parent 384b23ea62
commit 2973ca0a25
8 changed files with 81 additions and 24 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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)
{