Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11render.c @ 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 |
comparison
equal
deleted
inserted
replaced
4606:4e145485971b | 4607:9e9ec5e3be95 |
---|---|
378 /* Add some blending modes to the list of supported blending modes */ | 378 /* Add some blending modes to the list of supported blending modes */ |
379 renderer->info.blend_modes |= | 379 renderer->info.blend_modes |= |
380 (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK | SDL_BLENDMODE_MOD); | 380 (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK | SDL_BLENDMODE_MOD); |
381 /* Create a clip mask that is used for rendering primitives. */ | 381 /* Create a clip mask that is used for rendering primitives. */ |
382 data->stencil = XCreatePixmap(data->display, data->xwindow, | 382 data->stencil = XCreatePixmap(data->display, data->xwindow, |
383 window->w, window->h, 8); | 383 window->w, window->h, 32); |
384 | 384 |
385 /* Create the GC for the clip mask. */ | 385 /* Create the GC for the clip mask. */ |
386 data->stencil_gc = XCreateGC(data->display, data->stencil, | 386 data->stencil_gc = XCreateGC(data->display, data->stencil, |
387 GCGraphicsExposures, &gcv); | 387 GCGraphicsExposures, &gcv); |
388 XSetBackground(data->display, data->stencil_gc, 0x00); | 388 XSetBackground(data->display, data->stencil_gc, 0); |
389 XSetForeground(data->display, data->stencil_gc, 0x00); | 389 XSetForeground(data->display, data->stencil_gc, 0); |
390 XFillRectangle(data->display, data->stencil, data->stencil_gc, | 390 XFillRectangle(data->display, data->stencil, data->stencil_gc, |
391 0, 0, window->w, window->h); | 391 0, 0, window->w, window->h); |
392 XSetForeground(data->display, data->stencil_gc, 0xFF); | 392 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF); |
393 data->stencil_pict = | 393 data->stencil_pict = |
394 XRenderCreatePicture(data->display, data->stencil, | 394 XRenderCreatePicture(data->display, data->stencil, |
395 XRenderFindStandardFormat(data->display, | 395 XRenderFindStandardFormat(data->display, |
396 PictStandardA8), | 396 PictStandardARGB32), |
397 0, NULL); | 397 0, NULL); |
398 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 398 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
399 if (data->use_xdamage) { | 399 if (data->use_xdamage) { |
400 data->stencil_damage = | 400 data->stencil_damage = |
401 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty); | 401 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty); |
933 data->blend_op = PictOpSrc; | 933 data->blend_op = PictOpSrc; |
934 return 0; | 934 return 0; |
935 } | 935 } |
936 case SDL_BLENDMODE_MOD: | 936 case SDL_BLENDMODE_MOD: |
937 if (renderdata->use_xrender) { | 937 if (renderdata->use_xrender) { |
938 data->blend_op = PictOpSrc; | 938 data->blend_op = PictOpOver; |
939 return 0; | 939 return 0; |
940 } | 940 } |
941 case SDL_BLENDMODE_MASK: | 941 case SDL_BLENDMODE_MASK: |
942 case SDL_BLENDMODE_BLEND: | 942 case SDL_BLENDMODE_BLEND: |
943 if (renderdata->use_xrender) { | 943 if (renderdata->use_xrender) { |
1209 (renderer->blendMode != SDL_BLENDMODE_NONE) && | 1209 (renderer->blendMode != SDL_BLENDMODE_NONE) && |
1210 !(renderer->a == 0xFF && | 1210 !(renderer->a == 0xFF && |
1211 renderer->blendMode != SDL_BLENDMODE_ADD && | 1211 renderer->blendMode != SDL_BLENDMODE_ADD && |
1212 renderer->blendMode != SDL_BLENDMODE_MOD)) | 1212 renderer->blendMode != SDL_BLENDMODE_MOD)) |
1213 { | 1213 { |
1214 XSetForeground(data->display, data->stencil_gc, 0x00000000); | 1214 XSetForeground(data->display, data->stencil_gc, 0); |
1215 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1215 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1216 if (data->use_xdamage) | 1216 if (data->use_xdamage) |
1217 { | 1217 { |
1218 /* Update only those parts which were changed | 1218 /* Update only those parts which were changed |
1219 * in the previous drawing operation */ | 1219 * in the previous drawing operation */ |
1227 if (data->use_xdamage) | 1227 if (data->use_xdamage) |
1228 { | 1228 { |
1229 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None); | 1229 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None); |
1230 } | 1230 } |
1231 #endif | 1231 #endif |
1232 XSetForeground(data->display, data->stencil_gc, 0xFF); | 1232 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF); |
1233 | 1233 |
1234 XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount, | 1234 XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount, |
1235 CoordModeOrigin); | 1235 CoordModeOrigin); |
1236 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1236 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1237 if (data->use_xdamage) | 1237 if (data->use_xdamage) |
1321 renderer->blendMode != SDL_BLENDMODE_MOD)) | 1321 renderer->blendMode != SDL_BLENDMODE_MOD)) |
1322 { | 1322 { |
1323 drawable = data->stencil; | 1323 drawable = data->stencil; |
1324 gc = data->stencil_gc; | 1324 gc = data->stencil_gc; |
1325 | 1325 |
1326 XSetForeground(data->display, data->stencil_gc, 0x00000000); | 1326 XSetForeground(data->display, data->stencil_gc, 0); |
1327 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1327 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1328 if (data->use_xdamage) | 1328 if (data->use_xdamage) |
1329 XFixesSetGCClipRegion(data->display, data->stencil_gc, | 1329 XFixesSetGCClipRegion(data->display, data->stencil_gc, |
1330 0, 0, data->stencil_parts); | 1330 0, 0, data->stencil_parts); |
1331 #endif | 1331 #endif |
1334 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1334 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1335 if (data->use_xdamage) | 1335 if (data->use_xdamage) |
1336 XFixesSetGCClipRegion(data->display, data->stencil_gc, | 1336 XFixesSetGCClipRegion(data->display, data->stencil_gc, |
1337 0, 0, None); | 1337 0, 0, None); |
1338 #endif | 1338 #endif |
1339 XSetForeground(data->display, data->stencil_gc, 0xFF); | 1339 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF); |
1340 } | 1340 } |
1341 else | 1341 else |
1342 #endif | 1342 #endif |
1343 { | 1343 { |
1344 drawable = data->drawable; | 1344 drawable = data->drawable; |
1534 (renderer->blendMode != SDL_BLENDMODE_NONE) && | 1534 (renderer->blendMode != SDL_BLENDMODE_NONE) && |
1535 !(renderer->a == 0xFF && | 1535 !(renderer->a == 0xFF && |
1536 renderer->blendMode != SDL_BLENDMODE_ADD && | 1536 renderer->blendMode != SDL_BLENDMODE_ADD && |
1537 renderer->blendMode != SDL_BLENDMODE_MOD)) | 1537 renderer->blendMode != SDL_BLENDMODE_MOD)) |
1538 { | 1538 { |
1539 XSetForeground(data->display, data->stencil_gc, 0x00000000); | 1539 XSetForeground(data->display, data->stencil_gc, 0); |
1540 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1540 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1541 if (data->use_xdamage) | 1541 if (data->use_xdamage) |
1542 XFixesSetGCClipRegion(data->display, data->stencil_gc, | 1542 XFixesSetGCClipRegion(data->display, data->stencil_gc, |
1543 0, 0, data->stencil_parts); | 1543 0, 0, data->stencil_parts); |
1544 #endif | 1544 #endif |
1547 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1547 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1548 if (data->use_xdamage) | 1548 if (data->use_xdamage) |
1549 XFixesSetGCClipRegion(data->display, data->stencil_gc, | 1549 XFixesSetGCClipRegion(data->display, data->stencil_gc, |
1550 0, 0, None); | 1550 0, 0, None); |
1551 #endif | 1551 #endif |
1552 XSetForeground(data->display, data->stencil_gc, 0xFF); | 1552 XSetForeground(data->display, data->stencil_gc, 0xFFFFFFFF); |
1553 | 1553 |
1554 XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount); | 1554 XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount); |
1555 | 1555 |
1556 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE | 1556 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE |
1557 if (data->use_xdamage) | 1557 if (data->use_xdamage) |
1693 XPutImage(data->display, texturedata->pixmap, data->gc, | 1693 XPutImage(data->display, texturedata->pixmap, data->gc, |
1694 texturedata->image, srcrect->x, srcrect->y, dstrect->x, | 1694 texturedata->image, srcrect->x, srcrect->y, dstrect->x, |
1695 dstrect->y, srcrect->w, srcrect->h); | 1695 dstrect->y, srcrect->w, srcrect->h); |
1696 } | 1696 } |
1697 } | 1697 } |
1698 Picture src, mask, dst; | 1698 Picture mask; |
1699 XRenderPictureAttributes attr; | 1699 XRenderPictureAttributes attr; |
1700 const SDL_Rect *mrect; | |
1700 if(texture->blendMode == SDL_BLENDMODE_NONE) { | 1701 if(texture->blendMode == SDL_BLENDMODE_NONE) { |
1701 src = texturedata->picture; | |
1702 mask = None; | 1702 mask = None; |
1703 dst = data->drawable_pict; | 1703 mrect = srcrect; |
1704 } | 1704 } |
1705 /*else if (texture->blendMode == SDL_BLENDMODE_MOD) { | 1705 else if (texture->blendMode == SDL_BLENDMODE_MOD) { |
1706 src = data->drawable_pict; | 1706 mask = data->stencil_pict; |
1707 mrect = dstrect; | |
1708 } | |
1709 else { | |
1707 mask = texturedata->picture; | 1710 mask = texturedata->picture; |
1708 dst = data->drawable_pict; | 1711 mrect = srcrect; |
1709 attr.alpha_map = mask; | |
1710 }*/ | |
1711 else { | |
1712 src = texturedata->picture; | |
1713 mask = texturedata->picture; | |
1714 dst = data->drawable_pict; | |
1715 } | 1712 } |
1716 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) { | 1713 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) { |
1717 /*if (texture->blendMode == SDL_BLENDMODE_MOD) { | 1714 if (texture->blendMode == SDL_BLENDMODE_MOD) { |
1715 XRenderComposite(data->display, PictOpSrc, data->drawable_pict, | |
1716 texturedata->picture, data->stencil_pict, | |
1717 dstrect->x, dstrect->y, srcrect->x, srcrect->y, | |
1718 dstrect->x, dstrect->y, dstrect->w, dstrect->h); | |
1718 attr.component_alpha = True; | 1719 attr.component_alpha = True; |
1719 XRenderChangePicture(data->display, texturedata->picture, | 1720 XRenderChangePicture(data->display, data->stencil_pict, |
1720 CPComponentAlpha, &attr); | 1721 CPComponentAlpha, &attr); |
1721 XRenderChangePicture(data->display, src, CPAlphaMap, &attr); | 1722 } |
1722 }*/ | 1723 XRenderComposite(data->display, texturedata->blend_op, texturedata->picture, |
1723 XRenderComposite(data->display, texturedata->blend_op, src, | 1724 mask, data->drawable_pict, srcrect->x, srcrect->y, |
1724 mask, dst, srcrect->x, srcrect->y, | 1725 mrect->x, mrect->y, dstrect->x, dstrect->y, |
1725 srcrect->x, srcrect->y, dstrect->x, dstrect->y, | 1726 dstrect->w, dstrect->h); |
1726 srcrect->w, srcrect->h); | |
1727 } else { | 1727 } else { |
1728 double xscale = ((double) dstrect->w) / srcrect->w; | 1728 double xscale = ((double) dstrect->w) / srcrect->w; |
1729 double yscale = ((double) dstrect->h) / srcrect->h; | 1729 double yscale = ((double) dstrect->h) / srcrect->h; |
1730 XTransform xform = {{ | 1730 XTransform xform = {{ |
1731 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)}, | 1731 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)}, |
1732 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)}, | 1732 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)}, |
1733 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}}; | 1733 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}}; |
1734 XRenderSetPictureTransform(data->display, texturedata->picture, &xform); | 1734 XRenderSetPictureTransform(data->display, texturedata->picture, &xform); |
1735 | 1735 |
1736 /*if (texture->blendMode == SDL_BLENDMODE_MOD) { | 1736 if (texture->blendMode == SDL_BLENDMODE_MOD) { |
1737 XRenderComposite(data->display, PictOpSrc, data->drawable_pict, | |
1738 texturedata->picture, data->stencil_pict, | |
1739 dstrect->x, dstrect->y, srcrect->x, srcrect->y, | |
1740 dstrect->x, dstrect->y, dstrect->w, dstrect->h); | |
1737 attr.component_alpha = True; | 1741 attr.component_alpha = True; |
1738 XRenderChangePicture(data->display, texturedata->picture, | 1742 XRenderChangePicture(data->display, data->stencil_pict, |
1739 CPComponentAlpha, &attr); | 1743 CPComponentAlpha, &attr); |
1740 XRenderChangePicture(data->display, src, CPAlphaMap, &attr); | 1744 } |
1741 }*/ | |
1742 | 1745 |
1743 XRenderSetPictureFilter(data->display, texturedata->picture, | 1746 XRenderSetPictureFilter(data->display, texturedata->picture, |
1744 texturedata->filter, 0, 0); | 1747 texturedata->filter, 0, 0); |
1745 | 1748 |
1746 XRenderComposite(data->display, texturedata->blend_op, | 1749 XRenderComposite(data->display, texturedata->blend_op, |
1747 src, mask, dst, | 1750 texturedata->picture, mask, data->drawable_pict, |
1748 srcrect->x, srcrect->y, srcrect->x, srcrect->y, | 1751 srcrect->x, srcrect->y, mrect->x, mrect->y, |
1749 dstrect->x, dstrect->y, dstrect->w, dstrect->h); | 1752 dstrect->x, dstrect->y, dstrect->w, dstrect->h); |
1750 | 1753 |
1751 XTransform identity = {{ | 1754 XTransform identity = {{ |
1752 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)}, | 1755 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)}, |
1753 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)}, | 1756 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)}, |
1754 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}}; | 1757 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}}; |
1755 XRenderSetPictureTransform(data->display, texturedata->picture, &identity); | 1758 XRenderSetPictureTransform(data->display, texturedata->picture, &identity); |
1756 } | 1759 } |
1757 /*if (renderer->blendMode == SDL_BLENDMODE_MOD) { | 1760 if (renderer->blendMode == SDL_BLENDMODE_MOD) { |
1758 attr.component_alpha = False; | 1761 attr.component_alpha = False; |
1759 XRenderChangePicture(data->display, texturedata->picture, | 1762 XRenderChangePicture(data->display, data->stencil_pict, |
1760 CPComponentAlpha, &attr); | 1763 CPComponentAlpha, &attr); |
1761 attr.alpha_map = None; | 1764 } |
1762 XRenderChangePicture(data->display, data->drawable_pict, | |
1763 CPAlphaMap, &attr); | |
1764 }*/ | |
1765 } | 1765 } |
1766 else | 1766 else |
1767 #endif | 1767 #endif |
1768 { | 1768 { |
1769 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { | 1769 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { |