Lot of small fixes/improvements

This commit is contained in:
Jérôme Leclercq 2021-05-14 01:48:47 +02:00
parent 9376cfefd2
commit 61dbd91346
22 changed files with 84 additions and 82 deletions

View File

@ -57,7 +57,7 @@ namespace Nz
inline void SetCommandCallback(CommandCallback callback); inline void SetCommandCallback(CommandCallback callback);
inline void SetClearColor(std::size_t outputIndex, const std::optional<Color>& color); inline void SetClearColor(std::size_t outputIndex, const std::optional<Color>& color);
inline void SetDepthStencilClear(float depth, UInt32 stencil); inline void SetDepthStencilClear(float depth, UInt32 stencil);
inline void SetExecutionCallback(CommandCallback callback); inline void SetExecutionCallback(ExecutionCallback callback);
inline void SetDepthStencilInput(std::size_t attachmentId); inline void SetDepthStencilInput(std::size_t attachmentId);
inline void SetDepthStencilOutput(std::size_t attachmentId); inline void SetDepthStencilOutput(std::size_t attachmentId);

View File

@ -102,9 +102,9 @@ namespace Nz
dsClear.stencil = stencil; dsClear.stencil = stencil;
} }
inline void FramePass::SetExecutionCallback(CommandCallback callback) inline void FramePass::SetExecutionCallback(ExecutionCallback callback)
{ {
m_commandCallback = std::move(callback); m_executionCallback = std::move(callback);
} }
inline void FramePass::SetDepthStencilInput(std::size_t attachmentId) inline void FramePass::SetDepthStencilInput(std::size_t attachmentId)

View File

@ -29,10 +29,10 @@ namespace Nz
OpenGLUploadPool& GetUploadPool() override; OpenGLUploadPool& GetUploadPool() override;
void SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) override;
void Present() override; void Present() override;
void SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) override;
OpenGLRenderImage& operator=(const OpenGLRenderImage&) = delete; OpenGLRenderImage& operator=(const OpenGLRenderImage&) = delete;
OpenGLRenderImage& operator=(OpenGLRenderImage&&) = delete; OpenGLRenderImage& operator=(OpenGLRenderImage&&) = delete;

View File

@ -12,10 +12,8 @@
#include <Nazara/OpenGLRenderer/Config.hpp> #include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp> #include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp> #include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLContext.hpp>
#include <string>
#undef WIN32_LEAN_AND_MEAN //< Redefined by OpenGL header (ty Khronos)
#include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp> #include <Nazara/OpenGLRenderer/Wrapper/WGL/WGLFunctions.hpp>
#include <string>
namespace Nz::GL namespace Nz::GL
{ {

View File

@ -39,8 +39,6 @@ namespace Nz
static std::size_t GetSize(StructFieldType fieldType); static std::size_t GetSize(StructFieldType fieldType);
private: private:
static inline std::size_t Align(std::size_t source, std::size_t alignment);
std::size_t m_largestFieldAlignment; std::size_t m_largestFieldAlignment;
std::size_t m_offsetRounding; std::size_t m_offsetRounding;
std::size_t m_size; std::size_t m_size;

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/FieldOffsets.hpp> #include <Nazara/Utility/FieldOffsets.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
@ -163,15 +164,6 @@ namespace Nz
return 0; return 0;
} }
inline std::size_t FieldOffsets::Align(std::size_t source, std::size_t alignment)
{
if (source == 0)
return source;
assert(alignment > 0);
return ((source + alignment - 1) / alignment) * alignment;
}
} }
#include <Nazara/Utility/DebugOff.hpp> #include <Nazara/Utility/DebugOff.hpp>

View File

@ -21,8 +21,8 @@ size_t StreamWrite(aiFile* file, const char* buffer, size_t size, size_t count);
struct FileIOUserdata struct FileIOUserdata
{ {
Nz::Stream* originalStream; Nz::Stream* originalStream;
const char* originalFilePath; const char* originalFilePath;
}; };
aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMode); aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMode);

View File

@ -23,6 +23,7 @@ SOFTWARE.
*/ */
#include <CustomStream.hpp> #include <CustomStream.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Utility/Animation.hpp> #include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Mesh.hpp> #include <Nazara/Utility/Mesh.hpp>
@ -233,6 +234,8 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters)
excludedComponents |= aiComponent_TEXCOORDS; excludedComponents |= aiComponent_TEXCOORDS;
aiPropertyStore* properties = aiCreatePropertyStore(); aiPropertyStore* properties = aiCreatePropertyStore();
CallOnExit releaseProperties([&] { aiReleasePropertyStore(properties); });
aiSetImportPropertyFloat(properties, AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, float(smoothingAngle)); aiSetImportPropertyFloat(properties, AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, float(smoothingAngle));
aiSetImportPropertyInteger(properties, AI_CONFIG_PP_LBW_MAX_WEIGHTS, 4); aiSetImportPropertyInteger(properties, AI_CONFIG_PP_LBW_MAX_WEIGHTS, 4);
aiSetImportPropertyInteger(properties, AI_CONFIG_PP_SBP_REMOVE, ~aiPrimitiveType_TRIANGLE); //< We only want triangles aiSetImportPropertyInteger(properties, AI_CONFIG_PP_SBP_REMOVE, ~aiPrimitiveType_TRIANGLE); //< We only want triangles
@ -241,7 +244,9 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters)
aiSetImportPropertyInteger(properties, AI_CONFIG_PP_RVC_FLAGS, excludedComponents); aiSetImportPropertyInteger(properties, AI_CONFIG_PP_RVC_FLAGS, excludedComponents);
const aiScene* scene = aiImportFileExWithProperties(userdata.originalFilePath, postProcess, &fileIO, properties); const aiScene* scene = aiImportFileExWithProperties(userdata.originalFilePath, postProcess, &fileIO, properties);
aiReleasePropertyStore(properties); CallOnExit releaseScene([&] { aiReleaseImport(scene); });
releaseProperties.CallAndReset();
if (!scene) if (!scene)
{ {
@ -628,8 +633,6 @@ MeshRef LoadMesh(Stream& stream, const MeshParams& parameters)
mesh->Recenter(); mesh->Recenter();
} }
aiReleaseImport(scene);
return mesh; return mesh;
} }

View File

@ -906,6 +906,8 @@ namespace Nz
std::size_t passIndex = *itRead; std::size_t passIndex = *itRead;
if (seen.find(passIndex) == seen.end()) if (seen.find(passIndex) == seen.end())
{ {
seen.insert(passIndex);
if (itRead != itWrite) if (itRead != itWrite)
*itWrite++ = passIndex; *itWrite++ = passIndex;
else else

View File

@ -112,6 +112,7 @@ namespace Nz
context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data()); context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data());
//FIXME: Don't clear when not needed
for (std::size_t i = 0; i < colorBufferCount; ++i) for (std::size_t i = 0; i < colorBufferCount; ++i)
{ {
Nz::Color color = command.clearValues[i].color; Nz::Color color = command.clearValues[i].color;
@ -127,6 +128,7 @@ namespace Nz
GLenum buffer = GL_BACK; GLenum buffer = GL_BACK;
context->glDrawBuffers(1, &buffer); context->glDrawBuffers(1, &buffer);
//FIXME: Don't clear when not needed
Nz::Color color = command.clearValues[0].color; Nz::Color color = command.clearValues[0].color;
context->glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f); context->glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f);
context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); context->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@ -112,7 +112,7 @@ namespace Nz
m_commandBuffer.SetViewport(viewportRegion); m_commandBuffer.SetViewport(viewportRegion);
} }
void OpenGLCommandBufferBuilder::TextureBarrier(PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout, const Texture& texture) void OpenGLCommandBufferBuilder::TextureBarrier(PipelineStageFlags /*srcStageMask*/, PipelineStageFlags /*dstStageMask*/, MemoryAccessFlags /*srcAccessMask*/, MemoryAccessFlags /*dstAccessMask*/, TextureLayout /*oldLayout*/, TextureLayout /*newLayout*/, const Texture& /*texture*/)
{ {
/* nothing to do */ /* nothing to do */
} }

View File

@ -31,14 +31,15 @@ namespace Nz
return m_uploadPool; return m_uploadPool;
} }
void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) void OpenGLRenderImage::Present()
{
m_owner.Present();
m_uploadPool.Reset();
}
void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags /*queueTypeFlags*/)
{ {
OpenGLCommandBuffer* oglCommandBuffer = static_cast<OpenGLCommandBuffer*>(commandBuffer); OpenGLCommandBuffer* oglCommandBuffer = static_cast<OpenGLCommandBuffer*>(commandBuffer);
oglCommandBuffer->Execute(); oglCommandBuffer->Execute();
} }
void OpenGLRenderImage::Present()
{
m_owner.Present();
}
} }

