From 1905b66179fae1e96fc39cc6d542af258a0fb76e Mon Sep 17 00:00:00 2001 From: wuyize Date: Fri, 10 Feb 2023 13:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=BA=BF=E7=9A=84=E5=BE=84?= =?UTF-8?q?=E5=90=91=E6=B8=90=E5=8F=98\=E5=88=86=E5=B1=82=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shaders/element.comp | 56 +++++++-- .../Shaders/painting.comp | 108 ++++++++++++------ .../src/Renderer/Model.cpp | 7 +- .../src/Renderer/Painting/ElementStyle.cpp | 20 +++- .../src/Renderer/Painting/ElementStyle.h | 10 ++ .../Renderer/Painting/MaterialStyleStroke.cpp | 51 ++++++++- .../Renderer/Painting/MaterialStyleStroke.h | 14 ++- .../src/Renderer/Painting/Painting.cpp | 2 +- .../src/Renderer/Preview/ElementRenderer.cpp | 28 ++--- .../src/Renderer/Preview/ElementRenderer.h | 2 +- README.md | 10 +- UnitTest/ElementRendererTest.cpp | 88 +++++++++++--- UnitTest/ElementRendererTest.h | 56 +++++---- 13 files changed, 321 insertions(+), 131 deletions(-) diff --git a/ArchitectureColoredPainting/Shaders/element.comp b/ArchitectureColoredPainting/Shaders/element.comp index 67d2ca9..72779c8 100644 --- a/ArchitectureColoredPainting/Shaders/element.comp +++ b/ArchitectureColoredPainting/Shaders/element.comp @@ -893,21 +893,56 @@ bool angleLargeThanPi(vec2 a, vec2 b) /************************************************************************************/ -void drawLine(in float d, in uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness) +void drawLine(in float d, inout uint styleIndex, out vec4 elementColor, out vec2 metallicRoughness) { elementColor = vec4(1); - metallicRoughness = vec2(0.8); - // switch(int(elementData[styleIndex+3])) - switch (0) + metallicRoughness = vec2(0.8); + uint headUint = floatBitsToUint(style[styleIndex+1]); + vec4 head = unpackUnorm4x8(headUint); + switch (int(head.a*100)%10) + //switch (2) { + /// Plain case 0: { - elementColor = vec4(unpackUnorm4x8(floatBitsToUint(style[styleIndex + 2])).rgb, 1); - metallicRoughness = vec2(unpackUnorm4x8(floatBitsToUint(style[styleIndex + 1])).rg); + metallicRoughness = head.rg; + elementColor = vec4(unpackUnorm4x8(floatBitsToUint(style[styleIndex+2])).rgb, 1); break; } + /// RadialGradient case 1: { - elementColor = vec4(mix(vec3(0), vec3(1), d), 1); - metallicRoughness = vec2(0, 0.8); + uint size = headUint%(1<<15); + bool gradual = (headUint&(1<<15))!=0; + + uint lastData = floatBitsToUint(style[styleIndex+2+0*2]); + float lastLevel = 0; + vec2 lastMetallicRoughness = unpackUnorm4x8(lastData).rg; + vec4 lastColor = vec4(unpackUnorm4x8(floatBitsToUint(style[styleIndex+3+0*2])).rgb, 1); + + for(uint i = 0; i < size; i++) + { + uint data = floatBitsToUint(style[styleIndex+2+i*2]); + float level = unpackUnorm2x16(data).y; + vec4 currentColor = vec4(unpackUnorm4x8(floatBitsToUint(style[styleIndex+3+i*2])).rgb, 1); + vec2 currentMetallicRoughness = unpackUnorm4x8(data).rg; + if (d <= level) + { + if(gradual) + { + float a = (d-lastLevel)/(level-lastLevel); + elementColor = mix(lastColor, currentColor, a); + metallicRoughness = mix(lastMetallicRoughness, currentMetallicRoughness, a); + } + else + { + elementColor = currentColor; + metallicRoughness = currentMetallicRoughness; + } + break; + } + lastMetallicRoughness = currentMetallicRoughness; + lastColor = currentColor; + lastLevel = level; + } break; } case 2: { @@ -987,8 +1022,9 @@ void main() else // Stroke { float minDistance = 1e38; - // float lineType = elementData[styleIndex+4]; - float lineType = 2; + vec4 styleHead = unpackUnorm4x8(floatBitsToUint(style[styleIndex+1])); + float lineType = floor(styleHead.b*10); + //float lineType = 2; int debugBegin = 0; for (uint pathIndex = 0; pathIndex < pathSize; pathIndex++) { diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index 896d544..84fd5a6 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -898,44 +898,76 @@ void drawLine(in float d, in uint styleIndex, out vec4 elementColor, out vec2 me { elementColor = vec4(1); metallicRoughness = vec2(0.8); - //switch(int(elementData[styleIndex+3])) - switch(0) - { - case 0: - { - elementColor = vec4(unpackUnorm4x8(floatBitsToUint(elementData[styleIndex+2])).rgb,1); - metallicRoughness = vec2(unpackUnorm4x8(floatBitsToUint(elementData[styleIndex+1])).rg); - break; - } - case 1: - { - elementColor = vec4(mix(vec3(0), vec3(1), d), 1); - metallicRoughness = vec2(0,0.8); - break; - } - case 2: - { - float levels[] = {0.25,0.5,0.75}; - vec3 colors[] = {vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(1,1,0)}; - int i = 0; - while(i<3) - { - if(d> style = { + vector> style = { std::make_shared(), - std::make_shared(0.02) + std::make_shared(0.02), + std::make_shared(0.02) }; vector> element = { std::make_shared(Element{ contour[0], style[0]}), - std::make_shared(Element{ contour[1], style[1]}), + std::make_shared(Element{ contour[1], style[2]}), std::make_shared(Element{ contour[2], style[0]}), }; Painting painting; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp index 4cafdcd..262b456 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp @@ -18,5 +18,23 @@ Renderer::ElementStyleStrokeDemo::ElementStyleStrokeDemo(float width) std::vector Renderer::ElementStyleStrokeDemo::toBaseStyles() const { return { BaseStyle(std::make_shared(), - std::make_shared(width, StrokeType::kLeftSide, StrokeEndType::kRound, std::make_shared(QColor(0, 0, 255), 0, 0.8))) }; + std::make_shared(width, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared(QColor(0, 0, 255), 0, 0.8))) }; } + +Renderer::ElementStyleStrokeRadialGradientDemo::ElementStyleStrokeRadialGradientDemo(float width) + : width(width) +{ +} + +std::vector Renderer::ElementStyleStrokeRadialGradientDemo::toBaseStyles() const +{ + std::map materialMap = { + {0.25, Material{QColor(255,0,0)}}, + {0.50, Material{QColor(0,255,0)}}, + {0.75, Material{QColor(0,0,255)}}, + {1.00, Material{QColor(255,255,0)}}, + }; + return { BaseStyle(std::make_shared(), + std::make_shared(width, StrokeType::kLeftSide, StrokeEndType::kRound, + std::make_shared(materialMap, false))) }; +} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h index 1cbcea9..8b81e85 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h @@ -31,4 +31,14 @@ namespace Renderer protected: float width; }; + + class ElementStyleStrokeRadialGradientDemo : public ElementStyle + { + public: + ElementStyleStrokeRadialGradientDemo(float width); + virtual std::vector toBaseStyles() const override; + protected: + float width; + }; + } diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp index f9c9301..6f6ccd8 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.cpp @@ -1,4 +1,5 @@ #include "MaterialStyleStroke.h" +#include using namespace Renderer; @@ -7,6 +8,11 @@ Renderer::StrokePlain::StrokePlain(QColor color, float metallic, float roughness { } +Renderer::StrokePlain::StrokePlain(const Material& material) + : material(material) +{ +} + MaterialStrokeType Renderer::StrokePlain::type() const { return MaterialStrokeType::kPlain; @@ -24,8 +30,43 @@ bool Renderer::StrokePlain::operator==(const MaterialStroke& m) const && material == static_cast(m).material; } +Renderer::StrokeRadialGradient::StrokeRadialGradient(const std::map& materialMap, bool gradual) + : materialMap(materialMap), gradual(gradual) +{ +} + +MaterialStrokeType Renderer::StrokeRadialGradient::type() const +{ + return MaterialStrokeType::kRadialGradient; +} + +std::vector Renderer::StrokeRadialGradient::encoded() const +{ + GLuint head = materialMap.size() + (gradual ? (1 << 15) : 0); + + std::vector result = { glm::uintBitsToFloat(head) }; + for (auto& pair : materialMap) + { + auto [color, metallicRoughness] = pair.second.toVec(); + GLuint i = glm::packUnorm4x8(glm::vec4(metallicRoughness, 0, 0)); + glm::vec2 v = glm::unpackUnorm2x16(i); + v.y = pair.first; + result.push_back(glm::uintBitsToFloat(glm::packUnorm2x16(v))); + result.push_back(glm::uintBitsToFloat(glm::packUnorm4x8(color))); + qDebug() << pair.first; + } + return result; +} + +bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const +{ + return type() == m.type() + && gradual == static_cast(m).gradual + && materialMap == static_cast(m).materialMap; +} + Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr materialStroke) - : width(width), strokeType(strokeType), endType(endType), materialStroke(materialStroke) + : halfWidth(width/2), strokeType(strokeType), endType(endType), materialStroke(materialStroke) { } @@ -36,11 +77,11 @@ MaterialStyleType Renderer::MaterialStyleStroke::type() const std::vector Renderer::MaterialStyleStroke::encoded() const { - std::vector v = { width }; + std::vector v = { halfWidth }; auto encoded = materialStroke->encoded(); glm::vec4 head = glm::unpackUnorm4x8(glm::floatBitsToUint(encoded[0])); head.b = (float)strokeType / 10. + (float)endType / 100.; - head.a = 1; /// 预留 + head.a = 0.6 /*使得pack后小于0*/ + (float)materialStroke->type() / 100.; encoded[0] = glm::uintBitsToFloat(glm::packUnorm4x8(head)); v.insert(v.end(), encoded.begin(), encoded.end()); return v; @@ -51,9 +92,9 @@ bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const return type() == m.type() && *materialStroke == *static_cast(m).materialStroke; } -float Renderer::MaterialStyleStroke::getWidth() const +float Renderer::MaterialStyleStroke::getHalfWidth() const { - return width; + return halfWidth; } diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h index ef22b81..20c2eeb 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h @@ -3,7 +3,7 @@ namespace Renderer { - enum class MaterialStrokeType { kPlain, kLinearGradient, kRadialGradient}; + enum class MaterialStrokeType { kPlain = 0, kRadialGradient = 1, kLinearGradient = 2 }; class MaterialStroke { @@ -17,6 +17,7 @@ namespace Renderer { public: StrokePlain(QColor color, float metallic, float roughness); + StrokePlain(const Material& material); virtual MaterialStrokeType type() const override; virtual std::vector encoded() const override; virtual bool operator==(const MaterialStroke&) const override; @@ -27,12 +28,13 @@ namespace Renderer class StrokeRadialGradient : public MaterialStroke { public: - StrokeRadialGradient(QColor color, float metallic, float roughness); + StrokeRadialGradient(const std::map& materialMap, bool gradual); virtual MaterialStrokeType type() const override; virtual std::vector encoded() const override; virtual bool operator==(const MaterialStroke&) const override; - //std::map< + std::map materialMap; + bool gradual = true; }; enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 }; @@ -41,13 +43,13 @@ namespace Renderer class MaterialStyleStroke : public MaterialStyle { public: - MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr materialStroke); + MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr materialStroke); virtual MaterialStyleType type() const override; virtual std::vector encoded() const override; virtual bool operator==(const MaterialStyle&) const override; - float getWidth() const; + float getHalfWidth() const; protected: - float width; + float halfWidth; StrokeType strokeType; StrokeEndType endType; std::shared_ptr materialStroke; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp index f1b8337..9655bb8 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp @@ -43,7 +43,7 @@ void Renderer::Painting::addElement(ElementWithTransform elementWithTransform) { qDebug() << "Build LineTree-------------------------------------------------------------------------------------------------------"; LineTree lineTree(maxLineCount); - lineTree.buildLineTree(*element.contour, std::static_pointer_cast(element.style)->getWidth()); + lineTree.buildLineTree(*element.contour, std::static_pointer_cast(element.style)->getHalfWidth()); ContourBuffer elementBuffer; std::vector bvhLeaves = lineTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer); BvhTree bvhTree; diff --git a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp index 8c75783..ebb6ba0 100644 --- a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.cpp @@ -20,7 +20,7 @@ Renderer::ElementRenderer::ElementRenderer(QOpenGLWidget* glWidget) void Renderer::ElementRenderer::initialize() { initializeOpenGLFunctions(); - shader = std::make_shared(); + shader = std::make_unique(); if (!shader->addShaderFromSourceFile(QOpenGLShader::Compute, ":/Shaders/element.comp")) qDebug() << "ERROR: " << shader->log(); if (!shader->link()) @@ -37,30 +37,25 @@ std::vector generatePathBuffer(const QPainterPath& path) switch (element.type) { case QPainterPath::MoveToElement: - qDebug() << "MoveToElement"; pathBuffer.push_back(glm::vec2(std::numeric_limits::infinity())); pathBuffer.push_back(glm::vec2(element.x, element.y)); break; case QPainterPath::LineToElement: - qDebug() << "LineToElement"; - { - glm::vec2 end = glm::vec2(element.x, element.y); - glm::vec2 mid = (pathBuffer.back() + end) / 2.f; - pathBuffer.push_back(mid); - pathBuffer.push_back(mid); - pathBuffer.push_back(end); - } + { + glm::vec2 end = glm::vec2(element.x, element.y); + glm::vec2 mid = (pathBuffer.back() + end) / 2.f; + pathBuffer.push_back(mid); + pathBuffer.push_back(mid); + pathBuffer.push_back(end); break; + } case QPainterPath::CurveToElement: - qDebug() << "CurveToElement"; pathBuffer.push_back(glm::vec2(element.x, element.y)); break; case QPainterPath::CurveToDataElement: - qDebug() << "CurveToDataElement"; pathBuffer.push_back(glm::vec2(element.x, element.y)); break; } - qDebug() << element; } return pathBuffer; } @@ -95,11 +90,8 @@ QRectF calcBoundingRect(const QPainterPath& path, const std::vector& BaseTransform transform(originTransform.appliedTransformStyle(*baseStyle.transform)); if (baseStyle.material->type() == MaterialStyleType::kStroke) { - float halfWidth = std::static_pointer_cast(baseStyle.material)->getWidth() / 2; - transform.bound.x -= halfWidth; - transform.bound.y -= halfWidth; - transform.bound.z += halfWidth; - transform.bound.w += halfWidth; + float halfWidth = std::static_pointer_cast(baseStyle.material)->getHalfWidth(); + transform.bound += glm::vec4(glm::vec2(-halfWidth), glm::vec2(halfWidth)); } glm::vec2 points[] = { glm::vec2(transform.bound.x, transform.bound.y), diff --git a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.h b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.h index d105757..ca88d44 100644 --- a/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.h +++ b/ArchitectureColoredPainting/src/Renderer/Preview/ElementRenderer.h @@ -28,7 +28,7 @@ namespace Renderer std::pair drawElement(const QPainterPath& path, const ElementStyle& style, float pixelRatio, bool releaseContext = true); protected: QOpenGLWidget* glWidget; - std::shared_ptr shader; + std::unique_ptr shader; }; } diff --git a/README.md b/README.md index 946bee7..8b212e5 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,9 @@ ### 鍦烘櫙娓叉煋锛圧enderer锛 -閲囩敤 PBR (閲戝睘搴-绮楃硻搴) 鏉愯川妯″瀷锛屽満鏅腑瀛樺湪涓涓柟鍚戝厜锛屽彲鎷栧姩婊戝姩鏉¤皟鏁村厜婧愭柟鍚戣瀵熸潗璐ㄦ晥鏋溿 - -宸插疄鐜癇VH鍔犻熺粨鏋勭殑寤虹珛 - -宸插疄鐜板崟鍥惧厓鐨勬媶鍒嗭紝鍗冲垝鍒嗙綉鏍煎苟鐢熸垚蹇嵎娈靛拰缂犵粫澧為噺 +閲囩敤 PBR (閲戝睘搴-绮楃硻搴) 鏉愯川妯″瀷锛屽満鏅腑瀛樺湪涓涓柟鍚戝厜锛屽彲鎷栧姩婊戝姩鏉¤皟鏁村厜婧愭柟鍚戣瀵熸潗璐ㄦ晥鏋 宸插疄鐜扮敱鍥惧厓鏁版嵁寤虹珛瀹屾暣褰╃粯缂栫爜 -宸插疄鐜扮嚎鐨勫崟渚ф弿杈 - -寰呭畬鍠勫浘鍏冩牱寮忕殑缂栬В鐮 +宸插疄鐜伴潰鐨勭函鑹叉牱寮忥紝绾跨殑绾壊銆佸緞鍚戞笎鍙/鍒嗗眰銆佸崟渚х瓑鏍峰紡 diff --git a/UnitTest/ElementRendererTest.cpp b/UnitTest/ElementRendererTest.cpp index 9b4f0f8..711a18f 100644 --- a/UnitTest/ElementRendererTest.cpp +++ b/UnitTest/ElementRendererTest.cpp @@ -2,25 +2,81 @@ #include #include #include "ElementRendererTest.h" +#include "Renderer/Painting/ElementStyle.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; +using namespace Renderer; namespace UnitTest { - TEST_CLASS(ElementRendererTest) - { - public: - TEST_METHOD(TestMethod1) - { - QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); - char arg[] = ""; - char* argv[] = { arg }; - int argc = 1; - QApplication a(argc, argv); - TestGLWidget w; - w.show(); - a.exec(); - } - }; + TEST_CLASS(ElementRendererTest) + { + public: + TEST_METHOD(TestStrokePlain) + { + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + char* argv[] = { (char*)"" }; + int argc = 1; + QApplication a(argc, argv); + Renderer::ElementStyleStrokeDemo style(2); + TestGLWidget w(style); + w.show(); + a.exec(); + } + TEST_METHOD(TestStrokeRadialGradient1) + { + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + char* argv[] = { (char*)"" }; + int argc = 1; + QApplication a(argc, argv); + class StyleStrokeRadialGradient : public Renderer::ElementStyle + { + virtual std::vector toBaseStyles() const override + { + std::map materialMap = { + {0.25, Material{QColor(255,0,0)}}, + {0.50, Material{QColor(0,255,0)}}, + {0.75, Material{QColor(0,0,255)}}, + {1.00, Material{QColor(255,255,0)}}, + }; + return { BaseStyle(std::make_shared(), + std::make_shared(4, StrokeType::kLeftSide, StrokeEndType::kRound, + std::make_shared(materialMap, false))) }; + } + } style; + TestGLWidget w(style); + w.show(); + a.exec(); + } + TEST_METHOD(TestStrokeRadialGradient2) + { + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + char* argv[] = { (char*)"" }; + int argc = 1; + QApplication a(argc, argv); + class StyleStrokeRadialGradient : public Renderer::ElementStyle + { + virtual std::vector toBaseStyles() const override + { + std::map materialMap = { + {0.50, Material{QColor(0,255,0)}}, + {0.75, Material{QColor(0,0,255)}}, + {1.00, Material{QColor(255,255,0)}}, + }; + return { BaseStyle(std::make_shared(), + std::make_shared(4, StrokeType::kLeftSide, StrokeEndType::kRound, + std::make_shared(materialMap, true))) }; + } + } style; + TestGLWidget w(style); + w.show(); + a.exec(); + } + }; } diff --git a/UnitTest/ElementRendererTest.h b/UnitTest/ElementRendererTest.h index 1e95b8d..4ddb3c0 100644 --- a/UnitTest/ElementRendererTest.h +++ b/UnitTest/ElementRendererTest.h @@ -9,28 +9,36 @@ namespace UnitTest { - class TestGLWidget : public QOpenGLWidget, protected QOpenGLFunctions - { - Q_OBJECT - private: - Renderer::ElementRenderer renderer; - public: - TestGLWidget(QWidget* parent = nullptr) : QOpenGLWidget(parent), renderer(this) {}; - void initializeGL() override - { - initializeOpenGLFunctions(); - renderer.initialize(); - }; - void paintGL() override - { - glClearColor(1.0, 1.0, 1.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - QPainterPath path; - QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", path); - auto [img, pos] = renderer.drawElement(path, Renderer::ElementStyleStrokeDemo(2), 1, false); - QPainter painter(this); - painter.drawImage(pos, img); - }; - void resizeGL(int w, int h) override {}; - }; + class TestGLWidget : public QOpenGLWidget, protected QOpenGLFunctions + { + Q_OBJECT + private: + Renderer::ElementRenderer renderer; + Renderer::ElementStyle& style; + public: + TestGLWidget(Renderer::ElementStyle& style, QWidget* parent = nullptr) + : QOpenGLWidget(parent), renderer(this), style(style) {}; + void initializeGL() override + { + initializeOpenGLFunctions(); + renderer.initialize(); + }; + void paintGL() override + { + glClearColor(1.0, 1.0, 1.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + QPainterPath path; + QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", path); + /*QTransform transform; + transform.scale(10, 10); + transform.map(path);*/ + float pixelRatio = 30; + auto [img, pos] = renderer.drawElement(path, style, pixelRatio, false); + QPainter painter(this); + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(QPainter::HighQualityAntialiasing); + painter.drawImage(QRectF(QPointF(0, 0), img.size()/devicePixelRatioF()), img); + }; + void resizeGL(int w, int h) override {}; + }; } \ No newline at end of file