OpenGL Optimization, glBindBuffer() and glBufferData() vs creating new VBO? - c++

I have a class that makes textures in OpenGL 4.3.
So my question is...
Would it be faster if I render by changing one vertex buffer's vertices for each texture?
OR
Would it be faster if I have a vertex buffer for every texture that contains its own vertices?
I know the 1st method would require glBindBuffer() and glBufferData() every frame which sounds bad?
2nd method would mean I would call glGenBuffers, glBindBuffer, glBufferData once then only call glBindBuffer every frame. Although the 2nd method sounds good I want to hear other opinions.
Some context:
Creating 2d game engine that can use images and draw pixels quickly on textures or primitives using two different shaders.

Related

Displaying a framebuffer in OpenGL

I've been learning a bit of OpenGL lately, and I just got to the Framebuffers.
So by my current understanding, if you have a framebuffer of your own, and you want to draw the color buffer onto the window, you'll need to first draw a quad, and then wrap the texture over it? Is that right? Or is there something like glDrawArrays(), glDrawElements() version for framebuffers?
It seems a bit... Odd (clunky? Hackish?) to me that you have to wrap a texture over a quad in order to draw the framebuffer. This doesn't have to be done with the default framebuffer. Or is that done behind your back?
Well. The main point of framebuffer objects is to render scenes to buffers that will not get displayed but rather reused somewhere, as a source of data for some other operation (shadow maps, High dynamic range processing, reflections, portals...).
If you want to display it, why do you use a custom framebuffer in the first place?
Now, as #CoffeeandCode comments, there is indeed a glBlitFramebuffer call to allow transfering pixels from one framebuffer to another. But before you go ahead and use that call, ask yourself why you need that extra step. It's not a free operation...

Multiple VBOs and IBOs How to Handle

Actually, I have a lot of models that are produced by cpu.(around 100K and one of them around 100 triangle) and all model has its vbo and ibo. If I try to draw each model with glDrawElements() it is quite slow. also if I try to draw combine all vbos and ibos if a model is deleted I need to update vbo also almost all ibo because of removed points change index order and then I need the buffer all of these again it is slow. Also I am not sure about instancing performance and picking I need to know which triangle belongs to which model.Is there any way to buffer and than one draw function draw all individual model with its own vbo and index?
You can set a base vertex per mesh and pass it to the glDrawElementsBaseVertex call. This will still require a call per mesh which can be solved with glMultiDrawElementsBaseVertex with which you can combine them all into a single draw call.

OpenGL glBegin vs Vertex Buffer Arrays VBO

I want to make an OpenGL game but now realize that what I've learned in school -> draw objects directly by glBegin/glEnd -> is old-school and bad. Readings on the internet I see that Vertex Buffer Objects and GLSL is the "proper" method for 3d programming.
1) Should I use OpenGL's glDrawArrays or glDrawElements?
2) For a game with many entities/grounds/objects, must the render function be many glDrawArrays():
foreach(entity in entities):
glDrawArrays(entitiy->arrayFromMesh()) //Where we get an array of the mesh vertex points
or only one glDrawArrays() that encapsulates every entity:
glDrawArrays(map->arrayFromAllMeshes())
3) Does every graphics layer (such as DirectX) now standardize Vertex Buffer Objects?
1) Should I use OpenGL's glDrawArrays or glDrawElements?
This depends on what your source data looks like. glDrawArrays is a little less complex, as you just have to draw a stream of vertices, but glDrawElements is useful in a situation where you have many vertices which are shared by several triangles. If you're just drawing sprites, then glDrawArrays is probably the simplest, but glDrawElements is useful for huge complex meshes where you want to save buffer space.
2) For a game with many entities/grounds/objects, must the render function be many glDrawArrays() or only one glDrawArrays() that encapsulates every entity:
Again this is somewhat optional, but note that you can't change program state in the middle of a drawarrays call. So that means that any two objects which need different state (different textures, different shaders, different blend settings), must have a separate draw call. However it can sometimes be helpful for performance to group as many similar things into a single draw call as you can.
3) Does every graphics layer (such as DirectX) now standardize Vertex Buffer Objects?
DirectX does have a similar concept, yes.

Difficulty understanding the usage of VBOs

So I'm trying to implement VBOs but I can't find a good tutorial or documentation of the proper usage of them. I'm guessing you make a VBO when some object needs it and then when the next frame comes about it's drawn/redrawn. But here is where I'm confused:
How do I draw multiple VBOs?
How do I modify a VBO?
When and where do I make a new VBO?
I'm really sorry and I'm just learning OpenGL so excuse me for that! But it's hard to find a tutorial that doesn't just make one VBO, and doesn't make that VBO at the same time it's drawn.
Mainly what I'm asking for is a better understanding of how VBOs work, where they are stored, and how they are drawn. How many VBOs is too many? When I call glVertexPointer() what exactly happens with stored VBOs? What if I'm trying to draw VBOs of different types? (just use triangles?)
How do I draw multiple VBOs?
VBOs are data storage, just like textures. There's a function called glBindBuffer which binds a VBO for subsequent access through glVertexAttribPointer.
How do I modify a VBO?
glBufferSubData
or
buf = glMapBuffer(...);
modify_on(buf);
glUnmapBuffer(...);
When and where do I make a new VBO?
Whenever the existing VBOs no longer can satisfy your demands. Either because they're to small, full or don't match your data type.

Rendering multiple VBOs in one draw call in OpenGL

I have a few hundred VBOs. I want to only draw a subset of the VBOs each frame.
Is there anything faster than binding and drawing each VBO? Is there a batched draw command for multiple VBOs?
How do I bind multiple VBOs
Is there a version of glMultiDrawElements for sets of VBOs?
AFAIK there is not, because there is only one GL_ARRAY_BUFFER binding point and only one buffer can be bound to it at anytime.