mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
working on text put pipeline
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* xpm_reader.h :+: :+: :+: */
|
||||
/* text_pipeline.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 13:25:55 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/05 13:35:48 by maldavid ### ########.fr */
|
||||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/06 16:42:10 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_XPM_READER__
|
||||
#define __MLX_XPM_READER__
|
||||
|
||||
#include <filesystem>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <renderer/text_pipeline.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
std::vector<uint8_t> parseXpmData(char** data, int* w, int* h);
|
||||
std::vector<uint8_t> parseXpmFile(std::filesystem::path file, int* w, int* h);
|
||||
}
|
||||
void TextPutPipeline::init(Renderer& renderer) noexcept
|
||||
{
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextPutPipeline::put(int x, int y, int color, std::string str)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
38
src/renderer/text_pipeline.h
git.filemode.normal_file
38
src/renderer/text_pipeline.h
git.filemode.normal_file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* text_pipeline.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/06 16:41:09 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_TEXT_PIPELINE__
|
||||
#define __MLX_TEXT_PIPELINE__
|
||||
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <string>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class TextPutPipeline
|
||||
{
|
||||
public:
|
||||
TextPutPipeline() = default;
|
||||
|
||||
void init(Renderer& renderer) noexcept;
|
||||
|
||||
void put(int x, int y, int color, std::string str);
|
||||
|
||||
~TextPutPipeline() = default;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
27
src/utils/endian.h
git.filemode.normal_file
27
src/utils/endian.h
git.filemode.normal_file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* endian.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 15:33:15 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/06 15:35:25 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_ENDIAN__
|
||||
#define __MLX_ENDIAN__
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
inline bool isSystemBigEndian()
|
||||
{
|
||||
const int value = 0x01;
|
||||
const void* address = static_cast<const void*>(&value);
|
||||
const unsigned char* least_significant_address = static_cast<const unsigned char*>(address);
|
||||
return (*least_significant_address != 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* xpm_reader.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/05 13:37:21 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/06 15:20:14 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <utils/xpm_reader.h>
|
||||
#include <core/errors.h>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
std::vector<uint8_t> parseXpmFile(std::filesystem::path file, int* w, int* h)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> parseXpmData(char** data, int* w, int* h)
|
||||
{
|
||||
if(data == nullptr)
|
||||
{
|
||||
core::error::report(e_kind::error, "Xpm reader : null data");
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t width = -1;
|
||||
int32_t height = -1;
|
||||
int32_t ncolors = -1;
|
||||
int32_t cpp = -1; // chars per pixels
|
||||
//
|
||||
std::stringstream stream;
|
||||
|
||||
stream.str(data[0]);
|
||||
stream >> width;
|
||||
stream >> height;
|
||||
stream >> ncolors;
|
||||
stream >> cpp;
|
||||
if(width == -1 || height == -1 || ncolors == -1 || cpp == -1 || !stream.eof())
|
||||
{
|
||||
core::error::report(e_kind::error, "Xpm reader : invalid pixmap description");
|
||||
return {};
|
||||
}
|
||||
|
||||
*w = width;
|
||||
*h = height;
|
||||
|
||||
stream.clear();
|
||||
std::vector<std::string> colors;
|
||||
colors.reserve(ncolors);
|
||||
std::cout << ncolors << std::endl;
|
||||
for(int32_t i = 1; i < ncolors; ++i)
|
||||
{
|
||||
std::cout << (bool)(i < ncolors) << std::endl;
|
||||
stream.str(data[i]);
|
||||
std::string c;
|
||||
stream >> c;
|
||||
|
||||
std::cout << ncolors << " " << i << " " << c << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user