WinRT: made sure the device orientation transform gets applied (by the D3D 11.1 renderer) when drawing
This commit is contained in:
parent
46530ef818
commit
8b75a125cc
3 changed files with 59 additions and 9 deletions
|
@ -339,6 +339,20 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
|
|||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setup space to hold vertex shader constants:
|
||||
//
|
||||
CD3D11_BUFFER_DESC constantBufferDesc(sizeof(SDL_VertexShaderConstants), D3D11_BIND_CONSTANT_BUFFER);
|
||||
result = data->d3dDevice->CreateBuffer(
|
||||
&constantBufferDesc,
|
||||
nullptr,
|
||||
&data->vertexShaderConstants
|
||||
);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(__FUNCTION__, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a vertex buffer:
|
||||
//
|
||||
|
@ -553,7 +567,7 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
{
|
||||
case DisplayOrientations::Landscape:
|
||||
rotation = DXGI_MODE_ROTATION_IDENTITY;
|
||||
data->orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation
|
||||
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,
|
||||
|
@ -563,9 +577,9 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
|
||||
case DisplayOrientations::Portrait:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE270;
|
||||
data->orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f, 0.0f,
|
||||
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
|
||||
);
|
||||
|
@ -573,7 +587,7 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE180;
|
||||
data->orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation
|
||||
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,
|
||||
|
@ -583,9 +597,9 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE90;
|
||||
data->orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
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
|
||||
);
|
||||
|
@ -891,6 +905,15 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
nullptr
|
||||
);
|
||||
|
||||
rendererData->d3dContext->UpdateSubresource(
|
||||
rendererData->vertexShaderConstants.Get(),
|
||||
0,
|
||||
NULL,
|
||||
&rendererData->vertexShaderConstantsData,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
UINT stride = sizeof(VertexPositionColor);
|
||||
UINT offset = 0;
|
||||
rendererData->d3dContext->IASetVertexBuffers(
|
||||
|
@ -911,6 +934,12 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
0
|
||||
);
|
||||
|
||||
rendererData->d3dContext->VSSetConstantBuffers(
|
||||
0,
|
||||
1,
|
||||
rendererData->vertexShaderConstants.GetAddressOf()
|
||||
);
|
||||
|
||||
rendererData->d3dContext->PSSetShader(
|
||||
rendererData->pixelShader.Get(),
|
||||
nullptr,
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
#include <DirectXMath.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
struct SDL_VertexShaderConstants
|
||||
{
|
||||
DirectX::XMFLOAT4X4 projection;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice;
|
||||
|
@ -39,6 +44,10 @@ typedef struct
|
|||
unsigned int vertexCount;
|
||||
bool loadingComplete;
|
||||
|
||||
// Vertex buffer constants:
|
||||
SDL_VertexShaderConstants vertexShaderConstantsData;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> vertexShaderConstants;
|
||||
|
||||
// Cached renderer properties.
|
||||
DirectX::XMFLOAT2 windowSizeInDIPs;
|
||||
DirectX::XMFLOAT2 renderTargetSize;
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
|
||||
//#pragma pack_matrix( row_major )
|
||||
|
||||
cbuffer SDL_VertexShaderConstants : register(b0)
|
||||
{
|
||||
matrix projection;
|
||||
};
|
||||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float3 pos : POSITION;
|
||||
|
@ -16,7 +21,14 @@ struct VertexShaderOutput
|
|||
VertexShaderOutput main(VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output;
|
||||
output.pos = float4(input.pos, 1.0f);
|
||||
float4 pos = float4(input.pos, 1.0f);
|
||||
|
||||
// Transform the vertex position into projected space.
|
||||
pos = mul(pos, projection);
|
||||
output.pos = pos;
|
||||
|
||||
// Pass through the texture's color without modification.
|
||||
output.tex = input.tex;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue