Archived

This topic is now archived and is closed to further replies.

supagu

DrawIndexedPrimitive failing!?

Recommended Posts

im trying to create my own mesh class, and im having issues getting DrawIndexPrimitive to actually work. My Mesh is made up of a "textureBatch" which is just an index and vertex buffer with a texture and a material, so a mesh can have any number of these textureBatches here is my render function (this just loops through the sections(vector of textureBatches) and renders each one:
int Mesh::Render()
{
	int polys = 0;

	for( int i=0; i < sections.size(); i++)
	{

		//TEMP
		LPDIRECT3DINDEXBUFFER9 pIndexBuffer = sections.GetIndexBuffer();
		systemLog.WriteLog("RENDER TBATCH INDEX BUFFER %d", sections[i].GetNumPrimitives()*3);
		//see whats in buffer
		DWORD* index;
		if( FAILED( pIndexBuffer->Lock(0, 0, (void**)&index, 0) ))
		{
			systemLog.WriteLog("Lock ASE Vertex buffer [FAILED]");
		}

		for( int v = 0; v < sections[i].GetNumPrimitives()*3; v++ )
		{
			systemLog.WriteLog("RENDER TBATCH: index:%d references: %d", v, index[v]);
		}

		pIndexBuffer->Unlock();


		//see whats in buffer
		LPDIRECT3DVERTEXBUFFER9 pVertexBuffer = sections[i].GetVertexBuffer();
		STANDARD_VERTEX* vertex;
		if( FAILED( pVertexBuffer->Lock(0, 0, (void**)&vertex, 0) ))
		{
			systemLog.WriteLog("Lock ASE Vertex buffer [FAILED]");
		}

		for(  v = 0; v < sections[i].GetNumVertices(); v++ )
		{
			systemLog.WriteLog("RENDER TBATCH: index:%d v: %f %f %f", v, vertex[v].p.x,vertex[v].p.y,vertex[v].p.z);
		}

		pVertexBuffer->Unlock();

		//END TEMP


		systemLog.WriteLog("no verts:%d no prims:%d", sections[i].GetNumVertices(), sections[i].GetNumPrimitives());

		if (FAILED(Direct3D:D3DDevice->SetIndices( sections[i].GetIndexBuffer() ) ))
			systemLog.WriteLog("set indices [FAILED]");

		if (FAILED(Direct3D:D3DDevice->SetStreamSource(0, sections[i].GetVertexBuffer() , 0, sizeof(STANDARD_VERTEX)) ))
			systemLog.WriteLog("set stream [FAILED]");

		//if (FAILED(Direct3D:D3DDevice->SetFVF(STANDARD_FVF) ))
		//	systemLog.WriteLog("set fvf [FAILED]");

		if (FAILED(Direct3D:D3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
								  0, 0, sections[i].GetNumVertices() ,
								  0,  sections[i].GetNumPrimitives() )))
		{
			systemLog.WriteLog("Draw Mesh sections [FAILED]");
		}

		polys += sections[i].GetNumPrimitives();
		systemLog.WriteLog("rendering section: %d noPolys:%d",i, sections[i].GetNumPrimitives());
	}

	return polys;
}
 
i have included debugging code and this is the out put i get from this section:
RENDER TBATCH INDEX BUFFER 6
RENDER TBATCH: index:0 references: 1
RENDER TBATCH: index:1 references: 0
RENDER TBATCH: index:2 references: 3
RENDER TBATCH: index:3 references: 2
RENDER TBATCH: index:4 references: 3
RENDER TBATCH: index:5 references: 0

RENDER TBATCH: index:0 v: -28.500000 35.700001 -78.900002
RENDER TBATCH: index:1 v: 29.200001 17.400000 -78.900002
RENDER TBATCH: index:2 v: -43.599998 -12.200000 -78.900002
RENDER TBATCH: index:3 v: 14.100000 -30.400000 -78.900002

no verts:4 no prims:2
Draw Mesh sections [FAILED]
rendering section: 0 noPolys:2
 
as you can see the index buffer has thr right data, and so does the vertex buffer, the setindicies and setsourcestream works, but for some quere reason drawindexprimitive fails? any ideas are much appreciated

Share this post


Link to post
Share on other sites
First, you should at least tell us the value of the HRESULT returned when the API fails.

Second, have you run your app with the debug DX runtime and cranked up the debug level?

Share this post


Link to post
Share on other sites
It''s a 32 bit value. The DX9 SDK ships with a DirectX Error Lookup app. Look at the HRESULT in the debugger and then use the app to get a description of the error.

There is no output in the debugger when the API fails? Are you sure you''re running the debug DX runtime?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is how i do my dx calls:

#include <dxerr9.h>

//you also have to include dxerr9.lib into the project

HRESULT hr;

hr = d3ddevice->DrawIndexedPrimitive(.....);
if(FAILED(hr))
{
std::string str = "DrawIndexed Primitive failed in ......";
//this gives you the string version of the dxerror by
//passing it the HRESULT
str += DxGetErrorDescription9(hr);
//then send the string to a messagebox or your log
}


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you might want to take a look at the DXGetErrorStringN and DXGetErrorDescriptionN functions, where N is 8 or 9, depending upon what DX SDK version you''re using.

Share this post


Link to post
Share on other sites