1
Graphics / Re: sprite scaling: local-space vs. world-space
« on: April 04, 2017, 01:12:52 pm »
Ok, I'll give that a shot. Thanks for the quick reply!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Reading out of states.shader to set the current program costs a relatively high amount of CPU cycles because of the incurred cache miss. Cache misses ironically also count towards CPU load even though the CPU doesn't actually do anything while it stalls waiting for new data.
I think you forgot that the current program state is specific to each context... Your code would break if you rendered to 2 different sf::RenderTargets with the same shader
(not to mention your static variable would have to be protected by a mutex as well in order to support multi-threaded use).
This is the reason why the state cache is in the sf::RenderTarget itself. Following on from that, accessing the state cache anywhere outside of sf::RenderTarget would make little to no sense, meaning that this is an optimization that applies solely to applyShader. The uniform binding and everything else inside sf::Shader would be unaffected by this and you would still end up with loads of program changing per frame.
I'm not against these kinds of optimizations per se, but I still think that the best batching/caching strategy can only be conceived by the user. It is not the point of SFML to take bad code and make good performance out of it. Taking care of application specific optimizations should be left fully to the user. Building in more and more complex caching just so that the user doesn't have to give any thought to what they are doing isn't going to make the situation better.
This is one of the reasons SFML is not and will never be a complete game engine. It provides just enough to get people started, but the real meat should still be within their own code. Things like this are so application specific and even dependant on specific circumstances in the application that building them into places as general as sf::RenderTarget just makes something that should have been simple to start with overly complicated. These optimizations always come at a cost, and that cost will always be higher than the gains for the people who actually do optimize in their own code, and the last thing we want to do is punish them for giving more effort than others at making their application run faster.
The actual reading out of the OpenGL extension variable only happens once...
If you loaded up the CPU side of the driver with commands, switching away from a "full" context will always cause a flush to the GPU, meaning that you are forcing the driver to finally do some of the work it had been piling up for a while.
These lines take up over 20% of the CPU work done by RenderTarget::Draw:This is mostly due to really horrible CPU cache usage when trying to be smart about caching GL states. Having to hop around memory a lot isn't a fun thing to do.applyShader(states.shader)applyShader(NULL);
The expensive aspects of these applyShader calls are because of:Trust me... if you think this is bad, you don't want to know what it looks like inside the driver itself.
1. Shader::isAvailable is called every time, which takes a mutex lock. This seems very wasteful for each draw call.
I fact, i'm currently using an altered version of Let There Be Light 2 to have dynamic shadows during nighttime. My plan is to disable this lightning during daytime and draw dropshadows according to the above approach. Those dropshadows may move from left to right, that shouldnt be the problem at all. Dropshadows are not drawn during nighttime.
It would be better if the shadow would affect the dude walking on it somehow, but not as awkward as in the second pic.
This works well until a shadow hits another object, then things will "visually" break.
Did anyone implement a shadow system like this in the past and can share some experiences? How did it work? Color the sprite down to black, make it transparent, rotate it a bit and draw it behind its object? Or would you actually handpaint the shadows a load them in as a predefined resource? I would really like to hear some ideas. (Nice visuals > efficiency at the moment)
Steam also has games save into their own directory somewhere in SteamLibrary/steamapps/common or so. Many installed games do it too.
I'd say that a normal filesystem API is not a good fit for a game since in vast majority of games you don't go beyond own folders, care about rest of the OS, etc.