WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
authorDavid Ludwig <dludwig@pobox.com>
Sat, 16 Feb 2013 09:10:43 -0500
changeset 8429a8b45a923fbd
parent 8428 68c454170403
child 8430 87a1dbf2d1d2
WinRT: implemented SDL_RenderFillRect and SDL_RenderFillRects for the D3D 11.1 renderer
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj
VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj
VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters
src/render/direct3d11/SDL_D3D11_PixelShader_FixedColor.hlsl
src/render/direct3d11/SDL_D3D11_PixelShader_TextureCopy.hlsl
src/render/direct3d11/SDL_render_d3d11.cpp
src/render/direct3d11/SDL_render_d3d11_cpp.h
src/video/windowsrt/SimplePixelShader.hlsl
src/video/windowsrt/SimpleVertexShader.hlsl
     1.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Tue Feb 12 21:26:04 2013 -0500
     1.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj	Sat Feb 16 09:10:43 2013 -0500
     1.3 @@ -378,8 +378,13 @@
     1.4      </ClCompile>
     1.5    </ItemGroup>
     1.6    <ItemGroup>
     1.7 -    <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
     1.8 -      <FileType>Document</FileType>
     1.9 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
    1.10 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
    1.11 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
    1.12 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
    1.13 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
    1.14 +    </FxCompile>
    1.15 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
    1.16        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
    1.17        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
    1.18        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
     2.1 --- a/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Tue Feb 12 21:26:04 2013 -0500
     2.2 +++ b/VisualC-WinPhone/SDL/SDL_VS2012-WinPhone.vcxproj.filters	Sat Feb 16 09:10:43 2013 -0500
     2.3 @@ -598,10 +598,13 @@
     2.4      </ClCompile>
     2.5    </ItemGroup>
     2.6    <ItemGroup>
     2.7 -    <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
     2.8 +    <FxCompile Include="..\..\src\video\windowsrt\SimpleVertexShader.hlsl">
     2.9        <Filter>GPU Shaders</Filter>
    2.10      </FxCompile>
    2.11 -    <FxCompile Include="..\..\src\video\windowsrt\SimpleVertexShader.hlsl">
    2.12 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
    2.13 +      <Filter>GPU Shaders</Filter>
    2.14 +    </FxCompile>
    2.15 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
    2.16        <Filter>GPU Shaders</Filter>
    2.17      </FxCompile>
    2.18    </ItemGroup>
     3.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Tue Feb 12 21:26:04 2013 -0500
     3.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj	Sat Feb 16 09:10:43 2013 -0500
     3.3 @@ -281,11 +281,18 @@
     3.4      <ClInclude Include="..\..\src\video\windowsrt\SDL_winrtvideo.h" />
     3.5    </ItemGroup>
     3.6    <ItemGroup>
     3.7 -    <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
     3.8 -      <FileType>Document</FileType>
     3.9 -      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
    3.10 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
    3.11        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
    3.12        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
    3.13 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
    3.14 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
    3.15 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
    3.16 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
    3.17 +    </FxCompile>
    3.18 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
    3.19 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
    3.20 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
    3.21 +      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
    3.22        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
    3.23        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
    3.24        <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
     4.1 --- a/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Tue Feb 12 21:26:04 2013 -0500
     4.2 +++ b/VisualC-WinRT/SDL/SDL_VS2012-WinRT.vcxproj.filters	Sat Feb 16 09:10:43 2013 -0500
     4.3 @@ -1,10 +1,13 @@
     4.4  <?xml version="1.0" encoding="utf-8"?>
     4.5  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     4.6    <ItemGroup>
     4.7 -    <FxCompile Include="..\..\src\video\windowsrt\SimplePixelShader.hlsl">
     4.8 +    <FxCompile Include="..\..\src\video\windowsrt\SimpleVertexShader.hlsl">
     4.9        <Filter>GPU Shaders</Filter>
    4.10      </FxCompile>
    4.11 -    <FxCompile Include="..\..\src\video\windowsrt\SimpleVertexShader.hlsl">
    4.12 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_TextureCopy.hlsl">
    4.13 +      <Filter>GPU Shaders</Filter>
    4.14 +    </FxCompile>
    4.15 +    <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
    4.16        <Filter>GPU Shaders</Filter>
    4.17      </FxCompile>
    4.18    </ItemGroup>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/render/direct3d11/SDL_D3D11_PixelShader_FixedColor.hlsl	Sat Feb 16 09:10:43 2013 -0500
     5.3 @@ -0,0 +1,12 @@
     5.4 +
     5.5 +struct PixelShaderInput
     5.6 +{
     5.7 +    float4 pos : SV_POSITION;
     5.8 +    float2 tex : TEXCOORD0;
     5.9 +    float4 color : COLOR0;
    5.10 +};
    5.11 +
    5.12 +float4 main(PixelShaderInput input) : SV_TARGET
    5.13 +{
    5.14 +    return input.color;
    5.15 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/render/direct3d11/SDL_D3D11_PixelShader_TextureCopy.hlsl	Sat Feb 16 09:10:43 2013 -0500
     6.3 @@ -0,0 +1,14 @@
     6.4 +Texture2D theTexture : register(t0);
     6.5 +SamplerState theSampler : register(s0);
     6.6 +
     6.7 +struct PixelShaderInput
     6.8 +{
     6.9 +    float4 pos : SV_POSITION;
    6.10 +    float2 tex : TEXCOORD0;
    6.11 +    float4 color : COLOR0;
    6.12 +};
    6.13 +
    6.14 +float4 main(PixelShaderInput input) : SV_TARGET
    6.15 +{
    6.16 +    return theTexture.Sample(theSampler, input.tex);
    6.17 +}
     7.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Tue Feb 12 21:26:04 2013 -0500
     7.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 16 09:10:43 2013 -0500
     7.3 @@ -67,8 +67,8 @@
     7.4  //                                const SDL_FPoint * points, int count);
     7.5  //static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
     7.6  //                               const SDL_FPoint * points, int count);
     7.7 -//static int D3D11_RenderFillRects(SDL_Renderer * renderer,
     7.8 -//                               const SDL_FRect * rects, int count);
     7.9 +static int D3D11_RenderFillRects(SDL_Renderer * renderer,
    7.10 +                                 const SDL_FRect * rects, int count);
    7.11  static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    7.12                              const SDL_Rect * srcrect, const SDL_FRect * dstrect);
    7.13  //static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
    7.14 @@ -140,7 +140,7 @@
    7.15      renderer->RenderClear = D3D11_RenderClear;
    7.16      //renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
    7.17      //renderer->RenderDrawLines = D3D11_RenderDrawLines;
    7.18 -    //renderer->RenderFillRects = D3D11_RenderFillRects;
    7.19 +    renderer->RenderFillRects = D3D11_RenderFillRects;
    7.20      renderer->RenderCopy = D3D11_RenderCopy;
    7.21      //renderer->RenderCopyEx = D3D11_RenderCopyEx;
    7.22      //renderer->RenderReadPixels = D3D11_RenderReadPixels;
    7.23 @@ -212,6 +212,34 @@
    7.24      return D3D11_ReadFileContents(fileName, out);
    7.25  }
    7.26  
    7.27 +static HRESULT
    7.28 +D3D11_LoadPixelShader(SDL_Renderer * renderer,
    7.29 +                      const wstring & shaderName,
    7.30 +                      ID3D11PixelShader ** shaderOutput)
    7.31 +{
    7.32 +    D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
    7.33 +    HRESULT result = S_OK;
    7.34 +    vector<char> fileData;
    7.35 +    
    7.36 +    if (!D3D11_ReadShaderContents(shaderName, fileData)) {
    7.37 +        SDL_SetError("Unable to open SDL's pixel shader file.");
    7.38 +        return E_FAIL;
    7.39 +    }
    7.40 +
    7.41 +    result = data->d3dDevice->CreatePixelShader(
    7.42 +        &fileData[0],
    7.43 +        fileData.size(),
    7.44 +        nullptr,
    7.45 +        shaderOutput
    7.46 +        );
    7.47 +    if (FAILED(result)) {
    7.48 +        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
    7.49 +        return result;
    7.50 +    }
    7.51 +
    7.52 +    return S_OK;
    7.53 +}
    7.54 +
    7.55  // Create resources that depend on the device.
    7.56  HRESULT
    7.57  D3D11_CreateDeviceResources(SDL_Renderer * renderer)
    7.58 @@ -276,12 +304,10 @@
    7.59          return result;
    7.60      }
    7.61  
    7.62 -    // Start loading GPU shaders:
    7.63 -    vector<char> fileData;
    7.64 -
    7.65      //
    7.66      // Load in SDL's one and only vertex shader:
    7.67      //
    7.68 +    vector<char> fileData;
    7.69      if (!D3D11_ReadShaderContents(L"SimpleVertexShader.cso", fileData)) {
    7.70          SDL_SetError("Unable to open SDL's vertex shader file.");
    7.71          return E_FAIL;
    7.72 @@ -303,8 +329,9 @@
    7.73      //
    7.74      const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
    7.75      {
    7.76 -        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
    7.77 +        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    7.78          { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    7.79 +        { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    7.80      };
    7.81  
    7.82      result = data->d3dDevice->CreateInputLayout(
    7.83 @@ -320,21 +347,17 @@
    7.84      }
    7.85  
    7.86      //
    7.87 -    // Load in SDL's one and only pixel shader (for now, more are likely to follow):
    7.88 +    // Load in SDL's pixel shaders
    7.89      //
    7.90 -    if (!D3D11_ReadShaderContents(L"SimplePixelShader.cso", fileData)) {
    7.91 -        SDL_SetError("Unable to open SDL's pixel shader file.");
    7.92 -        return E_FAIL;
    7.93 +    result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_TextureCopy.cso", &data->texturePixelShader);
    7.94 +    if (FAILED(result)) {
    7.95 +        // D3D11_LoadPixelShader will have aleady set the SDL error
    7.96 +        return result;
    7.97      }
    7.98  
    7.99 -    result = data->d3dDevice->CreatePixelShader(
   7.100 -        &fileData[0],
   7.101 -        fileData.size(),
   7.102 -        nullptr,
   7.103 -        &data->pixelShader
   7.104 -        );
   7.105 +    result = D3D11_LoadPixelShader(renderer, L"SDL_D3D11_PixelShader_FixedColor.cso", &data->colorPixelShader);
   7.106      if (FAILED(result)) {
   7.107 -        WIN_SetErrorFromHRESULT(__FUNCTION__, result);
   7.108 +        // D3D11_LoadPixelShader will have aleady set the SDL error
   7.109          return result;
   7.110      }
   7.111  
   7.112 @@ -900,55 +923,21 @@
   7.113      return 0;
   7.114  }
   7.115  
   7.116 -static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   7.117 -                            const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   7.118 +static int
   7.119 +D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
   7.120 +                         const void * vertexData, unsigned int dataSizeInBytes)
   7.121  {
   7.122      D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.123 -    D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
   7.124      HRESULT result = S_OK;
   7.125 -
   7.126 -    rendererData->d3dContext->OMSetRenderTargets(
   7.127 -        1,
   7.128 -        rendererData->renderTargetView.GetAddressOf(),
   7.129 -        nullptr
   7.130 -        );
   7.131 -
   7.132 -    rendererData->d3dContext->UpdateSubresource(
   7.133 -        rendererData->vertexShaderConstants.Get(),
   7.134 -		0,
   7.135 -		NULL,
   7.136 -		&rendererData->vertexShaderConstantsData,
   7.137 -		0,
   7.138 -		0
   7.139 -		);
   7.140 -
   7.141 -    //
   7.142 -    // Create or update the vertex buffer:
   7.143 -    //
   7.144 -
   7.145 -    // WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
   7.146 -    //SDL_FRect fSrcRect;
   7.147 -    //fSrcRect.x = (float)srcrect->x;
   7.148 -    //fSrcRect.y = (float)srcrect->y;
   7.149 -    //fSrcRect.w = (float)srcrect->w;
   7.150 -    //fSrcRect.h = (float)srcrect->h;
   7.151 -
   7.152 -    VertexPositionColor vertices[] =
   7.153 -    {
   7.154 -        {XMFLOAT3(dstrect->x, dstrect->y, 0.0f),                           XMFLOAT2(0.0f, 0.0f)},
   7.155 -        {XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f),              XMFLOAT2(0.0f, 1.0f)},
   7.156 -        {XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f),              XMFLOAT2(1.0f, 0.0f)},
   7.157 -        {XMFLOAT3(dstrect->x + dstrect->w, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(1.0f, 1.0f)},
   7.158 -    };
   7.159  
   7.160      if (rendererData->vertexBuffer) {
   7.161 -        rendererData->d3dContext->UpdateSubresource(rendererData->vertexBuffer.Get(), 0, NULL, vertices, sizeof(vertices), 0);
   7.162 +        rendererData->d3dContext->UpdateSubresource(rendererData->vertexBuffer.Get(), 0, NULL, vertexData, dataSizeInBytes, 0);
   7.163      } else {
   7.164          D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
   7.165 -        vertexBufferData.pSysMem = vertices;
   7.166 +        vertexBufferData.pSysMem = vertexData;
   7.167          vertexBufferData.SysMemPitch = 0;
   7.168          vertexBufferData.SysMemSlicePitch = 0;
   7.169 -        CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
   7.170 +        CD3D11_BUFFER_DESC vertexBufferDesc(dataSizeInBytes, D3D11_BIND_VERTEX_BUFFER);
   7.171          result = rendererData->d3dDevice->CreateBuffer(
   7.172              &vertexBufferDesc,
   7.173              &vertexBufferData,
   7.174 @@ -968,37 +957,121 @@
   7.175          rendererData->vertexBuffer.GetAddressOf(),
   7.176          &stride,
   7.177          &offset
   7.178 +        );
   7.179 +
   7.180 +    return 0;
   7.181 +}
   7.182 +
   7.183 +static void
   7.184 +D3D11_RenderStartDrawOp(SDL_Renderer * renderer)
   7.185 +{
   7.186 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.187 +
   7.188 +    rendererData->d3dContext->OMSetRenderTargets(
   7.189 +        1,
   7.190 +        rendererData->renderTargetView.GetAddressOf(),
   7.191 +        nullptr
   7.192          );
   7.193  
   7.194 -    rendererData->d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
   7.195 +    rendererData->d3dContext->UpdateSubresource(
   7.196 +        rendererData->vertexShaderConstants.Get(),
   7.197 +		0,
   7.198 +		NULL,
   7.199 +		&rendererData->vertexShaderConstantsData,
   7.200 +		0,
   7.201 +		0
   7.202 +		);
   7.203 +}
   7.204 +
   7.205 +static void
   7.206 +D3D11_SetPixelShader(SDL_Renderer * renderer,
   7.207 +                     ID3D11PixelShader * shader,
   7.208 +                     ID3D11ShaderResourceView * shaderResource,
   7.209 +                     ID3D11SamplerState * sampler)
   7.210 +{
   7.211 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.212 +    rendererData->d3dContext->PSSetShader(shader, nullptr, 0);
   7.213 +    rendererData->d3dContext->PSSetShaderResources(0, 1, &shaderResource);
   7.214 +    rendererData->d3dContext->PSSetSamplers(0, 1, &sampler);
   7.215 +}
   7.216 +
   7.217 +static void
   7.218 +D3D11_RenderFinishDrawOp(SDL_Renderer * renderer,
   7.219 +                         D3D11_PRIMITIVE_TOPOLOGY primitiveTopology)
   7.220 +{
   7.221 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.222 +    rendererData->d3dContext->IASetPrimitiveTopology(primitiveTopology);
   7.223 +    rendererData->d3dContext->IASetInputLayout(rendererData->inputLayout.Get());
   7.224 +    rendererData->d3dContext->VSSetShader(rendererData->vertexShader.Get(), nullptr, 0);
   7.225 +    rendererData->d3dContext->VSSetConstantBuffers(0, 1, rendererData->vertexShaderConstants.GetAddressOf());
   7.226 +    rendererData->d3dContext->RSSetState(rendererData->mainRasterizer.Get());
   7.227 +    rendererData->d3dContext->Draw(4, 0);
   7.228 +}
   7.229 +
   7.230 +static int
   7.231 +D3D11_RenderFillRects(SDL_Renderer * renderer,
   7.232 +                      const SDL_FRect * rects, int count)
   7.233 +{
   7.234 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.235 +    float r, g, b, a;
   7.236 +
   7.237 +    r = (float)(renderer->r / 255);
   7.238 +    g = (float)(renderer->g / 255);
   7.239 +    b = (float)(renderer->b / 255);
   7.240 +    a = (float)(renderer->a / 255);
   7.241 +
   7.242 +    D3D11_RenderStartDrawOp(renderer);
   7.243 +
   7.244 +    for (int i = 0; i < count; ++i) {
   7.245 +        VertexPositionColor vertices[] = {
   7.246 +            {XMFLOAT3(rects[i].x, rects[i].y, 0.0f),                           XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)},
   7.247 +            {XMFLOAT3(rects[i].x, rects[i].y + rects[i].h, 0.0f),              XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)},
   7.248 +            {XMFLOAT3(rects[i].x + rects[i].w, rects[i].y, 0.0f),              XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)},
   7.249 +            {XMFLOAT3(rects[i].x + rects[i].w, rects[i].y + rects[i].h, 0.0f), XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)},
   7.250 +        };
   7.251 +        if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
   7.252 +            return -1;
   7.253 +        }
   7.254  
   7.255 -    rendererData->d3dContext->IASetInputLayout(rendererData->inputLayout.Get());
   7.256 +        D3D11_SetPixelShader(
   7.257 +            renderer,
   7.258 +            rendererData->colorPixelShader.Get(),
   7.259 +            nullptr,
   7.260 +            nullptr);
   7.261  
   7.262 -    rendererData->d3dContext->VSSetShader(
   7.263 -        rendererData->vertexShader.Get(),
   7.264 -        nullptr,
   7.265 -        0
   7.266 -        );
   7.267 +        D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
   7.268 +    }
   7.269 +
   7.270 +    return 0;
   7.271 +}
   7.272 +
   7.273 +static int
   7.274 +D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   7.275 +                 const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   7.276 +{
   7.277 +    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
   7.278 +    D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
   7.279 +
   7.280 +    D3D11_RenderStartDrawOp(renderer);
   7.281  
   7.282 -    rendererData->d3dContext->VSSetConstantBuffers(
   7.283 -		0,
   7.284 -		1,
   7.285 -        rendererData->vertexShaderConstants.GetAddressOf()
   7.286 -		);
   7.287 +    // WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
   7.288 +    VertexPositionColor vertices[] = {
   7.289 +        {XMFLOAT3(dstrect->x, dstrect->y, 0.0f),                           XMFLOAT2(0.0f, 0.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
   7.290 +        {XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f),              XMFLOAT2(0.0f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
   7.291 +        {XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f),              XMFLOAT2(1.0f, 0.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
   7.292 +        {XMFLOAT3(dstrect->x + dstrect->w, dstrect->y + dstrect->h, 0.0f), XMFLOAT2(1.0f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
   7.293 +    };
   7.294 +    if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
   7.295 +        return -1;
   7.296 +    }
   7.297  
   7.298 -    rendererData->d3dContext->PSSetShader(
   7.299 -        rendererData->pixelShader.Get(),
   7.300 -        nullptr,
   7.301 -        0
   7.302 -        );
   7.303 +    D3D11_SetPixelShader(
   7.304 +        renderer,
   7.305 +        rendererData->texturePixelShader.Get(),
   7.306 +        textureData->mainTextureResourceView.Get(),
   7.307 +        rendererData->mainSampler.Get());
   7.308  
   7.309 -    rendererData->d3dContext->PSSetShaderResources(0, 1, textureData->mainTextureResourceView.GetAddressOf());
   7.310 -
   7.311 -    rendererData->d3dContext->PSSetSamplers(0, 1, rendererData->mainSampler.GetAddressOf());
   7.312 -
   7.313 -    rendererData->d3dContext->RSSetState(rendererData->mainRasterizer.Get());
   7.314 -
   7.315 -    rendererData->d3dContext->Draw(4, 0);
   7.316 +    D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
   7.317  
   7.318      return 0;
   7.319  }
     8.1 --- a/src/render/direct3d11/SDL_render_d3d11_cpp.h	Tue Feb 12 21:26:04 2013 -0500
     8.2 +++ b/src/render/direct3d11/SDL_render_d3d11_cpp.h	Sat Feb 16 09:10:43 2013 -0500
     8.3 @@ -39,7 +39,8 @@
     8.4      Microsoft::WRL::ComPtr<ID3D11InputLayout> inputLayout;
     8.5      Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBuffer;
     8.6      Microsoft::WRL::ComPtr<ID3D11VertexShader> vertexShader;
     8.7 -    Microsoft::WRL::ComPtr<ID3D11PixelShader> pixelShader;
     8.8 +    Microsoft::WRL::ComPtr<ID3D11PixelShader> texturePixelShader;
     8.9 +    Microsoft::WRL::ComPtr<ID3D11PixelShader> colorPixelShader;
    8.10      Microsoft::WRL::ComPtr<ID3D11SamplerState> mainSampler;
    8.11      Microsoft::WRL::ComPtr<ID3D11RasterizerState> mainRasterizer;
    8.12      D3D_FEATURE_LEVEL featureLevel;
    8.13 @@ -69,6 +70,7 @@
    8.14  {
    8.15      DirectX::XMFLOAT3 pos;
    8.16      DirectX::XMFLOAT2 tex;
    8.17 +    DirectX::XMFLOAT4 color;
    8.18  };
    8.19  
    8.20  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/windowsrt/SimplePixelShader.hlsl	Tue Feb 12 21:26:04 2013 -0500
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,15 +0,0 @@
     9.4 -Texture2D theTexture : register(t0);
     9.5 -SamplerState theSampler : register(s0);
     9.6 -
     9.7 -struct PixelShaderInput
     9.8 -{
     9.9 -    float4 pos : SV_POSITION;
    9.10 -
    9.11 -    float2 tex : TEXCOORD0;
    9.12 -};
    9.13 -
    9.14 -float4 main(PixelShaderInput input) : SV_TARGET
    9.15 -{
    9.16 -    //return float4(input.color,1.0f);
    9.17 -    return theTexture.Sample(theSampler, input.tex);
    9.18 -}
    10.1 --- a/src/video/windowsrt/SimpleVertexShader.hlsl	Tue Feb 12 21:26:04 2013 -0500
    10.2 +++ b/src/video/windowsrt/SimpleVertexShader.hlsl	Sat Feb 16 09:10:43 2013 -0500
    10.3 @@ -11,12 +11,14 @@
    10.4  {
    10.5      float3 pos : POSITION;
    10.6      float2 tex : TEXCOORD0;
    10.7 +    float4 color : COLOR0;
    10.8  };
    10.9  
   10.10  struct VertexShaderOutput
   10.11  {
   10.12      float4 pos : SV_POSITION;
   10.13      float2 tex : TEXCOORD0;
   10.14 +    float4 color : COLOR0;
   10.15  };
   10.16  
   10.17  VertexShaderOutput main(VertexShaderInput input)
   10.18 @@ -29,8 +31,9 @@
   10.19      pos = mul(pos, projection);
   10.20      output.pos = pos;
   10.21  
   10.22 -    // Pass through the texture's color without modification.
   10.23 +    // Pass through texture coordinates and color values without transformation
   10.24      output.tex = input.tex;
   10.25 +    output.color = input.color;
   10.26  
   10.27      return output;
   10.28  }