Loading...
Searching...
No Matches
score-plugin-gfx/Gfx/Graph/Utils.hpp
1#pragma once
2
3#include <Gfx/Graph/Mesh.hpp>
4#include <Gfx/Graph/RenderState.hpp>
5#include <Gfx/Graph/Scale.hpp>
6#include <Gfx/Graph/Uniforms.hpp>
7
8#include <ossia/detail/hash_map.hpp>
9
10#include <score_plugin_gfx_export.h>
11
12#include <span>
13
14namespace score::gfx
15{
16class Node;
17class NodeModel;
18struct Port;
19struct Edge;
20class RenderList;
24struct Sampler
25{
26 QRhiSampler* sampler{};
27 QRhiTexture* texture{};
28};
29
34{
35 ossia::hash_map<RenderList*, Sampler> samplers;
36
37 std::vector<float> data;
38 int channels{};
39 int fixedSize{0};
40 enum Mode
41 {
42 Waveform,
43 FFT,
44 Histogram
45 } mode{};
46};
47
51struct Port
52{
55
57 void* value{};
58
60 Types type{};
61
63 std::vector<Edge*> edges;
64};
65
69struct Edge
70{
71 Edge(Port* source, Port* sink)
72 : source{source}
73 , sink{sink}
74 {
75 source->edges.push_back(this);
76 sink->edges.push_back(this);
77 }
78
79 ~Edge()
80 {
81 if(auto it = std::find(source->edges.begin(), source->edges.end(), this);
82 it != source->edges.end())
83 source->edges.erase(it);
84 if(auto it = std::find(sink->edges.begin(), sink->edges.end(), this);
85 it != sink->edges.end())
86 sink->edges.erase(it);
87 }
88
89 Port* source{};
90 Port* sink{};
91};
92
97{
98 QRhiGraphicsPipeline* pipeline{};
99 QRhiShaderResourceBindings* srb{};
100
101 void release()
102 {
103 delete pipeline;
104 pipeline = nullptr;
105
106 delete srb;
107 srb = nullptr;
108 }
109};
110
115{
116 QRhiTexture* texture{};
117 QRhiRenderBuffer* colorRenderBuffer{};
118 QRhiRenderBuffer* depthRenderBuffer{};
119 QRhiRenderPassDescriptor* renderPass{};
120 QRhiRenderTarget* renderTarget{};
121
122 operator bool() const noexcept { return texture != nullptr; }
123
124 void release()
125 {
126 if(texture)
127 {
128 delete texture;
129 texture = nullptr;
130
131 delete colorRenderBuffer;
132 colorRenderBuffer = nullptr;
133
134 delete depthRenderBuffer;
135 depthRenderBuffer = nullptr;
136
137 delete renderPass;
138 renderPass = nullptr;
139
140 delete renderTarget;
141 renderTarget = nullptr;
142 }
143 }
144};
145
149struct Image
150{
151 QString path;
152 std::vector<QImage> frames;
153};
154
158SCORE_PLUGIN_GFX_EXPORT
160createRenderTarget(const RenderState& state, QRhiTexture* tex, int samples, bool depth);
161
167SCORE_PLUGIN_GFX_EXPORT
169 const RenderState& state, QRhiTexture::Format fmt, QSize sz, int samples, bool depth,
170 QRhiTexture::Flags = {});
171
172SCORE_PLUGIN_GFX_EXPORT
173void replaceBuffer(QRhiShaderResourceBindings&, int binding, QRhiBuffer* newBuffer);
174SCORE_PLUGIN_GFX_EXPORT
175void replaceSampler(QRhiShaderResourceBindings&, int binding, QRhiSampler* newSampler);
176SCORE_PLUGIN_GFX_EXPORT
177void replaceTexture(QRhiShaderResourceBindings&, int binding, QRhiTexture* newTexture);
178
179SCORE_PLUGIN_GFX_EXPORT
180void replaceBuffer(
181 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiBuffer* newBuffer);
182SCORE_PLUGIN_GFX_EXPORT
183void replaceSampler(
184 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiSampler* newSampler);
185SCORE_PLUGIN_GFX_EXPORT
186void replaceTexture(
187 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiTexture* newTexture);
188
192SCORE_PLUGIN_GFX_EXPORT
193void replaceSampler(
194 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler);
195
199SCORE_PLUGIN_GFX_EXPORT
200void replaceTexture(
201 QRhiShaderResourceBindings&, QRhiSampler* sampler, QRhiTexture* newTexture);
202
206SCORE_PLUGIN_GFX_EXPORT
208 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler,
209 QRhiTexture* newTexture);
210
214SCORE_PLUGIN_GFX_EXPORT
215void replaceTexture(
216 QRhiShaderResourceBindings& srb, QRhiTexture* old_tex, QRhiTexture* new_tex);
220SCORE_PLUGIN_GFX_EXPORT
221QRhiShaderResourceBindings* createDefaultBindings(
222 const RenderList& renderer, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
223 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
224 std::span<QRhiShaderResourceBinding> additionalBindings = {});
225
229SCORE_PLUGIN_GFX_EXPORT
230Pipeline buildPipeline(
231 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
232 const QShader& fragmentS, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
233 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
234 std::span<QRhiShaderResourceBinding> additionalBindings = {});
235
241SCORE_PLUGIN_GFX_EXPORT
242std::pair<QShader, QShader>
243makeShaders(const RenderState& v, QString vert, QString frag);
244
250SCORE_PLUGIN_GFX_EXPORT
251QShader makeCompute(const RenderState& v, QString compt);
252
258struct SCORE_PLUGIN_GFX_EXPORT DefaultShaderMaterial
259{
260 void init(
261 RenderList& renderer, const std::vector<Port*>& input,
262 ossia::small_vector<Sampler, 8>& samplers);
263
264 QRhiBuffer* buffer{};
265 int size{};
266};
267
271SCORE_PLUGIN_GFX_EXPORT
272QSize resizeTextureSize(QSize img, int min, int max) noexcept;
273
277SCORE_PLUGIN_GFX_EXPORT
278QImage resizeTexture(const QImage& img, int min, int max) noexcept;
279
280inline void copyMatrix(const QMatrix4x4& mat, float* ptr) noexcept
281{
282 memcpy(ptr, mat.constData(), sizeof(float) * 16);
283}
284inline void copyMatrix(const QMatrix3x3& mat, float* ptr) noexcept
285{
286 memcpy(ptr, mat.constData(), sizeof(float) * 9);
287}
288
292SCORE_PLUGIN_GFX_EXPORT
293QSizeF computeScaleForMeshSizing(score::gfx::ScaleMode mode, QSizeF viewport, QSizeF texture);
294
298SCORE_PLUGIN_GFX_EXPORT
300 score::gfx::ScaleMode mode, QSizeF viewport, QSizeF texture);
301}
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:75
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
TreeNode< DeviceExplorerNode > Node
Definition DeviceNode.hpp:74
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
QSizeF computeScaleForTexcoordSizing(ScaleMode mode, QSizeF renderSize, QSizeF textureSize)
Comput the scale to apply to a texture rendered to a quad the size of viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:607
QRhiShaderResourceBindings * createDefaultBindings(const RenderList &renderer, const TextureRenderTarget &rt, QRhiBuffer *processUBO, QRhiBuffer *materialUBO, std::span< const Sampler > samplers, std::span< QRhiShaderResourceBinding > additionalBindings)
Create bindings following the score conventions for shaders and materials.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:316
QShader makeCompute(const RenderState &v, QString compute)
Compile a compute shader.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:420
QImage resizeTexture(const QImage &img, int min, int max) noexcept
Resize a texture to fit within GPU limits.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:557
QSizeF computeScaleForMeshSizing(ScaleMode mode, QSizeF viewport, QSizeF texture)
Comput the scale to apply to a texture so that it fits in a GL viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:567
void replaceSamplerAndTexture(QRhiShaderResourceBindings &srb, QRhiSampler *oldSampler, QRhiSampler *newSampler, QRhiTexture *newTexture)
Replace both sampler and texture in a SRC.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:200
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition Scale.hpp:10
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:393
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples, bool depth)
Create a render target from a texture.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:10
QSize resizeTextureSize(QSize sz, int min, int max) noexcept
Resize the size of a texture to fit within GPU limits.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:506
Data model for audio data being sent to the GPU.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:34
Utility to represent a shader material following score conventions.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:259
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:70
Image data and metadata.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:150
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:97
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:52
void * value
Pointer to the corresponding data.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:57
score::gfx::Node * node
Parent node of the port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:54
Types type
Type of the value.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:60
std::vector< Edge * > edges
Edges connected to that port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:63
Global state associated to a rendering context.
Definition RenderState.hpp:35
Stores a sampler and the texture currently associated with it.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:25
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:115