Compare commits

..

No commits in common. "e004809164f1558dd3b36ea2b9d5fffa481c9ce2" and "870531a0bec46361abbfb86ad576e61ad3d1ba9a" have entirely different histories.

15 changed files with 47 additions and 164 deletions

View File

@ -1033,9 +1033,8 @@ void main()
if (lineType == 2 || intTest % 2 == int(lineType)) if (lineType == 2 || intTest % 2 == int(lineType))
{ {
hitElement = true; hitElement = true;
//elementColor = vec4(1, 1, 0, 1); elementColor = vec4(1, 1, 0, 1);
vec2 metallicRoughness; // drawLine(minDistance / strokeWidth, styleIndex, elementColor, metallicRoughness);
drawLine(minDistance / strokeWidth, styleIndex, elementColor, metallicRoughness);
} }
else if (p3Last == p[0]) else if (p3Last == p[0])
hitElement = false; hitElement = false;

View File

@ -1034,9 +1034,8 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
uint contourIndex = linesOffset + leftChild - 0x80000000; uint contourIndex = linesOffset + leftChild - 0x80000000;
float minDistance = 1e38; float minDistance = 1e38;
uint lineCount = elementIndexs[contourIndex]; uint lineCount = elementIndexs[contourIndex];
vec4 styleHead = unpackUnorm4x8(floatBitsToUint(elementData[styleIndex+1])); //float lineType = elementData[styleIndex+4];
float lineType = floor(styleHead.b*10); float lineType = 2;
//float lineType = 2;
vec2 p3Last = vec2(1e38); vec2 p3Last = vec2(1e38);
vec2 p2Last = vec2(1e38); vec2 p2Last = vec2(1e38);
int debugBegin = 0; int debugBegin = 0;

View File

@ -6,62 +6,62 @@ PixelPath SimpleElement::getPaintObject() const
{ {
PixelPath result; PixelPath result;
result.addPath(painterPath); result.addPath(painterPath);
return result; return result;
} }
void SimpleElement::loadSvgFile(const QString& filePath) void SimpleElement::loadSvgFile(const QString& filePath)
{ {
// TODO ÑùʽÎÊÌâ // TODO ÑùʽÎÊÌâ
SvgFileLoader loader; SvgFileLoader loader;
loader.loadSvgFile(filePath, painterPath); loader.loadSvgFile(filePath, painterPath);
qDebug() << "load svg file success " << painterPath.elementCount(); qDebug() << "load svg file success "<<painterPath.elementCount();
} }
SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
{ {
painterPath.clear(); painterPath.clear();
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg"); //loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString()); loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString());
} }
GroupElement::GroupElement(FolderLayerWrapper* sourceLayer) GroupElement::GroupElement(FolderLayerWrapper *sourceLayer)
{ {
this->sourceLayer = sourceLayer; this->sourceLayer = sourceLayer;
} }
void GroupElement::setSourceLayer(FolderLayerWrapper* sourceLayer) void GroupElement::setSourceLayer(FolderLayerWrapper *sourceLayer)
{ {
this->sourceLayer = sourceLayer; this->sourceLayer = sourceLayer;
} }
PixelPath GroupElement::getPaintObject() const PixelPath GroupElement::getPaintObject() const
{ {
if (sourceLayer != nullptr) { if (sourceLayer != nullptr) {
sourceLayer->refresh(); sourceLayer->refresh();
return sourceLayer->getCache(); return sourceLayer->getCache();
} }
else else
return PixelPath(); return PixelPath();
} }
//TODO: apply styles and send back //TODO: apply styles and send back
PixelPath SimpleElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const { PixelPath SimpleElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const {
PixelPath result; PixelPath result;
Renderer::ElementStyleStrokeDemo demo(2); Renderer::ElementStyleStrokeDemo demo;
qDebug() << (renderer == nullptr) << "------------"; qDebug() << (renderer==nullptr)<<"------------";
auto [img, mov] = renderer->drawElement(painterPath, demo, 1.0, false); //auto [img, mov] = renderer->drawElement(painterPath,demo,1.0,false);
//qDebug() << img << " ------"; //qDebug() << img << " ------";
result.addImage(img, mov); //result.addImage(img, mov);
//result.addPath(painterPath); result.addPath(painterPath);
// QImage img(80,80,QImage::Format_ARGB32); // QImage img(80,80,QImage::Format_ARGB32);
// QPainter pt(&img); // QPainter pt(&img);
//pt.setPen(QPen(Qt::red, 2)); //pt.setPen(QPen(Qt::red, 2));
//pt.drawLine(0, 0, 80, 80); //pt.drawLine(0, 0, 80, 80);
//pt.end(); //pt.end();
//result.addImage(img, QPoint(0, 0)); //result.addImage(img, QPoint(0, 0));
return result; return result;
} }
PixelPath GroupElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const { PixelPath GroupElement::getPaintObject(std::vector<Renderer::ElementStyleStrokeDemo> styles) const {
return getPaintObject(); return getPaintObject();
} }
//BitmapPath::BitmapPath() { //BitmapPath::BitmapPath() {

