working on endianness with vulkan images

This commit is contained in:
2024-12-17 00:11:21 +01:00
parent a85ad6378e
commit c636229875
12 changed files with 162 additions and 109 deletions

View File

@@ -22,12 +22,12 @@ namespace mlx
void Render() noexcept;
inline void ResetRenderData(int color) noexcept;
inline void ResetRenderData(mlx_color color) noexcept;
inline void PixelPut(int x, int y, int color) noexcept;
inline void PixelPutArray(int x, int y, int* pixels, std::size_t pixels_size) noexcept;
inline void PixelPutRegion(int x, int y, int w, int h, int* pixels) noexcept;
inline void StringPut(int x, int y, int, std::string str);
inline void PixelPut(int x, int y, mlx_color color) noexcept;
inline void PixelPutArray(int x, int y, mlx_color* color, std::size_t pixels_size) noexcept;
inline void PixelPutRegion(int x, int y, int w, int h, mlx_color* color) noexcept;
inline void StringPut(int x, int y, mlx_color color, std::string str);
inline void TexturePut(NonOwningPtr<class Texture> texture, int x, int y, float scale_x, float scale_y, float angle);
inline void TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept;

View File

@@ -3,14 +3,14 @@
namespace mlx
{
void GraphicsSupport::ResetRenderData(int color) noexcept
void GraphicsSupport::ResetRenderData(mlx_color color) noexcept
{
MLX_PROFILE_FUNCTION();
Vec4f vec_color = {
static_cast<float>((color & 0xFF000000) >> 24) / 255.0f,
static_cast<float>((color & 0x00FF0000) >> 16) / 255.0f,
static_cast<float>((color & 0x0000FF00) >> 8) / 255.0f,
static_cast<float>((color & 0x000000FF)) / 255.0f,
static_cast<float>(color.r) / 255.0f,
static_cast<float>(color.g) / 255.0f,
static_cast<float>(color.b) / 255.0f,
static_cast<float>(color.a) / 255.0f
};
p_scene->ResetScene(std::move(vec_color));
m_put_pixel_manager.ResetRenderData();
@@ -18,7 +18,7 @@ namespace mlx
m_pixelput_called = false;
}
void GraphicsSupport::PixelPut(int x, int y, int color) noexcept
void GraphicsSupport::PixelPut(int x, int y, mlx_color color) noexcept
{
MLX_PROFILE_FUNCTION();
NonOwningPtr<Texture> texture = m_put_pixel_manager.DrawPixel(x, y, m_draw_layer, color);
@@ -30,7 +30,7 @@ namespace mlx
}
}
void GraphicsSupport::PixelPutArray(int x, int y, int* pixels, std::size_t pixels_size) noexcept
void GraphicsSupport::PixelPutArray(int x, int y, mlx_color* pixels, std::size_t pixels_size) noexcept
{
MLX_PROFILE_FUNCTION();
NonOwningPtr<Texture> texture = m_put_pixel_manager.DrawPixelsArray(x, y, m_draw_layer, pixels, pixels_size);
@@ -42,7 +42,7 @@ namespace mlx
}
}
void GraphicsSupport::PixelPutRegion(int x, int y, int w, int h, int* pixels) noexcept
void GraphicsSupport::PixelPutRegion(int x, int y, int w, int h, mlx_color* pixels) noexcept
{
MLX_PROFILE_FUNCTION();
NonOwningPtr<Texture> texture = m_put_pixel_manager.DrawPixelsRegion(x, y, w, h, m_draw_layer, pixels);
@@ -54,17 +54,17 @@ namespace mlx
}
}
void GraphicsSupport::StringPut(int x, int y, int color, std::string str)
void GraphicsSupport::StringPut(int x, int y, mlx_color color, std::string str)
{
MLX_PROFILE_FUNCTION();
if(str.empty())
return;
Vec4f vec_color = {
static_cast<float>((color & 0xFF000000) >> 24) / 255.0f,
static_cast<float>((color & 0x00FF0000) >> 16) / 255.0f,
static_cast<float>((color & 0x0000FF00) >> 8) / 255.0f,
static_cast<float>((color & 0x000000FF)) / 255.0f,
static_cast<float>(color.r) / 255.0f,
static_cast<float>(color.g) / 255.0f,
static_cast<float>(color.b) / 255.0f,
static_cast<float>(color.a) / 255.0f,
};
NonOwningPtr<Text> text = p_scene->GetTextFromPositionAndColor(str, Vec2f{ static_cast<float>(x), static_cast<float>(y) }, vec_color);

View File

@@ -11,9 +11,9 @@ namespace mlx
PutPixelManager(NonOwningPtr<class Renderer> renderer) : p_renderer(renderer) {}
// Returns a valid pointer when a new texture has been created
NonOwningPtr<Texture> DrawPixel(int x, int y, std::uint64_t draw_layer, int color);
NonOwningPtr<Texture> DrawPixelsArray(int x, int y, std::uint64_t draw_layer, int* pixels, std::size_t pixels_size);
NonOwningPtr<Texture> DrawPixelsRegion(int x, int y, int w, int h, std::uint64_t draw_layer, int* pixels);
NonOwningPtr<Texture> DrawPixel(int x, int y, std::uint64_t draw_layer, mlx_color color);
NonOwningPtr<Texture> DrawPixelsArray(int x, int y, std::uint64_t draw_layer, mlx_color* pixels, std::size_t pixels_size);
NonOwningPtr<Texture> DrawPixelsRegion(int x, int y, int w, int h, std::uint64_t draw_layer, mlx_color* pixels);
void ResetRenderData();
~PutPixelManager() = default;

View File

@@ -83,11 +83,11 @@ namespace mlx
void Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, [[maybe_unused]] std::string_view debug_name);
void Destroy() noexcept override;
void SetPixel(int x, int y, int color) noexcept;
void SetRegion(int x, int y, int w, int h, int* pixels) noexcept;
void SetLinearRegion(int x, int y, std::size_t len, int* pixels) noexcept;
int GetPixel(int x, int y) noexcept;
void GetRegion(int x, int y, int w, int h, int* dst) noexcept;
void SetPixel(int x, int y, mlx_color color) noexcept;
void SetRegion(int x, int y, int w, int h, mlx_color* color) noexcept;
void SetLinearRegion(int x, int y, std::size_t len, mlx_color* color) noexcept;
mlx_color GetPixel(int x, int y) noexcept;
void GetRegion(int x, int y, int w, int h, mlx_color* dst) noexcept;
void Clear(VkCommandBuffer cmd, Vec4f color) override;
void Update(VkCommandBuffer cmd);
@@ -98,7 +98,7 @@ namespace mlx
void OpenCPUBuffer();
private:
std::vector<int> m_cpu_buffer;
std::vector<mlx_color> m_cpu_buffer;
std::optional<GPUBuffer> m_staging_buffer;
bool m_has_been_modified = false;
};

View File

@@ -11,6 +11,38 @@ namespace mlx
std::ranges::reverse(value_representation);
return std::bit_cast<T>(value_representation);
}
constexpr std::uint32_t Rmask() noexcept
{
if constexpr(std::endian::native == std::endian::big)
return 0xFF000000;
else
return 0x000000FF;
}
constexpr std::uint32_t Gmask() noexcept
{
if constexpr(std::endian::native == std::endian::big)
return 0x00FF0000;
else
return 0x0000FF00;
}
constexpr std::uint32_t Bmask() noexcept
{
if constexpr(std::endian::native == std::endian::big)
return 0x0000FF00;
else
return 0x00FF0000;
}
constexpr std::uint32_t Amask() noexcept
{
if constexpr(std::endian::native == std::endian::big)
return 0x000000FF;
else
return 0xFF000000;
}
}
#endif