mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-09-03 05:00:01 +02:00
Added mlx_set_image_rectangle
This commit is contained in:
@@ -286,6 +286,36 @@ namespace mlx
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
void Texture::SetRectangle(int x, int y, int w, int h, mlx_color color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(w < 0 || h < 0 || x < -w || y < -h
|
||||
|| x >= static_cast<int>(m_width) || y >= static_cast<int>(m_height))
|
||||
return;
|
||||
if(!m_staging_buffer.has_value())
|
||||
OpenCPUBuffer();
|
||||
const int
|
||||
start_x = std::max<int>(x, 0),
|
||||
start_row = std::max<int>(y, 0) * m_width,
|
||||
end_x = std::min<int>(x + w, m_width),
|
||||
end_row = std::min<int>(y + h, m_height) * m_width;
|
||||
for(int dx = start_x, row = start_row;; dx++)
|
||||
{
|
||||
if(dx >= end_x)
|
||||
{
|
||||
dx = start_x;
|
||||
row += m_width;
|
||||
if(row >= end_row)
|
||||
break;
|
||||
}
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
m_staging_buffer->GetMap<mlx_color*>()[row + dx] = ReverseColor(color);
|
||||
else
|
||||
m_staging_buffer->GetMap<mlx_color*>()[row + dx] = color;
|
||||
}
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
mlx_color Texture::GetPixel(int x, int y) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
|
||||
Reference in New Issue
Block a user