Date: Fri, 19 Dec 2008 20:17:35 +0100
authorSam Lantinga <slouken@libsdl.org>
Sat, 20 Dec 2008 12:00:00 +0000
changeset 2884 9dde605c7540
parent 2883 11626a53e7bc
child 2885 ca6499468250
Date: Fri, 19 Dec 2008 20:17:35 +0100 From: Couriersud Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions > For consistency you'd probably want: > SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a); > SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode); > SDL_RenderLine(int x1, int y1, int x2, int y2); > SDL_RenderFill(SDL_Rect *rect); > > You probably also want to add API functions query the current state. > I have implemented the above api for the opengl, x11, directfb and software renderers. I have also renamed *TEXTUREBLENDMODE* constants to BLENDMODE*. The unix build compiles. The windows renderer still needs to be updated, but I have no windows development machine at hand. Have a look at the x11 renderer for a sample. Vector games now run at 90% both on opengl and directfb in comparison to sdlmame's own opengl renderer. The same applies to raster games. The diff also includes a) Changed XDrawRect to XFillRect in x11 renderer b) A number of changes to fix blending and modulation issues in the directfb renderer.
TODO
XCodeiPhoneOS/Demos/src/accelerometer.c
XCodeiPhoneOS/Demos/src/happy.c
XCodeiPhoneOS/Demos/src/keyboard.c
XCodeiPhoneOS/Demos/src/touch.c
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_glfuncs.h
src/video/SDL_renderer_gl.c
src/video/SDL_renderer_gles.c
src/video/SDL_renderer_sw.c
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/directfb/SDL_DirectFB_render.c
src/video/dummy/SDL_nullrender.c
src/video/nds/SDL_ndsrender.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11sym.h
test/common.c
test/nds-test-progs/sprite/source/common.c
test/nds-test-progs/sprite2/source/common.c
test/nds-test-progs/sprite2/source/testsprite2.c
test/testsprite2.c
--- a/TODO	Sat Dec 20 08:41:05 2008 +0000
+++ b/TODO	Sat Dec 20 12:00:00 2008 +0000
@@ -5,6 +5,7 @@
    - in progress, software support is done, Ryan is working on OpenGL shaders
  * Implement desktop video mode change notification?
  * Implement icon support (with translucency?)
+ * Add draw blend mode and line drawing support for software renderer and win32
  * Verify mouse grab support
  * Properly handle mouse grab with Vista DPI scaling
  * Make sure the mouse is where it's supposed to be when un-grabbed
--- a/XCodeiPhoneOS/Demos/src/accelerometer.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/XCodeiPhoneOS/Demos/src/accelerometer.c	Sat Dec 20 12:00:00 2008 +0000
@@ -145,7 +145,7 @@
     if (shipID == 0) {
         fatalError("could not create ship texture");
     }
-    SDL_SetTextureBlendMode(shipID, SDL_TEXTUREBLENDMODE_BLEND);
+    SDL_SetTextureBlendMode(shipID, SDL_BLENDMODE_BLEND);
 
     /* set the width and height of the ship from the surface dimensions */
     ship.rect.w = bmp_surface->w;
--- a/XCodeiPhoneOS/Demos/src/happy.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/XCodeiPhoneOS/Demos/src/happy.c	Sat Dec 20 12:00:00 2008 +0000
@@ -127,7 +127,7 @@
     if (texture_id == 0) {
         fatalError("could not create texture");
     }
-    SDL_SetTextureBlendMode(texture_id, SDL_TEXTUREBLENDMODE_BLEND);
+    SDL_SetTextureBlendMode(texture_id, SDL_BLENDMODE_BLEND);
 
     /* free up allocated memory */
     SDL_FreeSurface(bmp_surface_rgba);
--- a/XCodeiPhoneOS/Demos/src/keyboard.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/XCodeiPhoneOS/Demos/src/keyboard.c	Sat Dec 20 12:00:00 2008 +0000
@@ -223,7 +223,7 @@
             printf("texture creation failed: %s\n", SDL_GetError());
         } else {
             /* set blend mode for our texture */
-            SDL_SetTextureBlendMode(textureID, SDL_TEXTUREBLENDMODE_BLEND);
+            SDL_SetTextureBlendMode(textureID, SDL_BLENDMODE_BLEND);
         }
         SDL_FreeSurface(surface);
         SDL_FreeSurface(converted);
--- a/XCodeiPhoneOS/Demos/src/touch.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/XCodeiPhoneOS/Demos/src/touch.c	Sat Dec 20 12:00:00 2008 +0000
@@ -65,7 +65,7 @@
         fatalError("could not create brush texture");
     }
     /* additive blending -- laying strokes on top of eachother makes them brighter */
-    SDL_SetTextureBlendMode(brushID, SDL_TEXTUREBLENDMODE_ADD);
+    SDL_SetTextureBlendMode(brushID, SDL_BLENDMODE_ADD);
     /* set brush color (red) */
     SDL_SetTextureColorMod(brushID, 255, 100, 100);
 }
--- a/include/SDL_video.h	Sat Dec 20 08:41:05 2008 +0000
+++ b/include/SDL_video.h	Sat Dec 20 12:00:00 2008 +0000
@@ -206,18 +206,18 @@
 } SDL_TextureModulate;
 
 /**
- * \enum SDL_TextureBlendMode
+ * \enum SDL_BlendMode
  *
- * \brief The texture blend mode used in SDL_RenderCopy()
+ * \brief The blend mode used in SDL_RenderCopy() and drawing operations
  */
 typedef enum
 {
-    SDL_TEXTUREBLENDMODE_NONE = 0x00000000,     /**< No blending */
-    SDL_TEXTUREBLENDMODE_MASK = 0x00000001,     /**< dst = A ? src : dst (alpha is mask) */
-    SDL_TEXTUREBLENDMODE_BLEND = 0x00000002,    /**< dst = (src * A) + (dst * (1-A)) */
-    SDL_TEXTUREBLENDMODE_ADD = 0x00000004,      /**< dst = (src * A) + dst */
-    SDL_TEXTUREBLENDMODE_MOD = 0x00000008       /**< dst = src * dst */
-} SDL_TextureBlendMode;
+    SDL_BLENDMODE_NONE = 0x00000000,     /**< No blending */
+    SDL_BLENDMODE_MASK = 0x00000001,     /**< dst = A ? src : dst (alpha is mask) */
+    SDL_BLENDMODE_BLEND = 0x00000002,    /**< dst = (src * A) + (dst * (1-A)) */
+    SDL_BLENDMODE_ADD = 0x00000004,      /**< dst = (src * A) + dst */
+    SDL_BLENDMODE_MOD = 0x00000008       /**< dst = src * dst */
+} SDL_BlendMode;
 
 /**
  * \enum SDL_TextureScaleMode
@@ -1141,9 +1141,80 @@
                                               const SDL_Rect * rects);
 
 /**
- * \fn void SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect *rect)
+ * \fn void SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+ *
+ * \brief Set the color used for drawing operations (Fill and Line).
+ *
+ * \param r The red value used to draw on the rendering target
+ * \param g The green value used to draw on the rendering target
+ * \param b The blue value used to draw on the rendering target
+ * \param a The alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255)
+ * \return 0 on success, or -1 if there is no rendering context current
+ */
+extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
+                                           Uint8 a);
+
+/**
+ * \fn void SDL_GetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+ *
+ * \brief Get the color used for drawing operations (Fill and Line).
+ *
+ * \param r A pointer to the red value used to draw on the rendering target
+ * \param g A pointer to the green value used to draw on the rendering target
+ * \param b A pointer to the blue value used to draw on the rendering target
+ * \param a A pointer to the alpha value used to draw on the rendering target, usually SDL_ALPHA_OPAQUE (255)
+ * \return 0 on success, or -1 if there is no rendering context current
+ */
+extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b,
+                                           Uint8 * a);
+
+/**
+ * \fn int SDL_SetRenderDrawBlendMode(int blendMode)
+ *
+ * \brief Set the blend mode used for drawing operations
+ *
+ * \param blendMode SDL_BlendMode to use for blending
+ *
+ * \return 0 on success, or -1 if there is no rendering context current
  *
- * \brief Fill the current rendering target with the specified color.
+ * \note If the blend mode is not supported, the closest supported mode is chosen.
+ *
+ * \sa SDL_SetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode);
+
+/**
+ * \fn int SDL_GetRenderDrawBlendMode(int *blendMode)
+ *
+ * \brief Get the blend mode used for drawing operations
+ *
+ * \param blendMode A pointer filled in with the current blend mode
+ *
+ * \return 0 on success, or -1 if there is no rendering context current
+ *
+ * \sa SDL_SetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
+
+/**
+ * \fn void SDL_RenderLine(int x1, int y1, int x2, int y2)
+ *
+ * \brief Draw a line on the current rendering target.
+ *
+ * \param x1 The x coordinate of the start point
+ * \param y1 The y coordinate of the start point
+ * \param x2 The x coordinate of the end point
+ * \param y2 The y coordinate of the end point
+ *
+ * \return 0 on success, or -1 if there is no rendering context current
+ */
+
+extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2);
+
+/**
+ * \fn void SDL_RenderFill(const SDL_Rect *rect)
+ *
+ * \brief Fill the current rendering target with the drawing color.
  *
  * \param r The red value used to fill the rendering target
  * \param g The green value used to fill the rendering target
@@ -1153,8 +1224,7 @@
  *
  * \return 0 on success, or -1 if there is no rendering context current
  */
-extern DECLSPEC int SDLCALL SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a,
-                                           const SDL_Rect * rect);
+extern DECLSPEC int SDLCALL SDL_RenderFill(const SDL_Rect * rect);
 
 /**
  * \fn int SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
--- a/src/SDL_compat.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/SDL_compat.c	Sat Dec 20 12:00:00 2008 +0000
@@ -696,10 +696,10 @@
             value = 0xFF;
         }
         SDL_SetSurfaceAlphaMod(surface, value);
-        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
+        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
     } else {
         SDL_SetSurfaceAlphaMod(surface, 0xFF);
-        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_NONE);
+        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
     }
     SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));
 
--- a/src/video/SDL_glfuncs.h	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_glfuncs.h	Sat Dec 20 12:00:00 2008 +0000
@@ -206,7 +206,7 @@
 SDL_PROC_UNUSED(void, glLightiv,
                 (GLenum light, GLenum pname, const GLint * params))
 SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern))
-SDL_PROC_UNUSED(void, glLineWidth, (GLfloat width))
+SDL_PROC(void, glLineWidth, (GLfloat width))
 SDL_PROC_UNUSED(void, glListBase, (GLuint base))
 SDL_PROC(void, glLoadIdentity, (void))
 SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m))
@@ -272,7 +272,7 @@
 SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param))
 SDL_PROC_UNUSED(void, glPixelTransferi, (GLenum pname, GLint param))
 SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor))
-SDL_PROC_UNUSED(void, glPointSize, (GLfloat size))
+SDL_PROC(void, glPointSize, (GLfloat size))
 SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode))
 SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
 SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
@@ -324,7 +324,7 @@
 SDL_PROC_UNUSED(void, glRectf,
                 (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
 SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2))
-SDL_PROC_UNUSED(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
+SDL_PROC(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
 SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2))
 SDL_PROC_UNUSED(void, glRects,
                 (GLshort x1, GLshort y1, GLshort x2, GLshort y2))
--- a/src/video/SDL_renderer_gl.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_renderer_gl.c	Sat Dec 20 12:00:00 2008 +0000
@@ -51,14 +51,14 @@
 
     /* FOURCC format */
     switch (format) {
-        case SDL_PIXELFORMAT_YV12:
-        case SDL_PIXELFORMAT_IYUV:
-        case SDL_PIXELFORMAT_YUY2:
-        case SDL_PIXELFORMAT_UYVY:
-        case SDL_PIXELFORMAT_YVYU:
-            return 2;
-        default:
-            return 1;  /* shouldn't ever hit this. */
+    case SDL_PIXELFORMAT_YV12:
+    case SDL_PIXELFORMAT_IYUV:
+    case SDL_PIXELFORMAT_YUY2:
+    case SDL_PIXELFORMAT_UYVY:
+    case SDL_PIXELFORMAT_YVYU:
+        return 2;
+    default:
+        return 1;               /* shouldn't ever hit this. */
     }
 }
 
@@ -96,10 +96,14 @@
 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                             int numrects, const SDL_Rect * rects);
-static int GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                         Uint8 a, const SDL_Rect * rect);
+static int GL_SetDrawColor(SDL_Renderer * renderer);
+static int GL_SetDrawBlendMode(SDL_Renderer * renderer);
+static int GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
+                         int y2);
+static int GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
+
 static void GL_RenderPresent(SDL_Renderer * renderer);
 static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void GL_DestroyRenderer(SDL_Renderer * renderer);
@@ -113,9 +117,8 @@
       SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
-      SDL_TEXTUREBLENDMODE_MOD),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
       SDL_TEXTURESCALEMODE_SLOW),
      15,
@@ -186,7 +189,7 @@
     void *pixels;
     int pitch;
     SDL_DirtyRectList dirty;
-int HACK_RYAN_FIXME;
+    int HACK_RYAN_FIXME;
 } GL_TextureData;
 
 
@@ -308,6 +311,9 @@
     renderer->LockTexture = GL_LockTexture;
     renderer->UnlockTexture = GL_UnlockTexture;
     renderer->DirtyTexture = GL_DirtyTexture;
+    renderer->SetDrawColor = GL_SetDrawColor;
+    renderer->SetDrawBlendMode = GL_SetDrawBlendMode;
+    renderer->RenderLine = GL_RenderLine;
     renderer->RenderFill = GL_RenderFill;
     renderer->RenderCopy = GL_RenderCopy;
     renderer->RenderPresent = GL_RenderPresent;
@@ -429,6 +435,36 @@
     return renderer;
 }
 