View File

@ -377,7 +377,7 @@ namespace Nz::GL
return false; return false;
} }
if (DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0) if (m_loader.DescribePixelFormat(m_deviceContext, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &descriptor) != 0)
{ {
m_params.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits; m_params.bitsPerPixel = descriptor.cColorBits + descriptor.cAlphaBits;
m_params.depthBits = descriptor.cDepthBits; m_params.depthBits = descriptor.cDepthBits;

View File

@ -25,14 +25,6 @@ namespace Nz
return m_image->GetUploadPool(); return m_image->GetUploadPool();
} }
void RenderFrame::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{
if (!m_image)
throw std::runtime_error("frame is either invalid or has already been presented");
m_image->SubmitCommandBuffer(commandBuffer, queueTypeFlags);
}
void RenderFrame::Present() void RenderFrame::Present()
{ {
if (!m_image) if (!m_image)
@ -41,4 +33,12 @@ namespace Nz
m_image->Present(); m_image->Present();
m_image = nullptr; m_image = nullptr;
} }
void RenderFrame::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{
if (!m_image)
throw std::runtime_error("frame is either invalid or has already been presented");
m_image->SubmitCommandBuffer(commandBuffer, queueTypeFlags);
}
} }

View File

@ -68,7 +68,7 @@ namespace Nz
const ShaderAst::ExpressionType& rightType = GetExpressionType(*node.right); const ShaderAst::ExpressionType& rightType = GetExpressionType(*node.right);
ShaderAst::PrimitiveType leftTypeBase = RetrieveBaseType(leftType); ShaderAst::PrimitiveType leftTypeBase = RetrieveBaseType(leftType);
ShaderAst::PrimitiveType rightTypeBase = RetrieveBaseType(rightType); //ShaderAst::PrimitiveType rightTypeBase = RetrieveBaseType(rightType);
UInt32 leftOperand = EvaluateExpression(node.left); UInt32 leftOperand = EvaluateExpression(node.left);

View File

@ -79,7 +79,7 @@ namespace Nz
beginInfo.renderArea.offset.y = renderRect.y; beginInfo.renderArea.offset.y = renderRect.y;
beginInfo.renderArea.extent.width = renderRect.width; beginInfo.renderArea.extent.width = renderRect.width;
beginInfo.renderArea.extent.height = renderRect.height; beginInfo.renderArea.extent.height = renderRect.height;
beginInfo.clearValueCount = vkClearValues.size(); beginInfo.clearValueCount = UInt32(vkClearValues.size());
beginInfo.pClearValues = vkClearValues.data(); beginInfo.pClearValues = vkClearValues.data();
m_commandBuffer.BeginRenderPass(beginInfo); m_commandBuffer.BeginRenderPass(beginInfo);

View File

@ -63,6 +63,15 @@ namespace Nz
return m_uploadPool; return m_uploadPool;
} }
void VulkanRenderImage::Present()
{
Vk::QueueHandle& graphicsQueue = m_owner.GetGraphicsQueue();
if (!graphicsQueue.Submit(UInt32(m_graphicalCommandsBuffers.size()), m_graphicalCommandsBuffers.data(), m_imageAvailableSemaphore, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, m_renderFinishedSemaphore, m_inFlightFence))
throw std::runtime_error("Failed to submit command buffers: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
m_owner.Present(m_imageIndex, m_renderFinishedSemaphore);
}
void VulkanRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) void VulkanRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
{ {
VulkanCommandBuffer& vkCommandBuffer = *static_cast<VulkanCommandBuffer*>(commandBuffer); VulkanCommandBuffer& vkCommandBuffer = *static_cast<VulkanCommandBuffer*>(commandBuffer);
@ -81,13 +90,4 @@ namespace Nz
throw std::runtime_error("Failed to submit command buffer: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode())); throw std::runtime_error("Failed to submit command buffer: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
} }
} }
void VulkanRenderImage::Present()
{
Vk::QueueHandle& graphicsQueue = m_owner.GetGraphicsQueue();
if (!graphicsQueue.Submit(UInt32(m_graphicalCommandsBuffers.size()), m_graphicalCommandsBuffers.data(), m_imageAvailableSemaphore, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, m_renderFinishedSemaphore, m_inFlightFence))
throw std::runtime_error("Failed to submit command buffers: " + TranslateVulkanError(graphicsQueue.GetLastErrorCode()));
m_owner.Present(m_imageIndex, m_renderFinishedSemaphore);
}
} }

