Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_d3drender.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 | b1620a317791 |
children | 36a08379b3f2 |
comparison
equal
deleted
inserted
replaced
1984:b910bcabec26 | 1985:8055185ae4ed |
---|---|
35 const SDL_Color * colors, int firstcolor, | 35 const SDL_Color * colors, int firstcolor, |
36 int ncolors); | 36 int ncolors); |
37 static int D3D_GetTexturePalette(SDL_Renderer * renderer, | 37 static int D3D_GetTexturePalette(SDL_Renderer * renderer, |
38 SDL_Texture * texture, SDL_Color * colors, | 38 SDL_Texture * texture, SDL_Color * colors, |
39 int firstcolor, int ncolors); | 39 int firstcolor, int ncolors); |
40 static int D3D_SetTextureColorMod(SDL_Renderer * renderer, | |
41 SDL_Texture * texture); | |
42 static int D3D_SetTextureAlphaMod(SDL_Renderer * renderer, | |
43 SDL_Texture * texture); | |
44 static int D3D_SetTextureBlendMode(SDL_Renderer * renderer, | |
45 SDL_Texture * texture); | |
46 static int D3D_SetTextureScaleMode(SDL_Renderer * renderer, | |
47 SDL_Texture * texture); | |
40 static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 48 static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
41 const SDL_Rect * rect, const void *pixels, | 49 const SDL_Rect * rect, const void *pixels, |
42 int pitch); | 50 int pitch); |
43 static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 51 static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
44 const SDL_Rect * rect, int markDirty, | 52 const SDL_Rect * rect, int markDirty, |
45 void **pixels, int *pitch); | 53 void **pixels, int *pitch); |
46 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 54 static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
47 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 55 static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
48 int numrects, const SDL_Rect * rects); | 56 int numrects, const SDL_Rect * rects); |
49 static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, | 57 static int D3D_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, |
50 Uint32 color); | 58 Uint8 a, const SDL_Rect * rect); |
51 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 59 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
52 const SDL_Rect * srcrect, const SDL_Rect * dstrect, | 60 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
53 int blendMode, int scaleMode); | |
54 static void D3D_RenderPresent(SDL_Renderer * renderer); | 61 static void D3D_RenderPresent(SDL_Renderer * renderer); |
55 static void D3D_DestroyTexture(SDL_Renderer * renderer, | 62 static void D3D_DestroyTexture(SDL_Renderer * renderer, |
56 SDL_Texture * texture); | 63 SDL_Texture * texture); |
57 static void D3D_DestroyRenderer(SDL_Renderer * renderer); | 64 static void D3D_DestroyRenderer(SDL_Renderer * renderer); |
58 | 65 |
63 "d3d", | 70 "d3d", |
64 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | | 71 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | |
65 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | 72 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | |
66 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC | | 73 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC | |
67 SDL_RENDERER_ACCELERATED), | 74 SDL_RENDERER_ACCELERATED), |
75 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | | |
76 SDL_TEXTUREMODULATE_ALPHA), | |
68 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | | 77 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | |
69 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | | 78 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | |
70 SDL_TEXTUREBLENDMODE_MOD), | 79 SDL_TEXTUREBLENDMODE_MOD), |
71 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | | 80 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | |
72 SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST), | 81 SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST), |
257 | 266 |
258 renderer->DisplayModeChanged = D3D_DisplayModeChanged; | 267 renderer->DisplayModeChanged = D3D_DisplayModeChanged; |
259 renderer->CreateTexture = D3D_CreateTexture; | 268 renderer->CreateTexture = D3D_CreateTexture; |
260 renderer->SetTexturePalette = D3D_SetTexturePalette; | 269 renderer->SetTexturePalette = D3D_SetTexturePalette; |
261 renderer->GetTexturePalette = D3D_GetTexturePalette; | 270 renderer->GetTexturePalette = D3D_GetTexturePalette; |
271 renderer->SetTextureColorMod = D3D_SetTextureColorMod; | |
272 renderer->SetTextureAlphaMod = D3D_SetTextureAlphaMod; | |
273 renderer->SetTextureBlendMode = D3D_SetTextureBlendMode; | |
274 renderer->SetTextureScaleMode = D3D_SetTextureScaleMode; | |
262 renderer->UpdateTexture = D3D_UpdateTexture; | 275 renderer->UpdateTexture = D3D_UpdateTexture; |
263 renderer->LockTexture = D3D_LockTexture; | 276 renderer->LockTexture = D3D_LockTexture; |
264 renderer->UnlockTexture = D3D_UnlockTexture; | 277 renderer->UnlockTexture = D3D_UnlockTexture; |
265 renderer->DirtyTexture = D3D_DirtyTexture; | 278 renderer->DirtyTexture = D3D_DirtyTexture; |
266 renderer->RenderFill = D3D_RenderFill; | 279 renderer->RenderFill = D3D_RenderFill; |
476 | 489 |
477 return 0; | 490 return 0; |
478 } | 491 } |
479 | 492 |
480 static int | 493 static int |
494 D3D_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
495 { | |
496 /* FIXME: implement vertex coloring */ | |
497 return -1; | |
498 } | |
499 | |
500 static int | |
501 D3D_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
502 { | |
503 /* FIXME: implement vertex coloring */ | |
504 return -1; | |
505 } | |
506 | |
507 static int | |
508 D3D_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
509 { | |
510 switch (texture->blendMode) { | |
511 case SDL_TEXTUREBLENDMODE_NONE: | |
512 case SDL_TEXTUREBLENDMODE_MASK: | |
513 case SDL_TEXTUREBLENDMODE_BLEND: | |
514 case SDL_TEXTUREBLENDMODE_ADD: | |
515 case SDL_TEXTUREBLENDMODE_MOD: | |
516 return 0; | |
517 default: | |
518 SDL_Unsupported(); | |
519 texture->blendMode = SDL_TEXTUREBLENDMODE_NONE; | |
520 return -1; | |
521 } | |
522 } | |
523 | |
524 static int | |
525 D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
526 { | |
527 switch (texture->scaleMode) { | |
528 case SDL_TEXTURESCALEMODE_NONE: | |
529 case SDL_TEXTURESCALEMODE_FAST: | |
530 case SDL_TEXTURESCALEMODE_SLOW: | |
531 case SDL_TEXTURESCALEMODE_BEST: | |
532 return 0; | |
533 default: | |
534 SDL_Unsupported(); | |
535 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; | |
536 return -1; | |
537 } | |
538 return 0; | |
539 } | |
540 | |
541 static int | |
481 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 542 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
482 const SDL_Rect * rect, const void *pixels, int pitch) | 543 const SDL_Rect * rect, const void *pixels, int pitch) |
483 { | 544 { |
484 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; | 545 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; |
485 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata; | 546 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata; |
595 IDirect3DTexture9_AddDirtyRect(data->texture, &d3drect); | 656 IDirect3DTexture9_AddDirtyRect(data->texture, &d3drect); |
596 } | 657 } |
597 } | 658 } |
598 | 659 |
599 static int | 660 static int |
600 D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color) | 661 D3D_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, |
662 const SDL_Rect * rect) | |
601 { | 663 { |
602 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; | 664 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; |
603 D3DRECT d3drect; | 665 D3DRECT d3drect; |
604 HRESULT result; | 666 HRESULT result; |
605 | 667 |
613 d3drect.y1 = rect->y; | 675 d3drect.y1 = rect->y; |
614 d3drect.y2 = rect->y + rect->h; | 676 d3drect.y2 = rect->y + rect->h; |
615 | 677 |
616 result = | 678 result = |
617 IDirect3DDevice9_Clear(data->device, 1, &d3drect, D3DCLEAR_TARGET, | 679 IDirect3DDevice9_Clear(data->device, 1, &d3drect, D3DCLEAR_TARGET, |
618 (D3DCOLOR) color, 1.0f, 0); | 680 D3DCOLOR_ARGB(a, r, g, b), 1.0f, 0); |
619 if (FAILED(result)) { | 681 if (FAILED(result)) { |
620 D3D_SetError("Clear()", result); | 682 D3D_SetError("Clear()", result); |
621 return -1; | 683 return -1; |
622 } | 684 } |
623 return 0; | 685 return 0; |
624 } | 686 } |
625 | 687 |
626 static int | 688 static int |
627 D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 689 D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
628 const SDL_Rect * srcrect, const SDL_Rect * dstrect, | 690 const SDL_Rect * srcrect, const SDL_Rect * dstrect) |
629 int blendMode, int scaleMode) | |
630 { | 691 { |
631 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; | 692 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; |
632 D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; | 693 D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; |
633 float minx, miny, maxx, maxy; | 694 float minx, miny, maxx, maxy; |
634 float minu, maxu, minv, maxv; | 695 float minu, maxu, minv, maxv; |
676 vertices[3].z = 0.0f; | 737 vertices[3].z = 0.0f; |
677 vertices[3].rhw = 1.0f; | 738 vertices[3].rhw = 1.0f; |
678 vertices[3].u = minu; | 739 vertices[3].u = minu; |
679 vertices[3].v = maxv; | 740 vertices[3].v = maxv; |
680 | 741 |
681 switch (blendMode) { | 742 switch (texture->blendMode) { |
682 case SDL_TEXTUREBLENDMODE_NONE: | 743 case SDL_TEXTUREBLENDMODE_NONE: |
683 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, | 744 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, |
684 FALSE); | 745 FALSE); |
685 break; | 746 break; |
686 case SDL_TEXTUREBLENDMODE_MASK: | 747 case SDL_TEXTUREBLENDMODE_MASK: |
708 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, | 769 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND, |
709 D3DBLEND_SRCCOLOR); | 770 D3DBLEND_SRCCOLOR); |
710 break; | 771 break; |
711 } | 772 } |
712 | 773 |
713 switch (scaleMode) { | 774 switch (texture->scaleMode) { |
714 case SDL_TEXTURESCALEMODE_NONE: | 775 case SDL_TEXTURESCALEMODE_NONE: |
715 case SDL_TEXTURESCALEMODE_FAST: | 776 case SDL_TEXTURESCALEMODE_FAST: |
716 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER, | 777 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER, |
717 D3DTEXF_POINT); | 778 D3DTEXF_POINT); |
718 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER, | 779 IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER, |