Преглед на файлове

frame of julia preview scaled and texture upload thread

Nicolas Winkler преди 4 години
родител
ревизия
52a3da4ebe
променени са 4 файла, в които са добавени 79 реда и са изтрити 6 реда
  1. 7 4
      FractalWidget.cpp
  2. 46 1
      FractalZoomWidget.cpp
  3. 25 1
      FractalZoomWidget.h
  4. 1 0
      GradientWidget.cpp

+ 7 - 4
FractalWidget.cpp

@@ -206,19 +206,22 @@ void FractalWidget::paintGL(void)
         float minRes = getResolutionX();
         if (getResolutionY() < minRes)
             minRes = getResolutionY();
-        float offset = minRes * 0.1;
+        float offset = minRes * 0.05;
         if (offset < 30)
             offset = 30;
-        QRectF area{
-            60, 60,
+        QRectF area {
+            offset, offset,
             minRes * 0.3, minRes * 0.3
         };
 
         EscapeTimeVisualWidget::drawJulia(jx, jy, area, mandelInfo.smooth);
 
         QPainter framePainter{ this };
+        qreal dpr = devicePixelRatioF();
+        framePainter.scale(1.0 / dpr, 1.0 / dpr);
         QPen pen{ QColor{ 255, 255, 255 } };
-        pen.setWidth(2);
+        pen.setWidthF(1.5 * dpr);
+        pen.setJoinStyle(Qt::PenJoinStyle::RoundJoin);
         framePainter.setPen(pen);
         framePainter.drawRect(area);
     }

+ 46 - 1
FractalZoomWidget.cpp

@@ -144,6 +144,27 @@ void Calcer::redirect(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp)
 }
 
 
+TextureUploader::TextureUploader(EscapeTimeVisualWidget& shareWith, QObject* parent) :
+    QThread{ parent },
+    owner{ shareWith }
+{
+    this->context = new QOpenGLContext(this);
+    this->context->setFormat(owner.context()->format());
+    this->context->setScreen(owner.context()->screen());
+    this->context->setShareContext(owner.context());
+    bool created = this->context->create();
+}
+
+
+void TextureUploader::upload(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp)
+{
+    auto etvImg = std::make_shared<ETVImage>(owner, *bmp);
+    delete bmp;
+    bmp = nullptr;
+    uploaded(level, i, j, std::move(etvImg));
+}
+
+
 const int FractalZoomWidget::chunkSize = 256;
 
 
@@ -152,8 +173,10 @@ FractalZoomWidget::FractalZoomWidget(QWidget* parent) :
     calcer{ *this }
 {
     qMetaTypeId<GridIndex>();
-    connect(&calcer, &Calcer::done, this, &FractalZoomWidget::cellReady);
     setMaxIterations(250);
+
+    uploader = nullptr;
+    uploadeThread = nullptr;
 }
 
 
@@ -386,6 +409,19 @@ void FractalZoomWidget::initializeGL(void)
     Bitmap<float> empty{ 1, 1 };
     empty.get(0, 0) = 0.0f;
     emptyImage = new ETVImage(*this, empty);
+
+
+    if (useUploadThread) {
+        uploader = new TextureUploader(*this, this);
+        uploadeThread = new QThread(this);
+        uploader->moveToThread(uploadeThread);
+        uploadeThread->start();
+        connect(&calcer, &Calcer::done, uploader, &TextureUploader::upload);
+        connect(uploader, &TextureUploader::uploaded, this, &FractalZoomWidget::cellReadyTex);
+    }
+    else {
+        connect(&calcer, &Calcer::done, this, &FractalZoomWidget::cellReady);
+    }
 }
 
 
@@ -477,3 +513,12 @@ void FractalZoomWidget::cellReady(int level, GridIndex i, GridIndex j, Bitmap<fl
     delete bmp;
     emit update();
 }
+
+
+
+void FractalZoomWidget::cellReadyTex(int level, GridIndex i, GridIndex j, std::shared_ptr<ETVImage> img)
+{
+    this->getGrid(level).setCell(i, j,
+        std::make_unique<GridElement>(true, std::make_shared<ImageClip>(std::move(img))));
+    emit update();
+}

+ 25 - 1
FractalZoomWidget.h

@@ -10,6 +10,7 @@
 
 class FractalZoomWidget;
 
+Q_DECLARE_METATYPE(std::shared_ptr<ETVImage>)
 
 
 ///
@@ -66,6 +67,23 @@ signals:
 };
 
 
+class TextureUploader :
+    public QThread
+{
+    Q_OBJECT
+
+    QOpenGLContext* context;
+    EscapeTimeVisualWidget& owner;
+public:
+    TextureUploader(EscapeTimeVisualWidget& shareWith, QObject* parent = nullptr);
+
+public slots:
+    void upload(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp);
+signals:
+    void uploaded(int level, GridIndex i, GridIndex j, std::shared_ptr<ETVImage>);
+};
+
+
 class FractalZoomWidget :
     public EscapeTimeVisualWidget
 {
@@ -78,6 +96,11 @@ class FractalZoomWidget :
     Calcer calcer;
 
     ETVImage* emptyImage;
+
+    const bool useUploadThread = true;
+    TextureUploader* uploader;
+    QThread* uploadeThread;
+
 protected:
     mnd::MandelInfo mandelInfo;
 
@@ -120,9 +143,10 @@ public:
     virtual void initializeGL(void) override;
     virtual void resizeGL(int w, int h) override;
     virtual void paintGL(void) override;
-protected slots:
 
+protected slots:
     void cellReady(int level, GridIndex i, GridIndex j, Bitmap<float>* bmp);
+    void cellReadyTex(int level, GridIndex i, GridIndex j, std::shared_ptr<ETVImage> img);
 };
 
 #endif // FRACTALZOOMWIDGET_H

+ 1 - 0
GradientWidget.cpp

@@ -374,6 +374,7 @@ void GradientWidget::removeSelectedHandle(void)
         points.erase(points.begin() + selectedHandle);
         selectedHandle = -1;
         updateGradient();
+        update();
     }
 }