ElementRenderer初始化移至构造函数
parent
f4f1547d21
commit
08e54cfc30
|
@ -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);
|
||||
|
|
|
@ -36,7 +36,6 @@ void PreviewWindow::show()
|
|||
|
||||
void PreviewWindow::initializeGL()
|
||||
{
|
||||
this->renderer->initialize();
|
||||
initializeOpenGLFunctions();
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue