src/gl/partrenderer.cpp

changeset 333
07e65a4c6611
parent 329
6d75fa09cc0c
child 338
719b909a7d2b
equal deleted inserted replaced
332:ae7f7fbb9cda 333:07e65a4c6611
48 this->setFocusPolicy(Qt::WheelFocus); 48 this->setFocusPolicy(Qt::WheelFocus);
49 QSurfaceFormat surfaceFormat; 49 QSurfaceFormat surfaceFormat;
50 surfaceFormat.setSamples(8); 50 surfaceFormat.setSamples(8);
51 this->setFormat(surfaceFormat); 51 this->setFormat(surfaceFormat);
52 const auto setNeedBuild = [&]{this->needBuild = true;}; 52 const auto setNeedBuild = [&]{this->needBuild = true;};
53 connect(model, &Model::rowsInserted, setNeedBuild); 53 connect(model, &QTextDocument::contentsChange, setNeedBuild);
54 connect(model, &Model::rowsRemoved, setNeedBuild);
55 connect(model, &Model::dataChanged, setNeedBuild);
56 connect(model, &Model::modelReset, setNeedBuild);
57 const auto updateLayerMvpMatrix = [this]{ 54 const auto updateLayerMvpMatrix = [this]{
58 const glm::mat4 newMvpMatrix = this->projectionMatrix * this->viewMatrix * this->modelMatrix; 55 const glm::mat4 newMvpMatrix = this->projectionMatrix * this->viewMatrix * this->modelMatrix;
59 for (RenderLayer* layer : this->activeRenderLayers) { 56 for (RenderLayer* layer : this->activeRenderLayers) {
60 layer->mvpMatrixChanged(newMvpMatrix); 57 layer->mvpMatrixChanged(newMvpMatrix);
61 } 58 }
80 layer->initializeGL(); 77 layer->initializeGL();
81 } 78 }
82 for (RenderLayer* layer : this->inactiveRenderLayers) { 79 for (RenderLayer* layer : this->inactiveRenderLayers) {
83 layer->initializeGL(); 80 layer->initializeGL();
84 } 81 }
85 connect(this->model, &Model::dataChanged, this, &PartRenderer::build); 82 connect(this->model, &QTextDocument::contentsChanged, this, &PartRenderer::build);
86 this->initialized = true; 83 this->initialized = true;
87 this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0}); 84 this->modelQuaternion = glm::angleAxis(glm::radians(30.0f), glm::vec3{-1, 0, 0});
88 this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0}); 85 this->modelQuaternion *= glm::angleAxis(glm::radians(225.0f), glm::vec3{-0, 1, 0});
89 this->updateModelMatrix(); 86 this->updateModelMatrix();
90 this->updateViewMatrix(); 87 this->updateViewMatrix();
435 this->viewMatrix * this->modelMatrix, 432 this->viewMatrix * this->modelMatrix,
436 this->projectionMatrix, 433 this->projectionMatrix,
437 viewportVector); 434 viewportVector);
438 } 435 }
439 436
440 ElementId PartRenderer::pick(QPoint where) 437 int32_t PartRenderer::pick(QPoint where)
441 { 438 {
442 // y is flipped, take that into account 439 // y is flipped, take that into account
443 where.setY(this->height() - where.y()); 440 where.setY(this->height() - where.y());
444 // Since we are dealing with pixel data right from the framebuffer, its size 441 // Since we are dealing with pixel data right from the framebuffer, its size
445 // will be affected by High DPI scaling. We need to take this into account 442 // will be affected by High DPI scaling. We need to take this into account
492 ModelId PartRenderer::getHighlightedObject() const 489 ModelId PartRenderer::getHighlightedObject() const
493 { 490 {
494 return this->highlighted; 491 return this->highlighted;
495 } 492 }
496 493
497 void PartRenderer::setSelection(const QSet<ElementId>& selection) 494 void PartRenderer::setSelection(const QSet<int32_t>& selection)
498 { 495 {
496 #if 0
499 Q_ASSERT(not selection.contains({0})); 497 Q_ASSERT(not selection.contains({0}));
500 gl::setModelShaderSelectedObjects(&this->shaders, selection); 498 gl::setModelShaderSelectedObjects(&this->shaders, selection);
501 this->update(); 499 this->update();
500 #endif
502 } 501 }
503 502
504 glm::vec3 PartRenderer::cameraVector(const QPointF& point) const 503 glm::vec3 PartRenderer::cameraVector(const QPointF& point) const
505 { 504 {
506 const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0}); 505 const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0});

mercurial