Loading...
Searching...
No Matches
SceneDrawer.hpp
1#pragma once
2#include <Gfx/Graph/NodeRenderer.hpp>
3#include <Gfx/Graph/Utils.hpp>
4
5#include <Threedim/ModelDisplay/ModelSceneDrawer.hpp>
6
7#include <ossia/detail/hash_map.hpp>
8
9#include <Threedim/GeometryViewer/SceneSummary.hpp>
10
11#include <QMatrix4x4>
12
13#include <array>
14#include <memory>
15#include <optional>
16#include <vector>
17
18namespace Gfx::GeometryViewer
19{
20struct GeometryViewerNode;
21
22using SceneView = score::gfx::ModelSceneView;
23
34{
35public:
36 explicit SceneDrawer(const GeometryViewerNode& node);
37 ~SceneDrawer() override;
38 SceneDrawer(const SceneDrawer&) = delete;
39 SceneDrawer& operator=(const SceneDrawer&) = delete;
40
41 bool setScene(const ossia::scene_spec& scene) override;
42
45 bool active() const noexcept override { return m_active; }
46
47 const ossia::aabb& bounds() const noexcept override { return m_desc.bounds; }
48
49 void update(
50 score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res,
51 score::gfx::PassMap& passes, QRhiBuffer* processUBO, QRhiBuffer* cameraUBO,
52 const SceneView& view) override;
53
54 void draw(
55 score::gfx::RenderList& renderer, QRhiCommandBuffer& cb,
56 score::gfx::Edge& edge) override;
57
59 bool hasLines() const noexcept override { return m_lineVertices > 0 || m_wantsLines; }
61 score::gfx::RenderList& renderer, QRhiCommandBuffer& cb, score::gfx::Edge& edge,
62 QRhiGraphicsPipeline* lines, QRhiShaderResourceBindings* srb) override;
63
64 void release() override;
65
66private:
67 struct MeshEntry
68 {
70 ossia::geometry_spec spec;
71 const score::gfx::Mesh* mesh{};
74 uint8_t attributes{};
76 uint64_t layout{};
79 bool live{};
81 bool used{};
82 };
83
84 struct TextureEntry
85 {
86 std::shared_ptr<const ossia::texture_source> source;
87 QRhiTexture* texture{};
89 bool borrowed{};
90 bool used{};
91 bool failed{};
92 };
93
94 struct Draw
95 {
96 uint64_t mesh{};
97 QMatrix4x4 world;
98 ossia::material_component_ptr material;
100 uint64_t texture{}, emissive{};
102 uint64_t bindings{};
103 };
104
105 struct EdgePass
106 {
107 score::gfx::Edge* edge{};
108 QRhiRenderPassDescriptor* renderPass{};
111 ossia::hash_map<uint64_t, score::gfx::Pipeline> pipelines;
113 ossia::hash_map<uint64_t, QRhiShaderResourceBindings*> bindings;
114 };
115
116 void walk();
117 void publish();
118 uint64_t meshFor(const ossia::mesh_primitive& prim);
119 uint64_t meshFor(const ossia::geometry_spec& spec, std::size_t index);
120 uint64_t textureFor(const ossia::texture_ref& ref);
121
122 bool ensureShaders(score::gfx::RenderList& renderer, int variant);
123 uint64_t pipelineKey(const MeshEntry& m) const noexcept;
124 score::gfx::Pipeline makePipeline(
125 score::gfx::RenderList& renderer, const MeshEntry& m, const EdgePass& pass,
126 QRhiShaderResourceBindings* srb);
127 QRhiShaderResourceBindings* bindingsFor(
128 score::gfx::RenderList& renderer, EdgePass& pass, const Draw& draw,
129 QRhiBuffer* processUBO, QRhiBuffer* cameraUBO);
130 QRhiTexture* textureOf(uint64_t key) const noexcept;
131 void uploadTextures(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res);
132 void uploadDraws(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res, const SceneView& view);
133 void uploadLines(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res, const SceneView& view);
134 void releasePasses();
135
136 const GeometryViewerNode& m_node;
137
138 ossia::scene_spec m_scene;
139 const ossia::scene_state* m_state{};
140 int64_t m_version{-1}, m_dirty{-1};
141 bool m_active{};
142
143 SceneDescription m_desc;
144 uint32_t m_serial{};
145 bool m_summaryPending{};
146 std::vector<Draw> m_draws;
147 ossia::hash_map<uint64_t, MeshEntry> m_meshes;
148 ossia::hash_map<uint64_t, TextureEntry> m_textures;
149
151 std::array<std::optional<std::pair<QShader, QShader>>, 16> m_shaders;
152 std::array<bool, 16> m_shaderFailed{};
153
154 ossia::small_vector<EdgePass, 2> m_passes;
155 QRhiBuffer* m_drawUBO{};
156 QRhiBuffer* m_lightingUBO{};
157 QRhiSampler* m_sampler{};
158 int64_t m_drawStride{};
159 int64_t m_drawCapacity{};
160 bool m_drawsDirty{true};
162 bool m_passesDirty{true};
163 QMatrix4x4 m_drawsModel, m_linesModel;
164 std::vector<char> m_drawData;
165 int m_mode{-1};
166
167 QRhiBuffer* m_lineBuffer{};
168 int64_t m_lineCapacity{};
169 int m_lineVertices{};
170 bool m_wantsLines{};
171 bool m_linesDirty{true};
172 bool m_gizmos{};
173 int64_t m_selected{-1};
174 std::vector<float> m_lineData;
175};
176}
Definition SceneDrawer.hpp:34
void update(score::gfx::RenderList &renderer, QRhiResourceUpdateBatch &res, score::gfx::PassMap &passes, QRhiBuffer *processUBO, QRhiBuffer *cameraUBO, const SceneView &view) override
Once the passes of the renderer exist for the frame.
bool setScene(const ossia::scene_spec &scene) override
The scene the renderer received; returns whether it is another one.
const ossia::aabb & bounds() const noexcept override
The bounds of what is drawn, in the space of the scene.
Definition SceneDrawer.hpp:47
void drawLines(score::gfx::RenderList &renderer, QRhiCommandBuffer &cb, score::gfx::Edge &edge, QRhiGraphicsPipeline *lines, QRhiShaderResourceBindings *srb) override
With the line pipeline of the guides: world-space positions and colours.
bool hasLines() const noexcept override
The gizmos and the outline of the selected object.
Definition SceneDrawer.hpp:59
bool active() const noexcept override
Definition SceneDrawer.hpp:45
Definition ModelSceneDrawer.hpp:29
List of nodes to be rendered to an output.
Definition RenderList.hpp:36
Definition score-plugin-threedim/Threedim/GeometryViewer/Node.hpp:20
ossia::aabb bounds
The union of the bounds of what is drawn, in the space of the scene.
Definition SceneSummary.hpp:53
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:236
Definition Mesh.hpp:95
Data model for meshes.
Definition Mesh.hpp:196
What a frame of a Model Display shows its scene with.
Definition ModelSceneDrawer.hpp:15
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:278
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:307