v2.0.0
Loading...
Searching...
No Matches
BrainRenderer Class Reference

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

Detailed Description

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.

Member Typedef Documentation

◆ ShaderMode

Definition at line 86 of file brainrenderer.h.

Constructor & Destructor Documentation

◆ BrainRenderer()

BrainRenderer::BrainRenderer ( )

Default Constructor

Definition at line 208 of file brainrenderer.cpp.

◆ ~BrainRenderer()

BrainRenderer::~BrainRenderer ( )
default

Destructor

Member Function Documentation

◆ beginFrame()

void BrainRenderer::beginFrame ( QRhiCommandBuffer * cb)

Begin the first render pass of a frame. Clears color and depth.

Parameters
[in]cbCommand buffer to record to.

Definition at line 425 of file brainrenderer.cpp.

◆ beginPreservingPass()

void BrainRenderer::beginPreservingPass ( QRhiCommandBuffer * cb)

Begin an additional render pass that preserves previous output. Uses the internal preserving render target (m_rtPreserve).

Parameters
[in]cbCommand buffer.

Definition at line 447 of file brainrenderer.cpp.

◆ drawMergedSurfaces()

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().

Parameters
[in]cbCommand buffer.
[in]rhiQRhi pointer.
[in]dataScene uniforms.
[in]modeShader mode.

Definition at line 1714 of file brainrenderer.cpp.

◆ endPass()

void BrainRenderer::endPass ( QRhiCommandBuffer * cb)

End any render pass (clearing or preserving).

Parameters
[in]cbCommand buffer.

Definition at line 459 of file brainrenderer.cpp.

◆ ensureRenderTargets()

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:

  • m_rtClear: clears color+depth on beginPass (first pass)
  • m_rtPreserve: preserves previous output (passes 2+)

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.

Parameters
[in]rhiQRhi instance.
[in]colorTexColor texture (owned by QRhiWidget or caller).
[in]pixelSizeRender target dimensions.

Definition at line 378 of file brainrenderer.cpp.

◆ hasMergedContent()

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.

Parameters
[in]groupNameCategory name to check.
Returns
true if the group exists and has indices to draw.

Definition at line 1706 of file brainrenderer.cpp.

◆ initialize()

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.

Parameters
[in]rhiPointer to QRhi instance.
[in]rpRender pass descriptor.
[in]sampleCountMSAA sample count.

Definition at line 219 of file brainrenderer.cpp.

◆ invalidateMergedGroup()

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.

Parameters
[in]groupNameCategory name to invalidate.

Definition at line 1696 of file brainrenderer.cpp.

◆ issueSliceDraw()

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.

Parameters
[in]cbCommand buffer (must be inside a render pass).
[in]slotIndexSlot index matching the prepareSliceDraw call.
[in]uniformOffsetOffset returned by prepareSliceDraw().

Definition at line 1215 of file brainrenderer.cpp.

◆ issueSurfaceDraw()

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.

Parameters
[in]cbCommand buffer.
[in]surfacePointer to surface to draw.
[in]modeShader mode.
[in]uniformOffsetOffset returned by prepareSurfaceDraw().

Definition at line 1363 of file brainrenderer.cpp.

◆ prepareMergedSurfaces()

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.

Parameters
[in]rhiQRhi pointer.
[in]uResource update batch (pre-render uploads).
[in]surfacesBrain surfaces to merge.
[in]groupNameCategory name (e.g. "brain", "bem", "srcsp").

Definition at line 1542 of file brainrenderer.cpp.

◆ prepareSlice()

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.

Parameters
[in]rhiQRhi pointer.
[in]uResource update batch owned by the caller.
[in]slicePointer to SliceObject; ignored when null.
[in]slotIndexSlot index (0=axial, 1=coronal, 2=sagittal).

Definition at line 995 of file brainrenderer.cpp.

◆ prepareSliceDraw()

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.

Parameters
[in]uShared resource update batch.
[in]dataScene uniforms (MVP, camera position).
[in]slotIndexSlot index (0=axial, 1=coronal, 2=sagittal).
Returns
Uniform buffer offset for this draw, or -1 on failure.

