Skip to content

Commit cd59aba

Browse files
committed
Refactored the enable/disable functionality of renderers. A disabled renderer will still not draw, but will execute and update its data.
1 parent c6b478a commit cd59aba

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

source/FAST/Visualization/RenderToImage/RenderToImage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ void RenderToImage::paintGL() {
489489
for(auto& renderer : mNonVolumeRenderers) {
490490
if(!renderer->isDisabled()) {
491491
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, true, m_width, m_height);
492-
renderer->postDraw();
493492
}
493+
renderer->postDraw();
494494
}
495495
mRuntimeManager->stopRegularTimer("draw2D");
496496

@@ -506,16 +506,16 @@ void RenderToImage::paintGL() {
506506
for(auto& renderer : mNonVolumeRenderers) {
507507
if(!renderer->isDisabled()) {
508508
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, false, m_width, m_height);
509-
renderer->postDraw();
510509
}
510+
renderer->postDraw();
511511
}
512512

513513
if(!mVolumeRenderers.empty()) {
514514
for(auto& renderer : mVolumeRenderers) {
515515
if(!renderer->isDisabled()) {
516516
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, false, m_width, m_height);
517-
renderer->postDraw();
518517
}
518+
renderer->postDraw();
519519
}
520520

521521
// Blit/copy the framebuffer to the default framebuffer (window)

source/FAST/Visualization/Renderer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ void Renderer::stopPipeline() {
3838

3939
void Renderer::postDraw() {
4040
std::lock_guard<std::mutex> lock(mMutex);
41+
// It is important that this happens in this function, since postDraw is called even though it is disabled:
4142
mHasRendered = true;
4243
}
4344

4445
void Renderer::execute() {
4546
{
4647
std::lock_guard<std::mutex> lock(mMutex);
47-
if(m_disabled)
48-
return;
4948
if(mStop) {
5049
return;
5150
}

source/FAST/Visualization/Renderer.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class DataBoundingBox;
2323
*
2424
* Renderers are process objects which can visualize data in a View, typically using OpenGL.
2525
* They should inherit from this class.
26+
*
27+
* @ingroup renderers
2628
*/
2729
class FAST_EXPORT Renderer : public ProcessObject, protected QOpenGLFunctions_3_3_Core {
2830
public:
@@ -47,12 +49,12 @@ class FAST_EXPORT Renderer : public ProcessObject, protected QOpenGLFunctions_3
4749
virtual void stopPipeline();
4850
virtual void reset();
4951
/**
50-
* Set renderer to disabled or enabled. A disabled renderer will not draw.
52+
* @brief Set renderer to disabled or enabled. A disabled renderer will not draw, but it will execute.
5153
* @param disabled
5254
*/
5355
virtual void setDisabled(bool disabled);
5456
/**
55-
* Get whether this renderer is disabled or not
57+
* @brief Get whether this renderer is disabled or not
5658
* @return
5759
*/
5860
virtual bool isDisabled() const;
@@ -67,7 +69,7 @@ class FAST_EXPORT Renderer : public ProcessObject, protected QOpenGLFunctions_3
6769
void clearDataToRender();
6870

6971
/**
70-
* Creates an OpenGL shader program. Should be used in the renderer constructor.
72+
* @brief Creates an OpenGL shader program. Should be used in the renderer constructor.
7173
* @param shaderFilenames
7274
* @param programName
7375
*/
@@ -91,9 +93,9 @@ class FAST_EXPORT Renderer : public ProcessObject, protected QOpenGLFunctions_3
9193
std::mutex mMutex;
9294

9395
/**
94-
* A disabled renderer will not draw
96+
* @brief A disabled renderer will not draw, but it will execute
9597
*/
96-
bool m_disabled = false;
98+
std::atomic_bool m_disabled = false;
9799

98100
/**
99101
* Whether this renderer is only capable of 2D rendering

source/FAST/Visualization/View.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,8 @@ void View::initializeGL() {
477477
// Update all renderes, so that getBoundingBox works
478478
std::vector<Renderer::pointer> renderers = getRenderers();
479479
try {
480-
for (int i = 0; i < renderers.size(); i++) {
481-
if (!renderers[i]->isDisabled())
482-
renderers[i]->update(0);
480+
for(int i = 0; i < renderers.size(); i++) {
481+
renderers[i]->update(0);
483482
}
484483
} catch (ThreadStopped& e) {
485484
// TODO What to do in this case?
@@ -554,8 +553,8 @@ void View::paintGL() {
554553
for(auto renderer : mNonVolumeRenderers) {
555554
if(!renderer->isDisabled()) {
556555
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, true, width(), height());
557-
renderer->postDraw();
558556
}
557+
renderer->postDraw(); // Call postDraw even though it is disabled, so that it is marked as hasRendered
559558
}
560559

561560
if(m_showScalebar)
@@ -574,17 +573,17 @@ void View::paintGL() {
574573
for(auto renderer : mNonVolumeRenderers) {
575574
if(!renderer->isDisabled()) {
576575
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, false, width(), height());
577-
renderer->postDraw();
578576
}
577+
renderer->postDraw(); // Call postDraw even though it is disabled, so that it is marked as hasRendered
579578
}
580579

581580
if(!mVolumeRenderers.empty()) {
582581
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO);
583582
for(auto renderer : mVolumeRenderers) {
584583
if(!renderer->isDisabled()) {
585584
renderer->draw(mPerspectiveMatrix, m3DViewingTransformation.matrix(), zNear, zFar, false, width(), height());
586-
renderer->postDraw();
587585
}
586+
renderer->postDraw(); // Call postDraw even though it is disabled, so that it is marked as hasRendered
588587
}
589588

590589
// Blit/copy the framebuffer to the default framebuffer (window)

0 commit comments

Comments
 (0)