|
TachyonUI 1.1.0
High-performance UI for building tools.
|
A graphics backend: the device, the window contexts that render the GUI's windows, and the images and text atlases they draw with. More...
#include <gui_core/graphics/gui_graphics_context.h>
Public Member Functions | |
| bool | TakeContentChanged () |
| True when something drawn changed since the last call without a draw changing: an image registered or unregistered (a slot reused shows other pixels), or a scene rendered. | |
| GraphicsContext ()=default | |
| virtual | ~GraphicsContext () |
| virtual GraphicsAPI | GetAPI () const =0 |
| The API it presents with; window backends make their windows for it. | |
| virtual std::string_view | GetDeviceName () const |
| The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize and for a backend without a device. | |
| virtual void | SetAllocationHooks (const AllocationHooks &hooks)=0 |
| Host memory functions for the graphics API's allocations. Call before Initialize. | |
| virtual void | SetImageSlotCount (uint32_t) |
| How many images can be registered at once (fonts, icons, gradients and the app's own share them). | |
| virtual uint32_t | GetImageSlotCount () const |
| How many images can be registered at once; 0 when the backend doesn't say. | |
| virtual void | SetGpuPreference (std::string_view) |
| Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"), the GPU's number in the log's list of detected GPUs, or part of its name ("radeon"); see ChooseGpu. | |
| virtual Result< void > | Initialize (IWindowBackend *windowBackend)=0 |
| Brings the device up; GUIApplication::Initialize calls it once, before any window context. | |
| virtual bool | DeviceLost () const |
| True once the GPU device is lost; RecreateDevice then makes a new one. | |
| virtual Result< void > | RecreateDevice (IWindowBackend *) |
| Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are the caller's to make again). | |
| virtual void | Cleanup ()=0 |
| Waits for the GPU and destroys what the backend made, the renderer included. | |
| virtual void | BeginFrame ()=0 |
| Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough). | |
| virtual void | EndFrame ()=0 |
| Ends the UI build, before the uploads and the window contexts' recording. | |
| 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 image); mipmapped generates its mip levels. | |
| virtual bool | UpdateImageRows (Image *, uint32_t, uint32_t, const void *) |
| Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightly packed in its format, the image's width each. | |
| 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 it has finished the frames that may have drawn with it, however many frames draw nothing meanwhile; for DeviceScope::Application at Cleanup. | |
| virtual TextAtlasManager * | CreateTextAtlasManager ()=0 |
| A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup. | |
| 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::GetNativeHandle, size is in pixels and onGui builds the window's UI. | |
| virtual void | DestroyWindowContext (IWindowContext *context)=0 |
| Waits for the context's GPU work and destroys it now; its native window must still exist. | |
| virtual ImageSet * | GetImageSet () const =0 |
| The images the shaders sample, by ImageIndex. | |
| virtual ImageIndex | RegisterImage (Image *image)=0 |
| Adds the image to the image set; elements draw it by the returned index. | |
| virtual void | UnregisterImage (ImageIndex index)=0 |
| Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it). | |
| 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, kept for key while it's asked for every frame and made again when the size changes. | |
| 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 window contexts record. | |
| virtual float | GetLastFrameBuildSeconds () const |
| Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before the next, so without the vsync wait. | |
Public Attributes | |
| GUIRenderer * | guiRenderer = nullptr |
| Where the UI records its draw primitives. | |
Protected Member Functions | |
| void | MarkContentChanged () |
| For backends: see TakeContentChanged. | |
A graphics backend: the device, the window contexts that render the GUI's windows, and the images and text atlases they draw with.
GUIApplication::SetGraphicsBackend sets one; VulkanGraphicsContext is the default, NullGraphicsContext draws nothing.
|
default |
|
inlinevirtual |
|
inline |
True when something drawn changed since the last call without a draw changing: an image registered or unregistered (a slot reused shows other pixels), or a scene rendered.
Clears it.
|
pure virtual |
The API it presents with; window backends make their windows for it.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize and for a backend without a device.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Host memory functions for the graphics API's allocations. Call before Initialize.
Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
How many images can be registered at once (fonts, icons, gradients and the app's own share them).
Call before Initialize; the backend may hold fewer when the device does (GetImageSlotCount says). The default does nothing.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
How many images can be registered at once; 0 when the backend doesn't say.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"), the GPU's number in the log's list of detected GPUs, or part of its name ("radeon"); see ChooseGpu.
Empty, the default, leaves it to the backend (a discrete GPU first). The TACHYON_GPU environment variable takes its place when set. Call before Initialize. The default does nothing.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Brings the device up; GUIApplication::Initialize calls it once, before any window context.
It may make windows with the backend (Vulkan: a hidden one, to pick a GPU that can present to it).
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
True once the GPU device is lost; RecreateDevice then makes a new one.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are the caller's to make again).
The default fails with ErrorCode::Unsupported.
Reimplemented in tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Waits for the GPU and destroys what the backend made, the renderer included.
The window contexts are destroyed before it.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough).
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Ends the UI build, before the uploads and the window contexts' recording.
Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Makes an image from size.x x size.y tightly packed pixels of format (Vulkan: data null for a cleared image); mipmapped generates its mip levels.
Doesn't wait for the GPU: the upload goes with the next frame. RegisterImage makes it drawable.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightly packed in its format, the image's width each.
As CreateImage's upload, it doesn't wait for the GPU and goes with the next frame, ahead of its draws; the frames already sent draw what they had. False when the backend can't, and the caller makes the image again instead (the default).
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Destroys the image and deletes the object once the GPU is done with it: for DeviceScope::Frame once it has finished the frames that may have drawn with it, however many frames draw nothing meanwhile; for DeviceScope::Application at Cleanup.
Unregister it first (UnregisterImage): no frame may draw with it after this. Any thread. loc is for diagnostics.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Makes the context that renders an OS window: nativeWindowHandle comes from IWindowBackend::GetNativeHandle, size is in pixels and onGui builds the window's UI.
nullptr on failure. Destroy it with DestroyWindowContext.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Waits for the context's GPU work and destroys it now; its native window must still exist.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
The images the shaders sample, by ImageIndex.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Adds the image to the image set; elements draw it by the returned index.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
pure virtual |
Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
An image the app draws a scene into (a 3D viewport), size pixels with a depth buffer, kept for key while it's asked for every frame and made again when the size changes.
record draws it, in window's frame before the UI: it gets the backend's recording state (ScenePayload; Vulkan: a VulkanSceneRender, Direct3D 12: a D3D12SceneRender), the image cleared to clear and the rendering begun. Call it while the UI is built. Invalid when the backend can't.
Reimplemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, and tachyon::sdlgpu::SDLGPUGraphicsContext.
|
pure virtual |
Uploads the styles and gradient pages for this frame's draws, after the UI build and before the window contexts record.
elapsedTimeSecs: the frame clock's time, for shader animation.
Implemented in tachyon::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.
|
inlinevirtual |
Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before the next, so without the vsync wait.
0 for backends that don't measure it.
Reimplemented in tachyon::vulkan::VulkanGraphicsContext.
|
inlineprotected |
For backends: see TakeContentChanged.
| GUIRenderer* tachyon::GraphicsContext::guiRenderer = nullptr |
Where the UI records its draw primitives.
Owned by the context: made in its constructor, deleted by Cleanup.