diff --git a/include/SFML/Graphics/Transform.hpp b/include/SFML/Graphics/Transform.hpp index ab0307cc44..63e48ec36d 100644 --- a/include/SFML/Graphics/Transform.hpp +++ b/include/SFML/Graphics/Transform.hpp @@ -348,6 +348,19 @@ class SFML_GRAPHICS_API Transform //////////////////////////////////////////////////////////// Transform& scale(const Vector2f& factors, const Vector2f& center); + //////////////////////////////////////////////////////////// + /// \brief Check if the current transform is equal to another one + /// + /// Performs an element-wise comparison of all elements of the + /// current transform with all elements of the other transform. + /// + /// \param transform Transform to compare with this transform + /// + /// \return true if the transforms are equal, false otherwise + /// + //////////////////////////////////////////////////////////// + bool equals(const Transform& transform) const; + //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// @@ -403,6 +416,20 @@ SFML_GRAPHICS_API Transform& operator *=(Transform& left, const Transform& right //////////////////////////////////////////////////////////// SFML_GRAPHICS_API Vector2f operator *(const Transform& left, const Vector2f& right); +//////////////////////////////////////////////////////////// +/// \relates sf::Transform +/// \brief Overload of binary operator == to compare two transforms +/// +/// This call is equivalent to calling left.equals(right). +/// +/// \param left Left operand (the first transform) +/// \param right Right operand (the second transform) +/// +/// \return true if the transforms are equal, false otherwise +/// +//////////////////////////////////////////////////////////// +SFML_GRAPHICS_API bool operator ==(const Transform& left, const Transform& right); + } // namespace sf diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 244ee3021c..84a9280155 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -235,7 +235,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, // Since vertices are transformed, we must use an identity transform to render them if (!m_cache.useVertexCache) - applyTransform(Transform::Identity); + glCheck(glLoadIdentity()); } else { @@ -390,6 +390,7 @@ void RenderTarget::resetGLStates() glCheck(glEnable(GL_TEXTURE_2D)); glCheck(glEnable(GL_BLEND)); glCheck(glMatrixMode(GL_MODELVIEW)); + glCheck(glLoadIdentity()); glCheck(glEnableClientState(GL_VERTEX_ARRAY)); glCheck(glEnableClientState(GL_COLOR_ARRAY)); glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); @@ -397,7 +398,6 @@ void RenderTarget::resetGLStates() // Apply the default SFML states applyBlendMode(BlendAlpha); - applyTransform(Transform::Identity); applyTexture(NULL); if (shaderAvailable) applyShader(NULL); @@ -496,7 +496,10 @@ void RenderTarget::applyTransform(const Transform& transform) { // No need to call glMatrixMode(GL_MODELVIEW), it is always the // current mode (for optimization purpose, since it's the most used) - glCheck(glLoadMatrixf(transform.getMatrix())); + if (transform == Transform::Identity) + glCheck(glLoadIdentity()); + else + glCheck(glLoadMatrixf(transform.getMatrix())); } diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp index 3b831ba510..328c821ab5 100644 --- a/src/SFML/Graphics/Transform.cpp +++ b/src/SFML/Graphics/Transform.cpp @@ -26,6 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include @@ -249,6 +250,13 @@ Transform& Transform::scale(const Vector2f& factors, const Vector2f& center) } +//////////////////////////////////////////////////////////// +bool Transform::equals(const Transform& transform) const +{ + return std::equal(m_matrix, m_matrix + 16, transform.m_matrix); +} + + //////////////////////////////////////////////////////////// Transform operator *(const Transform& left, const Transform& right) { @@ -269,4 +277,11 @@ Vector2f operator *(const Transform& left, const Vector2f& right) return left.transformPoint(right); } + +//////////////////////////////////////////////////////////// +bool operator ==(const Transform& left, const Transform& right) +{ + return left.equals(right); +} + } // namespace sf