v2.0.0
Loading...
Searching...
No Matches
DISP3DLIB::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
 Per-draw scene uniforms: camera matrices, light and overlay mode. More...
struct  Impl

Public Types

using ShaderMode = DISP3DLIB::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 newFrame ()
int cachedMeshCount () const
void beginFrame (QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *updates=nullptr)
void beginPreservingPass (QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *updates=nullptr)
int prepareSurfaceDraw (QRhiResourceUpdateBatch *u, const SceneData &data, BrainSurface *surface)
void issueSurfaceDraw (QRhiCommandBuffer *cb, BrainSurface *surface, ShaderMode mode, int uniformOffset)
int prepareDipoleDraw (QRhiResourceUpdateBatch *u, const SceneData &data, DipoleObject *dipoles)
void issueDipoleDraw (QRhiCommandBuffer *cb, DipoleObject *dipoles, int uniformOffset)
int prepareNetworkDraw (QRhiResourceUpdateBatch *u, const SceneData &data, NetworkObject *network)
void issueNetworkDraw (QRhiCommandBuffer *cb, NetworkObject *network, int uniformOffset)
int preparePolylineDraw (QRhiResourceUpdateBatch *u, const SceneData &data, PolylineObject *polyline)
void issuePolylineDraw (QRhiCommandBuffer *cb, PolylineObject *polyline, int uniformOffset)
int prepareElectrodeDraw (QRhiResourceUpdateBatch *u, const SceneData &data, ElectrodeObject *electrodes)
void issueElectrodeDraw (QRhiCommandBuffer *cb, ElectrodeObject *electrodes, int uniformOffset)
void prepareVideoOverlay (QRhi *rhi, QRhiResourceUpdateBatch *u, DISP3DLIB::VideoOverlay *overlay)
int prepareVideoOverlayDraw (QRhiResourceUpdateBatch *u, const SceneData &data, DISP3DLIB::VideoOverlay *overlay, BrainSurface *surface)
void issueVideoOverlayDraw (QRhiCommandBuffer *cb, DISP3DLIB::VideoOverlay *overlay, BrainSurface *surface, int uniformOffset)
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 = DISP3DLIB::Standard
static constexpr ShaderMode Holographic = DISP3DLIB::Holographic
static constexpr ShaderMode Anatomical = DISP3DLIB::Anatomical
static constexpr ShaderMode Dipole = DISP3DLIB::Dipole
static constexpr ShaderMode XRay = DISP3DLIB::XRay
static constexpr ShaderMode ShowNormals = DISP3DLIB::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 76 of file brainrenderer.h.

Member Typedef Documentation

◆ ShaderMode

Constructor & Destructor Documentation

◆ BrainRenderer()

DISP3DLIB::BrainRenderer::BrainRenderer ( )

Default Constructor

Definition at line 267 of file brainrenderer.cpp.

◆ ~BrainRenderer()

DISP3DLIB::BrainRenderer::~BrainRenderer ( )
default

Destructor

Member Function Documentation

◆ beginFrame()

void DISP3DLIB::BrainRenderer::beginFrame ( QRhiCommandBuffer * cb,
QRhiResourceUpdateBatch * updates = nullptr )

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

Parameters
[in]cbCommand buffer to record to.
[in]updatesResource updates to commit before the pass, or nullptr.

Definition at line 635 of file brainrenderer.cpp.

◆ beginPreservingPass()

void DISP3DLIB::BrainRenderer::beginPreservingPass ( QRhiCommandBuffer * cb,
QRhiResourceUpdateBatch * updates = nullptr )

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

Parameters
[in]cbCommand buffer.
[in]updatesResource updates to commit before the pass, or nullptr.

Definition at line 642 of file brainrenderer.cpp.

◆ cachedMeshCount()

int DISP3DLIB::BrainRenderer::cachedMeshCount ( ) const
Returns
Number of renderables whose GPU copies the renderer currently holds.

Definition at line 601 of file brainrenderer.cpp.

◆ endPass()

void DISP3DLIB::BrainRenderer::endPass ( QRhiCommandBuffer * cb)

End any render pass (clearing or preserving).

Parameters
[in]cbCommand buffer.

Definition at line 649 of file brainrenderer.cpp.

◆ ensureRenderTargets()

void DISP3DLIB::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 535 of file brainrenderer.cpp.

◆ initialize()

void DISP3DLIB::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 278 of file brainrenderer.cpp.

◆ issueDipoleDraw()

