src/render/direct3d/SDL_render_d3d.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 04 Jun 2014 10:57:40 -0700
changeset 8822 b554a3e19d6c
parent 8792 333216331863
child 8823 15a1b4b8e20a
permissions -rw-r--r--
Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8131
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7989
diff changeset
    21
#include "../../SDL_internal.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
8193
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    23
#include "SDL_render.h"
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    24
#include "SDL_system.h"
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    25
5226
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    26
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    27
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    28
#include "../../core/windows/SDL_windows.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    29
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
    30
#include "SDL_hints.h"
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    31
#include "SDL_loadso.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    32
#include "SDL_syswm.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    33
#include "../SDL_sysrender.h"
8599
532cd234e923 Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
Sam Lantinga <slouken@libsdl.org>
parents: 8590
diff changeset
    34
#include "../SDL_d3dmath.h"
7762
51abf7664304 Moved SDL_Direct3D9GetAdapterIndex() to SDL_windowsvideo.c since it doesn't belong in the window code.
Sam Lantinga <slouken@libsdl.org>
parents: 7761
diff changeset
    35
#include "../../video/windows/SDL_windowsvideo.h"
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    36
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    37
#if SDL_VIDEO_RENDER_D3D
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    38
#define D3D_DEBUG_INFO
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    39
#include <d3d9.h>
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    40
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    42
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    43
#ifdef ASSEMBLE_SHADER
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    44
/**************************************************************************
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    45
 * ID3DXBuffer:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    46
 * ------------
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    47
 * The buffer object is used by D3DX to return arbitrary size data.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    48
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    49
 * GetBufferPointer -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    50
 *    Returns a pointer to the beginning of the buffer.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    51
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    52
 * GetBufferSize -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    53
 *    Returns the size of the buffer, in bytes.
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    54
 **************************************************************************/
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    55
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    56
typedef interface ID3DXBuffer ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    57
typedef interface ID3DXBuffer *LPD3DXBUFFER;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    58
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    59
/* {8BA5FB08-5195-40e2-AC58-0D989C3A0102} */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    60
DEFINE_GUID(IID_ID3DXBuffer,
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    61
0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2);
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    62
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    63
#undef INTERFACE
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    64
#define INTERFACE ID3DXBuffer
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    65
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    66
typedef interface ID3DXBuffer {
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    67
    const struct ID3DXBufferVtbl FAR* lpVtbl;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    68
} ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    69
typedef const struct ID3DXBufferVtbl ID3DXBufferVtbl;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    70
const struct ID3DXBufferVtbl
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    71
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    72
    /* IUnknown */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    73
    STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    74
    STDMETHOD_(ULONG, AddRef)(THIS) PURE;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    75
    STDMETHOD_(ULONG, Release)(THIS) PURE;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    76
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    77
    /* ID3DXBuffer */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    78
    STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    79
    STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    80
};
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    81
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    82
HRESULT WINAPI
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    83
    D3DXAssembleShader(
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    84
        LPCSTR                          pSrcData,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    85
        UINT                            SrcDataLen,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    86
        CONST LPVOID*                   pDefines,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    87
        LPVOID                          pInclude,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    88
        DWORD                           Flags,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    89
        LPD3DXBUFFER*                   ppShader,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    90
        LPD3DXBUFFER*                   ppErrorMsgs);
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    91
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    92
static void PrintShaderData(LPDWORD shader_data, DWORD shader_size)
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    93
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    94
    OutputDebugStringA("const DWORD shader_data[] = {\n\t");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    95
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    96
        SDL_bool newline = SDL_FALSE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    97
        unsigned i;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    98
        for (i = 0; i < shader_size / sizeof(DWORD); ++i) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    99
            char dword[11];
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   100
            if (i > 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   101
                if ((i%6) == 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   102
                    newline = SDL_TRUE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   103
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   104
                if (newline) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   105
                    OutputDebugStringA(",\n    ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   106
                    newline = SDL_FALSE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   107
                } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   108
                    OutputDebugStringA(", ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   109
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   110
            }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   111
            SDL_snprintf(dword, sizeof(dword), "0x%8.8x", shader_data[i]);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   112
            OutputDebugStringA(dword);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   113
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   114
        OutputDebugStringA("\n};\n");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   115
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   116
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   117
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   118
#endif /* ASSEMBLE_SHADER */
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   119
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   120
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
/* Direct3D renderer implementation */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   123
static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   124
static void D3D_WindowEvent(SDL_Renderer * renderer,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   125
                            const SDL_WindowEvent *event);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   126
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   127
static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   128
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   129
                             const SDL_Rect * rect, const void *pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   130
                             int pitch);
7761
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   131
static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   132
                                const SDL_Rect * rect,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   133
                                const Uint8 *Yplane, int Ypitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   134
                                const Uint8 *Uplane, int Upitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   135
                                const Uint8 *Vplane, int Vpitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   136
static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   137
                           const SDL_Rect * rect, void **pixels, int *pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   138
static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
8228
010ae1267485 Fixed infinite recursion in D3D_Reset()
Sam Lantinga <slouken@libsdl.org>
parents: 8224
diff changeset
   139
static int D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture);
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   140
static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   141
static int D3D_UpdateViewport(SDL_Renderer * renderer);
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   142
static int D3D_UpdateClipRect(SDL_Renderer * renderer);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   143
static int D3D_RenderClear(SDL_Renderer * renderer);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   144
static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   145
                                const SDL_FPoint * points, int count);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   146
