adding depth buffer, ci skip

This commit is contained in:
2024-09-02 13:02:32 +02:00
parent f65ac577bc
commit a455d7704d
26 changed files with 217 additions and 192 deletions

View File

@@ -7,7 +7,7 @@
Error("invalid window ptr (NULL)"); \
return; \
} \
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(_graphics.size()))\
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(m_graphics.size()))\
{ \
Error("invalid window ptr"); \
return; \
@@ -33,7 +33,7 @@ namespace mlx
*y = p_in->GetY();
}
void Application::MouseMove(void* win, int x, int y) noexcept
void Application::MouseMove(Handle win, int x, int y) noexcept
{
CHECK_WINDOW_PTR(win);
if(!m_graphics[*static_cast<int*>(win)]->HasWindow())
@@ -43,7 +43,7 @@ namespace mlx
}
}
void Application::OnEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
void Application::OnEvent(Handle win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
{
CHECK_WINDOW_PTR(win);
if(!m_graphics[*static_cast<int*>(win)]->HasWindow())
@@ -54,7 +54,7 @@ namespace mlx
m_in.OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
}
void Application::GetScreenSize(void* win, int* w, int* h) noexcept
void Application::GetScreenSize(Handle win, int* w, int* h) noexcept
{
CHECK_WINDOW_PTR(win);
*w = 0;
@@ -88,28 +88,28 @@ namespace mlx
return static_cast<void*>(&m_graphics.back()->GetID());
}
void Application::ClearGraphicsSupport(void* win)
void Application::ClearGraphicsSupport(Handle win)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->ClearRenderData();
}
void Application::DestroyGraphicsSupport(void* win)
void Application::DestroyGraphicsSupport(Handle win)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)].reset();
}
void Application::PixelPut(void* win, int x, int y, std::uint32_t color) const noexcept
void Application::PixelPut(Handle win, int x, int y, std::uint32_t color) const noexcept
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->PixelPut(x, y, color);
}
void Application::StringPut(void* win, int x, int y, std::uint32_t color, char* str)
void Application::StringPut(Handle win, int x, int y, std::uint32_t color, char* str)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
@@ -126,14 +126,14 @@ namespace mlx
m_graphics[*static_cast<int*>(win)]->StringPut(x, y, color, str);
}
void Application::LoadFont(void* win, const std::filesystem::path& filepath, float scale)
void Application::LoadFont(Handle win, const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->LoadFont(filepath, scale);
}
void Application::TexturePut(void* win, void* img, int x, int y)
void Application::TexturePut(Handle win, Handle img, int x, int y)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
@@ -145,7 +145,7 @@ namespace mlx
m_graphics[*static_cast<int*>(win)]->TexturePut(texture, x, y);
}
int Application::GetTexturePixel(void* img, int x, int y)
int Application::GetTexturePixel(Handle img, int x, int y)
{
MLX_PROFILE_FUNCTION();
CHECK_IMAGE_PTR(img, return 0);
@@ -158,7 +158,7 @@ namespace mlx
return texture->GetPixel(x, y);
}
void Application::setTexturePixel(void* img, int x, int y, std::uint32_t color)
void Application::SetTexturePixel(Handle img, int x, int y, std::uint32_t color)
{
MLX_PROFILE_FUNCTION();
CHECK_IMAGE_PTR(img, return);

View File

@@ -19,10 +19,10 @@ namespace mlx
enum class Event
{
DescriptorPoolResetEventCode = 55,
ResizeEventCode = 56,
FrameBeginEventCode = 57,
FatalErrorEventCode = 168,
QuitEventCode = 168,
EndEnum
};

View File

@@ -5,7 +5,7 @@ namespace mlx
{
struct EventBase
{
virtual std::uint32_t What() const = 0;
virtual Event What() const = 0;
};
}

View File

@@ -3,12 +3,10 @@
#include <Platform/Window.h>
#include <Renderer/Renderer.h>
#include <Renderer/PixelPut.h>
#include <Renderer/Core/DrawableResource.h>
#include <Renderer/Images/TextureRegistry.h>
#include <Renderer/Texts/TextManager.h>
#include <Utils/NonCopyable.h>
#include <Renderer/Images/Texture.h>
#include <Graphics/Scene.h>
#include <Graphics/Sprite.h>
#include <Renderer/ScenesRenderer.h>
#include <Maths/Mat4.h>
namespace mlx
{
@@ -18,36 +16,31 @@ namespace mlx
GraphicsSupport(std::size_t w, std::size_t h, NonOwningPtr<Texture> render_target, int id);
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
inline int& GetID() noexcept;
inline std::shared_ptr<Window> GetWindow();
[[nodiscard]] MLX_FORCEINLINE int& GetID() noexcept { return m_id; }
[[nodiscard]] inline std::shared_ptr<Window> GetWindow() { return p_window; }
void Render() noexcept;
inline void ClearRenderData() noexcept;
inline void ResetRenderData() noexcept;
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 LoadFont(const std::filesystem::path& filepath, float scale);
inline void TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept;
inline bool HasWindow() const noexcept { return m_has_window; }
inline void TryEraseTextureFromRegistry(NonOwningPtr<Texture> texture) noexcept;
inline Renderer& GetRenderer() { return m_renderer; }
[[nodiscard]] MLX_FORCEINLINE bool HasWindow() const noexcept { return m_has_window; }
[[nodiscard]] MLX_FORCEINLINE Renderer& GetRenderer() { return m_renderer; }
~GraphicsSupport();
private:
Renderer m_renderer;
PixelPutPipeline m_pixel_put_pipeline;
std::vector<NonOwningPtr<DrawableResource>> m_drawlist;
TextManager m_text_manager;
TextureRegistry m_texture_registry;
glm::mat4 m_proj = glm::mat4(1.0);
SceneRenderer m_scene_renderer;
std::shared_ptr<Window> p_window;
std::unique_ptr<Scene> p_scene;
std::size_t m_width = 0;
std::size_t m_height = 0;

View File

@@ -3,66 +3,35 @@
namespace mlx
{
int& GraphicsSupport::GetID() noexcept { return m_id; }
std::shared_ptr<Window> GraphicsSupport::GetWindow() { return p_window; }
void GraphicsSupport::ClearRenderData() noexcept
void GraphicsSupport::ResetRenderData() noexcept
{
MLX_PROFILE_FUNCTION();
m_drawlist.clear();
m_pixel_put_pipeline.Clear();
m_text_manager.Clear();
m_texture_registry.Clear();
p_scene->ResetSprites();
m_images_registry.Clear();
}
void GraphicsSupport::PixelPut(int x, int y, std::uint32_t color) noexcept
{
MLX_PROFILE_FUNCTION();
m_pixel_put_pipeline.SetPixel(x, y, color);
}
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
{
MLX_PROFILE_FUNCTION();
std::pair<NonOwningPtr<DrawableResource>, bool> res = m_text_manager.RegisterText(x, y, color, str);
if(!res.second) // if this is not a completly new text draw
{
auto it = std::find(m_drawlist.begin(), m_drawlist.end(), res.first);
if(it != m_drawlist.end())
m_drawlist.erase(it);
}
m_drawlist.push_back(res.first);
}
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
{
MLX_PROFILE_FUNCTION();
auto res = m_texture_registry.RegisterTexture(texture, x, y);
if(!res.second) // if this is not a completly new texture draw
{
auto it = std::find(m_drawlist.begin(), m_drawlist.end(), res.first);
if(it != m_drawlist.end())
m_drawlist.erase(it);
}
m_drawlist.push_back(res.first);
}
void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
m_text_manager.LoadFont(m_renderer, filepath, scale);
}
void GraphicsSupport::TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept
void GraphicsSupport::TryEraseTextureFromRegistry(NonOwningPtr<Texture> texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(auto it = m_drawlist.begin(); it != m_drawlist.end();)
{
if(m_texture_registry.IsTextureKnown(texture))
it = m_drawlist.erase(it);
else
++it;
}
m_texture_registry.EraseTextures(texture);
}
}

View File

@@ -4,9 +4,7 @@ module;
struct VertIn
{
[location(0)] pos: vec4[f32],
[location(1)] color: vec4[f32], // unused
[location(2)] normal: vec4[f32], // unused
[location(3)] uv: vec2[f32]
[location(1)] uv: vec2[f32]
}
struct VertOut
@@ -24,13 +22,13 @@ struct ViewerData
struct SpriteData
{
color: vec4[f32],
position: vec2[f32]
position: vec4[f32]
}
external
{
[set(0), binding(0)] viewer_data: uniform[ViewerData],
model : push_constant[SpriteData]
model: push_constant[SpriteData]
}
[entry(vert)]
@@ -40,6 +38,6 @@ fn main(input: VertIn) -> VertOut
let output: VertOut;
output.uv = input.uv;
output.color = model.color;
output.pos = viewer_data.projection_matrix * vec4[f32](input.pos.xy + model.position, 0.0, 1.0);
output.pos = viewer_data.projection_matrix * (input.pos + model.position);
return output;
}

View File

@@ -1,29 +1,29 @@
3,2,35,7,0,0,1,0,39,0,0,0,77,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,12,0,0,0,0,0,37,0,0,0,109,97,105,110,0,0,0,0,
14,0,0,0,18,0,0,0,20,0,0,0,23,0,0,0,29,0,0,0,31,0,0,0,32,0,0,0,3,0,
3,2,35,7,0,0,1,0,39,0,0,0,73,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,12,0,0,0,0,0,36,0,0,0,109,97,105,110,0,0,0,0,
13,0,0,0,17,0,0,0,19,0,0,0,23,0,0,0,29,0,0,0,31,0,0,0,32,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,
0,0,5,0,5,0,7,0,0,0,83,112,114,105,116,101,68,97,116,97,0,0,6,0,5,0,7,0,0,0,
0,0,0,0,99,111,108,111,114,0,0,0,6,0,6,0,7,0,0,0,1,0,0,0,112,111,115,105,116,105,
111,110,0,0,0,0,5,0,4,0,26,0,0,0,86,101,114,116,73,110,0,0,6,0,4,0,26,0,0,0,
0,0,0,0,112,111,115,0,6,0,5,0,26,0,0,0,1,0,0,0,99,111,108,111,114,0,0,0,6,0,
5,0,26,0,0,0,2,0,0,0,110,111,114,109,97,108,0,0,6,0,4,0,26,0,0,0,3,0,0,0,
117,118,0,0,5,0,4,0,33,0,0,0,86,101,114,116,79,117,116,0,6,0,5,0,33,0,0,0,0,0,
0,0,99,111,108,111,114,0,0,0,6,0,4,0,33,0,0,0,1,0,0,0,117,118,0,0,6,0,4,0,
33,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,4,0,18,0,0,0,99,111,108,111,114,0,0,0,5,0,4,0,20,0,0,0,110,111,114,109,97,108,
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,4,0,17,0,0,0,99,111,108,111,114,0,0,0,5,0,4,0,19,0,0,0,110,111,114,109,97,108,
0,0,5,0,3,0,23,0,0,0,117,118,0,0,5,0,4,0,29,0,0,0,99,111,108,111,114,0,0,0,
5,0,3,0,31,0,0,0,117,118,0,0,5,0,5,0,32,0,0,0,112,111,115,105,116,105,111,110,0,0,
0,0,5,0,4,0,37,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,5,0,4,0,36,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,32,0,0,0,11,0,
0,0,0,0,0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59,0,4,0,13,0,0,0,20,0,0,0,1,0,0,0,
59,0,4,0,22,0,0,0,23,0,0,0,1,0,0,0,59,0,4,0,28,0,0,0,29,0,0,0,3,0,
0,0,59,0,4,0,30,0,0,0,31,0,0,0,3,0,0,0,59,0,4,0,28,0,0,0,32,0,0,0,
3,0,0,0,54,0,5,0,11,0,0,0,37,0,0,0,0,0,0,0,12,0,0,0,248,0,2,0,38,0,
0,0,59,0,4,0,35,0,0,0,39,0,0,0,7,0,0,0,59,0,4,0,27,0,0,0,40,0,0,0,
7,0,0,0,65,0,5,0,17,0,0,0,41,0,0,0,40,0,0,0,16,0,0,0,63,0,3,0,41,0,
0,0,14,0,0,0,65,0,5,0,17,0,0,0,42,0,0,0,40,0,0,0,19,0,0,0,63,0,3,0,
42,0,0,0,18,0,0,0,65,0,5,0,17,0,0,0,43,0,0,0,40,0,0,0,21,0,0,0,63,0,
3,0,43,0,0,0,20,0,0,0,65,0,5,0,25,0,0,0,44,0,0,0,40,0,0,0,24,0,0,0,
63,0,3,0,44,0,0,0,23,0,0,0,65,0,5,0,25,0,0,0,45,0,0,0,40,0,0,0,24,0,
0,0,61,0,4,0,7,0,0,0,46,0,0,0,45,0,0,0,81,0,5,0,1,0,0,0,47,0,0,0,
46,0,0,0,0,0,0,0,127,0,4,0,1,0,0,0,48,0,0,0,34,0,0,0,133,0,5,0,1,0,
0,0,49,0,0,0,47,0,0,0,48,0,0,0,65,0,5,0,25,0,0,0,50,0,0,0,40,0,0,0,
24,0,0,0,65,0,5,0,51,0,0,0,52,0,0,0,50,0,0,0,16,0,0,0,62,0,3,0,52,0,
0,0,49,0,0,0,65,0,5,0,25,0,0,0,53,0,0,0,40,0,0,0,24,0,0,0,61,0,4,0,
7,0,0,0,54,0,0,0,53,0,0,0,65,0,5,0,25,0,0,0,55,0,0,0,39,0,0,0,19,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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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,16,0,0,0,41,0,0,0,39,0,0,0,18,0,0,0,63,0,3,0,41,0,
0,0,17,0,0,0,65,0,5,0,16,0,0,0,42,0,0,0,39,0,0,0,20,0,0,0,63,0,3,0,
42,0,0,0,19,0,0,0,65,0,5,0,25,0,0,0,43,0,0,0,39,0,0,0,24,0,0,0,63,0,
3,0,43,0,0,0,23,0,0,0,65,0,5,0,25,0,0,0,44,0,0,0,39,0,0,0,24,0,0,0,
61,0,4,0,21,0,0,0,45,0,0,0,44,0,0,0,81,0,5,0,1,0,0,0,46,0,0,0,45,0,
0,0,0,0,0,0,127,0,4,0,1,0,0,0,47,0,0,0,34,0,0,0,133,0,5,0,1,0,0,0,
48,0,0,0,46,0,0,0,47,0,0,0,65,0,5,0,25,0,0,0,49,0,0,0,39,0,0,0,24,0,
0,0,65,0,5,0,50,0,0,0,51,0,0,0,49,0,0,0,15,0,0,0,62,0,3,0,51,0,0,0,
48,0,0,0,65,0,5,0,25,0,0,0,52,0,0,0,39,0,0,0,24,0,0,0,61,0,4,0,21,0,
0,0,53,0,0,0,52,0,0,0,65,0,5,0,25,0,0,0,54,0,0,0,38,0,0,0,18,0,0,0,
62,0,3,0,54,0,0,0,53,0,0,0,65,0,5,0,55,0,0,0,56,0,0,0,9,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,16,0,0,0,58,0,0,0,
38,0,0,0,15,0,0,0,62,0,3,0,58,0,0,0,57,0,0,0,65,0,5,0,59,0,0,0,60,0,
0,0,6,0,0,0,15,0,0,0,61,0,4,0,3,0,0,0,61,0,0,0,60,0,0,0,65,0,5,0,
16,0,0,0,62,0,0,0,39,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,63,0,0,0,62,0,
0,0,65,0,5,0,55,0,0,0,64,0,0,0,9,0,0,0,18,0,0,0,61,0,4,0,2,0,0,0,
65,0,0,0,64,0,0,0,129,0,5,0,2,0,0,0,66,0,0,0,63,0,0,0,65,0,0,0,145,0,
5,0,2,0,0,0,67,0,0,0,61,0,0,0,66,0,0,0,65,0,5,0,16,0,0,0,68,0,0,0,
38,0,0,0,20,0,0,0,62,0,3,0,68,0,0,0,67,0,0,0,61,0,4,0,33,0,0,0,69,0,
0,0,38,0,0,0,81,0,5,0,2,0,0,0,70,0,0,0,69,0,0,0,0,0,0,0,62,0,3,0,
29,0,0,0,70,0,0,0,81,0,5,0,21,0,0,0,71,0,0,0,69,0,0,0,1,0,0,0,62,0,
3,0,31,0,0,0,71,0,0,0,81,0,5,0,2,0,0,0,72,0,0,0,69,0,0,0,2,0,0,0,
62,0,3,0,32,0,0,0,72,0,0,0,253,0,1,0,56,0,1,0

