浏览代码

Choose pixel format for external OpenGL windows. TODO: current implementation Windows-only, implement on other video drivers.

Lasse Öörni 13 年之前
父节点
当前提交
6337336c78

+ 1 - 1
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -2026,7 +2026,7 @@ bool Graphics::OpenWindow(int width, int height)
     if (!externalWindow_)
         impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0);
     else
-        impl_->window_ = SDL_CreateWindowFrom(externalWindow_);
+        impl_->window_ = SDL_CreateWindowFrom(externalWindow_, 0);
     
     if (!impl_->window_)
     {

+ 1 - 1
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -300,7 +300,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool vsync, bool
                 else
                 {
                     if (!impl_->window_)
-                        impl_->window_ = SDL_CreateWindowFrom(externalWindow_);
+                        impl_->window_ = SDL_CreateWindowFrom(externalWindow_, SDL_WINDOW_OPENGL);
                     fullscreen = false;
                 }
                 

+ 4 - 2
ThirdParty/SDL/include/SDL_video.h

@@ -400,12 +400,14 @@ extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title,
  *  \brief Create an SDL window from an existing native window.
  *  
  *  \param data A pointer to driver-dependent window creation data
- *  
+ *  \param flags The flags for the window, specify SDL_WINDOW_OPENGL to setup
+ *               OpenGL pixel format
+ *
  *  \return The id of the window created, or zero if window creation failed.
  *  
  *  \sa SDL_DestroyWindow()
  */
-extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data);
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data, Uint32 flags);
 
 /**
  *  \brief Get the numeric ID of a window, for logging purposes.

+ 11 - 14
ThirdParty/SDL/src/video/SDL_video.c

@@ -1220,7 +1220,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
 }
 
 SDL_Window *
-SDL_CreateWindowFrom(const void *data)
+SDL_CreateWindowFrom(const void *data, Uint32 flags)
 {
     SDL_Window *window;
 
@@ -1239,6 +1239,16 @@ SDL_CreateWindowFrom(const void *data)
     }
     _this->windows = window;
 
+    // Urho3D: load OpenGL if initializing an external OpenGL window
+    if (flags & SDL_WINDOW_OPENGL) {
+        if (!_this->GL_CreateContext) {
+            SDL_SetError("No OpenGL support in video driver");
+            return NULL;
+        }
+        SDL_GL_LoadLibrary(NULL);
+        window->flags |= SDL_WINDOW_OPENGL;
+    }
+
     if (!_this->CreateWindowFrom ||
         _this->CreateWindowFrom(_this, window, data) < 0) {
         SDL_DestroyWindow(window);
@@ -2511,22 +2521,9 @@ SDL_GL_CreateContext(SDL_Window * window)
     SDL_GLContext ctx = NULL;
     CHECK_WINDOW_MAGIC(window, NULL);
 
-    // Urho3D: set up OpenGL support dynamically if necessary for external windows
     if (!(window->flags & SDL_WINDOW_OPENGL)) {
-        #if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__
-            window->flags |= SDL_WINDOW_OPENGL;
-        #else
-            window->flags |= SDL_WINDOW_OPENGL;
-            if (!_this->GL_CreateContext) {
-                SDL_SetError("No OpenGL support in video driver");
-                return NULL;
-            }
-            SDL_GL_LoadLibrary(NULL);
-        #endif
-        /*
         SDL_SetError("The specified window isn't an OpenGL window");
         return NULL;
-        */
     }
 
     ctx = _this->GL_CreateContext(_this, window);

+ 8 - 0
ThirdParty/SDL/src/video/windows/SDL_windowswindow.c

@@ -272,6 +272,14 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
     if (SetupWindowData(_this, window, hwnd, SDL_FALSE) < 0) {
         return -1;
     }
+    
+    // Urho3D: if window will be used for OpenGL, choose pixel format
+    if (window->flags & SDL_WINDOW_OPENGL) {
+        if (WIN_GL_SetupWindow(_this, window) < 0) {
+            return -1;
+        }
+    }
+    
     return 0;
 }