WinRT: added rotation support to SDL_RenderCopyEx via D3D 11.1
This commit is contained in:
parent
5230205e27
commit
b7887dd326
3 changed files with 41 additions and 17 deletions
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
cbuffer SDL_VertexShaderConstants : register(b0)
|
cbuffer SDL_VertexShaderConstants : register(b0)
|
||||||
{
|
{
|
||||||
matrix view;
|
matrix model;
|
||||||
matrix projection;
|
matrix view;
|
||||||
|
matrix projection;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexShaderInput
|
struct VertexShaderInput
|
||||||
|
@ -27,6 +28,7 @@ VertexShaderOutput main(VertexShaderInput input)
|
||||||
float4 pos = float4(input.pos, 1.0f);
|
float4 pos = float4(input.pos, 1.0f);
|
||||||
|
|
||||||
// Transform the vertex position into projected space.
|
// Transform the vertex position into projected space.
|
||||||
|
pos = mul(pos, model);
|
||||||
pos = mul(pos, view);
|
pos = mul(pos, view);
|
||||||
pos = mul(pos, projection);
|
pos = mul(pos, projection);
|
||||||
output.pos = pos;
|
output.pos = pos;
|
||||||
|
|
|
@ -1129,6 +1129,11 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
|
||||||
data->vertexShaderConstantsData.view = XMMatrixIdentity();
|
data->vertexShaderConstantsData.view = XMMatrixIdentity();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reset the model matrix
|
||||||
|
//
|
||||||
|
XMStoreFloat4x4(&data->vertexShaderConstantsData.model, XMMatrixIdentity());
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update the Direct3D viewport, which seems to be aligned to the
|
// Update the Direct3D viewport, which seems to be aligned to the
|
||||||
// swap buffer's coordinate space, which is always in landscape:
|
// swap buffer's coordinate space, which is always in landscape:
|
||||||
|
@ -1250,15 +1255,6 @@ D3D11_RenderStartDrawOp(SDL_Renderer * renderer)
|
||||||
rendererData->renderTargetView.GetAddressOf(),
|
rendererData->renderTargetView.GetAddressOf(),
|
||||||
nullptr
|
nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
rendererData->d3dContext->UpdateSubresource(
|
|
||||||
rendererData->vertexShaderConstants.Get(),
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
&rendererData->vertexShaderConstantsData,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1299,6 +1295,16 @@ D3D11_RenderFinishDrawOp(SDL_Renderer * renderer,
|
||||||
UINT vertexCount)
|
UINT vertexCount)
|
||||||
{
|
{
|
||||||
D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
|
D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
|
||||||
|
|
||||||
|
rendererData->d3dContext->UpdateSubresource(
|
||||||
|
rendererData->vertexShaderConstants.Get(),
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
&rendererData->vertexShaderConstantsData,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
rendererData->d3dContext->IASetPrimitiveTopology(primitiveTopology);
|
rendererData->d3dContext->IASetPrimitiveTopology(primitiveTopology);
|
||||||
rendererData->d3dContext->IASetInputLayout(rendererData->inputLayout.Get());
|
rendererData->d3dContext->IASetInputLayout(rendererData->inputLayout.Get());
|
||||||
rendererData->d3dContext->VSSetShader(rendererData->vertexShader.Get(), nullptr, 0);
|
rendererData->d3dContext->VSSetShader(rendererData->vertexShader.Get(), nullptr, 0);
|
||||||
|
@ -1504,12 +1510,25 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||||
maxv = minv;
|
maxv = minv;
|
||||||
minv = tmp;
|
minv = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMFLOAT4X4 oldModelMatrix = rendererData->vertexShaderConstantsData.model;
|
||||||
|
XMStoreFloat4x4(
|
||||||
|
&rendererData->vertexShaderConstantsData.model,
|
||||||
|
XMMatrixMultiply(
|
||||||
|
XMMatrixRotationZ((float)(XM_PI * (float) angle / 180.0f)),
|
||||||
|
XMMatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
|
||||||
|
));
|
||||||
|
|
||||||
|
const float minx = -center->x;
|
||||||
|
const float maxx = dstrect->w - center->x;
|
||||||
|
const float miny = -center->y;
|
||||||
|
const float maxy = dstrect->h - center->y;
|
||||||
|
|
||||||
VertexPositionColor vertices[] = {
|
VertexPositionColor vertices[] = {
|
||||||
{XMFLOAT3(dstrect->x, dstrect->y, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
{XMFLOAT3(minx, miny, 0.0f), XMFLOAT2(minu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
||||||
{XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
{XMFLOAT3(minx, maxy, 0.0f), XMFLOAT2(minu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
||||||
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
{XMFLOAT3(maxx, miny, 0.0f), XMFLOAT2(maxu, minv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
||||||
{XMFLOAT3(dstrect->x + dstrect->w, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
{XMFLOAT3(maxx, maxy, 0.0f), XMFLOAT2(maxu, maxv), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
|
||||||
};
|
};
|
||||||
if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
|
if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1522,6 +1541,8 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||||
rendererData->mainSampler.Get());
|
rendererData->mainSampler.Get());
|
||||||
|
|
||||||
D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
|
D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
|
||||||
|
|
||||||
|
rendererData->vertexShaderConstantsData.model = oldModelMatrix;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@
|
||||||
|
|
||||||
struct SDL_VertexShaderConstants
|
struct SDL_VertexShaderConstants
|
||||||
{
|
{
|
||||||
DirectX::XMFLOAT4X4 view;
|
DirectX::XMFLOAT4X4 model;
|
||||||
DirectX::XMFLOAT4X4 projection;
|
DirectX::XMFLOAT4X4 view;
|
||||||
|
DirectX::XMFLOAT4X4 projection;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue