23 #if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
26 #include "../../core/windows/SDL_windows.h"
32 #include "../SDL_sysrender.h"
33 #include "../../video/windows/SDL_windowsvideo.h"
35 #if SDL_VIDEO_RENDER_D3D
36 #define D3D_DEBUG_INFO
46 0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
49 #define INTERFACE ID3DXMatrixStack
53 STDMETHOD(QueryInterface)(THIS_ REFIID riid,
LPVOID * ppvObj) PURE;
54 STDMETHOD_(ULONG,AddRef)(THIS) PURE;
55 STDMETHOD_(ULONG,Release)(THIS) PURE;
56 STDMETHOD(Pop)(THIS) PURE;
57 STDMETHOD(Push)(THIS) PURE;
58 STDMETHOD(LoadIdentity)(THIS) PURE;
59 STDMETHOD(LoadMatrix)(THIS_ CONST
D3DXMATRIX* pM ) PURE;
60 STDMETHOD(MultMatrix)(THIS_ CONST
D3DXMATRIX* pM ) PURE;
61 STDMETHOD(MultMatrixLocal)(THIS_ CONST
D3DXMATRIX* pM ) PURE;
62 STDMETHOD(RotateAxis)(THIS_ CONST
D3DXVECTOR3* pV, FLOAT Angle) PURE;
63 STDMETHOD(RotateAxisLocal)(THIS_ CONST
D3DXVECTOR3* pV, FLOAT Angle) PURE;
64 STDMETHOD(RotateYawPitchRoll)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
65 STDMETHOD(RotateYawPitchRollLocal)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
66 STDMETHOD(Scale)(THIS_ FLOAT
x, FLOAT
y, FLOAT
z) PURE;
67 STDMETHOD(ScaleLocal)(THIS_ FLOAT
x, FLOAT
y, FLOAT
z) PURE;
68 STDMETHOD(Translate)(THIS_ FLOAT
x, FLOAT
y, FLOAT
z ) PURE;
69 STDMETHOD(TranslateLocal)(THIS_ FLOAT
x, FLOAT
y, FLOAT
z) PURE;
75 #if !defined(__cplusplus) || defined(CINTERFACE)
76 #define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
77 #define ID3DXMatrixStack_AddRef(p) (p)->lpVtbl->AddRef(p)
78 #define ID3DXMatrixStack_Release(p) (p)->lpVtbl->Release(p)
79 #define ID3DXMatrixStack_Pop(p) (p)->lpVtbl->Pop(p)
80 #define ID3DXMatrixStack_Push(p) (p)->lpVtbl->Push(p)
81 #define ID3DXMatrixStack_LoadIdentity(p) (p)->lpVtbl->LoadIdentity(p)
82 #define ID3DXMatrixStack_LoadMatrix(p,a) (p)->lpVtbl->LoadMatrix(p,a)
83 #define ID3DXMatrixStack_MultMatrix(p,a) (p)->lpVtbl->MultMatrix(p,a)
84 #define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->lpVtbl->MultMatrixLocal(p,a)
85 #define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->lpVtbl->RotateAxis(p,a,b)
86 #define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->lpVtbl->RotateAxisLocal(p,a,b)
87 #define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
88 #define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
89 #define ID3DXMatrixStack_Scale(p,a,b,c) (p)->lpVtbl->Scale(p,a,b,c)
90 #define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->lpVtbl->ScaleLocal(p,a,b,c)
91 #define ID3DXMatrixStack_Translate(p,a,b,c) (p)->lpVtbl->Translate(p,a,b,c)
92 #define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->lpVtbl->TranslateLocal(p,a,b,c)
93 #define ID3DXMatrixStack_GetTop(p) (p)->lpVtbl->GetTop(p)
95 #define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
96 #define ID3DXMatrixStack_AddRef(p) (p)->AddRef()
97 #define ID3DXMatrixStack_Release(p) (p)->Release()
98 #define ID3DXMatrixStack_Pop(p) (p)->Pop()
99 #define ID3DXMatrixStack_Push(p) (p)->Push()
100 #define ID3DXMatrixStack_LoadIdentity(p) (p)->LoadIdentity()
101 #define ID3DXMatrixStack_LoadMatrix(p,a) (p)->LoadMatrix(a)
102 #define ID3DXMatrixStack_MultMatrix(p,a) (p)->MultMatrix(a)
103 #define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->MultMatrixLocal(a)
104 #define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->RotateAxis(a,b)
105 #define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->RotateAxisLocal(a,b)
106 #define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->RotateYawPitchRollLocal(a,b,c)
107 #define ID3DXMatrixStack_Scale(p,a,b,c) (p)->Scale(a,b,c)
108 #define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->ScaleLocal(a,b,c)
109 #define ID3DXMatrixStack_Translate(p,a,b,c) (p)->Translate(a,b,c)
110 #define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->TranslateLocal(a,b,c)
111 #define ID3DXMatrixStack_GetTop(p) (p)->GetTop()
124 #ifdef ASSEMBLE_SHADER
142 0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0
x1, 0
x2);
145 #define INTERFACE ID3DXBuffer
148 const struct ID3DXBufferVtbl
FAR* lpVtbl;
150 typedef const struct ID3DXBufferVtbl ID3DXBufferVtbl;
151 const struct ID3DXBufferVtbl
154 STDMETHOD(QueryInterface)(THIS_ REFIID iid,
LPVOID *ppv) PURE;
155 STDMETHOD_(ULONG, AddRef)(THIS) PURE;
156 STDMETHOD_(ULONG, Release)(THIS) PURE;
159 STDMETHOD_(
LPVOID, GetBufferPointer)(THIS) PURE;
160 STDMETHOD_(
DWORD, GetBufferSize)(THIS) PURE;
173 static void PrintShaderData(LPDWORD shader_data,
DWORD shader_size)
175 OutputDebugStringA(
"const DWORD shader_data[] = {\n\t");
179 for (i = 0; i < shader_size /
sizeof(
DWORD); ++
i) {
186 OutputDebugStringA(
",\n ");
189 OutputDebugStringA(
", ");
192 SDL_snprintf(dword,
sizeof(dword),
"0x%8.8x", shader_data[i]);
193 OutputDebugStringA(dword);
195 OutputDebugStringA(
"\n};\n");
213 const Uint8 *Yplane,
int Ypitch,
214 const Uint8 *Uplane,
int Upitch,
215 const Uint8 *Vplane,
int Vpitch);
223 static int D3D_RenderDrawPoints(
SDL_Renderer * renderer,
239 static void D3D_DestroyRenderer(
SDL_Renderer * renderer);
299 error =
"WRONGTEXTUREFORMAT";
302 error =
"UNSUPPORTEDCOLOROPERATION";
305 error =
"UNSUPPORTEDCOLORARG";
308 error =
"UNSUPPORTEDALPHAOPERATION";
311 error =
"UNSUPPORTEDALPHAARG";
314 error =
"TOOMANYOPERATIONS";
317 error =
"CONFLICTINGTEXTUREFILTER";
320 error =
"UNSUPPORTEDFACTORVALUE";
323 error =
"CONFLICTINGRENDERSTATE";
326 error =
"UNSUPPORTEDTEXTUREFILTER";
329 error =
"CONFLICTINGTEXTUREPALETTE";
332 error =
"DRIVERINTERNALERROR";
341 error =
"DEVICELOST";
344 error =
"DEVICENOTRESET";
347 error =
"NOTAVAILABLE";
350 error =
"OUTOFVIDEOMEMORY";
353 error =
"INVALIDDEVICE";
356 error =
"INVALIDCALL";
359 error =
"DRIVERINVALIDCALL";
362 error =
"WASSTILLDRAWING";
405 D3D_InitRenderState(D3D_RenderData *
data)
434 if (data->enableSeparateAlphaBlend) {
445 matrix.
m[0][0] = 1.0f;
446 matrix.
m[0][1] = 0.0f;
447 matrix.
m[0][2] = 0.0f;
448 matrix.
m[0][3] = 0.0f;
449 matrix.
m[1][0] = 0.0f;
450 matrix.
m[1][1] = 1.0f;
451 matrix.
m[1][2] = 0.0f;
452 matrix.
m[1][3] = 0.0f;
453 matrix.
m[2][0] = 0.0f;
454 matrix.
m[2][1] = 0.0f;
455 matrix.
m[2][2] = 1.0f;
456 matrix.
m[2][3] = 0.0f;
457 matrix.
m[3][0] = 0.0f;
458 matrix.
m[3][1] = 0.0f;
459 matrix.
m[3][2] = 0.0f;
460 matrix.
m[3][3] = 1.0f;
465 SDL_memset(data->scaleMode, 0xFF,
sizeof(data->scaleMode));
474 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
478 if (data->defaultRenderTarget) {
480 data->defaultRenderTarget =
NULL;
484 if (FAILED(result)) {
489 return D3D_SetError(
"Reset()", result);
494 D3D_InitRenderState(data);
495 D3D_UpdateViewport(renderer);
502 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
505 if (data->updateSize) {
510 data->pparams.BackBufferWidth =
w;
511 data->pparams.BackBufferHeight =
h;
513 data->pparams.BackBufferFormat =
518 if (D3D_Reset(renderer) < 0) {
524 if (data->beginScene) {
527 if (D3D_Reset(renderer) < 0) {
532 if (FAILED(result)) {
533 return D3D_SetError(
"BeginScene()", result);
544 D3D_RenderData *
data;
556 char d3dxDLLFile[50];
565 data = (D3D_RenderData *)
SDL_calloc(1,
sizeof(*data));
573 for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
575 SDL_snprintf(d3dxDLLFile,
sizeof(d3dxDLLFile),
"D3DX9_%02d.dll", d3dxVersion);
577 data->d3dxDLL = (
void *)LoadLibrary(dllName);
589 if (!data->matrixStack) {
594 if (!data->d3d || !data->matrixStack) {
620 renderer->
info = D3D_RenderDriver.
info;
636 if (window_flags & SDL_WINDOW_FULLSCREEN) {
638 PixelFormatToD3DFMT(fullscreen_mode.
format);
645 if (window_flags & SDL_WINDOW_FULLSCREEN) {
666 data->adapter = SDL_Direct3D9GetAdapterIndex( displayIndex );
686 &pparams, &data->device);
687 if (FAILED(result)) {
688 D3D_DestroyRenderer(renderer);
689 D3D_SetError(
"CreateDevice()", result);
695 if (FAILED(result)) {
696 D3D_DestroyRenderer(renderer);
697 D3D_SetError(
"GetSwapChain()", result);
701 if (FAILED(result)) {
703 D3D_DestroyRenderer(renderer);
704 D3D_SetError(
"GetPresentParameters()", result);
711 data->pparams = pparams;
721 data->enableSeparateAlphaBlend =
SDL_TRUE;
726 data->currentRenderTarget =
NULL;
729 D3D_InitRenderState(data);
733 #ifdef ASSEMBLE_SHADER
794 const char *shader_text =
796 "def c0, -0.0625, -0.5, -0.5, 1\n"
797 "def c1, 1.16400003, 0, 1.59599996, 0\n"
798 "def c2, 1.16400003, -0.391000003, -0.813000023, 0\n"
799 "def c3, 1.16400003, 2.01799989, 0, 0\n"
810 "add r0.xyz, r0, c0\n"
813 "dp2add r1.z, r0, c3, c3.z\n"
820 LPDWORD shader_data =
NULL;
821 DWORD shader_size = 0;
823 if (!FAILED(result)) {
824 shader_data = (
DWORD*)pCode->lpVtbl->GetBufferPointer(pCode);
825 shader_size = pCode->lpVtbl->GetBufferSize(pCode);
826 PrintShaderData(shader_data, shader_size);
828 const char *error = (
const char *)pErrorMsgs->lpVtbl->GetBufferPointer(pErrorMsgs);
832 const DWORD shader_data[] = {
833 0xffff0200, 0x05000051, 0xa00f0000, 0xbd800000, 0xbf000000, 0xbf000000,
834 0x3f800000, 0x05000051, 0xa00f0001, 0x3f94fdf4, 0x00000000, 0x3fcc49ba,
835 0x00000000, 0x05000051, 0xa00f0002, 0x3f94fdf4, 0xbec83127, 0xbf5020c5,
836 0x00000000, 0x05000051, 0xa00f0003, 0x3f94fdf4, 0x400126e9, 0x00000000,
837 0x00000000, 0x0200001f, 0x80000000, 0xb0030000, 0x0200001f, 0x80000000,
838 0x900f0000, 0x0200001f, 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000,
839 0xa00f0801, 0x0200001f, 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000,
840 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
841 0x03000042, 0x800f0002, 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000,
842 0x80000001, 0x02000001, 0x80040000, 0x80000002, 0x03000002, 0x80070000,
843 0x80e40000, 0xa0e40000, 0x03000008, 0x80010001, 0x80e40000, 0xa0e40001,
844 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
845 0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000,
846 0x03000005, 0x800f0000, 0x80e40001, 0x90e40000, 0x02000001, 0x800f0800,
847 0x80e40000, 0x0000ffff
850 if (shader_data !=
NULL) {
852 if (!FAILED(result)) {
856 D3D_SetError(
"CreatePixelShader()", result);
867 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
879 if (!hint || *hint ==
'0' ||
SDL_strcasecmp(hint,
"nearest") == 0) {
889 D3D_RenderData *renderdata = (D3D_RenderData *) renderer->
driverdata;
890 D3D_TextureData *data;
895 data = (D3D_TextureData *)
SDL_calloc(1,
sizeof(*data));
903 #ifdef USE_DYNAMIC_TEXTURE
921 PixelFormatToD3DFMT(texture->
format),
922 pool, &data->texture,
NULL);
923 if (FAILED(result)) {
924 return D3D_SetError(
"CreateTexture()", result);
934 PixelFormatToD3DFMT(texture->
format),
935 pool, &data->utexture,
NULL);
936 if (FAILED(result)) {
937 return D3D_SetError(
"CreateTexture()", result);
943 PixelFormatToD3DFMT(texture->
format),
944 pool, &data->vtexture,
NULL);
945 if (FAILED(result)) {
946 return D3D_SetError(
"CreateTexture()", result);
967 d3drect.right = x +
w;
969 d3drect.bottom = y +
h;
973 if (FAILED(result)) {
974 return D3D_SetError(
"LockRect()", result);
977 src = (
const Uint8 *)pixels;
980 if (length == pitch && length == locked.
Pitch) {
983 for (row = 0; row <
h; ++
row) {
996 const SDL_Rect * rect,
const void *pixels,
int pitch)
998 D3D_TextureData *data = (D3D_TextureData *) texture->
driverdata;
1001 #ifdef USE_DYNAMIC_TEXTURE
1003 rect->
x == 0 && rect->
y == 0 &&
1004 rect->
w == texture->
w && rect->
h == texture->
h) {
1009 if (D3D_UpdateTextureInternal(data->texture, texture->
format, full_texture, rect->
x, rect->
y, rect->
w, rect->
h, pixels, pitch) < 0) {
1015 pixels = (
const void*)((
const Uint8*)pixels + rect->
h * pitch);
1017 if (D3D_UpdateTextureInternal(texture->
format ==
SDL_PIXELFORMAT_YV12 ? data->vtexture : data->utexture, texture->
format, full_texture, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, pixels, pitch / 2) < 0) {
1022 pixels = (
const void*)((
const Uint8*)pixels + (rect->
h * pitch)/4);
1023 if (D3D_UpdateTextureInternal(texture->
format ==
SDL_PIXELFORMAT_YV12 ? data->utexture : data->vtexture, texture->
format, full_texture, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, pixels, pitch / 2) < 0) {
1033 const Uint8 *Yplane,
int Ypitch,
1034 const Uint8 *Uplane,
int Upitch,
1035 const Uint8 *Vplane,
int Vpitch)
1037 D3D_TextureData *data = (D3D_TextureData *) texture->
driverdata;
1040 #ifdef USE_DYNAMIC_TEXTURE
1042 rect->
x == 0 && rect->
y == 0 &&
1043 rect->
w == texture->
w && rect->
h == texture->
h) {
1048 if (D3D_UpdateTextureInternal(data->texture, texture->
format, full_texture, rect->
x, rect->
y, rect->
w, rect->
h, Yplane, Ypitch) < 0) {
1051 if (D3D_UpdateTextureInternal(data->utexture, texture->
format, full_texture, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Uplane, Upitch) < 0) {
1054 if (D3D_UpdateTextureInternal(data->vtexture, texture->
format, full_texture, rect->
x / 2, rect->
y / 2, rect->
w / 2, rect->
h / 2, Vplane, Vpitch) < 0) {
1062 const SDL_Rect * rect,
void **pixels,
int *pitch)
1064 D3D_TextureData *data = (D3D_TextureData *) texture->
driverdata;
1071 if (!data->pixels) {
1072 data->pitch = texture->
w;
1074 if (!data->pixels) {
1078 data->locked_rect = *rect;
1080 (
void *) ((
Uint8 *) data->pixels + rect->
y * data->pitch +
1082 *pitch = data->pitch;
1084 d3drect.left = rect->
x;
1085 d3drect.right = rect->
x + rect->
w;
1086 d3drect.top = rect->
y;
1087 d3drect.bottom = rect->
y + rect->
h;
1090 if (FAILED(result)) {
1091 return D3D_SetError(
"LockRect()", result);
1093 *pixels = locked.
pBits;
1094 *pitch = locked.
Pitch;
1102 D3D_TextureData *data = (D3D_TextureData *) texture->
driverdata;
1105 const SDL_Rect *rect = &data->locked_rect;
1107 (
void *) ((
Uint8 *) data->pixels + rect->
y * data->pitch +
1109 D3D_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
1118 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1119 D3D_TextureData *texturedata;
1122 D3D_ActivateRenderer(renderer);
1125 if (data->currentRenderTarget !=
NULL) {
1127 data->currentRenderTarget =
NULL;
1130 if (texture ==
NULL) {
1135 texturedata = (D3D_TextureData *) texture->
driverdata;
1137 if(FAILED(result)) {
1138 return D3D_SetError(
"GetSurfaceLevel()", result);
1141 if(FAILED(result)) {
1142 return D3D_SetError(
"SetRenderTarget()", result);
1151 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1160 viewport.MinZ = 0.0f;
1161 viewport.MaxZ = 1.0f;
1166 matrix.
m[0][0] = 2.0f / renderer->
viewport.
w;
1167 matrix.
m[0][1] = 0.0f;
1168 matrix.
m[0][2] = 0.0f;
1169 matrix.
m[0][3] = 0.0f;
1170 matrix.
m[1][0] = 0.0f;
1171 matrix.
m[1][1] = -2.0f / renderer->
viewport.
h;
1172 matrix.
m[1][2] = 0.0f;
1173 matrix.
m[1][3] = 0.0f;
1174 matrix.
m[2][0] = 0.0f;
1175 matrix.
m[2][1] = 0.0f;
1176 matrix.
m[2][2] = 1.0f;
1177 matrix.
m[2][3] = 0.0f;
1178 matrix.
m[3][0] = -1.0f;
1179 matrix.
m[3][1] = 1.0f;
1180 matrix.
m[3][2] = 0.0f;
1181 matrix.
m[3][3] = 1.0f;
1192 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1200 r.right = rect->
x + rect->
w;
1201 r.bottom = rect->
y + rect->
h;
1205 D3D_SetError(
"SetScissor()", result);
1217 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1221 if (D3D_ActivateRenderer(renderer) < 0) {
1229 renderer->
viewport.
w == data->pparams.BackBufferWidth &&
1230 renderer->
viewport.
h == data->pparams.BackBufferHeight) {
1238 viewport.
Width = data->pparams.BackBufferWidth;
1239 viewport.
Height = data->pparams.BackBufferHeight;
1240 viewport.
MinZ = 0.0f;
1241 viewport.
MaxZ = 1.0f;
1251 viewport.
MinZ = 0.0f;
1252 viewport.
MaxZ = 1.0f;
1256 if (FAILED(result)) {
1257 return D3D_SetError(
"Clear()", result);
1263 D3D_SetBlendMode(D3D_RenderData * data,
int blendMode)
1265 switch (blendMode) {
1277 if (data->enableSeparateAlphaBlend) {
1291 if (data->enableSeparateAlphaBlend) {
1305 if (data->enableSeparateAlphaBlend) {
1319 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1325 if (D3D_ActivateRenderer(renderer) < 0) {
1329 D3D_SetBlendMode(data, renderer->
blendMode);
1334 if (FAILED(result)) {
1335 return D3D_SetError(
"SetTexture()", result);
1341 for (i = 0; i <
count; ++
i) {
1353 if (FAILED(result)) {
1354 return D3D_SetError(
"DrawPrimitiveUP()", result);
1363 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1369 if (D3D_ActivateRenderer(renderer) < 0) {
1373 D3D_SetBlendMode(data, renderer->
blendMode);
1378 if (FAILED(result)) {
1379 return D3D_SetError(
"SetTexture()", result);
1385 for (i = 0; i <
count; ++
i) {
1400 points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
1407 if (FAILED(result)) {
1408 return D3D_SetError(
"DrawPrimitiveUP()", result);
1417 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1420 float minx, miny, maxx, maxy;
1424 if (D3D_ActivateRenderer(renderer) < 0) {
1428 D3D_SetBlendMode(data, renderer->
blendMode);
1433 if (FAILED(result)) {
1434 return D3D_SetError(
"SetTexture()", result);
1439 for (i = 0; i <
count; ++
i) {
1444 maxx = rect->
x + rect->
w;
1445 maxy = rect->
y + rect->
h;
1478 if (FAILED(result)) {
1479 return D3D_SetError(
"DrawPrimitiveUP()", result);
1486 D3D_UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata,
unsigned index)
1488 if (texturedata->scaleMode != data->scaleMode[index]) {
1490 texturedata->scaleMode);
1492 texturedata->scaleMode);
1493 data->scaleMode[
index] = texturedata->scaleMode;
1501 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1502 D3D_TextureData *texturedata = (D3D_TextureData *) texture->
driverdata;
1504 float minx, miny, maxx, maxy;
1510 if (D3D_ActivateRenderer(renderer) < 0) {
1514 minx = dstrect->
x - 0.5f;
1515 miny = dstrect->
y - 0.5f;
1516 maxx = dstrect->
x + dstrect->
w - 0.5f;
1517 maxy = dstrect->
y + dstrect->
h - 0.5f;
1519 minu = (float) srcrect->
x / texture->
w;
1520 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
1521 minv = (
float) srcrect->
y / texture->
h;
1522 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
1526 vertices[0].x = minx;
1527 vertices[0].y = miny;
1528 vertices[0].z = 0.0f;
1529 vertices[0].color =
color;
1530 vertices[0].u =
minu;
1531 vertices[0].v = minv;
1533 vertices[1].x = maxx;
1534 vertices[1].y = miny;
1535 vertices[1].z = 0.0f;
1536 vertices[1].color =
color;
1537 vertices[1].u =
maxu;
1538 vertices[1].v = minv;
1540 vertices[2].x = maxx;
1541 vertices[2].y = maxy;
1542 vertices[2].z = 0.0f;
1543 vertices[2].color =
color;
1544 vertices[2].u =
maxu;
1545 vertices[2].v = maxv;
1547 vertices[3].x = minx;
1548 vertices[3].y = maxy;
1549 vertices[3].z = 0.0f;
1550 vertices[3].color =
color;
1551 vertices[3].u =
minu;
1552 vertices[3].v = maxv;
1554 D3D_SetBlendMode(data, texture->
blendMode);
1556 D3D_UpdateTextureScaleMode(data, texturedata, 0);
1560 texturedata->texture);
1561 if (FAILED(result)) {
1562 return D3D_SetError(
"SetTexture()", result);
1565 if (texturedata->yuv) {
1566 shader = data->ps_yuv;
1568 D3D_UpdateTextureScaleMode(data, texturedata, 1);
1569 D3D_UpdateTextureScaleMode(data, texturedata, 2);
1573 texturedata->utexture);
1574 if (FAILED(result)) {
1575 return D3D_SetError(
"SetTexture()", result);
1580 texturedata->vtexture);
1581 if (FAILED(result)) {
1582 return D3D_SetError(
"SetTexture()", result);
1588 if (FAILED(result)) {
1589 return D3D_SetError(
"SetShader()", result);
1594 vertices,
sizeof(*vertices));
1595 if (FAILED(result)) {
1596 return D3D_SetError(
"DrawPrimitiveUP()", result);
1600 if (FAILED(result)) {
1601 return D3D_SetError(
"SetShader()", result);
1613 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1614 D3D_TextureData *texturedata = (D3D_TextureData *) texture->
driverdata;
1616 float minx, miny, maxx, maxy;
1618 float centerx, centery;
1623 if (D3D_ActivateRenderer(renderer) < 0) {
1627 centerx = center->
x;
1628 centery = center->
y;
1631 minx = dstrect->
w - centerx - 0.5f;
1632 maxx = -centerx - 0.5f;
1635 minx = -centerx - 0.5f;
1636 maxx = dstrect->
w - centerx - 0.5f;
1640 miny = dstrect->
h - centery - 0.5f;
1641 maxy = -centery - 0.5f;
1644 miny = -centery - 0.5f;
1645 maxy = dstrect->
h - centery - 0.5f;
1648 minu = (float) srcrect->
x / texture->
w;
1649 maxu = (
float) (srcrect->
x + srcrect->
w) / texture->
w;
1650 minv = (
float) srcrect->
y / texture->
h;
1651 maxv = (float) (srcrect->
y + srcrect->
h) / texture->
h;
1655 vertices[0].x = minx;
1656 vertices[0].y = miny;
1657 vertices[0].z = 0.0f;
1658 vertices[0].color =
color;
1659 vertices[0].u =
minu;
1660 vertices[0].v = minv;
1662 vertices[1].x = maxx;
1663 vertices[1].y = miny;
1664 vertices[1].z = 0.0f;
1665 vertices[1].color =
color;
1666 vertices[1].u =
maxu;
1667 vertices[1].v = minv;
1669 vertices[2].x = maxx;
1670 vertices[2].y = maxy;
1671 vertices[2].z = 0.0f;
1672 vertices[2].color =
color;
1673 vertices[2].u =
maxu;
1674 vertices[2].v = maxv;
1676 vertices[3].x = minx;
1677 vertices[3].y = maxy;
1678 vertices[3].z = 0.0f;
1679 vertices[3].color =
color;
1680 vertices[3].u =
minu;
1681 vertices[3].v = maxv;
1683 D3D_SetBlendMode(data, texture->
blendMode);
1686 ID3DXMatrixStack_Push(data->matrixStack);
1687 ID3DXMatrixStack_LoadIdentity(data->matrixStack);
1688 ID3DXMatrixStack_RotateYawPitchRoll(data->matrixStack, 0.0, 0.0, (
float)(
M_PI * (
float) angle / 180.0f));
1689 ID3DXMatrixStack_Translate(data->matrixStack, (
float)dstrect->
x + centerx, (
float)dstrect->
y + centery, (
float)0.0);
1692 D3D_UpdateTextureScaleMode(data, texturedata, 0);
1696 texturedata->texture);
1697 if (FAILED(result)) {
1698 return D3D_SetError(
"SetTexture()", result);
1701 if (texturedata->yuv) {
1702 shader = data->ps_yuv;
1704 D3D_UpdateTextureScaleMode(data, texturedata, 1);
1705 D3D_UpdateTextureScaleMode(data, texturedata, 2);
1709 texturedata->utexture);
1710 if (FAILED(result)) {
1711 return D3D_SetError(
"SetTexture()", result);
1716 texturedata->vtexture);
1717 if (FAILED(result)) {
1718 return D3D_SetError(
"SetTexture()", result);
1724 if (FAILED(result)) {
1725 return D3D_SetError(
"SetShader()", result);
1730 vertices,
sizeof(*vertices));
1731 if (FAILED(result)) {
1732 return D3D_SetError(
"DrawPrimitiveUP()", result);
1736 if (FAILED(result)) {
1737 return D3D_SetError(
"SetShader()", result);
1740 ID3DXMatrixStack_Pop(data->matrixStack);
1741 ID3DXMatrixStack_Push(data->matrixStack);
1742 ID3DXMatrixStack_LoadIdentity(data->matrixStack);
1744 ID3DXMatrixStack_Pop(data->matrixStack);
1750 Uint32 format,
void * pixels,
int pitch)
1752 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1761 if (FAILED(result)) {
1762 return D3D_SetError(
"GetBackBuffer()", result);
1766 if (FAILED(result)) {
1768 return D3D_SetError(
"GetDesc()", result);
1772 if (FAILED(result)) {
1774 return D3D_SetError(
"CreateOffscreenPlainSurface()", result);
1778 if (FAILED(result)) {
1781 return D3D_SetError(
"GetRenderTargetData()", result);
1784 d3drect.left = rect->
x;
1785 d3drect.right = rect->
x + rect->
w;
1786 d3drect.top = rect->
y;
1787 d3drect.bottom = rect->
y + rect->
h;
1790 if (FAILED(result)) {
1793 return D3D_SetError(
"LockRect()", result);
1797 D3DFMTToPixelFormat(desc.Format), locked.
pBits, locked.
Pitch,
1798 format, pixels, pitch);
1811 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1814 if (!data->beginScene) {
1825 D3D_Reset(renderer);
1828 if (FAILED(result)) {
1829 D3D_SetError(
"Present()", result);
1836 D3D_TextureData *data = (D3D_TextureData *) texture->
driverdata;
1841 if (data->texture) {
1844 if (data->utexture) {
1847 if (data->vtexture) {
1858 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1862 if (data->defaultRenderTarget) {
1864 data->defaultRenderTarget =
NULL;
1866 if (data->currentRenderTarget !=
NULL) {
1868 data->currentRenderTarget =
NULL;
1878 ID3DXMatrixStack_Release(data->matrixStack);
1889 D3D_RenderData *data = (D3D_RenderData *) renderer->
driverdata;
1898 device = data->device;
#define IDirect3DDevice9_SetTextureStageState(p, a, b, c)
#define IDirect3D9_CreateDevice(p, a, b, c, d, e, f)
int(* UpdateClipRect)(SDL_Renderer *renderer)
#define IDirect3DTexture9_UnlockRect(p, a)
#define IDirect3DSurface9_Release(p)
struct IDirect3D9 IDirect3D9
DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info)
This function allows access to driver-dependent window information.
#define D3DERR_DEVICELOST
#define WIN_UTF8ToString(S)
#define D3DERR_OUTOFVIDEOMEMORY
struct _D3DVECTOR * LPD3DXVECTOR3
#define IDirect3DDevice9_Clear(p, a, b, c, d, e, f)
#define IDirect3DDevice9_GetBackBuffer(p, a, b, c, d)
#define D3DERR_DRIVERINVALIDCALL
GLfloat GLfloat GLfloat GLfloat h
D3DFORMAT BackBufferFormat
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Copy a block of pixels of one format to another format.
#define IDirect3DTexture9_GetSurfaceLevel(p, a, b)
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
int(* RenderClear)(SDL_Renderer *renderer)
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
#define SDL_stack_free(data)
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
#define D3DCOLOR_ARGB(a, r, g, b)
#define D3DERR_UNSUPPORTEDFACTORVALUE
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
#define IDirect3DTexture9_Release(p)
#define IDirect3DDevice9_SetViewport(p, a)
HRESULT WINAPI D3DXAssembleShader(LPCSTR pSrcData, UINT SrcDataLen, CONST D3DXMACRO *pDefines, LPD3DXINCLUDE pInclude, DWORD Flags, LPD3DXBUFFER *ppShader, LPD3DXBUFFER *ppErrorMsgs)
#define IDirect3DPixelShader9_Release(p)
#define D3DERR_UNSUPPORTEDCOLORARG
#define D3DERR_TOOMANYOPERATIONS
interface IDirect3DSwapChain9 IDirect3DSwapChain9
DECLSPEC void SDLCALL SDL_free(void *mem)
Uint32 texture_formats[16]
The structure that defines a display mode.
#define SDL_BYTESPERPIXEL(X)
DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
Get the size of a window's client area.
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
#define IDirect3DDevice9_SetFVF(p, a)
#define D3DERR_NOTAVAILABLE
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
DECLARE_INTERFACE_(IXAudio2, IUnknown)
#define IDirect3DDevice9_SetRenderTarget(p, a, b)
DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window *window, SDL_DisplayMode *mode)
Fill in information about the display mode used when a fullscreen window is visible.
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
#define IDirect3D9_Release(p)
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
#define D3DERR_UNSUPPORTEDTEXTUREFILTER
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING
interface IDirect3DSurface9 IDirect3DSurface9
#define IDirect3DDevice9_SetScissorRect(p, a)
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
uint32_t Uint32
An unsigned 32-bit integer type.
struct IDirect3DPixelShader9 * LPDIRECT3DPIXELSHADER9
DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window *window)
Get the pixel format associated with the window.
#define IDirect3DDevice9_Release(p)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
#define IDirect3DSwapChain9_Release(p)
enum _D3DFORMAT D3DFORMAT
#define IDirect3DSwapChain9_GetPresentParameters(p, a)
GLenum GLenum GLvoid * row
#define D3DUSAGE_RENDERTARGET
#define D3DERR_CONFLICTINGTEXTUREPALETTE
int(* UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)
UINT PresentationInterval
UINT FullScreen_RefreshRateInHz
#define IDirect3DDevice9_GetRenderTarget(p, a, b)
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
struct _D3DMATRIX * LPD3DXMATRIX
#define D3DERR_CONFLICTINGTEXTUREFILTER
#define IDirect3DDevice9_EndScene(p)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
#define IDirect3DDevice9_SetPixelShader(p, a)
#define D3DCREATE_FPU_PRESERVE
static int GetScaleQuality(void)
#define D3DERR_DRIVERINTERNALERROR
#define IDirect3DDevice9_Reset(p, a)
#define D3DPMISCCAPS_SEPARATEALPHABLEND
#define D3DERR_WASSTILLDRAWING
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
#define D3DERR_UNSUPPORTEDALPHAOPERATION
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
enum _D3DTEXTUREFILTERTYPE D3DTEXTUREFILTERTYPE
DECLSPEC void SDLCALL SDL_UnloadObject(void *handle)
DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
interface ID3DXMatrixStack * LPD3DXMATRIXSTACK
#define D3DERR_UNSUPPORTEDALPHAARG
DECLSPEC int SDLCALL SDL_GetWindowDisplayIndex(SDL_Window *window)
Get the display index associated with a window.
#define IDirect3DDevice9_AddRef(p)
DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
#define D3DPRESENT_INTERVAL_ONE
DECLSPEC const char *SDLCALL SDL_GetHint(const char *name)
Get a hint.
#define D3DCREATE_MULTITHREADED
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
#define D3DERR_INVALIDDEVICE
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
union SDL_SysWMinfo::@78 info
HRESULT WINAPI D3DXCreateMatrixStack(DWORD Flags, LPD3DXMATRIXSTACK *ppStack)
#define IDirect3DDevice9_SetTransform(p, a, b)
static __inline ALuint minu(ALuint a, ALuint b)
SDL_bool D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
#define D3DERR_WRONGTEXTUREFORMAT
#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE
A variable controlling whether the Direct3D device is initialized for thread-safe operations...
typedef LPVOID(WINAPI *PFNWGLCREATEIMAGEBUFFERI3DPROC)(HDC hDC
Window state change event data (event.window.*)
#define IDirect3D9_GetDeviceCaps(p, a, b, c)
GLuint GLfloat GLfloat GLfloat x1
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
#define IDirect3DDevice9_CreatePixelShader(p, a, b)
EGLSurface EGLint EGLint y
#define IDirect3DSurface9_GetDesc(p, a)
#define SDL_OutOfMemory()
interface ID3DXMatrixStack ID3DXMatrixStack
#define IDirect3DDevice9_SetVertexShader(p, a)
GLenum GLenum GLuint texture
#define D3DDEVCAPS_HWTRANSFORMANDLIGHT
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
#define IDirect3DDevice9_SetRenderState(p, a, b)
#define D3DCREATE_HARDWARE_VERTEXPROCESSING
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
#define IDirect3DDevice9_SetTexture(p, a, b)
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
#define IDirect3DDevice9_CreateTexture(p, a, b, c, d, e, f, g, h)
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
uint8_t Uint8
An unsigned 8-bit integer type.
DECLSPEC int SDLCALL SDL_atoi(const char *str)
#define IDirect3DDevice9_GetDeviceCaps(p, a)
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
#define IDirect3DDevice9_GetRenderTargetData(p, a, b)
#define IDirect3DDevice9_TestCooperativeLevel(p)
interface IDirect3DDevice9 IDirect3DDevice9
DWORD MaxSimultaneousTextures
interface IDirect3DTexture9 IDirect3DTexture9
#define IDirect3DDevice9_GetSwapChain(p, a, b)
#define D3DERR_UNSUPPORTEDCOLOROPERATION
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint z
Uint32 num_texture_formats
interface ID3DXBuffer * LPD3DXBUFFER
#define D3DERR_INVALIDCALL
#define IDirect3DSurface9_UnlockRect(p)
GLint GLint GLint GLint GLint w
#define D3DERR_DEVICENOTRESET
#define SDL_stack_alloc(type, count)
int(* UpdateViewport)(SDL_Renderer *renderer)
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
#define IDirect3DTexture9_LockRect(p, a, b, c, d)
interface IDirect3DBaseTexture9 IDirect3DBaseTexture9
#define D3DPRESENT_INTERVAL_IMMEDIATE
int(* RenderCopyEx)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
void(* RenderPresent)(SDL_Renderer *renderer)
DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, const char *name)
void(* DestroyRenderer)(SDL_Renderer *renderer)
#define IDirect3DDevice9_Present(p, a, b, c, d)
#define IDirect3DSurface9_LockRect(p, a, b, c)
struct IDirect3DSurface9 * LPDIRECT3DSURFACE9
GLsizeiptr const GLvoid GLenum usage
#define IDirect3DDevice9_DrawPrimitiveUP(p, a, b, c, d)
#define IDirect3DDevice9_SetSamplerState(p, a, b, c)
DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2)
static __inline ALuint maxu(ALuint a, ALuint b)
#define IDirect3DDevice9_BeginScene(p)
A rectangle, with the origin at the upper left.
interface ID3DXBuffer ID3DXBuffer
#define D3DERR_CONFLICTINGRENDERSTATE