96 ossia::small_vector<BufferView, 2> buffers;
103 QRhiBuffer* indirectDrawBuffer{};
109 quint32 instanceMultiplier{1};
110 bool useIndirectDraw{
false};
111 bool indirectDrawIndexed{
false};
112 bool gpuIndirectSupported{
false};
114 bool baseInstanceSupported{
true};
115 quint32 indirectDrawOffset{0};
116 quint32 indirectDrawCount{1};
117 quint32 indirectDrawStride{0};
123 static constexpr quint32 indirect_record_stride = 5 *
sizeof(uint32_t);
132 void enableIndirectDraw(
133 QRhiBuffer* buffer,
bool indexed, int64_t byte_size,
134 quint32 byte_offset = 0) noexcept
136 indirectDrawBuffer = buffer;
137 useIndirectDraw =
true;
138 indirectDrawIndexed = indexed;
139 indirectDrawOffset = byte_offset;
140 indirectDrawStride = indirect_record_stride;
141 indirectDrawCount = quint32(byte_size / indirect_record_stride);
142 if(indirectDrawCount == 0)
143 indirectDrawCount = 1;
159 QRhiBuffer* indirectCountBuffer{};
160 quint32 indirectCountOffset{0};
166 QRhiBuffer* clampedIndirectBuffer{};
167 bool gpuIndirectCountSupported{
false};
170 bool gpuIndirectMultiSupported{
false};
177 ossia::small_vector<ossia::geometry::draw_command, 0> cpuDrawCommands;
182#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
183 QRhiReadbackResult readbackResult;
186 QRhiReadbackResult countReadbackResult;
188 QRhiBufferReadbackResult readbackResult;
189 QRhiBufferReadbackResult countReadbackResult;
195struct SCORE_PLUGIN_GFX_EXPORT
Mesh
203 HasPosition = SCORE_FLAG(1),
204 HasTexCoord = SCORE_FLAG(2),
205 HasColor = SCORE_FLAG(3),
206 HasNormals = SCORE_FLAG(4),
207 HasTangents = SCORE_FLAG(5),
209 using Flags = QFlags<Flag>;
211 [[nodiscard]]
virtual Flags flags()
const noexcept = 0;
213 [[nodiscard]]
virtual MeshBuffers init(QRhi& rhi)
const noexcept = 0;
216 update(QRhi& rhi,
MeshBuffers& bufs, QRhiResourceUpdateBatch& cb)
const noexcept
218 virtual void preparePipeline(QRhiGraphicsPipeline& pip)
const noexcept = 0;
222 [[nodiscard]]
virtual bool hasGeometry()
const noexcept {
return true; }
223 virtual void draw(
const MeshBuffers& bufs, QRhiCommandBuffer& cb)
const noexcept = 0;
234 virtual const ossia::
geometry* semanticGeometry() const noexcept {
return nullptr; }
236 ossia::geometry_filter_list_ptr filters;
238 std::atomic_int64_t dirtyGeometryIndex{-1};
240 bool hasGeometryChanged(int64_t& renderer)
const noexcept
242 int64_t res = dirtyGeometryIndex.load(std::memory_order_acquire);
255 Mesh(
const Mesh&) =
delete;
256 Mesh(Mesh&&) =
delete;
257 Mesh& operator=(
const Mesh&) =
delete;
258 Mesh& operator=(Mesh&&) =
delete;
266 [[nodiscard]]
virtual MeshBuffers init(QRhi& rhi)
const noexcept override;
268 QRhi& rhi,
MeshBuffers& bufs, QRhiResourceUpdateBatch& cb)
const noexcept override;
269 void preparePipeline(QRhiGraphicsPipeline& pip)
const noexcept override;
270 void draw(
const MeshBuffers& bufs, QRhiCommandBuffer& cb)
const noexcept override;
272 setupBindings(
const MeshBuffers& bufs, QRhiCommandBuffer& cb)
const noexcept = 0;
274 using pip = QRhiGraphicsPipeline;
275 pip::Topology topology = pip::Topology::TriangleStrip;
276 pip::CullMode cullMode = pip::CullMode::None;
277 pip::FrontFace frontFace = pip::FrontFace::CW;
279 ossia::small_vector<QRhiVertexInputBinding, 2> vertexBindings;
280 ossia::small_vector<QRhiVertexInputAttribute, 2> vertexAttributes;
282 std::span<const float> vertexArray;
368 static const constexpr float data[] = {
369 -1, -1, +1, -1, -1, +1, +1, +1,
371 0, 0, 1, 0, 0, 1, 1, 1};
373 static const constexpr float flipped_y_data[] = {
374 -1, -1, +1, -1, -1, +1, +1, +1,
376 0, 1, 1, 1, 0, 0, 1, 0};
381 setupBindings(
const MeshBuffers& bufs, QRhiCommandBuffer& cb)
const noexcept override;
void drawMeshWithOptionalIndirect(const Mesh &mesh, const MeshBuffers &bufs, QRhiCommandBuffer &cb) noexcept
Draw a mesh, using indirect multi-draw when available in MeshBuffers.
Definition Mesh.cpp:321
A mesh with positions and texture coordinates.
Definition Mesh.hpp:319
A quad mesh with positions and texture coordinates.
Definition Mesh.hpp:367
A triangle mesh with positions and texture coordinates.
Definition Mesh.hpp:346