Implemented basic game dll interaction

This commit is contained in:
Dynamitos
2023-01-29 18:58:59 +01:00
parent 2208ab438a
commit 0dce84459e
72 changed files with 1297 additions and 350 deletions
+3 -2
View File
@@ -3,6 +3,7 @@
namespace Seele
{
DECLARE_NAME_REF(Gfx, Graphics)
class Asset
{
public:
@@ -17,8 +18,8 @@ public:
Asset(const std::filesystem::path& path);
virtual ~Asset();
virtual void save() = 0;
virtual void load() = 0;
virtual void save(Gfx::PGraphics graphics) = 0;
virtual void load(Gfx::PGraphics graphics) = 0;
// returns the name of the file, without extension
std::string getFileName() const;
+9 -9
View File
@@ -21,9 +21,9 @@ AssetRegistry::~AssetRegistry()
{
}
void AssetRegistry::init(const std::string& rootFolder)
void AssetRegistry::init(const std::string& rootFolder, Gfx::PGraphics graphics)
{
get().init(rootFolder, WindowManager::getGraphics());
get().initialize(rootFolder, graphics);
}
void AssetRegistry::importFile(const std::string &filePath)
@@ -133,14 +133,14 @@ AssetRegistry::AssetRegistry()
{
}
void AssetRegistry::init(const std::filesystem::path &_rootFolder, Gfx::PGraphics graphics)
void AssetRegistry::initialize(const std::filesystem::path &_rootFolder, Gfx::PGraphics _graphics)
{
AssetRegistry &reg = get();
reg.rootFolder = _rootFolder;
reg.fontLoader = new FontLoader(graphics);
reg.meshLoader = new MeshLoader(graphics);
reg.textureLoader = new TextureLoader(graphics);
reg.materialLoader = new MaterialLoader(graphics);
this->graphics = _graphics;
this->rootFolder = _rootFolder;
this->fontLoader = new FontLoader(graphics);
this->meshLoader = new MeshLoader(graphics);
this->textureLoader = new TextureLoader(graphics);
this->materialLoader = new MaterialLoader(graphics);
}
std::string AssetRegistry::getRootFolder()
+3 -2
View File
@@ -19,7 +19,7 @@ class AssetRegistry
{
public:
~AssetRegistry();
static void init(const std::string& rootFolder);
static void init(const std::string& rootFolder, Gfx::PGraphics graphics);
static std::string getRootFolder();
@@ -47,7 +47,7 @@ private:
static AssetRegistry& get();
AssetRegistry();
void init(const std::filesystem::path& rootFolder, Gfx::PGraphics graphics);
void initialize(const std::filesystem::path& rootFolder, Gfx::PGraphics graphics);
void importMesh(const std::filesystem::path& filePath, const std::string& importPath);
void importTexture(const std::filesystem::path& filePath, const std::string& importPath);
@@ -66,6 +66,7 @@ private:
std::filesystem::path rootFolder;
AssetFolder assetRoot;
Gfx::PGraphics graphics;
UPTextureLoader textureLoader;
UPFontLoader fontLoader;
UPMeshLoader meshLoader;
+3 -49
View File
@@ -1,8 +1,5 @@
#include "FontAsset.h"
#include "Graphics/GraphicsResources.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include "Window/WindowManager.h"
#include "Graphics/Graphics.h"
using namespace Seele;
@@ -25,55 +22,12 @@ FontAsset::~FontAsset()
}
void FontAsset::save()
void FontAsset::save(Gfx::PGraphics graphics)
{
assert(false && "Cannot save font files");
}
// in case of the space character there is no bitmap
// so we create a single pixel empty texture
uint8 transparentPixel = 0;
void FontAsset::load()
void FontAsset::load(Gfx::PGraphics graphics)
{
FT_Library ft;
FT_Error error = FT_Init_FreeType(&ft);
assert(!error);
FT_Face face;
error = FT_New_Face(ft, getFullPath().c_str(), 0, &face);
assert(!error);
FT_Set_Pixel_Sizes(face, 0, 48);
for(uint32 c = 0; c < 256; ++c)
{
Gfx::PGraphics graphics = WindowManager::getGraphics();
if(FT_Load_Char(face, c, FT_LOAD_RENDER))
{
std::cout << "error loading " << (char)c << std::endl;
continue;
}
Glyph& glyph = glyphs[c];
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
glyph.advance = face->glyph->advance.x;
TextureCreateInfo imageData;
imageData.format = Gfx::SE_FORMAT_R8_UINT;
imageData.width = face->glyph->bitmap.width;
imageData.height = face->glyph->bitmap.rows;
imageData.resourceData.data = face->glyph->bitmap.buffer;
imageData.resourceData.size = imageData.width * imageData.height;
if(imageData.width == 0 || imageData.width == 0)
{
glyph.size.x = 1;
glyph.size.y = 1;
glyph.bearing.x = 0;
glyph.bearing.y = 0;
imageData.width = 1;
imageData.height = 1;
imageData.resourceData.size = sizeof(uint8);
imageData.resourceData.data = &transparentPixel;
}
glyph.texture = graphics->createTexture2D(imageData);
}
FT_Done_Face(face);
FT_Done_FreeType(ft);
}
+3 -2
View File
@@ -11,8 +11,8 @@ public:
FontAsset(const std::string& directory, const std::string& name);
FontAsset(const std::filesystem::path& fullPath);
virtual ~FontAsset();
virtual void save() override;
virtual void load() override;
virtual void save(Gfx::PGraphics graphics) override;
virtual void load(Gfx::PGraphics graphics) override;
struct Glyph
{
@@ -24,6 +24,7 @@ public:
const std::map<uint32, Glyph> getGlyphData() const { return glyphs; }
private:
std::map<uint32, Glyph> glyphs;
friend class FontLoader;
};
DECLARE_REF(FontAsset)
} // namespace Seele
+46 -1
View File
@@ -2,6 +2,9 @@
#include "Graphics/Graphics.h"
#include "FontAsset.h"
#include "AssetRegistry.h"
#include "Graphics/GraphicsResources.h"
#include <ft2build.h>
#include FT_FREETYPE_H
using namespace Seele;
@@ -27,7 +30,49 @@ void FontLoader::importAsset(const std::filesystem::path& filePath, const std::s
import(filePath, asset);
}
// in case of the space character there is no bitmap
// so we create a single pixel empty texture
uint8 transparentPixel = 0;
void FontLoader::import(std::filesystem::path path, PFontAsset asset)
{
asset->load();
FT_Library ft;
FT_Error error = FT_Init_FreeType(&ft);
assert(!error);
FT_Face face;
error = FT_New_Face(ft, asset->getFullPath().c_str(), 0, &face);
assert(!error);
FT_Set_Pixel_Sizes(face, 0, 48);
for(uint32 c = 0; c < 256; ++c)
{
if(FT_Load_Char(face, c, FT_LOAD_RENDER))
{
std::cout << "error loading " << (char)c << std::endl;
continue;
}
FontAsset::Glyph& glyph = asset->glyphs[c];
glyph.size = IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
glyph.bearing = IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
glyph.advance = face->glyph->advance.x;
TextureCreateInfo imageData;
imageData.format = Gfx::SE_FORMAT_R8_UINT;
imageData.width = face->glyph->bitmap.width;
imageData.height = face->glyph->bitmap.rows;
imageData.resourceData.data = face->glyph->bitmap.buffer;
imageData.resourceData.size = imageData.width * imageData.height;
if(imageData.width == 0 || imageData.width == 0)
{
glyph.size.x = 1;
glyph.size.y = 1;
glyph.bearing.x = 0;
glyph.bearing.y = 0;
imageData.width = 1;
imageData.height = 1;
imageData.resourceData.size = sizeof(uint8);
imageData.resourceData.data = &transparentPixel;
}
glyph.texture = graphics->createTexture2D(imageData);
}
FT_Done_Face(face);
FT_Done_FreeType(ft);
asset->setStatus(Asset::Status::Ready);
}
+3 -10
View File
@@ -1,5 +1,6 @@
#include "MaterialAsset.h"
#include "Material/Material.h"
#include "Graphics/Graphics.h"
using namespace Seele;
@@ -22,20 +23,12 @@ MaterialAsset::~MaterialAsset()
}
void MaterialAsset::save()
void MaterialAsset::save(Gfx::PGraphics graphics)
{
}
void MaterialAsset::load()
void MaterialAsset::load(Gfx::PGraphics graphics)
{
}
void MaterialAsset::beginFrame()
{
}
void MaterialAsset::endFrame()
{
}
+2 -4
View File
@@ -11,10 +11,8 @@ public:
MaterialAsset(const std::string &directory, const std::string &name);
MaterialAsset(const std::filesystem::path &fullPath);
virtual ~MaterialAsset();
virtual void beginFrame();
virtual void endFrame();
virtual void save() override;
virtual void load() override;
virtual void save(Gfx::PGraphics graphics) override;
virtual void load(Gfx::PGraphics graphics) override;
PMaterial getMaterial() const { return material; }
private:
PMaterial material;
+3 -2
View File
@@ -1,6 +1,7 @@
#include "MaterialInstanceAsset.h"
#include "Material/MaterialInstance.h"
#include "Material/Material.h"
#include "Graphics/Graphics.h"
using namespace Seele;
@@ -23,10 +24,10 @@ MaterialInstanceAsset::~MaterialInstanceAsset()
}
void MaterialInstanceAsset::save()
void MaterialInstanceAsset::save(Gfx::PGraphics graphics)
{
}
void MaterialInstanceAsset::load()
void MaterialInstanceAsset::load(Gfx::PGraphics graphics)
{
}
+2 -4
View File
@@ -11,10 +11,8 @@ public:
MaterialInstanceAsset(const std::string &directory, const std::string &name);
MaterialInstanceAsset(const std::filesystem::path &fullPath);
virtual ~MaterialInstanceAsset();
virtual void beginFrame();
virtual void endFrame();
virtual void save() override;
virtual void load() override;
virtual void save(Gfx::PGraphics graphics) override;
virtual void load(Gfx::PGraphics graphics) override;
private:
PMaterialInstance material;
};
+3 -2
View File
@@ -38,7 +38,7 @@ void MaterialLoader::import(std::filesystem::path name, PMaterialAsset asset)
json j;
stream >> j;
std::string materialName = j["name"].get<std::string>() + "Material";
Gfx::PDescriptorLayout layout = WindowManager::getGraphics()->createDescriptorLayout(materialName + "Layout");
Gfx::PDescriptorLayout layout = graphics->createDescriptorLayout(materialName + "Layout");
//Shader file needs to conform to the slang standard, which prohibits _
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end());
@@ -111,7 +111,7 @@ void MaterialLoader::import(std::filesystem::path name, PMaterialAsset asset)
{
PSamplerParameter p = new SamplerParameter(param.key(), 0, bindingCounter);
layout->addDescriptorBinding(bindingCounter++, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
p->data = WindowManager::getGraphics()->createSamplerState({});
p->data = graphics->createSamplerState({});
parameters.add(p);
}
else
@@ -128,6 +128,7 @@ void MaterialLoader::import(std::filesystem::path name, PMaterialAsset asset)
codeStream.close();
layout->create();
asset->material = new Material(
graphics,
std::move(parameters),
std::move(layout),
uniformDataSize,
+3 -2
View File
@@ -1,4 +1,5 @@
#include "MeshAsset.h"
#include "Graphics/Graphics.h"
#include "Graphics/Mesh.h"
#include "Graphics/VertexShaderInput.h"
#include "Material/MaterialInterface.h"
@@ -21,10 +22,10 @@ MeshAsset::~MeshAsset()
{
}
void MeshAsset::save()
void MeshAsset::save(Gfx::PGraphics graphics)
{
}
void MeshAsset::load()
void MeshAsset::load(Gfx::PGraphics graphics)
{
}
+2 -2
View File
@@ -13,8 +13,8 @@ public:
MeshAsset(const std::string& directory, const std::string& name);
MeshAsset(const std::filesystem::path& fullPath);
virtual ~MeshAsset();
virtual void save() override;
virtual void load() override;
virtual void save(Gfx::PGraphics graphics) override;
virtual void load(Gfx::PGraphics graphics) override;
void addMesh(PMesh mesh);
const Array<PMesh> getMeshes();
//Workaround while no editor
+1 -2
View File
@@ -259,7 +259,7 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
unsigned char* texData = new unsigned char[tex->mWidth * tex->mHeight * 4];
convertAssimpARGB(texData, tex->pcData, tex->mWidth * tex->mHeight);
stbi_write_png(texPngPath.string().c_str(), tex->mWidth, tex->mHeight, 4, tex->pcData, tex->mWidth * 32);
delete texData;
delete[] texData;
}
std::cout << "Loading model texture " << texPngPath.string() << std::endl;
AssetRegistry::importFile(texPngPath.string());
@@ -300,6 +300,5 @@ void MeshLoader::import(std::filesystem::path path, PMeshAsset meshAsset)
}
meshAsset->physicsMesh = std::move(collider);
meshAsset->setStatus(Asset::Status::Ready);
meshAsset->save();
std::cout << "Finished loading " << path << std::endl;
}
+17 -4
View File
@@ -25,13 +25,13 @@ TextureAsset::~TextureAsset()
}
void TextureAsset::save()
void TextureAsset::save(Gfx::PGraphics graphics)
{
//TODO: make this an actual file, not just a png wrapper
assert(false && "Editing textures is not yet supported");
}
void TextureAsset::load()
void TextureAsset::load(Gfx::PGraphics graphics)
{
setStatus(Status::Loading);
ktxTexture2* kTexture;
@@ -40,19 +40,32 @@ void TextureAsset::load()
ktxTexture2_CreateFromNamedFile(getFullPath().c_str(),
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
&kTexture);
TextureCreateInfo createInfo;
createInfo.width = kTexture->baseWidth;
createInfo.height = kTexture->baseHeight;
createInfo.depth = kTexture->baseDepth;
createInfo.bArray = kTexture->isArray;
createInfo.arrayLayers = kTexture->numLayers;
createInfo.arrayLayers = kTexture->isArray ? kTexture->numLayers : kTexture->numFaces;
createInfo.format = Vulkan::cast((VkFormat)kTexture->vkFormat);
createInfo.mipLevels = kTexture->numLevels;
createInfo.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
createInfo.resourceData.data = ktxTexture_GetData(ktxTexture(kTexture));
createInfo.resourceData.size = ktxTexture_GetDataSize(ktxTexture(kTexture));
createInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
Gfx::PTexture2D tex = WindowManager::getGraphics()->createTexture2D(createInfo);
Gfx::PTexture tex;
if (kTexture->isCubemap)
{
tex = graphics->createTextureCube(createInfo);
}
else if (kTexture->isArray)
{
tex = graphics->createTexture3D(createInfo);
}
else
{
tex = graphics->createTexture2D(createInfo);
}
tex->transferOwnership(Gfx::QueueType::GRAPHICS);
setTexture(tex);
setStatus(Asset::Status::Ready);
+2 -2
View File
@@ -11,8 +11,8 @@ public:
TextureAsset(const std::string& directory, const std::string& name);
TextureAsset(const std::filesystem::path& fullPath);
virtual ~TextureAsset();
virtual void save() override;
virtual void load() override;
virtual void save(Gfx::PGraphics graphics) override;
virtual void load(Gfx::PGraphics graphics) override;
void setTexture(Gfx::PTexture _texture)
{
std::scoped_lock lck(lock);
+64 -19
View File
@@ -15,7 +15,7 @@ TextureLoader::TextureLoader(Gfx::PGraphics graphics)
: graphics(graphics)
{
placeholderAsset = new TextureAsset(std::filesystem::absolute("./textures/placeholder.ktx"));
placeholderAsset->load();
placeholderAsset->load(graphics);
AssetRegistry::get().assetRoot.textures[""] = placeholderAsset;
}
@@ -41,35 +41,80 @@ PTextureAsset TextureLoader::getPlaceholderTexture()
void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset)
{
int x, y, n;
unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4);
int totalWidth, totalHeight, n;
unsigned char* data = stbi_load(path.string().c_str(), &totalWidth, &totalHeight, &n, 4);
ktxTexture2* kTexture;
ktxTextureCreateInfo createInfo;
createInfo.vkFormat = VK_FORMAT_R8G8B8A8_SRGB;
createInfo.baseWidth = x;
createInfo.baseHeight = y;
createInfo.baseDepth = 1;
createInfo.numDimensions = 1 + (y > 1);
createInfo.numLevels = 1;
createInfo.numLayers = 1;
createInfo.numFaces = 1;
createInfo.isArray = false;
createInfo.generateMipmaps = true;
if (totalWidth / 4 == totalHeight / 3)
{
uint32 faceWidth = totalWidth / 4;
uint32 faceHeight = totalHeight / 3;
// Cube map
createInfo.vkFormat = VK_FORMAT_R8G8B8A8_SRGB;
createInfo.baseWidth = totalWidth / 4;
createInfo.baseHeight = totalHeight / 3;
createInfo.baseDepth = 1;
createInfo.numFaces = 6;
createInfo.numDimensions = 3;
createInfo.numLevels = 1;
createInfo.numLayers = 1;
createInfo.isArray = false;
createInfo.generateMipmaps = true;
ktxTexture2_Create(&createInfo,
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&kTexture);
ktxTexture2_Create(&createInfo,
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&kTexture);
ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
0, 0, 0, data, x * y * 4 * sizeof(unsigned char));
auto loadCubeFace = [kTexture, faceWidth, totalWidth, data](int xPos, int yPos, int faceName)
{
std::vector<unsigned char> vec(faceWidth * faceWidth * 4);
for (int y = 0; y < faceWidth; ++y)
{
for (int x = 0; x < faceWidth; ++x)
{
int imgX = x + (xPos * faceWidth);
int imgY = y + (yPos * faceWidth);
std::memcpy(&vec[(x + (faceWidth * y)) * 4], &data[(imgX + (totalWidth * imgY)) * 4], 4);
}
}
ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
0, 0, faceName, vec.data(), vec.size());
};
loadCubeFace(1, 0, 0);
loadCubeFace(0, 1, 1);
loadCubeFace(1, 1, 2);
loadCubeFace(2, 1, 3);
loadCubeFace(3, 1, 4);
loadCubeFace(1, 2, 5);
}
else
{
createInfo.vkFormat = VK_FORMAT_R8G8B8A8_SRGB;
createInfo.baseWidth = totalWidth;
createInfo.baseHeight = totalHeight;
createInfo.baseDepth = 1;
createInfo.numDimensions = 1 + (totalHeight > 1);
createInfo.numLevels = 1;
createInfo.numLayers = 1;
createInfo.numFaces = 1;
createInfo.isArray = false;
createInfo.generateMipmaps = true;
ktxTexture2_Create(&createInfo,
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&kTexture);
ktxTexture_SetImageFromMemory(ktxTexture(kTexture),
0, 0, 0, data, totalWidth * totalHeight * 4 * sizeof(unsigned char));
}
stbi_image_free(data);
ktxTexture_WriteToNamedFile(ktxTexture(kTexture), textureAsset->getFullPath().c_str());
ktxTexture_Destroy(ktxTexture(kTexture));
textureAsset->load();
textureAsset->load(graphics);
textureAsset->setStatus(Asset::Status::Ready);
////co_return;
}
+2
View File
@@ -1,12 +1,14 @@
target_sources(Engine
PRIVATE
EngineTypes.h
Game.h
MinimalEngine.h
MinimalEngine.cpp)
target_sources(Engine
PUBLIC FILE_SET HEADERS
FILES
Game.h
EngineTypes.h
MinimalEngine.h)
+6 -2
View File
@@ -4,13 +4,15 @@ target_sources(Engine
BoxCollider.h
Camera.h
Camera.cpp
Component.h
Collider.h
Collider.cpp
Component.h
KeyboardInput.h
MeshCollider.h
RigidBody.h
ShapeBase.h
ShapeBase.cpp
Skybox.h
SphereCollider.h
StaticMesh.h
Transform.h
@@ -22,11 +24,13 @@ target_sources(Engine
AABB.h
BoxCollider.h
Camera.h
Component.h
Collider.h
Component.h
KeyboardInput.h
MeshCollider.h
RigidBody.h
ShapeBase.h
Skybox.h
SphereCollider.h
StaticMesh.h
Transform.h)
+1
View File
@@ -34,6 +34,7 @@ struct Camera
//Transforms relative to actor
float yaw;
float pitch;
bool mainCamera = true;
private:
bool bNeedsViewBuild;
};
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "Graphics/GraphicsResources.h"
namespace Seele
{
namespace Component
{
struct KeyboardInput
{
Seele::StaticArray<bool, static_cast<size_t>(Seele::KeyCode::KEY_LAST)> keys;
bool mouse1;
bool mouse2;
float mouseX;
float mouseY;
};
} // namespace Component
} // namespace Seele
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "Graphics/GraphicsResources.h"
namespace Seele
{
namespace Component
{
struct Skybox
{
Gfx::PTextureCube day;
Gfx::PTextureCube night;
Gfx::PSamplerState sampler;
Vector fogColor;
float blendFactor;
};
} // namespace Component
} // namespace Seele
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include "Scene/Scene.h"
#include "System/SystemGraph.h"
namespace Seele
{
class Game
{
public:
Game() {}
virtual ~Game() {}
virtual void setupScene(PScene scene, PSystemGraph graph) = 0;
};
} // namespace Seele
+1 -1
View File
@@ -25,4 +25,4 @@ PVertexBuffer Graphics::getNullVertexBuffer()
nullVertexBuffer = createVertexBuffer(createInfo);
}
return nullVertexBuffer;
}
}
+2
View File
@@ -37,6 +37,8 @@ public:
virtual void executeCommands(const Array<PComputeCommand>& commands) = 0;
virtual PTexture2D createTexture2D(const TextureCreateInfo &createInfo) = 0;
virtual PTexture3D createTexture3D(const TextureCreateInfo &createInfo) = 0;
virtual PTextureCube createTextureCube(const TextureCreateInfo &createInfo) = 0;
virtual PUniformBuffer createUniformBuffer(const UniformBufferCreateInfo &bulkData) = 0;
virtual PStructuredBuffer createStructuredBuffer(const StructuredBufferCreateInfo &bulkData) = 0;
virtual PVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) = 0;
+18
View File
@@ -434,6 +434,24 @@ Texture2D::~Texture2D()
{
}
Texture3D::Texture3D(QueueFamilyMapping mapping, Gfx::QueueType startQueueType)
: Texture(mapping, startQueueType)
{
}
Texture3D::~Texture3D()
{
}
TextureCube::TextureCube(QueueFamilyMapping mapping, Gfx::QueueType startQueueType)
: Texture(mapping, startQueueType)
{
}
TextureCube::~TextureCube()
{
}
RenderCommand::RenderCommand()
{
}
+48 -1
View File
@@ -45,7 +45,7 @@ DEFINE_REF(VertexShader)
class ControlShader
{
public:
ControlShader() {}
ControlShader() : numPatchPoints(0) {}
virtual ~ControlShader() {}
uint32 getNumPatches() const { return numPatchPoints; }
@@ -555,6 +555,7 @@ protected:
SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
};
DEFINE_REF(Texture)
class Texture2D : public Texture
{
public:
@@ -577,6 +578,50 @@ protected:
};
DEFINE_REF(Texture2D)
class Texture3D : public Texture
{
public:
Texture3D(QueueFamilyMapping mapping, QueueType startQueueType);
virtual ~Texture3D();
virtual SeFormat getFormat() const = 0;
virtual uint32 getSizeX() const = 0;
virtual uint32 getSizeY() const = 0;
virtual uint32 getSizeZ() const = 0;
virtual SeSampleCountFlags getNumSamples() const = 0;
virtual uint32 getMipLevels() const = 0;
virtual void changeLayout(SeImageLayout newLayout) = 0;
virtual class Texture3D* getTexture3D() { return this; }
protected:
//Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage,
SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
};
DEFINE_REF(Texture3D)
class TextureCube : public Texture
{
public:
TextureCube(QueueFamilyMapping mapping, QueueType startQueueType);
virtual ~TextureCube();
virtual SeFormat getFormat() const = 0;
virtual uint32 getSizeX() const = 0;
virtual uint32 getSizeY() const = 0;
virtual uint32 getSizeZ() const = 0;
virtual SeSampleCountFlags getNumSamples() const = 0;
virtual uint32 getMipLevels() const = 0;
virtual void changeLayout(SeImageLayout newLayout) = 0;
virtual class TextureCube* getTextureCube() { return this; }
protected:
//Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage,
SeAccessFlags dstAccess, SePipelineStageFlags dstStage) = 0;
};
DEFINE_REF(TextureCube)
DECLARE_REF(Viewport)
class RenderCommand
{
@@ -684,6 +729,8 @@ public:
, stencilLoadOp(stencilLoadOp)
, stencilStoreOp(stencilStoreOp)
, texture(texture)
, clear()
, componentFlags(0)
{
}
virtual ~RenderTargetAttachment()
@@ -14,6 +14,8 @@ target_sources(Engine
RenderGraphResources.h
RenderGraphResources.cpp
RenderPass.h
SkyboxRenderPass.h
SkyboxRenderPass.cpp
TextPass.h
TextPass.cpp
UIPass.h
@@ -30,5 +32,6 @@ target_sources(Engine
RenderGraph.h
RenderGraphResources.h
RenderPass.h
SkyboxRenderPass.h
TextPass.h
UIPass.h)
@@ -0,0 +1,194 @@
#include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h"
using namespace Seele;
SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
{
Array<Vector> vertices = {
// Back
Vector(-1, -1, -1),
Vector(1, -1, -1),
Vector(-1, 1, -1),
Vector(1, -1, -1),
Vector(-1, 1, -1),
Vector(1, 1, -1),
// Front
Vector(1, -1, 1),
Vector(-1, 1, 1),
Vector(-1, -1, 1),
Vector(-1, 1, 1),
Vector(1, 1, 1),
Vector(1, -1, 1),
// Top
Vector(-1, -1, -1),
Vector(1, -1, -1),
Vector(1, -1, 1),
Vector(1, -1, -1),
Vector(1, -1, 1),
Vector(1, -1, 1),
// Bottom
Vector(-1, 1, -1),
Vector(-1, 1, 1),
Vector(1, 1, -1),
Vector(1, 1, -1),
Vector(-1, 1, 1),
Vector(1, 1, 1),
// Left
Vector(-1, -1, -1),
Vector(-1, -1, 1),
Vector(-1, 1, -1),
Vector(-1, 1, -1),
Vector(-1, -1, 1),
Vector(-1, 1, 1),
// Right
Vector(1, -1, 1),
Vector(1, 1, -1),
Vector(1, -1, -1),
Vector(1, -1, 1),
Vector(1, 1, 1),
Vector(1, 1, -1),
};
VertexBufferCreateInfo vertexBufferInfo = {
.resourceData = {
.size = sizeof(Vector) * vertices.size(),
.data = (uint8*)vertices.data(),
},
.vertexSize = sizeof(Vector),
.numVertices = (uint32)vertices.size(),
};
cubeBuffer = graphics->createVertexBuffer(vertexBufferInfo);
}
SkyboxRenderPass::~SkyboxRenderPass()
{
}
void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
{
BulkResourceData uniformUpdate;
viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = viewport->getProjectionMatrix();
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 0);
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams;
viewParamsBuffer->updateContents(uniformUpdate);
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, viewParamsBuffer);
descriptorSet->updateTexture(1, passData.skybox.day);
descriptorSet->updateTexture(2, passData.skybox.night);
descriptorSet->updateSampler(3, passData.skybox.sampler);
descriptorSet->writeChanges();
}
void SkyboxRenderPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(descriptorSet);
renderCommand->bindVertexBuffer({ VertexInputStream(0, 0, cubeBuffer) });
renderCommand->pushConstants(pipelineLayout, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, sizeof(Vector), &passData.skybox.fogColor);
renderCommand->pushConstants(pipelineLayout, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, sizeof(Vector), sizeof(float), &passData.skybox.blendFactor);
renderCommand->draw(36, 1, 0, 0);
graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass();
}
void SkyboxRenderPass::endFrame()
{
}
void SkyboxRenderPass::publishOutputs()
{
UniformBufferCreateInfo viewCreateInfo = {
.resourceData = BulkResourceData {
.size = sizeof(ViewParameter),
.data = nullptr,
},
.bDynamic = true
};
viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
descriptorLayout = graphics->createDescriptorLayout("SkyboxDescLayout");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
descriptorLayout->create();
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.offset = 0,
.size = sizeof(Vector),
});
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.offset = sizeof(Vector),
.size = sizeof(float),
});
pipelineLayout->create();
}
void SkyboxRenderPass::createRenderPass()
{
Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
ShaderCreateInfo createInfo;
createInfo.name = "SkyboxVertex";
createInfo.mainModule = "Skybox";
createInfo.entryPoint = "vertexMain";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "SkyboxFragment";
createInfo.entryPoint = "fragmentMain";
Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
Gfx::VertexElement {
.streamIndex = 0,
.offset = 0,
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(Vector),
}
});
GraphicsPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = vertexDecl;
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
gfxInfo.rasterizationState.lineWidth = 5.f;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
gfxInfo.pipelineLayout = pipelineLayout;
gfxInfo.renderPass = renderPass;
pipeline = graphics->createGraphicsPipeline(gfxInfo);
}
@@ -0,0 +1,34 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
#include "Component/Skybox.h"
namespace Seele
{
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
struct SkyboxPassData
{
Component::Skybox skybox;
};
class SkyboxRenderPass : public RenderPass<SkyboxPassData>
{
public:
SkyboxRenderPass(Gfx::PGraphics graphics);
virtual ~SkyboxRenderPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
Gfx::PVertexBuffer cubeBuffer;
Gfx::PUniformBuffer viewParamsBuffer;
Gfx::PDescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
};
DEFINE_REF(SkyboxRenderPass)
} // namespace Seele
@@ -116,6 +116,18 @@ Gfx::PTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
return result;
}
Gfx::PTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
{
PTexture3D result = new Texture3D(this, createInfo);
return result;
}
Gfx::PTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
{
PTextureCube result = new TextureCube(this, createInfo);
return result;
}
Gfx::PUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
{
PUniformBuffer uniformBuffer = new UniformBuffer(this, bulkData);
@@ -45,6 +45,8 @@ public:
virtual void executeCommands(const Array<Gfx::PComputeCommand>& commands) override;
virtual Gfx::PTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
virtual Gfx::PTexture3D createTexture3D(const TextureCreateInfo &createInfo) override;
virtual Gfx::PTextureCube createTextureCube(const TextureCreateInfo &createInfo) override;
virtual Gfx::PUniformBuffer createUniformBuffer(const UniformBufferCreateInfo &bulkData) override;
virtual Gfx::PStructuredBuffer createStructuredBuffer(const StructuredBufferCreateInfo &bulkData) override;
virtual Gfx::PVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
@@ -268,6 +268,8 @@ private:
Gfx::SeImageLayout layout;
friend class TextureBase;
friend class Texture2D;
friend class Texture3D;
friend class TextureCube;
friend class Graphics;
};
@@ -336,6 +338,116 @@ protected:
};
DEFINE_REF(Texture2D)
class Texture3D : public Gfx::Texture3D, public TextureBase
{
public:
Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
virtual ~Texture3D();
virtual uint32 getSizeX() const override
{
return textureHandle->sizeX;
}
virtual uint32 getSizeY() const override
{
return textureHandle->sizeY;
}
virtual uint32 getSizeZ() const override
{
return textureHandle->sizeZ;
}
virtual Gfx::SeFormat getFormat() const override
{
return textureHandle->format;
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
return textureHandle->getNumSamples();
}
virtual uint32 getMipLevels() const override
{
return textureHandle->getMipLevels();
}
virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void* getNativeHandle() override
{
return textureHandle;
}
inline VkImage getHandle() const
{
return textureHandle->image;
}
inline VkImageView getView() const
{
return textureHandle->defaultView;
}
inline bool isDepthStencil() const
{
return textureHandle->isDepthStencil();
}
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
};
DEFINE_REF(Texture3D)
class TextureCube : public Gfx::TextureCube, public TextureBase
{
public:
TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage = VK_NULL_HANDLE);
virtual ~TextureCube();
virtual uint32 getSizeX() const override
{
return textureHandle->sizeX;
}
virtual uint32 getSizeY() const override
{
return textureHandle->sizeY;
}
virtual uint32 getSizeZ() const override
{
return textureHandle->sizeZ;
}
virtual Gfx::SeFormat getFormat() const override
{
return textureHandle->format;
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
return textureHandle->getNumSamples();
}
virtual uint32 getMipLevels() const override
{
return textureHandle->getMipLevels();
}
virtual void changeLayout(Gfx::SeImageLayout newLayout) override;
virtual void* getNativeHandle() override
{
return textureHandle;
}
inline VkImage getHandle() const
{
return textureHandle->image;
}
inline VkImageView getView() const
{
return textureHandle->defaultView;
}
inline bool isDepthStencil() const
{
return textureHandle->isDepthStencil();
}
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner);
virtual void executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage);
};
DEFINE_REF(TextureCube)
class SamplerState : public Gfx::SamplerState
{
public:
+55 -1
View File
@@ -305,4 +305,58 @@ void Texture2D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageF
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
}
Texture3D::Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage)
: Gfx::Texture3D(graphics->getFamilyMapping(), createInfo.resourceData.owner)
{
textureHandle = new TextureHandle(graphics, VK_IMAGE_VIEW_TYPE_3D,
createInfo, currentOwner, existingImage);
}
Texture3D::~Texture3D()
{
}
void Texture3D::changeLayout(Gfx::SeImageLayout newLayout)
{
textureHandle->changeLayout(newLayout);
}
void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
textureHandle->executeOwnershipBarrier(newOwner);
}
void Texture3D::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
TextureCube::TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo, VkImage existingImage)
: Gfx::TextureCube(graphics->getFamilyMapping(), createInfo.resourceData.owner)
{
textureHandle = new TextureHandle(graphics, createInfo.bArray ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE,
createInfo, currentOwner, existingImage);
}
TextureCube::~TextureCube()
{
}
void TextureCube::changeLayout(Gfx::SeImageLayout newLayout)
{
textureHandle->changeLayout(newLayout);
}
void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
textureHandle->executeOwnershipBarrier(newOwner);
}
void TextureCube::executePipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlags srcStage,
VkAccessFlags dstAccess, VkPipelineStageFlags dstStage)
{
textureHandle->executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
+5 -3
View File
@@ -1,14 +1,16 @@
#include "Material.h"
#include "Window/WindowManager.h"
#include "MaterialInstance.h"
#include "Graphics/VertexShaderInput.h"
#include "Graphics/Graphics.h"
using namespace Seele;
Gfx::ShaderMap Material::shaderMap;
std::mutex Material::shaderMapLock;
Material::Material(Array<PShaderParameter> parameter, Gfx::PDescriptorLayout layout, uint32 uniformDataSize, uint32 uniformBinding, std::string materialName)
: MaterialInterface(parameter, uniformDataSize, uniformBinding)
Material::Material(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, Gfx::PDescriptorLayout layout, uint32 uniformDataSize, uint32 uniformBinding, std::string materialName)
: MaterialInterface(graphics, parameter, uniformDataSize, uniformBinding)
, layout(layout)
, materialName(materialName)
{
@@ -40,7 +42,7 @@ Gfx::PDescriptorSet Material::createDescriptorSet()
PMaterialInstance Material::instantiate()
{
return new MaterialInstance(this);
return new MaterialInstance(graphics, this);
}
const Gfx::ShaderCollection* Material::getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const
+1 -1
View File
@@ -7,7 +7,7 @@ DECLARE_REF(MaterialInstance)
class Material : public MaterialInterface
{
public:
Material(Array<PShaderParameter> parameter, Gfx::PDescriptorLayout layout, uint32 uniformDataSize, uint32 uniformBinding, std::string materialName);
Material(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, Gfx::PDescriptorLayout layout, uint32 uniformDataSize, uint32 uniformBinding, std::string materialName);
virtual ~Material();
virtual Gfx::PDescriptorSet createDescriptorSet();
virtual Gfx::PDescriptorLayout getDescriptorLayout() const { return layout; }
+2 -2
View File
@@ -4,8 +4,8 @@
using namespace Seele;
MaterialInstance::MaterialInstance(PMaterial baseMaterial)
: MaterialInterface(baseMaterial->parameters, baseMaterial->uniformDataSize, baseMaterial->uniformBinding)
MaterialInstance::MaterialInstance(Gfx::PGraphics graphics, PMaterial baseMaterial)
: MaterialInterface(graphics, baseMaterial->parameters, baseMaterial->uniformDataSize, baseMaterial->uniformBinding)
, baseMaterial(baseMaterial)
{
}
+1 -1
View File
@@ -7,7 +7,7 @@ DECLARE_REF(Material)
class MaterialInstance : public MaterialInterface
{
public:
MaterialInstance(PMaterial baseMaterial);
MaterialInstance(Gfx::PGraphics graphics, PMaterial baseMaterial);
virtual ~MaterialInstance();
virtual Gfx::PDescriptorSet createDescriptorSet();
virtual Gfx::PDescriptorLayout getDescriptorLayout() const;
+4 -3
View File
@@ -4,8 +4,9 @@
using namespace Seele;
MaterialInterface::MaterialInterface(Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding)
: parameters(parameter)
MaterialInterface::MaterialInterface(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding)
: graphics(graphics)
, parameters(parameter)
, uniformDataSize(uniformDataSize)
, uniformBinding(uniformBinding)
{
@@ -18,7 +19,7 @@ MaterialInterface::MaterialInterface(Array<PShaderParameter> parameter, uint32 u
.data = nullptr,
}
};
uniformBuffer = WindowManager::getGraphics()->createUniformBuffer(uniformInitializer);
uniformBuffer = graphics->createUniformBuffer(uniformInitializer);
}
}
+2 -1
View File
@@ -9,7 +9,7 @@ DECLARE_NAME_REF(Gfx, UniformBuffer)
class MaterialInterface
{
public:
MaterialInterface(Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding);
MaterialInterface(Gfx::PGraphics graphics, Array<PShaderParameter> parameter, uint32 uniformDataSize, uint32 uniformBinding);
virtual ~MaterialInterface();
PShaderParameter getParameter(const std::string& name);
virtual Gfx::PDescriptorSet createDescriptorSet() = 0;
@@ -20,6 +20,7 @@ public:
virtual const Gfx::ShaderCollection* getShaders(Gfx::RenderPassType renderPass, VertexInputType* vertexInput) const = 0;
virtual Gfx::ShaderCollection& createShaders(Gfx::PGraphics graphics, Gfx::RenderPassType renderPass, VertexInputType* vertexInput) = 0;
protected:
Gfx::PGraphics graphics;
//For now its simply the collection of parameters, since there is no point for expressions
Array<PShaderParameter> parameters;
Gfx::PUniformBuffer uniformBuffer;
+7 -2
View File
@@ -1,7 +1,7 @@
#pragma once
#include <entt/entt.hpp>
#include "MinimalEngine.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Graphics.h"
#include "Graphics/MeshBatch.h"
#include "Physics/PhysicsSystem.h"
@@ -63,10 +63,15 @@ public:
{
return registry.get<Component>(entity);
}
template<typename Component, typename Func>
void view(Func func) requires std::is_invocable_v<Func, Component&>
{
registry.view<Component>().each(func);
}
Array<StaticMeshBatch> getStaticMeshes();
LightEnv getLightBuffer() const;
Gfx::PStructuredBuffer getSceneDataBuffer() const { return sceneDataBuffer; }
Gfx::PGraphics getGraphics() const { return graphics; }
entt::registry registry;
private:
struct PrimitiveSceneData
+7 -2
View File
@@ -1,11 +1,16 @@
target_sources(Engine
PRIVATE
ComponentSystem.h
Executor.h
Executor.cpp
SystemBase.h)
SystemBase.h
SystemGraph.h
SystemGraph.cpp)
target_sources(Engine
PUBLIC FILE_SET HEADERS
FILES
ComponentSystem.h
Executor.h
SystemBase.h)
SystemBase.h
SystemGraph.h)
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include "SystemBase.h"
#include "Component/Component.h"
namespace Seele
{
namespace System
{
template<typename... Components>
class ComponentSystem : public SystemBase
{
public:
ComponentSystem(PScene scene) : SystemBase(scene) {}
virtual ~ComponentSystem() {}
template<is_component Comp>
auto getDependencies()
{
return Comp::dependencies;
}
template<typename Comp>
Dependencies<> getDependencies()
{
return Dependencies<>();
}
template<typename... Dep>
auto mergeDependencies(Dep... deps)
{
return (deps | ...);
}
template<typename... Deps>
void setupView(Dependencies<Deps...>, dp::thread_pool<>&)
{
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
//pool.enqueue_detach([&](){
(accessComponent(deps) + ...);
update((comp,...));
//});
});
}
template<>
void setupView(Dependencies<>, dp::thread_pool<>&)
{
registry.view<Components...>().each([&](Components&... comp){
//pool.enqueue_detach([&](){
update(comp...);
//});
});
}
virtual void run(dp::thread_pool<>& pool, double delta) override
{
SystemBase::run(pool, delta);
setupView(mergeDependencies((getDependencies<Components>(),...)), pool);
}
virtual void update(Components&... components) = 0;
};
} // namespace System
} // namespace Seele
+10 -45
View File
@@ -1,63 +1,28 @@
#pragma once
#include <entt/entt.hpp>
#include <thread_pool/thread_pool.h>
#include "Component/Component.h"
#include <entt/entt.hpp>
#include "Scene/Scene.h"
namespace Seele
{
namespace System
{
template<typename... Components>
class SystemBase
class SystemBase
{
public:
SystemBase(entt::registry& registry) : registry(registry) {}
SystemBase(PScene scene) : registry(scene->registry), scene(scene) {}
virtual ~SystemBase() {}
template<is_component Comp>
auto getDependencies()
{
return Comp::dependencies;
}
template<typename Comp>
Dependencies<> getDependencies()
{
return Dependencies<>();
}
template<typename... Dep>
auto mergeDependencies(Dep... deps)
{
return (deps | ...);
}
template<typename... Deps>
void setupView(Dependencies<Deps...>, dp::thread_pool<>&)
{
registry.view<Components..., Deps...>().each([&](Components&... comp, Deps&... deps){
//pool.enqueue_detach([&](){
(accessComponent(deps) + ...);
update((comp,...));
//});
});
}
template<>
void setupView(Dependencies<>, dp::thread_pool<>&)
{
registry.view<Components...>().each([&](Components&... comp){
//pool.enqueue_detach([&](){
update(comp...);
//});
});
}
void run(dp::thread_pool<>& pool, double delta)
virtual void run(dp::thread_pool<>& pool, double delta)
{
deltaTime = delta;
setupView(mergeDependencies((getDependencies<Components>(),...)), pool);
update();
}
virtual void update(Components&... components) = 0;
virtual void update() {}
protected:
double deltaTime;
private:
entt::registry& registry;
PScene scene;
};
DEFINE_REF(SystemBase)
} // namespace System
} // namespace Seele
} // namespace Seele
+15
View File
@@ -0,0 +1,15 @@
#include "SystemGraph.h"
using namespace Seele;
void SystemGraph::addSystem(System::UPSystemBase system)
{
systems.add(std::move(system));
}
void SystemGraph::run(dp::thread_pool<>& threadPool, float deltaTime)
{
for(auto& system : systems) {
system->run(threadPool, deltaTime);
}
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "Containers/Array.h"
#include "SystemBase.h"
namespace Seele
{
class SystemGraph
{
public:
void addSystem(System::UPSystemBase system);
void run(dp::thread_pool<>& threadPool, float deltaTime);
private:
Array<System::UPSystemBase> systems;
};
DEFINE_REF(SystemGraph)
} // namespace Seele;
+2
View File
@@ -10,6 +10,8 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi
, name(name)
{
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
owner->addView(this);
setFocused();
}
View::~View()
+2 -7
View File
@@ -1,22 +1,17 @@
#include "WindowManager.h"
#include "Graphics/Vulkan/VulkanGraphics.h"
#include "Graphics/Graphics.h"
using namespace Seele;
Gfx::PGraphics WindowManager::graphics;
WindowManager::WindowManager()
{
graphics = new Vulkan::Graphics();
GraphicsInitializer initializer;
graphics->init(initializer);
}
WindowManager::~WindowManager()
{
}
PWindow WindowManager::addWindow(const WindowCreateInfo &createInfo)
PWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo)
{
Gfx::PWindow handle = graphics->createWindow(createInfo);
PWindow window = new Window(this, handle);
+2 -8
View File
@@ -1,22 +1,17 @@
#pragma once
#include "Graphics/GraphicsResources.h"
#include "Graphics/Graphics.h"
#include "Containers/Array.h"
#include "Window.h"
namespace Seele
{
DECLARE_NAME_REF(Gfx, Graphics)
class WindowManager
{
public:
WindowManager();
~WindowManager();
PWindow addWindow(const WindowCreateInfo &createInfo);
PWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo);
void notifyWindowClosed(PWindow window);
static Gfx::PGraphics getGraphics()
{
return graphics;
}
inline bool isActive() const
{
return windows.size();
@@ -24,7 +19,6 @@ public:
private:
Array<PWindow> windows;
static Gfx::PGraphics graphics;
};
DEFINE_REF(WindowManager)
} // namespace Seele