Implementing ECS SystemBase and updating slang
This commit is contained in:
@@ -31,10 +31,10 @@ public:
|
||||
std::scoped_lock lck(lock);
|
||||
return status;
|
||||
}
|
||||
inline void setStatus(Status status)
|
||||
inline void setStatus(Status _status)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
this->status = status;
|
||||
status = _status;
|
||||
}
|
||||
protected:
|
||||
std::mutex lock;
|
||||
|
||||
@@ -91,10 +91,10 @@ AssetRegistry::AssetRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
void AssetRegistry::init(const std::filesystem::path &rootFolder, Gfx::PGraphics graphics)
|
||||
void AssetRegistry::init(const std::filesystem::path &_rootFolder, Gfx::PGraphics graphics)
|
||||
{
|
||||
AssetRegistry ® = get();
|
||||
reg.rootFolder = rootFolder;
|
||||
reg.rootFolder = _rootFolder;
|
||||
reg.fontLoader = new FontLoader(graphics);
|
||||
reg.meshLoader = new MeshLoader(graphics);
|
||||
reg.textureLoader = new TextureLoader(graphics);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Asset.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ void FontAsset::load()
|
||||
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.size = Math::IVector2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||
glyph.bearing = Math::IVector2(face->glyph->bitmap_left, face->glyph->bitmap_top);
|
||||
glyph.advance = face->glyph->advance.x;
|
||||
TextureCreateInfo imageData;
|
||||
imageData.format = Gfx::SE_FORMAT_R8_UINT;
|
||||
|
||||
@@ -17,8 +17,8 @@ public:
|
||||
struct Glyph
|
||||
{
|
||||
Gfx::PTexture2D texture;
|
||||
IVector2 size;
|
||||
IVector2 bearing;
|
||||
Math::IVector2 size;
|
||||
Math::IVector2 bearing;
|
||||
uint32 advance;
|
||||
};
|
||||
const std::map<uint32, Glyph> getGlyphData() const { return glyphs; }
|
||||
|
||||
@@ -36,7 +36,7 @@ void MeshLoader::importAsset(const std::filesystem::path &path)
|
||||
import(path, asset);
|
||||
}
|
||||
|
||||
void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics)
|
||||
void MeshLoader::loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials)
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
for(uint32 i = 0; i < scene->mNumMaterials; ++i)
|
||||
@@ -111,44 +111,44 @@ void findMeshRoots(aiNode *node, List<aiNode *> &meshNodes)
|
||||
}
|
||||
VertexStreamComponent createVertexStream(uint32 size, aiVector3D* sourceData, Gfx::PGraphics graphics)
|
||||
{
|
||||
Array<Vector> buffer(size);
|
||||
Array<Math::Vector> buffer(size);
|
||||
for(uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = Vector(sourceData[i].x, sourceData[i].y, sourceData[i].z);
|
||||
buffer[i] = Math::Vector(sourceData[i].x, sourceData[i].y, sourceData[i].z);
|
||||
}
|
||||
VertexBufferCreateInfo vbInfo;
|
||||
vbInfo.numVertices = size;
|
||||
vbInfo.vertexSize = sizeof(Vector);
|
||||
vbInfo.vertexSize = sizeof(Math::Vector);
|
||||
vbInfo.resourceData.data = (uint8 *)buffer.data();
|
||||
vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||
vbInfo.resourceData.size = sizeof(Vector) * (uint32)buffer.size();
|
||||
vbInfo.resourceData.size = sizeof(Math::Vector) * buffer.size();
|
||||
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo);
|
||||
vertexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32B32_SFLOAT);
|
||||
}
|
||||
VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gfx::PGraphics graphics)
|
||||
{
|
||||
Array<Vector2> buffer(size);
|
||||
Array<Math::Vector2> buffer(size);
|
||||
for(uint32 i = 0; i < size; ++i)
|
||||
{
|
||||
buffer[i] = Vector2(sourceData[i].x, sourceData[i].y);
|
||||
buffer[i] = Math::Vector2(sourceData[i].x, sourceData[i].y);
|
||||
}
|
||||
VertexBufferCreateInfo vbInfo;
|
||||
vbInfo.numVertices = size;
|
||||
vbInfo.vertexSize = sizeof(Vector2);
|
||||
vbInfo.vertexSize = sizeof(Math::Vector2);
|
||||
vbInfo.resourceData.data = (uint8 *)buffer.data();
|
||||
vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||
vbInfo.resourceData.size = sizeof(Vector2) * (uint32)buffer.size();
|
||||
vbInfo.resourceData.size = sizeof(Math::Vector2) * buffer.size();
|
||||
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo);
|
||||
vertexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
|
||||
}
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics)
|
||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials)
|
||||
{
|
||||
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex)
|
||||
{
|
||||
aiMesh *mesh = scene->mMeshes[meshIndex];
|
||||
|
||||
PMaterialAsset material = materials[mesh->mMaterialIndex];
|
||||
PStaticMeshVertexInput vertexShaderInput = new StaticMeshVertexInput(std::string(mesh->mName.C_Str()));
|
||||
StaticMeshDataType data;
|
||||
data.positionStream = createVertexStream(mesh->mNumVertices, mesh->mVertices, graphics);
|
||||
@@ -188,7 +188,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMesh
|
||||
idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32;
|
||||
idxInfo.resourceData.data = (uint8 *)indices.data();
|
||||
idxInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||
idxInfo.resourceData.size = sizeof(uint32) * (uint32)indices.size();
|
||||
idxInfo.resourceData.size = sizeof(uint32) * indices.size();
|
||||
Gfx::PIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo);
|
||||
indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
|
||||
@@ -249,10 +249,10 @@ void MeshLoader::import(std::filesystem::path path, PMeshAsset meshAsset)
|
||||
|
||||
Array<PMaterialAsset> globalMaterials(scene->mNumMaterials);
|
||||
loadTextures(scene, path.parent_path());
|
||||
loadMaterials(scene, globalMaterials, graphics);
|
||||
loadMaterials(scene, globalMaterials);
|
||||
|
||||
Array<PMesh> globalMeshes(scene->mNumMeshes);
|
||||
loadGlobalMeshes(scene, globalMeshes, globalMaterials, graphics);
|
||||
loadGlobalMeshes(scene, globalMeshes, globalMaterials);
|
||||
|
||||
|
||||
List<aiNode *> meshNodes;
|
||||
|
||||
@@ -18,9 +18,9 @@ public:
|
||||
~MeshLoader();
|
||||
void importAsset(const std::filesystem::path& filePath);
|
||||
private:
|
||||
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials, Gfx::PGraphics graphics);
|
||||
void loadMaterials(const aiScene* scene, Array<PMaterialAsset>& globalMaterials);
|
||||
void loadTextures(const aiScene* scene, const std::filesystem::path& meshPath);
|
||||
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics);
|
||||
void loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials);
|
||||
void convertAssimpARGB(unsigned char* dst, aiTexel* src, uint32 numPixels);
|
||||
|
||||
void import(std::filesystem::path path, PMeshAsset meshAsset);
|
||||
|
||||
@@ -50,10 +50,10 @@ void TextureAsset::load()
|
||||
createInfo.mipLevels = kTexture->numLevels;
|
||||
createInfo.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT;
|
||||
createInfo.resourceData.data = ktxTexture_GetData(ktxTexture(kTexture));
|
||||
createInfo.resourceData.size = (uint32)ktxTexture_GetDataSize(ktxTexture(kTexture));
|
||||
createInfo.resourceData.size = ktxTexture_GetDataSize(ktxTexture(kTexture));
|
||||
createInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
|
||||
Gfx::PTexture2D texture = WindowManager::getGraphics()->createTexture2D(createInfo);
|
||||
texture->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
setTexture(texture);
|
||||
Gfx::PTexture2D tex = WindowManager::getGraphics()->createTexture2D(createInfo);
|
||||
tex->transferOwnership(Gfx::QueueType::GRAPHICS);
|
||||
setTexture(tex);
|
||||
setStatus(Asset::Status::Ready);
|
||||
}
|
||||
@@ -12,10 +12,10 @@ public:
|
||||
virtual ~TextureAsset();
|
||||
virtual void save() override;
|
||||
virtual void load() override;
|
||||
void setTexture(Gfx::PTexture texture)
|
||||
void setTexture(Gfx::PTexture _texture)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
this->texture = texture;
|
||||
texture = _texture;
|
||||
}
|
||||
Gfx::PTexture getTexture()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user