Skip to content

Commit a6139bc

Browse files
committedFeb 9, 2024·
moved d3d9 device reset to a hopefully better spot
1 parent 05db81b commit a6139bc

File tree

1 file changed

+99
-100
lines changed

1 file changed

+99
-100
lines changed
 

‎src/d3d/d3ddevice.cpp

+99-100
Original file line numberDiff line numberDiff line change
@@ -985,97 +985,6 @@ setViewport(Raster *fb)
985985
vp.Height = fb->height;
986986
d3ddevice->SetViewport(&vp);
987987
}
988-
989-
static void
990-
beginUpdate(Camera *cam)
991-
{
992-
float view[16], proj[16];
993-
994-
// View Matrix
995-
Matrix inv;
996-
Matrix::invert(&inv, cam->getFrame()->getLTM());
997-
// Since we're looking into positive Z,
998-
// flip X to ge a left handed view space.
999-
view[0] = -inv.right.x;
1000-
view[1] = inv.right.y;
1001-
view[2] = inv.right.z;
1002-
view[3] = 0.0f;
1003-
view[4] = -inv.up.x;
1004-
view[5] = inv.up.y;
1005-
view[6] = inv.up.z;
1006-
view[7] = 0.0f;
1007-
view[8] = -inv.at.x;
1008-
view[9] = inv.at.y;
1009-
view[10] = inv.at.z;
1010-
view[11] = 0.0f;
1011-
view[12] = -inv.pos.x;
1012-
view[13] = inv.pos.y;
1013-
view[14] = inv.pos.z;
1014-
view[15] = 1.0f;
1015-
memcpy(&cam->devView, view, sizeof(RawMatrix));
1016-
// d3ddevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)view);
1017-
1018-
// Projection Matrix
1019-
float32 invwx = 1.0f/cam->viewWindow.x;
1020-
float32 invwy = 1.0f/cam->viewWindow.y;
1021-
float32 invz = 1.0f/(cam->farPlane-cam->nearPlane);
1022-
1023-
proj[0] = invwx;
1024-
proj[1] = 0.0f;
1025-
proj[2] = 0.0f;
1026-
proj[3] = 0.0f;
1027-
1028-
proj[4] = 0.0f;
1029-
proj[5] = invwy;
1030-
proj[6] = 0.0f;
1031-
proj[7] = 0.0f;
1032-
1033-
proj[8] = cam->viewOffset.x*invwx;
1034-
proj[9] = cam->viewOffset.y*invwy;
1035-
proj[12] = -proj[8];
1036-
proj[13] = -proj[9];
1037-
if(cam->projection == Camera::PERSPECTIVE){
1038-
proj[10] = cam->farPlane*invz;
1039-
proj[11] = 1.0f;
1040-
1041-
proj[15] = 0.0f;
1042-
}else{
1043-
proj[10] = invz;
1044-
proj[11] = 0.0f;
1045-
1046-
proj[15] = 1.0f;
1047-
}
1048-
proj[14] = -cam->nearPlane*proj[10];
1049-
memcpy(&cam->devProj, proj, sizeof(RawMatrix));
1050-
// d3ddevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)proj);
1051-
1052-
// TODO: figure out where this is really done
1053-
// setRenderState(D3DRS_FOGSTART, *(uint32*)&cam->fogPlane);
1054-
// setRenderState(D3DRS_FOGEND, *(uint32*)&cam->farPlane);
1055-
d3dShaderState.fogData.start = cam->fogPlane;
1056-
d3dShaderState.fogData.end = cam->farPlane;
1057-
d3dShaderState.fogData.range = 1.0f/(cam->fogPlane - cam->farPlane);
1058-
// TODO: not quite sure this is the right place to do this...
1059-
d3dShaderState.fogData.disable = rwStateCache.fogenable ? 0.0f : 1.0f;
1060-
d3dShaderState.fogDisable.start = 0.0f;
1061-
d3dShaderState.fogDisable.end = 0.0f;
1062-
d3dShaderState.fogDisable.range = 0.0f;
1063-
d3dShaderState.fogDisable.disable = 1.0f;
1064-
d3dShaderState.fogDirty = true;
1065-
1066-
setRenderSurfaces(cam);
1067-
1068-
setViewport(cam->frameBuffer);
1069-
1070-
d3ddevice->BeginScene();
1071-
}
1072-
1073-
static void
1074-
endUpdate(Camera *cam)
1075-
{
1076-
d3ddevice->EndScene();
1077-
}
1078-
1079988
// Manage video memory
1080989

1081990
void
@@ -1310,16 +1219,81 @@ restoreVideoMemory(void)
13101219
}
13111220

13121221
static void
1313-
clearCamera(Camera *cam, RGBA *col, uint32 mode)
1222+
beginUpdate(Camera *cam)
13141223
{
1315-
int flags = 0;
1316-
if(mode & Camera::CLEARIMAGE)
1317-
mode |= D3DCLEAR_TARGET;
1318-
if(mode & Camera::CLEARZ)
1319-
mode |= D3DCLEAR_ZBUFFER;
1320-
if(mode & Camera::CLEARSTENCIL)
1321-
mode |= D3DCLEAR_STENCIL;
1322-
D3DCOLOR c = D3DCOLOR_RGBA(col->red, col->green, col->blue, col->alpha);
1224+
float view[16], proj[16];
1225+
1226+
// View Matrix
1227+
Matrix inv;
1228+
Matrix::invert(&inv, cam->getFrame()->getLTM());
1229+
// Since we're looking into positive Z,
1230+
// flip X to ge a left handed view space.
1231+
view[0] = -inv.right.x;
1232+
view[1] = inv.right.y;
1233+
view[2] = inv.right.z;
1234+
view[3] = 0.0f;
1235+
view[4] = -inv.up.x;
1236+
view[5] = inv.up.y;
1237+
view[6] = inv.up.z;
1238+
view[7] = 0.0f;
1239+
view[8] = -inv.at.x;
1240+
view[9] = inv.at.y;
1241+
view[10] = inv.at.z;
1242+
view[11] = 0.0f;
1243+
view[12] = -inv.pos.x;
1244+
view[13] = inv.pos.y;
1245+
view[14] = inv.pos.z;
1246+
view[15] = 1.0f;
1247+
memcpy(&cam->devView, view, sizeof(RawMatrix));
1248+
// d3ddevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)view);
1249+
1250+
// Projection Matrix
1251+
float32 invwx = 1.0f/cam->viewWindow.x;
1252+
float32 invwy = 1.0f/cam->viewWindow.y;
1253+
float32 invz = 1.0f/(cam->farPlane-cam->nearPlane);
1254+
1255+
proj[0] = invwx;
1256+
proj[1] = 0.0f;
1257+
proj[2] = 0.0f;
1258+
proj[3] = 0.0f;
1259+
1260+
proj[4] = 0.0f;
1261+
proj[5] = invwy;
1262+
proj[6] = 0.0f;
1263+
proj[7] = 0.0f;
1264+
1265+
proj[8] = cam->viewOffset.x*invwx;
1266+
proj[9] = cam->viewOffset.y*invwy;
1267+
proj[12] = -proj[8];
1268+
proj[13] = -proj[9];
1269+
if(cam->projection == Camera::PERSPECTIVE){
1270+
proj[10] = cam->farPlane*invz;
1271+
proj[11] = 1.0f;
1272+
1273+
proj[15] = 0.0f;
1274+
}else{
1275+
proj[10] = invz;
1276+
proj[11] = 0.0f;
1277+
1278+
proj[15] = 1.0f;
1279+
}
1280+
proj[14] = -cam->nearPlane*proj[10];
1281+
memcpy(&cam->devProj, proj, sizeof(RawMatrix));
1282+
// d3ddevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)proj);
1283+
1284+
// TODO: figure out where this is really done
1285+
// setRenderState(D3DRS_FOGSTART, *(uint32*)&cam->fogPlane);
1286+
// setRenderState(D3DRS_FOGEND, *(uint32*)&cam->farPlane);
1287+
d3dShaderState.fogData.start = cam->fogPlane;
1288+
d3dShaderState.fogData.end = cam->farPlane;
1289+
d3dShaderState.fogData.range = 1.0f/(cam->fogPlane - cam->farPlane);
1290+
// TODO: not quite sure this is the right place to do this...
1291+
d3dShaderState.fogData.disable = rwStateCache.fogenable ? 0.0f : 1.0f;
1292+
d3dShaderState.fogDisable.start = 0.0f;
1293+
d3dShaderState.fogDisable.end = 0.0f;
1294+
d3dShaderState.fogDisable.range = 0.0f;
1295+
d3dShaderState.fogDisable.disable = 1.0f;
1296+
d3dShaderState.fogDirty = true;
13231297

13241298
RECT r;
13251299
GetClientRect(d3d9Globals.window, &r);
@@ -1337,6 +1311,31 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
13371311

13381312
setRenderSurfaces(cam);
13391313

1314+
setViewport(cam->frameBuffer);
1315+
1316+
d3ddevice->BeginScene();
1317+
}
1318+
1319+
static void
1320+
endUpdate(Camera *cam)
1321+
{
1322+
d3ddevice->EndScene();
1323+
}
1324+
1325+
static void
1326+
clearCamera(Camera *cam, RGBA *col, uint32 mode)
1327+
{
1328+
int flags = 0;
1329+
if(mode & Camera::CLEARIMAGE)
1330+
mode |= D3DCLEAR_TARGET;
1331+
if(mode & Camera::CLEARZ)
1332+
mode |= D3DCLEAR_ZBUFFER;
1333+
if(mode & Camera::CLEARSTENCIL)
1334+
mode |= D3DCLEAR_STENCIL;
1335+
D3DCOLOR c = D3DCOLOR_RGBA(col->red, col->green, col->blue, col->alpha);
1336+
1337+
setRenderSurfaces(cam);
1338+
13401339
setViewport(cam->frameBuffer); // need to set this for the clear to work correctly
13411340
d3ddevice->Clear(0, nil, mode, c, 1.0f, 0);
13421341
}

0 commit comments

Comments
 (0)
Please sign in to comment.