View File

@@ -2,6 +2,7 @@
#define __MLX_SCENE__
#include <Graphics/Sprite.h>
#include <Renderer/ViewerData.h>
namespace mlx
{
@@ -18,14 +19,20 @@ namespace mlx
Sprite& CreateSprite(std::shared_ptr<class Texture> texture) noexcept;
[[nodiscard]] inline const std::vector<std::shared_ptr<Sprite>>& GetSprites() const noexcept { return m_sprites; }
[[nodiscard]] inline const SceneDescriptor& GetDescription() const noexcept { return m_descriptor; }
inline void ResetSprites() { m_sprites.clear(); }
[[nodiscard]] MLX_FORCEINLINE const std::vector<std::shared_ptr<Sprite>>& GetSprites() const noexcept { return m_sprites; }
[[nodiscard]] MLX_FORCEINLINE const SceneDescriptor& GetDescription() const noexcept { return m_descriptor; }
[[nodiscard]] MLX_FORCEINLINE DepthImage& GetDepth() noexcept { return m_depth; }
[[nodiscard]] MLX_FORCEINLINE ViewerData& GetViewerData() noexcept { return m_viewer_data; }
~Scene() = default;
private:
SceneDescriptor m_descriptor;
std::vector<std::shared_ptr<Sprite>> m_sprites;
DepthImage m_depth;
ViewerData m_viewer_data;
};
}

View File

@@ -1,7 +1,7 @@
#ifndef __MLX_SPRITE__
#define __MLX_SPRITE__
#include <Maths/Vec2.h>
#include <Maths/Vec3.h>
#include <Maths/Vec4.h>
#include <Graphics/Mesh.h>
#include <Renderer/Descriptor.h>
@@ -17,10 +17,10 @@ namespace mlx
Sprite(std::shared_ptr<Texture> texture);
inline void SetColor(Vec4f color) noexcept { m_color = color; }
inline void SetPosition(Vec2ui position) noexcept { m_position = position; }
inline void SetPosition(Vec3f position) noexcept { m_position = position; }
[[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; }
[[nodiscard]] inline const Vec2ui& GetPosition() const noexcept { return m_position; }
[[nodiscard]] inline const Vec3f& GetPosition() const noexcept { return m_position; }
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
[[nodiscard]] inline std::shared_ptr<Texture> GetTexture() const { return p_texture; }
@@ -46,7 +46,7 @@ namespace mlx
std::shared_ptr<Texture> p_texture;
std::shared_ptr<Mesh> p_mesh;
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
Vec2ui m_position = Vec2ui{ 0, 0 };
Vec3f m_position = Vec4f{ 0.0f, 0.0f, 0.0f };
};
}

