TachyonUI 1.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

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.

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

◆ TakeContentChanged()

bool tachyon::GraphicsContext::TakeContentChanged ( )
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.

◆ GetAPI()

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

◆ GetDeviceName()

virtual std::string_view tachyon::GraphicsContext::GetDeviceName ( ) const
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.

◆ 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.

◆ SetImageSlotCount()

virtual void tachyon::GraphicsContext::SetImageSlotCount ( uint32_t )
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.

◆ GetImageSlotCount()

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

◆ SetGpuPreference()

virtual void tachyon::GraphicsContext::SetGpuPreference ( std::string_view )
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.

◆ 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, and 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ UpdateImageRows()

virtual bool tachyon::GraphicsContext::UpdateImageRows ( Image * ,
uint32_t ,
uint32_t ,
const void *  )
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.

◆ 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: 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.

◆ 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, and tachyon::vulkan::VulkanGraphicsContext.

◆ GetImageSet()

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

◆ RegisterImage()

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

◆ UnregisterImage()

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

◆ RenderScene()

virtual ImageIndex tachyon::GraphicsContext::RenderScene ( ID ,
ID ,
uint2 ,
color4f ,
std::function< void(const ScenePayload &scene)>  )
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.

◆ 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::d3d12::D3D12GraphicsContext, tachyon::metal::MetalGraphicsContext, tachyon::NullGraphicsContext, tachyon::sdlgpu::SDLGPUGraphicsContext, 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.

◆ MarkContentChanged()

void tachyon::GraphicsContext::MarkContentChanged ( )
inlineprotected

For backends: see TakeContentChanged.

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: