src/render/direct3d/SDL_render_d3d.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 20 Feb 2014 21:07:56 -0800
changeset 8228 010ae1267485
parent 8224 32af2d3806d1
child 8255 49af9be342cd
permissions -rw-r--r--
Fixed infinite recursion in D3D_Reset()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     2
  Simple DirectMedia Layer
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8131
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5484
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7989
diff changeset
    21
#include "../../SDL_internal.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
8193
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    23
#include "SDL_render.h"
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    24
#include "SDL_system.h"
b4f1e02f2df6 Fixed bug 2385 - error: unknown type name 'IDirect3DDevice9'
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
    25
5226
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    26
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
710d00cb3a6a Made it possible to disable the rendering subsystem with configure --disable-render
Sam Lantinga <slouken@libsdl.org>
parents: 5224
diff changeset
    27
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    28
#include "../../core/windows/SDL_windows.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    29
5484
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
    30
#include "SDL_hints.h"
5154
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    31
#include "SDL_loadso.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    32
#include "SDL_syswm.h"
fb424691cfc7 Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
Sam Lantinga <slouken@libsdl.org>
parents: 5149
diff changeset
    33
#include "../SDL_sysrender.h"
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
    34
#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
    35
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
#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
    37
#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
    38
#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
    39
#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
    40
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    41
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    42
typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    43
typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    44
typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    45
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    46
DEFINE_GUID(IID_ID3DXMatrixStack,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    47
0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    48
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    49
#undef INTERFACE
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    50
#define INTERFACE ID3DXMatrixStack
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    51
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    52
DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    53
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    54
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    55
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    56
    STDMETHOD_(ULONG,Release)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    57
    STDMETHOD(Pop)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    58
    STDMETHOD(Push)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    59
    STDMETHOD(LoadIdentity)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    60
    STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    61
    STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    62
    STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    63
    STDMETHOD(RotateAxis)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    64
    STDMETHOD(RotateAxisLocal)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    65
    STDMETHOD(RotateYawPitchRoll)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    66
    STDMETHOD(RotateYawPitchRollLocal)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    67
    STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    68
    STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    69
    STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    70
    STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    71
    STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    72
};
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    73
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    74
#undef INTERFACE
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    75
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    76
#if !defined(__cplusplus) || defined(CINTERFACE)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    77
#define ID3DXMatrixStack_QueryInterface(p,a,b)            (p)->lpVtbl->QueryInterface(p,a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    78
#define ID3DXMatrixStack_AddRef(p)                        (p)->lpVtbl->AddRef(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    79
#define ID3DXMatrixStack_Release(p)                       (p)->lpVtbl->Release(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    80
#define ID3DXMatrixStack_Pop(p)                           (p)->lpVtbl->Pop(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    81
#define ID3DXMatrixStack_Push(p)                          (p)->lpVtbl->Push(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    82
#define ID3DXMatrixStack_LoadIdentity(p)                  (p)->lpVtbl->LoadIdentity(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    83
#define ID3DXMatrixStack_LoadMatrix(p,a)                  (p)->lpVtbl->LoadMatrix(p,a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    84
#define ID3DXMatrixStack_MultMatrix(p,a)                  (p)->lpVtbl->MultMatrix(p,a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    85
#define ID3DXMatrixStack_MultMatrixLocal(p,a)             (p)->lpVtbl->MultMatrixLocal(p,a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    86
#define ID3DXMatrixStack_RotateAxis(p,a,b)                (p)->lpVtbl->RotateAxis(p,a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    87
#define ID3DXMatrixStack_RotateAxisLocal(p,a,b)           (p)->lpVtbl->RotateAxisLocal(p,a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    88
#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c)      (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    89
#define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    90
#define ID3DXMatrixStack_Scale(p,a,b,c)                   (p)->lpVtbl->Scale(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    91
#define ID3DXMatrixStack_ScaleLocal(p,a,b,c)              (p)->lpVtbl->ScaleLocal(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    92
#define ID3DXMatrixStack_Translate(p,a,b,c)               (p)->lpVtbl->Translate(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    93
#define ID3DXMatrixStack_TranslateLocal(p,a,b,c)          (p)->lpVtbl->TranslateLocal(p,a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    94
#define ID3DXMatrixStack_GetTop(p)                        (p)->lpVtbl->GetTop(p)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    95
#else
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    96
#define ID3DXMatrixStack_QueryInterface(p,a,b)            (p)->QueryInterface(a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    97
#define ID3DXMatrixStack_AddRef(p)                        (p)->AddRef()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    98
#define ID3DXMatrixStack_Release(p)                       (p)->Release()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
    99
