Fix pick scene rendering: we cannot use glReadPixels when using multisampling, so we need to render the pick scene to a separate frame buffer

Mon, 20 Jun 2022 21:14:17 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 21:14:17 +0300
changeset 238
b8ad4c12d937
parent 237
10a6298f636f
child 239
74ce5ac84f25

Fix pick scene rendering: we cannot use glReadPixels when using multisampling, so we need to render the pick scene to a separate frame buffer

src/gl/partrenderer.cpp file | annotate | diff | comparison | revisions
--- a/src/gl/partrenderer.cpp	Mon Jun 20 19:49:56 2022 +0300
+++ b/src/gl/partrenderer.cpp	Mon Jun 20 21:14:17 2022 +0300
@@ -18,6 +18,7 @@
 
 #include <glm/ext/matrix_transform.hpp>
 #include <glm/ext/matrix_clip_space.hpp>
+#include <QOpenGLFramebufferObject>
 #include <QPainter>
 #include <GL/glu.h>
 #include <QMouseEvent>
@@ -461,13 +462,15 @@
 	const gl::RenderStyle oldRenderStyle = this->renderPreferences.style;
 	this->renderPreferences.style = gl::RenderStyle::PickScene;
 	this->makeCurrent();
+	QOpenGLFramebufferObject fbo{this->width(), this->height(), QOpenGLFramebufferObject::CombinedDepthStencil};
+	fbo.bind();
 	this->renderScene();
 	std::array<GLubyte, 3> data;
 	this->checkForGLErrors();
 	glfunc.glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);
 	this->checkForGLErrors();
+	fbo.release();
 	this->renderPreferences.style = oldRenderStyle;
-	this->update();
 	return gl::idFromColor(data);
 }
 

mercurial