1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include "OgreException.h"
|
---|
27 | #include "OgreLogManager.h"
|
---|
28 | #include "OgreStringConverter.h"
|
---|
29 | #include "OgreRoot.h"
|
---|
30 |
|
---|
31 | #include "OgreGLXGLSupport.h"
|
---|
32 |
|
---|
33 | #include "OgreGLXWindow.h"
|
---|
34 | #include "OgreGLTexture.h"
|
---|
35 |
|
---|
36 | #include "OgreGLXRenderTexture.h"
|
---|
37 |
|
---|
38 | namespace Ogre {
|
---|
39 |
|
---|
40 | GLXGLSupport::GLXGLSupport():
|
---|
41 | mDisplay(0) {}
|
---|
42 |
|
---|
43 | GLXGLSupport::~GLXGLSupport() {}
|
---|
44 |
|
---|
45 | void GLXGLSupport::addConfig(void) {
|
---|
46 | ConfigOption optFullScreen;
|
---|
47 | ConfigOption optVideoMode;
|
---|
48 | ConfigOption optBitDepth;
|
---|
49 | ConfigOption optFSAA;
|
---|
50 | ConfigOption optRTTMode;
|
---|
51 |
|
---|
52 | // FS setting possiblities
|
---|
53 | optFullScreen.name = "Full Screen";
|
---|
54 | optFullScreen.possibleValues.push_back("Yes");
|
---|
55 | optFullScreen.possibleValues.push_back("No");
|
---|
56 | optFullScreen.currentValue = "Yes";
|
---|
57 | optFullScreen.immutable = false;
|
---|
58 |
|
---|
59 | // Video mode possiblities
|
---|
60 | optVideoMode.name = "Video Mode";
|
---|
61 | optVideoMode.immutable = false;
|
---|
62 |
|
---|
63 | // We could query Xrandr here, but that wouldn't work in the non-fullscreen case
|
---|
64 | // or when that extension is disabled. Anyway, this list of modes is fairly
|
---|
65 | // complete.
|
---|
66 | optVideoMode.possibleValues.push_back("640 x 480");
|
---|
67 | optVideoMode.possibleValues.push_back("800 x 600");
|
---|
68 | optVideoMode.possibleValues.push_back("1024 x 768");
|
---|
69 | optVideoMode.possibleValues.push_back("1280 x 960");
|
---|
70 | optVideoMode.possibleValues.push_back("1280 x 1024");
|
---|
71 | optVideoMode.possibleValues.push_back("1600 x 1200");
|
---|
72 |
|
---|
73 | optVideoMode.currentValue = "800 x 600";
|
---|
74 |
|
---|
75 | //FSAA possibilities
|
---|
76 | optFSAA.name = "FSAA";
|
---|
77 | optFSAA.possibleValues.push_back("0");
|
---|
78 | optFSAA.possibleValues.push_back("2");
|
---|
79 | optFSAA.possibleValues.push_back("4");
|
---|
80 | optFSAA.possibleValues.push_back("6");
|
---|
81 | optFSAA.currentValue = "0";
|
---|
82 | optFSAA.immutable = false;
|
---|
83 |
|
---|
84 | optRTTMode.name = "RTT Preferred Mode";
|
---|
85 | optRTTMode.possibleValues.push_back("FBO");
|
---|
86 | optRTTMode.possibleValues.push_back("PBuffer");
|
---|
87 | optRTTMode.possibleValues.push_back("Copy");
|
---|
88 | optRTTMode.currentValue = "FBO";
|
---|
89 | optRTTMode.immutable = false;
|
---|
90 |
|
---|
91 |
|
---|
92 | mOptions[optFullScreen.name] = optFullScreen;
|
---|
93 | mOptions[optVideoMode.name] = optVideoMode;
|
---|
94 | mOptions[optFSAA.name] = optFSAA;
|
---|
95 | mOptions[optRTTMode.name] = optRTTMode;
|
---|
96 | }
|
---|
97 |
|
---|
98 | String GLXGLSupport::validateConfig(void) {
|
---|
99 | return String("");
|
---|
100 | }
|
---|
101 |
|
---|
102 | RenderWindow* GLXGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
|
---|
103 | {
|
---|
104 | if (autoCreateWindow) {
|
---|
105 | ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
|
---|
106 | if (opt == mOptions.end())
|
---|
107 | OGRE_EXCEPT(999, "Can't find full screen options!", "GLXGLSupport::createWindow");
|
---|
108 | bool fullscreen = (opt->second.currentValue == "Yes");
|
---|
109 |
|
---|
110 | opt = mOptions.find("Video Mode");
|
---|
111 | if (opt == mOptions.end())
|
---|
112 | OGRE_EXCEPT(999, "Can't find video mode options!", "GLXGLSupport::createWindow");
|
---|
113 | String val = opt->second.currentValue;
|
---|
114 | String::size_type pos = val.find('x');
|
---|
115 | if (pos == String::npos)
|
---|
116 | OGRE_EXCEPT(999, "Invalid Video Mode provided", "GLXGLSupport::createWindow");
|
---|
117 |
|
---|
118 | unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
|
---|
119 | unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
|
---|
120 |
|
---|
121 | // Parse FSAA config
|
---|
122 | NameValuePairList winOptions;
|
---|
123 | winOptions["title"] = windowTitle;
|
---|
124 | int fsaa_x_samples = 0;
|
---|
125 | opt = mOptions.find("FSAA");
|
---|
126 | if(opt != mOptions.end())
|
---|
127 | {
|
---|
128 | winOptions["FSAA"] = opt->second.currentValue;
|
---|
129 | }
|
---|
130 |
|
---|
131 | return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions);
|
---|
132 | } else {
|
---|
133 | // XXX What is the else?
|
---|
134 | return NULL;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | RenderWindow* GLXGLSupport::newWindow(const String &name, unsigned int width, unsigned int height,
|
---|
139 | bool fullScreen, const NameValuePairList *miscParams)
|
---|
140 | {
|
---|
141 | GLXWindow* window = new GLXWindow(mDisplay);
|
---|
142 | window->create(name, width, height, fullScreen, miscParams);
|
---|
143 | return window;
|
---|
144 | }
|
---|
145 |
|
---|
146 | void GLXGLSupport::start() {
|
---|
147 | LogManager::getSingleton().logMessage(
|
---|
148 | "******************************\n"
|
---|
149 | "*** Starting GLX Subsystem ***\n"
|
---|
150 | "******************************");
|
---|
151 | mDisplay = XOpenDisplay(NULL);
|
---|
152 | if(!mDisplay) {
|
---|
153 | OGRE_EXCEPT(999, "Couldn`t open X display", "GLXGLSupport::start");
|
---|
154 | }
|
---|
155 |
|
---|
156 | }
|
---|
157 |
|
---|
158 | void GLXGLSupport::stop() {
|
---|
159 | LogManager::getSingleton().logMessage(
|
---|
160 | "******************************\n"
|
---|
161 | "*** Stopping GLX Subsystem ***\n"
|
---|
162 | "******************************");
|
---|
163 | if(mDisplay)
|
---|
164 | XCloseDisplay(mDisplay);
|
---|
165 | mDisplay = 0;
|
---|
166 | }
|
---|
167 |
|
---|
168 | extern "C" {
|
---|
169 | extern void (*glXGetProcAddressARB(const GLubyte *procName))( void );
|
---|
170 | };
|
---|
171 |
|
---|
172 | void* GLXGLSupport::getProcAddress(const String& procname) {
|
---|
173 | return (void*)glXGetProcAddressARB((const GLubyte*)procname.c_str());
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | bool GLXGLSupport::supportsPBuffers()
|
---|
178 | {
|
---|
179 | return true;
|
---|
180 | }
|
---|
181 | GLPBuffer *GLXGLSupport::createPBuffer(PixelComponentType format, size_t width, size_t height)
|
---|
182 | {
|
---|
183 | return new GLXPBuffer(format, width, height);
|
---|
184 | }
|
---|
185 |
|
---|
186 | }
|
---|