Make 'Vertex' a 'constexpr' class

This commit is contained in:
Vittorio Romeo 2021-12-19 14:00:20 +01:00
parent ed201ce87a
commit a20d73aafa
3 changed files with 14 additions and 22 deletions

View File

@ -28,7 +28,6 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
@ -39,7 +38,7 @@ namespace sf
/// \brief Define a point with color and texture coordinates /// \brief Define a point with color and texture coordinates
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_GRAPHICS_API Vertex class Vertex
{ {
public: public:
@ -47,7 +46,7 @@ public:
/// \brief Default constructor /// \brief Default constructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex(); constexpr Vertex();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the vertex from its position /// \brief Construct the vertex from its position
@ -57,7 +56,7 @@ public:
/// \param thePosition Vertex position /// \param thePosition Vertex position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex(const Vector2f& thePosition); constexpr Vertex(const Vector2f& thePosition);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the vertex from its position and color /// \brief Construct the vertex from its position and color
@ -68,7 +67,7 @@ public:
/// \param theColor Vertex color /// \param theColor Vertex color
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex(const Vector2f& thePosition, const Color& theColor); constexpr Vertex(const Vector2f& thePosition, const Color& theColor);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the vertex from its position and texture coordinates /// \brief Construct the vertex from its position and texture coordinates
@ -79,7 +78,7 @@ public:
/// \param theTexCoords Vertex texture coordinates /// \param theTexCoords Vertex texture coordinates
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords); constexpr Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Construct the vertex from its position, color and texture coordinates /// \brief Construct the vertex from its position, color and texture coordinates
@ -89,7 +88,7 @@ public:
/// \param theTexCoords Vertex texture coordinates /// \param theTexCoords Vertex texture coordinates
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords); constexpr Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
@ -99,6 +98,8 @@ public:
Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex
}; };
#include <SFML/Graphics/Vertex.inl>
} // namespace sf } // namespace sf

View File

@ -22,16 +22,9 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Vertex.hpp>
namespace sf
{
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex::Vertex() : constexpr Vertex::Vertex() :
position (0, 0), position (0, 0),
color (255, 255, 255), color (255, 255, 255),
texCoords(0, 0) texCoords(0, 0)
@ -40,7 +33,7 @@ texCoords(0, 0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex::Vertex(const Vector2f& thePosition) : constexpr Vertex::Vertex(const Vector2f& thePosition) :
position (thePosition), position (thePosition),
color (255, 255, 255), color (255, 255, 255),
texCoords(0, 0) texCoords(0, 0)
@ -49,7 +42,7 @@ texCoords(0, 0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) :
position (thePosition), position (thePosition),
color (theColor), color (theColor),
texCoords(0, 0) texCoords(0, 0)
@ -58,7 +51,7 @@ texCoords(0, 0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) :
position (thePosition), position (thePosition),
color (255, 255, 255), color (255, 255, 255),
texCoords(theTexCoords) texCoords(theTexCoords)
@ -67,11 +60,9 @@ texCoords(theTexCoords)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) : constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) :
position (thePosition), position (thePosition),
color (theColor), color (theColor),
texCoords(theTexCoords) texCoords(theTexCoords)
{ {
} }
} // namespace sf

View File

@ -47,8 +47,8 @@ set(SRC
${INCROOT}/Transformable.hpp ${INCROOT}/Transformable.hpp
${SRCROOT}/View.cpp ${SRCROOT}/View.cpp
${INCROOT}/View.hpp ${INCROOT}/View.hpp
${SRCROOT}/Vertex.cpp
${INCROOT}/Vertex.hpp ${INCROOT}/Vertex.hpp
${INCROOT}/Vertex.inl
) )
source_group("" FILES ${SRC}) source_group("" FILES ${SRC})