RenderList.hpp
1 #pragma once
2 #include <Gfx/Graph/CommonUBOs.hpp>
3 #include <Gfx/Graph/Node.hpp>
4 
5 namespace score::gfx
6 {
7 
8 class OutputNode;
18 class SCORE_PLUGIN_GFX_EXPORT RenderList
19 {
20 private:
21  std::shared_ptr<RenderState> m_state;
22 
23 public:
24  explicit RenderList(OutputNode& output, const std::shared_ptr<RenderState>& state);
25  ~RenderList();
26 
30  void init();
31 
37  [[nodiscard]] QRhiResourceUpdateBatch* initialBatch() const noexcept;
38 
45  MeshBuffers initMeshBuffer(const Mesh& mesh, QRhiResourceUpdateBatch& res);
46 
50  void update(QRhiResourceUpdateBatch& res);
51 
55  void render(QRhiCommandBuffer& commands, bool force = false);
56 
60  void release();
61 
65  void maybeRebuild();
66 
72  TextureRenderTarget renderTargetForOutput(const Edge& edge) noexcept;
73 
79  QImage adaptImage(const QImage& in);
80 
85 
90 
91  using Buffers = std::pair<const Mesh* const, MeshBuffers>;
92  Buffers
93  acquireMesh(const ossia::geometry_spec&, QRhiResourceUpdateBatch& res) noexcept;
94 
98  std::vector<score::gfx::Node*> nodes;
99 
103  std::vector<score::gfx::NodeRenderer*> renderers;
104 
106  void clearRenderers();
107 
111  QRhiTexture& emptyTexture() const noexcept { return *m_emptyTexture; }
112 
119  QRhiBuffer& outputUBO() const noexcept { return *m_outputUBO; }
120 
124  const score::gfx::Mesh& defaultQuad() const noexcept;
125 
129  const score::gfx::Mesh& defaultTriangle() const noexcept;
130 
131  int samples() const noexcept { return m_samples; }
132 
133  bool canRender() const noexcept { return m_ready; }
134 
135 private:
136  OutputUBO m_outputUBOData;
137 
138  QRhiResourceUpdateBatch* m_initialBatch{};
139  // Material
140  QRhiBuffer* m_outputUBO{};
141  QRhiTexture* m_emptyTexture{};
142 
146  ossia::flat_map<Mesh*, MeshBuffers> m_vertexBuffers;
147 
148  ossia::flat_map<ossia::geometry_spec, Mesh*> m_customMeshCache;
149 
153  QSize m_lastSize{};
154 
155  int m_minTexSize{};
156  int m_maxTexSize{};
157  int m_samples{1};
158 
159  bool m_flip{};
160 
161  bool m_ready{};
162  bool m_built{};
163 };
164 }
Base class for sink nodes (QWindow, spout, syphon, NDI output, ...)
Definition: OutputNode.hpp:23
List of nodes to be rendered to an output.
Definition: RenderList.hpp:19
std::vector< score::gfx::NodeRenderer * > renderers
Renderers - one per node.
Definition: RenderList.hpp:103
std::vector< score::gfx::Node * > nodes
Nodes present in this RenderList, in order.
Definition: RenderList.hpp:98
RenderState & state
RenderState corresponding to this RenderList.
Definition: RenderList.hpp:89
QRhiBuffer & outputUBO() const noexcept
UBO corresponding to the output parameters:
Definition: RenderList.hpp:119
OutputNode & output
Output node to which this RenderList is rendering to.
Definition: RenderList.hpp:84
QRhiTexture & emptyTexture() const noexcept
Texture to use when a texture is missing.
Definition: RenderList.hpp:111
Graphics rendering pipeline for ossia score.
Definition: Filter/PreviewWidget.hpp:12
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Connection between two score::gfx::Port.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:66
Definition: Mesh.hpp:15
Data model for meshes.
Definition: Mesh.hpp:23
Global state associated to a rendering context.
Definition: RenderState.hpp:31
Useful abstraction for storing all the data related to a render target.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:111