src/video/win32/SDL_d3drender.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 12 Jul 2006 09:25:17 +0000
changeset 1900 5c6bdbf3aadf
parent 1898 f89e49e51e89
child 1901 f1828a500391
permissions -rw-r--r--
First stab at a D3D renderer, only 30FPS so far... ?
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@1900
   290
slouken@1900
   291
    result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT,        /* FIXME */
slouken@1900
   292
                                     D3DDEVTYPE_HAL,
slouken@1900
   293
                                     windowdata->hwnd,
slouken@1900
   294
                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
slouken@1900
   295
                                     &pparams, &data->device);
slouken@1900
   296
    if (FAILED(result)) {
slouken@1900
   297
        SDL_D3D_DestroyRenderer(renderer);
slouken@1900
   298
        D3D_SetError("CreateDevice()", result);
slouken@1900
   299
        return NULL;
slouken@1900
   300
    }
slouken@1900
   301
    data->beginScene = SDL_TRUE;
slouken@1900
   302
slouken@1895
   303
    return renderer;
slouken@1895
   304
}
slouken@1895
   305
slouken@1895
   306
static int
slouken@1895
   307
SDL_D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   308
{
slouken@1895
   309
    SDL_D3D_RenderData *renderdata =
slouken@1895
   310
        (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   311
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1895
   312
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
   313
    SDL_D3D_TextureData *data;
slouken@1895
   314
slouken@1895
   315
    data = (SDL_D3D_TextureData *) SDL_malloc(sizeof(*data));
slouken@1895
   316
    if (!data) {
slouken@1895
   317
        SDL_OutOfMemory();
slouken@1895
   318
        return -1;
slouken@1895
   319
    }
slouken@1895
   320
    SDL_zerop(data);
slouken@1895
   321
slouken@1895
   322
    texture->driverdata = data;
slouken@1895
   323
slouken@1895
   324
    return 0;
slouken@1895
   325
}
slouken@1895
   326
slouken@1895
   327
static int
slouken@1895
   328
SDL_D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   329
                           void **pixels, int *pitch)
slouken@1895
   330
{
slouken@1895
   331
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   332
slouken@1895
   333
    if (data->yuv) {
slouken@1895
   334
        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
slouken@1895
   335
    } else {
slouken@1895
   336
        return 0;
slouken@1895
   337
    }
slouken@1895
   338
}
slouken@1895
   339
slouken@1895
   340
static int
slouken@1895
   341
SDL_D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   342
                          const SDL_Color * colors, int firstcolor,
slouken@1895
   343
                          int ncolors)
slouken@1895
   344
{
slouken@1895
   345
    SDL_D3D_RenderData *renderdata =
slouken@1895
   346
        (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   347
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   348
slouken@1895
   349
    if (data->yuv) {
slouken@1895
   350
        SDL_SetError("YUV textures don't have a palette");
slouken@1895
   351
        return -1;
slouken@1895
   352
    } else {
slouken@1895
   353
        return 0;
slouken@1895
   354
    }
slouken@1895
   355
}
slouken@1895
   356
slouken@1895
   357
static int
slouken@1895
   358
SDL_D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   359
                          SDL_Color * colors, int firstcolor, int ncolors)
slouken@1895
   360
{
slouken@1895
   361
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   362
slouken@1895
   363
    if (data->yuv) {
slouken@1895
   364
        SDL_SetError("YUV textures don't have a palette");
slouken@1895
   365
        return -1;
slouken@1895
   366
    } else {
slouken@1895
   367
        return 0;
slouken@1895
   368
    }
slouken@1895
   369
}
slouken@1895
   370
slouken@1895
   371
static int
slouken@1895
   372
SDL_D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   373
                      const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1895
   374
{
slouken@1895
   375
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   376
slouken@1895
   377
    if (data->yuv) {
slouken@1895
   378
        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
slouken@1895
   379
            return -1;
slouken@1895
   380
        }
slouken@1895
   381
        UpdateYUVTextureData(texture);
slouken@1895
   382
        return 0;
slouken@1895
   383
    } else {
slouken@1895
   384
        SDL_D3D_RenderData *renderdata =
slouken@1895
   385
            (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   386
slouken@1895
   387
        return 0;
slouken@1895
   388
    }
slouken@1895
   389
}
slouken@1895
   390
slouken@1895
   391
static int
slouken@1895
   392
SDL_D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   393
                    const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1895
   394
                    int *pitch)
slouken@1895
   395
{
slouken@1895
   396
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   397
slouken@1895
   398
    if (data->yuv) {
slouken@1895
   399
        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
slouken@1895
   400
                                     pitch);
slouken@1895
   401
    } else {
slouken@1900
   402
        return -1;
slouken@1895
   403
    }
slouken@1895
   404
}
slouken@1895
   405
slouken@1895
   406
