Jump to content
  • Advertisement
Sign in to follow this  
floatingwoods

glDrawElements without indices?

This topic is 1552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I am using VBO's together with glDrawElements to quickly render a bunch of triangles. In my case, since each triangle has exactly 3 vertices, 3 normals and 3 texture coordinates, I could get rid of the indices and avoid having another VBO taking memory on the GPU.

My indices are always starting at zero and continuous.

 

Is there a way to avoid having to upload those indices?

 

Another option would be to have one single index buffer on the GPU that serves all the geometries that I need to render, but that is still taking some memory on the GPU.

 

Finally, and linked to the VBO's: how do people usually handle situations where there is no more free memory on the GPU for VBOs:

 

- how to notice that?

- how to overcome that?

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

Thank you COlumbo, that's exactly what I was looking for!

 

For the second part, how can I find out if my GPU's memory is already saturated?

 

Thanks

Share this post


Link to post
Share on other sites

Thank you for the clarification L. Spiro, which actually confuses me a little bit ;)

 

Take texture memory. Does that mean that if you try to put too many textures onto the GPU, some textures will automatically be flushed? If yes, then this means I might have to upload textures more than one time!?

 

I somehow feel that texure memory is yet another story. But take VBOs: I creating them via Qt, like:

QGLBuffer* myVBO=new QGLBuffer(QGLBuffer::VertexBuffer);
myVBO->create();
myVBO->bind();
myVBO->setUsagePattern(QGLBuffer::StaticDraw);
myVBO->allocate(vertices,3*verticesCnt*sizeof(float));

and everytime, in order to use them, I call:

myVBO->bind();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,0);
glDrawArrays(GL_TRIANGLES,0,verticesCnt);
glDisableClientState(GL_VERTEX_ARRAY);

And that works fine. I never have to upload the vertices to the GPU again. So is there something that happens behind the scene?

 

Thanks

 

Share this post


Link to post
Share on other sites

GPU Memory management shouldn't be treated any differently that CPU memory management. If the driver virtualize the memory and handling flushing on overcomit, thats great, but does that mean one should do it? The major graphics API provide means to check out of memory situation, though reactive instead of pro-active, its better than nothing. Properly design software should check these conditions and react accordingly. Also, just to clarify memory is memory wrt to the GPU, there is no separate texture memory, VBO, FBO, IBO memory. To the driver, they are just a block of memory with semantics attached to them( covering usage, access etc ).
 In the example you gave above, the memory is allocated by the driver and there is no need to upload anything else unless you are changing the content of the memory. The binding call and the client state setup is just telling the driver that all subsequent draw call will use the bounded buffer as the source for vertex data. There is no upload taking place in this case.

I guess the most important question is are you running on a memory constraint hw for you to be worried about running out of memory for such small amount of vertex data ?

Share this post


Link to post
Share on other sites

Take texture memory. Does that mean that if you try to put too many textures onto the GPU, some textures will automatically be flushed? If yes, then this means I might have to upload textures more than one time!?

 

The driver handles this automatically for you.  If your video RAM (there's no such thing as dedicated memory for textures any more) becomes overcommitted, the driver will swap textures out to system memory, and automatically swap them back in to video RAM as required, so there's no manual intervention required.

 

The best way of dealing with this is actually not to query GPU memory and make decisions based on that.  Instead you'll set a minimum required specification and use that as a guideline when sizing your assets.  Nowadays 1gb might be a realistic "run on all hardware" minimum, although if you want to target really old hardware you might set your minimum to 512mb.  Anything lower than that, you just don't bother supporting.

Share this post


Link to post
Share on other sites

Interesting, thanks to both of you!

 

So what about following strategy:

 

I keep track of all textures and VBOs that I have registered with the GPU. If I notice that I am coming close to a saturation, then I release a few textures or VBOs that were not used for a while... (e.g. not used because out of sight). Does that sound reasonable?

Share this post


Link to post
Share on other sites

Does that sound reasonable?

Not as reasonable as, “Make all the VBO’s you need and let the driver worry about the rest.”
Just because you’ve made a VBO it doesn’t necessarily mean it is consuming GPU RAM.
As I said, let the driver page in and page out memory. No game needs 2 GPU memory managers.


L. Spiro

Share this post


Link to post
Share on other sites

As I said, let the driver page in and page out memory. No game needs 2 GPU memory managers.

 

This, basically.

 

I'll add: just because you can it doesn't mean that you should.  The idea is that this should never even happen.  Just as you shouldn't write your own GPU memory manager, neither should the driver ever have to swap out resources.  If you're over-committing video RAM you don't start thinking about swapping out resources, you do start thinking about reducing the size of your resources.  So say you target a 1gb card and you find that you need 1.5gb - what you do is reduce the resolution of your textures, you reduce the polycount of your models, you think about using compressed textures or compressed vertex formats, you get everything to fit in that 1gb.

 

The reason why is because creating and destroying resources is expensive.  Disk access is now the primary bottleneck for a lot of computing tasks.  So you don't build something that has such heavy reliance on your slowest form of storage.  It all adds up to runtime hitches that affect the gameplay experience.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!