mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
adding transformations
This commit is contained in:
@@ -27,7 +27,7 @@ int update(void* param)
|
||||
mlx_string_put(mlx->mlx, mlx->win, 160, 120, 0xFFFF2066, "this text should be hidden");
|
||||
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_png, 100, 100);
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_bmp, 220, 40);
|
||||
mlx_transform_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_bmp, 220, 40, 0.5f, 75.0f);
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
|
||||
|
||||
mlx_set_font(mlx->mlx, "default");
|
||||
@@ -40,7 +40,7 @@ int update(void* param)
|
||||
color += (color < 255);
|
||||
}
|
||||
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_jpg, 210, 150);
|
||||
mlx_transform_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_jpg, 210, 150, 2.0f, 0.0f);
|
||||
mlx_set_font_scale(mlx->mlx, "default", 8.f);
|
||||
mlx_string_put(mlx->mlx, mlx->win, 210, 175, 0xFFAF2BFF, "hidden");
|
||||
|
||||
@@ -131,7 +131,7 @@ int main(void)
|
||||
int dummy;
|
||||
|
||||
mlx.mlx = mlx_init();
|
||||
mlx.win = mlx_new_resizable_window(mlx.mlx, 400, 400, "My window");
|
||||
mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window");
|
||||
|
||||
mlx_set_fps_goal(mlx.mlx, 60);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <contact@kbz8.me> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||
/* Updated: 2024/11/04 21:09:59 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/11/05 18:18:22 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -234,6 +234,21 @@ MLX_API void mlx_set_image_pixel(void* mlx, void* img, int x, int y, int color);
|
||||
*/
|
||||
MLX_API void mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y);
|
||||
|
||||
/**
|
||||
* @brief Transform and put image to the given window
|
||||
*
|
||||
* @param mlx Internal MLX application
|
||||
* @param win Internal window
|
||||
* @param img Internal image
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param scale Scale of the image
|
||||
* @param angle Rotation angle of the image (clockwise)
|
||||
*
|
||||
* @return (void)
|
||||
*/
|
||||
MLX_API void mlx_transform_put_image_to_window(void* mlx, void* win, void* img, int x, int y, float scale, float angle);
|
||||
|
||||
/**
|
||||
* @brief Destroys internal image
|
||||
*
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace mlx
|
||||
|
||||
Handle NewTexture(int w, int h);
|
||||
Handle NewStbTexture(char* file, int* w, int* h); // stb textures are image files (png, jpg, bpm, ...)
|
||||
inline void TexturePut(Handle win, Handle img, int x, int y);
|
||||
inline void TexturePut(Handle win, Handle img, int x, int y, float scale, float angle);
|
||||
inline int GetTexturePixel(Handle img, int x, int y);
|
||||
inline void SetTexturePixel(Handle img, int x, int y, std::uint32_t color);
|
||||
void DestroyTexture(Handle ptr);
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
void Application::TexturePut(Handle win, Handle img, int x, int y)
|
||||
void Application::TexturePut(Handle win, Handle img, int x, int y, float scale, float angle)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
CHECK_WINDOW_PTR(win);
|
||||
@@ -178,7 +178,7 @@ namespace mlx
|
||||
if(!texture->IsInit())
|
||||
Error("trying to put a texture that has been destroyed");
|
||||
else
|
||||
m_graphics[*static_cast<int*>(win)]->TexturePut(texture, x, y);
|
||||
m_graphics[*static_cast<int*>(win)]->TexturePut(texture, x, y, scale, angle);
|
||||
}
|
||||
|
||||
int Application::GetTexturePixel(Handle img, int x, int y)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace mlx
|
||||
|
||||
inline void PixelPut(int x, int y, std::uint32_t color) noexcept;
|
||||
inline void StringPut(int x, int y, std::uint32_t color, std::string str);
|
||||
inline void TexturePut(NonOwningPtr<class Texture> texture, int x, int y);
|
||||
inline void TexturePut(NonOwningPtr<class Texture> texture, int x, int y, float scale, float angle);
|
||||
|
||||
inline void TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept;
|
||||
|
||||
|
||||
@@ -54,15 +54,16 @@ namespace mlx
|
||||
Text& new_text = p_scene->CreateText(str);
|
||||
new_text.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
|
||||
new_text.SetColor(std::move(vec_color));
|
||||
new_text.SetCenter(Vec2f{ 0.0f, 0.0f });
|
||||
}
|
||||
else if(!p_scene->IsTextAtGivenDrawLayer(str, m_draw_layer))
|
||||
p_scene->BringToDrawLayer(text.Get(), m_draw_layer);
|
||||
}
|
||||
|
||||
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
|
||||
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y, float scale, float angle)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
NonOwningPtr<Sprite> sprite = p_scene->GetSpriteFromTextureAndPosition(texture, Vec2f{ static_cast<float>(x), static_cast<float>(y) });
|
||||
NonOwningPtr<Sprite> sprite = p_scene->GetSpriteFromTexturePositionScaleRotation(texture, Vec2f{ static_cast<float>(x), static_cast<float>(y) }, scale, angle);
|
||||
if(!sprite)
|
||||
{
|
||||
if(m_pixelput_called)
|
||||
@@ -72,7 +73,9 @@ namespace mlx
|
||||
}
|
||||
Sprite& new_sprite = p_scene->CreateSprite(texture);
|
||||
new_sprite.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
|
||||
|
||||
new_sprite.SetScale(Vec2f{ scale, scale });
|
||||
new_sprite.SetRotation(angle);
|
||||
new_sprite.SetCenter(Vec2f{ texture->GetWidth() / 2.0f, texture->GetHeight() / 2.0f });
|
||||
}
|
||||
else if(!p_scene->IsTextureAtGivenDrawLayer(texture, m_draw_layer))
|
||||
p_scene->BringToDrawLayer(sprite.Get(), m_draw_layer);
|
||||
|
||||
@@ -30,13 +30,8 @@ namespace mlx
|
||||
|
||||
static void Report(LogType type, std::string message);
|
||||
static void Report(LogType type, unsigned int line, std::string_view file, std::string_view function, std::string message);
|
||||
static void BeginSection();
|
||||
static void EndSection();
|
||||
|
||||
~Logs() = delete;
|
||||
|
||||
private:
|
||||
static std::uint32_t s_nesting;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -21,8 +21,8 @@ struct ViewerData
|
||||
|
||||
struct SpriteData
|
||||
{
|
||||
color: vec4[f32],
|
||||
position: vec2[f32]
|
||||
model_matrix: mat4[f32],
|
||||
color: vec4[f32]
|
||||
}
|
||||
|
||||
external
|
||||
@@ -34,11 +34,11 @@ external
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let position: vec4[f32] = vec4[f32](input.pos.xy + model.position, 1.0, 1.0);
|
||||
let position: vec4[f32] = vec4[f32](input.pos.xy, 1.0, 1.0);
|
||||
input.uv *= -1.0;
|
||||
let output: VertOut;
|
||||
output.uv = input.uv;
|
||||
output.color = model.color;
|
||||
output.pos = viewer_data.projection_matrix * position;
|
||||
output.pos = viewer_data.projection_matrix * model.model_matrix * position;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -1,70 +1,71 @@
|
||||
3,2,35,7,0,0,1,0,39,0,0,0,70,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0,
|
||||
3,0,0,0,0,0,1,0,0,0,15,0,10,0,0,0,0,0,34,0,0,0,109,97,105,110,0,0,0,0,
|
||||
14,0,0,0,19,0,0,0,25,0,0,0,27,0,0,0,28,0,0,0,3,0,3,0,0,0,0,0,100,0,
|
||||
13,0,0,0,19,0,0,0,25,0,0,0,27,0,0,0,28,0,0,0,3,0,3,0,0,0,0,0,100,0,
|
||||
0,0,5,0,5,0,4,0,0,0,86,105,101,119,101,114,68,97,116,97,0,0,6,0,8,0,4,0,0,0,
|
||||
0,0,0,0,112,114,111,106,101,99,116,105,111,110,95,109,97,116,114,105,120,0,0,0,5,0,5,0,8,0,
|
||||
0,0,83,112,114,105,116,101,68,97,116,97,0,0,6,0,5,0,8,0,0,0,0,0,0,0,99,111,108,111,
|
||||
114,0,0,0,6,0,6,0,8,0,0,0,1,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0,5,0,
|
||||
4,0,22,0,0,0,86,101,114,116,73,110,0,0,6,0,4,0,22,0,0,0,0,0,0,0,112,111,115,0,
|
||||
6,0,4,0,22,0,0,0,1,0,0,0,117,118,0,0,5,0,4,0,29,0,0,0,86,101,114,116,79,117,
|
||||
116,0,6,0,5,0,29,0,0,0,0,0,0,0,99,111,108,111,114,0,0,0,6,0,4,0,29,0,0,0,
|
||||
1,0,0,0,117,118,0,0,6,0,4,0,29,0,0,0,2,0,0,0,112,111,115,0,5,0,5,0,6,0,
|
||||
0,0,118,105,101,119,101,114,95,100,97,116,97,0,5,0,4,0,10,0,0,0,109,111,100,101,108,0,0,0,
|
||||
5,0,3,0,14,0,0,0,112,111,115,0,5,0,3,0,19,0,0,0,117,118,0,0,5,0,4,0,25,0,
|
||||
0,0,99,111,108,111,114,0,0,0,5,0,3,0,27,0,0,0,117,118,0,0,5,0,5,0,28,0,0,0,
|
||||
112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,34,0,0,0,109,97,105,110,0,0,0,0,71,0,
|
||||
4,0,6,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,6,0,0,0,34,0,0,0,0,0,0,0,
|
||||
71,0,4,0,28,0,0,0,11,0,0,0,0,0,0,0,71,0,4,0,14,0,0,0,30,0,0,0,0,0,
|
||||
0,0,71,0,4,0,19,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,25,0,0,0,30,0,0,0,
|
||||
0,0,0,0,71,0,4,0,27,0,0,0,30,0,0,0,1,0,0,0,71,0,3,0,4,0,0,0,2,0,
|
||||
0,0,72,0,4,0,4,0,0,0,0,0,0,0,5,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0,
|
||||
7,0,0,0,16,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0,
|
||||
3,0,8,0,0,0,2,0,0,0,72,0,5,0,8,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,
|
||||
72,0,5,0,8,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,22,0,0,0,0,0,
|
||||
0,0,35,0,0,0,0,0,0,0,72,0,5,0,22,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0,
|
||||
72,0,5,0,29,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,29,0,0,0,1,0,
|
||||
0,0,35,0,0,0,16,0,0,0,72,0,5,0,29,0,0,0,2,0,0,0,35,0,0,0,32,0,0,0,
|
||||
22,0,3,0,1,0,0,0,32,0,0,0,23,0,4,0,2,0,0,0,1,0,0,0,4,0,0,0,24,0,
|
||||
4,0,3,0,0,0,2,0,0,0,4,0,0,0,30,0,3,0,4,0,0,0,3,0,0,0,32,0,4,0,
|
||||
5,0,0,0,2,0,0,0,4,0,0,0,23,0,4,0,7,0,0,0,1,0,0,0,2,0,0,0,30,0,
|
||||
4,0,8,0,0,0,2,0,0,0,7,0,0,0,32,0,4,0,9,0,0,0,9,0,0,0,8,0,0,0,
|
||||
19,0,2,0,11,0,0,0,33,0,3,0,12,0,0,0,11,0,0,0,32,0,4,0,13,0,0,0,1,0,
|
||||
0,0,2,0,0,0,21,0,4,0,15,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,15,0,0,0,
|
||||
16,0,0,0,0,0,0,0,32,0,4,0,17,0,0,0,7,0,0,0,2,0,0,0,32,0,4,0,18,0,
|
||||
0,0,1,0,0,0,7,0,0,0,43,0,4,0,15,0,0,0,20,0,0,0,1,0,0,0,32,0,4,0,
|
||||
21,0,0,0,7,0,0,0,7,0,0,0,30,0,4,0,22,0,0,0,2,0,0,0,7,0,0,0,32,0,
|
||||
4,0,23,0,0,0,7,0,0,0,22,0,0,0,32,0,4,0,24,0,0,0,3,0,0,0,2,0,0,0,
|
||||
32,0,4,0,26,0,0,0,3,0,0,0,7,0,0,0,30,0,5,0,29,0,0,0,2,0,0,0,7,0,
|
||||
0,0,2,0,0,0,43,0,4,0,1,0,0,0,30,0,0,0,0,0,128,63,43,0,4,0,1,0,0,0,
|
||||
31,0,0,0,0,0,128,191,32,0,4,0,32,0,0,0,7,0,0,0,29,0,0,0,43,0,4,0,15,0,
|
||||
0,0,33,0,0,0,2,0,0,0,32,0,4,0,44,0,0,0,9,0,0,0,7,0,0,0,32,0,4,0,
|
||||
56,0,0,0,9,0,0,0,2,0,0,0,32,0,4,0,60,0,0,0,2,0,0,0,3,0,0,0,59,0,
|
||||
4,0,5,0,0,0,6,0,0,0,2,0,0,0,59,0,4,0,9,0,0,0,10,0,0,0,9,0,0,0,
|
||||
59,0,4,0,13,0,0,0,14,0,0,0,1,0,0,0,59,0,4,0,18,0,0,0,19,0,0,0,1,0,
|
||||
0,0,59,0,4,0,24,0,0,0,25,0,0,0,3,0,0,0,59,0,4,0,26,0,0,0,27,0,0,0,
|
||||
3,0,0,0,59,0,4,0,24,0,0,0,28,0,0,0,3,0,0,0,54,0,5,0,11,0,0,0,34,0,
|
||||
0,0,0,0,0,0,12,0,0,0,248,0,2,0,35,0,0,0,59,0,4,0,17,0,0,0,36,0,0,0,
|
||||
7,0,0,0,59,0,4,0,32,0,0,0,37,0,0,0,7,0,0,0,59,0,4,0,23,0,0,0,38,0,
|
||||
0,0,7,0,0,0,65,0,5,0,17,0,0,0,39,0,0,0,38,0,0,0,16,0,0,0,63,0,3,0,
|
||||
39,0,0,0,14,0,0,0,65,0,5,0,21,0,0,0,40,0,0,0,38,0,0,0,20,0,0,0,63,0,
|
||||
3,0,40,0,0,0,19,0,0,0,65,0,5,0,17,0,0,0,41,0,0,0,38,0,0,0,16,0,0,0,
|
||||
61,0,4,0,2,0,0,0,42,0,0,0,41,0,0,0,79,0,7,0,7,0,0,0,43,0,0,0,42,0,
|
||||
0,0,42,0,0,0,0,0,0,0,1,0,0,0,65,0,5,0,44,0,0,0,45,0,0,0,10,0,0,0,
|
||||
20,0,0,0,61,0,4,0,7,0,0,0,46,0,0,0,45,0,0,0,129,0,5,0,7,0,0,0,47,0,
|
||||
0,0,43,0,0,0,46,0,0,0,80,0,6,0,2,0,0,0,48,0,0,0,47,0,0,0,30,0,0,0,
|
||||
30,0,0,0,62,0,3,0,36,0,0,0,48,0,0,0,65,0,5,0,21,0,0,0,49,0,0,0,38,0,
|
||||
0,0,20,0,0,0,61,0,4,0,7,0,0,0,50,0,0,0,49,0,0,0,142,0,5,0,7,0,0,0,
|
||||
51,0,0,0,50,0,0,0,31,0,0,0,65,0,5,0,21,0,0,0,52,0,0,0,38,0,0,0,20,0,
|
||||
0,0,62,0,3,0,52,0,0,0,51,0,0,0,65,0,5,0,21,0,0,0,53,0,0,0,38,0,0,0,
|
||||
20,0,0,0,61,0,4,0,7,0,0,0,54,0,0,0,53,0,0,0,65,0,5,0,21,0,0,0,55,0,
|
||||
0,0,37,0,0,0,20,0,0,0,62,0,3,0,55,0,0,0,54,0,0,0,65,0,5,0,56,0,0,0,
|
||||
57,0,0,0,10,0,0,0,16,0,0,0,61,0,4,0,2,0,0,0,58,0,0,0,57,0,0,0,65,0,
|
||||
5,0,17,0,0,0,59,0,0,0,37,0,0,0,16,0,0,0,62,0,3,0,59,0,0,0,58,0,0,0,
|
||||
65,0,5,0,60,0,0,0,61,0,0,0,6,0,0,0,16,0,0,0,61,0,4,0,3,0,0,0,62,0,
|
||||
0,0,61,0,0,0,61,0,4,0,2,0,0,0,63,0,0,0,36,0,0,0,145,0,5,0,2,0,0,0,
|
||||
64,0,0,0,62,0,0,0,63,0,0,0,65,0,5,0,17,0,0,0,65,0,0,0,37,0,0,0,33,0,
|
||||
0,0,62,0,3,0,65,0,0,0,64,0,0,0,61,0,4,0,29,0,0,0,66,0,0,0,37,0,0,0,
|
||||
81,0,5,0,2,0,0,0,67,0,0,0,66,0,0,0,0,0,0,0,62,0,3,0,25,0,0,0,67,0,
|
||||
0,0,81,0,5,0,7,0,0,0,68,0,0,0,66,0,0,0,1,0,0,0,62,0,3,0,27,0,0,0,
|
||||
68,0,0,0,81,0,5,0,2,0,0,0,69,0,0,0,66,0,0,0,2,0,0,0,62,0,3,0,28,0,
|
||||
0,0,69,0,0,0,253,0,1,0,56,0,1,0
|
||||
0,0,0,0,112,114,111,106,101,99,116,105,111,110,95,109,97,116,114,105,120,0,0,0,5,0,5,0,7,0,
|
||||
0,0,83,112,114,105,116,101,68,97,116,97,0,0,6,0,7,0,7,0,0,0,0,0,0,0,109,111,100,101,
|
||||
108,95,109,97,116,114,105,120,0,0,0,0,6,0,5,0,7,0,0,0,1,0,0,0,99,111,108,111,114,0,
|
||||
0,0,5,0,4,0,22,0,0,0,86,101,114,116,73,110,0,0,6,0,4,0,22,0,0,0,0,0,0,0,
|
||||
112,111,115,0,6,0,4,0,22,0,0,0,1,0,0,0,117,118,0,0,5,0,4,0,29,0,0,0,86,101,
|
||||
114,116,79,117,116,0,6,0,5,0,29,0,0,0,0,0,0,0,99,111,108,111,114,0,0,0,6,0,4,0,
|
||||
29,0,0,0,1,0,0,0,117,118,0,0,6,0,4,0,29,0,0,0,2,0,0,0,112,111,115,0,5,0,
|
||||
5,0,6,0,0,0,118,105,101,119,101,114,95,100,97,116,97,0,5,0,4,0,9,0,0,0,109,111,100,101,
|
||||
108,0,0,0,5,0,3,0,13,0,0,0,112,111,115,0,5,0,3,0,19,0,0,0,117,118,0,0,5,0,
|
||||
4,0,25,0,0,0,99,111,108,111,114,0,0,0,5,0,3,0,27,0,0,0,117,118,0,0,5,0,5,0,
|
||||
28,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,34,0,0,0,109,97,105,110,0,0,
|
||||
0,0,71,0,4,0,6,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,6,0,0,0,34,0,0,0,
|
||||
0,0,0,0,71,0,4,0,28,0,0,0,11,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,30,0,
|
||||
0,0,0,0,0,0,71,0,4,0,19,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,25,0,0,0,
|
||||
30,0,0,0,0,0,0,0,71,0,4,0,27,0,0,0,30,0,0,0,1,0,0,0,71,0,3,0,4,0,
|
||||
0,0,2,0,0,0,72,0,4,0,4,0,0,0,0,0,0,0,5,0,0,0,72,0,5,0,4,0,0,0,
|
||||
0,0,0,0,7,0,0,0,16,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0,35,0,0,0,0,0,
|
||||
0,0,71,0,3,0,7,0,0,0,2,0,0,0,72,0,4,0,7,0,0,0,0,0,0,0,5,0,0,0,
|
||||
72,0,5,0,7,0,0,0,0,0,0,0,7,0,0,0,16,0,0,0,72,0,5,0,7,0,0,0,0,0,
|
||||
0,0,35,0,0,0,0,0,0,0,72,0,5,0,7,0,0,0,1,0,0,0,35,0,0,0,64,0,0,0,
|
||||
72,0,5,0,22,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,22,0,0,0,1,0,
|
||||
0,0,35,0,0,0,16,0,0,0,72,0,5,0,29,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,
|
||||
72,0,5,0,29,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,29,0,0,0,2,0,
|
||||
0,0,35,0,0,0,32,0,0,0,22,0,3,0,1,0,0,0,32,0,0,0,23,0,4,0,2,0,0,0,
|
||||
1,0,0,0,4,0,0,0,24,0,4,0,3,0,0,0,2,0,0,0,4,0,0,0,30,0,3,0,4,0,
|
||||
0,0,3,0,0,0,32,0,4,0,5,0,0,0,2,0,0,0,4,0,0,0,30,0,4,0,7,0,0,0,
|
||||
3,0,0,0,2,0,0,0,32,0,4,0,8,0,0,0,9,0,0,0,7,0,0,0,19,0,2,0,10,0,
|
||||
0,0,33,0,3,0,11,0,0,0,10,0,0,0,32,0,4,0,12,0,0,0,1,0,0,0,2,0,0,0,
|
||||
21,0,4,0,14,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,14,0,0,0,15,0,0,0,0,0,
|
||||
0,0,32,0,4,0,16,0,0,0,7,0,0,0,2,0,0,0,23,0,4,0,17,0,0,0,1,0,0,0,
|
||||
2,0,0,0,32,0,4,0,18,0,0,0,1,0,0,0,17,0,0,0,43,0,4,0,14,0,0,0,20,0,
|
||||
0,0,1,0,0,0,32,0,4,0,21,0,0,0,7,0,0,0,17,0,0,0,30,0,4,0,22,0,0,0,
|
||||
2,0,0,0,17,0,0,0,32,0,4,0,23,0,0,0,7,0,0,0,22,0,0,0,32,0,4,0,24,0,
|
||||
0,0,3,0,0,0,2,0,0,0,32,0,4,0,26,0,0,0,3,0,0,0,17,0,0,0,30,0,5,0,
|
||||
29,0,0,0,2,0,0,0,17,0,0,0,2,0,0,0,43,0,4,0,1,0,0,0,30,0,0,0,0,0,
|
||||
128,63,43,0,4,0,1,0,0,0,31,0,0,0,0,0,128,191,32,0,4,0,32,0,0,0,7,0,0,0,
|
||||
29,0,0,0,43,0,4,0,14,0,0,0,33,0,0,0,2,0,0,0,32,0,4,0,52,0,0,0,9,0,
|
||||
0,0,2,0,0,0,32,0,4,0,56,0,0,0,2,0,0,0,3,0,0,0,32,0,4,0,59,0,0,0,
|
||||
9,0,0,0,3,0,0,0,59,0,4,0,5,0,0,0,6,0,0,0,2,0,0,0,59,0,4,0,8,0,
|
||||
0,0,9,0,0,0,9,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,1,0,0,0,59,0,4,0,
|
||||
18,0,0,0,19,0,0,0,1,0,0,0,59,0,4,0,24,0,0,0,25,0,0,0,3,0,0,0,59,0,
|
||||
4,0,26,0,0,0,27,0,0,0,3,0,0,0,59,0,4,0,24,0,0,0,28,0,0,0,3,0,0,0,
|
||||
54,0,5,0,10,0,0,0,34,0,0,0,0,0,0,0,11,0,0,0,248,0,2,0,35,0,0,0,59,0,
|
||||
4,0,16,0,0,0,36,0,0,0,7,0,0,0,59,0,4,0,32,0,0,0,37,0,0,0,7,0,0,0,
|
||||
59,0,4,0,23,0,0,0,38,0,0,0,7,0,0,0,65,0,5,0,16,0,0,0,39,0,0,0,38,0,
|
||||
0,0,15,0,0,0,63,0,3,0,39,0,0,0,13,0,0,0,65,0,5,0,21,0,0,0,40,0,0,0,
|
||||
38,0,0,0,20,0,0,0,63,0,3,0,40,0,0,0,19,0,0,0,65,0,5,0,16,0,0,0,41,0,
|
||||
0,0,38,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,42,0,0,0,41,0,0,0,79,0,7,0,
|
||||
17,0,0,0,43,0,0,0,42,0,0,0,42,0,0,0,0,0,0,0,1,0,0,0,80,0,6,0,2,0,
|
||||
0,0,44,0,0,0,43,0,0,0,30,0,0,0,30,0,0,0,62,0,3,0,36,0,0,0,44,0,0,0,
|
||||
65,0,5,0,21,0,0,0,45,0,0,0,38,0,0,0,20,0,0,0,61,0,4,0,17,0,0,0,46,0,
|
||||
0,0,45,0,0,0,142,0,5,0,17,0,0,0,47,0,0,0,46,0,0,0,31,0,0,0,65,0,5,0,
|
||||
21,0,0,0,48,0,0,0,38,0,0,0,20,0,0,0,62,0,3,0,48,0,0,0,47,0,0,0,65,0,
|
||||
5,0,21,0,0,0,49,0,0,0,38,0,0,0,20,0,0,0,61,0,4,0,17,0,0,0,50,0,0,0,
|
||||
49,0,0,0,65,0,5,0,21,0,0,0,51,0,0,0,37,0,0,0,20,0,0,0,62,0,3,0,51,0,
|
||||
0,0,50,0,0,0,65,0,5,0,52,0,0,0,53,0,0,0,9,0,0,0,20,0,0,0,61,0,4,0,
|
||||
2,0,0,0,54,0,0,0,53,0,0,0,65,0,5,0,16,0,0,0,55,0,0,0,37,0,0,0,15,0,
|
||||
0,0,62,0,3,0,55,0,0,0,54,0,0,0,65,0,5,0,56,0,0,0,57,0,0,0,6,0,0,0,
|
||||
15,0,0,0,61,0,4,0,3,0,0,0,58,0,0,0,57,0,0,0,65,0,5,0,59,0,0,0,60,0,
|
||||
0,0,9,0,0,0,15,0,0,0,61,0,4,0,3,0,0,0,61,0,0,0,60,0,0,0,146,0,5,0,
|
||||
3,0,0,0,62,0,0,0,58,0,0,0,61,0,0,0,61,0,4,0,2,0,0,0,63,0,0,0,36,0,
|
||||
0,0,145,0,5,0,2,0,0,0,64,0,0,0,62,0,0,0,63,0,0,0,65,0,5,0,16,0,0,0,
|
||||
65,0,0,0,37,0,0,0,33,0,0,0,62,0,3,0,65,0,0,0,64,0,0,0,61,0,4,0,29,0,
|
||||
0,0,66,0,0,0,37,0,0,0,81,0,5,0,2,0,0,0,67,0,0,0,66,0,0,0,0,0,0,0,
|
||||
62,0,3,0,25,0,0,0,67,0,0,0,81,0,5,0,17,0,0,0,68,0,0,0,66,0,0,0,1,0,
|
||||
0,0,62,0,3,0,27,0,0,0,68,0,0,0,81,0,5,0,2,0,0,0,69,0,0,0,66,0,0,0,
|
||||
2,0,0,0,62,0,3,0,28,0,0,0,69,0,0,0,253,0,1,0,56,0,1,0
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define __MLX_DRAWABLE__
|
||||
|
||||
#include <Graphics/Enums.h>
|
||||
#include <Maths/Quaternions.h>
|
||||
#include <Maths/EulerAngles.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -12,13 +14,19 @@ namespace mlx
|
||||
public:
|
||||
inline Drawable(DrawableType type) : m_type(type) {}
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec2f position) noexcept { m_position = position; }
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = std::move(color); }
|
||||
inline void SetPosition(Vec2f position) noexcept { m_position = std::move(position); }
|
||||
inline void SetScale(Vec2f scale) noexcept { m_scale = std::move(scale); }
|
||||
inline void SetRotation(float rotation) noexcept { m_rotation = EulerAnglesf{ 0.0f, 0.0f, rotation }; }
|
||||
inline void SetCenter(Vec2f center) noexcept { m_center = std::move(center); }
|
||||
|
||||
inline virtual void Update([[maybe_unused]] VkCommandBuffer cmd) {}
|
||||
|
||||
[[nodiscard]] MLX_FORCEINLINE const Vec4f& GetColor() const noexcept { return m_color; }
|
||||
[[nodiscard]] MLX_FORCEINLINE const Vec2f& GetPosition() const noexcept { return m_position; }
|
||||
[[nodiscard]] MLX_FORCEINLINE const Vec2f& GetScale() const noexcept { return m_scale; }
|
||||
[[nodiscard]] MLX_FORCEINLINE const Quatf& GetRotation() const noexcept { return m_rotation; }
|
||||
[[nodiscard]] MLX_FORCEINLINE const Vec2f& GetCenter() const noexcept { return m_center; }
|
||||
[[nodiscard]] MLX_FORCEINLINE std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
[[nodiscard]] MLX_FORCEINLINE DrawableType GetType() const noexcept { return m_type; }
|
||||
|
||||
@@ -38,8 +46,11 @@ namespace mlx
|
||||
protected:
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
Quatf m_rotation = Quatf::Identity();
|
||||
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
Vec2f m_position = Vec2f{ 0.0f, 0.0f };
|
||||
Vec2f m_scale = Vec2f{ 1.0f, 1.0f };
|
||||
Vec2f m_center;
|
||||
DrawableType m_type;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace mlx
|
||||
Scene() = default;
|
||||
|
||||
Sprite& CreateSprite(NonOwningPtr<class Texture> texture) noexcept;
|
||||
NonOwningPtr<Sprite> GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const;
|
||||
NonOwningPtr<Sprite> GetSpriteFromTexturePositionScaleRotation(NonOwningPtr<Texture> texture, const Vec2f& position, float scale, float rotation) const;
|
||||
void TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture);
|
||||
bool IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <cstdarg>
|
||||
#include <iostream>
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
@@ -61,7 +61,7 @@
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_VULKAN_VERSION 1000000
|
||||
#define VMA_ASSERT(expr) ((void)0)
|
||||
#define VMA_ASSERT(expr) ((void)0) // Because why not
|
||||
|
||||
#ifdef MLX_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
|
||||
@@ -145,7 +145,13 @@ extern "C"
|
||||
void mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void mlx_transform_put_image_to_window(void* mlx, void* win, void* img, int x, int y, float scale, float angle)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y, scale, angle);
|
||||
}
|
||||
|
||||
void mlx_destroy_image(void* mlx, void* img)
|
||||
|
||||
@@ -12,10 +12,6 @@ namespace mlx
|
||||
};
|
||||
}
|
||||
|
||||
std::uint32_t Logs::s_nesting = 0;
|
||||
|
||||
constexpr int LOGS_TABS_WIDTH = 4;
|
||||
|
||||
void Logs::Report(LogType type, std::string message)
|
||||
{
|
||||
Report(type, 0, {}, {}, std::move(message));
|
||||
@@ -42,14 +38,7 @@ namespace mlx
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LogType::Debug:
|
||||
{
|
||||
std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << std::flush;
|
||||
std::printf("%*s", s_nesting * LOGS_TABS_WIDTH, "");
|
||||
std::fflush(stdout);
|
||||
std::cout << code_infos << message << std::endl;
|
||||
break;
|
||||
}
|
||||
case LogType::Debug: std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << code_infos << message << std::endl; break;
|
||||
case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
@@ -63,15 +52,4 @@ namespace mlx
|
||||
EventBus::Send("__MlxApplication", Internal::FatalErrorEvent{});
|
||||
}
|
||||
}
|
||||
|
||||
void Logs::BeginSection()
|
||||
{
|
||||
s_nesting++;
|
||||
}
|
||||
|
||||
void Logs::EndSection()
|
||||
{
|
||||
if(s_nesting > 0)
|
||||
s_nesting--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,17 @@ namespace mlx
|
||||
return *sprite;
|
||||
}
|
||||
|
||||
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
|
||||
NonOwningPtr<Sprite> Scene::GetSpriteFromTexturePositionScaleRotation(NonOwningPtr<Texture> texture, const Vec2f& position, float scale, float rotation) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position](std::shared_ptr<Drawable> drawable)
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position, scale, rotation](std::shared_ptr<Drawable> drawable)
|
||||
{
|
||||
if(!drawable || drawable->GetType() != DrawableType::Sprite)
|
||||
return false;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture && drawable->GetPosition() == position;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture &&
|
||||
drawable->GetPosition() == position &&
|
||||
drawable->GetScale() == Vec2f{ scale, scale } &&
|
||||
drawable->GetRotation() == EulerAnglesf{ 0.0f, 0.0f, rotation };
|
||||
});
|
||||
return static_cast<Sprite*>(it != m_drawables.end() ? it->get() : nullptr);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <mlx_profile.h>
|
||||
#include <PreCompiled.h>
|
||||
|
||||
#define VMA_IMPLEMENTATION
|
||||
|
||||
@@ -56,7 +56,6 @@ namespace mlx
|
||||
return;
|
||||
s_instance = this;
|
||||
|
||||
Logs::BeginSection();
|
||||
loader = std::make_unique<VulkanLoader>();
|
||||
|
||||
LoadKVFGlobalVulkanFunctionPointers();
|
||||
@@ -80,7 +79,6 @@ namespace mlx
|
||||
|
||||
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
|
||||
|
||||
Logs::BeginSection();
|
||||
m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface);
|
||||
|
||||
// just for style
|
||||
@@ -96,12 +94,10 @@ namespace mlx
|
||||
|
||||
loader->LoadDevice(m_device);
|
||||
LoadKVFDeviceVulkanFunctionPointers();
|
||||
Logs::EndSection();
|
||||
|
||||
vkDestroySurfaceKHR(m_instance, surface, nullptr);
|
||||
|
||||
m_allocator.Init();
|
||||
Logs::EndSection();
|
||||
}
|
||||
|
||||
#undef MLX_LOAD_FUNCTION
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
struct SpriteData
|
||||
struct DrawableData
|
||||
{
|
||||
Mat4f model_matrix;
|
||||
Vec4f color;
|
||||
Vec2f position;
|
||||
};
|
||||
|
||||
void Render2DPass::Init()
|
||||
@@ -25,7 +25,7 @@ namespace mlx
|
||||
{ 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }
|
||||
})
|
||||
}
|
||||
}, { ShaderPushConstantLayout({ 0, sizeof(SpriteData) }) }
|
||||
}, { ShaderPushConstantLayout({ 0, sizeof(DrawableData) }) }
|
||||
);
|
||||
std::vector<std::uint8_t> vertex_shader_code = {
|
||||
#include <Embedded/Shader2DVertex.spv.h>
|
||||
@@ -105,15 +105,19 @@ namespace mlx
|
||||
m_pipeline.BindPipeline(cmd, 0, {});
|
||||
for(auto& drawable : drawables)
|
||||
{
|
||||
SpriteData drawable_data;
|
||||
drawable_data.position = drawable->GetPosition();
|
||||
DrawableData drawable_data;
|
||||
drawable_data.color = drawable->GetColor();
|
||||
drawable_data.model_matrix = Mat4f::Identity();
|
||||
drawable_data.model_matrix.SetTranslation(Vec3f{ drawable->GetPosition(), 0.0f });
|
||||
drawable_data.model_matrix.SetScale(Vec3f{ drawable->GetScale(), 1.0f });
|
||||
drawable_data.model_matrix.SetRotation(drawable->GetRotation());
|
||||
//drawable_data.model_matrix = Mat4f::Translate(-Vec3f{ drawable->GetCenter(), 0.0f }) * Mat4f::Rotate(drawable->GetRotation()) * drawable_data.model_matrix;
|
||||
|
||||
drawable->Bind(frame_index, cmd);
|
||||
|
||||
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), drawable->GetSet(frame_index) };
|
||||
|
||||
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &drawable_data);
|
||||
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(DrawableData), &drawable_data);
|
||||
RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
|
||||
drawable->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef());
|
||||
|
||||
Reference in New Issue
Block a user