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 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 74 of file brainrenderer.h.

Member Typedef Documentation

◆ ShaderMode

Definition at line 91 of file brainrenderer.h.

Constructor & Destructor Documentation

◆ BrainRenderer()

BrainRenderer::BrainRenderer ( )

Default Constructor

Definition at line 151 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 368 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 389 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 887 of file brainrenderer.cpp.

◆ endPass()

void BrainRenderer::endPass ( QRhiCommandBuffer * cb)

End any render pass (clearing or preserving).

Parameters
[in]cbCommand buffer.

Definition at line 401 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 321 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 879 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 162 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 869 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 536 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 715 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 492 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 564 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 622 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 408 of file brainrenderer.cpp.

◆ rtClear()

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

Definition at line 356 of file brainrenderer.cpp.

◆ rtPreserve()

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

Definition at line 361 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 382 of file brainrenderer.cpp.

Member Data Documentation

◆ Anatomical

ShaderMode BrainRenderer::Anatomical = ::Anatomical
staticconstexpr

Definition at line 94 of file brainrenderer.h.

◆ Dipole

ShaderMode BrainRenderer::Dipole = ::Dipole
staticconstexpr

Definition at line 95 of file brainrenderer.h.

◆ Holographic

ShaderMode BrainRenderer::Holographic = ::Holographic
staticconstexpr

Definition at line 93 of file brainrenderer.h.

◆ ShowNormals

ShaderMode BrainRenderer::ShowNormals = ::ShowNormals
staticconstexpr

Definition at line 97 of file brainrenderer.h.

◆ Standard

ShaderMode BrainRenderer::Standard = ::Standard
staticconstexpr

Definition at line 92 of file brainrenderer.h.

◆ XRay

ShaderMode BrainRenderer::XRay = ::XRay
staticconstexpr

Definition at line 96 of file brainrenderer.h.


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