重构了Painting等

TaoZhang-Branch
wuyize 2023-03-03 20:30:45 +08:00
parent 50bc51a8a6
commit 4c623dd5b3
21 changed files with 185 additions and 283 deletions

View File

@ -140,7 +140,6 @@
<ClCompile Include="src\Renderer\Painting\LineTree.cpp" />
<ClCompile Include="src\Renderer\Painting\MaterialStyleStroke.cpp" />
<ClCompile Include="src\Renderer\Painting\Painting.cpp" />
<ClCompile Include="src\Renderer\Painting\PaintingHelper.cpp" />
<ClCompile Include="src\Renderer\PaintingMesh.cpp" />
<ClCompile Include="src\Renderer\Preview\ElementRenderer.cpp" />
<ClCompile Include="src\Renderer\RendererGLWidget.cpp" />
@ -226,7 +225,6 @@
<ClInclude Include="src\Renderer\Painting\Line.h" />
<ClInclude Include="src\Renderer\Mesh.h" />
<ClInclude Include="src\Renderer\Model.h" />
<ClInclude Include="src\Renderer\Painting\PaintingHelper.h" />
<ClInclude Include="src\Renderer\PaintingMesh.h" />
<ClInclude Include="src\Renderer\Painting\ShortCutTree.h" />
<ClInclude Include="src\Renderer\Painting\StraightLine.h" />

View File

@ -129,9 +129,6 @@
<ClCompile Include="src\Renderer\Painting\CubicBezier.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\PaintingHelper.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
<ClCompile Include="src\Renderer\Painting\ShortCutTree.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
@ -369,9 +366,6 @@
<ClInclude Include="src\Renderer\Painting\Line.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\PaintingHelper.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
<ClInclude Include="src\Renderer\Painting\ShortCutTree.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>

View File

@ -2,7 +2,7 @@
layout (local_size_x = 8, local_size_y = 8) in;
uniform ivec2 pixelOffset;
layout(location = 0) uniform ivec2 pixelOffset;
layout(rgba8, binding = 0) uniform image2D gBaseColor;
layout(rg8, binding = 1) uniform image2D gMetallicRoughness;
@ -17,13 +17,13 @@ layout(std430, binding = 1) buffer bvhBoundBuffer
};
layout(std430, binding = 2) buffer elementOffsetBuffer
{
/**********************
** @[0] elementBvhRoot
** @[1] styleOffset
** @[2] pointsOffset
** @[3] linesOffset
**********************/
uvec4 elementOffset[];
/**
* @[0] elementBvhRoot
* @[1] styleOffset
* @[2] pointsOffset
* @[3] linesOffset
*/
uint elementOffset[][4];
};
layout(std430, binding = 3) buffer elementIndexBuffer
{
@ -967,9 +967,8 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
vec4 elementColor = vec4(-1);
metallicRoughness = vec2(0, 0.8);
uvec4 currentOffset = elementOffset[elementIndex];
uint currentOffset[] = elementOffset[elementIndex];
uint elementBvhRoot = currentOffset[0];
//uint elementBvhLength = currentOffset[1];
uint styleIndex = currentOffset[1];
uint elementBvhLength = 0x80000000;
uint pointsOffset = currentOffset[2];

View File

@ -7,7 +7,7 @@ using Renderer::Line;
using std::vector;
using std::shared_ptr;
vector<vector<Point>> PainterPathUtil::transformToLines(QPainterPath& painterPath) {
vector<vector<Point>> PainterPathUtil::transformToLines(const QPainterPath& painterPath) {
vector<Point> line; line.clear();
vector<vector<Point> > lines; lines.clear();
QPointF startPoint(0, 0);
@ -61,3 +61,16 @@ QPainterPath PainterPathUtil::monotonization(QPainterPath& painterPath) {
}
return resPath;
}
std::pair<QPainterPath, float> PainterPathUtil::normalized(const QPainterPath& path)
{
auto rect = path.boundingRect();
return { (QTransform::fromTranslate(-rect.center().x(), -rect.center().y()) * QTransform::fromScale(1 / (rect.width() / 1.999999), -1 / (rect.height() / 1.999999))).map(path),
rect.width() / rect.height() };
}
std::pair<std::vector<std::vector<Renderer::Point>>, float> PainterPathUtil::toNormalizedLines(const QPainterPath& path)
{
auto [p, ratio] = normalized(path);
return { transformToLines(p), ratio };
}

View File

@ -6,7 +6,9 @@
class PainterPathUtil
{
public:
static std::vector<std::vector<Renderer::Point> > transformToLines(QPainterPath& painterPath);
static std::vector<std::vector<Renderer::Point>> transformToLines(const QPainterPath& painterPath);
static QPainterPath monotonization(QPainterPath& painterPath);
static std::pair<QPainterPath, float> normalized(const QPainterPath& path);
static std::pair<std::vector<std::vector<Renderer::Point>>, float> toNormalizedLines(const QPainterPath& path);
};

View File

@ -9,7 +9,7 @@ Renderer::Vertex::Vertex(const aiVector3D& position, const aiVector3D& normal, c
{
}
Mesh::Mesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model)
Mesh::Mesh(QOpenGLFunctions_4_5_Core* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model)
: glFunc(glFunc)
, shaderProgram(shaderProgram)
, shadowProgram(shadowProgram)

View File

@ -1,5 +1,5 @@
#pragma once
#include <QOpenGLFunctions_4_5_Compatibility>
#include <QOpenGLFunctions_4_5_Core>
#include <QString>
#include <QVector>
#include <QVector2D>
@ -46,10 +46,10 @@ namespace Renderer
GLuint textureNormal = 0;
QMatrix4x4 model;
QOpenGLFunctions_4_5_Compatibility* glFunc;
QOpenGLFunctions_4_5_Core* glFunc;
QOpenGLShaderProgram* shaderProgram, * shadowProgram;
Mesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model);
Mesh(QOpenGLFunctions_4_5_Core* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model);
void draw() override;
void drawShadow() override;
void setupMesh();

View File

@ -11,28 +11,23 @@
#include "Painting/ShortCutTree.h"
#include "Painting/Painting.h"
#include "../SvgParser.h"
#include "../Editor/util/PainterPathUtil.h"
#include <ThirdPartyLib/qquick/qquicksvgparser_p.h>
using namespace Renderer;
using std::vector;
Model::Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram,
QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram,
PaintingHelper* paintingHelper, VirtualTextureManager* vtManager)
QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager)
: context(context)
, glFunc(context->versionFunctions<QOpenGLFunctions_4_5_Compatibility>())
, glFunc(context->versionFunctions<QOpenGLFunctions_4_5_Core>())
, shaderProgram(shaderProgram)
, paintingProgram(paintingProgram)
, shadowProgram(shadowProgram)
, paintingHelper(paintingHelper)
, vtManager(vtManager)
{
}
Model::~Model() //Ïú»Ù¶ÔÏó
{
}
void Model::draw() {
//shaderProgram->bind();
for (auto& mesh : meshes) {
@ -47,12 +42,6 @@ void Model::drawShadow() {
}
}
void Model::destroy()
{
context->doneCurrent();
delete this;
}
void Renderer::Model::loadModel(QString path)
{
directory = path;
@ -87,7 +76,6 @@ void Renderer::Model::loadModel(QString path)
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
{
// 处理节点所有的网格(如果有的话)
for (unsigned int i = 0; i < node->mNumMeshes; i++)
{
@ -102,15 +90,6 @@ void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
}
}
GLuint encodeChild(GLuint index)
{
return 0x80000000 + index;
}
GLuint encodeZIndexAngle(GLuint zIndex, float angle)
{
return GLuint(angle / 360 * 65536 + zIndex * 65536);
}
std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model)
{
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
@ -119,7 +98,7 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
aiString str;
material->GetTexture(aiTextureType_BASE_COLOR, 0, &str);
if (paintingProgram != nullptr && ( std::strcmp(str.C_Str(), "17876391417123941155.jpg") == 0 || std::strcmp(str.C_Str(), "11474523244911310074.jpg") == 0))
if (paintingProgram != nullptr && (std::strcmp(str.C_Str(), "17876391417123941155.jpg") == 0 || std::strcmp(str.C_Str(), "11474523244911310074.jpg") == 0))
{
qDebug() << str.C_Str() << "Replaced";
// 初始化网格
@ -196,7 +175,6 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
}
else
return nullptr;
}
}
@ -234,11 +212,27 @@ GLuint Renderer::Model::loadPainting(std::string path)
if (iter != paintingLoaded.end())
return iter->second;
vector<std::shared_ptr<Contour>> contour = {
std::make_shared<Contour>(SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse()),
std::make_shared<Contour>(SvgParser("M308.49,212.25l23,28.38-82,78.31c-14.28,13.64-26.34-20.6-53.44,9.32l-30.24-13.4,63.56-51.59L190.71,215.6l-32.92,26.72L149.5,232.1l32.92-26.72L173.2,194l-32.91,26.72-7.38-9.08L165.83,185l-38.69-47.66L94.22,164,85,152.65l32.91-26.72-9.21-11.35L75.79,141.3l-5.53-6.81,32.92-26.72L94,96.42,61.05,123.14l-12-14.76L37.72,117.6l12,14.75L30.41,148,0,110.55,136.2,0l30.4,37.46L147.31,53.12l-12-14.76L124,47.58l12,14.75L103.05,89.05l9.21,11.35,32.92-26.72,5.52,6.81-32.91,26.72L127,118.56l32.92-26.72,9.21,11.35-32.91,26.72,38.69,47.67,32.91-26.72,7.37,9.08-32.91,26.72L191.49,198l32.92-26.72,8.29,10.22-32.92,26.71,38.7,47.68L302,204.3l6.45,7.95Z", 331.52, 328.26).parse()),
std::make_shared<Contour>(SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse())
};
//vector<std::shared_ptr<Contour>> contour = {
// std::make_shared<Contour>(SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse()),
// std::make_shared<Contour>(SvgParser("M308.49,212.25l23,28.38-82,78.31c-14.28,13.64-26.34-20.6-53.44,9.32l-30.24-13.4,63.56-51.59L190.71,215.6l-32.92,26.72L149.5,232.1l32.92-26.72L173.2,194l-32.91,26.72-7.38-9.08L165.83,185l-38.69-47.66L94.22,164,85,152.65l32.91-26.72-9.21-11.35L75.79,141.3l-5.53-6.81,32.92-26.72L94,96.42,61.05,123.14l-12-14.76L37.72,117.6l12,14.75L30.41,148,0,110.55,136.2,0l30.4,37.46L147.31,53.12l-12-14.76L124,47.58l12,14.75L103.05,89.05l9.21,11.35,32.92-26.72,5.52,6.81-32.91,26.72L127,118.56l32.92-26.72,9.21,11.35-32.91,26.72,38.69,47.67,32.91-26.72,7.37,9.08-32.91,26.72L191.49,198l32.92-26.72,8.29,10.22-32.92,26.71,38.7,47.68L302,204.3l6.45,7.95Z", 331.52, 328.26).parse()),
// std::make_shared<Contour>(SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse())
//};
vector<std::pair<std::shared_ptr<Contour>, float>> contours;
QPainterPath painterPaths[3];
QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z",
painterPaths[0]);
QQuickSvgParser::parsePathDataFast("M308.49,212.25l23,28.38-82,78.31c-14.28,13.64-26.34-20.6-53.44,9.32l-30.24-13.4,63.56-51.59L190.71,215.6l-32.92,26.72L149.5,232.1l32.92-26.72L173.2,194l-32.91,26.72-7.38-9.08L165.83,185l-38.69-47.66L94.22,164,85,152.65l32.91-26.72-9.21-11.35L75.79,141.3l-5.53-6.81,32.92-26.72L94,96.42,61.05,123.14l-12-14.76L37.72,117.6l12,14.75L30.41,148,0,110.55,136.2,0l30.4,37.46L147.31,53.12l-12-14.76L124,47.58l12,14.75L103.05,89.05l9.21,11.35,32.92-26.72,5.52,6.81-32.91,26.72L127,118.56l32.92-26.72,9.21,11.35-32.91,26.72,38.69,47.67,32.91-26.72,7.37,9.08-32.91,26.72L191.49,198l32.92-26.72,8.29,10.22-32.92,26.71,38.7,47.68L302,204.3l6.45,7.95Z",
painterPaths[1]);
QQuickSvgParser::parsePathDataFast("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z",
painterPaths[2]);
for (auto& i : painterPaths)
{
auto [contour, ratio] = PainterPathUtil::toNormalizedLines(i);
contours.emplace_back(std::make_shared<Contour>(contour), ratio);
}
vector<std::shared_ptr<ElementStyle>> style = {
std::make_shared<ElementStyleFillDemo>(),
@ -247,17 +241,17 @@ GLuint Renderer::Model::loadPainting(std::string path)
};
vector<std::shared_ptr<Element>> element = {
std::make_shared<Element>(Element{ contour[0], style[0]}),
std::make_shared<Element>(Element{ contour[1], style[2]}),
std::make_shared<Element>(Element{ contour[2], style[0]}),
std::make_shared<Element>(Element{ contours[0].first, style[0], contours[0].second}),
std::make_shared<Element>(Element{ contours[1].first, style[2], contours[1].second}),
std::make_shared<Element>(Element{ contours[2].first, style[0], contours[2].second}),
};
Painting painting;
if (path == "17876391417123941155.jpg")
{
painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.5,-0.45), glm::vec2(0.6,0.7), 45, glm::bvec2(true, false), 0 });
painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45,0.45), glm::vec2(0.5,0.5), 0, glm::bvec2(false), 0 });
painting.addElement(*element[2], ElementTransform{ glm::vec2(0.5,-0.45), glm::vec2(0.6,0.7), 0, glm::bvec2(false), 0 });
painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.5,-0.45), glm::vec2(0.6,0.7) / 2.f, 45, glm::bvec2(true, false), 0 });
painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45,0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 });
painting.addElement(*element[2], ElementTransform{ glm::vec2(0.50,-0.45), glm::vec2(0.6,0.7) / 2.f, 0, glm::bvec2(false), 0 });
}
else
{
@ -265,7 +259,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
{
float x = (float)rand() / RAND_MAX * 2 - 1;
float y = (float)rand() / RAND_MAX * 2 - 1;
painting.addElement(*element[i%3], ElementTransform{ glm::vec2(x,y), glm::vec2(0.05), (float)rand() / RAND_MAX * 360, glm::bvec2(false), 0 });
painting.addElement(*element[i % 3], ElementTransform{ glm::vec2(x,y), glm::vec2(0.025), (float)rand() / RAND_MAX * 360, glm::bvec2(false), 0 });
}
}

