Avara3D 0.2.0
C++ API reference
Renderer.h
1//
2// Renderer.h
3// avara3d
4//
5// Created by Morgan Davis on 4/22/18.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_RENDER_RENDERER_H
10#define AVARA3D_RENDER_RENDERER_H
11
12#include <cstdint>
13#include <memory>
14#include <optional>
15
16#include "a3d/render/PipelineDesc.h"
17#include "a3d/scene/Scene.h"
18
19namespace a3d {
20
21 struct BackgroundPass;
22 struct FrameStats;
23 struct GroundPass;
24 struct LinesPass;
25 struct RenderMemoryStats;
26
27 class FrameStatsHistory;
28 class Image;
29 class Line;
30 class Node;
31 class Material;
32 class Mesh;
33 class MeshElement;
34 class Point;
35 class Profiler;
36 class DrawPacket;
37 class Scene;
38
39 class Renderer {
40
41 public:
42 // [Internal Types]
43
44 struct Capabilities {
45 bool wireframeRendering {false};
46 bool gpuTiming {false};
47 };
48
49 struct ClearCommand {
50
51 struct Scissor {
52 std::int32_t x = 0;
53 std::int32_t y = 0;
54 std::int32_t width = 0;
55 std::int32_t height = 0;
56 };
57
58 bool clearColor = true;
59 bool clearDepth = true;
60 bool clearStencil = false;
61 math::vec4 color = {0.f, 0.f, 0.f, 1.f};
62 float depth = 1.0f;
63 int stencil = 0;
64 std::optional<Scissor> scissor = {};
65 // clear operations may respect the current scissor and write masks.
66 // override them when necessary to ensure the requested buffers are cleared.
67 bool forceWriteMasks = true;
68 };
69
70 struct FrameParams {
71 const RenderContext& context;
72 math::mat4 view = math::mat4(1.0f);
73 math::mat4 proj = math::mat4(1.0f);
75 FrameStats* stats = nullptr;
76 Profiler* profiler = nullptr;
77 };
78
79 // [Internal Lifecycle Functions]
80
81 Renderer();
82
83 Renderer(const Renderer&) = delete;
84 Renderer& operator=(const Renderer&) = delete;
85
86 Renderer(Renderer&&) = delete;
87 Renderer& operator=(Renderer&&) = delete;
88
89 virtual ~Renderer() = 0;
90
91 // [Internal Member Functions]
92
93 virtual bool initialize(const RenderContext& context) = 0;
94 virtual bool isInitialized() const = 0;
95
96 virtual const Capabilities& capabilities() const = 0;
97
98 virtual void beginFrame(const Scene& scene,
99 const RenderContext& context,
100 const Scene::DebugOptions& debugOptions,
101 FrameStats& stats,
102 Profiler& profiler) = 0;
103 virtual void endFrame(const Scene& scene,
104 const RenderContext& context,
105 const Scene::DebugOptions& debugOptions,
106 FrameStats& stats,
107 Profiler& profiler,
108 const FrameStatsHistory& statsHistory) = 0;
109
110 virtual void preTraversal(const Scene& scene,
111 const RenderContext& context,
112 const Scene::DebugOptions& debugOptions,
113 FrameStats& stats) = 0;
114 virtual void postTraversal(const Scene& scene,
115 const RenderContext& context,
116 const math::mat4& view,
117 const std::vector<Node*>& lightNodes,
118 const Scene::DebugOptions& debugOptions,
119 FrameStats& stats) = 0;
120
121 virtual void clear(const ClearCommand& cmd, const RenderContext& context) = 0;
122
123 virtual void renderPacket(DrawPacket& packet, const FrameParams& frame) = 0;
124
125 virtual std::unique_ptr<Image> snapshot(const RenderContext& context) const = 0;
126
127 protected:
128 // [Protected Member Functions]
129
130 virtual void resolvePacket(DrawPacket& packet, const FrameParams& frame) = 0;
131 virtual void drawPacket(const DrawPacket& packet, const FrameParams& frame) = 0;
132
133 virtual void drawBackground(const BackgroundPass& backgroundPass,
134 const math::mat4& view,
135 const math::mat4& proj) = 0;
136 virtual void drawGround(const GroundPass& groundPass,
137 const math::mat4& view,
138 const math::mat4& proj) = 0;
139
140 virtual void bindPipeline(PipelineId pipelineId) = 0;
141 virtual void bindMaterial(const Material& material) = 0;
142 virtual void bindMeshElement(const MeshElement& element) = 0;
143 virtual void applyMVP(const math::mat4& model, const math::mat4& view, const math::mat4& proj) = 0;
144 virtual void drawElements() = 0;
145
146 virtual void drawLines(const LinesPass& pass,
147 const RenderContext& context,
148 const math::mat4& view,
149 const math::mat4& proj) = 0;
150 };
151
152}
153
154#endif // AVARA3D_RENDER_RENDERER_H
DebugOptions
Scene-wide debug visualization options.
Definition: Scene.h:61
@ None
No scene debug visualization options enabled.