Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBMW

Posted 09 July 2013 - 05:04 AM

Hi all,

 

In my voxel engine similar to Minecraft, I draw each side of each block separately, like this:

for(unsigned int i = 0; i < BLOCKS_PER_CHUNK; i++)
{
	if(blocks[i].type == BLOCKTYPE_AIR)
		continue;

	if(blocks[i].BackFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 4, 2);
	}
	if(blocks[i].FrontFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK), 2);
	}
	if(blocks[i].LeftFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 8, 2);
	}
	if(blocks[i].RightFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 12, 2);
	}
	if(blocks[i].TopFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 16, 2);
	}
	if(blocks[i].BottomFaceVisible)
	{
		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 20, 2);
	}
}

Is it a bad idea to call DrawPrimitive so much like this? Should I use an index buffer and just make one call to DrawIndexedPrimitive?


#1BMW

Posted 09 July 2013 - 05:03 AM

Hi all,

 

In my voxel engine similar to Minecraft, I draw each side of each block separately, like this:

for(unsigned int i = 0; i < BLOCKS_PER_CHUNK; i++)
		{
			if(blocks[i].type == BLOCKTYPE_AIR)
				continue;

			if(blocks[i].BackFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 4, 2);
			}
			if(blocks[i].FrontFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK), 2);
			}
			if(blocks[i].LeftFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 8, 2);
			}
			if(blocks[i].RightFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 12, 2);
			}
			if(blocks[i].TopFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 16, 2);
			}
			if(blocks[i].BottomFaceVisible)
			{
				g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, (i * VERTICES_PER_BLOCK) + 20, 2);
			}
		}

Is it a bad idea to call DrawPrimitive so much like this? Should I use an index buffer and just make one call to DrawIndexedPrimitive?


PARTNERS