mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
reworking texture modifiers
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/22 19:56:48 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 15:09:04 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -156,17 +156,29 @@ int mlx_pixel_put(void* mlx, void* win, int x, int y, int color);
|
|||||||
void* mlx_new_image(void* mlx, int width, int height);
|
void* mlx_new_image(void* mlx, int width, int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get data address of the internal image to modify it
|
* @brief Get image pixel data
|
||||||
*
|
*
|
||||||
* @param mlx Internal MLX application
|
* @param mlx Internal MLX application
|
||||||
* @param img Internal image
|
* @param img Internal image
|
||||||
* @param bits_per_pixel Get bits per pixel information
|
* @param x X coordinate in the image
|
||||||
* @param size_line Get size of a line of the image
|
* @param y Y coordinate in the image
|
||||||
* @param endian Get endian of the processor
|
|
||||||
*
|
*
|
||||||
* @return (char*) Return raw address of the image's data or NULL (0x0) in case of error
|
* @return (int) Return the pixel data
|
||||||
*/
|
*/
|
||||||
char* mlx_get_data_addr(void* mlx, void* img, int* bits_per_pixel, int* size_line, int* endian);
|
int mlx_get_image_pixel(void* mlx, void* img, int x, int y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set image pixel data
|
||||||
|
*
|
||||||
|
* @param mlx Internal MLX application
|
||||||
|
* @param img Internal image
|
||||||
|
* @param x X coordinate in the image
|
||||||
|
* @param y Y coordinate in the image
|
||||||
|
* @param color Color of the pixel to set
|
||||||
|
*
|
||||||
|
* @return (void)
|
||||||
|
*/
|
||||||
|
void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Put image to the given window
|
* @brief Put image to the given window
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/22 19:39:59 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 15:12:57 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -46,16 +46,6 @@ namespace mlx::core
|
|||||||
return &_textures.front();
|
return &_textures.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Application::mapTexture(Texture* img, int* bits_per_pixel, int* size_line, int* endian)
|
|
||||||
{
|
|
||||||
static const int endianness = isSystemBigEndian();
|
|
||||||
|
|
||||||
*bits_per_pixel = 32;
|
|
||||||
*size_line = img->getWidth() * 4;
|
|
||||||
*endian = endianness;
|
|
||||||
return static_cast<char*>(img->openCPUmap());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::destroyTexture(void* ptr)
|
void Application::destroyTexture(void* ptr)
|
||||||
{
|
{
|
||||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/21 19:24:12 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 15:23:31 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -48,8 +48,9 @@ namespace mlx::core
|
|||||||
|
|
||||||
void* newTexture(int w, int h);
|
void* newTexture(int w, int h);
|
||||||
void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)
|
void* newStbTexture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)
|
||||||
char* mapTexture(Texture* img, int* bits_per_pixel, int* size_line, int* endian);
|
|
||||||
inline void texturePut(void* win, void* img, int x, int y);
|
inline void texturePut(void* win, void* img, int x, int y);
|
||||||
|
inline int getTexturePixel(void* img, int x, int y);
|
||||||
|
inline void setTexturePixel(void* img, int x, int y, uint32_t color);
|
||||||
void destroyTexture(void* ptr);
|
void destroyTexture(void* ptr);
|
||||||
|
|
||||||
inline void loopHook(int (*f)(void*), void* param);
|
inline void loopHook(int (*f)(void*), void* param);
|
||||||
|
|||||||
@@ -73,6 +73,18 @@ namespace mlx::core
|
|||||||
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
|
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Application::getTexturePixel(void* img, int x, int y)
|
||||||
|
{
|
||||||
|
Texture* texture = static_cast<Texture*>(img);
|
||||||
|
return texture->getPixel(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setTexturePixel(void* img, int x, int y, uint32_t color)
|
||||||
|
{
|
||||||
|
Texture* texture = static_cast<Texture*>(img);
|
||||||
|
texture->setPixel(x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
void Application::loopHook(int (*f)(void*), void* param)
|
void Application::loopHook(int (*f)(void*), void* param)
|
||||||
{
|
{
|
||||||
_loop_hook = f;
|
_loop_hook = f;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/21 19:29:49 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 15:23:05 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -80,9 +80,19 @@ extern "C"
|
|||||||
return mlx->newTexture(width, height);
|
return mlx->newTexture(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* mlx_get_data_addr(mlx::core::Application* mlx, mlx::Texture* img, int* bits_per_pixel, int* size_line, int* endian)
|
int mlx_get_image_pixel(mlx::core::Application* mlx, void* img, int x, int y)
|
||||||
{
|
{
|
||||||
return mlx->mapTexture(img, bits_per_pixel, size_line, endian);
|
return mlx->getTexturePixel(img, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_set_image_pixel(mlx::core::Application* mlx, void* img, int x, int y, int color)
|
||||||
|
{
|
||||||
|
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] = 0xFF;
|
||||||
|
mlx->setTexturePixel(img, x, y, *reinterpret_cast<unsigned int*>(color_bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_put_image_to_window(mlx::core::Application* mlx, void* win, void* img, int x, int y)
|
int mlx_put_image_to_window(mlx::core::Application* mlx, void* win, void* img, int x, int y)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/23 15:30:54 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 22:13:45 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -20,33 +20,12 @@
|
|||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, bool enable_mapping)
|
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format)
|
||||||
{
|
{
|
||||||
if(enable_mapping)
|
Image::create(width, height, format, VK_IMAGE_TILING_OPTIMAL,
|
||||||
{
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||||
#ifdef DEBUG
|
{ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT }
|
||||||
core::error::report(e_kind::message, "Texture : creating CPU mappable texture");
|
);
|
||||||
#endif
|
|
||||||
Image::create(width, height, format, VK_IMAGE_TILING_LINEAR,
|
|
||||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
||||||
{
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
|
||||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
|
||||||
core::error::report(e_kind::message, "Texture : creating non CPU mappable texture");
|
|
||||||
#endif
|
|
||||||
Image::create(width, height, format, VK_IMAGE_TILING_OPTIMAL,
|
|
||||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
||||||
{ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||||
Image::createSampler();
|
Image::createSampler();
|
||||||
@@ -73,6 +52,8 @@ namespace mlx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::setPixel()
|
||||||
|
|
||||||
void* Texture::openCPUmap()
|
void* Texture::openCPUmap()
|
||||||
{
|
{
|
||||||
if(_cpu_map != nullptr)
|
if(_cpu_map != nullptr)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/23 15:23:44 by maldavid ### ########.fr */
|
/* Updated: 2023/04/25 20:10:44 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -29,11 +29,12 @@ namespace mlx
|
|||||||
public:
|
public:
|
||||||
Texture() = default;
|
Texture() = default;
|
||||||
|
|
||||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, bool enable_mapping = false);
|
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
||||||
void render(class Renderer& renderer, int x, int y);
|
void render(class Renderer& renderer, int x, int y);
|
||||||
void destroy() noexcept override;
|
void destroy() noexcept override;
|
||||||
|
|
||||||
void* openCPUmap();
|
void setPixel(int x, int y, uint32_t color) noexcept;
|
||||||
|
int getPixel(int x, int y) noexcept;
|
||||||
|
|
||||||
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
||||||
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||||
|
|||||||
Reference in New Issue
Block a user