Replace glm with vec.h
Vec2, IVec2, Vec3, Vec4, IVec4 and a column-major Mat4, with glm's formulas, in one header. Free functions are vec_ and mat4_ prefixed. The leaked using namespace glm is gone. Render goldens still match.
This commit is contained in:
1 parent
c38a3a9890
commit
03bbb93ba6
79 files changed
+1232
-810
No files matched your search
+6
-6
@@ -26,11 +26,11 @@ TEST_CASE("Image png round trip and uid tracking")
|
||||
CHECK(copy.uid == image.uid);
|
||||
copy.pixel_set({1, 1}, {1.0f, 1.0f, 1.0f, 1.0f});
|
||||
CHECK(copy.uid != image.uid);
|
||||
CHECK(copy.pixel_read({1, 1}) == glm::vec4(1.0f));
|
||||
CHECK(copy.pixel_read({1, 1}) == Vec4(1.0f));
|
||||
|
||||
auto merged = Image::compose({{&image, {}, image.size, {}}, {&loaded, {}, loaded.size, {image.size.x, 0}}},
|
||||
{image.size.x * 2, image.size.y}, false);
|
||||
CHECK(merged.size == glm::ivec2(4, 2));
|
||||
CHECK(merged.size == IVec2(4, 2));
|
||||
CHECK(merged.pixel_read({2, 0}) == image.pixel_read({0, 0}));
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ TEST_CASE("an SVG spritesheet loads in SVG units and draws again at any scale")
|
||||
Image image(TEST_DIR / "render" / "vector.svg");
|
||||
REQUIRE(image.is_valid());
|
||||
CHECK(image.is_vector());
|
||||
CHECK(image.size == glm::ivec2(32, 16));
|
||||
CHECK(image.size == IVec2(32, 16));
|
||||
auto red = image.pixel_read({8.0f, 8.0f});
|
||||
CHECK(red.r > 0.8f);
|
||||
CHECK(red.b < 0.2f);
|
||||
|
||||
auto large = image.vector_render(4.0f);
|
||||
CHECK(large.size == glm::ivec2(128, 64));
|
||||
CHECK(large.size == IVec2(128, 64));
|
||||
CHECK(large.unit_size_get() == image.unit_size_get());
|
||||
CHECK(large.uid != image.uid);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ TEST_CASE("SVG spritesheets compose into SVGs that draw the same")
|
||||
REQUIRE(swapped.is_vector());
|
||||
CHECK(swapped.size == vector.size);
|
||||
CHECK(swapped.pixel_read({24.0f, 8.0f}) == vector.pixel_read({8.0f, 8.0f}));
|
||||
CHECK(swapped.pixel_read({1.0f, 1.0f}) == glm::vec4());
|
||||
CHECK(swapped.pixel_read({1.0f, 1.0f}) == Vec4());
|
||||
|
||||
// A PNG part is embedded as an image, pixel for pixel. Composing the result again still works.
|
||||
const std::vector<uint8_t> pixels = {255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255};
|
||||
@@ -115,7 +115,7 @@ TEST_CASE("an SVG's shapes meet without a seam")
|
||||
REQUIRE(image.is_vector());
|
||||
auto seam = image.pixel_read({10.0f, 2.0f});
|
||||
CHECK(seam.a == 1.0f);
|
||||
CHECK(glm::distance(glm::vec3(seam), glm::vec3(image.pixel_read({5.0f, 2.0f}))) < 2.0f / 255.0f);
|
||||
CHECK(vec_distance(Vec3(seam), Vec3(image.pixel_read({5.0f, 2.0f}))) < 2.0f / 255.0f);
|
||||
CHECK(image.pixel_read({20.0f, 2.0f}).a < 1.0f);
|
||||
}
|
||||
|
||||
|
||||
+13
-14
@@ -19,7 +19,7 @@ TEST_CASE("draw lists put the root first and each item's onion samples before it
|
||||
auto layerDraws = std::ranges::count_if(
|
||||
draws, [](const Draw& draw) { return draw.type == DrawType::LAYER && draw.sample == -1; });
|
||||
CHECK(layerDraws > 0);
|
||||
CHECK(animation_rect(anm2, animation, true) != glm::vec4(-1.0f));
|
||||
CHECK(animation_rect(anm2, animation, true) != Vec4(-1.0f));
|
||||
}
|
||||
|
||||
TEST_CASE("root transforms fold into layer draws")
|
||||
@@ -82,27 +82,27 @@ TEST_CASE("an animation layer draws its child animation, from this file or a lib
|
||||
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
|
||||
DrawOptions options = {.library_get = [&](const Model&, int id) { return id == 0 ? &spin : nullptr; }};
|
||||
auto red_position_get = [&](int layerId) {
|
||||
std::optional<glm::vec2> position{};
|
||||
std::optional<Vec2> position{};
|
||||
for (auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), options))
|
||||
if (draw.type == DrawType::LAYER && draw.id == layerId && draw.frame.crop == glm::vec2())
|
||||
position = glm::vec2(draw.parent * glm::vec4(draw.frame.position, 0.0f, 1.0f));
|
||||
if (draw.type == DrawType::LAYER && draw.id == layerId && draw.frame.crop == Vec2())
|
||||
position = Vec2(draw.parent * Vec4(draw.frame.position, 0.0f, 1.0f));
|
||||
return position;
|
||||
};
|
||||
|
||||
// The library's red square, half size at (40, 0), starts on its fifth frame (at x 16).
|
||||
CHECK(red_position_get(0) == glm::vec2(48.0f, 0.0f));
|
||||
CHECK(red_position_get(0) == Vec2(48.0f, 0.0f));
|
||||
// This file's Inner holds its first frame however far the parent plays.
|
||||
options.time = 1.0f;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 0.0f));
|
||||
CHECK(red_position_get(1) == Vec2(-40.0f, 0.0f));
|
||||
// An animation never draws inside itself.
|
||||
CHECK_FALSE(red_position_get(3));
|
||||
|
||||
// Once stops on the child's last frame. Loop wraps around it.
|
||||
options.time = 6.0f;
|
||||
anm2.frame_edit({0, LAYER, 1, 0})->childMode = ChildMode::ONCE;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 10.0f));
|
||||
CHECK(red_position_get(1) == Vec2(-40.0f, 10.0f));
|
||||
anm2.frame_edit({0, LAYER, 1, 0})->childMode = ChildMode::LOOP;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 0.0f));
|
||||
CHECK(red_position_get(1) == Vec2(-40.0f, 0.0f));
|
||||
|
||||
// Without the library loaded, its layer draws nothing.
|
||||
options.library_get = {};
|
||||
@@ -172,12 +172,11 @@ TEST_CASE("flattening animation layers bakes their children into plain layers th
|
||||
|
||||
// Every frame, the plain layers draw where the animation layers' children did.
|
||||
auto points_get = [&](const Model& model, const LibraryGet& get, float time) {
|
||||
std::vector<glm::vec2> points{};
|
||||
std::vector<Vec2> points{};
|
||||
for (auto& draw : animation_draws_get(model, *model.animation_get(0), {.time = time, .library_get = get}))
|
||||
if (draw.type == DrawType::LAYER)
|
||||
points.push_back(
|
||||
glm::round(glm::vec2(draw.parent * draw_quad_model_get(draw) * glm::vec4(1, 1, 0, 1))));
|
||||
std::ranges::sort(points, [](glm::vec2 a, glm::vec2 b) { return std::tie(a.x, a.y) < std::tie(b.x, b.y); });
|
||||
points.push_back(vec_round(Vec2(draw.parent * draw_quad_model_get(draw) * Vec4(1, 1, 0, 1))));
|
||||
std::ranges::sort(points, [](Vec2 a, Vec2 b) { return std::tie(a.x, a.y) < std::tie(b.x, b.y); });
|
||||
return points;
|
||||
};
|
||||
for (float time = 0.0f; time < 8.0f; time += 1.0f)
|
||||
@@ -205,7 +204,7 @@ TEST_CASE("an animation layer's child sits where the layer's frame puts it")
|
||||
auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2"));
|
||||
auto placement = layer_child_transform_get(*anm2.animation_get(0), 0, 0.0f, true);
|
||||
REQUIRE(placement);
|
||||
CHECK(glm::vec2(*placement * glm::vec4(16.0f, 0.0f, 0.0f, 1.0f)) == glm::vec2(48.0f, 0.0f));
|
||||
CHECK(Vec2(*placement * Vec4(16.0f, 0.0f, 0.0f, 1.0f)) == Vec2(48.0f, 0.0f));
|
||||
CHECK_FALSE(layer_child_transform_get(*anm2.animation_get(0), 99, 0.0f, true));
|
||||
}
|
||||
|
||||
@@ -223,7 +222,7 @@ TEST_CASE("the game's copy stands in for depth and alpha offsets")
|
||||
|
||||
// Every frame, the same crops draw in the same order and places, with no depth left.
|
||||
auto draws_get = [](const Model& model, float time) {
|
||||
std::vector<std::pair<glm::vec2, glm::vec2>> draws{};
|
||||
std::vector<std::pair<Vec2, Vec2>> draws{};
|
||||
for (auto& draw : animation_draws_get(model, *model.animation_get(0), {.time = time}))
|
||||
if (draw.type == DrawType::LAYER && draw.frame.isVisible)
|
||||
draws.emplace_back(draw.frame.crop, draw.frame.position);
|
||||
|
||||
+23
-23
@@ -109,27 +109,27 @@ TEST_CASE("frame_bake and frame_mix")
|
||||
to.rotation = 90.0f;
|
||||
to.tint = {0.0f, 1.0f, 1.0f, 0.5f};
|
||||
frame_mix(from, to, 0.5f);
|
||||
CHECK(from.position == glm::vec2(5.0f, -10.0f));
|
||||
CHECK(from.skew == glm::vec2(15.0f, 0.0f));
|
||||
CHECK(from.position == Vec2(5.0f, -10.0f));
|
||||
CHECK(from.skew == Vec2(15.0f, 0.0f));
|
||||
CHECK(from.rotation == doctest::Approx(45.0f));
|
||||
CHECK(from.tint.a == doctest::Approx(0.75f));
|
||||
}
|
||||
|
||||
TEST_CASE("rects_pack fits every rect without overlap")
|
||||
{
|
||||
std::vector<glm::ivec2> sizes{{16, 16}, {32, 8}, {8, 32}, {5, 7}, {64, 1}, {1, 1}};
|
||||
glm::ivec2 size{};
|
||||
std::vector<glm::ivec2> positions{};
|
||||
std::vector<IVec2> sizes{{16, 16}, {32, 8}, {8, 32}, {5, 7}, {64, 1}, {1, 1}};
|
||||
IVec2 size{};
|
||||
std::vector<IVec2> positions{};
|
||||
REQUIRE(rects_pack(sizes, size, positions));
|
||||
REQUIRE(positions.size() == sizes.size());
|
||||
for (std::size_t i = 0; i < sizes.size(); ++i)
|
||||
{
|
||||
CHECK(glm::all(glm::greaterThanEqual(positions[i], glm::ivec2(0))));
|
||||
CHECK(glm::all(glm::lessThanEqual(positions[i] + sizes[i], size)));
|
||||
CHECK(is_all_less_equal(IVec2(0), positions[i]));
|
||||
CHECK(is_all_less_equal(positions[i] + sizes[i], size));
|
||||
for (std::size_t j = i + 1; j < sizes.size(); ++j)
|
||||
{
|
||||
auto isSeparate = glm::any(glm::lessThanEqual(positions[i] + sizes[i], positions[j])) ||
|
||||
glm::any(glm::lessThanEqual(positions[j] + sizes[j], positions[i]));
|
||||
auto isSeparate = is_any_less_equal(positions[i] + sizes[i], positions[j]) ||
|
||||
is_any_less_equal(positions[j] + sizes[j], positions[i]);
|
||||
CHECK(isSeparate);
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ TEST_CASE("edit layer operations")
|
||||
|
||||
TEST_CASE("spritesheet pixel edits")
|
||||
{
|
||||
auto image_make = [](glm::ivec2 size, std::vector<glm::ivec2> opaque = {}) {
|
||||
auto image_make = [](IVec2 size, std::vector<IVec2> opaque = {}) {
|
||||
std::vector<uint8_t> pixels((std::size_t)size.x * size.y * IMAGE_CHANNELS, 0);
|
||||
for (auto point : opaque)
|
||||
std::fill_n(pixels.begin() + ((std::size_t)point.y * size.x + point.x) * IMAGE_CHANNELS, IMAGE_CHANNELS,
|
||||
@@ -249,9 +249,9 @@ TEST_CASE("spritesheet pixel edits")
|
||||
auto model = fixture_load("05_regions.anm2");
|
||||
CHECK(regions_trim(model, 0, {0, 1}, sheet));
|
||||
auto region = item_get(model.content.spritesheets[0].regions, 0);
|
||||
CHECK(region->crop == glm::vec2(4, 6));
|
||||
CHECK(region->size == glm::vec2(1, 1));
|
||||
CHECK(region->pivot == glm::vec2(-1, -1));
|
||||
CHECK(region->crop == Vec2(4, 6));
|
||||
CHECK(region->size == Vec2(1, 1));
|
||||
CHECK(region->pivot == Vec2(-1, -1));
|
||||
}
|
||||
|
||||
SUBCASE("spritesheet_pack returns an image holding every region")
|
||||
@@ -261,7 +261,7 @@ TEST_CASE("spritesheet pixel edits")
|
||||
REQUIRE(packed);
|
||||
CHECK(packed->is_valid());
|
||||
for (auto& region : model.content.spritesheets[0].regions)
|
||||
CHECK(glm::all(glm::lessThanEqual(glm::ivec2(region.crop + region.size), packed->size)));
|
||||
CHECK(is_all_less_equal(IVec2(region.crop + region.size), packed->size));
|
||||
}
|
||||
|
||||
SUBCASE("spritesheets_merge appends images and moves layers onto the base sheet")
|
||||
@@ -272,7 +272,7 @@ TEST_CASE("spritesheet pixel edits")
|
||||
};
|
||||
auto merged = spritesheets_merge(model, {0, 1}, image_get, true, true, false, Origin::TOP_LEFT);
|
||||
REQUIRE(merged);
|
||||
CHECK(merged->size == glm::ivec2(80, 64));
|
||||
CHECK(merged->size == IVec2(80, 64));
|
||||
CHECK(model.content.spritesheets.size() == 1);
|
||||
CHECK(item_get(model.content.layers, 1)->spritesheetId == 0);
|
||||
operation_check("spritesheets_merge", model);
|
||||
@@ -287,7 +287,7 @@ TEST_CASE("markers stay in the editor's copy and bound playback")
|
||||
animation->frameNum = 10;
|
||||
animation->startMarker = 2;
|
||||
animation->endMarker = 5;
|
||||
CHECK(animation_play_range_get(*animation) == glm::ivec2(2, 6));
|
||||
CHECK(animation_play_range_get(*animation) == IVec2(2, 6));
|
||||
|
||||
auto text = model_to_string(model);
|
||||
CHECK(game_document_get(text).find("Marker") == std::string::npos);
|
||||
@@ -325,11 +325,11 @@ TEST_CASE("frames_property_set copies one property to the frames that have it")
|
||||
auto nullCrop = model.frame_get(null)->crop;
|
||||
|
||||
frames_property_set(model, {layer, null}, FrameProperty::POSITION, source);
|
||||
CHECK(model.frame_get(layer)->position == glm::vec2(3, 4));
|
||||
CHECK(model.frame_get(null)->position == glm::vec2(3, 4));
|
||||
CHECK(model.frame_get(layer)->position == Vec2(3, 4));
|
||||
CHECK(model.frame_get(null)->position == Vec2(3, 4));
|
||||
|
||||
frames_property_set(model, {layer, null}, FrameProperty::CROP, source);
|
||||
CHECK(model.frame_get(layer)->crop == glm::vec2(7, 8));
|
||||
CHECK(model.frame_get(layer)->crop == Vec2(7, 8));
|
||||
CHECK(model.frame_get(null)->crop == nullCrop);
|
||||
|
||||
CHECK_FALSE(is_frame_property_valid(FrameProperty::EVENT, ItemType::LAYER));
|
||||
@@ -418,7 +418,7 @@ TEST_CASE("skew reads from the old Shear attributes too")
|
||||
{
|
||||
auto frames = frames_from_string(R"(<Frame ShearX="5" ShearY="6"/><Frame SkewX="7" ShearX="9"/>)", ItemType::NULL_);
|
||||
REQUIRE(frames.size() == 2);
|
||||
CHECK(frames[0].skew == glm::vec2(5, 6));
|
||||
CHECK(frames[0].skew == Vec2(5, 6));
|
||||
CHECK(frames[1].skew.x == 7);
|
||||
CHECK(frames[0].extras.attributes.empty());
|
||||
}
|
||||
@@ -445,10 +445,10 @@ TEST_CASE("SVG spritesheets pack and merge into SVGs")
|
||||
auto packed = spritesheet_pack(model, 0, vector, 1);
|
||||
REQUIRE(packed);
|
||||
CHECK(packed->is_vector());
|
||||
for (auto [id, original] : {std::pair{0, glm::vec2(8, 8)}, std::pair{1, glm::vec2(24, 8)}})
|
||||
for (auto [id, original] : {std::pair{0, Vec2(8, 8)}, std::pair{1, Vec2(24, 8)}})
|
||||
{
|
||||
auto region = item_get(model.content.spritesheets.front().regions, id);
|
||||
CHECK(packed->pixel_read(region->crop + glm::vec2(8, 8)) == vector.pixel_read(original));
|
||||
CHECK(packed->pixel_read(region->crop + Vec2(8, 8)) == vector.pixel_read(original));
|
||||
}
|
||||
|
||||
// A PNG sheet merged after an SVG one: the result is an SVG holding the PNG. A PNG first takes the .svg name.
|
||||
@@ -463,7 +463,7 @@ TEST_CASE("SVG spritesheets pack and merge into SVGs")
|
||||
auto merged = spritesheets_merge(mixed, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT);
|
||||
REQUIRE(merged);
|
||||
CHECK(merged->is_vector());
|
||||
CHECK(merged->size == glm::ivec2(36, 16));
|
||||
CHECK(merged->size == IVec2(36, 16));
|
||||
CHECK(merged->pixel_read({33, 1}) == raster.pixel_read({1, 1}));
|
||||
CHECK(mixed.content.spritesheets.front().path == "vector.svg");
|
||||
|
||||
|
||||
+19
-21
@@ -23,7 +23,7 @@ const std::filesystem::path OUTPUT_DIR = ANM2ED_RENDER_DIR;
|
||||
constexpr int CHANNEL_TOLERANCE = 8;
|
||||
constexpr double MISMATCH_RATIO_MAX = 0.01;
|
||||
constexpr float SCALE = 3.0f;
|
||||
constexpr glm::vec4 BACKGROUND = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
constexpr Vec4 BACKGROUND = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
|
||||
// Different OpenGL implementations round a little differently: a few pixels may differ, each only slightly.
|
||||
static void golden_image_check(const std::string& name)
|
||||
@@ -53,7 +53,7 @@ struct RenderFixture
|
||||
std::optional<ShaderProgram> shader;
|
||||
std::optional<Canvas> canvas;
|
||||
const Animation* animation = nullptr;
|
||||
glm::vec4 bounds{};
|
||||
Vec4 bounds{};
|
||||
|
||||
explicit RenderFixture(const char* file)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ struct RenderFixture
|
||||
document.emplace(RENDER_TEST_DIR / file, false);
|
||||
auto& info = SHADERS[SHADER_TEXTURE];
|
||||
shader.emplace(info.vertex, info.fragment);
|
||||
canvas.emplace(glm::vec2(1.0f));
|
||||
canvas.emplace(Vec2(1.0f));
|
||||
animation = document->model.animation_get(0);
|
||||
bounds = animation_bounds_get(*document, *animation, true);
|
||||
}
|
||||
@@ -76,9 +76,9 @@ struct RenderFixture
|
||||
return pixels;
|
||||
}
|
||||
|
||||
glm::u8vec4 pixel_get(const std::vector<uint8_t>& pixels, glm::vec2 point)
|
||||
TVec4<uint8_t> pixel_get(const std::vector<uint8_t>& pixels, Vec2 point)
|
||||
{
|
||||
auto position = glm::ivec2((point - glm::vec2(bounds.x, bounds.y)) * SCALE);
|
||||
auto position = IVec2((point - Vec2(bounds.x, bounds.y)) * SCALE);
|
||||
auto index = ((std::size_t)position.y * (std::size_t)canvas->size.x + (std::size_t)position.x) * 4;
|
||||
return {pixels[index], pixels[index + 1], pixels[index + 2], pixels[index + 3]};
|
||||
}
|
||||
@@ -106,7 +106,7 @@ TEST_CASE("frames draw where the animation puts them")
|
||||
CHECK(blue.b > blue.r + 40);
|
||||
|
||||
auto framePath = OUTPUT_DIR / "spin_frame_0.png";
|
||||
REQUIRE(Image::write_pixels_png(framePath, glm::ivec2(fixture.canvas->size), pixels.data()));
|
||||
REQUIRE(Image::write_pixels_png(framePath, IVec2(fixture.canvas->size), pixels.data()));
|
||||
golden_image_check("spin_frame_0.png");
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ TEST_CASE("a recorded spritesheet holds every frame")
|
||||
fixture.bounds, SCALE, BACKGROUND, true));
|
||||
Image sheet(options.path);
|
||||
auto layout = spritesheet_layout_get(0, 0, fixture.animation->frameNum);
|
||||
CHECK(sheet.size == glm::ivec2(fixture.canvas->size) * glm::ivec2(layout.columns, layout.rows));
|
||||
CHECK(sheet.size == IVec2(fixture.canvas->size) * IVec2(layout.columns, layout.rows));
|
||||
golden_image_check("spin_sheet.png");
|
||||
}
|
||||
|
||||
@@ -146,15 +146,14 @@ TEST_CASE("animation layers draw their child animations")
|
||||
// The library's red square at half size starts on its fifth frame, centered at (48, 0). This file's Inner holds its
|
||||
// red square at (-40, 0).
|
||||
auto pixels = fixture.frame_get(0.0f);
|
||||
for (auto point : {glm::vec2(48.0f, 0.0f), glm::vec2(-40.0f, 0.0f)})
|
||||
for (auto point : {Vec2(48.0f, 0.0f), Vec2(-40.0f, 0.0f)})
|
||||
{
|
||||
auto red = fixture.pixel_get(pixels, point);
|
||||
CHECK(red.r > 200);
|
||||
CHECK(red.g < 80);
|
||||
}
|
||||
|
||||
REQUIRE(
|
||||
Image::write_pixels_png(OUTPUT_DIR / "nested_frame_0.png", glm::ivec2(fixture.canvas->size), pixels.data()));
|
||||
REQUIRE(Image::write_pixels_png(OUTPUT_DIR / "nested_frame_0.png", IVec2(fixture.canvas->size), pixels.data()));
|
||||
golden_image_check("nested_frame_0.png");
|
||||
}
|
||||
|
||||
@@ -170,7 +169,7 @@ TEST_CASE("a blurred layer spreads past its crop like Flash's blur filter")
|
||||
|
||||
// The red square (16 x 16 at (-16, 0)) sharp leaves the canvas clear 2 above its top edge and solid 1 inside it. An
|
||||
// 8 pixel box spreads a third of it out and takes as much from inside.
|
||||
constexpr glm::vec2 OUTSIDE{-20.0f, -10.0f}, INSIDE{-20.0f, -7.0f};
|
||||
constexpr Vec2 OUTSIDE{-20.0f, -10.0f}, INSIDE{-20.0f, -7.0f};
|
||||
auto sharp = fixture.frame_get(0.0f);
|
||||
fixture.document->model.frame_edit({0, LAYER, 0, 0})->blur = 8.0f;
|
||||
fixture.animation = fixture.document->model.animation_get(0);
|
||||
@@ -178,8 +177,7 @@ TEST_CASE("a blurred layer spreads past its crop like Flash's blur filter")
|
||||
CHECK(fixture.pixel_get(blurred, OUTSIDE).r > fixture.pixel_get(sharp, OUTSIDE).r + 40);
|
||||
CHECK(fixture.pixel_get(blurred, INSIDE).r + 40 < fixture.pixel_get(sharp, INSIDE).r);
|
||||
|
||||
REQUIRE(Image::write_pixels_png(OUTPUT_DIR / "spin_blur_frame_0.png", glm::ivec2(fixture.canvas->size),
|
||||
blurred.data()));
|
||||
REQUIRE(Image::write_pixels_png(OUTPUT_DIR / "spin_blur_frame_0.png", IVec2(fixture.canvas->size), blurred.data()));
|
||||
}
|
||||
|
||||
TEST_CASE("SVG spritesheets draw sharp at any scale")
|
||||
@@ -200,8 +198,7 @@ TEST_CASE("SVG spritesheets draw sharp at any scale")
|
||||
CHECK(inside.r > 200);
|
||||
CHECK(outside.r < 80);
|
||||
|
||||
REQUIRE(
|
||||
Image::write_pixels_png(OUTPUT_DIR / "vector_frame_0.png", glm::ivec2(fixture.canvas->size), pixels.data()));
|
||||
REQUIRE(Image::write_pixels_png(OUTPUT_DIR / "vector_frame_0.png", IVec2(fixture.canvas->size), pixels.data()));
|
||||
golden_image_check("vector_frame_0.png");
|
||||
}
|
||||
|
||||
@@ -299,7 +296,7 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the
|
||||
|
||||
auto& info = SHADERS[SHADER_TEXTURE];
|
||||
ShaderProgram shader(info.vertex, info.fragment);
|
||||
Canvas canvas(glm::vec2(1.0f));
|
||||
Canvas canvas(Vec2(1.0f));
|
||||
for (int index = 0; index < document.model.animations_count_get(); ++index)
|
||||
{
|
||||
auto& animation = *document.model.animation_get(index);
|
||||
@@ -307,14 +304,14 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the
|
||||
INFO("animation: ", animation.name);
|
||||
// On whole pixels, so the baked images land on the pixels they were drawn on.
|
||||
auto bounds = animation_bounds_get(document, animation, true);
|
||||
bounds = glm::vec4(glm::floor(glm::vec2(bounds)) - 8.0f, glm::ceil(glm::vec2(bounds.z, bounds.w)) + 16.0f);
|
||||
bounds = Vec4(vec_floor(Vec2(bounds)) - 8.0f, vec_ceil(Vec2(bounds.z, bounds.w)) + 16.0f);
|
||||
for (int time = 0; time < animation.frameNum; ++time)
|
||||
{
|
||||
INFO("time: ", time);
|
||||
auto expected = animation_frame_render(canvas, shader, document, animation, (float)time, bounds, 1.0f,
|
||||
glm::vec4(0.0f), true);
|
||||
Vec4(0.0f), true);
|
||||
auto actual = animation_frame_render(canvas, shader, gameDocument, gameAnimation, (float)time, bounds, 1.0f,
|
||||
glm::vec4(0.0f), true);
|
||||
Vec4(0.0f), true);
|
||||
REQUIRE(actual.size() == expected.size());
|
||||
CHECK(std::ranges::any_of(expected, [](uint8_t channel) { return channel != 0; }));
|
||||
int mismatches = 0;
|
||||
@@ -344,8 +341,9 @@ TEST_CASE("audio decodes and mixes")
|
||||
|
||||
constexpr int FREQUENCY = 22050;
|
||||
constexpr int FRAMES = 100;
|
||||
std::vector<unsigned char> wav = {'R', 'I', 'F', 'F', 0, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0, 0,
|
||||
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 16, 0, 'd', 'a', 't', 'a', 0, 0, 0, 0};
|
||||
std::vector<unsigned char> wav = {'R', 'I', 'F', 'F', 0, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't',
|
||||
' ', 16, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 16, 0, 'd', 'a', 't', 'a', 0, 0, 0, 0};
|
||||
auto put = [&](int offset, std::uint32_t value, int size) {
|
||||
for (int i = 0; i < size; ++i)
|
||||
wav[offset + i] = (unsigned char)(value >> (i * 8));
|
||||
|
||||
Reference in new issue
Block a user