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"); //QString strPath = QString("C:\\Users\\86177\\Pictures\\Screenshots\\test.png");
//QPixmap itemPixmap(strPath); //QPixmap itemPixmap(strPath);
QPixmap itemPixmap(QSize(200,200)); //QPixmap itemPixmap(QSize(200,200));
itemPixmap.fill(Qt::red); //itemPixmap.fill(Qt::red);
//QPixmap itemPixmap = elements[index]->getPaintObject().getDetail(); QPixmap itemPixmap = elements[index]->getPaintObject().getDetail();
qDebug() << this->parentWidget()->size(); qDebug() << this->parentWidget()->size();
//auto p = new QWidget(); //auto p = new QWidget();
//auto lb = new QLabel(p); //auto lb = new QLabel(p);

View File

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

View File

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

View File

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