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