#define ID3DXMatrixStack_Pop(p)    (p)->Pop()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   100
#define ID3DXMatrixStack_Push(p)    (p)->Push()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   101
#define ID3DXMatrixStack_LoadIdentity(p)    (p)->LoadIdentity()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   102
#define ID3DXMatrixStack_LoadMatrix(p,a)    (p)->LoadMatrix(a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   103
#define ID3DXMatrixStack_MultMatrix(p,a)    (p)->MultMatrix(a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   104
#define ID3DXMatrixStack_MultMatrixLocal(p,a)    (p)->MultMatrixLocal(a)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   105
#define ID3DXMatrixStack_RotateAxis(p,a,b)    (p)->RotateAxis(a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   106
#define ID3DXMatrixStack_RotateAxisLocal(p,a,b)    (p)->RotateAxisLocal(a,b)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   107
#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c)    (p)->RotateYawPitchRollLocal(a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   108
#define ID3DXMatrixStack_Scale(p,a,b,c)    (p)->Scale(a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   109
#define ID3DXMatrixStack_ScaleLocal(p,a,b,c)    (p)->ScaleLocal(a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   110
#define ID3DXMatrixStack_Translate(p,a,b,c)    (p)->Translate(a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   111
#define ID3DXMatrixStack_TranslateLocal(p,a,b,c)    (p)->TranslateLocal(a,b,c)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   112
#define ID3DXMatrixStack_GetTop(p)    (p)->GetTop()
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   113
#endif
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   114
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   115
#ifdef __cplusplus
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   116
extern "C" {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   117
#endif
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   118
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   119
HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   120
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   121
#ifdef __cplusplus
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   122
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   123
#endif
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   124
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   125
#ifdef ASSEMBLE_SHADER
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   126
/**************************************************************************
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   127
 * ID3DXBuffer:
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   128
 * ------------
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   129
 * 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
   130
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   131
 * GetBufferPointer -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   132
 *    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
   133
 *
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   134
 * GetBufferSize -
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   135
 *    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
   136
 **************************************************************************/
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   137
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   138
typedef interface ID3DXBuffer ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   139
typedef interface ID3DXBuffer *LPD3DXBUFFER;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   140
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   141
/* {8BA5FB08-5195-40e2-AC58-0D989C3A0102} */
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   142
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
   143
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
   144
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   145
#undef INTERFACE
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   146
#define INTERFACE ID3DXBuffer
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   147
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   148
typedef interface ID3DXBuffer {
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   149
    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
   150
} ID3DXBuffer;
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   151
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
   152
const struct ID3DXBufferVtbl
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   153
{
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   154
    /* IUnknown */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   155
    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
   156
    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
   157
    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
   158
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   159
    /* ID3DXBuffer */
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   160
    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
   161
    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
   162
};
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   163
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   164
HRESULT WINAPI
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   165
    D3DXAssembleShader(
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   166
        LPCSTR                          pSrcData,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   167
        UINT                            SrcDataLen,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   168
        CONST LPVOID*                   pDefines,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   169
        LPVOID                          pInclude,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   170
        DWORD                           Flags,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   171
        LPD3DXBUFFER*                   ppShader,
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   172
        LPD3DXBUFFER*                   ppErrorMsgs);
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   173
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   174
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
   175
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   176
    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
   177
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   178
        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
   179
        unsigned i;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   180
        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
   181
            char dword[11];
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   182
            if (i > 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   183
                if ((i%6) == 0) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   184
                    newline = SDL_TRUE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   185
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   186
                if (newline) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   187
                    OutputDebugStringA(",\n    ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   188
                    newline = SDL_FALSE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   189
                } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   190
                    OutputDebugStringA(", ");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   191
                }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   192
            }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   193
            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
   194
            OutputDebugStringA(dword);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   195
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   196
        OutputDebugStringA("\n};\n");
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   197
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   198
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   199
3556
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   200
#endif /* ASSEMBLE_SHADER */
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   201
9c2e92de786a Added a BLENDMODE_MASK pixel shader so render tests succeed
Sam Lantinga <slouken@libsdl.org>
parents: 3553
diff changeset
   202
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
   203
