From dac8706e2e7791c7cff23a9ca6dad2b686804928 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Tue, 25 Sep 2012 22:39:13 +0200 Subject: [PATCH] Move GUI init code to gui module. --- src/GUI/gui.cxx | 84 +++++++++++++++++++++++++++++++++++++++-------- src/GUI/gui.h | 3 +- src/Main/main.cxx | 68 +++----------------------------------- 3 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index f9a169259..2f9192fe4 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -44,6 +44,7 @@ #include
#include
#include +#include #include #include @@ -97,24 +98,81 @@ public: } }; -osg::ref_ptr initOp; -} +// Operation for querying OpenGL parameters. This must be done in a +// valid OpenGL context, potentially in another thread. -void guiStartInit(osg::GraphicsContext* gc) +struct GeneralInitOperation : public GraphicsContextOperation { - if (gc) { - initOp = new GUIInitOperation; - gc->add(initOp.get()); + GeneralInitOperation() + : GraphicsContextOperation(std::string("General init")) + { } + void run(osg::GraphicsContext* gc) + { + SGPropertyNode* simRendering = fgGetNode("/sim/rendering"); + + simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR)); + SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR)); + + simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER)); + SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER)); + + simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION)); + SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION)); + + simRendering->setStringValue("gl-shading-language-version", (char*) glGetString(GL_SHADING_LANGUAGE_VERSION)); + SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_SHADING_LANGUAGE_VERSION)); + + GLint tmp; + glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp ); + simRendering->setIntValue("max-texture-size", tmp); + + glGetIntegerv( GL_DEPTH_BITS, &tmp ); + simRendering->setIntValue("depth-buffer-bits", tmp); + } +}; + +osg::ref_ptr initOp; + } -bool guiFinishInit() +/** Initializes GUI. + * Returns true when done, false when still busy (call again). */ +bool guiInit() { - if (!initOp.valid()) + static osg::ref_ptr genOp; + + if (!genOp.valid()) + { + // Pick some window on which to do queries. + // XXX Perhaps all this graphics initialization code should be + // moved to renderer.cxx? + genOp = new GeneralInitOperation; + osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault()); + WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA(); + osg::GraphicsContext* gc = 0; + if (guiCamera) + gc = guiCamera->getGraphicsContext(); + if (gc) { + gc->add(genOp.get()); + initOp = new GUIInitOperation; + gc->add(initOp.get()); + } else { + wsa->windows[0]->gc->add(genOp.get()); + } + return false; // not ready yet + } + else + { + if (!genOp->isFinished()) + return false; + if (!initOp.valid()) + return true; + if (!initOp->isFinished()) + return false; + genOp = 0; + initOp = 0; + // we're done return true; - if (!initOp->isFinished()) - return false; - initOp = 0; - return true; + } } - diff --git a/src/GUI/gui.h b/src/GUI/gui.h index cc523f756..c191c15d9 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -40,8 +40,7 @@ namespace osg class GraphicsContext; } // gui.cxx -extern void guiStartInit(osg::GraphicsContext*); -extern bool guiFinishInit(); +extern bool guiInit(); extern bool openBrowser(const std::string& address); extern void mkDialog(const char *txt); extern void guiErrorMessage(const char *txt); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 686585560..689e33aa6 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -55,8 +55,6 @@ #include #include