mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
adding manual image manipulation
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 15:11:53 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:49:03 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "application.h"
|
||||
#include <renderer/images/texture.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <X11/X.h> // for LSBFirst
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
@@ -32,6 +33,15 @@ namespace mlx::core
|
||||
}
|
||||
}
|
||||
|
||||
void* Application::newTexture(int w, int h)
|
||||
{
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>();
|
||||
texture->create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
TextureID id = _texture_lib.addTextureToLibrary(texture);
|
||||
_texture_ids.push_back(id);
|
||||
return &_texture_ids.back();
|
||||
}
|
||||
|
||||
void* Application::newStbTexture(char* file, int* w, int* h)
|
||||
{
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(stbTextureLoad(file, w, h));
|
||||
@@ -40,6 +50,17 @@ namespace mlx::core
|
||||
return &_texture_ids.back();
|
||||
}
|
||||
|
||||
char* Application::mapTexture(void* img, int* bits_per_pixel, int* size_line, int* endian)
|
||||
{
|
||||
TextureID id = *static_cast<TextureID*>(img);
|
||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
|
||||
char* map = static_cast<char*>(texture->openCPUmap());
|
||||
*bits_per_pixel = sizeof(uint32_t) * 8;
|
||||
*size_line = texture->getWidth();
|
||||
*endian = LSBFirst;
|
||||
return map;
|
||||
}
|
||||
|
||||
void Application::destroyTexture(void* ptr)
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 15:38:47 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/02 23:38:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_APPLICATION__
|
||||
#define __MLX_APPLICATION__
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
@@ -35,13 +35,17 @@ namespace mlx::core
|
||||
inline void getMousePos(int* x, int* y) noexcept;
|
||||
inline void mouseMove(void* win_ptr, int x, int y) noexcept;
|
||||
|
||||
inline void getScreenSize(int* w, int* h) noexcept;
|
||||
|
||||
inline void* newGraphicsSuport(std::size_t w, std::size_t h, std::string title);
|
||||
inline void clearGraphicsSupport(void* win_ptr);
|
||||
inline void destroyGraphicsSupport(void* win_ptr);
|
||||
|
||||
inline void pixelPut(void* win_ptr, int x, int y, int color) const noexcept;
|
||||
|
||||
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(void* img_ptr, int* bits_per_pixel, int* size_line, int* endian);
|
||||
inline void texturePut(void* win_ptr, void* img, int x, int y);
|
||||
void destroyTexture(void* ptr);
|
||||
|
||||
@@ -55,7 +59,7 @@ namespace mlx::core
|
||||
private:
|
||||
Input _in;
|
||||
TextureLibrary _texture_lib;
|
||||
std::vector<TextureID> _texture_ids;
|
||||
std::list<TextureID> _texture_ids;
|
||||
std::vector<std::unique_ptr<GraphicsSupport>> _graphics;
|
||||
std::function<int(void*)> _loop_hook;
|
||||
void* _param = nullptr;
|
||||
|
||||
@@ -27,6 +27,14 @@ namespace mlx::core
|
||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||
}
|
||||
|
||||
void Application::getScreenSize(int* w, int* h) noexcept
|
||||
{
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetDesktopDisplayMode(0, &DM);
|
||||
*w = DM.w;
|
||||
*h = DM.h;
|
||||
}
|
||||
|
||||
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, std::string title)
|
||||
{
|
||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, std::move(title), _graphics.size()));
|
||||
@@ -50,7 +58,8 @@ namespace mlx::core
|
||||
|
||||
void Application::texturePut(void* win_ptr, void* img, int x, int y)
|
||||
{
|
||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(*static_cast<TextureID*>(img));
|
||||
TextureID id = *static_cast<TextureID*>(img);
|
||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(id);
|
||||
_graphics[*static_cast<int*>(win_ptr)]->texturePut(texture, x, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 15:10:44 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/02 22:23:40 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -68,6 +68,16 @@ extern "C"
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* mlx_new_image(void* mlx, int width, int height)
|
||||
{
|
||||
return static_cast<mlx::core::Application*>(mlx)->newTexture(width, height);
|
||||
}
|
||||
|
||||
char* mlx_get_data_addr(void* mlx, void* img_ptr, int* bits_per_pixel, int* size_line, int* endian)
|
||||
{
|
||||
return static_cast<mlx::core::Application*>(mlx)->mapTexture(img_ptr, bits_per_pixel, size_line, endian);
|
||||
}
|
||||
|
||||
int mlx_put_image_to_window(void* mlx_ptr, void* win_ptr, void* img_ptr, int x, int y)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx_ptr)->texturePut(win_ptr, img_ptr, x, y);
|
||||
@@ -109,4 +119,10 @@ extern "C"
|
||||
mlx::Render_Core::get().destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_get_screens_size(void* mlx, int* w, int* h)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->getScreenSize(w, h);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user