+static void
+SetBlendMode(GL_RenderData * data, int blendMode)
+{
+    if (blendMode != data->blendMode) {
+        switch (blendMode) {
+        case SDL_BLENDMODE_NONE:
+            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
+            data->glDisable(GL_BLEND);
+            break;
+        case SDL_BLENDMODE_MASK:
+        case SDL_BLENDMODE_BLEND:
+            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+            data->glEnable(GL_BLEND);
+            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+            break;
+        case SDL_BLENDMODE_ADD:
+            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+            data->glEnable(GL_BLEND);
+            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+            break;
+        case SDL_BLENDMODE_MOD:
+            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+            data->glEnable(GL_BLEND);
+            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
+            break;
+        }
+        data->blendMode = blendMode;
+    }
+}
+
 static int
 GL_ActivateRenderer(SDL_Renderer * renderer)
 {
@@ -476,7 +512,7 @@
 //#define DEBUG_PROGRAM_COMPILE 1
 
 static GLuint
-compile_shader(GL_RenderData *data, GLenum shader_type, const char *_code)
+compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
 {
     const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
     const char *replacement = have_texture_rects ? "RECT" : "2D";
@@ -496,16 +532,17 @@
     if (code == NULL)
         return 0;
 
-    for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr+1, token)) {
+    for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
         memcpy(ptr, replacement, replacementlen);
-        memmove(ptr+replacementlen, ptr+tokenlen, strlen(ptr+tokenlen)+1);
+        memmove(ptr + replacementlen, ptr + tokenlen,
+                strlen(ptr + tokenlen) + 1);
     }
 
 #if DEBUG_PROGRAM_COMPILE
     printf("compiling shader:\n%s\n\n", code);
 #endif
 
-    data->glGetError();  /* flush any existing error state. */
+    data->glGetError();         /* flush any existing error state. */
     data->glGenProgramsARB(1, &program);
     data->glBindProgramARB(shader_type, program);
     data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
@@ -513,15 +550,14 @@
 
     SDL_free(code);
 
-    if (data->glGetError() == GL_INVALID_OPERATION)
-    {
+    if (data->glGetError() == GL_INVALID_OPERATION) {
 #if DEBUG_PROGRAM_COMPILE
         GLint pos = 0;
         const GLubyte *errstr;
         data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
         errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
         printf("program compile error at position %d: %s\n\n",
-                  (int) pos, (const char *) errstr);
+               (int) pos, (const char *) errstr);
 #endif
         data->glBindProgramARB(shader_type, 0);
         data->glDeleteProgramsARB(1, &program);
@@ -544,49 +580,33 @@
  * !!! FIXME: this ignores blendmodes, etc.
  * !!! FIXME: this could be more efficient...use a dot product for green, etc.
  */
-static const char *fragment_program_UYVY_source_code =
-    "!!ARBfp1.0\n"
-
+static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
     /* outputs... */
     "OUTPUT outcolor = result.color;\n"
-
     /* scratch registers... */
-    "TEMP uyvy;\n"
-    "TEMP luminance;\n"
-    "TEMP work;\n"
-
+    "TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
     /* Halve the coordinates to grab the correct 32 bits for the fragment. */
     "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
-
     /* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
     "TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
-
     /* Do subtractions (128/255, 16/255, 128/255, 16/255) */
     "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
-
     /* Choose the luminance component by texcoord. */
     /* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
     "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
     "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
-
     /* Multiply luminance by its magic value. */
     "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
-
     /* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
     "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
-
     /* Add luminance to Cr and Cb, store to RGB channels. */
     "ADD work.rgb, luminance, uyvy;\n"
-
     /* Do final addition for Green channel.  (!!! FIXME: this should be a DPH?) */
     "ADD work.g, work.g, uyvy.w;\n"
-
     /* Make sure alpha channel is fully opaque.  (!!! FIXME: blend modes!) */
     "MOV work.a, { 1.0 };\n"
-
     /* Store out the final fragment color... */
     "MOV outcolor, work;\n"
-
     /* ...and we're done! */
     "END\n";
 
@@ -801,14 +821,15 @@
 
     /* YUV formats use RGBA but are really two bytes per pixel */
     if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
-data->HACK_RYAN_FIXME = 2;
+        data->HACK_RYAN_FIXME = 2;
     } else {
-data->HACK_RYAN_FIXME = 1;
+        data->HACK_RYAN_FIXME = 1;
     }
     texture_w /= data->HACK_RYAN_FIXME;
 
     data->format = format;
     data->formattype = type;
+    renderdata->glEnable(data->type);
     renderdata->glBindTexture(data->type, data->texture);
     renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
                                 GL_NEAREST);
@@ -894,6 +915,7 @@
         *palette++ = colors->b;
         ++colors;
     }
+    renderdata->glEnable(data->type);
     renderdata->glBindTexture(data->type, data->texture);
     renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
                                 GL_UNSIGNED_BYTE, data->palette);
@@ -934,7 +956,9 @@
     }
     renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
-                              (pitch / bytes_per_pixel(texture->format)) / ((GL_TextureData *)texture->driverdata)->HACK_RYAN_FIXME);
+                              (pitch / bytes_per_pixel(texture->format)) /
+                              ((GL_TextureData *) texture->driverdata)->
+                              HACK_RYAN_FIXME);
 }
 
 static int
@@ -953,15 +977,15 @@
 GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
-    case SDL_TEXTUREBLENDMODE_ADD:
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
+    case SDL_BLENDMODE_ADD:
+    case SDL_BLENDMODE_MOD:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -995,6 +1019,7 @@
 
     renderdata->glGetError();
     SetupTextureUpdate(renderdata, texture, pitch);
+    renderdata->glEnable(data->type);
     renderdata->glBindTexture(data->type, data->texture);
     renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
                                 rect->h, data->format, data->formattype,
@@ -1043,17 +1068,57 @@
 }
 
 static int
-GL_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
-              const SDL_Rect * rect)
+GL_SetDrawColor(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+GL_SetDrawBlendMode(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);
 
-    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
-                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
-    data->glViewport(rect->x, window->h - rect->y, rect->w, rect->h);
-    data->glClear(GL_COLOR_BUFFER_BIT);
-    data->glViewport(0, 0, window->w, window->h);
+    data->glColor4f((GLfloat) renderer->r * inv255f,
+                    (GLfloat) renderer->g * inv255f,
+                    (GLfloat) renderer->b * inv255f,
+                    (GLfloat) renderer->a * inv255f);
+    SetBlendMode(data, renderer->blendMode);
+    data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
+
+    return 0;
+}
+
+static int
+GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
+{
+    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+    //data->glLineWidth(1.0);
+    //data->glPointSize(1.0);
+
+    SetBlendMode(data, renderer->blendMode);
+
+    data->glColor4f((GLfloat) renderer->r * inv255f,
+                    (GLfloat) renderer->g * inv255f,
+                    (GLfloat) renderer->b * inv255f,
+                    (GLfloat) renderer->a * inv255f);
+
+    if ((x1 == x2) && (y1 == y2)) {
+        data->glBegin(GL_POINTS);
+        data->glVertex2i(x1, y1);
+        data->glEnd();
+    } else {
+        data->glBegin(GL_LINES);
+        data->glVertex2i(x1, y1);
+        data->glVertex2i(x2, y2);
+        data->glEnd();
+    }
     return 0;
 }
 
@@ -1073,6 +1138,7 @@
         int pitch = texturedata->pitch;
 
         SetupTextureUpdate(data, texture, pitch);
+        data->glEnable(texturedata->type);
         data->glBindTexture(texturedata->type, texturedata->texture);
         for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
             SDL_Rect *rect = &dirty->rect;
@@ -1080,7 +1146,8 @@
                 (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
                           rect->x * bpp);
             data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
-                                  rect->w / texturedata->HACK_RYAN_FIXME, rect->h, texturedata->format,
+                                  rect->w / texturedata->HACK_RYAN_FIXME,
+                                  rect->h, texturedata->format,
                                   texturedata->formattype, pixels);
         }
         SDL_ClearDirtyRects(&texturedata->dirty);
@@ -1100,6 +1167,7 @@
     maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
     maxv *= texturedata->texh;
 
+    data->glEnable(texturedata->type);
     data->glBindTexture(texturedata->type, texturedata->texture);
 
     if (texture->modMode) {
@@ -1111,31 +1179,7 @@
         data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
     }
 
-    if (texture->blendMode != data->blendMode) {
-        switch (texture->blendMode) {
-        case SDL_TEXTUREBLENDMODE_NONE:
-            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
-            data->glDisable(GL_BLEND);
-            break;
-        case SDL_TEXTUREBLENDMODE_MASK:
-        case SDL_TEXTUREBLENDMODE_BLEND:
-            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-            data->glEnable(GL_BLEND);
-            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-            break;
-        case SDL_TEXTUREBLENDMODE_ADD:
-            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-            data->glEnable(GL_BLEND);
-            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-            break;
-        case SDL_TEXTUREBLENDMODE_MOD:
-            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-            data->glEnable(GL_BLEND);
-            data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
-            break;
-        }
-        data->blendMode = texture->blendMode;
-    }
+    SetBlendMode(data, texture->blendMode);
 
     if (texture->scaleMode != data->scaleMode) {
         switch (texture->scaleMode) {
@@ -1176,6 +1220,9 @@
     if (texturedata->shader != 0) {
         data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
     }
+
+    data->glDisable(texturedata->type);
+
     return 0;
 }
 
@@ -1219,7 +1266,8 @@
                 data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
                 data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
                 if (data->fragment_program_UYVY != 0) {
-                    data->glDeleteProgramsARB(1, &data->fragment_program_UYVY);
+                    data->glDeleteProgramsARB(1,
+                                              &data->fragment_program_UYVY);
                 }
             }
 
--- a/src/video/SDL_renderer_gles.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_renderer_gles.c	Sat Dec 20 12:00:00 2008 +0000
@@ -85,9 +85,8 @@
       SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
-      SDL_TEXTUREBLENDMODE_MOD),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
       SDL_TEXTURESCALEMODE_SLOW), 2,
      {
@@ -499,15 +498,15 @@
 GLES_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
-    case SDL_TEXTUREBLENDMODE_ADD:
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
+    case SDL_BLENDMODE_ADD:
+    case SDL_BLENDMODE_MOD:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -680,22 +679,22 @@
 
     if (texture->blendMode != data->blendMode) {
         switch (texture->blendMode) {
-        case SDL_TEXTUREBLENDMODE_NONE:
+        case SDL_BLENDMODE_NONE:
             data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
             data->glDisable(GL_BLEND);
             break;
-        case SDL_TEXTUREBLENDMODE_MASK:
-        case SDL_TEXTUREBLENDMODE_BLEND:
+        case SDL_BLENDMODE_MASK:
+        case SDL_BLENDMODE_BLEND:
             data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
             data->glEnable(GL_BLEND);
             data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
             break;
-        case SDL_TEXTUREBLENDMODE_ADD:
+        case SDL_BLENDMODE_ADD:
             data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
             data->glEnable(GL_BLEND);
             data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
             break;
-        case SDL_TEXTUREBLENDMODE_MOD:
+        case SDL_BLENDMODE_MOD:
             data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
             data->glEnable(GL_BLEND);
             data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
--- a/src/video/SDL_renderer_sw.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_renderer_sw.c	Sat Dec 20 12:00:00 2008 +0000
@@ -59,8 +59,8 @@
                           const SDL_Rect * rect, int markDirty, void **pixels,
                           int *pitch);
 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
-static int SW_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                         Uint8 a, const SDL_Rect * rect);
+static int SW_SetDrawColor(SDL_Renderer * renderer);
+static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static void SW_RenderPresent(SDL_Renderer * renderer);
@@ -77,9 +77,8 @@
       SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
-      SDL_TEXTUREBLENDMODE_MOD),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
      14,
      {
@@ -222,6 +221,13 @@
     }
     renderer->ActivateRenderer = SW_ActivateRenderer;
     renderer->DisplayModeChanged = SW_DisplayModeChanged;
+
+    renderer->SetDrawColor = SW_SetDrawColor;
+    /* FIXME : Implement
+       renderer->SetDrawBlendMode = GL_SetDrawBlendMode;
+       renderer->RenderLine = GL_RenderLine;
+     */
+
     renderer->RenderFill = SW_RenderFill;
     renderer->RenderCopy = SW_RenderCopy;
     renderer->RenderPresent = SW_RenderPresent;
@@ -520,8 +526,13 @@
 }
 
 static int
-SW_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
-              const SDL_Rect * rect)
+SW_SetDrawColor(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
     SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
     Uint32 color;
@@ -532,7 +543,8 @@
         SDL_AddDirtyRect(&data->dirty, rect);
     }
 
-    color = SDL_MapRGBA(data->surface.format, r, g, b, a);
+    color = SDL_MapRGBA(data->surface.format,
+                        renderer->r, renderer->g, renderer->b, renderer->a);
 
     if (data->renderer->LockTexture(data->renderer,
                                     data->texture[data->current_texture],
--- a/src/video/SDL_surface.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_surface.c	Sat Dec 20 12:00:00 2008 +0000
@@ -140,7 +140,7 @@
 
     /* By default surface with an alpha mask are set up for blending */
     if (Amask) {
-        SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
+        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
     }
 
     /* The surface is ready to go */
@@ -336,7 +336,7 @@
     SDL_UnlockSurface(surface);
 
     SDL_SetColorKey(surface, 0, 0);
-    SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
+    SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
 }
 
 int
@@ -434,18 +434,18 @@
     surface->map->info.flags &=
         ~(SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
     switch (blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         break;
-    case SDL_TEXTUREBLENDMODE_MASK:
+    case SDL_BLENDMODE_MASK:
         surface->map->info.flags |= SDL_COPY_MASK;
         break;
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_BLEND:
         surface->map->info.flags |= SDL_COPY_BLEND;
         break;
-    case SDL_TEXTUREBLENDMODE_ADD:
+    case SDL_BLENDMODE_ADD:
         surface->map->info.flags |= SDL_COPY_ADD;
         break;
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_MOD:
         surface->map->info.flags |= SDL_COPY_MOD;
         break;
     default:
@@ -483,19 +483,19 @@
             info.flags & (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
                           SDL_COPY_MOD)) {
     case SDL_COPY_MASK:
-        *blendMode = SDL_TEXTUREBLENDMODE_MASK;
+        *blendMode = SDL_BLENDMODE_MASK;
         break;
     case SDL_COPY_BLEND:
-        *blendMode = SDL_TEXTUREBLENDMODE_BLEND;
+        *blendMode = SDL_BLENDMODE_BLEND;
         break;
     case SDL_COPY_ADD:
-        *blendMode = SDL_TEXTUREBLENDMODE_ADD;
+        *blendMode = SDL_BLENDMODE_ADD;
         break;
     case SDL_COPY_MOD:
-        *blendMode = SDL_TEXTUREBLENDMODE_MOD;
+        *blendMode = SDL_BLENDMODE_MOD;
         break;
     default:
-        *blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        *blendMode = SDL_BLENDMODE_NONE;
         break;
     }
     return 0;
@@ -835,7 +835,7 @@
      * alpha channel or alpha modulation */
     if ((surface->format->Amask && format->Amask) ||
         (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
-        SDL_SetSurfaceBlendMode(convert, SDL_TEXTUREBLENDMODE_BLEND);
+        SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND);
     }
     if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
         SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
--- a/src/video/SDL_sysvideo.h	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_sysvideo.h	Sat Dec 20 12:00:00 2008 +0000
@@ -88,8 +88,11 @@
     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
                           int numrects, const SDL_Rect * rects);
-    int (*RenderFill) (SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                       Uint8 a, const SDL_Rect * rect);
+    int (*SetDrawColor) (SDL_Renderer * renderer);
+    int (*SetDrawBlendMode) (SDL_Renderer * renderer);
+    int (*RenderLine) (SDL_Renderer * renderer, int x1, int y1, int x2,
+                       int y2);
+    int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect);
     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
                        const SDL_Rect * srcrect, const SDL_Rect * dstrect);
     void (*RenderPresent) (SDL_Renderer * renderer);
