--- a/src/gl/partrenderer.cpp Sun Jun 12 20:47:04 2022 +0300 +++ b/src/gl/partrenderer.cpp Sun Jun 12 23:59:37 2022 +0300 @@ -46,6 +46,18 @@ this->needBuild = true; }); connect(model, &Model::rowsRemoved, [&]{ this->needBuild = true; }); + const auto updateLayerMvpMatrix = [this]{ + const glm::mat4 newMvpMatrix = this->projectionMatrix * this->viewMatrix * this->modelMatrix; + for (RenderLayer* layer : this->activeRenderLayers) { + layer->mvpMatrixChanged(newMvpMatrix); + } + for (RenderLayer* layer : this->inactiveRenderLayers) { + layer->mvpMatrixChanged(newMvpMatrix); + } + }; + connect(this, &PartRenderer::modelMatrixChanged, updateLayerMvpMatrix); + connect(this, &PartRenderer::viewMatrixChanged, updateLayerMvpMatrix); + connect(this, &PartRenderer::projectionMatrixChanged, updateLayerMvpMatrix); } PartRenderer::~PartRenderer() @@ -69,6 +81,12 @@ abort(); } gl::initializeModelShaders(&this->shaders); + for (RenderLayer* layer : this->activeRenderLayers) { + layer->initializeGL(); + } + for (RenderLayer* layer : this->inactiveRenderLayers) { + layer->initializeGL(); + } connect(this->model, &Model::dataChanged, this, &PartRenderer::build); this->initialized = true; this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); @@ -111,6 +129,9 @@ glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); this->renderScene(); + for (RenderLayer* layer : this->activeRenderLayers) { + layer->paintGL(); + } } void PartRenderer::renderScene() @@ -296,6 +317,23 @@ this->update(); } +void PartRenderer::addRenderLayer(RenderLayer* layer) +{ + this->activeRenderLayers.push_back(layer); + this->update(); +} + +void PartRenderer::setLayerEnabled(RenderLayer* layer, bool enabled) +{ + auto& from = enabled ? this->inactiveRenderLayers : this->activeRenderLayers; + auto& to = enabled ? this->activeRenderLayers : this->inactiveRenderLayers; + auto it = std::find(from.begin(), from.end(), layer); + if (it != from.end()) { + from.erase(it); + to.push_back(layer); + } +} + /** * @brief Converts the specified on the screen into the 3D world. The point is unprojected twice into 3D and the * intersection of the resulting line with the specified plane is returned. If the intersection point lies behind