diff --git a/.vscode/settings.json b/.vscode/settings.json index 9f87834..5db8820 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "files.associations": { "*.h": "cpp", "*.ush": "hlsl", + "*.pl": "prolog", "xstring": "cpp", "list": "cpp", "xhash": "cpp", @@ -108,7 +109,10 @@ "coroutine": "cpp", "*.tcc": "cpp", "stop_token": "cpp", - "span": "cpp" + "span": "cpp", + "charconv": "cpp", + "format": "cpp", + "semaphore": "cpp" }, "cmake.skipConfigureIfCachePresent": false, "cmake.configureArgs": [ @@ -118,5 +122,6 @@ "C_Cpp.default.intelliSenseMode": "msvc-x64", "files.watcherExclude": { "**/target": true - } + }, + "C_Cpp.errorSquiggles": "Disabled" } \ No newline at end of file diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 9c7d1e4..97bf76b 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -40,6 +40,8 @@ list (APPEND EXTRA_CMAKE_ARGS #-----------------KTX---------------------------- list(APPEND DEPENDENCIES ktx) +find_program(BASH_EXECUTABLE git-bash) + add_subdirectory(${KTX_ROOT} ${KTX_ROOT}) #--------------------JSON------------------ diff --git a/external/ktx b/external/ktx index 68674a6..a2ccc90 160000 --- a/external/ktx +++ b/external/ktx @@ -1 +1 @@ -Subproject commit 68674a69caeb42c35eff5b3aba42e4ce07261af7 +Subproject commit a2ccc90effc8a5831a271ea033a9e38e26e63a59 diff --git a/res/shaders/UIPass.slang b/res/shaders/UIPass.slang new file mode 100644 index 0000000..30d28b9 --- /dev/null +++ b/res/shaders/UIPass.slang @@ -0,0 +1,31 @@ +struct VertexStageOutput +{ + float4 position : SV_Position; + float2 uvCoords : TEXCOORD; +}; + + +[shader("vertex")] +VertexStageOutput vertexMain(uint vertexId : SV_VertexID) +{ + float2 coordinates[4] = { + float2(0, 0), + float2(0, 1), + float2(1, 0), + float2(1, 1) + }; + VertexStageOutput output; + output.uvCoords = coordinates[vertexId]; + output.position = float4(output.uvCoords * 2 - 1, 1, 1); + output.position.y = -output.position.y; + return output; +} + +[shader("fragment")] +float4 fragmentMain( + float4 position : SV_Position, + float2 uvCoords : TEXCOORD +) : SV_Target +{ + return float4(0, 1, 0, 1); +} \ No newline at end of file diff --git a/src/Engine/Graphics/Graphics.h b/src/Engine/Graphics/Graphics.h index 900623d..18d1e9f 100644 --- a/src/Engine/Graphics/Graphics.h +++ b/src/Engine/Graphics/Graphics.h @@ -30,7 +30,7 @@ public: virtual PWindow createWindow(const WindowCreateInfo &createInfo) = 0; virtual PViewport createViewport(PWindow owner, const ViewportCreateInfo &createInfo) = 0; - virtual PRenderPass createRenderPass(PRenderTargetLayout layout) = 0; + virtual PRenderPass createRenderPass(PRenderTargetLayout layout, PViewport renderArea) = 0; virtual void beginRenderPass(PRenderPass renderPass) = 0; virtual void endRenderPass() = 0; diff --git a/src/Engine/Graphics/GraphicsResources.h b/src/Engine/Graphics/GraphicsResources.h index 3d0f5c9..b93c411 100644 --- a/src/Engine/Graphics/GraphicsResources.h +++ b/src/Engine/Graphics/GraphicsResources.h @@ -549,6 +549,7 @@ public: virtual void bindVertexBuffer(const Array& streams) = 0; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0; virtual void draw(const MeshBatchElement& data) = 0; + virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) = 0; std::string name; }; DEFINE_REF(RenderCommand) @@ -588,6 +589,14 @@ public: { return samples; } + uint32 getSizeX() const + { + return sizeX; + } + uint32 getSizeY() const + { + return sizeY; + } protected: uint32 sizeX; @@ -628,7 +637,11 @@ public: SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) - : loadOp(loadOp), storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp), texture(texture) + : loadOp(loadOp) + , storeOp(storeOp) + , stencilLoadOp(stencilLoadOp) + , stencilStoreOp(stencilStoreOp) + , texture(texture) { } virtual ~RenderTargetAttachment() @@ -646,6 +659,14 @@ public: { return texture->getNumSamples(); } + virtual uint32 getSizeX() const + { + return texture->getSizeX(); + } + virtual uint32 getSizeY() const + { + return texture->getSizeY(); + } inline SeAttachmentLoadOp getLoadOp() const { return loadOp; } inline SeAttachmentStoreOp getStoreOp() const { return storeOp; } inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } @@ -665,7 +686,7 @@ class SwapchainAttachment : public RenderTargetAttachment { public: SwapchainAttachment(PWindow owner, - SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_CLEAR, + SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD, SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) @@ -689,7 +710,14 @@ public: { return owner->getNumSamples(); } - + virtual uint32 getSizeX() const + { + return owner->getSizeX(); + } + virtual uint32 getSizeY() const + { + return owner->getSizeY(); + } private: PWindow owner; }; diff --git a/src/Engine/Graphics/Mesh.h b/src/Engine/Graphics/Mesh.h index 67fac48..e7ad89c 100644 --- a/src/Engine/Graphics/Mesh.h +++ b/src/Engine/Graphics/Mesh.h @@ -4,44 +4,6 @@ namespace Seele { -/*#define MAX_TEX_CHANNELS 8 -struct MeshDescription -{ - Array layout; - Gfx::PVertexDeclaration declaration; - uint32 getStride() const - { - return getNumFloats() * sizeof(float); - } - uint32 getNumFloats() const - { - uint32 vertexSize = 0; - for(auto a : layout) - { - switch (a) - { - case Gfx::VertexAttribute::POSITION: - case Gfx::VertexAttribute::NORMAL: - case Gfx::VertexAttribute::TANGENT: - case Gfx::VertexAttribute::BITANGENT: - vertexSize += 3; - break; - case Gfx::VertexAttribute::TEXCOORD: - vertexSize += 2; - break; - } - } - return vertexSize; - } - - friend class boost::serialization::access; - template - void serialize(Archive& ar, const unsigned int version) - { - ar & layout; - //TODO declaration - } -};*/ DECLARE_REF(MaterialAsset) class Mesh { diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 55c4242..f310270 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -80,11 +80,9 @@ void BasePassMeshProcessor::clearCommands() } BasePass::BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) - : RenderPass(renderGraph) + : RenderPass(renderGraph, graphics, viewport) , processor(new BasePassMeshProcessor(scene, viewport, graphics, false)) , scene(scene) - , graphics(graphics) - , viewport(viewport) , descriptorSets(4) , source(source->getCameraComponent()) { @@ -198,7 +196,7 @@ void BasePass::createRenderPass() Gfx::PRenderTargetAttachment depthAttachment = renderGraph->requestRenderTarget("DEPTHPREPASS_DEPTH"); depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment); - renderPass = graphics->createRenderPass(layout); + renderPass = graphics->createRenderPass(layout, viewport); oLightIndexList = renderGraph->requestBuffer("LIGHTCULLING_OLIGHTLIST"); oLightGrid = renderGraph->requestTexture("LIGHTCULLING_OLIGHTGRID"); } diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index 8cb652f..cc0c77a 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -46,9 +46,8 @@ private: Gfx::PRenderTargetAttachment colorAttachment; Gfx::PTexture2D depthBuffer; UPBasePassMeshProcessor processor; + const PScene scene; - Gfx::PGraphics graphics; - Gfx::PViewport viewport; Array descriptorSets; PCameraComponent source; Gfx::PPipelineLayout basePassLayout; diff --git a/src/Engine/Graphics/RenderPass/CMakeLists.txt b/src/Engine/Graphics/RenderPass/CMakeLists.txt index 0da5f4a..62a4670 100644 --- a/src/Engine/Graphics/RenderPass/CMakeLists.txt +++ b/src/Engine/Graphics/RenderPass/CMakeLists.txt @@ -11,4 +11,6 @@ target_sources(SeeleEngine RenderGraph.h RenderGraph.cpp RenderPass.h - RenderPass.cpp) \ No newline at end of file + RenderPass.cpp + UIPass.h + UIPass.cpp) \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index d467f35..02109e6 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -79,11 +79,9 @@ void DepthPrepassMeshProcessor::clearCommands() } DepthPrepass::DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) - : RenderPass(renderGraph) + : RenderPass(renderGraph, graphics, viewport) , processor(new DepthPrepassMeshProcessor(scene, viewport, graphics)) , scene(scene) - , graphics(graphics) - , viewport(viewport) , descriptorSets(3) , source(source->getCameraComponent()) { @@ -156,8 +154,10 @@ void DepthPrepass::endFrame() void DepthPrepass::publishOutputs() { TextureCreateInfo depthBufferInfo; - depthBufferInfo.width = viewport->getSizeX(); - depthBufferInfo.height = viewport->getSizeY(); + // If we render to a part of an image, the depth buffer itself must + // still match the size of the whole image or their coordinate systems go out of sync + depthBufferInfo.width = viewport->getOwner()->getSizeX(); + depthBufferInfo.height = viewport->getOwner()->getSizeY(); depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT; depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; depthBuffer = graphics->createTexture2D(depthBufferInfo); @@ -170,7 +170,7 @@ void DepthPrepass::publishOutputs() void DepthPrepass::createRenderPass() { Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(depthAttachment); - renderPass = graphics->createRenderPass(layout); + renderPass = graphics->createRenderPass(layout, viewport); } void DepthPrepass::modifyRenderPassMacros(Map& defines) diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.h b/src/Engine/Graphics/RenderPass/DepthPrepass.h index 85247ff..f2896d5 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.h +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.h @@ -46,8 +46,7 @@ private: Gfx::PTexture2D depthBuffer; UPDepthPrepassMeshProcessor processor; const PScene scene; - Gfx::PGraphics graphics; - Gfx::PViewport viewport; + Array descriptorSets; PCameraComponent source; Gfx::PPipelineLayout depthPrepassLayout; diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index b5a600a..f2c94ef 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -8,10 +8,8 @@ using namespace Seele; LightCullingPass::LightCullingPass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera) - : RenderPass(renderGraph) + : RenderPass(renderGraph, graphics, viewport) , scene(scene) - , viewport(viewport) - , graphics(graphics) , source(camera->getCameraComponent()) { } diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index 97fc174..526ac92 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -44,9 +44,7 @@ private: }; PScene scene; - Gfx::PViewport viewport; - Gfx::PGraphics graphics; - + Gfx::PStructuredBuffer frustumBuffer; Gfx::PUniformBuffer dispatchParamsBuffer; Gfx::PUniformBuffer viewParamsBuffer; diff --git a/src/Engine/Graphics/RenderPass/RenderPass.cpp b/src/Engine/Graphics/RenderPass/RenderPass.cpp index 71fb066..11f2cc5 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.cpp +++ b/src/Engine/Graphics/RenderPass/RenderPass.cpp @@ -2,8 +2,8 @@ using namespace Seele; -RenderPass::RenderPass(PRenderGraph renderGraph) - : renderGraph(renderGraph) +RenderPass::RenderPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport) + : renderGraph(renderGraph), graphics(graphics), viewport(viewport) { } diff --git a/src/Engine/Graphics/RenderPass/RenderPass.h b/src/Engine/Graphics/RenderPass/RenderPass.h index 385df76..cd295ab 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.h +++ b/src/Engine/Graphics/RenderPass/RenderPass.h @@ -4,12 +4,14 @@ namespace Seele { +DECLARE_NAME_REF(Gfx, Viewport) +DECLARE_NAME_REF(Gfx, Graphics) DECLARE_NAME_REF(Gfx, RenderPass) DECLARE_REF(RenderGraph) class RenderPass { public: - RenderPass(PRenderGraph rendergraph); + RenderPass(PRenderGraph rendergraph, Gfx::PGraphics graphics, Gfx::PViewport viewport); virtual ~RenderPass(); virtual void beginFrame() = 0; virtual void render() = 0; @@ -27,6 +29,8 @@ protected: } viewParams; Gfx::PRenderPass renderPass; PRenderGraph renderGraph; + Gfx::PGraphics graphics; + Gfx::PViewport viewport; }; DEFINE_REF(RenderPass) } // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp new file mode 100644 index 0000000..335193b --- /dev/null +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -0,0 +1,91 @@ +#include "UIPass.h" +#include "RenderGraph.h" +#include "Graphics/Graphics.h" + +using namespace Seele; + +UIPass::UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment) + : RenderPass(renderGraph, graphics, viewport) + , renderTarget(attachment) +{ +} + +UIPass::~UIPass() +{ + +} + +void UIPass::beginFrame() +{ + +} + +void UIPass::render() +{ + graphics->beginRenderPass(renderPass); + Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand"); + command->setViewport(viewport); + command->bindPipeline(pipeline); + command->draw(4, 1, 0, 0); + graphics->executeCommands(Array({command})); + graphics->endRenderPass(); +} + +void UIPass::endFrame() +{ + +} + +void UIPass::publishOutputs() +{ + TextureCreateInfo depthBufferInfo; + // Even if we only render to part of an image, we need to make sure + // that the depthbuffer is the same size or they can't be used in the same + // framebuffer + depthBufferInfo.width = viewport->getOwner()->getSizeX(); + depthBufferInfo.height = viewport->getOwner()->getSizeY(); + depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT; + depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + depthBuffer = graphics->createTexture2D(depthBufferInfo); + depthAttachment = + new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + depthAttachment->clear.depthStencil.depth = 1.0f; + renderGraph->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment); +} + +void UIPass::createRenderPass() +{ + std::ifstream codeStream("./shaders/UIPass.slang", std::ios::ate); + auto fileSize = codeStream.tellg(); + codeStream.seekg(0); + Array buffer(static_cast(fileSize)); + codeStream.read(buffer.data(), fileSize); + + ShaderCreateInfo createInfo; + createInfo.shaderCode.add(std::string(buffer.data())); + createInfo.name = "UIVertex"; + createInfo.entryPoint = "vertexMain"; + vertexShader = graphics->createVertexShader(createInfo); + + createInfo.name = "UIFragment"; + createInfo.entryPoint = "fragmentMain"; + fragmentShader = graphics->createFragmentShader(createInfo); + declaration = graphics->createVertexDeclaration({}); + pipelineLayout = graphics->createPipelineLayout(); + pipelineLayout->create(); + + Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment); + renderPass = graphics->createRenderPass(layout, viewport); + + GraphicsPipelineCreateInfo pipelineInfo; + pipelineInfo.vertexDeclaration = declaration; + pipelineInfo.vertexShader = vertexShader; + pipelineInfo.fragmentShader = fragmentShader; + pipelineInfo.renderPass = renderPass; + pipelineInfo.pipelineLayout = pipelineLayout; + pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE; + pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + + pipeline = graphics->createGraphicsPipeline(pipelineInfo); +} diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h new file mode 100644 index 0000000..95a5243 --- /dev/null +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -0,0 +1,33 @@ +#pragma once +#include "RenderPass.h" +#include "UI/RenderHierarchy.h" +#include "Graphics/GraphicsResources.h" + +namespace Seele +{ +DECLARE_NAME_REF(Gfx, Texture2D) +DECLARE_NAME_REF(Gfx, RenderTargetAttachment) +class UIPass : public RenderPass +{ +public: + UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); + virtual ~UIPass(); + virtual void beginFrame() override; + virtual void render() override; + virtual void endFrame() override; + virtual void publishOutputs() override; + virtual void createRenderPass() override; +private: + UI::RenderHierarchy hierarchy; + Gfx::PRenderTargetAttachment renderTarget; + Gfx::PRenderTargetAttachment depthAttachment; + Gfx::PTexture2D depthBuffer; + + Gfx::PVertexDeclaration declaration; + Gfx::PVertexShader vertexShader; + Gfx::PFragmentShader fragmentShader; + Gfx::PPipelineLayout pipelineLayout; + Gfx::PGraphicsPipeline pipeline; +}; +DEFINE_REF(UIPass); +} // namespace Seele diff --git a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp index 9931d59..614666f 100644 --- a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp @@ -140,8 +140,8 @@ void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) dynamicBarriers[i] = barrier; dynamicBarriers[i].buffer = buffers[i].buffer; } - vkCmdPipelineBarrier(srcCommand, srcStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); - vkCmdPipelineBarrier(dstCommand, srcStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); + vkCmdPipelineBarrier(srcCommand, srcStage, srcStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); + vkCmdPipelineBarrier(dstCommand, dstStage, dstStage, 0, 0, nullptr, numBuffers, dynamicBarriers, 0, nullptr); sourceManager->submitCommands(); } diff --git a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp index 6794273..a515018 100644 --- a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp @@ -250,7 +250,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) auto descriptor = descriptorSet.cast(); boundDescriptors.add(descriptor.getHandle()); descriptor->bind(); - //std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl; + VkDescriptorSet setHandle = descriptor->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); } @@ -261,7 +261,7 @@ void RenderCommand::bindDescriptor(const Array& descriptorS { auto descriptorSet = descriptorSets[i].cast(); descriptorSet->bind(); - //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; + boundDescriptors.add(descriptorSet.getHandle()); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); } @@ -290,6 +290,11 @@ void RenderCommand::draw(const MeshBatchElement& data) vkCmdDrawIndexed(handle, data.indexBuffer->getNumIndices(), data.numInstances, data.minVertexIndex, data.baseVertexIndex, 0); } +void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) +{ + vkCmdDraw(handle, vertexCount, instanceCount, firstVertex, firstInstance); +} + ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool) : SecondaryCmdBuffer(graphics, cmdPool) { diff --git a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.h b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.h index 249f5e3..a6f4da2 100644 --- a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.h +++ b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.h @@ -109,7 +109,7 @@ public: virtual void bindVertexBuffer(const Array& streams) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void draw(const MeshBatchElement& data) override; - + virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override; private: PGraphicsPipeline pipeline; friend class CmdBuffer; diff --git a/src/Engine/Graphics/Vulkan/VulkanFramebuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanFramebuffer.cpp index e360dda..9ad4adb 100644 --- a/src/Engine/Graphics/Vulkan/VulkanFramebuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanFramebuffer.cpp @@ -13,31 +13,39 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::PRende FramebufferDescription description; std::memset(&description, 0, sizeof(FramebufferDescription)); Array attachments; + uint32 sizeX = 0; + uint32 sizeY = 0; for (auto inputAttachment : layout->inputAttachments) { PTexture2D vkInputAttachment = inputAttachment->getTexture().cast(); attachments.add(vkInputAttachment->getView()); description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView(); + sizeX = std::max(sizeX, vkInputAttachment->getSizeX()); + sizeY = std::max(sizeY, vkInputAttachment->getSizeY()); } for (auto colorAttachment : layout->colorAttachments) { PTexture2D vkColorAttachment = colorAttachment->getTexture().cast(); attachments.add(vkColorAttachment->getView()); description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView(); + sizeX = std::max(sizeX, vkColorAttachment->getSizeX()); + sizeY = std::max(sizeY, vkColorAttachment->getSizeY()); } if (layout->depthAttachment != nullptr) { PTexture2D vkDepthAttachment = layout->depthAttachment->getTexture().cast(); attachments.add(vkDepthAttachment->getView()); description.depthAttachment = vkDepthAttachment->getView(); + sizeX = std::max(sizeX, vkDepthAttachment->getSizeX()); + sizeY = std::max(sizeY, vkDepthAttachment->getSizeY()); } VkFramebufferCreateInfo createInfo = init::FramebufferCreateInfo( renderPass->getHandle(), (uint32)attachments.size(), attachments.data(), - renderPass->getRenderArea().extent.width, - renderPass->getRenderArea().extent.height, + sizeX, + sizeY, 1); VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle)); diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp index 073d600..c28f714 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp @@ -55,9 +55,9 @@ Gfx::PViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreate viewports.add(result); return result; } -Gfx::PRenderPass Graphics::createRenderPass(Gfx::PRenderTargetLayout layout) +Gfx::PRenderPass Graphics::createRenderPass(Gfx::PRenderTargetLayout layout, Gfx::PViewport renderArea) { - PRenderPass result = new RenderPass(this, layout); + PRenderPass result = new RenderPass(this, layout, renderArea); return result; } void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.h b/src/Engine/Graphics/Vulkan/VulkanGraphics.h index ed9befe..e578bf0 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphics.h +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.h @@ -42,7 +42,7 @@ public: virtual Gfx::PWindow createWindow(const WindowCreateInfo &createInfo) override; virtual Gfx::PViewport createViewport(Gfx::PWindow owner, const ViewportCreateInfo &createInfo) override; - virtual Gfx::PRenderPass createRenderPass(Gfx::PRenderTargetLayout layout) override; + virtual Gfx::PRenderPass createRenderPass(Gfx::PRenderTargetLayout layout, Gfx::PViewport renderArea) override; virtual void beginRenderPass(Gfx::PRenderPass renderPass) override; virtual void endRenderPass() override; diff --git a/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp b/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp index 86dc697..aad958d 100644 --- a/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp @@ -7,14 +7,14 @@ using namespace Seele; using namespace Seele::Vulkan; -RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout) +RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout, Gfx::PViewport viewport) : Gfx::RenderPass(layout) , graphics(graphics) { - renderArea.extent.width = layout->width; - renderArea.extent.height = layout->height; - renderArea.offset.x = 0; - renderArea.offset.y = 0; + renderArea.extent.width = viewport->getSizeX(); + renderArea.extent.height = viewport->getSizeY(); + renderArea.offset.x = viewport->getOffsetX(); + renderArea.offset.y = viewport->getOffsetY(); subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS; Array attachments; Array inputRefs; diff --git a/src/Engine/Graphics/Vulkan/VulkanRenderPass.h b/src/Engine/Graphics/Vulkan/VulkanRenderPass.h index f53af94..945e985 100644 --- a/src/Engine/Graphics/Vulkan/VulkanRenderPass.h +++ b/src/Engine/Graphics/Vulkan/VulkanRenderPass.h @@ -8,7 +8,7 @@ namespace Vulkan class RenderPass : public Gfx::RenderPass { public: - RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout); + RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout, Gfx::PViewport viewport); virtual ~RenderPass(); uint32 getFramebufferHash(); inline VkRenderPass getHandle() const diff --git a/src/Engine/Graphics/Vulkan/VulkanShader.cpp b/src/Engine/Graphics/Vulkan/VulkanShader.cpp index a712161..b2f0b29 100644 --- a/src/Engine/Graphics/Vulkan/VulkanShader.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanShader.cpp @@ -52,39 +52,6 @@ static SlangStage getStageFromShaderType(ShaderType type) } } -/*static void createMixedDescriptorLayout(PDescriptorLayout layout, VariableLayoutReflection* parameter) -{ - //std::cout << "category: " << (uint32)parameter->ge << std::endl; - uint32 categoryCount = parameter->getCategoryCount(); - std::cout << "Mixed parameter " << parameter->getName() << " with categories: " << std::endl; - for(uint32 i = 0; i < categoryCount; ++i) - { - ParameterCategory category = parameter->getCategoryByIndex(i); - uint32 offset = parameter->getOffset(category); - uint32 space = parameter->getBindingSpace(category); - std::cout << "category: " << category << std::endl << " offset: " << offset << std::endl << " space: " << space << std::endl; - } -} - -static Gfx::SeDescriptorType getTypeFromKind(slang::TypeReflection::Kind kind) -{ - switch (kind) - { - case slang::TypeReflection::Kind::ConstantBuffer: - case slang::TypeReflection::Kind::GenericTypeParameter: - case slang::TypeReflection::Kind::ParameterBlock: - return Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - case slang::TypeReflection::Kind::ShaderStorageBuffer: - return Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER; - case slang::TypeReflection::Kind::TextureBuffer: - return Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE; - case slang::TypeReflection::Kind::SamplerState: - return Gfx::SE_DESCRIPTOR_TYPE_SAMPLER; - default: - return Gfx::SE_DESCRIPTOR_TYPE_MAX_ENUM; - } -}*/ - void Shader::create(const ShaderCreateInfo& createInfo) { entryPointName = createInfo.entryPoint; diff --git a/src/Engine/Graphics/Vulkan/VulkanTexture.cpp b/src/Engine/Graphics/Vulkan/VulkanTexture.cpp index ee977f5..b22b7bf 100644 --- a/src/Engine/Graphics/Vulkan/VulkanTexture.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanTexture.cpp @@ -130,7 +130,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, region.imageSubresource.layerCount = 1; region.imageOffset = {0, 0, 0}; - region.imageExtent = {sizeX, sizeX, sizeZ}; + region.imageExtent = {sizeX, sizeY, sizeZ}; vkCmdCopyBufferToImage(cmdBufferManager->getCommands()->getHandle(), staging->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); @@ -251,10 +251,11 @@ void TextureHandle::executeOwnershipBarrier(Gfx::QueueType newOwner) dstStage = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; dstManager = graphics->getGraphicsCommands(); } + VkCommandBuffer sourceCmd = sourceManager->getCommands()->getHandle(); VkCommandBuffer destCmd = dstManager->getCommands()->getHandle(); - vkCmdPipelineBarrier(sourceCmd, srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); - vkCmdPipelineBarrier(destCmd, srcStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); + vkCmdPipelineBarrier(sourceCmd, srcStage, srcStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); + vkCmdPipelineBarrier(destCmd, dstStage, dstStage, 0, 0, nullptr, 0, nullptr, 1, &imageBarrier); currentOwner = newOwner; sourceManager->submitCommands(); } diff --git a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp index cece238..9fae121 100644 --- a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp @@ -162,8 +162,19 @@ void Window::advanceBackBuffer() imageAcquiredSemaphore = imageAcquired[semaphoreIndex]; currentImageIndex = imageIndex; - backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); PCmdBuffer cmdBuffer = graphics->getGraphicsCommands()->getCommands(); + backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + VkClearColorValue clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; + VkImageSubresourceRange range = init::ImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT); + vkCmdClearColorImage( + cmdBuffer->getHandle(), + backBufferImages[currentImageIndex]->getHandle(), + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + &clearColor, + 1, + &range); + + backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); graphics->getGraphicsCommands()->getCommands()->addWaitSemaphore(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, imageAcquiredSemaphore); graphics->getGraphicsCommands()->submitCommands(); } diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index f06b54d..f67c029 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -27,7 +27,7 @@ Scene::Scene(Gfx::PGraphics graphics) lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1); } lightEnv.numPointLights = 16; - lightEnv.pointLights[0].colorRange = Vector4(1, 0, 0, 100); + lightEnv.pointLights[0].colorRange = Vector4(1, 1, 1, 1000); lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1); } diff --git a/src/Engine/UI/CMakeLists.txt b/src/Engine/UI/CMakeLists.txt index 9aec08b..352d40b 100644 --- a/src/Engine/UI/CMakeLists.txt +++ b/src/Engine/UI/CMakeLists.txt @@ -1,8 +1,12 @@ target_sources(SeeleEngine PRIVATE - Element.h - Element.cpp + HorizontalLayout.h + HorizontalLayout.cpp + Layout.h + Layout.cpp RenderHierarchy.h RenderHierarchy.cpp - UIRenderPath.h - UIRenderPath.cpp) \ No newline at end of file + VerticalLayout.h + VerticalLayout.cpp) + +add_subdirectory(Elements/) \ No newline at end of file diff --git a/src/Engine/UI/Element.h b/src/Engine/UI/Element.h deleted file mode 100644 index 1fd7704..0000000 --- a/src/Engine/UI/Element.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "MinimalEngine.h" - -namespace Seele -{ -namespace UI -{ -//Element defines any part of the UI -DECLARE_REF(Element) -class Element -{ -public: - Element(); - virtual ~Element(); - void addElement(PElement element); - const Array getChildren() const; - void clear(); - void remove(PElement element); - void setEnabled(bool newEnabled); - bool isEnabled() const; -protected: - bool enabled; - Array children; -}; -DEFINE_REF(Element) -} // namespace UI -} // namespace Seele diff --git a/src/Engine/UI/Elements/CMakeLists.txt b/src/Engine/UI/Elements/CMakeLists.txt new file mode 100644 index 0000000..aba5a85 --- /dev/null +++ b/src/Engine/UI/Elements/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(SeeleEngine + PRIVATE + Element.h + Element.cpp) \ No newline at end of file diff --git a/src/Engine/UI/Element.cpp b/src/Engine/UI/Elements/Element.cpp similarity index 63% rename from src/Engine/UI/Element.cpp rename to src/Engine/UI/Elements/Element.cpp index a1984f5..4efd4c3 100644 --- a/src/Engine/UI/Element.cpp +++ b/src/Engine/UI/Elements/Element.cpp @@ -11,12 +11,12 @@ Element::~Element() { } -void Element::addElement(PElement element) +void Element::addChild(PElement element) { - children.add(element); + children.add(element); } -const Array Element::getChildren() const +const Array Element::getChildren() { return children; } @@ -39,4 +39,14 @@ void Element::setEnabled(bool newEnabled) bool Element::isEnabled() const { return enabled; +} + +Rect& Element::getBoundingBox() +{ + return boundingBox; +} + +const Rect Element::getBoundingBox() const +{ + return boundingBox; } \ No newline at end of file diff --git a/src/Engine/UI/Elements/Element.h b/src/Engine/UI/Elements/Element.h new file mode 100644 index 0000000..9609b93 --- /dev/null +++ b/src/Engine/UI/Elements/Element.h @@ -0,0 +1,40 @@ +#pragma once +#include "MinimalEngine.h" + +namespace Seele +{ +namespace UI +{ +//Element defines any part of the UI +DECLARE_REF(Element) +class Element +{ +public: + Element(); + virtual ~Element(); + void setParent(PElement element); + PElement getParent() const; + void addChild(PElement element); + const Array getChildren(); + void clear(); + void remove(PElement element); + void setEnabled(bool newEnabled); + bool isEnabled() const; + // maybe not the healthiest inteface + // non-const version + Rect& getBoundingBox(); + // The bounding box describes the relative size of any Element + // relative to the total view, meaning a bounding box of (0,0), (1,1) + // would take up the entire view + const Rect getBoundingBox() const; +protected: + Rect boundingBox; + bool enabled; + PElement parent; + Array children; + friend class Layout; + friend class RenderElement; +}; +DEFINE_REF(Element) +} // namespace UI +} // namespace Seele diff --git a/src/Engine/UI/Elements/Panel.h b/src/Engine/UI/Elements/Panel.h new file mode 100644 index 0000000..206cd4e --- /dev/null +++ b/src/Engine/UI/Elements/Panel.h @@ -0,0 +1,15 @@ +#pragma once +#include "Element.h" + +namespace Seele +{ +namespace UI +{ +class Panel : Element +{ +public: + Panel(); + virtual ~Panel(); +}; +} // namespace UI +} // namespace Seele diff --git a/src/Engine/UI/HorizontalLayout.cpp b/src/Engine/UI/HorizontalLayout.cpp new file mode 100644 index 0000000..dd57f75 --- /dev/null +++ b/src/Engine/UI/HorizontalLayout.cpp @@ -0,0 +1,33 @@ +#include "HorizontalLayout.h" + +using namespace Seele; +using namespace Seele::UI; + +HorizontalLayout::HorizontalLayout(PElement element) + : Layout(element) +{ + +} + +HorizontalLayout::~HorizontalLayout() +{ + +} + +void HorizontalLayout::apply() +{ + Array children = element->getChildren(); + const Rect parent = element->getBoundingBox(); + float xOffset = parent.offset.x; + float yOffset = parent.offset.y; + float xSize = parent.size.x / children.size(); + float ySize = parent.size.y; + for(uint32 index = 0; index < children.size(); ++index) + { + Rect& child = children[index]->getBoundingBox(); + child.offset.x = xOffset + (index * xSize); + child.offset.y = yOffset; + child.size.x = xSize; + child.size.y = ySize; + } +} \ No newline at end of file diff --git a/src/Engine/UI/HorizontalLayout.h b/src/Engine/UI/HorizontalLayout.h new file mode 100644 index 0000000..275d72c --- /dev/null +++ b/src/Engine/UI/HorizontalLayout.h @@ -0,0 +1,17 @@ +#pragma once +#include "Layout.h" + +namespace Seele +{ +namespace UI +{ +class HorizontalLayout : Layout +{ +public: + HorizontalLayout(PElement element); + ~HorizontalLayout(); + virtual void apply() override; +private: +}; +} // namespace UI +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/UI/Layout.cpp b/src/Engine/UI/Layout.cpp new file mode 100644 index 0000000..7a91fc3 --- /dev/null +++ b/src/Engine/UI/Layout.cpp @@ -0,0 +1,14 @@ +#include "Layout.h" + +using namespace Seele; +using namespace Seele::UI; + +Layout::Layout(PElement element) + : element(element) +{ +} + +Layout::~Layout() +{ + +} \ No newline at end of file diff --git a/src/Engine/UI/Layout.h b/src/Engine/UI/Layout.h new file mode 100644 index 0000000..6b77ed0 --- /dev/null +++ b/src/Engine/UI/Layout.h @@ -0,0 +1,18 @@ +#pragma once +#include "Elements/Element.h" + +namespace Seele +{ +namespace UI +{ +class Layout +{ +public: + Layout(PElement element); + virtual ~Layout(); + virtual void apply() = 0; +protected: + PElement element; +}; +} // namespace UI +} // namespace Seele diff --git a/src/Engine/UI/RenderHierarchy.cpp b/src/Engine/UI/RenderHierarchy.cpp index e69de29..2e9a0c6 100644 --- a/src/Engine/UI/RenderHierarchy.cpp +++ b/src/Engine/UI/RenderHierarchy.cpp @@ -0,0 +1,24 @@ +#include "RenderHierarchy.h" + +using namespace Seele; +using namespace Seele::UI; + +RenderElement::RenderElement() +{ + +} + +RenderElement::~RenderElement() +{ + +} + +RenderHierarchy::RenderHierarchy() +{ + +} + +RenderHierarchy::~RenderHierarchy() +{ + +} diff --git a/src/Engine/UI/RenderHierarchy.h b/src/Engine/UI/RenderHierarchy.h index 2b14268..1bf2271 100644 --- a/src/Engine/UI/RenderHierarchy.h +++ b/src/Engine/UI/RenderHierarchy.h @@ -1,15 +1,29 @@ #pragma once +#include "Elements/Element.h" namespace Seele { namespace UI { +DECLARE_NAME_REF(Gfx, RenderCommand); +class RenderElement +{ +public: + RenderElement(); + virtual ~RenderElement(); +private: + PElement referencedElement; + Gfx::PRenderCommand renderCommand; + friend class RenderHierarchy; +}; class RenderHierarchy { public: - + RenderHierarchy(); + ~RenderHierarchy(); private: - + // List of all drawable elements in draw order + Array drawElements; }; } // namespace UI } // namespace Seele diff --git a/src/Engine/UI/UIRenderPath.cpp b/src/Engine/UI/UIRenderPath.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/Engine/UI/UIRenderPath.h b/src/Engine/UI/UIRenderPath.h deleted file mode 100644 index 11e90f4..0000000 --- a/src/Engine/UI/UIRenderPath.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "Window/RenderPath.h" -#include "Element.h" - -namespace Seele -{ -class UIRenderPath : public RenderPath -{ -public: - UIRenderPath(); - virtual ~UIRenderPath(); - virtual void beginFrame(); - virtual void render(); - virtual void endFrame(); -private: - Array rootElements; -}; -DEFINE_REF(UIRenderPath); -} // namespace Seele - diff --git a/src/Engine/UI/VerticalLayout.cpp b/src/Engine/UI/VerticalLayout.cpp new file mode 100644 index 0000000..cfa0355 --- /dev/null +++ b/src/Engine/UI/VerticalLayout.cpp @@ -0,0 +1,33 @@ +#include "VerticalLayout.h" + +using namespace Seele; +using namespace Seele::UI; + +VerticalLayout::VerticalLayout(PElement element) + : Layout(element) +{ + +} + +VerticalLayout::~VerticalLayout() +{ + +} + +void VerticalLayout::apply() +{ + Array children = element->getChildren(); + const Rect parent = element->getBoundingBox(); + float xOffset = parent.offset.x; + float yOffset = parent.offset.y; + float xSize = parent.size.x; + float ySize = parent.size.y / children.size(); + for(uint32 index = 0; index < children.size(); ++index) + { + Rect& child = children[index]->getBoundingBox(); + child.offset.x = xOffset; + child.offset.y = yOffset + (index * ySize); + child.size.x = xSize; + child.size.y = ySize; + } +} \ No newline at end of file diff --git a/src/Engine/UI/VerticalLayout.h b/src/Engine/UI/VerticalLayout.h new file mode 100644 index 0000000..445a1c1 --- /dev/null +++ b/src/Engine/UI/VerticalLayout.h @@ -0,0 +1,17 @@ +#pragma once +#include "Layout.h" + +namespace Seele +{ +namespace UI +{ +class VerticalLayout : Layout +{ +public: + VerticalLayout(PElement element); + ~VerticalLayout(); + virtual void apply() override; +private: +}; +} // namespace UI +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/Window/InspectorView.cpp b/src/Engine/Window/InspectorView.cpp index 7bba555..b3ec79c 100644 --- a/src/Engine/Window/InspectorView.cpp +++ b/src/Engine/Window/InspectorView.cpp @@ -1,9 +1,16 @@ #include "InspectorView.h" +#include "Window.h" + using namespace Seele; InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo) : View(graphics, window, createInfo) { + renderGraph = new RenderGraph(); + Gfx::PRenderTargetAttachment attachment = new Gfx::SwapchainAttachment(window->getGfxHandle()); + uiPass = new UIPass(renderGraph, graphics, viewport, attachment); + renderGraph->addRenderPass(uiPass); + renderGraph->setup(); } InspectorView::~InspectorView() @@ -12,15 +19,40 @@ InspectorView::~InspectorView() void InspectorView::beginFrame() { - + uiPass->beginFrame(); } void InspectorView::render() { - + uiPass->render(); } void InspectorView::endFrame() +{ + uiPass->endFrame(); +} + +void InspectorView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier) +{ + +} + +void InspectorView::mouseMoveCallback(double xPos, double yPos) +{ + +} + +void InspectorView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) +{ + +} + +void InspectorView::scrollCallback(double xOffset, double yOffset) +{ + +} + +void InspectorView::fileCallback(int count, const char** paths) { } diff --git a/src/Engine/Window/InspectorView.h b/src/Engine/Window/InspectorView.h index fcadef4..64999e9 100644 --- a/src/Engine/Window/InspectorView.h +++ b/src/Engine/Window/InspectorView.h @@ -1,9 +1,11 @@ #pragma once #include "View.h" -#include "UI/UIRenderPath.h" +#include "Graphics/RenderPass/RenderGraph.h" +#include "Graphics/RenderPass/UIPass.h" namespace Seele { +DECLARE_REF(Actor) class InspectorView : public View { public: @@ -12,7 +14,19 @@ public: virtual void beginFrame(); virtual void render(); virtual void endFrame(); - -private: + void selectActor(); + +protected: + Array rootElements; + PUIPass uiPass; + PActor selectedActor; + PRenderGraph renderGraph; + + virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override; + virtual void mouseMoveCallback(double xPos, double yPos) override; + virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override; + virtual void scrollCallback(double xOffset, double yOffset) override; + virtual void fileCallback(int count, const char** paths) override; }; +DEFINE_REF(InspectorView) } // namespace Seele diff --git a/src/Engine/Window/SceneRenderPath.h b/src/Engine/Window/SceneRenderPath.h index c4ee5ec..c42bf40 100644 --- a/src/Engine/Window/SceneRenderPath.h +++ b/src/Engine/Window/SceneRenderPath.h @@ -25,6 +25,5 @@ protected: PDepthPrepass depthPrepass; PLightCullingPass lightCullingPass; PBasePass basePass; - }; } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Window/View.h b/src/Engine/Window/View.h index d0570a0..1007b65 100644 --- a/src/Engine/Window/View.h +++ b/src/Engine/Window/View.h @@ -3,7 +3,7 @@ namespace Seele { DECLARE_REF(Window) -// A view is a part of the window, which can be anything from a viewport to an editor +// A view is a part of the window, which can be anything from a viewport to an inspector class View { public: diff --git a/src/Engine/main.cpp b/src/Engine/main.cpp index 96c590b..935926a 100644 --- a/src/Engine/main.cpp +++ b/src/Engine/main.cpp @@ -1,5 +1,6 @@ #include "Graphics/RenderCore.h" #include "Window/SceneView.h" +#include "Window/InspectorView.h" #include "Asset/AssetRegistry.h" #include "Fibers/Fibers.h" #include @@ -19,12 +20,20 @@ int main() mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM; auto window = core.getWindowManager()->addWindow(mainWindowInfo); ViewportCreateInfo sceneViewInfo; - sceneViewInfo.sizeX = 1280; + sceneViewInfo.sizeX = 640; sceneViewInfo.sizeY = 720; sceneViewInfo.offsetX = 0; sceneViewInfo.offsetY = 0; PSceneView sceneView = new SceneView(core.getWindowManager()->getGraphics(), window, sceneViewInfo); window->addView(sceneView); + + ViewportCreateInfo inspectorViewInfo; + inspectorViewInfo.sizeX = 640; + inspectorViewInfo.sizeY = 720; + inspectorViewInfo.offsetX = 640; + inspectorViewInfo.offsetY = 0; + PInspectorView inspectorView = new InspectorView(core.getWindowManager()->getGraphics(), window, inspectorViewInfo); + window->addView(inspectorView); sceneView->setFocused(); AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject\\"); AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");