WinRT: rendering orientation fixes for Windows Phone, part 1 This change should allow apps to render correctly in Portrait mode, at minimum, Support for orientation changes is pending. Thanks to Pierre-Yves for assistance!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
diff --git a/src/render/direct3d11/SDL_render_d3d11.cpp b/src/render/direct3d11/SDL_render_d3d11.cpp
index 98b48ad..1de471a 100644
--- a/src/render/direct3d11/SDL_render_d3d11.cpp
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp
@@ -662,9 +662,14 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
// landscape-oriented width and height. If the window is in a portrait
// orientation, the dimensions must be reversed.
data->orientation = DisplayProperties::CurrentOrientation;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ const bool swapDimensions = false;
+#else
const bool swapDimensions =
data->orientation == DisplayOrientations::Portrait ||
data->orientation == DisplayOrientations::PortraitFlipped;
+#endif
data->renderTargetSize.x = swapDimensions ? windowHeight : windowWidth;
data->renderTargetSize.y = swapDimensions ? windowWidth : windowHeight;
@@ -785,6 +790,7 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
}
}
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// Set the proper orientation for the swap chain, and generate the
// 3D matrix transformation for rendering to the rotated swap chain.
DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
@@ -810,7 +816,6 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
throw ref new Platform::FailureException();
}
-#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
// TODO, WinRT: Windows Phone does not have the IDXGISwapChain1::SetRotation method. Check if an alternative is available, or needed.
result = data->swapChain->SetRotation(rotation);
if (FAILED(result)) {
@@ -1203,41 +1208,47 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
switch (data->orientation)
{
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ //
+ // Windows Phone rotations
+ //
case DisplayOrientations::Landscape:
- data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 0-degree Z-rotation
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- );
+ // 90-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(XM_PIDIV2));
break;
-
case DisplayOrientations::Portrait:
- data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 90-degree Z-rotation
- 0.0f, 1.0f, 0.0f, 0.0f,
- -1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- );
+ // 0-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixIdentity());
break;
-
case DisplayOrientations::LandscapeFlipped:
- data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 180-degree Z-rotation
- -1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, -1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- );
+ // 270-degree (-90 degree) Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(-XM_PIDIV2));
break;
-
case DisplayOrientations::PortraitFlipped:
- data->vertexShaderConstantsData.projection = XMFLOAT4X4( // 270-degree Z-rotation
- 0.0f, -1.0f, 0.0f, 0.0f,
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- );
+ // 180-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(XM_PI));
+ break;
+#else
+ //
+ // Non-Windows-Phone rotations (ex: Windows 8, Windows RT)
+ //
+ case DisplayOrientations::Landscape:
+ // 0-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixIdentity());
+ break;
+ case DisplayOrientations::Portrait:
+ // 90-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(XM_PIDIV2));
+ break;
+ case DisplayOrientations::LandscapeFlipped:
+ // 180-degree Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(XM_PI));
+ break;
+ case DisplayOrientations::PortraitFlipped:
+ // 270-degree (-90 degree) Z-rotation
+ XMStoreFloat4x4(&data->vertexShaderConstantsData.projection, XMMatrixRotationZ(-XM_PIDIV2));
break;
+#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
default:
SDL_SetError("An unknown DisplayOrientation is being used");
@@ -1270,9 +1281,13 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
// swap buffer's coordinate space, which is always in landscape:
//
SDL_FRect orientationAlignedViewport;
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ const bool swapDimensions = false;
+#else
const bool swapDimensions =
data->orientation == DisplayOrientations::Portrait ||
data->orientation == DisplayOrientations::PortraitFlipped;
+#endif
if (swapDimensions) {
orientationAlignedViewport.x = (float) renderer->viewport.y;
orientationAlignedViewport.y = (float) renderer->viewport.x;