src/render/direct3d/SDL_render_d3d.c
author David Ludwig <dludwig@pobox.com>
Fri, 24 Jun 2016 22:17:56 -0400
changeset 10183 17e0ded12e6f
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
Fixed Bug 3147 - Windows: Crash when resizing Window since hg 333216331863 Thanks for the fix, Gab!
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
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9702
diff changeset
     3
  Copyright (C) 1997-2016 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
8969
7fb90df60b99 The YUV offset is 16 / 255, not 16 / 256
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8823
diff changeset
    44
#pragma comment(lib, "d3dx9.lib")
7fb90df60b99 The YUV offset is 16 / 255, not 16 / 256
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8823
diff changeset
    45
7191
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
 * ID3DXBuffer:
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
 * 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
    50
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    51
 * GetBufferPointer -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    52
 *    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
    53
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    54
 * GetBufferSize -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    55
 *    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
    56
 **************************************************************************/
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    57
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    58
typedef interface ID3DXBuffer ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    59
typedef interface ID3DXBuffer *LPD3DXBUFFER;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    60
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    61
/* {8BA5FB08-5195-40e2-AC58-0D989C3A0102} */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    62
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
    63
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
    64
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    65
#undef INTERFACE
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    66
#define INTERFACE ID3DXBuffer
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    67
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    68
typedef interface ID3DXBuffer {
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    69
    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
    70
} ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    71
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
    72
