2022-03-02 13:02:38 +08:00
|
|
|
#include <SFML/Graphics/VertexArray.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2022-03-02 13:02:38 +08:00
|
|
|
|
2022-07-05 00:20:58 +08:00
|
|
|
#include <GraphicsUtil.hpp>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2022-07-05 13:51:18 +08:00
|
|
|
TEST_CASE("[Graphics] sf::VertexArray")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::VertexArray>);
|
|
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::VertexArray>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::VertexArray>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::VertexArray>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Default constructor")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
const sf::VertexArray vertexArray;
|
|
|
|
CHECK(vertexArray.getVertexCount() == 0);
|
|
|
|
CHECK(vertexArray.getPrimitiveType() == sf::PrimitiveType::Points);
|
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {0, 0}));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Explicit constructor with default argument")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
const sf::VertexArray vertexArray(sf::PrimitiveType::Lines);
|
|
|
|
CHECK(vertexArray.getVertexCount() == 0);
|
|
|
|
CHECK(vertexArray.getPrimitiveType() == sf::PrimitiveType::Lines);
|
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {0, 0}));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Explicit constructor")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
const sf::VertexArray vertexArray(sf::PrimitiveType::Lines, 10);
|
|
|
|
CHECK(vertexArray.getVertexCount() == 10);
|
|
|
|
CHECK(vertexArray.getPrimitiveType() == sf::PrimitiveType::Lines);
|
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {0, 0}));
|
|
|
|
for (std::size_t i = 0; i < vertexArray.getVertexCount(); ++i)
|
|
|
|
{
|
2024-02-09 20:21:44 +08:00
|
|
|
CHECK(vertexArray[i].position == sf::Vertex{}.position);
|
|
|
|
CHECK(vertexArray[i].color == sf::Vertex{}.color);
|
|
|
|
CHECK(vertexArray[i].texCoords == sf::Vertex{}.texCoords);
|
2022-03-02 13:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Resize array")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
|
|
|
vertexArray.resize(42);
|
|
|
|
CHECK(vertexArray.getVertexCount() == 42);
|
|
|
|
for (std::size_t i = 0; i < vertexArray.getVertexCount(); ++i)
|
|
|
|
{
|
2024-02-09 20:21:44 +08:00
|
|
|
CHECK(vertexArray[i].position == sf::Vertex{}.position);
|
|
|
|
CHECK(vertexArray[i].color == sf::Vertex{}.color);
|
|
|
|
CHECK(vertexArray[i].texCoords == sf::Vertex{}.texCoords);
|
2022-03-02 13:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Clear array")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
|
|
|
vertexArray.append({});
|
|
|
|
vertexArray.clear();
|
|
|
|
CHECK(vertexArray.getVertexCount() == 0);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Append to array")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
sf::VertexArray vertexArray;
|
2024-02-09 20:21:44 +08:00
|
|
|
const sf::Vertex vertex{{1.0f, 2.0f}, {3, 4, 5, 6}, {7.0f, 8.0f}};
|
2022-03-02 13:02:38 +08:00
|
|
|
vertexArray.append(vertex);
|
|
|
|
CHECK(vertexArray.getVertexCount() == 1);
|
|
|
|
CHECK(vertexArray[0].position == vertex.position);
|
|
|
|
CHECK(vertexArray[0].color == vertex.color);
|
|
|
|
CHECK(vertexArray[0].texCoords == vertex.texCoords);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Write to array")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
|
|
|
vertexArray.resize(10);
|
2024-02-09 20:21:44 +08:00
|
|
|
const sf::Vertex otherVertex{{2.0f, 3.0f}, {4, 5, 6, 7}, {8.0f, 9.0f}};
|
2022-03-02 13:02:38 +08:00
|
|
|
vertexArray[9] = otherVertex;
|
|
|
|
CHECK(vertexArray[9].position == otherVertex.position);
|
|
|
|
CHECK(vertexArray[9].color == otherVertex.color);
|
|
|
|
CHECK(vertexArray[9].texCoords == otherVertex.texCoords);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Set primitive type")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
|
|
|
vertexArray.setPrimitiveType(sf::PrimitiveType::TriangleStrip);
|
|
|
|
CHECK(vertexArray.getPrimitiveType() == sf::PrimitiveType::TriangleStrip);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Get bounds")
|
2022-03-02 13:02:38 +08:00
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
2024-02-09 20:21:44 +08:00
|
|
|
vertexArray.append({{1, 1}});
|
|
|
|
vertexArray.append({{2, 2}});
|
2022-03-02 13:02:38 +08:00
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({1, 1}, {1, 1}));
|
2024-02-09 20:21:44 +08:00
|
|
|
vertexArray[0] = {{0, 0}};
|
2022-03-02 13:02:38 +08:00
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {2, 2}));
|
2024-02-09 20:21:44 +08:00
|
|
|
vertexArray[0] = {{5, 5}};
|
2022-03-02 13:02:38 +08:00
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({2, 2}, {3, 3}));
|
2024-02-09 20:21:44 +08:00
|
|
|
vertexArray.append({{10, 10}});
|
2022-03-02 13:02:38 +08:00
|
|
|
CHECK(vertexArray.getBounds() == sf::FloatRect({2, 2}, {8, 8}));
|
|
|
|
}
|
2024-10-01 23:38:40 +08:00
|
|
|
|
|
|
|
SECTION("Ranged loop")
|
|
|
|
{
|
|
|
|
sf::VertexArray vertexArray;
|
|
|
|
vertexArray.append({{1, 1}});
|
|
|
|
vertexArray.append({{1, 1}});
|
|
|
|
vertexArray.append({{1, 1}});
|
|
|
|
|
|
|
|
std::size_t count = 0;
|
|
|
|
|
|
|
|
SECTION("Const")
|
|
|
|
{
|
|
|
|
for (const auto& vertex : std::as_const(vertexArray))
|
|
|
|
{
|
|
|
|
CHECK(vertex.position == sf::Vector2f(1, 1));
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Non const")
|
|
|
|
{
|
|
|
|
for (const auto& vertex : vertexArray)
|
|
|
|
{
|
|
|
|
CHECK(vertex.position == sf::Vector2f(1, 1));
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(count == vertexArray.getVertexCount());
|
|
|
|
}
|
2022-03-02 13:02:38 +08:00
|
|
|
}
|