src/video/win32/SDL_d3drender.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 07 Aug 2006 05:25:13 +0000
changeset 1976 b1620a317791
parent 1975 ccef0d0c40c6
child 1985 8055185ae4ed
permissions -rw-r--r--
Whoops, remove debug code
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
slouken@1895
    28
/* Direct3D renderer implementation */
slouken@1895
    29
slouken@1913
    30
static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
slouken@1975
    31
static int D3D_DisplayModeChanged(SDL_Renderer * renderer);
slouken@1913
    32
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1913
    33
static int D3D_SetTexturePalette(SDL_Renderer * renderer,
slouken@1913
    34
                                 SDL_Texture * texture,
slouken@1913
    35
                                 const SDL_Color * colors, int firstcolor,
slouken@1913
    36
                                 int ncolors);
slouken@1913
    37
static int D3D_GetTexturePalette(SDL_Renderer * renderer,
slouken@1913
    38
                                 SDL_Texture * texture, SDL_Color * colors,
slouken@1913
    39
                                 int firstcolor, int ncolors);
slouken@1913
    40
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
    41
                             const SDL_Rect * rect, const void *pixels,
slouken@1913
    42
                             int pitch);
slouken@1913
    43
static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
    44
                           const SDL_Rect * rect, int markDirty,
slouken@1913
    45
                           void **pixels, int *pitch);
slouken@1913
    46
static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1913
    47
static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
    48
                             int numrects, const SDL_Rect * rects);
slouken@1913
    49
static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
slouken@1913
    50
                          Uint32 color);
slouken@1913
    51
static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
    52
                          const SDL_Rect * srcrect, const SDL_Rect * dstrect,
slouken@1913
    53
                          int blendMode, int scaleMode);
slouken@1913
    54
static void D3D_RenderPresent(SDL_Renderer * renderer);
slouken@1913
    55
static void D3D_DestroyTexture(SDL_Renderer * renderer,
slouken@1913
    56
                               SDL_Texture * texture);
slouken@1913
    57
static void D3D_DestroyRenderer(SDL_Renderer * renderer);
slouken@1895
    58
slouken@1895
    59
slouken@1913
    60
SDL_RenderDriver D3D_RenderDriver = {
slouken@1913
    61
    D3D_CreateRenderer,
slouken@1895
    62
    {
slouken@1895
    63
     "d3d",
slouken@1965
    64
     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
slouken@1975
    65
      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
slouken@1965
    66
      SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_PRESENTVSYNC |
slouken@1965
    67
      SDL_RENDERER_ACCELERATED),
slouken@1965
    68
     (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
slouken@1965
    69
      SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
slouken@1965
    70
      SDL_TEXTUREBLENDMODE_MOD),
slouken@1965
    71
     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
slouken@1965
    72
      SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
slouken@1903
    73
     12,
slouken@1895
    74
     {
slouken@1965
    75
      SDL_PIXELFORMAT_INDEX8,
slouken@1965
    76
      SDL_PIXELFORMAT_RGB332,
slouken@1965
    77
      SDL_PIXELFORMAT_RGB444,
slouken@1965
    78
      SDL_PIXELFORMAT_RGB555,
slouken@1965
    79
      SDL_PIXELFORMAT_ARGB4444,
slouken@1965
    80
      SDL_PIXELFORMAT_ARGB1555,
slouken@1965
    81
      SDL_PIXELFORMAT_RGB565,
slouken@1965
    82
      SDL_PIXELFORMAT_RGB888,
slouken@1965
    83
      SDL_PIXELFORMAT_ARGB8888,
slouken@1965
    84
      SDL_PIXELFORMAT_ARGB2101010,
slouken@1965
    85
      SDL_PIXELFORMAT_UYVY,
slouken@1965
    86
      SDL_PIXELFORMAT_YUY2},
slouken@1895
    87
     0,
slouken@1895
    88
     0}
slouken@1895
    89
};
slouken@1895
    90
slouken@1895
    91
typedef struct
slouken@1895
    92
{
slouken@1895
    93
    IDirect3DDevice9 *device;
slouken@1975
    94
    D3DPRESENT_PARAMETERS pparams;
slouken@1900
    95
    SDL_bool beginScene;
slouken@1913
    96
} D3D_RenderData;
slouken@1895
    97
slouken@1895
    98
typedef struct
slouken@1895
    99
{
slouken@1903
   100
    IDirect3DTexture9 *texture;
slouken@1913
   101
} D3D_TextureData;
slouken@1895
   102
slouken@1903
   103
typedef struct
slouken@1903
   104
{
slouken@1903
   105
    float x, y, z;
slouken@1904
   106
    float rhw;
slouken@1904
   107
    float u, v;
slouken@1903
   108
} Vertex;
slouken@1903
   109
slouken@1895
   110
static void
slouken@1900
   111
D3D_SetError(const char *prefix, HRESULT result)
slouken@1900
   112
{
slouken@1900
   113
    const char *error;
slouken@1900
   114
slouken@1900
   115
    switch (result) {
slouken@1900
   116
    case D3DERR_WRONGTEXTUREFORMAT:
slouken@1900
   117
        error = "WRONGTEXTUREFORMAT";
slouken@1900
   118
        break;
slouken@1900
   119
    case D3DERR_UNSUPPORTEDCOLOROPERATION:
slouken@1900
   120
        error = "UNSUPPORTEDCOLOROPERATION";
slouken@1900
   121
        break;
slouken@1900
   122
    case D3DERR_UNSUPPORTEDCOLORARG:
slouken@1900
   123
        error = "UNSUPPORTEDCOLORARG";
slouken@1900
   124
        break;
slouken@1900
   125
    case D3DERR_UNSUPPORTEDALPHAOPERATION:
slouken@1900
   126
        error = "UNSUPPORTEDALPHAOPERATION";
slouken@1900
   127
        break;
slouken@1900
   128
    case D3DERR_UNSUPPORTEDALPHAARG:
slouken@1900
   129
        error = "UNSUPPORTEDALPHAARG";
slouken@1900
   130
        break;
slouken@1900
   131
    case D3DERR_TOOMANYOPERATIONS:
slouken@1900
   132
        error = "TOOMANYOPERATIONS";
slouken@1900
   133
        break;
slouken@1900
   134
    case D3DERR_CONFLICTINGTEXTUREFILTER:
slouken@1900
   135
        error = "CONFLICTINGTEXTUREFILTER";
slouken@1900
   136
        break;
slouken@1900
   137
    case D3DERR_UNSUPPORTEDFACTORVALUE:
slouken@1900
   138
        error = "UNSUPPORTEDFACTORVALUE";
slouken@1900
   139
        break;
slouken@1900
   140
    case D3DERR_CONFLICTINGRENDERSTATE:
slouken@1900
   141
        error = "CONFLICTINGRENDERSTATE";
slouken@1900
   142
        break;
slouken@1900
   143
    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
slouken@1900
   144
        error = "UNSUPPORTEDTEXTUREFILTER";
slouken@1900
   145
        break;
slouken@1900
   146
    case D3DERR_CONFLICTINGTEXTUREPALETTE:
slouken@1900
   147
        error = "CONFLICTINGTEXTUREPALETTE";
slouken@1900
   148
        break;
slouken@1900
   149
    case D3DERR_DRIVERINTERNALERROR:
slouken@1900
   150
        error = "DRIVERINTERNALERROR";
slouken@1900
   151
        break;
slouken@1900
   152
    case D3DERR_NOTFOUND:
slouken@1900
   153
        error = "NOTFOUND";
slouken@1900
   154
        break;
slouken@1900
   155
    case D3DERR_MOREDATA:
slouken@1900
   156
        error = "MOREDATA";
slouken@1900
   157
        break;
slouken@1900
   158
    case D3DERR_DEVICELOST:
slouken@1900
   159
        error = "DEVICELOST";
slouken@1900
   160
        break;
slouken@1900
   161
    case D3DERR_DEVICENOTRESET:
slouken@1900
   162
        error = "DEVICENOTRESET";
slouken@1900
   163
        break;
slouken@1900
   164
    case D3DERR_NOTAVAILABLE:
slouken@1900
   165
        error = "NOTAVAILABLE";
slouken@1900
   166
        break;
slouken@1900
   167
    case D3DERR_OUTOFVIDEOMEMORY:
slouken@1900
   168
        error = "OUTOFVIDEOMEMORY";
slouken@1900
   169
        break;
slouken@1900
   170
    case D3DERR_INVALIDDEVICE:
slouken@1900
   171
        error = "INVALIDDEVICE";
slouken@1900
   172
        break;
slouken@1900
   173
    case D3DERR_INVALIDCALL:
slouken@1900
   174
        error = "INVALIDCALL";
slouken@1900
   175
        break;
slouken@1900
   176
    case D3DERR_DRIVERINVALIDCALL:
slouken@1900
   177
        error = "DRIVERINVALIDCALL";
slouken@1900
   178
        break;
slouken@1900
   179
    case D3DERR_WASSTILLDRAWING:
slouken@1900
   180
        error = "WASSTILLDRAWING";
slouken@1900
   181
        break;
slouken@1900
   182
    default:
slouken@1900
   183
        error = "UNKNOWN";
slouken@1900
   184
        break;
slouken@1900
   185
    }
slouken@1900
   186
    SDL_SetError("%s: %s", prefix, error);
slouken@1900
   187
}
slouken@1900
   188
slouken@1903
   189
static D3DFORMAT
slouken@1903
   190