const struct ID3DXBufferVtbl
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    73
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    74
    /* IUnknown */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    75
    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
    76
    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
    77
    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
    78
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
    79
    /* ID3DXBuffer */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    80
    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
    81
    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
    82
};
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    83
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    84
HRESULT WINAPI
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    85
    D3DXAssembleShader(
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    86
        LPCSTR                          pSrcData,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    87
        UINT                            SrcDataLen,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    88
        CONST LPVOID*                   pDefines,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    89
        LPVOID                          pInclude,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    90
        DWORD                           Flags,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    91
        LPD3DXBUFFER*                   ppShader,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    92
        LPD3DXBUFFER*                   ppErrorMsgs);
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
    93
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    94
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
    95
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    96
    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
    97
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
    98
        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
    99
        unsigned i;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   100
        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
   101
            char dword[11];
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   102
            if (i > 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   103
                if ((i%6) == 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   104
                    newline = SDL_TRUE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   105
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   106
                if (newline) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   107
                    OutputDebugStringA(",\n    ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   108
                    newline = SDL_FALSE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   109
                } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   110
                    OutputDebugStringA(", ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   111
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   112
            }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   113
            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
   114
            OutputDebugStringA(dword);
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
        OutputDebugStringA("\n};\n");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   117
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   118
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   119
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   120
#endif /* ASSEMBLE_SHADER */
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   121
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   122
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
   123
/* 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
   124
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   125
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
   126
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
   127
                            const SDL_WindowEvent *event);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   128
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
   129
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
   130
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   131
                             const SDL_Rect * rect, const void *pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   132
                             int pitch);
7761
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   133
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
   134
                                const SDL_Rect * rect,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   135
                                const Uint8 *Yplane, int Ypitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   136
                                const Uint8 *Uplane, int Upitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   137
                                const Uint8 *Vplane, int Vpitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   138
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
   139
                           const SDL_Rect * rect, void **pixels, int *pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   140
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
   141
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
   142
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
   143
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
   144
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
   145
static int D3D_RenderClear(SDL_Renderer * renderer);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   146
static int D3D_RenderDrawPoints(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_RenderDrawLines(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   149
                               const SDL_FPoint * points, int count);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   150
static int D3D_RenderFillRects(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   151
                               const SDL_FRect * rects, int count);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   152
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
   153
                          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
   154
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
   155
                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   156
                          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
   157
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
   158
                                Uint32 format, void * pixels, int pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   159
static void D3D_RenderPresent(SDL_Renderer * renderer);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   160
static void D3D_DestroyTexture(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   161
                               SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   162
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
   163
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
   164
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   165
SDL_RenderDriver D3D_RenderDriver = {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   166
    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
   167
    {
5186
97d0480b420c Updated the name of the Direct3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   168
     "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
   169
     (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
   170
     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
   171
     {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
   172
     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
   173
     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
   174
};
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
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
   176
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
   177
{
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
   178
    void* d3dDLL;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   179
    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
   180
    IDirect3DDevice9 *device;
3527
444cb12cadb6 Fixed to use the correct display adapter
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   181
    UINT adapter;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   182
    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
   183
    SDL_bool updateSize;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   184
    SDL_bool beginScene;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   185
    SDL_bool enableSeparateAlphaBlend;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   186
    D3DTEXTUREFILTERTYPE scaleMode[8];
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   187
    IDirect3DSurface9 *defaultRenderTarget;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   188
    IDirect3DSurface9 *currentRenderTarget;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   189
    void* d3dxDLL;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   190
    LPDIRECT3DPIXELSHADER9 ps_yuv;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   191
} 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
   192
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
   193
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
   194
{
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
   195
    SDL_bool dirty;
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   196
    int w, h;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   197
    DWORD usage;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   198
    Uint32 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
   199
    IDirect3DTexture9 *texture;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   200
    IDirect3DTexture9 *staging;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   201
} D3D_TextureRep;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   202
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   203
typedef struct
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   204
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   205
    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
   206
    D3DTEXTUREFILTERTYPE scaleMode;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   207
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   208
    /* YV12 texture support */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   209
    SDL_bool yuv;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   210
    D3D_TextureRep utexture;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   211
    D3D_TextureRep vtexture;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   212
    Uint8 *pixels;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   213
    int pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   214
    SDL_Rect locked_rect;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   215
} 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
   216
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
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
   218
{
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
   219
    float x, y, z;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
   220
    DWORD color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   221
    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
   222
} 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
   223
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   224
static int
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   225
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
   226
{
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   227
    const char *error;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   228
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   229
    switch (result) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   230
    case D3DERR_WRONGTEXTUREFORMAT:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   231
        error = "WRONGTEXTUREFORMAT";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   232
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   233
    case D3DERR_UNSUPPORTEDCOLOROPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   234
        error = "UNSUPPORTEDCOLOROPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   235
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   236
    case D3DERR_UNSUPPORTEDCOLORARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   237
        error = "UNSUPPORTEDCOLORARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   238
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   239
    case D3DERR_UNSUPPORTEDALPHAOPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   240
        error = "UNSUPPORTEDALPHAOPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   241
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   242
    case D3DERR_UNSUPPORTEDALPHAARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   243
        error = "UNSUPPORTEDALPHAARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   244
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   245
    case D3DERR_TOOMANYOPERATIONS:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   246
        error = "TOOMANYOPERATIONS";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   247
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   248
    case D3DERR_CONFLICTINGTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   249
        error = "CONFLICTINGTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   250
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   251
    case D3DERR_UNSUPPORTEDFACTORVALUE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   252
        error = "UNSUPPORTEDFACTORVALUE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   253
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   254
    case D3DERR_CONFLICTINGRENDERSTATE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   255
        error = "CONFLICTINGRENDERSTATE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   256
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   257
    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   258
        error = "UNSUPPORTEDTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   259
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   260
    case D3DERR_CONFLICTINGTEXTUREPALETTE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   261
        error = "CONFLICTINGTEXTUREPALETTE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   262
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   263
    case D3DERR_DRIVERINTERNALERROR:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   264
        error = "DRIVERINTERNALERROR";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   265
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   266
    case D3DERR_NOTFOUND:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   267
        error = "NOTFOUND";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   268
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   269
    case D3DERR_MOREDATA:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   270
        error = "MOREDATA";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   271
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   272
    case D3DERR_DEVICELOST:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   273
        error = "DEVICELOST";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   274
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   275
    case D3DERR_DEVICENOTRESET:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   276
        error = "DEVICENOTRESET";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   277
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   278
    case D3DERR_NOTAVAILABLE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   279
        error = "NOTAVAILABLE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   280
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   281
    case D3DERR_OUTOFVIDEOMEMORY:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   282
        error = "OUTOFVIDEOMEMORY";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   283
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   284
    case D3DERR_INVALIDDEVICE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   285
        error = "INVALIDDEVICE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   286
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   287
    case D3DERR_INVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   288
        error = "INVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   289
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   290
    case D3DERR_DRIVERINVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   291
        error = "DRIVERINVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   292
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   293
    case D3DERR_WASSTILLDRAWING:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   294
        error = "WASSTILLDRAWING";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   295
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   296
    default:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   297
        error = "UNKNOWN";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   298
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   299
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   300
    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
   301
}
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   302
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
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
   304
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
   305
{
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
   306
    switch (format) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   307
    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
   308
        return D3DFMT_R5G6B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   309
    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
   310
        return D3DFMT_X8R8G8B8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   311
    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
   312
        return D3DFMT_A8R8G8B8;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   313
    case SDL_PIXELFORMAT_YV12:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   314
    case SDL_PIXELFORMAT_IYUV:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   315
        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
   316
    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
   317
        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
   318
    }
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
   319
}
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
   320
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
   321
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
   322
