00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2004 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 00026 #include "OgreException.h" 00027 #include "OgreLogManager.h" 00028 #include "OgreStringConverter.h" 00029 00030 #include "OgreGLXGLSupport.h" 00031 00032 #include "OgreGLXWindow.h" 00033 00034 namespace Ogre { 00035 00036 GLXGLSupport::GLXGLSupport(): 00037 mDisplay(0) {} 00038 00039 GLXGLSupport::~GLXGLSupport() {} 00040 00041 void GLXGLSupport::addConfig(void) { 00042 ConfigOption optFullScreen; 00043 ConfigOption optVideoMode; 00044 ConfigOption optBitDepth; 00045 00046 // FS setting possiblities 00047 optFullScreen.name = "Full Screen"; 00048 optFullScreen.possibleValues.push_back("Yes"); 00049 optFullScreen.possibleValues.push_back("No"); 00050 optFullScreen.currentValue = "Yes"; 00051 optFullScreen.immutable = false; 00052 00053 // Video mode possiblities 00054 optVideoMode.name = "Video Mode"; 00055 optVideoMode.immutable = false; 00056 00057 // We could query Xrandr here, but that wouldn't work in the non-fullscreen case 00058 // or when that extension is disables. Anyway, this list of modes is fairly 00059 // complete. 00060 optVideoMode.possibleValues.push_back("640 x 480"); 00061 optVideoMode.possibleValues.push_back("800 x 600"); 00062 optVideoMode.possibleValues.push_back("1024 x 768"); 00063 optVideoMode.possibleValues.push_back("1280 x 960"); 00064 optVideoMode.possibleValues.push_back("1280 x 1024"); 00065 optVideoMode.possibleValues.push_back("1600 x 1200"); 00066 00067 optVideoMode.currentValue = "800 x 600"; 00068 00069 mOptions[optFullScreen.name] = optFullScreen; 00070 mOptions[optVideoMode.name] = optVideoMode; 00071 00072 } 00073 00074 String GLXGLSupport::validateConfig(void) { 00075 return String(""); 00076 } 00077 00078 RenderWindow* GLXGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) { 00079 if (autoCreateWindow) { 00080 ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); 00081 if (opt == mOptions.end()) 00082 Except(999, "Can't find full screen options!", "GLXGLSupport::createWindow"); 00083 bool fullscreen = (opt->second.currentValue == "Yes"); 00084 00085 opt = mOptions.find("Video Mode"); 00086 if (opt == mOptions.end()) 00087 Except(999, "Can't find video mode options!", "GLXGLSupport::createWindow"); 00088 String val = opt->second.currentValue; 00089 String::size_type pos = val.find('x'); 00090 if (pos == String::npos) 00091 Except(999, "Invalid Video Mode provided", "GLXGLSupport::createWindow"); 00092 00093 unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); 00094 unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); 00095 00096 // Make sure the window is centered 00097 int screen = DefaultScreen(mDisplay); 00098 int left = DisplayWidth(mDisplay, screen)/2 - w/2; 00099 int top = DisplayHeight(mDisplay, screen)/2 - h/2; 00100 00101 return renderSystem->createRenderWindow(windowTitle, w, h, 32, fullscreen, left, top); 00102 } else { 00103 // XXX What is the else? 00104 return NULL; 00105 } 00106 } 00107 00108 RenderWindow* GLXGLSupport::newWindow(const String& name, unsigned int width, unsigned int height, unsigned int colourDepth, 00109 bool fullScreen, int left, int top, bool depthBuffer, RenderWindow* parentWindowHandle, 00110 bool vsync) { 00111 GLXWindow* window = new GLXWindow(mDisplay); 00112 window->create(name, width, height, colourDepth, fullScreen, left, top, depthBuffer, 00113 parentWindowHandle); 00114 return window; 00115 } 00116 00117 void GLXGLSupport::start() { 00118 LogManager::getSingleton().logMessage( 00119 "******************************\n" 00120 "*** Starting GLX Subsystem ***\n" 00121 "******************************"); 00122 mDisplay = XOpenDisplay(NULL); 00123 if(!mDisplay) { 00124 Except(999, "Couldn`t open X display", "GLXGLSupport::start"); 00125 } 00126 00127 } 00128 00129 void GLXGLSupport::stop() { 00130 LogManager::getSingleton().logMessage( 00131 "******************************\n" 00132 "*** Stopping GLX Subsystem ***\n" 00133 "******************************"); 00134 if(mDisplay) 00135 XCloseDisplay(mDisplay); 00136 mDisplay = 0; 00137 } 00138 extern "C" { 00139 extern void (*glXGetProcAddressARB(const GLubyte *procName))( void ); 00140 }; 00141 00142 void* GLXGLSupport::getProcAddress(const String& procname) { 00143 return (void*)glXGetProcAddressARB((const GLubyte*)procname.c_str()); 00144 } 00145 00146 #if 0 00147 // TODO: multiple context/window support 00148 00149 void GLXGLSupport::begin_context(RenderTarget *_target) 00150 { 00151 // Support nested contexts, in which case.. nothing happens 00152 ++_context_ref; 00153 if (_context_ref == 1) { 00154 if(_target) { 00155 // Begin a specific context 00156 OGREWidget *_ogre_widget = static_cast<GTKWindow*>(_target)->get_ogre_widget(); 00157 00158 _ogre_widget->get_gl_window()->gl_begin(_ogre_widget->get_gl_context()); 00159 } else { 00160 // Begin a generic main context 00161 _main_window->gl_begin(_main_context); 00162 } 00163 } 00164 } 00165 00166 void GLXGLSupport::end_context() 00167 { 00168 --_context_ref; 00169 if(_context_ref < 0) 00170 Except(999, "Too many contexts destroyed!", "GTKGLSupport::end_context"); 00171 if (_context_ref == 0) 00172 { 00173 // XX is this enough? (_main_window might not be the current window, 00174 // but we can never be sure the previous rendering window 00175 // even still exists) 00176 _main_window->gl_end(); 00177 } 00178 } 00179 #endif 00180 00181 };
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:27 2004