Skip to content
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

Enable comparing sf::Transform and optimize resetting OpenGL back to the identity matrix #1298

Merged
merged 1 commit into from Oct 12, 2017

Conversation

binary1248
Copy link
Member

@binary1248 binary1248 commented Oct 1, 2017

In cases where the RenderTarget is forced to go in and out of "cache mode", it will end up constantly uploading the matrix of Transform::Identity to OpenGL even though this is most likely a built in constant (and probably highly optimized). This patch makes use of the built-in and reduces CPU/RAM load in cases where the copying is happening excessively.

Copy link
Member

@LaurentGomila LaurentGomila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my comments:

  • Why both equals and operator==?
  • If operator== is defined, I like to have operator!= as well
  • You compare 16 floats while only 9 are used

And is it so obvious that using glLoadIdentity + the added float comparisons is more optimized than glLoadMatrix? (just wondering)

@binary1248
Copy link
Member Author

Fixed in new version.

And is it so obvious that using glLoadIdentity + the added float comparisons is more optimized than glLoadMatrix? (just wondering)

The values of the matrix will very likely be in the L1 cache since they were passed into draw() and applyTransform() by reference. Float comparisons are super fast, much faster than copying memory from one address space into another and then over the PCIe interface. Who knows, maybe the driver compares our data with the identity matrix and optimizes this itself, but if we do it ourselves we are on the safer side.

@@ -26,6 +26,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Transform.hpp>
#include <algorithm>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can be removed now.

@binary1248
Copy link
Member Author

Fixed.

@eXpl0it3r eXpl0it3r added this to the 2.5 milestone Oct 11, 2017
@eXpl0it3r eXpl0it3r added this to Review & Testing in SFML 2.5.0 Oct 11, 2017
@eXpl0it3r eXpl0it3r moved this from Review & Testing to Ready in SFML 2.5.0 Oct 11, 2017
… of data every time we want to reset the OpenGL matrix back to identity.
@eXpl0it3r eXpl0it3r merged commit 898c235 into master Oct 12, 2017
@eXpl0it3r eXpl0it3r deleted the feature/identity_matrix branch October 12, 2017 20:31
@eXpl0it3r eXpl0it3r moved this from Ready to Merged / Superseded in SFML 2.5.0 Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

3 participants