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

Commit

Permalink
Browse files Browse the repository at this point in the history
WinRT: fixed bug: SDL_RenderCopy was always filling the entire screen
  • Loading branch information
DavidLudwig committed Feb 13, 2013
1 parent 7f614fb commit 6dd4030
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
52 changes: 47 additions & 5 deletions src/render/direct3d11/SDL_render_d3d11.cpp
Expand Up @@ -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!
//
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/render/direct3d11/SDL_render_d3d11_cpp.h
Expand Up @@ -26,6 +26,7 @@

struct SDL_VertexShaderConstants
{
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};

Expand All @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/video/windowsrt/SimpleVertexShader.hlsl
@@ -1,8 +1,9 @@

//#pragma pack_matrix( row_major )
#pragma pack_matrix( row_major )

cbuffer SDL_VertexShaderConstants : register(b0)
{
matrix view;
matrix projection;
};

Expand All @@ -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;

Expand Down

0 comments on commit 6dd4030

Please sign in to comment.