21#include "../../SDL_internal.h"
26#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
28#include "../../core/windows/SDL_windows.h"
35#include "../SDL_sysrender.h"
36#include "../SDL_d3dmath.h"
37#include "../../video/windows/SDL_windowsvideo.h"
39#if SDL_VIDEO_RENDER_D3D
57 LPDIRECT3DPIXELSHADER9
shader;
69 D3DPRESENT_PARAMETERS pparams;
73 D3DTEXTUREFILTERTYPE scaleMode[8];
74 IDirect3DSurface9 *defaultRenderTarget;
75 IDirect3DSurface9 *currentRenderTarget;
78 LPDIRECT3DVERTEXBUFFER9 vertexBuffers[8];
79 size_t vertexBufferSize[8];
80 int currentVertexBuffer;
82 D3D_DrawStateCache drawstate;
93 IDirect3DTexture9 *staging;
99 D3DTEXTUREFILTERTYPE scaleMode;
103 D3D_TextureRep utexture;
104 D3D_TextureRep vtexture;
118D3D_SetError(
const char *prefix, HRESULT
result)
123 case D3DERR_WRONGTEXTUREFORMAT:
124 error =
"WRONGTEXTUREFORMAT";
126 case D3DERR_UNSUPPORTEDCOLOROPERATION:
127 error =
"UNSUPPORTEDCOLOROPERATION";
129 case D3DERR_UNSUPPORTEDCOLORARG:
130 error =
"UNSUPPORTEDCOLORARG";
132 case D3DERR_UNSUPPORTEDALPHAOPERATION:
133 error =
"UNSUPPORTEDALPHAOPERATION";
135 case D3DERR_UNSUPPORTEDALPHAARG:
136 error =
"UNSUPPORTEDALPHAARG";
138 case D3DERR_TOOMANYOPERATIONS:
139 error =
"TOOMANYOPERATIONS";
141 case D3DERR_CONFLICTINGTEXTUREFILTER:
142 error =
"CONFLICTINGTEXTUREFILTER";
144 case D3DERR_UNSUPPORTEDFACTORVALUE:
145 error =
"UNSUPPORTEDFACTORVALUE";
147 case D3DERR_CONFLICTINGRENDERSTATE:
148 error =
"CONFLICTINGRENDERSTATE";
150 case D3DERR_UNSUPPORTEDTEXTUREFILTER:
151 error =
"UNSUPPORTEDTEXTUREFILTER";
153 case D3DERR_CONFLICTINGTEXTUREPALETTE:
154 error =
"CONFLICTINGTEXTUREPALETTE";
156 case D3DERR_DRIVERINTERNALERROR:
157 error =
"DRIVERINTERNALERROR";
159 case D3DERR_NOTFOUND:
162 case D3DERR_MOREDATA:
165 case D3DERR_DEVICELOST:
166 error =
"DEVICELOST";
168 case D3DERR_DEVICENOTRESET:
169 error =
"DEVICENOTRESET";
171 case D3DERR_NOTAVAILABLE:
172 error =
"NOTAVAILABLE";
174 case D3DERR_OUTOFVIDEOMEMORY:
175 error =
"OUTOFVIDEOMEMORY";
177 case D3DERR_INVALIDDEVICE:
178 error =
"INVALIDDEVICE";
180 case D3DERR_INVALIDCALL:
181 error =
"INVALIDCALL";
183 case D3DERR_DRIVERINVALIDCALL:
184 error =
"DRIVERINVALIDCALL";
186 case D3DERR_WASSTILLDRAWING:
187 error =
"WASSTILLDRAWING";
201 return D3DFMT_R5G6B5;
203 return D3DFMT_X8R8G8B8;
205 return D3DFMT_A8R8G8B8;
212 return D3DFMT_UNKNOWN;
217D3DFMTToPixelFormat(D3DFORMAT
format)
222 case D3DFMT_X8R8G8B8:
224 case D3DFMT_A8R8G8B8:
232D3D_InitRenderState(D3D_RenderData *
data)
237 IDirect3DDevice9_SetFVF(
device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
238 IDirect3DDevice9_SetVertexShader(
device,
NULL);
239 IDirect3DDevice9_SetRenderState(
device, D3DRS_ZENABLE, D3DZB_FALSE);
240 IDirect3DDevice9_SetRenderState(
device, D3DRS_CULLMODE, D3DCULL_NONE);
241 IDirect3DDevice9_SetRenderState(
device, D3DRS_LIGHTING,
FALSE);
244 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLOROP,
246 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLORARG1,
248 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLORARG2,
252 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAOP,
254 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAARG1,
256 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAARG2,
260 if (
data->enableSeparateAlphaBlend) {
261 IDirect3DDevice9_SetRenderState(
device, D3DRS_SEPARATEALPHABLENDENABLE,
TRUE);
265 IDirect3DDevice9_SetTextureStageState(
device, 1, D3DTSS_COLOROP,
267 IDirect3DDevice9_SetTextureStageState(
device, 1, D3DTSS_ALPHAOP,
276 IDirect3DDevice9_SetTransform(
device, D3DTS_WORLD, &
matrix);
277 IDirect3DDevice9_SetTransform(
device, D3DTS_VIEW, &
matrix);
294 if (
data->updateSize) {
300 data->pparams.BackBufferWidth =
w;
301 data->pparams.BackBufferHeight =
h;
306 data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.
format);
310 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
311 data->pparams.FullScreen_RefreshRateInHz = 0;
319 if (
data->beginScene) {
320 result = IDirect3DDevice9_BeginScene(
data->device);
321 if (
result == D3DERR_DEVICELOST) {
325 result = IDirect3DDevice9_BeginScene(
data->device);
328 return D3D_SetError(
"BeginScene()",
result);
349 return D3DBLEND_ZERO;
353 return D3DBLEND_SRCCOLOR;
355 return D3DBLEND_INVSRCCOLOR;
357 return D3DBLEND_SRCALPHA;
359 return D3DBLEND_INVSRCALPHA;
361 return D3DBLEND_DESTCOLOR;
363 return D3DBLEND_INVDESTCOLOR;
365 return D3DBLEND_DESTALPHA;
367 return D3DBLEND_INVDESTALPHA;
384 if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
385 !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor)) {
388 if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !
data->enableSeparateAlphaBlend) {
410 PixelFormatToD3DFMT(
format),
413 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
428 return D3D_SetError(
"CreateTexture(D3DPOOL_SYSTEMMEM)",
result);
438 IDirect3DTexture9_Release(
texture->texture);
442 IDirect3DTexture9_AddDirtyRect(
texture->staging,
NULL);
452 D3DLOCKED_RECT locked;
463 d3drect.right =
x +
w;
465 d3drect.bottom =
y +
h;
467 result = IDirect3DTexture9_LockRect(
texture->staging, 0, &locked, &d3drect, 0);
469 return D3D_SetError(
"LockRect()",
result);
481 if (
length > locked.Pitch) {
492 return D3D_SetError(
"UnlockRect()",
result);
500D3D_DestroyTextureRep(D3D_TextureRep *
texture)
503 IDirect3DTexture9_Release(
texture->texture);
507 IDirect3DTexture9_Release(
texture->staging);
516 D3D_TextureData *texturedata;
519 texturedata = (D3D_TextureData *)
SDL_calloc(1,
sizeof(*texturedata));
525 texture->driverdata = texturedata;
528 usage = D3DUSAGE_RENDERTARGET;
556 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
562 if (D3D_RecreateTextureRep(
data->device, &texturedata->texture) < 0) {
566 if (texturedata->yuv) {
567 if (D3D_RecreateTextureRep(
data->device, &texturedata->utexture) < 0) {
571 if (D3D_RecreateTextureRep(
data->device, &texturedata->vtexture) < 0) {
583 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
594 if (texturedata->yuv) {
614 const Uint8 *Yplane,
int Ypitch,
615 const Uint8 *Uplane,
int Upitch,
616 const Uint8 *Vplane,
int Vpitch)
619 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
626 if (D3D_UpdateTextureRep(
data->device, &texturedata->texture,
rect->
x,
rect->
y,
rect->
w,
rect->
h, Yplane, Ypitch) < 0) {
629 if (D3D_UpdateTextureRep(
data->device, &texturedata->utexture,
rect->
x / 2,
rect->
y / 2, (
rect->
w + 1) / 2, (
rect->
h + 1) / 2, Uplane, Upitch) < 0) {
632 if (D3D_UpdateTextureRep(
data->device, &texturedata->vtexture,
rect->
x / 2,
rect->
y / 2, (
rect->
w + 1) / 2, (
rect->
h + 1) / 2, Vplane, Vpitch) < 0) {
643 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
651 texturedata->locked_rect = *
rect;
653 if (texturedata->yuv) {
655 if (!texturedata->pixels) {
658 if (!texturedata->pixels) {
663 (
void *) ((
Uint8 *) texturedata->pixels +
rect->
y * texturedata->pitch +
665 *pitch = texturedata->pitch;
668 D3DLOCKED_RECT locked;
671 if (D3D_CreateStagingTexture(
device, &texturedata->texture) < 0) {
675 d3drect.left =
rect->
x;
677 d3drect.top =
rect->
y;
680 result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
682 return D3D_SetError(
"LockRect()",
result);
685 *pitch = locked.Pitch;
694 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
700 if (texturedata->yuv) {
703 (
void *) ((
Uint8 *) texturedata->pixels +
rect->
y * texturedata->pitch +
707 IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
708 texturedata->texture.dirty =
SDL_TRUE;
719 D3D_TextureData *texturedata;
720 D3D_TextureRep *texturerep;
725 if (
data->currentRenderTarget !=
NULL) {
726 IDirect3DSurface9_Release(
data->currentRenderTarget);
731 IDirect3DDevice9_SetRenderTarget(
data->device, 0,
data->defaultRenderTarget);
735 texturedata = (D3D_TextureData *)
texture->driverdata;
742 texturerep = &texturedata->texture;
743 if (texturerep->dirty && texturerep->staging) {
744 if (!texturerep->texture) {
745 result = IDirect3DDevice9_CreateTexture(
device, texturerep->w, texturerep->h, 1, texturerep->usage,
746 PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture,
NULL);
748 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
752 result = IDirect3DDevice9_UpdateTexture(
device, (IDirect3DBaseTexture9 *)texturerep->staging, (IDirect3DBaseTexture9 *)texturerep->texture);
754 return D3D_SetError(
"UpdateTexture()",
result);
759 result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &
data->currentRenderTarget);
761 return D3D_SetError(
"GetSurfaceLevel()",
result);
763 result = IDirect3DDevice9_SetRenderTarget(
data->device, 0,
data->currentRenderTarget);
765 return D3D_SetError(
"SetRenderTarget()",
result);
774 if (D3D_ActivateRenderer(
renderer) < 0) {
792 const size_t vertslen =
count *
sizeof (Vertex);
806 verts->color =
color;
816 const size_t vertslen =
count *
sizeof (Vertex) * 4;
829 const float minx =
rect->
x;
831 const float miny =
rect->
y;
836 verts->color =
color;
841 verts->color =
color;
846 verts->color =
color;
851 verts->color =
color;
863 float minx, miny, maxx, maxy;
864 float minu, maxu, minv, maxv;
865 const size_t vertslen =
sizeof (Vertex) * 4;
874 minx = dstrect->
x - 0.5f;
875 miny = dstrect->
y - 0.5f;
876 maxx = dstrect->
x + dstrect->
w - 0.5f;
877 maxy = dstrect->
y + dstrect->
h - 0.5f;
879 minu = (float) srcrect->
x /
texture->w;
880 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
881 minv = (
float) srcrect->
y /
texture->h;
882 maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
887 verts->color =
color;
895 verts->color =
color;
903 verts->color =
color;
911 verts->color =
color;
925 float minx, miny, maxx, maxy;
926 float minu, maxu, minv, maxv;
927 const size_t vertslen =
sizeof (Vertex) * 5;
937 maxx = dstrect->
w - center->
x;
939 maxy = dstrect->
h - center->
y;
942 minu = (float) (srcquad->
x + srcquad->
w) /
texture->w;
943 maxu = (float) srcquad->
x /
texture->w;
945 minu = (float) srcquad->
x /
texture->w;
946 maxu = (
float) (srcquad->
x + srcquad->
w) /
texture->w;
950 minv = (float) (srcquad->
y + srcquad->
h) /
texture->h;
951 maxv = (float) srcquad->
y /
texture->h;
953 minv = (float) srcquad->
y /
texture->h;
954 maxv = (
float) (srcquad->
y + srcquad->
h) /
texture->h;
960 verts->color =
color;
968 verts->color =
color;
976 verts->color =
color;
984 verts->color =
color;
989 verts->x = dstrect->
x + center->
x - 0.5f;
990 verts->y = dstrect->
y + center->
y - 0.5f;
991 verts->z = (float)(M_PI * (
float)
angle / 180.0f);
1009 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
1013 result = IDirect3DDevice9_UpdateTexture(
device, (IDirect3DBaseTexture9 *)
texture->staging, (IDirect3DBaseTexture9 *)
texture->texture);
1015 return D3D_SetError(
"UpdateTexture()",
result);
1029 return D3D_SetError(
"SetTexture()",
result);
1035UpdateTextureScaleMode(D3D_RenderData *
data, D3D_TextureData *texturedata,
unsigned index)
1037 if (texturedata->scaleMode !=
data->scaleMode[
index]) {
1038 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_MINFILTER,
1039 texturedata->scaleMode);
1040 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_MAGFILTER,
1041 texturedata->scaleMode);
1042 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_ADDRESSU,
1044 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_ADDRESSV,
1046 data->scaleMode[
index] = texturedata->scaleMode;
1053 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
1062 UpdateTextureScaleMode(
data, texturedata, 0);
1064 if (BindTextureRep(
data->device, &texturedata->texture, 0) < 0) {
1068 if (texturedata->yuv) {
1080 return SDL_SetError(
"Unsupported YUV conversion mode");
1083 UpdateTextureScaleMode(
data, texturedata, 1);
1084 UpdateTextureScaleMode(
data, texturedata, 2);
1086 if (BindTextureRep(
data->device, &texturedata->utexture, 1) < 0) {
1089 if (BindTextureRep(
data->device, &texturedata->vtexture, 2) < 0) {
1099 const SDL_bool was_copy_ex =
data->drawstate.is_copy_ex;
1105 D3D_TextureData *oldtexturedata =
data->drawstate.texture ? (D3D_TextureData *)
data->drawstate.texture->driverdata :
NULL;
1106 D3D_TextureData *newtexturedata =
texture ? (D3D_TextureData *)
texture->driverdata :
NULL;
1111 IDirect3DDevice9_SetTexture(
data->device, 0,
NULL);
1113 if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
1114 IDirect3DDevice9_SetTexture(
data->device, 1,
NULL);
1115 IDirect3DDevice9_SetTexture(
data->device, 2,
NULL);
1122 const HRESULT
result = IDirect3DDevice9_SetPixelShader(
data->device,
shader);
1124 return D3D_SetError(
"IDirect3DDevice9_SetPixelShader()",
result);
1131 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
1132 UpdateDirtyTexture(
data->device, &texturedata->texture);
1133 if (texturedata->yuv) {
1134 UpdateDirtyTexture(
data->device, &texturedata->utexture);
1135 UpdateDirtyTexture(
data->device, &texturedata->vtexture);
1139 if (blend !=
data->drawstate.blend) {
1141 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_ALPHABLENDENABLE,
FALSE);
1143 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
1144 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SRCBLEND,
1146 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_DESTBLEND,
1148 if (
data->enableSeparateAlphaBlend) {
1149 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SRCBLENDALPHA,
1151 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_DESTBLENDALPHA,
1156 data->drawstate.blend = blend;
1159 if (is_copy_ex != was_copy_ex) {
1161 const Float4X4 d3dmatrix = MatrixIdentity();
1162 IDirect3DDevice9_SetTransform(
data->device, D3DTS_VIEW, (D3DMATRIX*) &d3dmatrix);
1164 data->drawstate.is_copy_ex = is_copy_ex;
1167 if (
data->drawstate.viewport_dirty) {
1170 IDirect3DDevice9_SetViewport(
data->device, &d3dviewport);
1174 D3DMATRIX d3dmatrix;
1177 d3dmatrix.m[1][1] = -2.0f /
viewport->
h;
1178 d3dmatrix.m[2][2] = 1.0f;
1179 d3dmatrix.m[3][0] = -1.0f;
1180 d3dmatrix.m[3][1] = 1.0f;
1181 d3dmatrix.m[3][3] = 1.0f;
1182 IDirect3DDevice9_SetTransform(
data->device, D3DTS_PROJECTION, &d3dmatrix);
1188 if (
data->drawstate.cliprect_enabled_dirty) {
1189 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
data->drawstate.cliprect_enabled ?
TRUE :
FALSE);
1193 if (
data->drawstate.cliprect_dirty) {
1197 IDirect3DDevice9_SetScissorRect(
data->device, &d3drect);
1208 const int vboidx =
data->currentVertexBuffer;
1209 IDirect3DVertexBuffer9 *vbo =
NULL;
1213 if (D3D_ActivateRenderer(
renderer) < 0) {
1218 vbo =
data->vertexBuffers[vboidx];
1219 if (!vbo || (
data->vertexBufferSize[vboidx] < vertsize)) {
1220 const DWORD
usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
1221 const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
1223 IDirect3DVertexBuffer9_Release(vbo);
1226 if (
FAILED(IDirect3DDevice9_CreateVertexBuffer(
data->device, (UINT) vertsize,
usage, fvf, D3DPOOL_DEFAULT, &vbo,
NULL))) {
1229 data->vertexBuffers[vboidx] = vbo;
1230 data->vertexBufferSize[vboidx] = vbo ? vertsize : 0;
1235 if (
FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT) vertsize, &ptr, D3DLOCK_DISCARD))) {
1239 if (
FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
1247 data->currentVertexBuffer++;
1249 data->currentVertexBuffer = 0;
1251 }
else if (!
data->reportedVboProblem) {
1259 IDirect3DDevice9_SetStreamSource(
data->device, 0, vbo, 0, sizeof (Vertex));
1299 if (
data->drawstate.cliprect_enabled) {
1300 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
FALSE);
1306 IDirect3DDevice9_Clear(
data->device, 0,
NULL, D3DCLEAR_TARGET,
color, 0.0f, 0);
1309 const D3DVIEWPORT9 wholeviewport = { 0, 0, backw, backh, 0.0f, 1.0f };
1310 IDirect3DDevice9_SetViewport(
data->device, &wholeviewport);
1312 IDirect3DDevice9_Clear(
data->device, 0,
NULL, D3DCLEAR_TARGET,
color, 0.0f, 0);
1323 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_POINTLIST, (UINT) (
first / sizeof (Vertex)), (UINT)
count);
1325 const Vertex *verts = (Vertex *) (((
Uint8 *) vertices) +
first);
1326 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_POINTLIST, (UINT)
count, verts, sizeof (Vertex));
1334 const Vertex *verts = (Vertex *) (((
Uint8 *) vertices) +
first);
1343 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_LINESTRIP, (UINT) (
first / sizeof (Vertex)), (UINT) (
count - 1));
1344 if (close_endpoint) {
1345 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_POINTLIST, (UINT) ((
first / sizeof (Vertex)) + (
count - 1)), 1);
1348 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_LINESTRIP, (UINT) (
count - 1), verts, sizeof (Vertex));
1349 if (close_endpoint) {
1350 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_POINTLIST, 1, &verts[
count-1], sizeof (Vertex));
1363 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_TRIANGLEFAN, (UINT) ((
first / sizeof (Vertex)) +
offset), 2);
1366 const Vertex *verts = (Vertex *) (((
Uint8 *) vertices) +
first);
1367 for (
i = 0;
i <
count; ++
i, verts += 4) {
1368 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
1381 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_TRIANGLEFAN, (UINT) ((
first / sizeof (Vertex)) +
offset), 2);
1384 const Vertex *verts = (Vertex *) (((
Uint8 *) vertices) +
first);
1385 for (
i = 0;
i <
count; ++
i, verts += 4) {
1386 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
1394 const Vertex *verts = (Vertex *) (((
Uint8 *) vertices) +
first);
1395 const Vertex *transvert = verts + 4;
1396 const float translatex = transvert->x;
1397 const float translatey = transvert->y;
1398 const float rotation = transvert->z;
1399 const Float4X4 d3dmatrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
1402 IDirect3DDevice9_SetTransform(
data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
1405 IDirect3DDevice9_DrawPrimitive(
data->device, D3DPT_TRIANGLEFAN, (UINT) (
first / sizeof (Vertex)), 2);
1407 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
1428 D3DSURFACE_DESC desc;
1429 LPDIRECT3DSURFACE9 backBuffer;
1432 D3DLOCKED_RECT locked;
1435 if (
data->currentRenderTarget) {
1436 backBuffer =
data->currentRenderTarget;
1438 backBuffer =
data->defaultRenderTarget;
1441 result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
1443 IDirect3DSurface9_Release(backBuffer);
1444 return D3D_SetError(
"GetDesc()",
result);
1447 result = IDirect3DDevice9_CreateOffscreenPlainSurface(
data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &
surface,
NULL);
1449 IDirect3DSurface9_Release(backBuffer);
1450 return D3D_SetError(
"CreateOffscreenPlainSurface()",
result);
1453 result = IDirect3DDevice9_GetRenderTargetData(
data->device, backBuffer,
surface);
1455 IDirect3DSurface9_Release(
surface);
1456 IDirect3DSurface9_Release(backBuffer);
1457 return D3D_SetError(
"GetRenderTargetData()",
result);
1460 d3drect.left =
rect->
x;
1462 d3drect.top =
rect->
y;
1465 result = IDirect3DSurface9_LockRect(
surface, &locked, &d3drect, D3DLOCK_READONLY);
1467 IDirect3DSurface9_Release(
surface);
1468 IDirect3DSurface9_Release(backBuffer);
1469 return D3D_SetError(
"LockRect()",
result);
1473 D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
1476 IDirect3DSurface9_UnlockRect(
surface);
1478 IDirect3DSurface9_Release(
surface);
1489 if (!
data->beginScene) {
1490 IDirect3DDevice9_EndScene(
data->device);
1494 result = IDirect3DDevice9_TestCooperativeLevel(
data->device);
1495 if (
result == D3DERR_DEVICELOST) {
1499 if (
result == D3DERR_DEVICENOTRESET) {
1504 D3D_SetError(
"Present()",
result);
1512 D3D_TextureData *
data = (D3D_TextureData *)
texture->driverdata;
1514 if (renderdata->drawstate.texture ==
texture) {
1515 renderdata->drawstate.texture =
NULL;
1522 D3D_DestroyTextureRep(&
data->texture);
1523 D3D_DestroyTextureRep(&
data->utexture);
1524 D3D_DestroyTextureRep(&
data->vtexture);
1539 if (
data->defaultRenderTarget) {
1540 IDirect3DSurface9_Release(
data->defaultRenderTarget);
1543 if (
data->currentRenderTarget !=
NULL) {
1544 IDirect3DSurface9_Release(
data->currentRenderTarget);
1548 if (
data->shaders[
i]) {
1549 IDirect3DPixelShader9_Release(
data->shaders[
i]);
1555 if (
data->vertexBuffers[
i]) {
1556 IDirect3DVertexBuffer9_Release(
data->vertexBuffers[
i]);
1561 IDirect3DDevice9_Release(
data->device);
1565 IDirect3D9_Release(
data->d3d);
1577 const Float4X4 d3dmatrix = MatrixIdentity();
1583 if (
data->defaultRenderTarget) {
1584 IDirect3DSurface9_Release(
data->defaultRenderTarget);
1587 if (
data->currentRenderTarget !=
NULL) {
1588 IDirect3DSurface9_Release(
data->currentRenderTarget);
1603 if (
data->vertexBuffers[
i]) {
1604 IDirect3DVertexBuffer9_Release(
data->vertexBuffers[
i]);
1611 if (
result == D3DERR_DEVICELOST) {
1615 return D3D_SetError(
"Reset()",
result);
1626 IDirect3DDevice9_GetRenderTarget(
data->device, 0, &
data->defaultRenderTarget);
1627 D3D_InitRenderState(
data);
1636 IDirect3DDevice9_SetTransform(
data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
1652 D3D_RenderData *
data;
1655 D3DPRESENT_PARAMETERS pparams;
1656 IDirect3DSwapChain9 *chain;
1716 pparams.hDeviceWindow = windowinfo.
info.win.
window;
1717 pparams.BackBufferWidth =
w;
1718 pparams.BackBufferHeight =
h;
1719 pparams.BackBufferCount = 1;
1720 pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
1723 pparams.Windowed =
FALSE;
1724 pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.
format);
1725 pparams.FullScreen_RefreshRateInHz = fullscreen_mode.
refresh_rate;
1727 pparams.Windowed =
TRUE;
1728 pparams.BackBufferFormat = D3DFMT_UNKNOWN;
1729 pparams.FullScreen_RefreshRateInHz = 0;
1732 pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
1734 pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
1741 IDirect3D9_GetDeviceCaps(
data->d3d,
data->adapter, D3DDEVTYPE_HAL, &caps);
1743 device_flags = D3DCREATE_FPU_PRESERVE;
1744 if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
1745 device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
1747 device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
1751 device_flags |= D3DCREATE_MULTITHREADED;
1756 pparams.hDeviceWindow,
1758 &pparams, &
data->device);
1761 D3D_SetError(
"CreateDevice()",
result);
1766 result = IDirect3DDevice9_GetSwapChain(
data->device, 0, &chain);
1769 D3D_SetError(
"GetSwapChain()",
result);
1772 result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
1774 IDirect3DSwapChain9_Release(chain);
1776 D3D_SetError(
"GetPresentParameters()",
result);
1779 IDirect3DSwapChain9_Release(chain);
1780 if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
1783 data->pparams = pparams;
1785 IDirect3DDevice9_GetDeviceCaps(
data->device, &caps);
1788 if (caps.NumSimultaneousRTs >= 2) {
1792 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
1797 IDirect3DDevice9_GetRenderTarget(
data->device, 0, &
data->defaultRenderTarget);
1801 D3D_InitRenderState(
data);
1803 if (caps.MaxSimultaneousTextures >= 3) {
1808 D3D_SetError(
"CreatePixelShader()",
result);
1841#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
1852 IDirect3DDevice9_AddRef(
device);
#define SDL_assert(condition)
SDL_BlendOperation
The blend operation used when combining source and destination pixel components.
SDL_BlendFactor
The normalized factor used to multiply pixel components.
@ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR
@ SDL_BLENDFACTOR_SRC_COLOR
@ SDL_BLENDFACTOR_SRC_ALPHA
@ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR
@ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA
@ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
@ SDL_BLENDFACTOR_DST_ALPHA
@ SDL_BLENDFACTOR_DST_COLOR
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
#define SDL_GetWindowSize
#define SDL_GetWindowFlags
#define SDL_GetYUVConversionModeForResolution
#define SDL_GetWindowDisplayIndex
#define SDL_GetWindowDisplayMode
#define SDL_GetHintBoolean
#define SDL_ConvertPixels
#define SDL_GetWindowWMInfo
#define SDL_OutOfMemory()
@ SDL_RENDER_TARGETS_RESET
#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE
A variable controlling whether the Direct3D device is initialized for thread-safe operations.
@ SDL_LOG_CATEGORY_RENDER
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLint GLint GLint x
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLfixed GLfixed GLint GLint GLfixed points
GLsizei GLsizei GLuint * shaders
GLenum GLenum GLuint texture
GLuint GLsizei GLsizei * length
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
GLsizeiptr const void GLenum usage
#define SDL_BYTESPERPIXEL(X)
@ SDL_PIXELFORMAT_ARGB8888
@ SDL_PIXELFORMAT_UNKNOWN
SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
void * SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
@ SDL_RENDERER_ACCELERATED
@ SDL_RENDERER_PRESENTVSYNC
@ SDL_RENDERER_TARGETTEXTURE
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
@ SDL_TEXTUREACCESS_TARGET
static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
HRESULT D3D9_CreatePixelShader(IDirect3DDevice9 *d3dDevice, D3D9_Shader shader, IDirect3DPixelShader9 **pixelShader)
#define SDL_arraysize(array)
@ SDL_YUV_CONVERSION_BT601
@ SDL_YUV_CONVERSION_JPEG
@ SDL_YUV_CONVERSION_BT709
SDL_RenderDriver D3D_RenderDriver
@ SDL_RENDERCMD_SETCLIPRECT
@ SDL_RENDERCMD_DRAW_LINES
@ SDL_RENDERCMD_SETVIEWPORT
@ SDL_RENDERCMD_DRAW_POINTS
@ SDL_RENDERCMD_FILL_RECTS
@ SDL_RENDERCMD_SETDRAWCOLOR
int SDL_Direct3D9GetAdapterIndex(int displayIndex)
Returns the D3D9 adapter index that matches the specified display index.
IDirect3DDevice9 * SDL_RenderGetD3D9Device(SDL_Renderer *renderer)
Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
struct IDirect3DDevice9 IDirect3DDevice9
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
@ SDL_WINDOW_FULLSCREEN_DESKTOP
@ SDL_WINDOWEVENT_SIZE_CHANGED
SDL_bool D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
struct IDirect3D9 IDirect3D9
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
EGLSurface EGLNativeWindowType * window
EGLSurface EGLint * rects
static SDL_AudioDeviceID device
The structure that defines a display mode.
The structure that defines a point (floating point)
A rectangle, with the origin at the upper left (floating point).
A rectangle, with the origin at the upper left (integer).
union SDL_RenderCommand::@30 data
struct SDL_RenderCommand * next
struct SDL_RenderCommand::@30::@33 draw
struct SDL_RenderCommand::@30::@31 viewport
SDL_RenderCommandType command
struct SDL_RenderCommand::@30::@32 cliprect
struct SDL_RenderCommand::@30::@34 color
int(* QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
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)
int(* QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
void(* DestroyRenderer)(SDL_Renderer *renderer)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_bool(* SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode)
void(* RenderPresent)(SDL_Renderer *renderer)
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
int(* QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
int(* QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
int(* RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
int(* QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
int(* QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
Uint32 texture_formats[16]
Uint32 num_texture_formats
union SDL_SysWMinfo::@17 info
Window state change event data (event.window.*)
The type used to identify a window.
static SDL_Renderer * renderer
static SDL_BlendMode blendMode