WinRT: another device-rotation and rendering fix
authorDavid Ludwig <dludwig@pobox.com>
Tue, 19 Feb 2013 22:07:07 -0500
changeset 8434c49d0a46f516
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
     1.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Feb 17 23:23:59 2013 -0500
     1.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Tue Feb 19 22:07:07 2013 -0500
     1.3 @@ -975,6 +975,9 @@
     1.4                  XMMatrixTranslation(-1, -1, 0),
     1.5                  XMMatrixRotationX(XM_PI)
     1.6                  )));
     1.7 +#if 0
     1.8 +    data->vertexShaderConstantsData.view = XMMatrixIdentity();
     1.9 +#endif
    1.10  
    1.11      //
    1.12      // Update the Direct3D viewport, which seems to be aligned to the
    1.13 @@ -1152,14 +1155,15 @@
    1.14  
    1.15  #if 0
    1.16      // Set up a test pattern:
    1.17 -    SDL_FRect rects[] = {
    1.18 +    SDL_FRect _rects[] = {
    1.19          {-1.1f, 1.1f, 1.1f, -1.1f},
    1.20          {-1.0f, 1.0f, 1.0f, -1.0f},     // red
    1.21          {0.0f, 1.0f, 1.0f, -1.0f},      // green
    1.22          {-1.0f, 0.0f, 1.0f, -1.0f},     // blue
    1.23          {0.0f, 0.0f, 1.0f, -1.0f}       // white
    1.24      };
    1.25 -    count = sizeof(rects) / sizeof(SDL_FRect);
    1.26 +    count = sizeof(_rects) / sizeof(SDL_FRect);
    1.27 +#define rects _rects
    1.28  #endif
    1.29  
    1.30      for (int i = 0; i < count; ++i) {
     2.1 --- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun Feb 17 23:23:59 2013 -0500
     2.2 +++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Tue Feb 19 22:07:07 2013 -0500
     2.3 @@ -12,6 +12,8 @@
     2.4  #include "../../events/scancodes_windows.h"
     2.5  #include "SDL_events.h"
     2.6  #include "SDL_log.h"
     2.7 +#include "SDL_render.h"
     2.8 +#include "../../render/SDL_sysrender.h"
     2.9  }
    2.10  
    2.11  #include <string>
    2.12 @@ -168,6 +170,30 @@
    2.13          m_sdlWindowData->sdlWindow->fullscreen_mode = SDL_WinRTGlobalApp->GetMainDisplayMode();
    2.14          SDL_AddDisplayMode(&m_sdlVideoDevice->displays[0], &m_sdlWindowData->sdlWindow->fullscreen_mode);
    2.15  
    2.16 +        // HACK, Feb 19, 2013: SDL_WINDOWEVENT_RESIZED events, when sent,
    2.17 +        // will attempt to fix the values of the main window's renderer's
    2.18 +        // viewport.  While this can be good, it does appear to be buggy,
    2.19 +        // and can cause a fullscreen viewport to become corrupted.  This
    2.20 +        // behavior was noticed on a Surface RT while rotating the device
    2.21 +        // from landscape to portrait.  Oddly enough, this did not occur
    2.22 +        // in the Windows Simulator.
    2.23 +        //
    2.24 +        // Backing up, then restoring, the main renderer's 'resized' flag
    2.25 +        // seems to fix fullscreen viewport problems when rotating a
    2.26 +        // Windows device.
    2.27 +        //
    2.28 +        // Commencing hack in 3... 2... 1...
    2.29 +        SDL_Renderer * rendererForMainWindow = SDL_GetRenderer(m_sdlWindowData->sdlWindow);
    2.30 +        // For now, limit the hack to when the Direct3D 11.1 is getting used:
    2.31 +        const bool usingD3D11Renderer = \
    2.32 +            (rendererForMainWindow != NULL) &&
    2.33 +            (SDL_strcmp(rendererForMainWindow->info.name, "direct3d 11.1") == 0);
    2.34 +        SDL_bool wasD3D11RendererResized = SDL_FALSE;
    2.35 +        if (usingD3D11Renderer) {
    2.36 +            wasD3D11RendererResized = rendererForMainWindow->resized;
    2.37 +        }
    2.38 +
    2.39 +        // Send the window-resize event to the rest of SDL, and to apps:
    2.40          const int windowWidth = (int) ceil(args->Size.Width);
    2.41          const int windowHeight = (int) ceil(args->Size.Height);
    2.42          SDL_SendWindowEvent(
    2.43 @@ -175,6 +201,11 @@
    2.44              SDL_WINDOWEVENT_RESIZED,
    2.45              windowWidth,
    2.46              windowHeight);
    2.47 +
    2.48 +        // Viewport hack, part two:
    2.49 +        if (usingD3D11Renderer) {
    2.50 +            rendererForMainWindow->resized = wasD3D11RendererResized;
    2.51 +        }
    2.52      }
    2.53  }
    2.54