2#include <Process/Dataflow/CableData.hpp>
4#include <Gfx/Graph/Mesh.hpp>
5#include <Gfx/Graph/RenderState.hpp>
6#include <Gfx/Graph/Scale.hpp>
7#include <Gfx/Graph/Uniforms.hpp>
9#include <ossia/detail/hash_map.hpp>
10#include <ossia/detail/small_flat_map.hpp>
12#include <score_plugin_gfx_export.h>
28 QRhiSampler* sampler{};
29 QRhiTexture* texture{};
37 ossia::hash_map<RenderList*, Sampler> samplers;
39 std::vector<float> data;
81 source->
edges.push_back(
this);
82 sink->
edges.push_back(
this);
87 if(
auto it = std::find(source->
edges.begin(), source->
edges.end(),
this);
88 it != source->
edges.end())
89 source->
edges.erase(it);
90 if(
auto it = std::find(sink->
edges.begin(), sink->
edges.end(),
this);
91 it != sink->
edges.end())
92 sink->
edges.erase(it);
97 Process::CableType type{};
105 QRhiGraphicsPipeline* pipeline{};
106 QRhiShaderResourceBindings* srb{};
123 QRhiTexture* texture{};
124 std::vector<QRhiTexture*> additionalColorTextures;
125 QRhiRenderBuffer* colorRenderBuffer{};
126 QRhiRenderBuffer* depthRenderBuffer{};
127 QRhiTexture* depthTexture{};
128 QRhiTexture* msDepthTexture{};
129 QRhiRenderPassDescriptor* renderPass{};
130 QRhiRenderTarget* renderTarget{};
132 operator bool()
const noexcept {
return texture !=
nullptr; }
134 int colorAttachmentCount()
const noexcept
136 return texture ? 1 + (int)additionalColorTextures.size() : 0;
146 int sampleCount()
const noexcept
149 return renderTarget->sampleCount();
150 if(colorRenderBuffer)
151 return colorRenderBuffer->sampleCount();
153 return texture->sampleCount();
164 for(
auto* t : additionalColorTextures)
166 additionalColorTextures.clear();
168 delete colorRenderBuffer;
169 colorRenderBuffer =
nullptr;
171 delete depthRenderBuffer;
172 depthRenderBuffer =
nullptr;
175 depthTexture =
nullptr;
177 delete msDepthTexture;
178 msDepthTexture =
nullptr;
181 renderPass =
nullptr;
184 renderTarget =
nullptr;
195 std::vector<QImage> frames;
201SCORE_PLUGIN_GFX_EXPORT
210SCORE_PLUGIN_GFX_EXPORT
212 const RenderState& state, QRhiTexture::Format fmt, QSize sz,
int samples,
bool depth,
213 bool samplableDepth =
false, QRhiTexture::Flags flags = {});
221SCORE_PLUGIN_GFX_EXPORT
223 const RenderState& state,
224 std::span<QRhiTexture* const> colorTextures,
225 QRhiTexture* depthTexture,
228SCORE_PLUGIN_GFX_EXPORT
229void replaceBuffer(QRhiShaderResourceBindings&,
int binding, QRhiBuffer* newBuffer);
230SCORE_PLUGIN_GFX_EXPORT
231void replaceSampler(QRhiShaderResourceBindings&,
int binding, QRhiSampler* newSampler);
232SCORE_PLUGIN_GFX_EXPORT
233void replaceTexture(QRhiShaderResourceBindings&,
int binding, QRhiTexture* newTexture);
235SCORE_PLUGIN_GFX_EXPORT
237 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiBuffer* newBuffer);
238SCORE_PLUGIN_GFX_EXPORT
240 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiSampler* newSampler);
241SCORE_PLUGIN_GFX_EXPORT
243 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiTexture* newTexture);
248SCORE_PLUGIN_GFX_EXPORT
250 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler);
255SCORE_PLUGIN_GFX_EXPORT
257 QRhiShaderResourceBindings&, QRhiSampler* sampler, QRhiTexture* newTexture);
262SCORE_PLUGIN_GFX_EXPORT
264 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler,
265 QRhiTexture* newTexture);
270SCORE_PLUGIN_GFX_EXPORT
272 QRhiShaderResourceBindings& srb, QRhiTexture* old_tex, QRhiTexture* new_tex);
276SCORE_PLUGIN_GFX_EXPORT
278 const RenderList& renderer,
const TextureRenderTarget& rt, QRhiBuffer* processUBO,
279 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
280 std::span<QRhiShaderResourceBinding> additionalBindings = {});
290SCORE_PLUGIN_GFX_EXPORT
292 QRhiGraphicsPipeline& pip,
const QShader& vertexShader,
293 const ossia::geometry& geom);
298SCORE_PLUGIN_GFX_EXPORT
299Pipeline buildPipeline(
300 const RenderList& renderer,
const Mesh& mesh,
const QShader& vertexS,
301 const QShader& fragmentS,
const TextureRenderTarget& rt, QRhiBuffer* processUBO,
302 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
303 std::span<QRhiShaderResourceBinding> additionalBindings = {});
310SCORE_PLUGIN_GFX_EXPORT
311std::pair<QShader, QShader>
312makeShaders(
const RenderState& v, QString vert, QString frag);
319SCORE_PLUGIN_GFX_EXPORT
320QShader
makeCompute(
const RenderState& v, QString compt);
330 RenderList& renderer,
const std::vector<Port*>& input,
331 ossia::small_vector<Sampler, 8>& samplers);
333 QRhiBuffer* buffer{};
340SCORE_PLUGIN_GFX_EXPORT
346SCORE_PLUGIN_GFX_EXPORT
347QImage
resizeTexture(
const QImage& img,
int min,
int max)
noexcept;
349inline void copyMatrix(
const QMatrix4x4& mat,
float* ptr)
noexcept
351 memcpy(ptr, mat.constData(),
sizeof(
float) * 16);
353inline void copyMatrix(
const QMatrix3x3& mat,
float* ptr)
noexcept
355 memcpy(ptr, mat.constData(),
sizeof(
float) * 9);
361SCORE_PLUGIN_GFX_EXPORT
367SCORE_PLUGIN_GFX_EXPORT
375 QRhiResourceUpdateBatch* ub
382#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
383 ub->updateDynamicBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
385 ub->updateDynamicBuffer(buf, offset, bytesize, data);
390 QRhiResourceUpdateBatch* ub
396#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
397 ub->updateDynamicBuffer(buf, offset, std::move(b));
399 ub->updateDynamicBuffer(buf, offset, b.size(), b.data());
407 QRhiResourceUpdateBatch* ub
414#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
415 ub->uploadStaticBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
417 ub->uploadStaticBuffer(buf, offset, bytesize, data);
422 QRhiResourceUpdateBatch* ub
428#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
429 ub->uploadStaticBuffer(buf, offset, std::move(b));
431 ub->uploadStaticBuffer(buf, offset, b.size(), b.data());
435SCORE_PLUGIN_GFX_EXPORT
436std::vector<Sampler> initInputSamplers(
437 const score::gfx::Node& node, RenderList& renderer,
const std::vector<Port*>& ports);
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:74
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)
Compute the scale to apply to a texture rendered to a quad the size of viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:861
void updateDynamicBufferWithStoredData(QRhiResourceUpdateBatch *ub, QRhiBuffer *buf, int offset, int64_t bytesize, const char *data)
Schedule a Dynamic buffer update when we can guarantee the buffer outlives the frame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:374
bool remapPipelineVertexInputs(QRhiGraphicsPipeline &pip, const QShader &vertexShader, const ossia::geometry &geom)
Remap a pipeline's vertex input layout using semantic matching.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:436
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:570
QShader makeCompute(const RenderState &v, QString compute)
Compile a compute shader.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:674
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples, bool depth, bool samplableDepth)
Create a render target from a texture.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:11
void uploadStaticBufferWithStoredData(QRhiResourceUpdateBatch *ub, QRhiBuffer *buf, int offset, int64_t bytesize, const char *data)
Schedule a Static buffer update when we can guarantee the buffer outlives the frame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:406
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:811
QSizeF computeScaleForMeshSizing(ScaleMode mode, QSizeF viewport, QSizeF texture)
Compute the scale to apply to a texture so that it fits in a GL viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:821
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:364
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:647
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:760
Data model for audio data being sent to the GPU.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:36
Utility to represent a shader material following score conventions.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:328
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:75
Image data and metadata.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:193
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:104
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:54
void * value
Pointer to the corresponding data.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:59
score::gfx::Node * node
Parent node of the port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:56
Types type
Type of the value.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:62
std::vector< Edge * > edges
Edges connected to that port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:68
Flag flags
Optional setting flags.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:65
Global state associated to a rendering context.
Definition RenderState.hpp:37
Stores a sampler and the texture currently associated with it.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:27
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:122