src/gl/partrenderer.cpp

changeset 382
94d5587bb0c4
parent 376
3cef3b016330
equal deleted inserted replaced
381:80bea7a6e84f 382:94d5587bb0c4
105 105
106 void PartRenderer::paintGL() 106 void PartRenderer::paintGL()
107 { 107 {
108 glEnable(GL_DEPTH_TEST); 108 glEnable(GL_DEPTH_TEST);
109 glShadeModel(GL_SMOOTH); 109 glShadeModel(GL_SMOOTH);
110 this->renderScene(); 110 this->renderScene(this->render_preferences);
111 for (RenderLayer* layer : this->activeRenderLayers) { 111 for (RenderLayer* layer : this->activeRenderLayers) {
112 layer->paintGL(); 112 layer->paintGL();
113 } 113 }
114 QPainter painter{this}; 114 QPainter painter{this};
115 painter.setRenderHint(QPainter::Antialiasing); 115 painter.setRenderHint(QPainter::Antialiasing);
116 for (RenderLayer* layer : this->activeRenderLayers) { 116 for (RenderLayer* layer : this->activeRenderLayers) {
117 layer->overpaint(&painter); 117 layer->overpaint(&painter);
118 } 118 }
119 } 119 }
120 120
121 void PartRenderer::renderScene() 121 void PartRenderer::renderScene(const gl::RenderPreferences* preferences)
122 { 122 {
123 if (this->needBuild) 123 if (this->needBuild)
124 { 124 {
125 gl::build(&this->shaders, this->model, this->colorTable, this->documents, this->build_preferences); 125 gl::build(&this->shaders, this->model, this->colorTable, this->documents, this->build_preferences);
126 this->boundingBox = gl::boundingBoxForModel(this->model, this->documents); 126 this->boundingBox = gl::boundingBoxForModel(this->model, this->documents);
127 this->needBuild = false; 127 this->needBuild = false;
128 } 128 }
129 this->checkForGLErrors(); 129 this->checkForGLErrors();
130 if (this->render_preferences->lineAntiAliasing) 130 if (preferences->lineAntiAliasing)
131 { 131 {
132 glEnable(GL_LINE_SMOOTH); 132 glEnable(GL_LINE_SMOOTH);
133 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); 133 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
134 } 134 }
135 else { 135 else {
136 glDisable(GL_LINE_SMOOTH); 136 glDisable(GL_LINE_SMOOTH);
137 } 137 }
138 if (this->render_preferences->style != gl::RenderStyle::PickScene) 138 if (preferences->style != gl::RenderStyle::PickScene)
139 { 139 {
140 const QColor& backgroundColor = this->build_preferences->backgroundColor; 140 const QColor& backgroundColor = this->build_preferences->backgroundColor;
141 glClearColor( 141 glClearColor(
142 static_cast<float>(backgroundColor.redF()), 142 static_cast<float>(backgroundColor.redF()),
143 static_cast<float>(backgroundColor.greenF()), 143 static_cast<float>(backgroundColor.greenF()),
149 { 149 {
150 glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 150 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
151 gl::setShaderUniform(&this->shaders, "useLighting", GL_FALSE); 151 gl::setShaderUniform(&this->shaders, "useLighting", GL_FALSE);
152 } 152 }
153 this->checkForGLErrors(); 153 this->checkForGLErrors();
154 const QColor qs = this->render_preferences->selectedColor; 154 const QColor qs = preferences->selectedColor;
155 const glm::vec4 selectedColor{qs.redF(), qs.greenF(), qs.blueF(), 1.0f}; 155 const glm::vec4 selectedColor{qs.redF(), qs.greenF(), qs.blueF(), 1.0f};
156 gl::setShaderUniformVector(&this->shaders, "selectedColor", selectedColor); 156 gl::setShaderUniformVector(&this->shaders, "selectedColor", selectedColor);
157 gl::setShaderUniform(&this->shaders, "highlighted", this->highlighted.value); 157 gl::setShaderUniform(&this->shaders, "highlighted", this->highlighted.value);
158 this->checkForGLErrors(); 158 this->checkForGLErrors();
159 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 159 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
160 glEnable(GL_DEPTH_TEST); 160 glEnable(GL_DEPTH_TEST);
161 glEnable(GL_POLYGON_OFFSET_FILL); 161 glEnable(GL_POLYGON_OFFSET_FILL);
162 glPolygonOffset(1.0f, 1.0f); 162 glPolygonOffset(1.0f, 1.0f);
163 glLineWidth(this->render_preferences->lineThickness); 163 glLineWidth(preferences->lineThickness);
164 const auto renderAllArrays = [this](){ 164 const auto renderAllArrays = [this](){
165 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. 165 // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering.
166 this->renderVao<gl::ArrayClass::Triangles>(); 166 this->renderVao<gl::ArrayClass::Triangles>();
167 this->renderVao<gl::ArrayClass::Quads>(); 167 this->renderVao<gl::ArrayClass::Quads>();
168 this->renderVao<gl::ArrayClass::Lines>(); 168 this->renderVao<gl::ArrayClass::Lines>();
169 }; 169 };
170 if (this->render_preferences->wireframe) 170 if (preferences->wireframe)
171 { 171 {
172 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 172 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
173 } 173 }
174 switch (this->render_preferences->style) 174 switch (preferences->style)
175 { 175 {
176 case gl::RenderStyle::Normal: 176 case gl::RenderStyle::Normal:
177 this->setFragmentStyle(gl::FragmentStyle::Normal); 177 this->setFragmentStyle(gl::FragmentStyle::Normal);
178 renderAllArrays(); 178 renderAllArrays();
179 break; 179 break;
439 .lineThickness = 3.0f, 439 .lineThickness = 3.0f,
440 .lineAntiAliasing = false, 440 .lineAntiAliasing = false,
441 .drawAxes = false, 441 .drawAxes = false,
442 .wireframe = false, 442 .wireframe = false,
443 }; 443 };
444 const gl::RenderPreferences* old_render_preferences = this->render_preferences;
445 this->render_preferences = &pick_scene_preferences;
446 this->makeCurrent(); 444 this->makeCurrent();
447 QOpenGLFramebufferObject fbo{this->width(), this->height(), QOpenGLFramebufferObject::CombinedDepthStencil}; 445 QOpenGLFramebufferObject fbo{this->width(), this->height(), QOpenGLFramebufferObject::CombinedDepthStencil};
448 fbo.bind(); 446 fbo.bind();
449 this->renderScene(); 447 this->renderScene(&pick_scene_preferences);
450 std::array<GLubyte, 3> data; 448 std::array<GLubyte, 3> data;
451 this->checkForGLErrors(); 449 this->checkForGLErrors();
452 glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); 450 glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);
453 this->checkForGLErrors(); 451 this->checkForGLErrors();
454 fbo.release(); 452 fbo.release();
455 this->render_preferences = old_render_preferences;
456 return gl::idFromUcharColor(data); 453 return gl::idFromUcharColor(data);
457 } 454 }
458 455
459 /** 456 /**
460 * @brief Changes the color of rendered fragments 457 * @brief Changes the color of rendered fragments

mercurial