/* 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
   204
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   205
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
   206
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
   207
                            const SDL_WindowEvent *event);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   208
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   209
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   210
                             const SDL_Rect * rect, const void *pixels,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   211
                             int pitch);
7761
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   212
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
   213
                                const SDL_Rect * rect,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   214
                                const Uint8 *Yplane, int Ypitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   215
                                const Uint8 *Uplane, int Upitch,
bddbfca922cd Implemented SDL_UpdateYUVTexture() for Direct3D
Sam Lantinga <slouken@libsdl.org>
parents: 7756
diff changeset
   216
                                const Uint8 *Vplane, int Vpitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   217
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
   218
                           const SDL_Rect * rect, void **pixels, int *pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   219
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
   220
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
   221
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
   222
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
   223
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
   224
static int D3D_RenderClear(SDL_Renderer * renderer);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   225
static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   226
                                const SDL_FPoint * points, int count);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   227
static int D3D_RenderDrawLines(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   228
                               const SDL_FPoint * points, int count);
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   229
static int D3D_RenderFillRects(SDL_Renderer * renderer,
6528
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   230
                               const SDL_FRect * rects, int count);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   231
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
   232
                          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
   233
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
   234
                          const SDL_Rect * srcrect, const SDL_FRect * dstrect,
e978048ced60 Added SDL_RenderSetScale() and SDL_RenderGetScale()
Sam Lantinga <slouken@libsdl.org>
parents: 6404
diff changeset
   235
                          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
   236
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
   237
                                Uint32 format, void * pixels, int pitch);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   238
static void D3D_RenderPresent(SDL_Renderer * renderer);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   239
static void D3D_DestroyTexture(SDL_Renderer * renderer,
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   240
                               SDL_Texture * texture);
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   241
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
   242
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
   243
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   244
SDL_RenderDriver D3D_RenderDriver = {
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   245
    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
   246
    {
5186
97d0480b420c Updated the name of the Direct3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   247
     "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
   248
     (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
   249
     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
   250
     {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
   251
     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
   252
     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
   253
};
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
   254
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
   255
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
   256
{
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
   257
    void* d3dDLL;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   258
    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
   259
    IDirect3DDevice9 *device;
3527
444cb12cadb6 Fixed to use the correct display adapter
Sam Lantinga <slouken@libsdl.org>
parents: 3520
diff changeset
   260
    UINT adapter;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   261
    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
   262
    SDL_bool updateSize;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   263
    SDL_bool beginScene;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   264
    SDL_bool enableSeparateAlphaBlend;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   265
    D3DTEXTUREFILTERTYPE scaleMode[8];
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   266
    IDirect3DSurface9 *defaultRenderTarget;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   267
    IDirect3DSurface9 *currentRenderTarget;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   268
    void* d3dxDLL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   269
    ID3DXMatrixStack *matrixStack;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   270
    LPDIRECT3DPIXELSHADER9 ps_yuv;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   271
} 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
   272
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
   273
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
   274
{
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
   275
    IDirect3DTexture9 *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
   276
    D3DTEXTUREFILTERTYPE scaleMode;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   277
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   278
    /* YV12 texture support */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   279
    SDL_bool yuv;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   280
    IDirect3DTexture9 *utexture;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   281
    IDirect3DTexture9 *vtexture;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   282
    Uint8 *pixels;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   283
    int pitch;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   284
    SDL_Rect locked_rect;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   285
} 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
   286
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
   287
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
   288
{
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
   289
    float x, y, z;
1987
36a08379b3f2 Implemented color modulation in the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1985
diff changeset
   290
    DWORD color;
1904
1a713f9d1f71 Yay! D3D renderer works!
Sam Lantinga <slouken@libsdl.org>
parents: 1903
diff changeset
   291
    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
   292
} 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
   293
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   294
static int
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   295
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
   296
{
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   297
    const char *error;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   298
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   299
    switch (result) {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   300
    case D3DERR_WRONGTEXTUREFORMAT:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   301
        error = "WRONGTEXTUREFORMAT";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   302
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   303
    case D3DERR_UNSUPPORTEDCOLOROPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   304
        error = "UNSUPPORTEDCOLOROPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   305
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   306
    case D3DERR_UNSUPPORTEDCOLORARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   307
        error = "UNSUPPORTEDCOLORARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   308
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   309
    case D3DERR_UNSUPPORTEDALPHAOPERATION:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   310
        error = "UNSUPPORTEDALPHAOPERATION";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   311
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   312
    case D3DERR_UNSUPPORTEDALPHAARG:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   313
        error = "UNSUPPORTEDALPHAARG";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   314
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   315
    case D3DERR_TOOMANYOPERATIONS:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   316
        error = "TOOMANYOPERATIONS";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   317
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   318
    case D3DERR_CONFLICTINGTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   319
        error = "CONFLICTINGTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   320
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   321
    case D3DERR_UNSUPPORTEDFACTORVALUE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   322
        error = "UNSUPPORTEDFACTORVALUE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   323
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   324
    case D3DERR_CONFLICTINGRENDERSTATE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   325
        error = "CONFLICTINGRENDERSTATE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   326
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   327
    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   328
        error = "UNSUPPORTEDTEXTUREFILTER";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   329
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   330
    case D3DERR_CONFLICTINGTEXTUREPALETTE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   331
        error = "CONFLICTINGTEXTUREPALETTE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   332
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   333
    case D3DERR_DRIVERINTERNALERROR:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   334
        error = "DRIVERINTERNALERROR";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   335
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   336
    case D3DERR_NOTFOUND:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   337
        error = "NOTFOUND";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   338
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   339
    case D3DERR_MOREDATA:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   340
        error = "MOREDATA";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   341
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   342
    case D3DERR_DEVICELOST:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   343
        error = "DEVICELOST";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   344
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   345
    case D3DERR_DEVICENOTRESET:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   346
        error = "DEVICENOTRESET";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   347
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   348
    case D3DERR_NOTAVAILABLE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   349
        error = "NOTAVAILABLE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   350
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   351
    case D3DERR_OUTOFVIDEOMEMORY:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   352
        error = "OUTOFVIDEOMEMORY";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   353
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   354
    case D3DERR_INVALIDDEVICE:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   355
        error = "INVALIDDEVICE";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   356
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   357
    case D3DERR_INVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   358
        error = "INVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   359
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   360
    case D3DERR_DRIVERINVALIDCALL:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   361
        error = "DRIVERINVALIDCALL";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   362
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   363
    case D3DERR_WASSTILLDRAWING:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   364
        error = "WASSTILLDRAWING";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   365
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   366
    default:
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   367
        error = "UNKNOWN";
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   368
        break;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   369
    }
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   370
    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
   371
}
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   372
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
   373
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
   374
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
   375
{
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
   376
    switch (format) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   377
    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
   378
        return D3DFMT_R5G6B5;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   379
    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
   380
        return D3DFMT_X8R8G8B8;
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   381
    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
   382
        return D3DFMT_A8R8G8B8;
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   383
    case SDL_PIXELFORMAT_YV12:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   384
    case SDL_PIXELFORMAT_IYUV:
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   385
        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
   386
    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
   387
        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
   388
    }
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
   389
}
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
   390
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
   391
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
   392
D3DFMTToPixelFormat(D3DFORMAT format)
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   393
{
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
   394
    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
   395
    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
   396
        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
   397
    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
   398
        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
   399
    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
   400
        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
   401
    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
   402
        return SDL_PIXELFORMAT_UNKNOWN;
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   403
    }
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
   404
}
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
   405
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
   406
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
   407
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
   408
{
7651
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   409
    D3DMATRIX matrix;
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   410
e36a26e969c7 Fixed Windows build
Sam Lantinga <slouken@libsdl.org>
parents: 7648
diff changeset
   411
    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
   412
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
   413
    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
   414
    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
   415
    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
   416
    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
   417
    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
   418
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
   419
    /* 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
   420
    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
   421
                                          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
   422
    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
   423
                                          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
   424
    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
   425
                                          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
   426
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
   427
    /* 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
   428
    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
   429
                                          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
   430
    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
   431
                                          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
   432
    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
   433
                                          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
   434
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
   435
    /* 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
   436
    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
   437
        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
   438
    }
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
   439
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
   440
    /* 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
   441
    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
   442
                                          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
   443
    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
   444
                                          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
   445
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
   446
    /* 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
   447
    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
   448
    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
   449
    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
   450
    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
   451
    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
   452
    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
   453
    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
   454
    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
   455
    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
   456
    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
   457
    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
   458
    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
   459
    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
   460
    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
   461
    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
   462
    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
   463
    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
   464
    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
   465
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
   466
    /* 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
   467
    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
   468
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
   469
    /* 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
   470
    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
   471
}
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
   472
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   473
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   474
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
   475
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   476
    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
   477
    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
   478
    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
   479
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   480
    /* 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
   481
    if (data->defaultRenderTarget) {
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   482
        IDirect3DSurface9_Release(data->defaultRenderTarget);
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   483
        data->defaultRenderTarget = NULL;
031a1fd143ec Fixed bug 1722 - An attempt to release NULL Direct3d surface
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   484
    }
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
   485
    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
   486
        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
   487
        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
   488
    }
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   489
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
   490
    /* 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
   491
    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
   492
        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
   493
            D3D_DestroyTexture(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
   494
        }
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
   495
    }
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
   496
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   497
    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
   498
    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
   499
        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
   500
            /* 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
   501
            return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   502
        } else {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   503
            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
   504
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   505
    }
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
   506
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
   507
    /* 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
   508
    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
   509
        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
   510
            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
   511
        }
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
   512
    }
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
   513
6860
c16fc4e46ae5 Fixed bug 1491 - Directx3d Crash on resize
Sam Lantinga <slouken@libsdl.org>
parents: 6782
diff changeset
   514
    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
   515
    D3D_InitRenderState(data);
8228
010ae1267485 Fixed infinite recursion in D3D_Reset()
Sam Lantinga <slouken@libsdl.org>
parents: 8224
diff changeset
   516
    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
   517
    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
   518
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
   519
    /* 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
   520
    {
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
   521
        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
   522
        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
   523
        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
   524
    }
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
   525
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   526
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   527
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   528
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   529
static int
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   530
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
   531
{
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   532
    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
   533
    HRESULT result;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   534
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   535
    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
   536
        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
   537
        int w, h;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   538
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   539
        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
   540
        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
   541
        data->pparams.BackBufferHeight = h;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   542
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   543
            data->pparams.BackBufferFormat =
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   544
                PixelFormatToD3DFMT(SDL_GetWindowPixelFormat(window));
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   545
        } else {
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   546
            data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   547
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   548
        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
   549
            return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   550
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   551
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   552
        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
   553
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   554
    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
   555
        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
   556
        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
   557
            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
   558
                return -1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   559
            }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   560
            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
   561
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   562
        if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   563
            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
   564
        }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   565
        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
   566
    }
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   567
    return 0;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   568
}
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   569
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
   570
SDL_Renderer *
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   571
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
   572
{
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
   573
    SDL_Renderer *renderer;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   574
    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
   575
    SDL_SysWMinfo windowinfo;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   576
    HRESULT result;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   577
    const char *hint;
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   578
    D3DPRESENT_PARAMETERS pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   579
    IDirect3DSwapChain9 *chain;
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   580
    D3DCAPS9 caps;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   581
    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
   582
    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
   583
    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
   584
    SDL_DisplayMode fullscreen_mode;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   585
    int d3dxVersion;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   586
    char d3dxDLLFile[50];
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   587
    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
   588
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
   589
    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
   590
    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
   591
        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
   592
        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
   593
    }
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
   594
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
   595
    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
   596
    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
   597
        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
   598
        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
   599
        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
   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
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
   602
    if (D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   603
        for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
6971
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6968
diff changeset
   604
            LPTSTR dllName;
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6968
diff changeset
   605
            SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion);
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6968
diff changeset
   606
            dllName = WIN_UTF8ToString(d3dxDLLFile);
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6968
diff changeset
   607
            data->d3dxDLL = (void *)LoadLibrary(dllName); /* not using SDL_LoadObject() as we want silently fail - no error message */
5ded971ee761 Fixed compile errors on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 6968
diff changeset
   608
            SDL_free(dllName);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   609
            if (data->d3dxDLL) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   610
                HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK*  ppStack);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   611
                D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack");
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   612
                if (D3DXCreateMatrixStack) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   613
                    D3DXCreateMatrixStack(0, &data->matrixStack);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   614
                    break;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   615
                }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   616
            }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   617
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   618
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   619
        if (!data->matrixStack) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   620
            if (data->d3dxDLL) SDL_UnloadObject(data->d3dxDLL);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   621
        }
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
   622
    }
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   623
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 6247
diff changeset
   624
    if (!data->d3d || !data->matrixStack) {
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
   625
        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
   626
        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
   627
        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
   628
        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
   629
    }
