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) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com>
8 Copyright (c) 2000-2013 Torus Knot Software Ltd
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 -----------------------------------------------------------------------------
28 */
29 
30 #include "OgreException.h"
31 #include "OgreLogManager.h"
32 #include "OgreStringConverter.h"
33 #include "OgreRoot.h"
34 
35 #include "OgreGLESPrerequisites.h"
36 #include "OgreGLESRenderSystem.h"
37 
38 #include "OgreWin32EGLSupport.h"
39 #include "OgreWin32EGLWindow.h"
40 #include "OgreWin32EGLRenderTexture.h"
41 #include "OgreWin32EGLContext.h"
42 
43 
44 
45 namespace Ogre {
46 
47 
Win32EGLSupport()48 	Win32EGLSupport::Win32EGLSupport()
49 	{
50 		//RECT windowRect;
51 		//GetClientRect(mNativeDisplay, &windowRect);
52 		mNativeDisplay = getNativeDisplay();
53 		mGLDisplay = getGLDisplay();
54 
55 		// Video mode possibilities
56 		DEVMODE DevMode;
57 		DevMode.dmSize = sizeof(DEVMODE);
58 		for (DWORD i = 0; EnumDisplaySettings(NULL, i, &DevMode); ++i)
59 		{
60 			if (DevMode.dmBitsPerPel < 16)
61 				continue;
62 
63 			mCurrentMode.first.first = DevMode.dmPelsWidth;
64 			mCurrentMode.first.second = DevMode.dmPelsHeight;
65 			mCurrentMode.second = 0;
66 			mOriginalMode = mCurrentMode;
67 			mVideoModes.push_back(mCurrentMode);
68 		}
69 
70 		EGLConfig *glConfigs;
71 		int config, nConfigs = 0;
72 
73 		glConfigs = chooseGLConfig(NULL, &nConfigs);
74 
75 		for (config = 0; config < nConfigs; config++)
76 		{
77 			int caveat, samples;
78 
79 			getGLConfigAttrib(glConfigs[config], EGL_CONFIG_CAVEAT, &caveat);
80 
81 			if (caveat != EGL_SLOW_CONFIG)
82 			{
83 				getGLConfigAttrib(glConfigs[config], EGL_SAMPLES, &samples);
84 				mSampleLevels.push_back(StringConverter::toString(samples));
85 			}
86 		}
87 
88 		free(glConfigs);
89 
90 		removeDuplicates(mSampleLevels);
91 
92 
93 	}
94 
~Win32EGLSupport()95 	Win32EGLSupport::~Win32EGLSupport()
96 	{
97 
98 	}
99 
100 	//Removed createEGLWindow because it was easier to call new Win32EGLWindow
101 	//directly to get the native version.
102 //	EGLWindow* Win32EGLSupport::createEGLWindow(  EGLSupport * support )
103 //	{
104 //		return new Win32EGLWindow(support);
105 //	}
106 
createPBuffer(PixelComponentType format,size_t width,size_t height)107 	GLESPBuffer* Win32EGLSupport::createPBuffer( PixelComponentType format, size_t width, size_t height )
108 	{
109 		return new Win32EGLPBuffer(this, format, width, height);
110 	}
111 
switchMode(uint & width,uint & height,short & frequency)112 	void Win32EGLSupport::switchMode( uint& width, uint& height, short& frequency )
113 	{
114 		if (!mRandr)
115 			return;
116 
117 		int size = 0;
118 		int newSize = -1;
119 
120 		VideoModes::iterator mode;
121 		VideoModes::iterator end = mVideoModes.end();
122 		VideoMode *newMode = 0;
123 
124 		for(mode = mVideoModes.begin(); mode != end; size++)
125 		{
126 			if (mode->first.first >= static_cast<int>(width) &&
127 				mode->first.second >= static_cast<int>(height))
128 			{
129 				if (!newMode ||
130 					mode->first.first < newMode->first.first ||
131 					mode->first.second < newMode->first.second)
132 				{
133 					newSize = size;
134 					newMode = &(*mode);
135 				}
136 			}
137 
138 			VideoMode* lastMode = &(*mode);
139 
140 			while (++mode != end && mode->first == lastMode->first)
141 			{
142 				if (lastMode == newMode && mode->second == frequency)
143 				{
144 					newMode = &(*mode);
145 				}
146 			}
147 		}
148 
149 		//todo
150 	}
151 
152 	//Moved to native from EGLSupport
newWindow(const String & name,unsigned int width,unsigned int height,bool fullScreen,const NameValuePairList * miscParams)153    RenderWindow* Win32EGLSupport::newWindow(const String &name,
154                                         unsigned int width, unsigned int height,
155                                         bool fullScreen,
156                                         const NameValuePairList *miscParams)
157     {
158 //        EGLWindow* window = createEGLWindow(this);
159 
160 	Win32EGLWindow* window = new Win32EGLWindow(this);
161         window->create(name, width, height, fullScreen, miscParams);
162 
163         return window;
164     }
165 
166 	//Moved to native from EGLSupport
getNativeDisplay()167 	NativeDisplayType Win32EGLSupport::getNativeDisplay()
168 	{
169 		return EGL_DEFAULT_DISPLAY; // TODO
170 	}
171 
172 	//Win32EGLSupport::getGLDisplay sets up the native variable
173 	//then calls EGLSupport::getGLDisplay
getGLDisplay()174 	EGLDisplay Win32EGLSupport::getGLDisplay()
175 	{
176 		if (!mGLDisplay)
177 		{
178 			mNativeDisplay = getNativeDisplay();
179 			return EGLSupport::getGLDisplay();
180 		}
181 		return mGLDisplay;
182 	}
183 
184 
185 }
186