static int D3D_RenderDrawLines(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   147
                               const SDL_FPoint * points, int count);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   148
static int D3D_RenderFillRects(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   149
                               const SDL_FRect * rects, int count);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   150
static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   151
                          const SDL_Rect * srcrect, const SDL_FRect * dstrect);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   152
static int D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   153
                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   154
                          const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
   155
static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
3480
cd763d104465 The Direct3D Read/Write pixels interface is in progress.
Sam Lantinga <slouken@libsdl.org>
parents: 3427
diff changeset
   156
                                Uint32 format, void * pixels, int pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   157
static void D3D_RenderPresent(SDL_Renderer * renderer);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   158
static void D3D_DestroyTexture(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   159
                               SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   160
static void D3D_DestroyRenderer(SDL_Renderer * renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   163
SDL_RenderDriver D3D_RenderDriver = {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   164
    D3D_CreateRenderer,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    {
5186
97d0480b420c Updated the name of the Direct3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   166
     "direct3d",
6237
240f1bced46b Added a renderer flag to expose whether a renderer supports render to texture.
Sam Lantinga <slouken@libsdl.org>
parents: 6236
diff changeset
   167
     (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   168
     1,
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   169
     {SDL_PIXELFORMAT_ARGB8888},
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
     0,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
     0}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
};
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
{
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   176
    void* d3dDLL;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   177
    IDirect3D9 *d3d;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    IDirect3DDevice9 *device;
3527
444cb12cadb6 Fixed to use the correct display adapter
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   179
    UINT adapter;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   180
    D3DPRESENT_PARAMETERS pparams;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   181
    SDL_bool updateSize;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   182
    SDL_bool beginScene;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   183
    SDL_bool enableSeparateAlphaBlend;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   184
    D3DTEXTUREFILTERTYPE scaleMode[8];
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   185
    IDirect3DSurface9 *defaultRenderTarget;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   186
    IDirect3DSurface9 *currentRenderTarget;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   187
    void* d3dxDLL;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   188
    LPDIRECT3DPIXELSHADER9 ps_yuv;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   189
} D3D_RenderData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
{
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   193
    SDL_bool dirty;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   194
    IDirect3DTexture9 *texture;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   195
    IDirect3DTexture9 *staging;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   196
} D3D_TextureRep;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   197
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   198
typedef struct
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   199
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   200
    D3D_TextureRep texture;
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   201
    D3DTEXTUREFILTERTYPE scaleMode;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   202
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   203
    /* YV12 texture support */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   204
    SDL_bool yuv;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   205
    D3D_TextureRep utexture;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   206
    D3D_TextureRep vtexture;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   207
    Uint8 *pixels;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   208
    int pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   209
    SDL_Rect locked_rect;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   210
} D3D_TextureData;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   212
typedef struct
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   213
{
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   214
    float x, y, z;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
   215
    DWORD color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   216
    float u, v;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   217
} Vertex;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   218
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   219
static int
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   220
D3D_SetError(const char *prefix, HRESULT result)
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   221
{
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   222
    const char *error;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   223
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   224
    switch (result) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   225
    case D3DERR_WRONGTEXTUREFORMAT:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   226
        error = "WRONGTEXTUREFORMAT";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   227
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   228
    case D3DERR_UNSUPPORTEDCOLOROPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   229
        error = "UNSUPPORTEDCOLOROPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   230
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   231
    case D3DERR_UNSUPPORTEDCOLORARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   232
        error = "UNSUPPORTEDCOLORARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   233
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   234
    case D3DERR_UNSUPPORTEDALPHAOPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   235
        error = "UNSUPPORTEDALPHAOPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   236
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   237
    case D3DERR_UNSUPPORTEDALPHAARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   238
        error = "UNSUPPORTEDALPHAARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   239
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   240
    case D3DERR_TOOMANYOPERATIONS:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   241
        error = "TOOMANYOPERATIONS";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   242
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   243
    case D3DERR_CONFLICTINGTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   244
        error = "CONFLICTINGTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   245
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   246
    case D3DERR_UNSUPPORTEDFACTORVALUE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   247
        error = "UNSUPPORTEDFACTORVALUE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   248
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   249
    case D3DERR_CONFLICTINGRENDERSTATE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   250
        error = "CONFLICTINGRENDERSTATE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   251
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   252
    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   253
        error = "UNSUPPORTEDTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   254
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   255
    case D3DERR_CONFLICTINGTEXTUREPALETTE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   256
        error = "CONFLICTINGTEXTUREPALETTE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   257
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   258
    case D3DERR_DRIVERINTERNALERROR:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   259
        error = "DRIVERINTERNALERROR";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   260
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   261
    case D3DERR_NOTFOUND:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   262
        error = "NOTFOUND";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   263
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   264
    case D3DERR_MOREDATA:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   265
        error = "MOREDATA";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   266
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   267
    case D3DERR_DEVICELOST:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   268
        error = "DEVICELOST";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   269
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   270
    case D3DERR_DEVICENOTRESET:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   271
        error = "DEVICENOTRESET";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   272
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   273
    case D3DERR_NOTAVAILABLE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   274
        error = "NOTAVAILABLE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   275
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   276
    case D3DERR_OUTOFVIDEOMEMORY:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   277
        error = "OUTOFVIDEOMEMORY";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   278
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   279
    case D3DERR_INVALIDDEVICE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   280
        error = "INVALIDDEVICE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   281
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   282
    case D3DERR_INVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   283
        error = "INVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   284
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   285
    case D3DERR_DRIVERINVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   286
        error = "DRIVERINVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   287
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   288
    case D3DERR_WASSTILLDRAWING:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   289
        error = "WASSTILLDRAWING";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   290
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   291
    default:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   292
        error = "UNKNOWN";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   293
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   294
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   295
    return SDL_SetError("%s: %s", prefix, error);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   296
}
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   297
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   298
static D3DFORMAT
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   299
PixelFormatToD3DFMT(Uint32 format)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
{
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   301
    switch (format) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   302
    case SDL_PIXELFORMAT_RGB565:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   303
        return D3DFMT_R5G6B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   304
    case SDL_PIXELFORMAT_RGB888:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   305
        return D3DFMT_X8R8G8B8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   306
    case SDL_PIXELFORMAT_ARGB8888:
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   307
        return D3DFMT_A8R8G8B8;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   308
    case SDL_PIXELFORMAT_YV12:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   309
    case SDL_PIXELFORMAT_IYUV:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   310
        return D3DFMT_L8;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   311
    default:
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   312
        return D3DFMT_UNKNOWN;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   313
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   316
static Uint32
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   317
D3DFMTToPixelFormat(D3DFORMAT format)
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   318
{
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   319
    switch (format) {
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   320
    case D3DFMT_R5G6B5:
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   321
        return SDL_PIXELFORMAT_RGB565;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   322
    case D3DFMT_X8R8G8B8:
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   323
        return SDL_PIXELFORMAT_RGB888;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   324
    case D3DFMT_A8R8G8B8:
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   325
        return SDL_PIXELFORMAT_ARGB8888;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   326
    default:
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   327
        return SDL_PIXELFORMAT_UNKNOWN;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   328
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
7648
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   331
static void
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   332
D3D_InitRenderState(D3D_RenderData *data)
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   333
{
7651
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   334
    D3DMATRIX matrix;
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   335
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   336
    IDirect3DDevice9 *device = data->device;
7648
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   337
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   338
    IDirect3DDevice9_SetVertexShader(device, NULL);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   339
    IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   340
    IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   341
    IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   342
    IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   343
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   344
    /* Enable color modulation by diffuse color */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   345
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   346
                                          D3DTOP_MODULATE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   347
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   348
                                          D3DTA_TEXTURE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   349
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   350
                                          D3DTA_DIFFUSE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   351
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   352
    /* Enable alpha modulation by diffuse alpha */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   353
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   354
                                          D3DTOP_MODULATE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   355
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   356
                                          D3DTA_TEXTURE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   357
    IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG2,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   358
                                          D3DTA_DIFFUSE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   359
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   360
    /* Enable separate alpha blend function, if possible */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   361
    if (data->enableSeparateAlphaBlend) {
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   362
        IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   363
    }
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   364
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   365
    /* Disable second texture stage, since we're done */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   366
    IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   367
                                          D3DTOP_DISABLE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   368
    IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP,
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   369
                                          D3DTOP_DISABLE);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   370
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   371
    /* Set an identity world and view matrix */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   372
    matrix.m[0][0] = 1.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   373
    matrix.m[0][1] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   374
    matrix.m[0][2] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   375
    matrix.m[0][3] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   376
    matrix.m[1][0] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   377
    matrix.m[1][1] = 1.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   378
    matrix.m[1][2] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   379
    matrix.m[1][3] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   380
    matrix.m[2][0] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   381
    matrix.m[2][1] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   382
    matrix.m[2][2] = 1.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   383
    matrix.m[2][3] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   384
    matrix.m[3][0] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   385
    matrix.m[3][1] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   386
    matrix.m[3][2] = 0.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   387
    matrix.m[3][3] = 1.0f;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   388
    IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &matrix);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   389
    IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &matrix);
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   390
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   391
    /* Reset our current scale mode */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   392
    SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   393
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   394
    /* Start the render with beginScene */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   395
    data->beginScene = SDL_TRUE;
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   396
}
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   397
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   398
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   399
D3D_Reset(SDL_Renderer * renderer)
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   400
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   401
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   402
    HRESULT result;
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   403
    SDL_Texture *texture;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   404
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   405
    /* Release the default render target before reset */
6895
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   406
    if (data->defaultRenderTarget) {
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   407
        IDirect3DSurface9_Release(data->defaultRenderTarget);
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   408
        data->defaultRenderTarget = NULL;
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   409
    }
8224
32af2d3806d1 Fixed resetting the current render target if the D3D device is reset while using a non-default render target.
Sam Lantinga <slouken@libsdl.org>
parents: 8208
diff changeset
   410
    if (data->currentRenderTarget != NULL) {
32af2d3806d1 Fixed resetting the current render target if the D3D device is reset while using a non-default render target.
Sam Lantinga <slouken@libsdl.org>
parents: 8208
diff changeset
   411
        IDirect3DSurface9_Release(data->currentRenderTarget);
32af2d3806d1 Fixed resetting the current render target if the D3D device is reset while using a non-default render target.
Sam Lantinga <slouken@libsdl.org>
parents: 8208
diff changeset
   412
        data->currentRenderTarget = NULL;
32af2d3806d1 Fixed resetting the current render target if the D3D device is reset while using a non-default render target.
Sam Lantinga <slouken@libsdl.org>
parents: 8208
diff changeset
   413
    }
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   414
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   415
    /* Release application render targets */
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   416
    for (texture = renderer->textures; texture; texture = texture->next) {
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   417
        if (texture->access == SDL_TEXTUREACCESS_TARGET) {
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   418
            D3D_DestroyTexture(renderer, texture);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   419
        } else {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   420
            D3D_RecreateTexture(renderer, texture);
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   421
        }
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   422
    }
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   423
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   424
    result = IDirect3DDevice9_Reset(data->device, &data->pparams);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   425
    if (FAILED(result)) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   426
        if (result == D3DERR_DEVICELOST) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   427
            /* Don't worry about it, we'll reset later... */
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   428
            return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   429
        } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   430
            return D3D_SetError("Reset()", result);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   431
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   432
    }