View File

@ -1,7 +1,6 @@
#pragma once
#include "Mesh.h"
#include "Drawable.h"
#include "Painting/PaintingHelper.h"
#include "VirtualTextureManager.h"
#include <QDir>
#include <assimp/scene.h>
@ -15,17 +14,14 @@ namespace Renderer
void draw();
void drawShadow();
void destroy();
void loadModel(QString path);
Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, PaintingHelper* paintingHelper, VirtualTextureManager* vtManager);
Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager);
private:
~Model();
QOpenGLContext* context;
QOpenGLFunctions_4_5_Compatibility* glFunc = nullptr;
QOpenGLFunctions_4_5_Core* glFunc = nullptr;
QOpenGLShaderProgram* shaderProgram = nullptr;
QOpenGLShaderProgram* paintingProgram = nullptr; //彩绘着色器程序
QOpenGLShaderProgram* paintingProgram = nullptr;
QOpenGLShaderProgram* shadowProgram = nullptr;
PaintingHelper* paintingHelper = nullptr;
VirtualTextureManager* vtManager = nullptr;
/* Ä£ÐÍÊý¾Ý */
@ -38,13 +34,13 @@ namespace Renderer
float minX, maxX, minY, maxY, minZ, maxZ;
//递归遍历结点
/// 递归遍历结点
void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
//加载网格
/// 加载网格
std::unique_ptr<Drawable> processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 model);
//加载材质纹理
/// 加载材质纹理
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
GLuint loadPainting(std::string path);

View File

@ -16,7 +16,7 @@ namespace Renderer
glm::bvec2 flip = glm::bvec2(false);
};
enum class MaterialStyleType { kFill, kStroke };
enum class MaterialStyleType { kFill = 0, kStroke = 1 };
class MaterialStyle
{

View File

@ -3,7 +3,7 @@
void Renderer::ElementTransform::applyTransformStyle(const TransformStyle& t)
{
center += t.translation;
size *= t.scale;
scale *= t.scale;
rotation += t.rotation;
flip ^= t.flip;
}

View File

@ -11,14 +11,16 @@ namespace Renderer
struct Element
{
std::shared_ptr<Contour> contour;
std::shared_ptr<Contour> contour; /// 坐标范围-1到1
std::shared_ptr<ElementStyle> style;
float ratio; /// 宽高比
};
struct ElementTransform
{
glm::vec2 center;
glm::vec2 size;
//glm::vec2 size;
glm::vec2 scale; /// 相对于画布
float rotation; /// ½Ç¶ÈÖÆ
glm::bvec2 flip;
GLuint zIndex;

View File

@ -7,7 +7,7 @@
using namespace Renderer;
constexpr int maxLineCount = 20;
constexpr int kMaxLineCount = 20;
Painting::Painting()
{
@ -18,46 +18,40 @@ void Renderer::Painting::addElement(ElementWithTransform elementWithTransform)
auto it = elementPool.find(elementWithTransform.element);
if (it == elementPool.end())
{
auto element = elementWithTransform.element;
auto iter = contourPool.insert({ element.contour, {nullptr, nullptr} }).first;
auto& element = elementWithTransform.element;
if (auto [iter, inserted] = contourPool.emplace(std::forward_as_tuple(element.contour, element.style->type()), ContourBuffer()); inserted)
{
ContourBuffer& elementBuffer = iter->second;
std::vector<BvhTreeData> bvhLeaves;
switch (element.style->type())
{
case MaterialStyleType::kFill:
if (iter->second.first == nullptr)
{
qDebug() << "Build ShortCutTree---------------------------------------------------------------------------------------------------";
ShortCutTree shortCutTree(maxLineCount);
qDebug() << "Build ShortCutTree Begin-----------------------------------";
ShortCutTree shortCutTree(kMaxLineCount);
shortCutTree.buildShortCutTree(*element.contour);
ContourBuffer elementBuffer;
std::vector<BvhTreeData> bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
BvhTree bvhTree;
bvhTree.buildBvhTree(bvhLeaves.data(), bvhLeaves.size());
bvhTree.getBvhArray(elementBuffer.bvhChildren, elementBuffer.bvhBounds);
iter->second.first = std::make_shared<ContourBuffer>(elementBuffer);
qDebug() << "---------------------------------------------------------------------------------------------------------------------";
}
bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
qDebug() << "Build ShortCutTree End-------------------------------------";
break;
}
case MaterialStyleType::kStroke:
if (iter->second.second == nullptr)
{
qDebug() << "Build LineTree-------------------------------------------------------------------------------------------------------";
LineTree lineTree(maxLineCount);
qDebug() << "Build LineTree Begin---------------------------------------";
LineTree lineTree(kMaxLineCount);
lineTree.buildLineTree(*element.contour, std::static_pointer_cast<MaterialStyleStroke>(element.style)->getHalfWidth());
ContourBuffer elementBuffer;
std::vector<BvhTreeData> bvhLeaves = lineTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
bvhLeaves = lineTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
qDebug() << "Build LineTree End-----------------------------------------";
break;
}
}
BvhTree bvhTree;
bvhTree.buildBvhTree(bvhLeaves.data(), bvhLeaves.size());
bvhTree.getBvhArray(elementBuffer.bvhChildren, elementBuffer.bvhBounds);
iter->second.second = std::make_shared<ContourBuffer>(elementBuffer);
qDebug() << "---------------------------------------------------------------------------------------------------------------------";
}
break;
}
stylePool.insert({ element.style, 0 });
elementPool.insert({ element, 0 });
}
elements.push_back(elementWithTransform);
}
@ -81,31 +75,50 @@ void Renderer::Painting::addElement(const Element& element, const ElementTransfo
ElementTransform trans = transform;
trans.applyTransformStyle(*style.transform);
trans.zIndex = trans.zIndex * 10 + i;
addElement(ElementWithTransform{ BaseElement{element.contour, style.material}, BaseTransform(trans) });
addElement(ElementWithTransform{ BaseElement{element.contour, style.material, element.ratio}, trans });
}
}
Renderer::BaseTransform::BaseTransform(ElementTransform t)
: bound(glm::vec4(t.center - t.scale, t.center + t.scale))
, rotation(t.rotation)
, flip(t.flip)
, zIndex(t.zIndex)
{
}
void Renderer::Painting::addElement(std::shared_ptr<Element> element, QVector4D bound, float rotation, int zIndex)
{
}
GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
{
return GLuint(rotation / 360 * 0x10000 + zIndex * 0x10000);
}
BvhTreeData Painting::encodeElementLeaf(ElementWithTransform e)
{
QVector4D bound(e.transform.bound.x, e.transform.bound.y, e.transform.bound.z, e.transform.bound.w);
GLuint rightSon = GLuint(glm::mod(e.transform.rotation, 360.f)/360.f * (1 << 16))
glm::vec4 bound;
switch (e.element.style->type())
{
case MaterialStyleType::kStroke:
{
auto w = std::static_pointer_cast<MaterialStyleStroke>(e.element.style)->getHalfWidth();
glm::vec2 size = glm::normalize(glm::vec2(e.element.ratio, 1)) + glm::vec2(2 * w);
glm::vec2 scale = size * e.transform.scale;
bound = glm::vec4(e.transform.center - scale, e.transform.center + scale);
break;
}
case MaterialStyleType::kFill:
{
bound = glm::vec4(e.transform.center - e.transform.scale, e.transform.center + e.transform.scale);
break;
}
}
bound = glm::vec4(e.transform.center - e.transform.scale, e.transform.center + e.transform.scale);
GLuint rightSon = (GLuint)(glm::mod(e.transform.rotation, 360.f) / 360.f * (1 << 16))
+ (e.transform.flip.x << 16) + (e.transform.flip.y << 17) + (e.transform.zIndex << 18);
return BvhTreeData(bound, elementPool[e.element], rightSon);
return BvhTreeData(QVector4D(bound.x, bound.y, bound.z, bound.w), elementPool[e.element], rightSon);
}
void Painting::generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc)
void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc)
{
qDebug() << "Element Count: " << elementPool.size();
qDebug() << "Coutour Count: " << contourPool.size();
@ -113,12 +126,11 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc)
bvhChildren.clear();
bvhBounds.clear();
elementOffset.clear();
elementOffsets.clear();
elementIndex.clear();
elementData.clear();
int index = 0;
for (auto& i : elementPool)
for (int index = 0; auto & i : elementPool)
{
i.second = index++;
}
@ -140,10 +152,7 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc)
for (auto& i : contourPool)
{
if (i.second.first != nullptr)
insertContourBuffer(i.second.first);
if (i.second.second != nullptr)
insertContourBuffer(i.second.second);
insertContourBuffer(i.second);
}
for (auto& i : stylePool)
@ -156,8 +165,9 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc)
for (auto& i : elementPool)
{
//qDebug() <<"element:" << i.second;
std::shared_ptr<ContourBuffer> contourBuffer = i.first.style->type()==MaterialStyleType::kStroke ? contourPool[i.first.contour].second : contourPool[i.first.contour].first;
elementOffset.push_back({ contourBuffer->bvhOffset, stylePool[i.first.style], contourBuffer->pointsOffset, contourBuffer->linesOffset });
//std::shared_ptr<ContourBuffer> contourBuffer = i.first.style->type() == MaterialStyleType::kStroke ? contourPool[i.first.contour].second : contourPool[i.first.contour].first;
auto& contourBuffer = contourPool[{i.first.contour, i.first.style->type()}];
elementOffsets.push_back({ contourBuffer.bvhOffset, stylePool[i.first.style], contourBuffer.pointsOffset, contourBuffer.linesOffset });
//std::cout << std::format("{} {} {} {}\n", contourBuffer->bvhOffset, stylePool[i.first->style], contourBuffer->pointsOffset, contourBuffer->linesOffset);
}
@ -168,11 +178,11 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc)
GLuint& elementIndexSSBO = buffers[3];
GLuint& elementDataSSBO = buffers[4];
glFunc->glNamedBufferData(bvhSSBO, bvhChildren.size() * sizeof(GLuint), bvhChildren.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(bvhBoundSSBO, bvhBounds.size() * sizeof(QVector4D), bvhBounds.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(elementOffsetSSBO, elementOffset.size() * sizeof(glm::uvec4), elementOffset.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(elementIndexSSBO, elementIndex.size() * sizeof(GLuint), elementIndex.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(elementDataSSBO, elementData.size() * sizeof(GLfloat), elementData.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(buffers[0], bvhChildren.size() * sizeof(bvhChildren[0]), bvhChildren.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(buffers[1], bvhBounds.size() * sizeof(bvhBounds[0]), bvhBounds.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(buffers[2], elementOffsets.size() * sizeof(elementOffsets[0]), elementOffsets.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(buffers[3], elementIndex.size() * sizeof(elementIndex[0]), elementIndex.data(), GL_STATIC_READ);
glFunc->glNamedBufferData(buffers[4], elementData.size() * sizeof(elementData[0]), elementData.data(), GL_STATIC_READ);
}
GLuint Renderer::Painting::getElementCount()
@ -180,16 +190,16 @@ GLuint Renderer::Painting::getElementCount()
return elements.size();
}
void Renderer::Painting::insertContourBuffer(std::shared_ptr<ContourBuffer> buffer)
void Renderer::Painting::insertContourBuffer(ContourBuffer& buffer)
{
buffer->pointsOffset = elementData.size();
buffer->linesOffset = elementIndex.size();
buffer->bvhOffset = bvhBounds.size();
buffer.pointsOffset = elementData.size();
buffer.linesOffset = elementIndex.size();
buffer.bvhOffset = bvhBounds.size();
elementData.insert(elementData.end(), buffer->pointBuffer.begin(), buffer->pointBuffer.end());
elementIndex.insert(elementIndex.end(), buffer->lineBuffer.begin(), buffer->lineBuffer.end());
bvhChildren.insert(bvhChildren.end(), buffer->bvhChildren.begin(), buffer->bvhChildren.end());
bvhBounds.insert(bvhBounds.end(), buffer->bvhBounds.begin(), buffer->bvhBounds.end());
elementData.insert(elementData.end(), buffer.pointBuffer.begin(), buffer.pointBuffer.end());
elementIndex.insert(elementIndex.end(), buffer.lineBuffer.begin(), buffer.lineBuffer.end());
bvhChildren.insert(bvhChildren.end(), buffer.bvhChildren.begin(), buffer.bvhChildren.end());
bvhBounds.insert(bvhBounds.end(), buffer.bvhBounds.begin(), buffer.bvhBounds.end());
}
bool Renderer::BaseElement::operator<(const BaseElement& e) const
@ -197,10 +207,16 @@ bool Renderer::BaseElement::operator<(const BaseElement& e) const
return contour == e.contour ? style < e.style : contour < e.contour;
}
Renderer::BaseTransform::BaseTransform(ElementTransform t)
: bound(glm::vec4(t.center - t.size / 2.f, t.center + t.size / 2.f))
, rotation(t.rotation)
, flip(t.flip)
, zIndex(t.zIndex)
std::size_t Renderer::Painting::ContourHash::operator()(const std::tuple<std::shared_ptr<Contour>, MaterialStyleType>& k) const
{
return std::hash<std::shared_ptr<Contour>>()(std::get<0>(k)) ^
std::hash<MaterialStyleType>()(std::get<1>(k));
}
bool Renderer::Painting::CompareMaterialStyle::operator()(const std::shared_ptr<MaterialStyle>& left, const std::shared_ptr<MaterialStyle>& right) const
{
if (left == right || *left == *right)
return false;
else
return left < right;
}

View File

@ -7,7 +7,7 @@
#include "BvhTree.h"
#include "ElementStyle.h"
#include "Element.h"
#include <QOpenGLFunctions_4_5_Compatibility>
#include <QOpenGLFunctions_4_5_Core>
namespace Renderer
{
@ -15,6 +15,7 @@ namespace Renderer
{
std::shared_ptr<Contour> contour;
std::shared_ptr<MaterialStyle> style;
float ratio; /// ¿í¸ß±È
bool operator<(const BaseElement& e) const;
};
@ -30,7 +31,8 @@ namespace Renderer
struct ElementWithTransform
{
BaseElement element;
BaseTransform transform;
ElementTransform transform;
//BaseTransform transform;
};
struct ContourBuffer
@ -39,30 +41,25 @@ namespace Renderer
std::vector<GLuint> lineBuffer;
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBounds;
//std::vector<BvhTreeData> bvhLeaves;
GLuint pointsOffset;
GLuint linesOffset;
GLuint bvhOffset;
};
struct CompareMaterialStyle
struct ElementOffset
{
inline bool operator()(const std::shared_ptr<MaterialStyle>& left, const std::shared_ptr<MaterialStyle>& right) const
{
if (left == right || *left == *right)
return false;
else
return left < right;
}
GLuint elementBvhRoot;
GLuint styleOffset;
GLuint pointsOffset;
GLuint linesOffset;
};
class Painting
{
public:
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBounds;
std::vector<glm::uvec4> elementOffset;
std::vector<ElementOffset> elementOffsets;
std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData;
int paintingId = 0;
@ -71,10 +68,12 @@ namespace Renderer
Painting();
void addElement(const Element& element, const ElementTransform& transform);
void addElement(std::shared_ptr<Element> element, QVector4D bound, float rotation, int zIndex);
void generateBuffers(QOpenGLFunctions_4_5_Compatibility* glFunc);
void generateBuffers(QOpenGLFunctions_4_5_Core* glFunc);
GLuint getElementCount();
private:
std::unordered_map<std::shared_ptr<Contour>, std::pair<std::shared_ptr<ContourBuffer>/*Ãæ*/, std::shared_ptr<ContourBuffer>/*Ïß*/>> contourPool;
struct ContourHash { std::size_t operator()(const std::tuple<std::shared_ptr<Contour>, MaterialStyleType>&) const; };
std::unordered_map<std::tuple<std::shared_ptr<Contour>, MaterialStyleType>, ContourBuffer, ContourHash> contourPool;
struct CompareMaterialStyle { bool operator()(const std::shared_ptr<MaterialStyle>&, const std::shared_ptr<MaterialStyle>&) const; };
std::set<std::shared_ptr<MaterialStyle>, CompareMaterialStyle> styleSet;
std::unordered_map<std::shared_ptr<ElementStyle>, std::vector<BaseStyle>> elementStyleMap;
std::unordered_map<std::shared_ptr<MaterialStyle>, GLuint> stylePool;
@ -82,7 +81,7 @@ namespace Renderer
std::vector<ElementWithTransform> elements;
void addElement(ElementWithTransform element);
void insertContourBuffer(std::shared_ptr<ContourBuffer> buffer);
void insertContourBuffer(ContourBuffer& buffer);
BvhTreeData encodeElementLeaf(ElementWithTransform e);
};
}

View File

@ -1,71 +0,0 @@
#include "PaintingHelper.h"
using namespace Renderer;
PaintingHelper::PaintingHelper(QOpenGLFunctions_4_5_Core* glFunc) :glFunc(glFunc)
{
}
int Renderer::PaintingHelper::addPainting(Painting painting)
{
return addPainting(painting.bvhChildren, painting.bvhBounds, painting.elementOffset, painting.elementIndex, painting.elementData);
}
int PaintingHelper::addPainting(std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound, std::vector<glm::uvec4> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData)
{
this->paintingOffsets.push_back(0);//paintingBvhRoot
this->paintingOffsets.push_back(0);
this->bvhChildren.insert(this->bvhChildren.end(), bvhChildren.begin(), bvhChildren.end());
this->bvhBound.insert(this->bvhBound.end(), bvhBound.begin(), bvhBound.end());
this->elementOffset.insert(this->elementOffset.end(), elementOffset.begin(), elementOffset.end());
this->elementIndex.insert(this->elementIndex.end(), elementIndex.begin(), elementIndex.end());
this->elementData.insert(this->elementData.end(), elementData.begin(), elementData.end());
return ++paintingCount;
}
void PaintingHelper::allocateBuffers()
{
glFunc->glGenBuffers(1, &paintingOffsetsSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, paintingOffsetsSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, paintingOffsets.size() * sizeof(GLuint), paintingOffsets.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &bvhSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, bvhSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhChildren.size() * sizeof(GLuint), bvhChildren.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &bvhBoundSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, bvhBoundSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, bvhBound.size() * sizeof(QVector4D), bvhBound.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementOffsetSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementOffsetSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementOffset.size() * sizeof(glm::uvec4), elementOffset.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementIndexSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementIndexSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementIndex.size() * sizeof(GLuint), elementIndex.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glFunc->glGenBuffers(1, &elementDataSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementDataSSBO);
glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementData.size() * sizeof(GLfloat), elementData.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
void PaintingHelper::bindPaintingBuffers()
{
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, paintingOffsetsSSBO);
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, bvhSSBO);
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, bvhBoundSSBO);
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, elementOffsetSSBO);
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, elementIndexSSBO);
glFunc->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, elementDataSSBO);
}

