WinRT: another device-rotation and rendering fix
authorDavid Ludwig <dludwig@pobox.com>
Tue, 19 Feb 2013 22:07:07 -0500
changeset 8434 c49d0a46f516
parent 8433 3017f87e4479
child 8435 2d3fe6870df3
WinRT: another device-rotation and rendering fix
src/render/direct3d11/SDL_render_d3d11.cpp
src/video/windowsrt/SDL_WinRTApp.cpp
--- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Feb 17 23:23:59 2013 -0500
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Tue Feb 19 22:07:07 2013 -0500
@@ -975,6 +975,9 @@
                 XMMatrixTranslation(-1, -1, 0),
                 XMMatrixRotationX(XM_PI)
                 )));
+#if 0
+    data->vertexShaderConstantsData.view = XMMatrixIdentity();
+#endif
 
     //
     // Update the Direct3D viewport, which seems to be aligned to the
@@ -1152,14 +1155,15 @@
 
 #if 0
     // Set up a test pattern:
-    SDL_FRect rects[] = {
+    SDL_FRect _rects[] = {
         {-1.1f, 1.1f, 1.1f, -1.1f},
         {-1.0f, 1.0f, 1.0f, -1.0f},     // red
         {0.0f, 1.0f, 1.0f, -1.0f},      // green
         {-1.0f, 0.0f, 1.0f, -1.0f},     // blue
         {0.0f, 0.0f, 1.0f, -1.0f}       // white
     };
-    count = sizeof(rects) / sizeof(SDL_FRect);
+    count = sizeof(_rects) / sizeof(SDL_FRect);
+#define rects _rects
 #endif
 
     for (int i = 0; i < count; ++i) {
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Feb 17 23:23:59 2013 -0500
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Feb 19 22:07:07 2013 -0500
@@ -12,6 +12,8 @@
 #include "../../events/scancodes_windows.h"
 #include "SDL_events.h"
 #include "SDL_log.h"
+#include "SDL_render.h"
+#include "../../render/SDL_sysrender.h"
 }
 
 #include <string>
@@ -168,6 +170,30 @@
         m_sdlWindowData->sdlWindow->fullscreen_mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
         SDL_AddDisplayMode(&m_sdlVideoDevice->displays[0], &m_sdlWindowData->sdlWindow->fullscreen_mode);
 
+        // HACK, Feb 19, 2013: SDL_WINDOWEVENT_RESIZED events, when sent,
+        // will attempt to fix the values of the main window's renderer's
+        // viewport.  While this can be good, it does appear to be buggy,
+        // and can cause a fullscreen viewport to become corrupted.  This
+        // behavior was noticed on a Surface RT while rotating the device
+        // from landscape to portrait.  Oddly enough, this did not occur
+        // in the Windows Simulator.
+        //
+        // Backing up, then restoring, the main renderer's 'resized' flag
+        // seems to fix fullscreen viewport problems when rotating a
+        // Windows device.
+        //
+        // Commencing hack in 3... 2... 1...
+        SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
+        // For now, limit the hack to when the Direct3D 11.1 is getting used:
+        const bool usingD3D11Renderer = \
+            (rendererForMainWindow != NULL) &&
+            (SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
+        SDL_bool wasD3D11RendererResized = SDL_FALSE;
+        if (usingD3D11Renderer) {
+            wasD3D11RendererResized = rendererForMainWindow->resized;
+        }
+
+        // Send the window-resize event to the rest of SDL, and to apps:
         const int windowWidth = (int) ceil(args->Size.Width);
         const int windowHeight = (int) ceil(args->Size.Height);
         SDL_SendWindowEvent(
@@ -175,6 +201,11 @@
             SDL_WINDOWEVENT_RESIZED,
             windowWidth,
             windowHeight);
+
+        // Viewport hack, part two:
+        if (usingD3D11Renderer) {
+            rendererForMainWindow->resized = wasD3D11RendererResized;
+        }
     }
 }