diff src/video/win32/SDL_d3drender.c @ 3599:0f958e527e5e

Updated to compile on Windows
author Sam Lantinga <slouken@libsdl.org>
date Thu, 24 Dec 2009 19:18:05 +0000
parents 9c2e92de786a
children e86edac50872
line wrap: on
line diff
--- a/src/video/win32/SDL_d3drender.c	Thu Dec 24 19:16:08 2009 +0000
+++ b/src/video/win32/SDL_d3drender.c	Thu Dec 24 19:18:05 2009 +0000
@@ -118,12 +118,14 @@
 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                              int numrects, const SDL_Rect * rects);
-static int D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
-                            int count);
-static int D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
-                           int count);
-static int D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                           int count);
+static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
+                                const SDL_Point * points, int count);
+static int D3D_RenderDrawLines(SDL_Renderer * renderer,
+                               const SDL_Point * points, int count);
+static int D3D_RenderDrawRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
+static int D3D_RenderFillRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
@@ -462,9 +464,9 @@
     renderer->LockTexture = D3D_LockTexture;
     renderer->UnlockTexture = D3D_UnlockTexture;
     renderer->DirtyTexture = D3D_DirtyTexture;
-    renderer->RenderPoints = D3D_RenderPoints;
-    renderer->RenderLines = D3D_RenderLines;
-    renderer->RenderRects = D3D_RenderRects;
+    renderer->RenderDrawPoints = D3D_RenderDrawPoints;
+    renderer->RenderDrawLines = D3D_RenderDrawLines;
+    renderer->RenderDrawRects = D3D_RenderDrawRects;
     renderer->RenderCopy = D3D_RenderCopy;
     renderer->RenderReadPixels = D3D_RenderReadPixels;
     renderer->RenderWritePixels = D3D_RenderWritePixels;
@@ -1021,7 +1023,8 @@
 }
 
 static int
-D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
+D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
+                     int count)
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     DWORD color;
@@ -1068,7 +1071,8 @@
 }
 
 static int
-D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
+D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
+                    int count)
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     DWORD color;
@@ -1124,7 +1128,73 @@
 }
 
 static int
-D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+D3D_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
+                    int count)
+{
+    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+    DWORD color;
+    int i;
+    Vertex vertices[5];
+    HRESULT result;
+
+    if (data->beginScene) {
+        IDirect3DDevice9_BeginScene(data->device);
+        data->beginScene = SDL_FALSE;
+    }
+
+    D3D_SetBlendMode(data, renderer->blendMode);
+
+    result =
+        IDirect3DDevice9_SetTexture(data->device, 0,
+                                    (IDirect3DBaseTexture9 *) 0);
+    if (FAILED(result)) {
+        D3D_SetError("SetTexture()", result);
+        return -1;
+    }
+
+    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
+
+    for (i = 0; i < SDL_arraysize(vertices); ++i) {
+        vertices[i].z = 0.0f;
+        vertices[i].rhw = 1.0f;
+        vertices[i].color = color;
+        vertices[i].u = 0.0f;
+        vertices[i].v = 0.0f;
+    }
+
+    for (i = 0; i < count; ++i) {
+        const SDL_Rect *rect = rects[i];
+
+        vertices[0].x = (float) rect->x;
+        vertices[0].y = (float) rect->y;
+
+        vertices[1].x = (float) rect->x+rect->w-1;
+        vertices[1].y = (float) rect->y;
+
+        vertices[2].x = (float) rect->x+rect->w-1;
+        vertices[2].y = (float) rect->y+rect->h-1;
+
+        vertices[3].x = (float) rect->x;
+        vertices[3].y = (float) rect->y+rect->h-1;
+
+        vertices[4].x = (float) rect->x;
+        vertices[4].y = (float) rect->y;
+
+        result =
+            IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, 4,
+                                             vertices, sizeof(*vertices));
+
+        if (FAILED(result)) {
+            D3D_SetError("DrawPrimitiveUP()", result);
+            return -1;
+        }
+    }
+    return 0;
+}
+
+static int
+D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
+                    int count)
 {
     D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
     DWORD color;