mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
removing texture library
This commit is contained in:
5
Makefile
5
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
||||||
# Updated: 2023/04/04 16:21:17 by maldavid ### ########.fr #
|
# Updated: 2023/04/21 14:13:15 by maldavid ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ SRCS = $(wildcard $(addsuffix /*.cpp, ./src/core))
|
|||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform))
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer))
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
|
||||||
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/utils/**))
|
||||||
|
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ CXXFLAGS = -std=c++17 -O3 -fPIC
|
|||||||
INCLUDES = -I./includes -I./src -I./third_party
|
INCLUDES = -I./includes -I./src -I./third_party
|
||||||
|
|
||||||
ifeq ($(DEBUG), true)
|
ifeq ($(DEBUG), true)
|
||||||
CXXFLAGS += -g
|
CXXFLAGS += -g -D DEBUG
|
||||||
endif
|
endif
|
||||||
|
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/19 12:35:03 by maldavid ### ########.fr */
|
/* Updated: 2023/04/19 13:11:27 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ int mlx_mouse_move(void* mlx, void* win, int x, int y);
|
|||||||
* @brief Get cursor's position
|
* @brief Get cursor's position
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param x X coordinate
|
* @param x Get x coordinate
|
||||||
* @param y Y coordinate
|
* @param y Get y coordinate
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
||||||
*/
|
*/
|
||||||
@@ -148,7 +148,7 @@ int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
|
|||||||
* @param width Width of the image
|
* @param width Width of the image
|
||||||
* @param height Height of the image
|
* @param height Height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
void* mlx_new_image(void* mlx, int width, int height);
|
void* mlx_new_image(void* mlx, int width, int height);
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ void* mlx_new_image(void* mlx, int width, int height);
|
|||||||
* @param size_line Get size of a line of the image
|
* @param size_line Get size of a line of the image
|
||||||
* @param endian Get endian of the processor
|
* @param endian Get endian of the processor
|
||||||
*
|
*
|
||||||
* @return (char*) Return raw address of the image's data
|
* @return (char*) Return raw address of the image's data or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
char* mlx_get_data_addr(void* mlx, void* img, int* bits_per_pixel, int* size_line, int* endian);
|
char* mlx_get_data_addr(void* mlx, void* img, int* bits_per_pixel, int* size_line, int* endian);
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ int mlx_destroy_image(void* mlx, void* img);
|
|||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ void* mlx_png_file_to_image(void* mlx, char* filename, int* width, int* height);
|
|||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ void* mlx_jpg_file_to_image(void* mlx, char* filename, int* width, int* height);
|
|||||||
* @param width Get the width of the image
|
* @param width Get the width of the image
|
||||||
* @param heigth Get the height of the image
|
* @param heigth Get the height of the image
|
||||||
*
|
*
|
||||||
* @return (void*) An opaque pointer to the internal image
|
* @return (void*) An opaque pointer to the internal image or NULL (0x0) in case of error
|
||||||
*/
|
*/
|
||||||
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height);
|
void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int* height);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
/* 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)
|
void* Application::newTexture(int w, int h)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>();
|
_textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
|
||||||
texture->create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
|
_textures.front().openCPUmap();
|
||||||
TextureID id = _texture_lib.addTextureToLibrary(texture);
|
return &_textures.front();
|
||||||
_texture_ids.push_back(id);
|
|
||||||
return &_texture_ids.back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Application::newStbTexture(char* file, int* w, int* h)
|
void* Application::newStbTexture(char* file, int* w, int* h)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(stbTextureLoad(file, w, h));
|
_textures.emplace_front(stbTextureLoad(file, w, h));
|
||||||
TextureID id = _texture_lib.addTextureToLibrary(texture);
|
_textures.front().openCPUmap();
|
||||||
_texture_ids.push_back(id);
|
return &_textures.front();
|
||||||
return &_texture_ids.back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
static const int endianness = isSystemBigEndian();
|
||||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
|
|
||||||
char* map = static_cast<char*>(texture->openCPUmap());
|
*bits_per_pixel = 32;
|
||||||
*bits_per_pixel = sizeof(uint32_t) * 8;
|
*size_line = img->getWidth() * 4;
|
||||||
*size_line = texture->getWidth();
|
*endian = endianness;
|
||||||
*endian = isSystemBigEndian();
|
return static_cast<char*>(img->getMap());
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::destroyTexture(void* ptr)
|
void Application::destroyTexture(void* ptr)
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||||
TextureID id = *static_cast<TextureID*>(ptr);
|
Texture* texture = static_cast<Texture*>(ptr);
|
||||||
_texture_lib.removeTextureFromLibrary(id);
|
texture->destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
/* 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 <core/graphics.h>
|
||||||
#include <platform/inputs.h>
|
#include <platform/inputs.h>
|
||||||
|
|
||||||
#include <renderer/texture_library.h>
|
|
||||||
|
|
||||||
namespace mlx::core
|
namespace mlx::core
|
||||||
{
|
{
|
||||||
class Application
|
class Application
|
||||||
@@ -50,7 +48,7 @@ namespace mlx::core
|
|||||||
|
|
||||||
void* newTexture(int w, int h);
|
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, ...)
|
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);
|
inline void texturePut(void* win, void* img, int x, int y);
|
||||||
void destroyTexture(void* ptr);
|
void destroyTexture(void* ptr);
|
||||||
|
|
||||||
@@ -62,8 +60,7 @@ namespace mlx::core
|
|||||||
~Application() = default;
|
~Application() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextureLibrary _texture_lib;
|
std::list<Texture> _textures;
|
||||||
std::list<TextureID> _texture_ids;
|
|
||||||
std::vector<std::unique_ptr<GraphicsSupport>> _graphics;
|
std::vector<std::unique_ptr<GraphicsSupport>> _graphics;
|
||||||
std::function<int(void*)> _loop_hook;
|
std::function<int(void*)> _loop_hook;
|
||||||
std::unique_ptr<Input> _in;
|
std::unique_ptr<Input> _in;
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ namespace mlx::core
|
|||||||
|
|
||||||
void Application::texturePut(void* win, void* img, int x, int y)
|
void Application::texturePut(void* win, void* img, int x, int y)
|
||||||
{
|
{
|
||||||
TextureID id = *static_cast<TextureID*>(img);
|
Texture* texture = static_cast<Texture*>(img);
|
||||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
|
|
||||||
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
|
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
/* 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();
|
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;
|
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;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,47 +57,47 @@ extern "C"
|
|||||||
return SDL_ShowCursor(SDL_DISABLE);
|
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;
|
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;
|
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;
|
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;
|
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;
|
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);
|
std::filesystem::path file(filename);
|
||||||
if(file.extension() != ".png")
|
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);
|
mlx::core::error::report(e_kind::error, "PNG loader : not a png file '%s'", filename);
|
||||||
return nullptr;
|
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);
|
std::filesystem::path file(filename);
|
||||||
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
|
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);
|
mlx::core::error::report(e_kind::error, "PNG loader : not a jpg file '%s'", filename);
|
||||||
return nullptr;
|
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);
|
std::filesystem::path file(filename);
|
||||||
if(file.extension() != ".bmp" && file.extension() != ".dib")
|
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);
|
mlx::core::error::report(e_kind::error, "PNG loader : not a jpg file '%s'", filename);
|
||||||
return nullptr;
|
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];
|
unsigned char color_bits[4];
|
||||||
color_bits[0] = (color & 0x00FF0000) >> 16;
|
color_bits[0] = (color & 0x00FF0000) >> 16;
|
||||||
color_bits[1] = (color & 0x0000FF00) >> 8;
|
color_bits[1] = (color & 0x0000FF00) >> 8;
|
||||||
color_bits[2] = color & 0x000000FF;
|
color_bits[2] = color & 0x000000FF;
|
||||||
color_bits[3] = 0xFF;
|
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;
|
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];
|
unsigned char color_bits[4];
|
||||||
color_bits[0] = (color & 0x00FF0000) >> 16;
|
color_bits[0] = (color & 0x00FF0000) >> 16;
|
||||||
color_bits[1] = (color & 0x0000FF00) >> 8;
|
color_bits[1] = (color & 0x0000FF00) >> 8;
|
||||||
color_bits[2] = color & 0x000000FF;
|
color_bits[2] = color & 0x000000FF;
|
||||||
color_bits[3] = 0xFF;
|
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;
|
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;
|
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;
|
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();
|
mlx::Render_Core::get().destroy();
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
/* 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 clearRenderData() noexcept;
|
||||||
inline void pixelPut(int x, int y, uint32_t color) 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 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;
|
void endRender() noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace mlx
|
|||||||
_text_put_pipeline->put(x, y, color, str);
|
_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);
|
_textures_to_render.emplace(texture, x, y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/02 18:13:38 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 13:24:56 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,11 +19,16 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
void CmdBuffer::init(CmdManager* manager)
|
void CmdBuffer::init(CmdManager* manager)
|
||||||
{
|
{
|
||||||
_manager = manager;
|
init(&manager->getCmdPool());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::init(CmdPool* pool)
|
||||||
|
{
|
||||||
|
_pool = pool;
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo allocInfo{};
|
VkCommandBufferAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
allocInfo.commandPool = manager->getCmdPool().get();
|
allocInfo.commandPool = pool->get();
|
||||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
allocInfo.commandBufferCount = 1;
|
allocInfo.commandBufferCount = 1;
|
||||||
|
|
||||||
@@ -57,6 +62,26 @@ namespace mlx
|
|||||||
_is_recording = false;
|
_is_recording = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::submitIdle() noexcept
|
||||||
|
{
|
||||||
|
auto device = Render_Core::get().getDevice().get();
|
||||||
|
|
||||||
|
VkSubmitInfo submitInfo = {};
|
||||||
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
submitInfo.commandBufferCount = 1;
|
||||||
|
submitInfo.pCommandBuffers = &_cmd_buffer;
|
||||||
|
|
||||||
|
VkFenceCreateInfo fenceCreateInfo = {};
|
||||||
|
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
|
|
||||||
|
VkFence fence;
|
||||||
|
vkCreateFence(device, &fenceCreateInfo, nullptr, &fence);
|
||||||
|
vkResetFences(device, 1, &fence);
|
||||||
|
vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, fence);
|
||||||
|
vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX);
|
||||||
|
vkDestroyFence(device, fence, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void CmdBuffer::submit(Semaphore& semaphores) noexcept
|
void CmdBuffer::submit(Semaphore& semaphores) noexcept
|
||||||
{
|
{
|
||||||
VkSemaphore signalSemaphores[] = { semaphores.getRenderImageSemaphore() };
|
VkSemaphore signalSemaphores[] = { semaphores.getRenderImageSemaphore() };
|
||||||
@@ -79,7 +104,6 @@ namespace mlx
|
|||||||
|
|
||||||
void CmdBuffer::destroy() noexcept
|
void CmdBuffer::destroy() noexcept
|
||||||
{
|
{
|
||||||
vkFreeCommandBuffers(Render_Core::get().getDevice().get(), _manager->getCmdPool().get(), 1, &_cmd_buffer);
|
|
||||||
_fence.destroy();
|
_fence.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/02 17:57:26 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 13:20:49 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -22,23 +22,27 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void init(class CmdManager* manager);
|
void init(class CmdManager* manager);
|
||||||
|
void init(class CmdPool* pool);
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
void beginRecord(VkCommandBufferUsageFlags usage = 0);
|
void beginRecord(VkCommandBufferUsageFlags usage = 0);
|
||||||
void submit(class Semaphore& semaphores) noexcept;
|
void submit(class Semaphore& semaphores) noexcept;
|
||||||
|
void submitIdle() noexcept;
|
||||||
inline void waitForExecution() noexcept { _fence.waitAndReset(); }
|
inline void waitForExecution() noexcept { _fence.waitAndReset(); }
|
||||||
inline void reset() noexcept { vkResetCommandBuffer(_cmd_buffer, 0); }
|
inline void reset() noexcept { vkResetCommandBuffer(_cmd_buffer, 0); }
|
||||||
void endRecord();
|
void endRecord();
|
||||||
|
|
||||||
inline bool isRecording() const noexcept { return _is_recording; }
|
inline bool isRecording() const noexcept { return _is_recording; }
|
||||||
|
inline bool isInit() const noexcept { return _cmd_buffer != VK_NULL_HANDLE; }
|
||||||
|
|
||||||
inline VkCommandBuffer& operator()() noexcept { return _cmd_buffer; }
|
inline VkCommandBuffer& operator()() noexcept { return _cmd_buffer; }
|
||||||
inline VkCommandBuffer& get() noexcept { return _cmd_buffer; }
|
inline VkCommandBuffer& get() noexcept { return _cmd_buffer; }
|
||||||
|
inline Fence& getFence() noexcept { return _fence; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fence _fence;
|
Fence _fence;
|
||||||
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
||||||
class CmdManager* _manager = nullptr;
|
class CmdPool* _pool = nullptr;
|
||||||
bool _is_recording = false;
|
bool _is_recording = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/01/25 15:23:19 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 14:13:32 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ namespace mlx
|
|||||||
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef DEBUG
|
||||||
constexpr const bool enableValidationLayers = true;
|
constexpr const bool enableValidationLayers = true;
|
||||||
#else
|
#else
|
||||||
constexpr const bool enableValidationLayers = false;
|
constexpr const bool enableValidationLayers = false;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/08 18:41:54 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 19:31:15 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -58,12 +58,11 @@ namespace mlx
|
|||||||
|
|
||||||
void* Texture::openCPUmap()
|
void* Texture::openCPUmap()
|
||||||
{
|
{
|
||||||
if(_cpu_map == nullptr)
|
if(_cpu_map_adress != nullptr)
|
||||||
{
|
return _cpu_map_adress;
|
||||||
_cpu_map = std::make_shared<Buffer>();
|
_cpu_map = std::make_shared<Buffer>();
|
||||||
_cpu_map->create(Buffer::kind::dynamic, sizeof(uint32_t) * (getWidth() * getHeight()), VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
_cpu_map->create(Buffer::kind::dynamic, sizeof(uint32_t) * (getWidth() * getHeight()), VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
||||||
Image::copyToBuffer(*_cpu_map);
|
Image::copyToBuffer(*_cpu_map);
|
||||||
}
|
|
||||||
if(!_cpu_map->isMapped())
|
if(!_cpu_map->isMapped())
|
||||||
_cpu_map->mapMem(&_cpu_map_adress);
|
_cpu_map->mapMem(&_cpu_map_adress);
|
||||||
if(_cpu_map_adress == nullptr)
|
if(_cpu_map_adress == nullptr)
|
||||||
@@ -103,15 +102,9 @@ namespace mlx
|
|||||||
if(!std::filesystem::exists(std::move(file)))
|
if(!std::filesystem::exists(std::move(file)))
|
||||||
core::error::report(e_kind::fatal_error, "Image : file not found '%s'", filename.c_str());
|
core::error::report(e_kind::fatal_error, "Image : file not found '%s'", filename.c_str());
|
||||||
if(stbi_is_hdr(filename.c_str()))
|
if(stbi_is_hdr(filename.c_str()))
|
||||||
{
|
core::error::report(e_kind::fatal_error, "Texture : unsupported image format '%s'", filename.c_str());
|
||||||
data = (uint8_t*)stbi_loadf(filename.c_str(), w, h, &channels, 4);
|
data = stbi_load(filename.c_str(), w, h, &channels, 4);
|
||||||
format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data = stbi_load(filename.c_str(), w, h, &channels, 4);
|
|
||||||
format = VK_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
}
|
|
||||||
texture.create(data, *w, *h, format);
|
texture.create(data, *w, *h, format);
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
return texture;
|
return texture;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/07 16:39:35 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 19:05:34 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ namespace mlx
|
|||||||
void destroy() noexcept override;
|
void destroy() noexcept override;
|
||||||
|
|
||||||
void* openCPUmap();
|
void* openCPUmap();
|
||||||
|
inline void* getMap() const noexcept { return _cpu_map_adress; }
|
||||||
|
|
||||||
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
||||||
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||||
@@ -56,11 +57,11 @@ namespace mlx
|
|||||||
|
|
||||||
struct TextureRenderData
|
struct TextureRenderData
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> texture;
|
Texture* texture;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
TextureRenderData(std::shared_ptr<Texture> _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {}
|
TextureRenderData(Texture* _texture, int _x, int _y) : texture(_texture), x(_x), y(_y) {}
|
||||||
bool operator==(const TextureRenderData& rhs) const { return texture == rhs.texture && x == rhs.x && y == rhs.y; }
|
bool operator==(const TextureRenderData& rhs) const { return texture == rhs.texture && x == rhs.x && y == rhs.y; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -72,7 +73,7 @@ namespace std
|
|||||||
{
|
{
|
||||||
size_t operator()(const mlx::TextureRenderData& td) const noexcept
|
size_t operator()(const mlx::TextureRenderData& td) const noexcept
|
||||||
{
|
{
|
||||||
return std::hash<std::shared_ptr<mlx::Texture>>()(td.texture) + std::hash<int>()(td.x) + std::hash<int>()(td.y);
|
return std::hash<mlx::Texture*>()(td.texture) + std::hash<int>()(td.x) + std::hash<int>()(td.y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/13 15:07:01 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 13:23:52 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <renderer/core/render_core.h>
|
#include <renderer/core/render_core.h>
|
||||||
#include <renderer/buffers/vk_buffer.h>
|
#include <renderer/buffers/vk_buffer.h>
|
||||||
#include <renderer/command/vk_cmd_pool.h>
|
#include <renderer/command/vk_cmd_pool.h>
|
||||||
|
#include <renderer/core/vk_fence.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,8 @@ namespace mlx
|
|||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate memory for an image");
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate memory for an image");
|
||||||
|
|
||||||
vkBindImageMemory(Render_Core::get().getDevice().get(), _image, _memory, 0);
|
vkBindImageMemory(Render_Core::get().getDevice().get(), _image, _memory, 0);
|
||||||
|
|
||||||
|
_pool.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept
|
void Image::createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept
|
||||||
@@ -93,24 +96,11 @@ namespace mlx
|
|||||||
|
|
||||||
void Image::copyFromBuffer(Buffer& buffer)
|
void Image::copyFromBuffer(Buffer& buffer)
|
||||||
{
|
{
|
||||||
CmdPool cmdpool;
|
if(!_transfer_cmd.isInit())
|
||||||
cmdpool.init();
|
_transfer_cmd.init(&_pool);
|
||||||
auto device = Render_Core::get().getDevice().get();
|
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo allocInfo{};
|
_transfer_cmd.reset();
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
_transfer_cmd.beginRecord();
|
||||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
||||||
allocInfo.commandPool = cmdpool.get();
|
|
||||||
allocInfo.commandBufferCount = 1;
|
|
||||||
|
|
||||||
VkCommandBuffer cmdBuffer;
|
|
||||||
vkAllocateCommandBuffers(device, &allocInfo, &cmdBuffer);
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo{};
|
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
||||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
||||||
|
|
||||||
vkBeginCommandBuffer(cmdBuffer, &beginInfo);
|
|
||||||
|
|
||||||
VkImageMemoryBarrier copy_barrier = {};
|
VkImageMemoryBarrier copy_barrier = {};
|
||||||
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
@@ -123,7 +113,7 @@ namespace mlx
|
|||||||
copy_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
copy_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
copy_barrier.subresourceRange.levelCount = 1;
|
copy_barrier.subresourceRange.levelCount = 1;
|
||||||
copy_barrier.subresourceRange.layerCount = 1;
|
copy_barrier.subresourceRange.layerCount = 1;
|
||||||
vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
||||||
|
|
||||||
VkBufferImageCopy region = {};
|
VkBufferImageCopy region = {};
|
||||||
region.bufferOffset = 0;
|
region.bufferOffset = 0;
|
||||||
@@ -139,7 +129,8 @@ namespace mlx
|
|||||||
_height,
|
_height,
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
vkCmdCopyBufferToImage(cmdBuffer, buffer.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
||||||
|
vkCmdCopyBufferToImage(_transfer_cmd.get(), buffer.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||||
|
|
||||||
VkImageMemoryBarrier use_barrier = {};
|
VkImageMemoryBarrier use_barrier = {};
|
||||||
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
@@ -153,43 +144,19 @@ namespace mlx
|
|||||||
use_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
use_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
use_barrier.subresourceRange.levelCount = 1;
|
use_barrier.subresourceRange.levelCount = 1;
|
||||||
use_barrier.subresourceRange.layerCount = 1;
|
use_barrier.subresourceRange.layerCount = 1;
|
||||||
vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &use_barrier);
|
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &use_barrier);
|
||||||
|
|
||||||
vkEndCommandBuffer(cmdBuffer);
|
_transfer_cmd.endRecord();
|
||||||
|
_transfer_cmd.submitIdle();
|
||||||
VkSubmitInfo submitInfo{};
|
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
||||||
submitInfo.commandBufferCount = 1;
|
|
||||||
submitInfo.pCommandBuffers = &cmdBuffer;
|
|
||||||
|
|
||||||
auto graphicsQueue = Render_Core::get().getQueue().getGraphic();
|
|
||||||
|
|
||||||
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
|
||||||
vkQueueWaitIdle(graphicsQueue);
|
|
||||||
|
|
||||||
cmdpool.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::copyToBuffer(Buffer& buffer)
|
void Image::copyToBuffer(Buffer& buffer)
|
||||||
{
|
{
|
||||||
CmdPool cmdpool;
|
if(!_transfer_cmd.isInit())
|
||||||
cmdpool.init();
|
_transfer_cmd.init(&_pool);
|
||||||
auto device = Render_Core::get().getDevice().get();
|
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo allocInfo{};
|
_transfer_cmd.reset();
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
_transfer_cmd.beginRecord();
|
||||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
||||||
allocInfo.commandPool = cmdpool.get();
|
|
||||||
allocInfo.commandBufferCount = 1;
|
|
||||||
|
|
||||||
VkCommandBuffer cmdBuffer;
|
|
||||||
vkAllocateCommandBuffers(device, &allocInfo, &cmdBuffer);
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo{};
|
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
||||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
||||||
|
|
||||||
vkBeginCommandBuffer(cmdBuffer, &beginInfo);
|
|
||||||
|
|
||||||
VkImageMemoryBarrier copy_barrier = {};
|
VkImageMemoryBarrier copy_barrier = {};
|
||||||
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
@@ -202,7 +169,7 @@ namespace mlx
|
|||||||
copy_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
copy_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
copy_barrier.subresourceRange.levelCount = 1;
|
copy_barrier.subresourceRange.levelCount = 1;
|
||||||
copy_barrier.subresourceRange.layerCount = 1;
|
copy_barrier.subresourceRange.layerCount = 1;
|
||||||
vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
||||||
|
|
||||||
VkBufferImageCopy region = {};
|
VkBufferImageCopy region = {};
|
||||||
region.bufferOffset = 0;
|
region.bufferOffset = 0;
|
||||||
@@ -218,7 +185,7 @@ namespace mlx
|
|||||||
_height,
|
_height,
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
vkCmdCopyImageToBuffer(cmdBuffer, _image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.get(), 1, ®ion);
|
vkCmdCopyImageToBuffer(_transfer_cmd.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.get(), 1, ®ion);
|
||||||
|
|
||||||
VkImageMemoryBarrier use_barrier = {};
|
VkImageMemoryBarrier use_barrier = {};
|
||||||
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
@@ -232,21 +199,10 @@ namespace mlx
|
|||||||
use_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
use_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
use_barrier.subresourceRange.levelCount = 1;
|
use_barrier.subresourceRange.levelCount = 1;
|
||||||
use_barrier.subresourceRange.layerCount = 1;
|
use_barrier.subresourceRange.layerCount = 1;
|
||||||
vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &use_barrier);
|
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &use_barrier);
|
||||||
|
|
||||||
vkEndCommandBuffer(cmdBuffer);
|
_transfer_cmd.endRecord();
|
||||||
|
_transfer_cmd.submitIdle();
|
||||||
VkSubmitInfo submitInfo{};
|
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
||||||
submitInfo.commandBufferCount = 1;
|
|
||||||
submitInfo.pCommandBuffers = &cmdBuffer;
|
|
||||||
|
|
||||||
auto graphicsQueue = Render_Core::get().getQueue().getGraphic();
|
|
||||||
|
|
||||||
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
|
||||||
vkQueueWaitIdle(graphicsQueue);
|
|
||||||
|
|
||||||
cmdpool.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::destroy() noexcept
|
void Image::destroy() noexcept
|
||||||
@@ -258,6 +214,9 @@ namespace mlx
|
|||||||
|
|
||||||
vkFreeMemory(Render_Core::get().getDevice().get(), _memory, nullptr);
|
vkFreeMemory(Render_Core::get().getDevice().get(), _memory, nullptr);
|
||||||
vkDestroyImage(Render_Core::get().getDevice().get(), _image, nullptr);
|
vkDestroyImage(Render_Core::get().getDevice().get(), _image, nullptr);
|
||||||
|
if(_transfer_cmd.isInit())
|
||||||
|
_transfer_cmd.destroy();
|
||||||
|
_pool.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t formatSize(VkFormat format)
|
uint32_t formatSize(VkFormat format)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/13 10:59:04 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 10:58:02 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <renderer/command/vk_cmd_buffer.h>
|
||||||
|
#include <renderer/command/vk_cmd_pool.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -45,6 +47,8 @@ namespace mlx
|
|||||||
virtual ~Image() = default;
|
virtual ~Image() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CmdBuffer _transfer_cmd;
|
||||||
|
CmdPool _pool;
|
||||||
VkImage _image = VK_NULL_HANDLE;
|
VkImage _image = VK_NULL_HANDLE;
|
||||||
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
||||||
VkImageView _image_view = VK_NULL_HANDLE;
|
VkImageView _image_view = VK_NULL_HANDLE;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/19 11:32:54 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 14:51:47 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ namespace mlx
|
|||||||
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||||
|
|
||||||
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||||
|
_buffer.mapMem(&_map);
|
||||||
_width = width;
|
_width = width;
|
||||||
_height = height;
|
_height = height;
|
||||||
}
|
}
|
||||||
@@ -34,8 +35,6 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
if(x < 0 || y < 0 || x > _width || y > _height)
|
if(x < 0 || y < 0 || x > _width || y > _height)
|
||||||
return;
|
return;
|
||||||
if(!_buffer.isMapped())
|
|
||||||
_buffer.mapMem(&_map);
|
|
||||||
unsigned char* mem = static_cast<unsigned char*>(_map) + (y * _width * sizeof(uint32_t)) + (x * sizeof(uint32_t));
|
unsigned char* mem = static_cast<unsigned char*>(_map) + (y * _width * sizeof(uint32_t)) + (x * sizeof(uint32_t));
|
||||||
*reinterpret_cast<uint32_t*>(mem) = color;
|
*reinterpret_cast<uint32_t*>(mem) = color;
|
||||||
_has_been_modified = true;
|
_has_been_modified = true;
|
||||||
@@ -43,8 +42,6 @@ namespace mlx
|
|||||||
|
|
||||||
void PixelPutPipeline::clear()
|
void PixelPutPipeline::clear()
|
||||||
{
|
{
|
||||||
if(!_buffer.isMapped())
|
|
||||||
_buffer.mapMem(&_map);
|
|
||||||
unsigned char* mem = static_cast<unsigned char*>(_map);
|
unsigned char* mem = static_cast<unsigned char*>(_map);
|
||||||
std::memset(mem, 0, sizeof(uint32_t) * (_width * _height));
|
std::memset(mem, 0, sizeof(uint32_t) * (_width * _height));
|
||||||
_has_been_modified = true;
|
_has_been_modified = true;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/02 18:10:01 by maldavid ### ########.fr */
|
/* Updated: 2023/04/21 20:56:51 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
|
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/12 13:24:19 by maldavid ### ########.fr */
|
/* Updated: 2023/04/19 13:43:43 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
#include <core/errors.h>
|
#include <core/errors.h>
|
||||||
#include <renderer/renderer.h>
|
#include <renderer/renderer.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/13 10:49:04 by maldavid ### ########.fr */
|
/* Updated: 2023/04/19 13:43:49 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,8 +19,6 @@
|
|||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
TextDrawData::TextDrawData(std::string _text, int _color, int _x, int _y) :
|
TextDrawData::TextDrawData(std::string _text, int _color, int _x, int _y) :
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* texture_library.cpp :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/01 14:24:00 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2023/04/12 13:26:59 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include <core/errors.h>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <renderer/texture_library.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
std::shared_ptr<Texture> TextureLibrary::getTexture(TextureID id)
|
|
||||||
{
|
|
||||||
if(!_cache.count(id))
|
|
||||||
core::error::report(e_kind::fatal_error, "Texture Library : wrong texture ID '%d'", id);
|
|
||||||
return _cache[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureID TextureLibrary::addTextureToLibrary(std::shared_ptr<Texture> texture)
|
|
||||||
{
|
|
||||||
auto it = std::find_if(_cache.begin(), _cache.end(), [=](const std::pair<TextureID, std::shared_ptr<Texture>>& v)
|
|
||||||
{
|
|
||||||
return v.second.get() == texture.get();
|
|
||||||
});
|
|
||||||
if(it != _cache.end())
|
|
||||||
return it->first;
|
|
||||||
_cache[_current_id] = texture;
|
|
||||||
_current_id++;
|
|
||||||
return _current_id - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureLibrary::removeTextureFromLibrary(TextureID id)
|
|
||||||
{
|
|
||||||
if(_cache.count(id))
|
|
||||||
{
|
|
||||||
_cache[id]->destroy();
|
|
||||||
_cache.erase(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureLibrary::clearLibrary()
|
|
||||||
{
|
|
||||||
for(auto [id, texture] : _cache)
|
|
||||||
texture->destroy();
|
|
||||||
_cache.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* texture_library.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/01 14:16:13 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2023/04/01 14:42:39 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef __MLX_TEXTURE_LIBRARY__
|
|
||||||
#define __MLX_TEXTURE_LIBRARY__
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <renderer/images/texture.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
using TextureID = uint32_t;
|
|
||||||
constexpr TextureID nulltexture = 0;
|
|
||||||
|
|
||||||
class TextureLibrary
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TextureLibrary() = default;
|
|
||||||
|
|
||||||
std::shared_ptr<Texture> getTexture(TextureID id);
|
|
||||||
TextureID addTextureToLibrary(std::shared_ptr<Texture> texture);
|
|
||||||
void removeTextureFromLibrary(TextureID id);
|
|
||||||
|
|
||||||
void clearLibrary();
|
|
||||||
|
|
||||||
~TextureLibrary() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unordered_map<TextureID, std::shared_ptr<Texture>> _cache;
|
|
||||||
TextureID _current_id = 1;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user