comparison src/video/win32/SDL_gdirender.c @ 1985:8055185ae4ed

Added source color and alpha modulation support. Added perl script to generate optimized render copy functions.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 28 Aug 2006 03:17:39 +0000
parents ccef0d0c40c6
children 926294b2bb4e
comparison
equal deleted inserted replaced
1984:b910bcabec26 1985:8055185ae4ed
40 const SDL_Color * colors, int firstcolor, 40 const SDL_Color * colors, int firstcolor,
41 int ncolors); 41 int ncolors);
42 static int GDI_GetTexturePalette(SDL_Renderer * renderer, 42 static int GDI_GetTexturePalette(SDL_Renderer * renderer,
43 SDL_Texture * texture, SDL_Color * colors, 43 SDL_Texture * texture, SDL_Color * colors,
44 int firstcolor, int ncolors); 44 int firstcolor, int ncolors);
45 static int GDI_SetTextureAlphaMod(SDL_Renderer * renderer,
46 SDL_Texture * texture);
47 static int GDI_SetTextureBlendMode(SDL_Renderer * renderer,
48 SDL_Texture * texture);
49 static int GDI_SetTextureScaleMode(SDL_Renderer * renderer,
50 SDL_Texture * texture);
45 static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 51 static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
46 const SDL_Rect * rect, const void *pixels, 52 const SDL_Rect * rect, const void *pixels,
47 int pitch); 53 int pitch);
48 static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 54 static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
49 const SDL_Rect * rect, int markDirty, 55 const SDL_Rect * rect, int markDirty,
50 void **pixels, int *pitch); 56 void **pixels, int *pitch);
51 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 57 static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
52 static void GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 58 static void GDI_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
53 int numrects, const SDL_Rect * rects); 59 int numrects, const SDL_Rect * rects);
54 static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, 60 static int GDI_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
55 Uint32 color); 61 Uint8 a, const SDL_Rect * rect);
56 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 62 static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
57 const SDL_Rect * srcrect, const SDL_Rect * dstrect, 63 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
58 int blendMode, int scaleMode);
59 static void GDI_RenderPresent(SDL_Renderer * renderer); 64 static void GDI_RenderPresent(SDL_Renderer * renderer);
60 static void GDI_DestroyTexture(SDL_Renderer * renderer, 65 static void GDI_DestroyTexture(SDL_Renderer * renderer,
61 SDL_Texture * texture); 66 SDL_Texture * texture);
62 static void GDI_DestroyRenderer(SDL_Renderer * renderer); 67 static void GDI_DestroyRenderer(SDL_Renderer * renderer);
63 68
67 { 72 {
68 "gdi", 73 "gdi",
69 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 74 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
70 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | 75 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
71 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), 76 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
77 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_ALPHA),
72 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | 78 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
73 SDL_TEXTUREBLENDMODE_BLEND), 79 SDL_TEXTUREBLENDMODE_BLEND),
74 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST), 80 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST),
75 11, 81 11,
76 { 82 {
159 renderer->DisplayModeChanged = GDI_DisplayModeChanged; 165 renderer->DisplayModeChanged = GDI_DisplayModeChanged;
160 renderer->CreateTexture = GDI_CreateTexture; 166 renderer->CreateTexture = GDI_CreateTexture;
161 renderer->QueryTexturePixels = GDI_QueryTexturePixels; 167 renderer->QueryTexturePixels = GDI_QueryTexturePixels;
162 renderer->SetTexturePalette = GDI_SetTexturePalette; 168 renderer->SetTexturePalette = GDI_SetTexturePalette;
163 renderer->GetTexturePalette = GDI_GetTexturePalette; 169 renderer->GetTexturePalette = GDI_GetTexturePalette;
170 renderer->SetTextureAlphaMod = GDI_SetTextureAlphaMod;
171 renderer->SetTextureBlendMode = GDI_SetTextureBlendMode;
172 renderer->SetTextureScaleMode = GDI_SetTextureScaleMode;
164 renderer->UpdateTexture = GDI_UpdateTexture; 173 renderer->UpdateTexture = GDI_UpdateTexture;
165 renderer->LockTexture = GDI_LockTexture; 174 renderer->LockTexture = GDI_LockTexture;
166 renderer->UnlockTexture = GDI_UnlockTexture; 175 renderer->UnlockTexture = GDI_UnlockTexture;
167 renderer->DirtyTexture = GDI_DirtyTexture; 176 renderer->DirtyTexture = GDI_DirtyTexture;
168 renderer->RenderFill = GDI_RenderFill; 177 renderer->RenderFill = GDI_RenderFill;
436 return 0; 445 return 0;
437 } 446 }
438 } 447 }
439 448
440 static int 449 static int
450 GDI_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
451 {
452 return 0;
453 }
454
455 static int
456 GDI_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
457 {
458 switch (texture->blendMode) {
459 case SDL_TEXTUREBLENDMODE_NONE:
460 case SDL_TEXTUREBLENDMODE_MASK:
461 case SDL_TEXTUREBLENDMODE_BLEND:
462 return 0;
463 default:
464 SDL_Unsupported();
465 texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
466 return -1;
467 }
468 }
469
470 static int
471 GDI_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
472 {
473 switch (texture->scaleMode) {
474 case SDL_TEXTURESCALEMODE_NONE:
475 case SDL_TEXTURESCALEMODE_FAST:
476 return 0;
477 case SDL_TEXTURESCALEMODE_SLOW:
478 case SDL_TEXTURESCALEMODE_BEST:
479 SDL_Unsupported();
480 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
481 return -1;
482 default:
483 SDL_Unsupported();
484 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
485 return -1;
486 }
487 return 0;
488 }
489
490 static int
441 GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 491 GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
442 const SDL_Rect * rect, const void *pixels, int pitch) 492 const SDL_Rect * rect, const void *pixels, int pitch)
443 { 493 {
444 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata; 494 GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
445 495
522 const SDL_Rect * rects) 572 const SDL_Rect * rects)
523 { 573 {
524 } 574 }
525 575
526 static int 576 static int
527 GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color) 577 GDI_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
578 const SDL_Rect * rect)
528 { 579 {
529 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; 580 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
530 Uint8 r, g, b;
531 RECT rc; 581 RECT rc;
532 HBRUSH brush; 582 HBRUSH brush;
533 int status; 583 int status;
534 584
535 if (data->makedirty) { 585 if (data->makedirty) {
536 SDL_AddDirtyRect(&data->dirty, rect); 586 SDL_AddDirtyRect(&data->dirty, rect);
537 } 587 }
538
539 r = (Uint8) ((color >> 16) & 0xFF);
540 g = (Uint8) ((color >> 8) & 0xFF);
541 b = (Uint8) (color & 0xFF);
542 588
543 rc.left = rect->x; 589 rc.left = rect->x;
544 rc.top = rect->y; 590 rc.top = rect->y;
545 rc.right = rect->x + rect->w + 1; 591 rc.right = rect->x + rect->w + 1;
546 rc.bottom = rect->y + rect->h + 1; 592 rc.bottom = rect->y + rect->h + 1;
558 return 0; 604 return 0;
559 } 605 }
560 606
561 static int 607 static int
562 GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 608 GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
563 const SDL_Rect * srcrect, const SDL_Rect * dstrect, 609 const SDL_Rect * srcrect, const SDL_Rect * dstrect)
564 int blendMode, int scaleMode)
565 { 610 {
566 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; 611 GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
567 GDI_TextureData *texturedata = (GDI_TextureData *) texture->driverdata; 612 GDI_TextureData *texturedata = (GDI_TextureData *) texture->driverdata;
568 613
569 if (data->makedirty) { 614 if (data->makedirty) {
573 SelectObject(data->memory_hdc, texturedata->hbm); 618 SelectObject(data->memory_hdc, texturedata->hbm);
574 if (texturedata->hpal) { 619 if (texturedata->hpal) {
575 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE); 620 SelectPalette(data->memory_hdc, texturedata->hpal, TRUE);
576 RealizePalette(data->memory_hdc); 621 RealizePalette(data->memory_hdc);
577 } 622 }
578 if (blendMode & (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND)) { 623 if (texture->
579 static BLENDFUNCTION blendFunc = { 624 blendMode & (SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND))
625 {
626 BLENDFUNCTION blendFunc = {
580 AC_SRC_OVER, 627 AC_SRC_OVER,
581 0, 628 0,
582 255, 629 texture->a,
583 AC_SRC_ALPHA 630 AC_SRC_ALPHA
584 }; 631 };
585 /* FIXME: GDI uses premultiplied alpha! */ 632 /* FIXME: GDI uses premultiplied alpha! */
586 if (!AlphaBlend 633 if (!AlphaBlend
587 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w, 634 (data->current_hdc, dstrect->x, dstrect->y, dstrect->w,