mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
fixing projection issue
This commit is contained in:
@@ -6,13 +6,14 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/03/25 18:10:41 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/10/03 06:39:01 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../includes/mlx.h"
|
||||
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
void* mlx;
|
||||
@@ -32,13 +33,13 @@ int update(void* param)
|
||||
|
||||
if(i == 200)
|
||||
mlx_clear_window(mlx->mlx, mlx->win);
|
||||
/*
|
||||
if(img)
|
||||
mlx_destroy_image(mlx->mlx,img);
|
||||
img = mlx_new_image(mlx->mlx, 800, 800);
|
||||
mlx_set_image_pixel(mlx->mlx, img, 4, 4, 0xFF00FF00);
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, img, 0, 0);
|
||||
*/
|
||||
|
||||
// if(img)
|
||||
// mlx_destroy_image(mlx->mlx,img);
|
||||
// img = mlx_new_image(mlx->mlx, 800, 800);
|
||||
// mlx_set_image_pixel(mlx->mlx, img, 4, 4, 0xFF00FF00);
|
||||
// mlx_put_image_to_window(mlx->mlx, mlx->win, img, 0, 0);
|
||||
|
||||
if(i >= 250)
|
||||
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
|
||||
else
|
||||
@@ -176,3 +177,41 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int window_hook(int event, void* param)
|
||||
{
|
||||
if(event == 0)
|
||||
mlx_loop_end(param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void* mlx;
|
||||
void* win;
|
||||
|
||||
mlx = mlx_init();
|
||||
win = mlx_new_window(mlx, 400, 400, "My window");
|
||||
|
||||
mlx_set_fps_goal(mlx, 60);
|
||||
|
||||
mlx_on_event(mlx, win, MLX_WINDOW_EVENT, window_hook, mlx);
|
||||
|
||||
int dummy;
|
||||
void* logo_png = mlx_png_file_to_image(mlx, "42_logo.png", &dummy, &dummy);
|
||||
|
||||
mlx_put_image_to_window(mlx, win, logo_png, 10, 190);
|
||||
mlx_put_image_to_window(mlx, win, logo_png, 11, 190);
|
||||
mlx_put_image_to_window(mlx, win, logo_png, 10, 190);
|
||||
mlx_put_image_to_window(mlx, win, logo_png, 100, 190);
|
||||
mlx_put_image_to_window(mlx, win, logo_png, 10, 190);
|
||||
|
||||
mlx_loop(mlx);
|
||||
|
||||
mlx_destroy_image(mlx, logo_png);
|
||||
mlx_destroy_window(mlx, win);
|
||||
mlx_destroy_display(mlx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <Core/Graphics.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
||||
@@ -34,10 +34,11 @@ external
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
input.uv.x *= -1.0;
|
||||
let position: vec2[f32] = input.pos.xy + model.position.xy;
|
||||
input.uv *= -1.0;
|
||||
let output: VertOut;
|
||||
output.uv = input.uv;
|
||||
output.color = model.color;
|
||||
output.pos = viewer_data.projection_matrix * (input.pos + model.position);
|
||||
output.pos = viewer_data.projection_matrix * vec4[f32](position, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
3,2,35,7,0,0,1,0,39,0,0,0,67,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,33,0,0,0,109,97,105,110,0,0,0,0,
|
||||
3,2,35,7,0,0,1,0,39,0,0,0,71,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,35,0,0,0,109,97,105,110,0,0,0,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,7,0,
|
||||
@@ -12,7 +12,7 @@
|
||||
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,33,0,0,0,109,97,105,110,0,0,0,0,71,0,
|
||||
112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,35,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,
|
||||
@@ -36,33 +36,36 @@
|
||||
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,191,32,0,4,0,31,0,0,0,
|
||||
7,0,0,0,29,0,0,0,43,0,4,0,14,0,0,0,32,0,0,0,2,0,0,0,32,0,4,0,44,0,
|
||||
0,0,7,0,0,0,1,0,0,0,32,0,4,0,49,0,0,0,9,0,0,0,2,0,0,0,32,0,4,0,
|
||||
53,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,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,33,0,0,0,0,0,0,0,11,0,0,0,248,0,2,0,34,0,
|
||||
0,0,59,0,4,0,31,0,0,0,35,0,0,0,7,0,0,0,59,0,4,0,23,0,0,0,36,0,0,0,
|
||||
7,0,0,0,65,0,5,0,16,0,0,0,37,0,0,0,36,0,0,0,15,0,0,0,63,0,3,0,37,0,
|
||||
0,0,13,0,0,0,65,0,5,0,21,0,0,0,38,0,0,0,36,0,0,0,20,0,0,0,63,0,3,0,
|
||||
38,0,0,0,19,0,0,0,65,0,5,0,21,0,0,0,39,0,0,0,36,0,0,0,20,0,0,0,61,0,
|
||||
4,0,17,0,0,0,40,0,0,0,39,0,0,0,81,0,5,0,1,0,0,0,41,0,0,0,40,0,0,0,
|
||||
0,0,0,0,133,0,5,0,1,0,0,0,42,0,0,0,41,0,0,0,30,0,0,0,65,0,5,0,21,0,
|
||||
0,0,43,0,0,0,36,0,0,0,20,0,0,0,65,0,5,0,44,0,0,0,45,0,0,0,43,0,0,0,
|
||||
15,0,0,0,62,0,3,0,45,0,0,0,42,0,0,0,65,0,5,0,21,0,0,0,46,0,0,0,36,0,
|
||||
0,0,20,0,0,0,61,0,4,0,17,0,0,0,47,0,0,0,46,0,0,0,65,0,5,0,21,0,0,0,
|
||||
48,0,0,0,35,0,0,0,20,0,0,0,62,0,3,0,48,0,0,0,47,0,0,0,65,0,5,0,49,0,
|
||||
0,0,50,0,0,0,9,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,51,0,0,0,50,0,0,0,
|
||||
65,0,5,0,16,0,0,0,52,0,0,0,35,0,0,0,15,0,0,0,62,0,3,0,52,0,0,0,51,0,
|
||||
0,0,65,0,5,0,53,0,0,0,54,0,0,0,6,0,0,0,15,0,0,0,61,0,4,0,3,0,0,0,
|
||||
55,0,0,0,54,0,0,0,65,0,5,0,16,0,0,0,56,0,0,0,36,0,0,0,15,0,0,0,61,0,
|
||||
4,0,2,0,0,0,57,0,0,0,56,0,0,0,65,0,5,0,49,0,0,0,58,0,0,0,9,0,0,0,
|
||||
20,0,0,0,61,0,4,0,2,0,0,0,59,0,0,0,58,0,0,0,129,0,5,0,2,0,0,0,60,0,
|
||||
0,0,57,0,0,0,59,0,0,0,145,0,5,0,2,0,0,0,61,0,0,0,55,0,0,0,60,0,0,0,
|
||||
65,0,5,0,16,0,0,0,62,0,0,0,35,0,0,0,32,0,0,0,62,0,3,0,62,0,0,0,61,0,
|
||||
0,0,61,0,4,0,29,0,0,0,63,0,0,0,35,0,0,0,81,0,5,0,2,0,0,0,64,0,0,0,
|
||||
63,0,0,0,0,0,0,0,62,0,3,0,25,0,0,0,64,0,0,0,81,0,5,0,17,0,0,0,65,0,
|
||||
0,0,63,0,0,0,1,0,0,0,62,0,3,0,27,0,0,0,65,0,0,0,81,0,5,0,2,0,0,0,
|
||||
66,0,0,0,63,0,0,0,2,0,0,0,62,0,3,0,28,0,0,0,66,0,0,0,253,0,1,0,56,0,
|
||||
1,0
|
||||
7,0,0,0,29,0,0,0,43,0,4,0,14,0,0,0,32,0,0,0,2,0,0,0,43,0,4,0,1,0,
|
||||
0,0,33,0,0,0,0,0,0,0,43,0,4,0,1,0,0,0,34,0,0,0,0,0,128,63,32,0,4,0,
|
||||
45,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,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,35,0,
|
||||
0,0,0,0,0,0,11,0,0,0,248,0,2,0,36,0,0,0,59,0,4,0,21,0,0,0,37,0,0,0,
|
||||
7,0,0,0,59,0,4,0,31,0,0,0,38,0,0,0,7,0,0,0,59,0,4,0,23,0,0,0,39,0,
|
||||
0,0,7,0,0,0,65,0,5,0,16,0,0,0,40,0,0,0,39,0,0,0,15,0,0,0,63,0,3,0,
|
||||
40,0,0,0,13,0,0,0,65,0,5,0,21,0,0,0,41,0,0,0,39,0,0,0,20,0,0,0,63,0,
|
||||
3,0,41,0,0,0,19,0,0,0,65,0,5,0,16,0,0,0,42,0,0,0,39,0,0,0,15,0,0,0,
|
||||
61,0,4,0,2,0,0,0,43,0,0,0,42,0,0,0,79,0,7,0,17,0,0,0,44,0,0,0,43,0,
|
||||
0,0,43,0,0,0,0,0,0,0,1,0,0,0,65,0,5,0,45,0,0,0,46,0,0,0,9,0,0,0,
|
||||
20,0,0,0,61,0,4,0,2,0,0,0,47,0,0,0,46,0,0,0,79,0,7,0,17,0,0,0,48,0,
|
||||
0,0,47,0,0,0,47,0,0,0,0,0,0,0,1,0,0,0,129,0,5,0,17,0,0,0,49,0,0,0,
|
||||
44,0,0,0,48,0,0,0,62,0,3,0,37,0,0,0,49,0,0,0,65,0,5,0,21,0,0,0,50,0,
|
||||
0,0,39,0,0,0,20,0,0,0,61,0,4,0,17,0,0,0,51,0,0,0,50,0,0,0,142,0,5,0,
|
||||
17,0,0,0,52,0,0,0,51,0,0,0,30,0,0,0,65,0,5,0,21,0,0,0,53,0,0,0,39,0,
|
||||
0,0,20,0,0,0,62,0,3,0,53,0,0,0,52,0,0,0,65,0,5,0,21,0,0,0,54,0,0,0,
|
||||
39,0,0,0,20,0,0,0,61,0,4,0,17,0,0,0,55,0,0,0,54,0,0,0,65,0,5,0,21,0,
|
||||
0,0,56,0,0,0,38,0,0,0,20,0,0,0,62,0,3,0,56,0,0,0,55,0,0,0,65,0,5,0,
|
||||
45,0,0,0,57,0,0,0,9,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,58,0,0,0,57,0,
|
||||
0,0,65,0,5,0,16,0,0,0,59,0,0,0,38,0,0,0,15,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,15,0,0,0,61,0,4,0,3,0,
|
||||
0,0,62,0,0,0,61,0,0,0,61,0,4,0,17,0,0,0,63,0,0,0,37,0,0,0,80,0,6,0,
|
||||
2,0,0,0,64,0,0,0,63,0,0,0,33,0,0,0,34,0,0,0,145,0,5,0,2,0,0,0,65,0,
|
||||
0,0,62,0,0,0,64,0,0,0,65,0,5,0,16,0,0,0,66,0,0,0,38,0,0,0,32,0,0,0,
|
||||
62,0,3,0,66,0,0,0,65,0,0,0,61,0,4,0,29,0,0,0,67,0,0,0,38,0,0,0,81,0,
|
||||
5,0,2,0,0,0,68,0,0,0,67,0,0,0,0,0,0,0,62,0,3,0,25,0,0,0,68,0,0,0,
|
||||
81,0,5,0,17,0,0,0,69,0,0,0,67,0,0,0,1,0,0,0,62,0,3,0,27,0,0,0,69,0,
|
||||
0,0,81,0,5,0,2,0,0,0,70,0,0,0,67,0,0,0,2,0,0,0,62,0,3,0,28,0,0,0,
|
||||
70,0,0,0,253,0,1,0,56,0,1,0
|
||||
|
||||
1
runtime/Includes/Maths/Readme.md
git.filemode.normal_file
1
runtime/Includes/Maths/Readme.md
git.filemode.normal_file
@@ -0,0 +1 @@
|
||||
Highly inspired by [Nazara Maths library](https://github.com/NazaraEngine/NazaraEngine/tree/main/include/Nazara/Math)
|
||||
@@ -36,6 +36,7 @@ namespace mlx
|
||||
if(f_loop_hook)
|
||||
f_loop_hook(p_param);
|
||||
|
||||
#pragma omp parallel for
|
||||
for(auto& gs : m_graphics)
|
||||
{
|
||||
if(gs)
|
||||
@@ -80,6 +81,7 @@ namespace mlx
|
||||
Error("trying to destroy a texture that has already been destroyed");
|
||||
else
|
||||
texture->Destroy();
|
||||
#pragma omp parallel for
|
||||
for(auto& gs : m_graphics)
|
||||
{
|
||||
if(gs)
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace mlx
|
||||
{
|
||||
void EventBus::Send(const std::string& listener_name, const EventBase& event)
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for(const EventListener& listener : s_listeners)
|
||||
{
|
||||
if(listener.GetName() == listener_name)
|
||||
@@ -19,6 +20,7 @@ namespace mlx
|
||||
|
||||
void EventBus::SendBroadcast(const EventBase& event)
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for(const EventListener& listener : s_listeners)
|
||||
listener.Call(event);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace mlx
|
||||
void Mesh::Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn) const noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
#pragma omp parallel for
|
||||
for(std::size_t i = 0; i < m_sub_meshes.size(); i++)
|
||||
Draw(cmd, drawcalls, polygondrawn, i);
|
||||
}
|
||||
@@ -25,6 +26,7 @@ namespace mlx
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
#pragma omp parallel for
|
||||
for(auto& mesh : m_sub_meshes)
|
||||
{
|
||||
mesh.vbo.Destroy();
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace mlx
|
||||
data[3].position = Vec4f(x, y + height, 0.0f, 1.0f);
|
||||
data[3].uv = Vec2f(1.0f, 0.0f);
|
||||
|
||||
std::vector<std::uint32_t> indices = {
|
||||
std::vector<std::uint32_t> indices{
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
@@ -40,7 +40,7 @@ namespace mlx
|
||||
Sprite::Sprite(Renderer& renderer, NonOwningPtr<Texture> texture)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify((bool)texture, "Sprite: invalid texture");
|
||||
Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)");
|
||||
p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight());
|
||||
p_texture = texture;
|
||||
|
||||
@@ -49,6 +49,6 @@ namespace mlx
|
||||
if(event.What() == Event::DescriptorPoolResetEventCode)
|
||||
m_set.Reallocate(renderer.GetCurrentFrameIndex());
|
||||
};
|
||||
EventBus::RegisterListener({ functor, "__Sprite" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
|
||||
EventBus::RegisterListener({ functor, "__MlxSprite" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ namespace mlx
|
||||
|
||||
void DescriptorPoolManager::Destroy()
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for(auto& pool : m_pools)
|
||||
pool.Destroy();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#include <PreCompiled.h>
|
||||
#include <Renderer/Pipelines/Graphics.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Renderer/Renderer.h>
|
||||
#include <Renderer/Vertex.h>
|
||||
#include <Core/EventBus.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -114,6 +114,7 @@ namespace mlx
|
||||
scissor.extent = fb_extent;
|
||||
RenderCore::Get().vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
||||
|
||||
#pragma omp parallel for
|
||||
for(std::size_t i = 0; i < m_clears.size(); i++)
|
||||
{
|
||||
m_clears[i].color.float32[0] = clear[0];
|
||||
@@ -141,6 +142,7 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
p_vertex_shader.reset();
|
||||
p_fragment_shader.reset();
|
||||
#pragma omp parallel for
|
||||
for(auto& fb : m_framebuffers)
|
||||
{
|
||||
kvfDestroyFramebuffer(RenderCore::Get().GetDevice(), fb);
|
||||
@@ -169,6 +171,7 @@ namespace mlx
|
||||
attachment_views.push_back(p_renderer->GetSwapchainImages()[0].GetImageView());
|
||||
}
|
||||
|
||||
#pragma omp parallel for
|
||||
for(NonOwningPtr<Texture> image : render_targets)
|
||||
{
|
||||
attachments.push_back(kvfBuildAttachmentDescription((kvfIsDepthFormat(image->GetFormat()) ? KVF_IMAGE_DEPTH : KVF_IMAGE_COLOR), image->GetFormat(), image->GetLayout(), image->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT));
|
||||
@@ -195,6 +198,7 @@ namespace mlx
|
||||
DebugLog("Vulkan : framebuffer created");
|
||||
}
|
||||
}
|
||||
#pragma omp parallel for
|
||||
for(NonOwningPtr<Texture> image : render_targets)
|
||||
{
|
||||
m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image->GetWidth(), .height = image->GetHeight() }));
|
||||
@@ -208,6 +212,7 @@ namespace mlx
|
||||
if(p_depth)
|
||||
p_depth->TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, cmd);
|
||||
|
||||
#pragma omp parallel for
|
||||
for(NonOwningPtr<Texture> image : m_attachments)
|
||||
{
|
||||
if(!image->IsInit())
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Renderer/Renderer.h>
|
||||
#include <Graphics/Scene.h>
|
||||
#include <Maths/Mat4.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -44,7 +45,6 @@ namespace mlx
|
||||
};
|
||||
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));
|
||||
|
||||
|
||||
func::function<void(const EventBase&)> functor = [this, &renderer](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::ResizeEventCode)
|
||||
@@ -65,6 +65,7 @@ namespace mlx
|
||||
|
||||
p_viewer_data_buffer = std::make_shared<UniformBuffer>();
|
||||
p_viewer_data_buffer->Init(sizeof(ViewerData), "mlx_2d_pass_viewer_data");
|
||||
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
p_viewer_data_set->SetUniformBuffer(i, 0, p_viewer_data_buffer->Get(i));
|
||||
@@ -93,13 +94,15 @@ namespace mlx
|
||||
std::uint32_t frame_index = renderer.GetCurrentFrameIndex();
|
||||
|
||||
ViewerData viewer_data;
|
||||
viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), 0.0f, render_target.GetHeight(), -1.0f, 100'000.0f);
|
||||
viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f, -1.0f, 100'000.0f);
|
||||
static CPUBuffer buffer(sizeof(ViewerData));
|
||||
std::memcpy(buffer.GetData(), &viewer_data, buffer.GetSize());
|
||||
p_viewer_data_buffer->SetData(buffer, frame_index);
|
||||
|
||||
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
|
||||
m_pipeline.BindPipeline(cmd, 0, {});
|
||||
|
||||
#pragma omp parallel for
|
||||
for(auto sprite : scene.GetSprites())
|
||||
{
|
||||
SpriteData sprite_data;
|
||||
@@ -107,7 +110,7 @@ namespace mlx
|
||||
sprite_data.color = sprite->GetColor();
|
||||
if(!sprite->IsSetInit())
|
||||
sprite->UpdateDescriptorSet(*p_texture_set);
|
||||
Verify((bool)sprite->GetTexture(), "a sprite has no texture attached");
|
||||
Verify((bool)sprite->GetTexture(), "a sprite has no texture attached (internal mlx issue, please report to the devs)");
|
||||
sprite->GetTexture()->Update(cmd);
|
||||
sprite->Bind(frame_index, cmd);
|
||||
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), sprite->GetSet(frame_index) };
|
||||
|
||||
@@ -69,10 +69,10 @@ namespace mlx
|
||||
VkResult result = RenderCore::Get().vkAcquireNextImageKHR(RenderCore::Get().GetDevice(), m_swapchain, UINT64_MAX, m_image_available_semaphores[m_current_frame_index], VK_NULL_HANDLE, &m_swapchain_image_index);
|
||||
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
{
|
||||
DestroySwapchain();
|
||||
CreateSwapchain();
|
||||
EventBus::SendBroadcast(Internal::ResizeEventBroadcast{});
|
||||
return false;
|
||||
//DestroySwapchain();
|
||||
//CreateSwapchain();
|
||||
//EventBus::SendBroadcast(Internal::ResizeEventBroadcast{});
|
||||
//return false;
|
||||
}
|
||||
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
||||
FatalError("Vulkan error : failed to acquire swapchain image, %", kvfVerbaliseVkResult(result));
|
||||
@@ -94,9 +94,9 @@ namespace mlx
|
||||
if(!kvfQueuePresentKHR(RenderCore::Get().GetDevice(), m_render_finished_semaphores[m_current_frame_index], m_swapchain, m_swapchain_image_index) || m_framebuffers_resize)
|
||||
{
|
||||
m_framebuffers_resize = false;
|
||||
DestroySwapchain();
|
||||
CreateSwapchain();
|
||||
EventBus::SendBroadcast(Internal::ResizeEventBroadcast{});
|
||||
//DestroySwapchain();
|
||||
//CreateSwapchain();
|
||||
//EventBus::SendBroadcast(Internal::ResizeEventBroadcast{});
|
||||
}
|
||||
m_current_frame_index = (m_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user