From 9d72ed2d5801b1506158082f08bd0b47e58db17f Mon Sep 17 00:00:00 2001 From: fschildt Date: Mon, 29 Sep 2025 13:20:43 +0200 Subject: renderer: major refactor; vectors: now aggregates --- src/renderer/Renderer.hpp | 110 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 20 deletions(-) (limited to 'src/renderer/Renderer.hpp') diff --git a/src/renderer/Renderer.hpp b/src/renderer/Renderer.hpp index 24d4b71..4fdf524 100644 --- a/src/renderer/Renderer.hpp +++ b/src/renderer/Renderer.hpp @@ -1,41 +1,111 @@ #pragma once #include -#include + #include #include +#include + +#include +#include + + +class RSoftwareBackend; +class Renderer; + +extern Renderer g_renderer; + + +enum REntityType : int32_t { + REntityType_Rectangle, + REntityType_MonoBitmap, +}; -struct RCanvas { - uint32_t rshift; - uint32_t gshift; - uint32_t bshift; - uint32_t ashift; +struct REntity_Rectangle { + REntityType type; + float x0; + float y0; + float x1; + float y1; + float z; + Color color; +}; + +struct REntity_MonoBitmap { + REntityType type; + float x; + float y; int32_t w; int32_t h; - uint32_t *pixels; + float z; + void *data; +}; + +union REntity { + REntityType type; + REntity_Rectangle rect; + REntity_MonoBitmap bitmap; +}; + +struct RSortEntry { + float z; + size_t entity_index; }; class Renderer { public: - Renderer(SDL_Window *window); + void Init(SDL_Window* window); + + + /* core functions */ + + void Draw(); + void Reset(); + + void Clear(Color color); + void PushRectangle(RectF32 rect, float z, Color color); + void PushMonoBitmap(V3F32 pos, int w, int h, void* bitmap); + + + /* helper functions */ + + void SetScreenSize(int32_t w, int32_t h); + void SetCameraSize(float w, float h); + + + int32_t WorldXToScreenX(float x); + int32_t WorldYToScreenY(float y); + + int32_t WorldWidthToScreenWidth(float w); + int32_t WorldHeightToScreenHeight(float h); + + + /* temporary helper functions (from old RGroup api) */ + float GetScale(); + V2F32 ViewPosToScreenPos(V2F32 view_pos); + V2F32 ViewSizeToScreenSize(V2F32 view_size); + ImVec2 ViewPosToScreenPosImGui(V2F32 view_pos); + ImVec2 ViewSizeToScreenSizeImGui(V2F32 view_size); + + + + // Todo: make this private +public: + int32_t m_screen_w; + int32_t m_screen_h; - bool Init(); - void ResizeCanvas(int32_t w, int32_t h); - void Draw(RenderGroup &render_group); + float m_camera_w; + float m_camera_h; + Color m_clear_color {}; + std::vector m_render_entities; + std::vector m_sort_entries; -private: - void DrawRectangle(RenderGroup& rgroup, REntity_Rectangle& rect); - void DrawMonoBitmap(REntity_Bitmap& bitmap, Color color); - int32_t WorldXToScreenX(RenderGroup& rgroup, float x); - int32_t WorldYToScreenY(RenderGroup& rgroup, float y); + std::unique_ptr m_backend; -private: - SDL_Window *m_Window; - uint32_t m_GlTexId; - RCanvas m_Canvas; + friend class RSoftwareBackend; }; -- cgit v1.2.3