2022-05-26 02:36:06 +08:00
|
|
|
#include <SFML/Graphics/RenderStates.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2022-05-26 02:36:06 +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::RenderStates")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(std::is_copy_constructible_v<sf::RenderStates>);
|
|
|
|
STATIC_CHECK(std::is_copy_assignable_v<sf::RenderStates>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RenderStates>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderStates>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Default constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
|
|
|
const sf::RenderStates renderStates;
|
|
|
|
CHECK(renderStates.blendMode == sf::BlendMode());
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == sf::Transform());
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("BlendMode constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2024-01-27 22:36:29 +08:00
|
|
|
const sf::BlendMode blendMode(sf::BlendMode::Factor::Zero,
|
|
|
|
sf::BlendMode::Factor::SrcColor,
|
|
|
|
sf::BlendMode::Equation::ReverseSubtract,
|
|
|
|
sf::BlendMode::Factor::OneMinusDstAlpha,
|
|
|
|
sf::BlendMode::Factor::DstAlpha,
|
|
|
|
sf::BlendMode::Equation::Max);
|
2022-05-26 02:36:06 +08:00
|
|
|
const sf::RenderStates renderStates(blendMode);
|
|
|
|
CHECK(renderStates.blendMode == blendMode);
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == sf::Transform());
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
|
2015-04-29 11:28:02 +08:00
|
|
|
SECTION("StencilMode constructor")
|
|
|
|
{
|
|
|
|
const sf::StencilMode stencilMode{sf::StencilComparison::Equal, sf::StencilUpdateOperation::Replace, 1, 0u, true};
|
|
|
|
const sf::RenderStates renderStates(stencilMode);
|
|
|
|
CHECK(renderStates.blendMode == sf::BlendMode());
|
|
|
|
CHECK(renderStates.stencilMode == stencilMode);
|
|
|
|
CHECK(renderStates.transform == sf::Transform());
|
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Transform constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
const sf::Transform transform(10, 9, 8, 7, 6, 5, 4, 3, 2);
|
2022-05-26 02:36:06 +08:00
|
|
|
const sf::RenderStates renderStates(transform);
|
|
|
|
CHECK(renderStates.blendMode == sf::BlendMode());
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == transform);
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Texture constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
const sf::Texture* texture = nullptr;
|
2022-05-26 02:36:06 +08:00
|
|
|
const sf::RenderStates renderStates(texture);
|
|
|
|
CHECK(renderStates.blendMode == sf::BlendMode());
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == sf::Transform());
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == texture);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Shader constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2022-07-05 00:20:58 +08:00
|
|
|
const sf::Shader* shader = nullptr;
|
2022-05-26 02:36:06 +08:00
|
|
|
const sf::RenderStates renderStates(shader);
|
|
|
|
CHECK(renderStates.blendMode == sf::BlendMode());
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == sf::Transform());
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == shader);
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Verbose constructor")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
2015-04-29 11:28:02 +08:00
|
|
|
const sf::BlendMode blendMode(sf::BlendMode::Factor::One,
|
2024-01-27 22:36:29 +08:00
|
|
|
sf::BlendMode::Factor::SrcColor,
|
|
|
|
sf::BlendMode::Equation::ReverseSubtract,
|
|
|
|
sf::BlendMode::Factor::OneMinusDstAlpha,
|
|
|
|
sf::BlendMode::Factor::DstAlpha,
|
|
|
|
sf::BlendMode::Equation::Max);
|
2015-04-29 11:28:02 +08:00
|
|
|
const sf::StencilMode stencilMode{sf::StencilComparison::Equal, sf::StencilUpdateOperation::Replace, 1, 0u, true};
|
|
|
|
const sf::Transform transform(10, 2, 3, 4, 50, 40, 30, 20, 10);
|
|
|
|
const sf::RenderStates renderStates(blendMode, stencilMode, transform, sf::CoordinateType::Normalized, nullptr, nullptr);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.blendMode == blendMode);
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(renderStates.stencilMode == stencilMode);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.transform == transform);
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(renderStates.coordinateType == sf::CoordinateType::Normalized);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(renderStates.texture == nullptr);
|
|
|
|
CHECK(renderStates.shader == nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Default constant")
|
2022-05-26 02:36:06 +08:00
|
|
|
{
|
|
|
|
CHECK(sf::RenderStates::Default.blendMode == sf::BlendMode());
|
2015-04-29 11:28:02 +08:00
|
|
|
CHECK(sf::RenderStates::Default.stencilMode == sf::StencilMode{});
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(sf::RenderStates::Default.transform == sf::Transform());
|
2021-07-04 14:47:48 +08:00
|
|
|
CHECK(sf::RenderStates::Default.coordinateType == sf::CoordinateType::Pixels);
|
2022-05-26 02:36:06 +08:00
|
|
|
CHECK(sf::RenderStates::Default.texture == nullptr);
|
2022-06-24 07:09:22 +08:00
|
|
|
CHECK(sf::RenderStates::Default.shader == nullptr);
|
2022-05-26 02:36:06 +08:00
|
|
|
}
|
|
|
|
}
|