PixelFormatToD3DFMT(Uint32 format)
slouken@1895
   191
{
slouken@1903
   192
    switch (format) {
slouken@1965
   193
    case SDL_PIXELFORMAT_INDEX8:
slouken@1903
   194
        return D3DFMT_P8;
slouken@1965
   195
    case SDL_PIXELFORMAT_RGB332:
slouken@1903
   196
        return D3DFMT_R3G3B2;
slouken@1965
   197
    case SDL_PIXELFORMAT_RGB444:
slouken@1903
   198
        return D3DFMT_X4R4G4B4;
slouken@1965
   199
    case SDL_PIXELFORMAT_RGB555:
slouken@1903
   200
        return D3DFMT_X1R5G5B5;
slouken@1965
   201
    case SDL_PIXELFORMAT_ARGB4444:
slouken@1903
   202
        return D3DFMT_A4R4G4B4;
slouken@1965
   203
    case SDL_PIXELFORMAT_ARGB1555:
slouken@1903
   204
        return D3DFMT_A1R5G5B5;
slouken@1965
   205
    case SDL_PIXELFORMAT_RGB565:
slouken@1903
   206
        return D3DFMT_R5G6B5;
slouken@1965
   207
    case SDL_PIXELFORMAT_RGB888:
slouken@1903
   208
        return D3DFMT_X8R8G8B8;
slouken@1965
   209
    case SDL_PIXELFORMAT_ARGB8888:
slouken@1903
   210
        return D3DFMT_A8R8G8B8;
slouken@1965
   211
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@1903
   212
        return D3DFMT_A2R10G10B10;
slouken@1965
   213
    case SDL_PIXELFORMAT_UYVY:
slouken@1903
   214
        return D3DFMT_UYVY;
slouken@1965
   215
    case SDL_PIXELFORMAT_YUY2:
slouken@1903
   216
        return D3DFMT_YUY2;
slouken@1903
   217
    default:
slouken@1903
   218
        return D3DFMT_UNKNOWN;
slouken@1903
   219
    }
slouken@1895
   220
}
slouken@1895
   221
slouken@1895
   222
void
slouken@1895
   223
D3D_AddRenderDriver(_THIS)
slouken@1895
   224
{
slouken@1895
   225
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1895
   226
slouken@1895
   227
    if (data->d3d) {
slouken@1913
   228
        SDL_AddRenderDriver(0, &D3D_RenderDriver);
slouken@1895
   229
    }
slouken@1895
   230
}
slouken@1895
   231
slouken@1895
   232
SDL_Renderer *
slouken@1913
   233
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
slouken@1895
   234
{
slouken@1895
   235
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1895
   236
    SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata;
slouken@1895
   237
    SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
slouken@1895
   238
    SDL_Renderer *renderer;
slouken@1913
   239
    D3D_RenderData *data;
slouken@1900
   240
    HRESULT result;
slouken@1900
   241
    D3DPRESENT_PARAMETERS pparams;
slouken@1907
   242
    IDirect3DSwapChain9 *chain;
slouken@1925
   243
    D3DCAPS9 caps;
slouken@1895
   244
slouken@1920
   245
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
slouken@1895
   246
    if (!renderer) {
slouken@1895
   247
        SDL_OutOfMemory();
slouken@1895
   248
        return NULL;
slouken@1895
   249
    }
slouken@1895
   250
slouken@1920
   251
    data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
slouken@1895
   252
    if (!data) {
slouken@1913
   253
        D3D_DestroyRenderer(renderer);
slouken@1895
   254
        SDL_OutOfMemory();
slouken@1895
   255
        return NULL;
slouken@1895
   256
    }
slouken@1895
   257
slouken@1975
   258
    renderer->DisplayModeChanged = D3D_DisplayModeChanged;
slouken@1913
   259
    renderer->CreateTexture = D3D_CreateTexture;
slouken@1913
   260
    renderer->SetTexturePalette = D3D_SetTexturePalette;
slouken@1913
   261
    renderer->GetTexturePalette = D3D_GetTexturePalette;
slouken@1913
   262
    renderer->UpdateTexture = D3D_UpdateTexture;
slouken@1913
   263
    renderer->LockTexture = D3D_LockTexture;
slouken@1913
   264
    renderer->UnlockTexture = D3D_UnlockTexture;
slouken@1913
   265
    renderer->DirtyTexture = D3D_DirtyTexture;
slouken@1913
   266
    renderer->RenderFill = D3D_RenderFill;
slouken@1913
   267
    renderer->RenderCopy = D3D_RenderCopy;
slouken@1913
   268
    renderer->RenderPresent = D3D_RenderPresent;
slouken@1913
   269
    renderer->DestroyTexture = D3D_DestroyTexture;
slouken@1913
   270
    renderer->DestroyRenderer = D3D_DestroyRenderer;
slouken@1913
   271
    renderer->info = D3D_RenderDriver.info;
slouken@1895
   272
    renderer->window = window->id;
slouken@1895
   273
    renderer->driverdata = data;
slouken@1895
   274
slouken@1965
   275
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
slouken@1895
   276
slouken@1900
   277
    SDL_zero(pparams);
slouken@1900
   278
    pparams.BackBufferWidth = window->w;
slouken@1900
   279
    pparams.BackBufferHeight = window->h;
slouken@1903
   280
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1903
   281
        pparams.BackBufferFormat =
slouken@1975
   282
            PixelFormatToD3DFMT(display->fullscreen_mode.format);
slouken@1903
   283
    } else {
slouken@1903
   284
        pparams.BackBufferFormat = D3DFMT_UNKNOWN;
slouken@1903
   285
    }
