Jump to content

  • Log In with Google      Sign In   
  • Create Account

How do I manage loaded geometry?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 greenzone   Members   -  Reputation: 672

Like
0Likes
Like

Posted 19 March 2013 - 02:42 PM

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


Edited by greenzone, 19 March 2013 - 03:25 PM.

J-GREEN

Greenpanoply

Sponsor:

#2 EddieV223   Members   -  Reputation: 1406

Like
2Likes
Like

Posted 19 March 2013 - 03:46 PM

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.


Edited by EddieV223, 19 March 2013 - 05:02 PM.

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.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// 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

 


#3 powly k   Members   -  Reputation: 653

Like
1Likes
Like

Posted 19 March 2013 - 05:32 PM

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.


Edited by powly k, 19 March 2013 - 05:34 PM.


#4 greenzone   Members   -  Reputation: 672

Like
0Likes
Like

Posted 20 March 2013 - 11:20 AM

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

#5 powly k   Members   -  Reputation: 653

Like
1Likes
Like

Posted 20 March 2013 - 03:13 PM

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.



#6 RobTheBloke   Crossbones+   -  Reputation: 2342

Like
0Likes
Like

Posted 26 March 2013 - 05:36 PM

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



#7 mhagain   Crossbones+   -  Reputation: 7970

Like
1Likes
Like

Posted 26 March 2013 - 08:44 PM

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[i]);
    glBufferData (GL_ARRAY_BUFFER, ...);
}

 

And for drawing:

 

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

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS