source: OGRE/trunk/ogrenew/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp @ 657

Revision 657, 4.2 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

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