reworking texture modifiers

This commit is contained in:
2023-04-25 22:14:01 +02:00
parent cb4e9dbe8d
commit 6a8d55dbe8
7 changed files with 60 additions and 53 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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();
}
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)
{
vkDeviceWaitIdle(Render_Core::get().getDevice().get());

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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* 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 int getTexturePixel(void* img, int x, int y);
inline void setTexturePixel(void* img, int x, int y, uint32_t color);
void destroyTexture(void* ptr);
inline void loopHook(int (*f)(void*), void* param);

View File

@@ -73,6 +73,18 @@ namespace mlx::core
_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)
{
_loop_hook = f;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
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)