use a parameter to avoid temporarily changing member variables

Sat, 10 Jun 2023 17:26:32 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 10 Jun 2023 17:26:32 +0300
changeset 382
94d5587bb0c4
parent 381
80bea7a6e84f
child 383
530d23cd4e97

use a parameter to avoid temporarily changing member variables

src/gl/partrenderer.cpp file | annotate | diff | comparison | revisions
src/gl/partrenderer.h file | annotate | diff | comparison | revisions
--- a/src/gl/partrenderer.cpp	Wed Apr 19 22:51:56 2023 +0300
+++ b/src/gl/partrenderer.cpp	Sat Jun 10 17:26:32 2023 +0300
@@ -107,7 +107,7 @@
 {
 	glEnable(GL_DEPTH_TEST);
 	glShadeModel(GL_SMOOTH);
-	this->renderScene();
+	this->renderScene(this->render_preferences);
 	for (RenderLayer* layer : this->activeRenderLayers) {
 		layer->paintGL();
 	}
@@ -118,7 +118,7 @@
 	}
 }
 
-void PartRenderer::renderScene()
+void PartRenderer::renderScene(const gl::RenderPreferences* preferences)
 {
 	if (this->needBuild)
 	{
@@ -127,7 +127,7 @@
 		this->needBuild = false;
 	}
 	this->checkForGLErrors();
-	if (this->render_preferences->lineAntiAliasing)
+	if (preferences->lineAntiAliasing)
 	{
 		glEnable(GL_LINE_SMOOTH);
 		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
@@ -135,7 +135,7 @@
 	else {
 		glDisable(GL_LINE_SMOOTH);
 	}
-	if (this->render_preferences->style != gl::RenderStyle::PickScene)
+	if (preferences->style != gl::RenderStyle::PickScene)
 	{
 		const QColor& backgroundColor = this->build_preferences->backgroundColor;
 		glClearColor(
@@ -151,7 +151,7 @@
 		gl::setShaderUniform(&this->shaders, "useLighting", GL_FALSE);
 	}
 	this->checkForGLErrors();
-	const QColor qs = this->render_preferences->selectedColor;
+	const QColor qs = preferences->selectedColor;
 	const glm::vec4 selectedColor{qs.redF(), qs.greenF(), qs.blueF(), 1.0f};
 	gl::setShaderUniformVector(&this->shaders, "selectedColor", selectedColor);
 	gl::setShaderUniform(&this->shaders, "highlighted", this->highlighted.value);
@@ -160,18 +160,18 @@
 	glEnable(GL_DEPTH_TEST);
 	glEnable(GL_POLYGON_OFFSET_FILL);
 	glPolygonOffset(1.0f, 1.0f);
-	glLineWidth(this->render_preferences->lineThickness);
+	glLineWidth(preferences->lineThickness);
 	const auto renderAllArrays = [this](){
 		// Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering.
 		this->renderVao<gl::ArrayClass::Triangles>();
 		this->renderVao<gl::ArrayClass::Quads>();
 		this->renderVao<gl::ArrayClass::Lines>();
 	};
-	if (this->render_preferences->wireframe)
+	if (preferences->wireframe)
 	{
 		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 	}
-	switch (this->render_preferences->style)
+	switch (preferences->style)
 	{
 	case gl::RenderStyle::Normal:
 		this->setFragmentStyle(gl::FragmentStyle::Normal);
@@ -441,18 +441,15 @@
 		.drawAxes = false,
 		.wireframe = false,
 	};
-	const gl::RenderPreferences* old_render_preferences = this->render_preferences;
-	this->render_preferences = &pick_scene_preferences;
 	this->makeCurrent();
 	QOpenGLFramebufferObject fbo{this->width(), this->height(), QOpenGLFramebufferObject::CombinedDepthStencil};
 	fbo.bind();
-	this->renderScene();
+	this->renderScene(&pick_scene_preferences);
 	std::array<GLubyte, 3> data;
 	this->checkForGLErrors();
 	glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);
 	this->checkForGLErrors();
 	fbo.release();
-	this->render_preferences = old_render_preferences;
 	return gl::idFromUcharColor(data);
 }
 
--- a/src/gl/partrenderer.h	Wed Apr 19 22:51:56 2023 +0300
+++ b/src/gl/partrenderer.h	Sat Jun 10 17:26:32 2023 +0300
@@ -69,7 +69,7 @@
 	void wheelEvent(QWheelEvent* event) override;
 	glm::vec3 unproject(const glm::vec3& win) const;
 	void setFragmentStyle(gl::FragmentStyle fragStyle);
-	void renderScene();
+	void renderScene(const gl::RenderPreferences* preferences);
 	void updateViewMatrix();
 	void updateModelMatrix();
 	void renderVao(const gl::ArrayClass arrayClass, const GLenum glType);

mercurial