Graphic Plugin
Hardware-accelerated graphics backend for EngineSquared, built on WebGPU via wgpu-native. It provides GPU context management, shaders, textures, buffers, bind groups, and a render-graph pipeline integrated with the engine’s rendering stages.
Description
The Graphic plugin adds a full graphics stack to EngineSquared:
- WebGPU / wgpu-native — Cross-platform GPU API (Vulkan, Metal, D3D12).
- Context & device — Instance, adapter, device, and queue setup with configurable limits and features.
- Resources — Shaders (WGSL), textures, samplers, GPU buffers, and bind groups.
- Render graph — Declarative render passes with dependencies and topological execution.
- Pipeline integration — Hooks into the engine’s RenderingPipeline (Setup, Preparation, CommandCreation, Presentation) and Shutdown.
It registers resources (e.g. Context, GraphicSettings, ShaderContainer, TextureContainer, GPUBufferContainer, SamplerContainer, BindGroupManager, RenderGraphContainer) and systems for initialization, frame preparation, command recording, presentation, and cleanup. Other plugins (e.g. Default Pipeline, RmlUi) can depend on it for rendering.
Dependencies
External (xmake packages)
| Package | Purpose |
| wgpu-native | WebGPU implementation |
| glfw | Windowing (optional) |
| glfw3webgpu | GLFW–WebGPU surface |
| glm | Math types |
| entt | ECS / hashed names |
| spdlog | Logging |
| fmt | Formatting |
| stb | Image loading |
| lodepng | PNG support |
| tinyobjloader | OBJ mesh loading |
Engine
- EngineSquaredCore — Core engine and scheduler
- PluginObject — Entities and components (e.g. Mesh, Transform)
- PluginRenderingPipeline — Rendering stages (Setup, Preparation, CommandCreation, Presentation)
- PluginWindow — Window and surface (when using a window)
- PluginEvent — Event handling
- UtilsLog — Logging utilities
The plugin requires RenderingPipeline::Plugin and Event::Plugin; use with Window::Plugin when rendering to a window.
Install
The Graphic plugin is built as part of EngineSquared with xmake. There is no separate install step.
- Clone and enter the repo
git clone https://github.com/EngineSquared/EngineSquared.git
cd EngineSquared
- Install xmake (if needed)
See xmake install.
Configure and build
The static target PluginGraphic is built with the rest of the engine. Link it (or the main EngineSquared target that already depends on it) into your application.
- Run tests (optional)
xmake build PluginGraphicTests
xmake build RenderGraphTest # or any test binary from tests/
Configuration
Configure the plugin by editing the GraphicSettings resource before running the rendering pipeline (e.g. in a system registered for RenderingPipeline::Init or earlier). Access it via the core:
Definition GraphicSettings.hpp:18
Window system
Choose how the surface is created (e.g. for headless tests vs windowed apps):
@ None
Definition GraphicSettings.hpp:9
@ GLFW
Definition GraphicSettings.hpp:10
Power preference
@ LowPower
Definition GraphicSettings.hpp:14
@ HighPerformance
Definition GraphicSettings.hpp:15
Device limits and features
settings.AddRequiredFeature(wgpu::FeatureName::TextureCompressionBC);
constexpr DefaultFlag Default
Definition webgpu.hpp:78
Uncaptured device errors
Set a custom callback for WebGPU uncaptured errors (e.g. to log and/or throw in debug):
settings.SetOnErrorCallback(
[](WGPUDevice const*, WGPUErrorType type, WGPUStringView message,
void*, void*) {
Log::Error(fmt::format(
"WebGPU error: type {:x} ({})",
static_cast<uint32_t>(type),
std::string(message.data, message.length)));
});
void Error(const T &msg) noexcept
Definition Logger.hpp:51
Usage
Adding the plugin
Ensure required plugins are added; then add the Graphic plugin:
return 0;
}
Definition PluginDefaultPipeline.hpp:6
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
void AddPlugins()
Adds multiple plugins that will be call instantly through the Bind method to agregate their systems a...
Definition Core.inl:88
void RunCore()
Execute the core loop, which will run all the schedulers.
Definition Core.cpp:74
Definition PluginGraphic.hpp:6
Definition PluginWindow.hpp:6
int main(void)
Definition main.cpp:80
Other plugins that depend on graphics (e.g. Default Pipeline, RmlUi) will typically RequirePlugins<..., Graphic::Plugin>(); your app only needs to add the plugin (and Window, if you render to a window).
Configuring settings at startup
WGPUStringView message, void*, void*) {
Log::Error(fmt::format(
"Device error: {}", std::string(message.data, message.length)));
});
});
TResource & GetResource()
Get a reference of a resource.
Definition Core.inl:14
decltype(auto) RegisterSystem(Systems... systems)
Add one or multiple systems associated with a specific scheduler.
Definition Core.inl:61
GraphicSettings & SetOnErrorCallback(WGPUUncapturedErrorCallback callback)
Definition GraphicSettings.hpp:64
GraphicSettings & SetWindowSystem(WindowSystem system)
Definition GraphicSettings.hpp:27
GraphicSettings & SetPowerPreference(PowerPreference preference)
Definition GraphicSettings.hpp:34
This class is used to initialize libraries like GLFW, etc.
Definition Init.hpp:9
Headless (no window)
Useful for tests or offscreen rendering:
});
void RunSystems()
Run all the systems once by calling each scheduler.
Definition Core.cpp:83
Accessing graphics resources
After the pipeline has run setup, you can use the registered resources:
Object::Resource::ResourceManager< Sampler > SamplerContainer
SamplerContainer is a resource that stores Sampler resources.
Definition SamplerContainer.hpp:17
Object::Resource::ResourceManager< std::unique_ptr< AGPUBuffer > > GPUBufferContainer
GPUBufferContainer is a resource that stores GPUBuffer resources.
Definition GPUBufferContainer.hpp:17
Object::Resource::ResourceManager< Shader > ShaderContainer
ShaderContainer is a resource that stores Shader resources.
Definition ShaderContainer.hpp:17
Object::Resource::ResourceManager< RenderGraph > RenderGraphContainer
RenderGraphContainer is a resource that stores RenderGraph resources.
Definition RenderGraphContainer.hpp:17
Object::Resource::ResourceManager< BindGroup > BindGroupManager
BindGroupManager is a resource that stores BindGroup resources.
Definition BindGroupManager.hpp:17
Object::Resource::ResourceManager< Texture > TextureContainer
TextureContainer is a resource that stores Texture resources.
Definition TextureContainer.hpp:17
Shader from WGSL source
@vertex fn vs_main() -> @builtin(position) vec4f {
return vec4f(0.0, 0.0, 0.0, 1.0);
}
@fragment fn fs_main() -> @location(0) vec4f {
return vec4f(1.0, 0.0, 0.0, 1.0);
}
)")
.addColorTargetState(Graphic::Resource::ColorTargetState(wgpu::TextureFormat::BGRA8Unorm));
container.Add("my_shader", std::move(shader));
Definition ShaderDescriptor.hpp:21
ShaderDescriptor & setVertexEntryPoint(std::string_view entryPoint)
Definition ShaderDescriptor.hpp:50
ShaderDescriptor & setFragmentEntryPoint(std::string_view entryPoint)
Definition ShaderDescriptor.hpp:56
ShaderDescriptor & setShader(std::string_view source)
Definition ShaderDescriptor.hpp:26
static Shader Create(const ShaderDescriptor &descriptor, Context &context)
Definition Shader.hpp:45
Render graph with a render pass
auto& graph = graphContainer.Get();
graph.
Add<MyRenderPass>(
"main_pass", MyRenderPass(core, ...));
graph.SetDependency("other_pass", "main_pass");
entt::resource< ResourceType > Add(const entt::hashed_string &id, Args &&...args)
Adds a resource to the manager.
Definition ResourceManager.hpp:52
(Your render pass type must satisfy the plugin’s ARenderPass interface and be registered/used within the engine’s render graph execution.)
Full example (minimal app with error callback)
See examples/graphic_usage/src/main.cpp for a complete sample: plugin setup, GraphicSettings (including SetOnErrorCallback), and a simple scene with mesh and camera.
License
Copyright (c) 2025 EngineSquared.
This plugin is part of EngineSquared and is distributed under the MIT License.
See the LICENSE file in the repository root for the full text.