Added DisplaySetting::s/getCompileContextHint() and use of this hint in osgViewer::Viewer/CompositeViewer.

Removed the CustomViewer in osgterrain example as the above now removes the need for it.
This commit is contained in:
Robert Osfield 2007-08-11 14:49:14 +00:00
parent 4cd437d7d4
commit d57a16e023
8 changed files with 93 additions and 65 deletions

View File

@ -74,12 +74,6 @@ int main(int argc, char** argv)
return 1; return 1;
} }
bool createBackgroundContextForCompiling = false;
while (arguments.read("--bc")) { createBackgroundContextForCompiling = true; }
bool createBackgroundThreadsForCompiling = false;
while (arguments.read("--bt")) { createBackgroundContextForCompiling = true; createBackgroundThreadsForCompiling = true; }
// set up the camera manipulators. // set up the camera manipulators.
{ {
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
@ -151,27 +145,6 @@ int main(int argc, char** argv)
viewer.realize(); viewer.realize();
if (createBackgroundContextForCompiling)
{
int numProcessors = OpenThreads::GetNumberOfProcessors();
int processNum = 0;
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
{
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
if (gc && createBackgroundThreadsForCompiling)
{
gc->createGraphicsThread();
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
gc->getGraphicsThread()->startThread();
++processNum;
}
}
}
viewer.run(); viewer.run();
} }

View File

@ -574,47 +574,12 @@ protected:
osg::observer_ptr<osgTerrain::Layer> _layer; osg::observer_ptr<osgTerrain::Layer> _layer;
}; };
class CustomViewer : public osgViewer::Viewer
{
public:
CustomViewer(osg::ArgumentParser& arguments):
Viewer(arguments) {}
// override the realize to create the compile graphics contexts + threads for us.
virtual void realize()
{
Viewer::realize();
int numProcessors = OpenThreads::GetNumberOfProcessors();
int processNum = (getThreadingModel()==osgViewer::Viewer::SingleThreaded) ? 1 : 0;
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
{
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
if (gc)
{
gc->createGraphicsThread();
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
gc->getGraphicsThread()->startThread();
++processNum;
}
}
}
protected:
};
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
osg::ArgumentParser arguments(&argc, argv); osg::ArgumentParser arguments(&argc, argv);
// construct the viewer. // construct the viewer.
CustomViewer viewer(arguments); osgViewer::Viewer viewer(arguments);
// set up the camera manipulators. // set up the camera manipulators.
{ {
@ -935,6 +900,9 @@ int main(int argc, char** argv)
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
// enable the use of compile contexts and associated threads.
osg::DisplaySettings::instance()->setCompileContextsHint(true);
// realize the graphics windows. // realize the graphics windows.
viewer.realize(); viewer.realize();

View File

@ -175,6 +175,9 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
unsigned int getNumMultiSamples() const { return _numMultiSamples; } unsigned int getNumMultiSamples() const { return _numMultiSamples; }
bool getMultiSamples() const { return _numMultiSamples!=0; } bool getMultiSamples() const { return _numMultiSamples!=0; }
void setCompileContextsHint(bool useCompileContexts) { _compileContextsHint = useCompileContexts; }
bool getCompileContextsHint() const { return _compileContextsHint; }
protected: protected:
virtual ~DisplaySettings(); virtual ~DisplaySettings();
@ -208,6 +211,8 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
unsigned int _numMultiSamples; unsigned int _numMultiSamples;
bool _compileContextsHint;
}; };
} }

View File

@ -70,6 +70,8 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
_maxNumOfGraphicsContexts = vs._maxNumOfGraphicsContexts; _maxNumOfGraphicsContexts = vs._maxNumOfGraphicsContexts;
_numMultiSamples = vs._numMultiSamples; _numMultiSamples = vs._numMultiSamples;
_compileContextsHint = vs._compileContextsHint;
} }
void DisplaySettings::merge(const DisplaySettings& vs) void DisplaySettings::merge(const DisplaySettings& vs)
@ -85,6 +87,9 @@ void DisplaySettings::merge(const DisplaySettings& vs)
if (vs._minimumNumberAlphaBits>_minimumNumberAlphaBits) _minimumNumberAlphaBits = vs._minimumNumberAlphaBits; if (vs._minimumNumberAlphaBits>_minimumNumberAlphaBits) _minimumNumberAlphaBits = vs._minimumNumberAlphaBits;
if (vs._minimumNumberStencilBits>_minimumNumberStencilBits) _minimumNumberStencilBits = vs._minimumNumberStencilBits; if (vs._minimumNumberStencilBits>_minimumNumberStencilBits) _minimumNumberStencilBits = vs._minimumNumberStencilBits;
if (vs._numMultiSamples>_numMultiSamples) _numMultiSamples = vs._numMultiSamples; if (vs._numMultiSamples>_numMultiSamples) _numMultiSamples = vs._numMultiSamples;
if (vs._compileContextsHint) _compileContextsHint = vs._compileContextsHint;
} }
void DisplaySettings::setDefaults() void DisplaySettings::setDefaults()
@ -123,6 +128,8 @@ void DisplaySettings::setDefaults()
// switch on anti-aliasing by default, just in case we have an Onyx :-) // switch on anti-aliasing by default, just in case we have an Onyx :-)
_numMultiSamples = 4; _numMultiSamples = 4;
#endif #endif
_compileContextsHint = false;
} }
void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num) void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num)
@ -157,7 +164,7 @@ static ApplicationUsageProxy DisplaySetting_e9(ApplicationUsage::ENVIRONMENTAL_V
static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>","OFF | ON Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo. Note, if you are setting fovx and fovy explicityly OFF should be used."); static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>","OFF | ON Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo. Note, if you are setting fovx and fovy explicityly OFF should be used.");
static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports"); static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports");
static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications."); static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications.");
static ApplicationUsageProxy DisplaySetting_e13(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_COMPIlE_CONTEXTS <mode>","OFF | ON Enable/disable the use a backgrouind compile contexts and threads.");
void DisplaySettings::readEnvironmentalVariables() void DisplaySettings::readEnvironmentalVariables()
{ {
const char* ptr = 0; const char* ptr = 0;
@ -308,6 +315,19 @@ void DisplaySettings::readEnvironmentalVariables()
{ {
_maxNumOfGraphicsContexts = atoi(ptr); _maxNumOfGraphicsContexts = atoi(ptr);
} }
if( (ptr = getenv("OSG_COMPIlE_CONTEXTS")) != 0)
{
if (strcmp(ptr,"OFF")==0)
{
_compileContextsHint = false;
}
else
if (strcmp(ptr,"ON")==0)
{
_compileContextsHint = true;
}
}
} }
void DisplaySettings::readCommandLine(ArgumentParser& arguments) void DisplaySettings::readCommandLine(ArgumentParser& arguments)
@ -324,6 +344,7 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments)
arguments.getApplicationUsage()->addCommandLineOption("--accum-rgb","Request a rgb accumulator buffer visual"); arguments.getApplicationUsage()->addCommandLineOption("--accum-rgb","Request a rgb accumulator buffer visual");
arguments.getApplicationUsage()->addCommandLineOption("--accum-rgba","Request a rgb accumulator buffer visual"); arguments.getApplicationUsage()->addCommandLineOption("--accum-rgba","Request a rgb accumulator buffer visual");
arguments.getApplicationUsage()->addCommandLineOption("--samples <num>","Request a multisample visual"); arguments.getApplicationUsage()->addCommandLineOption("--samples <num>","Request a multisample visual");
arguments.getApplicationUsage()->addCommandLineOption("--cc","Request use of compile contexts and threads");
} }
std::string str; std::string str;
@ -376,4 +397,10 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments)
{ {
_numMultiSamples = atoi(str.c_str()); _numMultiSamples = atoi(str.c_str());
} }
while(arguments.read("--cc"))
{
_compileContextsHint = true;
}
} }

View File

@ -160,7 +160,7 @@ Registry::Registry()
} }
addFileExtensionAlias("shadow", "osgShadow"); addFileExtensionAlias("shadow", "osgShadow");
addFileExtensionAlias("terrain", "osgTerrain");
addFileExtensionAlias("view", "osgViewer"); addFileExtensionAlias("view", "osgViewer");
addFileExtensionAlias("sgi", "rgb"); addFileExtensionAlias("sgi", "rgb");

View File

@ -597,6 +597,27 @@ void CompositeViewer::realize()
// pass on the start tick to all the associated eventqueues // pass on the start tick to all the associated eventqueues
setStartTick(osg::Timer::instance()->getStartTick()); setStartTick(osg::Timer::instance()->getStartTick());
if (osg::DisplaySettings::instance()->getCompileContextsHint())
{
int numProcessors = OpenThreads::GetNumberOfProcessors();
int processNum = 0;
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
{
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
if (gc)
{
gc->createGraphicsThread();
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
gc->getGraphicsThread()->startThread();
++processNum;
}
}
}
} }

View File

@ -935,6 +935,27 @@ void Viewer::realize()
setStartTick(osg::Timer::instance()->getStartTick()); setStartTick(osg::Timer::instance()->getStartTick());
setUpThreading(); setUpThreading();
if (osg::DisplaySettings::instance()->getCompileContextsHint())
{
int numProcessors = OpenThreads::GetNumberOfProcessors();
int processNum = 0;
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
{
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
if (gc)
{
gc->createGraphicsThread();
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
gc->getGraphicsThread()->startThread();
++processNum;
}
}
}
} }

View File

@ -329,6 +329,16 @@ BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings)
__bool__getMultiSamples, __bool__getMultiSamples,
"", "",
""); "");
I_Method1(void, setCompileContextsHint, IN, bool, useCompileContexts,
Properties::NON_VIRTUAL,
__void__setCompileContextsHint__bool,
"",
"");
I_Method0(bool, getCompileContextsHint,
Properties::NON_VIRTUAL,
__bool__getCompileContextsHint,
"",
"");
I_StaticMethod0(osg::DisplaySettings *, instance, I_StaticMethod0(osg::DisplaySettings *, instance,
__DisplaySettings_P1__instance_S, __DisplaySettings_P1__instance_S,
"Maintain a DisplaySettings singleton for objects to query at runtime. ", "Maintain a DisplaySettings singleton for objects to query at runtime. ",
@ -339,6 +349,9 @@ BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings)
I_SimpleProperty(bool, AlphaBuffer, I_SimpleProperty(bool, AlphaBuffer,
__bool__getAlphaBuffer, __bool__getAlphaBuffer,
0); 0);
I_SimpleProperty(bool, CompileContextsHint,
__bool__getCompileContextsHint,
__void__setCompileContextsHint__bool);
I_SimpleProperty(bool, DepthBuffer, I_SimpleProperty(bool, DepthBuffer,
__bool__getDepthBuffer, __bool__getDepthBuffer,
__void__setDepthBuffer__bool); __void__setDepthBuffer__bool);