[692] | 1 | #include "OgreException.h"
|
---|
| 2 | #include "OgreLogManager.h"
|
---|
| 3 | #include "OgreStringConverter.h"
|
---|
| 4 |
|
---|
| 5 | #include "OgreSDLGLSupport.h"
|
---|
| 6 |
|
---|
| 7 | #include "OgreSDLWindow.h"
|
---|
| 8 |
|
---|
| 9 | using namespace Ogre;
|
---|
| 10 |
|
---|
| 11 | SDLGLSupport::SDLGLSupport()
|
---|
| 12 | {
|
---|
| 13 |
|
---|
| 14 | SDL_Init(SDL_INIT_VIDEO);
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | SDLGLSupport::~SDLGLSupport()
|
---|
| 18 | {
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | void SDLGLSupport::addConfig(void)
|
---|
| 22 | {
|
---|
| 23 | mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
|
---|
| 24 |
|
---|
| 25 | if (mVideoModes == (SDL_Rect **)0)
|
---|
| 26 | {
|
---|
| 27 | OGRE_EXCEPT(999, "Unable to load video modes",
|
---|
| 28 | "SDLRenderSystem::initConfigOptions");
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | ConfigOption optFullScreen;
|
---|
| 32 | ConfigOption optVideoMode;
|
---|
| 33 | ConfigOption optFSAA;
|
---|
| 34 | ConfigOption optRTTMode;
|
---|
| 35 |
|
---|
| 36 | // FS setting possiblities
|
---|
| 37 | optFullScreen.name = "Full Screen";
|
---|
| 38 | optFullScreen.possibleValues.push_back("Yes");
|
---|
| 39 | optFullScreen.possibleValues.push_back("No");
|
---|
| 40 | optFullScreen.currentValue = "Yes";
|
---|
| 41 | optFullScreen.immutable = false;
|
---|
| 42 |
|
---|
| 43 | // Video mode possiblities
|
---|
| 44 | optVideoMode.name = "Video Mode";
|
---|
| 45 | optVideoMode.immutable = false;
|
---|
| 46 | for (size_t i = 0; mVideoModes[i]; i++)
|
---|
| 47 | {
|
---|
| 48 | char szBuf[16];
|
---|
| 49 | snprintf(szBuf, 16, "%d x %d", mVideoModes[i]->w, mVideoModes[i]->h);
|
---|
| 50 | optVideoMode.possibleValues.push_back(szBuf);
|
---|
| 51 | // Make the first one default
|
---|
| 52 | if (i == 0)
|
---|
| 53 | {
|
---|
| 54 | optVideoMode.currentValue = szBuf;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | //FSAA possibilities
|
---|
| 59 | optFSAA.name = "FSAA";
|
---|
| 60 | optFSAA.possibleValues.push_back("0");
|
---|
| 61 | optFSAA.possibleValues.push_back("2");
|
---|
| 62 | optFSAA.possibleValues.push_back("4");
|
---|
| 63 | optFSAA.possibleValues.push_back("6");
|
---|
| 64 | optFSAA.currentValue = "0";
|
---|
| 65 | optFSAA.immutable = false;
|
---|
| 66 |
|
---|
| 67 | optRTTMode.name = "RTT Preferred Mode";
|
---|
| 68 | optRTTMode.possibleValues.push_back("FBO");
|
---|
| 69 | optRTTMode.possibleValues.push_back("PBuffer");
|
---|
| 70 | optRTTMode.possibleValues.push_back("Copy");
|
---|
| 71 | optRTTMode.currentValue = "FBO";
|
---|
| 72 | optRTTMode.immutable = false;
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | mOptions[optFullScreen.name] = optFullScreen;
|
---|
| 76 | mOptions[optVideoMode.name] = optVideoMode;
|
---|
| 77 | mOptions[optFSAA.name] = optFSAA;
|
---|
| 78 | mOptions[optRTTMode.name] = optRTTMode;
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | String SDLGLSupport::validateConfig(void)
|
---|
| 83 | {
|
---|
| 84 | return String("");
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
|
---|
| 88 | {
|
---|
| 89 | if (autoCreateWindow)
|
---|
| 90 | {
|
---|
| 91 | ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
|
---|
| 92 | if (opt == mOptions.end())
|
---|
| 93 | OGRE_EXCEPT(999, "Can't find full screen options!", "SDLGLSupport::createWindow");
|
---|
| 94 | bool fullscreen = (opt->second.currentValue == "Yes");
|
---|
| 95 |
|
---|
| 96 | opt = mOptions.find("Video Mode");
|
---|
| 97 | if (opt == mOptions.end())
|
---|
| 98 | OGRE_EXCEPT(999, "Can't find video mode options!", "SDLGLSupport::createWindow");
|
---|
| 99 | String val = opt->second.currentValue;
|
---|
| 100 | String::size_type pos = val.find('x');
|
---|
| 101 | if (pos == String::npos)
|
---|
| 102 | OGRE_EXCEPT(999, "Invalid Video Mode provided", "SDLGLSupport::createWindow");
|
---|
| 103 |
|
---|
| 104 | // Parse FSAA config
|
---|
| 105 | NameValuePairList winOptions;
|
---|
| 106 | winOptions["title"] = windowTitle;
|
---|
| 107 | int fsaa_x_samples = 0;
|
---|
| 108 | opt = mOptions.find("FSAA");
|
---|
| 109 | if(opt != mOptions.end())
|
---|
| 110 | {
|
---|
| 111 | winOptions["FSAA"] = opt->second.currentValue;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
|
---|
| 115 | unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
|
---|
| 116 |
|
---|
| 117 | const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
|
---|
| 118 | return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions);
|
---|
| 119 | }
|
---|
| 120 | else
|
---|
| 121 | {
|
---|
| 122 | // XXX What is the else?
|
---|
| 123 | return NULL;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | RenderWindow* SDLGLSupport::newWindow(const String &name, unsigned int width, unsigned int height,
|
---|
| 130 | bool fullScreen, const NameValuePairList *miscParams)
|
---|
| 131 | {
|
---|
| 132 | SDLWindow* window = new SDLWindow();
|
---|
| 133 | window->create(name, width, height, fullScreen, miscParams);
|
---|
| 134 | return window;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void SDLGLSupport::start()
|
---|
| 138 | {
|
---|
| 139 | LogManager::getSingleton().logMessage(
|
---|
| 140 | "******************************\n"
|
---|
| 141 | "*** Starting SDL Subsystem ***\n"
|
---|
| 142 | "******************************");
|
---|
| 143 |
|
---|
| 144 | SDL_Init(SDL_INIT_VIDEO);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | void SDLGLSupport::stop()
|
---|
| 148 | {
|
---|
| 149 | LogManager::getSingleton().logMessage(
|
---|
| 150 | "******************************\n"
|
---|
| 151 | "*** Stopping SDL Subsystem ***\n"
|
---|
| 152 | "******************************");
|
---|
| 153 |
|
---|
| 154 | SDL_Quit();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void* SDLGLSupport::getProcAddress(const String& procname)
|
---|
| 158 | {
|
---|
| 159 | return SDL_GL_GetProcAddress(procname.c_str());
|
---|
| 160 | }
|
---|