From 552293eb033393649c64febece10e52896c31035 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Jan 2007 21:11:57 +0000 Subject: [PATCH] Added extra methods WindowSystemInterface for controlling frame rate and resolution, and adde useCursor flag. --- genwrapper.conf | 1 + include/osg/GraphicsContext | 8 ++++++++ src/osgViewer/CompositeViewer.cpp | 4 ++++ src/osgViewer/GraphicsWindowX11.cpp | 5 ++++- src/osgViewer/SimpleViewer.cpp | 4 ++++ src/osgViewer/Viewer.cpp | 8 ++++++-- src/osgWrappers/osg/GraphicsContext.cpp | 9 +++++++++ 7 files changed, 36 insertions(+), 3 deletions(-) diff --git a/genwrapper.conf b/genwrapper.conf index ef32ebc29..0cfeecff6 100644 --- a/genwrapper.conf +++ b/genwrapper.conf @@ -49,6 +49,7 @@ suppress reflector "osg::CullStack" ignore file "osgViewer/GraphicsWindowX11" ignore file "osgViewer/GraphicsWindowWin32" ignore file "osgViewer/GraphicsWindowCocoa" +ignore file "osgViewer/GraphicsWindowCarbon" ############################################################################# diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index c18354ad4..c1968a1a7 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -75,6 +75,7 @@ class OSG_EXPORT GraphicsContext : public Referenced face(0), mipMapGeneration(false), vsync(true), + useCursor(true), sharedContext(0) {} // graphics context orginal and size @@ -114,6 +115,9 @@ class OSG_EXPORT GraphicsContext : public Referenced // V-sync bool vsync; + // enable cursor + bool useCursor; + // shared context GraphicsContext* sharedContext; }; @@ -125,7 +129,11 @@ class OSG_EXPORT GraphicsContext : public Referenced virtual unsigned int getNumScreens(const ScreenIdentifier& screenIdentifier = ScreenIdentifier()) = 0; virtual void getScreenResolution(const ScreenIdentifier& screenIdentifier, unsigned int& width, unsigned int& height) = 0; + + virtual bool setScreenResolution(const ScreenIdentifier& /*screenIdentifier*/, unsigned int /*width*/, unsigned int /*height*/) { return false; } + virtual bool setScreenRefreshRate(const ScreenIdentifier& /*screenIdentifier*/, double /*refreshRate*/) { return false; } + virtual GraphicsContext* createGraphicsContext(Traits* traits) = 0; virtual ~WindowingSystemInterface() {}; diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 975c1a4cd..ae50e4990 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -573,6 +573,8 @@ void CompositeViewer::setUpRenderingSupport() sceneView->setSceneData(view->getSceneData()); sceneView->setFrameStamp(frameStamp); + if (dp) dp->setCompileGLObjectsForContextID(view->getCamera()->getGraphicsContext()->getState()->getContextID(), true); + view->getCamera()->getGraphicsContext()->add(new CompositeViewerRenderingOperation(sceneView, dp)); } @@ -592,6 +594,8 @@ void CompositeViewer::setUpRenderingSupport() sceneView->setSceneData(view->getSceneData()); sceneView->setFrameStamp(frameStamp); + if (dp) dp->setCompileGLObjectsForContextID(slave._camera->getGraphicsContext()->getState()->getContextID(), true); + slave._camera->getGraphicsContext()->add(new CompositeViewerRenderingOperation(sceneView, dp)); } } diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index d9b5e40fa..e42cc28d3 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -358,6 +358,9 @@ void GraphicsWindowX11::useCursor(bool cursorOn) XFlush(_display); XSync(_display,0); } + + _traits->useCursor = cursorOn; + } void GraphicsWindowX11::init() @@ -488,7 +491,7 @@ void GraphicsWindowX11::init() _nullCursor = XCreatePixmapCursor( _display, pixmap, pixmap, &ncol, &ncol, 0, 0 ); } - useCursor(true); + useCursor(_traits->useCursor); XSelectInput( _display, _window, ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | diff --git a/src/osgViewer/SimpleViewer.cpp b/src/osgViewer/SimpleViewer.cpp index bd52d3278..4bd6fa554 100644 --- a/src/osgViewer/SimpleViewer.cpp +++ b/src/osgViewer/SimpleViewer.cpp @@ -29,12 +29,15 @@ SimpleViewer::SimpleViewer(): _eventVisitor = new osgGA::EventVisitor; setDatabasePager(new osgDB::DatabasePager); + + _databasePager->setCompileGLObjectsForContextID(_sceneView->getState()->getContextID(), true); } SimpleViewer::~SimpleViewer() { _sceneView->releaseAllGLObjects(); osg::GraphicsContext::decrementContextIDUsageCount(_sceneView->getState()->getContextID()); + _databasePager->setCompileGLObjectsForContextID(_sceneView->getState()->getContextID(), false); } void SimpleViewer::setSceneData(osg::Node* node) @@ -53,6 +56,7 @@ void SimpleViewer::setSceneData(osg::Node* node) { // register any PagedLOD that need to be tracked in the scene graph _databasePager->registerPagedLODs(node); + } } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index aa8a07b81..1d8a6cbca 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -463,12 +463,12 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation _sceneView->cull(); _sceneView->draw(); + double availableTime = 0.004; // 4 ms if (_databasePager.valid()) { - double availableTime = 0.004; // 4 ms _databasePager->compileGLObjects(*(_sceneView->getState()), availableTime); - _sceneView->flushDeletedGLObjects(availableTime); } + _sceneView->flushDeletedGLObjects(availableTime); } osg::observer_ptr _sceneView; @@ -508,6 +508,8 @@ void Viewer::setUpRenderingSupport() sceneView->setState(_camera->getGraphicsContext()->getState()); sceneView->setSceneData(getSceneData()); sceneView->setFrameStamp(frameStamp); + + if (dp) dp->setCompileGLObjectsForContextID(_camera->getGraphicsContext()->getState()->getContextID(), true); _camera->getGraphicsContext()->add(new ViewerRenderingOperation(sceneView, dp)); } @@ -528,6 +530,8 @@ void Viewer::setUpRenderingSupport() sceneView->setSceneData(getSceneData()); sceneView->setFrameStamp(frameStamp); + if (dp) dp->setCompileGLObjectsForContextID(slave._camera->getGraphicsContext()->getState()->getContextID(), true); + slave._camera->getGraphicsContext()->add(new ViewerRenderingOperation(sceneView, dp)); } } diff --git a/src/osgWrappers/osg/GraphicsContext.cpp b/src/osgWrappers/osg/GraphicsContext.cpp index 8c4aae0ae..81b2aa7c3 100644 --- a/src/osgWrappers/osg/GraphicsContext.cpp +++ b/src/osgWrappers/osg/GraphicsContext.cpp @@ -309,6 +309,7 @@ BEGIN_OBJECT_REFLECTOR(osg::GraphicsContext::Traits) I_PublicMemberProperty(unsigned int, face); I_PublicMemberProperty(unsigned int, mipMapGeneration); I_PublicMemberProperty(bool, vsync); + I_PublicMemberProperty(bool, useCursor); I_PublicMemberProperty(osg::GraphicsContext *, sharedContext); END_REFLECTOR @@ -325,6 +326,14 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext::WindowingSystemInterface) __void__getScreenResolution__C5_ScreenIdentifier_R1__unsigned_int_R1__unsigned_int_R1, "", ""); + I_Method3(bool, setScreenResolution, IN, const osg::GraphicsContext::ScreenIdentifier &, x, IN, unsigned, int, IN, unsigned, int, + __bool__setScreenResolution__C5_ScreenIdentifier_R1__unsigned__unsigned, + "", + ""); + I_Method2(bool, setScreenRefreshRate, IN, const osg::GraphicsContext::ScreenIdentifier &, x, IN, double, x, + __bool__setScreenRefreshRate__C5_ScreenIdentifier_R1__double, + "", + ""); I_Method1(osg::GraphicsContext *, createGraphicsContext, IN, osg::GraphicsContext::Traits *, traits, __GraphicsContext_P1__createGraphicsContext__Traits_P1, "",