7648
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   433
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   434
    /* Allocate application render targets */
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   435
    for (texture = renderer->textures; texture; texture = texture->next) {
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   436
        if (texture->access == SDL_TEXTUREACCESS_TARGET) {
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   437
            D3D_CreateTexture(renderer, texture);
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   438
        }
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   439
    }
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   440
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   441
    IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
7648
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   442
    D3D_InitRenderState(data);
8228
010ae1267485 Fixed infinite recursion in D3D_Reset()
Sam Lantinga <slouken@libsdl.org>
parents: 8224
diff changeset
   443
    D3D_SetRenderTargetInternal(renderer, renderer->target);
7586
6f1539dc6b57 Reset the viewport when we reset the other D3D state.
Sam Lantinga <slouken@libsdl.org>
parents: 7577
diff changeset
   444
    D3D_UpdateViewport(renderer);
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   445
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   446
    /* Let the application know that render targets were reset */
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   447
    {
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   448
        SDL_Event event;
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   449
        event.type = SDL_RENDER_TARGETS_RESET;
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   450
        SDL_PushEvent(&event);
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   451
    }
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   452
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   453
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   454
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   455
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   456
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   457
D3D_ActivateRenderer(SDL_Renderer * renderer)
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   458
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   459
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   460
    HRESULT result;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   461
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   462
    if (data->updateSize) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   463
        SDL_Window *window = renderer->window;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   464
        int w, h;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   465
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   466
        SDL_GetWindowSize(window, &w, &h);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   467
        data->pparams.BackBufferWidth = w;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   468
        data->pparams.BackBufferHeight = h;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   469
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   470
            data->pparams.BackBufferFormat =
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   471
                PixelFormatToD3DFMT(SDL_GetWindowPixelFormat(window));
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   472
        } else {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   473
            data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   474
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   475
        if (D3D_Reset(renderer) < 0) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   476
            return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   477
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   478
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   479
        data->updateSize = SDL_FALSE;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   480
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   481
    if (data->beginScene) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   482
        result = IDirect3DDevice9_BeginScene(data->device);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   483
        if (result == D3DERR_DEVICELOST) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   484
            if (D3D_Reset(renderer) < 0) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   485
                return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   486
            }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   487
            result = IDirect3DDevice9_BeginScene(data->device);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   488
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   489
        if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   490
            return D3D_SetError("BeginScene()", result);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   491
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   492
        data->beginScene = SDL_FALSE;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   493
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   494
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   495
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   496
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   497
SDL_Renderer *
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   498
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   499
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   500
    SDL_Renderer *renderer;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   501
    D3D_RenderData *data;
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   502
    SDL_SysWMinfo windowinfo;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   503
    HRESULT result;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   504
    const char *hint;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   505
    D3DPRESENT_PARAMETERS pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   506
    IDirect3DSwapChain9 *chain;
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   507
    D3DCAPS9 caps;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   508
    DWORD device_flags;
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   509
    Uint32 window_flags;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   510
    int w, h;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   511
    SDL_DisplayMode fullscreen_mode;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   512
    int displayIndex;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   513
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
   514
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   515
    if (!renderer) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   516
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   517
        return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   518
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   519
1920
8a162bfdc838 Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations.
Sam Lantinga <slouken@libsdl.org>
parents: 1918
diff changeset
   520
    data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   521
    if (!data) {
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   522
        SDL_free(renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   523
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   524
        return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   525
    }
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   526
8599
532cd234e923 Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
Sam Lantinga <slouken@libsdl.org>
parents: 8590
diff changeset
   527
    if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   528
        SDL_free(renderer);
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   529
        SDL_free(data);
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   530
        SDL_SetError("Unable to create Direct3D interface");
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   531
        return NULL;
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   532
    }
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   533
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   534
    renderer->WindowEvent = D3D_WindowEvent;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   535
    renderer->CreateTexture = D3D_CreateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   536
    renderer->UpdateTexture = D3D_UpdateTexture;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   537
    renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   538
    renderer->LockTexture = D3D_LockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   539
    renderer->UnlockTexture = D3D_UnlockTexture;
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   540
    renderer->SetRenderTarget = D3D_SetRenderTarget;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   541
    renderer->UpdateViewport = D3D_UpdateViewport;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   542
    renderer->UpdateClipRect = D3D_UpdateClipRect;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
    renderer->RenderClear = D3D_RenderClear;
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   544
    renderer->RenderDrawPoints = D3D_RenderDrawPoints;
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   545
    renderer->RenderDrawLines = D3D_RenderDrawLines;