4569
e1664f94f026 Andrey A.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   630
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   631
    renderer->WindowEvent = D3D_WindowEvent;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   632
    renderer->CreateTexture = D3D_CreateTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   633
    renderer->UpdateTexture = D3D_UpdateTexture;
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   634
    renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   635
    renderer->LockTexture = D3D_LockTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   636
    renderer->UnlockTexture = D3D_UnlockTexture;
6247
b6212690f78d Renamed SetTargetTexture() to SetRenderTarget()
Sam Lantinga <slouken@libsdl.org>
parents: 6246
diff changeset
   637
    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
   638
    renderer->UpdateViewport = D3D_UpdateViewport;
7141
e276777b4247 First pass on SDL render clip rect functionality
Sam Lantinga <slouken@libsdl.org>
parents: 7037
diff changeset
   639
    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
   640
    renderer->RenderClear = D3D_RenderClear;
3599
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   641
    renderer->RenderDrawPoints = D3D_RenderDrawPoints;
0f958e527e5e Updated to compile on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 3556
diff changeset
   642
    renderer->RenderDrawLines = D3D_RenderDrawLines;
3675
e86edac50872 Fixed bug #932
Sam Lantinga <slouken@libsdl.org>
parents: 3599
diff changeset
   643
    renderer->RenderFillRects = D3D_RenderFillRects;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   644
    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
   645
    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
   646
    renderer->RenderReadPixels = D3D_RenderReadPixels;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   647
    renderer->RenderPresent = D3D_RenderPresent;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   648
    renderer->DestroyTexture = D3D_DestroyTexture;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   649
    renderer->DestroyRenderer = D3D_DestroyRenderer;
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   650
    renderer->info = D3D_RenderDriver.info;
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
   651
    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
   652
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
   653
    renderer->info.flags = SDL_RENDERER_ACCELERATED;
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
   654
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
   655
    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
   656
    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
   657
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
   658
    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
   659
    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
   660
    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
   661
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   662
    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
   663
    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
   664
    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
   665
    pparams.BackBufferHeight = h;
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   666
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   667
        pparams.BackBufferFormat =