void DISP3DLIB::BrainRenderer::issueDipoleDraw ( QRhiCommandBuffer * cb,
DipoleObject * dipoles,
int uniformOffset )

Draw dipoles as instanced cones. Call inside a pass.

Parameters
[in]cbCommand buffer.
[in]dipolesPointer to DipoleObject.
[in]uniformOffsetOffset returned by prepareDipoleDraw().

Definition at line 1569 of file brainrenderer.cpp.

◆ issueElectrodeDraw()

void DISP3DLIB::BrainRenderer::issueElectrodeDraw ( QRhiCommandBuffer * cb,
ElectrodeObject * electrodes,
int uniformOffset )

Draw electrode lead bodies and contacts, opaque and depth-tested. Call inside a pass.

Parameters
[in]cbCommand buffer.
[in]electrodesPointer to ElectrodeObject.
[in]uniformOffsetOffset returned by prepareElectrodeDraw().

Definition at line 1538 of file brainrenderer.cpp.

◆ issueNetworkDraw()

void DISP3DLIB::BrainRenderer::issueNetworkDraw ( QRhiCommandBuffer * cb,
NetworkObject * network,
int uniformOffset )

Draw a connectivity network: instanced node spheres and edge cylinders. Call inside a pass.

Parameters
[in]cbCommand buffer.
[in]networkPointer to NetworkObject.
[in]uniformOffsetOffset returned by prepareNetworkDraw().

Definition at line 1577 of file brainrenderer.cpp.

◆ issuePolylineDraw()

void DISP3DLIB::BrainRenderer::issuePolylineDraw ( QRhiCommandBuffer * cb,
PolylineObject * polyline,
int uniformOffset )

Draw a polyline as connected segments. Call inside a pass.

Parameters
[in]cbCommand buffer.
[in]polylinePointer to PolylineObject.
[in]uniformOffsetOffset returned by preparePolylineDraw().

Definition at line 1587 of file brainrenderer.cpp.

◆ issueSliceDraw()

void DISP3DLIB::BrainRenderer::issueSliceDraw ( QRhiCommandBuffer * cb,
int slotIndex,
int uniformOffset )

Draw an MRI slice prepared with prepareSliceDraw(). Call inside a pass.

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 1364 of file brainrenderer.cpp.

◆ issueSurfaceDraw()

void DISP3DLIB::BrainRenderer::issueSurfaceDraw ( QRhiCommandBuffer * cb,
BrainSurface * surface,
ShaderMode mode,
int uniformOffset )

Draw a surface with the uniforms from prepareSurfaceDraw(). Call inside a pass.

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

Definition at line 1435 of file brainrenderer.cpp.

◆ issueVideoOverlayDraw()

void DISP3DLIB::BrainRenderer::issueVideoOverlayDraw ( QRhiCommandBuffer * cb,
DISP3DLIB::VideoOverlay * overlay,
BrainSurface * surface,
int uniformOffset )

Draw a video overlay prepared with prepareVideoOverlayDraw(). Call inside a pass.

Parameters
[in]cbCommand buffer.
[in]overlayPointer to VideoOverlay.
[in]surfaceSame target surface as in prepareVideoOverlayDraw().
[in]uniformOffsetOffset returned by prepareVideoOverlayDraw().

Definition at line 1113 of file brainrenderer.cpp.

◆ newFrame()

void DISP3DLIB::BrainRenderer::newFrame ( )

Start a new frame: frees all per-draw uniform slots. Call before the frame's first prepare call.

A frame is recorded in two phases. First every prepare*() call writes its uniforms and uploads into resource update batches. Then beginFrame() commits them, and the issue*() calls only bind and draw: QRhi forbids resource updates inside a render pass, and prepare calls made inside one are rejected with a warning.

The renderer owns the GPU copies of the renderables' streams. They are created on the first draw, updated when a stream's generation changes, and freed once the renderable is destroyed or has not been drawn for a while.

Definition at line 581 of file brainrenderer.cpp.

◆ prepareDipoleDraw()

int DISP3DLIB::BrainRenderer::prepareDipoleDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
DipoleObject * dipoles )

Upload the dipoles' streams if they changed and write the uniforms of their draw.

Parameters
[in]uResource update batch, committed before the pass.
[in]dataScene uniforms.
[in]dipolesPointer to DipoleObject.
Returns
Uniform buffer offset, or -1 when nothing is drawn.

Definition at line 1490 of file brainrenderer.cpp.