3675
e86edac50872 Fixed bug #932
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
   546
    renderer->RenderFillRects = D3D_RenderFillRects;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   547
    renderer->RenderCopy = D3D_RenderCopy;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   548
    renderer->RenderCopyEx = D3D_RenderCopyEx;
3427
36cf454ba065 Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
Sam Lantinga <slouken@libsdl.org>
parents: 3279
diff changeset
   549
    renderer->RenderReadPixels = D3D_RenderReadPixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   550
    renderer->RenderPresent = D3D_RenderPresent;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   551
    renderer->DestroyTexture = D3D_DestroyTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   552
    renderer->DestroyRenderer = D3D_DestroyRenderer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   553
    renderer->info = D3D_RenderDriver.info;
8590
6e6bd53feff0 Fixed renderer flags to include support for target textures after the renderer is created.
Sam Lantinga <slouken@libsdl.org>
parents: 8255
diff changeset
   554
    renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   555
    renderer->driverdata = data;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   556
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   557
    SDL_VERSION(&windowinfo.version);
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   558
    SDL_GetWindowWMInfo(window, &windowinfo);
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   559
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   560
    window_flags = SDL_GetWindowFlags(window);
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   561
    SDL_GetWindowSize(window, &w, &h);
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   562
    SDL_GetWindowDisplayMode(window, &fullscreen_mode);
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   563
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   564
    SDL_zero(pparams);
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   565
    pparams.hDeviceWindow = windowinfo.info.win.window;
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   566
    pparams.BackBufferWidth = w;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   567
    pparams.BackBufferHeight = h;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   568
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   569
        pparams.BackBufferFormat =
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   570
            PixelFormatToD3DFMT(fullscreen_mode.format);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   571
    } else {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   572
        pparams.BackBufferFormat = D3DFMT_UNKNOWN;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   573
    }
