2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Graphics/RenderTexture.hpp>
|
|
|
|
|
2024-08-21 05:30:38 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/System/Exception.hpp>
|
|
|
|
|
2023-09-02 06:42:47 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include <WindowUtil.hpp>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-09-02 06:42:47 +08:00
|
|
|
TEST_CASE("[Graphics] sf::RenderTexture", runDisplayTests())
|
|
|
|
{
|
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(!std::is_copy_constructible_v<sf::RenderTexture>);
|
|
|
|
STATIC_CHECK(!std::is_copy_assignable_v<sf::RenderTexture>);
|
2023-06-07 06:12:44 +08:00
|
|
|
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RenderTexture>);
|
|
|
|
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderTexture>);
|
2023-09-02 06:42:47 +08:00
|
|
|
}
|
|
|
|
|
2024-07-06 09:38:32 +08:00
|
|
|
SECTION("Construction")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
SECTION("Default constructor")
|
|
|
|
{
|
|
|
|
const sf::RenderTexture renderTexture;
|
|
|
|
CHECK(!renderTexture.isSmooth());
|
|
|
|
CHECK(!renderTexture.isRepeated());
|
|
|
|
CHECK(renderTexture.getSize() == sf::Vector2u(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("2 parameter constructor")
|
|
|
|
{
|
2024-08-21 05:30:38 +08:00
|
|
|
CHECK_THROWS_AS(sf::RenderTexture({1'000'000, 1'000'000}), sf::Exception);
|
2024-07-06 10:24:00 +08:00
|
|
|
|
|
|
|
CHECK_NOTHROW(sf::RenderTexture({100, 100}, sf::ContextSettings{8 /* depthBits */, 0 /* stencilBits */}));
|
|
|
|
CHECK_NOTHROW(sf::RenderTexture({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}));
|
|
|
|
|
|
|
|
const sf::RenderTexture renderTexture({360, 480});
|
|
|
|
CHECK(renderTexture.getSize() == sf::Vector2u(360, 480));
|
|
|
|
CHECK(!renderTexture.isSmooth());
|
|
|
|
CHECK(!renderTexture.isRepeated());
|
|
|
|
CHECK(!renderTexture.isSrgb());
|
|
|
|
|
|
|
|
const auto& texture = renderTexture.getTexture();
|
|
|
|
CHECK(texture.getSize() == sf::Vector2u(360, 480));
|
|
|
|
CHECK(!texture.isSmooth());
|
|
|
|
CHECK(!texture.isSrgb());
|
|
|
|
CHECK(!texture.isRepeated());
|
|
|
|
CHECK(texture.getNativeHandle() != 0);
|
|
|
|
}
|
2024-07-06 09:38:32 +08:00
|
|
|
}
|
|
|
|
|
2024-07-06 10:24:00 +08:00
|
|
|
SECTION("resize()")
|
2023-09-02 06:42:47 +08:00
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::RenderTexture renderTexture;
|
|
|
|
CHECK(!renderTexture.resize({1'000'000, 1'000'000}));
|
2024-05-22 05:12:13 +08:00
|
|
|
|
2024-07-06 10:24:00 +08:00
|
|
|
CHECK(renderTexture.resize({100, 100}, sf::ContextSettings{8 /* depthBits */, 0 /* stencilBits */}));
|
|
|
|
CHECK(renderTexture.resize({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}));
|
2024-05-22 05:12:13 +08:00
|
|
|
|
2024-07-06 10:24:00 +08:00
|
|
|
REQUIRE(renderTexture.resize({360, 480}));
|
2024-05-22 05:12:13 +08:00
|
|
|
CHECK(renderTexture.getSize() == sf::Vector2u(360, 480));
|
2023-09-02 06:42:47 +08:00
|
|
|
CHECK(!renderTexture.isSmooth());
|
|
|
|
CHECK(!renderTexture.isRepeated());
|
|
|
|
CHECK(!renderTexture.isSrgb());
|
2024-05-25 02:36:42 +08:00
|
|
|
|
2024-05-22 05:12:13 +08:00
|
|
|
const auto& texture = renderTexture.getTexture();
|
|
|
|
CHECK(texture.getSize() == sf::Vector2u(360, 480));
|
|
|
|
CHECK(!texture.isSmooth());
|
|
|
|
CHECK(!texture.isSrgb());
|
|
|
|
CHECK(!texture.isRepeated());
|
|
|
|
CHECK(texture.getNativeHandle() != 0);
|
2023-09-02 06:42:47 +08:00
|
|
|
}
|
|
|
|
|
2024-07-06 09:38:32 +08:00
|
|
|
SECTION("resize()")
|
|
|
|
{
|
|
|
|
sf::RenderTexture renderTexture;
|
|
|
|
CHECK(!renderTexture.resize({1'000'000, 1'000'000}));
|
|
|
|
CHECK(renderTexture.resize({480, 360}));
|
|
|
|
CHECK(!renderTexture.isSmooth());
|
|
|
|
CHECK(!renderTexture.isRepeated());
|
|
|
|
CHECK(renderTexture.getSize() == sf::Vector2u(480, 360));
|
|
|
|
CHECK(!renderTexture.isSrgb());
|
|
|
|
CHECK(renderTexture.resize({360, 480}));
|
|
|
|
CHECK(renderTexture.getSize() == sf::Vector2u(360, 480));
|
|
|
|
CHECK(renderTexture.resize({100, 100}, sf::ContextSettings{8 /* depthBits */, 0 /* stencilBits */}));
|
|
|
|
CHECK(renderTexture.resize({100, 100}, sf::ContextSettings{0 /* depthBits */, 8 /* stencilBits */}));
|
|
|
|
}
|
|
|
|
|
2024-09-09 06:21:18 +08:00
|
|
|
SECTION("getMaximumAntiAliasingLevel()")
|
2023-09-02 06:42:47 +08:00
|
|
|
{
|
2024-09-09 06:21:18 +08:00
|
|
|
CHECK(sf::RenderTexture::getMaximumAntiAliasingLevel() <= 64);
|
2023-09-02 06:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set/get smooth")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::RenderTexture renderTexture({64, 64});
|
2023-09-02 06:42:47 +08:00
|
|
|
renderTexture.setSmooth(true);
|
|
|
|
CHECK(renderTexture.isSmooth());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set/get repeated")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::RenderTexture renderTexture({64, 64});
|
2023-09-02 06:42:47 +08:00
|
|
|
renderTexture.setRepeated(true);
|
|
|
|
CHECK(renderTexture.isRepeated());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("generateMipmap()")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::RenderTexture renderTexture({64, 64});
|
2023-09-02 06:42:47 +08:00
|
|
|
CHECK(renderTexture.generateMipmap());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("setActive()")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
sf::RenderTexture renderTexture({64, 64});
|
2023-09-02 06:42:47 +08:00
|
|
|
CHECK(renderTexture.setActive());
|
2024-05-22 05:12:13 +08:00
|
|
|
CHECK(renderTexture.setActive(false));
|
|
|
|
CHECK(renderTexture.setActive(true));
|
2023-09-02 06:42:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("getTexture()")
|
|
|
|
{
|
2024-07-06 10:24:00 +08:00
|
|
|
const sf::RenderTexture renderTexture({64, 64});
|
2024-05-22 05:12:13 +08:00
|
|
|
CHECK(renderTexture.getTexture().getSize() == sf::Vector2u(64, 64));
|
2023-09-02 06:42:47 +08:00
|
|
|
}
|
|
|
|
}
|