Qt RHI-based 3-D renderer managing scene objects, lighting, camera, and render pipeline for brain visualization. More...
#include <brainrenderer.h>
Classes | |
| struct | SceneData |
| Aggregated GPU resources and render state for the 3-D brain visualization scene. More... | |
| struct | Impl |
Public Types | |
| using | ShaderMode = ::ShaderMode |
Public Member Functions | |
| BrainRenderer () | |
| ~BrainRenderer () | |
| void | initialize (QRhi *rhi, QRhiRenderPassDescriptor *rp, int sampleCount) |
| void | ensureRenderTargets (QRhi *rhi, QRhiTexture *colorTex, const QSize &pixelSize) |
| QRhiRenderTarget * | rtClear () const |
| QRhiRenderTarget * | rtPreserve () const |
| void | beginFrame (QRhiCommandBuffer *cb) |
| void | beginPreservingPass (QRhiCommandBuffer *cb) |
| void | updateSceneUniforms (QRhi *rhi, const SceneData &data) |
| void | renderSurface (QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, BrainSurface *surface, ShaderMode mode) |
| int | prepareSurfaceDraw (QRhiResourceUpdateBatch *u, const SceneData &data, BrainSurface *surface) |
| void | issueSurfaceDraw (QRhiCommandBuffer *cb, BrainSurface *surface, ShaderMode mode, int uniformOffset) |
| void | prepareMergedSurfaces (QRhi *rhi, QRhiResourceUpdateBatch *u, const QVector< BrainSurface * > &surfaces, const QString &groupName=QStringLiteral("default")) |
| void | invalidateMergedGroup (const QString &groupName=QStringLiteral("default")) |
| bool | hasMergedContent (const QString &groupName) const |
| void | drawMergedSurfaces (QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, ShaderMode mode, const QString &groupName=QStringLiteral("default")) |
| void | renderDipoles (QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, DipoleObject *dipoles) |
| void | renderNetwork (QRhiCommandBuffer *cb, QRhi *rhi, const SceneData &data, NetworkObject *network) |
| void | prepareVideoOverlay (QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::VideoOverlay *overlay) |
| 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) |
| int | prepareSliceDraw (QRhiResourceUpdateBatch *u, const SceneData &data, int slotIndex) |
| void | issueSliceDraw (QRhiCommandBuffer *cb, int slotIndex, int uniformOffset) |
| void | endPass (QRhiCommandBuffer *cb) |
Static Public Attributes | |
| static constexpr ShaderMode | Standard = ::Standard |
| static constexpr ShaderMode | Holographic = ::Holographic |
| static constexpr ShaderMode | Anatomical = ::Anatomical |
| static constexpr ShaderMode | Dipole = ::Dipole |
| static constexpr ShaderMode | XRay = ::XRay |
| static constexpr ShaderMode | ShowNormals = ::ShowNormals |
Qt RHI-based 3-D renderer managing scene objects, lighting, camera, and render pipeline for brain visualization.
BrainRenderer handles the low-level RHI rendering logic, managing pipelines, shaders, and draw calls for brain surfaces.
Definition at line 69 of file brainrenderer.h.
Definition at line 86 of file brainrenderer.h.
| BrainRenderer::BrainRenderer | ( | ) |
Default Constructor
Definition at line 208 of file brainrenderer.cpp.
|
default |
Destructor
| void BrainRenderer::beginFrame | ( | QRhiCommandBuffer * | cb | ) |
Begin the first render pass of a frame. Clears color and depth.
| [in] | cb | Command buffer to record to. |
Definition at line 425 of file brainrenderer.cpp.
| void BrainRenderer::beginPreservingPass | ( | QRhiCommandBuffer * | cb | ) |
Begin an additional render pass that preserves previous output. Uses the internal preserving render target (m_rtPreserve).
| [in] | cb | Command buffer. |
Definition at line 447 of file brainrenderer.cpp.
| void BrainRenderer::drawMergedSurfaces | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| ShaderMode | mode, | ||
| const QString & | groupName = QStringLiteral("default") ) |
Draw previously prepared merged surfaces in a single drawIndexed. Call between beginFrame()/beginPreservingPass() and endPass().
| [in] | cb | Command buffer. |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms. |
| [in] | mode | Shader mode. |
Definition at line 1714 of file brainrenderer.cpp.
| void BrainRenderer::endPass | ( | QRhiCommandBuffer * | cb | ) |
End any render pass (clearing or preserving).
| [in] | cb | Command buffer. |
Definition at line 459 of file brainrenderer.cpp.
| void BrainRenderer::ensureRenderTargets | ( | QRhi * | rhi, |
| QRhiTexture * | colorTex, | ||
| const QSize & | pixelSize ) |
Create the dual render-target pair for multi-pass rendering.
Both render targets share the same color texture and depth-stencil buffer but differ in their load/store flags:
Qt bakes these flags into native resources at create() time, so calling setFlags() dynamically does NOT work (especially on WebGL). This is the validated pattern from test_wasm_multi_pass.
| [in] | rhi | QRhi instance. |
| [in] | colorTex | Color texture (owned by QRhiWidget or caller). |
| [in] | pixelSize | Render target dimensions. |
Definition at line 378 of file brainrenderer.cpp.
| bool BrainRenderer::hasMergedContent | ( | const QString & | groupName | ) | const |
Check if a merged group has drawable geometry (indexCount > 0). Use before beginPreservingPass() to avoid empty render passes which can clear the framebuffer on some WebGL implementations.
| [in] | groupName | Category name to check. |
Definition at line 1706 of file brainrenderer.cpp.
| void BrainRenderer::initialize | ( | QRhi * | rhi, |
| QRhiRenderPassDescriptor * | rp, | ||
| int | sampleCount ) |
Initialize resources (shaders, pipelines) for the given RHI and render pass. Ensures pipelines for all supported modes are created.
| [in] | rhi | Pointer to QRhi instance. |
| [in] | rp | Render pass descriptor. |
| [in] | sampleCount | MSAA sample count. |
Definition at line 219 of file brainrenderer.cpp.
| void BrainRenderer::invalidateMergedGroup | ( | const QString & | groupName = QStringLiteral("default") | ) |
Mark a merged group as dirty so it is rebuilt on the next prepareMergedSurfaces call. Call when surfaces are added/removed or visibility changes.
| [in] | groupName | Category name to invalidate. |
Definition at line 1696 of file brainrenderer.cpp.
| void BrainRenderer::issueSliceDraw | ( | QRhiCommandBuffer * | cb, |
| int | slotIndex, | ||
| int | uniformOffset ) |
Issue draw commands for a prepared MRI slice.
Call after cb->resourceUpdate() has been submitted with the batch from prepareSliceDraw(). Does not create resource batches.
| [in] | cb | Command buffer (must be inside a render pass). |
| [in] | slotIndex | Slot index matching the prepareSliceDraw call. |
| [in] | uniformOffset | Offset returned by prepareSliceDraw(). |
Definition at line 1215 of file brainrenderer.cpp.
| void BrainRenderer::issueSurfaceDraw | ( | QRhiCommandBuffer * | cb, |
| BrainSurface * | surface, | ||
| ShaderMode | mode, | ||
| int | uniformOffset ) |
Issue draw commands for a surface using a pre-computed uniform offset.
Call after cb->resourceUpdate() has been submitted with the batch from prepareSurfaceDraw(). Does not create resource batches or modify viewport/scissor state.
| [in] | cb | Command buffer. |
| [in] | surface | Pointer to surface to draw. |
| [in] | mode | Shader mode. |
| [in] | uniformOffset | Offset returned by prepareSurfaceDraw(). |
Definition at line 1363 of file brainrenderer.cpp.
| void BrainRenderer::prepareMergedSurfaces | ( | QRhi * | rhi, |
| QRhiResourceUpdateBatch * | u, | ||
| const QVector< BrainSurface * > & | surfaces, | ||
| const QString & | groupName = QStringLiteral("default") ) |
Prepare merged brain surface geometry for single-drawIndexed rendering. Call BEFORE beginFrame() with a pre-upload resource batch.
Uses dirty-flag caching: geometry is only rebuilt when the surface list changes (add/remove/visibility toggle). Per-vertex color updates (STC animation) only re-upload the color channel.
| [in] | rhi | QRhi pointer. |
| [in] | u | Resource update batch (pre-render uploads). |
| [in] | surfaces | Brain surfaces to merge. |
| [in] | groupName | Category name (e.g. "brain", "bem", "srcsp"). |
Definition at line 1542 of file brainrenderer.cpp.
| void BrainRenderer::prepareSlice | ( | QRhi * | rhi, |
| QRhiResourceUpdateBatch * | u, | ||
| DISP3DLIB::SliceObject * | slice, | ||
| int | slotIndex ) |
Prepare MRI slice GPU resources and upload texture data.
Must be called before a render pass starts. Creates the slice pipeline lazily on first use and uploads the slice texture.
| [in] | rhi | QRhi pointer. |
| [in] | u | Resource update batch owned by the caller. |
| [in] | slice | Pointer to SliceObject; ignored when null. |
| [in] | slotIndex | Slot index (0=axial, 1=coronal, 2=sagittal). |
Definition at line 995 of file brainrenderer.cpp.
| int BrainRenderer::prepareSliceDraw | ( | QRhiResourceUpdateBatch * | u, |
| const SceneData & | data, | ||
| int | slotIndex ) |
Upload uniform data for an MRI slice into a shared resource batch.
Call once per visible slice, then submit the batch with cb->resourceUpdate(), and finally call issueSliceDraw() for each slice.
| [in] | u | Shared resource update batch. |
| [in] | data | Scene uniforms (MVP, camera position). |
| [in] | slotIndex | Slot index (0=axial, 1=coronal, 2=sagittal). |
Definition at line 1167 of file brainrenderer.cpp.
| int BrainRenderer::prepareSurfaceDraw | ( | QRhiResourceUpdateBatch * | u, |
| const SceneData & | data, | ||
| BrainSurface * | surface ) |
Upload uniform data for a surface into a shared resource batch.
This is the batched equivalent of the first half of renderSurface(). Call once per surface, then submit the batch with cb->resourceUpdate(), and finally call issueSurfaceDraw() for each surface.
| [in] | u | Shared resource update batch. |
| [in] | data | Scene uniforms (MVP, light, etc). |
| [in] | surface | Pointer to surface. |
Definition at line 1319 of file brainrenderer.cpp.
| void BrainRenderer::prepareVideoOverlay | ( | QRhi * | rhi, |
| QRhiResourceUpdateBatch * | u, | ||
| DISP3DLIB::VideoOverlay * | overlay ) |
Prepare live video overlay GPU resources and upload the latest frame.
Must be called before a render pass starts. Texture uploads require a blit encoder on Metal and must not be recorded while a render encoder is active.
| [in] | rhi | QRhi pointer. |
| [in] | u | Resource update batch owned by the caller. |
| [in] | overlay | Pointer to VideoOverlay; ignored when null/disabled. |
Definition at line 468 of file brainrenderer.cpp.
| void BrainRenderer::renderDipoles | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| DipoleObject * | dipoles ) |
Render dipoles using instanced rendering.
| [in] | cb | Command buffer. |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms. |
| [in] | dipoles | Pointer to DipoleObject. |
Definition at line 1391 of file brainrenderer.cpp.
| void BrainRenderer::renderNetwork | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| NetworkObject * | network ) |
Render a connectivity network using instanced rendering. Renders both node spheres and edge cylinders as two draw calls.
| [in] | cb | Command buffer. |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms. |
| [in] | network | Pointer to NetworkObject. |
Definition at line 1449 of file brainrenderer.cpp.
| void BrainRenderer::renderSurface | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| BrainSurface * | surface, | ||
| ShaderMode | mode ) |
Render a single surface. Must be called between beginFrame/beginPreservingPass and endPass.
| [in] | cb | Command buffer. |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms (MVP, light, etc). |
| [in] | surface | Pointer to surface to draw. |
| [in] | mode | Shader mode to use for this surface. |
Definition at line 1235 of file brainrenderer.cpp.
| void BrainRenderer::renderVideoOverlay | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| DISP3DLIB::VideoOverlay * | overlay ) |
Render a live video overlay as a camera-facing textured quad. Always drawn last (depth test disabled) so the cut-out sits on top of the head surface at the current focus position.
| [in] | cb | Command buffer (must be inside a render pass). |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms (MVP, camera position). |
| [in] | overlay | Pointer to VideoOverlay; ignored when null/disabled. |
Definition at line 783 of file brainrenderer.cpp.
| void BrainRenderer::renderVideoOverlayOnSurface | ( | QRhiCommandBuffer * | cb, |
| QRhi * | rhi, | ||
| const SceneData & | data, | ||
| DISP3DLIB::VideoOverlay * | overlay, | ||
| BrainSurface * | surface ) |
Render a live video overlay projected onto an existing surface mesh.
| [in] | cb | Command buffer (must be inside a render pass). |
| [in] | rhi | QRhi pointer. |
| [in] | data | Scene uniforms (MVP, camera position). |
| [in] | overlay | Pointer to VideoOverlay; ignored when null/disabled. |
| [in] | surface | Target surface mesh (typically scalp/head). |
Definition at line 876 of file brainrenderer.cpp.
| QRhiRenderTarget * BrainRenderer::rtClear | ( | ) | const |
Definition at line 413 of file brainrenderer.cpp.
| QRhiRenderTarget * BrainRenderer::rtPreserve | ( | ) | const |
Definition at line 418 of file brainrenderer.cpp.
| void BrainRenderer::updateSceneUniforms | ( | QRhi * | rhi, |
| const SceneData & | data ) |
Set uniforms that are shared for the entire frame.
| [in] | data | Scene uniforms (MVP, light, etc). |
Definition at line 440 of file brainrenderer.cpp.
|
staticconstexpr |
Definition at line 89 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 90 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 88 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 92 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 87 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 91 of file brainrenderer.h.