I was writing a new code base in opengl and have encountered a weird bug very early on. It is a distinct fluctuation in framerate that is repetitive and predictable.
I know that it is definitely proportional to objects rendered. It is also proportional to screen size (not viewport size, not window size, just physical device size) It is roughly a ratio of 0.2:1 (low:high) frames
I got curious and graphed it, bear in mind that the window/context isn't vsynced or capped.
The view is completely stationary and all objects are stationary. Each frame is exactly the same. No input was given at any time. There is nothing time-based. No garbage collection happens.
I don't get it, if it is basically one frame being rendered over and over what could cause such a great change?
Here's the pseudo code of program flow
create window
load shaders
grab uniform locations
create camera
create 3 meshes // They just hold the buffers and data for a model
create x objects and pass a pointer to a random mesh // Objects hold position, rotation etc + link to mesh
while game is running
poll window for events
capture mouse and recalculate VP matrix if required
for each object
recalc MVP
bind mesh's buffers and draw elements
draw window //SFML handles this, just swaps front/back buffers and draws
clean up data
If this gives no insights then I uploaded the VS2012 project to github: https://github.com/Twistedsnail/Untitled_for_SO(it probably won't run locally because it requires SFML2 in a specified location and GLM in VS's files)
The most common reason for reduced FPS is graphics settings that create a larger workload than your hardware can handle. So how do you achieve better FPS? Getting a faster CPU, more RAM, or a newer graphics card is one solution.
Go into NVIDIA Control Panel, go to the Manage 3D Settings and click on Global, go down to Shader Cache Size or whatever it's called and make sure it's set to Disabled. Give your PC a quick and fresh reboot. Open up NVIDIA Experience and go to the Drivers tab and click on reinstall, then clean installation.
When we were building a game engine at my last job we also had curious problems like that from time to time.
Causes I remember:
Lua garbage collection. Where were using Lua as scripting language for the engine and the GC would make it appear as if there was problem with the rendering! Though it was not obviously. Check for any other threads or even processes that might become greedy in your application/machine.
OpenGL driver issues: disabling or enabling "Threaded Optimization" in the NVIDIA driver had funny effects on performance like this sometimes. ATI drivers more often simply had bugs which required an upgrade.
Problems with the Windows event loop. Like using GetMessage instead of PeekMessage.
Another thing: If you are really not rendering much and have several thousand FPS: even the slightest increase in rendering time will have "huge" effects on your FPS. So what you are seeing might be very normal operating system/driver tasks that are irrelevant when working with "normal" game FPS like 60 to 120 and not much noticeable later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With