New game interface

This commit is contained in:
Dynamitos
2023-02-01 22:13:04 +01:00
parent 0dce84459e
commit 9e1e4076f0
91 changed files with 268 additions and 21014 deletions
@@ -5,7 +5,6 @@ using namespace Seele;
GameInterface::GameInterface(std::string dllPath)
: dllPath(dllPath)
{
reloadGame();
}
GameInterface::~GameInterface()
@@ -13,7 +12,12 @@ GameInterface::~GameInterface()
}
Game* GameInterface::reloadGame()
Game* GameInterface::getGame()
{
return game;
}
void GameInterface::reload(AssetRegistry* registry)
{
if(lib != NULL)
{
@@ -23,6 +27,5 @@ Game* GameInterface::reloadGame()
lib = LoadLibraryA(dllPath.c_str());
createInstance = (decltype(createInstance))GetProcAddress(lib, "createInstance");
destroyInstance = (decltype(destroyInstance))GetProcAddress(lib, "destroyInstance");
game = createInstance();
return game;
game = createInstance(registry);
}
+3 -2
View File
@@ -9,12 +9,13 @@ class GameInterface
public:
GameInterface(std::string dllPath);
~GameInterface();
Game* reloadGame();
Game* getGame();
void reload(AssetRegistry* registry);
private:
HMODULE lib = NULL;
std::string dllPath;
Game* game;
Game* (*createInstance)() = nullptr;
Game* (*createInstance)(AssetRegistry*) = nullptr;
void (*destroyInstance)(Game*) = nullptr;
};
} // namespace Seele
+7 -1
View File
@@ -3,9 +3,12 @@
#include "Window/Window.h"
#include "Component/KeyboardInput.h"
#include "Actor/CameraActor.h"
#include "Asset/AssetRegistry.h"
using namespace Seele;
AssetRegistry* instance = new AssetRegistry();
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo, "Game")
, gameInterface("C:\\Users\\Dynamitos\\TrackClear\\bin\\TrackCleard.dll")
@@ -20,8 +23,10 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
))
{
scene = new Scene(graphics);
gameInterface.reload(instance);
gameInterface.getGame()->importAssets();
systemGraph = new SystemGraph();
gameInterface.reloadGame()->setupScene(scene, systemGraph);
gameInterface.getGame()->setupScene(scene, systemGraph);
renderGraph.updateViewport(viewport);
}
@@ -52,6 +57,7 @@ void GameView::commitUpdate()
lightCullingData.lightEnv = scene->getLightBuffer();
basePassData.staticDrawList = scene->getStaticMeshes();
basePassData.sceneDataBuffer = scene->getSceneDataBuffer();
skyboxData.skybox = scene->getSkybox();
#ifdef EDITOR
if(showDebug)
{
+1 -1
View File
@@ -46,7 +46,7 @@ private:
dp::thread_pool<> threadPool;
float updateTime = 0;
#ifdef EDITOR
bool showDebug = true;
bool showDebug = false;
#endif
virtual void keyCallback(Seele::KeyCode code, Seele::InputAction action, Seele::KeyModifier modifier) override;
+4 -1
View File
@@ -3,6 +3,7 @@
#include "Actor/Actor.h"
#include "Window/Window.h"
#include "Asset/AssetRegistry.h"
#include "Asset/FontLoader.h"
#include "UI/System.h"
using namespace Seele;
@@ -15,7 +16,9 @@ InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const View
))
, uiSystem(new UI::System())
{
AssetRegistry::importFile("./fonts/Calibri.ttf");
AssetRegistry::importFont(FontImportArgs{
.filePath = "./fonts/Calibri.ttf",
});
renderGraph.updateViewport(viewport);
uiSystem->updateViewport(viewport);
}
+1 -1
View File
@@ -25,7 +25,7 @@ SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreat
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
//AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
cameraSystem.update(viewportCamera, static_cast<float>(Gfx::currentFrameDelta));
+6 -6
View File
@@ -30,12 +30,12 @@ int main()
sceneViewInfo.dimensions.offset.y = 0;
PGameView sceneView = new GameView(graphics, window, sceneViewInfo);
ViewportCreateInfo inspectorViewInfo;
inspectorViewInfo.dimensions.size.x = 640;
inspectorViewInfo.dimensions.size.y = 720;
inspectorViewInfo.dimensions.offset.x = 640;
inspectorViewInfo.dimensions.offset.y = 0;
PInspectorView inspectorView = new InspectorView(graphics, window, inspectorViewInfo);
//ViewportCreateInfo inspectorViewInfo;
//inspectorViewInfo.dimensions.size.x = 640;
//inspectorViewInfo.dimensions.size.y = 720;
//inspectorViewInfo.dimensions.offset.x = 640;
//inspectorViewInfo.dimensions.offset.y = 0;
//PInspectorView inspectorView = new InspectorView(graphics, window, inspectorViewInfo);
//window->addView(inspectorView);
sceneView->setFocused();
+2 -2
View File
@@ -42,12 +42,12 @@ Asset::~Asset()
std::ifstream Asset::getReadStream() const
{
return std::ifstream(fullPath);
return std::ifstream(fullPath, std::ios::binary);
}
std::ofstream Asset::getWriteStream() const
{
return std::ofstream(fullPath);
return std::ofstream(fullPath, std::ios::binary);
}
std::string Asset::getFileName() const
+18 -46
View File
@@ -17,6 +17,8 @@
using namespace Seele;
using json = nlohmann::json;
extern AssetRegistry* instance;
AssetRegistry::~AssetRegistry()
{
}
@@ -26,36 +28,27 @@ void AssetRegistry::init(const std::string& rootFolder, Gfx::PGraphics graphics)
get().initialize(rootFolder, graphics);
}
void AssetRegistry::importFile(const std::string &filePath)
void AssetRegistry::importMesh(MeshImportArgs args)
{
importFile(filePath, "");
get().meshLoader->importAsset(args);
}
void AssetRegistry::importFile(const std::string &filePath, const std::string& importPath)
void AssetRegistry::importTexture(TextureImportArgs args)
{
std::filesystem::path fsPath = std::filesystem::path(filePath);
std::string extension = fsPath.extension().string();
if (extension.compare(".fbx") == 0
|| extension.compare(".obj") == 0
|| extension.compare(".blend") == 0)
{
get().importMesh(fsPath, importPath);
}
if (extension.compare(".png") == 0
|| extension.compare(".jpg") == 0)
{
get().importTexture(fsPath, importPath);
}
if(extension.compare(".ttf") == 0)
{
get().importFont(fsPath, importPath);
}
if (extension.compare(".asset") == 0)
{
get().importMaterial(fsPath, importPath);
}
get().textureLoader->importAsset(args);
}
void AssetRegistry::importFont(FontImportArgs args)
{
get().fontLoader->importAsset(args);
}
void AssetRegistry::importMaterial(MaterialImportArgs args)
{
get().materialLoader->importAsset(args);
}
PMeshAsset AssetRegistry::findMesh(const std::string &filePath)
{
AssetFolder& folder = get().assetRoot;
@@ -125,8 +118,7 @@ std::ifstream AssetRegistry::createReadStream(const std::string& relativePath, s
AssetRegistry &AssetRegistry::get()
{
static AssetRegistry instance;
return instance;
return *instance;
}
AssetRegistry::AssetRegistry()
@@ -148,26 +140,6 @@ std::string AssetRegistry::getRootFolder()
return get().rootFolder.generic_string();
}
void AssetRegistry::importMesh(const std::filesystem::path &filePath, const std::string& importPath)
{
meshLoader->importAsset(filePath, importPath);
}
void AssetRegistry::importTexture(const std::filesystem::path &filePath, const std::string& importPath)
{
textureLoader->importAsset(filePath, importPath);
}
void AssetRegistry::importFont(const std::filesystem::path& filePath, const std::string& importPath)
{
fontLoader->importAsset(filePath, importPath);
}
void AssetRegistry::importMaterial(const std::filesystem::path &filePath, const std::string& importPath)
{
materialLoader->importAsset(filePath, importPath);
}
void AssetRegistry::registerMesh(PMeshAsset mesh, const std::string& importPath)
{
AssetFolder& folder = getOrCreateFolder(importPath);
+8 -8
View File
@@ -15,6 +15,7 @@ DECLARE_REF(FontAsset)
DECLARE_REF(MeshAsset)
DECLARE_REF(MaterialAsset)
DECLARE_NAME_REF(Gfx, Graphics)
class AssetRegistry
{
public:
@@ -23,9 +24,6 @@ public:
static std::string getRootFolder();
static void importFile(const std::string& filePath);
static void importFile(const std::string& filePath, const std::string& importPath);
static PMeshAsset findMesh(const std::string& filePath);
static PTextureAsset findTexture(const std::string& filePath);
static PFontAsset findFont(const std::string& name);
@@ -33,6 +31,13 @@ public:
static std::ofstream createWriteStream(const std::string& relativePath, std::ios_base::openmode openmode = std::ios::out);
static std::ifstream createReadStream(const std::string& relativePath, std::ios_base::openmode openmode = std::ios::in);
static void importMesh(struct MeshImportArgs args);
static void importTexture(struct TextureImportArgs args);
static void importFont(struct FontImportArgs args);
static void importMaterial(struct MaterialImportArgs args);
static void set(AssetRegistry registry);
AssetRegistry();
private:
struct AssetFolder
{
@@ -46,13 +51,8 @@ private:
static AssetRegistry& get();
AssetRegistry();
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);
void importFont(const std::filesystem::path& filePath, const std::string& importPath);
void importMaterial(const std::filesystem::path& filePath, const std::string& importPath);
void registerMesh(PMeshAsset mesh, const std::string& importPath);
void registerTexture(PTextureAsset texture, const std::string& importPath);
-1
View File
@@ -24,7 +24,6 @@ FontAsset::~FontAsset()
void FontAsset::save(Gfx::PGraphics graphics)
{
assert(false && "Cannot save font files");
}
+2 -2
View File
@@ -21,9 +21,9 @@ public:
IVector2 bearing;
uint32 advance;
};
const std::map<uint32, Glyph> getGlyphData() const { return glyphs; }
const Map<uint32, Glyph> getGlyphData() const { return glyphs; }
private:
std::map<uint32, Glyph> glyphs;
Map<uint32, Glyph> glyphs;
friend class FontLoader;
};
DECLARE_REF(FontAsset)
+6 -6
View File
@@ -18,22 +18,22 @@ FontLoader::~FontLoader()
{
}
void FontLoader::importAsset(const std::filesystem::path& filePath, const std::string& importPath)
void FontLoader::importAsset(FontImportArgs args)
{
std::filesystem::path assetPath = filePath.filename();
std::filesystem::path assetPath = args.filePath.filename();
assetPath.replace_extension("asset");
PFontAsset asset = new FontAsset(assetPath.generic_string());
std::error_code code;
std::filesystem::copy_file(filePath, asset->getFullPath(), code);
std::filesystem::copy_file(args.filePath, asset->getFullPath(), code);
asset->setStatus(Asset::Status::Loading);
AssetRegistry::get().registerFont(asset, importPath);
import(filePath, asset);
AssetRegistry::get().registerFont(asset, args.importPath);
import(args, 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)
void FontLoader::import(FontImportArgs args, PFontAsset asset)
{
FT_Library ft;
FT_Error error = FT_Init_FreeType(&ft);
+7 -2
View File
@@ -7,14 +7,19 @@ namespace Seele
{
DECLARE_REF(FontAsset)
DECLARE_NAME_REF(Gfx, Graphics)
struct FontImportArgs
{
std::filesystem::path filePath;
std::string importPath;
};
class FontLoader
{
public:
FontLoader(Gfx::PGraphics graphic);
~FontLoader();
void importAsset(const std::filesystem::path& filePath, const std::string& importPath);
void importAsset(FontImportArgs args);
private:
void import(std::filesystem::path path, PFontAsset asset);
void import(FontImportArgs args, PFontAsset asset);
Gfx::PGraphics graphics;
};
DEFINE_REF(FontLoader)
+10 -7
View File
@@ -15,26 +15,29 @@ using json = nlohmann::json;
MaterialLoader::MaterialLoader(Gfx::PGraphics graphics)
: graphics(graphics)
{
importAsset(std::filesystem::absolute("./shaders/Placeholder.asset"), "");
importAsset(MaterialImportArgs{
.filePath = std::filesystem::absolute("./shaders/Placeholder.asset"),
.importPath = "",
});
}
MaterialLoader::~MaterialLoader()
{
}
void MaterialLoader::importAsset(const std::filesystem::path& name, const std::string& importPath)
void MaterialLoader::importAsset(MaterialImportArgs args)
{
std::filesystem::path assetPath = name.filename();
std::filesystem::path assetPath = args.filePath.filename();
assetPath.replace_extension("asset");
PMaterialAsset asset = new MaterialAsset(assetPath.generic_string());
asset->setStatus(Asset::Status::Loading);
AssetRegistry::get().registerMaterial(asset, importPath);
import(name, asset);
AssetRegistry::get().registerMaterial(asset, args.importPath);
import(args, asset);
}
void MaterialLoader::import(std::filesystem::path name, PMaterialAsset asset)
void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
{
auto stream = std::ifstream(name.c_str());
auto stream = std::ifstream(args.filePath.c_str());
json j;
stream >> j;
std::string materialName = j["name"].get<std::string>() + "Material";
+7 -2
View File
@@ -7,15 +7,20 @@ namespace Seele
{
DECLARE_REF(MaterialAsset)
DECLARE_NAME_REF(Gfx, Graphics)
struct MaterialImportArgs
{
std::filesystem::path filePath;
std::string importPath;
};
class MaterialLoader
{
public:
MaterialLoader(Gfx::PGraphics graphic);
~MaterialLoader();
void importAsset(const std::filesystem::path& name, const std::string& importPath);
void importAsset(MaterialImportArgs args);
PMaterialAsset getPlaceHolderMaterial();
private:
void import(std::filesystem::path filePath, PMaterialAsset asset);
void import(MaterialImportArgs args, PMaterialAsset asset);
Gfx::PGraphics graphics;
PMaterialAsset placeholderMaterial;
};
+19 -11
View File
@@ -15,6 +15,8 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/material.h>
#include <Asset/MaterialLoader.h>
#include <Asset/TextureLoader.h>
using namespace Seele;
@@ -27,14 +29,14 @@ MeshLoader::~MeshLoader()
{
}
void MeshLoader::importAsset(const std::filesystem::path &path, const std::string& importPath)
void MeshLoader::importAsset(MeshImportArgs args)
{
std::filesystem::path assetPath = path.filename();
std::filesystem::path assetPath = args.filePath.filename();
assetPath.replace_extension("asset");
PMeshAsset asset = new MeshAsset(assetPath.generic_string());
asset->setStatus(Asset::Status::Loading);
AssetRegistry::get().registerMesh(asset, importPath);
import(path, asset);
AssetRegistry::get().registerMesh(asset, args.importPath);
import(args, asset);
}
void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterial>& globalMaterials)
@@ -93,7 +95,10 @@ void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterial>& globalMat
outMatFile.close();
std::cout << "writing json to " << outMatFilename << std::endl;
AssetRegistry::importFile(AssetRegistry::getRootFolder() + "/" + outMatFilename);
AssetRegistry::importMaterial(MaterialImportArgs{
.filePath = AssetRegistry::getRootFolder() + "/" + outMatFilename,
.importPath = "",
});
PMaterialAsset asset = AssetRegistry::findMaterial(matCode["name"].get<std::string>());
globalMaterials[i] = asset->getMaterial();
}
@@ -262,15 +267,18 @@ void MeshLoader::loadTextures(const aiScene* scene, const std::filesystem::path&
delete[] texData;
}
std::cout << "Loading model texture " << texPngPath.string() << std::endl;
AssetRegistry::importFile(texPngPath.string());
AssetRegistry::importTexture(TextureImportArgs {
.filePath = texPath,
.importPath = ""
});
}
}
void MeshLoader::import(std::filesystem::path path, PMeshAsset meshAsset)
void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
{
std::cout << "Starting to import "<<path << std::endl;
std::cout << "Starting to import "<<args.filePath<< std::endl;
meshAsset->setStatus(Asset::Status::Loading);
Assimp::Importer importer;
importer.ReadFile(path.string().c_str(), (uint32)(
importer.ReadFile(args.filePath.string().c_str(), (uint32)(
aiProcess_FlipUVs |
aiProcess_Triangulate |
aiProcess_SortByPType |
@@ -281,7 +289,7 @@ void MeshLoader::import(std::filesystem::path path, PMeshAsset meshAsset)
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
Array<PMaterial> globalMaterials(scene->mNumMaterials);
loadTextures(scene, path.parent_path());
loadTextures(scene, args.filePath.parent_path());
loadMaterials(scene, globalMaterials);
Array<PMesh> globalMeshes(scene->mNumMeshes);
@@ -300,5 +308,5 @@ void MeshLoader::import(std::filesystem::path path, PMeshAsset meshAsset)
}
meshAsset->physicsMesh = std::move(collider);
meshAsset->setStatus(Asset::Status::Ready);
std::cout << "Finished loading " << path << std::endl;
std::cout << "Finished loading " << args.filePath<< std::endl;
}
+7 -2
View File
@@ -12,19 +12,24 @@ DECLARE_REF(Mesh)
DECLARE_REF(MeshAsset)
DECLARE_REF(Material)
DECLARE_NAME_REF(Gfx, Graphics)
struct MeshImportArgs
{
std::filesystem::path filePath;
std::string importPath;
};
class MeshLoader
{
public:
MeshLoader(Gfx::PGraphics graphic);
~MeshLoader();
void importAsset(const std::filesystem::path& filePath, const std::string& importPath);
void importAsset(MeshImportArgs args);
private:
void loadMaterials(const aiScene* scene, Array<PMaterial>& globalMaterials);
void loadTextures(const aiScene* scene, const std::filesystem::path& meshPath);
void loadGlobalMeshes(const aiScene* scene, const Array<PMaterial>& materials, Array<PMesh>& globalMeshes, Component::Collider& collider);
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
void import(std::filesystem::path path, PMeshAsset meshAsset);
void import(MeshImportArgs args, PMeshAsset meshAsset);
Gfx::PGraphics graphics;
};
DEFINE_REF(MeshLoader)
+15 -15
View File
@@ -23,15 +23,15 @@ TextureLoader::~TextureLoader()
{
}
void TextureLoader::importAsset(const std::filesystem::path& path, const std::string& importPath)
void TextureLoader::importAsset(TextureImportArgs args)
{
std::filesystem::path assetPath = path.filename();
std::filesystem::path assetPath = args.filePath.filename();
assetPath.replace_extension("asset");
PTextureAsset asset = new TextureAsset(assetPath.generic_string());
asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderAsset->getTexture());
AssetRegistry::get().registerTexture(asset, importPath);
import(path, asset);
AssetRegistry::get().registerTexture(asset, args.importPath);
import(args, asset);
}
PTextureAsset TextureLoader::getPlaceholderTexture()
@@ -39,14 +39,14 @@ PTextureAsset TextureLoader::getPlaceholderTexture()
return placeholderAsset;
}
void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset)
void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
{
int totalWidth, totalHeight, n;
unsigned char* data = stbi_load(path.string().c_str(), &totalWidth, &totalHeight, &n, 4);
unsigned char* data = stbi_load(args.filePath.string().c_str(), &totalWidth, &totalHeight, &n, 4);
ktxTexture2* kTexture;
ktxTextureCreateInfo createInfo;
if (totalWidth / 4 == totalHeight / 3)
if (args.type == TextureImportType::TEXTURE_CUBEMAP)
{
uint32 faceWidth = totalWidth / 4;
uint32 faceHeight = totalHeight / 3;
@@ -56,7 +56,7 @@ void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsse
createInfo.baseHeight = totalHeight / 3;
createInfo.baseDepth = 1;
createInfo.numFaces = 6;
createInfo.numDimensions = 3;
createInfo.numDimensions = 2;
createInfo.numLevels = 1;
createInfo.numLayers = 1;
createInfo.isArray = false;
@@ -66,7 +66,7 @@ void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsse
KTX_TEXTURE_CREATE_ALLOC_STORAGE,
&kTexture);
auto loadCubeFace = [kTexture, faceWidth, totalWidth, data](int xPos, int yPos, int faceName)
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)
@@ -81,12 +81,12 @@ void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsse
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);
loadCubeFace(2, 1, 0); // +X
loadCubeFace(0, 1, 1); // -X
loadCubeFace(1, 0, 2); // +Y
loadCubeFace(1, 2, 3); // -Y
loadCubeFace(1, 1, 4); // -Z
loadCubeFace(3, 1, 5); // -Z
}
else
{
+13 -2
View File
@@ -8,15 +8,26 @@ namespace Seele
DECLARE_REF(TextureAsset)
DECLARE_NAME_REF(Gfx, Graphics)
DECLARE_NAME_REF(Gfx, Texture2D)
enum class TextureImportType
{
TEXTURE_2D,
TEXTURE_CUBEMAP,
};
struct TextureImportArgs
{
std::filesystem::path filePath;
std::string importPath;
TextureImportType type = TextureImportType::TEXTURE_2D;
};
class TextureLoader
{
public:
TextureLoader(Gfx::PGraphics graphic);
~TextureLoader();
void importAsset(const std::filesystem::path& filePath, const std::string& importPath);
void importAsset(TextureImportArgs args);
PTextureAsset getPlaceholderTexture();
private:
void import(std::filesystem::path path, PTextureAsset asset);
void import(TextureImportArgs args, PTextureAsset asset);
Gfx::PGraphics graphics;
PTextureAsset placeholderAsset;
};
-1
View File
@@ -9,7 +9,6 @@ struct Skybox
{
Gfx::PTextureCube day;
Gfx::PTextureCube night;
Gfx::PSamplerState sampler;
Vector fogColor;
float blendFactor;
};
+1 -2
View File
@@ -364,7 +364,6 @@ public:
{
return _size;
}
private:
void verifyTree()
{
@@ -441,7 +440,7 @@ private:
return Iterator(endIndex, &nodeContainer, std::move(endTraversal));
}
Array<Node, NodeAlloc> nodeContainer;
Array<Node, NodeAlloc> nodeContainer = Array<Node, NodeAlloc>();
size_t root;
Iterator beginIt;
Iterator endIt;
+3 -1
View File
@@ -1,14 +1,16 @@
#pragma once
#include "Scene/Scene.h"
#include "System/SystemGraph.h"
#include "Asset/AssetRegistry.h"
namespace Seele
{
class Game
{
public:
Game() {}
Game(AssetRegistry* registry) {}
virtual ~Game() {}
virtual void importAssets() = 0;
virtual void setupScene(PScene scene, PSystemGraph graph) = 0;
};
} // namespace Seele
+2
View File
@@ -547,6 +547,8 @@ public:
virtual uint32 getMipLevels() const = 0;
virtual void changeLayout(SeImageLayout newLayout) = 0;
virtual class Texture2D* getTexture2D() { return nullptr; }
virtual class Texture3D* getTexture3D() { return nullptr; }
virtual class TextureCube* getTextureCube() { return nullptr; }
virtual void* getNativeHandle() { return nullptr; }
protected:
// Inherited via QueueOwnedResource
@@ -8,58 +8,58 @@ SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics)
{
Array<Vector> vertices = {
// Back
Vector(-1, -1, -1),
Vector(1, -1, -1),
Vector(-1, 1, -1),
Vector(-512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, -512, 512),
Vector(1, -1, -1),
Vector(-1, 1, -1),
Vector(1, 1, -1),
Vector( 512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, 512, 512),
// Front
Vector(1, -1, 1),
Vector(-1, 1, 1),
Vector(-1, -1, 1),
Vector( 512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, -512, -512),
Vector(-1, 1, 1),
Vector(1, 1, 1),
Vector(1, -1, 1),
Vector(-512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, 512, -512),
// Top
Vector(-1, -1, -1),
Vector(1, -1, -1),
Vector(1, -1, 1),
Vector(-512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, -512),
Vector(1, -1, -1),
Vector(1, -1, 1),
Vector(1, -1, 1),
Vector( 512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, 512),
// Bottom
Vector(-1, 1, -1),
Vector(-1, 1, 1),
Vector(1, 1, -1),
Vector(-512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, 512),
Vector(1, 1, -1),
Vector(-1, 1, 1),
Vector(1, 1, 1),
Vector( 512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, -512),
// Left
Vector(-1, -1, -1),
Vector(-1, -1, 1),
Vector(-1, 1, -1),
Vector(-512, -512, -512),
Vector(-512, 512, -512),
Vector(-512, -512, 512),
Vector(-1, 1, -1),
Vector(-1, -1, 1),
Vector(-1, 1, 1),
Vector(-512, -512, 512),
Vector(-512, 512, -512),
Vector(-512, 512, 512),
// Right
Vector(1, -1, 1),
Vector(1, 1, -1),
Vector(1, -1, -1),
Vector( 512, -512, 512),
Vector( 512, 512, 512),
Vector( 512, -512, -512),
Vector(1, -1, 1),
Vector(1, 1, 1),
Vector(1, 1, -1),
Vector( 512, -512, -512),
Vector( 512, 512, 512),
Vector( 512, 512, -512),
};
VertexBufferCreateInfo vertexBufferInfo = {
@@ -93,7 +93,7 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
descriptorSet->updateBuffer(0, viewParamsBuffer);
descriptorSet->updateTexture(1, passData.skybox.day);
descriptorSet->updateTexture(2, passData.skybox.night);
descriptorSet->updateSampler(3, passData.skybox.sampler);
descriptorSet->updateSampler(3, skyboxSampler);
descriptorSet->writeChanges();
}
@@ -105,8 +105,8 @@ void SkyboxRenderPass::render()
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->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(Vector), &passData.skybox.fogColor);
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, sizeof(Vector), sizeof(float), &passData.skybox.blendFactor);
renderCommand->draw(36, 1, 0, 0);
graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass();
@@ -138,17 +138,14 @@ void SkyboxRenderPass::publishOutputs()
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.stageFlags = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
.size = sizeof(Vector),
});
pipelineLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
.offset = sizeof(Vector),
.size = sizeof(float),
.size = sizeof(Vector4),
});
pipelineLayout->create();
skyboxSampler = graphics->createSamplerState({});
}
void SkyboxRenderPass::createRenderPass()
@@ -29,6 +29,7 @@ private:
Gfx::PDescriptorSet descriptorSet;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::PSamplerState skyboxSampler;
};
DEFINE_REF(SkyboxRenderPass)
} // namespace Seele
@@ -258,6 +258,7 @@ private:
uint32 sizeY;
uint32 sizeZ;
uint32 arrayCount;
uint32 layerCount;
uint32 mipLevels;
uint32 samples;
Gfx::SeFormat format;
+15 -4
View File
@@ -37,6 +37,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
, sizeY(createInfo.height)
, sizeZ(createInfo.depth)
, arrayCount(createInfo.bArray ? createInfo.arrayLayers : 1)
, layerCount(1)
, mipLevels(createInfo.mipLevels)
, samples(createInfo.samples)
, format(createInfo.format)
@@ -53,10 +54,8 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
info.extent.width = sizeX;
info.extent.height = sizeY;
info.extent.depth = sizeZ;
info.arrayLayers = arrayCount;
info.format = cast(format);
uint32 layerCount = 1;
switch (viewType)
{
case VK_IMAGE_VIEW_TYPE_1D:
@@ -72,6 +71,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
break;
case VK_IMAGE_VIEW_TYPE_CUBE:
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
info.imageType = VK_IMAGE_TYPE_2D;
layerCount = 6 * arrayCount;
break;
@@ -127,7 +127,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageSubresource.layerCount = layerCount;
region.imageOffset = {0, 0, 0};
region.imageExtent = {sizeX, sizeY, sizeZ};
@@ -153,7 +153,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType,
viewInfo.viewType = viewType;
viewInfo.image = image;
viewInfo.format = cast(format);
viewInfo.subresourceRange.layerCount = (viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY || viewType == VK_IMAGE_VIEW_TYPE_CUBE) ? 6 : 1;
viewInfo.subresourceRange.layerCount = layerCount;
viewInfo.subresourceRange.levelCount = mipLevels;
VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &defaultView));
@@ -181,6 +181,16 @@ TextureHandle* TextureBase::cast(Gfx::PTexture texture)
PTexture2D texture2D = texture.cast<Texture2D>();
return texture2D->textureHandle;
}
if(texture->getTexture3D() != nullptr)
{
PTexture3D texture3D = texture.cast<Texture3D>();
return texture3D->textureHandle;
}
if(texture->getTextureCube() != nullptr)
{
PTextureCube textureCube = texture.cast<TextureCube>();
return textureCube->textureHandle;
}
return nullptr;
}
@@ -193,6 +203,7 @@ void TextureHandle::changeLayout(Gfx::SeImageLayout newLayout)
cast(newLayout));
barrier.subresourceRange =
init::ImageSubresourceRange(aspect);
barrier.subresourceRange.layerCount = layerCount;
PCommandBufferManager cmdManager = graphics->getQueueCommands(currentOwner);
vkCmdPipelineBarrier(cmdManager->getCommands()->getHandle(),
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
+1 -1
View File
@@ -72,7 +72,7 @@ static inline Vector toRotator(const Quaternion &other)
const float yawX = (1.f - 2.f * (square(other.y) + square(other.z)));
const float SINGULARITY_THRESHOLD = 0.4999995f;
const float RAD_TO_DEG = (180.f) / glm::pi<float>();
constexpr const float RAD_TO_DEG = (180.f) / glm::pi<float>();
Vector rotatorFromQuat;
if (singularityTest < -SINGULARITY_THRESHOLD)
+12
View File
@@ -3,6 +3,8 @@
#include "Graphics/Mesh.h"
#include "Component/StaticMesh.h"
#include "Component/Transform.h"
#include "Asset/AssetRegistry.h"
#include "Asset/TextureAsset.h"
using namespace Seele;
@@ -88,4 +90,14 @@ LightEnv Scene::getLightBuffer() const
result.numDirectionalLights = 1;
result.numPointLights = 0;
return result;
}
Component::Skybox Scene::getSkybox()
{
return Seele::Component::Skybox {
.day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(),
.night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(),
.fogColor = Vector(0.2, 0.1, 0.6),
.blendFactor = 0,
};
}
+2
View File
@@ -4,6 +4,7 @@
#include "Graphics/Graphics.h"
#include "Graphics/MeshBatch.h"
#include "Physics/PhysicsSystem.h"
#include "Component/Skybox.h"
namespace Seele
{
@@ -70,6 +71,7 @@ public:
}
Array<StaticMeshBatch> getStaticMeshes();
LightEnv getLightBuffer() const;
Component::Skybox getSkybox();
Gfx::PStructuredBuffer getSceneDataBuffer() const { return sceneDataBuffer; }
Gfx::PGraphics getGraphics() const { return graphics; }
entt::registry registry;
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include "Array.h"
namespace Seele
{
class ArchiveBuffer
{
public:
private:
Array<uint8> memory;
};
} // namespace Seele
+9
View File
@@ -0,0 +1,9 @@
target_sources(Engine
PRIVATE
ArchiveBuffer.h)
target_sources(Engine
PUBLIC FILE_SET HEADERS
FILES
ArchiveBuffer.h)