changeset 4607:9e9ec5e3be95

Get SDL_BLENDMODE_MOD to work! Tested on nvidia only ATM.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Wed, 21 Jul 2010 17:54:31 +0530
parents 4e145485971b
children ff7b00d4b0d3
files src/video/x11/SDL_x11render.c
diffstat 1 files changed, 44 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c	Tue Jul 20 11:43:13 2010 +0530
+++ b/src/video/x11/SDL_x11render.c	Wed Jul 21 17:54:31 2010 +0530
@@ -380,20 +380,20 @@
             (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK | SDL_BLENDMODE_MOD);
         /* Create a clip mask that is used for rendering primitives. */
         data->stencil = XCreatePixmap(data->display, data->xwindow,
-                                   window->w, window->h, 8);
+                                   window->w, window->h, 32);
         
         /* Create the GC for the clip mask. */
         data->stencil_gc = XCreateGC(data->display, data->stencil,
                                   GCGraphicsExposures, &gcv);
-        XSetBackground(data->display, data->stencil_gc, 0x00);
-        XSetForeground(data->display, data->stencil_gc, 0x00);
+        XSetBackground(data->display, data->stencil_gc, 0);
+        XSetForeground(data->display, data->stencil_gc, 0);
         XFillRectangle(data->display, data->stencil, data->stencil_gc,
                        0, 0, window->w, window->h);
-        XSetForeground(data->display, data->stencil_gc, 0xFF);
+        XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
         data->stencil_pict =
             XRenderCreatePicture(data->display, data->stencil,
                                  XRenderFindStandardFormat(data->display,
-                                                           PictStandardA8),
+                                                           PictStandardARGB32),
                                  0, NULL);
 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
         if (data->use_xdamage) {
@@ -935,7 +935,7 @@
         }
     case SDL_BLENDMODE_MOD:
         if (renderdata->use_xrender) {
-            data->blend_op = PictOpSrc;
+            data->blend_op = PictOpOver;
             return 0;
         }
     case SDL_BLENDMODE_MASK:
@@ -1211,7 +1211,7 @@
               renderer->blendMode != SDL_BLENDMODE_ADD &&
               renderer->blendMode != SDL_BLENDMODE_MOD))
         {
-            XSetForeground(data->display, data->stencil_gc, 0x00000000);
+            XSetForeground(data->display, data->stencil_gc, 0);
 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
             if (data->use_xdamage)
             {
@@ -1229,7 +1229,7 @@
                 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
             }
 #endif
-            XSetForeground(data->display, data->stencil_gc, 0xFF);
+            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
 
             XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
                         CoordModeOrigin);
@@ -1323,7 +1323,7 @@
             drawable = data->stencil;
             gc = data->stencil_gc;
 
-            XSetForeground(data->display, data->stencil_gc, 0x00000000);
+            XSetForeground(data->display, data->stencil_gc, 0);
 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
             if (data->use_xdamage)
                 XFixesSetGCClipRegion(data->display, data->stencil_gc,
@@ -1336,7 +1336,7 @@
                 XFixesSetGCClipRegion(data->display, data->stencil_gc,
                                       0, 0, None);
 #endif
-            XSetForeground(data->display, data->stencil_gc, 0xFF);
+            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
         }
         else
 #endif
@@ -1536,7 +1536,7 @@
               renderer->blendMode != SDL_BLENDMODE_ADD &&
               renderer->blendMode != SDL_BLENDMODE_MOD))
         {
-            XSetForeground(data->display, data->stencil_gc, 0x00000000);
+            XSetForeground(data->display, data->stencil_gc, 0);
 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
             if (data->use_xdamage)
                 XFixesSetGCClipRegion(data->display, data->stencil_gc,
@@ -1549,7 +1549,7 @@
                 XFixesSetGCClipRegion(data->display, data->stencil_gc,
                                       0, 0, None);
 #endif
-            XSetForeground(data->display, data->stencil_gc, 0xFF);
+            XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF);
 
             XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
 
@@ -1695,35 +1695,35 @@
                           dstrect->y, srcrect->w, srcrect->h);
             }
         }
-        Picture src, mask, dst;
+        Picture mask;
         XRenderPictureAttributes attr;
+        const SDL_Rect *mrect;
         if(texture->blendMode == SDL_BLENDMODE_NONE) {
-            src = texturedata->picture;
             mask = None;
-            dst = data->drawable_pict;
+            mrect = srcrect;
         }
-        /*else if (texture->blendMode == SDL_BLENDMODE_MOD) {
-            src = data->drawable_pict;
+        else if (texture->blendMode == SDL_BLENDMODE_MOD) {
+            mask = data->stencil_pict;
+                        mrect = dstrect;
+        }
+        else {
             mask = texturedata->picture;
-            dst = data->drawable_pict;
-            attr.alpha_map = mask;
-        }*/
-        else {
-            src = texturedata->picture;
-            mask = texturedata->picture;
-            dst = data->drawable_pict;
+            mrect = srcrect;
         }
         if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
-            /*if (texture->blendMode == SDL_BLENDMODE_MOD) {
+            if (texture->blendMode == SDL_BLENDMODE_MOD) {
+                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
+                             texturedata->picture, data->stencil_pict,
+                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
+                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
                 attr.component_alpha = True;
-                XRenderChangePicture(data->display, texturedata->picture,
+                XRenderChangePicture(data->display, data->stencil_pict,
                                      CPComponentAlpha, &attr);
-                XRenderChangePicture(data->display, src, CPAlphaMap, &attr);
-            }*/
-            XRenderComposite(data->display, texturedata->blend_op, src,
-                            mask, dst, srcrect->x, srcrect->y,
-                            srcrect->x, srcrect->y, dstrect->x, dstrect->y,
-                            srcrect->w, srcrect->h);
+            }
+            XRenderComposite(data->display, texturedata->blend_op, texturedata->picture,
+                            mask, data->drawable_pict, srcrect->x, srcrect->y,
+                            mrect->x, mrect->y, dstrect->x, dstrect->y,
+                            dstrect->w, dstrect->h);
         } else {
             double xscale = ((double) dstrect->w) / srcrect->w;
             double yscale = ((double) dstrect->h) / srcrect->h;
@@ -1733,19 +1733,22 @@
                     {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
             XRenderSetPictureTransform(data->display, texturedata->picture, &xform);
             
-            /*if (texture->blendMode == SDL_BLENDMODE_MOD) {
+            if (texture->blendMode == SDL_BLENDMODE_MOD) {
+                XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
+                             texturedata->picture, data->stencil_pict,
+                             dstrect->x, dstrect->y, srcrect->x, srcrect->y,
+                             dstrect->x, dstrect->y, dstrect->w, dstrect->h);
                 attr.component_alpha = True;
-                XRenderChangePicture(data->display, texturedata->picture,
+                XRenderChangePicture(data->display, data->stencil_pict,
                                      CPComponentAlpha, &attr);
-                XRenderChangePicture(data->display, src, CPAlphaMap, &attr);
-            }*/
+            }
 
             XRenderSetPictureFilter(data->display, texturedata->picture,
                                     texturedata->filter, 0, 0);
 
             XRenderComposite(data->display, texturedata->blend_op,
-                             src, mask, dst,
-                             srcrect->x, srcrect->y, srcrect->x, srcrect->y,
+                             texturedata->picture, mask, data->drawable_pict,
+                             srcrect->x, srcrect->y, mrect->x, mrect->y,
                              dstrect->x, dstrect->y, dstrect->w, dstrect->h);
             
             XTransform identity = {{
@@ -1754,14 +1757,11 @@
                     {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
             XRenderSetPictureTransform(data->display, texturedata->picture, &identity);
         }
-        /*if (renderer->blendMode == SDL_BLENDMODE_MOD) {
+        if (renderer->blendMode == SDL_BLENDMODE_MOD) {
             attr.component_alpha = False;
-            XRenderChangePicture(data->display, texturedata->picture,
+            XRenderChangePicture(data->display, data->stencil_pict,
                                  CPComponentAlpha, &attr);
-            attr.alpha_map = None;
-            XRenderChangePicture(data->display, data->drawable_pict,
-                                 CPAlphaMap, &attr);
-        }*/
+        }
     }
     else
 #endif