comparison src/video/win32/SDL_d3drender.c @ 2783:e33ad7ebb7eb

Fixed Direct3D rendering
author Sam Lantinga <slouken@libsdl.org>
date Tue, 25 Nov 2008 00:29:44 +0000
parents 204be4fc2726
children 6bacfecbf27e
comparison
equal deleted inserted replaced
2782:53689036f265 2783:e33ad7ebb7eb
24 #if SDL_VIDEO_RENDER_D3D 24 #if SDL_VIDEO_RENDER_D3D
25 25
26 #include "SDL_win32video.h" 26 #include "SDL_win32video.h"
27 27
28 /* Direct3D renderer implementation */ 28 /* Direct3D renderer implementation */
29
30 #if 1 /* This takes more memory but you won't lose your texture data */
31 #define D3DPOOL_SDL D3DPOOL_MANAGED
32 #define SDL_MEMORY_POOL_MANAGED
33 #else
34 #define D3DPOOL_SDL D3DPOOL_DEFAULT
35 #define SDL_MEMORY_POOL_DEFAULT
36 #endif
29 37
30 static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags); 38 static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
31 static int D3D_DisplayModeChanged(SDL_Renderer * renderer); 39 static int D3D_DisplayModeChanged(SDL_Renderer * renderer);
32 static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); 40 static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
33 static int D3D_SetTexturePalette(SDL_Renderer * renderer, 41 static int D3D_SetTexturePalette(SDL_Renderer * renderer,
471 479
472 result = 480 result =
473 IDirect3DDevice9_CreateTexture(renderdata->device, texture->w, 481 IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
474 texture->h, 1, 0, 482 texture->h, 1, 0,
475 PixelFormatToD3DFMT(texture->format), 483 PixelFormatToD3DFMT(texture->format),
476 D3DPOOL_MANAGED, &data->texture, NULL); 484 D3DPOOL_SDL, &data->texture, NULL);
477 if (FAILED(result)) { 485 if (FAILED(result)) {
478 D3D_SetError("CreateTexture()", result); 486 D3D_SetError("CreateTexture()", result);
479 return -1; 487 return -1;
480 } 488 }
481 489
545 return -1; 553 return -1;
546 } 554 }
547 return 0; 555 return 0;
548 } 556 }
549 557
558 #ifdef SDL_MEMORY_POOL_DEFAULT
550 static int 559 static int
551 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 560 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
552 const SDL_Rect * rect, const void *pixels, int pitch) 561 const SDL_Rect * rect, const void *pixels, int pitch)
553 { 562 {
554 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; 563 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
603 D3D_SetError("UpdateTexture()", result); 612 D3D_SetError("UpdateTexture()", result);
604 return -1; 613 return -1;
605 } 614 }
606 return 0; 615 return 0;
607 } 616 }
617 #else
618 static int
619 D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
620 const SDL_Rect * rect, const void *pixels, int pitch)
621 {
622 D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
623 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
624 RECT d3drect;
625 D3DLOCKED_RECT locked;
626 const Uint8 *src;
627 Uint8 *dst;
628 int row, length;
629 HRESULT result;
630
631 d3drect.left = rect->x;
632 d3drect.right = rect->x + rect->w;
633 d3drect.top = rect->y;
634 d3drect.bottom = rect->y + rect->h;
635
636 result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
637 if (FAILED(result)) {
638 D3D_SetError("LockRect()", result);
639 return -1;
640 }
641
642 src = pixels;
643 dst = locked.pBits;
644 length = rect->w * SDL_BYTESPERPIXEL(texture->format);
645 for (row = 0; row < rect->h; ++row) {
646 SDL_memcpy(dst, src, length);
647 src += pitch;
648 dst += locked.Pitch;
649 }
650 IDirect3DTexture9_UnlockRect(data->texture, 0);
651 return 0;
652 }
653 #endif // SDL_MEMORY_POOL_DEFAULT
608 654
609 static int 655 static int
610 D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 656 D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
611 const SDL_Rect * rect, int markDirty, void **pixels, 657 const SDL_Rect * rect, int markDirty, void **pixels,
612 int *pitch) 658 int *pitch)