I don’t know how to make opengl go any faster. In my ENTIRE project, i have only ONE Vertex Array Object, ONE Vertex Buffer Object, ONE Index Buffer Object, and only ONE Shader.
However, i am calling glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr) 100 times in a loop, and that drops my FPS down A LOT, Please help me, i am developing a 2D game, but because of this problem, i cant move forward.
Side note: I only made a VBO VAO IBO once in my program (meaning that its not in a loop). If i render only 4, 6, 10 etc, it still drops my FPS. I need help. If someone really needs my code, i will give it.
Is the behavior even defined if you pass in a nullptr...? 100 calls of 2x triangles could be improved, but it shouldn't be that detrimental.
i render only 4, 6, 10 etc, it still drops my FPS.
Drops your FPS from what to what? You're making us completely guess. Also, it's probably more accurate to measure your render time instead of the overall frame rate.
Are you re-allocating the triangles/buffers each time in the loop? What is your shader program doing? We need more information.
Thanks for your reply sir, as I mentioned in my question, no, i am NOT allocating buffers each frame, I only sent the data to OpenGL once, in my loop I am ONLY rendering the trianges and using matrices to transform my geometery. And yes, my FPS is 1600+ if I render nothing, but if I render more, let’s say for example, 100 x 100 rectangles, it drops my FPS to around 10 or 20.
in my loop I am ONLY rendering the trianges and using matrices to transform my geometery.
You mean, to make one frame you essentially do:
LOOP k = 1..n
APPLY transform k
DRAW one triangle
Do all these n transforms change between each frame?
Even if yes, you can't precompute n triangles on CPU?
If you could, then drawing of one frame would simplify to:
void Renderer::drawRectangles(){
for(auto& rect : rectangles) {
//load uniforms, apply colors, transformations through shaders, etc.
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
}
}
Could you have:
1 2 3 4 5
void Renderer::drawRectangles(){
//load uniforms, apply colors, transformations through shaders, etc.
glDrawElements(GL_TRIANGLES, 6 * rectangles.size(), GL_UNSIGNED_SHORT, nullptr);
}
You say that drawRectangles() is called 10'000 times. Does that mean that in your version the //load uniforms, apply colors, transformations through shaders, etc.
is called rectangles.size()*10'000 times?