slouken@1965
   286
    if (flags & SDL_RENDERER_PRESENTFLIP2) {
slouken@1900
   287
        pparams.BackBufferCount = 2;
slouken@1900
   288
        pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
slouken@1965
   289
    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
slouken@1900
   290
        pparams.BackBufferCount = 3;
slouken@1900
   291
        pparams.SwapEffect = D3DSWAPEFFECT_FLIP;
slouken@1965
   292
    } else if (flags & SDL_RENDERER_PRESENTCOPY) {
slouken@1900
   293
        pparams.BackBufferCount = 1;
slouken@1900
   294
        pparams.SwapEffect = D3DSWAPEFFECT_COPY;
slouken@1900
   295
    } else {
slouken@1900
   296
        pparams.BackBufferCount = 1;
slouken@1900
   297
        pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
slouken@1900
   298
    }
slouken@1900
   299
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1900
   300
        pparams.Windowed = FALSE;
slouken@1903
   301
        pparams.FullScreen_RefreshRateInHz =
slouken@1975
   302
            display->fullscreen_mode.refresh_rate;
slouken@1900
   303
    } else {
slouken@1900
   304
        pparams.Windowed = TRUE;
slouken@1903
   305
        pparams.FullScreen_RefreshRateInHz = 0;
slouken@1900
   306
    }
slouken@1965
   307
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1907
   308
        pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
slouken@1907
   309
    } else {
slouken@1907
   310
        pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
slouken@1907
   311
    }
slouken@1900
   312
slouken@1900
   313
    result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT,        /* FIXME */
slouken@1900
   314
                                     D3DDEVTYPE_HAL,
slouken@1900
   315
                                     windowdata->hwnd,
slouken@1900
   316
                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
slouken@1900
   317
                                     &pparams, &data->device);
slouken@1900
   318
    if (FAILED(result)) {
slouken@1913
   319
        D3D_DestroyRenderer(renderer);
slouken@1900
   320
        D3D_SetError("CreateDevice()", result);
slouken@1900
   321
        return NULL;
slouken@1900
   322
    }
slouken@1900
   323
    data->beginScene = SDL_TRUE;
slouken@1900
   324
slouken@1907
   325
    /* Get presentation parameters to fill info */
slouken@1907
   326
    result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
slouken@1907
   327
    if (FAILED(result)) {
slouken@1913
   328
        D3D_DestroyRenderer(renderer);
slouken@1907
   329
        D3D_SetError("GetSwapChain()", result);
slouken@1907
   330
        return NULL;
slouken@1907
   331
    }
slouken@1907
   332
    result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
slouken@1907
   333
    if (FAILED(result)) {
slouken@1907
   334
        IDirect3DSwapChain9_Release(chain);
slouken@1913
   335
        D3D_DestroyRenderer(renderer);
slouken@1907
   336
        D3D_SetError("GetPresentParameters()", result);
slouken@1907
   337
        return NULL;
slouken@1907
   338
    }
slouken@1907
   339
    IDirect3DSwapChain9_Release(chain);
slouken@1907
   340
    switch (pparams.SwapEffect) {
slouken@1907
   341
    case D3DSWAPEFFECT_COPY:
slouken@1965
   342
        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
slouken@1907
   343
        break;
slouken@1907
   344
    case D3DSWAPEFFECT_FLIP:
slouken@1907
   345
        switch (pparams.BackBufferCount) {
slouken@1907
   346
        case 2:
slouken@1965
   347
            renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
slouken@1907
   348
            break;
slouken@1907
   349
        case 3:
slouken@1965
   350
            renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
slouken@1907
   351
            break;
slouken@1907
   352
        }
slouken@1907
   353
        break;
slouken@1907
   354
    case D3DSWAPEFFECT_DISCARD:
slouken@1965
   355
        renderer->info.flags |= SDL_RENDERER_PRESENTDISCARD;
slouken@1907
   356
        break;
slouken@1907
   357
    }
slouken@1907
   358
    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
slouken@1965
   359
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1907
   360
    }
slouken@1975
   361
    data->pparams = pparams;
slouken@1907
   362
slouken@1925
   363
    IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
slouken@1925
   364
    renderer->info.max_texture_width = caps.MaxTextureWidth;
slouken@1925
   365
    renderer->info.max_texture_height = caps.MaxTextureHeight;
slouken@1918
   366
slouken@1903
   367
    /* Set up parameters for rendering */
slouken@1904
   368
    IDirect3DDevice9_SetVertexShader(data->device, NULL);
slouken@1904
   369
    IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
slouken@1903
   370
    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
slouken@1903
   371
                                    D3DCULL_NONE);
slouken@1904
   372
    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
slouken@1903
   373
slouken@1895
   374
    return renderer;
slouken@1895
   375
}
slouken@1895
   376
slouken@1895
   377
static int
slouken@1975
   378
D3D_Reset(SDL_Renderer * renderer)
slouken@1975
   379
{
slouken@1975
   380
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1975
   381
    HRESULT result;
slouken@1975
   382
slouken@1975
   383
    result = IDirect3DDevice9_Reset(data->device, &data->pparams);
slouken@1975
   384
    if (FAILED(result)) {
slouken@1975
   385
        if (result == D3DERR_DEVICELOST) {
slouken@1975
   386
            /* Don't worry about it, we'll reset later... */
slouken@1975
   387
            return 0;
slouken@1975
   388
        } else {
slouken@1975
   389
            D3D_SetError("Reset()", result);
slouken@1975
   390
            return -1;
slouken@1975
   391
        }
slouken@1975
   392
    }
slouken@1975
   393
    IDirect3DDevice9_SetVertexShader(data->device, NULL);
slouken@1975
   394
    IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
slouken@1975
   395
    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
slouken@1975
   396
                                    D3DCULL_NONE);
slouken@1975
   397
    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
slouken@1975
   398
    return 0;
slouken@1975
   399
}
slouken@1975
   400
slouken@1975
   401
static int
slouken@1975
   402
D3D_DisplayModeChanged(SDL_Renderer * renderer)
slouken@1975
   403
{
slouken@1975
   404
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1975
   405
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1975
   406
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1975
   407
slouken@1975
   408
    data->pparams.BackBufferWidth = window->w;
slouken@1975
   409
    data->pparams.BackBufferHeight = window->h;
slouken@1975
   410
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1975
   411
        data->pparams.BackBufferFormat =
slouken@1975
   412
            PixelFormatToD3DFMT(display->fullscreen_mode.format);
slouken@1975
   413
    } else {
slouken@1975
   414
        data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
slouken@1975
   415
    }
slouken@1975
   416
    return D3D_Reset(renderer);
slouken@1975
   417
}
slouken@1975
   418
slouken@1975
   419
static int
slouken@1913
   420
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   421
{
slouken@1913
   422
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
slouken@1895
   423
    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
slouken@1895
   424
    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
slouken@1913
   425
    D3D_TextureData *data;
slouken@1903
   426
    D3DPOOL pool;
slouken@1903
   427
    HRESULT result;
slouken@1895
   428
slouken@1920
   429
    data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
slouken@1895
   430
    if (!data) {
slouken@1895
   431
        SDL_OutOfMemory();
slouken@1895
   432
        return -1;
slouken@1895
   433
    }
slouken@1895
   434
slouken@1895
   435
    texture->driverdata = data;
slouken@1895
   436
slouken@1975
   437
#if 1
slouken@1975
   438
    /* FIXME: Do we want non-managed textures?
slouken@1975
   439
       They need to be freed on device reset and then reloaded by the app...
slouken@1975
   440
     */
slouken@1975
   441
    texture->access = SDL_TEXTUREACCESS_LOCAL;
slouken@1975
   442
#endif
slouken@1965
   443
    if (texture->access == SDL_TEXTUREACCESS_LOCAL) {
slouken@1903
   444
        pool = D3DPOOL_MANAGED;
slouken@1903
   445
    } else {
slouken@1903
   446
        pool = D3DPOOL_DEFAULT;
slouken@1903
   447
    }
slouken@1903
   448
    result =
slouken@1903
   449
        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
slouken@1903
   450
                                       texture->h, 1, 0,
slouken@1903
   451
                                       PixelFormatToD3DFMT(texture->format),
slouken@1903
   452
                                       pool, &data->texture, NULL);
slouken@1903
   453
    if (FAILED(result)) {
slouken@1903
   454
        D3D_SetError("CreateTexture()", result);
slouken@1903
   455
        return -1;
slouken@1903
   456
    }
slouken@1895
   457
slouken@1903
   458
    return 0;
slouken@1895
   459
}
slouken@1895
   460
slouken@1895
   461
static int
slouken@1913
   462
D3D_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
   463
                      const SDL_Color * colors, int firstcolor, int ncolors)
slouken@1895
   464
{
slouken@1913
   465
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
slouken@1913
   466
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1895
   467
slouken@1903
   468
    return 0;
slouken@1895
   469
}
slouken@1895
   470
slouken@1895
   471
static int
slouken@1913
   472
D3D_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
   473
                      SDL_Color * colors, int firstcolor, int ncolors)
slouken@1895
   474
{
slouken@1913
   475
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1895
   476
slouken@1903
   477
    return 0;
slouken@1895
   478
}
slouken@1895
   479
slouken@1895
   480
static int
slouken@1913
   481
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
   482
                  const SDL_Rect * rect, const void *pixels, int pitch)
slouken@1895
   483
{
slouken@1913
   484
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1913
   485
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
slouken@1903
   486
    IDirect3DTexture9 *temp;
slouken@1903
   487
    RECT d3drect;
slouken@1903
   488
    D3DLOCKED_RECT locked;
slouken@1903
   489
    const Uint8 *src;
slouken@1903
   490
    Uint8 *dst;
slouken@1903
   491
    int row, length;
slouken@1903
   492
    HRESULT result;
slouken@1895
   493
slouken@1903
   494
    result =
slouken@1903
   495
        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
slouken@1903
   496
                                       texture->h, 1, 0,
slouken@1903
   497
                                       PixelFormatToD3DFMT(texture->format),
slouken@1903
   498
                                       D3DPOOL_SYSTEMMEM, &temp, NULL);
slouken@1903
   499
    if (FAILED(result)) {
slouken@1903
   500
        D3D_SetError("CreateTexture()", result);
slouken@1903
   501
        return -1;
slouken@1903
   502
    }
slouken@1903
   503
