Runs on MacOS, tho window size is terrible

This commit is contained in:
Dynamitos
2024-01-24 23:10:33 +01:00
parent cf4a8e9d03
commit 87417f483c
21 changed files with 119 additions and 43 deletions
+1 -1
View File
@@ -233,7 +233,7 @@ int main()
sceneViewInfo.dimensions.size.y = 1080; sceneViewInfo.dimensions.size.y = 1080;
sceneViewInfo.dimensions.offset.x = 0; sceneViewInfo.dimensions.offset.x = 0;
sceneViewInfo.dimensions.offset.y = 0; sceneViewInfo.dimensions.offset.y = 0;
sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_4_BIT; sceneViewInfo.numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT;
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string()); OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
//ViewportCreateInfo inspectorViewInfo; //ViewportCreateInfo inspectorViewInfo;
+5 -2
View File
@@ -9,7 +9,9 @@ target_sources(Engine
Entity.cpp Entity.cpp
Entity.h Entity.h
PointLightActor.cpp PointLightActor.cpp
PointLightActor.h) PointLightActor.h
StaticMeshActor.h
StaticMeshActor.cpp)
target_sources(Engine target_sources(Engine
PUBLIC FILE_SET HEADERS PUBLIC FILE_SET HEADERS
@@ -18,4 +20,5 @@ target_sources(Engine
CameraActor.h CameraActor.h
DirectionalLightActor.h DirectionalLightActor.h
Entity.h Entity.h
PointLightActor.h) PointLightActor.h
StaticMeshActor.h)
+23
View File
@@ -0,0 +1,23 @@
#include "StaticMeshActor.h"
using namespace Seele;
StaticMeshActor::StaticMeshActor(PScene scene, PMeshAsset mesh)
: Actor(scene)
{
attachComponent<Component::Mesh>(mesh);
}
Seele::StaticMeshActor::~StaticMeshActor()
{
}
Component::Mesh &Seele::StaticMeshActor::getMesh()
{
return accessComponent<Component::Mesh>();
}
const Component::Mesh &Seele::StaticMeshActor::getMesh() const
{
return accessComponent<Component::Mesh>();
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "Actor.h"
#include "Component/Mesh.h"
namespace Seele
{
class StaticMeshActor : public Actor
{
public:
StaticMeshActor(PScene scene, PMeshAsset mesh);
virtual ~StaticMeshActor();
Component::Mesh& getMesh();
const Component::Mesh& getMesh() const;
private:
};
} // namespace Seele
-3
View File
@@ -1,8 +1,5 @@
#pragma once #pragma once
#include "Asset/MeshAsset.h" #include "Asset/MeshAsset.h"
#include "Graphics/VertexData.h"
#include "Material/MaterialInstance.h"
#include "Graphics/Mesh.h"
namespace Seele namespace Seele
{ {
+1 -1
View File
@@ -155,7 +155,7 @@ struct RasterizationState
float depthBiasConstantFactor = 0; float depthBiasConstantFactor = 0;
float depthBiasClamp = 0; float depthBiasClamp = 0;
float depthBiasSlopeFactor = 0; float depthBiasSlopeFactor = 0;
float lineWidth = 0; float lineWidth = 1.0;
}; };
struct MultisampleState struct MultisampleState
{ {
+1 -9
View File
@@ -71,7 +71,6 @@ void BasePass::render()
tLightGrid->pipelineBarrier( tLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
colorBuffer->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet; descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet(); descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
@@ -186,14 +185,7 @@ void BasePass::endFrame()
void BasePass::publishOutputs() void BasePass::publishOutputs()
{ {
colorBuffer = graphics->createTexture2D(TextureCreateInfo{ colorAttachment = new Gfx::SwapchainAttachment(viewport, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
.format = viewport->getOwner()->getBackBuffer()->getFormat(),
.width = viewport->getWidth(),
.height = viewport->getHeight(),
.samples = viewport->getSamples(),
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
});
colorAttachment = new Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment); resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
} }
@@ -20,7 +20,6 @@ public:
static void modifyRenderPassMacros(Map<const char*, const char*>& defines); static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
private: private:
Gfx::ORenderTargetAttachment colorAttachment; Gfx::ORenderTargetAttachment colorAttachment;
Gfx::OTexture2D colorBuffer;
Gfx::PTexture2D depthBuffer; Gfx::PTexture2D depthBuffer;
Gfx::PShaderBuffer oLightIndexList; Gfx::PShaderBuffer oLightIndexList;
Gfx::PShaderBuffer tLightIndexList; Gfx::PShaderBuffer tLightIndexList;
@@ -148,26 +148,19 @@ void DepthPrepass::publishOutputs()
.format = Gfx::SE_FORMAT_D32_SFLOAT, .format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(), .width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(), .height = viewport->getOwner()->getFramebufferHeight(),
.samples = viewport->getSamples(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, .usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
}; };
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment = depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f; depthAttachment->clear.depthStencil.depth = 1.0f;
depthBufferInfo.samples = Gfx::SE_SAMPLE_COUNT_1_BIT;
depthResolveBuffer = graphics->createTexture2D(depthBufferInfo);
depthResolveAttachment =
new Gfx::RenderTargetAttachment(depthResolveBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment); resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
resources->registerRenderPassOutput("DEPTHPREPASS_RESOLVED_DEPTH", depthResolveAttachment);
} }
void DepthPrepass::createRenderPass() void DepthPrepass::createRenderPass()
{ {
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{ Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
.depthAttachment = depthAttachment, .depthAttachment = depthAttachment,
.depthResolveAttachment = depthResolveAttachment,
}; };
renderPass = graphics->createRenderPass(std::move(layout), viewport); renderPass = graphics->createRenderPass(std::move(layout), viewport);
} }
@@ -19,9 +19,7 @@ public:
static void modifyRenderPassMacros(Map<const char*, const char*>& defines); static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
private: private:
Gfx::ORenderTargetAttachment depthAttachment; Gfx::ORenderTargetAttachment depthAttachment;
Gfx::ORenderTargetAttachment depthResolveAttachment;
Gfx::OTexture2D depthBuffer; Gfx::OTexture2D depthBuffer;
Gfx::OTexture2D depthResolveBuffer;
Array<Gfx::PDescriptorSet> descriptorSets; Array<Gfx::PDescriptorSet> descriptorSets;
@@ -174,7 +174,7 @@ void LightCullingPass::publishOutputs()
void LightCullingPass::createRenderPass() void LightCullingPass::createRenderPass()
{ {
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_RESOLVED_DEPTH")->getTexture(); depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture();
} }
void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>&) void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>&)
@@ -51,8 +51,6 @@ void SkyboxRenderPass::render()
renderCommand->draw(36, 1, 0, 0); renderCommand->draw(36, 1, 0, 0);
graphics->executeCommands(Array{ renderCommand }); graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass(); graphics->endRenderPass();
baseColorAttachment->getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
graphics->resolveTexture(baseColorAttachment->getTexture(), viewport->getOwner()->getBackBuffer());
} }
void SkyboxRenderPass::endFrame() void SkyboxRenderPass::endFrame()
+44 -6
View File
@@ -15,24 +15,24 @@ public:
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE, SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE, SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE); SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
~RenderTargetAttachment(); virtual ~RenderTargetAttachment();
PTexture2D getTexture() virtual PTexture2D getTexture()
{ {
return texture; return texture;
} }
SeFormat getFormat() const virtual SeFormat getFormat() const
{ {
return texture->getFormat(); return texture->getFormat();
} }
SeSampleCountFlags getNumSamples() const virtual SeSampleCountFlags getNumSamples() const
{ {
return texture->getNumSamples(); return texture->getNumSamples();
} }
uint32 getWidth() const virtual uint32 getWidth() const
{ {
return texture->getWidth(); return texture->getWidth();
} }
uint32 getHeight() const virtual uint32 getHeight() const
{ {
return texture->getHeight(); return texture->getHeight();
} }
@@ -51,6 +51,44 @@ protected:
}; };
DEFINE_REF(RenderTargetAttachment) DEFINE_REF(RenderTargetAttachment)
class SwapchainAttachment : public RenderTargetAttachment
{
public:
SwapchainAttachment(PViewport viewport,
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)
: RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp)
, viewport(viewport)
{}
virtual ~SwapchainAttachment()
{
}
virtual PTexture2D getTexture()
{
return viewport->getOwner()->getBackBuffer();
}
virtual SeFormat getFormat() const
{
return viewport->getOwner()->getSwapchainFormat();
}
virtual SeSampleCountFlags getNumSamples() const
{
return viewport->getSamples();
}
virtual uint32 getWidth() const
{
return viewport->getWidth();
}
virtual uint32 getHeight() const
{
return viewport->getHeight();
}
private:
PViewport viewport;
};
class RenderTargetLayout class RenderTargetLayout
{ {
public: public:
+1
View File
@@ -6,6 +6,7 @@
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Component/Mesh.h" #include "Component/Mesh.h"
#include "Graphics/Shader.h" #include "Graphics/Shader.h"
#include "Graphics/Mesh.h"
#include "Containers/Set.h" #include "Containers/Set.h"
using namespace Seele; using namespace Seele;
+1 -1
View File
@@ -140,7 +140,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
.depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor, .depthBiasConstantFactor = gfxInfo.rasterizationState.depthBiasConstantFactor,
.depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp, .depthBiasClamp = gfxInfo.rasterizationState.depthBiasClamp,
.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor, .depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor,
.lineWidth = 0, .lineWidth = gfxInfo.rasterizationState.lineWidth,
}; };
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash); hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash);
+1 -1
View File
@@ -20,7 +20,7 @@ Semaphore::Semaphore(PGraphics graphics)
Semaphore::~Semaphore() Semaphore::~Semaphore()
{ {
vkDestroySemaphore(graphics->getDevice(), handle, nullptr); graphics->getDestructionManager()->queueSemaphore(graphics->getGraphicsCommands()->getCommands(), handle);
} }
Fence::Fence(PGraphics graphics) Fence::Fence(PGraphics graphics)
+16 -4
View File
@@ -53,7 +53,8 @@ void glfwCloseCallback(GLFWwindow* handle)
Window* window = (Window*)glfwGetWindowUserPointer(handle); Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->close(); window->close();
} }
void glfwResizeCallback(GLFWwindow* handle, int width, int height)
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height)
{ {
Window* window = (Window*)glfwGetWindowUserPointer(handle); Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->resize(width, height); window->resize(width, height);
@@ -69,6 +70,8 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, nullptr, nullptr); GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, nullptr, nullptr);
windowHandle = handle; windowHandle = handle;
glfwSetWindowUserPointer(handle, this); glfwSetWindowUserPointer(handle, this);
int w, h;
glfwGetWindowSize(handle, &w, &h);
glfwSetKeyCallback(handle, &glfwKeyCallback); glfwSetKeyCallback(handle, &glfwKeyCallback);
glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback); glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback);
@@ -76,7 +79,8 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
glfwSetScrollCallback(handle, &glfwScrollCallback); glfwSetScrollCallback(handle, &glfwScrollCallback);
glfwSetDropCallback(handle, &glfwFileCallback); glfwSetDropCallback(handle, &glfwFileCallback);
glfwSetWindowCloseCallback(handle, &glfwCloseCallback); glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
glfwSetWindowSizeCallback(handle, &glfwResizeCallback); glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
//glfwSetWindowSizeCallback(handle, &glfwResizeCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface); glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -104,8 +108,10 @@ void Window::pollInput()
void Window::beginFrame() void Window::beginFrame()
{ {
vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), VK_NULL_HANDLE, &currentImageIndex); imageAvailableFences[currentSemaphoreIndex]->wait(100000);
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); imageAvailableFences[currentSemaphoreIndex]->reset();
vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), imageAvailableFences[currentSemaphoreIndex]->getHandle(), &currentImageIndex);
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, imageAvailableSemaphores[currentSemaphoreIndex]); graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, imageAvailableSemaphores[currentSemaphoreIndex]);
} }
@@ -334,6 +340,12 @@ void Window::createSwapChain()
.samples = 1, .samples = 1,
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSFER_DST_BIT, .usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSFER_DST_BIT,
}, swapChainImages[i]); }, swapChainImages[i]);
if(imageAvailableFences[i] != nullptr)
{
imageAvailableFences[i]->wait(100000);
imageAvailableFences[i]->reset();
}
imageAvailableFences[i] = new Fence(graphics);
imageAvailableSemaphores[i] = new Semaphore(graphics); imageAvailableSemaphores[i] = new Semaphore(graphics);
renderingDoneSemaphores[i] = new Semaphore(graphics); renderingDoneSemaphores[i] = new Semaphore(graphics);
} }
+1
View File
@@ -55,6 +55,7 @@ protected:
void *windowHandle; void *windowHandle;
StaticArray<VkImage, Gfx::numFramesBuffered> swapChainImages; StaticArray<VkImage, Gfx::numFramesBuffered> swapChainImages;
StaticArray<OTexture2D, Gfx::numFramesBuffered> swapChainTextures; StaticArray<OTexture2D, Gfx::numFramesBuffered> swapChainTextures;
StaticArray<OFence, Gfx::numFramesBuffered> imageAvailableFences;
StaticArray<OSemaphore, Gfx::numFramesBuffered> imageAvailableSemaphores; StaticArray<OSemaphore, Gfx::numFramesBuffered> imageAvailableSemaphores;
StaticArray<OSemaphore, Gfx::numFramesBuffered> renderingDoneSemaphores; StaticArray<OSemaphore, Gfx::numFramesBuffered> renderingDoneSemaphores;
uint32 currentImageIndex = 0; uint32 currentImageIndex = 0;
-1
View File
@@ -26,7 +26,6 @@
typedef OwningPtr<x> O##x; \ typedef OwningPtr<x> O##x; \
} }
namespace Seele namespace Seele
{ {
template <typename T> template <typename T>
+6 -1
View File
@@ -5,6 +5,7 @@
#include "Physics/PhysicsSystem.h" #include "Physics/PhysicsSystem.h"
#include "Component/Skybox.h" #include "Component/Skybox.h"
#include "LightEnvironment.h" #include "LightEnvironment.h"
#include <iostream>
namespace Seele namespace Seele
{ {
@@ -18,7 +19,9 @@ public:
void update(float deltaTime); void update(float deltaTime);
entt::entity createEntity() entt::entity createEntity()
{ {
return registry.create(); auto result = registry.create();
std::cout << "Created " << (uint64_t)result << " at " << this << std::endl;
return result;
} }
void destroyEntity(entt::entity identifier) void destroyEntity(entt::entity identifier)
{ {
@@ -27,6 +30,8 @@ public:
template<typename Component, typename... Args> template<typename Component, typename... Args>
Component& attachComponent(entt::entity entity, Args&&... args) Component& attachComponent(entt::entity entity, Args&&... args)
{ {
std::cout << "Emplace " << (uint64_t)entity << std::endl;
std::cout << "Exists " << registry.valid(entity) << std::endl;
return registry.emplace<Component>(entity, std::forward<Args>(args)...); return registry.emplace<Component>(entity, std::forward<Args>(args)...);
} }
template<typename Component> template<typename Component>
+1
View File
@@ -1,5 +1,6 @@
#include "MeshUpdater.h" #include "MeshUpdater.h"
#include "Component/Mesh.h" #include "Component/Mesh.h"
#include "Graphics/Mesh.h"
using namespace Seele; using namespace Seele;
using namespace Seele::System; using namespace Seele::System;