src/video/win32/SDL_d3drender.c
changeset 1907 06c27a737b7a
parent 1905 36d52b1f0504
child 1913 83420da906a5
     1.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 14 08:24:43 2006 +0000
     1.2 +++ b/src/video/win32/SDL_d3drender.c	Sat Jul 15 09:46:36 2006 +0000
     1.3 @@ -50,20 +50,12 @@
     1.4  static void SDL_D3D_DirtyTexture(SDL_Renderer * renderer,
     1.5                                   SDL_Texture * texture, int numrects,
     1.6                                   const SDL_Rect * rects);
     1.7 -static void SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer,
     1.8 -                                        SDL_Texture * texture);
     1.9  static int SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    1.10                                Uint32 color);
    1.11  static int SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    1.12                                const SDL_Rect * srcrect,
    1.13                                const SDL_Rect * dstrect, int blendMode,
    1.14                                int scaleMode);
    1.15 -static int SDL_D3D_RenderReadPixels(SDL_Renderer * renderer,
    1.16 -                                    const SDL_Rect * rect, void *pixels,
    1.17 -                                    int pitch);
    1.18 -static int SDL_D3D_RenderWritePixels(SDL_Renderer * renderer,
    1.19 -                                     const SDL_Rect * rect,
    1.20 -                                     const void *pixels, int pitch);
    1.21  static void SDL_D3D_RenderPresent(SDL_Renderer * renderer);
    1.22  static void SDL_D3D_DestroyTexture(SDL_Renderer * renderer,
    1.23                                     SDL_Texture * texture);
    1.24 @@ -76,10 +68,9 @@
    1.25       "d3d",
    1.26       (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    1.27        SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    1.28 -      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    1.29 -     (SDL_TextureBlendMode_None |
    1.30 -      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    1.31 -     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    1.32 +      SDL_Renderer_PresentDiscard | SDL_Renderer_PresentVSync),
    1.33 +     (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),      /* FIXME */
    1.34 +     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),   /* FIXME */
    1.35       12,
    1.36       {
    1.37        SDL_PixelFormat_Index8,
    1.38 @@ -101,8 +92,6 @@
    1.39  typedef struct
    1.40  {
    1.41      IDirect3DDevice9 *device;
    1.42 -    IDirect3DSurface9 *surface;
    1.43 -    IDirect3DSurface9 *offscreen;
    1.44      SDL_bool beginScene;
    1.45  } SDL_D3D_RenderData;
    1.46  
    1.47 @@ -250,6 +239,7 @@
    1.48      SDL_D3D_RenderData *data;
    1.49      HRESULT result;
    1.50      D3DPRESENT_PARAMETERS pparams;
    1.51 +    IDirect3DSwapChain9 *chain;
    1.52  
    1.53      renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
    1.54      if (!renderer) {
    1.55 @@ -273,11 +263,8 @@
    1.56      renderer->LockTexture = SDL_D3D_LockTexture;
    1.57      renderer->UnlockTexture = SDL_D3D_UnlockTexture;
    1.58      renderer->DirtyTexture = SDL_D3D_DirtyTexture;
    1.59 -    renderer->SelectRenderTexture = SDL_D3D_SelectRenderTexture;
    1.60      renderer->RenderFill = SDL_D3D_RenderFill;
    1.61      renderer->RenderCopy = SDL_D3D_RenderCopy;
    1.62 -    renderer->RenderReadPixels = SDL_D3D_RenderReadPixels;
    1.63 -    renderer->RenderWritePixels = SDL_D3D_RenderWritePixels;
    1.64      renderer->RenderPresent = SDL_D3D_RenderPresent;
    1.65      renderer->DestroyTexture = SDL_D3D_DestroyTexture;
    1.66      renderer->DestroyRenderer = SDL_D3D_DestroyRenderer;
    1.67 @@ -285,7 +272,7 @@
    1.68      renderer->window = window->id;
    1.69      renderer->driverdata = data;
    1.70  
    1.71 -    renderer->info.flags = SDL_Renderer_RenderTarget;
    1.72 +    renderer->info.flags = SDL_Renderer_Accelerated;
    1.73  
    1.74      SDL_zero(pparams);
    1.75      pparams.BackBufferWidth = window->w;
    1.76 @@ -317,7 +304,11 @@
    1.77          pparams.Windowed = TRUE;
    1.78          pparams.FullScreen_RefreshRateInHz = 0;
    1.79      }
    1.80 -    pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    1.81 +    if (flags & SDL_Renderer_PresentVSync) {
    1.82 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    1.83 +    } else {
    1.84 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    1.85 +    }
    1.86  
    1.87      result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT,        /* FIXME */
    1.88                                       D3DDEVTYPE_HAL,
    1.89 @@ -331,6 +322,43 @@
    1.90      }
    1.91      data->beginScene = SDL_TRUE;
    1.92  
    1.93 +    /* Get presentation parameters to fill info */
    1.94 +    result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
    1.95 +    if (FAILED(result)) {
    1.96 +        SDL_D3D_DestroyRenderer(renderer);
    1.97 +        D3D_SetError("GetSwapChain()", result);
    1.98 +        return NULL;
    1.99 +    }
   1.100 +    result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
   1.101 +    if (FAILED(result)) {
   1.102 +        IDirect3DSwapChain9_Release(chain);
   1.103 +        SDL_D3D_DestroyRenderer(renderer);
   1.104 +        D3D_SetError("GetPresentParameters()", result);
   1.105 +        return NULL;
   1.106 +    }
   1.107 +    IDirect3DSwapChain9_Release(chain);
   1.108 +    switch (pparams.SwapEffect) {
   1.109 +    case D3DSWAPEFFECT_COPY:
   1.110 +        renderer->info.flags |= SDL_Renderer_PresentCopy;
   1.111 +        break;
   1.112 +    case D3DSWAPEFFECT_FLIP:
   1.113 +        switch (pparams.BackBufferCount) {
   1.114 +        case 2:
   1.115 +            renderer->info.flags |= SDL_Renderer_PresentFlip2;
   1.116 +            break;
   1.117 +        case 3:
   1.118 +            renderer->info.flags |= SDL_Renderer_PresentFlip3;
   1.119 +            break;
   1.120 +        }
   1.121 +        break;
   1.122 +    case D3DSWAPEFFECT_DISCARD:
   1.123 +        renderer->info.flags |= SDL_Renderer_PresentDiscard;
   1.124 +        break;
   1.125 +    }
   1.126 +    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
   1.127 +        renderer->info.flags |= SDL_Renderer_PresentVSync;
   1.128 +    }
   1.129 +
   1.130      /* Set up parameters for rendering */
   1.131      IDirect3DDevice9_SetVertexShader(data->device, NULL);
   1.132      IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
   1.133 @@ -527,14 +555,6 @@
   1.134      }
   1.135  }
   1.136  
   1.137 -static void
   1.138 -SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.139 -{
   1.140 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   1.141 -
   1.142 -    /* FIXME */
   1.143 -}
   1.144 -
   1.145  static int
   1.146  SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.147                     Uint32 color)
   1.148 @@ -637,93 +657,6 @@
   1.149      return 0;
   1.150  }
   1.151  
   1.152 -static int
   1.153 -SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.154 -                         void *pixels, int pitch)
   1.155 -{
   1.156 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   1.157 -
   1.158 -    /* FIXME */
   1.159 -    return 0;
   1.160 -}
   1.161 -
   1.162 -static int
   1.163 -SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   1.164 -                          const void *pixels, int pitch)
   1.165 -{
   1.166 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.167 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.168 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   1.169 -    RECT d3drect;
   1.170 -    POINT point;
   1.171 -    D3DLOCKED_RECT locked;
   1.172 -    const Uint8 *src;
   1.173 -    Uint8 *dst;
   1.174 -    int row, length;
   1.175 -    HRESULT result;
   1.176 -
   1.177 -    if (!data->surface) {
   1.178 -        result =
   1.179 -            IDirect3DDevice9_GetBackBuffer(data->device, 0, 0,
   1.180 -                                           D3DBACKBUFFER_TYPE_MONO,
   1.181 -                                           &data->surface);
   1.182 -        if (FAILED(result)) {
   1.183 -            D3D_SetError("GetBackBuffer()", result);
   1.184 -            return -1;
   1.185 -        }
   1.186 -    }
   1.187 -    if (!data->offscreen) {
   1.188 -        result =
   1.189 -            IDirect3DDevice9_CreateOffscreenPlainSurface(data->device,
   1.190 -                                                         window->w, window->h,
   1.191 -                                                         PixelFormatToD3DFMT
   1.192 -                                                         (display->
   1.193 -                                                          current_mode.
   1.194 -                                                          format),
   1.195 -                                                         D3DPOOL_SYSTEMMEM,
   1.196 -                                                         &data->offscreen,
   1.197 -                                                         NULL);
   1.198 -        if (FAILED(result)) {
   1.199 -            D3D_SetError("CreateOffscreenPlainSurface()", result);
   1.200 -            return -1;
   1.201 -        }
   1.202 -    }
   1.203 -
   1.204 -    d3drect.left = rect->x;
   1.205 -    d3drect.right = rect->x + rect->w;
   1.206 -    d3drect.top = rect->y;
   1.207 -    d3drect.bottom = rect->y + rect->h;
   1.208 -
   1.209 -    result =
   1.210 -        IDirect3DSurface9_LockRect(data->offscreen, &locked, &d3drect, 0);
   1.211 -    if (FAILED(result)) {
   1.212 -        D3D_SetError("LockRect()", result);
   1.213 -        return -1;
   1.214 -    }
   1.215 -
   1.216 -    src = pixels;
   1.217 -    dst = locked.pBits;
   1.218 -    length = rect->w * SDL_BYTESPERPIXEL(display->current_mode.format);
   1.219 -    for (row = 0; row < rect->h; ++row) {
   1.220 -        SDL_memcpy(dst, src, length);
   1.221 -        src += pitch;
   1.222 -        dst += locked.Pitch;
   1.223 -    }
   1.224 -    IDirect3DSurface9_UnlockRect(data->offscreen);
   1.225 -
   1.226 -    point.x = rect->x;
   1.227 -    point.y = rect->y;
   1.228 -    result =
   1.229 -        IDirect3DDevice9_UpdateSurface(data->device, data->offscreen,
   1.230 -                                       &d3drect, data->surface, &point);
   1.231 -    if (FAILED(result)) {
   1.232 -        D3D_SetError("UpdateSurface()", result);
   1.233 -        return -1;
   1.234 -    }
   1.235 -
   1.236 -    return 0;
   1.237 -}
   1.238 -
   1.239  static void
   1.240  SDL_D3D_RenderPresent(SDL_Renderer * renderer)
   1.241  {
   1.242 @@ -765,12 +698,6 @@
   1.243          if (data->device) {
   1.244              IDirect3DDevice9_Release(data->device);
   1.245          }
   1.246 -        if (data->surface) {
   1.247 -            IDirect3DSurface9_Release(data->surface);
   1.248 -        }
   1.249 -        if (data->offscreen) {
   1.250 -            IDirect3DSurface9_Release(data->offscreen);
   1.251 -        }
   1.252          SDL_free(data);
   1.253      }
   1.254      SDL_free(renderer);