9#include <SDL3/SDL_gpu.h>
10#include <SDL3/SDL_properties.h>
36 SDL_GPUTextureFormat
colorFormat = SDL_GPU_TEXTUREFORMAT_INVALID;
37 SDL_GPUTextureFormat
depthFormat = SDL_GPU_TEXTUREFORMAT_INVALID;
137 std::function<
void(
const ScenePayload& scene)> record)
override;
166 std::unique_ptr<Impl> m_impl;
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:65
Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one,...
Definition gui_window_backend.h:112
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:106
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
A value, or the Error saying why there is none.
Definition gui_result.h:36
What GraphicsContext::RenderScene's record gets: the backend's recording state, as the struct of the ...
Definition gui_graphics_api.h:41
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
~SDLGPUGraphicsContext() override
void RePrepareFrame()
PrepareFrame again with its last arguments: a live resize's redraw changes styles.
void SetDriver(std::string_view driver)
The driver SDL renders with: "vulkan", "direct3d12" or "metal"; empty, SDL's choice.
void SetGpuPreference(std::string_view preference) override
"integrated" or "cpu" ask SDL for its low-power GPU; SDL picks among the others.
void SetExternalDevice(SDL_GPUDevice *device)
Render on the host's device instead of making one.
void Cleanup() override
Waits for the GPU and destroys what the backend made, the renderer included.
ImageIndex RenderScene(ID key, ID window, uint2 size, color4f clear, std::function< void(const ScenePayload &scene)> record) override
The scene's color texture (R8G8B8A8_UNORM, sampled with Sampler::LinearClampToEdge) and depth (D32_FL...
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 i...
void SetDebugConfig(const DebugConfig &config)
Call before Initialize.
Image * CreateImage(void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false) override
R8G8B8 is widened to R8G8B8A8, and R8 and R8G8 in sRGB too (SDL GPU has no such formats).
std::string_view GetDriver() const
The driver in use, after Initialize.
uint32_t GetImageSlotCount() const override
How many images can be registered at once; 0 when the backend doesn't say.
void SetImageSlotCount(uint32_t slots) override
4096 by default. Call before Initialize.
SDL_Window *(*)(OSWindowHandle window) WindowResolver
The SDL window of a window backend's window (OSWindowHandle): SDLWindowBackend sets it.
Definition sdlgpu_graphics_context.h:58
void SetWindowImageTarget(ID window, SDL_GPUTexture *texture, uint2 size)
The host texture a render-to-image window (WindowFlags::RenderToImage) is copied into each frame; nul...
Result< void > Initialize(IWindowBackend *windowBackend) override
Makes the device, on a driver that takes the shaders the GUI has (SPIR-V, DXIL) and,...
void UnregisterImage(ImageIndex index) override
A host's texture's slot (RegisterExternalImage) goes too; the texture stays the host's.
ImageIndex RegisterExternalImage(SDL_GPUTexture *texture, Sampler sampler)
A texture the host renders (a 3D viewport) in the image set, for the Image control or a primitive to ...
void BeginFrame() override
Lets go of the scenes no longer asked for.
ImageSet * GetImageSet() const override
The images the shaders sample, by ImageIndex.
Impl & Internal()
Library internal: the device and what the window contexts share.
Definition sdlgpu_graphics_context.h:163
void UpdateExternalImage(ImageIndex index, SDL_GPUTexture *texture, Sampler sampler)
Points an existing index at another texture, for example after a resize, under the same rules.
static bool CheckDeviceSupport(SDL_GPUDevice *device, std::string *problems=nullptr)
Whether device takes the GUI's shaders; what it lacks, one line each, in problems.
std::string_view GetDeviceName() const override
The GPU, and the driver SDL renders with: "NVIDIA GeForce RTX 4070 (vulkan)".
void PrepareFrame(StyleManager &styleManager, GradientManager &gradientManager, float elapsedTimeSecs) override
The gradient pages into the image set, the styles uploaded where they changed, and the images each st...
TextAtlasManager * CreateTextAtlasManager() override
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
void WaitIdle()
Waits until the GPU has done all work submitted so far.
ImageIndex RegisterImage(Image *image) override
Adds the image to the image set; elements draw it by the returned index.
static void ApplyDeviceRequirements(SDL_PropertiesID props)
Sets on props what the GUI's shaders need of a device a host makes with SDL_CreateGPUDeviceWithProper...
GraphicsAPI GetAPI() const override
The API it presents with; window backends make their windows for it.
Definition sdlgpu_graphics_context.h:82
bool UpdateImageRows(Image *image, uint32_t firstRow, uint32_t rowCount, const void *data) override
Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightl...
void DestroyWindowContext(IWindowContext *context) override
Waits for the context's GPU work and destroys it now; its native window must still exist.
void SetWindowResolver(WindowResolver resolver)
IWindowContext * CreateWindowContext(void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) override
An OS window is claimed for the device: SDL makes its swapchain.
DebugSeverity
How serious a message from SDL GPU's debug mode is.
Definition sdlgpu_graphics_context.h:44
Sampler
How an image is filtered and addressed when sampled.
Definition gui_image.h:89
ImageFormat
Pixel formats for GraphicsContext::CreateImage, 8 bits per channel.
Definition gui_image.h:75
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
DeviceScope
When a deferred GPU resource destruction runs: Frame once the GPU has finished the frames that may us...
Definition gui_graphics_context.h:44
std::function< void()> OnGuiFunc
Definition gui_base_types.h:13
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:14
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
Definition sdlgpu_device.h:37
GraphicsAPI
The graphics API a backend presents with; window backends create their windows to match (SDL: SDL_WIN...
Definition gui_graphics_api.h:14
@ SDLGPU
SDL3's GPU API, over Vulkan, Direct3D 12 or Metal as SDL picks.
Definition gui_graphics_api.h:18
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
Definition gui_base_types.h:394
Integer 2D vector.
Definition gui_base_types.h:18
Where SDL GPU's messages go.
Definition sdlgpu_graphics_context.h:49
void * userData
Definition sdlgpu_graphics_context.h:51
void(*) callback(DebugSeverity severity, const char *message, void *userData)
Definition sdlgpu_graphics_context.h:50
Definition sdlgpu_device.h:93
What GraphicsContext::RenderScene's record gets on SDL GPU (ScenePayload::As): the window frame's com...
Definition sdlgpu_graphics_context.h:29
uint2 extent
Definition sdlgpu_graphics_context.h:38
SDL_GPUCommandBuffer * commandBuffer
Definition sdlgpu_graphics_context.h:33
SDL_GPUDevice * device
Definition sdlgpu_graphics_context.h:32
SDL_GPUTextureFormat depthFormat
Definition sdlgpu_graphics_context.h:37
SDL_GPUTexture * colorTexture
Definition sdlgpu_graphics_context.h:34
SDL_GPUColorTargetInfo colorTarget
Definition sdlgpu_graphics_context.h:39
SDL_GPUTexture * depthTexture
Definition sdlgpu_graphics_context.h:35
SDL_GPUTextureFormat colorFormat
Definition sdlgpu_graphics_context.h:36
SDL_GPUDepthStencilTargetInfo depthTarget
Definition sdlgpu_graphics_context.h:40
static constexpr GraphicsAPI kAPI
Definition sdlgpu_graphics_context.h:30
Definition gui_base_types.h:74