src/video/win32/SDL_d3drender.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 13 Jul 2006 08:13:02 +0000
changeset 1901 f1828a500391
parent 1900 5c6bdbf3aadf
child 1903 f132024010be
permissions -rw-r--r--
Removed libc dependency on Windows again, to fix building with Visual C++ 2005 Express Edition.
Fixed performance problem with testsprite2 on the D3D driver.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@1895
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1895
     4
slouken@1895
     5
    This library is free software; you can redistribute it and/or
slouken@1895
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1895
     7
    License as published by the Free Software Foundation; either
slouken@1895
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1895
     9
slouken@1895
    10
    This library is distributed in the hope that it will be useful,
slouken@1895
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1895
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1895
    13
    Lesser General Public License for more details.
slouken@1895
    14
slouken@1895
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1895
    16
    License along with this library; if not, write to the Free Software
slouken@1895
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1895
    18
slouken@1895
    19
    Sam Lantinga
slouken@1895
    20
    slouken@libsdl.org
slouken@1895
    21
*/
slouken@1895
    22
#include "SDL_config.h"
slouken@1895
    23
slouken@1895
    24
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    25
slouken@1895
    26
#include "SDL_win32video.h"
slouken@1895
    27
#include "../SDL_yuv_sw_c.h"
slouken@1895
    28
slouken@1895
    29
/* Direct3D renderer implementation */
slouken@1895
    30
slouken@1895
    31
static SDL_Renderer *SDL_D3D_CreateRenderer(SDL_Window * window,
slouken@1895
    32
                                            Uint32 flags);
slouken@1895
    33
static int SDL_D3D_CreateTexture(SDL_Renderer * renderer,
slouken@1895
    34
                                 SDL_Texture * texture);
slouken@1895
    35
static int SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer,
slouken@1895
    36
                                      SDL_Texture * texture, void **pixels,
slouken@1895
    37
                                      int *pitch);
slouken@1895
    38
static int SDL_D3D_SetTexturePalette(SDL_Renderer * renderer,
slouken@1895
    39
                                     SDL_Texture * texture,
slouken@1895
    40
                                     const SDL_Color * colors, int firstcolor,
slouken@1895
    41
                                     int ncolors);
slouken@1895
    42
static int SDL_D3D_GetTexturePalette(SDL_Renderer * renderer,
slouken@1895
    43
                                     SDL_Texture * texture,
slouken@1895
    44
                                     SDL_Color * colors, int firstcolor,
slouken@1895
    45
                                     int ncolors);
slouken@1895
    46
static int SDL_D3D_UpdateTexture(SDL_Renderer * renderer,
slouken@1895
    47
                                 SDL_Texture * texture, const SDL_Rect * rect,
slouken@1895
    48
                                 const void *pixels, int pitch);
slouken@1895
    49
static int SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    50
                               const SDL_Rect * rect, int markDirty,
slouken@1895
    51
                               void **pixels, int *pitch);
slouken@1895
    52
static void SDL_D3D_UnlockTexture(SDL_Renderer * renderer,
slouken@1895
    53
                                  SDL_Texture * texture);
slouken@1895
    54
static void SDL_D3D_DirtyTexture(SDL_Renderer * renderer,
slouken@1895
    55
                                 SDL_Texture * texture, int numrects,
slouken@1895
    56
                                 const SDL_Rect * rects);
slouken@1895
    57
static void SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer,
slouken@1895
    58
                                        SDL_Texture * texture);
slouken@1895
    59
static int SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
    60
                              Uint32 color);
slouken@1895
    61
static int SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    62
                              const SDL_Rect * srcrect,
slouken@1895
    63
                              const SDL_Rect * dstrect, int blendMode,
slouken@1895
    64
                              int scaleMode);
slouken@1895
    65
static int SDL_D3D_RenderReadPixels(SDL_Renderer * renderer,
slouken@1895
    66
                                    const SDL_Rect * rect, void *pixels,
slouken@1895
    67
                                    int pitch);
slouken@1895
    68
static int SDL_D3D_RenderWritePixels(SDL_Renderer * renderer,
slouken@1895
    69
                                     const SDL_Rect * rect,
slouken@1895
    70
                                     const void *pixels, int pitch);
slouken@1895
    71
static void SDL_D3D_RenderPresent(SDL_Renderer * renderer);
slouken@1895
    72
static void SDL_D3D_DestroyTexture(SDL_Renderer * renderer,
slouken@1895
    73
                                   SDL_Texture * texture);
slouken@1895
    74
static void SDL_D3D_DestroyRenderer(SDL_Renderer * renderer);
slouken@1895
    75
slouken@1895
    76
slouken@1895
    77
SDL_RenderDriver SDL_D3D_RenderDriver = {
slouken@1895
    78
    SDL_D3D_CreateRenderer,
slouken@1895
    79
    {
slouken@1895
    80
     "d3d",
slouken@1900
    81
     (                          //SDL_Renderer_Minimal |
slouken@1900
    82
         SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
slouken@1900
    83
         SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
slouken@1900
    84
         SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
slouken@1895
    85
     (SDL_TextureBlendMode_None |
slouken@1895
    86
      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
slouken@1895
    87
     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
slouken@1895
    88
     11,
slouken@1895
    89
     {
slouken@1895
    90
      SDL_PixelFormat_Index8,
slouken@1895
    91
      SDL_PixelFormat_RGB555,
slouken@1895
    92
      SDL_PixelFormat_RGB565,
slouken@1895
    93
      SDL_PixelFormat_RGB888,
slouken@1895
    94
      SDL_PixelFormat_BGR888,
slouken@1895
    95
      SDL_PixelFormat_ARGB8888,
slouken@1895
    96
      SDL_PixelFormat_RGBA8888,
slouken@1895
    97
      SDL_PixelFormat_ABGR8888,
slouken@1895
    98
      SDL_PixelFormat_BGRA8888,
slouken@1895
    99
      SDL_PixelFormat_YUY2,
slouken@1895
   100
      SDL_PixelFormat_UYVY},
slouken@1895
   101
     0,
slouken@1895
   102
     0}
slouken@1895
   103
};
slouken@1895
   104
slouken@1895
   105
typedef struct
slouken@1895
   106
{
slouken@1895
   107
    IDirect3DDevice9 *device;
slouken@1900
   108
    SDL_bool beginScene;
slouken@1895
   109
} SDL_D3D_RenderData;
slouken@1895
   110
slouken@1895
   111
typedef struct
slouken@1895
   112
{
slouken@1895
   113
    SDL_SW_YUVTexture *yuv;
slouken@1895
   114
} SDL_D3D_TextureData;
slouken@1895
   115
slouken@1895
   116
static void
slouken@1900
   117
D3D_SetError(const char *prefix, HRESULT result)
slouken@1900
   118
{
slouken@1900
   119
    const char *error;
slouken@1900
   120
slouken@1900
   121
    switch (result) {
slouken@1900
   122
    case D3DERR_WRONGTEXTUREFORMAT:
slouken@1900
   123
        error = "WRONGTEXTUREFORMAT";
slouken@1900
   124
        break;
slouken@1900
   125
    case D3DERR_UNSUPPORTEDCOLOROPERATION:
slouken@1900
   126
        error = "UNSUPPORTEDCOLOROPERATION";
slouken@1900
   127
        break;
slouken@1900
   128
    case D3DERR_UNSUPPORTEDCOLORARG:
slouken@1900
   129
        error = "UNSUPPORTEDCOLORARG";
slouken@1900
   130
        break;
slouken@1900
   131
    case D3DERR_UNSUPPORTEDALPHAOPERATION:
slouken@1900
   132
        error = "UNSUPPORTEDALPHAOPERATION";
slouken@1900
   133
        break;
slouken@1900
   134
    case D3DERR_UNSUPPORTEDALPHAARG:
slouken@1900
   135
        error = "UNSUPPORTEDALPHAARG";
slouken@1900
   136
        break;
slouken@1900
   137
    case D3DERR_TOOMANYOPERATIONS:
slouken@1900
   138
        error = "TOOMANYOPERATIONS";
slouken@1900
   139
        break;
slouken@1900
   140
    case D3DERR_CONFLICTINGTEXTUREFILTER:
slouken@1900
   141
        error = "CONFLICTINGTEXTUREFILTER";
slouken@1900
   142
        break;
slouken@1900
   143
    case D3DERR_UNSUPPORTEDFACTORVALUE:
slouken@1900
   144
        error = "UNSUPPORTEDFACTORVALUE";
slouken@1900
   145
        break;
slouken@1900
   146
    case D3DERR_CONFLICTINGRENDERSTATE:
slouken@1900
   147
        error = "CONFLICTINGRENDERSTATE";
slouken@1900
   148
        break;
slouken@1900
   149
    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
slouken@1900
   150
        error = "UNSUPPORTEDTEXTUREFILTER";
slouken@1900
   151
        break;
slouken@1900
   152
    case D3DERR_CONFLICTINGTEXTUREPALETTE:
slouken@1900
   153
        error = "CONFLICTINGTEXTUREPALETTE";
slouken@1900
   154
        break;
slouken@1900
   155
    case D3DERR_DRIVERINTERNALERROR:
slouken@1900
   156
        error = "DRIVERINTERNALERROR";
slouken@1900
   157
        break;
slouken@1900
   158
    case D3DERR_NOTFOUND:
slouken@1900
   159
        error = "NOTFOUND";
slouken@1900
   160
        break;
slouken@1900
   161
    case D3DERR_MOREDATA:
slouken@1900
   162
        error = "MOREDATA";
slouken@1900
   163
        break;
slouken@1900
   164
    case D3DERR_DEVICELOST:
slouken@1900
   165
        error = "DEVICELOST";
slouken@1900
   166
        break;
slouken@1900
   167
    case D3DERR_DEVICENOTRESET:
slouken@1900
   168
        error = "DEVICENOTRESET";
slouken@1900
   169
        break;
slouken@1900
   170
    case D3DERR_NOTAVAILABLE:
slouken@1900
   171
        error = "NOTAVAILABLE";
slouken@1900
   172
        break;
slouken@1900
   173
    case D3DERR_OUTOFVIDEOMEMORY:
slouken@1900
   174
        error = "OUTOFVIDEOMEMORY";
slouken@1900
   175
        break;
slouken@1900
   176
    case D3DERR_INVALIDDEVICE:
slouken@1900
   177
        error = "INVALIDDEVICE";
slouken@1900
   178
        break;
slouken@1900
   179
    case D3DERR_INVALIDCALL:
slouken@1900
   180
        error = "INVALIDCALL";
slouken@1900
   181
        break;
slouken@1900
   182
    case D3DERR_DRIVERINVALIDCALL:
slouken@1900
   183
        error = "DRIVERINVALIDCALL";
slouken@1900
   184
        break;
slouken@1900
   185
    case D3DERR_WASSTILLDRAWING:
slouken@1900
   186
        error = "WASSTILLDRAWING";
slouken@1900
   187
        break;
slouken@1900
   188
    default:
slouken@1900
   189
        error = "UNKNOWN";
slouken@1900
   190
        break;
slouken@1900
   191
    }
slouken@1900
   192
    SDL_SetError("%s: %s", prefix, error);
slouken@1900
   193
}
slouken@1900
   194
slouken@1900
   195
static void
slouken@1895
   196
UpdateYUVTextureData(SDL_Texture * texture)
slouken@1895
   197
{
slouken@1895
   198
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   199
    SDL_Rect rect;
slouken@1895
   200
slouken@1895
   201
    rect.x = 0;
slouken@1895
   202
    rect.y = 0;
slouken@1895
   203
    rect.w = texture->w;
slouken@1895
   204
    rect.h = texture->h;
slouken@1895
   205
    //SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
slouken@1895
   206
    //                    texture->h, data->pixels, data->pitch);
slouken@1895
   207
}
slouken@1895
   208
slouken@1895
   209
void
slouken@1895
   210
D3D_AddRenderDriver(_THIS)
slouken@1895
   211
{
slouken@1895
   212
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1895
   213
slouken@1895
   214
    if (data->d3d) {
slouken@1895
   215
        SDL_AddRenderDriver(0, &SDL_D3D_RenderDriver);
slouken@1895
   216
    }
slouken@1895
   217
}
slouken@1895
   218
slouken@1895
   219
SDL_Renderer *
slouken@1895
   220
SDL_D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1895
   221
{
slouken@1895
   222
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
   223
    SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
slouken@1895
   224
    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
slouken@1895
   225
    SDL_Renderer *renderer;
slouken@1895
   226
    SDL_D3D_RenderData *data;
slouken@1900
   227
    HRESULT result;
slouken@1900
   228
    D3DPRESENT_PARAMETERS pparams;
slouken@1895
   229
slouken@1895
   230
    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
slouken@1895
   231
    if (!renderer) {
slouken@1895
   232
        SDL_OutOfMemory();
slouken@1895
   233
        return NULL;
slouken@1895
   234
    }
slouken@1895
   235
    SDL_zerop(renderer);
slouken@1895
   236
slouken@1895
   237
    data = (SDL_D3D_RenderData *) SDL_malloc(sizeof(*data));
slouken@1895
   238
    if (!data) {
slouken@1895
   239
        SDL_D3D_DestroyRenderer(renderer);
slouken@1895
   240
        SDL_OutOfMemory();
slouken@1895
   241
        return NULL;
slouken@1895
   242
    }
slouken@1895
   243
    SDL_zerop(data);
slouken@1895
   244
slouken@1895
   245
    renderer->CreateTexture = SDL_D3D_CreateTexture;
slouken@1895
   246
    renderer->QueryTexturePixels = SDL_D3D_QueryTexturePixels;
slouken@1895
   247
    renderer->SetTexturePalette = SDL_D3D_SetTexturePalette;
slouken@1895
   248
    renderer->GetTexturePalette = SDL_D3D_GetTexturePalette;
slouken@1895
   249
    renderer->UpdateTexture = SDL_D3D_UpdateTexture;
slouken@1895
   250
    renderer->LockTexture = SDL_D3D_LockTexture;
slouken@1895
   251
    renderer->UnlockTexture = SDL_D3D_UnlockTexture;
slouken@1895
   252
    renderer->DirtyTexture = SDL_D3D_DirtyTexture;
slouken@1895
   253
    renderer->SelectRenderTexture = SDL_D3D_SelectRenderTexture;
slouken@1895
   254
    renderer->RenderFill = SDL_D3D_RenderFill;
slouken@1895
   255
    renderer->RenderCopy = SDL_D3D_RenderCopy;
slouken@1895
   256
    renderer->RenderReadPixels = SDL_D3D_RenderReadPixels;
slouken@1895
   257
    renderer->RenderWritePixels = SDL_D3D_RenderWritePixels;
slouken@1895
   258
    renderer->RenderPresent = SDL_D3D_RenderPresent;
slouken@1895
   259
    renderer->DestroyTexture = SDL_D3D_DestroyTexture;
slouken@1895
   260
    renderer->DestroyRenderer = SDL_D3D_DestroyRenderer;
slouken@1895
   261
    renderer->info = SDL_D3D_RenderDriver.info;
slouken@1895
   262
    renderer->window = window->id;
slouken@1895
   263
    renderer->driverdata = data;
slouken@1895
   264
slouken@1895
   265
    renderer->info.flags = SDL_Renderer_RenderTarget;
slouken@1895
   266
slouken@1900
   267
    SDL_zero(pparams);
slouken@1900
   268
    pparams.BackBufferWidth = window->w;
slouken@1900
   269
    pparams.BackBufferHeight = window->h;
slouken@1900
   270
    pparams.BackBufferFormat = D3DFMT_UNKNOWN;  /* FIXME */
slouken@1900
   271
    if (flags & SDL_Renderer_PresentFlip2) {
slouken@1900
   272
        pparams.BackBufferCount = 2;
slouken@1900
   273
        pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
slouken@1900
   274
    } else if (flags & SDL_Renderer_PresentFlip3) {
slouken@1900
   275
        pparams.BackBufferCount = 3;
slouken@1900
   276
        pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
slouken@1900
   277
    } else if (flags & SDL_Renderer_PresentCopy) {
slouken@1900
   278
        pparams.BackBufferCount = 1;
slouken@1900
   279
        pparams.SwapEffect = D3DSWAPEFFECT_COPY;
slouken@1900
   280
    } else {
slouken@1900
   281
        pparams.BackBufferCount = 1;
slouken@1900
   282
        pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
slouken@1900
   283
    }
slouken@1900
   284
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1900
   285
        pparams.Windowed = FALSE;
slouken@1900
   286
    } else {
slouken@1900
   287
        pparams.Windowed = TRUE;
slouken@1900
   288
    }
slouken@1900
   289
    pparams.FullScreen_RefreshRateInHz = 0;     /* FIXME */
slouken@1901
   290
    pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
slouken@1900
   291
slouken@1900
   292
    result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT,        /* FIXME */
slouken@1900
   293
                                     D3DDEVTYPE_HAL,
slouken@1900
   294
                                     windowdata->hwnd,
slouken@1900
   295
                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
slouken@1900
   296
                                     &pparams, &data->device);
slouken@1900
   297
    if (FAILED(result)) {
slouken@1900
   298
        SDL_D3D_DestroyRenderer(renderer);
slouken@1900
   299
        D3D_SetError("CreateDevice()", result);
slouken@1900
   300
        return NULL;
slouken@1900
   301
    }
slouken@1900
   302
    data->beginScene = SDL_TRUE;
slouken@1900
   303
slouken@1895
   304
    return renderer;
slouken@1895
   305
}
slouken@1895
   306
