Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: another device-rotation and rendering fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Feb 20, 2013
1 parent 776330e commit 0998de6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/render/direct3d11/SDL_render_d3d11.cpp
Expand Up @@ -975,6 +975,9 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
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
Expand Down Expand Up @@ -1152,14 +1155,15 @@ D3D11_RenderFillRects(SDL_Renderer * renderer,

#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) {
Expand Down
31 changes: 31 additions & 0 deletions src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -12,6 +12,8 @@ extern "C" {
#include "../../events/scancodes_windows.h"
#include "SDL_events.h"
#include "SDL_log.h"
#include "SDL_render.h"
#include "../../render/SDL_sysrender.h"
}

#include <string>
Expand Down Expand Up @@ -168,13 +170,42 @@ void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEven
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(
m_sdlWindowData->sdlWindow,
SDL_WINDOWEVENT_RESIZED,
windowWidth,
windowHeight);

// Viewport hack, part two:
if (usingD3D11Renderer) {
rendererForMainWindow->resized = wasD3D11RendererResized;
}
}
}

Expand Down

0 comments on commit 0998de6

Please sign in to comment.