• 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
noodleBowl

Index buffer help

5 posts in this topic

Hi All

 

I am having a little trouble with my index buffer and I'm not really sure why

I currently have declared 2 buffer lock holders in a class header file, one for my vertices and one for my indices:

vertex *vertices;
short *indices;

And they are set to NULL in my class constructor

vertices = NULL;
indices = NULL;

But what baffles me is when I write to my vertex buffer lock using:

vertices[currentVertexBufferPosition] = (*i).verts[0];
vertices[currentVertexBufferPosition + 1] = (*i).verts[1];
vertices[currentVertexBufferPosition + 2] = (*i).verts[2];
vertices[currentVertexBufferPosition + 3] = (*i).verts[3];

Everything works and I can get all my expected values back using

//12 because we can hold at most 12 vertices (Max buffer size of 3 quads for testing)
for(int i = 0; i < 12; i++)
	{
		std::cout<<"I["<<i<<"]: X "<<vertices[i].x<<std::endl;
	}

BUT using the same method for my index buffer lock

indices[currentIndexBufferPosition] = currentVertexBufferPosition;
indices[currentIndexBufferPosition + 1] = currentVertexBufferPosition + 1;
indices[currentIndexBufferPosition + 2] = currentVertexBufferPosition + 2;
indices[currentIndexBufferPosition + 3] = currentVertexBufferPosition + 3;
indices[currentIndexBufferPosition + 4] = currentVertexBufferPosition;
indices[currentIndexBufferPosition + 5] = currentVertexBufferPosition + 2;

And same method to get my data

//18 because we can hold at most 18 vertices (Max buffer size of 3 quads for testing)
for(int i = 0; i < 18; i++)
	{
		std::cout<<"I["<<i<<"]: Indices = "<<indices[i]<<std::endl;
	}

I always get 0 back

when I step through, it seems like all of my indices are getting the value of 0.

Like the program is only accepting the first value assigned as the value to use all the time.

 

I know it is not a position issue as I always increase there values at the end of my run

currentIndexBufferPosition += 6;
currentVertexBufferPosition += 4;

Also just in case this is how I am locking, where the bufferLockFlag is set to NOOVERWRITE by default

vBuffer->Lock(0, 0, (void**) &vertices, bufferLockFlag);
iBuffer->Lock(0, 0, (void**) &indices, bufferLockFlag);

/* Code for drawing all loading the vertices / indices in the buffers. If the vertex buffer is full, unlock the buffers and change
the lock flag to DISCARD. Lock the buffers again and change the lokc flag back to NOOVERWRITE*/

vBuffer->Unlock();
iBuffer->Unlock();

Anyone have any ideas why this is happening?

Edited by noodleBowl
0

Share this post


Link to post
Share on other sites

According to your code, you are reading from the vertex and index buffer. Have you specified READ flag in the creation? The memory used for those buffers may not be readable by default. 

 

Otherwise, reading data from GPU resources is typically not a good idea. 

 

Cheers!

0

Share this post


Link to post
Share on other sites

According to your code, you are reading from the vertex and index buffer. Have you specified READ flag in the creation? The memory used for those buffers may not be readable by default. 
 
Otherwise, reading data from GPU resources is typically not a good idea. 
 
Cheers!


The only 2 flags I have when I create my buffers are the D3DUSAGE_WRITEONLY and D3DUSAGE_DYNAMIC flags

My buffers are created like so

batDevice->CreateVertexBuffer(vertexBufferSize, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, CUSTOMFVF2, D3DPOOL_DEFAULT, &vBuffer, NULL);

batDevice->CreateIndexBuffer(indexBufferSize, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &iBuffer, NULL);

But the thing I don't understand is that even if I step through my code it says my buffer is only storing 0 or whatever the first value was set. I don't think it would matter if I have the read flag and I'm stepping through my code. Right?
0

Share this post


Link to post
Share on other sites


But the thing I don't understand is that even if I step through my code it says my buffer is only storing 0 or whatever the first value was set. I don't think it would matter if I have the read flag and I'm stepping through my code. Right?

 

Oh yes it matters, having set D3DUSAGE_WRITEONLY especially ensures that card that you never ever will attempt to read form the buffer, and therefore have it store that data so that it won't ever need to be read back to RAM. That way, when locking the buffer, that handle will contain any data other than what you filled it in previously. The memory of the GPU is seperated from the system RAM, so even if you step through in the debugger, you'll get the same results.

0

Share this post


Link to post
Share on other sites

 
Oh yes it matters, having set D3DUSAGE_WRITEONLY especially ensures that card that you never ever will attempt to read form the buffer, and therefore have it store that data so that it won't ever need to be read back to RAM. That way, when locking the buffer, that handle will contain any data other than what you filled it in previously. The memory of the GPU is seperated from the system RAM, so even if you step through in the debugger, you'll get the same results.


I find this interesting and confusing.

Its interest that saying
 
indices[currentIndexBufferPosition] = currentVertexBufferPosition;
indices[currentIndexBufferPosition + 1] = currentVertexBufferPosition + 1;
indices[currentIndexBufferPosition + 2] = currentVertexBufferPosition + 2;
indices[currentIndexBufferPosition + 3] = currentVertexBufferPosition + 3;
indices[currentIndexBufferPosition + 4] = currentVertexBufferPosition;
indices[currentIndexBufferPosition + 5] = currentVertexBufferPosition + 2;
Is only a link to the GPU and that it is the only thing that knows what is going on

I find it confusing that using the exact same setup code for my vertex buffer, method of filling, and reading works just fine.

Does this mean that its safe to assume I'm not actually having all zeros in my index buffer?
0

Share this post


Link to post
Share on other sites

You should use PIX or some other software the verify the contents of your buffers. That is an easy and good way to handle the situation.

 

If your draw code works fine ie. the output is what you are expecting, then your buffers contain the correct information. 

 

Cheers!

Edited by kauna
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