WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
This commit is contained in:
parent
48ce80d49a
commit
5e66f60ffa
3 changed files with 52 additions and 6 deletions
|
@ -384,6 +384,27 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
|
|||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setup the Direct3D rasterizer
|
||||
//
|
||||
D3D11_RASTERIZER_DESC rasterDesc;
|
||||
memset(&rasterDesc, 0, sizeof(rasterDesc));
|
||||
rasterDesc.AntialiasedLineEnable = false;
|
||||
rasterDesc.CullMode = D3D11_CULL_NONE;
|
||||
rasterDesc.DepthBias = 0;
|
||||
rasterDesc.DepthBiasClamp = 0.0f;
|
||||
rasterDesc.DepthClipEnable = true;
|
||||
rasterDesc.FillMode = D3D11_FILL_SOLID;
|
||||
rasterDesc.FrontCounterClockwise = false;
|
||||
rasterDesc.MultisampleEnable = false;
|
||||
rasterDesc.ScissorEnable = false;
|
||||
rasterDesc.SlopeScaledDepthBias = 0.0f;
|
||||
result = data->d3dDevice->CreateRasterizerState(&rasterDesc, &data->mainRasterizer);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(__FUNCTION__, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// All done!
|
||||
//
|
||||
|
@ -595,6 +616,17 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Update the view matrix
|
||||
//
|
||||
XMStoreFloat4x4(&data->vertexShaderConstantsData.view, // (4)
|
||||
XMMatrixMultiply(
|
||||
XMMatrixScaling(2.0f / windowWidth, 2.0f / windowHeight, 1.0f),
|
||||
XMMatrixMultiply(
|
||||
XMMatrixTranslation(-1, -1, 0),
|
||||
XMMatrixRotationX(XM_PI)
|
||||
)));
|
||||
|
||||
// Create a render target view of the swap chain back buffer.
|
||||
ComPtr<ID3D11Texture2D> backBuffer;
|
||||
result = data->swapChain->GetBuffer(
|
||||
|
@ -893,12 +925,20 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
//
|
||||
// Create or update the vertex buffer:
|
||||
//
|
||||
VertexPositionColor vertices[] =
|
||||
|
||||
// WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
|
||||
//SDL_FRect fSrcRect;
|
||||
//fSrcRect.x = (float)srcrect->x;
|
||||
//fSrcRect.y = (float)srcrect->y;
|
||||
//fSrcRect.w = (float)srcrect->w;
|
||||
//fSrcRect.h = (float)srcrect->h;
|
||||
|
||||
VertexPositionColor vertices[] =
|
||||
{
|
||||
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
|
||||
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
|
||||
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
|
||||
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
|
||||
{XMFLOAT3(dstrect->x, dstrect->y, 0.0f), XMFLOAT2(0.0f, 0.0f)},
|
||||
{XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(0.0f, 1.0f)},
|
||||
{XMFLOAT3(dstrect->x + dstrect->h, dstrect->y, 0.0f), XMFLOAT2(1.0f, 0.0f)},
|
||||
{XMFLOAT3(dstrect->x + dstrect->h, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(1.0f, 1.0f)},
|
||||
};
|
||||
|
||||
if (rendererData->vertexBuffer) {
|
||||
|
@ -956,6 +996,8 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
|
||||
rendererData->d3dContext->PSSetSamplers(0, 1, rendererData->mainSampler.GetAddressOf());
|
||||
|
||||
rendererData->d3dContext->RSSetState(rendererData->mainRasterizer.Get());
|
||||
|
||||
rendererData->d3dContext->Draw(4, 0);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
struct SDL_VertexShaderConstants
|
||||
{
|
||||
DirectX::XMFLOAT4X4 view;
|
||||
DirectX::XMFLOAT4X4 projection;
|
||||
};
|
||||
|
||||
|
@ -40,6 +41,7 @@ typedef struct
|
|||
Microsoft::WRL::ComPtr<ID3D11VertexShader> vertexShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> pixelShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> mainSampler;
|
||||
Microsoft::WRL::ComPtr<ID3D11RasterizerState> mainRasterizer;
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
bool loadingComplete;
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
//#pragma pack_matrix( row_major )
|
||||
#pragma pack_matrix( row_major )
|
||||
|
||||
cbuffer SDL_VertexShaderConstants : register(b0)
|
||||
{
|
||||
matrix view;
|
||||
matrix projection;
|
||||
};
|
||||
|
||||
|
@ -24,6 +25,7 @@ VertexShaderOutput main(VertexShaderInput input)
|
|||
float4 pos = float4(input.pos, 1.0f);
|
||||
|
||||
// Transform the vertex position into projected space.
|
||||
pos = mul(pos, view);
|
||||
pos = mul(pos, projection);
|
||||
output.pos = pos;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue