src/video/win32/SDL_d3drender.c
changeset 1905 36d52b1f0504
parent 1904 1a713f9d1f71
child 1907 06c27a737b7a
     1.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 14 07:41:16 2006 +0000
     1.2 +++ b/src/video/win32/SDL_d3drender.c	Fri Jul 14 08:22:45 2006 +0000
     1.3 @@ -74,10 +74,9 @@
     1.4      SDL_D3D_CreateRenderer,
     1.5      {
     1.6       "d3d",
     1.7 -     (                          //SDL_Renderer_Minimal |
     1.8 -         SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
     1.9 -         SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    1.10 -         SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    1.11 +     (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    1.12 +      SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    1.13 +      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    1.14       (SDL_TextureBlendMode_None |
    1.15        SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    1.16       (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    1.17 @@ -102,6 +101,8 @@
    1.18  typedef struct
    1.19  {
    1.20      IDirect3DDevice9 *device;
    1.21 +    IDirect3DSurface9 *surface;
    1.22 +    IDirect3DSurface9 *offscreen;
    1.23      SDL_bool beginScene;
    1.24  } SDL_D3D_RenderData;
    1.25  
    1.26 @@ -530,6 +531,8 @@
    1.27  SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.28  {
    1.29      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    1.30 +
    1.31 +    /* FIXME */
    1.32  }
    1.33  
    1.34  static int
    1.35 @@ -640,6 +643,7 @@
    1.36  {
    1.37      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    1.38  
    1.39 +    /* FIXME */
    1.40      return 0;
    1.41  }
    1.42  
    1.43 @@ -647,7 +651,75 @@
    1.44  SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    1.45                            const void *pixels, int pitch)
    1.46  {
    1.47 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.48 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.49      SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
    1.50 +    RECT d3drect;
    1.51 +    POINT point;
    1.52 +    D3DLOCKED_RECT locked;
    1.53 +    const Uint8 *src;
    1.54 +    Uint8 *dst;
    1.55 +    int row, length;
    1.56 +    HRESULT result;
    1.57 +
    1.58 +    if (!data->surface) {
    1.59 +        result =
    1.60 +            IDirect3DDevice9_GetBackBuffer(data->device, 0, 0,
    1.61 +                                           D3DBACKBUFFER_TYPE_MONO,
    1.62 +                                           &data->surface);
    1.63 +        if (FAILED(result)) {
    1.64 +            D3D_SetError("GetBackBuffer()", result);
    1.65 +            return -1;
    1.66 +        }
    1.67 +    }
    1.68 +    if (!data->offscreen) {
    1.69 +        result =
    1.70 +            IDirect3DDevice9_CreateOffscreenPlainSurface(data->device,
    1.71 +                                                         window->w, window->h,
    1.72 +                                                         PixelFormatToD3DFMT
    1.73 +                                                         (display->
    1.74 +                                                          current_mode.
    1.75 +                                                          format),
    1.76 +                                                         D3DPOOL_SYSTEMMEM,
    1.77 +                                                         &data->offscreen,
    1.78 +                                                         NULL);
    1.79 +        if (FAILED(result)) {
    1.80 +            D3D_SetError("CreateOffscreenPlainSurface()", result);
    1.81 +            return -1;
    1.82 +        }
    1.83 +    }
    1.84 +
    1.85 +    d3drect.left = rect->x;
    1.86 +    d3drect.right = rect->x + rect->w;
    1.87 +    d3drect.top = rect->y;
    1.88 +    d3drect.bottom = rect->y + rect->h;
    1.89 +
    1.90 +    result =
    1.91 +        IDirect3DSurface9_LockRect(data->offscreen, &locked, &d3drect, 0);
    1.92 +    if (FAILED(result)) {
    1.93 +        D3D_SetError("LockRect()", result);
    1.94 +        return -1;
    1.95 +    }
    1.96 +
    1.97 +    src = pixels;
    1.98 +    dst = locked.pBits;
    1.99 +    length = rect->w * SDL_BYTESPERPIXEL(display->current_mode.format);
   1.100 +    for (row = 0; row < rect->h; ++row) {
   1.101 +        SDL_memcpy(dst, src, length);
   1.102 +        src += pitch;
   1.103 +        dst += locked.Pitch;
   1.104 +    }
   1.105 +    IDirect3DSurface9_UnlockRect(data->offscreen);
   1.106 +
   1.107 +    point.x = rect->x;
   1.108 +    point.y = rect->y;
   1.109 +    result =
   1.110 +        IDirect3DDevice9_UpdateSurface(data->device, data->offscreen,
   1.111 +                                       &d3drect, data->surface, &point);
   1.112 +    if (FAILED(result)) {
   1.113 +        D3D_SetError("UpdateSurface()", result);
   1.114 +        return -1;
   1.115 +    }
   1.116  
   1.117      return 0;
   1.118  }
   1.119 @@ -693,6 +765,12 @@
   1.120          if (data->device) {
   1.121              IDirect3DDevice9_Release(data->device);
   1.122          }
   1.123 +        if (data->surface) {
   1.124 +            IDirect3DSurface9_Release(data->surface);
   1.125 +        }
   1.126 +        if (data->offscreen) {
   1.127 +            IDirect3DSurface9_Release(data->offscreen);
   1.128 +        }
   1.129          SDL_free(data);
   1.130      }
   1.131      SDL_free(renderer);