slouken@1895
   307
static int
slouken@1895
   308
SDL_D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   309
{
slouken@1895
   310
    SDL_D3D_RenderData *renderdata =
slouken@1895
   311
        (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   312
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1895
   313
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
   314
    SDL_D3D_TextureData *data;
slouken@1895
   315
slouken@1895
   316
    data = (SDL_D3D_TextureData *) SDL_malloc(sizeof(*data));
slouken@1895
   317
    if (!data) {
slouken@1895
   318
        SDL_OutOfMemory();
slouken@1895
   319
        return -1;
slouken@1895
   320
    }
slouken@1895
   321
    SDL_zerop(data);
slouken@1895
   322
slouken@1895
   323
    texture->driverdata = data;
slouken@1895
   324
slouken@1895
   325
    return 0;
slouken@1895
   326
}
slouken@1895
   327
slouken@1895
   328
static int
slouken@1895
   329
SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   330
                           void **pixels, int *pitch)
slouken@1895
   331
{
slouken@1895
   332
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   333
slouken@1895
   334
    if (data->yuv) {
slouken@1895
   335
        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
slouken@1895
   336
    } else {
slouken@1895
   337
        return 0;
slouken@1895
   338
    }
slouken@1895
   339
}
slouken@1895
   340
slouken@1895
   341
