Hi, I am using C++ and Direct3D9.
My problem is that if I have any more than 72 vertices sent to the vertex buffer nothing renders. If there are 72 vertices, everything renders. If I have 78 vertices nothing renders (well, none of the primitives sent to the vertex buffer renders).
My app is 2d, I have z buffer disabled and a dynamic vertex buffer. My vertices are size 24, eg sizeof(VERTEX)=24 (I'm not sure whether it's bits, bytes). According to my code checking the directx9 device caps, my max vertex count=65535 and my max primitive count=65535.
//Create a dynamic vertex buffer in system memory
void CVertexManager::SetupVertexBuffer(void)
{
//create d3d9 vertex buffer
HRESULT hr=g_pD3DDevice9->CreateVertexBuffer(sizeof(VERTEX)*10920,D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,g_dwFVF,D3DPOOL_SYSTEMMEM,&g_pVertexBuffer,NULL);
g_Log<<"SetupVertices() Create Vertex Buffer: "<<DXGetErrorString9(hr)<<endl;
}
//add 6 vertices to list of vertices (vertex buffer will later be filled with vertices from the list)
void CVertexManager::AddSquare(RECT &recPos,const float &fZOrder,TILE &TilePos)
{
if(m_lstVertexList.empty()==true)
{
m_nPrimitiveCount=0;
}
//vertices must be sort in order of Z value (0.0 close, >0.0 far). Z values closer to 0 are rendered first.
//Use RECT coordinates to create vertices
VERTEX vrtBottomLeft,vrtTopLeft,vrtTopRight,vrtBottomRight;
vrtBottomLeft.x=recPos.left; vrtBottomLeft.y=recPos.bottom; vrtBottomLeft.z=fZOrder; vrtBottomLeft.rhw=1.0f; vrtBottomLeft.tu=TilePos.m_tuLeft; vrtBottomLeft.tv=TilePos.m_TvBottom;
vrtTopLeft.x=recPos.left; vrtTopLeft.y=recPos.top; vrtTopLeft.z=fZOrder; vrtTopLeft.rhw=1.0f; vrtTopLeft.tu=TilePos.m_tuLeft; vrtTopLeft.tv=TilePos.m_tvTop;
vrtTopRight.x=recPos.right; vrtTopRight.y=recPos.top; vrtTopRight.z=fZOrder; vrtTopRight.rhw=1.0f; vrtTopRight.tu=TilePos.m_tuRight; vrtTopRight.tv=TilePos.m_tvTop;
vrtBottomRight.x=recPos.right; vrtBottomRight.y=recPos.bottom; vrtBottomRight.z=fZOrder; vrtBottomRight.rhw=1.0f; vrtBottomRight.tu=TilePos.m_tuRight; vrtBottomRight.tv=TilePos.m_TvBottom;
//add six vertices to the list of vertices(orignal)
// v2---v3|v5 //0.0-----0.0 //tu=horizontal
// | /| //| / | //tv=vertical
// | / | //| / |
// | / | //| / |
//v1|v4---v6 //0.0-----1.0
m_lstVertexList.push_back(vrtBottomLeft);
m_lstVertexList.push_back(vrtTopLeft);
m_lstVertexList.push_back(vrtTopRight);
m_lstVertexList.push_back(vrtBottomLeft);
m_lstVertexList.push_back(vrtTopRight);
m_lstVertexList.push_back(vrtBottomRight);
//update how many primitives and vertices there are to render
++m_nPrimitiveCount;++m_nPrimitiveCount;
}
//filling the vertex buffer with vertices from a vector list
void CVertexManager::FillVertexBuffer(void)
{
//stable sort vertices in order of z value
stable_sort(m_lstVertexList.begin(),m_lstVertexList.end());
//fill vertex buffer
void *vb_vertices;
g_pVertexBuffer->Lock(0,0,&vb_vertices,0);
memcpy(vb_vertices,&(m_lstVertexList[0]),m_lstVertexList.size()*sizeof(VERTEX));
g_pVertexBuffer->Unlock();
//clear list of vertices
m_lstVertexList.clear();
}
Anyone able to help?
[Edited by - utilae on June 1, 2005 7:20:02 PM]