Files
Seele/src/Engine/Asset/TextureAsset.cpp
T

53 lines
1.4 KiB
C++
Raw Normal View History

2020-06-02 11:46:18 +02:00
#include "TextureAsset.h"
#include "Graphics/GraphicsResources.h"
2020-06-08 01:44:47 +02:00
#include "Graphics/Graphics.h"
2021-01-19 15:30:00 +01:00
#include "Window/WindowManager.h"
2020-06-08 01:44:47 +02:00
#include <stb_image.h>
#include <stb_image_write.h>
2020-06-02 11:46:18 +02:00
using namespace Seele;
TextureAsset::TextureAsset()
{
}
TextureAsset::TextureAsset(const std::string& directory, const std::string& name)
: Asset(directory, name)
{
}
2020-06-08 01:44:47 +02:00
TextureAsset::TextureAsset(const std::filesystem::path& fullPath)
2020-06-02 11:46:18 +02:00
: Asset(fullPath)
2020-06-08 01:44:47 +02:00
{
}
TextureAsset::~TextureAsset()
2020-06-02 11:46:18 +02:00
{
2020-06-08 01:44:47 +02:00
}
void TextureAsset::save()
{
//TODO: make this an actual file, not just a png wrapper
2021-01-19 15:30:00 +01:00
assert(false && "Editing textures is not yet supported");
2020-06-08 01:44:47 +02:00
}
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);
2020-06-02 11:46:18 +02:00
}