Definition at line 1167 of file brainrenderer.cpp.

◆ prepareSurfaceDraw()

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.

Parameters
[in]uShared resource update batch.
[in]dataScene uniforms (MVP, light, etc).
[in]surfacePointer to surface.
Returns
Uniform buffer offset for this draw, or -1 on failure.

Definition at line 1319 of file brainrenderer.cpp.

◆ prepareVideoOverlay()

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.

Parameters
[in]rhiQRhi pointer.
[in]uResource update batch owned by the caller.
[in]overlayPointer to VideoOverlay; ignored when null/disabled.

Definition at line 468 of file brainrenderer.cpp.

◆ renderDipoles()

void BrainRenderer::renderDipoles ( QRhiCommandBuffer * cb,
QRhi * rhi,
const SceneData & data,
DipoleObject * dipoles )

Render dipoles using instanced rendering.

Parameters
[in]cbCommand buffer.
[in]rhiQRhi pointer.
[in]dataScene uniforms.
[in]dipolesPointer to DipoleObject.

Definition at line 1391 of file brainrenderer.cpp.

◆ renderNetwork()

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.

Parameters
[in]cbCommand buffer.
[in]rhiQRhi pointer.
[in]dataScene uniforms.
[in]networkPointer to NetworkObject.

Definition at line 1449 of file brainrenderer.cpp.

◆ renderSurface()

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.

Parameters
[in]cbCommand buffer.
[in]rhiQRhi pointer.
[in]dataScene uniforms (MVP, light, etc).
[in]surfacePointer to surface to draw.
[in]modeShader mode to use for this surface.

Definition at line 1235 of file brainrenderer.cpp.

◆ renderVideoOverlay()

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.

Parameters
[in]cbCommand buffer (must be inside a render pass).
[in]rhiQRhi pointer.
[in]dataScene uniforms (MVP, camera position).
[in]overlayPointer to VideoOverlay; ignored when null/disabled.

Definition at line 783 of file brainrenderer.cpp.

◆ renderVideoOverlayOnSurface()

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.

Parameters
[in]cbCommand buffer (must be inside a render pass).
[in]rhiQRhi pointer.
[in]dataScene uniforms (MVP, camera position).
[in]overlayPointer to VideoOverlay; ignored when null/disabled.
[in]surfaceTarget surface mesh (typically scalp/head).

Definition at line 876 of file brainrenderer.cpp.

◆ rtClear()

QRhiRenderTarget * BrainRenderer::rtClear ( ) const
Returns
The clearing render target (pass 1).

Definition at line 413 of file brainrenderer.cpp.

◆ rtPreserve()

QRhiRenderTarget * BrainRenderer::rtPreserve ( ) const
Returns
The preserving render target (passes 2+).

Definition at line 418 of file brainrenderer.cpp.

◆ updateSceneUniforms()

void BrainRenderer::updateSceneUniforms ( QRhi * rhi,
const SceneData & data )

Set uniforms that are shared for the entire frame.

Parameters
[in]dataScene uniforms (MVP, light, etc).

Definition at line 440 of file brainrenderer.cpp.

Member Data Documentation

◆ Anatomical

ShaderMode BrainRenderer::Anatomical = ::Anatomical
staticconstexpr

Definition at line 89 of file brainrenderer.h.

◆ Dipole

ShaderMode BrainRenderer::Dipole = ::Dipole
staticconstexpr

Definition at line 90 of file brainrenderer.h.

◆ Holographic

ShaderMode BrainRenderer::Holographic = ::Holographic
staticconstexpr

Definition at line 88 of file brainrenderer.h.

◆ ShowNormals

ShaderMode BrainRenderer::ShowNormals = ::ShowNormals
staticconstexpr

Definition at line 92 of file brainrenderer.h.

◆ Standard

ShaderMode BrainRenderer::Standard = ::Standard
staticconstexpr

Definition at line 87 of file brainrenderer.h.

◆ XRay

ShaderMode BrainRenderer::XRay = ::XRay
staticconstexpr

Definition at line 91 of file brainrenderer.h.


The documentation for this class was generated from the following files: