source: OGRE/trunk/ogrenew/RenderSystems/GL/src/gtk/OgreGTKGLSupport.cpp @ 692

Revision 692, 7.0 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25
26#include "OgreGTKGLSupport.h"
27#include "OgreGTKWindow.h"
28
29#include "OgreLogManager.h"
30#include "OgreException.h"
31#include "OgreStringConverter.h"
32
33
34
35using namespace Ogre;
36
37template<> GTKGLSupport* Singleton<GTKGLSupport>::ms_Singleton = 0;
38GTKGLSupport* GTKGLSupport::getSingletonPtr(void)
39{
40    return ms_Singleton;
41}
42GTKGLSupport& GTKGLSupport::getSingleton(void)
43
44    assert( ms_Singleton );  return ( *ms_Singleton ); 
45}
46
47GTKGLSupport::GTKGLSupport() :
48    _kit(0, NULL),
49    _context_ref(0)
50{
51    Gtk::GL::init(0, NULL);
52    _main_context = 0;
53    _main_window = 0;
54    //_ogre_widget = 0;
55}
56
57void GTKGLSupport::addConfig()
58{
59    ConfigOption optFullScreen;
60    ConfigOption optVideoMode;
61
62     // FS setting possiblities
63    optFullScreen.name = "Full Screen";
64    optFullScreen.possibleValues.push_back("Yes");
65    optFullScreen.possibleValues.push_back("No");
66    optFullScreen.currentValue = "No";
67    optFullScreen.immutable = false;
68 
69    // Video mode possiblities
70    // XXX Actually do this
71    optVideoMode.name = "Video Mode";
72    optVideoMode.immutable = false;
73    optVideoMode.possibleValues.push_back("640 x 480");
74    optVideoMode.possibleValues.push_back("800 x 600");
75    optVideoMode.possibleValues.push_back("1024 x 768");
76    optVideoMode.possibleValues.push_back("1280 x 1024");
77
78    optVideoMode.currentValue = "800 x 600";
79
80    mOptions[optFullScreen.name] = optFullScreen;
81    mOptions[optVideoMode.name] = optVideoMode;
82}
83   
84String GTKGLSupport::validateConfig()
85{
86    return String("");
87}
88
89RenderWindow* GTKGLSupport::createWindow(bool autoCreateWindow,
90                                         GLRenderSystem* renderSystem,
91                                         const String& windowTitle)
92{
93    if (autoCreateWindow)
94    {
95        ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
96        if (opt == mOptions.end())
97            OGRE_EXCEPT(999, "Can't find full screen options!", "GTKGLSupport::createWindow");
98        bool fullscreen = (opt->second.currentValue == "Yes");
99 
100        opt = mOptions.find("Video Mode");
101        if (opt == mOptions.end())
102            OGRE_EXCEPT(999, "Can't find video mode options!", "GTKGLSupport::createWindow");
103        String val = opt->second.currentValue;
104        String::size_type pos = val.find('x');
105        if (pos == String::npos)
106            OGRE_EXCEPT(999, "Invalid Video Mode provided", "GTKGLSupport::createWindow");
107 
108        unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
109        unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
110 
111        return renderSystem->createRenderWindow(windowTitle, w, h, 32,
112fullscreen);
113    }
114    else
115    {
116        // XXX What is the else?
117                return NULL;
118    }
119}
120
121RenderWindow* GTKGLSupport::newWindow(const String& name, unsigned int width,
122        unsigned int height, unsigned int colourDepth, bool fullScreen, int left, int top,
123        bool depthBuffer, RenderWindow* parentWindowHandle, bool vsync)
124{
125    GTKWindow* window = new GTKWindow();
126    window->create(name, width, height, colourDepth, fullScreen, left, top,
127                   depthBuffer, parentWindowHandle);
128
129    //if(!_ogre_widget)
130    //  _ogre_widget = window->get_ogre_widget();
131
132    // Copy some important information for future reference, for example
133    // for when the context is needed
134    if(!_main_context)
135        _main_context = window->get_ogre_widget()->get_gl_context();
136    if(!_main_window)
137        _main_window = window->get_ogre_widget()->get_gl_window();
138
139    return window;
140}
141
142void GTKGLSupport::start()
143{
144    LogManager::getSingleton().logMessage(
145        "******************************\n"
146        "*** Starting GTK Subsystem ***\n"
147        "******************************");
148
149}
150 
151void GTKGLSupport::stop()
152{
153    LogManager::getSingleton().logMessage(
154        "******************************\n"
155        "*** Stopping GTK Subsystem ***\n"
156        "******************************");
157}
158
159void GTKGLSupport::begin_context(RenderTarget *_target)
160{
161        // Support nested contexts, in which case.. nothing happens
162        ++_context_ref;
163        if (_context_ref == 1) {
164                if(_target) {
165                        // Begin a specific context
166                        OGREWidget *_ogre_widget = static_cast<GTKWindow*>(_target)->get_ogre_widget();
167
168                        _ogre_widget->get_gl_window()->gl_begin(_ogre_widget->get_gl_context());
169                } else {
170                        // Begin a generic main context
171                        _main_window->gl_begin(_main_context);
172                }
173        }
174}
175
176void GTKGLSupport::end_context()
177{
178        --_context_ref;
179        if(_context_ref < 0)
180                OGRE_EXCEPT(999, "Too many contexts destroyed!", "GTKGLSupport::end_context");
181        if (_context_ref == 0)
182        {
183                // XX is this enough? (_main_window might not be the current window,
184                // but we can never be sure the previous rendering window
185                // even still exists)
186                _main_window->gl_end();
187        }
188}
189 
190void GTKGLSupport::initialiseExtensions(void)
191{
192    // XXX anythign to actually do here?
193}
194
195bool GTKGLSupport::checkMinGLVersion(const String& v) const
196{
197    int major, minor;
198    Gdk::GL::query_version(major, minor);
199
200    std::string::size_type pos = v.find(".");
201    int cmaj = atoi(v.substr(0, pos).c_str());
202    int cmin = atoi(v.substr(pos + 1).c_str());
203
204    return ( (major >= cmaj) && (minor >= cmin) );
205}
206
207bool GTKGLSupport::checkExtension(const String& ext) const
208{
209        // query_gl_extension needs an active context, doesn't matter which one
210        if (_context_ref == 0)
211                _main_window->gl_begin(_main_context);
212
213        bool result = Gdk::GL::query_gl_extension(ext.c_str());
214
215        if (_context_ref == 0)
216                _main_window->gl_end();
217}
218
219void* GTKGLSupport::getProcAddress(const String& procname)
220{
221    return (void*)Gdk::GL::get_proc_address(procname.c_str());
222}
223
224Glib::RefPtr<const Gdk::GL::Context> GTKGLSupport::getMainContext() const {
225        return _main_context;
226}
227
Note: See TracBrowser for help on using the repository browser.