View File

@ -1,33 +0,0 @@
#pragma once
#include <vector>
#include <QDebug>
#include <QVector4D>
#include <QOpenGLFunctions_4_5_Core>
#include "BvhTree.h"
#include "Painting.h"
namespace Renderer
{
class PaintingHelper
{
private:
QOpenGLFunctions_4_5_Core* glFunc;
GLuint paintingOffsetsSSBO, bvhSSBO, bvhBoundSSBO, elementOffsetSSBO, elementIndexSSBO, elementDataSSBO;
std::vector<GLuint> paintingOffsets;
std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound;
std::vector<glm::uvec4> elementOffset;
std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData;
int paintingCount = 0;
public:
PaintingHelper(QOpenGLFunctions_4_5_Core* glFunc);
int addPainting(Painting painting);
int addPainting(std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound,
std::vector<glm::uvec4> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData);
void allocateBuffers();
void bindPaintingBuffers();
};
}

View File

@ -1,6 +1,6 @@
#include "PaintingMesh.h"
using namespace Renderer;
PaintingMesh::PaintingMesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model)
PaintingMesh::PaintingMesh(QOpenGLFunctions_4_5_Core* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model)
: glFunc(glFunc)
, shaderProgram(shaderProgram)
, shadowProgram(shadowProgram)

View File

@ -1,5 +1,5 @@
#pragma once
#include <QOpenGLFunctions_4_5_Compatibility>
#include <QOpenGLFunctions_4_5_Core>
#include <QString>
#include <QVector>
#include <QVector2D>
@ -23,11 +23,11 @@ namespace Renderer
GLuint textureBasecolor;
GLuint textureMetallicRoughness;
QMatrix4x4 model;
QOpenGLFunctions_4_5_Compatibility* glFunc;
QOpenGLFunctions_4_5_Core* glFunc;
QOpenGLShaderProgram* shaderProgram, * shadowProgram;
GLuint paintingId;
PaintingMesh(QOpenGLFunctions_4_5_Compatibility* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model);
PaintingMesh(QOpenGLFunctions_4_5_Core* glFunc, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* shadowProgram, const QMatrix4x4& model);
void draw() override;
void drawShadow() override;
void setupMesh();

View File

@ -143,12 +143,9 @@ std::pair<QImage, QPointF> Renderer::ElementRenderer::drawElement(const QPainter
if (releaseContext) glWidget->makeCurrent();
GLuint ssbo[2];
glGenBuffers(2, ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, pathBuffer.size() * sizeof(glm::vec2), pathBuffer.data(), GL_STATIC_READ);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, styleBuffer.size() * sizeof(GLfloat), styleBuffer.data(), GL_STATIC_READ);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
glCreateBuffers(2, ssbo);
glNamedBufferData(ssbo[0], pathBuffer.size() * sizeof(glm::vec2), pathBuffer.data(), GL_STATIC_READ);
glNamedBufferData(ssbo[1], styleBuffer.size() * sizeof(GLfloat), styleBuffer.data(), GL_STATIC_READ);
auto fbo = QOpenGLFramebufferObject(size, QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D);
fbo.bind();

View File

@ -257,9 +257,7 @@ void RendererGLWidget::initializeGL()
finalProgramPtr->release();
vtManager = std::make_unique<VirtualTextureManager>(gl.get());
paintingHelper = new PaintingHelper(glFunc);
model = new Model(context(), modelProgramPtr, paintingProgramPtr, shadowProgramPtr, paintingHelper, vtManager.get());
model = new Model(context(), modelProgramPtr, paintingProgramPtr, shadowProgramPtr, vtManager.get());
skyBoxProgramPtr->bind();
skyBoxProgramPtr->setUniformValue("environmentMap", 0);

View File

@ -9,7 +9,6 @@
#include "Camera.h"
#include "Light.h"
#include "Model.h"
#include "Painting/PaintingHelper.h"
struct GladGLContext;
@ -78,7 +77,6 @@ namespace Renderer
QOpenGLBuffer quadVBO;
QOpenGLVertexArrayObject quadVAO;
Model* model = nullptr;
PaintingHelper* paintingHelper;
std::unique_ptr<VirtualTextureManager> vtManager;
GLuint timeQuery;