Browse Source

If GL3 context creation fails, retry with GL2.

Lasse Öörni 10 years ago
parent
commit
f4dc0bf149
1 changed files with 19 additions and 5 deletions
  1. 19 5
      Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

+ 19 - 5
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -321,20 +321,21 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 
     multiSample = Clamp(multiSample, 1, 16);
     multiSample = Clamp(multiSample, 1, 16);
     
     
-    if (IsInitialized() && width == width_ && height == height_ && fullscreen == fullscreen_ && borderless == borderless_ && resizable == resizable_ &&
-        vsync == vsync_ && tripleBuffer == tripleBuffer_ && multiSample == multiSample_)
+    if (IsInitialized() && width == width_ && height == height_ && fullscreen == fullscreen_ && borderless == borderless_ && 
+        resizable == resizable_ && vsync == vsync_ && tripleBuffer == tripleBuffer_ && multiSample == multiSample_)
         return true;
         return true;
     
     
     // If only vsync changes, do not destroy/recreate the context
     // If only vsync changes, do not destroy/recreate the context
-    if (IsInitialized() && width == width_ && height == height_ && fullscreen == fullscreen_ && borderless == borderless_ && resizable == resizable_ &&
-        tripleBuffer == tripleBuffer_ && multiSample == multiSample_ && vsync != vsync_)
+    if (IsInitialized() && width == width_ && height == height_ && fullscreen == fullscreen_ && borderless == borderless_ &&
+        resizable == resizable_ && tripleBuffer == tripleBuffer_ && multiSample == multiSample_ && vsync != vsync_)
     {
     {
         SDL_GL_SetSwapInterval(vsync ? 1 : 0);
         SDL_GL_SetSwapInterval(vsync ? 1 : 0);
         vsync_ = vsync;
         vsync_ = vsync;
         return true;
         return true;
     }
     }
     
     
-    // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size. If zero in fullscreen, use desktop mode
+    // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size. 
+    // If zero in fullscreen, use desktop mode
     if (!width || !height)
     if (!width || !height)
     {
     {
         if (fullscreen || borderless)
         if (fullscreen || borderless)
@@ -2553,6 +2554,19 @@ void Graphics::Restore()
     if (!impl_->context_)
     if (!impl_->context_)
     {
     {
         impl_->context_ = SDL_GL_CreateContext(impl_->window_);
         impl_->context_ = SDL_GL_CreateContext(impl_->window_);
+
+        #ifndef GL_ES_VERSION_2_0
+        // If we're trying to use OpenGL 3, but context creation fails, retry with 2
+        if (!forceGL2_ && !impl_->context_)
+        {
+            forceGL2_ = true;
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
+            impl_->context_ = SDL_GL_CreateContext(impl_->window_);
+        }
+        #endif
+
         #ifdef IOS
         #ifdef IOS
         glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&impl_->systemFBO_);
         glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&impl_->systemFBO_);
         #endif
         #endif