Compare commits

..

3 Commits

15 changed files with 164 additions and 47 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,13 @@
#include "BaseStyle.h"
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,4 +30,13 @@ namespace Renderer
std::shared_ptr<TransformStyle> transform;
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,8 +10,13 @@ std::vector<BaseStyle> Renderer::ElementStyleFillDemo::toBaseStyles() const
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
{
return { BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleStroke>(0.02, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared<StrokePlain>(QColor(0, 0, 255), 0, 0.8))) };
std::make_shared<MaterialStyleStroke>(width, StrokeType::kLeftSide, StrokeEndType::kRound, std::make_shared<StrokePlain>(QColor(0, 0, 255), 0, 0.8))) };
}

View File

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

View File

@ -3,7 +3,7 @@
using namespace Renderer;
Renderer::StrokePlain::StrokePlain(QColor color, float metallic, float roughness)
: color(color), metallic(metallic), roughness(roughness)
: material{ color,metallic,roughness }
{
}
@ -14,16 +14,14 @@ MaterialStrokeType Renderer::StrokePlain::type() const
std::vector<GLfloat> Renderer::StrokePlain::encoded() const
{
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(metallic, roughness, 0, 0))),
glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF()))) };
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))),
glm::uintBitsToFloat(glm::packUnorm4x8(material.toVec().first)) };
}
bool Renderer::StrokePlain::operator==(const MaterialStroke& m) const
{
return type() == m.type()
&& color == static_cast<const StrokePlain&>(m).color
&& metallic == static_cast<const StrokePlain&>(m).metallic
&& roughness == static_cast<const StrokePlain&>(m).roughness;
&& material == static_cast<const StrokePlain&>(m).material;
}
Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke)
@ -40,6 +38,10 @@ std::vector<GLfloat> Renderer::MaterialStyleStroke::encoded() const
{
std::vector<GLfloat> v = { width };
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());
return v;
}

View File

@ -3,7 +3,7 @@
namespace Renderer
{
enum class MaterialStrokeType { kPlain };
enum class MaterialStrokeType { kPlain, kLinearGradient, kRadialGradient};
class MaterialStroke
{
@ -21,14 +21,22 @@ namespace Renderer
virtual std::vector<GLfloat> encoded() const override;
virtual bool operator==(const MaterialStroke&) const override;
QColor color;
float metallic;
float roughness;
Material material;
};
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 StrokeEndType { kRound };
enum class StrokeEndType { kRound = 0 };
class MaterialStyleStroke : public MaterialStyle
{

View File

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

View File

@ -0,0 +1,26 @@
#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

@ -0,0 +1,36 @@
#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,6 +105,12 @@
</ItemDefinitionGroup>
<ItemGroup>
<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" />
</ItemGroup>
<ItemGroup>
@ -116,6 +122,9 @@
<Value>$(QtDllPath)</Value>
</T4ParameterValues>
</ItemGroup>
<ItemGroup>
<QtMoc Include="ElementRendererTest.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />

View File

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