mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Create the GraphicsWindowSDL2 directly
This commit is contained in:
parent
0498e6e5f0
commit
298b3ed2ef
3 changed files with 3 additions and 113 deletions
|
@ -163,110 +163,4 @@ void GraphicsWindowSDL2::raiseWindow()
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue