Updated to compile on Windows
authorSam Lantinga <slouken@libsdl.org>
Thu, 24 Dec 2009 19:18:05 +0000
changeset 3599 0f958e527e5e
parent 3598 427ff6d745df
child 3600 e36bead37acb
Updated to compile on Windows
src/video/SDL_renderer_gl.c
src/video/SDL_renderer_sw.c
src/video/SDL_video.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
--- a/src/video/SDL_renderer_gl.c	Thu Dec 24 19:16:08 2009 +0000
+++ b/src/video/SDL_renderer_gl.c	Thu Dec 24 19:18:05 2009 +0000
@@ -1225,7 +1225,6 @@
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     int i, x, y;
-    SDL_Point points[4];
 
     GL_SetBlendMode(data, renderer->blendMode, 1);
 
--- a/src/video/SDL_renderer_sw.c	Thu Dec 24 19:16:08 2009 +0000
+++ b/src/video/SDL_renderer_sw.c	Thu Dec 24 19:18:05 2009 +0000
@@ -698,6 +698,7 @@
     }
 
     for (i = 0; i < count; ++i) {
+        /* FIXME: We don't want to draw clipped edges */
         if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
             /* Nothing to draw */
             continue;
--- a/src/video/SDL_video.c	Thu Dec 24 19:16:08 2009 +0000
+++ b/src/video/SDL_video.c	Thu Dec 24 19:18:05 2009 +0000
@@ -2673,6 +2673,7 @@
     return renderer->RenderFillRects(renderer, rects, count);
 }
 
+#if 0
 int
 SDL_RenderDrawCircle(int x, int y, int radius)
 {
@@ -2714,6 +2715,7 @@
     }
     return renderer->RenderFillEllipse(renderer, x, y, w, h);
 }
+#endif // 0
 
 int
 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
--- 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;
--- a/src/video/win32/SDL_gdirender.c	Thu Dec 24 19:16:08 2009 +0000
+++ b/src/video/win32/SDL_gdirender.c	Thu Dec 24 19:18:05 2009 +0000
@@ -61,12 +61,14 @@
                            void **pixels, int *pitch);
 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static int GDI_SetDrawBlendMode(SDL_Renderer * renderer);
-static int GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
-                            int count);
-static int GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
-                           int count);
-static int GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                           int count);
+static int GDI_RenderDrawPoints(SDL_Renderer * renderer,
+                                const SDL_Point * points, int count);
+static int GDI_RenderDrawLines(SDL_Renderer * renderer,
+                               const SDL_Point * points, int count);
+static int GDI_RenderDrawRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
+static int GDI_RenderFillRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static int GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
@@ -194,9 +196,10 @@
     renderer->LockTexture = GDI_LockTexture;
     renderer->UnlockTexture = GDI_UnlockTexture;
     renderer->SetDrawBlendMode = GDI_SetDrawBlendMode;
-    renderer->RenderPoints = GDI_RenderPoints;
-    renderer->RenderLines = GDI_RenderLines;
-    renderer->RenderRects = GDI_RenderRects;
+    renderer->RenderDrawPoints = GDI_RenderDrawPoints;
+    renderer->RenderDrawLines = GDI_RenderDrawLines;
+    renderer->RenderDrawRects = GDI_RenderDrawRects;
+    renderer->RenderFillRects = GDI_RenderFillRects;
     renderer->RenderCopy = GDI_RenderCopy;
     renderer->RenderReadPixels = GDI_RenderReadPixels;
     renderer->RenderWritePixels = GDI_RenderWritePixels;
@@ -687,7 +690,8 @@
 }
 
 static int
-GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
+GDI_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
+                     int count)
 {
     GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
     int i;
@@ -719,7 +723,8 @@
 }
 
 static int
-GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
+GDI_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
+                    int count)
 {
     GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
     HPEN pen;
@@ -773,7 +778,65 @@
 }
 
 static int
-GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+GDI_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
+                    int count)
+{
+    GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
+    HPEN pen;
+    POINT vertices[5];
+    int i, status = 1;
+
+    if (data->makedirty) {
+        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+        SDL_Rect clip, rect;
+
+        clip.x = 0;
+        clip.y = 0;
+        clip.w = window->w;
+        clip.h = window->h;
+
+        for (i = 0; i < count; ++i) {
+            if (SDL_IntersectRect(rects[i], &clip, &rect)) {
+                SDL_AddDirtyRect(&data->dirty, &rect);
+            }
+        }
+    }
+
+    /* Should we cache the pen? .. it looks like GDI does for us. :) */
+    pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
+    SelectObject(data->current_hdc, pen);
+    for (i = 0; i < count; ++i) {
+        const SDL_Rect *rect = rects[i];
+
+        vertices[0].x = rect->x;
+        vertices[0].y = rect->y;
+
+        vertices[1].x = rect->x+rect->w-1;
+        vertices[1].y = rect->y;
+
+        vertices[2].x = rect->x+rect->w-1;
+        vertices[2].y = rect->y+rect->h-1;
+
+        vertices[3].x = rect->x;
+        vertices[3].y = rect->y+rect->h-1;
+
+        vertices[4].x = rect->x;
+        vertices[4].y = rect->y;
+
+        status &= Polyline(data->current_hdc, vertices, 5);
+    }
+    DeleteObject(pen);
+
+    if (!status) {
+        WIN_SetError("Polyline()");
+        return -1;
+    }
+    return 0;
+}
+
+static int
+GDI_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
+                    int count)
 {
     GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
     RECT rc;