TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_image.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_base_types.h> // float2, uint2, IntRect
4
5#include <stdint.h>
6
7namespace tachyon
8{
11
14 struct UVRect
15 {
16 float2 min { 0.0f, 0.0f };
17 float2 max { 1.0f, 1.0f };
18
21 static UVRect FromPixels(IntRect pixels, uint2 imageSize)
22 {
23 const float w = imageSize.x > 0 ? float(imageSize.x) : 1.0f;
24 const float h = imageSize.y > 0 ? float(imageSize.y) : 1.0f;
25 return { { float(pixels.x) / w, float(pixels.y) / h },
26 { float(pixels.x + pixels.w) / w, float(pixels.y + pixels.h) / h } };
27 }
28
29 bool operator==(const UVRect&) const = default;
30 };
31
33 enum class ImageChannel : uint8_t { Red, Green, Blue, Alpha, Zero, One };
34
42 {
43 color4f tint { 1.0f, 1.0f, 1.0f, 1.0f };
48 bool srgbEncode = false;
49
52 {
53 ImageDisplay display;
54 display.red = display.green = display.blue = channel;
55 display.alpha = ImageChannel::One;
56 return display;
57 }
58
61 uint32_t PackedFlags() const
62 {
63 const uint32_t channels = uint32_t(red) | (uint32_t(green) << 3) | (uint32_t(blue) << 6) | (uint32_t(alpha) << 9);
64 const uint32_t flags = channels | (srgbEncode ? (1u << 12) : 0u);
65 constexpr uint32_t kIdentity = 0u | (1u << 3) | (2u << 6) | (3u << 9);
66 return flags == kIdentity ? 0u : (flags | (1u << 31));
67 }
68
69 bool operator==(const ImageDisplay&) const = default;
70 };
71
86
96
99 enum ImageIndex : uint32_t { Invalid = 0 };
100
102 class Image {};
103
106 {
107 public:
108 virtual ~ImageSet() {}
110 virtual void Clear() = 0;
112 virtual ImageIndex Add(Image* image) = 0;
114 virtual void Remove(ImageIndex index) = 0;
115 };
116
117}
The images the shaders can sample, each at an ImageIndex. Implemented by the backend.
Definition gui_image.h:106
virtual void Remove(ImageIndex index)=0
Frees the index for reuse; the image itself stays.
virtual ~ImageSet()
Definition gui_image.h:108
virtual ImageIndex Add(Image *image)=0
Adds an image (not owned) and returns its index.
virtual void Clear()=0
Removes every image, freeing all indices.
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
Sampler
How an image is filtered and addressed when sampled.
Definition gui_image.h:89
ImageFormat
Pixel formats for GraphicsContext::CreateImage, 8 bits per channel.
Definition gui_image.h:75
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
ImageChannel
A channel of an image's pixel, or a constant, for ImageDisplay.
Definition gui_image.h:33
@ NearestRepeat
Definition gui_image.h:92
@ LinearClampToEdge
Definition gui_image.h:94
@ LinearRepeat
Definition gui_image.h:93
@ UNDEFINED
Definition gui_image.h:76
@ R8G8B8
Definition gui_image.h:81
@ R8G8B8A8
Definition gui_image.h:83
@ R8G8B8A8_SRGB
Definition gui_image.h:84
@ R8G8B8_SRGB
Definition gui_image.h:82
@ R8G8_SRGB
Definition gui_image.h:80
@ R8G8
Definition gui_image.h:79
@ R8_SRGB
Definition gui_image.h:78
@ R8
Definition gui_image.h:77
@ Invalid
Definition gui_image.h:99
@ One
Definition gui_image.h:33
@ Alpha
Definition gui_image.h:33
@ Blue
Definition gui_image.h:33
@ Green
Definition gui_image.h:33
@ Zero
Definition gui_image.h:33
@ Red
Definition gui_image.h:33
Definition gui_logging.h:24
How an image is shown, in this order:
Definition gui_image.h:42
ImageChannel blue
Definition gui_image.h:46
static ImageDisplay Channel(ImageChannel channel)
One channel shown as grey, opaque: a mask, a roughness map, an image's alpha.
Definition gui_image.h:51
bool srgbEncode
Definition gui_image.h:48
ImageChannel alpha
Definition gui_image.h:47
color4f tint
Definition gui_image.h:43
ImageChannel red
Definition gui_image.h:44
uint32_t PackedFlags() const
The channels and the sRGB flag as the shader reads them: 3 bits a channel (red first),...
Definition gui_image.h:61
ImageChannel green
Definition gui_image.h:45
bool operator==(const ImageDisplay &) const =default
Definition gui_base_types.h:406
The part of an image to draw, in UV: 0,0 is its top-left corner and 1,1 its bottom-right.
Definition gui_image.h:15
float2 max
Definition gui_image.h:17
float2 min
Definition gui_image.h:16
static UVRect FromPixels(IntRect pixels, uint2 imageSize)
The part of an image imageSize pixels big covered by pixels, as for a cell of an atlas.
Definition gui_image.h:21
bool operator==(const UVRect &) const =default
Definition gui_base_types.h:394
Definition gui_base_types.h:120
Definition gui_base_types.h:74
uint32_t x
Definition gui_base_types.h:75
uint32_t y
Definition gui_base_types.h:75