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 |
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.
Definition at line 93 of file brainrenderer.h.
| DISP3DLIB::BrainRenderer::BrainRenderer | ( | ) |
Default Constructor
Definition at line 267 of file brainrenderer.cpp.
|
default |
Destructor
| void DISP3DLIB::BrainRenderer::beginFrame | ( | QRhiCommandBuffer * | cb, |
| QRhiResourceUpdateBatch * | updates = nullptr ) |
Begin the first render pass of a frame. Clears color and depth.
| [in] | cb | Command buffer to record to. |
| [in] | updates | Resource updates to commit before the pass, or nullptr. |
Definition at line 635 of file brainrenderer.cpp.
| 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).
| [in] | cb | Command buffer. |
| [in] | updates | Resource updates to commit before the pass, or nullptr. |
Definition at line 642 of file brainrenderer.cpp.
| int DISP3DLIB::BrainRenderer::cachedMeshCount | ( | ) | const |
Definition at line 601 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::endPass | ( | QRhiCommandBuffer * | cb | ) |
End any render pass (clearing or preserving).
| [in] | cb | Command buffer. |
Definition at line 649 of file brainrenderer.cpp.
| 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:
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 535 of file brainrenderer.cpp.
| 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.
| [in] | rhi | Pointer to QRhi instance. |
| [in] | rp | Render pass descriptor. |
| [in] | sampleCount | MSAA sample count. |
Definition at line 278 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueDipoleDraw | ( | QRhiCommandBuffer * | cb, |
| DipoleObject * | dipoles, | ||
| int | uniformOffset ) |
Draw dipoles as instanced cones. Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | dipoles | Pointer to DipoleObject. |
| [in] | uniformOffset | Offset returned by prepareDipoleDraw(). |
Definition at line 1569 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueElectrodeDraw | ( | QRhiCommandBuffer * | cb, |
| ElectrodeObject * | electrodes, | ||
| int | uniformOffset ) |
Draw electrode lead bodies and contacts, opaque and depth-tested. Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | electrodes | Pointer to ElectrodeObject. |
| [in] | uniformOffset | Offset returned by prepareElectrodeDraw(). |
Definition at line 1538 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueNetworkDraw | ( | QRhiCommandBuffer * | cb, |
| NetworkObject * | network, | ||
| int | uniformOffset ) |
Draw a connectivity network: instanced node spheres and edge cylinders. Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | network | Pointer to NetworkObject. |
| [in] | uniformOffset | Offset returned by prepareNetworkDraw(). |
Definition at line 1577 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issuePolylineDraw | ( | QRhiCommandBuffer * | cb, |
| PolylineObject * | polyline, | ||
| int | uniformOffset ) |
Draw a polyline as connected segments. Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | polyline | Pointer to PolylineObject. |
| [in] | uniformOffset | Offset returned by preparePolylineDraw(). |
Definition at line 1587 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueSliceDraw | ( | QRhiCommandBuffer * | cb, |
| int | slotIndex, | ||
| int | uniformOffset ) |
Draw an MRI slice prepared with prepareSliceDraw(). Call inside a pass.
| [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 1364 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueSurfaceDraw | ( | QRhiCommandBuffer * | cb, |
| BrainSurface * | surface, | ||
| ShaderMode | mode, | ||
| int | uniformOffset ) |
Draw a surface with the uniforms from prepareSurfaceDraw(). Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | surface | Pointer to surface to draw. |
| [in] | mode | Shader mode. |
| [in] | uniformOffset | Offset returned by prepareSurfaceDraw(). |
Definition at line 1435 of file brainrenderer.cpp.
| void DISP3DLIB::BrainRenderer::issueVideoOverlayDraw | ( | QRhiCommandBuffer * | cb, |
| DISP3DLIB::VideoOverlay * | overlay, | ||
| BrainSurface * | surface, | ||
| int | uniformOffset ) |
Draw a video overlay prepared with prepareVideoOverlayDraw(). Call inside a pass.
| [in] | cb | Command buffer. |
| [in] | overlay | Pointer to VideoOverlay. |
| [in] | surface | Same target surface as in prepareVideoOverlayDraw(). |
| [in] | uniformOffset | Offset returned by prepareVideoOverlayDraw(). |
Definition at line 1113 of file brainrenderer.cpp.
| 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.
| 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.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms. |
| [in] | dipoles | Pointer to DipoleObject. |
Definition at line 1490 of file brainrenderer.cpp.
| 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.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms. |
| [in] | electrodes | Pointer to ElectrodeObject. |
Definition at line 1525 of file brainrenderer.cpp.
| 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.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms. |
| [in] | network | Pointer to NetworkObject. |
Definition at line 1501 of file brainrenderer.cpp.
| 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.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms. |
| [in] | polyline | Pointer to PolylineObject. |
Definition at line 1514 of file brainrenderer.cpp.
| 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.
| [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 1146 of file brainrenderer.cpp.
| int DISP3DLIB::BrainRenderer::prepareSliceDraw | ( | QRhiResourceUpdateBatch * | u, |
| const SceneData & | data, | ||
| int | slotIndex ) |
Write the uniforms of one MRI slice draw into a resource update batch.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms (MVP, camera position). |
| [in] | slotIndex | Slot index (0=axial, 1=coronal, 2=sagittal). |
Definition at line 1312 of file brainrenderer.cpp.
| 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.
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms (MVP, light, etc). |
| [in] | surface | Pointer to surface. |
Definition at line 1387 of file brainrenderer.cpp.
| 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.
| [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 659 of file brainrenderer.cpp.
| 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().
| [in] | u | Resource update batch, committed before the pass. |
| [in] | data | Scene uniforms (MVP, camera position). |
| [in] | overlay | Pointer to VideoOverlay; ignored when null/disabled. |
| [in] | surface | Target surface mesh (typically scalp/head), or nullptr for the quad. |
Definition at line 939 of file brainrenderer.cpp.
| QRhiRenderTarget * DISP3DLIB::BrainRenderer::rtClear | ( | ) | const |
Definition at line 569 of file brainrenderer.cpp.
| QRhiRenderTarget * DISP3DLIB::BrainRenderer::rtPreserve | ( | ) | const |
Definition at line 574 of file brainrenderer.cpp.
|
staticconstexpr |
Definition at line 96 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 97 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 95 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 99 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 94 of file brainrenderer.h.
|
staticconstexpr |
Definition at line 98 of file brainrenderer.h.