-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise OpenGL renderer by utilizing OpenGL's state machine #8166
Comments
Later I will make a PR where the constants will be cached. To discuss it and to see: this optimization makes sense or it's an overcomplication 🙌🏻 |
I found the Emscripten Optimizing WebGL article that describes a similar idea. The sum up: there is an overhead for any OpenGL function call and you need to reuse OpenGL state as much as possible. That is, don't reset buffers and textures after each draw if the same buffers and textures are used in the next draw call. And so on. https://emscripten.org/docs/optimizing/Optimizing-WebGL.html#avoid-redundant-calls |
By the way, I have already done some tests with 200 draw calls of 3d models (models are behind the screen, not cut off by frustum culling so as not to overload GPU). On a Chromebook ARM, rendering these actually empty 200 draw calls takes 40% of the total frame time. 🤯 |
Is your feature request related to a problem? Please describe (REQUIRED):
By learning the OpenGL renderer of the Defold engine, I came to the conclusion that it is designed as if it was created according to the OpenGL handbook (I hope that didn't sound rude!). I mean that any draw call starts with activation (or bind) of an object/texture/program and ends with deactivation (or unbind). Even if the next draw call uses the same texture, the same program, the same matrices, etc.
As we know, OpenGL is stateful. Therefore, you can specify texture parameters once, set constants to the program once, and so on.
How to use this fact? In modern games 50-100 draw calls per frame is becoming normal, because it is impossible to draw shadows, outlines, other effects and objects themselves in 1-3 draw calls. And I have found that in my game for about 100 draw calls the Defold engine makes about 5000 API calls. In a single frame! That may not be so much, but modern OpenGL is:
And I came to the point that we can reduce the number of OpenGL API calls if we:
Describe the solution you'd like (REQUIRED):
Reduce the number of OpenGL API calls by setting texture parameters and constants once, and so on.
The text was updated successfully, but these errors were encountered: