Loading...
Searching...
No Matches
ModelSceneDrawer.hpp
1#pragma once
2#include <Gfx/Graph/NodeRenderer.hpp>
3
4#include <ossia/dataflow/geometry_port.hpp>
5
6#include <QMatrix4x4>
7#include <QVector3D>
8
9#include <cstring>
10
11namespace score::gfx
12{
15{
17 QMatrix4x4 model;
18 QMatrix4x4 view;
19 QVector3D eye;
21 bool changed{};
22};
23
29{
30public:
31 virtual ~ModelSceneDrawer() = default;
32
34 virtual bool setScene(const ossia::scene_spec& scene) = 0;
36 virtual bool active() const noexcept = 0;
38 virtual const ossia::aabb& bounds() const noexcept = 0;
39
41 virtual void update(
42 RenderList& renderer, QRhiResourceUpdateBatch& res, PassMap& passes,
43 QRhiBuffer* processUBO, QRhiBuffer* cameraUBO, const ModelSceneView& view)
44 = 0;
45 virtual void draw(RenderList& renderer, QRhiCommandBuffer& cb, Edge& edge) = 0;
46
48 virtual bool hasLines() const noexcept = 0;
50 virtual void drawLines(
51 RenderList& renderer, QRhiCommandBuffer& cb, Edge& edge,
52 QRhiGraphicsPipeline* lines, QRhiShaderResourceBindings* srb)
53 = 0;
54
57 virtual void release() = 0;
58};
59
62inline ossia::aabb geometryPositionBounds(const ossia::geometry& g) noexcept
63{
64 ossia::aabb box{{1.f, 1.f, 1.f}, {-1.f, -1.f, -1.f}};
65 using attribute = ossia::geometry::attribute;
66 const attribute* attr{};
67 for(const auto& a : g.attributes)
68 if(a.semantic == ossia::attribute_semantic::position)
69 {
70 attr = &a;
71 break;
72 }
73 if(!attr)
74 for(const auto& a : g.attributes)
75 if(a.location == 0)
76 {
77 attr = &a;
78 break;
79 }
80 if(!attr || (attr->format != attribute::float3 && attr->format != attribute::float4)
81 || attr->binding < 0 || attr->binding >= int(g.input.size())
82 || attr->binding >= int(g.bindings.size()))
83 return box;
84 const auto& in = g.input[attr->binding];
85 if(in.buffer < 0 || in.buffer >= int(g.buffers.size()))
86 return box;
87 const auto* cpu = ossia::get_if<ossia::geometry::cpu_buffer>(&g.buffers[in.buffer].data);
88 if(!cpu || !cpu->raw_data)
89 return box;
90 const int64_t element = attr->format == attribute::float3 ? 12 : 16;
91 const int64_t stride = g.bindings[attr->binding].byte_stride > 0
92 ? g.bindings[attr->binding].byte_stride
93 : element;
94 const int64_t first = in.byte_offset + attr->byte_offset;
95 const auto* bytes = static_cast<const char*>(cpu->raw_data.get());
96 for(int64_t i = 0; i < g.vertices; i++)
97 {
98 const int64_t at = first + i * stride;
99 if(at < 0 || at + 12 > cpu->byte_size)
100 break;
101 float p[3];
102 std::memcpy(p, bytes + at, sizeof(p));
103 box.expand(p[0], p[1], p[2]);
104 }
105 return box;
106}
107}
Definition ModelSceneDrawer.hpp:29
virtual void update(RenderList &renderer, QRhiResourceUpdateBatch &res, PassMap &passes, QRhiBuffer *processUBO, QRhiBuffer *cameraUBO, const ModelSceneView &view)=0
Once the passes of the renderer exist for the frame.
virtual bool hasLines() const noexcept=0
Whether there are lines to draw with the guides.
virtual bool setScene(const ossia::scene_spec &scene)=0
The scene the renderer received; returns whether it is another one.
virtual bool active() const noexcept=0
Whether it draws the scene rather than the renderer its first geometry.
virtual const ossia::aabb & bounds() const noexcept=0
The bounds of what is drawn, in the space of the scene.
virtual void drawLines(RenderList &renderer, QRhiCommandBuffer &cb, Edge &edge, QRhiGraphicsPipeline *lines, QRhiShaderResourceBindings *srb)=0
With the line pipeline of the guides: world-space positions and colours.
List of nodes to be rendered to an output.
Definition RenderList.hpp:36
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
ossia::aabb geometryPositionBounds(const ossia::geometry &g) noexcept
Definition ModelSceneDrawer.hpp:62
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:236
What a frame of a Model Display shows its scene with.
Definition ModelSceneDrawer.hpp:15
bool changed
Raised whenever one of the above changed.
Definition ModelSceneDrawer.hpp:21
QMatrix4x4 model
The model matrix of the node, applied over the transforms of the scene.
Definition ModelSceneDrawer.hpp:17
Definition Uniforms.hpp:8