mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
adding clear color in mlx_clear_window
This commit is contained in:
@@ -264,10 +264,15 @@ extern "C"
|
||||
static_cast<mlx::Application*>(mlx)->LoadFont(file, scale);
|
||||
}
|
||||
|
||||
void mlx_clear_window(void* mlx, void* win)
|
||||
void mlx_clear_window(void* mlx, void* win, int color)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::Application*>(mlx)->ClearGraphicsSupport(win);
|
||||
unsigned char color_bits[4];
|
||||
color_bits[0] = (color & 0x00FF0000) >> 16;
|
||||
color_bits[1] = (color & 0x0000FF00) >> 8;
|
||||
color_bits[2] = (color & 0x000000FF);
|
||||
color_bits[3] = (color & 0xFF000000) >> 24;
|
||||
static_cast<mlx::Application*>(mlx)->ClearGraphicsSupport(win, *reinterpret_cast<unsigned int*>(color_bits));
|
||||
}
|
||||
|
||||
void mlx_destroy_window(void* mlx, void* win)
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
#include <Graphics/Font.h>
|
||||
#include <Core/Memory.h>
|
||||
|
||||
#define STBRP_ASSERT(x) mlx::Assert(x, "internal stb assertion")
|
||||
#define STBRP_ASSERT(x) mlx::Assert(x, "internal stb assertion " #x)
|
||||
#define STB_RECT_PACK_IMPLEMENTATION
|
||||
#include <stb_rect_pack.h>
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STB_malloc(x, u) ((void)(u), MemManager::Get().Malloc(x))
|
||||
#define STB_free(x, u) ((void)(u), MemManager::Get().Free(x))
|
||||
#define STB_malloc(x, u) ((void)(u), mlx::MemManager::Get().Malloc(x))
|
||||
#define STB_free(x, u) ((void)(u), mlx::MemManager::Get().Free(x))
|
||||
#include <stb_truetype.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -43,7 +43,7 @@ namespace mlx
|
||||
stbtt_PackFontRange(&pc, std::get<std::vector<std::uint8_t>>(m_build_data).data(), 0, m_scale, 32, 96, m_cdata.data());
|
||||
stbtt_PackEnd(&pc);
|
||||
|
||||
// TODO : find better solution
|
||||
// TODO : find better solution; No, using VK_FORMAT_R8_SRGB does not work
|
||||
CPUBuffer vulkan_bitmap(RANGE * RANGE * 4);
|
||||
for(int i = 0, j = 0; i < RANGE * RANGE; i++, j += 4)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
#include <PreCompiled.h>
|
||||
#include <Renderer/Image.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Utils/CallOnExit.h>
|
||||
#include <Core/Memory.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
|
||||
#define STBI_ASSERT(x) mlx::Assert(x, "internal stb assertion " #x)
|
||||
#define STBI_MALLOC(x) (mlx::MemManager::Get().Malloc(x))
|
||||
#define STBI_REALLOC(p, x) (mlx::MemManager::Get().Realloc(p, x))
|
||||
#define STBI_FREE(x) (mlx::MemManager::Get().Free(x))
|
||||
|
||||
#ifdef MLX_COMPILER_GCC
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
||||
@@ -264,7 +272,7 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::string filename = file.string();
|
||||
|
||||
if(file.stem() == "banana")
|
||||
if(file.stem() == "terracotta.pie")
|
||||
Message("banana, banana, banana, banana, terracotta banana terracotta, terracotta pie");
|
||||
|
||||
if(!std::filesystem::exists(file))
|
||||
@@ -274,21 +282,28 @@ namespace mlx
|
||||
}
|
||||
if(stbi_is_hdr(filename.c_str()))
|
||||
{
|
||||
Error("Texture: unsupported image format % (HDR image)", file);
|
||||
Error("Texture: unsupported image format from % (HDR image)", file);
|
||||
return nullptr;
|
||||
}
|
||||
int dummy_w;
|
||||
int dummy_h;
|
||||
int channels;
|
||||
std::uint8_t* data = stbi_load(filename.c_str(), (w == nullptr ? &dummy_w : w), (h == nullptr ? &dummy_h : h), &channels, 4);
|
||||
|
||||
Vec2i size;
|
||||
int channels;
|
||||
|
||||
std::uint8_t* data = stbi_load(filename.c_str(), &size.x, &size.y, &channels, STBI_rgb_alpha);
|
||||
CallOnExit defer([=]() { stbi_image_free(data); });
|
||||
|
||||
CPUBuffer buffer((w == nullptr ? dummy_w : *w) * (h == nullptr ? dummy_h : *h) * 4);
|
||||
Verify(channels == 4, "invalid channels number in image loaded (should be 4, was %)", channels);
|
||||
|
||||
CPUBuffer buffer(size.x * size.y * 4);
|
||||
std::memcpy(buffer.GetData(), data, buffer.GetSize());
|
||||
|
||||
if(w != nullptr)
|
||||
*w = size.x;
|
||||
if(h != nullptr)
|
||||
*h = size.y;
|
||||
|
||||
Texture* texture;
|
||||
try { texture = new Texture(std::move(buffer), (w == nullptr ? dummy_w : *w), (h == nullptr ? dummy_h : *h), VK_FORMAT_R8G8B8A8_SRGB, false, std::move(filename)); }
|
||||
try { texture = new Texture(std::move(buffer), size.x, size.y, VK_FORMAT_R8G8B8A8_SRGB, false, std::move(filename)); }
|
||||
catch(...) { return nullptr; }
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace mlx
|
||||
{
|
||||
m_2Dpass.Init();
|
||||
m_final.Init();
|
||||
func::function<void(const EventBase&)> functor = [this, renderer](const EventBase& event)
|
||||
func::function<void(const EventBase&)> functor = [this, &renderer](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::ResizeEventCode)
|
||||
{
|
||||
@@ -34,9 +34,9 @@ namespace mlx
|
||||
m_main_render_texture.TransitionLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
void RenderPasses::Pass(Scene& scene, Renderer& renderer)
|
||||
void RenderPasses::Pass(Scene& scene, Renderer& renderer, const Vec4f& clear_color)
|
||||
{
|
||||
m_main_render_texture.Clear(renderer.GetActiveCommandBuffer(), Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
m_main_render_texture.Clear(renderer.GetActiveCommandBuffer(), clear_color);
|
||||
|
||||
m_2Dpass.Pass(scene, renderer, m_main_render_texture);
|
||||
m_final.Pass(scene, renderer, m_main_render_texture);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace mlx
|
||||
void SceneRenderer::Render(Scene& scene, Renderer& renderer)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
m_passes.Pass(scene, renderer);
|
||||
m_passes.Pass(scene, renderer, scene.GetClearColor());
|
||||
}
|
||||
|
||||
void SceneRenderer::Destroy()
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace mlx
|
||||
|
||||
for(Image& img : m_swapchain_images)
|
||||
img.DestroyImageView();
|
||||
// kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), m_swapchain);
|
||||
kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), m_swapchain);
|
||||
|
||||
RenderCore::Get().vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr);
|
||||
m_surface = VK_NULL_HANDLE;
|
||||
@@ -79,8 +79,8 @@ namespace mlx
|
||||
|
||||
VkSwapchainKHR old_swapchain = m_swapchain;
|
||||
m_swapchain = kvfCreateSwapchainKHR(RenderCore::Get().GetDevice(), RenderCore::Get().GetPhysicalDevice(), m_surface, extent, VK_NULL_HANDLE, true);
|
||||
// if(old_swapchain != VK_NULL_HANDLE)
|
||||
// kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), old_swapchain);
|
||||
if(old_swapchain != VK_NULL_HANDLE)
|
||||
kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), old_swapchain);
|
||||
|
||||
m_images_count = kvfGetSwapchainImagesCount(m_swapchain);
|
||||
m_min_images_count = kvfGetSwapchainMinImagesCount(m_swapchain);
|
||||
|
||||
Reference in New Issue
Block a user