TachyonUI 0.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
5
8
10
11#include <gui_core/windows/gui_window_backend.h> // OSWindowHandle (used in pure-virtual signatures)
12
13#include <source_location>
14#include <span>
15#include <string_view>
16#include <vector>
17
18namespace tachyon
19{
22
23 enum class WindowFlags : uint32_t;
24 enum class VisualColorStyleIndex : uint16_t;
25
26 class GUIRenderer;
27 class TextAtlasManager;
28 class StyleManager;
29 class GradientManager;
30 class ImageSet;
31 class Image;
32 class Buffer;
33 class VisualColorStyle;
34 struct VisualBoxStyle;
35 class ITextSystem;
36 class GUIStateManager;
37 class IWindowBackend;
38 class IWindowContext;
39
42 enum class DeviceScope
43 {
46 };
47
50 enum class GraphicsAPI : uint8_t
51 {
54 };
55
60 {
61 public:
65
66 public:
67 GraphicsContext() = default;
68
69 virtual ~GraphicsContext() {}
70
71 public:
73 virtual GraphicsAPI GetAPI() const = 0;
74
76 virtual void SetAllocationHooks(const AllocationHooks& hooks) = 0;
80 virtual Result<void> Initialize(IWindowBackend* windowBackend) = 0;
82 virtual bool DeviceLost() const { return false; }
85 virtual Result<void> RecreateDevice(IWindowBackend*) { return Error{ ErrorCode::Unsupported, "this backend can't recreate its device" }; }
88 virtual void Cleanup() = 0;
91 virtual void BeginFrame() = 0;
93 virtual void EndFrame() = 0;
94
95 public:
99 virtual Image* CreateImage(void* data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped = false) = 0;
102 virtual void DestroyImageAtEnd(Image* img, DeviceScope scope, const std::source_location& loc = std::source_location::current()) = 0;
103
104 public:
107
108 // ---- Window-context lifecycle ----
109
113 virtual IWindowContext* CreateWindowContext(void* nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) = 0;
115 virtual void DestroyWindowContext(IWindowContext* context) = 0;
116
117 public:
119 virtual ImageSet* GetImageSet() const = 0;
121 virtual ImageIndex RegisterImage(Image* image) = 0;
123 virtual void UnregisterImage(ImageIndex index) = 0;
124
128 virtual void PrepareFrame(StyleManager& styleManager, GradientManager& gradientManager, float elapsedTimeSecs) = 0;
129
132 virtual float GetLastFrameBuildSeconds() const { return 0.0f; }
133
134 };
135
136}
Definition gui_buffer.h:9
Definition gui_renderer.h:43
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:64
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 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:69
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:132
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:82
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:85
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: a few frames on for DeviceSco...
GUIRenderer * guiRenderer
Where the UI records its draw primitives.
Definition gui_graphics_context.h:64
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...
Text and icon registration, measurement, rendering and editing.
Definition gui_text_system.h:178
Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one,...
Definition gui_window_backend.h:105
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:44
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:40
A value, or the Error saying why there is none.
Definition gui_result.h:36
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:580
@ None
Definition gui_element_flags.h:19
Sampler
How an image is filtered and addressed when sampled.
Definition gui_image.h:27
ImageFormat
Pixel formats for GraphicsContext::CreateImage, 8 bits per channel.
Definition gui_image.h:13
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:37
DeviceScope
When a deferred GPU resource destruction runs: Frame once the frames that may use it are done,...
Definition gui_graphics_context.h:43
GraphicsAPI
The graphics API a backend presents with; window backends create their windows to match (SDL: SDL_WIN...
Definition gui_graphics_context.h:51
@ Frame
Definition gui_graphics_context.h:44
@ Application
Definition gui_graphics_context.h:45
@ Vulkan
Definition gui_graphics_context.h:53
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:14
@ 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:12
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
Memory functions a host gives the library, for the allocations that can be routed: Vulkan objects,...
Definition gui_allocation_hooks.h:15
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:933
Integer 2D vector.
Definition gui_base_types.h:19
Definition gui_base_types.h:75