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;
58class BrainSurface;
59class DipoleObject;
60class NetworkObject;
61namespace DISP3DLIB { class VideoOverlay; class SliceObject; }
62
63//=============================================================================================================
70{
71public:
72 //=========================================================================================================
77
78 //=========================================================================================================
83
84 // ShaderMode is defined in core/rendertypes.h for lightweight inclusion.
85 // These aliases preserve backward compatibility.
87 static constexpr ShaderMode Standard = ::Standard;
90 static constexpr ShaderMode Dipole = ::Dipole;
91 static constexpr ShaderMode XRay = ::XRay;
93
102 struct SceneData {
103 QMatrix4x4 mvp;
104 QVector3D cameraPos;
105 QVector3D lightDir;
107 float overlayMode = 0.0f; // 0=FsSurface, 1=FsAnnotation, 2=Scientific, 3=STC
108
109 // Viewport rectangle (floating-point, pixels)
110 float viewportX = 0, viewportY = 0, viewportW = 0, viewportH = 0;
111 // Scissor rectangle (integer, pixels)
112 int scissorX = 0, scissorY = 0, scissorW = 0, scissorH = 0;
113 };
114
115 //=========================================================================================================
124 void initialize(QRhi *rhi, QRhiRenderPassDescriptor *rp, int sampleCount);
125
126 //=========================================================================================================
143 void ensureRenderTargets(QRhi *rhi, QRhiTexture *colorTex, const QSize &pixelSize);
144
145 //=========================================================================================================
149 QRhiRenderTarget *rtClear() const;
150
154 QRhiRenderTarget *rtPreserve() const;
155
156 //=========================================================================================================
162 void beginFrame(QRhiCommandBuffer *cb);
163
164 //=========================================================================================================
171 void beginPreservingPass(QRhiCommandBuffer *cb);
172
173 //=========================================================================================================
179 void updateSceneUniforms(QRhi *rhi, const SceneData &data);
180
181 //=========================================================================================================
191 void renderSurface(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, BrainSurface *surface, ShaderMode mode);
192
193 //=========================================================================================================
206 int prepareSurfaceDraw(QRhiResourceUpdateBatch *u, const SceneData &data, BrainSurface *surface);
207
220 void issueSurfaceDraw(QRhiCommandBuffer *cb, BrainSurface *surface, ShaderMode mode, int uniformOffset);
221
222 //=========================================================================================================
223 // ── WORKAROUND(QRhi-GLES2) ──────────────────────────────────────────
224 // The Qt QRhi GLES2/WebGL backend has a bug where only the first
225 // drawIndexed() per render pass produces visible output. On WASM we
226 // work around this by merging all brain surfaces into a single VBO/IBO
227 // and issuing one drawIndexed(). When the upstream bug is fixed these
228 // two methods (and the merged buffers in Impl) can be removed.
229 //
243 void prepareMergedSurfaces(QRhi *rhi, QRhiResourceUpdateBatch *u,
244 const QVector<BrainSurface*> &surfaces,
245 const QString &groupName = QStringLiteral("default"));
246
254 void invalidateMergedGroup(const QString &groupName = QStringLiteral("default"));
255
264 bool hasMergedContent(const QString &groupName) const;
265
275 void drawMergedSurfaces(QRhiCommandBuffer *cb, QRhi *rhi,
276 const SceneData &data, ShaderMode mode,
277 const QString &groupName = QStringLiteral("default"));
278
279 //=========================================================================================================
288 void renderDipoles(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DipoleObject *dipoles);
289
290 //=========================================================================================================
300 void renderNetwork(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, NetworkObject *network);
301
302 //=========================================================================================================
314 void prepareVideoOverlay(QRhi *rhi,
315 QRhiResourceUpdateBatch *u,
316 DISP3DLIB::VideoOverlay *overlay);
317
318 //=========================================================================================================
329 void renderVideoOverlay(QRhiCommandBuffer *cb, QRhi *rhi,
330 const SceneData &data,
331 DISP3DLIB::VideoOverlay *overlay);
332
342 void renderVideoOverlayOnSurface(QRhiCommandBuffer *cb, QRhi *rhi,
343 const SceneData &data,
345 BrainSurface *surface);
346
347 //=========================================================================================================
359 void prepareSlice(QRhi *rhi,
360 QRhiResourceUpdateBatch *u,
362 int slotIndex);
363
364 //=========================================================================================================
376 int prepareSliceDraw(QRhiResourceUpdateBatch *u,
377 const SceneData &data,
378 int slotIndex);
379
380 //=========================================================================================================
391 void issueSliceDraw(QRhiCommandBuffer *cb,
392 int slotIndex,
393 int uniformOffset);
394
395 //=========================================================================================================
401 void endPass(QRhiCommandBuffer *cb);
402
403private:
405 struct Impl;
406 std::unique_ptr<Impl> d;
407};
408
409#endif // BRAINRENDERER_H
Lightweight render-related enums (ShaderMode, VisualizationMode) shared across disp3D.
Library export/import macros and namespace marker for the disp3D library.
#define DISP3DSHARED_EXPORT
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.
Data model for a single 2-D MRI volume slice.
Definition sliceobject.h:79
Camera-facing textured quad rendered at a focus point in the 3-D scene.
void prepareSlice(QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::SliceObject *slice, int slotIndex)
void endPass(QRhiCommandBuffer *cb)
int prepareSliceDraw(QRhiResourceUpdateBatch *u, const SceneData &data, int slotIndex)
void renderVideoOverlay(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DISP3DLIB::VideoOverlay *overlay)
static constexpr ShaderMode Anatomical
bool hasMergedContent(const QString &groupName) const
QRhiRenderTarget * rtClear() const
static constexpr ShaderMode Holographic
void renderNetwork(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, NetworkObject *network)
void beginPreservingPass(QRhiCommandBuffer *cb)
::ShaderMode ShaderMode
static constexpr ShaderMode ShowNormals
void issueSurfaceDraw(QRhiCommandBuffer *cb, BrainSurface *surface, ShaderMode mode, int uniformOffset)
QRhiRenderTarget * rtPreserve() const
void drawMergedSurfaces(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, ShaderMode mode, const QString &groupName=QStringLiteral("default"))
int prepareSurfaceDraw(QRhiResourceUpdateBatch *u, const SceneData &data, BrainSurface *surface)
void renderSurface(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, BrainSurface *surface, ShaderMode mode)
void issueSliceDraw(QRhiCommandBuffer *cb, int slotIndex, int uniformOffset)
void updateSceneUniforms(QRhi *rhi, const SceneData &data)
static constexpr ShaderMode Dipole
void prepareVideoOverlay(QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::VideoOverlay *overlay)
void ensureRenderTargets(QRhi *rhi, QRhiTexture *colorTex, const QSize &pixelSize)
void initialize(QRhi *rhi, QRhiRenderPassDescriptor *rp, int sampleCount)
void beginFrame(QRhiCommandBuffer *cb)
static constexpr ShaderMode Standard
void renderVideoOverlayOnSurface(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DISP3DLIB::VideoOverlay *overlay, BrainSurface *surface)
void invalidateMergedGroup(const QString &groupName=QStringLiteral("default"))
void prepareMergedSurfaces(QRhi *rhi, QRhiResourceUpdateBatch *u, const QVector< BrainSurface * > &surfaces, const QString &groupName=QStringLiteral("default"))
void renderDipoles(QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DipoleObject *dipoles)
static constexpr ShaderMode XRay
Aggregated GPU resources and render state for the 3-D brain visualization scene.