v2.0.0
Loading...
Searching...
No Matches
brainrenderer.h
Go to the documentation of this file.
1//=============================================================================================================
30
31#ifndef BRAINRENDERER_H
32#define BRAINRENDERER_H
33
34//=============================================================================================================
35// INCLUDES
36//=============================================================================================================
37
38#include "../disp3D_global.h"
39
40#include "../core/rendertypes.h"
41
42#include <QMatrix4x4>
43#include <QVector3D>
44#include <memory>
45
46//=============================================================================================================
47// FORWARD DECLARATIONS
48//=============================================================================================================
49
50class QRhi;
51class QRhiCommandBuffer;
52class QRhiRenderTarget;
53class QRhiRenderPassDescriptor;
54class QRhiResourceUpdateBatch;
55class QRhiTexture;
56class QRhiRenderBuffer;
57class QRhiTextureRenderTarget;
58
59namespace DISP3DLIB
60{
61
62class BrainSurface;
63class DipoleObject;
64class NetworkObject;
65class PolylineObject;
66class VideoOverlay;
67class SliceObject;
68
69//=============================================================================================================
76{
77public:
78 //=========================================================================================================
83
84 //=========================================================================================================
89
90 // ShaderMode is defined in core/rendertypes.h for lightweight inclusion.
91 // These aliases preserve backward compatibility.
97 static constexpr ShaderMode XRay = DISP3DLIB::XRay;
99
109 {
110 QMatrix4x4 mvp;
111 QVector3D cameraPos;
112 QVector3D lightDir;
114 float overlayMode = 0.0f; // 0=FsSurface, 1=FsAnnotation, 2=Scientific, 3=STC
115
116 // Viewport rectangle (floating-point, pixels)
117 float viewportX = 0, viewportY = 0, viewportW = 0, viewportH = 0;
118 // Scissor rectangle (integer, pixels)
119 int scissorX = 0, scissorY = 0, scissorW = 0, scissorH = 0;
120 };
121
122 //=========================================================================================================
131 void initialize(QRhi* rhi, QRhiRenderPassDescriptor* rp, int sampleCount);
132
133 //=========================================================================================================
150 void ensureRenderTargets(QRhi* rhi, QRhiTexture* colorTex, const QSize& pixelSize);
151
152 //=========================================================================================================
156 QRhiRenderTarget* rtClear() const;
157
161 QRhiRenderTarget* rtPreserve() const;
162
163 //=========================================================================================================
169 void beginFrame(QRhiCommandBuffer* cb);
170
171 //=========================================================================================================
178 void beginPreservingPass(QRhiCommandBuffer* cb);
179
180 //=========================================================================================================
187 void updateSceneUniforms(QRhi* rhi, const SceneData& data);
188
189 //=========================================================================================================
199 void renderSurface(QRhiCommandBuffer* cb, QRhi* rhi, const SceneData& data, BrainSurface* surface, ShaderMode mode);
200
201 //=========================================================================================================
214 int prepareSurfaceDraw(QRhiResourceUpdateBatch* u, const SceneData& data, BrainSurface* surface);
215
228 void issueSurfaceDraw(QRhiCommandBuffer* cb, BrainSurface* surface, ShaderMode mode, int uniformOffset);
229
230 //=========================================================================================================
231 // ── WORKAROUND(QRhi-GLES2) ──────────────────────────────────────────
232 // The Qt QRhi GLES2/WebGL backend has a bug where only the first
233 // drawIndexed() per render pass produces visible output. On WASM we
234 // work around this by merging all brain surfaces into a single VBO/IBO
235 // and issuing one drawIndexed(). When the upstream bug is fixed these
236 // two methods (and the merged buffers in Impl) can be removed.
237 //
251 void prepareMergedSurfaces(QRhi* rhi, QRhiResourceUpdateBatch* u,
252 const QVector<BrainSurface*>& surfaces,
253 const QString& groupName = QStringLiteral("default"));
254
262 void invalidateMergedGroup(const QString& groupName = QStringLiteral("default"));
263
272 bool hasMergedContent(const QString& groupName) const;
273
284 void drawMergedSurfaces(QRhiCommandBuffer* cb, QRhi* rhi,
285 const SceneData& data, ShaderMode mode,
286 const QString& groupName = QStringLiteral("default"));
287
288 //=========================================================================================================
297 void renderDipoles(QRhiCommandBuffer* cb, QRhi* rhi, const SceneData& data, DipoleObject* dipoles);
298
299 //=========================================================================================================
309 void renderNetwork(QRhiCommandBuffer* cb, QRhi* rhi, const SceneData& data, NetworkObject* network);
310
311 //=========================================================================================================
320 void renderPolyline(QRhiCommandBuffer* cb, QRhi* rhi, const SceneData& data, PolylineObject* polyline);
321
322 //=========================================================================================================
334 void prepareVideoOverlay(QRhi* rhi,
335 QRhiResourceUpdateBatch* u,
336 DISP3DLIB::VideoOverlay* overlay);
337
338 //=========================================================================================================
349 void renderVideoOverlay(QRhiCommandBuffer* cb, QRhi* rhi,
350 const SceneData& data,
351 DISP3DLIB::VideoOverlay* overlay);
352
362 void renderVideoOverlayOnSurface(QRhiCommandBuffer* cb, QRhi* rhi,
363 const SceneData& data,
365 BrainSurface* surface);
366
367 //=========================================================================================================
379 void prepareSlice(QRhi* rhi,
380 QRhiResourceUpdateBatch* u,
382 int slotIndex);
383
384 //=========================================================================================================
396 int prepareSliceDraw(QRhiResourceUpdateBatch* u,
397 const SceneData& data,
398 int slotIndex);
399
400 //=========================================================================================================
411 void issueSliceDraw(QRhiCommandBuffer* cb,
412 int slotIndex,
413 int uniformOffset);
414
415 //=========================================================================================================
421 void endPass(QRhiCommandBuffer* cb);
422
423private:
425 struct Impl;
426 std::unique_ptr<Impl> d;
427};
428
429} // namespace DISP3DLIB
430
431#endif // BRAINRENDERER_H
Library export/import macros and namespace marker for the disp3D library.
#define DISP3DSHARED_EXPORT
Lightweight render-related enums (ShaderMode, VisualizationMode) shared across disp3D.
3-D brain visualisation using the Qt RHI rendering backend.
Renderable cortical surface mesh with per-vertex color, curvature data, and GPU buffer management.
Renderable dipole arrow set with instanced GPU rendering for QRhi.
Renderable network visualization for QRhi.
Connected line segments through an ordered list of points.
Data model for a single 2-D MRI volume slice.
Definition sliceobject.h:82
Camera-facing textured quad rendered at a focus point in the 3-D scene.
void updateSceneUniforms(QRhi *rhi, const SceneData &data)
static constexpr ShaderMode Dipole
void renderVideoOverlay(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DISP3DLIB::VideoOverlay *overlay)
void renderVideoOverlayOnSurface(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DISP3DLIB::VideoOverlay *overlay, BrainSurface *surface)
void prepareSlice(QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::SliceObject *slice, int slotIndex)
void ensureRenderTargets(QRhi *rhi, QRhiTexture *colorTex, const QSize &pixelSize)
int prepareSliceDraw(QRhiResourceUpdateBatch *u, const SceneData &data, int slotIndex)
void issueSliceDraw(QRhiCommandBuffer *cb, int slotIndex, int uniformOffset)
void renderDipoles(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DipoleObject *dipoles)
static constexpr ShaderMode ShowNormals
QRhiRenderTarget * rtPreserve() const
void initialize(QRhi *rhi, QRhiRenderPassDescriptor *rp, int sampleCount)
void prepareMergedSurfaces(QRhi *rhi, QRhiResourceUpdateBatch *u, const QVector< BrainSurface * > &surfaces, const QString &groupName=QStringLiteral("default"))
void issueSurfaceDraw(QRhiCommandBuffer *cb, BrainSurface *surface, ShaderMode mode, int uniformOffset)
QRhiRenderTarget * rtClear() const
bool hasMergedContent(const QString &groupName) const
void invalidateMergedGroup(const QString &groupName=QStringLiteral("default"))
static constexpr ShaderMode Standard
void endPass(QRhiCommandBuffer *cb)
int prepareSurfaceDraw(QRhiResourceUpdateBatch *u, const SceneData &data, BrainSurface *surface)
static constexpr ShaderMode Holographic
static constexpr ShaderMode Anatomical
void renderSurface(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, BrainSurface *surface, ShaderMode mode)
void prepareVideoOverlay(QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::VideoOverlay *overlay)
static constexpr ShaderMode XRay
void beginPreservingPass(QRhiCommandBuffer *cb)
void renderNetwork(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, NetworkObject *network)
void renderPolyline(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, PolylineObject *polyline)
void drawMergedSurfaces(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, ShaderMode mode, const QString &groupName=QStringLiteral("default"))
DISP3DLIB::ShaderMode ShaderMode
void beginFrame(QRhiCommandBuffer *cb)
Aggregated GPU resources and render state for the 3-D brain visualization scene.