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

Integrating VAO to work with my VBO's

8 posts in this topic

Hi guys,

I've just done some reading about VAO's and it looks like they can be a decent improvement on my current rendering routine. Currently all of my rendering is done using simple interleaved VBO's with indices (position, normal, uv). My model class has a vector of VBO's (each one relates to a specific sub object in my model format) and i was thinking i could just use a single VAO to describe all of them? I'm not sure however if a VAO can be used for multiple VBO's though.

Currently my drawing routine looks like (don't have code with me):

[CODE]
void drawModel(Model* model)
{
for (int i = 0; i < model->getVBOList(); i++)
{
VBO vbo = model->getVBOList()[i];

glBindBuffer(GL_ARRAY_BUFFER, vbo.id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.ibo.id)
// do vertex attrib pointers
glDrawElements(..)
}
}
[/CODE]

If i had a vertex array object bound to all of these VBO's would it be possible to simply draw them all by binding the VAO and calling drawElements again?

Thanks guys,

- rocklobster
0

Share this post


Link to post
Share on other sites
That's what VAO's are for, yes. They store all vertex array bindings in one object, so as long as the bindings (pointers, enabled attributes, attribute locations and such) remain the same, you only need to bind the VAO and draw.
2

Share this post


Link to post
Share on other sites
Great thanks!

One more question, should i still be using glDrawElements()? The parameter takes the size of my index buffer, but i'm going to be drawing multiple VBO's each with their own index buffer?
0

Share this post


Link to post
Share on other sites
You still have to use glDrawElements, it is not stored in the VAO. The element buffer object is a binding stored in the VAO though, so you don't have to rebind the index buffer every time.

The parameter you're talking about is not the size of the index buffer, but how many indices you want to draw. There is a distict difference between the meaning of the two, especially if the index buffer stores more indices than you want to draw in one single draw call.
2

Share this post


Link to post
Share on other sites
Ah right thanks, so i'll just get the total sum of indices from all the vbo's and use that.
0

Share this post


Link to post
Share on other sites
Hrm, it only seems to be drawing the first VBO. Hate to post a bit of a code dump, but someone might be able to spot an error?

First i'm creating a vertex array object and binding it. Then i iterate over the model data in each VBO and create the opengl VBO from it.

[CODE]
void loadModel(Model* model, bool withIBO)
{
unsigned int indexCount = 0;
GLuint vaoID;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
model->setVAOHandle(vaoID);
for (int i = 0; i < (signed)model->getVBOs()->size(); i++)
{
VBO vbo = model->getVBOs()->at(i);
GLuint vboID;
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, vbo.getArray().size() * sizeof(Vertex), &vbo.getArray()[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(12));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(24));
vbo.setVBOID(vboID);
GLuint iboID;
glGenBuffers(1, &iboID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vbo.getIBO().getArray().size() * sizeof(unsigned int), &vbo.getIBO().getArray()[0], GL_STATIC_DRAW);
vbo.setIBOID(iboID);
indexCount += vbo.getIBO().getArray().size() * sizeof(unsigned int);
}
model->setTotalIndices(indexCount);
}
...
void drawModel(Model* model)
{
glBindVertexArray(model->getVAOHandle());
glDrawElements(GL_TRIANGLES, model->getTotalIndices(), GL_UNSIGNED_INT, BUFFER_OFFSET(0));

}
[/CODE] Edited by rocklobster
0

Share this post


Link to post
Share on other sites
Small misunderstanding here.

[quote name='Brother Bob' timestamp='1339088949' post='4947094']
That's what VAO's are for, yes. They store all vertex array bindings in one object...
[/quote]
That is, one VAO for every object, and you have many objects. So you will need a different VAO for every iteration in the loop.

Notice also that the use of VAO is not optional, it is now mandatory.
1

Share this post


Link to post
Share on other sites
The index count parameter is the number of indices to draw from the currently bound index array, not the total amount from all index arrays you have ever bound. Besides, there is only one index array that can be bound anyway, so your for-loop is overwriting the binding each loop, and then you're trying to draw more than what it contains.

You need one VAO per object in your code. And by object, I mean whatever goes in one iteration of your for-loop. Likewise, you need a for-loop to loop over all VAOs.
2

Share this post


Link to post
Share on other sites
Ah cool, thanks for clearing that up, yeah i was sorta trying to ask that in my initial post. Thanks once again guys.

I'd assume if i had a separate buffer for each normal and uv coordinates it would then be useful because i would have an[left]glEnableVertexAttribArray call [/left]for each buffer Edited by rocklobster
0

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