5156
307ccc9c135e Made it possible to create a texture of any format, even if not supported by the renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5154
diff changeset
   668
            PixelFormatToD3DFMT(fullscreen_mode.format);
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   669
    } else {
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   670
        pparams.BackBufferFormat = D3DFMT_UNKNOWN;
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   671
    }
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
   672
    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
   673
    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
   674
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
   675
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   676
        if ((window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)  {
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   677
            pparams.Windowed = TRUE;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   678
            pparams.FullScreen_RefreshRateInHz = 0;
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   679
        } else {
8207
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   680
            pparams.Windowed = FALSE;
f06add42160c Recreate render target textures when the D3D device is being reset, and notify the application using the SDL_RENDER_TARGETS_RESET event when this happens.
Sam Lantinga <slouken@libsdl.org>
parents: 8193
diff changeset
   681
            pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7183
diff changeset
   682
        }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   683
    } else {
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   684
        pparams.Windowed = TRUE;
1903
f132024010be More of the Direct3D renderer is implemented, I'm not sure why it's not showing texture copies yet...
Sam Lantinga <slouken@libsdl.org>
parents: 1901
diff changeset
   685
        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
   686
    }
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   687
    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
   688
        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
   689
    } else {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   690
        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
   691
    }
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   692
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
   693
    /* 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
   694
    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
   695
    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
   696
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
   697
    IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
3197
434ce3242e1c Alexei Tereschenko
Sam Lantinga <slouken@libsdl.org>
parents: 3013
diff changeset
   698
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   699
    device_flags = D3DCREATE_FPU_PRESERVE;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   700
    if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   701
        device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   702
    } else {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   703
        device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   704
    }
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
   705
7877
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   706
    hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE);
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   707
    if (hint && SDL_atoi(hint)) {
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   708
        device_flags |= D3DCREATE_MULTITHREADED;
aa7e6130d6e9 Fixed whitespace
Sam Lantinga <slouken@libsdl.org>
parents: 7837
diff changeset
   709
    }
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
   710
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
   711
    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
   712
                                     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
   713
                                     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
   714
                                     device_flags,
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   715
                                     &pparams, &data->device);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   716
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   717
        D3D_DestroyRenderer(renderer);
1900
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   718
        D3D_SetError("CreateDevice()", result);
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   719
        return NULL;
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   720
    }
5c6bdbf3aadf First stab at a D3D renderer, only 30FPS so far... ?
Sam Lantinga <slouken@libsdl.org>
parents: 1898
diff changeset
   721
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   722
    /* 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
   723
    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
   724
    if (FAILED(result)) {
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   725
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   726
        D3D_SetError("GetSwapChain()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   727
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   728
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   729
    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
   730
    if (FAILED(result)) {
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   731
        IDirect3DSwapChain9_Release(chain);
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   732
        D3D_DestroyRenderer(renderer);
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   733
        D3D_SetError("GetPresentParameters()", result);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   734
        return NULL;
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   735
    }
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   736
    IDirect3DSwapChain9_Release(chain);
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   737
    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
1965
a788656ca29a SDL constants are all uppercase.
Sam Lantinga <slouken@libsdl.org>
parents: 1925
diff changeset
   738
        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
   739
    }
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   740
    data->pparams = pparams;
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1905
diff changeset
   741
1925
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   742
    IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
411bfb37082b Query the maximum texture size for the D3D renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1924
diff changeset
   743
    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
   744
    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
   745
    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
   746
        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
   747
    }
1918
092bd3a019c5 Starting on the OpenGL renderer...
Sam Lantinga <slouken@libsdl.org>
parents: 1917
diff changeset
   748
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   749
    if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   750
        data->enableSeparateAlphaBlend = SDL_TRUE;
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   751
    }
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7472
diff changeset
   752
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   753
    /* Store the default render target */
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   754
    IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   755
    data->currentRenderTarget = NULL;
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   756
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
   757
    /* 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
   758
    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
   759
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   760
    if (caps.MaxSimultaneousTextures >= 3)
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   761
    {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   762
#ifdef ASSEMBLE_SHADER
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   763
        /* 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
   764
           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
   765
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   766
           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
   767
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   768
           --- yuv.fx ---
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   769
           Texture2D g_txY;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   770
           Texture2D g_txU;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   771
           Texture2D g_txV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   772
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   773
           SamplerState samLinear
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   774
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   775
               Filter = ANISOTROPIC;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   776
               AddressU = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   777
               AddressV = Clamp;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   778
               MaxAnisotropy = 1;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   779
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   780
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   781
           struct VS_OUTPUT
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   782
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   783
                float2 TextureUV  : TEXCOORD0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   784
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   785
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   786
           struct PS_OUTPUT
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   787
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   788
                float4 RGBAColor : SV_Target;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   789
           };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   790
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   791
           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
   792
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   793
               const float3 offset = {-0.0625, -0.5, -0.5};
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   794
               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
   795
               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
   796
               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
   797
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   798
               PS_OUTPUT Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   799
               float2 TextureUV = In.TextureUV;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   800
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   801
               float3 yuv;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   802
               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
   803
               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
   804
               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
   805
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   806
               yuv += offset;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   807
               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
   808
               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
   809
               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
   810
               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
   811
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   812
               return Output;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   813
           }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   814
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   815
           technique10 RenderYUV420
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   816
           {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   817
               pass P0
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   818
               {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   819
                    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
   820
               }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   821
           }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   822
        */
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   823
        const char *shader_text =
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   824
            "ps_2_0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   825
            "def c0, -0.0625, -0.5, -0.5, 1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   826
            "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
   827
            "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
   828
            "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
   829
            "dcl t0.xy\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   830
            "dcl v0.xyzw\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   831
            "dcl_2d s0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   832
            "dcl_2d s1\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   833
            "dcl_2d s2\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   834
            "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
   835
            "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
   836
            "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
   837
            "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
   838
            "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
   839
            "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
   840
            "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
   841
            "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
   842
            "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
   843
            "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
   844
            "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
   845
            "mov oC0, r0\n"
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   846
        ;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   847
        LPD3DXBUFFER pCode;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   848
        LPD3DXBUFFER pErrorMsgs;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   849
        LPDWORD shader_data = NULL;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   850
        DWORD   shader_size = 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   851
        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
   852
        if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   853
            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
   854
            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
   855
            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
   856
        } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   857
            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
   858
            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
   859
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   860
#else
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   861
        const DWORD shader_data[] = {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   862
            0xffff0200, 0x05000051, 0xa00f0000, 0xbd800000, 0xbf000000, 0xbf000000,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   863
            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
   864
            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
   865
            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
   866
            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
   867
            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
   868
            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
   869
            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
   870
            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
   871
            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
   872
            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
   873
            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
   874
            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
   875
            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
   876
            0x80e40000, 0x0000ffff
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   877
        };
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   878
#endif
7547
abdea1385dbb Fixed compiler warning with gcc
Sam Lantinga <slouken@libsdl.org>
parents: 7505
diff changeset
   879
        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
   880
            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
   881
            if (!FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   882
                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
   883
                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
   884
            } else {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   885
                D3D_SetError("CreatePixelShader()", result);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   886
            }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   887
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   888
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   889
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
   890
    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
   891
}
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
   892
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   893
static void
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   894
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
   895
{
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   896
    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
   897
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   898
    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
   899
        data->updateSize = SDL_TRUE;
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   900
    }
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   901
}
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   902
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
   903
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
   904
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
   905
{
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   906
    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
   907
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   908
    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
   909
        return D3DTEXF_POINT;
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   910
    } 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
   911
        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
   912
    }
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   913
}
e20c93bc9122 Added the SDL_HINT_RENDER_SCALE_QUALITY hint, which defaults to nearest pixel sampling.
Sam Lantinga <slouken@libsdl.org>
parents: 5299
diff changeset
   914