D3DFMTToPixelFormat(D3DFORMAT format)
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   323
{
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
   324
    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
   325
    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
   326
        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
   327
    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
   328
        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
   329
    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
   330
        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
   331
    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
   332
        return SDL_PIXELFORMAT_UNKNOWN;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   333
    }
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
   334
}
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
   335
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
   336
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
   337
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
   338
{
7651
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   339
    D3DMATRIX matrix;
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   340
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   341
    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
   342
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
    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
   344
    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
   345
    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
   346
    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
   347
    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
   348
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
    /* 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
   350
    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
   351
                                          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
   352
    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
   353
                                          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
   354
    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
   355
                                          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
   356
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
    /* 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
   358
    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
   359
                                          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
   360
    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
   361
                                          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
   362
    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
   363
                                          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
   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
    /* 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
   366
    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
   367
        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
   368
    }
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
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
    /* 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
   371
    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
   372
                                          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
   373
    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
   374
                                          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
   375
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
    /* 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
   377
    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
   378
    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
   379
    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
   380
    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
   381
    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
   382
    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
   383
    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
   384
    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
   385
    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
   386
    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
   387
    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
   388
    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
   389
    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
   390
    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
   391
    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
   392
    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
   393
    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
   394
    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
   395
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
    /* 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
   397
    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
   398
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
   399
    /* 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
   400
    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
   401
}
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
   402
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   403
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   404
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
   405
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   406
    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
   407
    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
   408
    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
   409
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   410
    /* 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
   411
    if (data->defaultRenderTarget) {
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   412
        IDirect3DSurface9_Release(data->defaultRenderTarget);
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   413
        data->defaultRenderTarget = NULL;
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   414
    }
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
   415
    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
   416
        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
   417
        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
   418
    }
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   419
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
   420
    /* 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
   421
    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
   422
        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
   423
            D3D_DestroyTexture(renderer, texture);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   424
        } else {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   425
            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
   426
        }
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
   427
    }
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
   428
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   429
    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
   430
    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
   431
        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
   432
            /* 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
   433
            return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   434
        } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   435
            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
   436
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   437
    }
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
   438
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
   439
    /* 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
   440
    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
   441
        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
   442
            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
   443
        }
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
   444
    }
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
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   446
    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
   447
    D3D_InitRenderState(data);
8228
010ae1267485 Fixed infinite recursion in D3D_Reset()
Sam Lantinga <slouken@libsdl.org>
parents: 8224
diff changeset
   448
    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
   449
    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
   450
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
    /* 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
   452
    {
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
   453
        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
   454
        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
   455
        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
   456
    }
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
   457
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   458
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   459
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   460
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   461
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   462
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
   463
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   464
    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
   465
    HRESULT result;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   466
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   467
    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
   468
        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
   469
        int w, h;
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   470
        Uint32 window_flags = SDL_GetWindowFlags(window);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   471
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   472
        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
   473
        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
   474
        data->pparams.BackBufferHeight = h;
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   475
        if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   476
            SDL_DisplayMode fullscreen_mode;
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   477
            SDL_GetWindowDisplayMode(window, &fullscreen_mode);
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   478
            data->pparams.Windowed = FALSE;
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   479
            data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   480
            data->pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   481
        } else {
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   482
            data->pparams.Windowed = TRUE;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   483
            data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   484
            data->pparams.FullScreen_RefreshRateInHz = 0;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   485
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   486
        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
   487
            return -1;
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
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   490
        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
   491
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   492
    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
   493
        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
   494
        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
   495
            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
   496
                return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   497
            }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   498
            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
   499
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   500
        if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   501
            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
   502
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   503
        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
   504
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   505
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   506
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   507
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
   508
SDL_Renderer *
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   509
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
   510
{
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
   511
    SDL_Renderer *renderer;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   512
    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
   513
    SDL_SysWMinfo windowinfo;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   514
    HRESULT result;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   515
    const char *hint;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   516
    D3DPRESENT_PARAMETERS pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   517
    IDirect3DSwapChain9 *chain;
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   518
    D3DCAPS9 caps;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   519
    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
   520
    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
   521
    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
   522
    SDL_DisplayMode fullscreen_mode;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   523
    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
   524
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
   525
    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
   526
    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
   527
        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
   528
        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
   529
    }
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
   530
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
   531
    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
   532
    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
   533
        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
   534
        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
   535
        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
   536
    }
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
   537
8599
532cd234e923 Fixed D3D9 initialization on Windows 8, which doesn't have D3DX
Sam Lantinga <slouken@libsdl.org>
parents: 8590
diff changeset
   538
    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
   539
        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
   540
        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
   541
        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
   542
        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
   543
    }
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   544
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   545
    renderer->WindowEvent = D3D_WindowEvent;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   546
    renderer->CreateTexture = D3D_CreateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   547
    renderer->UpdateTexture = D3D_UpdateTexture;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   548
    renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   549
    renderer->LockTexture = D3D_LockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   550
    renderer->UnlockTexture = D3D_UnlockTexture;
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   551
    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
   552
    renderer->UpdateViewport = D3D_UpdateViewport;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   553
    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
   554
    renderer->RenderClear = D3D_RenderClear;
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   555
    renderer->RenderDrawPoints = D3D_RenderDrawPoints;
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   556
    renderer->RenderDrawLines = D3D_RenderDrawLines;
3675
e86edac50872 Fixed bug #932
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
   557
    renderer->RenderFillRects = D3D_RenderFillRects;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   558
    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
   559
    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
   560
    renderer->RenderReadPixels = D3D_RenderReadPixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   561
    renderer->RenderPresent = D3D_RenderPresent;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   562
    renderer->DestroyTexture = D3D_DestroyTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   563
    renderer->DestroyRenderer = D3D_DestroyRenderer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   564
    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
   565
    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
   566
    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
   567
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
   568
    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
   569
    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
   570
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
   571
    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
   572
    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
   573
    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
   574
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   575
    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
   576
    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
   577
    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
   578
    pparams.BackBufferHeight = h;
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
   579
    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
   580
    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
   581
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   582
    if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   583
        pparams.Windowed = FALSE;
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   584
        pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   585
        pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   586
    } else {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   587
        pparams.Windowed = TRUE;
8823
15a1b4b8e20a Setting the window size changes the fullscreen display mode, unless a window display mode has been set.
Sam Lantinga <slouken@libsdl.org>
parents: 8822
diff changeset
   588
        pparams.BackBufferFormat = D3DFMT_UNKNOWN;
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
   589
        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
   590
    }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   591
    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
   592
        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
   593
    } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   594
        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
   595
    }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   596
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
   597
    /* 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
   598
    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
   599
    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
   600
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
   601
    IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
3197
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   602
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   603
    device_flags = D3DCREATE_FPU_PRESERVE;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   604
    if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   605
        device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   606
    } else {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   607
        device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   608
    }
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
   609
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   610
    hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE);
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   611
    if (hint && SDL_atoi(hint)) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   612
        device_flags |= D3DCREATE_MULTITHREADED;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   613
    }
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
   614
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
    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
   616
                                     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
   617
                                     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
   618
                                     device_flags,
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   619
                                     &pparams, &data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   620
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   621
        D3D_DestroyRenderer(renderer);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   622
        D3D_SetError("CreateDevice()", result);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   623
        return NULL;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   624
    }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   625
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   626
    /* 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
   627
    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
   628
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   629
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   630
        D3D_SetError("GetSwapChain()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   631
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   632
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   633
    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
   634
    if (FAILED(result)) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   635
        IDirect3DSwapChain9_Release(chain);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   636
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   637
        D3D_SetError("GetPresentParameters()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   638
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   639
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   640
    IDirect3DSwapChain9_Release(chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   641
    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   642
        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
   643
    }
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   644
    data->pparams = pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   645
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   646
    IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   647
    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
   648
    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
   649
    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
   650
        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
   651
    }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1917
diff changeset
   652
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   653
    if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   654
        data->enableSeparateAlphaBlend = SDL_TRUE;
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   655
    }
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   656
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   657
    /* 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
   658
    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
   659
    data->currentRenderTarget = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   660
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
   661
    /* 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
   662
    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
   663
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   664
    if (caps.MaxSimultaneousTextures >= 3)
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   665
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   666
#ifdef ASSEMBLE_SHADER
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   667
        /* 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
   668
           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
   669
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   670
           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
   671
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   672
           --- yuv.fx ---
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   673
           Texture2D g_txY;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   674
           Texture2D g_txU;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   675
           Texture2D g_txV;
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
           SamplerState samLinear
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   678
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   679
               Filter = ANISOTROPIC;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   680
               AddressU = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   681
               AddressV = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   682
               MaxAnisotropy = 1;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   683
           };
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
           struct VS_OUTPUT
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
                float2 TextureUV  : TEXCOORD0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   688
           };
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
           struct PS_OUTPUT
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
                float4 RGBAColor : SV_Target;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   693
           };
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
           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
   696
           {
8969
7fb90df60b99 The YUV offset is 16 / 255, not 16 / 256
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8823
diff changeset
   697
               const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   698
               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
   699
               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
   700
               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
   701
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   702
               PS_OUTPUT Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   703
               float2 TextureUV = In.TextureUV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   704
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   705
               float3 yuv;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   706
               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
   707
               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
   708
               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
   709
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   710
               yuv += offset;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   711
               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
   712
               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
   713
               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
   714
               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
   715
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   716
               return Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   717
           }
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
           technique10 RenderYUV420
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
               pass P0
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
                    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
   724
               }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   725
           }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   726
        */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   727
        const char *shader_text =
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   728
            "ps_2_0\n"
8969
7fb90df60b99 The YUV offset is 16 / 255, not 16 / 256
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8823
diff changeset
   729
            "def c0, -0.0627451017, -0.501960814, -0.501960814, 1\n"
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   730
            "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
   731
            "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
   732
            "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
   733
            "dcl t0.xy\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   734
            "dcl v0.xyzw\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   735
            "dcl_2d s0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   736
            "dcl_2d s1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   737
            "dcl_2d s2\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   738
            "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
   739
            "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
   740
            "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
   741
            "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
   742
            "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
   743
            "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
   744
            "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
   745
            "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
   746
            "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
   747
            "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
   748
            "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
   749
            "mov oC0, r0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   750
        ;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   751
        LPD3DXBUFFER pCode;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   752
        LPD3DXBUFFER pErrorMsgs;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   753
        LPDWORD shader_data = NULL;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   754
        DWORD   shader_size = 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   755
        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
   756
        if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   757
            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
   758
            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
   759
            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
   760
        } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   761
            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
   762
            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
   763
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   764
#else
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   765
        const DWORD shader_data[] = {
8969
7fb90df60b99 The YUV offset is 16 / 255, not 16 / 256
Alfred Reynolds <alfred@valvesoftware.com>
parents: 8823
diff changeset
   766
            0xffff0200, 0x05000051, 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081,
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   767
            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
   768
            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
   769
            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
   770
            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
   771
            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
   772
            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
   773
            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
   774
            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
   775
            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
   776
            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
   777
            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
   778
            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
   779
            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
   780
            0x80e40000, 0x0000ffff
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   781
        };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   782
