mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
adding hidden bindings
This commit is contained in:
@@ -32,16 +32,29 @@ namespace mlx
|
|||||||
|
|
||||||
inline void TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept;
|
inline void TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept;
|
||||||
|
|
||||||
|
inline void AddPreRenderHook(void(*f)(VkCommandBuffer, void*), void* param);
|
||||||
|
|
||||||
[[nodiscard]] MLX_FORCEINLINE bool HasWindow() const noexcept { return m_has_window; }
|
[[nodiscard]] MLX_FORCEINLINE bool HasWindow() const noexcept { return m_has_window; }
|
||||||
[[nodiscard]] MLX_FORCEINLINE Renderer& GetRenderer() { return m_renderer; }
|
[[nodiscard]] MLX_FORCEINLINE Renderer& GetRenderer() { return m_renderer; }
|
||||||
[[nodiscard]] MLX_FORCEINLINE Scene& GetScene() { return *p_scene; }
|
[[nodiscard]] MLX_FORCEINLINE Scene& GetScene() { return *p_scene; }
|
||||||
|
|
||||||
~GraphicsSupport();
|
~GraphicsSupport();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Hook
|
||||||
|
{
|
||||||
|
std::function<void(VkCommandBuffer, void*)> fn;
|
||||||
|
void* param;
|
||||||
|
|
||||||
|
Hook(std::function<void(VkCommandBuffer, void*)> fn, void* param) : fn(fn), param(param) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer m_renderer;
|
Renderer m_renderer;
|
||||||
SceneRenderer m_scene_renderer;
|
SceneRenderer m_scene_renderer;
|
||||||
PutPixelManager m_put_pixel_manager;
|
PutPixelManager m_put_pixel_manager;
|
||||||
|
std::vector<Hook> m_hooks;
|
||||||
std::shared_ptr<Window> p_window;
|
std::shared_ptr<Window> p_window;
|
||||||
std::unique_ptr<Scene> p_scene;
|
std::unique_ptr<Scene> p_scene;
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,9 @@ namespace mlx
|
|||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
p_scene->TryEraseSpriteFromTexture(texture);
|
p_scene->TryEraseSpriteFromTexture(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsSupport::AddPreRenderHook(void(*f)(VkCommandBuffer, void*), void* param)
|
||||||
|
{
|
||||||
|
m_hooks.emplace_back(f, param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -448,6 +448,18 @@ extern "C"
|
|||||||
return mlx::RenderCore::Get().GetDevice();
|
return mlx::RenderCore::Get().GetDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkQueue mlx_get_vk_graphics_queue(mlx_context mlx)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
return kvfGetDeviceQueue(mlx::RenderCore::Get().GetDevice(), KVF_GRAPHICS_QUEUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int mlx_get_vk_graphics_queue_family(mlx_context mlx)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
return kvfGetDeviceQueueFamily(mlx::RenderCore::Get().GetDevice(), KVF_GRAPHICS_QUEUE);
|
||||||
|
}
|
||||||
|
|
||||||
mlx_function mlx_get_vk_fn(const char* name)
|
mlx_function mlx_get_vk_fn(const char* name)
|
||||||
{
|
{
|
||||||
#define MLX_VULKAN_GLOBAL_FUNCTION(fn) if(std::strcmp(name, #fn) == 0) return reinterpret_cast<mlx_function>(mlx::RenderCore::Get().fn);
|
#define MLX_VULKAN_GLOBAL_FUNCTION(fn) if(std::strcmp(name, #fn) == 0) return reinterpret_cast<mlx_function>(mlx::RenderCore::Get().fn);
|
||||||
@@ -461,6 +473,60 @@ extern "C"
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkSurfaceKHR mlx_get_vk_surface(mlx_context mlx, mlx_window win)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs)
|
||||||
|
return nullptr;
|
||||||
|
return gs->GetRenderer().GetSwapchain().GetSurface();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImage mlx_get_vk_swapchain_image(mlx_context mlx, mlx_window win, unsigned int index)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs || index > gs->GetRenderer().GetSwapchain().GetImagesCount())
|
||||||
|
return nullptr;
|
||||||
|
return gs->GetRenderer().GetSwapchain().GetSwapchainImages()[index].Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImageView mlx_get_vk_swapchain_image_view(mlx_context mlx, mlx_window win, unsigned int index)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs || index > gs->GetRenderer().GetSwapchain().GetImagesCount())
|
||||||
|
return nullptr;
|
||||||
|
return gs->GetRenderer().GetSwapchain().GetSwapchainImages()[index].GetImageView();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int mlx_get_current_vk_swapchain_image_index(mlx_context mlx, mlx_window win)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs)
|
||||||
|
return -1;
|
||||||
|
return gs->GetRenderer().GetSwapchain().GetImageIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkExtent2D mlx_get_vk_swapchain_extent(mlx_context mlx, mlx_window win)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs)
|
||||||
|
return {};
|
||||||
|
return kvfGetSwapchainImagesSize(gs->GetRenderer().GetSwapchain().Get());
|
||||||
|
}
|
||||||
|
|
||||||
|
VkFormat mlx_get_vk_swapchain_format(mlx_context mlx, mlx_window win)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs)
|
||||||
|
return VK_FORMAT_UNDEFINED;
|
||||||
|
return kvfGetSwapchainImagesFormat(gs->GetRenderer().GetSwapchain().Get());
|
||||||
|
}
|
||||||
|
|
||||||
void* mlx_get_window_handle(mlx_context mlx, mlx_window win)
|
void* mlx_get_window_handle(mlx_context mlx, mlx_window win)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
@@ -470,6 +536,15 @@ extern "C"
|
|||||||
return mlx::SDLManager::Get().GetRawWindow(gs->GetWindow()->GetRawHandle());
|
return mlx::SDLManager::Get().GetRawWindow(gs->GetWindow()->GetRawHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mlx_add_pre_render_hook(mlx_context mlx, mlx_window win, void(*f)(VkCommandBuffer, void*), void* param)
|
||||||
|
{
|
||||||
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
|
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
|
||||||
|
if(!gs)
|
||||||
|
return;
|
||||||
|
gs->AddPreRenderHook(f, param);
|
||||||
|
}
|
||||||
|
|
||||||
mlx_function mlx_get_proc_addr(mlx_context mlx, const char* name)
|
mlx_function mlx_get_proc_addr(mlx_context mlx, const char* name)
|
||||||
{
|
{
|
||||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||||
@@ -477,9 +552,17 @@ extern "C"
|
|||||||
std::unordered_map<std::string, mlx_function> entries = {
|
std::unordered_map<std::string, mlx_function> entries = {
|
||||||
MLX_MAKE_ENTRY(mlx_get_vk_instance),
|
MLX_MAKE_ENTRY(mlx_get_vk_instance),
|
||||||
MLX_MAKE_ENTRY(mlx_get_vk_physical_device),
|
MLX_MAKE_ENTRY(mlx_get_vk_physical_device),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_graphics_queue),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_graphics_queue_family),
|
||||||
MLX_MAKE_ENTRY(mlx_get_vk_device),
|
MLX_MAKE_ENTRY(mlx_get_vk_device),
|
||||||
MLX_MAKE_ENTRY(mlx_get_vk_fn),
|
MLX_MAKE_ENTRY(mlx_get_vk_fn),
|
||||||
MLX_MAKE_ENTRY(mlx_get_window_handle),
|
MLX_MAKE_ENTRY(mlx_get_window_handle),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_swapchain_extent),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_swapchain_format),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_swapchain_image),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_vk_swapchain_image_view),
|
||||||
|
MLX_MAKE_ENTRY(mlx_get_current_vk_swapchain_image_index),
|
||||||
|
MLX_MAKE_ENTRY(mlx_add_pre_render_hook),
|
||||||
};
|
};
|
||||||
auto it = entries.find(std::string{ name });
|
auto it = entries.find(std::string{ name });
|
||||||
if(it != entries.end())
|
if(it != entries.end())
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ namespace mlx
|
|||||||
m_renderer.BeginFrame();
|
m_renderer.BeginFrame();
|
||||||
m_draw_layer = 0;
|
m_draw_layer = 0;
|
||||||
m_scene_renderer.Render(*p_scene, m_renderer);
|
m_scene_renderer.Render(*p_scene, m_renderer);
|
||||||
|
for(const auto& hook : m_hooks)
|
||||||
|
{
|
||||||
|
if(hook.fn)
|
||||||
|
hook.fn(m_renderer.GetActiveCommandBuffer(), hook.param);
|
||||||
|
}
|
||||||
m_renderer.EndFrame();
|
m_renderer.EndFrame();
|
||||||
#ifdef GRAPHICS_MEMORY_DUMP
|
#ifdef GRAPHICS_MEMORY_DUMP
|
||||||
// Dump memory usage to file every two seconds
|
// Dump memory usage to file every two seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user