From 0d3c7f1c324b5b1feedb103a8b7d599186b9ef3b Mon Sep 17 00:00:00 2001 From: kimci86 Date: Sat, 27 Jan 2024 15:36:55 +0100 Subject: [PATCH] Make VertexBuffer::Usage a scoped enumeration --- examples/island/Island.cpp | 2 +- include/SFML/Graphics/VertexBuffer.hpp | 6 +++--- src/SFML/Graphics/VertexBuffer.cpp | 4 ++-- test/Graphics/VertexBuffer.test.cpp | 30 +++++++++++++------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 3bcb40054..e88dcdb61 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -99,7 +99,7 @@ int main() sf::Text statusText(font); sf::Shader terrainShader; const sf::RenderStates terrainStates(&terrainShader); - sf::VertexBuffer terrain(sf::PrimitiveType::Triangles, sf::VertexBuffer::Static); + sf::VertexBuffer terrain(sf::PrimitiveType::Triangles, sf::VertexBuffer::Usage::Static); // Set up our text drawables statusText.setCharacterSize(28); diff --git a/include/SFML/Graphics/VertexBuffer.hpp b/include/SFML/Graphics/VertexBuffer.hpp index 542bd9c7c..318889b51 100644 --- a/include/SFML/Graphics/VertexBuffer.hpp +++ b/include/SFML/Graphics/VertexBuffer.hpp @@ -59,7 +59,7 @@ public: /// good compromise. /// //////////////////////////////////////////////////////////// - enum Usage + enum class Usage { Stream, //!< Constantly changing data Dynamic, //!< Occasionally changing data @@ -270,7 +270,7 @@ public: /// to be updated with new data for the usage specifier to /// take effect. /// - /// The default primitive type is sf::VertexBuffer::Stream. + /// The default usage type is sf::VertexBuffer::Usage::Stream. /// /// \param usage Usage specifier /// @@ -336,7 +336,7 @@ private: unsigned int m_buffer{}; //!< Internal buffer identifier std::size_t m_size{}; //!< Size in Vertices of the currently allocated buffer PrimitiveType m_primitiveType{PrimitiveType::Points}; //!< Type of primitives to draw - Usage m_usage{Stream}; //!< How this vertex buffer is to be used + Usage m_usage{Usage::Stream}; //!< How this vertex buffer is to be used }; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/VertexBuffer.cpp b/src/SFML/Graphics/VertexBuffer.cpp index 80d786519..81f0ed168 100644 --- a/src/SFML/Graphics/VertexBuffer.cpp +++ b/src/SFML/Graphics/VertexBuffer.cpp @@ -47,9 +47,9 @@ GLenum usageToGlEnum(sf::VertexBuffer::Usage usage) { switch (usage) { - case sf::VertexBuffer::Static: + case sf::VertexBuffer::Usage::Static: return GLEXT_GL_STATIC_DRAW; - case sf::VertexBuffer::Dynamic: + case sf::VertexBuffer::Usage::Dynamic: return GLEXT_GL_DYNAMIC_DRAW; default: return GLEXT_GL_STREAM_DRAW; diff --git a/test/Graphics/VertexBuffer.test.cpp b/test/Graphics/VertexBuffer.test.cpp index a35ee581d..40af922e1 100644 --- a/test/Graphics/VertexBuffer.test.cpp +++ b/test/Graphics/VertexBuffer.test.cpp @@ -35,7 +35,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") CHECK(vertexBuffer.getVertexCount() == 0); CHECK(vertexBuffer.getNativeHandle() == 0); CHECK(vertexBuffer.getPrimitiveType() == sf::PrimitiveType::Points); - CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Stream); + CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Usage::Stream); } SECTION("Primitive type constructor") @@ -44,31 +44,31 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") CHECK(vertexBuffer.getVertexCount() == 0); CHECK(vertexBuffer.getNativeHandle() == 0); CHECK(vertexBuffer.getPrimitiveType() == sf::PrimitiveType::Triangles); - CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Stream); + CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Usage::Stream); } SECTION("Usage constructor") { - const sf::VertexBuffer vertexBuffer(sf::VertexBuffer::Static); + const sf::VertexBuffer vertexBuffer(sf::VertexBuffer::Usage::Static); CHECK(vertexBuffer.getVertexCount() == 0); CHECK(vertexBuffer.getNativeHandle() == 0); CHECK(vertexBuffer.getPrimitiveType() == sf::PrimitiveType::Points); - CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Static); + CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Usage::Static); } SECTION("Primitive type and usage constructor") { - const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic); + const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Usage::Dynamic); CHECK(vertexBuffer.getVertexCount() == 0); CHECK(vertexBuffer.getNativeHandle() == 0); CHECK(vertexBuffer.getPrimitiveType() == sf::PrimitiveType::LineStrip); - CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Dynamic); + CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Usage::Dynamic); } } SECTION("Copy semantics") { - const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic); + const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Usage::Dynamic); SECTION("Construction") { @@ -76,7 +76,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") CHECK(vertexBufferCopy.getVertexCount() == 0); CHECK(vertexBufferCopy.getNativeHandle() == 0); CHECK(vertexBufferCopy.getPrimitiveType() == sf::PrimitiveType::LineStrip); - CHECK(vertexBufferCopy.getUsage() == sf::VertexBuffer::Dynamic); + CHECK(vertexBufferCopy.getUsage() == sf::VertexBuffer::Usage::Dynamic); } SECTION("Assignment") @@ -86,7 +86,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") CHECK(vertexBufferCopy.getVertexCount() == 0); CHECK(vertexBufferCopy.getNativeHandle() == 0); CHECK(vertexBufferCopy.getPrimitiveType() == sf::PrimitiveType::LineStrip); - CHECK(vertexBufferCopy.getUsage() == sf::VertexBuffer::Dynamic); + CHECK(vertexBufferCopy.getUsage() == sf::VertexBuffer::Usage::Dynamic); } } @@ -146,10 +146,10 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") SECTION("swap()") { - sf::VertexBuffer vertexBuffer1(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic); + sf::VertexBuffer vertexBuffer1(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Usage::Dynamic); CHECK(vertexBuffer1.create(50)); - sf::VertexBuffer vertexBuffer2(sf::PrimitiveType::TriangleStrip, sf::VertexBuffer::Stream); + sf::VertexBuffer vertexBuffer2(sf::PrimitiveType::TriangleStrip, sf::VertexBuffer::Usage::Stream); CHECK(vertexBuffer2.create(60)); sf::swap(vertexBuffer1, vertexBuffer2); @@ -157,12 +157,12 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") CHECK(vertexBuffer1.getVertexCount() == 60); CHECK(vertexBuffer1.getNativeHandle() != 0); CHECK(vertexBuffer1.getPrimitiveType() == sf::PrimitiveType::TriangleStrip); - CHECK(vertexBuffer1.getUsage() == sf::VertexBuffer::Stream); + CHECK(vertexBuffer1.getUsage() == sf::VertexBuffer::Usage::Stream); CHECK(vertexBuffer2.getVertexCount() == 50); CHECK(vertexBuffer2.getNativeHandle() != 0); CHECK(vertexBuffer2.getPrimitiveType() == sf::PrimitiveType::LineStrip); - CHECK(vertexBuffer2.getUsage() == sf::VertexBuffer::Dynamic); + CHECK(vertexBuffer2.getUsage() == sf::VertexBuffer::Usage::Dynamic); } SECTION("Set/get primitive type") @@ -175,7 +175,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]") SECTION("Set/get usage") { sf::VertexBuffer vertexBuffer; - vertexBuffer.setUsage(sf::VertexBuffer::Dynamic); - CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Dynamic); + vertexBuffer.setUsage(sf::VertexBuffer::Usage::Dynamic); + CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Usage::Dynamic); } }