ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
SDL3Backend.hpp
Go to the documentation of this file.
1#pragma once
2
3// @backend_name SDL3 + OpenGL 3.3
4// @backend_target ZenitUI::SDL3Backend
5// @backend_role Desktop GPU backend with HiDPI (SDL3 + batched GL 3.3 Core)
6// @backend_features Effects, NestedTargets, TargetSubRect
7// @backend_classes ZenitUI::SDL3Backend ZenitUI::SDL3Platform ZenitUI::SDL3Renderer ZenitUI::SDL3AssetProvider
8
14
15#include "Backend.hpp"
16#include "SDL3Platform.hpp"
17#include "SDL3Renderer.hpp"
18#include "SDL3AssetProvider.hpp"
19
20#include <cstdint>
21#include <memory>
22
23struct SDL_Window;
24struct SDL_GLContextState;
25using SDL_GLContext = SDL_GLContextState *;
26
27namespace ZenitUI
28{
32
39 class SDL3Backend final : public IBackend
40 {
41 public:
42 SDL3Backend() = default;
43 ~SDL3Backend() override { shutdown(); }
44
45 SDL3Backend(const SDL3Backend &) = delete;
46 SDL3Backend &operator=(const SDL3Backend &) = delete;
47
48 bool init(const WindowConfig &config) override;
49 void shutdown() override;
50 bool pollFrame() override;
51 float deltaTime() const override { return deltaTime_; }
52 void beginDraw(Color clearColor) override;
53 void endDraw() override;
54 std::string_view name() const override { return "SDL3 + OpenGL 3.3"; }
55
56 IPlatform &platform() override { return *platform_; }
57 IRenderer &renderer() override { return *renderer_; }
58 IAssetProvider &assets() override { return *assets_; }
59
60 private:
61 SDL_Window *window_{nullptr};
62 SDL_GLContext glContext_{nullptr};
63 std::unique_ptr<SDL3Platform> platform_;
64 std::unique_ptr<SDL3Renderer> renderer_;
65 std::unique_ptr<SDL3AssetProvider> assets_;
66 uint64_t lastTicksNs_{0};
67 float deltaTime_{1.0f / 60.0f};
68 bool running_{false};
69 bool initialized_{false};
70 };
71
73} // namespace ZenitUI
Unified host interface (IBackend) for backend-agnostic ZenitUI apps.
Abstract name-based lookup and runtime lifecycle for textures and shaders.
Definition UIContext.hpp:449
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
Abstract windowing, timing, input, and clipboard backend.
Definition UIContext.hpp:383
Abstract 2D rendering backend.
Definition UIContext.hpp:106
void beginDraw(Color clearColor) override
Begin presenting a frame and clear the main framebuffer to clearColor.
std::string_view name() const override
Short human-readable backend identifier (e.g.
Definition SDL3Backend.hpp:54
IAssetProvider & assets() override
Access the underlying asset provider.
Definition SDL3Backend.hpp:58
float deltaTime() const override
Return the elapsed time in seconds since the previous pollFrame().
Definition SDL3Backend.hpp:51
bool pollFrame() override
Pump OS events for the next frame; returns false when the window should close.
void endDraw() override
Finish the frame and swap buffers.
IPlatform & platform() override
Access the underlying platform adapter.
Definition SDL3Backend.hpp:56
bool init(const WindowConfig &config) override
Create the window and graphics context, and bind subsystems to UIContext.
void shutdown() override
Release pooled targets, unbind UIContext, and tear down the window/context.
IRenderer & renderer() override
Access the underlying renderer adapter.
Definition SDL3Backend.hpp:57
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Backend-agnostic window and graphics-context creation parameters.
Definition Backend.hpp:31