TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::NullGraphicsContext Class Reference

A graphics backend that draws nothing: the UI is built, laid out and recorded as usual, but no GPU is used and windows stay empty. More...

#include <gui_core/graphics/null/gui_null_graphics_context.h>

Inheritance diagram for tachyon::NullGraphicsContext:

Public Member Functions

 NullGraphicsContext ()
 ~NullGraphicsContext () override
GraphicsAPI GetAPI () const override
 The API it presents with; window backends make their windows for it.
void SetAllocationHooks (const AllocationHooks &) override
 Host memory functions for the graphics API's allocations. Call before Initialize.
Result< void > Initialize (IWindowBackend *windowBackend) override
 Brings the device up; GUIApplication::Initialize calls it once, before any window context.
void Cleanup () override
 Waits for the GPU and destroys what the backend made, the renderer included.
void BeginFrame () override
 Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough).
void EndFrame () override
 Ends the UI build, before the uploads and the window contexts' recording.
Image * CreateImage (void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false) override
 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.
void DestroyImageAtEnd (Image *img, DeviceScope scope, const std::source_location &loc=std::source_location::current()) override
 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.
TextAtlasManager * CreateTextAtlasManager () override
 A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
IWindowContext * CreateWindowContext (void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) override
 Makes the context that renders an OS window: nativeWindowHandle comes from IWindowBackend::GetNativeHandle, size is in pixels and onGui builds the window's UI.
void DestroyWindowContext (IWindowContext *context) override
 Waits for the context's GPU work and destroys it now; its native window must still exist.
ImageSet * GetImageSet () const override
 The images the shaders sample, by ImageIndex.
ImageIndex RegisterImage (Image *image) override
 Adds the image to the image set; elements draw it by the returned index.
void UnregisterImage (ImageIndex index) override
 Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).
void PrepareFrame (StyleManager &styleManager, GradientManager &gradientManager, float) override
 Nothing to upload: takes the style and gradient changes, as a GPU backend's upload does.
uint64_t RecordedFrames (ID window) const
 How many frames the window was recorded in (RecordWindowFrame), for tests.
Public Member Functions inherited from tachyon::GraphicsContext
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 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 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 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 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 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 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.

Additional Inherited Members

Public Attributes inherited from tachyon::GraphicsContext
GUIRenderer * guiRenderer = nullptr
 Where the UI records its draw primitives.
Protected Member Functions inherited from tachyon::GraphicsContext
void MarkContentChanged ()
 For backends: see TakeContentChanged.

Detailed Description

A graphics backend that draws nothing: the UI is built, laid out and recorded as usual, but no GPU is used and windows stay empty.

For headless runs and tests, and as the minimal example of a backend.

Constructor & Destructor Documentation

◆ NullGraphicsContext()

tachyon::NullGraphicsContext::NullGraphicsContext ( )

◆ ~NullGraphicsContext()

tachyon::NullGraphicsContext::~NullGraphicsContext ( )
override

Member Function Documentation

◆ GetAPI()

GraphicsAPI tachyon::NullGraphicsContext::GetAPI ( ) const
inlineoverridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ SetAllocationHooks()

void tachyon::NullGraphicsContext::SetAllocationHooks ( const AllocationHooks & hooks)
inlineoverridevirtual

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

Implements tachyon::GraphicsContext.

◆ Initialize()

Result< void > tachyon::NullGraphicsContext::Initialize ( IWindowBackend * windowBackend)
overridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ Cleanup()

void tachyon::NullGraphicsContext::Cleanup ( )
overridevirtual

Waits for the GPU and destroys what the backend made, the renderer included.

The window contexts are destroyed before it.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ BeginFrame()

void tachyon::NullGraphicsContext::BeginFrame ( )
overridevirtual

Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough).

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ EndFrame()

void tachyon::NullGraphicsContext::EndFrame ( )
inlineoverridevirtual

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

Implements tachyon::GraphicsContext.

◆ CreateImage()

Image * tachyon::NullGraphicsContext::CreateImage ( void * data,
uint2 size,
ImageFormat format,
Sampler sampler,
bool mipmapped = false )
overridevirtual

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.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ DestroyImageAtEnd()

void tachyon::NullGraphicsContext::DestroyImageAtEnd ( Image * img,
DeviceScope scope,
const std::source_location & loc = std::source_location::current() )
overridevirtual

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.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ CreateTextAtlasManager()

TextAtlasManager * tachyon::NullGraphicsContext::CreateTextAtlasManager ( )
overridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ CreateWindowContext()

IWindowContext * tachyon::NullGraphicsContext::CreateWindowContext ( void * nativeWindowHandle,
OSWindowHandle osHandle,
ID id,
int2 size,
WindowFlags windowFlags,
OnGuiFunc onGui )
overridevirtual

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.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ DestroyWindowContext()

void tachyon::NullGraphicsContext::DestroyWindowContext ( IWindowContext * context)
overridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ GetImageSet()

ImageSet * tachyon::NullGraphicsContext::GetImageSet ( ) const
overridevirtual

The images the shaders sample, by ImageIndex.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ RegisterImage()

ImageIndex tachyon::NullGraphicsContext::RegisterImage ( Image * image)
overridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ UnregisterImage()

void tachyon::NullGraphicsContext::UnregisterImage ( ImageIndex index)
overridevirtual

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

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ PrepareFrame()

void tachyon::NullGraphicsContext::PrepareFrame ( StyleManager & styleManager,
GradientManager & gradientManager,
float  )
overridevirtual

Nothing to upload: takes the style and gradient changes, as a GPU backend's upload does.

Implements tachyon::GraphicsContext.

Reimplemented in tachyon::sdlgpu::SDLGPUGraphicsContext.

◆ RecordedFrames()

uint64_t tachyon::NullGraphicsContext::RecordedFrames ( ID window) const

How many frames the window was recorded in (RecordWindowFrame), for tests.


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