1975
ccef0d0c40c6 Added resize support for GDI and Direct3D renderers
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   915
static int
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   916
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
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
   917
{
6404
724e1fba7933 Whoops, removed wrong variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 6403
diff changeset
   918
    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
1913
83420da906a5 Implemented Windows OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   919
    D3D_TextureData *data;
5173
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   920
    D3DPOOL pool;
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   921
    DWORD usage;
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
   922
    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
   923
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
   924
    data = (D3D_TextureData *) 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
   925
    if (!data) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   926
        return SDL_OutOfMemory();
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
   927
    }
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
   928
    data->scaleMode = GetScaleQuality();
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
   929
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
   930
    texture->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
   931
5173
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   932
#ifdef USE_DYNAMIC_TEXTURE
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   933
    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   934
        pool = D3DPOOL_DEFAULT;
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   935
        usage = D3DUSAGE_DYNAMIC;
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   936
    } else
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   937
#endif
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   938
    if (texture->access == SDL_TEXTUREACCESS_TARGET) {
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
   939
        /* D3DPOOL_MANAGED does not work with D3DUSAGE_RENDERTARGET */
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
   940
        pool = D3DPOOL_DEFAULT;
6232
37e8d0736366 Implementation of render targets, by Mason Wheeler and Gabriel Jacobo
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
   941
        usage = D3DUSAGE_RENDERTARGET;
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
   942
    } else {
5173
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   943
        pool = D3DPOOL_MANAGED;
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   944
        usage = 0;
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   945
    }
2973
ab0c00f1b070 Improved Direct3D YUV texture support
Sam Lantinga <slouken@libsdl.org>
parents: 2972
diff changeset
   946
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
   947
    result =
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
   948
        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
5173
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   949
                                       texture->h, 1, usage,
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   950
                                       PixelFormatToD3DFMT(texture->format),
ebfedf3787b1 Standardized on using the managed texture pool.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
   951
                                       pool, &data->texture, NULL);
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
   952
    if (FAILED(result)) {
7037
3fedf1f25b94 Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents: 6971
diff changeset
   953
        return D3D_SetError("CreateTexture()", result);
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
   954
    }
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
   955
7505
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   956
    if (texture->format == SDL_PIXELFORMAT_YV12 ||
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   957
        texture->format == SDL_PIXELFORMAT_IYUV) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   958
        data->yuv = SDL_TRUE;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   959
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   960
        result =
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   961
            IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   962
                                           texture->h / 2, 1, usage,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   963
                                           PixelFormatToD3DFMT(texture->format),
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   964
                                           pool, &data->utexture, NULL);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   965
        if (FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   966
            return D3D_SetError("CreateTexture()", result);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   967
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   968
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   969
        result =
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   970
            IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   971
                                           texture->h / 2, 1, usage,
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   972
                                           PixelFormatToD3DFMT(texture->format),
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   973
                                           pool, &data->vtexture, NULL);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   974
        if (FAILED(result)) {
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   975
            return D3D_SetError("CreateTexture()", result);
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   976
        }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   977
    }
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   978
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   979
    return 0;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   980
}
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   981
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   982
static int
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   983
D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool full_texture, int x, int y, int w, int h, const void *pixels, int pitch)
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   984
{
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   985
    RECT d3drect;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   986
    D3DLOCKED_RECT locked;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   987
    const Uint8 *src;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   988
    Uint8 *dst;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   989
    int row, length;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   990
    HRESULT result;
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   991
bc709c9493e7 Added Direct3D shader to hardware accelerate YV12 and IYUV textures.
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   992
    if (full_texture) {
bc709c9493e7 Added Direct3D shader to hardware