mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
working on texts and fonts
This commit is contained in:
@@ -24,6 +24,7 @@ namespace mlx
|
||||
|
||||
m_fps.Init();
|
||||
p_render_core = std::make_unique<RenderCore>();
|
||||
LoadFont("default", 6.0f);
|
||||
}
|
||||
|
||||
void Application::Run() noexcept
|
||||
|
||||
@@ -155,13 +155,13 @@ extern "C"
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filename == nullptr)
|
||||
{
|
||||
mlx::Error("PNG loader : filename is NULL");
|
||||
mlx::Error("PNG loader: filename is NULL");
|
||||
return nullptr;
|
||||
}
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".png")
|
||||
{
|
||||
mlx::Error("PNG loader : not a png file '%'", filename);
|
||||
mlx::Error("PNG loader: not a png file '%'", filename);
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
|
||||
@@ -172,13 +172,13 @@ extern "C"
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filename == nullptr)
|
||||
{
|
||||
mlx::Error("JPG loader : filename is NULL");
|
||||
mlx::Error("JPG loader: filename is NULL");
|
||||
return nullptr;
|
||||
}
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".jpg" && file.extension() != ".jpeg")
|
||||
{
|
||||
mlx::Error("JPG loader : not a jpg file '%'", filename);
|
||||
mlx::Error("JPG loader: not a jpg file '%'", filename);
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
|
||||
@@ -189,13 +189,13 @@ extern "C"
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filename == nullptr)
|
||||
{
|
||||
mlx::Error("BMP loader : filename is NULL");
|
||||
mlx::Error("BMP loader: filename is NULL");
|
||||
return nullptr;
|
||||
}
|
||||
std::filesystem::path file(filename);
|
||||
if(file.extension() != ".bmp" && file.extension() != ".dib")
|
||||
{
|
||||
mlx::Error("BMP loader : not a bmp file '%'", filename);
|
||||
mlx::Error("BMP loader: not a bmp file '%'", filename);
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
|
||||
@@ -230,13 +230,13 @@ extern "C"
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filepath == nullptr)
|
||||
{
|
||||
mlx::Error("Font loader : filepath is NULL");
|
||||
mlx::Error("Font loader: filepath is NULL");
|
||||
return;
|
||||
}
|
||||
std::filesystem::path file(filepath);
|
||||
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
{
|
||||
mlx::Error("TTF loader : not a truetype font file '%'", filepath);
|
||||
mlx::Error("TTF loader: not a truetype font file '%'", filepath);
|
||||
return;
|
||||
}
|
||||
if(std::strcmp(filepath, "default") == 0)
|
||||
@@ -250,13 +250,13 @@ extern "C"
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
if (filepath == nullptr)
|
||||
{
|
||||
mlx::Error("Font loader : filepath is NULL");
|
||||
mlx::Error("Font loader: filepath is NULL");
|
||||
return;
|
||||
}
|
||||
std::filesystem::path file(filepath);
|
||||
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
|
||||
{
|
||||
mlx::Error("TTF loader : not a truetype font file '%'", filepath);
|
||||
mlx::Error("TTF loader: not a truetype font file '%'", filepath);
|
||||
return;
|
||||
}
|
||||
static_cast<mlx::Application*>(mlx)->LoadFont(file, scale);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace mlx
|
||||
auto it = std::find(s_blocks.begin(), s_blocks.end(), ptr);
|
||||
if(it == s_blocks.end())
|
||||
{
|
||||
Error("Memory Manager : trying to free a pointer not allocated by the memory manager");
|
||||
Error("Memory Manager: trying to free a pointer not allocated by the memory manager");
|
||||
return;
|
||||
}
|
||||
std::free(*it);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace mlx
|
||||
if(m_output_stream.is_open())
|
||||
WriteHeader();
|
||||
else
|
||||
Error("Profiler : cannot open runtime profile file");
|
||||
Error("Profiler: cannot open runtime profile file");
|
||||
m_runtime_session_began = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,21 +43,21 @@ namespace mlx
|
||||
#endif
|
||||
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
||||
FatalError("SDL : unable to init all subsystems; %", SDL_GetError());
|
||||
FatalError("SDL: unable to init all subsystems; %", SDL_GetError());
|
||||
DebugLog("SDL Manager initialized");
|
||||
}
|
||||
|
||||
Handle SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden, std::int32_t& id)
|
||||
{
|
||||
Internal::WindowInfos* infos = new Internal::WindowInfos;
|
||||
Verify(infos != nullptr, "SDL : window allocation failed");
|
||||
Verify(infos != nullptr, "SDL: window allocation failed");
|
||||
|
||||
if(title == "让我们在月光下做爱吧")
|
||||
infos->window = SDL_CreateWindow(title.c_str(), std::rand() % 512, std::rand() % 512, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN));
|
||||
else
|
||||
infos->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN));
|
||||
if(!infos->window)
|
||||
FatalError("SDL : unable to open a new window; %", SDL_GetError());
|
||||
FatalError("SDL: unable to open a new window; %", SDL_GetError());
|
||||
infos->icon = SDL_CreateRGBSurfaceFrom(static_cast<void*>(logo_mlx), logo_mlx_width, logo_mlx_height, 32, 4 * logo_mlx_width, rmask, gmask, bmask, amask);
|
||||
SDL_SetWindowIcon(infos->window, infos->icon);
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace mlx
|
||||
|
||||
void SDLManager::DestroyWindow(Handle window) noexcept
|
||||
{
|
||||
Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL : cannot destroy window; unknown window pointer");
|
||||
Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL: cannot destroy window; unknown window pointer");
|
||||
|
||||
Internal::WindowInfos* infos = static_cast<Internal::WindowInfos*>(window);
|
||||
if(infos->window != nullptr)
|
||||
@@ -86,7 +86,7 @@ namespace mlx
|
||||
{
|
||||
VkSurfaceKHR surface;
|
||||
if(!SDL_Vulkan_CreateSurface(static_cast<Internal::WindowInfos*>(window)->window, instance, &surface))
|
||||
FatalError("SDL : could not create a Vulkan surface; %", SDL_GetError());
|
||||
FatalError("SDL: could not create a Vulkan surface; %", SDL_GetError());
|
||||
return surface;
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ namespace mlx
|
||||
{
|
||||
std::uint32_t count;
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, nullptr))
|
||||
FatalError("SDL Manager : could not retrieve Vulkan instance extensions");
|
||||
FatalError("SDL Manager: could not retrieve Vulkan instance extensions");
|
||||
std::vector<const char*> extensions(count);
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, extensions.data()))
|
||||
FatalError("SDL Manager : could not retrieve Vulkan instance extensions");
|
||||
FatalError("SDL Manager: could not retrieve Vulkan instance extensions");
|
||||
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
return extensions;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
constexpr const int RANGE = 1024;
|
||||
|
||||
void Font::BuildFont()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
@@ -21,7 +19,7 @@ namespace mlx
|
||||
std::ifstream file(std::get<std::filesystem::path>(m_build_data), std::ios::binary);
|
||||
if(!file.is_open())
|
||||
{
|
||||
Error("Font : cannot open font file, %", m_name);
|
||||
Error("Font: cannot open font file, %", m_name);
|
||||
return;
|
||||
}
|
||||
std::ifstream::pos_type file_size = std::filesystem::file_size(std::get<std::filesystem::path>(m_build_data));
|
||||
@@ -56,6 +54,8 @@ namespace mlx
|
||||
#else
|
||||
m_atlas.Init(vulkan_bitmap, RANGE, RANGE, VK_FORMAT_R8G8B8A8_SRGB, false, {});
|
||||
#endif
|
||||
|
||||
DebugLog("Font: loaded %", m_name);
|
||||
}
|
||||
|
||||
void Font::Destroy()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "Graphics/Enums.h"
|
||||
#include <PreCompiled.h>
|
||||
#include <Graphics/Scene.h>
|
||||
#include <Renderer/Renderer.h>
|
||||
@@ -10,64 +11,117 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify((bool)texture, "Scene: invalid texture (internal mlx issue, please report to devs)");
|
||||
|
||||
#pragma omp parallel for
|
||||
for(auto& sprite : m_sprites)
|
||||
for(auto& drawable : m_drawables)
|
||||
{
|
||||
if(texture->GetWidth() == sprite->GetTexture()->GetWidth() && texture->GetHeight() == sprite->GetTexture()->GetHeight())
|
||||
if(!drawable || drawable->GetType() != DrawableType::Sprite)
|
||||
continue;
|
||||
if(texture->GetWidth() == static_cast<Sprite*>(drawable.get())->GetTexture()->GetWidth() && texture->GetHeight() == static_cast<Sprite*>(drawable.get())->GetTexture()->GetHeight())
|
||||
{
|
||||
std::shared_ptr<Sprite> new_sprite = std::make_shared<Sprite>(sprite->GetMesh(), texture);
|
||||
m_sprites.push_back(new_sprite);
|
||||
std::shared_ptr<Sprite> new_sprite = std::make_shared<Sprite>(drawable->GetMesh(), texture);
|
||||
m_drawables.push_back(new_sprite);
|
||||
return *new_sprite;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture);
|
||||
m_sprites.push_back(sprite);
|
||||
m_drawables.push_back(sprite);
|
||||
return *sprite;
|
||||
}
|
||||
|
||||
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture, &position](std::shared_ptr<Sprite> sprite)
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position](std::shared_ptr<Drawable> drawable)
|
||||
{
|
||||
return sprite->GetTexture() == texture && sprite->GetPosition().x == position.x && sprite->GetPosition().y == position.y;
|
||||
if(!drawable || drawable->GetType() != DrawableType::Sprite)
|
||||
return false;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture && drawable->GetPosition() == position;
|
||||
});
|
||||
return (it != m_sprites.end() ? it->get() : nullptr);
|
||||
}
|
||||
|
||||
void Scene::BringToFront(NonOwningPtr<Sprite> sprite)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&sprite](std::shared_ptr<Sprite> sprite_ptr)
|
||||
{
|
||||
return sprite_ptr.get() == sprite.Get();
|
||||
});
|
||||
if(it == m_sprites.end())
|
||||
return;
|
||||
std::rotate(it, it + 1, m_sprites.end());
|
||||
return static_cast<Sprite*>(it != m_drawables.end() ? it->get() : nullptr);
|
||||
}
|
||||
|
||||
void Scene::TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = m_sprites.begin();
|
||||
auto it = m_drawables.begin();
|
||||
do
|
||||
{
|
||||
it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture](std::shared_ptr<Sprite> sprite)
|
||||
it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture](std::shared_ptr<Drawable> drawable)
|
||||
{
|
||||
return sprite->GetTexture() == texture;
|
||||
if(!drawable || drawable->GetType() != DrawableType::Sprite)
|
||||
return false;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture;
|
||||
});
|
||||
if(it != m_sprites.end())
|
||||
m_sprites.erase(it);
|
||||
} while(it != m_sprites.end());
|
||||
if(it != m_drawables.end())
|
||||
m_drawables.erase(it);
|
||||
} while(it != m_drawables.end());
|
||||
}
|
||||
|
||||
|
||||
bool Scene::IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(draw_layer >= m_sprites.size())
|
||||
if(draw_layer >= m_drawables.size())
|
||||
return false;
|
||||
return m_sprites[draw_layer]->GetTexture() == texture;
|
||||
if(!m_drawables[draw_layer] || m_drawables[draw_layer]->GetType() != DrawableType::Sprite)
|
||||
return false;
|
||||
return static_cast<Sprite*>(m_drawables[draw_layer].get())->GetTexture() == texture;
|
||||
}
|
||||
|
||||
Text& Scene::CreateText(const std::string& text) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
|
||||
Assert((bool)p_bound_font, "no font bound");
|
||||
|
||||
for(auto& drawable : m_drawables)
|
||||
{
|
||||
if(!drawable || drawable->GetType() != DrawableType::Text)
|
||||
continue;
|
||||
if(text == static_cast<Text*>(drawable.get())->GetText() && p_bound_font == static_cast<Text*>(drawable.get())->GetFont())
|
||||
{
|
||||
std::shared_ptr<Text> new_text = std::make_shared<Text>(text, p_bound_font, drawable->GetMesh());
|
||||
m_drawables.push_back(new_text);
|
||||
return *new_text;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Text> new_text = std::make_shared<Text>(text, p_bound_font);
|
||||
m_drawables.push_back(new_text);
|
||||
return *new_text;
|
||||
}
|
||||
|
||||
NonOwningPtr<Text> Scene::GetTextFromPositionAndColor(const std::string& text, const Vec2f& position, const Vec4f& color) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&text, &position, &color](std::shared_ptr<Drawable> drawable)
|
||||
{
|
||||
if(!drawable || drawable->GetType() != DrawableType::Text)
|
||||
return false;
|
||||
return static_cast<Text*>(drawable.get())->GetText() == text && drawable->GetPosition() == position && drawable->GetColor() == color;
|
||||
});
|
||||
return static_cast<Text*>(it != m_drawables.end() ? it->get() : nullptr);
|
||||
}
|
||||
|
||||
bool Scene::IsTextAtGivenDrawLayer(const std::string& text, std::uint64_t draw_layer) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(draw_layer >= m_drawables.size())
|
||||
return false;
|
||||
if(!m_drawables[draw_layer] || m_drawables[draw_layer]->GetType() != DrawableType::Text)
|
||||
return false;
|
||||
Text* ptr = static_cast<Text*>(m_drawables[draw_layer].get());
|
||||
return ptr->GetText() == text && ptr->GetFont() == p_bound_font;
|
||||
}
|
||||
|
||||
void Scene::BringToFront(NonOwningPtr<Drawable> drawable)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&drawable](std::shared_ptr<Drawable> drawable_ptr)
|
||||
{
|
||||
return drawable_ptr.get() == drawable.Get();
|
||||
});
|
||||
if(it == m_drawables.end())
|
||||
return;
|
||||
std::rotate(it, it + 1, m_drawables.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace mlx
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Sprite::Sprite(NonOwningPtr<Texture> texture)
|
||||
Sprite::Sprite(NonOwningPtr<Texture> texture) : Drawable(DrawableType::Sprite)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)");
|
||||
@@ -45,7 +45,7 @@ namespace mlx
|
||||
p_texture = texture;
|
||||
}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture)
|
||||
Sprite::Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture) : Drawable(DrawableType::Sprite)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)");
|
||||
|
||||
61
runtime/Sources/Graphics/Text.cpp
git.filemode.normal_file
61
runtime/Sources/Graphics/Text.cpp
git.filemode.normal_file
@@ -0,0 +1,61 @@
|
||||
#include <PreCompiled.h>
|
||||
|
||||
#include <Graphics/Text.h>
|
||||
|
||||
#define STB_RECT_PACK_IMPLEMENTATION
|
||||
#include <stb_rect_pack.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
Text::Text(const std::string& text, std::shared_ptr<Font> font) : Drawable(DrawableType::Text)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
|
||||
Assert(font != nullptr, "invalid font");
|
||||
|
||||
std::vector<Vertex> vertex_data;
|
||||
std::vector<std::uint32_t> index_data;
|
||||
|
||||
float stb_x = 0.0f;
|
||||
float stb_y = 0.0f;
|
||||
|
||||
for(char c : text)
|
||||
{
|
||||
if(c < 32)
|
||||
continue;
|
||||
|
||||
stbtt_aligned_quad q;
|
||||
stbtt_GetPackedQuad(font->GetCharData().data(), RANGE, RANGE, c - 32, &stb_x, &stb_y, &q, 1);
|
||||
|
||||
std::size_t index = vertex_data.size();
|
||||
|
||||
vertex_data.emplace_back(Vec4f{ q.x0, q.y0, 0.0f, 0.0f }, Vec2f{ q.s0, q.t0 });
|
||||
vertex_data.emplace_back(Vec4f{ q.x1, q.y0, 0.0f, 0.0f }, Vec2f{ q.s1, q.t0 });
|
||||
vertex_data.emplace_back(Vec4f{ q.x1, q.y1, 0.0f, 0.0f }, Vec2f{ q.s1, q.t1 });
|
||||
vertex_data.emplace_back(Vec4f{ q.x0, q.y1, 0.0f, 0.0f }, Vec2f{ q.s0, q.t1 });
|
||||
|
||||
index_data.emplace_back(index + 0);
|
||||
index_data.emplace_back(index + 1);
|
||||
index_data.emplace_back(index + 2);
|
||||
index_data.emplace_back(index + 2);
|
||||
index_data.emplace_back(index + 3);
|
||||
index_data.emplace_back(index + 0);
|
||||
}
|
||||
|
||||
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
|
||||
mesh->AddSubMesh({ std::move(vertex_data), std::move(index_data) });
|
||||
Init(text, font, mesh);
|
||||
}
|
||||
|
||||
void Text::Init(const std::string& text, std::shared_ptr<Font> font, std::shared_ptr<Mesh> mesh)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
|
||||
Assert(font != nullptr, "invalid font");
|
||||
Assert(mesh != nullptr, "invalid mesh");
|
||||
|
||||
p_mesh = mesh;
|
||||
p_font = font;
|
||||
m_text = text;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace mlx
|
||||
{
|
||||
if(data.Empty())
|
||||
{
|
||||
Warning("Vulkan : trying to create constant buffer without data (constant buffers cannot be modified after creation)");
|
||||
Warning("Vulkan: trying to create constant buffer without data (constant buffers cannot be modified after creation)");
|
||||
return;
|
||||
}
|
||||
m_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
@@ -70,12 +70,12 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(!(m_usage & VK_BUFFER_USAGE_TRANSFER_DST_BIT))
|
||||
{
|
||||
Error("Vulkan : buffer cannot be the destination of a copy because it does not have the correct usage flag");
|
||||
Error("Vulkan: buffer cannot be the destination of a copy because it does not have the correct usage flag");
|
||||
return false;
|
||||
}
|
||||
if(!(buffer.m_usage & VK_BUFFER_USAGE_TRANSFER_SRC_BIT))
|
||||
{
|
||||
Error("Vulkan : buffer cannot be the source of a copy because it does not have the correct usage flag");
|
||||
Error("Vulkan: buffer cannot be the source of a copy because it does not have the correct usage flag");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace mlx
|
||||
if(new_buffer.CopyFrom(*this))
|
||||
Swap(new_buffer);
|
||||
new_buffer.Destroy();
|
||||
DebugLog("Vulkan : pushed buffer to GPU memory");
|
||||
DebugLog("Vulkan: pushed buffer to GPU memory");
|
||||
}
|
||||
|
||||
void GPUBuffer::Destroy() noexcept
|
||||
@@ -141,12 +141,12 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(data.GetSize() > m_size)
|
||||
{
|
||||
Error("Vulkan : trying to store to much data in a vertex buffer (% bytes in % bytes)", data.GetSize(), m_size);
|
||||
Error("Vulkan: trying to store to much data in a vertex buffer (% bytes in % bytes)", data.GetSize(), m_size);
|
||||
return;
|
||||
}
|
||||
if(data.Empty())
|
||||
{
|
||||
Warning("Vulkan : cannot set empty data in a vertex buffer");
|
||||
Warning("Vulkan: cannot set empty data in a vertex buffer");
|
||||
return;
|
||||
}
|
||||
GPUBuffer staging;
|
||||
@@ -164,12 +164,12 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(data.GetSize() > m_size)
|
||||
{
|
||||
Error("Vulkan : trying to store to much data in an index buffer (% bytes in % bytes)", data.GetSize(), m_size);
|
||||
Error("Vulkan: trying to store to much data in an index buffer (% bytes in % bytes)", data.GetSize(), m_size);
|
||||
return;
|
||||
}
|
||||
if(data.Empty())
|
||||
{
|
||||
Warning("Vulkan : cannot set empty data in an index buffer");
|
||||
Warning("Vulkan: cannot set empty data in an index buffer");
|
||||
return;
|
||||
}
|
||||
GPUBuffer staging;
|
||||
@@ -194,7 +194,7 @@ namespace mlx
|
||||
#endif
|
||||
m_maps[i] = m_buffers[i].GetMap();
|
||||
if(m_maps[i] == nullptr)
|
||||
FatalError("Vulkan : unable to map a uniform buffer");
|
||||
FatalError("Vulkan: unable to map a uniform buffer");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(data.GetSize() != m_buffers[frame_index].GetSize())
|
||||
{
|
||||
Error("Vulkan : invalid data size to update to a uniform buffer, % != %", data.GetSize(), m_buffers[frame_index].GetSize());
|
||||
Error("Vulkan: invalid data size to update to a uniform buffer, % != %", data.GetSize(), m_buffers[frame_index].GetSize());
|
||||
return;
|
||||
}
|
||||
if(m_maps[frame_index] != nullptr)
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlx
|
||||
if(image.GetType() == ImageType::Color)
|
||||
image.TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, cmd);
|
||||
else
|
||||
Error("Vulkan : cannot transition descriptor image layout, unkown image type");
|
||||
Error("Vulkan: cannot transition descriptor image layout, unkown image type");
|
||||
}
|
||||
|
||||
void DescriptorPool::Init() noexcept
|
||||
@@ -128,7 +128,7 @@ namespace mlx
|
||||
});
|
||||
if(it == m_used_sets.end())
|
||||
{
|
||||
Error("Vulkan : cannot return descriptor set to pool, invalid pool");
|
||||
Error("Vulkan: cannot return descriptor set to pool, invalid pool");
|
||||
return;
|
||||
}
|
||||
m_used_sets.erase(it);
|
||||
@@ -182,12 +182,12 @@ namespace mlx
|
||||
});
|
||||
if(it == m_descriptors.end())
|
||||
{
|
||||
Warning("Vulkan : cannot update descriptor set image; invalid binding");
|
||||
Warning("Vulkan: cannot update descriptor set image; invalid binding");
|
||||
return;
|
||||
}
|
||||
if(it->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
|
||||
{
|
||||
Error("Vulkan : trying to bind an image to the wrong descriptor");
|
||||
Error("Vulkan: trying to bind an image to the wrong descriptor");
|
||||
return;
|
||||
}
|
||||
it->image_ptr = ℑ
|
||||
@@ -203,12 +203,12 @@ namespace mlx
|
||||
});
|
||||
if(it == m_descriptors.end())
|
||||
{
|
||||
Warning("Vulkan : cannot update descriptor set buffer; invalid binding");
|
||||
Warning("Vulkan: cannot update descriptor set buffer; invalid binding");
|
||||
return;
|
||||
}
|
||||
if(it->type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
|
||||
{
|
||||
Error("Vulkan : trying to bind a buffer to the wrong descriptor");
|
||||
Error("Vulkan: trying to bind a buffer to the wrong descriptor");
|
||||
return;
|
||||
}
|
||||
it->storage_buffer_ptr = &buffer;
|
||||
@@ -224,12 +224,12 @@ namespace mlx
|
||||
});
|
||||
if(it == m_descriptors.end())
|
||||
{
|
||||
Warning("Vulkan : cannot update descriptor set buffer; invalid binding");
|
||||
Warning("Vulkan: cannot update descriptor set buffer; invalid binding");
|
||||
return;
|
||||
}
|
||||
if(it->type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
|
||||
{
|
||||
Error("Vulkan : trying to bind a buffer to the wrong descriptor");
|
||||
Error("Vulkan: trying to bind a buffer to the wrong descriptor");
|
||||
return;
|
||||
}
|
||||
it->uniform_buffer_ptr = &buffer;
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
#include <stb_image.h>
|
||||
#endif
|
||||
|
||||
#ifdef IMAGE_OPTIMIZED
|
||||
#define TILING VK_IMAGE_TILING_OPTIMAL
|
||||
#else
|
||||
#define TILING VK_IMAGE_TILING_LINEAR
|
||||
#endif
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled, [[maybe_unused]] std::string_view debug_name)
|
||||
@@ -153,7 +159,7 @@ namespace mlx
|
||||
void Texture::Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, [[maybe_unused]] std::string_view debug_name)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled, std::move(debug_name));
|
||||
Image::Init(ImageType::Color, width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled, std::move(debug_name));
|
||||
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
Image::CreateSampler();
|
||||
if(pixels)
|
||||
@@ -228,7 +234,7 @@ namespace mlx
|
||||
if(m_staging_buffer.has_value())
|
||||
return;
|
||||
#ifdef DEBUG
|
||||
DebugLog("Texture : enabling CPU mapping for '%'", m_debug_name);
|
||||
DebugLog("Texture: enabling CPU mapping for '%'", m_debug_name);
|
||||
#endif
|
||||
m_staging_buffer.emplace();
|
||||
std::size_t size = m_width * m_height * kvfFormatSize(m_format);
|
||||
@@ -263,12 +269,12 @@ namespace mlx
|
||||
|
||||
if(!std::filesystem::exists(file))
|
||||
{
|
||||
Error("Image : file not found %", file);
|
||||
Error("Image: file not found %", file);
|
||||
return nullptr;
|
||||
}
|
||||
if(stbi_is_hdr(filename.c_str()))
|
||||
{
|
||||
Error("Texture : unsupported image format % (HDR image)", file);
|
||||
Error("Texture: unsupported image format % (HDR image)", file);
|
||||
return nullptr;
|
||||
}
|
||||
int dummy_w;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace mlx
|
||||
allocator_create_info.pVulkanFunctions = &vma_vulkan_func;
|
||||
|
||||
kvfCheckVk(vmaCreateAllocator(&allocator_create_info, &m_allocator));
|
||||
DebugLog("Graphics allocator : created new allocator");
|
||||
DebugLog("Graphics Allocator: created new allocator");
|
||||
}
|
||||
|
||||
VmaAllocation GPUAllocator::CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) noexcept
|
||||
@@ -74,7 +74,7 @@ namespace mlx
|
||||
#endif
|
||||
vmaSetAllocationName(m_allocator, allocation, name);
|
||||
}
|
||||
DebugLog("Graphics Allocator : created new buffer '%'", name);
|
||||
DebugLog("Graphics Allocator: created new buffer '%'", name);
|
||||
m_active_buffers_allocations++;
|
||||
return allocation;
|
||||
}
|
||||
@@ -85,9 +85,9 @@ namespace mlx
|
||||
RenderCore::Get().WaitDeviceIdle();
|
||||
vmaDestroyBuffer(m_allocator, buffer, allocation);
|
||||
if(name != nullptr)
|
||||
DebugLog("Graphics Allocator : destroyed buffer '%'", name);
|
||||
DebugLog("Graphics Allocator: destroyed buffer '%'", name);
|
||||
else
|
||||
DebugLog("Graphics Allocator : destroyed buffer");
|
||||
DebugLog("Graphics Allocator: destroyed buffer");
|
||||
m_active_buffers_allocations--;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace mlx
|
||||
#endif
|
||||
vmaSetAllocationName(m_allocator, allocation, name);
|
||||
}
|
||||
DebugLog("Graphics Allocator : created new image '%'", name);
|
||||
DebugLog("Graphics Allocator: created new image '%'", name);
|
||||
m_active_images_allocations++;
|
||||
return allocation;
|
||||
}
|
||||
@@ -119,9 +119,9 @@ namespace mlx
|
||||
RenderCore::Get().WaitDeviceIdle();
|
||||
vmaDestroyImage(m_allocator, image, allocation);
|
||||
if(name != nullptr)
|
||||
DebugLog("Graphics Allocator : destroyed image '%'", name);
|
||||
DebugLog("Graphics Allocator: destroyed image '%'", name);
|
||||
else
|
||||
DebugLog("Graphics Allocator : destroyed image");
|
||||
DebugLog("Graphics Allocator: destroyed image");
|
||||
m_active_images_allocations--;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace mlx
|
||||
std::ofstream file(name);
|
||||
if(!file.is_open())
|
||||
{
|
||||
Error("Graphics allocator : unable to dump memory to a json file");
|
||||
Error("Graphics Allocator: unable to dump memory to a json file");
|
||||
return;
|
||||
}
|
||||
char* str = nullptr;
|
||||
@@ -166,14 +166,14 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(m_active_images_allocations != 0)
|
||||
Error("Graphics allocator : some user-dependant allocations were not freed before destroying the display (% active allocations). You may have not destroyed all the MLX resources you've created", m_active_images_allocations);
|
||||
Error("Graphics Allocator: some user-dependant allocations were not freed before destroying the display (% active allocations). You may have not destroyed all the MLX resources you've created", m_active_images_allocations);
|
||||
else if(m_active_buffers_allocations != 0)
|
||||
Error("Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (% active allocations). This is an error in the MLX, please report this should not happen", m_active_buffers_allocations);
|
||||
Error("Graphics Allocator: some MLX-dependant allocations were not freed before destroying the display (% active allocations). This is an error in the MLX, please report this should not happen", m_active_buffers_allocations);
|
||||
if(m_active_images_allocations < 0 || m_active_buffers_allocations < 0)
|
||||
Warning("Graphics allocator : the impossible happened, the MLX has freed more allocations than it has made (wtf)");
|
||||
Warning("Graphics Allocator: the impossible happened, the MLX has freed more allocations than it has made (wtf)");
|
||||
vmaDestroyAllocator(m_allocator);
|
||||
m_active_buffers_allocations = 0;
|
||||
m_active_images_allocations = 0;
|
||||
DebugLog("Vulkan : destroyed a graphics allocator");
|
||||
DebugLog("Vulkan: destroyed a graphics allocator");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(!descriptor.vertex_shader || !descriptor.fragment_shader)
|
||||
FatalError("Vulkan : invalid shaders");
|
||||
FatalError("Vulkan: invalid shaders");
|
||||
|
||||
m_attachments = descriptor.color_attachments;
|
||||
p_vertex_shader = descriptor.vertex_shader;
|
||||
@@ -51,7 +51,7 @@ namespace mlx
|
||||
}
|
||||
|
||||
m_pipeline = kvfCreateGraphicsPipeline(RenderCore::Get().GetDevice(), m_pipeline_layout, builder, m_renderpass);
|
||||
DebugLog("Vulkan : graphics pipeline created");
|
||||
DebugLog("Vulkan: graphics pipeline created");
|
||||
kvfDestroyGPipelineBuilder(builder);
|
||||
|
||||
#ifdef MLX_HAS_DEBUG_UTILS_FUNCTIONS
|
||||
@@ -132,18 +132,18 @@ namespace mlx
|
||||
for(auto& fb : m_framebuffers)
|
||||
{
|
||||
kvfDestroyFramebuffer(RenderCore::Get().GetDevice(), fb);
|
||||
DebugLog("Vulkan : framebuffer destroyed");
|
||||
DebugLog("Vulkan: framebuffer destroyed");
|
||||
}
|
||||
m_framebuffers.clear();
|
||||
kvfDestroyPipelineLayout(RenderCore::Get().GetDevice(), m_pipeline_layout);
|
||||
m_pipeline_layout = VK_NULL_HANDLE;
|
||||
DebugLog("Vulkan : graphics pipeline layout destroyed");
|
||||
DebugLog("Vulkan: graphics pipeline layout destroyed");
|
||||
kvfDestroyRenderPass(RenderCore::Get().GetDevice(), m_renderpass);
|
||||
m_renderpass = VK_NULL_HANDLE;
|
||||
DebugLog("Vulkan : renderpass destroyed");
|
||||
DebugLog("Vulkan: renderpass destroyed");
|
||||
kvfDestroyPipeline(RenderCore::Get().GetDevice(), m_pipeline);
|
||||
m_pipeline = VK_NULL_HANDLE;
|
||||
DebugLog("Vulkan : graphics pipeline destroyed");
|
||||
DebugLog("Vulkan: graphics pipeline destroyed");
|
||||
}
|
||||
|
||||
void GraphicPipeline::CreateFramebuffers(const std::vector<NonOwningPtr<Texture>>& render_targets, bool clear_attachments)
|
||||
@@ -167,7 +167,7 @@ namespace mlx
|
||||
m_renderpass = kvfCreateRenderPass(RenderCore::Get().GetDevice(), attachments.data(), attachments.size(), GetPipelineBindPoint());
|
||||
m_clears.clear();
|
||||
m_clears.resize(attachments.size());
|
||||
DebugLog("Vulkan : renderpass created");
|
||||
DebugLog("Vulkan: renderpass created");
|
||||
|
||||
if(p_renderer)
|
||||
{
|
||||
@@ -175,14 +175,14 @@ namespace mlx
|
||||
{
|
||||
attachment_views[0] = image.GetImageView();
|
||||
m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image.GetWidth(), .height = image.GetHeight() }));
|
||||
DebugLog("Vulkan : framebuffer created");
|
||||
DebugLog("Vulkan: framebuffer created");
|
||||
}
|
||||
}
|
||||
#pragma omp parallel for
|
||||
for(NonOwningPtr<Texture> image : render_targets)
|
||||
{
|
||||
m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image->GetWidth(), .height = image->GetHeight() }));
|
||||
DebugLog("Vulkan : framebuffer created");
|
||||
DebugLog("Vulkan: framebuffer created");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace mlx
|
||||
default : FatalError("wtf"); break;
|
||||
}
|
||||
m_module = kvfCreateShaderModule(RenderCore::Get().GetDevice(), reinterpret_cast<std::uint32_t*>(m_bytecode.data()), m_bytecode.size() / 4);
|
||||
DebugLog("Vulkan : shader module created");
|
||||
DebugLog("Vulkan: shader module created");
|
||||
|
||||
GeneratePipelineLayout(m_layout);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace mlx
|
||||
bindings[i].stageFlags = m_stage;
|
||||
}
|
||||
m_set_layouts.emplace_back(kvfCreateDescriptorSetLayout(RenderCore::Get().GetDevice(), bindings.data(), bindings.size()));
|
||||
DebugLog("Vulkan : descriptor set layout created");
|
||||
DebugLog("Vulkan: descriptor set layout created");
|
||||
m_pipeline_layout_part.set_layouts.push_back(m_set_layouts.back());
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
kvfDestroyShaderModule(RenderCore::Get().GetDevice(), m_module);
|
||||
DebugLog("Vulkan : shader module destroyed");
|
||||
DebugLog("Vulkan: shader module destroyed");
|
||||
for(auto& layout : m_set_layouts)
|
||||
{
|
||||
kvfDestroyDescriptorSetLayout(RenderCore::Get().GetDevice(), layout);
|
||||
DebugLog("Vulkan : descriptor set layout destroyed");
|
||||
DebugLog("Vulkan: descriptor set layout destroyed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace mlx
|
||||
#endif
|
||||
|
||||
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
||||
DebugLog("Vulkan : instance created");
|
||||
DebugLog("Vulkan: instance created");
|
||||
|
||||
loader->LoadInstance(m_instance);
|
||||
LoadKVFInstanceVulkanFunctionPointers();
|
||||
@@ -81,13 +81,13 @@ namespace mlx
|
||||
// just for style
|
||||
VkPhysicalDeviceProperties props;
|
||||
vkGetPhysicalDeviceProperties(m_physical_device, &props);
|
||||
DebugLog("Vulkan : physical device picked '%'", props.deviceName);
|
||||
DebugLog("Vulkan: physical device picked '%'", props.deviceName);
|
||||
|
||||
const char* device_extensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
|
||||
VkPhysicalDeviceFeatures features{};
|
||||
vkGetPhysicalDeviceFeatures(m_physical_device, &features);
|
||||
m_device = kvfCreateDevice(m_physical_device, device_extensions, sizeof(device_extensions) / sizeof(device_extensions[0]), &features);
|
||||
DebugLog("Vulkan : logical device created");
|
||||
DebugLog("Vulkan: logical device created");
|
||||
|
||||
loader->LoadDevice(m_device);
|
||||
LoadKVFDeviceVulkanFunctionPointers();
|
||||
@@ -201,9 +201,9 @@ namespace mlx
|
||||
m_descriptor_pool_manager.Destroy();
|
||||
m_allocator.Destroy();
|
||||
kvfDestroyDevice(m_device);
|
||||
DebugLog("Vulkan : logical device destroyed");
|
||||
DebugLog("Vulkan: logical device destroyed");
|
||||
kvfDestroyInstance(m_instance);
|
||||
DebugLog("Vulkan : instance destroyed");
|
||||
DebugLog("Vulkan: instance destroyed");
|
||||
loader.reset();
|
||||
|
||||
s_instance = nullptr;
|
||||
|
||||
@@ -92,32 +92,31 @@ namespace mlx
|
||||
|
||||
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
||||
|
||||
const auto& sprites = scene.GetSprites();
|
||||
const auto& drawables = scene.GetDrawables();
|
||||
|
||||
for(auto sprite : sprites)
|
||||
for(auto drawable : drawables)
|
||||
{
|
||||
// Check every textures and update modified ones to GPU before starting the render pass
|
||||
if(!sprite->IsSetInit())
|
||||
sprite->UpdateDescriptorSet(p_texture_set);
|
||||
Verify((bool)sprite->GetTexture(), "a sprite has no texture attached (internal mlx issue, please report to the devs)");
|
||||
sprite->GetTexture()->Update(cmd);
|
||||
if(!drawable->IsSetInit())
|
||||
drawable->UpdateDescriptorSet(p_texture_set);
|
||||
drawable->Update(cmd);
|
||||
}
|
||||
|
||||
m_pipeline.BindPipeline(cmd, 0, {});
|
||||
for(auto sprite : sprites)
|
||||
for(auto drawable : drawables)
|
||||
{
|
||||
SpriteData sprite_data;
|
||||
sprite_data.position = Vec4f{ sprite->GetPosition(), 0.0f, 1.0f };
|
||||
sprite_data.color = sprite->GetColor();
|
||||
SpriteData drawable_data;
|
||||
drawable_data.position = Vec4f{ drawable->GetPosition(), 0.0f, 1.0f };
|
||||
drawable_data.color = drawable->GetColor();
|
||||
|
||||
sprite->Bind(frame_index, cmd);
|
||||
drawable->Bind(frame_index, cmd);
|
||||
|
||||
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), sprite->GetSet(frame_index) };
|
||||
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), drawable->GetSet(frame_index) };
|
||||
|
||||
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &sprite_data);
|
||||
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &drawable_data);
|
||||
RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
|
||||
sprite->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef());
|
||||
drawable->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef());
|
||||
}
|
||||
m_pipeline.EndPipeline(cmd);
|
||||
}
|
||||
|
||||
@@ -33,20 +33,20 @@ namespace mlx
|
||||
p_window = window;
|
||||
|
||||
m_surface = p_window->CreateVulkanSurface(RenderCore::Get().GetInstance());
|
||||
DebugLog("Vulkan : surface created");
|
||||
DebugLog("Vulkan: surface created");
|
||||
|
||||
CreateSwapchain();
|
||||
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
m_image_available_semaphores[i] = kvfCreateSemaphore(RenderCore::Get().GetDevice());
|
||||
DebugLog("Vulkan : image available semaphore created");
|
||||
DebugLog("Vulkan: image available semaphore created");
|
||||
m_render_finished_semaphores[i] = kvfCreateSemaphore(RenderCore::Get().GetDevice());
|
||||
DebugLog("Vulkan : render finished semaphore created");
|
||||
DebugLog("Vulkan: render finished semaphore created");
|
||||
m_cmd_buffers[i] = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||
DebugLog("Vulkan : command buffer created");
|
||||
DebugLog("Vulkan: command buffer created");
|
||||
m_cmd_fences[i] = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
DebugLog("Vulkan : fence created");
|
||||
DebugLog("Vulkan: fence created");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace mlx
|
||||
//return false;
|
||||
}
|
||||
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
||||
FatalError("Vulkan error : failed to acquire swapchain image, %", kvfVerbaliseVkResult(result));
|
||||
FatalError("Vulkan error: failed to acquire swapchain image, %", kvfVerbaliseVkResult(result));
|
||||
|
||||
RenderCore::Get().vkResetCommandBuffer(m_cmd_buffers[m_current_frame_index], 0);
|
||||
kvfBeginCommandBuffer(m_cmd_buffers[m_current_frame_index], 0);
|
||||
@@ -110,7 +110,7 @@ namespace mlx
|
||||
m_swapchain_images[i].TransitionLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
m_swapchain_images[i].CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
}
|
||||
DebugLog("Vulkan : swapchain created");
|
||||
DebugLog("Vulkan: swapchain created");
|
||||
}
|
||||
|
||||
void Renderer::DestroySwapchain()
|
||||
@@ -120,7 +120,7 @@ namespace mlx
|
||||
for(Image& img : m_swapchain_images)
|
||||
img.DestroyImageView();
|
||||
kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), m_swapchain);
|
||||
DebugLog("Vulkan : swapchain destroyed");
|
||||
DebugLog("Vulkan: swapchain destroyed");
|
||||
}
|
||||
|
||||
void Renderer::Destroy() noexcept
|
||||
@@ -131,16 +131,16 @@ namespace mlx
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
kvfDestroySemaphore(RenderCore::Get().GetDevice(), m_image_available_semaphores[i]);
|
||||
DebugLog("Vulkan : image available semaphore destroyed");
|
||||
DebugLog("Vulkan: image available semaphore destroyed");
|
||||
kvfDestroySemaphore(RenderCore::Get().GetDevice(), m_render_finished_semaphores[i]);
|
||||
DebugLog("Vulkan : render finished semaphore destroyed");
|
||||
DebugLog("Vulkan: render finished semaphore destroyed");
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), m_cmd_fences[i]);
|
||||
DebugLog("Vulkan : fence destroyed");
|
||||
DebugLog("Vulkan: fence destroyed");
|
||||
}
|
||||
|
||||
DestroySwapchain();
|
||||
RenderCore::Get().vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr);
|
||||
DebugLog("Vulkan : surface destroyed");
|
||||
DebugLog("Vulkan: surface destroyed");
|
||||
m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace mlx
|
||||
{
|
||||
PFN_vkVoidFunction function = RenderCore::Get().vkGetInstanceProcAddr(static_cast<VkInstance>(context), name);
|
||||
if(!function)
|
||||
FatalError("Vulkan loader : could not load '%'", name);
|
||||
//DebugLog("Vulkan loader : loaded %", name);
|
||||
FatalError("Vulkan Loader: could not load '%'", name);
|
||||
//DebugLog("Vulkan Loader: loaded %", name);
|
||||
return function;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ namespace mlx
|
||||
{
|
||||
PFN_vkVoidFunction function = RenderCore::Get().vkGetDeviceProcAddr(static_cast<VkDevice>(context), name);
|
||||
if(!function)
|
||||
FatalError("Vulkan loader : could not load '%'", name);
|
||||
//DebugLog("Vulkan loader : loaded %", name);
|
||||
FatalError("Vulkan Loader: could not load '%'", name);
|
||||
//DebugLog("Vulkan Loader: loaded %", name);
|
||||
return function;
|
||||
}
|
||||
|
||||
@@ -95,13 +95,13 @@ namespace mlx
|
||||
RESTORE_GCC_PEDANTIC_WARNINGS
|
||||
if(RenderCore::Get().vkGetInstanceProcAddr)
|
||||
{
|
||||
DebugLog("Vulkan loader : libvulkan loaded using '%'", libname);
|
||||
DebugLog("Vulkan Loader: libvulkan loaded using '%'", libname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!p_module || !RenderCore::Get().vkGetInstanceProcAddr)
|
||||
FatalError("Vulkan loader : failed to load libvulkan");
|
||||
FatalError("Vulkan Loader: failed to load libvulkan");
|
||||
LoadGlobalFunctions(nullptr, Internal::vkGetInstanceProcAddrStub);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace mlx
|
||||
#define MLX_VULKAN_GLOBAL_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
|
||||
#include <Renderer/Vulkan/VulkanDefs.h>
|
||||
#undef MLX_VULKAN_GLOBAL_FUNCTION
|
||||
DebugLog("Vulkan loader : global functions loaded");
|
||||
DebugLog("Vulkan Loader: global functions loaded");
|
||||
}
|
||||
|
||||
void VulkanLoader::LoadInstanceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept
|
||||
@@ -128,7 +128,7 @@ namespace mlx
|
||||
#define MLX_VULKAN_INSTANCE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
|
||||
#include <Renderer/Vulkan/VulkanDefs.h>
|
||||
#undef MLX_VULKAN_INSTANCE_FUNCTION
|
||||
DebugLog("Vulkan loader : instance functions loaded");
|
||||
DebugLog("Vulkan Loader: instance functions loaded");
|
||||
}
|
||||
|
||||
void VulkanLoader::LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept
|
||||
@@ -136,7 +136,7 @@ namespace mlx
|
||||
#define MLX_VULKAN_DEVICE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
|
||||
#include <Renderer/Vulkan/VulkanDefs.h>
|
||||
#undef MLX_VULKAN_DEVICE_FUNCTION
|
||||
DebugLog("Vulkan loader : device functions loaded");
|
||||
DebugLog("Vulkan Loader: device functions loaded");
|
||||
}
|
||||
|
||||
VulkanLoader::~VulkanLoader()
|
||||
@@ -147,6 +147,6 @@ namespace mlx
|
||||
dlclose(p_module);
|
||||
#endif
|
||||
p_module = nullptr;
|
||||
DebugLog("Vulkan loader : libvulkan unloaded");
|
||||
DebugLog("Vulkan Loader: libvulkan unloaded");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user