TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_graphics_context.h
Go to the documentation of this file.
1#pragma once
2
4#include <gui_core/gui_id.h>
6
9
11
13#include <gui_core/windows/gui_window_backend.h> // OSWindowHandle (used in pure-virtual signatures)
14
15#include <functional>
16#include <source_location>
17#include <string_view>
18
19namespace tachyon
20{
23
24 enum class WindowFlags : uint32_t;
25 enum class VisualColorStyleIndex : uint16_t;
26
27 class GUIRenderer;
28 class TextAtlasManager;
29 class StyleManager;
30 class GradientManager;
31 class ImageSet;
32 class Image;
33 class Buffer;
34 class VisualColorStyle;
35 struct VisualBoxStyle;
36 class ITextSystem;
37 class GUIStateManager;
38 class IWindowBackend;
39 class IWindowContext;
40
43 enum class DeviceScope
44 {
47 };
48
53 {
54 public:
58
62 bool TakeContentChanged() { const bool changed = m_contentChanged; m_contentChanged = false; return changed; }
63
64 public:
65 GraphicsContext() = default;
66
67 virtual ~GraphicsContext() {}
68
69 public:
71 virtual GraphicsAPI GetAPI() const = 0;
74 virtual std::string_view GetDeviceName() const { return {}; }
75
77 virtual void SetAllocationHooks(const AllocationHooks& hooks) = 0;
81 virtual void SetImageSlotCount(uint32_t) {}
83 virtual uint32_t GetImageSlotCount() const { return 0; }
89 virtual void SetGpuPreference(std::string_view) {}
93 virtual Result<void> Initialize(IWindowBackend* windowBackend) = 0;
95 virtual bool DeviceLost() const { return false; }
98 virtual Result<void> RecreateDevice(IWindowBackend*) { return Error{ ErrorCode::Unsupported, "this backend can't recreate its device" }; }
101 virtual void Cleanup() = 0;
104 virtual void BeginFrame() = 0;
106 virtual void EndFrame() = 0;
107
108 public:
112 virtual Image* CreateImage(void* data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped = false) = 0;
118 virtual bool UpdateImageRows(Image* /*image*/, uint32_t /*firstRow*/, uint32_t /*rowCount*/, const void* /*data*/) { return false; }
124 virtual void DestroyImageAtEnd(Image* img, DeviceScope scope, const std::source_location& loc = std::source_location::current()) = 0;
125
126 public:
129
130 // ---- Window-context lifecycle ----
131
135 virtual IWindowContext* CreateWindowContext(void* nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) = 0;
137 virtual void DestroyWindowContext(IWindowContext* context) = 0;
138
139 public:
141 virtual ImageSet* GetImageSet() const = 0;
143 virtual ImageIndex RegisterImage(Image* image) = 0;
145 virtual void UnregisterImage(ImageIndex index) = 0;
146
154 virtual ImageIndex RenderScene(ID /*key*/, ID /*window*/, uint2 /*size*/, color4f /*clear*/,
155 std::function<void(const ScenePayload& scene)> /*record*/) { return ImageIndex::Invalid; }
156
160 virtual void PrepareFrame(StyleManager& styleManager, GradientManager& gradientManager, float elapsedTimeSecs) = 0;
161
164 virtual float GetLastFrameBuildSeconds() const { return 0.0f; }
165
166 protected:
168 void MarkContentChanged() { m_contentChanged = true; }
169
170 private:
171 bool m_contentChanged = false;
172 };
173
174}
Definition gui_buffer.h:9
Definition gui_renderer.h:78
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:65
virtual TextAtlasManager * CreateTextAtlasManager()=0
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
virtual void SetAllocationHooks(const AllocationHooks &hooks)=0
Host memory functions for the graphics API's allocations. Call before Initialize.
virtual void UnregisterImage(ImageIndex index)=0
Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).
virtual GraphicsAPI GetAPI() const =0
The API it presents with; window backends make their windows for it.
virtual IWindowContext * CreateWindowContext(void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui)=0
Makes the context that renders an OS window: nativeWindowHandle comes from IWindowBackend::GetNativeH...
virtual std::string_view GetDeviceName() const
The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize ...
Definition gui_graphics_context.h:74
virtual Image * CreateImage(void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false)=0
Makes an image from size.x x size.y tightly packed pixels of format (Vulkan: data null for a cleared ...
virtual void EndFrame()=0
Ends the UI build, before the uploads and the window contexts' recording.
virtual void DestroyWindowContext(IWindowContext *context)=0
Waits for the context's GPU work and destroys it now; its native window must still exist.
virtual ~GraphicsContext()
Definition gui_graphics_context.h:67
virtual float GetLastFrameBuildSeconds() const
Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before ...
Definition gui_graphics_context.h:164
virtual ImageIndex RegisterImage(Image *image)=0
Adds the image to the image set; elements draw it by the returned index.
virtual ImageSet * GetImageSet() const =0
The images the shaders sample, by ImageIndex.
virtual void Cleanup()=0
Waits for the GPU and destroys what the backend made, the renderer included.
virtual bool DeviceLost() const
True once the GPU device is lost; RecreateDevice then makes a new one.
Definition gui_graphics_context.h:95
virtual uint32_t GetImageSlotCount() const
How many images can be registered at once; 0 when the backend doesn't say.
Definition gui_graphics_context.h:83
virtual Result< void > RecreateDevice(IWindowBackend *)
Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are t...
Definition gui_graphics_context.h:98
void MarkContentChanged()
For backends: see TakeContentChanged.
Definition gui_graphics_context.h:168
virtual void DestroyImageAtEnd(Image *img, DeviceScope scope, const std::source_location &loc=std::source_location::current())=0
Destroys the image and deletes the object once the GPU is done with it: for DeviceScope::Frame once i...
virtual bool UpdateImageRows(Image *, uint32_t, uint32_t, const void *)
Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightl...
Definition gui_graphics_context.h:118
virtual ImageIndex RenderScene(ID, ID, uint2, color4f, std::function< void(const ScenePayload &scene)>)
An image the app draws a scene into (a 3D viewport), size pixels with a depth buffer,...
Definition gui_graphics_context.h:154
virtual void SetImageSlotCount(uint32_t)
How many images can be registered at once (fonts, icons, gradients and the app's own share them).
Definition gui_graphics_context.h:81
GUIRenderer * guiRenderer
Where the UI records its draw primitives.
Definition gui_graphics_context.h:57
bool TakeContentChanged()
True when something drawn changed since the last call without a draw changing: an image registered or...
Definition gui_graphics_context.h:62
virtual Result< void > Initialize(IWindowBackend *windowBackend)=0
Brings the device up; GUIApplication::Initialize calls it once, before any window context.
virtual void BeginFrame()=0
Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scop...
virtual void PrepareFrame(StyleManager &styleManager, GradientManager &gradientManager, float elapsedTimeSecs)=0
Uploads the styles and gradient pages for this frame's draws, after the UI build and before the windo...
virtual void SetGpuPreference(std::string_view)
Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"),...
Definition gui_graphics_context.h:89
Text and icon registration, measurement, rendering and editing.
Definition gui_text_system.h:189
Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one,...
Definition gui_window_backend.h:112
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
The images the shaders can sample, each at an ImageIndex. Implemented by the backend.
Definition gui_image.h:106
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
A value, or the Error saying why there is none.
Definition gui_result.h:36
What GraphicsContext::RenderScene's record gets: the backend's recording state, as the struct of the ...
Definition gui_graphics_api.h:41
Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices in...
Definition gui_style_manager.h:39
Definition gui_text_atlas_manager.h:17
GPU form of a ColorStyle, uploaded as is: the gradient is baked into an atlas slot that colorUV / gra...
Definition gui_style.h:591
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
DeviceScope
When a deferred GPU resource destruction runs: Frame once the GPU has finished the frames that may us...
Definition gui_graphics_context.h:44
@ Invalid
Definition gui_image.h:99
@ Frame
Definition gui_graphics_context.h:45
@ Application
Definition gui_graphics_context.h:46
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
std::function< void()> OnGuiFunc
Definition gui_base_types.h:13
@ Unsupported
the device or backend lacks a feature
Definition gui_result.h:19
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:14
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
Definition gui_logging.h:24
GraphicsAPI
The graphics API a backend presents with; window backends create their windows to match (SDL: SDL_WIN...
Definition gui_graphics_api.h:14
Memory functions a host gives the library, for the allocations that can be routed: Vulkan objects,...
Definition gui_allocation_hooks.h:17
A failure: its category and a human-readable message.
Definition gui_result.h:26
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
The box part of one state of a registered Style, in pixels; uploaded to the GPU as is (32 bytes).
Definition gui_style.h:923
Definition gui_base_types.h:394
Integer 2D vector.
Definition gui_base_types.h:18
Definition gui_base_types.h:74