static void
slouken@1895
   407
SDL_D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   408
{
slouken@1895
   409
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   410
slouken@1895
   411
    if (data->yuv) {
slouken@1895
   412
        SDL_SW_UnlockYUVTexture(data->yuv);
slouken@1895
   413
        UpdateYUVTextureData(texture);
slouken@1895
   414
    }
slouken@1895
   415
}
slouken@1895
   416
slouken@1895
   417
static void
slouken@1895
   418
SDL_D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   419
                     int numrects, const SDL_Rect * rects)
slouken@1895
   420
{
slouken@1895
   421
}
slouken@1895
   422
slouken@1895
   423
static void
slouken@1895
   424
SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   425
{
slouken@1895
   426
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   427
}
slouken@1895
   428
slouken@1895
   429
static int
slouken@1895
   430
SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   431
                   Uint32 color)
slouken@1895
   432
{
slouken@1895
   433
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1900
   434
    HRESULT result;
slouken@1895
   435
slouken@1900
   436
    if (data->beginScene) {
slouken@1900
   437
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   438
        data->beginScene = SDL_FALSE;
slouken@1900
   439
    }
slouken@1895
   440
slouken@1900
   441
    result =
slouken@1900
   442
        IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET,
slouken@1900
   443
                               (D3DCOLOR) color, 1.0f, 0);
slouken@1900
   444
    if (FAILED(result)) {
slouken@1900
   445
        D3D_SetError("Clear()", result);
slouken@1900
   446
        return -1;
slouken@1900
   447
    }
slouken@1895
   448
    return 0;
slouken@1895
   449
}
slouken@1895
   450
slouken@1895
   451
static int
slouken@1895
   452
SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
   453
                   const SDL_Rect * srcrect, const SDL_Rect * dstrect,
slouken@1895
   454
                   int blendMode, int scaleMode)
slouken@1895
   455
{
slouken@1895
   456
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   457
    SDL_D3D_TextureData *texturedata =
slouken@1895
   458
        (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   459
slouken@1900
   460
    if (data->beginScene) {
slouken@1900
   461
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   462
        data->beginScene = SDL_FALSE;
slouken@1900
   463
    }
slouken@1895
   464
    return 0;
slouken@1895
   465
}
slouken@1895
   466
slouken@1895
   467
static int
slouken@1895
   468
SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   469
                         void *pixels, int pitch)
slouken@1895
   470
{
slouken@1895
   471
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   472
slouken@1895
   473
    return 0;
slouken@1895
   474
}
slouken@1895
   475
slouken@1895
   476
static int
slouken@1895
   477
SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1895
   478
                          const void *pixels, int pitch)
slouken@1895
   479
{
slouken@1895
   480
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   481
slouken@1895
   482
    return 0;
slouken@1895
   483
}
slouken@1895
   484
slouken@1895
   485
static void
slouken@1895
   486
SDL_D3D_RenderPresent(SDL_Renderer * renderer)
slouken@1895
   487
{
slouken@1900
   488
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1900
   489
    HRESULT result;
slouken@1900
   490
slouken@1900
   491
    if (!data->beginScene) {
slouken@1900
   492
        IDirect3DDevice9_EndScene(data->device);
slouken@1900
   493
        data->beginScene = SDL_TRUE;
slouken@1900
   494
    }
slouken@1900
   495
slouken@1900
   496
    result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
slouken@1900
   497
    if (FAILED(result)) {
slouken@1900
   498
        D3D_SetError("Present()", result);
slouken@1900
   499
    }
slouken@1895
   500
}
slouken@1895
   501
slouken@1895
   502
static void
slouken@1895
   503
SDL_D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   504
{
slouken@1895
   505
    SDL_D3D_TextureData *data = (SDL_D3D_TextureData *) texture->driverdata;
slouken@1895
   506
slouken@1895
   507
    if (!data) {
slouken@1895
   508
        return;
slouken@1895
   509
    }
slouken@1895
   510
    SDL_free(data);
slouken@1895
   511
    texture->driverdata = NULL;
slouken@1895
   512
}
slouken@1895
   513
slouken@1895
   514
void
slouken@1895
   515
SDL_D3D_DestroyRenderer(SDL_Renderer * renderer)
slouken@1895
   516
{
slouken@1895
   517
    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
slouken@1895
   518
slouken@1895
   519
    if (data) {
slouken@1900
   520
        if (data->device) {
slouken@1900
   521
            IDirect3DDevice9_Release(data->device);
slouken@1900
   522
        }
slouken@1895
   523
        SDL_free(data);
slouken@1895
   524
    }
slouken@1895
   525
    SDL_free(renderer);
slouken@1895
   526
}
slouken@1895
   527
slouken@1895
   528
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@1895
   529
slouken@1895
   530
/* vi: set ts=4 sw=4 expandtab: */