TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::GraphicsContext Class Referenceabstract

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>

Inheritance diagram for tachyon::GraphicsContext:

Public Member Functions

 GraphicsContext ()=default
virtual ~GraphicsContext ()
virtual GraphicsAPI GetAPI () const =0
 The API it presents with; window backends make their windows for it.
virtual void SetAllocationHooks (const AllocationHooks &hooks)=0
 Host memory functions for the graphics API's allocations. Call before Initialize.
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 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 DeviceScope::Frame, at Cleanup for DeviceScope::Application.
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 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ GraphicsContext()

tachyon::GraphicsContext::GraphicsContext ( )
default

◆ ~GraphicsContext()

virtual tachyon::GraphicsContext::~GraphicsContext ( )
inlinevirtual

Member Function Documentation

◆ GetAPI()

virtual GraphicsAPI tachyon::GraphicsContext::GetAPI ( ) const
pure virtual

The API it presents with; window backends make their windows for it.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ SetAllocationHooks()

virtual void tachyon::GraphicsContext::SetAllocationHooks ( const AllocationHooks & hooks)
pure virtual

Host memory functions for the graphics API's allocations. Call before Initialize.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ Initialize()

virtual Result< void > tachyon::GraphicsContext::Initialize ( IWindowBackend * windowBackend)
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ DeviceLost()

virtual bool tachyon::GraphicsContext::DeviceLost ( ) const
inlinevirtual

True once the GPU device is lost; RecreateDevice then makes a new one.

Reimplemented in tachyon::vulkan::VulkanGraphicsContext.

◆ RecreateDevice()

virtual Result< void > tachyon::GraphicsContext::RecreateDevice ( IWindowBackend * )
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.

◆ Cleanup()

virtual void tachyon::GraphicsContext::Cleanup ( )
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ BeginFrame()

virtual void tachyon::GraphicsContext::BeginFrame ( )
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ EndFrame()

virtual void tachyon::GraphicsContext::EndFrame ( )
pure virtual

Ends the UI build, before the uploads and the window contexts' recording.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ CreateImage()

virtual Image * tachyon::GraphicsContext::CreateImage ( void * data,
uint2 size,
ImageFormat format,
Sampler sampler,
bool mipmapped = false )
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ DestroyImageAtEnd()

virtual void tachyon::GraphicsContext::DestroyImageAtEnd ( Image * img,
DeviceScope scope,
const std::source_location & loc = std::source_location::current() )
pure virtual

Destroys the image and deletes the object once the GPU is done with it: a few frames on for DeviceScope::Frame, at Cleanup for DeviceScope::Application.

loc is for diagnostics.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ CreateTextAtlasManager()

virtual TextAtlasManager * tachyon::GraphicsContext::CreateTextAtlasManager ( )
pure virtual

A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ CreateWindowContext()

virtual IWindowContext * tachyon::GraphicsContext::CreateWindowContext ( void * nativeWindowHandle,
OSWindowHandle osHandle,
ID id,
int2 size,
WindowFlags windowFlags,
OnGuiFunc onGui )
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ DestroyWindowContext()

virtual void tachyon::GraphicsContext::DestroyWindowContext ( IWindowContext * context)
pure virtual

Waits for the context's GPU work and destroys it now; its native window must still exist.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ GetImageSet()

virtual ImageSet * tachyon::GraphicsContext::GetImageSet ( ) const
pure virtual

The images the shaders sample, by ImageIndex.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ RegisterImage()

virtual ImageIndex tachyon::GraphicsContext::RegisterImage ( Image * image)
pure virtual

Adds the image to the image set; elements draw it by the returned index.

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ UnregisterImage()

virtual void tachyon::GraphicsContext::UnregisterImage ( ImageIndex index)
pure virtual

Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).

Implemented in tachyon::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ PrepareFrame()

virtual void tachyon::GraphicsContext::PrepareFrame ( StyleManager & styleManager,
GradientManager & gradientManager,
float elapsedTimeSecs )
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::NullGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ GetLastFrameBuildSeconds()

virtual float tachyon::GraphicsContext::GetLastFrameBuildSeconds ( ) const
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.

Member Data Documentation

◆ guiRenderer

GUIRenderer* tachyon::GraphicsContext::guiRenderer = nullptr

Where the UI records its draw primitives.

Owned by the context: made in its constructor, deleted by Cleanup.


The documentation for this class was generated from the following file: