WinRT: added point drawing support to the Direct3D 11.1 rendering backend
authorDavid Ludwig <dludwig@pobox.com>
Sun, 24 Mar 2013 21:57:40 -0400
changeset 8450 6f34a798cb54
parent 8449 2e4e5085e5b1
child 8451 092ea651523a
WinRT: added point drawing support to the Direct3D 11.1 rendering backend
src/render/direct3d11/SDL_render_d3d11.cpp
--- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Mar 24 21:19:26 2013 -0400
+++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sun Mar 24 21:57:40 2013 -0400
@@ -65,8 +65,8 @@
 //static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
 static int D3D11_UpdateViewport(SDL_Renderer * renderer);
 static int D3D11_RenderClear(SDL_Renderer * renderer);
-//static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
-//                                const SDL_FPoint * points, int count);
+static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
+                                  const SDL_FPoint * points, int count);
 static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
                                  const SDL_FPoint * points, int count);
 static int D3D11_RenderFillRects(SDL_Renderer * renderer,
@@ -143,7 +143,7 @@
     //renderer->SetRenderTarget = D3D11_SetRenderTarget;
     renderer->UpdateViewport = D3D11_UpdateViewport;
     renderer->RenderClear = D3D11_RenderClear;
-    //renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
+    renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
     renderer->RenderDrawLines = D3D11_RenderDrawLines;
     renderer->RenderFillRects = D3D11_RenderFillRects;
     renderer->RenderCopy = D3D11_RenderCopy;
@@ -1201,6 +1201,42 @@
 }
 
 static int
+D3D11_RenderDrawPoints(SDL_Renderer * renderer,
+                       const SDL_FPoint * points, int count)
+{
+    D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+    float r, g, b, a;
+
+    r = (float)(renderer->r / 255.0f);
+    g = (float)(renderer->g / 255.0f);
+    b = (float)(renderer->b / 255.0f);
+    a = (float)(renderer->a / 255.0f);
+
+    vector<VertexPositionColor> vertices;
+    vertices.reserve(count);
+    for (int i = 0; i < count; ++i) {
+        VertexPositionColor v = {XMFLOAT3(points[i].x, points[i].y, 0.0f),  XMFLOAT2(0.0f, 0.0f), XMFLOAT4(r, g, b, a)};
+        vertices.push_back(v);
+    }
+
+    D3D11_RenderStartDrawOp(renderer);
+    D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
+    if (D3D11_UpdateVertexBuffer(renderer, &vertices[0], vertices.size() * sizeof(VertexPositionColor)) != 0) {
+        return -1;
+    }
+
+    D3D11_SetPixelShader(
+        renderer,
+        rendererData->colorPixelShader.Get(),
+        nullptr,
+        nullptr);
+
+    D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, vertices.size());
+
+    return 0;
+}
+
+static int
 D3D11_RenderDrawLines(SDL_Renderer * renderer,
                       const SDL_FPoint * points, int count)
 {