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

Performance, VBOs and Objects

3 posts in this topic

Hi,

 

I was making a simple game in C++ and OpenGL with what I learned from a bunch of pretty old tutorials (which I discovered later), and now I'm in the process of updating everything and I've got some questions about the VBO implementation.

 

I had this code:

 

class Vertex
{
    public:
        float posX, posY, posZ;
};
class Face
{
    public:
        Vertex** vertexes;
        //bunch of functions to get and set the vertexes and their values
};
class Object3D : public Object
{
    public:
        Face* faces;
        Vertex* vertexes;
        //bunch of functions to initialize the vertexes and faces
};

 

So my Object3D had an array of all vertexes informations, each with their X, Y and Z, and another array for Faces, which gave me the addresses of 3 Vertexes that composed 1 Face of the object.

It worked fine since I was calling:

 

void Game::Draw(Object3D* object)
{
    for(int i = 0; i < object->totalFaces; i++)
    {
        glVertex3f(object->faces[i].GetVertex[0]->posX, object->faces[i].GetVertex[0]->posY, object->faces[i].GetVertex[0]->posZ);
        glVertex3f(object->faces[i].GetVertex[1]->posX, object->faces[i].GetVertex[1]->posY, object->faces[i].GetVertex[1]->posZ);
        glVertex3f(object->faces[i].GetVertex[2]->posX, object->faces[i].GetVertex[2]->posY, object->faces[i].GetVertex[2]->posZ);
    }
}

 

But now that I'm going to turn everything into VBOs, I need a single array with the sequential float values of each of the object's faces, so it means I'll even have to repeat some vertex's values sometime when they share the same point.

This is where I'm at, I'm trying to figure what would be the best way to do this.

My animation code (unfinished) moved the vertexes according to the bone's movement and weight, and all I had to do was to change the values in my "vertexes[]" array of the Object3D, and I didn't had to worry about it's faces.

Now, I will have to change the new vertex data array I'll be buffering as VBO, and I'd like to get some ideas on how.

 

I have no experience releasing games, and I never seen a professional/released engine code before, so I've got literally no idea what's the common approach to this.

 

For now I'm thinking in getting something like this:

 

class Object3D : public class Object
{
    public:
        float* vertexData; // = new float[totalVertexes]; - this will be what I'll send/map to the VBO as data
        //same as before, vertex and faces arrays
};

 

And everytime there's a change in the model, I'll change the vertexes array as usual, and then update the values in "vertexData" and finally update the VBO.

This seems a bad idea as I'll be doing this for every animated object in the screen... and I'd be using twice as much memory for every model since I have two variables with the same values.

 

Isn't there a way to send the VBO data in a different manner? If it searched by index, I think I could create a class and override the brackets operator to send the address that I want, but since it's function asks for the size, I'm guessing it moves by memory size...

 

Is there any good approaches to this, or what's the best way to do this? (I'd like to totally scrap the vertexes array and only work with the vertexData I've sent/mapped to the VBO)

0

Share this post


Link to post
Share on other sites

You can do what you just said. Just repeat the vertices that are shared among several faces. It will work.

 

Or you could look up indexed drawing, which is more or less what your face system did. You have an array of all the (non repeated) vertices and an array of indices. The array of indices is what describes how to draw your mesh. Each triangle will require 3 indices, and those indices are going to be used by your GPU for fetching the vertex data in your vertex array.

 

Say that several faces use the 3rd vertex in your vertex array. Instead of repeating 3 times the same vertex, you just use the index array to point to the 3rd vertex for each of the faces that use it.

1

Share this post


Link to post
Share on other sites

Thanks, that was exactly what I was looking for!

 

I got one question about it now that I've implemented most of it: Can you use only one VBO ID for all of the objects' data?

In an older topic here in GameDev there was a post saying that you can use the VBO ID to store different data, though I think the example might be wrong (http://www.gamedev.net/topic/178256-vbo-texture-coords/).

 

I'm thinking if something like this is possible:

 

glGenBuffers(1, &object->ObjectID);
glBindBuffer(GL_ARRAY_BUFFER, object->ObjectID);
glBufferData(GL_ARRAY_BUFFER, object->GetVertexSize(), object->GetVertexData(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, object->GetIndexSize(), object->GetIndexData(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, object->GetTextureSize(), object->GetTextureData(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, object->GetNormalSize(), object->GetNormalData(), GL_STATIC_DRAW);

//And then for drawing
glBindBufferARB(GL_ARRAY_BUFFER_ARB, object->ObjectID);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, 0); //0 because it was the first data uploaded
glTexCoordPointer(2, GL_FLOAT, 0, object->GetIndexSize() + object->GetVertexSize()); //begin after both the index/vertex bytes' size
glNormalPointer(GL_FLOAT, 0, object->GetIndexSize() + object->GetVertexSize() + object->GetNormalSize()); //begin after all 3 datas

 


Is it better than creating 4 VBOs?

 

 

I can't test it since I'm still trying to figure how to fill my Texture Coords from a FBX file, any help in how do I decipher those values are also appreciated!

0

Share this post


Link to post
Share on other sites

You can use a single buffer object, yes, but you have to load it at different places and not keep replacing the attributes. Your current code creates a buffer object for the vertex data, and then replaces the entire buffer with the index data, and then replaces the index buffer with the texture data, and so on. You're left with a buffer containing the normal data only.

 

You need to allocate a buffer large enough to contain all the data, and then load parts of the buffer with the corresponding data.

glGenBuffers(1, &object->ObjectID);
glBindBuffer(GL_ARRAY_BUFFER, object->ObjectID);
glBufferData(GL_ARRAY_BUFFER, object->GetVertexSize()+object->GetTextureSize()+object->GetNormalSize(), 0, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, object->GetVertexSize(), object->GetVertexData());
glBufferSubData(GL_ARRAY_BUFFER, object->GetVertexSize(), object->GetNormalSize(), object->GetNormalData());
glBufferSubData(GL_ARRAY_BUFFER, object->GetVertexSize()+object->GetNormalSize(), object->GetTextureSize(), object->GetTextureData());

 

Also, if your index pointer is the vertex index data, then you must put it in a GL_ELEMENT_ARRAY_BUFFER object.

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