mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
adding std namespace to all libstd provided primitive types
This commit is contained in:
@@ -18,8 +18,8 @@ namespace mlx
|
||||
{
|
||||
static std::random_device random_device;
|
||||
static std::mt19937_64 engine(random_device());
|
||||
static std::uniform_int_distribution<uint64_t> uniform_distribution;
|
||||
static std::uniform_int_distribution<std::uint64_t> uniform_distribution;
|
||||
|
||||
UUID::UUID() : _uuid(uniform_distribution(engine)) {}
|
||||
UUID::UUID(uint64_t uuid) : _uuid(uuid) {}
|
||||
UUID::UUID(std::uint64_t uuid) : _uuid(uuid) {}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace mlx
|
||||
{
|
||||
public:
|
||||
UUID();
|
||||
UUID(uint64_t uuid);
|
||||
UUID(std::uint64_t uuid);
|
||||
|
||||
inline operator uint64_t() const { return _uuid; }
|
||||
inline operator std::uint64_t() const { return _uuid; }
|
||||
|
||||
private:
|
||||
uint64_t _uuid;
|
||||
std::uint64_t _uuid;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/26 11:56:34 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 07:52:04 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace mlx::core
|
||||
|
||||
void Application::run() noexcept
|
||||
{
|
||||
while(_in->is_running())
|
||||
while(_in->isRunning())
|
||||
{
|
||||
if(!_fps.update())
|
||||
continue;
|
||||
|
||||
@@ -40,20 +40,20 @@ namespace mlx::core
|
||||
|
||||
inline void getScreenSize(void* win, int* w, int* h) noexcept;
|
||||
|
||||
inline void setFPSCap(uint32_t fps) noexcept;
|
||||
inline void setFPSCap(std::uint32_t fps) noexcept;
|
||||
|
||||
inline void* newGraphicsSuport(std::size_t w, std::size_t h, const char* title);
|
||||
inline void clearGraphicsSupport(void* win);
|
||||
inline void destroyGraphicsSupport(void* win);
|
||||
|
||||
inline void pixelPut(void* win, int x, int y, uint32_t color) const noexcept;
|
||||
inline void stringPut(void* win, int x, int y, uint32_t color, char* str);
|
||||
inline void pixelPut(void* win, int x, int y, std::uint32_t color) const noexcept;
|
||||
inline void stringPut(void* win, int x, int y, std::uint32_t color, char* str);
|
||||
|
||||
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, ...)
|
||||
inline void texturePut(void* win, void* img, int x, int y);
|
||||
inline int getTexturePixel(void* img, int x, int y);
|
||||
inline void setTexturePixel(void* img, int x, int y, uint32_t color);
|
||||
inline void setTexturePixel(void* img, int x, int y, std::uint32_t color);
|
||||
void destroyTexture(void* ptr);
|
||||
|
||||
inline void loopHook(int (*f)(void*), void* param);
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace mlx::core
|
||||
*h = DM.h;
|
||||
}
|
||||
|
||||
void Application::setFPSCap(uint32_t fps) noexcept
|
||||
void Application::setFPSCap(std::uint32_t fps) noexcept
|
||||
{
|
||||
_fps.setMaxFPS(fps);
|
||||
}
|
||||
@@ -120,14 +120,14 @@ namespace mlx::core
|
||||
_graphics[*static_cast<int*>(win)].reset();
|
||||
}
|
||||
|
||||
void Application::pixelPut(void* win, int x, int y, uint32_t color) const noexcept
|
||||
void Application::pixelPut(void* win, int x, int y, std::uint32_t color) const noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->pixelPut(x, y, color);
|
||||
}
|
||||
|
||||
void Application::stringPut(void* win, int x, int y, uint32_t color, char* str)
|
||||
void Application::stringPut(void* win, int x, int y, std::uint32_t color, char* str)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
CHECK_WINDOW_PTR(win);
|
||||
@@ -176,7 +176,7 @@ namespace mlx::core
|
||||
return texture->getPixel(x, y);
|
||||
}
|
||||
|
||||
void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
|
||||
void Application::setTexturePixel(void* img, int x, int y, std::uint32_t color)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
CHECK_IMAGE_PTR(img, return);
|
||||
|
||||
@@ -300,7 +300,7 @@ extern "C"
|
||||
mlx::core::error::report(e_kind::error, "You cannot set a FPS cap to 0 (nice try)");
|
||||
return 0;
|
||||
}
|
||||
static_cast<mlx::core::Application*>(mlx)->setFPSCap(static_cast<uint32_t>(fps));
|
||||
static_cast<mlx::core::Application*>(mlx)->setFPSCap(static_cast<std::uint32_t>(fps));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace mlx
|
||||
void FpsManager::init()
|
||||
{
|
||||
_timer = SDL_GetTicks64();
|
||||
_fps_before = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
_fps_now = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
_fps_before = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
bool FpsManager::update()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
_fps_now = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
|
||||
if(SDL_GetTicks64() - _timer > 1000)
|
||||
_timer += 1000;
|
||||
|
||||
@@ -24,17 +24,17 @@ namespace mlx
|
||||
|
||||
void init();
|
||||
bool update();
|
||||
inline void setMaxFPS(uint32_t fps) noexcept { _max_fps = fps; _ns = 1000000000.0 / fps; }
|
||||
inline void setMaxFPS(std::uint32_t fps) noexcept { _max_fps = fps; _ns = 1000000000.0 / fps; }
|
||||
|
||||
~FpsManager() = default;
|
||||
|
||||
private:
|
||||
double _ns = 1000000000.0 / 1'337'000.0;
|
||||
uint64_t _timer = 0;
|
||||
uint64_t _fps_before = 0;
|
||||
uint64_t _fps_now = 0;
|
||||
uint32_t _max_fps = 1'337'000;
|
||||
uint32_t _fps_elapsed_time = 0;
|
||||
std::uint64_t _timer = 0;
|
||||
std::uint64_t _fps_before = 0;
|
||||
std::uint64_t _fps_now = 0;
|
||||
std::uint32_t _max_fps = 1'337'000;
|
||||
std::uint32_t _fps_elapsed_time = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace mlx
|
||||
|
||||
#ifdef GRAPHICS_MEMORY_DUMP
|
||||
// dump memory to file every two seconds
|
||||
static uint64_t timer = SDL_GetTicks64();
|
||||
static std::uint64_t timer = SDL_GetTicks64();
|
||||
if(SDL_GetTicks64() - timer > 2000)
|
||||
{
|
||||
Render_Core::get().getAllocator().dumpMemoryToJson();
|
||||
|
||||
@@ -45,8 +45,8 @@ namespace mlx
|
||||
void render() noexcept;
|
||||
|
||||
inline void clearRenderData() noexcept;
|
||||
inline void pixelPut(int x, int y, uint32_t color) noexcept;
|
||||
inline void stringPut(int x, int y, uint32_t color, std::string str);
|
||||
inline void pixelPut(int x, int y, std::uint32_t color) noexcept;
|
||||
inline void stringPut(int x, int y, std::uint32_t color, std::string str);
|
||||
inline void texturePut(Texture* texture, int x, int y);
|
||||
inline void loadFont(const std::filesystem::path& filepath, float scale);
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace mlx
|
||||
_texture_manager.clear();
|
||||
}
|
||||
|
||||
void GraphicsSupport::pixelPut(int x, int y, uint32_t color) noexcept
|
||||
void GraphicsSupport::pixelPut(int x, int y, std::uint32_t color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_pixel_put_pipeline.setPixel(x, y, color);
|
||||
}
|
||||
|
||||
void GraphicsSupport::stringPut(int x, int y, uint32_t color, std::string str)
|
||||
void GraphicsSupport::stringPut(int x, int y, std::uint32_t color, std::string str)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::pair<DrawableResource*, bool> res = _text_manager.registerText(x, y, color, str);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace mlx
|
||||
_yRel = _event.motion.yrel;
|
||||
}
|
||||
|
||||
uint32_t id = _event.window.windowID;
|
||||
std::uint32_t id = _event.window.windowID;
|
||||
if(_events_hooks.find(id) == _events_hooks.end())
|
||||
continue;
|
||||
auto& hooks = _events_hooks[id];
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/16 07:59:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 07:51:55 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace mlx
|
||||
inline int getXRel() const noexcept { return _xRel; }
|
||||
inline int getYRel() const noexcept { return _yRel; }
|
||||
|
||||
inline bool is_running() const noexcept { return !_end; }
|
||||
inline bool isRunning() const noexcept { return !_end; }
|
||||
inline constexpr void finish() noexcept { _end = true; }
|
||||
|
||||
inline void addWindow(std::shared_ptr<MLX_Window> window)
|
||||
@@ -53,7 +53,7 @@ namespace mlx
|
||||
_events_hooks[window->getID()] = {};
|
||||
}
|
||||
|
||||
inline void onEvent(uint32_t id, int event, int (*funct_ptr)(int, void*), void* param) noexcept
|
||||
inline void onEvent(std::uint32_t id, int event, int (*funct_ptr)(int, void*), void* param) noexcept
|
||||
{
|
||||
_events_hooks[id][event].hook = funct_ptr;
|
||||
_events_hooks[id][event].param = param;
|
||||
@@ -62,8 +62,8 @@ namespace mlx
|
||||
~Input() = default;
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32_t, std::shared_ptr<MLX_Window>> _windows;
|
||||
std::unordered_map<uint32_t, std::array<Hook, 6>> _events_hooks;
|
||||
std::unordered_map<std::uint32_t, std::shared_ptr<MLX_Window>> _windows;
|
||||
std::unordered_map<std::uint32_t, std::array<Hook, 6>> _events_hooks;
|
||||
SDL_Event _event;
|
||||
|
||||
int _x = 0;
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
namespace mlx
|
||||
{
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
constexpr const uint32_t rmask = 0xff000000;
|
||||
constexpr const uint32_t gmask = 0x00ff0000;
|
||||
constexpr const uint32_t bmask = 0x0000ff00;
|
||||
constexpr const uint32_t amask = 0x000000ff;
|
||||
constexpr const std::uint32_t rmask = 0xff000000;
|
||||
constexpr const std::uint32_t gmask = 0x00ff0000;
|
||||
constexpr const std::uint32_t bmask = 0x0000ff00;
|
||||
constexpr const std::uint32_t amask = 0x000000ff;
|
||||
#else
|
||||
constexpr const uint32_t rmask = 0x000000ff;
|
||||
constexpr const uint32_t gmask = 0x0000ff00;
|
||||
constexpr const uint32_t bmask = 0x00ff0000;
|
||||
constexpr const uint32_t amask = 0xff000000;
|
||||
constexpr const std::uint32_t rmask = 0x000000ff;
|
||||
constexpr const std::uint32_t gmask = 0x0000ff00;
|
||||
constexpr const std::uint32_t bmask = 0x00ff0000;
|
||||
constexpr const std::uint32_t amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace mlx
|
||||
inline SDL_Window* getNativeWindow() const noexcept { return _win; }
|
||||
inline int getWidth() const noexcept { return _width; }
|
||||
inline int getHeight() const noexcept { return _height; }
|
||||
inline uint32_t getID() const noexcept { return _id; }
|
||||
inline std::uint32_t getID() const noexcept { return _id; }
|
||||
|
||||
void destroy() noexcept;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mlx
|
||||
SDL_Window* _win = nullptr;
|
||||
int _width = 0;
|
||||
int _height = 0;
|
||||
uint32_t _id = -1;
|
||||
std::uint32_t _id = -1;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace mlx
|
||||
class C_IBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
|
||||
inline void create(std::uint32_t size, const std::uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindIndexBuffer(*this); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void UBO::create(Renderer* renderer, uint32_t size, [[maybe_unused]] const char* name)
|
||||
void UBO::create(Renderer* renderer, std::uint32_t size, [[maybe_unused]] const char* name)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_renderer = renderer;
|
||||
@@ -37,16 +37,16 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
void UBO::setData(uint32_t size, const void* data)
|
||||
void UBO::setData(std::uint32_t size, const void* data)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<size_t>(size));
|
||||
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<std::size_t>(size));
|
||||
}
|
||||
|
||||
void UBO::setDynamicData(uint32_t size, const void* data)
|
||||
void UBO::setDynamicData(std::uint32_t size, const void* data)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<size_t>(size));
|
||||
std::memcpy(_maps[_renderer->getActiveImageIndex()], data, static_cast<std::size_t>(size));
|
||||
_buffers[_renderer->getActiveImageIndex()].flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace mlx
|
||||
class UBO
|
||||
{
|
||||
public:
|
||||
void create(class Renderer* renderer, uint32_t size, const char* name);
|
||||
void create(class Renderer* renderer, std::uint32_t size, const char* name);
|
||||
|
||||
void setData(uint32_t size, const void* data);
|
||||
void setDynamicData(uint32_t size, const void* data);
|
||||
void setData(std::uint32_t size, const void* data);
|
||||
void setDynamicData(std::uint32_t size, const void* data);
|
||||
|
||||
void destroy() noexcept;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void VBO::setData(uint32_t size, const void* data)
|
||||
void VBO::setData(std::uint32_t size, const void* data)
|
||||
{
|
||||
if(size > getSize())
|
||||
{
|
||||
@@ -28,11 +28,11 @@ namespace mlx
|
||||
|
||||
void* temp = nullptr;
|
||||
mapMem(&temp);
|
||||
std::memcpy(temp, data, static_cast<size_t>(size));
|
||||
std::memcpy(temp, data, static_cast<std::size_t>(size));
|
||||
unmapMem();
|
||||
}
|
||||
|
||||
void D_VBO::setData(uint32_t size, const void* data)
|
||||
void D_VBO::setData(std::uint32_t size, const void* data)
|
||||
{
|
||||
if(size > getSize())
|
||||
{
|
||||
|
||||
@@ -22,23 +22,23 @@ namespace mlx
|
||||
class VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
void setData(uint32_t size, const void* data);
|
||||
inline void create(std::uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
void setData(std::uint32_t size, const void* data);
|
||||
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindVertexBuffer(*this); }
|
||||
};
|
||||
|
||||
class D_VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic_device_local, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
void setData(uint32_t size, const void* data);
|
||||
inline void create(std::uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::dynamic_device_local, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
void setData(std::uint32_t size, const void* data);
|
||||
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindVertexBuffer(*this); }
|
||||
};
|
||||
|
||||
class C_VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
inline void create(std::uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindVertexBuffer(*this); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace mlx
|
||||
|
||||
~SingleTimeCmdManager() = default;
|
||||
|
||||
inline static constexpr const uint8_t BASE_POOL_SIZE = 16;
|
||||
inline static constexpr const std::uint8_t BASE_POOL_SIZE = 16;
|
||||
|
||||
private:
|
||||
std::vector<CmdBuffer> _buffers;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/10 18:30:04 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 08:02:26 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate a buffer, %s", RCore::verbaliseResultVk(res));
|
||||
if(name != nullptr)
|
||||
{
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_BUFFER, (uint64_t)buffer, name);
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_BUFFER, (std::uint64_t)buffer, name);
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@@ -124,7 +124,7 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : failed to allocate an image, %s", RCore::verbaliseResultVk(res));
|
||||
if(name != nullptr)
|
||||
{
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_IMAGE, (uint64_t)image, name);
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_IMAGE, (std::uint64_t)image, name);
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@@ -161,7 +161,7 @@ namespace mlx
|
||||
|
||||
void GPUallocator::dumpMemoryToJson()
|
||||
{
|
||||
static uint32_t id = 0;
|
||||
static std::uint32_t id = 0;
|
||||
std::string name("memory_dump");
|
||||
name.append(std::to_string(id) + ".json");
|
||||
std::ofstream file(name);
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace mlx
|
||||
|
||||
private:
|
||||
VmaAllocator _allocator;
|
||||
uint32_t _active_buffers_allocations = 0;
|
||||
uint32_t _active_images_allocations = 0;
|
||||
std::uint32_t _active_buffers_allocations = 0;
|
||||
std::uint32_t _active_images_allocations = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace mlx
|
||||
{
|
||||
namespace RCore
|
||||
{
|
||||
std::optional<uint32_t> findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error)
|
||||
std::optional<std::uint32_t> findMemoryType(std::uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error)
|
||||
{
|
||||
VkPhysicalDeviceMemoryProperties memProperties;
|
||||
vkGetPhysicalDeviceMemoryProperties(Render_Core::get().getDevice().getPhysicalDevice(), &memProperties);
|
||||
|
||||
for(uint32_t i = 0; i < memProperties.memoryTypeCount; i++)
|
||||
for(std::uint32_t i = 0; i < memProperties.memoryTypeCount; i++)
|
||||
{
|
||||
if((typeFilter & (1 << i)) && (memProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
return i;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace mlx
|
||||
{
|
||||
namespace RCore
|
||||
{
|
||||
std::optional<uint32_t> findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error = true);
|
||||
std::optional<std::uint32_t> findMemoryType(std::uint32_t typeFilter, VkMemoryPropertyFlags properties, bool error = true);
|
||||
const char* verbaliseResultVk(VkResult result);
|
||||
VkPipelineStageFlags accessFlagsToPipelineStage(VkAccessFlags accessFlags, VkPipelineStageFlags stageFlags);
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace mlx
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().getFamilies();
|
||||
|
||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
||||
std::set<uint32_t> uniqueQueueFamilies = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
||||
std::set<std::uint32_t> uniqueQueueFamilies = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
||||
|
||||
float queuePriority = 1.0f;
|
||||
for(uint32_t queueFamily : uniqueQueueFamilies)
|
||||
for(std::uint32_t queueFamily : uniqueQueueFamilies)
|
||||
{
|
||||
VkDeviceQueueCreateInfo queueCreateInfo{};
|
||||
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||
@@ -49,12 +49,12 @@ namespace mlx
|
||||
VkDeviceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
|
||||
createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());
|
||||
createInfo.queueCreateInfoCount = static_cast<std::uint32_t>(queueCreateInfos.size());
|
||||
createInfo.pQueueCreateInfos = queueCreateInfos.data();
|
||||
|
||||
createInfo.pEnabledFeatures = &deviceFeatures;
|
||||
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size());
|
||||
createInfo.enabledExtensionCount = static_cast<std::uint32_t>(deviceExtensions.size());
|
||||
createInfo.ppEnabledExtensionNames = deviceExtensions.data();
|
||||
createInfo.enabledLayerCount = 0;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace mlx
|
||||
|
||||
void Device::pickPhysicalDevice()
|
||||
{
|
||||
uint32_t deviceCount = 0;
|
||||
std::uint32_t deviceCount = 0;
|
||||
vkEnumeratePhysicalDevices(Render_Core::get().getInstance().get(), &deviceCount, nullptr);
|
||||
|
||||
if(deviceCount == 0)
|
||||
@@ -113,7 +113,7 @@ namespace mlx
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(device, surface);
|
||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||
|
||||
uint32_t formatCount = 0;
|
||||
std::uint32_t formatCount = 0;
|
||||
if(extensionsSupported)
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace mlx
|
||||
|
||||
bool Device::checkDeviceExtensionSupport(VkPhysicalDevice device)
|
||||
{
|
||||
uint32_t extensionCount;
|
||||
std::uint32_t extensionCount;
|
||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
||||
|
||||
std::vector<VkExtensionProperties> availableExtensions(extensionCount);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:53:06 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/06 16:57:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 08:02:45 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/02/24 04:31:00 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/24 21:10:32 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mlx
|
||||
VkApplicationInfo appInfo{};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pEngineName = "MacroLibX";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 2, 1);
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 3, 1);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_2;
|
||||
|
||||
auto extensions = getRequiredExtensions();
|
||||
@@ -30,7 +30,7 @@ namespace mlx
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
createInfo.enabledExtensionCount = static_cast<std::uint32_t>(extensions.size());
|
||||
createInfo.ppEnabledExtensionNames = extensions.data();
|
||||
createInfo.enabledLayerCount = 0; // will be replaced if validation layers are enabled
|
||||
createInfo.pNext = nullptr;
|
||||
@@ -40,7 +40,7 @@ namespace mlx
|
||||
{
|
||||
if(Render_Core::get().getLayers().checkValidationLayerSupport())
|
||||
{
|
||||
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
|
||||
createInfo.enabledLayerCount = static_cast<std::uint32_t>(validationLayers.size());
|
||||
createInfo.ppEnabledLayerNames = validationLayers.data();
|
||||
Render_Core::get().getLayers().populateDebugMessengerCreateInfo(debugCreateInfo);
|
||||
createInfo.pNext = static_cast<VkDebugUtilsMessengerCreateInfoEXT*>(&debugCreateInfo);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace mlx
|
||||
{
|
||||
Queues::QueueFamilyIndices Queues::findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface)
|
||||
{
|
||||
uint32_t queueFamilyCount = 0;
|
||||
std::uint32_t queueFamilyCount = 0;
|
||||
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
|
||||
|
||||
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace mlx
|
||||
public:
|
||||
struct QueueFamilyIndices
|
||||
{
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
std::optional<std::uint32_t> graphicsFamily;
|
||||
std::optional<std::uint32_t> presentFamily;
|
||||
|
||||
inline bool isComplete() { return graphicsFamily.has_value() && presentFamily.has_value(); }
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace mlx
|
||||
if constexpr(!enableValidationLayers)
|
||||
return;
|
||||
|
||||
uint32_t extensionCount;
|
||||
std::uint32_t extensionCount;
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
||||
std::vector<VkExtensionProperties> extensions(extensionCount);
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data());
|
||||
@@ -56,7 +56,7 @@ namespace mlx
|
||||
|
||||
bool ValidationLayers::checkValidationLayerSupport()
|
||||
{
|
||||
uint32_t layerCount;
|
||||
std::uint32_t layerCount;
|
||||
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
|
||||
std::vector<VkLayerProperties> availableLayers(layerCount);
|
||||
@@ -73,7 +73,7 @@ namespace mlx
|
||||
});
|
||||
}
|
||||
|
||||
VkResult ValidationLayers::setDebugUtilsObjectNameEXT(VkObjectType object_type, uint64_t object_handle, const char* object_name)
|
||||
VkResult ValidationLayers::setDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name)
|
||||
{
|
||||
if(!real_vkSetDebugUtilsObjectNameEXT)
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace mlx
|
||||
bool checkValidationLayerSupport();
|
||||
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
|
||||
|
||||
VkResult setDebugUtilsObjectNameEXT(VkObjectType object_type, uint64_t object_handle, const char* object_name);
|
||||
VkResult setDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name);
|
||||
|
||||
~ValidationLayers() = default;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace mlx
|
||||
VkDescriptorSetAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
allocInfo.descriptorPool = _pool->get();
|
||||
allocInfo.descriptorSetCount = static_cast<uint32_t>(MAX_FRAMES_IN_FLIGHT);
|
||||
allocInfo.descriptorSetCount = static_cast<std::uint32_t>(MAX_FRAMES_IN_FLIGHT);
|
||||
allocInfo.pSetLayouts = layouts.data();
|
||||
|
||||
VkResult res = vkAllocateDescriptorSets(device, &allocInfo, _desc_set.data());
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
void Texture::create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
||||
@@ -45,15 +45,15 @@ namespace mlx
|
||||
{{0, height}, {1.f, 1.f, 1.f, 1.f}, {0.0f, 1.0f}}
|
||||
};
|
||||
|
||||
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||
std::vector<std::uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
#ifdef DEBUG
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), name);
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), name);
|
||||
_ibo.create(sizeof(std::uint16_t) * indexData.size(), indexData.data(), name);
|
||||
_name = name;
|
||||
#else
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), nullptr);
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), nullptr);
|
||||
_ibo.create(sizeof(std::uint16_t) * indexData.size(), indexData.data(), nullptr);
|
||||
#endif
|
||||
|
||||
Buffer staging_buffer;
|
||||
@@ -68,7 +68,7 @@ namespace mlx
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<uint32_t> default_pixels(width * height, 0x00000000);
|
||||
std::vector<std::uint32_t> default_pixels(width * height, 0x00000000);
|
||||
#ifdef DEBUG
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, name, default_pixels.data());
|
||||
#else
|
||||
@@ -79,10 +79,10 @@ namespace mlx
|
||||
staging_buffer.destroy();
|
||||
}
|
||||
|
||||
void Texture::setPixel(int x, int y, uint32_t color) noexcept
|
||||
void Texture::setPixel(int x, int y, std::uint32_t color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(x < 0 || y < 0 || static_cast<uint32_t>(x) > getWidth() || static_cast<uint32_t>(y) > getHeight())
|
||||
if(x < 0 || y < 0 || static_cast<std::uint32_t>(x) > getWidth() || static_cast<std::uint32_t>(y) > getHeight())
|
||||
return;
|
||||
if(_map == nullptr)
|
||||
openCPUmap();
|
||||
@@ -93,13 +93,13 @@ namespace mlx
|
||||
int Texture::getPixel(int x, int y) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(x < 0 || y < 0 || static_cast<uint32_t>(x) > getWidth() || static_cast<uint32_t>(y) > getHeight())
|
||||
if(x < 0 || y < 0 || static_cast<std::uint32_t>(x) > getWidth() || static_cast<std::uint32_t>(y) > getHeight())
|
||||
return 0;
|
||||
if(_map == nullptr)
|
||||
openCPUmap();
|
||||
uint32_t color = _cpu_map[(y * getWidth()) + x];
|
||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(&color);
|
||||
uint8_t tmp = bytes[0];
|
||||
std::uint32_t color = _cpu_map[(y * getWidth()) + x];
|
||||
std::uint8_t* bytes = reinterpret_cast<std::uint8_t*>(&color);
|
||||
std::uint8_t tmp = bytes[0];
|
||||
bytes[0] = bytes[2];
|
||||
bytes[2] = tmp;
|
||||
return *reinterpret_cast<int*>(bytes);
|
||||
@@ -123,7 +123,7 @@ namespace mlx
|
||||
#endif
|
||||
Image::copyToBuffer(*_buf_map);
|
||||
_buf_map->mapMem(&_map);
|
||||
_cpu_map = std::vector<uint32_t>(getWidth() * getHeight(), 0);
|
||||
_cpu_map = std::vector<std::uint32_t>(getWidth() * getHeight(), 0);
|
||||
std::memcpy(_cpu_map.data(), _map, size);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Texture : mapped CPU memory using staging buffer");
|
||||
@@ -152,7 +152,7 @@ namespace mlx
|
||||
vkCmdPushConstants(cmd.get(), renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
|
||||
sets[1] = _set.get();
|
||||
vkCmdBindDescriptorSets(renderer.getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, renderer.getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
vkCmdDrawIndexed(cmd.get(), static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
||||
vkCmdDrawIndexed(cmd.get(), static_cast<std::uint32_t>(_ibo.getSize() / sizeof(std::uint16_t)), 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Texture::destroy() noexcept
|
||||
@@ -171,7 +171,7 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Texture texture;
|
||||
int channels;
|
||||
uint8_t* data = nullptr;
|
||||
std::uint8_t* data = nullptr;
|
||||
std::string filename = file.string();
|
||||
|
||||
if(!std::filesystem::exists(std::move(file)))
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace mlx
|
||||
public:
|
||||
Texture() = default;
|
||||
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer, int x, int y);
|
||||
void destroy() noexcept override;
|
||||
|
||||
void setPixel(int x, int y, uint32_t color) noexcept;
|
||||
void setPixel(int x, int y, std::uint32_t color) noexcept;
|
||||
int getPixel(int x, int y) noexcept;
|
||||
|
||||
inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; }
|
||||
@@ -56,7 +56,7 @@ namespace mlx
|
||||
std::string _name;
|
||||
#endif
|
||||
DescriptorSet _set;
|
||||
std::vector<uint32_t> _cpu_map;
|
||||
std::vector<std::uint32_t> _cpu_map;
|
||||
std::optional<Buffer> _buf_map = std::nullopt;
|
||||
void* _map = nullptr;
|
||||
bool _has_been_modified = false;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void TextureAtlas::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
void TextureAtlas::create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
{
|
||||
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
@@ -39,13 +39,13 @@ namespace mlx
|
||||
staging_buffer.destroy();
|
||||
}
|
||||
|
||||
void TextureAtlas::render(Renderer& renderer, int x, int y, uint32_t ibo_size) const
|
||||
void TextureAtlas::render(Renderer& renderer, int x, int y, std::uint32_t ibo_size) const
|
||||
{
|
||||
auto cmd = renderer.getActiveCmdBuffer().get();
|
||||
|
||||
glm::vec2 translate(x, y);
|
||||
vkCmdPushConstants(cmd, renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
|
||||
vkCmdDrawIndexed(cmd, ibo_size / sizeof(uint16_t), 1, 0, 0, 0);
|
||||
vkCmdDrawIndexed(cmd, ibo_size / sizeof(std::uint16_t), 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
void TextureAtlas::destroy() noexcept
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace mlx
|
||||
public:
|
||||
TextureAtlas() = default;
|
||||
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void render(class Renderer& renderer, int x, int y, uint32_t ibo_size) const;
|
||||
void create(std::uint8_t* pixels, std::uint32_t width, std::uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void render(class Renderer& renderer, int x, int y, std::uint32_t ibo_size) const;
|
||||
void destroy() noexcept override;
|
||||
|
||||
inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 09:47:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 08:03:47 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
VkFormat bitsToFormat(uint32_t bits)
|
||||
VkFormat bitsToFormat(std::uint32_t bits)
|
||||
{
|
||||
switch(bits)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ namespace mlx
|
||||
return accessMask;
|
||||
}
|
||||
|
||||
void Image::create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool dedicated_memory)
|
||||
void Image::create(std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool dedicated_memory)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
@@ -153,7 +153,7 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image view, %s", RCore::verbaliseResultVk(res));
|
||||
#ifdef DEBUG
|
||||
else
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t)_image_view, _name.c_str());
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_IMAGE_VIEW, (std::uint64_t)_image_view, _name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image sampler, %s", RCore::verbaliseResultVk(res));
|
||||
#ifdef DEBUG
|
||||
else
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_SAMPLER, (uint64_t)_sampler, _name.c_str());
|
||||
Render_Core::get().getLayers().setDebugUtilsObjectNameEXT(VK_OBJECT_TYPE_SAMPLER, (std::uint64_t)_sampler, _name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace mlx
|
||||
//CmdResource::requireDestroy();
|
||||
}
|
||||
|
||||
uint32_t formatSize(VkFormat format)
|
||||
std::uint32_t formatSize(VkFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
uint32_t formatSize(VkFormat format);
|
||||
std::uint32_t formatSize(VkFormat format);
|
||||
bool isStencilFormat(VkFormat format);
|
||||
bool isDepthFormat(VkFormat format);
|
||||
VkFormat bitsToFormat(uint32_t bits);
|
||||
VkFormat bitsToFormat(std::uint32_t bits);
|
||||
VkPipelineStageFlags layoutToAccessMask(VkImageLayout layout, bool isDestination);
|
||||
|
||||
class Image : public CmdResource
|
||||
@@ -39,7 +39,7 @@ namespace mlx
|
||||
public:
|
||||
Image() = default;
|
||||
|
||||
inline void create(VkImage image, VkFormat format, uint32_t width, uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept
|
||||
inline void create(VkImage image, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept
|
||||
{
|
||||
_image = image;
|
||||
_format = format;
|
||||
@@ -47,7 +47,7 @@ namespace mlx
|
||||
_height = height;
|
||||
_layout = layout;
|
||||
}
|
||||
void create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool decated_memory = false);
|
||||
void create(std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool decated_memory = false);
|
||||
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
|
||||
void createSampler() noexcept;
|
||||
void copyFromBuffer(class Buffer& buffer);
|
||||
@@ -62,8 +62,8 @@ namespace mlx
|
||||
inline VkImageTiling getTiling() const noexcept { return _tiling; }
|
||||
inline VkImageLayout getLayout() const noexcept { return _layout; }
|
||||
inline VkSampler getSampler() const noexcept { return _sampler; }
|
||||
inline uint32_t getWidth() const noexcept { return _width; }
|
||||
inline uint32_t getHeight() const noexcept { return _height; }
|
||||
inline std::uint32_t getWidth() const noexcept { return _width; }
|
||||
inline std::uint32_t getHeight() const noexcept { return _height; }
|
||||
inline bool isInit() const noexcept { return _image != VK_NULL_HANDLE; }
|
||||
|
||||
virtual ~Image() = default;
|
||||
@@ -83,8 +83,8 @@ namespace mlx
|
||||
VkFormat _format;
|
||||
VkImageTiling _tiling;
|
||||
VkImageLayout _layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
uint32_t _width = 0;
|
||||
uint32_t _height = 0;
|
||||
std::uint32_t _width = 0;
|
||||
std::uint32_t _height = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace mlx
|
||||
gl_Position = uProj.mat * vec4(pos.x, pos.y, 0.0, 1.0);
|
||||
}
|
||||
*/
|
||||
const std::vector<uint32_t> vertex_shader = { // precompiled vertex shader
|
||||
const std::vector<std::uint32_t> vertex_shader = { // precompiled vertex shader
|
||||
0x07230203,0x00010000,0x0008000b,0x0000003b,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
|
||||
@@ -124,7 +124,7 @@ namespace mlx
|
||||
fColor = process_color;
|
||||
}
|
||||
*/
|
||||
const std::vector<uint32_t> fragment_shader = { // pre compiled fragment shader
|
||||
const std::vector<std::uint32_t> fragment_shader = { // pre compiled fragment shader
|
||||
0x07230203,0x00010000,0x0008000b,0x0000002c,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000d,0x0000002a,0x00030010,
|
||||
@@ -164,7 +164,7 @@ namespace mlx
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = vertex_shader.size() * sizeof(uint32_t);
|
||||
createInfo.codeSize = vertex_shader.size() * sizeof(std::uint32_t);
|
||||
createInfo.pCode = vertex_shader.data();
|
||||
VkShaderModule vshader;
|
||||
if(vkCreateShaderModule(Render_Core::get().getDevice().get(), &createInfo, nullptr, &vshader) != VK_SUCCESS)
|
||||
@@ -176,7 +176,7 @@ namespace mlx
|
||||
push_constant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = fragment_shader.size() * sizeof(uint32_t);
|
||||
createInfo.codeSize = fragment_shader.size() * sizeof(std::uint32_t);
|
||||
createInfo.pCode = fragment_shader.data();
|
||||
VkShaderModule fshader;
|
||||
if(vkCreateShaderModule(Render_Core::get().getDevice().get(), &createInfo, nullptr, &fshader) != VK_SUCCESS)
|
||||
@@ -203,7 +203,7 @@ namespace mlx
|
||||
vertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
vertexInputStateCreateInfo.vertexBindingDescriptionCount = 1;
|
||||
vertexInputStateCreateInfo.pVertexBindingDescriptions = &bindingDescription;
|
||||
vertexInputStateCreateInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
|
||||
vertexInputStateCreateInfo.vertexAttributeDescriptionCount = static_cast<std::uint32_t>(attributeDescriptions.size());
|
||||
vertexInputStateCreateInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
|
||||
|
||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
|
||||
@@ -213,7 +213,7 @@ namespace mlx
|
||||
|
||||
VkDynamicState states[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
|
||||
constexpr size_t statesCount = sizeof(states) / sizeof(VkDynamicState);
|
||||
constexpr std::size_t statesCount = sizeof(states) / sizeof(VkDynamicState);
|
||||
VkPipelineDynamicStateCreateInfo dynamicStates{};
|
||||
dynamicStates.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
||||
dynamicStates.dynamicStateCount = statesCount;
|
||||
|
||||
@@ -16,20 +16,20 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
|
||||
void PixelPutPipeline::init(std::uint32_t width, std::uint32_t height, Renderer& renderer) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_pixel_put_pipeline_texture", true);
|
||||
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||
|
||||
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "__mlx_pixel_put_pipeline_texture");
|
||||
_buffer.create(Buffer::kind::dynamic, sizeof(std::uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "__mlx_pixel_put_pipeline_texture");
|
||||
_buffer.mapMem(&_buffer_map);
|
||||
_cpu_map = std::vector<uint32_t>(height * width + 1, 0);
|
||||
_cpu_map = std::vector<std::uint32_t>(height * width + 1, 0);
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
void PixelPutPipeline::setPixel(int x, int y, uint32_t color) noexcept
|
||||
void PixelPutPipeline::setPixel(int x, int y, std::uint32_t color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(x < 0 || y < 0 || x > static_cast<int>(_width) || y > static_cast<int>(_height))
|
||||
@@ -50,7 +50,7 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(_has_been_modified)
|
||||
{
|
||||
std::memcpy(_buffer_map, _cpu_map.data(), sizeof(uint32_t) * _cpu_map.size());
|
||||
std::memcpy(_buffer_map, _cpu_map.data(), sizeof(std::uint32_t) * _cpu_map.size());
|
||||
_texture.copyFromBuffer(_buffer);
|
||||
_has_been_modified = false;
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ namespace mlx
|
||||
public:
|
||||
PixelPutPipeline() = default;
|
||||
|
||||
void init(uint32_t width, uint32_t height, class Renderer& renderer) noexcept;
|
||||
void init(std::uint32_t width, std::uint32_t height, class Renderer& renderer) noexcept;
|
||||
|
||||
void setPixel(int x, int y, uint32_t color) noexcept;
|
||||
void setPixel(int x, int y, std::uint32_t color) noexcept;
|
||||
void render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer) noexcept;
|
||||
|
||||
void clear();
|
||||
@@ -38,10 +38,10 @@ namespace mlx
|
||||
Texture _texture;
|
||||
Buffer _buffer;
|
||||
// using vector as CPU map and not directly writting to mapped buffer to improve performances
|
||||
std::vector<uint32_t> _cpu_map;
|
||||
std::vector<std::uint32_t> _cpu_map;
|
||||
void* _buffer_map = nullptr;
|
||||
uint32_t _width = 0;
|
||||
uint32_t _height = 0;
|
||||
std::uint32_t _width = 0;
|
||||
std::uint32_t _height = 0;
|
||||
bool _has_been_modified = true;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/20 08:19:46 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 08:02:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@@ -106,8 +106,8 @@ namespace mlx
|
||||
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
|
||||
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
|
||||
inline DescriptorSetLayout& getFragDescriptorSetLayout() noexcept { return _frag_layout; }
|
||||
inline uint32_t getActiveImageIndex() noexcept { return _current_frame_index; }
|
||||
inline uint32_t getImageIndex() noexcept { return _image_index; }
|
||||
inline std::uint32_t getActiveImageIndex() noexcept { return _current_frame_index; }
|
||||
inline std::uint32_t getImageIndex() noexcept { return _image_index; }
|
||||
|
||||
constexpr inline void requireFrameBufferResize() noexcept { _framebufferResized = true; }
|
||||
|
||||
@@ -136,8 +136,8 @@ namespace mlx
|
||||
class MLX_Window* _window = nullptr;
|
||||
class Texture* _render_target = nullptr;
|
||||
|
||||
uint32_t _current_frame_index = 0;
|
||||
uint32_t _image_index = 0;
|
||||
std::uint32_t _current_frame_index = 0;
|
||||
std::uint32_t _image_index = 0;
|
||||
bool _framebufferResized = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ namespace mlx
|
||||
|
||||
inline VkFramebuffer& operator()() noexcept { return _framebuffer; }
|
||||
inline VkFramebuffer& get() noexcept { return _framebuffer; }
|
||||
inline uint32_t getWidth() const noexcept { return _width; }
|
||||
inline uint32_t getHeight() const noexcept { return _height; }
|
||||
inline std::uint32_t getWidth() const noexcept { return _width; }
|
||||
inline std::uint32_t getHeight() const noexcept { return _height; }
|
||||
|
||||
private:
|
||||
VkFramebuffer _framebuffer = VK_NULL_HANDLE;
|
||||
uint32_t _width = 0;
|
||||
uint32_t _height = 0;
|
||||
std::uint32_t _width = 0;
|
||||
std::uint32_t _height = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace mlx
|
||||
renderPassInfo.pAttachments = &colorAttachment;
|
||||
renderPassInfo.subpassCount = sizeof(subpasses) / sizeof(VkSubpassDescription);
|
||||
renderPassInfo.pSubpasses = subpasses;
|
||||
renderPassInfo.dependencyCount = static_cast<uint32_t>(subpassesDeps.size());
|
||||
renderPassInfo.dependencyCount = static_cast<std::uint32_t>(subpassesDeps.size());
|
||||
renderPassInfo.pDependencies = subpassesDeps.data();
|
||||
|
||||
VkResult res = vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_renderPass);
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace mlx
|
||||
VkPresentModeKHR presentMode = chooseSwapPresentMode(_swapChainSupport.presentModes);
|
||||
_extent = chooseSwapExtent(_swapChainSupport.capabilities);
|
||||
|
||||
uint32_t imageCount = _swapChainSupport.capabilities.minImageCount + 1;
|
||||
std::uint32_t imageCount = _swapChainSupport.capabilities.minImageCount + 1;
|
||||
if(_swapChainSupport.capabilities.maxImageCount > 0 && imageCount > _swapChainSupport.capabilities.maxImageCount)
|
||||
imageCount = _swapChainSupport.capabilities.maxImageCount;
|
||||
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), renderer->getSurface().get());
|
||||
uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
||||
std::uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
||||
|
||||
VkSwapchainCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
@@ -90,7 +90,7 @@ namespace mlx
|
||||
if(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : unable to retrieve surface capabilities");
|
||||
|
||||
uint32_t formatCount = 0;
|
||||
std::uint32_t formatCount = 0;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
|
||||
if(formatCount != 0)
|
||||
@@ -99,7 +99,7 @@ namespace mlx
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
|
||||
}
|
||||
|
||||
uint32_t presentModeCount;
|
||||
std::uint32_t presentModeCount;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
|
||||
|
||||
if(presentModeCount != 0)
|
||||
@@ -119,13 +119,13 @@ namespace mlx
|
||||
|
||||
VkExtent2D SwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities)
|
||||
{
|
||||
if(capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
||||
if(capabilities.currentExtent.width != std::numeric_limits<std::uint32_t>::max())
|
||||
return capabilities.currentExtent;
|
||||
|
||||
int width, height;
|
||||
SDL_Vulkan_GetDrawableSize(_renderer->getWindow()->getNativeWindow(), &width, &height);
|
||||
|
||||
VkExtent2D actualExtent = { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
|
||||
VkExtent2D actualExtent = { static_cast<std::uint32_t>(width), static_cast<std::uint32_t>(height) };
|
||||
|
||||
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace mlx
|
||||
|
||||
inline VkSwapchainKHR get() noexcept { return _swapChain; }
|
||||
inline VkSwapchainKHR operator()() noexcept { return _swapChain; }
|
||||
inline size_t getImagesNumber() const noexcept { return _images.size(); }
|
||||
inline std::size_t getImagesNumber() const noexcept { return _images.size(); }
|
||||
inline Image& getImage(std::size_t i) noexcept { return _images[i]; }
|
||||
inline SwapChainSupportDetails getSupport() noexcept { return _swapChainSupport; }
|
||||
inline VkExtent2D getExtent() noexcept { return _extent; }
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace mlx
|
||||
_build_data = path;
|
||||
}
|
||||
|
||||
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale) : _name(name), _renderer(renderer), _scale(scale)
|
||||
Font::Font(class Renderer& renderer, const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale) : _name(name), _renderer(renderer), _scale(scale)
|
||||
{
|
||||
_build_data = ttf_data;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace mlx
|
||||
void Font::buildFont()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::vector<uint8_t> file_bytes;
|
||||
std::vector<std::uint8_t> file_bytes;
|
||||
if(std::holds_alternative<std::filesystem::path>(_build_data))
|
||||
{
|
||||
std::ifstream file(std::get<std::filesystem::path>(_build_data), std::ios::binary);
|
||||
@@ -48,14 +48,14 @@ namespace mlx
|
||||
file.close();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> tmp_bitmap(RANGE * RANGE);
|
||||
std::vector<uint8_t> vulkan_bitmap(RANGE * RANGE * 4);
|
||||
std::vector<std::uint8_t> tmp_bitmap(RANGE * RANGE);
|
||||
std::vector<std::uint8_t> vulkan_bitmap(RANGE * RANGE * 4);
|
||||
stbtt_pack_context pc;
|
||||
stbtt_PackBegin(&pc, tmp_bitmap.data(), RANGE, RANGE, RANGE, 1, nullptr);
|
||||
if(std::holds_alternative<std::filesystem::path>(_build_data))
|
||||
stbtt_PackFontRange(&pc, file_bytes.data(), 0, _scale, 32, 96, _cdata.data());
|
||||
else
|
||||
stbtt_PackFontRange(&pc, std::get<std::vector<uint8_t>>(_build_data).data(), 0, _scale, 32, 96, _cdata.data());
|
||||
stbtt_PackFontRange(&pc, std::get<std::vector<std::uint8_t>>(_build_data).data(), 0, _scale, 32, 96, _cdata.data());
|
||||
stbtt_PackEnd(&pc);
|
||||
for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace mlx
|
||||
public:
|
||||
Font() = delete;
|
||||
Font(class Renderer& renderer, const std::filesystem::path& path, float scale);
|
||||
Font(class Renderer& renderer, const std::string& name, const std::vector<uint8_t>& ttf_data, float scale);
|
||||
Font(class Renderer& renderer, const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale);
|
||||
|
||||
inline const std::string& getName() const { return _name; }
|
||||
inline float getScale() const noexcept { return _scale; }
|
||||
@@ -45,7 +45,7 @@ namespace mlx
|
||||
private:
|
||||
std::array<stbtt_packedchar, 96> _cdata;
|
||||
TextureAtlas _atlas;
|
||||
std::variant<std::filesystem::path, std::vector<uint8_t>> _build_data;
|
||||
std::variant<std::filesystem::path, std::vector<std::uint8_t>> _build_data;
|
||||
std::string _name;
|
||||
class Renderer& _renderer;
|
||||
float _scale = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
using FontID = uint32_t;
|
||||
using FontID = std::uint32_t;
|
||||
constexpr FontID nullfont = 0;
|
||||
|
||||
class FontLibrary : public Singleton<FontLibrary>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Text::init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
|
||||
void Text::init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_text = std::move(text);
|
||||
@@ -30,11 +30,11 @@ namespace mlx
|
||||
}
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), debug_name.c_str());
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), debug_name.c_str());
|
||||
_ibo.create(sizeof(std::uint16_t) * ibo_data.size(), ibo_data.data(), debug_name.c_str());
|
||||
#else
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_vbo[i].create(sizeof(Vertex) * vbo_data.size(), static_cast<const void*>(vbo_data.data()), nullptr);
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), nullptr);
|
||||
_ibo.create(sizeof(std::uint16_t) * ibo_data.size(), ibo_data.data(), nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ namespace mlx
|
||||
public:
|
||||
Text() = default;
|
||||
|
||||
void init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data);
|
||||
void init(std::string text, FontID font, std::vector<Vertex> vbo_data, std::vector<std::uint16_t> ibo_data);
|
||||
void bind(class Renderer& renderer) noexcept;
|
||||
inline FontID getFontInUse() const noexcept { return _font; }
|
||||
void updateVertexData(int frame, std::vector<Vertex> vbo_data);
|
||||
inline uint32_t getIBOsize() noexcept { return _ibo.getSize(); }
|
||||
inline std::uint32_t getIBOsize() noexcept { return _ibo.getSize(); }
|
||||
inline const std::string& getText() const { return _text; }
|
||||
void destroy() noexcept;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 00:23:11 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 09:44:54 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 07:58:21 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -30,14 +30,14 @@ constexpr const int RANGE = 1024;
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
TextDrawDescriptor::TextDrawDescriptor(std::string text, uint32_t _color, int _x, int _y) : color(_color), x(_x), y(_y), _text(std::move(text))
|
||||
TextDrawDescriptor::TextDrawDescriptor(std::string text, std::uint32_t _color, int _x, int _y) : color(_color), x(_x), y(_y), _text(std::move(text))
|
||||
{}
|
||||
|
||||
void TextDrawDescriptor::init(FontID font) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::vector<Vertex> vertexData;
|
||||
std::vector<uint16_t> indexData;
|
||||
std::vector<std::uint16_t> indexData;
|
||||
|
||||
float stb_x = 0.0f;
|
||||
float stb_y = 0.0f;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 00:13:34 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 09:40:06 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 07:58:13 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -30,12 +30,12 @@ namespace mlx
|
||||
|
||||
public:
|
||||
TextID id;
|
||||
uint32_t color;
|
||||
std::uint32_t color;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
public:
|
||||
TextDrawDescriptor(std::string text, uint32_t _color, int _x, int _y);
|
||||
TextDrawDescriptor(std::string text, std::uint32_t _color, int _x, int _y);
|
||||
|
||||
void init(FontID font) noexcept;
|
||||
bool operator==(const TextDrawDescriptor& rhs) const { return _text == rhs._text && x == rhs.x && y == rhs.y && color == rhs.color; }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 08:02:31 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/24 21:38:11 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <renderer/renderer.h>
|
||||
#include <algorithm>
|
||||
#include <core/profiler.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -49,6 +50,7 @@ namespace mlx
|
||||
core::error::report(e_kind::warning, "Text Library : trying to remove a text with an unkown or invalid ID '%d'", id);
|
||||
return;
|
||||
}
|
||||
std::cout << _cache[id]->getText() << std::endl;
|
||||
_cache[id]->destroy();
|
||||
_invalid_ids.push_back(id);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
using TextID = uint32_t;
|
||||
using TextID = std::uint32_t;
|
||||
constexpr TextID nulltext = 0;
|
||||
|
||||
class TextLibrary : public Singleton<TextLibrary>
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 09:45:24 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/24 21:39:12 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include <renderer/texts/text_descriptor.h>
|
||||
#include <renderer/texts/text_library.h>
|
||||
#include <renderer/texts/text.h>
|
||||
@@ -38,7 +39,7 @@ namespace mlx
|
||||
_font_in_use = FontLibrary::get().addFontToLibrary(font);
|
||||
}
|
||||
|
||||
std::pair<DrawableResource*, bool> TextManager::registerText(int x, int y, uint32_t color, std::string str)
|
||||
std::pair<DrawableResource*, bool> TextManager::registerText(int x, int y, std::uint32_t color, std::string str)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto res = _text_descriptors.emplace(std::move(str), color, x, y);
|
||||
@@ -52,6 +53,7 @@ namespace mlx
|
||||
if(_font_in_use != text_ptr->getFontInUse())
|
||||
{
|
||||
// TODO : update text vertex buffers rather than destroying it and recreating it
|
||||
std::cout << "test" << std::endl;
|
||||
TextLibrary::get().removeTextFromLibrary(res.first->id);
|
||||
const_cast<TextDrawDescriptor&>(*res.first).init(_font_in_use);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/18 13:52:01 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/02/25 07:58:36 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace mlx
|
||||
TextManager() = default;
|
||||
|
||||
void init(Renderer& renderer) noexcept;
|
||||
std::pair<DrawableResource*, bool> registerText(int x, int y, uint32_t color, std::string str);
|
||||
inline void clear() { _text_descriptors.clear(); TextLibrary::get().clearLibrary(); }
|
||||
std::pair<DrawableResource*, bool> registerText(int x, int y, std::uint32_t color, std::string str);
|
||||
inline void clear() { _text_descriptors.clear(); }
|
||||
void loadFont(Renderer& renderer, const std::filesystem::path& filepath, float scale);
|
||||
void destroy() noexcept;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ constexpr const int logo_mlx_height = 125;
|
||||
constexpr const int logo_mlx_width = 125;
|
||||
constexpr const int logo_mlx_size = logo_mlx_height * logo_mlx_width * 4;
|
||||
|
||||
inline static uint8_t logo_mlx[logo_mlx_size] = {
|
||||
inline static std::uint8_t logo_mlx[logo_mlx_size] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
Reference in New Issue
Block a user