Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
RmluiRenderPass.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "core/Core.hpp"
4#include "entt/core/fwd.hpp"
5
8#include "resource/Shader.hpp"
9
11#include "utils/webgpu.hpp"
12
13#include <entt/core/hashed_string.hpp>
14#include <string_view>
15
16namespace Rmlui::Utils {
17static inline constexpr std::string_view RMLUI_RENDER_PASS_NAME = "RMLUI_RENDER_PASS";
18static inline constexpr std::string_view RMLUI_RENDER_PASS_SHADER_NAME = "RMLUI_RENDER_PASS_SHADER";
19static inline const entt::hashed_string RMLUI_RENDER_PASS_SHADER_ID{RMLUI_RENDER_PASS_SHADER_NAME.data(),
21
22static inline constexpr std::string_view RMLUI_RENDER_PASS_SHADER_CONTENT = R"(
23struct ScreenData {
24 size : vec2f,
25 _pad : vec2f,
26};
27
28@group(0) @binding(0) var uiTexture : texture_2d<f32>;
29@group(0) @binding(1) var uiSampler : sampler;
30@group(1) @binding(0) var<uniform> screen : ScreenData;
31
32struct VertexInput {
33 @location(0) position : vec2f,
34 @location(1) color : vec4<u32>,
35 @location(2) uv : vec2f,
36};
37
38struct VertexOutput {
39 @builtin(position) Position : vec4f,
40 @location(0) color : vec4f,
41 @location(1) uv : vec2f,
42};
43
44@vertex
45fn vs_main(input : VertexInput) -> VertexOutput {
46 var output : VertexOutput;
47 let ndc = vec2f(
48 (input.position.x / screen.size.x) * 2.0 - 1.0,
49 1.0 - (input.position.y / screen.size.y) * 2.0
50 );
51 output.Position = vec4f(ndc, 0.0, 1.0);
52 output.color = vec4f(input.color) / 255.0;
53 output.uv = input.uv;
54 return output;
55}
56
57@fragment
58fn fs_main(input : VertexOutput) -> @location(0) vec4f {
59 let texColor = textureSample(uiTexture, uiSampler, input.uv);
60 return input.color * texColor;
61}
62)";
63
65 public:
67 virtual ~RmluiRenderPass() = default;
68
69 void UniqueRenderCallback(wgpu::RenderPassEncoder &renderPass, Engine::Core & /*core*/) override
70 {
71 auto *renderer = RenderInterface::GetActive();
72 if (renderer == nullptr)
73 {
74 return;
75 }
76 renderer->FlushDrawCommands(renderPass);
77 }
78
80};
81} // namespace Rmlui::Utils
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
Definition ASingleExecutionRenderPass.hpp:9
ASingleExecutionRenderPass(std::string_view name)
Definition ASingleExecutionRenderPass.hpp:11
Definition Context.hpp:8
Definition Shader.hpp:14
static RenderInterface * GetActive()
Definition RenderInterface.cpp:73
RmluiRenderPass()
Definition RmluiRenderPass.hpp:66
static Graphic::Resource::Shader CreateShader(Graphic::Resource::Context &graphicContext)
Definition RmluiRenderPass.cpp:23
virtual ~RmluiRenderPass()=default
void UniqueRenderCallback(wgpu::RenderPassEncoder &renderPass, Engine::Core &) override
Definition RmluiRenderPass.hpp:69
Definition IRenderer.hpp:6
static constexpr std::string_view RMLUI_RENDER_PASS_SHADER_NAME
Definition RmluiRenderPass.hpp:18
static constexpr std::string_view RMLUI_RENDER_PASS_SHADER_CONTENT
Definition RmluiRenderPass.hpp:22
static constexpr std::string_view RMLUI_RENDER_PASS_NAME
Definition RmluiRenderPass.hpp:17
static const entt::hashed_string RMLUI_RENDER_PASS_SHADER_ID
Definition RmluiRenderPass.hpp:19