static int
slouken@1895
   342
SDL_D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   343
                          const SDL_Color * colors, int firstcolor,
slouken@1895
   344
                          int ncolors)
slouken@1895
   345
{
slouken@1895
   346
    SDL_D3D_RenderData *renderdata =
slouken@1895
   347
        (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   348
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   349
slouken@1895
   350
    if (data->yuv) {
slouken@1895
   351
        SDL_SetError("YUV textures don't have a palette");
slouken@1895
   352
        return -1;
slouken@1895
   353
    } else {
slouken@1895
   354
        return 0;
slouken@1895
   355
    }
slouken@1895
   356
}
slouken@1895
   357
slouken@1895
   358
static int
slouken@1895
   359
SDL_D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   360
                          SDL_Color * colors, int firstcolor, int ncolors)
slouken@1895
   361
{
slouken@1895
   362
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   363
slouken@1895
   364
    if (data->yuv) {
slouken@1895
   365
        SDL_SetError("YUV textures don't have a palette");
slouken@1895
   366
        return -1;
slouken@1895
   367
    } else {
slouken@1895
   368
        return 0;
slouken@1895
   369
    }
slouken@1895
   370
}
slouken@1895
   371
slouken@1895
   372
static int
slouken@1895
   373
SDL_D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   374
                      const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1895
   375
{
slouken@1895
   376
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   377
slouken@1895
   378
    if (data->yuv) {
slouken@1895
   379
        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
slouken@1895
   380
            return -1;
slouken@1895
   381
        }
slouken@1895
   382
        UpdateYUVTextureData(texture);
slouken@1895
   383
        return 0;
slouken@1895
   384
    } else {
slouken@1895
   385
        SDL_D3D_RenderData *renderdata =
slouken@1895
   386
            (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   387
slouken@1895
   388
        return 0;
slouken@1895
   389
    }
slouken@1895
   390
}
slouken@1895
   391
