30 lines
642 B
C++
30 lines
642 B
C++
#include "assets/fallback_data/fallback_texture.hpp"
|
|
|
|
assets::texture_data assets::generate_fallback_texture(
|
|
const int width,
|
|
const int height,
|
|
const std::span<const fallback_color> colors
|
|
) {
|
|
const auto pixel_count = width * height;
|
|
|
|
auto data = std::make_unique<texture_data::value_type[]>(pixel_count * sizeof(fallback_color));
|
|
|
|
auto pixels = reinterpret_cast<fallback_color*>(data.get());
|
|
|
|
for (int y{}; y != height; ++y)
|
|
{
|
|
for (int x{}; x != width; ++x)
|
|
{
|
|
const auto index = (x + y) % colors.size();
|
|
*pixels++ = colors[index];
|
|
}
|
|
}
|
|
|
|
return {
|
|
std::move(data),
|
|
width,
|
|
height,
|
|
fallback_color::components
|
|
};
|
|
}
|