@@ -103,6 +106,9 @@
     /* The window associated with the renderer */
     SDL_WindowID window;
 
+    Uint8 r, g, b, a;                   /**< Color for drawing operations values */
+    int blendMode;                      /**< The drawing blend mode */
+
     void *driverdata;
 };
 
--- a/src/video/SDL_video.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/SDL_video.c	Sat Dec 20 12:00:00 2008 +0000
@@ -1975,7 +1975,104 @@
 }
 
 int
-SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect)
+SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+    SDL_Renderer *renderer;
+
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+    renderer = SDL_CurrentDisplay.current_renderer;
+    if (!renderer) {
+        return -1;
+    }
+    if (!renderer->SetDrawColor) {
+        SDL_Unsupported();
+        return -1;
+    }
+    renderer->r = r;
+    renderer->g = g;
+    renderer->b = b;
+    renderer->a = a;
+    renderer->SetDrawColor(renderer);
+    return 0;
+}
+
+int
+SDL_GetRenderDrawColor(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
+{
+    SDL_Renderer *renderer;
+
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+    renderer = SDL_CurrentDisplay.current_renderer;
+    if (!renderer) {
+        return -1;
+    }
+    if (!renderer->SetDrawColor) {
+        SDL_Unsupported();
+        return -1;
+    }
+    if (r) {
+        *r = renderer->r;
+    }
+    if (g) {
+        *g = renderer->g;
+    }
+    if (b) {
+        *b = renderer->b;
+    }
+    if (a) {
+        *a = renderer->a;
+    }
+    return 0;
+}
+
+int
+SDL_SetRenderDrawBlendMode(int blendMode)
+{
+    SDL_Renderer *renderer;
+
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+    renderer = SDL_CurrentDisplay.current_renderer;
+    if (!renderer) {
+        return -1;
+    }
+    if (!renderer->SetDrawBlendMode) {
+        SDL_Unsupported();
+        return -1;
+    }
+    renderer->blendMode = blendMode;
+    renderer->SetDrawBlendMode(renderer);
+    return 0;
+}
+
+int
+SDL_GetRenderDrawBlendMode(int *blendMode)
+{
+    SDL_Renderer *renderer;
+
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+    renderer = SDL_CurrentDisplay.current_renderer;
+    if (!renderer) {
+        return -1;
+    }
+    *blendMode = renderer->blendMode;
+    return 0;
+}
+
+
+int
+SDL_RenderFill(const SDL_Rect * rect)
 {
     SDL_Renderer *renderer;
     SDL_Window *window;
@@ -2003,7 +2100,42 @@
             return 0;
         }
     }
-    return renderer->RenderFill(renderer, r, g, b, a, &real_rect);
+    return renderer->RenderFill(renderer, &real_rect);
+}
+
+int
+SDL_RenderLine(int x1, int y1, int x2, int y2)
+{
+    SDL_Renderer *renderer;
+    SDL_Window *window;
+    SDL_Rect real_rect;
+
+    if (!_this) {
+        SDL_UninitializedVideo();
+        return -1;
+    }
+    renderer = SDL_CurrentDisplay.current_renderer;
+    if (!renderer) {
+        return -1;
+    }
+    if (!renderer->RenderLine) {
+        SDL_Unsupported();
+        return -1;
+    }
+#if 0
+    //FIXME: Need line intersect routine
+    window = SDL_GetWindowFromID(renderer->window);
+    real_rect.x = 0;
+    real_rect.y = 0;
+    real_rect.w = window->w;
+    real_rect.h = window->h;
+    if (rect) {
+        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
+            return 0;
+        }
+    }
+#endif
+    return renderer->RenderLine(renderer, x1, y1, x2, y2);
 }
 
 int
--- a/src/video/directfb/SDL_DirectFB_render.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/directfb/SDL_DirectFB_render.c	Sat Dec 20 12:00:00 2008 +0000
@@ -71,8 +71,12 @@
 static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
                                   SDL_Texture * texture, int numrects,
                                   const SDL_Rect * rects);
-static int DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
-                               Uint8 b, Uint8 a, const SDL_Rect * rect);
+static int DirectFB_SetDrawColor(SDL_Renderer * renderer);
+static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
+static int DirectFB_RenderLine(SDL_Renderer * renderer, int x1, int y1,
+                               int x2, int y2);
+static int DirectFB_RenderFill(SDL_Renderer * renderer,
+                               const SDL_Rect * rect);
 static int DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                                const SDL_Rect * srcrect,
                                const SDL_Rect * dstrect);
@@ -91,9 +95,8 @@
       SDL_RENDERER_ACCELERATED),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
-      SDL_TEXTUREBLENDMODE_MOD),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
       SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
      14,
@@ -122,6 +125,9 @@
     DFBSurfaceFlipFlags flipflags;
     int isyuvdirect;
     int size_changed;
+    int lastBlendMode;
+    DFBSurfaceBlittingFlags blitFlags;
+    DFBSurfaceDrawingFlags drawFlags;
 } DirectFB_RenderData;
 
 typedef struct
@@ -147,6 +153,79 @@
     dr->w = sr->w;
 }
 
