Asset bakers now support multiple extensions if necessary
This commit is contained in:
@@ -74,7 +74,7 @@ FileType File::GetFileType() const
|
||||
return FileType::Solution;
|
||||
}
|
||||
|
||||
if (ext == ".mesh")
|
||||
if (ext == ".nkmesh")
|
||||
{
|
||||
return FileType::Mesh;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,25 @@ std::string FileSystem::Root = "";
|
||||
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
Ref<filewatch::FileWatch<std::string>> FileSystem::RootFileWatch;
|
||||
|
||||
void FileSystem::ForeachFile(std::function<void(Ref<File>)> func)
|
||||
{
|
||||
ForeachFile(func, RootDirectory);
|
||||
}
|
||||
|
||||
void FileSystem::ForeachFile(std::function<void(Ref<File>)> func, Ref<Directory> dir)
|
||||
{
|
||||
for(auto& file : RootDirectory->Files)
|
||||
{
|
||||
func(file);
|
||||
}
|
||||
|
||||
for(auto& dir : RootDirectory->Directories)
|
||||
{
|
||||
ForeachFile(func, dir);
|
||||
}
|
||||
}
|
||||
|
||||
void FileSystem::ScanDirectory(Ref<Directory> directory)
|
||||
{
|
||||
directory->Files.clear();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "src/Core/Core.h"
|
||||
#include "FileTypes.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace filewatch
|
||||
{
|
||||
template<typename T>
|
||||
@@ -21,7 +23,13 @@ namespace Nuake
|
||||
static Ref<filewatch::FileWatch<std::string>> RootFileWatch;
|
||||
|
||||
static void SetRootDirectory(const std::string path);
|
||||
|
||||
|
||||
// Starts from root
|
||||
static void ForeachFile(std::function<void(Ref<File>)> func);
|
||||
|
||||
// Strats from specified folder
|
||||
static void ForeachFile(std::function<void(Ref<File>)> func, Ref<Directory> dir);
|
||||
|
||||
static void Scan();
|
||||
static std::string AbsoluteToRelative(const std::string& path);
|
||||
static std::string RelativeToAbsolute(const std::string& path);
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
VkMesh::VkMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
VkMesh::VkMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices) :
|
||||
DescriptorLayout(nullptr)
|
||||
{
|
||||
// First we allocate the buffers on the GPU
|
||||
const size_t vertexBufferSize = vertices.size() * sizeof(Vertex);
|
||||
@@ -55,13 +56,16 @@ void VkMesh::UploadToGPU(const std::vector<Vertex>& vertices, const std::vector<
|
||||
|
||||
void VkMesh::CreateDescriptorSet()
|
||||
{
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
|
||||
auto& vk = VkRenderer::Get();
|
||||
auto device = vk.GetDevice();
|
||||
DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout);
|
||||
|
||||
if (!DescriptorLayout)
|
||||
{
|
||||
DescriptorLayoutBuilder builder;
|
||||
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout);
|
||||
}
|
||||
|
||||
VkDescriptorBufferInfo bufferInfo{};
|
||||
bufferInfo.buffer = GetVertexBuffer()->GetBuffer();
|
||||
|
||||
@@ -80,9 +80,9 @@ void VkRenderer::Initialize()
|
||||
// Init global pool
|
||||
std::vector<DescriptorAllocator::PoolSizeRatio> sizes =
|
||||
{
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 8 },
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 },
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 50 }
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 4096 },
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 4096 },
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024 }
|
||||
};
|
||||
|
||||
GlobalDescriptorAllocator.InitPool(Device, 1000, sizes);
|
||||
@@ -883,5 +883,7 @@ VkDescriptorSet DescriptorAllocator::Allocate(VkDevice device, VkDescriptorSetLa
|
||||
VkDescriptorSet ds;
|
||||
VK_CALL(vkAllocateDescriptorSets(device, &allocInfo, &ds));
|
||||
|
||||
NumAllocation++;
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace Nuake
|
||||
|
||||
struct DescriptorAllocator
|
||||
{
|
||||
uint32_t NumAllocation = 0;
|
||||
struct PoolSizeRatio
|
||||
{
|
||||
VkDescriptorType type;
|
||||
@@ -244,7 +245,7 @@ namespace Nuake
|
||||
|
||||
void EndDraw();
|
||||
|
||||
DescriptorAllocator GetDescriptorAllocator()
|
||||
DescriptorAllocator& GetDescriptorAllocator()
|
||||
{
|
||||
return GlobalDescriptorAllocator;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,11 @@ namespace Nuake
|
||||
|
||||
void RegisterBaker(Ref<IAssetBaker> baker)
|
||||
{
|
||||
Bakers[baker->GetExtension()] = baker;
|
||||
// Latest registered baker overwrites previous
|
||||
for(const auto& extension : baker->GetExtensions())
|
||||
{
|
||||
Bakers[extension] = baker;
|
||||
}
|
||||
}
|
||||
|
||||
Ref<File> Bake(const Ref<File>& file)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Nuake
|
||||
class GLTFBaker : public IAssetBaker
|
||||
{
|
||||
public:
|
||||
GLTFBaker() : IAssetBaker(".glb") {}
|
||||
GLTFBaker() : IAssetBaker({".glb", ".gltf", "fbx"}) {}
|
||||
|
||||
Ref<File> Bake(const Ref<File>& file) override;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/FileSystem/File.h"
|
||||
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
namespace Nuake
|
||||
@@ -10,14 +12,20 @@ namespace Nuake
|
||||
class IAssetBaker
|
||||
{
|
||||
private:
|
||||
std::string Extension;
|
||||
|
||||
std::set<std::string> Extensions;
|
||||
|
||||
public:
|
||||
IAssetBaker(const std::string& extension) : Extension(extension) {}
|
||||
IAssetBaker(const std::string& extension) : Extensions { extension } {}
|
||||
IAssetBaker(std::initializer_list<std::string> extension) : Extensions(extension.begin(), extension.end()) {}
|
||||
virtual ~IAssetBaker() = default;
|
||||
|
||||
std::string GetExtension() const { return Extension; }
|
||||
|
||||
std::set<std::string> GetExtensions() const { return Extensions; }
|
||||
|
||||
inline bool CanBakeFile(const Ref<File>& file) const
|
||||
{
|
||||
return Extensions.find(file->GetExtension()) != Extensions.end();
|
||||
}
|
||||
|
||||
public:
|
||||
virtual Ref<File> Bake(const Ref<File>& file) = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user