Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_d3drender.c @ 1905:36d52b1f0504
Prefer the D3D renderer over GDI, at least for testing.
Added support for the SDL_VIDEO_RENDERER environment variable to pick the desired render driver.
Implemented WritePixels support for the D3D renderer.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Jul 2006 08:22:45 +0000 |
parents | 1a713f9d1f71 |
children | 06c27a737b7a |
comparison
equal
deleted
inserted
replaced
1904:1a713f9d1f71 | 1905:36d52b1f0504 |
---|---|
72 | 72 |
73 SDL_RenderDriver SDL_D3D_RenderDriver = { | 73 SDL_RenderDriver SDL_D3D_RenderDriver = { |
74 SDL_D3D_CreateRenderer, | 74 SDL_D3D_CreateRenderer, |
75 { | 75 { |
76 "d3d", | 76 "d3d", |
77 ( //SDL_Renderer_Minimal | | 77 (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy | |
78 SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy | | 78 SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 | |
79 SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 | | 79 SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget), |
80 SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget), | |
81 (SDL_TextureBlendMode_None | | 80 (SDL_TextureBlendMode_None | |
82 SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend), | 81 SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend), |
83 (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast), | 82 (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast), |
84 12, | 83 12, |
85 { | 84 { |
100 }; | 99 }; |
101 | 100 |
102 typedef struct | 101 typedef struct |
103 { | 102 { |
104 IDirect3DDevice9 *device; | 103 IDirect3DDevice9 *device; |
104 IDirect3DSurface9 *surface; | |
105 IDirect3DSurface9 *offscreen; | |
105 SDL_bool beginScene; | 106 SDL_bool beginScene; |
106 } SDL_D3D_RenderData; | 107 } SDL_D3D_RenderData; |
107 | 108 |
108 typedef struct | 109 typedef struct |
109 { | 110 { |
528 | 529 |
529 static void | 530 static void |
530 SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 531 SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
531 { | 532 { |
532 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; | 533 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; |
534 | |
535 /* FIXME */ | |
533 } | 536 } |
534 | 537 |
535 static int | 538 static int |
536 SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, | 539 SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, |
537 Uint32 color) | 540 Uint32 color) |
638 SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 641 SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
639 void *pixels, int pitch) | 642 void *pixels, int pitch) |
640 { | 643 { |
641 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; | 644 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; |
642 | 645 |
646 /* FIXME */ | |
643 return 0; | 647 return 0; |
644 } | 648 } |
645 | 649 |
646 static int | 650 static int |
647 SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, | 651 SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, |
648 const void *pixels, int pitch) | 652 const void *pixels, int pitch) |
649 { | 653 { |
654 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
655 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
650 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; | 656 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; |
657 RECT d3drect; | |
658 POINT point; | |
659 D3DLOCKED_RECT locked; | |
660 const Uint8 *src; | |
661 Uint8 *dst; | |
662 int row, length; | |
663 HRESULT result; | |
664 | |
665 if (!data->surface) { | |
666 result = | |
667 IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, | |
668 D3DBACKBUFFER_TYPE_MONO, | |
669 &data->surface); | |
670 if (FAILED(result)) { | |
671 D3D_SetError("GetBackBuffer()", result); | |
672 return -1; | |
673 } | |
674 } | |
675 if (!data->offscreen) { | |
676 result = | |
677 IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, | |
678 window->w, window->h, | |
679 PixelFormatToD3DFMT | |
680 (display-> | |
681 current_mode. | |
682 format), | |
683 D3DPOOL_SYSTEMMEM, | |
684 &data->offscreen, | |
685 NULL); | |
686 if (FAILED(result)) { | |
687 D3D_SetError("CreateOffscreenPlainSurface()", result); | |
688 return -1; | |
689 } | |
690 } | |
691 | |
692 d3drect.left = rect->x; | |
693 d3drect.right = rect->x + rect->w; | |
694 d3drect.top = rect->y; | |
695 d3drect.bottom = rect->y + rect->h; | |
696 | |
697 result = | |
698 IDirect3DSurface9_LockRect(data->offscreen, &locked, &d3drect, 0); | |
699 if (FAILED(result)) { | |
700 D3D_SetError("LockRect()", result); | |
701 return -1; | |
702 } | |
703 | |
704 src = pixels; | |
705 dst = locked.pBits; | |
706 length = rect->w * SDL_BYTESPERPIXEL(display->current_mode.format); | |
707 for (row = 0; row < rect->h; ++row) { | |
708 SDL_memcpy(dst, src, length); | |
709 src += pitch; | |
710 dst += locked.Pitch; | |
711 } | |
712 IDirect3DSurface9_UnlockRect(data->offscreen); | |
713 | |
714 point.x = rect->x; | |
715 point.y = rect->y; | |
716 result = | |
717 IDirect3DDevice9_UpdateSurface(data->device, data->offscreen, | |
718 &d3drect, data->surface, &point); | |
719 if (FAILED(result)) { | |
720 D3D_SetError("UpdateSurface()", result); | |
721 return -1; | |
722 } | |
651 | 723 |
652 return 0; | 724 return 0; |
653 } | 725 } |
654 | 726 |
655 static void | 727 static void |
691 | 763 |
692 if (data) { | 764 if (data) { |
693 if (data->device) { | 765 if (data->device) { |
694 IDirect3DDevice9_Release(data->device); | 766 IDirect3DDevice9_Release(data->device); |
695 } | 767 } |
768 if (data->surface) { | |
769 IDirect3DSurface9_Release(data->surface); | |
770 } | |
771 if (data->offscreen) { | |
772 IDirect3DSurface9_Release(data->offscreen); | |
773 } | |
696 SDL_free(data); | 774 SDL_free(data); |
697 } | 775 } |
698 SDL_free(renderer); | 776 SDL_free(renderer); |
699 } | 777 } |
700 | 778 |