/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* application.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ /* Updated: 2023/04/22 19:39:59 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #include "application.h" #include #include #include #include namespace mlx::core { void Application::run() noexcept { while(_in->is_running()) { _in->update(); for(auto& gs : _graphics) gs->beginRender(); if(_loop_hook) _loop_hook(_param); for(auto& gs : _graphics) gs->endRender(); } } void* Application::newTexture(int w, int h) { _textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM); return &_textures.front(); } void* Application::newStbTexture(char* file, int* w, int* h) { _textures.emplace_front(stbTextureLoad(file, w, h)); return &_textures.front(); } char* Application::mapTexture(Texture* img, int* bits_per_pixel, int* size_line, int* endian) { static const int endianness = isSystemBigEndian(); *bits_per_pixel = 32; *size_line = img->getWidth() * 4; *endian = endianness; return static_cast(img->openCPUmap()); } void Application::destroyTexture(void* ptr) { vkDeviceWaitIdle(Render_Core::get().getDevice().get()); Texture* texture = static_cast(ptr); texture->destroy(); } }