5142
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
   574
    pparams.BackBufferCount = 1;
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
   575
    pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
c8e049de174c Making the API simpler, the renderer present semantics are always having a backbuffer and then discarding it. This is best for hardware accelerated rendering.
Sam Lantinga <slouken@libsdl.org>
parents: 5141
diff changeset
   576
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   577
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   578
        if ((window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)  {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   579
            pparams.Windowed = TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   580
            pparams.FullScreen_RefreshRateInHz = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   581
        } else {
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   582
            pparams.Windowed = FALSE;
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   583
            pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   584
        }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   585
    } else {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   586
        pparams.Windowed = TRUE;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   587
        pparams.FullScreen_RefreshRateInHz = 0;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   588
    }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   589
    if (flags & SDL_RENDERER_PRESENTVSYNC) {
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   590
        pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   591
    } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   592
        pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   593
    }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   594
7742
84e32c3d415c Added SDL_Direct3D9GetAdapterIndex(), which returns the adapter index you would pass into CreateDevice to get your device on the right monitor in full screen mode. This fixes the default adapter in SDL_render_d3d.c, which means that tests will work fullscreen off the main monitor now.
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   595
    /* Get the adapter for the display that the window is on */
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   596
    displayIndex = SDL_GetWindowDisplayIndex(window);
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   597
    data->adapter = SDL_Direct3D9GetAdapterIndex(displayIndex);
7742
84e32c3d415c Added SDL_Direct3D9GetAdapterIndex(), which returns the adapter index you would pass into CreateDevice to get your device on the right monitor in full screen mode. This fixes the default adapter in SDL_render_d3d.c, which means that tests will work fullscreen off the main monitor now.
Sam Lantinga <slouken@libsdl.org>
parents: 7719
diff changeset
   598
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   599
    IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
3197
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   600
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   601
    device_flags = D3DCREATE_FPU_PRESERVE;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   602
    if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   603
        device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   604
    } else {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   605
        device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   606
    }
7764
0f48b5f28668 Added a hint to create the D3D device in thread-safe mode: SDL_HINT_RENDER_DIRECT3D_THREADSAFE
Sam Lantinga <slouken@libsdl.org>
parents: 7763
diff changeset
   607
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   608
    hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE);
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   609
    if (hint && SDL_atoi(hint)) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   610
        device_flags |= D3DCREATE_MULTITHREADED;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   611
    }
7764
0f48b5f28668 Added a hint to create the D3D device in thread-safe mode: SDL_HINT_RENDER_DIRECT3D_THREADSAFE
Sam Lantinga <slouken@libsdl.org>
parents: 7763
diff changeset
   612
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   613
    result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   614
                                     D3DDEVTYPE_HAL,
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
   615
                                     pparams.hDeviceWindow,
7764
0f48b5f28668 Added a hint to create the D3D device in thread-safe mode: SDL_HINT_RENDER_DIRECT3D_THREADSAFE
Sam Lantinga <slouken@libsdl.org>
parents: 7763
diff changeset
   616
                                     device_flags,
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   617
                                     &pparams, &data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   618
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   619
        D3D_DestroyRenderer(renderer);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   620
        D3D_SetError("CreateDevice()", result);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   621
        return NULL;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   622
    }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   623
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   624
    /* Get presentation parameters to fill info */
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   625
    result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   626
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   627
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   628
        D3D_SetError("GetSwapChain()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   629
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   630
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   631
    result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   632
    if (FAILED(result)) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   633
        IDirect3DSwapChain9_Release(chain);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   634
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   635
        D3D_SetError("GetPresentParameters()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   636
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   637
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   638
    IDirect3DSwapChain9_Release(chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   639
    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   640
        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   641
    }
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   642
    data->pparams = pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   643
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   644
    IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   645
    renderer->info.max_texture_width = caps.MaxTextureWidth;
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   646
    renderer->info.max_texture_height = caps.MaxTextureHeight;
6246
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6242
diff changeset
   647
    if (caps.NumSimultaneousRTs >= 2) {
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6242
diff changeset
   648
        renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
c70ec935a4bb Reorganized the render target code, moving the viewport handling to the general code and adding software implementation.
Sam Lantinga <slouken@libsdl.org>
parents: 6242
diff changeset
   649
    }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1917
diff changeset
   650
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   651
    if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   652
        data->enableSeparateAlphaBlend = SDL_TRUE;
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   653
    }
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   654
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   655
    /* Store the default render target */
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   656
    IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   657
    data->currentRenderTarget = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   658
7648
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   659
    /* Set up parameters for rendering */
297c43ff3d7e Do full state initialization in D3D_Reset(), this fixes blend mode issues when resizing the window on Windows 8.
Sam Lantinga <slouken@libsdl.org>
parents: 7586
diff changeset
   660
    D3D_InitRenderState(data);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   661
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   662
    if (caps.MaxSimultaneousTextures >= 3)
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   663
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   664
#ifdef ASSEMBLE_SHADER
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   665
        /* This shader was created by running the following HLSL through the fxc compiler
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   666
           and then tuning the generated assembly.
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   667
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   668
           fxc /T fx_4_0 /O3 /Gfa /Fc yuv.fxc yuv.fx
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   669
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   670
           --- yuv.fx ---
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   671
           Texture2D g_txY;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   672
           Texture2D g_txU;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   673
           Texture2D g_txV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   674
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   675
           SamplerState samLinear
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   676
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   677
               Filter = ANISOTROPIC;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   678
               AddressU = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   679
               AddressV = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   680
               MaxAnisotropy = 1;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   681
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   682
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   683
           struct VS_OUTPUT
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   684
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   685
                float2 TextureUV  : TEXCOORD0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   686
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   687
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   688
           struct PS_OUTPUT
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   689
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   690
                float4 RGBAColor : SV_Target;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   691
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   692
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   693
           PS_OUTPUT YUV420( VS_OUTPUT In ) 
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   694
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   695
               const float3 offset = {-0.0625, -0.5, -0.5};
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   696
               const float3 Rcoeff = {1.164,  0.000,  1.596};
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   697
               const float3 Gcoeff = {1.164, -0.391, -0.813};
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   698
               const float3 Bcoeff = {1.164,  2.018,  0.000};
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   699
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   700
               PS_OUTPUT Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   701
               float2 TextureUV = In.TextureUV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   702
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   703
               float3 yuv;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   704
               yuv.x = g_txY.Sample( samLinear, TextureUV ).r;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   705
               yuv.y = g_txU.Sample( samLinear, TextureUV ).r;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   706
               yuv.z = g_txV.Sample( samLinear, TextureUV ).r;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   707
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   708
               yuv += offset;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   709
               Output.RGBAColor.r = dot(yuv, Rcoeff);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   710
               Output.RGBAColor.g = dot(yuv, Gcoeff);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   711
               Output.RGBAColor.b = dot(yuv, Bcoeff);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   712
               Output.RGBAColor.a = 1.0f;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   713
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   714
               return Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   715
           }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   716
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   717
           technique10 RenderYUV420
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   718
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   719
               pass P0
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   720
               {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   721
                    SetPixelShader( CompileShader( ps_4_0_level_9_0, YUV420() ) );
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   722
               }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   723
           }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   724
        */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   725
        const char *shader_text =
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   726
            "ps_2_0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   727
            "def c0, -0.0625, -0.5, -0.5, 1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   728
            "def c1, 1.16400003, 0, 1.59599996, 0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   729
            "def c2, 1.16400003, -0.391000003, -0.813000023, 0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   730
            "def c3, 1.16400003, 2.01799989, 0, 0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   731
            "dcl t0.xy\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   732
            "dcl v0.xyzw\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   733
            "dcl_2d s0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   734
            "dcl_2d s1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   735
            "dcl_2d s2\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   736
            "texld r0, t0, s0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   737
            "texld r1, t0, s1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   738
            "texld r2, t0, s2\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   739
            "mov r0.y, r1.x\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   740
            "mov r0.z, r2.x\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   741
            "add r0.xyz, r0, c0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   742
            "dp3 r1.x, r0, c1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   743
            "dp3 r1.y, r0, c2\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   744
            "dp2add r1.z, r0, c3, c3.z\n"   /* Logically this is "dp3 r1.z, r0, c3" but the optimizer did its magic */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   745
            "mov r1.w, c0.w\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   746
            "mul r0, r1, v0\n"              /* Not in the HLSL, multiply by vertex color */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   747
            "mov oC0, r0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   748
        ;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   749
        LPD3DXBUFFER pCode;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   750
        LPD3DXBUFFER pErrorMsgs;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   751
        LPDWORD shader_data = NULL;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   752
        DWORD   shader_size = 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   753
        result = D3DXAssembleShader(shader_text, SDL_strlen(shader_text), NULL, NULL, 0, &pCode, &pErrorMsgs);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   754
        if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   755
            shader_data = (DWORD*)pCode->lpVtbl->GetBufferPointer(pCode);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   756
            shader_size = pCode->lpVtbl->GetBufferSize(pCode);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   757
            PrintShaderData(shader_data, shader_size);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   758
        } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   759
            const char *error = (const char *)pErrorMsgs->lpVtbl->GetBufferPointer(pErrorMsgs);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   760
            SDL_SetError("Couldn't assemble shader: %s", error);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   761
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   762
#else
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   763
        const DWORD shader_data[] = {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   764
            0xffff0200, 0x05000051, 0xa00f0000, 0xbd800000, 0xbf000000, 0xbf000000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   765
            0x3f800000, 0x05000051, 0xa00f0001, 0x3f94fdf4, 0x00000000, 0x3fcc49ba,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   766
            0x00000000, 0x05000051, 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   767
            0x00000000, 0x05000051, 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   768
            0x00000000, 0x0200001f, 0x80000000, 0xb0030000, 0x0200001f, 0x80000000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   769
            0x900f0000, 0x0200001f, 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   770
            0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   771
            0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   772
            0x03000042, 0x800f0002, 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   773
            0x80000001, 0x02000001, 0x80040000, 0x80000002, 0x03000002, 0x80070000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   774
            0x80e40000, 0xa0e40000, 0x03000008, 0x80010001, 0x80e40000, 0xa0e40001,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   775
            0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   776
            0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   777
            0x03000005, 0x800f0000, 0x80e40001, 0x90e40000, 0x02000001, 0x800f0800,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   778
            0x80e40000, 0x0000ffff
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   779
        };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   780
