removing texture library

This commit is contained in:
kbz_8
2023-04-21 22:17:55 +02:00
parent 5f1298f9ce
commit 77f707ca7a
21 changed files with 162 additions and 290 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/04/12 11:03:57 by maldavid ### ########.fr */
/* Updated: 2023/04/21 19:24:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,36 +36,32 @@ namespace mlx::core
void* Application::newTexture(int w, int h)
{
std::shared_ptr<Texture> texture = std::make_shared<Texture>();
texture->create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
TextureID id = _texture_lib.addTextureToLibrary(texture);
_texture_ids.push_back(id);
return &_texture_ids.back();
_textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
_textures.front().openCPUmap();
return &_textures.front();
}
void* Application::newStbTexture(char* file, int* w, int* h)
{
std::shared_ptr<Texture> texture = std::make_shared<Texture>(stbTextureLoad(file, w, h));
TextureID id = _texture_lib.addTextureToLibrary(texture);
_texture_ids.push_back(id);
return &_texture_ids.back();
_textures.emplace_front(stbTextureLoad(file, w, h));
_textures.front().openCPUmap();
return &_textures.front();
}
char* Application::mapTexture(void* img, int* bits_per_pixel, int* size_line, int* endian)
char* Application::mapTexture(Texture* img, int* bits_per_pixel, int* size_line, int* endian)
{
TextureID id = *static_cast<TextureID*>(img);
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
char* map = static_cast<char*>(texture->openCPUmap());
*bits_per_pixel = sizeof(uint32_t) * 8;
*size_line = texture->getWidth();
*endian = isSystemBigEndian();
return map;
static const int endianness = isSystemBigEndian();
*bits_per_pixel = 32;
*size_line = img->getWidth() * 4;
*endian = endianness;
return static_cast<char*>(img->getMap());
}
void Application::destroyTexture(void* ptr)
{
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
TextureID id = *static_cast<TextureID*>(ptr);
_texture_lib.removeTextureFromLibrary(id);
Texture* texture = static_cast<Texture*>(ptr);
texture->destroy();
}
}