summaryrefslogtreecommitdiffhomepage
path: root/loader/error-tex.cpp
blob: bcb53898973f340ea1292686d9538d335a96bbf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "impl.hpp"
#include "compat/assert.hpp"
#include <Corrade/Containers/Array.h>
#include <Magnum/Math/Vector4.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/Trade/ImageData.h>

namespace floormat::loader_detail {

Trade::ImageData2D loader_impl::make_error_texture(Vector2ui size)
{
    constexpr auto magenta = Vector4ub{255, 0, 255, 255};
    return make_error_texture(size, magenta);
}

Trade::ImageData2D loader_impl::make_error_texture(Vector2ui size, Vector4ub color)
{
    fm_assert(size.product() != 0);
    auto array = Array<char>{NoInit, 4uz * size.product()};
    auto data = array.data(), end = data + array.size();
    while (data != end)
    {
        *(Vector4ub*)data = color;
        data += 4;
    }
    auto img = Trade::ImageData2D{PixelFormat::RGBA8Unorm, Vector2i(size), move(array)};
    return img;
}

} // namespace floormat::loader_detail