source: OGRE/trunk/ogrenew/RenderSystems/GL/src/GLX/OgreGLXGLSupport.cpp @ 657

Revision 657, 6.2 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
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 "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
38namespace Ogre {
39
40GLXGLSupport::GLXGLSupport():
41mDisplay(0) {}
42
43GLXGLSupport::~GLXGLSupport() {}
44
45void GLXGLSupport::addConfig(void) {
46        ConfigOption optFullScreen;
47        ConfigOption optVideoMode;
48        ConfigOption optBitDepth;
49    ConfigOption optFSAA;
50
51        // FS setting possiblities
52        optFullScreen.name = "Full Screen";
53        optFullScreen.possibleValues.push_back("Yes");
54        optFullScreen.possibleValues.push_back("No");
55        optFullScreen.currentValue = "Yes";
56        optFullScreen.immutable = false;
57
58        // Video mode possiblities
59        optVideoMode.name = "Video Mode";
60        optVideoMode.immutable = false;
61
62        // We could query Xrandr here, but that wouldn't work in the non-fullscreen case
63        // or when that extension is disabled. Anyway, this list of modes is fairly
64        // complete.
65        optVideoMode.possibleValues.push_back("640 x 480");
66        optVideoMode.possibleValues.push_back("800 x 600");
67        optVideoMode.possibleValues.push_back("1024 x 768");
68        optVideoMode.possibleValues.push_back("1280 x 960");
69        optVideoMode.possibleValues.push_back("1280 x 1024");
70        optVideoMode.possibleValues.push_back("1600 x 1200");
71
72        optVideoMode.currentValue = "800 x 600";
73
74    //FSAA possibilities
75    optFSAA.name = "FSAA";
76    optFSAA.possibleValues.push_back("0");
77    optFSAA.possibleValues.push_back("2");
78    optFSAA.possibleValues.push_back("4");
79    optFSAA.possibleValues.push_back("6");
80    optFSAA.currentValue = "0";
81    optFSAA.immutable = false;
82
83
84        mOptions[optFullScreen.name] = optFullScreen;
85        mOptions[optVideoMode.name] = optVideoMode;
86    mOptions[optFSAA.name] = optFSAA;
87}
88
89String GLXGLSupport::validateConfig(void) {
90        return String("");
91}
92
93RenderWindow* GLXGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
94{
95        if (autoCreateWindow) {
96                ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
97                if (opt == mOptions.end())
98                        OGRE_EXCEPT(999, "Can't find full screen options!", "GLXGLSupport::createWindow");
99                bool fullscreen = (opt->second.currentValue == "Yes");
100
101                opt = mOptions.find("Video Mode");
102                if (opt == mOptions.end())
103                        OGRE_EXCEPT(999, "Can't find video mode options!", "GLXGLSupport::createWindow");
104                String val = opt->second.currentValue;
105                String::size_type pos = val.find('x');
106                if (pos == String::npos)
107                        OGRE_EXCEPT(999, "Invalid Video Mode provided", "GLXGLSupport::createWindow");
108
109                unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos));
110                unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1));
111
112        // Parse FSAA config
113                NameValuePairList winOptions;
114                winOptions["title"] = windowTitle;
115        int fsaa_x_samples = 0;
116        opt = mOptions.find("FSAA");
117        if(opt != mOptions.end())
118        {
119                        winOptions["FSAA"] = opt->second.currentValue;
120        }
121
122                return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions);
123        } else {
124                // XXX What is the else?
125                return NULL;
126        }
127}
128
129RenderWindow* GLXGLSupport::newWindow(const String &name, unsigned int width, unsigned int height,
130        bool fullScreen, const NameValuePairList *miscParams)
131{
132        GLXWindow* window = new GLXWindow(mDisplay);
133        window->create(name, width, height, fullScreen, miscParams);
134        return window;
135}
136
137void GLXGLSupport::start() {
138        LogManager::getSingleton().logMessage(
139                "******************************\n"
140                "*** Starting GLX Subsystem ***\n"
141                "******************************");
142        mDisplay = XOpenDisplay(NULL);
143        if(!mDisplay) {
144                OGRE_EXCEPT(999, "Couldn`t open X display", "GLXGLSupport::start");
145        }
146
147}
148
149void GLXGLSupport::stop() {
150        LogManager::getSingleton().logMessage(
151                "******************************\n"
152                "*** Stopping GLX Subsystem ***\n"
153                "******************************");
154        if(mDisplay)
155                XCloseDisplay(mDisplay);
156        mDisplay = 0;
157}
158
159void GLXGLSupport::initialiseCapabilities(RenderSystemCapabilities &caps)
160{
161    // Broken for ATI glx currently
162        if(getGLVendor() != "ATI")
163        caps.setCapability(RSC_HWRENDER_TO_TEXTURE);
164        // This does work for ATI, even under Linux
165        if(checkExtension("GL_SGIS_generate_mipmap"))
166                caps.setCapability(RSC_AUTOMIPMAP);
167}
168
169
170extern "C" {
171extern void (*glXGetProcAddressARB(const GLubyte *procName))( void );
172};
173
174void* GLXGLSupport::getProcAddress(const String& procname) {
175        return (void*)glXGetProcAddressARB((const GLubyte*)procname.c_str());
176}
177
178
179
180RenderTexture * GLXGLSupport::createRenderTexture( const String & name, unsigned int width, unsigned int height,
181                TextureType texType, PixelFormat internalFormat,
182                const NameValuePairList *miscParams )
183{
184        if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE))
185                return new GLXRenderTexture(name, width, height, texType, internalFormat, miscParams);
186        else
187                return new GLRenderTexture(name, width, height, texType, internalFormat, miscParams);
188
189
190}
Note: See TracBrowser for help on using the repository browser.