GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::imgui::GraphicalUserInterface Class Reference

Persistent system that manages a platform+renderer backend for Dear ImGui. More...

#include <GREM/imgui/GraphicalUserInterface.hpp>

Classes

struct  Vertex
 Data layout for the attributes of a single vertex of a GUI. More...
struct  VertexShaderConstants
 Struct of GUI vertex shader constants. More...
struct  VertexShaderOutputs
 Struct of fields output by a GUI vertex shader. More...
struct  ViewParameters
 Struct of shader parameters representing the view of a GUI. More...
struct  FragmentShaderConstants
 Struct of GUI fragment shader constants. More...
struct  FragmentShaderOutputs
 Struct of fields output by a GUI fragment shader. More...
struct  TextureParameters
 Struct of shader parameters representing the texture of a GUI. More...

Public Types

using TextureID = uint64_t
 Identifier for a texture used by the Dear ImGui backend.
using Index = uint16_t
 Data type used in the index buffer of a GUI.
using Mesh = graphics::Mesh<Vertex, Index>
 Mesh type of the GUI.
using ViewParameterBuffer = graphics::UniformBuffer<ViewParameters, "GUIViewParameters">
 Shader buffer for GUI view parameters.
using VertexShader = graphics::VertexShader<Mesh, VertexShaderConstants, VertexShaderOutputs, ViewParameterBuffer>
 Default vertex shader for drawing a GUI.
using TextureBuffer = graphics::UniformBuffer<TextureParameters, "GUITexture">
 Shader buffer for GUI texture parameters.
using FragmentShader = graphics::FragmentShader<Mesh, VertexShaderOutputs, FragmentShaderConstants, FragmentShaderOutputs, ViewParameterBuffer, TextureBuffer>
 Default fragment shader for drawing a GUI.
using ShaderPipeline = graphics::ShaderPipeline<Mesh>
 Shader pipeline for drawing a GUI.

Public Member Functions

 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.
 GraphicalUserInterface (Filesystem &filesystem, events::EventPump &eventPump, graphics::Window &window, graphics::Device &device, graphics::Swapchain &swapchain, graphics::Renderer2D &renderer2D, ImGuiContext &context, const GraphicalUserInterfaceOptions &options={})
 Construct a graphical user interface for an existing Dear ImGui context.
 ~GraphicalUserInterface ()
 Destructor.
 GraphicalUserInterface (const GraphicalUserInterface &)=delete
 Copying a GUI is not allowed.
 GraphicalUserInterface (GraphicalUserInterface &&)=delete
 Moving a GUI is not allowed.
GraphicalUserInterface & operator= (const GraphicalUserInterface &)=delete
 Copying a GUI is not allowed.
GraphicalUserInterface & operator= (GraphicalUserInterface &&)=delete
 Moving a GUI is not allowed.
bool handleEvent (const events::Event &event)
 Handle an event from an events::EventPump in the GUI.
void update (Duration deltaTime)
 Prepare for a new GUI frame.
void drawFrame (graphics::RenderPass &renderPass, const ImDrawData &drawData, SharedPointer< graphics::ShaderPipelineImplementation > shaderPipelineOverrideHandle={})
 Push the draw commands of a GUI frame to a render pass.
void drawFrame (graphics::RenderPass &renderPass, const ImDrawData &drawData, const ShaderPipeline &shaderPipelineOverride)
 Push the draw commands of a GUI frame to a render pass.
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 call to update() after the texture has been destroyed, by extending the lifetime of the texture.
ImGuiContext * getContext () const noexcept
 Get the underlying Dear ImGui context.
const VertexShader & getDefaultVertexShader ()
 Get the default GUI vertex shader.
const FragmentShader & getPlainFragmentShader ()
 Get the default plain GUI fragment shader.
const ShaderPipeline & getPlainShaderPipeline ()
 Get the default plain GUI shader pipeline.

Static Public Member Functions

static graphics::Window & getWindow (ImGuiViewport &viewport)
 Get the window associated with an ImGui viewport.
static graphics::Swapchain & getSwapchain (ImGuiViewport &viewport)
 Get the swapchain associated with an ImGui viewport.

Static Public Attributes

static constexpr VertexShaderConstants DEFAULT_VERTEX_SHADER_CONSTANTS {}
 Default GUI vertex shader constants.
static constexpr FragmentShaderConstants DEFAULT_FRAGMENT_SHADER_CONSTANTS {}
 Default GUI fragment shader constants.
static constexpr graphics::ShaderPipelineOptions DEFAULT_SHADER_PIPELINE_OPTIONS
 Default GUI graphics pipeline configuration.

Detailed Description

Persistent system that manages a platform+renderer backend for Dear ImGui.