#endif
7547
abdea1385dbb Fixed compiler warning with gcc
Sam Lantinga <slouken@libsdl.org>
parents: 7505
diff changeset
   783
        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
   784
            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
   785
            if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   786
                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
   787
                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
   788
            } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   789
                D3D_SetError("CreatePixelShader()", result);
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
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   792
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   793
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
   794
    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
   795
}
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
   796
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   797
static void
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   798
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
   799
{
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   800
    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
   801
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   802
    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
   803
        data->updateSize = SDL_TRUE;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   804
    }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   805
}
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   806
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
   807
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
   808
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
   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
    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
   811
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   812
    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
   813
        return D3DTEXF_POINT;
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   814
    } 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
   815
        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
   816
    }
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   817
}
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   818
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   819
static int
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   820
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
   821
{
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
   822
    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
   823
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
   824
    texture->dirty = SDL_FALSE;
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   825
    texture->w = w;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   826
    texture->h = h;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   827
    texture->usage = usage;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   828
    texture->format = format;
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
   829
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   830
    result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   831
        PixelFormatToD3DFMT(format),
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   832
        D3DPOOL_DEFAULT, &texture->texture, NULL);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   833
    if (FAILED(result)) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   834
        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
   835
    }
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   836
    return 0;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   837
}
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   838
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   839
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   840
static int
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   841
D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   842
{
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   843
    HRESULT result;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   844
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   845
    if (texture->staging == NULL) {
9702
115bc7548a8d Fixed bug 2625 - Direct3D9 with SDL_TEXTUREACCESS_TARGET textures causes an application crash
Sam Lantinga <slouken@libsdl.org>
parents: 9680
diff changeset
   846
        result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0,
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   847
            PixelFormatToD3DFMT(texture->format),
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   848
            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
   849
        if (FAILED(result)) {
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   850
            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
   851
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   852
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   853
    return 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   854
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   855
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   856
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
   857
D3D_BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   858
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   859
    HRESULT result;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   860
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
   861
    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
   862
        if (!texture->texture) {
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   863
            result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   864
                PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
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
   865
            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
   866
                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
   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
        }
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
   869
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
        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
   871
        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
   872
            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
   873
        }
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
   874
        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
   875
    }
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
    result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   877
    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
   878
        return D3D_SetError("SetTexture()", result);
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   879
    }
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
   880
    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
   881
}
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   882
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
   883
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
   884
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
   885
{
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
   886
    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
   887
        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
   888
        texture->texture = NULL;
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   889
    }
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   890
    if (texture->staging) {
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   891
        IDirect3DTexture9_AddDirtyRect(texture->staging, NULL);
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   892
        texture->dirty = SDL_TRUE;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   893
    }
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   894
    return 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   895
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   896
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   897
static int
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   898
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
   899
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   900
    RECT d3drect;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   901
    D3DLOCKED_RECT locked;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   902
    const Uint8 *src;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   903
    Uint8 *dst;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   904
    int row, length;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   905
    HRESULT result;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   906
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   907
    if (D3D_CreateStagingTexture(device, texture) < 0) {
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   908
        return -1;
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   909
    }
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   910
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   911
    d3drect.left = x;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   912
    d3drect.right = x + w;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   913
    d3drect.top = y;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   914
    d3drect.bottom = y + h;