View File

@ -392,7 +392,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
vector<std::shared_ptr<ElementStyle>> style = { vector<std::shared_ptr<ElementStyle>> style = {
std::make_shared<ElementStyleFillDemo>(), std::make_shared<ElementStyleFillDemo>(),
std::make_shared<ElementStyleStrokeDemo>(0.02) std::make_shared<ElementStyleStrokeDemo>()
}; };
vector<std::shared_ptr<Element>> element = { vector<std::shared_ptr<Element>> element = {

View File

@ -1,13 +1,3 @@
#include "BaseStyle.h" #include "BaseStyle.h"
using namespace Renderer; using namespace Renderer;
bool Renderer::Material::operator==(const Material& m) const
{
return color == m.color && metallic == m.metallic && roughness == m.roughness;
}
std::pair<glm::vec4, glm::vec2> Renderer::Material::toVec() const
{
return { glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF()), glm::vec2(metallic, roughness)};
}

View File

@ -30,13 +30,4 @@ namespace Renderer
std::shared_ptr<TransformStyle> transform; std::shared_ptr<TransformStyle> transform;
std::shared_ptr<MaterialStyle> material; std::shared_ptr<MaterialStyle> material;
}; };
struct Material
{
QColor color;
float metallic;
float roughness;
bool operator==(const Material&) const;
std::pair<glm::vec4, glm::vec2> toVec() const;
};
} }

View File

@ -10,13 +10,8 @@ std::vector<BaseStyle> Renderer::ElementStyleFillDemo::toBaseStyles() const
std::make_shared<MaterialStyleFill>(std::make_shared<FillPlain>(QColor(0, 255, 0), 0, 0.8))) }; std::make_shared<MaterialStyleFill>(std::make_shared<FillPlain>(QColor(0, 255, 0), 0, 0.8))) };
} }
Renderer::ElementStyleStrokeDemo::ElementStyleStrokeDemo(float width)
: width(width)
{
}
std::vector<BaseStyle> Renderer::ElementStyleStrokeDemo::toBaseStyles() const std::vector<BaseStyle> Renderer::ElementStyleStrokeDemo::toBaseStyles() const
{ {
return { BaseStyle(std::make_shared<TransformStyle>(), return { BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleStroke>(width, StrokeType::kLeftSide, StrokeEndType::kRound, std::make_shared<StrokePlain>(QColor(0, 0, 255), 0, 0.8))) }; std::make_shared<MaterialStyleStroke>(0.02, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared<StrokePlain>(QColor(0, 0, 255), 0, 0.8))) };
} }

View File

@ -26,9 +26,6 @@ namespace Renderer
class ElementStyleStrokeDemo : public ElementStyle class ElementStyleStrokeDemo : public ElementStyle
{ {
public: public:
ElementStyleStrokeDemo(float width);
virtual std::vector<BaseStyle> toBaseStyles() const override; virtual std::vector<BaseStyle> toBaseStyles() const override;
protected:
float width;
}; };
} }

View File