+
+static int
+TextureHasAlpha(DirectFB_TextureData * data)
+{
+    /* Drawing primitive ? */
+    if (!data)
+        return 0;
+    switch (data->format) {
+    case SDL_PIXELFORMAT_INDEX4LSB:
+    case SDL_PIXELFORMAT_ARGB4444:
+    case SDL_PIXELFORMAT_ARGB1555:
+    case SDL_PIXELFORMAT_ARGB8888:
+    case SDL_PIXELFORMAT_RGBA8888:
+    case SDL_PIXELFORMAT_ABGR8888:
+    case SDL_PIXELFORMAT_BGRA8888:
+    case SDL_PIXELFORMAT_ARGB2101010:
+        return 1;
+    default:
+        return 0;
+    }
+}
+
+static void
+SetBlendMode(DirectFB_RenderData * data, int blendMode,
+             DirectFB_TextureData * source)
+{
+    //FIXME: check for format change
+    if (1 || data->lastBlendMode != blendMode) {
+        switch (blendMode) {
+        case SDL_BLENDMODE_NONE:
+                                           /**< No blending */
+            data->blitFlags = DSBLIT_NOFX;
+            data->drawFlags = DSDRAW_NOFX;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
+            break;
+        case SDL_BLENDMODE_MASK:
+            data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+            data->drawFlags = DSDRAW_BLEND;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
+            data->surface->SetDstBlendFunction(data->surface,
+                                               DSBF_INVSRCALPHA);
+            break;
+        case SDL_BLENDMODE_BLEND:
+            data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+            data->drawFlags = DSDRAW_BLEND;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
+            data->surface->SetDstBlendFunction(data->surface,
+                                               DSBF_INVSRCALPHA);
+            break;
+        case SDL_BLENDMODE_ADD:
+            data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+            data->drawFlags = DSDRAW_BLEND;
+            //FIXME: SRCALPHA kills performance on radeon ...
+            //Eventually use a premultiplied texture
+            if (0 && TextureHasAlpha(source))
+                data->surface->SetSrcBlendFunction(data->surface,
+                                                   DSBF_SRCALPHA);
+            else
+                data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ONE);
+            break;
+        case SDL_BLENDMODE_MOD:
+            data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+            data->drawFlags = DSDRAW_BLEND;
+            data->surface->SetSrcBlendFunction(data->surface, DSBF_DESTCOLOR);
+            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
+            break;
+        }
+        data->lastBlendMode = blendMode;
+    }
+}
+
 void
 DirectFB_AddRenderDriver(_THIS)
 {
@@ -214,6 +293,9 @@
     renderer->LockTexture = DirectFB_LockTexture;
     renderer->UnlockTexture = DirectFB_UnlockTexture;
     renderer->DirtyTexture = DirectFB_DirtyTexture;
+    renderer->SetDrawColor = DirectFB_SetDrawColor;
+    renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
+    renderer->RenderLine = DirectFB_RenderLine;
     renderer->RenderFill = DirectFB_RenderFill;
     renderer->RenderCopy = DirectFB_RenderCopy;
     renderer->RenderPresent = DirectFB_RenderPresent;
@@ -304,7 +386,11 @@
     case SDL_PIXELFORMAT_INDEX4MSB:
         return DSPF_UNKNOWN;
     case SDL_PIXELFORMAT_RGB444:
+#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
+        return DSPF_RGB444;
+#else
         return DSPF_UNKNOWN;
+#endif
     case SDL_PIXELFORMAT_BGR24:
         return DSPF_UNKNOWN;
     case SDL_PIXELFORMAT_BGR888:
@@ -576,15 +662,15 @@
 DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
-    case SDL_TEXTUREBLENDMODE_ADD:
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
+    case SDL_BLENDMODE_ADD:
+    case SDL_BLENDMODE_MOD:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -710,13 +796,73 @@
 }
 
 static int
-DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                    Uint8 a, const SDL_Rect * rect)
+DirectFB_SetDrawColor(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+PrepareDraw(SDL_Renderer * renderer)
+{
+    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+    DFBResult ret;
+    Uint8 r, g, b, a;
+
+    r = renderer->r;
+    g = renderer->g;
+    b = renderer->b;
+    a = renderer->a;
+
+    SetBlendMode(data, renderer->blendMode, NULL);
+    SDL_DFB_CHECKERR(data->surface->
+                     SetDrawingFlags(data->surface, data->drawFlags));
+
+    switch (renderer->blendMode) {
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
+        break;
+    case SDL_BLENDMODE_ADD:
+    case SDL_BLENDMODE_MOD:
+        r = ((int) r * (int) a) / 255;
+        g = ((int) g * (int) a) / 255;
+        b = ((int) b * (int) a) / 255;
+        a = 255;
+        break;
+    }
+
+    SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
+    return 0;
+  error:
+    return -1;
+}
+
+static int
+DirectFB_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     DFBResult ret;
 
-    SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, r, g, b, a));
+    PrepareDraw(renderer);
+    SDL_DFB_CHECKERR(data->surface->DrawLine(data->surface, x1, y1, x2, y2));
+    return 0;
+  error:
+    return -1;
+}
+
+static int
+DirectFB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+    DFBResult ret;
+
+    PrepareDraw(renderer);
     SDL_DFB_CHECKERR(data->surface->
                      FillRectangle(data->surface, rect->x, rect->y, rect->w,
                                    rect->h));
@@ -733,6 +879,7 @@
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
     DirectFB_TextureData *texturedata =
         (DirectFB_TextureData *) texture->driverdata;
+    Uint8 alpha = 0xFF;
     DFBResult ret;
 
     if (texturedata->display) {
@@ -772,68 +919,45 @@
             }
             SDL_ClearDirtyRects(&texturedata->dirty);
         }
+
+        SDLtoDFBRect(srcrect, &sr);
+        SDLtoDFBRect(dstrect, &dr);
+
+        SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
+                                                 0xFF, 0xFF, 0xFF));
+        if (texture->
+            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
+        {
+            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
+                alpha = texture->a;
+                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
+                                                         0xFF, 0xFF, alpha));
+            }
+            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
+
+                SDL_DFB_CHECKERR(data->surface->
+                                 SetColor(data->surface, texture->r,
+                                          texture->g, texture->b, alpha));
+                flags |= DSBLIT_COLORIZE;
+            }
+            if (alpha < 0xFF)
+                flags |= DSBLIT_SRC_PREMULTCOLOR;
+        } else
+            SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
+                                                     0xFF, 0xFF, 0xFF));
+
+        SetBlendMode(data, texture->blendMode, texturedata);
+
+        SDL_DFB_CHECKERR(data->surface->
+                         SetBlittingFlags(data->surface,
+                                          data->blitFlags | flags));
+
 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
         SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface,
                                                          texturedata->
                                                          render_options));
 #endif
 
-        SDLtoDFBRect(srcrect, &sr);
-        SDLtoDFBRect(dstrect, &dr);
-
-        if (texture->
-            modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
-        {
-            Uint8 alpha = 0xFF;
-            if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
-                alpha = texture->a;
-                flags |= DSBLIT_SRC_PREMULTCOLOR;
-                SDL_DFB_CHECKERR(data->surface->SetColor(data->surface, 0xFF,
-                                                         0xFF, 0xFF, alpha));
-            }
-            if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
-                SDL_DFB_CHECKERR(data->surface->
-                                 SetColor(data->surface, texture->r,
-                                          texture->g, texture->b, alpha));
-                /* Only works together .... */
-                flags |= DSBLIT_COLORIZE | DSBLIT_SRC_PREMULTCOLOR;
-            }
-        }
-
-        switch (texture->blendMode) {
-        case SDL_TEXTUREBLENDMODE_NONE:
-                                       /**< No blending */
-            flags |= DSBLIT_NOFX;
-            data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
-            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
-            break;
-        case SDL_TEXTUREBLENDMODE_MASK:
-            flags |= DSBLIT_BLEND_ALPHACHANNEL;
-            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
-            data->surface->SetDstBlendFunction(data->surface,
-                                               DSBF_INVSRCALPHA);
-            break;
-        case SDL_TEXTUREBLENDMODE_BLEND:
-            flags |= DSBLIT_BLEND_ALPHACHANNEL;
-            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
-            data->surface->SetDstBlendFunction(data->surface,
-                                               DSBF_INVSRCALPHA);
-            break;
-        case SDL_TEXTUREBLENDMODE_ADD:
-            flags |= DSBLIT_BLEND_ALPHACHANNEL;
-            data->surface->SetSrcBlendFunction(data->surface, DSBF_SRCALPHA);
-            data->surface->SetDstBlendFunction(data->surface, DSBF_ONE);
-            break;
-        case SDL_TEXTUREBLENDMODE_MOD:
-            flags |= DSBLIT_BLEND_ALPHACHANNEL;
-            data->surface->SetSrcBlendFunction(data->surface, DSBF_DESTCOLOR);
-            data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
-            break;
-        }
-
-        SDL_DFB_CHECKERR(data->surface->
-                         SetBlittingFlags(data->surface, flags));
-
         if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
             SDL_DFB_CHECKERR(data->surface->
                              Blit(data->surface, texturedata->surface,
--- a/src/video/dummy/SDL_nullrender.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/dummy/SDL_nullrender.c	Sat Dec 20 12:00:00 2008 +0000
@@ -31,8 +31,9 @@
 
 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
                                               Uint32 flags);
-static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
-                                Uint8 b, Uint8 a, const SDL_Rect * rect);
+static int SDL_DUMMY_SetDrawColor(SDL_Renderer * renderer);
+static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer,
+                                const SDL_Rect * rect);
 static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
                                 SDL_Texture * texture,
                                 const SDL_Rect * srcrect,
