Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreGTKGLSupport.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://ogre.sourceforge.net/
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 "OgreGTKGLSupport.h"
00027 #include "OgreGTKWindow.h"
00028 
00029 #include "OgreLogManager.h"
00030 #include "OgreException.h"
00031 #include "OgreStringConverter.h"
00032 
00033 
00034 
00035 using namespace Ogre;
00036 
00037 template<> GTKGLSupport* Singleton<GTKGLSupport>::ms_Singleton = 0;
00038 GTKGLSupport* GTKGLSupport::getSingletonPtr(void)
00039 {
00040     return ms_Singleton;
00041 }
00042 GTKGLSupport& GTKGLSupport::getSingleton(void)
00043 {  
00044     assert( ms_Singleton );  return ( *ms_Singleton );  
00045 }
00046 
00047 GTKGLSupport::GTKGLSupport() : 
00048     _kit(0, NULL),
00049     _context_ref(0)
00050 {
00051     Gtk::GL::init(0, NULL);
00052     _main_context = 0;
00053     _main_window = 0;
00054     //_ogre_widget = 0;
00055 }
00056 
00057 void GTKGLSupport::addConfig()
00058 {
00059     ConfigOption optFullScreen;
00060     ConfigOption optVideoMode;
00061 
00062      // FS setting possiblities
00063     optFullScreen.name = "Full Screen";
00064     optFullScreen.possibleValues.push_back("Yes");
00065     optFullScreen.possibleValues.push_back("No");
00066     optFullScreen.currentValue = "No";
00067     optFullScreen.immutable = false;
00068  
00069     // Video mode possiblities
00070     // XXX Actually do this
00071     optVideoMode.name = "Video Mode";
00072     optVideoMode.immutable = false;
00073     optVideoMode.possibleValues.push_back("640 x 480");
00074     optVideoMode.possibleValues.push_back("800 x 600");
00075     optVideoMode.possibleValues.push_back("1024 x 768");
00076     optVideoMode.possibleValues.push_back("1280 x 1024");
00077 
00078     optVideoMode.currentValue = "800 x 600";
00079 
00080     mOptions[optFullScreen.name] = optFullScreen;
00081     mOptions[optVideoMode.name] = optVideoMode;
00082 }
00083     
00084 String GTKGLSupport::validateConfig()
00085 {
00086     return String("");
00087 }
00088 
00089 RenderWindow* GTKGLSupport::createWindow(bool autoCreateWindow, 
00090                                          GLRenderSystem* renderSystem, 
00091                      const String& windowTitle)
00092 {
00093     if (autoCreateWindow)
00094     {
00095         ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
00096         if (opt == mOptions.end())
00097             Except(999, "Can't find full screen options!", "SDLGLSupport::createWindow");
00098         bool fullscreen = (opt->second.currentValue == "Yes");
00099  
00100         opt = mOptions.find("Video Mode");
00101         if (opt == mOptions.end())
00102             Except(999, "Can't find video mode options!", "SDLGLSupport::createWindow");
00103         String val = opt->second.currentValue;
00104         String::size_type pos = val.find('x');
00105         if (pos == String::npos)
00106             Except(999, "Invalid Video Mode provided", "SDLGLSupport::createWindow");
00107  
00108         unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
00109         unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
00110  
00111         return renderSystem->createRenderWindow(windowTitle, w, h, 32,
00112 fullscreen);
00113     }
00114     else
00115     {
00116         // XXX What is the else?
00117                 return NULL;
00118     }
00119 }
00120 
00121 RenderWindow* GTKGLSupport::newWindow(const String& name, unsigned int width, 
00122         unsigned int height, unsigned int colourDepth, bool fullScreen, int left, int top,
00123         bool depthBuffer, RenderWindow* parentWindowHandle, bool vsync)
00124 {
00125     GTKWindow* window = new GTKWindow();
00126     window->create(name, width, height, colourDepth, fullScreen, left, top,
00127                    depthBuffer, parentWindowHandle);
00128 
00129     //if(!_ogre_widget)
00130     //  _ogre_widget = window->get_ogre_widget();
00131 
00132     // Copy some important information for future reference, for example
00133     // for when the context is needed
00134     if(!_main_context)
00135         _main_context = window->get_ogre_widget()->get_gl_context();
00136     if(!_main_window)
00137         _main_window = window->get_ogre_widget()->get_gl_window();
00138 
00139     return window;
00140 }
00141 
00142 void GTKGLSupport::start()
00143 {
00144     LogManager::getSingleton().logMessage(
00145         "******************************\n"
00146         "*** Starting GTK Subsystem ***\n"
00147         "******************************");
00148 
00149 }
00150  
00151 void GTKGLSupport::stop()
00152 {
00153     LogManager::getSingleton().logMessage(
00154         "******************************\n"
00155         "*** Stopping GTK Subsystem ***\n"
00156         "******************************");
00157 }
00158 
00159 void GTKGLSupport::begin_context(RenderTarget *_target)
00160 {
00161     // Support nested contexts, in which case.. nothing happens
00162         ++_context_ref;
00163         if (_context_ref == 1) {
00164         if(_target) {
00165             // Begin a specific context
00166             OGREWidget *_ogre_widget = static_cast<GTKWindow*>(_target)->get_ogre_widget();
00167 
00168                 _ogre_widget->get_gl_window()->gl_begin(_ogre_widget->get_gl_context());
00169         } else {
00170             // Begin a generic main context
00171             _main_window->gl_begin(_main_context);
00172         }
00173         }
00174 }
00175 
00176 void GTKGLSupport::end_context()
00177 {
00178         --_context_ref;
00179         if(_context_ref < 0)
00180             Except(999, "Too many contexts destroyed!", "GTKGLSupport::end_context");
00181         if (_context_ref == 0)
00182         {
00183         // XX is this enough? (_main_window might not be the current window,
00184         // but we can never be sure the previous rendering window 
00185         // even still exists)
00186         _main_window->gl_end();
00187         }
00188 }
00189  
00190 void GTKGLSupport::initialiseExtensions(void)
00191 {
00192     // XXX anythign to actually do here?
00193 }
00194 
00195 bool GTKGLSupport::checkMinGLVersion(const String& v) const
00196 {
00197     int major, minor;
00198     Gdk::GL::query_version(major, minor);
00199 
00200     std::string::size_type pos = v.find(".");
00201     int cmaj = atoi(v.substr(0, pos).c_str());
00202     int cmin = atoi(v.substr(pos + 1).c_str());
00203 
00204     return ( (major >= cmaj) && (minor >= cmin) );
00205 }
00206 
00207 bool GTKGLSupport::checkExtension(const String& ext) const
00208 {
00209     // query_gl_extension needs an active context, doesn't matter which one
00210     if (_context_ref == 0)
00211         _main_window->gl_begin(_main_context);
00212 
00213     bool result = Gdk::GL::query_gl_extension(ext.c_str());
00214 
00215     if (_context_ref == 0)
00216         _main_window->gl_end();
00217 }
00218 
00219 void* GTKGLSupport::getProcAddress(const String& procname)
00220 {
00221     return (void*)Gdk::GL::get_proc_address(procname.c_str());
00222 }
00223 
00224 Glib::RefPtr<const Gdk::GL::Context> GTKGLSupport::getMainContext() const {
00225     return _main_context;
00226 }
00227 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:14 2004