@ -3,7 +3,7 @@
using namespace Renderer; using namespace Renderer;
Renderer::StrokePlain::StrokePlain(QColor color, float metallic, float roughness) Renderer::StrokePlain::StrokePlain(QColor color, float metallic, float roughness)
: material{ color,metallic,roughness } : color(color), metallic(metallic), roughness(roughness)
{ {
} }
@ -14,14 +14,16 @@ MaterialStrokeType Renderer::StrokePlain::type() const
std::vector<GLfloat> Renderer::StrokePlain::encoded() const std::vector<GLfloat> Renderer::StrokePlain::encoded() const
{ {
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))), return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(metallic, roughness, 0, 0))),
glm::uintBitsToFloat(glm::packUnorm4x8(material.toVec().first)) }; glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF()))) };
} }
bool Renderer::StrokePlain::operator==(const MaterialStroke& m) const bool Renderer::StrokePlain::operator==(const MaterialStroke& m) const
{ {
return type() == m.type() return type() == m.type()
&& material == static_cast<const StrokePlain&>(m).material; && color == static_cast<const StrokePlain&>(m).color
&& metallic == static_cast<const StrokePlain&>(m).metallic
&& roughness == static_cast<const StrokePlain&>(m).roughness;
} }
Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke) Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke)
@ -38,10 +40,6 @@ std::vector<GLfloat> Renderer::MaterialStyleStroke::encoded() const
{ {
std::vector<GLfloat> v = { width }; std::vector<GLfloat> v = { width };
auto encoded = materialStroke->encoded(); auto encoded = materialStroke->encoded();
glm::vec4 head = glm::unpackUnorm4x8(glm::floatBitsToUint(encoded[0]));
head.b = (float)strokeType / 10. + (float)endType / 100.;
head.a = 1; /// Ô¤Áô
encoded[0] = glm::uintBitsToFloat(glm::packUnorm4x8(head));
v.insert(v.end(), encoded.begin(), encoded.end()); v.insert(v.end(), encoded.begin(), encoded.end());
return v; return v;
} }

View File

@ -3,7 +3,7 @@
namespace Renderer namespace Renderer
{ {
enum class MaterialStrokeType { kPlain, kLinearGradient, kRadialGradient}; enum class MaterialStrokeType { kPlain };
class MaterialStroke class MaterialStroke
{ {
@ -21,22 +21,14 @@ namespace Renderer
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual bool operator==(const MaterialStroke&) const override; virtual bool operator==(const MaterialStroke&) const override;
Material material; QColor color;
float metallic;
float roughness;
}; };
class StrokeRadialGradient : public MaterialStroke
{
public:
StrokeRadialGradient(QColor color, float metallic, float roughness);
virtual MaterialStrokeType type() const override;
virtual std::vector<GLfloat> encoded() const override;
virtual bool operator==(const MaterialStroke&) const override;
//std::map<
};
enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 }; enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 };
enum class StrokeEndType { kRound = 0 }; enum class StrokeEndType { kRound };
class MaterialStyleStroke : public MaterialStyle class MaterialStyleStroke : public MaterialStyle
{ {

View File

@ -1,8 +1,11 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "Renderer/Painting/CubicBezier.h"
#include <QGuiApplication> #include <QGuiApplication>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <FramelessHelper/Core/private/framelessconfig_p.h> #include <FramelessHelper/Core/private/framelessconfig_p.h>
using Renderer::CubicBezier;
extern "C" extern "C"
{ {
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
@ -17,7 +20,7 @@ int main(int argc, char* argv[])
//QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); //QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QApplication a(argc, argv); QApplication a(argc, argv);
//FramelessHelper::Core::setApplicationOSThemeAware(); FramelessHelper::Core::setApplicationOSThemeAware();
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow); FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow);

View File

@ -1,26 +0,0 @@
#include "CppUnitTest.h"
#include <QGuiApplication>
#include <QtWidgets/QApplication>
#include "ElementRendererTest.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
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();
}
};
}

View File

@ -1,36 +0,0 @@
#pragma once
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QPainter>
#include "Renderer/Preview/ElementRenderer.h"
#include "Editor/ThirdPartyLib/qquick/qquicksvgparser_p.h"
#include "Renderer/Painting/MaterialStyleStroke.h"
#include "Renderer/Painting/ElementStyle.h"
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 {};
};
}

View File

@ -105,12 +105,6 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="UnitTest.ui" /> <QtUic Include="UnitTest.ui" />
<ClCompile Include="ElementRendererTest.cpp">
<DynamicSource Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">input</DynamicSource>
<QtMocFileName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).moc</QtMocFileName>
<DynamicSource Condition="'$(Configuration)|$(Platform)'=='Release|x64'">input</DynamicSource>
<QtMocFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).moc</QtMocFileName>
</ClCompile>
<ClCompile Include="UnitTest.cpp" /> <ClCompile Include="UnitTest.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -122,9 +116,6 @@
<Value>$(QtDllPath)</Value> <Value>$(QtDllPath)</Value>
</T4ParameterValues> </T4ParameterValues>
</ItemGroup> </ItemGroup>
<ItemGroup>
<QtMoc Include="ElementRendererTest.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" /> <Import Project="$(QtMsBuild)\qt.targets" />

View File

@ -33,14 +33,4 @@
<ItemGroup> <ItemGroup>
<None Include="Qt.runsettings.tt" /> <None Include="Qt.runsettings.tt" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<QtMoc Include="ElementRendererTest.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ElementRendererTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project> </Project>