View File

@@ -28,6 +28,7 @@ namespace mlx
void SetStorageBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
void SetUniformBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
void Update(std::size_t i, VkCommandBuffer cmd = VK_NULL_HANDLE) noexcept;
void Reallocate() noexcept;
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t i) const noexcept { return m_set[i]; }
[[nodiscard]] inline DescriptorSet Duplicate() const { return DescriptorSet{ m_set_layout, m_descriptors }; }

View File

@@ -17,6 +17,7 @@ namespace mlx
enum class ImageType
{
Color = 0,
Depth,
EndEnum
};

View File

@@ -23,7 +23,7 @@ namespace mlx
m_layout = layout;
}
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool is_multisampled = false);
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled = false);
void CreateImageView(VkImageViewType type, VkImageAspectFlags aspectFlags, int layer_count = 1) noexcept;
void CreateSampler() noexcept;
void TransitionLayout(VkImageLayout new_layout, VkCommandBuffer cmd = VK_NULL_HANDLE);
@@ -34,7 +34,6 @@ namespace mlx
virtual void Destroy() noexcept;
[[nodiscard]] MLX_FORCEINLINE VkImage Get() const noexcept { return m_image; }
[[nodiscard]] MLX_FORCEINLINE VkImage operator()() const noexcept { return m_image; }
[[nodiscard]] MLX_FORCEINLINE VkDeviceMemory GetDeviceMemory() const noexcept { return m_memory.memory; }
[[nodiscard]] MLX_FORCEINLINE VkImageView GetImageView() const noexcept { return m_image_view; }
[[nodiscard]] MLX_FORCEINLINE VkFormat GetFormat() const noexcept { return m_format; }
@@ -62,6 +61,21 @@ namespace mlx
bool m_is_multisampled = false;
};
class DepthImage : public Image
{
public:
DepthImage() = default;
inline void Init(std::uint32_t width, std::uint32_t height, bool is_multisampled = false)
{
std::vector<VkFormat> candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT };
VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, is_multisampled);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT);
Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
}
~DepthImage() = default;
};
class Texture : public Image
{
public:
@@ -72,7 +86,7 @@ namespace mlx
}
inline void Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format = VK_FORMAT_R8G8B8A8_SRGB, bool is_multisampled = false)
{
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, is_multisampled);
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
Image::CreateSampler();
if(pixels)

View File