@@ -88,6 +89,7 @@
     }
     SDL_zerop(data);
 
+    renderer->SetDrawColor = SDL_DUMMY_SetDrawColor;
     renderer->RenderFill = SDL_DUMMY_RenderFill;
     renderer->RenderCopy = SDL_DUMMY_RenderCopy;
     renderer->RenderPresent = SDL_DUMMY_RenderPresent;
@@ -124,8 +126,13 @@
 }
 
 static int
-SDL_DUMMY_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                     Uint8 a, const SDL_Rect * rect)
+SDL_DUMMY_SetDrawColor(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
     SDL_DUMMY_RenderData *data =
         (SDL_DUMMY_RenderData *) renderer->driverdata;
@@ -133,7 +140,8 @@
     Uint32 color;
     SDL_Rect real_rect = *rect;
 
-    color = SDL_MapRGBA(target->format, r, g, b, a);
+    color = SDL_MapRGBA(target->format,
+                        renderer->r, renderer->g, renderer->b, renderer->a);
 
     return SDL_FillRect(target, &real_rect, color);
 }
--- a/src/video/nds/SDL_ndsrender.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/nds/SDL_ndsrender.c	Sat Dec 20 12:00:00 2008 +0000
@@ -140,7 +140,7 @@
     {"nds",                     /* char* name */
      (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC),  /* u32 flags */
      (SDL_TEXTUREMODULATE_NONE),        /* u32 mod_modes */
-     (SDL_TEXTUREBLENDMODE_MASK),       /* u32 blend_modes */
+     (SDL_BLENDMODE_MASK),      /* u32 blend_modes */
      (SDL_TEXTURESCALEMODE_FAST),       /* u32 scale_modes */
      3,                         /* u32 num_texture_formats */
      {
--- a/src/video/win32/SDL_d3drender.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/win32/SDL_d3drender.c	Sat Dec 20 12:00:00 2008 +0000
@@ -82,9 +82,8 @@
       SDL_RENDERER_ACCELERATED),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
       SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
-      SDL_TEXTUREBLENDMODE_MOD),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
       SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
      12,
@@ -525,15 +524,15 @@
 D3D_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
-    case SDL_TEXTUREBLENDMODE_ADD:
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
+    case SDL_BLENDMODE_ADD:
+    case SDL_BLENDMODE_MOD:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -798,12 +797,12 @@
     vertices[3].v = maxv;
 
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
                                         FALSE);
         break;
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
                                         TRUE);
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
@@ -811,7 +810,7 @@
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
                                         D3DBLEND_INVSRCALPHA);
         break;
-    case SDL_TEXTUREBLENDMODE_ADD:
+    case SDL_BLENDMODE_ADD:
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
                                         TRUE);
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
@@ -819,7 +818,7 @@
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
                                         D3DBLEND_ONE);
         break;
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_MOD:
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
                                         TRUE);
         IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
--- a/src/video/win32/SDL_gdirender.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/win32/SDL_gdirender.c	Sat Dec 20 12:00:00 2008 +0000
@@ -73,8 +73,7 @@
       SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
       SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
      (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
-     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
-      SDL_TEXTUREBLENDMODE_BLEND),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND),
      (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
      14,
      {
@@ -459,13 +458,13 @@
 GDI_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
-    case SDL_TEXTUREBLENDMODE_MASK:
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_NONE:
+    case SDL_BLENDMODE_MASK:
+    case SDL_BLENDMODE_BLEND:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -617,8 +616,7 @@
         SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
         RealizePalette(data->memory_hdc);
     }
-    if (texture->blendMode &
-        (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND)) {
+    if (texture->blendMode & (SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND)) {
         BLENDFUNCTION blendFunc = {
             AC_SRC_OVER,
             0,
--- a/src/video/x11/SDL_x11render.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/x11/SDL_x11render.c	Sat Dec 20 12:00:00 2008 +0000
@@ -47,8 +47,11 @@
                            const SDL_Rect * rect, int markDirty,
                            void **pixels, int *pitch);
 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
-static int X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
-                          Uint8 a, const SDL_Rect * rect);
+static int X11_SetDrawColor(SDL_Renderer * renderer);
+static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
+static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
+                          int y2);
+static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static void X11_RenderPresent(SDL_Renderer * renderer);
@@ -65,7 +68,7 @@
       SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
       SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
      SDL_TEXTUREMODULATE_NONE,
-     SDL_TEXTUREBLENDMODE_NONE,
+     SDL_BLENDMODE_NONE,
      SDL_TEXTURESCALEMODE_NONE,
      0,
      {0},
@@ -191,6 +194,9 @@
     renderer->UpdateTexture = X11_UpdateTexture;
     renderer->LockTexture = X11_LockTexture;
     renderer->UnlockTexture = X11_UnlockTexture;
+    renderer->SetDrawColor = X11_SetDrawColor;
+    renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
+    renderer->RenderLine = X11_RenderLine;
     renderer->RenderFill = X11_RenderFill;
     renderer->RenderCopy = X11_RenderCopy;
     renderer->RenderPresent = X11_RenderPresent;
@@ -445,11 +451,11 @@
 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     switch (texture->blendMode) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         return 0;
     default:
         SDL_Unsupported();
-        texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
+        texture->blendMode = SDL_BLENDMODE_NONE;
         return -1;
     }
 }
@@ -552,8 +558,73 @@
 }
 
 static int
-X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
-               const SDL_Rect * rect)
+X11_SetDrawColor(SDL_Renderer * renderer)
+{
+    return 0;
+}
+
+static int
+X11_SetDrawBlendMode(SDL_Renderer * renderer)
+{
+    switch (renderer->blendMode) {
+    case SDL_BLENDMODE_NONE:
+        return 0;
+    default:
+        SDL_Unsupported();
+        renderer->blendMode = SDL_BLENDMODE_NONE;
+        return -1;
+    }
+}
+
+static Uint32
+renderdrawcolor(SDL_Renderer * renderer, int premult)
+{
+    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
+    Uint8 r = renderer->r;
+    Uint8 g = renderer->g;
+    Uint8 b = renderer->b;
+    Uint8 a = renderer->a;
+    if (premult)
+        return SDL_MapRGBA(data->format, ((int) r * (int) a) / 255,
+                           ((int) g * (int) a) / 255,
+                           ((int) b * (int) a) / 255, 255);
+    else
+        return SDL_MapRGBA(data->format, r, g, b, a);
+}
+
+static int
+X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
+{
+    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
+    unsigned long foreground;
+    if (data->makedirty) {
+        SDL_Rect rect;
+
+        if (x1 < x2) {
+            rect.x = x1;
+            rect.w = (x2 - x1) + 1;
+        } else {
+            rect.x = x2;
+            rect.w = (x1 - x2) + 1;
+        }
+        if (y1 < y2) {
+            rect.y = y1;
+            rect.h = (y2 - y1) + 1;
+        } else {
+            rect.y = y2;
+            rect.h = (y1 - y2) + 1;
+        }
+        SDL_AddDirtyRect(&data->dirty, &rect);
+    }
+
+    foreground = renderdrawcolor(renderer, 1);
+    XSetForeground(data->display, data->gc, foreground);
+    XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2);
+
+}
+
+static int
+X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
     X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
     unsigned long foreground;