slouken@1903
   504
    d3drect.left = rect->x;
slouken@1903
   505
    d3drect.right = rect->x + rect->w;
slouken@1903
   506
    d3drect.top = rect->y;
slouken@1903
   507
    d3drect.bottom = rect->y + rect->h;
slouken@1903
   508
slouken@1903
   509
    result = IDirect3DTexture9_LockRect(temp, 0, &locked, &d3drect, 0);
slouken@1903
   510
    if (FAILED(result)) {
slouken@1903
   511
        IDirect3DTexture9_Release(temp);
slouken@1903
   512
        D3D_SetError("LockRect()", result);
slouken@1903
   513
        return -1;
slouken@1903
   514
    }
slouken@1895
   515
slouken@1903
   516
    src = pixels;
slouken@1903
   517
    dst = locked.pBits;
slouken@1903
   518
    length = rect->w * SDL_BYTESPERPIXEL(texture->format);
slouken@1903
   519
    for (row = 0; row < rect->h; ++row) {
slouken@1903
   520
        SDL_memcpy(dst, src, length);
slouken@1903
   521
        src += pitch;
slouken@1903
   522
        dst += locked.Pitch;
slouken@1895
   523
    }
slouken@1903
   524
    IDirect3DTexture9_UnlockRect(temp, 0);
slouken@1903
   525
slouken@1903
   526
    result =
slouken@1903
   527
        IDirect3DDevice9_UpdateTexture(renderdata->device,
slouken@1903
   528
                                       (IDirect3DBaseTexture9 *) temp,
slouken@1903
   529
                                       (IDirect3DBaseTexture9 *) data->
slouken@1903
   530
                                       texture);
slouken@1903
   531
    IDirect3DTexture9_Release(temp);
slouken@1903
   532
    if (FAILED(result)) {
slouken@1903
   533
        D3D_SetError("UpdateTexture()", result);
slouken@1903
   534
        return -1;
slouken@1903
   535
    }
slouken@1903
   536
    return 0;
slouken@1895
   537
}
slouken@1895
   538
slouken@1895
   539
static int
slouken@1913
   540
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
   541
                const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1913
   542
                int *pitch)
slouken@1895
   543
{
slouken@1913
   544
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1903
   545
    RECT d3drect;
slouken@1903
   546
    D3DLOCKED_RECT locked;
slouken@1903
   547
    HRESULT result;
slouken@1895
   548
slouken@1965
   549
    if (texture->access != SDL_TEXTUREACCESS_LOCAL) {
slouken@1903
   550
        SDL_SetError("Can't lock remote video memory");
slouken@1900
   551
        return -1;
slouken@1895
   552
    }
slouken@1903
   553
slouken@1903
   554
    d3drect.left = rect->x;
slouken@1903
   555
    d3drect.right = rect->x + rect->w;
slouken@1903
   556
    d3drect.top = rect->y;
slouken@1903
   557
    d3drect.bottom = rect->y + rect->h;
slouken@1903
   558
slouken@1903
   559
    result =
slouken@1903
   560
        IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect,
slouken@1903
   561
                                   markDirty ? 0 : D3DLOCK_NO_DIRTY_UPDATE);
slouken@1903
   562
    if (FAILED(result)) {
slouken@1903
   563
        D3D_SetError("LockRect()", result);
slouken@1903
   564
        return -1;
slouken@1903
   565
    }
slouken@1903
   566
    *pixels = locked.pBits;
slouken@1903
   567
    *pitch = locked.Pitch;
slouken@1903
   568
    return 0;
slouken@1895
   569
}
slouken@1895
   570
slouken@1895
   571
static void
slouken@1913
   572
D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   573
{
slouken@1913
   574
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1895
   575
slouken@1903
   576
    IDirect3DTexture9_UnlockRect(data->texture, 0);
slouken@1895
   577
}
slouken@1895
   578
slouken@1895
   579
static void
slouken@1913
   580
D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
slouken@1913
   581
                 const SDL_Rect * rects)
slouken@1895
   582
{
slouken@1913
   583
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1903
   584
    RECT d3drect;
slouken@1903
   585
    int i;
slouken@1903
   586
slouken@1903
   587
    for (i = 0; i < numrects; ++i) {
slouken@1903
   588
        const SDL_Rect *rect = &rects[i];
slouken@1903
   589
slouken@1903
   590
        d3drect.left = rect->x;
slouken@1903
   591
        d3drect.right = rect->x + rect->w;
slouken@1903
   592
        d3drect.top = rect->y;
slouken@1903
   593
        d3drect.bottom = rect->y + rect->h;
slouken@1903
   594
slouken@1903
   595
        IDirect3DTexture9_AddDirtyRect(data->texture, &d3drect);
slouken@1903
   596
    }
slouken@1895
   597
}
slouken@1895
   598
slouken@1895
   599
static int
slouken@1913
   600
