VoxelEngine
 
Loading...
Searching...
No Matches
RenderPass.h
1#pragma once
2
3#include <cstdint>
4#include <glm/glm.hpp>
5#include <memory>
6#include <optional>
7#include <string>
8
9
10namespace gl {
11 class FBO;
12} // namespace gl
13
14
15namespace engine {
16 class Engine;
17 class Material;
18
19 class RenderPass {
20 public:
21 using ID = uint16_t;
22
23 // Built-in pass IDs
24 static constexpr ID DirectionalShadow = 1 << 0;
25 static constexpr ID OmniShadow = 1 << 1;
26 static constexpr ID Scene = 1 << 2;
27 static constexpr ID SceneTransparent = 1 << 3;
28 static constexpr ID Composite = 1 << 4;
29
30 virtual ~RenderPass() = default;
31
32 RenderPass(const RenderPass&) = delete;
33 RenderPass& operator=(const RenderPass&) = delete;
34 RenderPass(RenderPass&&) noexcept = delete;
35 RenderPass& operator=(RenderPass&&) noexcept = delete;
36
37 virtual void beforeRender(Engine& engine, uint8_t pass) = 0;
38 virtual void afterRender(Engine& engine, uint8_t pass) = 0;
39
40 virtual void resize(glm::ivec2 resolution) { m_resolution = resolution; }
41
42 ID id() const { return m_id; }
43 uint8_t passes() const { return m_passes; }
44
45 const Material* material = nullptr;
46 const gl::FBO* fbo = nullptr;
47 std::optional<glm::ivec2> viewportSize = std::nullopt;
48
49 protected:
50 glm::ivec2 m_resolution;
51
53 explicit RenderPass(glm::ivec2 resolution, uint8_t passes = 1)
54 : m_id(1 << s_nextPassIndex++),
55 m_passes(passes),
56 m_resolution(resolution) {}
57
59 explicit RenderPass(glm::ivec2 resolution, ID id, uint8_t passes = 1)
60 : m_id(id),
61 m_passes(passes),
62 m_resolution(resolution) {}
63
64
65 private:
66 ID m_id;
67 uint8_t m_passes;
68 inline static unsigned int s_nextPassIndex = 4;
69 };
70
71} // namespace engine
Definition Engine.h:36
Definition Material.h:7
Definition RenderPass.h:19
RenderPass(glm::ivec2 resolution, uint8_t passes=1)
Constructs pass with next available ID, use only for custom passes.
Definition RenderPass.h:53
RenderPass(glm::ivec2 resolution, ID id, uint8_t passes=1)
Constructs pass with specific ID, use only for built-in passes.
Definition RenderPass.h:59