Member Typedef Documentation

◆ TextureID

Identifier for a texture used by the Dear ImGui backend.

◆ Index

Data type used in the index buffer of a GUI.

Meets the requirements of the grem::graphics::mesh_index concept.

◆ Mesh

◆ ViewParameterBuffer

Shader buffer for GUI view parameters.

◆ VertexShader

◆ TextureBuffer

Shader buffer for GUI texture parameters.

◆ FragmentShader

◆ ShaderPipeline

Constructor & Destructor Documentation

◆ GraphicalUserInterface() [1/4]

grem::imgui::GraphicalUserInterface::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.

Parameters
filesystemfilesystem to create the GUI for. Must outlive the GUI.
eventPumpevent pump to create the GUI for. Must outlive the GUI.
windowmain window to create the GUI for. Must outlive the GUI.
devicedevice to create the GUI for. Must be associated with the given window. Must outlive the GUI.
swapchainswapchain associated with the main window. Must be associated with the given window and device. Must outlive the GUI.
renderer2Drenderer to create the GUI for. Must be associated with the given device. Must outlive the GUI.
optionsinitial configuration of the graphical user interface, see GraphicalUserInterfaceOptions.
Exceptions
imgui::Erroron failure to initialize the GUI.
std::bad_allocon allocation failure.

◆ GraphicalUserInterface() [2/4]

grem::imgui::GraphicalUserInterface::GraphicalUserInterface ( Filesystem & filesystem,
events::EventPump & eventPump,
graphics::Window & window,
graphics::Device & device,
graphics::Swapchain & swapchain,
graphics::Renderer2D & renderer2D,
ImGuiContext & context,
const GraphicalUserInterfaceOptions & options = {} )

Construct a graphical user interface for an existing Dear ImGui context.

Parameters
filesystemfilesystem to create the GUI for. Must outlive the GUI.
eventPumpevent pump to create the GUI for. Must outlive the GUI.
windowmain window to create the GUI for. Must outlive the GUI.
devicedevice to create the GUI for. Must be associated with the given window. Must outlive the GUI.
swapchainswapchain associated with the main window. Must be associated with the given window and device. Must outlive the GUI.
renderer2Drenderer to create the GUI for. Must be associated with the given device. Must outlive the GUI.
contextDear ImGui context to use for this GUI. Must outlive the GUI.
optionsinitial configuration of the graphical user interface, see GraphicalUserInterfaceOptions.
Exceptions
imgui::Erroron failure to initialize the GUI.
std::bad_allocon allocation failure.

◆ ~GraphicalUserInterface()

grem::imgui::GraphicalUserInterface::~GraphicalUserInterface ( )

Destructor.

◆ GraphicalUserInterface() [3/4]

grem::imgui::GraphicalUserInterface::GraphicalUserInterface ( const GraphicalUserInterface & )
delete

Copying a GUI is not allowed.

◆ GraphicalUserInterface() [4/4]

grem::imgui::GraphicalUserInterface::GraphicalUserInterface ( GraphicalUserInterface && )
delete

Moving a GUI is not allowed.

Member Function Documentation

◆ getWindow()

graphics::Window & grem::imgui::GraphicalUserInterface::getWindow ( ImGuiViewport & viewport)
staticnodiscard

Get the window associated with an ImGui viewport.

Parameters
viewportImGui viewport to get the window of. Must be a viewport created from this GUI's context.
Returns
a reference to the window associated with the given viewport.
See also
getSwapchain()

◆ getSwapchain()

graphics::Swapchain & grem::imgui::GraphicalUserInterface::getSwapchain ( ImGuiViewport & viewport)
staticnodiscard

Get the swapchain associated with an ImGui viewport.

Parameters
viewportImGui viewport to get the swapchain of. Must be a viewport created from this GUI's context.
Returns
a reference to the swapchain associated with the given viewport.
See also
getWindow()

◆ operator=() [1/2]

GraphicalUserInterface & grem::imgui::GraphicalUserInterface::operator= ( const GraphicalUserInterface & )
delete

Copying a GUI is not allowed.

◆ operator=() [2/2]

GraphicalUserInterface & grem::imgui::GraphicalUserInterface::operator= ( GraphicalUserInterface && )
delete

Moving a GUI is not allowed.

◆ handleEvent()

bool grem::imgui::GraphicalUserInterface::handleEvent ( const events::Event & event)

Handle an event from an events::EventPump in the GUI.

Parameters
eventevent to handle.
Returns
true if the event was consumed and should be discarded, false if the event should be propagated to the rest of the application.
See also
update()

◆ update()

void grem::imgui::GraphicalUserInterface::update ( Duration deltaTime)

Prepare for a new GUI frame.

