Changeset 98909 in vbox for trunk/src/VBox/Additions/WINNT/Graphics
- Timestamp:
- Mar 10, 2023 4:49:13 PM (23 months ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d9main.cpp
r98138 r98909 201 201 mPP.BackBufferFormat = D3DFMT_UNKNOWN; 202 202 #else 203 mPP.BackBufferWidth = 640; 204 mPP.BackBufferHeight = 480; 203 RECT clientRect; 204 GetClientRect(mHwnd, &clientRect); 205 mPP.BackBufferWidth = clientRect.right; 206 mPP.BackBufferHeight = clientRect.bottom; 205 207 mPP.BackBufferFormat = D3DFMT_X8R8G8B8; 206 208 #endif -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d9render.cpp
r98103 r98909 28 28 #include "d3d9render.h" 29 29 30 #include <intrin.h> 30 31 31 32 static HRESULT d3dCopyToVertexBuffer(IDirect3DVertexBuffer9 *pVB, const void *pvSrc, int cbSrc) … … 1448 1449 1449 1450 /* 1451 * Render a texture to screen. 1452 */ 1453 1454 class D3D9RenderTextureToScreen: public D3D9Render 1455 { 1456 public: 1457 D3D9RenderTextureToScreen(float cPixelShift); 1458 virtual ~D3D9RenderTextureToScreen(); 1459 virtual HRESULT InitRender(D3D9DeviceProvider *pDP); 1460 virtual HRESULT DoRender(D3D9DeviceProvider *pDP); 1461 private: 1462 IDirect3DVertexBuffer9 *mpVB; 1463 IDirect3DVertexDeclaration9 *mpVertexDecl; 1464 IDirect3DVertexShader9 *mpVS; 1465 IDirect3DPixelShader9 *mpPS; 1466 IDirect3DTexture9 *mpTex; 1467 1468 static const int cxTexture = 4; 1469 static const int cyTexture = 4; 1470 float mcPixelShift; 1471 1472 struct Vertex 1473 { 1474 D3DVECTOR position; 1475 float x, y; 1476 }; 1477 static D3DVERTEXELEMENT9 VertexElements[]; 1478 static DWORD adwTextureData[cxTexture * cyTexture]; 1479 }; 1480 1481 D3DVERTEXELEMENT9 D3D9RenderTextureToScreen::VertexElements[] = 1482 { 1483 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, 1484 {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, 1485 D3DDECL_END() 1486 }; 1487 1488 DWORD D3D9RenderTextureToScreen::adwTextureData[cxTexture * cyTexture] = 1489 { 1490 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00FFFFFF, 1491 0x0000FF00, 0x00FF0000, 0x000000FF, 0x00FFFFFF, 1492 0x00FF0000, 0x000000FF, 0x0000FF00, 0x00FFFFFF, 1493 0x0000FFFF, 0x00FF00FF, 0x00FFFF00, 0x00FFFFFF, 1494 }; 1495 1496 1497 D3D9RenderTextureToScreen::D3D9RenderTextureToScreen(float cPixelShift) 1498 : 1499 mpVB(0), 1500 mpVertexDecl(0), 1501 mpVS(0), 1502 mpPS(0), 1503 mpTex(0), 1504 mcPixelShift(cPixelShift) 1505 { 1506 } 1507 1508 D3D9RenderTextureToScreen::~D3D9RenderTextureToScreen() 1509 { 1510 D3D_RELEASE(mpVS); 1511 D3D_RELEASE(mpPS); 1512 D3D_RELEASE(mpVB); 1513 D3D_RELEASE(mpVertexDecl); 1514 D3D_RELEASE(mpTex); 1515 } 1516 1517 HRESULT D3D9RenderTextureToScreen::InitRender(D3D9DeviceProvider *pDP) 1518 { 1519 IDirect3DDevice9 *pDevice = pDP->Device(0); 1520 1521 static DWORD aVSCode[] = 1522 { 1523 0xFFFE0200, // vs_2_0 1524 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, // def c0, 1, 0, 0, 0 1525 0x0200001f, 0x80000000, 0x900f0000, // dcl_position v0 1526 0x0200001f, 0x80000005, 0x900f0001, // dcl_texcoord v1 1527 0x02000001, 0xc0070000, 0x90e40000, // mov oPos.xyz, v0 1528 0x02000001, 0xc0080000, 0xa0000000, // mov oPos.w, c0.x 1529 0x02000001, 0xe0030000, 0x90e40001, // mov oT0.xy, v1 1530 0x0000FFFF 1531 }; 1532 1533 static DWORD aPSCodePass[] = 1534 { 1535 0xffff0200, // ps_2_0 1536 0x0200001f, 0x80000000, 0xb0030000, // dcl t0.xy 1537 0x0200001f, 0x90000000, 0xa00f0800, // dcl_2d s0 1538 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, // texld r0, t0, s0 1539 0x02000001, 0x800f0800, 0x80e40000, // mov oC0, r0 1540 0x0000ffff 1541 }; 1542 1543 static DWORD aPSCodeCoord[] = 1544 { 1545 0xffff0200, // ps_2_0 1546 0x0200001f, 0x80000000, 0xb0010000, // dcl t0.x 1547 0x02000001, 0x800f0000, 0xb0000000, // mov r0, t0.x 1548 0x02000001, 0x800f0800, 0x80e40000, // mov oC0, r0 1549 0x0000ffff 1550 }; 1551 1552 D3DVIEWPORT9 vp; 1553 pDevice->GetViewport(&vp); 1554 1555 int x1 = 1; 1556 int y1 = 1; 1557 int x2 = x1 + cxTexture * 1; 1558 int y2 = y1 + cyTexture * 1; 1559 1560 float cPixelShift = mcPixelShift; 1561 1562 #define VX(x) ( 2.0f * (float(x) + cPixelShift) / float(vp.Width) - 1.0f) 1563 #define VY(y) (-2.0f * (float(y) + cPixelShift) / float(vp.Height) + 1.0f) 1564 1565 Vertex vTopLeft = { { VX(x1), VY(y1), 0.0f }, 0.0f, 0.0f}; 1566 Vertex vBottomLeft = { { VX(x1), VY(y2), 0.0f }, 0.0f, 1.0f}; 1567 Vertex vTopRight = { { VX(x2), VY(y1), 0.0f }, 1.0f, 0.0f}; 1568 Vertex vBottomRight = { { VX(x2), VY(y2), 0.0f }, 1.0f, 1.0f}; 1569 1570 Vertex aVertices[6] = 1571 { 1572 vBottomLeft, vBottomRight, vTopLeft, 1573 vTopLeft, vBottomRight, vTopRight 1574 }; 1575 1576 HRESULT hr = S_OK; 1577 1578 HTEST(pDevice->CreateVertexDeclaration(VertexElements, &mpVertexDecl)); 1579 HTEST(pDevice->CreateVertexBuffer(sizeof(aVertices), 1580 0, /* D3DUSAGE_* */ 1581 0, /* FVF */ 1582 D3DPOOL_DEFAULT, 1583 &mpVB, 1584 0)); 1585 HTEST(pDevice->CreateVertexShader(aVSCode, &mpVS)); 1586 HTEST(pDevice->CreatePixelShader(aPSCodePass, &mpPS)); 1587 1588 HTEST(d3dCopyToVertexBuffer(mpVB, aVertices, sizeof(aVertices))); 1589 1590 HTEST(pDevice->CreateTexture(cxTexture, 1591 cyTexture, 1592 1, 1593 D3DUSAGE_DYNAMIC, 1594 D3DFMT_A8R8G8B8, 1595 D3DPOOL_DEFAULT, 1596 &mpTex, 1597 NULL)); 1598 1599 D3DLOCKED_RECT LockedRect; 1600 HTEST(mpTex->LockRect(0, &LockedRect, NULL /* entire texture */, D3DLOCK_DISCARD)); 1601 1602 unsigned char *pu8Dst = (unsigned char *)LockedRect.pBits; 1603 for (int y = 0; y < cyTexture; ++y) 1604 { 1605 memcpy(pu8Dst, &adwTextureData[y * cxTexture], 4 * cxTexture); 1606 pu8Dst += LockedRect.Pitch; 1607 } 1608 1609 HTEST(mpTex->UnlockRect(0)); 1610 1611 return hr; 1612 } 1613 1614 HRESULT D3D9RenderTextureToScreen::DoRender(D3D9DeviceProvider *pDP) 1615 { 1616 HRESULT hr = S_OK; 1617 1618 IDirect3DDevice9 *pDevice = pDP->Device(0); 1619 1620 HTEST(pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff7f7f7f, 1.0f, 0)); 1621 1622 HTEST(pDevice->BeginScene()); 1623 1624 HTEST(pDevice->SetStreamSource(0, mpVB, 0, sizeof(Vertex))); 1625 HTEST(pDevice->SetVertexDeclaration(mpVertexDecl)); 1626 HTEST(pDevice->SetVertexShader(mpVS)); 1627 HTEST(pDevice->SetPixelShader(mpPS)); 1628 HTEST(pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)); 1629 HTEST(pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE)); 1630 1631 HTEST(pDevice->SetTexture(0, mpTex)); 1632 HTEST(pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR)); 1633 HTEST(pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR)); 1634 HTEST(pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR)); 1635 1636 HTEST(pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2)); 1637 1638 HTEST(pDevice->EndScene()); 1639 1640 HTEST(pDevice->Present(0, 0, 0, 0)); 1641 1642 return S_OK; 1643 } 1644 1645 1646 /* 1450 1647 * "Public" interface. 1451 1648 */ … … 1455 1652 switch (iRenderId) 1456 1653 { 1654 case 11: 1655 return new D3D9RenderTextureToScreen(0.0f); 1656 case 10: 1657 return new D3D9RenderTextureToScreen(-0.5f); 1457 1658 case 9: 1458 1659 return new D3D9RenderTexture();
Note:
See TracChangeset
for help on using the changeset viewer.