Loading...
Searching...
No Matches
Mesh.hpp
1#pragma once
2#include <Process/ProcessFlags.hpp>
3
4#include <ossia/dataflow/geometry_port.hpp>
5#include <ossia/detail/small_vector.hpp>
6#include <span>
7
8#include <private/qrhi_p.h>
9
10#include <score_plugin_gfx_export.h>
11
12namespace score::gfx
13{
15{
16 QRhiBuffer* handle{};
17 int64_t byte_offset{};
18 int64_t byte_size{};
19
20 inline operator bool() const noexcept { return handle; }
21};
23{
24 ossia::small_vector<BufferView, 2> buffers;
25};
29struct SCORE_PLUGIN_GFX_EXPORT Mesh
30{
31public:
32 explicit Mesh();
33 virtual ~Mesh();
34
35 enum Flag
36 {
37 HasPosition = SCORE_FLAG(1),
38 HasTexCoord = SCORE_FLAG(2),
39 HasColor = SCORE_FLAG(3),
40 HasNormals = SCORE_FLAG(4),
41 HasTangents = SCORE_FLAG(5),
42 };
43 using Flags = QFlags<Flag>;
44
45 [[nodiscard]] virtual Flags flags() const noexcept = 0;
46
47 [[nodiscard]] virtual MeshBuffers init(QRhi& rhi) const noexcept = 0;
48
49 virtual void
50 update(QRhi& rhi, MeshBuffers& bufs, QRhiResourceUpdateBatch& cb) const noexcept
51 = 0;
52 virtual void preparePipeline(QRhiGraphicsPipeline& pip) const noexcept = 0;
53 virtual void draw(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept = 0;
54
56 virtual const char* defaultVertexShader() const noexcept = 0;
57
58 ossia::geometry_filter_list_ptr filters;
59
60 std::atomic_int64_t dirtyGeometryIndex{-1};
61
62 bool hasGeometryChanged(int64_t& renderer) const noexcept
63 {
64 int64_t res = dirtyGeometryIndex.load(std::memory_order_acquire);
65 if(renderer != res)
66 {
67 renderer = res;
68 return true;
69 }
70 return false;
71 }
72
73protected:
74 /*
75*/
76private:
77 Mesh(const Mesh&) = delete;
78 Mesh(Mesh&&) = delete;
79 Mesh& operator=(const Mesh&) = delete;
80 Mesh& operator=(Mesh&&) = delete;
81};
82
83Q_DECLARE_OPERATORS_FOR_FLAGS(Mesh::Flags);
84
85struct SCORE_PLUGIN_GFX_EXPORT BasicMesh : Mesh
86{
87 using Mesh::Mesh;
88 [[nodiscard]] virtual MeshBuffers init(QRhi& rhi) const noexcept override;
89 void update(
90 QRhi& rhi, MeshBuffers& bufs, QRhiResourceUpdateBatch& cb) const noexcept override;
91 void preparePipeline(QRhiGraphicsPipeline& pip) const noexcept override;
92 void draw(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
93 virtual void
94 setupBindings(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept = 0;
95
96 using pip = QRhiGraphicsPipeline;
97 pip::Topology topology = pip::Topology::TriangleStrip;
98 pip::CullMode cullMode = pip::CullMode::None;
99 pip::FrontFace frontFace = pip::FrontFace::CW;
100
101 ossia::small_vector<QRhiVertexInputBinding, 2> vertexBindings;
102 ossia::small_vector<QRhiVertexInputAttribute, 2> vertexAttributes;
103
104 std::span<const float> vertexArray;
105 int vertexCount{};
106};
107/*
108* @brief A dummy mesh for only accessing a gl_VertexId without caring about attributes
109*/
110struct SCORE_PLUGIN_GFX_EXPORT DummyMesh : BasicMesh
111{
112 explicit DummyMesh(int count);
113 [[nodiscard]] Flags flags() const noexcept override { return Flags{}; }
114 const char* defaultVertexShader() const noexcept override;
115 void
116 setupBindings(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
117 void draw(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
118};
119
123struct SCORE_PLUGIN_GFX_EXPORT PlainMesh : BasicMesh
124{
125 explicit PlainMesh(std::span<const float> vtx, int count);
126 [[nodiscard]] Flags flags() const noexcept override { return HasPosition; }
127 const char* defaultVertexShader() const noexcept override;
128 void
129 setupBindings(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
130};
131
135struct SCORE_PLUGIN_GFX_EXPORT TexturedMesh : BasicMesh
136{
137 explicit TexturedMesh(std::span<const float> vtx, int count);
138 [[nodiscard]] Flags flags() const noexcept override
139 {
140 return HasPosition | HasTexCoord;
141 }
142
143 const char* defaultVertexShader() const noexcept override;
144};
145
149struct SCORE_PLUGIN_GFX_EXPORT PlainTriangle final : PlainMesh
150{
151 static const constexpr float data[] = {-1, -1, 3, -1, -1, 3};
152
153 explicit PlainTriangle();
154 static const PlainTriangle& instance() noexcept;
155};
156
162struct SCORE_PLUGIN_GFX_EXPORT TexturedTriangle final : TexturedMesh
163{
164 static const constexpr float data[] = {// positions
165 -1, -1, 3, -1, -1, 3,
166 // tex coords
167 0, 0, 2, 0, 0, 2};
168 static const constexpr float flipped_y_data[] = {// positions
169 -1, -1, 3, -1, -1, 3,
170 // tex coords
171 0, 2, 2, 2, 0, 0};
172
173 explicit TexturedTriangle(bool flipped = false);
174
175 void
176 setupBindings(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
177};
178
183struct SCORE_PLUGIN_GFX_EXPORT TexturedQuad final : TexturedMesh
184{
185 static const constexpr float data[] = {// positions
186 -1, -1, +1, -1, -1, +1, +1, +1,
187 // tex coords
188 0, 0, 1, 0, 0, 1, 1, 1};
189
190 static const constexpr float flipped_y_data[] = {// positions
191 -1, -1, +1, -1, -1, +1, +1, +1,
192 // tex coords
193 0, 1, 1, 1, 0, 0, 1, 0};
194
195 explicit TexturedQuad(bool flipped = false);
196
197 void
198 setupBindings(const MeshBuffers& bufs, QRhiCommandBuffer& cb) const noexcept override;
199};
200
201}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
STL namespace.
Definition Mesh.hpp:86
Definition Mesh.hpp:15
Definition Mesh.hpp:111
Definition Mesh.hpp:23
Data model for meshes.
Definition Mesh.hpp:30
virtual const char * defaultVertexShader() const noexcept=0
A basic vertex shader that is going to work with this mesh.
A mesh with only position attributes.
Definition Mesh.hpp:124
A triangle mesh with only positions.
Definition Mesh.hpp:150
A mesh with positions and texture coordinates.
Definition Mesh.hpp:136
A quad mesh with positions and texture coordinates.
Definition Mesh.hpp:184
A triangle mesh with positions and texture coordinates.
Definition Mesh.hpp:163