◆ prepareElectrodeDraw()

int DISP3DLIB::BrainRenderer::prepareElectrodeDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
ElectrodeObject * electrodes )

Upload the electrodes' streams if they changed and write the uniforms of their draws.

Parameters
[in]uResource update batch, committed before the pass.
[in]dataScene uniforms.
[in]electrodesPointer to ElectrodeObject.
Returns
Uniform buffer offset, or -1 when nothing is drawn.

Definition at line 1525 of file brainrenderer.cpp.

◆ prepareNetworkDraw()

int DISP3DLIB::BrainRenderer::prepareNetworkDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
NetworkObject * network )

Upload the network's streams if they changed and write the uniforms of its draws.

Parameters
[in]uResource update batch, committed before the pass.
[in]dataScene uniforms.
[in]networkPointer to NetworkObject.
Returns
Uniform buffer offset, or -1 when nothing is drawn.

Definition at line 1501 of file brainrenderer.cpp.

◆ preparePolylineDraw()

int DISP3DLIB::BrainRenderer::preparePolylineDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
PolylineObject * polyline )

Upload the polyline's streams if they changed and write the uniforms of its draw.

Parameters
[in]uResource update batch, committed before the pass.
[in]dataScene uniforms.
[in]polylinePointer to PolylineObject.
Returns
Uniform buffer offset, or -1 when nothing is drawn.

Definition at line 1514 of file brainrenderer.cpp.

◆ prepareSlice()

void DISP3DLIB::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 1146 of file brainrenderer.cpp.

◆ prepareSliceDraw()

int DISP3DLIB::BrainRenderer::prepareSliceDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
int slotIndex )

Write the uniforms of one MRI slice draw into a resource update batch.

Parameters
[in]uResource update batch, committed before the pass.
[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 1312 of file brainrenderer.cpp.

◆ prepareSurfaceDraw()

int DISP3DLIB::BrainRenderer::prepareSurfaceDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
BrainSurface * surface )

Upload the surface's streams if they changed and write the uniforms of one surface draw.

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

Definition at line 1387 of file brainrenderer.cpp.

◆ prepareVideoOverlay()

void DISP3DLIB::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 659 of file brainrenderer.cpp.

◆ prepareVideoOverlayDraw()

int DISP3DLIB::BrainRenderer::prepareVideoOverlayDraw ( QRhiResourceUpdateBatch * u,
const SceneData & data,
DISP3DLIB::VideoOverlay * overlay,
BrainSurface * surface )

Write the uniforms of one video overlay draw: a camera-facing quad at the focus position, or, with a target surface, a decal projected onto that mesh. Call after prepareVideoOverlay().

Parameters
[in]uResource update batch, committed before the pass.
[in]dataScene uniforms (MVP, camera position).
[in]overlayPointer to VideoOverlay; ignored when null/disabled.
[in]surfaceTarget surface mesh (typically scalp/head), or nullptr for the quad.
Returns
Uniform buffer offset for this draw, or -1 when nothing is drawn.

Definition at line 939 of file brainrenderer.cpp.

◆ rtClear()

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

Definition at line 569 of file brainrenderer.cpp.

◆ rtPreserve()

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

Definition at line 574 of file brainrenderer.cpp.

Member Data Documentation

◆ Anatomical

ShaderMode DISP3DLIB::BrainRenderer::Anatomical = DISP3DLIB::Anatomical
staticconstexpr

Definition at line 96 of file brainrenderer.h.

◆ Dipole

ShaderMode DISP3DLIB::BrainRenderer::Dipole = DISP3DLIB::Dipole
staticconstexpr

Definition at line 97 of file brainrenderer.h.

◆ Holographic

ShaderMode DISP3DLIB::BrainRenderer::Holographic = DISP3DLIB::Holographic
staticconstexpr

Definition at line 95 of file brainrenderer.h.

◆ ShowNormals

ShaderMode DISP3DLIB::BrainRenderer::ShowNormals = DISP3DLIB::ShowNormals
staticconstexpr

Definition at line 99 of file brainrenderer.h.

◆ Standard

ShaderMode DISP3DLIB::BrainRenderer::Standard = DISP3DLIB::Standard
staticconstexpr

Definition at line 94 of file brainrenderer.h.

◆ XRay

ShaderMode DISP3DLIB::BrainRenderer::XRay = DISP3DLIB::XRay
staticconstexpr

Definition at line 98 of file brainrenderer.h.


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