mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
fixing bug in texture clear
This commit is contained in:
@@ -59,26 +59,25 @@ namespace mlx
|
||||
}
|
||||
is_newlayer = true;
|
||||
|
||||
bool adjusment = false;
|
||||
if(m_current_texture_index >= m_textures.size())
|
||||
{
|
||||
#ifdef DEBUG
|
||||
m_textures.push_back(std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_put_pixel_layer_" + std::to_string(draw_layer)));
|
||||
m_textures.push_back(std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_put_pixel_layer_" + std::to_string(m_current_texture_index)));
|
||||
#else
|
||||
m_textures.push_back(std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, std::string_view{}));
|
||||
#endif
|
||||
m_current_texture_index++;
|
||||
adjusment = true;
|
||||
}
|
||||
try
|
||||
{
|
||||
m_placements[draw_layer] = m_textures.at(m_current_texture_index - adjusment).get();
|
||||
m_textures.at(m_current_texture_index - adjusment)->Clear(VK_NULL_HANDLE, Vec4f{ 0.0f });
|
||||
return m_textures.at(m_current_texture_index - adjusment).get();
|
||||
m_placements[draw_layer] = m_textures.at(m_current_texture_index).get();
|
||||
m_textures.at(m_current_texture_index)->Clear(VK_NULL_HANDLE, Vec4f{ 0.0f });
|
||||
NonOwningPtr<Texture> texture = m_textures.at(m_current_texture_index).get();
|
||||
m_current_texture_index++;
|
||||
return texture;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
Error("PutPixelManager: invalid texture index; % is not in range of 0-% (internal mlx issue, please report to devs)", m_current_texture_index - adjusment, m_textures.size());
|
||||
Error("PutPixelManager: invalid texture index; % is not in range of 0-% (internal mlx issue, please report to devs)", m_current_texture_index, m_textures.size());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -86,8 +85,6 @@ namespace mlx
|
||||
void PutPixelManager::ResetRenderData()
|
||||
{
|
||||
m_placements.clear();
|
||||
for(auto& texture : m_textures)
|
||||
texture->Clear(VK_NULL_HANDLE, Vec4f{ 0.0f });
|
||||
m_current_texture_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,6 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
unsigned char reverse(unsigned char b)
|
||||
{
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
@@ -293,6 +285,21 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::Clear(VkCommandBuffer cmd, Vec4f color)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Image::Clear(cmd, std::move(color));
|
||||
if(m_staging_buffer.has_value())
|
||||
{
|
||||
std::uint8_t color_bytes[4];
|
||||
color_bytes[0] = static_cast<std::uint8_t>(color.r * 255.f);
|
||||
color_bytes[1] = static_cast<std::uint8_t>(color.g * 255.f);
|
||||
color_bytes[2] = static_cast<std::uint8_t>(color.b * 255.f);
|
||||
color_bytes[3] = static_cast<std::uint8_t>(color.a * 255.f);
|
||||
std::fill(m_cpu_buffer.begin(), m_cpu_buffer.end(), *reinterpret_cast<int*>(color_bytes));
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::Update(VkCommandBuffer cmd)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
|
||||
Reference in New Issue
Block a user