Changeset 30138 in vbox
- Timestamp:
- Jun 9, 2010 6:49:01 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62538
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
r30133 r30138 1531 1531 Assert(pDevice->pDevice9If); 1532 1532 Assert(!pFlagBuffer); 1533 IDirect3DVertexDeclaration9* pDecl; 1534 HRESULT hr = pDevice->pDevice9If->GetVertexDeclaration(&pDecl); 1535 Assert(hr == S_OK); 1536 if (hr == S_OK) 1537 { 1538 Assert(pDecl); 1539 D3DVERTEXELEMENT9 aDecls9[MAXD3DDECLLENGTH]; 1540 UINT cDecls9 = 0; 1541 hr = pDecl->GetDeclaration(aDecls9, &cDecls9); 1533 HRESULT hr = S_OK; 1534 1535 if (!pDevice->cStreamSources) 1536 { 1537 Assert(pDevice->aStreamSourceUm[0].pvBuffer); 1538 #ifdef DEBUG 1539 for (UINT i = 1; i < RT_ELEMENTS(pDevice->aStreamSourceUm); ++i) 1540 { 1541 Assert(!pDevice->aStreamSourceUm[i].pvBuffer); 1542 } 1543 #endif 1544 hr = pDevice->pDevice9If->DrawPrimitiveUP(pData->PrimitiveType, 1545 pData->PrimitiveCount, 1546 pDevice->aStreamSourceUm[0].pvBuffer, 1547 pDevice->aStreamSourceUm[0].cbStride); 1548 Assert(hr == S_OK); 1549 } 1550 else 1551 { 1552 IDirect3DVertexDeclaration9* pDecl; 1553 hr = pDevice->pDevice9If->GetVertexDeclaration(&pDecl); 1542 1554 Assert(hr == S_OK); 1543 1555 if (hr == S_OK) 1544 1556 { 1545 Assert(cDecls9); 1546 for (UINT i = 0; i < cDecls9 - 1 /* the last one is D3DDECL_END */; ++i) 1547 { 1548 D3DVERTEXELEMENT9 *pDecl9 = &aDecls9[i]; 1549 Assert(pDecl9->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm) || pDecl9->Stream == 0xff); 1550 if (pDecl9->Stream != 0xff) 1557 Assert(pDecl); 1558 D3DVERTEXELEMENT9 aDecls9[MAXD3DDECLLENGTH]; 1559 UINT cDecls9 = 0; 1560 hr = pDecl->GetDeclaration(aDecls9, &cDecls9); 1561 Assert(hr == S_OK); 1562 if (hr == S_OK) 1563 { 1564 Assert(cDecls9); 1565 for (UINT i = 0; i < cDecls9 - 1 /* the last one is D3DDECL_END */; ++i) 1551 1566 { 1552 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrc = &pDevice->aStreamSourceUm[pDecl9->Stream]; 1553 if (pStrSrc->pvBuffer) 1567 D3DVERTEXELEMENT9 *pDecl9 = &aDecls9[i]; 1568 Assert(pDecl9->Stream < RT_ELEMENTS(pDevice->aStreamSourceUm) || pDecl9->Stream == 0xff); 1569 if (pDecl9->Stream != 0xff) 1554 1570 { 1555 WORD iStream = pDecl9->Stream; 1556 D3DVERTEXELEMENT9 *pLastCDecl9 = pDecl9; 1557 for (UINT j = i+1; j < cDecls9 - 1 /* the last one is D3DDECL_END */; ++j) 1571 PVBOXWDDMDISP_STREAMSOURCEUM pStrSrc = &pDevice->aStreamSourceUm[pDecl9->Stream]; 1572 if (pStrSrc->pvBuffer) 1558 1573 { 1559 pDecl9 = &aDecls9[j]; 1560 if (iStream == pDecl9->Stream) 1574 WORD iStream = pDecl9->Stream; 1575 D3DVERTEXELEMENT9 *pLastCDecl9 = pDecl9; 1576 for (UINT j = i+1; j < cDecls9 - 1 /* the last one is D3DDECL_END */; ++j) 1561 1577 { 1562 pDecl9->Stream = 0xff; /* mark as done */ 1563 Assert(pDecl9->Offset != pLastCDecl9->Offset); 1564 if (pDecl9->Offset > pLastCDecl9->Offset) 1565 pLastCDecl9 = pDecl9; 1578 pDecl9 = &aDecls9[j]; 1579 if (iStream == pDecl9->Stream) 1580 { 1581 pDecl9->Stream = 0xff; /* mark as done */ 1582 Assert(pDecl9->Offset != pLastCDecl9->Offset); 1583 if (pDecl9->Offset > pLastCDecl9->Offset) 1584 pLastCDecl9 = pDecl9; 1585 } 1566 1586 } 1567 } 1568 /* vertex size is MAX(all Offset's) + sizeof (data_type with MAX offset) + stride*/ 1569 UINT cbVertex = pLastCDecl9->Offset + pStrSrc->cbStride; 1570 UINT cbType; 1571 switch (pLastCDecl9->Type) 1572 { 1573 case D3DDECLTYPE_FLOAT1: 1574 cbType = sizeof (float); 1575 break; 1576 case D3DDECLTYPE_FLOAT2: 1577 cbType = sizeof (float) * 2; 1578 break; 1579 case D3DDECLTYPE_FLOAT3: 1580 cbType = sizeof (float) * 3; 1581 break; 1582 case D3DDECLTYPE_FLOAT4: 1583 cbType = sizeof (float) * 4; 1584 break; 1585 case D3DDECLTYPE_D3DCOLOR: 1586 cbType = 4; 1587 break; 1588 case D3DDECLTYPE_UBYTE4: 1589 cbType = 4; 1590 break; 1591 case D3DDECLTYPE_SHORT2: 1592 cbType = sizeof (short) * 2; 1593 break; 1594 case D3DDECLTYPE_SHORT4: 1595 cbType = sizeof (short) * 4; 1596 break; 1597 case D3DDECLTYPE_UBYTE4N: 1598 cbType = 4; 1599 break; 1600 case D3DDECLTYPE_SHORT2N: 1601 cbType = sizeof (short) * 2; 1602 break; 1603 case D3DDECLTYPE_SHORT4N: 1604 cbType = sizeof (short) * 4; 1605 break; 1606 case D3DDECLTYPE_USHORT2N: 1607 cbType = sizeof (short) * 2; 1608 break; 1609 case D3DDECLTYPE_USHORT4N: 1610 cbType = sizeof (short) * 4; 1611 break; 1612 case D3DDECLTYPE_UDEC3: 1613 cbType = sizeof (signed) * 3; 1614 break; 1615 case D3DDECLTYPE_DEC3N: 1616 cbType = sizeof (unsigned) * 3; 1617 break; 1618 case D3DDECLTYPE_FLOAT16_2: 1619 cbType = 2 * 2; 1620 break; 1621 case D3DDECLTYPE_FLOAT16_4: 1622 cbType = 2 * 4; 1623 break; 1624 default: 1625 AssertBreakpoint(); 1626 cbType = 1; 1627 } 1628 cbVertex += cbType; 1629 1630 UINT cVertexes; 1631 switch (pData->PrimitiveType) 1632 { 1633 case D3DPT_POINTLIST: 1634 cVertexes = pData->PrimitiveCount; 1635 break; 1636 case D3DPT_LINELIST: 1637 cVertexes = pData->PrimitiveCount * 2; 1638 break; 1639 case D3DPT_LINESTRIP: 1640 cVertexes = pData->PrimitiveCount + 1; 1641 break; 1642 case D3DPT_TRIANGLELIST: 1643 cVertexes = pData->PrimitiveCount * 3; 1644 break; 1645 case D3DPT_TRIANGLESTRIP: 1646 cVertexes = pData->PrimitiveCount + 2; 1647 break; 1648 case D3DPT_TRIANGLEFAN: 1649 cVertexes = pData->PrimitiveCount + 2; 1650 break; 1651 default: 1652 AssertBreakpoint(); 1653 cVertexes = pData->PrimitiveCount; 1654 } 1655 UINT cbVertexes = cVertexes * cbVertex; 1656 IDirect3DVertexBuffer9 *pCurVb = NULL, *pVb = NULL; 1657 UINT cbOffset; 1658 UINT cbStride; 1659 hr = pDevice->pDevice9If->GetStreamSource(iStream, &pCurVb, &cbOffset, &cbStride); 1660 Assert(hr == S_OK); 1661 if (hr == S_OK) 1662 { 1663 if (pCurVb) 1587 /* vertex size is MAX(all Offset's) + sizeof (data_type with MAX offset) + stride*/ 1588 UINT cbVertex = pLastCDecl9->Offset + pStrSrc->cbStride; 1589 UINT cbType; 1590 switch (pLastCDecl9->Type) 1664 1591 { 1665 if (cbStride == pStrSrc->cbStride) 1592 case D3DDECLTYPE_FLOAT1: 1593 cbType = sizeof (float); 1594 break; 1595 case D3DDECLTYPE_FLOAT2: 1596 cbType = sizeof (float) * 2; 1597 break; 1598 case D3DDECLTYPE_FLOAT3: 1599 cbType = sizeof (float) * 3; 1600 break; 1601 case D3DDECLTYPE_FLOAT4: 1602 cbType = sizeof (float) * 4; 1603 break; 1604 case D3DDECLTYPE_D3DCOLOR: 1605 cbType = 4; 1606 break; 1607 case D3DDECLTYPE_UBYTE4: 1608 cbType = 4; 1609 break; 1610 case D3DDECLTYPE_SHORT2: 1611 cbType = sizeof (short) * 2; 1612 break; 1613 case D3DDECLTYPE_SHORT4: 1614 cbType = sizeof (short) * 4; 1615 break; 1616 case D3DDECLTYPE_UBYTE4N: 1617 cbType = 4; 1618 break; 1619 case D3DDECLTYPE_SHORT2N: 1620 cbType = sizeof (short) * 2; 1621 break; 1622 case D3DDECLTYPE_SHORT4N: 1623 cbType = sizeof (short) * 4; 1624 break; 1625 case D3DDECLTYPE_USHORT2N: 1626 cbType = sizeof (short) * 2; 1627 break; 1628 case D3DDECLTYPE_USHORT4N: 1629 cbType = sizeof (short) * 4; 1630 break; 1631 case D3DDECLTYPE_UDEC3: 1632 cbType = sizeof (signed) * 3; 1633 break; 1634 case D3DDECLTYPE_DEC3N: 1635 cbType = sizeof (unsigned) * 3; 1636 break; 1637 case D3DDECLTYPE_FLOAT16_2: 1638 cbType = 2 * 2; 1639 break; 1640 case D3DDECLTYPE_FLOAT16_4: 1641 cbType = 2 * 4; 1642 break; 1643 default: 1644 AssertBreakpoint(); 1645 cbType = 1; 1646 } 1647 cbVertex += cbType; 1648 1649 UINT cVertexes; 1650 switch (pData->PrimitiveType) 1651 { 1652 case D3DPT_POINTLIST: 1653 cVertexes = pData->PrimitiveCount; 1654 break; 1655 case D3DPT_LINELIST: 1656 cVertexes = pData->PrimitiveCount * 2; 1657 break; 1658 case D3DPT_LINESTRIP: 1659 cVertexes = pData->PrimitiveCount + 1; 1660 break; 1661 case D3DPT_TRIANGLELIST: 1662 cVertexes = pData->PrimitiveCount * 3; 1663 break; 1664 case D3DPT_TRIANGLESTRIP: 1665 cVertexes = pData->PrimitiveCount + 2; 1666 break; 1667 case D3DPT_TRIANGLEFAN: 1668 cVertexes = pData->PrimitiveCount + 2; 1669 break; 1670 default: 1671 AssertBreakpoint(); 1672 cVertexes = pData->PrimitiveCount; 1673 } 1674 UINT cbVertexes = cVertexes * cbVertex; 1675 IDirect3DVertexBuffer9 *pCurVb = NULL, *pVb = NULL; 1676 UINT cbOffset; 1677 UINT cbStride; 1678 hr = pDevice->pDevice9If->GetStreamSource(iStream, &pCurVb, &cbOffset, &cbStride); 1679 Assert(hr == S_OK); 1680 if (hr == S_OK) 1681 { 1682 if (pCurVb) 1666 1683 { 1667 /* ensure our data feets in the buffer */ 1668 D3DVERTEXBUFFER_DESC Desc; 1669 hr = pCurVb->GetDesc(&Desc); 1684 if (cbStride == pStrSrc->cbStride) 1685 { 1686 /* ensure our data feets in the buffer */ 1687 D3DVERTEXBUFFER_DESC Desc; 1688 hr = pCurVb->GetDesc(&Desc); 1689 Assert(hr == S_OK); 1690 if (hr == S_OK) 1691 { 1692 if (Desc.Size >= cbVertexes) 1693 pVb = pCurVb; 1694 } 1695 } 1696 } 1697 } 1698 else 1699 { 1700 pCurVb = NULL; 1701 } 1702 1703 if (!pVb) 1704 { 1705 hr = pDevice->pDevice9If->CreateVertexBuffer(cbVertexes, 1706 0, /* DWORD Usage */ 1707 0, /* DWORD FVF */ 1708 D3DPOOL_DEFAULT, /* D3DPOOL Pool */ 1709 &pVb, 1710 NULL /*HANDLE* pSharedHandle*/); 1711 Assert(hr == S_OK); 1712 if (hr == S_OK) 1713 { 1714 hr = pDevice->pDevice9If->SetStreamSource(iStream, pVb, 0, pStrSrc->cbStride); 1670 1715 Assert(hr == S_OK); 1671 1716 if (hr == S_OK) 1672 1717 { 1673 if (Desc.Size >= cbVertexes) 1674 pVb = pCurVb; 1718 if (pCurVb) 1719 pCurVb->Release(); 1720 } 1721 else 1722 { 1723 pVb->Release(); 1724 pVb = NULL; 1675 1725 } 1676 1726 } 1677 1727 } 1678 } 1679 else 1680 { 1681 pCurVb = NULL; 1682 } 1683 1684 if (!pVb) 1685 { 1686 hr = pDevice->pDevice9If->CreateVertexBuffer(cbVertexes, 1687 0, /* DWORD Usage */ 1688 0, /* DWORD FVF */ 1689 D3DPOOL_DEFAULT, /* D3DPOOL Pool */ 1690 &pVb, 1691 NULL /*HANDLE* pSharedHandle*/); 1692 Assert(hr == S_OK); 1693 if (hr == S_OK) 1728 1729 if (pVb) 1694 1730 { 1695 hr = pDevice->pDevice9If->SetStreamSource(iStream, pVb, 0, pStrSrc->cbStride); 1731 Assert(hr == S_OK); 1732 VOID *pvData; 1733 hr = pVb->Lock(0, /* UINT OffsetToLock */ 1734 cbVertexes, 1735 &pvData, 1736 D3DLOCK_DISCARD); 1696 1737 Assert(hr == S_OK); 1697 1738 if (hr == S_OK) 1698 1739 { 1699 if (pCurVb) 1700 pCurVb->Release(); 1740 memcpy (pvData, ((uint8_t*)pStrSrc->pvBuffer) + pData->VStart * cbVertex, cbVertexes); 1741 HRESULT tmpHr = pVb->Unlock(); 1742 Assert(tmpHr == S_OK); 1701 1743 } 1702 else1703 {1704 pVb->Release();1705 pVb = NULL;1706 }1707 }1708 }1709 1710 if (pVb)1711 {1712 Assert(hr == S_OK);1713 VOID *pvData;1714 hr = pVb->Lock(0, /* UINT OffsetToLock */1715 cbVertexes,1716 &pvData,1717 D3DLOCK_DISCARD);1718 Assert(hr == S_OK);1719 if (hr == S_OK)1720 {1721 memcpy (pvData, ((uint8_t*)pStrSrc->pvBuffer) + pData->VStart * cbVertex, cbVertexes);1722 HRESULT tmpHr = pVb->Unlock();1723 Assert(tmpHr == S_OK);1724 1744 } 1725 1745 } … … 1727 1747 } 1728 1748 } 1729 }1730 if (hr == S_OK)1731 {1732 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType,1733 0 /* <- since we use our owne StreamSource buffer which has data at the very beginning*/,1734 pData->PrimitiveCount);1735 Assert(hr == S_OK);1749 if (hr == S_OK) 1750 { 1751 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, 1752 0 /* <- since we use our owne StreamSource buffer which has data at the very beginning*/, 1753 pData->PrimitiveCount); 1754 Assert(hr == S_OK); 1755 } 1736 1756 } 1737 1757 } -
trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.h
r30133 r30138 79 79 D3DDDI_CREATEDEVICEFLAGS fFlags; 80 80 HWND hWnd; 81 /* number of StreamSources set */ 82 UINT cStreamSources; 81 83 VBOXWDDMDISP_STREAMSOURCEUM aStreamSourceUm[16]; 82 84 IDirect3DDevice9 *pDevice9If;
Note:
See TracChangeset
for help on using the changeset viewer.