@@ -562,9 +633,9 @@
         SDL_AddDirtyRect(&data->dirty, rect);
     }
 
-    foreground = SDL_MapRGBA(data->format, r, g, b, a);
+    foreground = renderdrawcolor(renderer, 1);
     XSetForeground(data->display, data->gc, foreground);
-    XDrawRectangle(data->display, data->drawable, data->gc, rect->x, rect->y,
+    XFillRectangle(data->display, data->drawable, data->gc, rect->x, rect->y,
                    rect->w, rect->h);
     return 0;
 }
--- a/src/video/x11/SDL_x11sym.h	Sat Dec 20 08:41:05 2008 +0000
+++ b/src/video/x11/SDL_x11sym.h	Sat Dec 20 12:00:00 2008 +0000
@@ -51,6 +51,7 @@
 SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return)
 SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return)
 SDL_X11_SYM(int,XDrawRectangle,(Display* a,Drawable b,GC c,int d, int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(int,XFillRectangle,(Display* a,Drawable b,GC c,int d, int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
 SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return)
 SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return)
 SDL_X11_SYM(Bool,XFilterEvent,(XEvent *event,Window w),(event,w),return)
@@ -94,6 +95,7 @@
 SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b),(a,b),return)
 SDL_X11_SYM(int,XPending,(Display* a),(a),return)
 SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j),(a,b,c,d,e,f,g,h,i,j),return)
+SDL_X11_SYM(int,XDrawLine,(Display* a, Drawable b, GC c, int d, int e, int f, int g),(a,b,c,d,e,f,g),return)
 SDL_X11_SYM(int,XQueryColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return)
 SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return)
 SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return)
--- a/test/common.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/test/common.c	Sat Dec 20 12:00:00 2008 +0000
@@ -322,19 +322,19 @@
 PrintBlendMode(Uint32 flag)
 {
     switch (flag) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         fprintf(stderr, "None");
         break;
-    case SDL_TEXTUREBLENDMODE_MASK:
+    case SDL_BLENDMODE_MASK:
         fprintf(stderr, "Mask");
         break;
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_BLEND:
         fprintf(stderr, "Blend");
         break;
-    case SDL_TEXTUREBLENDMODE_ADD:
+    case SDL_BLENDMODE_ADD:
         fprintf(stderr, "Add");
         break;
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_MOD:
         fprintf(stderr, "Mod");
         break;
     default:
--- a/test/nds-test-progs/sprite/source/common.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/test/nds-test-progs/sprite/source/common.c	Sat Dec 20 12:00:00 2008 +0000
@@ -322,19 +322,19 @@
 PrintBlendMode(Uint32 flag)
 {
     switch (flag) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         fprintf(stderr, "None");
         break;
-    case SDL_TEXTUREBLENDMODE_MASK:
+    case SDL_BLENDMODE_MASK:
         fprintf(stderr, "Mask");
         break;
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_BLEND:
         fprintf(stderr, "Blend");
         break;
-    case SDL_TEXTUREBLENDMODE_ADD:
+    case SDL_BLENDMODE_ADD:
         fprintf(stderr, "Add");
         break;
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_MOD:
         fprintf(stderr, "Mod");
         break;
     default:
--- a/test/nds-test-progs/sprite2/source/common.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/test/nds-test-progs/sprite2/source/common.c	Sat Dec 20 12:00:00 2008 +0000
@@ -322,19 +322,19 @@
 PrintBlendMode(Uint32 flag)
 {
     switch (flag) {
-    case SDL_TEXTUREBLENDMODE_NONE:
+    case SDL_BLENDMODE_NONE:
         fprintf(stderr, "None");
         break;
-    case SDL_TEXTUREBLENDMODE_MASK:
+    case SDL_BLENDMODE_MASK:
         fprintf(stderr, "Mask");
         break;
-    case SDL_TEXTUREBLENDMODE_BLEND:
+    case SDL_BLENDMODE_BLEND:
         fprintf(stderr, "Blend");
         break;
-    case SDL_TEXTUREBLENDMODE_ADD:
+    case SDL_BLENDMODE_ADD:
         fprintf(stderr, "Add");
         break;
-    case SDL_TEXTUREBLENDMODE_MOD:
+    case SDL_BLENDMODE_MOD:
         fprintf(stderr, "Mod");
         break;
     default:
--- a/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Dec 20 12:00:00 2008 +0000
@@ -21,7 +21,7 @@
 static SDL_Rect *positions;
 static SDL_Rect *velocities;
 static int sprite_w, sprite_h;
-static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK;
+static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK;
 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
 
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
--- a/test/testsprite2.c	Sat Dec 20 08:41:05 2008 +0000
+++ b/test/testsprite2.c	Sat Dec 20 12:00:00 2008 +0000
@@ -20,7 +20,7 @@
 static SDL_Rect *positions;
 static SDL_Rect *velocities;
 static int sprite_w, sprite_h;
-static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK;
+static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK;
 static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
 
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
@@ -119,7 +119,8 @@
 
     /* Move the sprite, bounce at the wall, and draw */
     n = 0;
-    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
+    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
+    SDL_RenderFill(NULL);
     for (i = 0; i < num_sprites; ++i) {
         position = &positions[i];
         velocity = &velocities[i];
@@ -166,19 +167,19 @@
             if (SDL_strcasecmp(argv[i], "--blend") == 0) {
                 if (argv[i + 1]) {
                     if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
-                        blendMode = SDL_TEXTUREBLENDMODE_NONE;
+                        blendMode = SDL_BLENDMODE_NONE;
                         consumed = 2;
                     } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
-                        blendMode = SDL_TEXTUREBLENDMODE_MASK;
+                        blendMode = SDL_BLENDMODE_MASK;
                         consumed = 2;
                     } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
-                        blendMode = SDL_TEXTUREBLENDMODE_BLEND;
+                        blendMode = SDL_BLENDMODE_BLEND;
                         consumed = 2;
                     } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
-                        blendMode = SDL_TEXTUREBLENDMODE_ADD;
+                        blendMode = SDL_BLENDMODE_ADD;
                         consumed = 2;
                     } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
-                        blendMode = SDL_TEXTUREBLENDMODE_MOD;
+                        blendMode = SDL_BLENDMODE_MOD;
                         consumed = 2;
                     }
                 }
@@ -230,7 +231,8 @@
     }
     for (i = 0; i < state->num_windows; ++i) {
         SDL_SelectRenderer(state->windows[i]);
-        SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
+        SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
+        SDL_RenderFill(NULL);
     }
     if (LoadSprite("icon.bmp") < 0) {
         quit(2);
@@ -275,7 +277,8 @@
                 switch (event.window.event) {
                 case SDL_WINDOWEVENT_EXPOSED:
                     SDL_SelectRenderer(event.window.windowID);
-                    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
+                    SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
+                    SDL_RenderFill(NULL);
                     break;
                 }
                 break;