#endif
7547
abdea1385dbb Fixed compiler warning with gcc
Sam Lantinga <slouken@libsdl.org>
parents: 7505
diff changeset
   781
        if (shader_data != NULL) {
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   782
            result = IDirect3DDevice9_CreatePixelShader(data->device, shader_data, &data->ps_yuv);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   783
            if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   784
                renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   785
                renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   786
            } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   787
                D3D_SetError("CreatePixelShader()", result);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   788
            }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   789
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   790
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   791
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   792
    return renderer;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   793
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   794
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   795
static void
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   796
D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   797
{
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   798
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   799
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   800
    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   801
        data->updateSize = SDL_TRUE;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   802
    }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   803
}
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   804
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   805
static D3DTEXTUREFILTERTYPE
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   806
GetScaleQuality(void)
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   807
{
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   808
    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   809
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   810
    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   811
        return D3DTEXF_POINT;
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   812
    } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   813
        return D3DTEXF_LINEAR;
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   814
    }
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   815
}
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   816
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   817
static int
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   818
D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, int w, int h)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   819
{
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   820
    HRESULT result;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   821
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   822
    texture->dirty = SDL_FALSE;
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   823
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   824
    result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   825
        PixelFormatToD3DFMT(format),
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   826
        D3DPOOL_DEFAULT, &texture->texture, NULL);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   827
    if (FAILED(result)) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   828
        return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
