Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering dynamic VertexBuffer using static IndexBuffer (solved)

Started by ds2k5 May 24, 2009 at 7:02 AM 0 replies 700+ views
Original Post
ds2k5
ds2k5
EDIT: Thread can be deleted. It took me several days to notice that I simply used the INDEX16 format when creating my index buffer, although I actually used integer indices. ------------------------------------------------------------------------------ Hi there, I'm really new to Direct3D (DirectX9, native) and while trying to get a dynamic vertex buffer working I've encountered a serious problem. I should say that I use a static index buffer, since I don't really expect my indices to change. The problem itself is that when I tell D3D to draw my vertices, it doesn't. Since I've been looking for a solution for a couple of days now I'll be very detailed and hope that anyone can help me. What I do: 1.) Creating device and static vertex buffer. 2.) Rendering static buffer only (everything works as expected so far) ... 3.) At some point, via mouse click in this case, I create a new VB and IB

if(m_d3dVertexBufferDynamic != NULL)
     m_d3dVertexBufferDynamic->Release();

m_d3dDevice->CreateVertexBuffer(m_iCurrentLengthV * sizeof(VertexTextured),
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
		FVF_TEXTURED,
		D3DPOOL_DEFAULT,
		buffer,
		NULL);

if(m_d3dIndexBufferDynamic != NULL)
     m_d3dIndexBufferDynamic->Release();

m_d3dDevice->CreateIndexBuffer(m_iCurrentLengthI * sizeof(int),
	D3DUSAGE_WRITEONLY,
	D3DFMT_INDEX16,
	D3DPOOL_DEFAULT,
	&m_d3dIndexBufferDynamic,
	NULL);

void* pData;
m_d3dIndexBufferDynamic->Lock(0, 0, &pData, 0);
memcpy(pData, m_pItemsI, m_iCurrentLengthI * sizeof(int));
m_d3dIndexBufferDynamic->Unlock();

device->SetIndices(m_d3dIndexBufferDynamic);




(the index buffer is called "m_d3dIndexBufferDynamic" because it stores the indices of the dynamic VB, not because it is a dynamic one itself) For the sake of simpleness I've put together the relevant code from the several classes I actually have. So m_iCurrentLength is the count of elements in a dynamic array of vertices or indices with the suffix V or I respectively and m_pItems is the array/pointer itself. 4.) Rendering both, static and dynamic buffer

if(m_d3dVertexBufferDynamic != NULL)
{
   void* pData;
   m_d3dVertexDynamicBuffer->Lock(0, 0, &pData, D3DLOCK_DISCARD);
   memcpy(pData, m_pItemsV, m_iCurrentLengthV * sizeof(VertexTextured));
   m_d3dVertexDynamicBuffer->Unlock();
}

m_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_dwBackColor, 1.0f, 0);
m_d3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, m_dwBackColor, 1.0f, 0);

m_d3dDevice->BeginScene();
m_d3dDevice->SetFVF(FVF_TEXTURED);

[Transformations...]
[Render static buffer...]

if(m_d3dVertexBufferDynamic != NULL)
{
  m_d3dDevice->SetStreamSource(0, m_d3dVertexBufferDynamic, 0, sizeof(VertexTextured));
  m_d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iVertices, 0, m_iCurrentLengthI / 3);
}

m_d3dDevice->EndScene();
m_d3dDevice->Present(NULL, NULL, NULL, NULL);




What happens: - Nothing. Nothing is being drawn on the screen. Right, so something must have gone wrong. What I do then: - I set my DX debug level to the highest possible and let PIX run the application for 5 seconds. Still nothing. The log doesn't show a single error. The DrawIndexedPrimitive calls happen with proper parameters. - Well, if PIX won't help me, I have to look for the problem further myself. I decided to check if the data in the VRAM is like it's supposed to be. After copying my dynamic arrays I read the data back, set a breakpoint and it was (unsurprisingly) correct. In order to read the data I locked VB and IB respectively, and I've also used GetIndices for the index buffer, each of those having the same result: there's nothing wrong with the data. The fact that everything seems fine, but still won't work drives me crazy. I'd be really grateful if anyone could help me out on this one. Thanks for the help in advance. [Edited by - ds2k5 on May 24, 2009 11:51:33 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.