D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color)
slouken@1895
   601
{
slouken@1913
   602
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1901
   603
    D3DRECT d3drect;
slouken@1900
   604
    HRESULT result;
slouken@1900
   605
slouken@1900
   606
    if (data->beginScene) {
slouken@1900
   607
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   608
        data->beginScene = SDL_FALSE;
slouken@1900
   609
    }
slouken@1895
   610
slouken@1901
   611
    d3drect.x1 = rect->x;
slouken@1903
   612
    d3drect.x2 = rect->x + rect->w;
slouken@1901
   613
    d3drect.y1 = rect->y;
slouken@1903
   614
    d3drect.y2 = rect->y + rect->h;
slouken@1901
   615
slouken@1903
   616
    result =
slouken@1903
   617
        IDirect3DDevice9_Clear(data->device, 1, &d3drect, D3DCLEAR_TARGET,
slouken@1903
   618
                               (D3DCOLOR) color, 1.0f, 0);
slouken@1900
   619
    if (FAILED(result)) {
slouken@1900
   620
        D3D_SetError("Clear()", result);
slouken@1900
   621
        return -1;
slouken@1900
   622
    }
slouken@1895
   623
    return 0;
slouken@1895
   624
}
slouken@1895
   625
slouken@1895
   626
static int
slouken@1913
   627
D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1913
   628
               const SDL_Rect * srcrect, const SDL_Rect * dstrect,
slouken@1913
   629
               int blendMode, int scaleMode)
slouken@1895
   630
{
slouken@1913
   631
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1913
   632
    D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
slouken@1903
   633
    float minx, miny, maxx, maxy;
slouken@1904
   634
    float minu, maxu, minv, maxv;
slouken@1903
   635
    Vertex vertices[4];
slouken@1903
   636
    HRESULT result;
slouken@1895
   637
slouken@1900
   638
    if (data->beginScene) {
slouken@1900
   639
        IDirect3DDevice9_BeginScene(data->device);
slouken@1900
   640
        data->beginScene = SDL_FALSE;
slouken@1900
   641
    }
slouken@1903
   642
slouken@1904
   643
    minx = (float) dstrect->x - 0.5f;
slouken@1904
   644
    miny = (float) dstrect->y - 0.5f;
slouken@1904
   645
    maxx = (float) dstrect->x + dstrect->w - 0.5f;
slouken@1904
   646
    maxy = (float) dstrect->y + dstrect->h - 0.5f;
slouken@1903
   647
slouken@1904
   648
    minu = (float) srcrect->x / texture->w;
slouken@1904
   649
    maxu = (float) (srcrect->x + srcrect->w) / texture->w;
slouken@1904
   650
    minv = (float) srcrect->y / texture->h;
slouken@1904
   651
    maxv = (float) (srcrect->y + srcrect->h) / texture->h;
slouken@1903
   652
slouken@1903
   653
    vertices[0].x = minx;
slouken@1903
   654
    vertices[0].y = miny;
slouken@1903
   655
    vertices[0].z = 0.0f;
slouken@1904
   656
    vertices[0].rhw = 1.0f;
slouken@1904
   657
    vertices[0].u = minu;
slouken@1904
   658
    vertices[0].v = minv;
slouken@1904
   659
slouken@1903
   660
    vertices[1].x = maxx;
slouken@1903
   661
    vertices[1].y = miny;
slouken@1903
   662
    vertices[1].z = 0.0f;
slouken@1904
   663
    vertices[1].rhw = 1.0f;
slouken@1904
   664
    vertices[1].u = maxu;
slouken@1904
   665
    vertices[1].v = minv;
slouken@1904
   666
slouken@1903
   667
    vertices[2].x = maxx;
slouken@1903
   668
    vertices[2].y = maxy;
slouken@1903
   669
    vertices[2].z = 0.0f;
slouken@1904
   670
    vertices[2].rhw = 1.0f;
slouken@1904
   671
    vertices[2].u = maxu;
slouken@1904
   672
    vertices[2].v = maxv;
slouken@1904
   673
slouken@1903
   674
    vertices[3].x = minx;
slouken@1903
   675
    vertices[3].y = maxy;
slouken@1903
   676
    vertices[3].z = 0.0f;
slouken@1904
   677
    vertices[3].rhw = 1.0f;
slouken@1904
   678
    vertices[3].u = minu;
slouken@1904
   679
    vertices[3].v = maxv;
slouken@1903
   680
slouken@1916
   681
    switch (blendMode) {
slouken@1965
   682
    case SDL_TEXTUREBLENDMODE_NONE:
slouken@1916
   683
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
slouken@1916
   684
                                        FALSE);
slouken@1916
   685
        break;
slouken@1965
   686
    case SDL_TEXTUREBLENDMODE_MASK:
slouken@1965
   687
    case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1916
   688
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
slouken@1916
   689
                                        TRUE);
slouken@1916
   690
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
slouken@1916
   691
                                        D3DBLEND_SRCALPHA);
slouken@1916
   692
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
slouken@1916
   693
                                        D3DBLEND_INVSRCALPHA);
slouken@1916
   694
        break;
slouken@1965
   695
    case SDL_TEXTUREBLENDMODE_ADD:
slouken@1916
   696
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
slouken@1916
   697
                                        TRUE);
slouken@1916
   698
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
slouken@1916
   699
                                        D3DBLEND_SRCALPHA);
slouken@1916
   700
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
slouken@1916
   701
                                        D3DBLEND_ONE);