@@ -14,6 +14,7 @@ namespace mlx
std::shared_ptr<Shader> fragment_shader;
std::vector<NonOwningPtr<Texture>> color_attachments;
NonOwningPtr<class Renderer> renderer = nullptr;
NonOwningPtr<DepthImage> depth = nullptr;
bool clear_color_attachments = true;
bool no_vertex_inputs = false;
};
@@ -51,6 +52,7 @@ namespace mlx
VkPipeline m_pipeline = VK_NULL_HANDLE;
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
NonOwningPtr<class Renderer> p_renderer;
NonOwningPtr<DepthImage> p_depth;
};
}

View File

@@ -8,15 +8,14 @@ namespace mlx
{
struct Vertex
{
alignas(16) Vec2f position = Vec4f{ 0.0f, 0.0f };
alignas(16) Vec4f color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
alignas(16) Vec4f position = Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f };
alignas(16) Vec2f uv = Vec2f{ 0.0f, 0.0f };
Vertex() = default;
Vertex(Vec2f p, Vec4f c, Vec2f u) : position(std::move(p)), color(std::move(c)), uv(std::move(u)) {}
Vertex(Vec4f p, Vec2f u) : position(std::move(p)), uv(std::move(u)) {}
[[nodiscard]] inline static VkVertexInputBindingDescription GetBindingDescription();
[[nodiscard]] inline static std::array<VkVertexInputAttributeDescription, 3> GetAttributeDescriptions();
[[nodiscard]] inline static std::array<VkVertexInputAttributeDescription, 2> GetAttributeDescriptions();
};
}

View File

@@ -12,24 +12,19 @@ namespace mlx
return binding_description;
}
std::array<VkVertexInputAttributeDescription, 3> Vertex::GetAttributeDescriptions()
std::array<VkVertexInputAttributeDescription, 2> Vertex::GetAttributeDescriptions()
{
std::array<VkVertexInputAttributeDescription, 3> attribute_descriptions;
attribute_descriptions[0].binding = 0;
attribute_descriptions[0].location = 0;
attribute_descriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[0].format = VK_FORMAT_R32G32B32A32_SFLOAT;
attribute_descriptions[0].offset = offsetof(Vertex, position);
attribute_descriptions[1].binding = 0;
attribute_descriptions[1].location = 1;
attribute_descriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
attribute_descriptions[1].offset = offsetof(Vertex, color);
attribute_descriptions[2].binding = 0;
attribute_descriptions[2].location = 2;
attribute_descriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[2].offset = offsetof(Vertex, uv);
attribute_descriptions[1].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[1].offset = offsetof(Vertex, uv);
return attribute_descriptions;
}

View File

@@ -1,5 +1,4 @@
#include <PreCompiled.h>
#include <Core/Graphics.h>
namespace mlx
@@ -14,8 +13,11 @@ namespace mlx
MLX_PROFILE_FUNCTION();
m_renderer.SetWindow(nullptr);
m_renderer.Init(render_target);
m_pixel_put_pipeline.Init(w, h, m_renderer);
m_text_manager.Init(m_renderer);
m_scene_renderer.Init();
SceneDescriptor descriptor{};
descriptor.renderer = &m_renderer;
p_scene = std::make_unique<Scene>(std::move(descriptor));
}
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
@@ -28,29 +30,21 @@ namespace mlx
MLX_PROFILE_FUNCTION();
m_renderer.SetWindow(p_window.get());
m_renderer.Init(nullptr);
m_pixel_put_pipeline.Init(w, h, m_renderer);
m_text_manager.Init(m_renderer);
m_scene_renderer.Init();
SceneDescriptor descriptor{};
descriptor.renderer = &m_renderer;
p_scene = std::make_unique<Scene>(std::move(descriptor));
}
void GraphicsSupport::Render() noexcept
{
MLX_PROFILE_FUNCTION();
if(!m_renderer.BeginFrame())
return;
m_proj = glm::ortho<float>(0, m_width, 0, m_height);
m_renderer.GetUniformBuffer()->SetData(sizeof(m_proj), &m_proj);
m_renderer.getVertDescriptorSet().Bind();
for(auto& data : m_drawlist)
data->Render(m_renderer);
m_pixel_put_pipeline.Render(m_renderer);
m_renderer.EndFrame();
for(auto& data : _drawlist)
data->ResetUpdate();
if(m_renderer.BeginFrame())
{
m_scene_renderer.Render(*p_scene, m_renderer);
m_renderer.EndFrame();
}
#ifdef GRAPHICS_MEMORY_DUMP
// dump memory to file every two seconds
@@ -67,9 +61,9 @@ namespace mlx
GraphicsSupport::~GraphicsSupport()
{
MLX_PROFILE_FUNCTION();
vkDeviceWaitIdle(RenderCore::Get().GetDevice().Get());
m_text_manager.Destroy();
m_pixel_put_pipeline.Destroy();
RenderCore::Get().WaitDeviceIdle();
p_scene.reset();
m_scene_renderer.Destroy();
m_renderer->Destroy();
if(p_window)
p_window->Destroy();

View File

@@ -1,7 +1,7 @@
#include <PreCompiled.h>
#include <Core/SDLManager.h>
#include <Core/Memory.h>
#include <Utils/IconMlx.h>
#include <Embedded/IconMlx.h>
namespace mlx
{
@@ -101,6 +101,8 @@ namespace mlx
default: break;
}
return 0;
}, &watcher_data);
}

