How do I manage loaded geometry?

Started by
5 comments, last by 21st Century Moose 11 years ago

I have created a parser that will load my custom geometry. when it loads the geometry it places the vertex array into a VBO. I want to make many of the same object or introduce new objects into the scene but use them later as one is playing the game. how do i store geometry so it is not loading from a file into the VBO when it is called upon? but rather from some sort of buffer that holds it in an efficient way until its needed perhaps.

one of the things I am trying to set up are missiles for a tank game. I want the user to be able to just shut a 100 missiles back to back. each missile geometry is the same. how would you recommend I create multiple missiles with our having to load the geometry for each missile every time the user fires the missile?

thanks

J-GREEN

Greenpanoply
Advertisement

You didn't specify if you are using c/c++ so I'll assume c++.

The easiest way to do this would be to pass around your VAO id. For every object that uses that mesh just have a copy of that VAO id. When you get ready to draw a missile for example you just bind the vao, send in your objects world matrix ( to the shader uniform ), and draw. This is called instancing.

Another way to handle it is more work but more robust, create a Manager Class that manages your Meshes. You have a vector of pointers to mesh objects ( use unique_ptr ) in the mesh manager and you can get a pointer to a managed mesh object, from that Manager class, by file name.

Managing Textures and Shaders can also be done in similar ways.

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

In OpenGL, there are specific draw calls for instancing (drawing multiple copies of the same thing) so you don't have to care about keeping them all in memory - just keep their locations in a texture and render based on that and instanceID. Just write a class that handles a single model and load all your geometry as instances of that class in the beginning of your program.

I am not understanding "powly k", What do you mean just keep their locations in a texture? also what are these specific OpenGL draw calls for instancing?

J-GREEN

Greenpanoply

A texture can easily be read in a shader and written to on the CPU, so you can upload your positions and orientations as a texture, though you probably should do it with uniform buffers or something. The draw calls i was referring to are glDrawArraysInstanced and glDrawElementsInstanced.

You could of course just use a vertex attrib via glVertexAttribDivisor instead.

Regarding this part:

how do i store geometry so it is not loading from a file into the VBO when it is called upon?

You seem unaware that you can have more than one VBO created. Psuedocode for load-time might look something like this:


GLuint geometryBuffers[NUM_GEOMETRY];

glGenBuffers (NUM_GEOMETRY, geometryBuffers);

for (int i = 0; i < NUM_GEOMETRY; i++)
{
    LoadGeometryItem (i);
    glBindBuffer (GL_ARRAY_BUFFER, geometryBuffers);
    glBufferData (GL_ARRAY_BUFFER, ...);
}

And for drawing:


for (int i = 0; i < NUM_GEOMETRY; i++)
{
    glBindBuffer (GL_ARRAY_BUFFER, geometryBuffers);
    glEnableVertexAttribArray (...);
    glVertexAttribPointer (...);
    glDrawArrays (...);
}

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement