TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_image_batcher.h
Go to the documentation of this file.
1#pragma once
2
3// For a backend that binds only a few images per draw (SDL GPU, 16 samplers a shader stage):
4// which images the primitives of a draw read, and where to cut the draw so each part reads no
5// more than the backend binds. The parts are consecutive runs of the draw's primitives, so
6// they draw the same thing in the same order. The images are 0-based image slots, as the
7// shaders index them.
8
11
12#include <array>
13#include <cstddef>
14#include <cstdint>
15#include <span>
16#include <vector>
17
18namespace tachyon
19{
22
24 {
25 public:
27 static constexpr uint32_t kMaxImages = 16;
28
30 struct Batch
31 {
32 uint32_t first = 0;
33 uint32_t count = 0;
34 uint32_t imageCount = 0;
35 std::array<uint32_t, kMaxImages> images {};
36 };
37
40 void SetStyles(std::span<const VisualColorStyle> colorStyles, std::span<const VisualBoxStyle> boxStyles);
41
45 void Split(PrimitiveKind kind, std::span<const std::byte> primitives, uint32_t firstPrimitive, uint32_t maxImages,
46 std::vector<Batch>& out) const;
47
48 private:
49 static constexpr uint32_t kNone = UINT32_MAX;
52 static constexpr uint32_t kMostPerPrimitive = 1 + 2 * (1 + 4 * 5);
53
55 uint32_t Read(PrimitiveKind kind, const std::byte* primitive, std::array<uint32_t, kMostPerPrimitive>& images) const;
56 void AddColorStyle(int colorStyle, std::array<uint32_t, kMostPerPrimitive>& images, uint32_t& count) const;
57
59 std::vector<std::array<uint32_t, 2>> m_colorImages;
61 std::vector<std::array<uint16_t, 5>> m_boxColors;
62 };
63
64}
Definition gui_image_batcher.h:24
void Split(PrimitiveKind kind, std::span< const std::byte > primitives, uint32_t firstPrimitive, uint32_t maxImages, std::vector< Batch > &out) const
Cuts a draw of kind: primitives are its primitives' bytes, from firstPrimitive.
static constexpr uint32_t kMaxImages
The most images a batch holds.
Definition gui_image_batcher.h:27
void SetStyles(std::span< const VisualColorStyle > colorStyles, std::span< const VisualBoxStyle > boxStyles)
The styles the frame's draws use, as uploaded: the color styles' gradient pages are their image slots...
PrimitiveKind
Definition gui_render_primitives.h:209
Definition gui_logging.h:24
A run of a draw's primitives, and the images it reads.
Definition gui_image_batcher.h:31
uint32_t first
its first primitive, in the kind's stream
Definition gui_image_batcher.h:32
uint32_t count
Definition gui_image_batcher.h:33
std::array< uint32_t, kMaxImages > images
Definition gui_image_batcher.h:35
uint32_t imageCount
Definition gui_image_batcher.h:34