slouken@1916
   702
        break;
slouken@1965
   703
    case SDL_TEXTUREBLENDMODE_MOD:
slouken@1916
   704
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
slouken@1916
   705
                                        TRUE);
slouken@1916
   706
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
slouken@1916
   707
                                        D3DBLEND_ZERO);
slouken@1916
   708
        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
slouken@1916
   709
                                        D3DBLEND_SRCCOLOR);
slouken@1916
   710
        break;
slouken@1916
   711
    }
slouken@1916
   712
slouken@1917
   713
    switch (scaleMode) {
slouken@1965
   714
    case SDL_TEXTURESCALEMODE_NONE:
slouken@1965
   715
    case SDL_TEXTURESCALEMODE_FAST:
slouken@1917
   716
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
slouken@1917
   717
                                         D3DTEXF_POINT);
slouken@1917
   718
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
slouken@1917
   719
                                         D3DTEXF_POINT);
slouken@1917
   720
        break;
slouken@1965
   721
    case SDL_TEXTURESCALEMODE_SLOW:
slouken@1917
   722
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
slouken@1917
   723
                                         D3DTEXF_LINEAR);
slouken@1917
   724
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
slouken@1917
   725
                                         D3DTEXF_LINEAR);
slouken@1917
   726
        break;
slouken@1965
   727
    case SDL_TEXTURESCALEMODE_BEST:
slouken@1917
   728
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
slouken@1917
   729
                                         D3DTEXF_GAUSSIANQUAD);
slouken@1917
   730
        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
slouken@1917
   731
                                         D3DTEXF_GAUSSIANQUAD);
slouken@1917
   732
        break;
slouken@1917
   733
    }
slouken@1917
   734
slouken@1903
   735
    result =
slouken@1903
   736
        IDirect3DDevice9_SetTexture(data->device, 0,
slouken@1903
   737
                                    (IDirect3DBaseTexture9 *) texturedata->
slouken@1903
   738
                                    texture);
slouken@1903
   739
    if (FAILED(result)) {
slouken@1903
   740
        D3D_SetError("SetTexture()", result);
slouken@1903
   741
        return -1;
slouken@1903
   742
    }
slouken@1903
   743
    result =
slouken@1903
   744
        IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
slouken@1903
   745
                                         vertices, sizeof(*vertices));
slouken@1903
   746
    if (FAILED(result)) {
slouken@1903
   747
        D3D_SetError("DrawPrimitiveUP()", result);
slouken@1903
   748
        return -1;
slouken@1903
   749
    }
slouken@1895
   750
    return 0;
slouken@1895
   751
}
slouken@1895
   752
slouken@1895
   753
static void
slouken@1913
   754
D3D_RenderPresent(SDL_Renderer * renderer)
slouken@1895
   755
{
slouken@1913
   756
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1900
   757
    HRESULT result;
slouken@1900
   758
slouken@1900
   759
    if (!data->beginScene) {
slouken@1900
   760
        IDirect3DDevice9_EndScene(data->device);
slouken@1900
   761
        data->beginScene = SDL_TRUE;
slouken@1900
   762
    }
slouken@1900
   763
slouken@1975
   764
    result = IDirect3DDevice9_TestCooperativeLevel(data->device);
slouken@1975
   765
    if (result == D3DERR_DEVICELOST) {
slouken@1975
   766
        /* We'll reset later */
slouken@1975
   767
        return;
slouken@1975
   768
    }
slouken@1975
   769
    if (result == D3DERR_DEVICENOTRESET) {
slouken@1975
   770
        D3D_Reset(renderer);
slouken@1975
   771
    }
slouken@1900
   772
    result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
slouken@1900
   773
    if (FAILED(result)) {
slouken@1900
   774
        D3D_SetError("Present()", result);
slouken@1900
   775
    }
slouken@1895
   776
}
slouken@1895
   777
slouken@1895
   778
static void
slouken@1913
   779
D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
slouken@1895
   780
{
slouken@1913
   781
    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
slouken@1895
   782
slouken@1895
   783
    if (!data) {
slouken@1895
   784
        return;
slouken@1895
   785
    }
slouken@1903
   786
    if (data->texture) {
slouken@1903
   787
        IDirect3DTexture9_Release(data->texture);
slouken@1903
   788
    }
slouken@1895
   789
    SDL_free(data);
slouken@1895
   790
    texture->driverdata = NULL;
slouken@1895
   791
}
slouken@1895
   792
slouken@1975
   793
static void
slouken@1913
   794
D3D_DestroyRenderer(SDL_Renderer * renderer)
slouken@1895
   795
{
slouken@1913
   796
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
slouken@1895
   797
slouken@1895
   798
    if (data) {
slouken@1900
   799
        if (data->device) {
slouken@1900
   800
            IDirect3DDevice9_Release(data->device);
slouken@1900
   801
        }
slouken@1895
   802
        SDL_free(data);
slouken@1895
   803
    }
slouken@1895
   804
    SDL_free(renderer);
slouken@1895
   805
}
slouken@1895
   806
slouken@1895
   807
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@1895
   808
slouken@1895
   809
/* vi: set ts=4 sw=4 expandtab: */