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>
31 QRhiSampler* sampler{};
32 QRhiTexture* texture{};
40 ossia::hash_map<RenderList*, Sampler> samplers;
42 std::vector<float> data;
84 source->
edges.push_back(
this);
85 sink->
edges.push_back(
this);
90 if(
auto it = std::find(source->
edges.begin(), source->
edges.end(),
this);
91 it != source->
edges.end())
92 source->
edges.erase(it);
93 if(
auto it = std::find(sink->
edges.begin(), sink->
edges.end(),
this);
94 it != sink->
edges.end())
95 sink->
edges.erase(it);
100 Process::CableType type{};
108 QRhiGraphicsPipeline* pipeline{};
109 QRhiShaderResourceBindings* srb{};
126 QRhiTexture* texture{};
127 std::vector<QRhiTexture*> additionalColorTextures;
128 QRhiRenderBuffer* colorRenderBuffer{};
129 QRhiRenderBuffer* depthRenderBuffer{};
130 QRhiTexture* depthTexture{};
131 QRhiTexture* msDepthTexture{};
132 QRhiRenderPassDescriptor* renderPass{};
133 QRhiRenderTarget* renderTarget{};
135 operator bool()
const noexcept {
return texture !=
nullptr; }
137 int colorAttachmentCount()
const noexcept
139 return texture ? 1 + (int)additionalColorTextures.size() : 0;
149 int sampleCount()
const noexcept
152 return renderTarget->sampleCount();
153 if(colorRenderBuffer)
154 return colorRenderBuffer->sampleCount();
156 return texture->sampleCount();
167 for(
auto* t : additionalColorTextures)
169 additionalColorTextures.clear();
171 delete colorRenderBuffer;
172 colorRenderBuffer =
nullptr;
174 delete depthRenderBuffer;
175 depthRenderBuffer =
nullptr;
178 depthTexture =
nullptr;
180 delete msDepthTexture;
181 msDepthTexture =
nullptr;
184 renderPass =
nullptr;
187 renderTarget =
nullptr;
198 std::vector<QImage> frames;
204SCORE_PLUGIN_GFX_EXPORT
213SCORE_PLUGIN_GFX_EXPORT
215 const RenderState& state, QRhiTexture::Format fmt, QSize sz,
int samples,
bool depth,
216 bool samplableDepth =
false, QRhiTexture::Flags flags = {});
224SCORE_PLUGIN_GFX_EXPORT
226 const RenderState& state,
227 std::span<QRhiTexture* const> colorTextures,
228 QRhiTexture* depthTexture,
231SCORE_PLUGIN_GFX_EXPORT
232void replaceBuffer(QRhiShaderResourceBindings&,
int binding, QRhiBuffer* newBuffer);
233SCORE_PLUGIN_GFX_EXPORT
234void replaceSampler(QRhiShaderResourceBindings&,
int binding, QRhiSampler* newSampler);
235SCORE_PLUGIN_GFX_EXPORT
236void replaceTexture(QRhiShaderResourceBindings&,
int binding, QRhiTexture* newTexture);
238SCORE_PLUGIN_GFX_EXPORT
240 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiBuffer* newBuffer);
241SCORE_PLUGIN_GFX_EXPORT
243 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiSampler* newSampler);
244SCORE_PLUGIN_GFX_EXPORT
246 std::vector<QRhiShaderResourceBinding>&,
int binding, QRhiTexture* newTexture);
251SCORE_PLUGIN_GFX_EXPORT
253 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler);
258SCORE_PLUGIN_GFX_EXPORT
260 QRhiShaderResourceBindings&, QRhiSampler* sampler, QRhiTexture* newTexture);
265SCORE_PLUGIN_GFX_EXPORT
267 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler,
268 QRhiTexture* newTexture);
273SCORE_PLUGIN_GFX_EXPORT
275 QRhiShaderResourceBindings& srb, QRhiTexture* old_tex, QRhiTexture* new_tex);
279SCORE_PLUGIN_GFX_EXPORT
281 const RenderList& renderer,
const TextureRenderTarget& rt, QRhiBuffer* processUBO,
282 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
283 std::span<QRhiShaderResourceBinding> additionalBindings = {});
293SCORE_PLUGIN_GFX_EXPORT
295 QRhiGraphicsPipeline& pip,
const QShader& vertexShader,
296 const ossia::geometry& geom);
301SCORE_PLUGIN_GFX_EXPORT
302Pipeline buildPipeline(
303 const RenderList& renderer,
const Mesh& mesh,
const QShader& vertexS,
304 const QShader& fragmentS,
const TextureRenderTarget& rt, QRhiBuffer* processUBO,
305 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
306 std::span<QRhiShaderResourceBinding> additionalBindings = {});
313SCORE_PLUGIN_GFX_EXPORT
314std::pair<QShader, QShader>
315makeShaders(
const RenderState& v, QString vert, QString frag);
322SCORE_PLUGIN_GFX_EXPORT
323QShader
makeCompute(
const RenderState& v, QString compt);
333 RenderList& renderer,
const std::vector<Port*>& input,
334 ossia::small_vector<Sampler, 8>& samplers);
336 QRhiBuffer* buffer{};
343SCORE_PLUGIN_GFX_EXPORT
349SCORE_PLUGIN_GFX_EXPORT
350QImage
resizeTexture(
const QImage& img,
int min,
int max)
noexcept;
352inline void copyMatrix(
const QMatrix4x4& mat,
float* ptr)
noexcept
354 memcpy(ptr, mat.constData(),
sizeof(
float) * 16);
356inline void copyMatrix(
const QMatrix3x3& mat,
float* ptr)
noexcept
358 memcpy(ptr, mat.constData(),
sizeof(
float) * 9);
364SCORE_PLUGIN_GFX_EXPORT
370SCORE_PLUGIN_GFX_EXPORT
378 QRhiResourceUpdateBatch* ub
385#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
386 ub->updateDynamicBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
388 ub->updateDynamicBuffer(buf, offset, bytesize, data);
393 QRhiResourceUpdateBatch* ub
399#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
400 ub->updateDynamicBuffer(buf, offset, std::move(b));
402 ub->updateDynamicBuffer(buf, offset, b.size(), b.data());
410 QRhiResourceUpdateBatch* ub
417#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
418 ub->uploadStaticBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
420 ub->uploadStaticBuffer(buf, offset, bytesize, data);
425 QRhiResourceUpdateBatch* ub
431#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
432 ub->uploadStaticBuffer(buf, offset, std::move(b));
434 ub->uploadStaticBuffer(buf, offset, b.size(), b.data());
438SCORE_PLUGIN_GFX_EXPORT
439std::vector<Sampler> initInputSamplers(
440 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:866
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:377
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:441
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:575
QShader makeCompute(const RenderState &v, QString compute)
Compile a compute shader.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:679
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:16
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:409
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:816
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:826
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:369
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:652
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:765
Data model for audio data being sent to the GPU.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:39
Utility to represent a shader material following score conventions.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:331
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:78
Image data and metadata.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:196
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:107
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:57
void * value
Pointer to the corresponding data.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:62
score::gfx::Node * node
Parent node of the port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:59
Types type
Type of the value.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:65
std::vector< Edge * > edges
Edges connected to that port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:71
Flag flags
Optional setting flags.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:68
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:30
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:125