working on text put pipeline

This commit is contained in:
2023-04-06 17:26:19 +02:00
parent b03bd6fe0a
commit bada255057
12 changed files with 125 additions and 108 deletions

View File

@@ -6,16 +6,15 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/04/06 15:27:21 by maldavid ### ########.fr */
/* Updated: 2023/04/06 15:35:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "application.h"
#include <renderer/images/texture.h>
#include <renderer/core/render_core.h>
#include <X11/X.h> // for LSBFirst
#include <array>
#include <utils/xpm_reader.h>
#include <utils/endian.h>
namespace mlx::core
{
@@ -59,7 +58,7 @@ namespace mlx::core
char* map = static_cast<char*>(texture->openCPUmap());
*bits_per_pixel = sizeof(uint32_t) * 8;
*size_line = texture->getWidth();
*endian = LSBFirst;
*endian = isSystemBigEndian();
return map;
}

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/06 15:27:32 by maldavid ### ########.fr */
/* Updated: 2023/04/06 16:08:34 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,7 +35,7 @@ namespace mlx::core
Application() : _in() {}
inline void getMousePos(int* x, int* y) noexcept;
inline void mouseMove(void* win_ptr, int x, int y) noexcept;
inline void mouseMove(void* win, int x, int y) noexcept;
inline constexpr void enableAutoRepeat() noexcept;
inline constexpr void disableAutoRepeat() noexcept;
@@ -43,15 +43,16 @@ namespace mlx::core
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 clearGraphicsSupport(void* win);
inline void destroyGraphicsSupport(void* win);
inline void pixelPut(void* win_ptr, int x, int y, int color) const noexcept;
inline void pixelPut(void* win, int x, int y, int color) const noexcept;
inline void stringPut(void* win, int x, int y, int color, char* str);
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);
char* mapTexture(void* img, int* bits_per_pixel, int* size_line, int* endian);
inline void texturePut(void* win, void* img, int x, int y);
void destroyTexture(void* ptr);
inline void loopHook(int (*f)(void*), void* param);

View File

@@ -20,9 +20,9 @@ namespace mlx::core
*y = _in.getY();
}
void Application::mouseMove(void* win_ptr, int x, int y) noexcept
void Application::mouseMove(void* win, int x, int y) noexcept
{
SDL_WarpMouseInWindow(_graphics[*static_cast<int*>(win_ptr)]->getWindow()->getNativeWindow(), x, y);
SDL_WarpMouseInWindow(_graphics[*static_cast<int*>(win)]->getWindow()->getNativeWindow(), x, y);
SDL_PumpEvents();
SDL_FlushEvent(SDL_MOUSEMOTION);
}
@@ -51,26 +51,31 @@ namespace mlx::core
return static_cast<void*>(&_graphics.back()->getID());
}
void Application::clearGraphicsSupport(void* win_ptr)
void Application::clearGraphicsSupport(void* win)
{
_graphics[*static_cast<int*>(win_ptr)]->clearRenderData();
_graphics[*static_cast<int*>(win)]->clearRenderData();
}
void Application::destroyGraphicsSupport(void* win_ptr)
void Application::destroyGraphicsSupport(void* win)
{
_graphics[*static_cast<int*>(win_ptr)].reset();
_graphics[*static_cast<int*>(win)].reset();
}
void Application::pixelPut(void* win_ptr, int x, int y, int color) const noexcept
void Application::pixelPut(void* win, int x, int y, int color) const noexcept
{
_graphics[*static_cast<int*>(win_ptr)]->pixelPut(x, y, color);
_graphics[*static_cast<int*>(win)]->pixelPut(x, y, color);
}
void Application::texturePut(void* win_ptr, void* img, int x, int y)
void Application::stringPut(void* win, int x, int y, int color, char* str)
{
}
void Application::texturePut(void* win, void* img, int x, int y)
{
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);
_graphics[*static_cast<int*>(win)]->texturePut(texture, x, y);
}
void Application::loopHook(int (*f)(void*), void* param)

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/06 15:27:54 by maldavid ### ########.fr */
/* Updated: 2023/04/06 16:09:47 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -142,6 +142,12 @@ extern "C"
return 0;
}
int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str)
{
static_cast<mlx::core::Application*>(mlx)->stringPut(win, x, y, color, str);
return 0;
}
int mlx_clear_window(void* mlx, void* win)
{
static_cast<mlx::core::Application*>(mlx)->clearGraphicsSupport(win);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2023/04/02 17:33:47 by maldavid ### ########.fr */
/* Updated: 2023/04/06 16:39:13 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,6 +22,7 @@ namespace mlx
_renderer->setWindow(_window.get());
_renderer->init();
_pixel_put_pipeline.init(w, h, *_renderer);
_text_put_pipeline.init(*_renderer);
}
void GraphicsSupport::endRender() noexcept

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2023/04/03 14:23:57 by maldavid ### ########.fr */
/* Updated: 2023/04/06 16:38:50 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,6 +39,7 @@ namespace mlx
inline void clearRenderData() noexcept;
inline void pixelPut(int x, int y, int color) noexcept;
inline void stringPut(int x, int y, int color, std::string str);
inline void texturePut(std::shared_ptr<Texture> texture, int x, int y);
void endRender() noexcept;
@@ -47,9 +48,10 @@ namespace mlx
private:
std::unordered_set<TextureRenderData> _textures_to_render;
PixelPutPipeline _pixel_put_pipeline;
TextPutPipeline _text_put_pipeline;
glm::mat4 _proj = glm::mat4(1.0);
std::shared_ptr<MLX_Window> _window;
PixelPutPipeline _pixel_put_pipeline;
std::unique_ptr<Renderer> _renderer;
int _id;
};

View File

@@ -36,6 +36,11 @@ namespace mlx
_pixel_put_pipeline.setPixel(x, y, color);
}
void GraphicsSupport::stringPut(int x, int y, int color, std::string str)
{
_text_put_pipeline.put(x, y, color, str);
}
void GraphicsSupport::texturePut(std::shared_ptr<Texture> texture, int x, int y)
{
_textures_to_render.emplace(texture, x, y);