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");
|
//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);
|
||||||
|
|
|
@ -36,7 +36,6 @@ void PreviewWindow::show()
|
||||||
|
|
||||||
void PreviewWindow::initializeGL()
|
void PreviewWindow::initializeGL()
|
||||||
{
|
{
|
||||||
this->renderer->initialize();
|
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue