WinRT: made the D3D 11.1 renderer respect the 'srcrect' parameter of SDL_RenderCopy
authorDavid Ludwig <dludwig@pobox.com>
Sun, 24 Feb 2013 12:27:28 -0500
changeset 8448 a85b3f8374b3
parent 8447 cd47b09e6e96
child 8449 2e4e5085e5b1
WinRT: made the D3D 11.1 renderer respect the 'srcrect' parameter of SDL_RenderCopy
src/render/direct3d11/SDL_render_d3d11.cpp
--- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Feb 24 10:41:35 2013 -0500
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Feb 24 12:27:28 2013 -0500
@@ -1261,13 +1261,17 @@
 
     D3D11_RenderStartDrawOp(renderer);
     D3D11_RenderSetBlendMode(renderer, texture->blendMode);
+
+    float minu = (float) srcrect->x / texture->w;
+    float maxu = (float) (srcrect->x + srcrect->w) / texture->w;
+    float minv = (float) srcrect->y / texture->h;
+    float maxv = (float) (srcrect->y + srcrect->h) / texture->h;
 
-    // WinRT, TODO: get srcrect working in tandem with SDL_RenderCopy, etc.
     VertexPositionColor vertices[] = {
-        {XMFLOAT3(dstrect->x, dstrect->y, 0.0f),                           XMFLOAT2(0.0f, 0.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
-        {XMFLOAT3(dstrect->x, dstrect->y + dstrect->h, 0.0f),              XMFLOAT2(0.0f, 1.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
-        {XMFLOAT3(dstrect->x + dstrect->w, dstrect->y, 0.0f),              XMFLOAT2(1.0f, 0.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f)},
-        {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)},
+        {XMFLOAT3(dstrect->x, dstrect->y, 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(dstrect->x + dstrect->w, dstrect->y, 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)},
     };
     if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
         return -1;