Loading logic moved to Asset classes

This commit is contained in:
Dynamitos
2020-06-08 01:44:47 +02:00
parent 356e6058fe
commit ab4a3b5e23
50 changed files with 966 additions and 558 deletions
+36 -1
View File
@@ -1,5 +1,9 @@
#include "TextureAsset.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Graphics.h"
#include "Graphics/WindowManager.h"
#include <stb_image.h>
#include <stb_image_write.h>
using namespace Seele;
@@ -11,7 +15,38 @@ TextureAsset::TextureAsset(const std::string& directory, const std::string& name
: Asset(directory, name)
{
}
TextureAsset::TextureAsset(const std::string& fullPath)
TextureAsset::TextureAsset(const std::filesystem::path& fullPath)
: Asset(fullPath)
{
}
TextureAsset::~TextureAsset()
{
}
void TextureAsset::save()
{
//TODO: make this an actual file, not just a png wrapper
}
void TextureAsset::load()
{
setStatus(Status::Loading);
int x, y, n;
unsigned char* data = stbi_load(getFullPath().c_str(), &x, &y, &n, 4);
TextureCreateInfo createInfo;
//TODO: support other formats
createInfo.format = Gfx::SE_FORMAT_R8G8B8A8_UINT;
createInfo.resourceData.data = data;
createInfo.resourceData.size = x * y * 4 * sizeof(unsigned char);
createInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
createInfo.width = x;
createInfo.height = y;
Gfx::PTexture2D texture = WindowManager::getGraphics()->createTexture2D(createInfo);
stbi_image_free(data);
texture->transferOwnership(Gfx::QueueType::GRAPHICS);
setTexture(texture);
setStatus(Asset::Status::Ready);
}