View File

@@ -3,11 +3,13 @@
#include <Renderer/Renderer.h>
#include <Renderer/RenderCore.h>
namespace Scop
namespace mlx
{
Scene::Scene(SceneDescriptor desc)
: m_descriptor(std::move(desc))
{
Verify((bool)m_descriptor.renderer, "invalid renderer");
m_depth.Init(m_descriptor.renderer->GetSwapchainImages().back().GetWidth(), m_descriptor.renderer->GetSwapchainImages().back().GetHeight());
}
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept

View File

@@ -40,5 +40,12 @@ namespace mlx
Verify((bool)texture, "Sprite: invalid texture");
p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight());
p_texture = texture;
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
if(event.What() == Event::DescriptorPoolResetEventCode)
m_set.Reallocate();
};
EventBus::RegisterListener({ functor, "__Sprite" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
}
}

View File

@@ -138,4 +138,10 @@ namespace mlx
}
vkUpdateDescriptorSets(RenderCore::Get().GetDevice(), writes.size(), writes.data(), 0, nullptr);
}
void Descriptor::Reallocate() noexcept
{
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), m_set_layout);
}
}

View File

@@ -5,7 +5,7 @@
namespace mlx
{
void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool is_multisampled)
void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled)
{
m_type = type;
m_width = width;
@@ -55,6 +55,8 @@ namespace mlx
switch(m_type)
{
case ImageType::Color: kvf_type = KVF_IMAGE_COLOR; break;
case ImageType::Depth: kvf_type = KVF_IMAGE_DEPTH; break;
default: break;
}
kvfTransitionImageLayout(RenderCore::Get().GetDevice(), m_image, kvf_type, cmd, m_format, m_layout, new_layout, is_single_time_cmd_buffer);

View File

@@ -16,6 +16,7 @@ namespace Scop
p_vertex_shader = descriptor.vertex_shader;
p_fragment_shader = descriptor.fragment_shader;
p_renderer = descriptor.renderer;
p_depth = descriptor.depth;
std::vector<VkPushConstantRange> push_constants;
std::vector<VkDescriptorSetLayout> set_layouts;
@@ -37,7 +38,10 @@ namespace Scop
kvfGPipelineBuilderSetInputTopology(builder, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
kvfGPipelineBuilderSetCullMode(builder, VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE);
kvfGPipelineBuilderEnableAlphaBlending(builder);
kvfGPipelineBuilderDisableDepthTest(builder);
if(p_depth)
kvfGPipelineBuilderEnableDepthTest(builder, (descriptor.depth_test_equal ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_LESS), true);
else
kvfGPipelineBuilderDisableDepthTest(builder);
kvfGPipelineBuilderSetPolygonMode(builder, VK_POLYGON_MODE_FILL, 1.0f);
if(features.sampleRateShading)
kvfGPipelineBuilderSetMultisamplingShading(builder, VK_SAMPLE_COUNT_1_BIT, 0.25f);
@@ -84,6 +88,9 @@ namespace Scop
m_clears[i].color.float32[3] = clear[3];
}
if(p_depth)
m_clears.back().depthStencil = VkClearDepthStencilValue{ 1.0f, 0 };
kvfBeginRenderPass(m_renderpass, command_buffer, fb, fb_extent, m_clears.data(), m_clears.size());
vkCmdBindPipeline(command_buffer, GetPipelineBindPoint(), GetPipeline());
return true;
@@ -127,10 +134,16 @@ namespace Scop
for(NonOwningPtr<Texture> image : render_targets)
{
attachments.push_back(kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, image->GetFormat(), image->GetLayout(), image->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT));
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));
attachment_views.push_back(image->GetImageView());
}
if(p_depth)
{
attachments.push_back(kvfBuildAttachmentDescription((kvfIsDepthFormat(p_depth->GetFormat()) ? KVF_IMAGE_DEPTH : KVF_IMAGE_COLOR), p_depth->GetFormat(), p_depth->GetLayout(), p_depth->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT));
attachment_views.push_back(p_depth->GetImageView());
}
m_renderpass = kvfCreateRenderPass(RenderCore::Get().GetDevice(), attachments.data(), attachments.size(), GetPipelineBindPoint());
m_clears.clear();
m_clears.resize(attachments.size());
@@ -154,6 +167,9 @@ namespace Scop
void GraphicPipeline::TransitionAttachments(VkCommandBuffer cmd)
{
if(p_depth)
p_depth->TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, cmd);
for(NonOwningPtr<Texture> image : m_attachments)
{
if(!image->IsInit())

View File

@@ -11,7 +11,7 @@ namespace mlx
struct SpriteData
{
Vec4f color;
Vec2f position;
Vec4f position;
};
void Render2DPass::Init()
@@ -43,10 +43,20 @@ namespace mlx
};
p_fragment_shader = std::make_shared<Shader>(fragment_shader, ShaderType::Fragment, std::move(fragment_shader_layout));
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
if(event.What() == Event::ResizeEventCode)
m_pipeline.Destroy();
if(event.What() == Event::DescriptorPoolResetEventCode)
{
p_texture_set->Reallocate();
p_viewer_data_set.Reallocate();
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));
p_viewer_data_set->Update(i);
}
}
};
EventBus::RegisterListener({ functor, "__ScopRender2DPass" });
@@ -70,6 +80,7 @@ namespace mlx
pipeline_descriptor.vertex_shader = p_vertex_shader;
pipeline_descriptor.fragment_shader = p_fragment_shader;
pipeline_descriptor.color_attachments = { &render_target };
pipeline_descriptor.depth = scene.GetDepth();
pipeline_descriptor.clear_color_attachments = false;
m_pipeline.Init(pipeline_descriptor);
}
@@ -87,7 +98,7 @@ namespace mlx
for(auto sprite : scene.GetSprites())
{
SpriteData sprite_data;
sprite_data.position = Vec2f{ static_cast<float>(sprite->GetPosition().x), static_cast<float>(sprite->GetPosition().y) };
sprite_data.position = Vec4f{ sprite->GetPosition(), 1.0f };
sprite_data.color = sprite->GetColor();
if(!sprite->IsSetInit())
sprite->UpdateDescriptorSet(*p_texture_set);

View File

@@ -30,10 +30,12 @@ namespace mlx
};
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
if(event.What() == Event::ResizeEventCode)
m_pipeline.Destroy();
if(event.What() == Event::DescriptorPoolResetEventCode)
p_set->Reallocate();
};
EventBus::RegisterListener({ functor, "__ScopFinalPass" });

