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);
}
}