Changeset 79838 in vbox for trunk/src/VBox
- Timestamp:
- Jul 17, 2019 3:36:57 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d9render.cpp
r79767 r79838 43 43 } 44 44 return hr; 45 } 46 47 static void drawTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture, int x, int y, int w, int h) 48 { 49 HRESULT hr = S_OK; 50 51 HTEST(pDevice->Clear(0, 0, D3DCLEAR_TARGET, 0xffafaf00, 0.0f, 0)); 52 53 HTEST(pDevice->BeginScene()); 54 55 IDirect3DSurface9 *pSurface; 56 HTEST(pTexture->GetSurfaceLevel(0, &pSurface)); 57 58 /* Copy the texture to the backbuffer. */ 59 IDirect3DSurface9 *pBackBuffer; 60 HTEST(pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)); 61 62 RECT rDst; 63 rDst.left = x; 64 rDst.top = y; 65 rDst.right = x + w; 66 rDst.bottom = y + h; 67 68 HTEST(pDevice->StretchRect(pSurface, NULL, pBackBuffer, &rDst, D3DTEXF_POINT)); 69 70 HTEST(pDevice->EndScene()); 71 72 D3D_RELEASE(pBackBuffer); 73 D3D_RELEASE(pSurface); 45 74 } 46 75 … … 938 967 939 968 void renderToTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture); 940 void drawTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture);941 969 }; 942 970 … … 1063 1091 } 1064 1092 1065 void D3D9RenderShared::drawTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture)1066 {1067 HRESULT hr = S_OK;1068 1069 HTEST(pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffafaf00, 1.0f, 0));1070 1071 HTEST(pDevice->BeginScene());1072 1073 IDirect3DSurface9 *pSurface;1074 HTEST(pTexture->GetSurfaceLevel(0, &pSurface));1075 1076 /* Copy the texture to the backbuffer. */1077 IDirect3DSurface9 *pBackBuffer;1078 HTEST(pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer));1079 1080 RECT rDst;1081 rDst.left = 50;1082 rDst.top = 50;1083 rDst.right = 250;1084 rDst.bottom = 250;1085 1086 HTEST(pDevice->StretchRect(pSurface, NULL, pBackBuffer, &rDst, D3DTEXF_NONE));1087 1088 HTEST(pDevice->EndScene());1089 1090 D3D_RELEASE(pBackBuffer);1091 D3D_RELEASE(pSurface);1092 1093 HTEST(pDevice->Present(0, 0, 0, 0));1094 }1095 1096 1093 static void issueQuery(IDirect3DDevice9 *pDevice) 1097 1094 { … … 1137 1134 &mhRtShared)); 1138 1135 1139 drawTexture(pDevice2, mpTexShared );1136 drawTexture(pDevice2, mpTexShared, 50, 50, 200, 200); 1140 1137 } 1141 1138 else 1142 1139 { 1143 drawTexture(pDevice, mpRT );1140 drawTexture(pDevice, mpRT, 50, 50, 200, 200); 1144 1141 } 1142 1143 HTEST(pDevice->Present(0, 0, 0, 0)); 1145 1144 1146 1145 return S_OK; … … 1194 1193 1195 1194 /* 1195 * Render a texture to texture. 1196 */ 1197 1198 class D3D9RenderTexture: public D3D9Render 1199 { 1200 public: 1201 D3D9RenderTexture(); 1202 virtual ~D3D9RenderTexture(); 1203 virtual HRESULT InitRender(D3D9DeviceProvider *pDP); 1204 virtual HRESULT DoRender(D3D9DeviceProvider *pDP); 1205 private: 1206 IDirect3DVertexBuffer9 *mpVB; 1207 IDirect3DVertexDeclaration9 *mpVertexDecl; 1208 IDirect3DVertexShader9 *mpVS; 1209 IDirect3DPixelShader9 *mpPS; 1210 IDirect3DTexture9 *mpTexDst; 1211 IDirect3DTexture9 *mpTexSrc; 1212 1213 static const int cxTexture = 8; 1214 static const int cyTexture = 8; 1215 1216 struct Vertex 1217 { 1218 D3DVECTOR position; 1219 float x, y; 1220 }; 1221 static D3DVERTEXELEMENT9 VertexElements[]; 1222 1223 void renderToTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture, IDirect3DTexture9 *pTexSrc); 1224 }; 1225 1226 D3DVERTEXELEMENT9 D3D9RenderTexture::VertexElements[] = 1227 { 1228 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, 1229 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, 1230 D3DDECL_END() 1231 }; 1232 1233 1234 D3D9RenderTexture::D3D9RenderTexture() 1235 : 1236 mpVB(0), 1237 mpVertexDecl(0), 1238 mpVS(0), 1239 mpPS(0), 1240 mpTexDst(0), 1241 mpTexSrc(0) 1242 { 1243 } 1244 1245 D3D9RenderTexture::~D3D9RenderTexture() 1246 { 1247 D3D_RELEASE(mpVS); 1248 D3D_RELEASE(mpPS); 1249 D3D_RELEASE(mpVB); 1250 D3D_RELEASE(mpVertexDecl); 1251 D3D_RELEASE(mpTexSrc); 1252 D3D_RELEASE(mpTexDst); 1253 } 1254 1255 HRESULT D3D9RenderTexture::InitRender(D3D9DeviceProvider *pDP) 1256 { 1257 IDirect3DDevice9 *pDevice = pDP->Device(0); 1258 1259 static DWORD aVSCode[] = 1260 { 1261 0xFFFE0200, // vs_2_0 1262 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, // def c0, 1, 0, 0, 0 1263 0x0200001f, 0x80000000, 0x900f0000, // dcl_position v0 1264 0x0200001f, 0x80000005, 0x900f0001, // dcl_texcoord v1 1265 0x02000001, 0xc0070000, 0x90e40000, // mov oPos.xyz, v0 1266 0x02000001, 0xc0080000, 0xa0000000, // mov oPos.w, c0.x 1267 0x02000001, 0xe0030000, 0x90e40001, // mov oT0.xy, v1 1268 0x0000FFFF 1269 }; 1270 1271 static DWORD aVSCodeMad[] = 1272 { 1273 0xFFFE0200, // vs_2_0 1274 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, // def c0, 1, 0, 0, 0 1275 0x0200001f, 0x80000000, 0x900f0000, // dcl_position v0 1276 0x0200001f, 0x80000005, 0x900f0001, // dcl_texcoord v1 1277 0x04000004, 0xc00f0000, 0x90240000, 0xa0400000, 0xa0150000, // mad oPos, v0.xyzx, c0.xxxy, c0.yyyx 1278 0x02000001, 0xe0030000, 0x90e40001, // mov oT0.xy, v1 1279 0x0000FFFF 1280 }; 1281 1282 static DWORD aPSCodeSwap[] = 1283 { 1284 0xffff0200, // ps_2_0 1285 0x0200001f, 0x80000000, 0xb0030000, // dcl t0.xy 1286 0x0200001f, 0x90000000, 0xa00f0800, // dcl_2d s0 1287 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, // texld r0, t0, s0 1288 0x02000001, 0x80090001, 0x80d20000, // mov r1.xw, r0.zxyw 1289 0x02000001, 0x80040001, 0x80000000, // mov r1.z, r0.x 1290 0x02000001, 0x80020001, 0x80550000, // mov r1.y, r0.y 1291 0x02000001, 0x800f0800, 0x80e40001, // mov oC0, r1 1292 0x0000ffff 1293 }; 1294 1295 static DWORD aPSCodePass[] = 1296 { 1297 0xffff0200, // ps_2_0 1298 0x0200001f, 0x80000000, 0xb0030000, // dcl t0.xy 1299 0x0200001f, 0x90000000, 0xa00f0800, // dcl_2d s0 1300 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, // texld r0, t0, s0 1301 0x02000001, 0x800f0800, 0x80e40000, // mov oC0, r0 1302 0x0000ffff 1303 }; 1304 1305 static DWORD aPSCodeCoord[] = 1306 { 1307 0xffff0200, // ps_2_0 1308 0x0200001f, 0x80000000, 0xb0010000, // dcl t0.x 1309 0x02000001, 0x800f0000, 0xb0000000, // mov r0, t0.x 1310 0x02000001, 0x800f0800, 0x80e40000, // mov oC0, r0 1311 0x0000ffff 1312 }; 1313 1314 static Vertex aVertices[] = 1315 { 1316 { -1.0f, -1.0f, 0.0f, 0.0f, 1.0f}, 1317 { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f}, 1318 { -1.0f, 1.0f, 0.0f, 0.0f, 0.0f}, 1319 1320 { -1.0f, 1.0f, 0.0f, 0.0f, 0.0f}, 1321 { 1.0f, -1.0f, 0.0f, 1.0f, 1.0f}, 1322 { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f}, 1323 }; 1324 1325 HRESULT hr = S_OK; 1326 1327 HTEST(pDevice->CreateVertexDeclaration(VertexElements, &mpVertexDecl)); 1328 HTEST(pDevice->CreateVertexBuffer(sizeof(aVertices), 1329 0, /* D3DUSAGE_* */ 1330 0, /* FVF */ 1331 D3DPOOL_DEFAULT, 1332 &mpVB, 1333 0)); 1334 HTEST(pDevice->CreateVertexShader(aVSCodeMad, &mpVS)); 1335 HTEST(pDevice->CreatePixelShader(aPSCodeSwap, &mpPS)); 1336 1337 HTEST(d3dCopyToVertexBuffer(mpVB, aVertices, sizeof(aVertices))); 1338 1339 HTEST(pDevice->CreateTexture(cxTexture, 1340 cyTexture, 1341 1, 1342 D3DUSAGE_RENDERTARGET, 1343 D3DFMT_A8R8G8B8, 1344 D3DPOOL_DEFAULT, 1345 &mpTexDst, 1346 NULL)); 1347 1348 HTEST(pDevice->CreateTexture(cxTexture, 1349 cyTexture, 1350 1, 1351 D3DUSAGE_DYNAMIC, 1352 D3DFMT_A8R8G8B8, 1353 D3DPOOL_DEFAULT, 1354 &mpTexSrc, 1355 NULL)); 1356 1357 D3DLOCKED_RECT LockedRect; 1358 HTEST(mpTexSrc->LockRect(0, &LockedRect, NULL /* entire texture */, 0)); 1359 1360 unsigned char *pScanline = (unsigned char *)LockedRect.pBits; 1361 for (UINT y = 0; y < cxTexture; ++y) 1362 { 1363 for (UINT x = 0; x < cxTexture; ++x) 1364 { 1365 if (x < y) 1366 { 1367 pScanline[x * 4 + 0] = 0xff; 1368 pScanline[x * 4 + 1] = 0x00; 1369 pScanline[x * 4 + 2] = 0x00; 1370 pScanline[x * 4 + 3] = 0x00; 1371 } 1372 else 1373 { 1374 pScanline[x * 4 + 0] = 0x00; 1375 pScanline[x * 4 + 1] = 0x00; 1376 pScanline[x * 4 + 2] = 0xff; 1377 pScanline[x * 4 + 3] = 0x00; 1378 } 1379 } 1380 1381 pScanline += LockedRect.Pitch; 1382 } 1383 1384 HTEST(mpTexSrc->UnlockRect(0)); 1385 1386 return hr; 1387 } 1388 1389 void D3D9RenderTexture::renderToTexture(IDirect3DDevice9 *pDevice, IDirect3DTexture9 *pTexture, IDirect3DTexture9 *pTexSrc) 1390 { 1391 HRESULT hr = S_OK; 1392 1393 /* 1394 * Render to texture. 1395 */ 1396 IDirect3DSurface9 *pSavedRT = NULL; 1397 HTEST(pDevice->GetRenderTarget(0, &pSavedRT)); 1398 1399 IDirect3DSurface9 *pSurface = NULL; 1400 HTEST(pTexture->GetSurfaceLevel(0, &pSurface)); 1401 HTEST(pDevice->SetRenderTarget(0, pSurface)); 1402 1403 HTEST(pDevice->BeginScene()); 1404 1405 HTEST(pDevice->SetStreamSource(0, mpVB, 0, sizeof(Vertex))); 1406 HTEST(pDevice->SetVertexDeclaration(mpVertexDecl)); 1407 HTEST(pDevice->SetVertexShader(mpVS)); 1408 HTEST(pDevice->SetPixelShader(mpPS)); 1409 HTEST(pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)); 1410 HTEST(pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE)); 1411 1412 HTEST(pDevice->SetTexture(0, pTexSrc)); 1413 1414 HTEST(pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2)); 1415 1416 HTEST(pDevice->EndScene()); 1417 1418 HTEST(pDevice->SetRenderTarget(0, pSavedRT)); 1419 1420 D3D_RELEASE(pSurface); 1421 } 1422 1423 HRESULT D3D9RenderTexture::DoRender(D3D9DeviceProvider *pDP) 1424 { 1425 HRESULT hr = S_OK; 1426 1427 IDirect3DDevice9 *pDevice = pDP->Device(0); 1428 1429 renderToTexture(pDevice, mpTexDst, mpTexSrc); 1430 1431 drawTexture(pDevice, mpTexDst, 50, 50, 200, 200); 1432 1433 HTEST(pDevice->Present(0, 0, 0, 0)); 1434 1435 return S_OK; 1436 } 1437 1438 1439 /* 1196 1440 * "Public" interface. 1197 1441 */ … … 1201 1445 switch (iRenderId) 1202 1446 { 1447 case 9: 1448 return new D3D9RenderTexture(); 1203 1449 case 8: 1204 1450 return new D3D9RenderColorFill();
Note:
See TracChangeset
for help on using the changeset viewer.