Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#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