slouken@1895
   392
static int
slouken@1895
   393
SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   394
                    const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1895
   395
                    int *pitch)
slouken@1895
   396
{
slouken@1895
   397
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   398
slouken@1895
   399
    if (data->yuv) {
slouken@1895
   400
        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
slouken@1895
   401
                                     pitch);
slouken@1895
   402
    } else {
slouken@1900
   403
        return -1;
slouken@1895
   404
    }
slouken@1895
   405
}
slouken@1895
   406
slouken@1895
   407
static void
slouken@1895
   408
SDL_D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   409
{
slouken@1895
   410
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   411
slouken@1895
   412
    if (data->yuv) {
slouken@1895
   413
        SDL_SW_UnlockYUVTexture(data->yuv);
slouken@1895
   414
        UpdateYUVTextureData(texture);
slouken@1895
   415
    }
slouken@1895
   416
}
slouken@1895
   417
slouken@1895
   418
static void
slouken@1895
   419
SDL_D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   420
                     int numrects, const SDL_Rect * rects)
slouken@1895
   421
{
slouken@1895
   422
}
slouken@1895
   423
slouken@1895
   424
static void
slouken@1895
   425
SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   426
{
slouken@1895
   427
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   428
}
slouken@1895
   429
slouken@1895
   430
static int
slouken@1895
   431
SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   432
                   Uint32 color)
slouken@1895
   433
{
slouken@1895
   434
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1901
   435
    D3DRECT d3drect;
slouken@1900
   436
    HRESULT result;
slouken@1900
   437
slouken@1900
   438
    if (data->beginScene) {
slouken@1900
   439
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   440
        data->beginScene = SDL_FALSE;
slouken@1900
   441
    }
slouken@1895
   442
slouken@1901
   443
    d3drect.x1 = rect->x;
slouken@1901
   444
    d3drect.x2 = rect->x+rect->w;
slouken@1901
   445
    d3drect.y1 = rect->y;
slouken@1901
   446
    d3drect.y2 = rect->y+rect->h;
slouken@1901
   447
slouken@1901
   448
    result = IDirect3DDevice9_Clear(data->device, 1, &d3drect, D3DCLEAR_TARGET, (D3DCOLOR) color, 1.0f, 0);
slouken@1900
   449
    if (FAILED(result)) {
slouken@1900
   450
        D3D_SetError("Clear()", result);
slouken@1900
   451
        return -1;
slouken@1900
   452
    }
slouken@1895
   453
    return 0;
slouken@1895
   454
}
slouken@1895
   455
slouken@1895
   456
static int
slouken@1895
   457
SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   458
                   const SDL_Rect * srcrect, const SDL_Rect * dstrect,
slouken@1895
   459
                   int blendMode, int scaleMode)
slouken@1895
   460
{
slouken@1895
   461
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   462
    SDL_D3D_TextureData *texturedata =
slouken@1895
   463
        (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   464
slouken@1900
   465
    if (data->beginScene) {
slouken@1900
   466
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   467
        data->beginScene = SDL_FALSE;
slouken@1900
   468
    }
slouken@1895
   469
    return 0;
slouken@1895
   470
}
slouken@1895
   471
slouken@1895
   472
static int
slouken@1895
   473
SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   474
                         void *pixels, int pitch)
slouken@1895
   475
{
slouken@1895
   476
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   477
slouken@1895
   478
    return 0;
slouken@1895
   479
}
slouken@1895
   480
slouken@1895
   481
static int
slouken@1895
   482
SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   483
                          const void *pixels, int pitch)
slouken@1895
   484
{
slouken@1895
   485
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   486
slouken@1895
   487
    return 0;
slouken@1895
   488
}
slouken@1895
   489
slouken@1895
   490
static void
slouken@1895
   491
SDL_D3D_RenderPresent(SDL_Renderer * renderer)
slouken@1895
   492
{
slouken@1900
   493
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1900
   494
    HRESULT result;
slouken@1900
   495
slouken@1900
   496
    if (!data->beginScene) {
slouken@1900
   497
        IDirect3DDevice9_EndScene(data->device);
slouken@1900
   498
        data->beginScene = SDL_TRUE;
slouken@1900
   499
    }
slouken@1900
   500
slouken@1900
   501
    result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
slouken@1900
   502
    if (FAILED(result)) {
slouken@1900
   503
        D3D_SetError("Present()", result);
slouken@1900
   504
    }
slouken@1895
   505
}
slouken@1895
   506
slouken@1895
   507
static void
slouken@1895
   508
SDL_D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   509
{
slouken@1895
   510
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   511
slouken@1895
   512
    if (!data) {
slouken@1895
   513
        return;
slouken@1895
   514
    }
slouken@1895
   515
    SDL_free(data);
slouken@1895
   516
    texture->driverdata = NULL;
slouken@1895
   517
}
slouken@1895
   518
slouken@1895
   519
void
slouken@1895
   520
SDL_D3D_DestroyRenderer(SDL_Renderer * renderer)
slouken@1895
   521
{
slouken@1895
   522
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   523
slouken@1895
   524
    if (data) {
slouken@1900
   525
        if (data->device) {
slouken@1900
   526
            IDirect3DDevice9_Release(data->device);
slouken@1900
   527
        }
slouken@1895
   528
        SDL_free(data);
slouken@1895
   529
    }
slouken@1895
   530
    SDL_free(renderer);
slouken@1895
   531
}
slouken@1895
   532
slouken@1895
   533
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@1895
   534
slouken@1895
   535
/* vi: set ts=4 sw=4 expandtab: */