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 "OgreGLES2Prerequisites.h" 36 #include "OgreGLES2RenderSystem.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 EGLint const attrib_list[] = { 74 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 75 EGL_BUFFER_SIZE, 32, 76 EGL_DEPTH_SIZE, 24, 77 EGL_STENCIL_SIZE, 8, 78 EGL_NONE 79 }; 80 81 glConfigs = chooseGLConfig(attrib_list, &nConfigs); 82 83 for (config = 0; config < nConfigs; config++) 84 { 85 int caveat, samples; 86 87 getGLConfigAttrib(glConfigs[config], EGL_CONFIG_CAVEAT, &caveat); 88 89 if (caveat != EGL_SLOW_CONFIG) 90 { 91 getGLConfigAttrib(glConfigs[config], EGL_SAMPLES, &samples); 92 mSampleLevels.push_back(StringConverter::toString(samples)); 93 } 94 } 95 96 free(glConfigs); 97 98 removeDuplicates(mSampleLevels); 99 100 101 } 102 ~Win32EGLSupport()103 Win32EGLSupport::~Win32EGLSupport() 104 { 105 106 } 107 108 //Removed createEGLWindow because it was easier to call new Win32EGLWindow 109 //directly to get the native version. 110 // EGLWindow* Win32EGLSupport::createEGLWindow( EGLSupport * support ) 111 // { 112 // return new Win32EGLWindow(support); 113 // } 114 115 /*GLESPBuffer* Win32EGLSupport::createPBuffer( PixelComponentType format, size_t width, size_t height ) 116 { 117 return new Win32EGLPBuffer(this, format, width, height); 118 }*/ 119 switchMode(uint & width,uint & height,short & frequency)120 void Win32EGLSupport::switchMode( uint& width, uint& height, short& frequency ) 121 { 122 if (!mRandr) 123 return; 124 125 int size = 0; 126 int newSize = -1; 127 128 VideoModes::iterator mode; 129 VideoModes::iterator end = mVideoModes.end(); 130 VideoMode *newMode = 0; 131 132 for(mode = mVideoModes.begin(); mode != end; size++) 133 { 134 if (mode->first.first >= static_cast<int>(width) && 135 mode->first.second >= static_cast<int>(height)) 136 { 137 if (!newMode || 138 mode->first.first < newMode->first.first || 139 mode->first.second < newMode->first.second) 140 { 141 newSize = size; 142 newMode = &(*mode); 143 } 144 } 145 146 VideoMode* lastMode = &(*mode); 147 148 while (++mode != end && mode->first == lastMode->first) 149 { 150 if (lastMode == newMode && mode->second == frequency) 151 { 152 newMode = &(*mode); 153 } 154 } 155 } 156 157 //todo 158 } 159 160 //Moved to native from EGLSupport newWindow(const String & name,unsigned int width,unsigned int height,bool fullScreen,const NameValuePairList * miscParams)161 RenderWindow* Win32EGLSupport::newWindow(const String &name, 162 unsigned int width, unsigned int height, 163 bool fullScreen, 164 const NameValuePairList *miscParams) 165 { 166 // EGLWindow* window = createEGLWindow(this); 167 168 Win32EGLWindow* window = new Win32EGLWindow(this); 169 window->create(name, width, height, fullScreen, miscParams); 170 171 return window; 172 } 173 174 //Moved to native from EGLSupport getNativeDisplay()175 NativeDisplayType Win32EGLSupport::getNativeDisplay() 176 { 177 return EGL_DEFAULT_DISPLAY; // TODO 178 } 179 180 //Win32EGLSupport::getGLDisplay sets up the native variable 181 //then calls EGLSupport::getGLDisplay getGLDisplay()182 EGLDisplay Win32EGLSupport::getGLDisplay() 183 { 184 if (!mGLDisplay) 185 { 186 mNativeDisplay = getNativeDisplay(); 187 return EGLSupport::getGLDisplay(); 188 } 189 return mGLDisplay; 190 } 191 192 193 } 194