implementing last functions, adding put pixel region

This commit is contained in:
2024-12-16 16:13:44 +01:00
parent feb3fcbd1f
commit 623021a669
10 changed files with 201 additions and 18 deletions

View File

@@ -25,6 +25,8 @@ namespace mlx
inline void ResetRenderData(int 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 TexturePut(NonOwningPtr<class Texture> texture, int x, int y, float scale_x, float scale_y, float angle);

View File

@@ -30,6 +30,30 @@ namespace mlx
}
}
void GraphicsSupport::PixelPutArray(int x, int y, int* 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);
if(texture)
{
m_pixelput_called = true;
Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetPosition(Vec2f{ 0.0f, 0.0f });
}
}
void GraphicsSupport::PixelPutRegion(int x, int y, int w, int h, int* pixels) noexcept
{
MLX_PROFILE_FUNCTION();
NonOwningPtr<Texture> texture = m_put_pixel_manager.DrawPixelsRegion(x, y, w, h, m_draw_layer, pixels);
if(texture)
{
m_pixelput_called = true;
Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetPosition(Vec2f{ 0.0f, 0.0f });
}
}
void GraphicsSupport::StringPut(int x, int y, int color, std::string str)
{
MLX_PROFILE_FUNCTION();

View File

@@ -12,10 +12,15 @@ namespace mlx
// 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);
void ResetRenderData();
~PutPixelManager() = default;
private:
NonOwningPtr<Texture> GetLayer(std::uint64_t draw_layer, bool& is_newlayer);
private:
std::unordered_map<std::uint64_t, NonOwningPtr<Texture>> m_placements;
std::vector<std::unique_ptr<Texture>> m_textures;

View File

@@ -84,7 +84,10 @@ namespace mlx
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 Update(VkCommandBuffer cmd);

16
runtime/Includes/Utils/Bits.h git.filemode.normal_file
View File

@@ -0,0 +1,16 @@
#ifndef __MLX_BITS__
#define __MLX_BITS__
namespace mlx
{
template<std::integral T>
constexpr T ByteSwap(T value) noexcept
{
static_assert(std::has_unique_object_representations_v<T>, "T may not have padding bits");
auto value_representation = std::bit_cast<std::array<std::byte, sizeof(T)>>(value);
std::ranges::reverse(value_representation);
return std::bit_cast<T>(value_representation);
}
}
#endif