Jump to content
  • Advertisement
Sign in to follow this  
blueskies9041

OpenGL Having a VBO/VAO for each object.

This topic is 2052 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

http://tomdalling.com/blog/category/modern-opengl/

 

I asked this earlier, but I'm gonna do it again with a bit more detail.

 

I'm working on a 2D Game Framework for a college assignment, I need to handle Basic sprite creation and animation, along with text display. I've read through probably about 30 different tutorials now, and this one above seems promising.

 

However I've been told that having a VAO/VBO for each object I'm rendering (each sprite in this case) is not good as that leads to more OpenGL binding and draw calls. In that tutorial (and almost every other tutorial I've seen) objects each have their own VBO/VAO.

 

How would I go about getting multiple textured quads on screen using only one VBO?

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

What version and profile are you using? In core you require a valid VAO to be bound, but you don't need a VBO bound to render. For instance:

 

glsl:

const vec2 position[4] = vec2[]
(
    vec2(-1.0,  1.0),
    vec2(-1.0, -1.0),
    vec2( 1.0,  1.0),
    vec2( 1.0, -1.0)
);

void main()
{
    gl_Position = vec4(position[gl_VertexID], 0.0, 1.0);
}

gl:

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

This draws a fullscreen quad without any need for vertex buffers, vertex attributes, etc. Maybe you could use glDrawArraysInstanced to render multiple quads with one call and use a UBO/SSBO to store an array of sprite data which contains your position, orientation, etc for each sprite. You can index this array with gl_InstanceID. You can also store an index into a texture array that contains all of your sprite textures. This would keep the number of GL calls to a minimum.

Edited by Chris_F

Share this post


Link to post
Share on other sites

 

I'm working on a 2D Game Framework for a college assignment, I need to handle Basic sprite creation and animation, along with text display.

 

You don't need a vbo then. About 7 years ago when I started openGL I used to draw all my models with glBegin()/glEnd() drawing 100,000 some vertices at 60 fps or more I dont know. So for a basic 2D game say mario, then vbo's arent even needed. So whatever you decide to do I wouldn't worry too much about architecture in managing sprites. Managing sprites/particles in a next-gen 3d renderer is when you need to get down to managing sprite vbos.

Edited by dpadam450

Share this post


Link to post
Share on other sites

SSBO (UBO would work too)
Isn't a shader storage buffer object considerably slower than an uniform buffer object?

 

Though of course the SSBO allows you to run sprite animations right on the GPU and write the resulting positions into the SSBO without round-trip. Given an array texture, the u/v texture coordinates are redundant, too, so you probably only need to care about which layer a sprite uses as actual data... really a good idea actually.

 

Now how do you simulate a SSBO when you need to support OpenGL 3.3 as well... glCopyBufferSubData from something else (transform feedback, texture) into an UBO?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!