View File

@ -76,7 +76,7 @@ namespace Nz
return colorBlendStates; return colorBlendStates;
} }
VkPipelineColorBlendStateCreateInfo VulkanRenderPipeline::BuildColorBlendInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState) VkPipelineColorBlendStateCreateInfo VulkanRenderPipeline::BuildColorBlendInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkPipelineColorBlendAttachmentState>& attachmentState)
{ {
VkPipelineColorBlendStateCreateInfo createInfo = {}; VkPipelineColorBlendStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
@ -100,7 +100,7 @@ namespace Nz
return createInfo; return createInfo;
} }
VkPipelineDynamicStateCreateInfo VulkanRenderPipeline::BuildDynamicStateInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkDynamicState>& dynamicStates) VkPipelineDynamicStateCreateInfo VulkanRenderPipeline::BuildDynamicStateInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkDynamicState>& dynamicStates)
{ {
VkPipelineDynamicStateCreateInfo createInfo = {}; VkPipelineDynamicStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
@ -110,7 +110,7 @@ namespace Nz
return createInfo; return createInfo;
} }
std::vector<VkDynamicState> VulkanRenderPipeline::BuildDynamicStateList(const RenderPipelineInfo& pipelineInfo) std::vector<VkDynamicState> VulkanRenderPipeline::BuildDynamicStateList(const RenderPipelineInfo& /*pipelineInfo*/)
{ {
return { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; return { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
} }
@ -124,7 +124,7 @@ namespace Nz
return createInfo; return createInfo;
} }
VkPipelineMultisampleStateCreateInfo VulkanRenderPipeline::BuildMultisampleInfo(const RenderPipelineInfo& pipelineInfo) VkPipelineMultisampleStateCreateInfo VulkanRenderPipeline::BuildMultisampleInfo(const RenderPipelineInfo& /*pipelineInfo*/)
{ {
VkPipelineMultisampleStateCreateInfo createInfo = {}; VkPipelineMultisampleStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
@ -146,7 +146,7 @@ namespace Nz
return createInfo; return createInfo;
} }
VkPipelineViewportStateCreateInfo VulkanRenderPipeline::BuildViewportInfo(const RenderPipelineInfo& pipelineInfo) VkPipelineViewportStateCreateInfo VulkanRenderPipeline::BuildViewportInfo(const RenderPipelineInfo& /*pipelineInfo*/)
{ {
VkPipelineViewportStateCreateInfo createInfo = {}; VkPipelineViewportStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
@ -229,7 +229,7 @@ namespace Nz
return vertexBindings; return vertexBindings;
} }
VkPipelineVertexInputStateCreateInfo VulkanRenderPipeline::BuildVertexInputInfo(const RenderPipelineInfo& pipelineInfo, const std::vector<VkVertexInputAttributeDescription>& vertexAttributes, const std::vector<VkVertexInputBindingDescription>& bindingDescriptions) VkPipelineVertexInputStateCreateInfo VulkanRenderPipeline::BuildVertexInputInfo(const RenderPipelineInfo& /*pipelineInfo*/, const std::vector<VkVertexInputAttributeDescription>& vertexAttributes, const std::vector<VkVertexInputBindingDescription>& bindingDescriptions)
{ {
VkPipelineVertexInputStateCreateInfo createInfo = {}; VkPipelineVertexInputStateCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;

View File

@ -24,7 +24,7 @@ namespace Nz
std::vector<EntryPoint> entryPoints; std::vector<EntryPoint> entryPoints;
bool HandleOpcode(const SpirvInstruction& instruction, UInt32 wordCount) override bool HandleOpcode(const SpirvInstruction& instruction, UInt32 /*wordCount*/) override
{ {
switch (instruction.op) switch (instruction.op)
{ {

View File

@ -56,14 +56,15 @@ namespace
} }
ShaderGraph::ShaderGraph() : ShaderGraph::ShaderGraph() :
m_flowScene(BuildRegistry()),
m_type(ShaderType::NotSet) m_type(ShaderType::NotSet)
{ {
m_flowScene.emplace(BuildRegistry());
m_previewModel = std::make_unique<QuadPreview>(); m_previewModel = std::make_unique<QuadPreview>();
QObject::connect(&m_flowScene, &QGraphicsScene::selectionChanged, [&] QObject::connect(&m_flowScene.value(), &QGraphicsScene::selectionChanged, [&]
{ {
auto selectedNodes = m_flowScene.selectedNodes(); auto selectedNodes = m_flowScene->selectedNodes();
if (selectedNodes.size() == 1) if (selectedNodes.size() == 1)
OnSelectedNodeUpdate(this, static_cast<ShaderNode*>(selectedNodes.front()->nodeDataModel())); OnSelectedNodeUpdate(this, static_cast<ShaderNode*>(selectedNodes.front()->nodeDataModel()));
else else
@ -78,31 +79,31 @@ m_type(ShaderType::NotSet)
UpdateTexturePreview(0, QImage(R"(C:\Users\Lynix\Pictures\potatavril.png)")); UpdateTexturePreview(0, QImage(R"(C:\Users\Lynix\Pictures\potatavril.png)"));
auto& node1 = m_flowScene.createNode(std::make_unique<TextureValue>(*this)); auto& node1 = m_flowScene->createNode(std::make_unique<TextureValue>(*this));
node1.nodeGraphicsObject().setPos(0, 200); node1.nodeGraphicsObject().setPos(0, 200);
auto& node2 = m_flowScene.createNode(std::make_unique<InputValue>(*this)); auto& node2 = m_flowScene->createNode(std::make_unique<InputValue>(*this));
node2.nodeGraphicsObject().setPos(50, 350); node2.nodeGraphicsObject().setPos(50, 350);
auto& node3 = m_flowScene.createNode(std::make_unique<SampleTexture>(*this)); auto& node3 = m_flowScene->createNode(std::make_unique<SampleTexture>(*this));
node3.nodeGraphicsObject().setPos(200, 200); node3.nodeGraphicsObject().setPos(200, 200);
auto& node4 = m_flowScene.createNode(std::make_unique<VecMul>(*this)); auto& node4 = m_flowScene->createNode(std::make_unique<VecMul>(*this));
node4.nodeGraphicsObject().setPos(400, 200); node4.nodeGraphicsObject().setPos(400, 200);
auto& node5 = m_flowScene.createNode(std::make_unique<OutputValue>(*this)); auto& node5 = m_flowScene->createNode(std::make_unique<OutputValue>(*this));
node5.nodeGraphicsObject().setPos(600, 300); node5.nodeGraphicsObject().setPos(600, 300);
m_flowScene.createConnection(node3, 0, node1, 0); m_flowScene->createConnection(node3, 0, node1, 0);
m_flowScene.createConnection(node3, 1, node2, 0); m_flowScene->createConnection(node3, 1, node2, 0);
m_flowScene.createConnection(node4, 0, node3, 0); m_flowScene->createConnection(node4, 0, node3, 0);
m_flowScene.createConnection(node4, 1, node3, 0); m_flowScene->createConnection(node4, 1, node3, 0);
m_flowScene.createConnection(node5, 0, node4, 0); m_flowScene->createConnection(node5, 0, node4, 0);
} }
ShaderGraph::~ShaderGraph() ShaderGraph::~ShaderGraph()
{ {
m_flowScene.clearScene(); m_flowScene.reset();
} }
std::size_t ShaderGraph::AddBuffer(std::string name, BufferType bufferType, std::size_t structIndex, std::size_t bindingIndex) std::size_t ShaderGraph::AddBuffer(std::string name, BufferType bufferType, std::size_t structIndex, std::size_t bindingIndex)
@ -187,8 +188,8 @@ void ShaderGraph::Clear()
{ {
m_type = ShaderType::NotSet; m_type = ShaderType::NotSet;
m_flowScene.clearScene(); m_flowScene->clearScene();
m_flowScene.clear(); m_flowScene->clear();
m_buffers.clear(); m_buffers.clear();
m_conditions.clear(); m_conditions.clear();
@ -313,10 +314,10 @@ void ShaderGraph::Load(const QJsonObject& data)
OnTextureListUpdate(this); OnTextureListUpdate(this);
for (QJsonValueRef node : data["nodes"].toArray()) for (QJsonValueRef node : data["nodes"].toArray())
m_flowScene.restoreNode(node.toObject()); m_flowScene->restoreNode(node.toObject());
for (QJsonValueRef connection : data["connections"].toArray()) for (QJsonValueRef connection : data["connections"].toArray())
m_flowScene.restoreConnection(connection.toObject()); m_flowScene->restoreConnection(connection.toObject());
} }
QJsonObject ShaderGraph::Save() QJsonObject ShaderGraph::Save()
@ -430,14 +431,14 @@ QJsonObject ShaderGraph::Save()
QJsonArray nodesJsonArray; QJsonArray nodesJsonArray;
{ {
for (auto&& [uuid, node] : m_flowScene.nodes()) for (auto&& [uuid, node] : m_flowScene->nodes())
nodesJsonArray.append(node->save()); nodesJsonArray.append(node->save());
} }
sceneJson["nodes"] = nodesJsonArray; sceneJson["nodes"] = nodesJsonArray;
QJsonArray connectionJsonArray; QJsonArray connectionJsonArray;
{ {
for (auto&& [uuid, connection] : m_flowScene.connections()) for (auto&& [uuid, connection] : m_flowScene->connections())
{ {
QJsonObject connectionJson = connection->save(); QJsonObject connectionJson = connection->save();
@ -638,8 +639,12 @@ void ShaderGraph::UpdateTexturePreview(std::size_t textureIndex, QImage preview)
{ {
assert(textureIndex < m_textures.size()); assert(textureIndex < m_textures.size());
auto& textureEntry = m_textures[textureIndex]; auto& textureEntry = m_textures[textureIndex];
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
textureEntry.preview = std::move(preview); textureEntry.preview = std::move(preview);
textureEntry.preview.convertTo(QImage::Format_RGBA8888); textureEntry.preview.convertTo(QImage::Format_RGBA8888);
#else
textureEntry.preview = preview.convertToFormat(QImage::Format_RGBA8888);
#endif
OnTexturePreviewUpdate(this, textureIndex); OnTexturePreviewUpdate(this, textureIndex);
} }
@ -844,7 +849,7 @@ std::unique_ptr<Nz::ShaderAst::DeclareFunctionStatement> ShaderGraph::ToFunction
std::vector<QtNodes::Node*> outputNodes; std::vector<QtNodes::Node*> outputNodes;
m_flowScene.iterateOverNodes([&](QtNodes::Node* node) m_flowScene->iterateOverNodes([&](QtNodes::Node* node)
{ {
if (node->nodeDataModel()->nPorts(QtNodes::PortType::Out) == 0) if (node->nodeDataModel()->nPorts(QtNodes::PortType::Out) == 0)
{ {

View File

@ -9,6 +9,7 @@
#include <nodes/FlowScene> #include <nodes/FlowScene>
#include <ShaderNode/Enums.hpp> #include <ShaderNode/Enums.hpp>
#include <ShaderNode/Previews/PreviewModel.hpp> #include <ShaderNode/Previews/PreviewModel.hpp>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -153,7 +154,7 @@ class ShaderGraph
std::shared_ptr<QtNodes::DataModelRegistry> BuildRegistry(); std::shared_ptr<QtNodes::DataModelRegistry> BuildRegistry();
std::unique_ptr<Nz::ShaderAst::DeclareFunctionStatement> ToFunction() const; std::unique_ptr<Nz::ShaderAst::DeclareFunctionStatement> ToFunction() const;
mutable QtNodes::FlowScene m_flowScene; mutable std::optional<QtNodes::FlowScene> m_flowScene;
std::vector<BufferEntry> m_buffers; std::vector<BufferEntry> m_buffers;
std::vector<ConditionEntry> m_conditions; std::vector<ConditionEntry> m_conditions;
std::vector<InputEntry> m_inputs; std::vector<InputEntry> m_inputs;

View File

@ -87,7 +87,7 @@ inline const PreviewModel& ShaderGraph::GetPreviewModel() const
inline QtNodes::FlowScene& ShaderGraph::GetScene() inline QtNodes::FlowScene& ShaderGraph::GetScene()
{ {
return m_flowScene; return *m_flowScene;
} }
inline auto ShaderGraph::GetTexture(std::size_t textureIndex) const -> const TextureEntry& inline auto ShaderGraph::GetTexture(std::size_t textureIndex) const -> const TextureEntry&