removing texture library

This commit is contained in:
2023-04-21 22:17:55 +02:00
parent f6736f210a
commit 6d3421d7f4
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();
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2023/04/19 12:14:07 by maldavid ### ########.fr */
/* Updated: 2023/04/21 19:24:12 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,8 +25,6 @@
#include <core/graphics.h>
#include <platform/inputs.h>
#include <renderer/texture_library.h>
namespace mlx::core
{
class Application
@@ -50,7 +48,7 @@ namespace mlx::core
void* newTexture(int w, int h);
void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)
char* mapTexture(void* img, int* bits_per_pixel, int* size_line, int* endian);
char* mapTexture(Texture* img, int* bits_per_pixel, int* size_line, int* endian);
inline void texturePut(void* win, void* img, int x, int y);
void destroyTexture(void* ptr);
@@ -62,8 +60,7 @@ namespace mlx::core
~Application() = default;
private:
TextureLibrary _texture_lib;
std::list<TextureID> _texture_ids;
std::list<Texture> _textures;
std::vector<std::unique_ptr<GraphicsSupport>> _graphics;
std::function<int(void*)> _loop_hook;
std::unique_ptr<Input> _in;

View File

@@ -69,8 +69,7 @@ namespace mlx::core
void Application::texturePut(void* win, void* img, int x, int y)
{
TextureID id = *static_cast<TextureID*>(img);
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
Texture* texture = static_cast<Texture*>(img);
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2023/04/19 12:14:02 by maldavid ### ########.fr */
/* Updated: 2023/04/21 19:29:49 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,26 +24,26 @@ extern "C"
return new mlx::core::Application();
}
void* mlx_new_window(void* mlx, int w, int h, const char* title)
void* mlx_new_window(mlx::core::Application* mlx, int w, int h, const char* title)
{
return static_cast<mlx::core::Application*>(mlx)->newGraphicsSuport(w, h, title);
return mlx->newGraphicsSuport(w, h, title);
}
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param)
int mlx_loop_hook(mlx::core::Application* mlx, int (*f)(void*), void* param)
{
static_cast<mlx::core::Application*>(mlx)->loopHook(f, param);
mlx->loopHook(f, param);
return 0;
}
int mlx_loop(void* mlx)
int mlx_loop(mlx::core::Application* mlx)
{
static_cast<mlx::core::Application*>(mlx)->run();
mlx->run();
return 0;
}
int mlx_loop_end(void* mlx)
int mlx_loop_end(mlx::core::Application* mlx)
{
static_cast<mlx::core::Application*>(mlx)->loopEnd();
mlx->loopEnd();
return 0;
}
@@ -57,47 +57,47 @@ extern "C"
return SDL_ShowCursor(SDL_DISABLE);
}
int mlx_mouse_move(void* mlx, void* win, int x, int y)
int mlx_mouse_move(mlx::core::Application* mlx, void* win, int x, int y)
{
static_cast<mlx::core::Application*>(mlx)->mouseMove(win, x, y);
mlx->mouseMove(win, x, y);
return 0;
}
int mlx_mouse_get_pos(void* mlx, int* x, int* y)
int mlx_mouse_get_pos(mlx::core::Application* mlx, int* x, int* y)
{
static_cast<mlx::core::Application*>(mlx)->getMousePos(x, y);
mlx->getMousePos(x, y);
return 0;
}
int mlx_on_event(void* mlx, void* win, int event, int (*funct_ptr)(int, void*), void* param)
int mlx_on_event(mlx::core::Application* mlx, void* win, int event, int (*funct_ptr)(int, void*), void* param)
{
static_cast<mlx::core::Application*>(mlx)->onEvent(win, event, funct_ptr, param);
mlx->onEvent(win, event, funct_ptr, param);
return 0;
}
void* mlx_new_image(void* mlx, int width, int height)
void* mlx_new_image(mlx::core::Application* mlx, int width, int height)
{
return static_cast<mlx::core::Application*>(mlx)->newTexture(width, height);
return mlx->newTexture(width, height);
}
char* mlx_get_data_addr(void* mlx, void* img, int* bits_per_pixel, int* size_line, int* endian)
char* mlx_get_data_addr(mlx::core::Application* mlx, mlx::Texture* img, int* bits_per_pixel, int* size_line, int* endian)
{
return static_cast<mlx::core::Application*>(mlx)->mapTexture(img, bits_per_pixel, size_line, endian);
return mlx->mapTexture(img, bits_per_pixel, size_line, endian);
}
int mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
int mlx_put_image_to_window(mlx::core::Application* mlx, void* win, void* img, int x, int y)
{
static_cast<mlx::core::Application*>(mlx)->texturePut(win, img, x, y);
mlx->texturePut(win, img, x, y);
return 0;
}
int mlx_destroy_image(void* mlx, void* img)
int mlx_destroy_image(mlx::core::Application* mlx, void* img)
{
static_cast<mlx::core::Application*>(mlx)->destroyTexture(img);
mlx->destroyTexture(img);
return 0;
}
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height)
void* mlx_png_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".png")
@@ -105,10 +105,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "PNG loader : not a png file '%s'", filename);
return nullptr;
}
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
return mlx->newStbTexture(filename, width, height);
}
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height)
void* mlx_jpg_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
@@ -116,10 +116,10 @@ extern "C"
mlx::core::error::report(e_kind::error, "PNG loader : not a jpg file '%s'", filename);
return nullptr;
}
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
return mlx->newStbTexture(filename, width, height);
}
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height)
void* mlx_bmp_file_to_image(mlx::core::Application* mlx, char* filename, int* width, int* height)
{
std::filesystem::path file(filename);
if(file.extension() != ".bmp" && file.extension() != ".dib")
@@ -127,53 +127,53 @@ extern "C"
mlx::core::error::report(e_kind::error, "PNG loader : not a jpg file '%s'", filename);
return nullptr;
}
return static_cast<mlx::core::Application*>(mlx)->newStbTexture(filename, width, height);
return mlx->newStbTexture(filename, width, height);
}
int mlx_pixel_put(void* mlx, void* win, int x, int y, int color)
int mlx_pixel_put(mlx::core::Application* mlx, void* win, int x, int y, int color)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
static_cast<mlx::core::Application*>(mlx)->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
mlx->pixelPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits));
return 0;
}
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
int mlx_string_put(mlx::core::Application* mlx, void* win, int x, int y, int color, char* str)
{
unsigned char color_bits[4];
color_bits[0] = (color & 0x00FF0000) >> 16;
color_bits[1] = (color & 0x0000FF00) >> 8;
color_bits[2] = color & 0x000000FF;
color_bits[3] = 0xFF;
static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
mlx->stringPut(win, x, y, *reinterpret_cast<unsigned int*>(color_bits), str);
return 0;
}
int mlx_clear_window(void* mlx, void* win)
int mlx_clear_window(mlx::core::Application* mlx, void* win)
{
static_cast<mlx::core::Application*>(mlx)->clearGraphicsSupport(win);
mlx->clearGraphicsSupport(win);
return 0;
}
int mlx_destroy_window(void* mlx, void* win)
int mlx_destroy_window(mlx::core::Application* mlx, void* win)
{
static_cast<mlx::core::Application*>(mlx)->destroyGraphicsSupport(win);
mlx->destroyGraphicsSupport(win);
return 0;
}
int mlx_destroy_display(void* mlx)
int mlx_destroy_display(mlx::core::Application* mlx)
{
delete static_cast<mlx::core::Application*>(mlx);
delete mlx;
mlx::Render_Core::get().destroy();
return 0;
}
int mlx_get_screens_size(void* mlx, int* w, int* h)
int mlx_get_screens_size(mlx::core::Application* mlx, int* w, int* h)
{
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
mlx->getScreenSize(w, h);
return 0;
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2023/04/19 11:32:16 by maldavid ### ########.fr */
/* Updated: 2023/04/21 18:43:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,7 +42,7 @@ namespace mlx
inline void clearRenderData() noexcept;
inline void pixelPut(int x, int y, uint32_t color) noexcept;
inline void stringPut(int x, int y, int color, std::string str);
inline void texturePut(std::shared_ptr<Texture> texture, int x, int y);
inline void texturePut(Texture* texture, int x, int y);
void endRender() noexcept;

View File

@@ -42,7 +42,7 @@ namespace mlx
_text_put_pipeline->put(x, y, color, str);
}
void GraphicsSupport::texturePut(std::shared_ptr<Texture> texture, int x, int y)
void GraphicsSupport::texturePut(Texture* texture, int x, int y)
{
_textures_to_render.emplace(texture, x, y);
}