9074
86a6f6d92960 Fixed bugs 2677 and 2625, made it possible to lock render targets in D3D
Sam Lantinga <slouken@libsdl.org>
parents: 8976
diff changeset
   915
    
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   916
    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
   917
    if (FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   918
        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
   919
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   920
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   921
    src = (const Uint8 *)pixels;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   922
    dst = locked.pBits;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   923
    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
   924
    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
   925
        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
   926
    } 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
   927
        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
   928
            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
   929
        }
49af9be342cd Fixed crash if the input data pitch is larger than the locked texture pitch
Sam Lantinga <slouken@libsdl.org>
parents: 8228
diff changeset
   930
        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
   931
            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
   932
        }
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   933
        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
   934
            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
   935
            src += pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   936
            dst += locked.Pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   937
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   938
    }
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
   939
    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
   940
    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
   941
        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
   942
    }
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
   943
    texture->dirty = SDL_TRUE;
8792
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
    return 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   946
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   947
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   948
static void
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   949
D3D_DestroyTextureRep(D3D_TextureRep *texture)
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   950
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   951
    if (texture->texture) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   952
        IDirect3DTexture9_Release(texture->texture);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   953
        texture->texture = NULL;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   954
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   955
    if (texture->staging) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   956
        IDirect3DTexture9_Release(texture->staging);
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   957
        texture->staging = NULL;
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
}
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   960
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   961
static int
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   962
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   963
{
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   964
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   965
    D3D_TextureData *texturedata;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   966
    DWORD usage;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   967
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   968
    texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   969
    if (!texturedata) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   970
        return SDL_OutOfMemory();
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   971
    }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   972
    texturedata->scaleMode = GetScaleQuality();
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   973
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   974
    texture->driverdata = texturedata;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   975
8792
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   976
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   977
        usage = D3DUSAGE_RENDERTARGET;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   978
    } else {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   979
        usage = 0;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   980
    }
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
    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
   983
        return -1;
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
    if (texture->format == SDL_PIXELFORMAT_YV12 ||
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   987
        texture->format == SDL_PIXELFORMAT_IYUV) {
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   988
        texturedata->yuv = SDL_TRUE;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   989
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   990
        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
   991
            return -1;
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   992
        }
333216331863 Use D3D9Ex when available
Sam Lantinga <slouken@libsdl.org>
parents: 8778
diff changeset
   993