Unravel Engine C++ Reference
Loading...
Searching...
No Matches
default_textures.cpp
Go to the documentation of this file.
1#include "default_textures.h"
2#include <graphics/graphics.h>
3#include <array>
4#include <cstdint>
5
6namespace unravel
7{
8
9namespace
10{
11
12auto create_4x4_rgba8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) -> gfx::texture::ptr
13{
14 constexpr uint16_t width = 4;
15 constexpr uint16_t height = 4;
16 constexpr uint16_t num_layers = 1;
17 std::array<uint8_t, width * height * 4> pixels{};
18 for(size_t i = 0; i < width * height; ++i)
19 {
20 pixels[i * 4 + 0] = r;
21 pixels[i * 4 + 1] = g;
22 pixels[i * 4 + 2] = b;
23 pixels[i * 4 + 3] = a;
24 }
25 auto* mem = gfx::copy(pixels.data(), static_cast<uint32_t>(pixels.size()));
26 return std::make_shared<gfx::texture>(
28 false,
29 num_layers,
30 gfx::texture_format::RGBA8,
31 BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE,
32 mem);
33}
34
35} // namespace
36
37default_textures::default_textures() = default;
38
40{
41 static default_textures instance;
42 return instance;
43}
44
46{
47 black_ = create_4x4_rgba8(0, 0, 0, 255);
48 white_ = create_4x4_rgba8(255, 255, 255, 255);
49 missing_ = create_4x4_rgba8(255, 0, 255, 255);
50 transparent_ = create_4x4_rgba8(0, 0, 0, 0);
51
52 cloud_noise_.generate();
53}
54
56{
57 black_.reset();
58 white_.reset();
59 missing_.reset();
60 transparent_.reset();
61
62 cloud_noise_.clear();
63}
64
65} // namespace unravel
uint32_t width
uint32_t height
entt::handle b
entt::handle a
static auto get() -> default_textures &
std::vector< uint8_t > pixels
Definition mcp_async.cpp:28
const memory_view * copy(const void *_data, uint32_t _size)
Definition graphics.cpp:460