Parameters
deltaTimetime elapsed between the beginning of the previous frame and the beginning of the new frame.
Exceptions
imgui::Erroron failure to prepare a new frame.
graphics::Errorif graphics resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
This function should be called once before each call to ImGui::NewFrame(), ideally after handling the events for the current frame.
See also
handleEvent()

◆ drawFrame() [1/2]

void grem::imgui::GraphicalUserInterface::drawFrame ( graphics::RenderPass & renderPass,
const ImDrawData & drawData,
SharedPointer< graphics::ShaderPipelineImplementation > shaderPipelineOverrideHandle = {} )

Push the draw commands of a GUI frame to a render pass.

Parameters
renderPassrender pass to push the draw commands to.
drawDataGUI frame to draw, obtained using ImGui::GetDrawData() after calling ImGui::Render(). Must have been rendered with the context of this GUI.
shaderPipelineOverrideHandleshader pipeline override to use, or nullptr to not use a shader override.
Exceptions
imgui::Erroron failure to draw the frame.
graphics::Errorif graphics resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
Additional platform windows may be rendered by calling ImGui::RenderPlatformWindowsDefault(), or by manually calling this function for each window's swapchain, which can be obtained using getSwapchain().

◆ drawFrame() [2/2]

void grem::imgui::GraphicalUserInterface::drawFrame ( graphics::RenderPass & renderPass,
const ImDrawData & drawData,
const ShaderPipeline & shaderPipelineOverride )
inline

Push the draw commands of a GUI frame to a render pass.

Parameters
renderPassrender pass to push the draw commands to.
drawDataGUI frame to draw, obtained using ImGui::GetDrawData() after calling ImGui::Render(). Must have been rendered with the context of this GUI.
shaderPipelineOverrideshader pipeline override to use.
Exceptions
imgui::Erroron failure to draw the frame.
graphics::Errorif graphics resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
Additional platform windows may be rendered by calling ImGui::RenderPlatformWindowsDefault(), or by manually calling this function for each window's swapchain, which can be obtained using getSwapchain().

◆ getTextureID()

TextureID grem::imgui::GraphicalUserInterface::getTextureID ( const graphics::Texture & texture)
nodiscard

Create a texture ID for a texture that will be valid for rendering in the GUI until at least the next call to update() after the texture has been destroyed, by extending the lifetime of the texture.

Parameters
texturetexture to create an ID for.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Returns
an ImTextureID for the specified texture, suitable for passing to functions like ImGui::Image() for the current frame.

◆ getContext()

ImGuiContext * grem::imgui::GraphicalUserInterface::getContext ( ) const
nodiscardnoexcept

Get the underlying Dear ImGui context.

Returns
a non-null non-owning pointer to the Dear ImGui context of this GUI.

◆ getDefaultVertexShader()

const VertexShader & grem::imgui::GraphicalUserInterface::getDefaultVertexShader ( )
nodiscard

Get the default GUI vertex shader.

Returns
a read-only reference to the default GUI vertex shader.

◆ getPlainFragmentShader()

const FragmentShader & grem::imgui::GraphicalUserInterface::getPlainFragmentShader ( )
nodiscard

Get the default plain GUI fragment shader.

Returns
a read-only reference to the plain GUI fragment shader.

◆ getPlainShaderPipeline()

const ShaderPipeline & grem::imgui::GraphicalUserInterface::getPlainShaderPipeline ( )
nodiscard

Get the default plain GUI shader pipeline.

Returns
a read-only reference to the plain GUI shader pipeline.

Member Data Documentation

◆ DEFAULT_VERTEX_SHADER_CONSTANTS

VertexShaderConstants grem::imgui::GraphicalUserInterface::DEFAULT_VERTEX_SHADER_CONSTANTS {}
staticconstexpr

Default GUI vertex shader constants.

◆ DEFAULT_FRAGMENT_SHADER_CONSTANTS

FragmentShaderConstants grem::imgui::GraphicalUserInterface::DEFAULT_FRAGMENT_SHADER_CONSTANTS {}
staticconstexpr

Default GUI fragment shader constants.

◆ DEFAULT_SHADER_PIPELINE_OPTIONS

graphics::ShaderPipelineOptions grem::imgui::GraphicalUserInterface::DEFAULT_SHADER_PIPELINE_OPTIONS
staticconstexpr
Initial value:
{
.depthBufferMode = graphics::DepthBufferMode::NONE,
.faceCullingMode = graphics::FaceCullingMode::NONE,
}
@ 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
static const BlendState ALPHA_BLENDING_STRAIGHT
Blend state to use for straight alpha blending using the standard "over" operator.
Definition shaders.hpp:390

Default GUI graphics pipeline configuration.


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