5173
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   829
    }
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   830
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   831
    if (usage != D3DUSAGE_RENDERTARGET) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   832
        result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   833
            PixelFormatToD3DFMT(format),
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   834
            D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   835
        if (FAILED(result)) {
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   836
            return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result);
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   837
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   838
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   839
    return 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   840
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   841
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   842
static int
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   843
D3D_BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   844
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   845
    HRESULT result;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   846
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   847
    if (texture->dirty && texture->staging) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   848
        if (!texture->texture) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   849
            D3DSURFACE_DESC desc;
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   850
            result = IDirect3DTexture9_GetLevelDesc(texture->staging, 0, &desc);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   851
            if (FAILED(result)) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   852
                return D3D_SetError("GetLevelDesc", result);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   853
            }
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   854
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   855
            result = IDirect3DDevice9_CreateTexture(device, desc.Width, desc.Height, 1, 0,
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   856
                desc.Format, D3DPOOL_DEFAULT, &texture->texture, NULL);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   857
            if (FAILED(result)) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   858
                return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   859
            }
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   860
        }
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   861
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   862
        result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   863
        if (FAILED(result)) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   864
            return D3D_SetError("UpdateTexture()", result);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   865
        }
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   866
        texture->dirty = SDL_FALSE;
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   867
    }
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   868
    result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   869
    if (FAILED(result)) {
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   870
        return D3D_SetError("SetTexture()", result);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   871
    }
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   872
    return 0;
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   873
}
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   874
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   875
static int
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   876
D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int w, int h)
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   877
{
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   878
    if (texture->texture) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   879
        IDirect3DTexture9_Release(texture->texture);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   880
        texture->texture = NULL;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   881
    }
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   882
    IDirect3DTexture9_AddDirtyRect(texture->staging, NULL);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   883
    texture->dirty = SDL_TRUE;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   884
    return 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   885
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   886
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   887
static int
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   888
D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch)
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   889
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   890
    RECT d3drect;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   891
    D3DLOCKED_RECT locked;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   892
    const Uint8 *src;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   893
    Uint8 *dst;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   894
    int row, length;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   895
    HRESULT result;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   896
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   897
    d3drect.left = x;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   898
    d3drect.right = x + w;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   899
    d3drect.top = y;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   900
    d3drect.bottom = y + h;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   901
    result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   902
    if (FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   903
        return D3D_SetError("LockRect()", result);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   904
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   905
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   906
    src = (const Uint8 *)pixels;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   907
    dst = locked.pBits;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   908
    length = w * SDL_BYTESPERPIXEL(format);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   909
    if (length == pitch && length == locked.Pitch) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   910
        SDL_memcpy(dst, src, length*h);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   911
    } else {
8255
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   912
        if (length > pitch) {
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   913
            length = pitch;
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   914
        }
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   915
        if (length > locked.Pitch) {
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   916
            length = locked.Pitch;
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   917
        }
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   918
        for (row = 0; row < h; ++row) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   919
            SDL_memcpy(dst, src, length);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   920
            src += pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   921
            dst += locked.Pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   922
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   923
    }
8822
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   924
    result = IDirect3DTexture9_UnlockRect(texture->staging, 0);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   925
    if (FAILED(result)) {
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   926
        return D3D_SetError("UnlockRect()", result);
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   927
    }
b554a3e19d6c Fixed crash and lost pixel data when recovering from a lost device situation (e.g. alt-tab from fullscreen)
Sam Lantinga <slouken@libsdl.org>
parents: 8792
diff changeset
   928
    texture->dirty = SDL_TRUE;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   929
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   930
    return 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   931
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   932
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   933
static void
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   934
D3D_DestroyTextureRep(D3D_TextureRep *texture)
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   935
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   936
    if (texture->texture) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   937
        IDirect3DTexture9_Release(texture->texture);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   938
        texture->texture = NULL;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   939
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   940
    if (texture->staging) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   941
        IDirect3DTexture9_Release(texture->staging);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   942
        texture->staging = NULL;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   943
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   944
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   945
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   946
static int
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   947
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   948
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   949
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   950
    D3D_TextureData *texturedata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   951
    DWORD usage;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   952
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   953
    texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   954
    if (!texturedata) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   955
        return SDL_OutOfMemory();
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   956
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   957
    texturedata->scaleMode = GetScaleQuality();
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   958
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   959
    texture->driverdata = texturedata;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   960
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   961
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   962
        usage = D3DUSAGE_RENDERTARGET;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   963
    } else {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   964
        usage = 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   965
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   966
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   967
    if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, texture->w, texture->h) < 0) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   968
        return -1;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   969
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   970
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   971
    if (texture->format == SDL_PIXELFORMAT_YV12 ||
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   972
        texture->format == SDL_PIXELFORMAT_IYUV) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   973
        texturedata->yuv = SDL_TRUE;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   974
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   975
        if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   976
            return -1;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   977
        }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   978
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   979
        if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   980
            return -1;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   981
        }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   982
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   983
    return 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   984
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   985
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   986
static int
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   987
D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   988
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   989
    D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   990
    D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   991
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   992
    if (D3D_RecreateTextureRep(data->device, &texturedata->texture, texture->format, texture->w, texture->h) < 0) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   993
        return -1;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   994
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   995
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset