| 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-2006 Torus Knot Software Ltd | 
|---|
| 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 | You may alternatively use this source under the terms of a specific version of | 
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from | 
|---|
| 26 | Torus Knot Software Ltd. | 
|---|
| 27 | ----------------------------------------------------------------------------- | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | #include "OgreException.h" | 
|---|
| 31 | #include "OgreLogManager.h" | 
|---|
| 32 | #include "OgreStringConverter.h" | 
|---|
| 33 | #include "OgreRoot.h" | 
|---|
| 34 |  | 
|---|
| 35 | #include "OgreGLXGLSupport.h" | 
|---|
| 36 |  | 
|---|
| 37 | #include "OgreGLXWindow.h" | 
|---|
| 38 | #include "OgreGLTexture.h" | 
|---|
| 39 |  | 
|---|
| 40 | #include "OgreGLXRenderTexture.h" | 
|---|
| 41 |  | 
|---|
| 42 | namespace Ogre { | 
|---|
| 43 |  | 
|---|
| 44 | GLXGLSupport::GLXGLSupport(): | 
|---|
| 45 | mDisplay(0) {} | 
|---|
| 46 |  | 
|---|
| 47 | GLXGLSupport::~GLXGLSupport() {} | 
|---|
| 48 |  | 
|---|
| 49 | void GLXGLSupport::addConfig(void) { | 
|---|
| 50 |         ConfigOption optFullScreen; | 
|---|
| 51 |         ConfigOption optVideoMode; | 
|---|
| 52 |         ConfigOption optBitDepth; | 
|---|
| 53 |     ConfigOption optFSAA; | 
|---|
| 54 |         ConfigOption optRTTMode; | 
|---|
| 55 |  | 
|---|
| 56 |         // FS setting possiblities | 
|---|
| 57 |         optFullScreen.name = "Full Screen"; | 
|---|
| 58 |         optFullScreen.possibleValues.push_back("Yes"); | 
|---|
| 59 |         optFullScreen.possibleValues.push_back("No"); | 
|---|
| 60 |         optFullScreen.currentValue = "Yes"; | 
|---|
| 61 |         optFullScreen.immutable = false; | 
|---|
| 62 |  | 
|---|
| 63 |         // Video mode possiblities | 
|---|
| 64 |         optVideoMode.name = "Video Mode"; | 
|---|
| 65 |         optVideoMode.immutable = false; | 
|---|
| 66 |  | 
|---|
| 67 |         // We could query Xrandr here, but that wouldn't work in the non-fullscreen case | 
|---|
| 68 |         // or when that extension is disabled. Anyway, this list of modes is fairly | 
|---|
| 69 |         // complete. | 
|---|
| 70 |         optVideoMode.possibleValues.push_back("640 x 480"); | 
|---|
| 71 |         optVideoMode.possibleValues.push_back("800 x 600"); | 
|---|
| 72 |         optVideoMode.possibleValues.push_back("1024 x 768"); | 
|---|
| 73 |         optVideoMode.possibleValues.push_back("1280 x 960"); | 
|---|
| 74 |         optVideoMode.possibleValues.push_back("1280 x 1024"); | 
|---|
| 75 |         optVideoMode.possibleValues.push_back("1600 x 1200"); | 
|---|
| 76 |  | 
|---|
| 77 |         optVideoMode.currentValue = "800 x 600"; | 
|---|
| 78 |  | 
|---|
| 79 |     //FSAA possibilities | 
|---|
| 80 |     optFSAA.name = "FSAA"; | 
|---|
| 81 |     optFSAA.possibleValues.push_back("0"); | 
|---|
| 82 |     optFSAA.possibleValues.push_back("2"); | 
|---|
| 83 |     optFSAA.possibleValues.push_back("4"); | 
|---|
| 84 |     optFSAA.possibleValues.push_back("6"); | 
|---|
| 85 |     optFSAA.currentValue = "0"; | 
|---|
| 86 |     optFSAA.immutable = false; | 
|---|
| 87 |  | 
|---|
| 88 |         optRTTMode.name = "RTT Preferred Mode"; | 
|---|
| 89 |         optRTTMode.possibleValues.push_back("FBO"); | 
|---|
| 90 |         optRTTMode.possibleValues.push_back("PBuffer"); | 
|---|
| 91 |         optRTTMode.possibleValues.push_back("Copy"); | 
|---|
| 92 |         optRTTMode.currentValue = "FBO"; | 
|---|
| 93 |         optRTTMode.immutable = false; | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 |         mOptions[optFullScreen.name] = optFullScreen; | 
|---|
| 97 |         mOptions[optVideoMode.name] = optVideoMode; | 
|---|
| 98 |     mOptions[optFSAA.name] = optFSAA; | 
|---|
| 99 |         mOptions[optRTTMode.name] = optRTTMode; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | String GLXGLSupport::validateConfig(void) { | 
|---|
| 103 |         return String(""); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | RenderWindow* GLXGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)  | 
|---|
| 107 | { | 
|---|
| 108 |         if (autoCreateWindow) { | 
|---|
| 109 |                 ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); | 
|---|
| 110 |                 if (opt == mOptions.end()) | 
|---|
| 111 |                         OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find full screen options!", "GLXGLSupport::createWindow"); | 
|---|
| 112 |                 bool fullscreen = (opt->second.currentValue == "Yes"); | 
|---|
| 113 |  | 
|---|
| 114 |                 opt = mOptions.find("Video Mode"); | 
|---|
| 115 |                 if (opt == mOptions.end()) | 
|---|
| 116 |                         OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find video mode options!", "GLXGLSupport::createWindow"); | 
|---|
| 117 |                 String val = opt->second.currentValue; | 
|---|
| 118 |                 String::size_type pos = val.find('x'); | 
|---|
| 119 |                 if (pos == String::npos) | 
|---|
| 120 |                         OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid Video Mode provided", "GLXGLSupport::createWindow"); | 
|---|
| 121 |  | 
|---|
| 122 |                 unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); | 
|---|
| 123 |                 unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); | 
|---|
| 124 |  | 
|---|
| 125 |         // Parse FSAA config | 
|---|
| 126 |                 NameValuePairList winOptions; | 
|---|
| 127 |                 winOptions["title"] = windowTitle; | 
|---|
| 128 |         int fsaa_x_samples = 0; | 
|---|
| 129 |         opt = mOptions.find("FSAA"); | 
|---|
| 130 |         if(opt != mOptions.end()) | 
|---|
| 131 |         { | 
|---|
| 132 |                         winOptions["FSAA"] = opt->second.currentValue; | 
|---|
| 133 |         } | 
|---|
| 134 |  | 
|---|
| 135 |                 return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions); | 
|---|
| 136 |         } else { | 
|---|
| 137 |                 // XXX What is the else? | 
|---|
| 138 |                 return NULL; | 
|---|
| 139 |         } | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | RenderWindow* GLXGLSupport::newWindow(const String &name, unsigned int width, unsigned int height,  | 
|---|
| 143 |         bool fullScreen, const NameValuePairList *miscParams) | 
|---|
| 144 | { | 
|---|
| 145 |         GLXWindow* window = new GLXWindow(mDisplay); | 
|---|
| 146 |         window->create(name, width, height, fullScreen, miscParams); | 
|---|
| 147 |         return window; | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | void GLXGLSupport::start() { | 
|---|
| 151 |         LogManager::getSingleton().logMessage( | 
|---|
| 152 |                 "******************************\n" | 
|---|
| 153 |                 "*** Starting GLX Subsystem ***\n" | 
|---|
| 154 |                 "******************************"); | 
|---|
| 155 |         mDisplay = XOpenDisplay(NULL); | 
|---|
| 156 |         if(!mDisplay) { | 
|---|
| 157 |                 OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Couldn`t open X display", "GLXGLSupport::start"); | 
|---|
| 158 |         } | 
|---|
| 159 |  | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 | void GLXGLSupport::stop() { | 
|---|
| 163 |         LogManager::getSingleton().logMessage( | 
|---|
| 164 |                 "******************************\n" | 
|---|
| 165 |                 "*** Stopping GLX Subsystem ***\n" | 
|---|
| 166 |                 "******************************"); | 
|---|
| 167 |         if(mDisplay) | 
|---|
| 168 |                 XCloseDisplay(mDisplay); | 
|---|
| 169 |         mDisplay = 0; | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | extern "C" { | 
|---|
| 173 | extern void (*glXGetProcAddressARB(const GLubyte *procName))( void ); | 
|---|
| 174 | }; | 
|---|
| 175 |  | 
|---|
| 176 | void* GLXGLSupport::getProcAddress(const String& procname) { | 
|---|
| 177 |         return (void*)glXGetProcAddressARB((const GLubyte*)procname.c_str()); | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 |  | 
|---|
| 181 | GLPBuffer *GLXGLSupport::createPBuffer(PixelComponentType format, size_t width, size_t height) | 
|---|
| 182 | { | 
|---|
| 183 |     return new GLXPBuffer(format, width, height); | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | } | 
|---|