GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
GraphicalUserInterface.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_IMGUI_GRAPHICAL_USER_INTERFACE_HPP
5#define GREM_IMGUI_GRAPHICAL_USER_INTERFACE_HPP
6
8
16
17struct ImGuiContext; // Forward declaration, to avoid including imgui.h.
18struct ImGuiViewport; // Forward declaration, to avoid including imgui.h.
19struct ImDrawData; // Forward declaration, to avoid including imgui.h.
20
21namespace grem {
22class Filesystem; // Forward declaration, to avoid including Filesystem.hpp.
23} // namespace grem
24
25namespace grem::events {
26struct Event; // Forward declaration, to avoid including Event.hpp.
27class EventPump; // Forward declaration, to avoid including EventPump.hpp.
28} // namespace grem::events
29
30namespace grem::graphics {
31class Texture; // Forward declaration, to avoid including Texture.hpp.
32class Window; // Forward declaration, to avoid including Window.hpp.
33class Device; // Forward declaration, to avoid including Device.hpp.
34class Swapchain; // Forward declaration, to avoid including Swapchain.hpp.
35class Renderer2D; // Forward declaration, to avoid including Renderer2D.hpp.
36class RenderPass; // Forward declaration, to avoid including RenderPass.hpp.
37class Bootstrapper; // Forward declaration.
38} // namespace grem::graphics
39
40namespace grem::imgui {
41
53 [[nodiscard]] constexpr bool operator==(const GraphicalUserInterfaceOptions& other) const = default;
54};
55
60public:
64 using TextureID = uint64_t;
65
76
82 using Index = uint16_t;
83
86
89
95
101
104
107
110
115
120
123
126
129
132
135
144
155 [[nodiscard]] GREM_API(imgui) static graphics::Window& getWindow(ImGuiViewport& viewport);
156
167 [[nodiscard]] GREM_API(imgui) static graphics::Swapchain& getSwapchain(ImGuiViewport& viewport);
168
187 GREM_API(imgui)
188 GraphicalUserInterface(Filesystem& filesystem, events::EventPump& eventPump, graphics::Window& window, graphics::Device& device, graphics::Swapchain& swapchain,
189 graphics::Renderer2D& renderer2D, const GraphicalUserInterfaceOptions& options = {});
190
211 GREM_API(imgui)
212 GraphicalUserInterface(Filesystem& filesystem, events::EventPump& eventPump, graphics::Window& window, graphics::Device& device, graphics::Swapchain& swapchain,
213 graphics::Renderer2D& renderer2D, ImGuiContext& context, const GraphicalUserInterfaceOptions& options = {});
214
217
220
223
226
229
240 GREM_API(imgui)
241 bool handleEvent(const events::Event& event);
242
261 GREM_API(imgui)
262 void update(Duration deltaTime);
263
285 GREM_API(imgui)
286 void drawFrame(graphics::RenderPass& renderPass, const ImDrawData& drawData, SharedPointer<graphics::ShaderPipelineImplementation> shaderPipelineOverrideHandle = {});
287
308 void drawFrame(graphics::RenderPass& renderPass, const ImDrawData& drawData, const ShaderPipeline& shaderPipelineOverride) {
309 drawFrame(renderPass, drawData, shaderPipelineOverride.lock());
310 }
311
326 [[nodiscard]] GREM_API(imgui) TextureID getTextureID(const graphics::Texture& texture);
327
334 [[nodiscard]] GREM_API(imgui) ImGuiContext* getContext() const noexcept;
335
341 [[nodiscard]] GREM_API(imgui) const VertexShader& getDefaultVertexShader();
342
348 [[nodiscard]] GREM_API(imgui) const FragmentShader& getPlainFragmentShader();
349
355 [[nodiscard]] GREM_API(imgui) const ShaderPipeline& getPlainShaderPipeline();
356
357private:
358 friend graphics::Bootstrapper;
359
360 class Implementation;
361
362 UniquePointer<Implementation> implementation;
363};
364
365} // namespace grem::imgui
366
367#endif
Base interface for a filesystem.
Definition Filesystem.hpp:25
Definition SharedPointer.hpp:65
Nullable RAII data pointer with exclusive ownership of an object that is automatically destroyed on p...
Definition UniquePointer.hpp:77
Persistent system for polling Event data and other user input from the host environment on demand.
Definition EventPump.hpp:78
Persistent system managing the rendering context of a Window.
Definition Device.hpp:68
Compiled GPU fragment shader stage.
Definition shaders.hpp:1274
Generic abstraction of a GPU vertex array object and its associated buffers.
Definition Mesh.hpp:209
Backend-specific implementation of RenderPass.
Definition RenderPass.hpp:38
Persistent system that provides 2D rendering capabilities.
Definition Renderer2D.hpp:46
Linked GPU shader pipeline.
Definition shaders.hpp:1508
Render target texture holding a chain of images leading to a window to be presented to.
Definition Swapchain.hpp:61
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition Texture.hpp:700
GPU memory buffer containing a fixed-size struct of uniform parameters to be read by a shader program...
Definition buffers.hpp:426
Compiled GPU vertex shader stage.
Definition shaders.hpp:1060
Graphical window that can be rendered to.
Definition Window.hpp:131
uint16_t Index
Data type used in the index buffer of a GUI.
Definition GraphicalUserInterface.hpp:82
static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS
Default GUI vertex shader constants.
Definition GraphicalUserInterface.hpp:131
ImGuiContext * getContext() const noexcept
Get the underlying Dear ImGui context.
void drawFrame(graphics::RenderPass &renderPass, const ImDrawData &drawData, SharedPointer< graphics::ShaderPipelineImplementation > shaderPipelineOverrideHandle={})
Push the draw commands of a GUI frame to a render pass.
graphics::UniformBuffer< TextureParameters, "GUITexture"> TextureBuffer
Shader buffer for GUI texture parameters.
Definition GraphicalUserInterface.hpp:122
void drawFrame(graphics::RenderPass &renderPass, const ImDrawData &drawData, const ShaderPipeline &shaderPipelineOverride)
Push the draw commands of a GUI frame to a render pass.
Definition GraphicalUserInterface.hpp:308
GraphicalUserInterface & operator=(GraphicalUserInterface &&)=delete
Moving a GUI is not allowed.
const VertexShader & getDefaultVertexShader()
Get the default GUI vertex shader.
graphics::UniformBuffer< ViewParameters, "GUIViewParameters"> ViewParameterBuffer
Shader buffer for GUI view parameters.
Definition GraphicalUserInterface.hpp:103
const ShaderPipeline & getPlainShaderPipeline()
Get the default plain GUI shader pipeline.
graphics::Mesh< Vertex, Index > Mesh
Mesh type of the GUI.
Definition GraphicalUserInterface.hpp:85
static graphics::Window & getWindow(ImGuiViewport &viewport)
Get the window associated with an ImGui viewport.
static constexpr FragmentShaderConstants DEFAULT_FRAGMENT_SHADER_CONSTANTS
Default GUI fragment shader constants.
Definition GraphicalUserInterface.hpp:134
TextureID getTextureID(const graphics::Texture &texture)
Create a texture ID for a texture that will be valid for rendering in the GUI until at least the next...
GraphicalUserInterface & operator=(const GraphicalUserInterface &)=delete
Copying a GUI is not allowed.
graphics::VertexShader< Mesh, VertexShaderConstants, VertexShaderOutputs, ViewParameterBuffer > VertexShader
Default vertex shader for drawing a GUI.
Definition GraphicalUserInterface.hpp:106
GraphicalUserInterface(GraphicalUserInterface &&)=delete
Moving a GUI is not allowed.
static graphics::Swapchain & getSwapchain(ImGuiViewport &viewport)
Get the swapchain associated with an ImGui viewport.
GraphicalUserInterface(const GraphicalUserInterface &)=delete
Copying a GUI is not allowed.
static constexpr graphics::ShaderPipelineOptions DEFAULT_SHADER_PIPELINE_OPTIONS
Default GUI graphics pipeline configuration.
Definition GraphicalUserInterface.hpp:137
void update(Duration deltaTime)
Prepare for a new GUI frame.
const FragmentShader & getPlainFragmentShader()
Get the default plain GUI fragment shader.
uint64_t TextureID
Identifier for a texture used by the Dear ImGui backend.
Definition GraphicalUserInterface.hpp:64
graphics::ShaderPipeline< Mesh > ShaderPipeline
Shader pipeline for drawing a GUI.
Definition GraphicalUserInterface.hpp:128
GraphicalUserInterface(Filesystem &filesystem, events::EventPump &eventPump, graphics::Window &window, graphics::Device &device, graphics::Swapchain &swapchain, graphics::Renderer2D &renderer2D, const GraphicalUserInterfaceOptions &options={})
Construct a graphical user interface.
graphics::FragmentShader< Mesh, VertexShaderOutputs, FragmentShaderConstants, FragmentShaderOutputs, ViewParameterBuffer, TextureBuffer > FragmentShader
Default fragment shader for drawing a GUI.
Definition GraphicalUserInterface.hpp:125
bool handleEvent(const events::Event &event)
Handle an event from an events::EventPump in the GUI.
Definition controller.hpp:11
Definition buffer_layouts.hpp:20
@ TRIANGLES
Each consecutive triple of points forms an individual filled triangle.
Definition shaders.hpp:295
@ NONE
Ignore the depth buffer.
Definition shaders.hpp:59
@ NONE
Ignore facing, don't cull primitives based on their winding order.
Definition shaders.hpp:319
@ CLOCKWISE
Consider faces with clockwise winding order to be front-facing.
Definition shaders.hpp:345
Definition Error.hpp:11
Definition aliases.hpp:9
Clock::duration Duration
Definition Clock.hpp:25
vec< 4, float > vec4
Definition math.hpp:440
vec< 2, float > vec2
Definition math.hpp:438
vec< 4, u8norm > u8vec4norm
Definition math.hpp:464
Data structure containing information about an event.
Definition Event.hpp:370
static const BlendState ALPHA_BLENDING_STRAIGHT
Blend state to use for straight alpha blending using the standard "over" operator.
Definition shaders.hpp:390
Configuration of a graphics pipeline.
Definition shaders.hpp:428
Reference to a sampler2D Texture that may be used as a parameter value type in a shader-read buffer.
Definition ParameterDescription.hpp:131
Configuration options for a GraphicalUserInterface.
Definition GraphicalUserInterface.hpp:45
constexpr bool operator==(const GraphicalUserInterfaceOptions &other) const =default
Compare these options to another set of options for equality.
Struct of GUI fragment shader constants.
Definition GraphicalUserInterface.hpp:109
Struct of fields output by a GUI fragment shader.
Definition GraphicalUserInterface.hpp:112
vec4 outputColor
Final fragment color.
Definition GraphicalUserInterface.hpp:113
Struct of shader parameters representing the texture of a GUI.
Definition GraphicalUserInterface.hpp:117
graphics::sampler2D mainTexture
Texture to use when rendering the GUI.
Definition GraphicalUserInterface.hpp:118
Struct of GUI vertex shader constants.
Definition GraphicalUserInterface.hpp:88
Struct of fields output by a GUI vertex shader.
Definition GraphicalUserInterface.hpp:91
vec2 fragmentTextureCoordinates
Texture coordinates of the vertex.
Definition GraphicalUserInterface.hpp:92
vec4 fragmentColor
Linear tint color of the vertex.
Definition GraphicalUserInterface.hpp:93
Data layout for the attributes of a single vertex of a GUI.
Definition GraphicalUserInterface.hpp:71
vec2 vertexPosition
Position relative to the top left of the viewport, in pixels.
Definition GraphicalUserInterface.hpp:72
vec2 vertexTextureCoordinates
Texture UV coordinates that map to this vertex.
Definition GraphicalUserInterface.hpp:73
u8vec4norm vertexColor
Tint color of this vertex, sRGB-encoded.
Definition GraphicalUserInterface.hpp:74
Struct of shader parameters representing the view of a GUI.
Definition GraphicalUserInterface.hpp:97
vec2 guiOffset
Offset of the view.
Definition GraphicalUserInterface.hpp:98
vec2 guiScale
Scale of the view.
Definition GraphicalUserInterface.hpp:99