Please note that this is not my code, just wanted to share since some people still use the old&crappy method.
To demonstrate how fast this is:
For 0-10000 it takes 14 steps to get the correct number
For 0-20000 it takes 15 steps.
For 0-1000000 it takes 20 steps.
And you'll never skip a frame while logging =D
globals:
Code:
int iCurNum = 5000;
int iLastHigh = 10000;
int iLastLow = 0;
bool LogEnabled=false;
IDirect3DTexture9 *pTexBlue;
IDirect3DTexture9 *pTexGreen;
IDirect3DTexture9 *pTexRed;
functions needed(answers why's question I think) :
Code:
int OMGZ(int X, int Y)
{
return (X+Y)/2;
}
HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
return E_FAIL;
WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
|(WORD)(((colour32>>20)&0xF)<<8)
|(WORD)(((colour32>>12)&0xF)<<4)
|(WORD)(((colour32>>4)&0xF)<<0);
D3DLOCKED_RECT d3dlr;
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;
for(int xy=0; xy < 8*8; xy++)
*pDst16++ = colour16;
(*ppD3Dtex)->UnlockRect(0);
return S_OK;
}
During initialization(CD3DManager::Initialize() in Azo's base)
Code:
GenerateTexture(m_pD3Ddev, &pTexBlue, D3DCOLOR_ARGB(255,0,0,255));
GenerateTexture(m_pD3Ddev, &pTexRed, D3DCOLOR_ARGB(255,255,0,0));
GenerateTexture(m_pD3Ddev, &pTexGreen, D3DCOLOR_ARGB(255,0,255,0));
in DrawIndexedPrimitive(hkIDirect3DDevice9:rawIndexedPrimitive in azos base)
Code:
if(LogEnabled==true)
{
if(NumVertices < (UINT)iCurNum&&NumVertices>=(UINT)iLastLow)
{
m_pD3Ddev->SetTexture(0, pTexBlue);
}
else if(NumVertices > (UINT)iCurNum&&NumVertices<=(UINT)iLastHigh)
{
m_pD3Ddev->SetTexture(0, pTexRed);
}
else if(NumVertices == (UINT)iCurNum)
{
m_pD3Ddev->SetTexture(0, pTexGreen);
}
}
in present(hkIDirect3DDevice9::Present in azos base)
Code:
int iTemp = iCurNum;
if(GetAsyncKeyState(VK_NUMPAD4)&1)
{
iCurNum = OMGZ(iCurNum, iLastHigh);
iLastLow = iTemp;
}
else if(GetAsyncKeyState(VK_NUMPAD6)&1)
{
iCurNum = OMGZ(iCurNum, iLastLow);
iLastHigh = iTemp;
}
if(GetAsyncKeyState(VK_NUMPAD0)&1)
{
add_log("/*========================");
add_log(" Logged: %d", iCurNum);
add_log("========================*/");
}
if(GetAsyncKeyState(VK_NUMPAD5)&1)
{
iCurNum = 5000;
iLastHigh = 10000;
iLastLow = 0;
}
if(GetAsyncKeyState(VK_NUMPAD1)&1)
{
LogEnabled =! LogEnabled;
}
Credits: Azorbix
Note that the code posted here is for NumVerts, if you want to do primcounts or strides you'll have to change DrawIndexedPrimitive