Hello guys, I want to render some Mesh and it's Bounding Box. I didn't want to use multiple VAOs because I thought this could be done using single one since data is kind of related (each mesh has it's own bounding box). I've created Mesh class, whose constructor initializes Bounding Box for that mesh. Bounding box holds reference to mesh so it can access it's VAO. I've filled VAO with both mesh VBO and EBO, and bounding box VBO and EBO. I was wondering if I should make separate VAOs for mesh and bounding box? Also should I make separate shaders since I am using Phong shading for my meshes (thought I could just not send uniforms to shaders since they will ignore them if vlaue is not provided)? 1st picture shows my meshes being rendered when bounding box is disabled, other one is bounding box being enabled.
https://paste.ofcode.org/FGxqCvpJws7azpJugDHs9H
https://paste.ofcode.org/LKpY864uhYFyguq39FsfLv
My Mesh and BoundingBox classes have a lot of common which is poorly written... (I've read somewhere that those should be separate classes)
I don't know how to tell program to stop after rendering Mesh data (first VBO) and then use different approach (basically just gllines instead of triangles) when it comes to rendering 2nd VBO
#Rendering multiple VBOs using single VAO
97 messages ยท Page 1 of 1 (latest)
think of the vao as your vertex input descriptor/input layout
normal mesh has positions, normals, uvs, perhaps tangents and other stuff
a bounding box is just position and color perhaps, to visualize them better
that means you should have 2 vaos, one per vertex type
since it describes how the input assembly is supposed to interpret your vertexbuffer to be able to send it off to the vertex shader
Thank you very much for the reply. Let me just see if I got it right: If VBOs have same input layouts, they should use same vao?
Question just for the future reference: If VBO's have same input layouts, they will use same drawing logic? We don't have to specify when to draw data from 1st VBO, or when to draw data from 2nd VBO, it will draw it all one after the other (all must be drawn)?
Since VBO's have same input layouts, they will be drawn in the same way, and there won't be any complication as shown in images above? The only downside is that we can't tell VAO to draw certain amount of VBOs that it contains (for example it can't draw 5 out of 7 total VBOs that are stored in it)?
Should you also have different instances of vertex and fragment shaders (one for each vao)?
Sorry for lot of questions, I am still figuring things out ๐
Thank you ๐
this part is not so simple
vao and vbo are not contained in each other
vaos refer to one or many vbo
since you can source attributes from 1 or many buffers
but you can change that association at any time
so for example, you use 1 vao for a cube, a sphere and a cone
but cube and sphere and cone vertices live in differnt vbos
then you bind the vao, bind cubevbo then draw, then bind spherevbo then draw, then bind conevbo then draw
there are like 10 different ways to do it better, but i suppose you are a beginner witha ll this opengl stuff, so doing it the naive way is alright
Yeah sorry I expressed myself poorly
no worries
vao/vbo/ebo and their relationship is poorly explained in any opengl tutorial
I have function that binds VBO and EBO to VAO when setting up the mesh (that's also the part where I fill my VBO and EBO with data, and then first unind VAO followed by unbinding VBO and EBO - that way they are still bound to VAO). When I draw meshes, I just bind VAO and draw stuff
I don't think there is need to bind VBO everytime it is being drawn since it is linked (or bound?) to VAO right?
Only bounding VAO is necesarry right?
if you have a vao per mesh thats fine
like cubevao, spherevao, conevao
its the most naive and trivial case beginners should implement this
when you learn more about opengl and what it has to offer later you can always refactor your stuff towards to "more modern" stuff
Oh I thought that separate vao for every mesh was optimal?
Could you give me an example of what would more modern use of vao look like?
For example if I wanted to render 10 houses, 7 trees and 15 car meshes, I can't imagine putting all of that in single vao because you can't render different numbers of those meshes in same vao (i think?)
for now it really doesnt matter
1 vao per mesh it totally fine
then you add lights and shadows later
render more complicated things
perhaps try out deferred rendering or advanced forward techniques
then you will learn how to make that vao nonsens more proper, or get rid of them entirely
but its good that you understood how they work and what they mean in the beginning
Got it, thank you for all the help!
It means a lot
np
Just for curiosity: if you have multiple vbos linked to same vao, can you render different amounts of those meshes?
Or is the number the same
you usually have 1 set of vbo/ebo linked to a vao at a time
if we stay in naive land
like
ah
hang on i missread
Yeah true, but if we used more modern approach and put multiple vbos and ebos to same vao
yes
lets assume
cubevao, cubevbo, cubeebo
spherevao, spherevbo, sphereebo
you can render 1 cube and 20 spheres with that
or 400 cubes and 2 spheres
if that was the question
I was thinking more about this case:
shared vao which contains cubevbo cubeebo spherevbo and sphereebo
Will do. Thank you very much ๐
you understand what vaos really are
later
you can then do
bind vertexpositioncolor-vao
bind cubevbo
draw 100 cubes
bind spherevbo
draw 20 spheres
I thought I was missing out on lot haha. This is awesome to hear
cube and sphere vbo will match the vao, ie contain vertexpositioncolor data, in this example here
then you might want to draw some ui... which only has position and uv data
Thank you once again for all the info, Ill keep going at my pace and hopefully one day make something non lame haha
Ui as in user interface?
ye
Yeah thats what I am aiming for currently
ideally, work through learnopengl.com once, you dont have to understand each and everything immediately to the fullest, make notes about stuff which doesnt make sense, but keep on reading
I've passed lighting chapter recently
cool
Do you recommend reading whole thing or are there some things that arent that relevant
Learnopengl.com is great literature, it has a lot of info, definitely best stuff that ive found on opengl
I will probably skip materials for now as I have to focus on some other aspects for university
dont skip
work through it, it wont take too much time anyway
and will probably explain a few things which come up later
or make more sense then
Good point, I'll work through it all, it doesnt cost me anything to atleast read chapters after all