comparison src/video/directfb/SDL_DirectFB_render.c @ 5143:e743b9c3f6d6

Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 31 Jan 2011 23:23:57 -0800
parents da10636e5eca
children 31e7f523ab3d
comparison
equal deleted inserted replaced
5142:57851a238c8f 5143:e743b9c3f6d6
53 int firstcolor, int ncolors); 53 int firstcolor, int ncolors);
54 static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, 54 static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
55 SDL_Texture * texture); 55 SDL_Texture * texture);
56 static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer, 56 static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
57 SDL_Texture * texture); 57 SDL_Texture * texture);
58 static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
59 SDL_Texture * texture);
60 static int DirectFB_UpdateTexture(SDL_Renderer * renderer, 58 static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
61 SDL_Texture * texture, 59 SDL_Texture * texture,
62 const SDL_Rect * rect, 60 const SDL_Rect * rect,
63 const void *pixels, int pitch); 61 const void *pixels, int pitch);
64 static int DirectFB_LockTexture(SDL_Renderer * renderer, 62 static int DirectFB_LockTexture(SDL_Renderer * renderer,
98 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | 96 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
99 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD | 97 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD |
100 SDL_RENDERER_ACCELERATED), 98 SDL_RENDERER_ACCELERATED),
101 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | 99 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
102 SDL_TEXTUREMODULATE_ALPHA), 100 SDL_TEXTUREMODULATE_ALPHA),
103 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
104 SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
105 14, 101 14,
106 { 102 {
107 SDL_PIXELFORMAT_INDEX4LSB, 103 SDL_PIXELFORMAT_INDEX4LSB,
108 SDL_PIXELFORMAT_INDEX8, 104 SDL_PIXELFORMAT_INDEX8,
109 SDL_PIXELFORMAT_RGB332, 105 SDL_PIXELFORMAT_RGB332,
192 data->blitFlags = DSBLIT_NOFX; 188 data->blitFlags = DSBLIT_NOFX;
193 data->drawFlags = DSDRAW_NOFX; 189 data->drawFlags = DSDRAW_NOFX;
194 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); 190 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
195 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO)); 191 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
196 break; 192 break;
197 case SDL_BLENDMODE_MASK:
198 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
199 data->drawFlags = DSDRAW_BLEND;
200 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
201 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
202 break;
203 case SDL_BLENDMODE_BLEND: 193 case SDL_BLENDMODE_BLEND:
204 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL; 194 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
205 data->drawFlags = DSDRAW_BLEND; 195 data->drawFlags = DSDRAW_BLEND;
206 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); 196 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
207 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA)); 197 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
216 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); 206 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
217 else 207 else
218 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); 208 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
219 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE)); 209 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE));
220 break; 210 break;
221 case SDL_BLENDMODE_MOD:
222 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
223 data->drawFlags = DSDRAW_BLEND;
224 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR));
225 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
226 break;
227 } 211 }
228 data->lastBlendMode = blendMode; 212 data->lastBlendMode = blendMode;
229 } 213 }
230 } 214 }
231 215
291 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; 275 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
292 renderer->SetTexturePalette = DirectFB_SetTexturePalette; 276 renderer->SetTexturePalette = DirectFB_SetTexturePalette;
293 renderer->GetTexturePalette = DirectFB_GetTexturePalette; 277 renderer->GetTexturePalette = DirectFB_GetTexturePalette;
294 renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod; 278 renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
295 renderer->SetTextureColorMod = DirectFB_SetTextureColorMod; 279 renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
296 renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
297 renderer->UpdateTexture = DirectFB_UpdateTexture; 280 renderer->UpdateTexture = DirectFB_UpdateTexture;
298 renderer->LockTexture = DirectFB_LockTexture; 281 renderer->LockTexture = DirectFB_LockTexture;
299 renderer->UnlockTexture = DirectFB_UnlockTexture; 282 renderer->UnlockTexture = DirectFB_UnlockTexture;
300 renderer->DirtyTexture = DirectFB_DirtyTexture; 283 renderer->DirtyTexture = DirectFB_DirtyTexture;
301 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; 284 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
663 { 646 {
664 return 0; 647 return 0;
665 } 648 }
666 649
667 static int 650 static int
668 DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
669 {
670 switch (texture->blendMode) {
671 case SDL_BLENDMODE_NONE:
672 case SDL_BLENDMODE_MASK:
673 case SDL_BLENDMODE_BLEND:
674 case SDL_BLENDMODE_ADD:
675 case SDL_BLENDMODE_MOD:
676 return 0;
677 default:
678 SDL_Unsupported();
679 texture->blendMode = SDL_BLENDMODE_NONE;
680 return -1;
681 }
682 }
683
684 static int
685 DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
686 {
687 switch (renderer->blendMode) {
688 case SDL_BLENDMODE_NONE:
689 case SDL_BLENDMODE_MASK:
690 case SDL_BLENDMODE_BLEND:
691 case SDL_BLENDMODE_ADD:
692 case SDL_BLENDMODE_MOD:
693 return 0;
694 default:
695 SDL_Unsupported();
696 renderer->blendMode = SDL_BLENDMODE_NONE;
697 return -1;
698 }
699 }
700
701 static int
702 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) 651 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
703 { 652 {
704 #if (DFB_VERSION_ATLEAST(1,2,0)) 653 #if (DFB_VERSION_ATLEAST(1,2,0))
705 654
706 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 655 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
850 SetBlendMode(data, renderer->blendMode, NULL); 799 SetBlendMode(data, renderer->blendMode, NULL);
851 SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags)); 800 SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags));
852 801
853 switch (renderer->blendMode) { 802 switch (renderer->blendMode) {
854 case SDL_BLENDMODE_NONE: 803 case SDL_BLENDMODE_NONE:
855 case SDL_BLENDMODE_MASK:
856 case SDL_BLENDMODE_BLEND: 804 case SDL_BLENDMODE_BLEND:
857 break; 805 break;
858 case SDL_BLENDMODE_ADD: 806 case SDL_BLENDMODE_ADD:
859 case SDL_BLENDMODE_MOD:
860 r = ((int) r * (int) a) / 255; 807 r = ((int) r * (int) a) / 255;
861 g = ((int) g * (int) a) / 255; 808 g = ((int) g * (int) a) / 255;
862 b = ((int) b * (int) a) / 255; 809 b = ((int) b * (int) a) / 255;
863 a = 255; 810 a = 255;
864 break; 811 break;