21 #include "../../SDL_internal.h"
26 #if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
28 #include "../../core/windows/SDL_windows.h"
33 #include "../SDL_sysrender.h"
34 #include "../SDL_d3dmath.h"
35 #include "../../video/windows/SDL_windowsvideo.h"
37 #if SDL_VIDEO_RENDER_D3D
38 #define D3D_DEBUG_INFO
58 const Uint8 *Yplane,
int Ypitch,
59 const Uint8 *Uplane,
int Upitch,
60 const Uint8 *Vplane,
int Vpitch);
105 D3DPRESENT_PARAMETERS pparams;
109 D3DTEXTUREFILTERTYPE scaleMode[8];
110 IDirect3DSurface9 *defaultRenderTarget;
111 IDirect3DSurface9 *currentRenderTarget;
124 IDirect3DTexture9 *staging;
130 D3DTEXTUREFILTERTYPE scaleMode;
134 D3D_TextureRep utexture;
135 D3D_TextureRep vtexture;
149 D3D_SetError(
const char *prefix, HRESULT
result)
154 case D3DERR_WRONGTEXTUREFORMAT:
155 error =
"WRONGTEXTUREFORMAT";
157 case D3DERR_UNSUPPORTEDCOLOROPERATION:
158 error =
"UNSUPPORTEDCOLOROPERATION";
160 case D3DERR_UNSUPPORTEDCOLORARG:
161 error =
"UNSUPPORTEDCOLORARG";
163 case D3DERR_UNSUPPORTEDALPHAOPERATION:
164 error =
"UNSUPPORTEDALPHAOPERATION";
166 case D3DERR_UNSUPPORTEDALPHAARG:
167 error =
"UNSUPPORTEDALPHAARG";
169 case D3DERR_TOOMANYOPERATIONS:
170 error =
"TOOMANYOPERATIONS";
172 case D3DERR_CONFLICTINGTEXTUREFILTER:
173 error =
"CONFLICTINGTEXTUREFILTER";
175 case D3DERR_UNSUPPORTEDFACTORVALUE:
176 error =
"UNSUPPORTEDFACTORVALUE";
178 case D3DERR_CONFLICTINGRENDERSTATE:
179 error =
"CONFLICTINGRENDERSTATE";
181 case D3DERR_UNSUPPORTEDTEXTUREFILTER:
182 error =
"UNSUPPORTEDTEXTUREFILTER";
184 case D3DERR_CONFLICTINGTEXTUREPALETTE:
185 error =
"CONFLICTINGTEXTUREPALETTE";
187 case D3DERR_DRIVERINTERNALERROR:
188 error =
"DRIVERINTERNALERROR";
190 case D3DERR_NOTFOUND:
193 case D3DERR_MOREDATA:
196 case D3DERR_DEVICELOST:
197 error =
"DEVICELOST";
199 case D3DERR_DEVICENOTRESET:
200 error =
"DEVICENOTRESET";
202 case D3DERR_NOTAVAILABLE:
203 error =
"NOTAVAILABLE";
205 case D3DERR_OUTOFVIDEOMEMORY:
206 error =
"OUTOFVIDEOMEMORY";
208 case D3DERR_INVALIDDEVICE:
209 error =
"INVALIDDEVICE";
211 case D3DERR_INVALIDCALL:
212 error =
"INVALIDCALL";
214 case D3DERR_DRIVERINVALIDCALL:
215 error =
"DRIVERINVALIDCALL";
217 case D3DERR_WASSTILLDRAWING:
218 error =
"WASSTILLDRAWING";
232 return D3DFMT_R5G6B5;
234 return D3DFMT_X8R8G8B8;
236 return D3DFMT_A8R8G8B8;
243 return D3DFMT_UNKNOWN;
248 D3DFMTToPixelFormat(D3DFORMAT
format)
253 case D3DFMT_X8R8G8B8:
255 case D3DFMT_A8R8G8B8:
263 D3D_InitRenderState(D3D_RenderData *
data)
269 IDirect3DDevice9_SetVertexShader(
device,
NULL);
270 IDirect3DDevice9_SetFVF(
device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
271 IDirect3DDevice9_SetRenderState(
device, D3DRS_ZENABLE, D3DZB_FALSE);
272 IDirect3DDevice9_SetRenderState(
device, D3DRS_CULLMODE, D3DCULL_NONE);
273 IDirect3DDevice9_SetRenderState(
device, D3DRS_LIGHTING,
FALSE);
276 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLOROP,
278 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLORARG1,
280 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_COLORARG2,
284 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAOP,
286 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAARG1,
288 IDirect3DDevice9_SetTextureStageState(
device, 0, D3DTSS_ALPHAARG2,
292 if (
data->enableSeparateAlphaBlend) {
293 IDirect3DDevice9_SetRenderState(
device, D3DRS_SEPARATEALPHABLENDENABLE,
TRUE);
297 IDirect3DDevice9_SetTextureStageState(
device, 1, D3DTSS_COLOROP,
299 IDirect3DDevice9_SetTextureStageState(
device, 1, D3DTSS_ALPHAOP,
319 IDirect3DDevice9_SetTransform(
device, D3DTS_WORLD, &
matrix);
320 IDirect3DDevice9_SetTransform(
device, D3DTS_VIEW, &
matrix);
337 if (
data->defaultRenderTarget) {
338 IDirect3DSurface9_Release(
data->defaultRenderTarget);
341 if (
data->currentRenderTarget !=
NULL) {
342 IDirect3DSurface9_Release(
data->currentRenderTarget);
357 if (
result == D3DERR_DEVICELOST) {
361 return D3D_SetError(
"Reset()",
result);
372 IDirect3DDevice9_GetRenderTarget(
data->device, 0, &
data->defaultRenderTarget);
373 D3D_InitRenderState(
data);
393 if (
data->updateSize) {
399 data->pparams.BackBufferWidth =
w;
400 data->pparams.BackBufferHeight =
h;
405 data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.
format);
409 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
410 data->pparams.FullScreen_RefreshRateInHz = 0;
418 if (
data->beginScene) {
419 result = IDirect3DDevice9_BeginScene(
data->device);
420 if (
result == D3DERR_DEVICELOST) {
424 result = IDirect3DDevice9_BeginScene(
data->device);
427 return D3D_SetError(
"BeginScene()",
result);
438 D3D_RenderData *
data;
441 D3DPRESENT_PARAMETERS pparams;
442 IDirect3DSwapChain9 *chain;
502 pparams.hDeviceWindow = windowinfo.
info.win.
window;
503 pparams.BackBufferWidth =
w;
504 pparams.BackBufferHeight =
h;
505 pparams.BackBufferCount = 1;
506 pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
509 pparams.Windowed =
FALSE;
510 pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.
format);
511 pparams.FullScreen_RefreshRateInHz = fullscreen_mode.
refresh_rate;
513 pparams.Windowed =
TRUE;
514 pparams.BackBufferFormat = D3DFMT_UNKNOWN;
515 pparams.FullScreen_RefreshRateInHz = 0;
518 pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
520 pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
527 IDirect3D9_GetDeviceCaps(
data->d3d,
data->adapter, D3DDEVTYPE_HAL, &caps);
529 device_flags = D3DCREATE_FPU_PRESERVE;
530 if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
531 device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
533 device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
537 device_flags |= D3DCREATE_MULTITHREADED;
542 pparams.hDeviceWindow,
544 &pparams, &
data->device);
547 D3D_SetError(
"CreateDevice()",
result);
552 result = IDirect3DDevice9_GetSwapChain(
data->device, 0, &chain);
555 D3D_SetError(
"GetSwapChain()",
result);
558 result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
560 IDirect3DSwapChain9_Release(chain);
562 D3D_SetError(
"GetPresentParameters()",
result);
565 IDirect3DSwapChain9_Release(chain);
566 if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
569 data->pparams = pparams;
571 IDirect3DDevice9_GetDeviceCaps(
data->device, &caps);
574 if (caps.NumSimultaneousRTs >= 2) {
578 if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
583 IDirect3DDevice9_GetRenderTarget(
data->device, 0, &
data->defaultRenderTarget);
587 D3D_InitRenderState(
data);
589 if (caps.MaxSimultaneousTextures >= 3) {
594 D3D_SetError(
"CreatePixelShader()",
result);
619 return D3DBLEND_ZERO;
623 return D3DBLEND_SRCCOLOR;
625 return D3DBLEND_INVSRCCOLOR;
627 return D3DBLEND_SRCALPHA;
629 return D3DBLEND_INVSRCALPHA;
631 return D3DBLEND_DESTCOLOR;
633 return D3DBLEND_INVDESTCOLOR;
635 return D3DBLEND_DESTALPHA;
637 return D3DBLEND_INVDESTALPHA;
654 if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
655 !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor)) {
658 if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !
data->enableSeparateAlphaBlend) {
680 PixelFormatToD3DFMT(
format),
683 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
698 return D3D_SetError(
"CreateTexture(D3DPOOL_SYSTEMMEM)",
result);
714 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
718 result = IDirect3DDevice9_UpdateTexture(
device, (IDirect3DBaseTexture9 *)
texture->staging, (IDirect3DBaseTexture9 *)
texture->texture);
720 return D3D_SetError(
"UpdateTexture()",
result);
726 return D3D_SetError(
"SetTexture()",
result);
735 IDirect3DTexture9_Release(
texture->texture);
739 IDirect3DTexture9_AddDirtyRect(
texture->staging,
NULL);
749 D3DLOCKED_RECT locked;
760 d3drect.right =
x +
w;
762 d3drect.bottom =
y +
h;
764 result = IDirect3DTexture9_LockRect(
texture->staging, 0, &locked, &d3drect, 0);
766 return D3D_SetError(
"LockRect()",
result);
778 if (
length > locked.Pitch) {
789 return D3D_SetError(
"UnlockRect()",
result);
797 D3D_DestroyTextureRep(D3D_TextureRep *
texture)
800 IDirect3DTexture9_Release(
texture->texture);
804 IDirect3DTexture9_Release(
texture->staging);
813 D3D_TextureData *texturedata;
816 texturedata = (D3D_TextureData *)
SDL_calloc(1,
sizeof(*texturedata));
822 texture->driverdata = texturedata;
825 usage = D3DUSAGE_RENDERTARGET;
853 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
859 if (D3D_RecreateTextureRep(
data->device, &texturedata->texture) < 0) {
863 if (texturedata->yuv) {
864 if (D3D_RecreateTextureRep(
data->device, &texturedata->utexture) < 0) {
868 if (D3D_RecreateTextureRep(
data->device, &texturedata->vtexture) < 0) {
880 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
891 if (texturedata->yuv) {
911 const Uint8 *Yplane,
int Ypitch,
912 const Uint8 *Uplane,
int Upitch,
913 const Uint8 *Vplane,
int Vpitch)
916 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
923 if (D3D_UpdateTextureRep(
data->device, &texturedata->texture,
rect->
x,
rect->
y,
rect->
w,
rect->
h, Yplane, Ypitch) < 0) {
926 if (D3D_UpdateTextureRep(
data->device, &texturedata->utexture,
rect->
x / 2,
rect->
y / 2, (
rect->
w + 1) / 2, (
rect->
h + 1) / 2, Uplane, Upitch) < 0) {
929 if (D3D_UpdateTextureRep(
data->device, &texturedata->vtexture,
rect->
x / 2,
rect->
y / 2, (
rect->
w + 1) / 2, (
rect->
h + 1) / 2, Vplane, Vpitch) < 0) {
940 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
948 texturedata->locked_rect = *
rect;
950 if (texturedata->yuv) {
952 if (!texturedata->pixels) {
955 if (!texturedata->pixels) {
960 (
void *) ((
Uint8 *) texturedata->pixels +
rect->
y * texturedata->pitch +
962 *pitch = texturedata->pitch;
965 D3DLOCKED_RECT locked;
968 if (D3D_CreateStagingTexture(
device, &texturedata->texture) < 0) {
972 d3drect.left =
rect->
x;
974 d3drect.top =
rect->
y;
977 result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
979 return D3D_SetError(
"LockRect()",
result);
982 *pitch = locked.Pitch;
991 D3D_TextureData *texturedata = (D3D_TextureData *)
texture->driverdata;
997 if (texturedata->yuv) {
1000 (
void *) ((
Uint8 *) texturedata->pixels +
rect->
y * texturedata->pitch +
1004 IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
1005 texturedata->texture.dirty =
SDL_TRUE;
1013 D3D_TextureData *texturedata;
1014 D3D_TextureRep *texturerep;
1019 if (
data->currentRenderTarget !=
NULL) {
1020 IDirect3DSurface9_Release(
data->currentRenderTarget);
1025 IDirect3DDevice9_SetRenderTarget(
data->device, 0,
data->defaultRenderTarget);
1029 texturedata = (D3D_TextureData *)
texture->driverdata;
1036 texturerep = &texturedata->texture;
1037 if (texturerep->dirty && texturerep->staging) {
1038 if (!texturerep->texture) {
1039 result = IDirect3DDevice9_CreateTexture(
device, texturerep->w, texturerep->h, 1, texturerep->usage,
1040 PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture,
NULL);
1042 return D3D_SetError(
"CreateTexture(D3DPOOL_DEFAULT)",
result);
1046 result = IDirect3DDevice9_UpdateTexture(
device, (IDirect3DBaseTexture9 *)texturerep->staging, (IDirect3DBaseTexture9 *)texturerep->texture);
1048 return D3D_SetError(
"UpdateTexture()",
result);
1053 result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &
data->currentRenderTarget);
1055 return D3D_SetError(
"GetSurfaceLevel()",
result);
1057 result = IDirect3DDevice9_SetRenderTarget(
data->device, 0,
data->currentRenderTarget);
1059 return D3D_SetError(
"SetRenderTarget()",
result);
1068 if (D3D_ActivateRenderer(
renderer) < 0) {
1109 IDirect3DDevice9_SetTransform(
data->device, D3DTS_PROJECTION, &
matrix);
1125 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
TRUE);
1131 result = IDirect3DDevice9_SetScissorRect(
data->device, &
r);
1133 D3D_SetError(
"SetScissor()",
result);
1137 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
FALSE);
1148 int BackBufferWidth, BackBufferHeight;
1150 if (D3D_ActivateRenderer(
renderer) < 0) {
1160 BackBufferWidth =
data->pparams.BackBufferWidth;
1161 BackBufferHeight =
data->pparams.BackBufferHeight;
1165 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
FALSE);
1180 viewport.Height = BackBufferHeight;
1198 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SCISSORTESTENABLE,
TRUE);
1202 return D3D_SetError(
"Clear()",
result);
1211 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_ALPHABLENDENABLE,
FALSE);
1213 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
1214 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SRCBLEND,
1216 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_DESTBLEND,
1218 if (
data->enableSeparateAlphaBlend) {
1219 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_SRCBLENDALPHA,
1221 IDirect3DDevice9_SetRenderState(
data->device, D3DRS_DESTBLENDALPHA,
1237 if (D3D_ActivateRenderer(
renderer) < 0) {
1244 IDirect3DDevice9_SetTexture(
data->device, 0,
1245 (IDirect3DBaseTexture9 *) 0);
1247 return D3D_SetError(
"SetTexture()",
result);
1256 vertices[
i].z = 0.0f;
1257 vertices[
i].color =
color;
1258 vertices[
i].u = 0.0f;
1259 vertices[
i].v = 0.0f;
1262 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_POINTLIST,
count,
1263 vertices,
sizeof(*vertices));
1266 return D3D_SetError(
"DrawPrimitiveUP()",
result);
1281 if (D3D_ActivateRenderer(
renderer) < 0) {
1288 IDirect3DDevice9_SetTexture(
data->device, 0,
1289 (IDirect3DBaseTexture9 *) 0);
1291 return D3D_SetError(
"SetTexture()",
result);
1300 vertices[
i].z = 0.0f;
1301 vertices[
i].color =
color;
1302 vertices[
i].u = 0.0f;
1303 vertices[
i].v = 0.0f;
1306 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_LINESTRIP,
count-1,
1307 vertices,
sizeof(*vertices));
1315 result = IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_POINTLIST, 1, vertices,
sizeof(*vertices));
1320 return D3D_SetError(
"DrawPrimitiveUP()",
result);
1332 float minx, miny, maxx, maxy;
1336 if (D3D_ActivateRenderer(
renderer) < 0) {
1343 IDirect3DDevice9_SetTexture(
data->device, 0,
1344 (IDirect3DBaseTexture9 *) 0);
1346 return D3D_SetError(
"SetTexture()",
result);
1359 vertices[0].x = minx;
1360 vertices[0].y = miny;
1361 vertices[0].z = 0.0f;
1362 vertices[0].color =
color;
1363 vertices[0].u = 0.0f;
1364 vertices[0].v = 0.0f;
1366 vertices[1].x = maxx;
1367 vertices[1].y = miny;
1368 vertices[1].z = 0.0f;
1369 vertices[1].color =
color;
1370 vertices[1].u = 0.0f;
1371 vertices[1].v = 0.0f;
1373 vertices[2].x = maxx;
1374 vertices[2].y = maxy;
1375 vertices[2].z = 0.0f;
1376 vertices[2].color =
color;
1377 vertices[2].u = 0.0f;
1378 vertices[2].v = 0.0f;
1380 vertices[3].x = minx;
1381 vertices[3].y = maxy;
1382 vertices[3].z = 0.0f;
1383 vertices[3].color =
color;
1384 vertices[3].u = 0.0f;
1385 vertices[3].v = 0.0f;
1388 IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN,
1389 2, vertices,
sizeof(*vertices));
1391 return D3D_SetError(
"DrawPrimitiveUP()",
result);
1398 D3D_UpdateTextureScaleMode(D3D_RenderData *
data, D3D_TextureData *texturedata,
unsigned index)
1400 if (texturedata->scaleMode !=
data->scaleMode[
index]) {
1401 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_MINFILTER,
1402 texturedata->scaleMode);
1403 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_MAGFILTER,
1404 texturedata->scaleMode);
1405 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_ADDRESSU,
1407 IDirect3DDevice9_SetSamplerState(
data->device,
index, D3DSAMP_ADDRESSV,
1409 data->scaleMode[
index] = texturedata->scaleMode;
1417 D3D_TextureData *texturedata;
1421 texturedata = (D3D_TextureData *)
texture->driverdata;
1427 D3D_UpdateTextureScaleMode(
data, texturedata, 0);
1429 if (D3D_BindTextureRep(
data->device, &texturedata->texture, 0) < 0) {
1433 if (texturedata->yuv) {
1445 return SDL_SetError(
"Unsupported YUV conversion mode");
1448 D3D_UpdateTextureScaleMode(
data, texturedata, 1);
1449 D3D_UpdateTextureScaleMode(
data, texturedata, 2);
1451 if (D3D_BindTextureRep(
data->device, &texturedata->utexture, 1) < 0) {
1454 if (D3D_BindTextureRep(
data->device, &texturedata->vtexture, 2) < 0) {
1466 LPDIRECT3DPIXELSHADER9
shader;
1467 float minx, miny, maxx, maxy;
1468 float minu, maxu, minv, maxv;
1473 if (D3D_ActivateRenderer(
renderer) < 0) {
1477 minx = dstrect->
x - 0.5f;
1478 miny = dstrect->
y - 0.5f;
1479 maxx = dstrect->
x + dstrect->
w - 0.5f;
1480 maxy = dstrect->
y + dstrect->
h - 0.5f;
1482 minu = (float) srcrect->
x /
texture->w;
1483 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
1484 minv = (
float) srcrect->
y /
texture->h;
1485 maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
1489 vertices[0].x = minx;
1490 vertices[0].y = miny;
1491 vertices[0].z = 0.0f;
1492 vertices[0].color =
color;
1493 vertices[0].u = minu;
1494 vertices[0].v = minv;
1496 vertices[1].x = maxx;
1497 vertices[1].y = miny;
1498 vertices[1].z = 0.0f;
1499 vertices[1].color =
color;
1500 vertices[1].u = maxu;
1501 vertices[1].v = minv;
1503 vertices[2].x = maxx;
1504 vertices[2].y = maxy;
1505 vertices[2].z = 0.0f;
1506 vertices[2].color =
color;
1507 vertices[2].u = maxu;
1508 vertices[2].v = maxv;
1510 vertices[3].x = minx;
1511 vertices[3].y = maxy;
1512 vertices[3].z = 0.0f;
1513 vertices[3].color =
color;
1514 vertices[3].u = minu;
1515 vertices[3].v = maxv;
1526 return D3D_SetError(
"SetShader()",
result);
1529 result = IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN, 2,
1530 vertices,
sizeof(*vertices));
1532 D3D_SetError(
"DrawPrimitiveUP()",
result);
1535 IDirect3DDevice9_SetPixelShader(
data->device,
NULL);
1548 float minx, miny, maxx, maxy;
1549 float minu, maxu, minv, maxv;
1550 float centerx, centery;
1553 Float4X4 modelMatrix;
1556 if (D3D_ActivateRenderer(
renderer) < 0) {
1560 centerx = center->
x;
1561 centery = center->
y;
1564 maxx = dstrect->
w - centerx;
1566 maxy = dstrect->
h - centery;
1568 minu = (float) srcrect->
x /
texture->w;
1569 maxu = (
float) (srcrect->
x + srcrect->
w) /
texture->w;
1570 minv = (
float) srcrect->
y /
texture->h;
1571 maxv = (float) (srcrect->
y + srcrect->
h) /
texture->h;
1586 vertices[0].x = minx;
1587 vertices[0].y = miny;
1588 vertices[0].z = 0.0f;
1589 vertices[0].color =
color;
1590 vertices[0].u = minu;
1591 vertices[0].v = minv;
1593 vertices[1].x = maxx;
1594 vertices[1].y = miny;
1595 vertices[1].z = 0.0f;
1596 vertices[1].color =
color;
1597 vertices[1].u = maxu;
1598 vertices[1].v = minv;
1600 vertices[2].x = maxx;
1601 vertices[2].y = maxy;
1602 vertices[2].z = 0.0f;
1603 vertices[2].color =
color;
1604 vertices[2].u = maxu;
1605 vertices[2].v = maxv;
1607 vertices[3].x = minx;
1608 vertices[3].y = maxy;
1609 vertices[3].z = 0.0f;
1610 vertices[3].color =
color;
1611 vertices[3].u = minu;
1612 vertices[3].v = maxv;
1621 modelMatrix = MatrixMultiply(
1622 MatrixRotationZ((
float)(M_PI * (
float)
angle / 180.0
f)),
1623 MatrixTranslation(dstrect->
x + center->
x - 0.5f, dstrect->
y + center->
y - 0.5f, 0));
1624 IDirect3DDevice9_SetTransform(
data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
1629 D3D_SetError(
"SetShader()",
result);
1633 result = IDirect3DDevice9_DrawPrimitiveUP(
data->device, D3DPT_TRIANGLEFAN, 2,
1634 vertices,
sizeof(*vertices));
1636 D3D_SetError(
"DrawPrimitiveUP()",
result);
1640 IDirect3DDevice9_SetPixelShader(
data->device,
NULL);
1643 modelMatrix = MatrixIdentity();
1644 IDirect3DDevice9_SetTransform(
data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
1654 D3DSURFACE_DESC desc;
1655 LPDIRECT3DSURFACE9 backBuffer;
1658 D3DLOCKED_RECT locked;
1661 if (
data->currentRenderTarget) {
1662 backBuffer =
data->currentRenderTarget;
1664 backBuffer =
data->defaultRenderTarget;
1667 result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
1669 IDirect3DSurface9_Release(backBuffer);
1670 return D3D_SetError(
"GetDesc()",
result);
1673 result = IDirect3DDevice9_CreateOffscreenPlainSurface(
data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &
surface,
NULL);
1675 IDirect3DSurface9_Release(backBuffer);
1676 return D3D_SetError(
"CreateOffscreenPlainSurface()",
result);
1679 result = IDirect3DDevice9_GetRenderTargetData(
data->device, backBuffer,
surface);
1681 IDirect3DSurface9_Release(
surface);
1682 IDirect3DSurface9_Release(backBuffer);
1683 return D3D_SetError(
"GetRenderTargetData()",
result);
1686 d3drect.left =
rect->
x;
1688 d3drect.top =
rect->
y;
1691 result = IDirect3DSurface9_LockRect(
surface, &locked, &d3drect, D3DLOCK_READONLY);
1693 IDirect3DSurface9_Release(
surface);
1694 IDirect3DSurface9_Release(backBuffer);
1695 return D3D_SetError(
"LockRect()",
result);
1699 D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
1702 IDirect3DSurface9_UnlockRect(
surface);
1704 IDirect3DSurface9_Release(
surface);
1715 if (!
data->beginScene) {
1716 IDirect3DDevice9_EndScene(
data->device);
1720 result = IDirect3DDevice9_TestCooperativeLevel(
data->device);
1721 if (
result == D3DERR_DEVICELOST) {
1725 if (
result == D3DERR_DEVICENOTRESET) {
1730 D3D_SetError(
"Present()",
result);
1737 D3D_TextureData *
data = (D3D_TextureData *)
texture->driverdata;
1742 D3D_DestroyTextureRep(&
data->texture);
1743 D3D_DestroyTextureRep(&
data->utexture);
1744 D3D_DestroyTextureRep(&
data->vtexture);
1759 if (
data->defaultRenderTarget) {
1760 IDirect3DSurface9_Release(
data->defaultRenderTarget);
1763 if (
data->currentRenderTarget !=
NULL) {
1764 IDirect3DSurface9_Release(
data->currentRenderTarget);
1768 if (
data->shaders[
i]) {
1769 IDirect3DPixelShader9_Release(
data->shaders[
i]);
1774 IDirect3DDevice9_Release(
data->device);
1778 IDirect3D9_Release(
data->d3d);
1794 #if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
1805 IDirect3DDevice9_AddRef(
device);