View File

@@ -15,7 +15,7 @@ namespace mlx
{
if(!m_main_render_texture.IsInit())
{
std::function<void(const EventBase&)> functor = [this, renderer](const EventBase& event)
func::function<void(const EventBase&)> functor = [this, renderer](const EventBase& event)
{
if(event.What() == Event::ResizeEventCode)
{
@@ -31,6 +31,7 @@ namespace mlx
}
m_main_render_texture.Clear(renderer.GetActiveCommandBuffer(), Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f });
scene.GetDepth().Clear(renderer.GetActiveCommandBuffer(), {});
m_2Dpass.Pass(scene, renderer, m_main_render_texture);
m_final.Pass(scene, renderer, m_main_render_texture);

View File

@@ -18,11 +18,16 @@ namespace mlx
{
Event What() const override { return Event::FrameBeginEventCode; }
};
struct DescriptorPoolResetEventBroadcast : public EventBase
{
Event What() const override { return Event::DescriptorPoolResetEventCode; }
};
}
void Renderer::Init(NonOwningPtr<Window> window)
{
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
if(event.What() == Event::ResizeEventCode)
this->RequireFramebufferResize();
@@ -86,6 +91,7 @@ namespace mlx
}
m_current_frame_index = (m_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
kvfResetDeviceDescriptorPools(RenderCore::Get().GetDevice());
EventBus::SendBroadcast(Internal::DescriptorPoolResetEventBroadcast{});
}
void Renderer::CreateSwapchain()