ElementRenderer初始化移至构造函数

TaoZhang-Branch
wuyize 2023-03-08 16:40:04 +08:00
parent f4f1547d21
commit 08e54cfc30
4 changed files with 6 additions and 25 deletions

View File

@ -32,9 +32,9 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
//
//QString strPath = QString("C:\\Users\\86177\\Pictures\\Screenshots\\test.png");
//QPixmap itemPixmap(strPath);
QPixmap itemPixmap(QSize(200,200));
itemPixmap.fill(Qt::red);
//QPixmap itemPixmap = elements[index]->getPaintObject().getDetail();
//QPixmap itemPixmap(QSize(200,200));
//itemPixmap.fill(Qt::red);
QPixmap itemPixmap = elements[index]->getPaintObject().getDetail();
qDebug() << this->parentWidget()->size();
//auto p = new QWidget();
//auto lb = new QLabel(p);

View File

@ -36,7 +36,6 @@ void PreviewWindow::show()
void PreviewWindow::initializeGL()
{
this->renderer->initialize();
initializeOpenGLFunctions();
}

View File

@ -12,11 +12,6 @@
#include "../Painting/MaterialStyleStroke.h"
using namespace Renderer;
Renderer::ElementRenderer::ElementRenderer(QOpenGLWidget* glWidget)
: glWidget(glWidget)
{
}
std::vector<glm::vec2> generatePathBuffer(const QPainterPath& path)
{
std::vector<glm::vec2> pathBuffer;
@ -119,18 +114,14 @@ QRectF calcBoundingRect(const QPainterPath& path, const std::vector<BaseStyle>&
return QRectF(QPointF(leftTop.x, leftTop.y), QPointF(rightBottom.x, rightBottom.y));
}
void Renderer::ElementRenderer::initialize()
Renderer::ElementRenderer::ElementRenderer(QOpenGLWidget* glWidget)
: glWidget(glWidget)
{
auto mainContext = QOpenGLContext::currentContext();
auto mainSurface = mainContext->surface();
surface.setFormat(mainContext->format());
surface.create();
mainContext->doneCurrent();
thread = std::jthread([&] {
std::cout << thread.get_id();
QOpenGLContext context;
context.setFormat(mainContext->format());
context.setShareContext(mainContext);
context.create();
context.makeCurrent(&surface);
@ -190,9 +181,6 @@ void Renderer::ElementRenderer::initialize()
while (!initialized)
std::this_thread::yield();
mainContext->makeCurrent(mainSurface);
}
std::pair<QImage, QPointF> Renderer::ElementRenderer::drawElement(const QPainterPath& path, const ElementStyle& style, float pixelRatio)

View File

@ -12,11 +12,6 @@ namespace Renderer
public:
ElementRenderer(QOpenGLWidget* glWidget);
/**
* @brief initializeGL
*/
void initialize();
/**
* @brief QImage
* @param path
@ -37,7 +32,6 @@ namespace Renderer
bool needDraw = false;
std::condition_variable draw;
std::mutex drawMutex;
const QPainterPath* path;
const ElementStyle* style;
float pixelRatio;