• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BMW

Calling DrawPrimitive Heaps

4 posts in this topic

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?

Edited by BMW
0

Share this post


Link to post
Share on other sites

Yes, it's a very bad idea.

 

You should render the whole scene with the minimum possible calls to DrawPrimitive. That is, render various cubes at once if possible otherwise performance will degrade very fast.

 

Reducing DrawPrimitive calls by grouping geometry/materials is called batching. You should find lots of info by google for "geometry batching" and similar terms.

1

Share this post


Link to post
Share on other sites

Ok, I will see if I can render an entire chunk using one DrawPrimitive() call. That should help.

0

Share this post


Link to post
Share on other sites

You might be much happier doing a DIP call for each block type, so you don't have to mess up to much with shader parameters.

Doing a whole chunk per-DIP is excessive in my opinion and the issues involved in managing the multiple textures have to be carefully considered.

 

edit: oh, I see you're using a texture atlas from the other thread. No problem then, go ahead!

Edited by Krohm
1

Share this post


Link to post
Share on other sites

You might be much happier doing a DIP call for each block type, so you don't have to mess up to much with shader parameters.

Doing a whole chunk per-DIP is excessive in my opinion and the issues involved in managing the multiple textures have to be carefully considered.

 

edit: oh, I see you're using a texture atlas from the other thread. No problem then, go ahead!

 

WOW WOWOWOWOWOWOWOWOWOWOWOW

 

Using the inferior method as discussed earlier (heaps of draw primitive calls) = 62FPS.

 

Using new method - 1 DIP call per chunk = 320FPS. THATS IT, THREE HUNDRED AND TWENTY FRAMES PER SECOND. (Considering my laptop has integrated graphics, NOT TOO FOUL!!!!)

 

THIS IS THE BEST DAY OF MY LIFE.

 

THANK YOU EVERYONE.

 

I love game development.

 

EDIT: Is updating the entire index buffer for the chunk every time a block changes a good idea? It seems to run ok.

 

This is how I update index buffer:

void Chunk::UpdateIndices()
{
	void* IB = NULL;

	unsigned int* pIBEntry = NULL;

	PrimitiveCount = 0;

	if(g_pIB->Lock(0, BLOCKS_PER_CHUNK * INDICES_PER_BLOCK * 4, &IB, D3DLOCK_DISCARD) != D3D_OK)
		return;

	pIBEntry = (unsigned int*)IB;

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

		if(blocks[i].FrontFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
		if(blocks[i].BackFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK + 4;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 4 + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 4 + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 4 + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 4 + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 4 + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
		if(blocks[i].LeftFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK + 8;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 8 + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 8 + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 8 + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 8 + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 8 + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
		if(blocks[i].RightFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK + 12;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 12 + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 12 + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 12 + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 12 + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 12 + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
		if(blocks[i].TopFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK + 16;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 16 + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 16 + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 16 + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 16 + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 16 + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
		if(blocks[i].BottomFaceVisible)
		{
			*pIBEntry = i * VERTICES_PER_BLOCK + 20;
			*(pIBEntry + 1) = i * VERTICES_PER_BLOCK + 20 + 1;
			*(pIBEntry + 2) = i * VERTICES_PER_BLOCK + 20 + 2;
			*(pIBEntry + 3) = i * VERTICES_PER_BLOCK + 20 + 1;
			*(pIBEntry + 4) = i * VERTICES_PER_BLOCK + 20 + 3;
			*(pIBEntry + 5) = i * VERTICES_PER_BLOCK + 20 + 2;
			pIBEntry += 6;
			PrimitiveCount += 2;
		}
	}

	g_pIB->Unlock();
}
Edited by BMW
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0