diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index 3e8ede4..7324942 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -4,6 +4,11 @@ layout(local_size_x = 8, local_size_y = 8) in; layout(location = 0) uniform ivec2 pixelOffset; +layout(std140, binding = 1) uniform ubo +{ + vec3 backgroundColor; +}; + layout(rgba8, binding = 0) uniform image2D gBaseColor; layout(rg8, binding = 1) uniform image2D gMetallicRoughness; @@ -1353,7 +1358,7 @@ void main() vec3 debugBVH = vec3(0); // bool debugHit = false; //vec4 color = vec4(0.76, 0.33, 0.15, -1); - vec4 color = vec4(1,1,1, -1); + vec4 color = vec4(backgroundColor, -1); vec2 metallicRoughness = vec2(0, 0.8); stack.top = 0; uint index = 0, visitTime = 0; diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 4f62c3b..e96d36a 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -273,7 +273,8 @@ GLuint Renderer::Model::loadPainting(std::string path) } else if (path == "1.json") { - float widths[] = { 0.43, 0.43 * 0.25 / 0.15, 0.43 * 0.25 / 0.15 }; + painting.backgroundColor = QColor(196, 81, 35); + float widths[] = { 0.22, 0.22 * 0.25 / 0.15, 0.22 * 0.25 / 0.15 }; QPainterPath painterPaths[6]; for (int i = 0; i < 6; i++) if (!SvgFileLoader().loadSvgFile(QString(std::format("../svg/{}.svg", i + 1).c_str()), painterPaths[i])) diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp index 3d1fb2a..afd7e04 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp @@ -9,7 +9,7 @@ using namespace Renderer; constexpr int kMaxLineCount = 20; -Painting::Painting() +Painting::Painting(QColor backgroundColor) : backgroundColor(backgroundColor) { } @@ -171,18 +171,21 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc) //std::cout << std::format("{} {} {} {}\n", contourBuffer->bvhOffset, stylePool[i.first->style], contourBuffer->pointsOffset, contourBuffer->linesOffset); } - glFunc->glCreateBuffers(5, buffers.data()); + glFunc->glCreateBuffers(6, buffers.data()); GLuint& bvhSSBO = buffers[0]; GLuint& bvhBoundSSBO = buffers[1]; GLuint& elementOffsetSSBO = buffers[2]; GLuint& elementIndexSSBO = buffers[3]; GLuint& elementDataSSBO = buffers[4]; + GLuint& backgroundColorUBO = buffers[5]; 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); + glm::vec3 color(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF()); + glFunc->glNamedBufferData(buffers[5], sizeof(glm::vec3), &color, GL_STATIC_READ); } GLuint Renderer::Painting::getElementCount() diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h index ab8f31a..9194040 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h @@ -64,9 +64,10 @@ namespace Renderer std::vector elementIndex; std::vector elementData; int paintingId = 0; - std::array buffers; + std::array buffers; + QColor backgroundColor; - Painting(); + Painting(QColor backgroundColor = Qt::white); void addElement(const Element& element, const ElementTransform& transform); void addElement(std::shared_ptr element, QVector4D bound, float rotation, int zIndex); void generateBuffers(QOpenGLFunctions_4_5_Core* glFunc); diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp index eeba398..b926ad4 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp @@ -126,6 +126,7 @@ std::uint16_t Renderer::VirtualTextureManager::createVirtualTexture(Painting pai for (int i = 0; i < 5; i++) glMain->BindBufferBase(GL_SHADER_STORAGE_BUFFER, i, painting.buffers[i]); + glMain->BindBufferBase(GL_UNIFORM_BUFFER, 1, painting.buffers[5]); for (auto level = levels - 1; level < levels; ++level) { @@ -143,7 +144,7 @@ std::uint16_t Renderer::VirtualTextureManager::createVirtualTexture(Painting pai GL_TRUE); program.bind(); - glMain->Uniform2i(gl->GetUniformLocation(program.programId(), "pixelOffset"), static_cast(pageSize) * i, static_cast(pageSize) * j); + glMain->Uniform2i(0 /*pixelOffset*/, static_cast(pageSize) * i, static_cast(pageSize) * j); glMain->BindImageTexture(0, baseColor, level, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8); glMain->BindImageTexture(1, metallicRoughness, level, GL_FALSE, 0, GL_READ_WRITE, GL_RG8); glMain->DispatchCompute(pageSize / 8, pageSize / 8, 1); @@ -190,6 +191,7 @@ void Renderer::VirtualTextureManager::pageCommitmentById(const glm::u16vec2& pag program.bind(); for (int i = 0; i < 5; i++) gl->BindBufferBase(GL_SHADER_STORAGE_BUFFER, i, painting.buffers[i]); + glMain->BindBufferBase(GL_UNIFORM_BUFFER, 1, painting.buffers[5]); gl->Uniform2i(gl->GetUniformLocation(program.programId(), "pixelOffset"), static_cast(pageSize) * page.x, static_cast(pageSize) * page.y); gl->BindImageTexture(0, painting.baseColor, level, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA8); gl->BindImageTexture(1, painting.metallicRoughness, level, GL_FALSE, 0, GL_READ_WRITE, GL_RG8); diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h index e1d3a03..520800b 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h @@ -15,7 +15,7 @@ namespace Renderer { GLuint baseColor; GLuint metallicRoughness; - std::array buffers; + std::array buffers; }; class VirtualTextureManager diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 6ef683c..5bf6bbe 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include "consoleapi2.h" +#include extern "C" { @@ -50,6 +51,9 @@ int main(int argc, char* argv[]) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication a(argc, argv); Q_INIT_RESOURCE(resources); + QtMaterialTheme theme; + theme.setColor("primary1", QColor(0, 90, 158)); + QtMaterialStyle::instance().setTheme(&theme); //FramelessHelper::Core::setApplicationOSThemeAware(); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); //FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);