forked from teamnwah/openmw-tes3coop
Create the GraphicsWindowSDL2 directly
This commit is contained in:
parent
0498e6e5f0
commit
298b3ed2ef
3 changed files with 3 additions and 113 deletions
|
@ -352,8 +352,6 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||||
|
|
||||||
setWindowIcon();
|
setWindowIcon();
|
||||||
|
|
||||||
SDLUtil::setupWindowingSystemInterface();
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||||
SDL_GetWindowPosition(mWindow, &traits->x, &traits->y);
|
SDL_GetWindowPosition(mWindow, &traits->x, &traits->y);
|
||||||
SDL_GetWindowSize(mWindow, &traits->width, &traits->height);
|
SDL_GetWindowSize(mWindow, &traits->width, &traits->height);
|
||||||
|
@ -371,11 +369,11 @@ void OMW::Engine::createWindow(Settings::Manager& settings)
|
||||||
traits->doubleBuffer = true;
|
traits->doubleBuffer = true;
|
||||||
traits->inheritedWindowData = new SDLUtil::GraphicsWindowSDL2::WindowData(mWindow);
|
traits->inheritedWindowData = new SDLUtil::GraphicsWindowSDL2::WindowData(mWindow);
|
||||||
|
|
||||||
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
osg::ref_ptr<SDLUtil::GraphicsWindowSDL2> graphicsWindow = new SDLUtil::GraphicsWindowSDL2(traits);
|
||||||
if(!gc.valid()) throw std::runtime_error("Failed to create GraphicsContext");
|
if(!graphicsWindow->valid()) throw std::runtime_error("Failed to create GraphicsContext");
|
||||||
|
|
||||||
osg::ref_ptr<osg::Camera> camera = mViewer->getCamera();
|
osg::ref_ptr<osg::Camera> camera = mViewer->getCamera();
|
||||||
camera->setGraphicsContext(gc.get());
|
camera->setGraphicsContext(graphicsWindow);
|
||||||
camera->setViewport(0, 0, width, height);
|
camera->setViewport(0, 0, width, height);
|
||||||
|
|
||||||
mViewer->realize();
|
mViewer->realize();
|
||||||
|
|
|
@ -163,110 +163,4 @@ void GraphicsWindowSDL2::raiseWindow()
|
||||||
SDL_RaiseWindow(mWindow);
|
SDL_RaiseWindow(mWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SDL2WindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SDL2WindowingSystemInterface()
|
|
||||||
{
|
|
||||||
OSG_INFO<< "SDL2WindowingSystemInterface()" <<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~SDL2WindowingSystemInterface()
|
|
||||||
{
|
|
||||||
if(osg::Referenced::getDeleteHandler())
|
|
||||||
{
|
|
||||||
osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0);
|
|
||||||
osg::Referenced::getDeleteHandler()->flushAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
//OSG_NOTICE<< "~SDL2WindowingSystemInterface()" <<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier&/*si*/)
|
|
||||||
{
|
|
||||||
return SDL_GetNumVideoDisplays();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier &si, osg::GraphicsContext::ScreenSettings &resolution)
|
|
||||||
{
|
|
||||||
SDL_DisplayMode mode;
|
|
||||||
if(SDL_GetCurrentDisplayMode(si.screenNum, &mode) == 0)
|
|
||||||
{
|
|
||||||
int bpp = 32;
|
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
|
||||||
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask);
|
|
||||||
|
|
||||||
resolution.width = mode.w;
|
|
||||||
resolution.height = mode.h;
|
|
||||||
resolution.colorDepth = bpp;
|
|
||||||
resolution.refreshRate = mode.refresh_rate;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OSG_NOTICE<< "Unable to query screen \""<<si.screenNum<<"\"." <<std::endl;
|
|
||||||
resolution.width = 0;
|
|
||||||
resolution.height = 0;
|
|
||||||
resolution.colorDepth = 0;
|
|
||||||
resolution.refreshRate = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool setScreenSettings(const osg::GraphicsContext::ScreenIdentifier&/*si*/, const osg::GraphicsContext::ScreenSettings&/*resolution*/)
|
|
||||||
{
|
|
||||||
// FIXME: SDL sets a new video mode by having the fullscreen flag on an
|
|
||||||
// appropriately-sized window, rather than changing it 'raw'.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier &si, osg::GraphicsContext::ScreenSettingsList &resolutionList)
|
|
||||||
{
|
|
||||||
osg::GraphicsContext::ScreenSettingsList().swap(resolutionList);
|
|
||||||
|
|
||||||
int num_modes = SDL_GetNumDisplayModes(si.screenNum);
|
|
||||||
resolutionList.reserve(num_modes);
|
|
||||||
|
|
||||||
for(int i = 0;i < num_modes;++i)
|
|
||||||
{
|
|
||||||
SDL_DisplayMode mode;
|
|
||||||
if(SDL_GetDisplayMode(si.screenNum, i, &mode) != 0)
|
|
||||||
{
|
|
||||||
OSG_NOTICE<< "Failed to get info for display mode "<<i <<std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpp = 32;
|
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
|
||||||
if(SDL_PixelFormatEnumToMasks(mode.format, &bpp, &rmask, &gmask, &bmask, &amask) == SDL_FALSE)
|
|
||||||
{
|
|
||||||
OSG_NOTICE<< "Failed to get pixel format info for format ID "<<mode.format <<std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolutionList.push_back(osg::GraphicsContext::ScreenSettings(mode.w, mode.h, mode.refresh_rate, bpp));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(resolutionList.empty())
|
|
||||||
{
|
|
||||||
OSG_NOTICE<< "SDL2WindowingSystemInterface::enumerateScreenSettings() not supported." <<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual osg::GraphicsContext* createGraphicsContext(osg::GraphicsContext::Traits *traits)
|
|
||||||
{
|
|
||||||
// No PBuffer support (you should use FBOs anyway)
|
|
||||||
if(traits->pbuffer)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
osg::ref_ptr<GraphicsWindowSDL2> window = new GraphicsWindowSDL2(traits);
|
|
||||||
if(window->valid()) return window.release();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setupWindowingSystemInterface()
|
|
||||||
{
|
|
||||||
osg::GraphicsContext::setWindowingSystemInterface(new SDL2WindowingSystemInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,6 @@ public:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
void setupWindowingSystemInterface();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* OSGGRAPHICSWINDOW_H */
|
#endif /* OSGGRAPHICSWINDOW_H */
|
||||||
|
|
Loading…
Reference in a new issue