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 int rectUniformOffset{};
41 bool fft{};
42};
43
47struct Port
48{
51
53 void* value{};
54
56 Types type{};
57
59 std::vector<Edge*> edges;
60};
61
65struct Edge
66{
67 Edge(Port* source, Port* sink)
68 : source{source}
69 , sink{sink}
70 {
71 source->edges.push_back(this);
72 sink->edges.push_back(this);
73 }
74
75 ~Edge()
76 {
77 if(auto it = std::find(source->edges.begin(), source->edges.end(), this);
78 it != source->edges.end())
79 source->edges.erase(it);
80 if(auto it = std::find(sink->edges.begin(), sink->edges.end(), this);
81 it != sink->edges.end())
82 sink->edges.erase(it);
83 }
84
85 Port* source{};
86 Port* sink{};
87};
88
93{
94 QRhiGraphicsPipeline* pipeline{};
95 QRhiShaderResourceBindings* srb{};
96
97 void release()
98 {
99 delete pipeline;
100 pipeline = nullptr;
101
102 delete srb;
103 srb = nullptr;
104 }
105};
106
111{
112 QRhiTexture* texture{};
113 QRhiRenderBuffer* colorRenderBuffer{};
114 QRhiRenderBuffer* depthRenderBuffer{};
115 QRhiRenderPassDescriptor* renderPass{};
116 QRhiRenderTarget* renderTarget{};
117
118 operator bool() const noexcept { return texture != nullptr; }
119
120 void release()
121 {
122 if(texture)
123 {
124 delete texture;
125 texture = nullptr;
126
127 delete colorRenderBuffer;
128 colorRenderBuffer = nullptr;
129
130 delete depthRenderBuffer;
131 depthRenderBuffer = nullptr;
132
133 delete renderPass;
134 renderPass = nullptr;
135
136 delete renderTarget;
137 renderTarget = nullptr;
138 }
139 }
140};
141
145struct Image
146{
147 QString path;
148 std::vector<QImage> frames;
149};
150
154SCORE_PLUGIN_GFX_EXPORT
156createRenderTarget(const RenderState& state, QRhiTexture* tex, int samples);
157
163SCORE_PLUGIN_GFX_EXPORT
165 const RenderState& state, QRhiTexture::Format fmt, QSize sz, int samples,
166 QRhiTexture::Flags = {});
167
168SCORE_PLUGIN_GFX_EXPORT
169void replaceBuffer(QRhiShaderResourceBindings&, int binding, QRhiBuffer* newBuffer);
170SCORE_PLUGIN_GFX_EXPORT
171void replaceSampler(QRhiShaderResourceBindings&, int binding, QRhiSampler* newSampler);
172SCORE_PLUGIN_GFX_EXPORT
173void replaceTexture(QRhiShaderResourceBindings&, int binding, QRhiTexture* newTexture);
174
175SCORE_PLUGIN_GFX_EXPORT
176void replaceBuffer(
177 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiBuffer* newBuffer);
178SCORE_PLUGIN_GFX_EXPORT
179void replaceSampler(
180 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiSampler* newSampler);
181SCORE_PLUGIN_GFX_EXPORT
182void replaceTexture(
183 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiTexture* newTexture);
184
188SCORE_PLUGIN_GFX_EXPORT
189void replaceSampler(
190 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler);
191
195SCORE_PLUGIN_GFX_EXPORT
196void replaceTexture(
197 QRhiShaderResourceBindings&, QRhiSampler* sampler, QRhiTexture* newTexture);
198
202SCORE_PLUGIN_GFX_EXPORT
204 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler,
205 QRhiTexture* newTexture);
206
210SCORE_PLUGIN_GFX_EXPORT
211void replaceTexture(
212 QRhiShaderResourceBindings& srb, QRhiTexture* old_tex, QRhiTexture* new_tex);
216SCORE_PLUGIN_GFX_EXPORT
217QRhiShaderResourceBindings* createDefaultBindings(
218 const RenderList& renderer, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
219 QRhiBuffer* materialUBO, const std::vector<Sampler>& samplers,
220 std::span<QRhiShaderResourceBinding> additionalBindings = {});
221
225SCORE_PLUGIN_GFX_EXPORT
226Pipeline buildPipeline(
227 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
228 const QShader& fragmentS, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
229 QRhiBuffer* materialUBO, const std::vector<Sampler>& samplers,
230 std::span<QRhiShaderResourceBinding> additionalBindings = {});
231
237SCORE_PLUGIN_GFX_EXPORT
238std::pair<QShader, QShader>
239makeShaders(const RenderState& v, QString vert, QString frag);
240
246SCORE_PLUGIN_GFX_EXPORT
247QShader makeCompute(const RenderState& v, QString compt);
248
254struct SCORE_PLUGIN_GFX_EXPORT DefaultShaderMaterial
255{
256 void init(
257 RenderList& renderer, const std::vector<Port*>& input,
258 std::vector<Sampler>& samplers);
259
260 QRhiBuffer* buffer{};
261 int size{};
262};
263
267SCORE_PLUGIN_GFX_EXPORT
268QSize resizeTextureSize(QSize img, int min, int max) noexcept;
269
273SCORE_PLUGIN_GFX_EXPORT
274QImage resizeTexture(const QImage& img, int min, int max) noexcept;
275
276inline void copyMatrix(const QMatrix4x4& mat, float* ptr) noexcept
277{
278 memcpy(ptr, mat.constData(), sizeof(float) * 16);
279}
280inline void copyMatrix(const QMatrix3x3& mat, float* ptr) noexcept
281{
282 memcpy(ptr, mat.constData(), sizeof(float) * 9);
283}
284
288SCORE_PLUGIN_GFX_EXPORT
289QSizeF computeScale(score::gfx::ScaleMode mode, QSizeF viewport, QSizeF texture);
290}
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
QShader makeCompute(const RenderState &v, QString compute)
Compile a compute shader.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:399
QRhiShaderResourceBindings * createDefaultBindings(const RenderList &renderer, const TextureRenderTarget &rt, QRhiBuffer *processUBO, QRhiBuffer *materialUBO, const std::vector< Sampler > &samplers, std::span< QRhiShaderResourceBinding > additionalBindings)
Create bindings following the score conventions for shaders and materials.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:295
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:536
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples)
Create a render target from a texture.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:10
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:185
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition Scale.hpp:10
QSizeF computeScale(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:546
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:372
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:485
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:255
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:66
Image data and metadata.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:146
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:93
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:48
void * value
Pointer to the corresponding data.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:53
score::gfx::Node * node
Parent node of the port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:50
Types type
Type of the value.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:56
std::vector< Edge * > edges
Edges connected to that port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:59
Global state associated to a rendering context.
Definition RenderState.hpp:31
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:111