#pragma once #include #include #include #include #include #include #include #include class RSoftwareBackend; class Renderer; extern Renderer g_renderer; enum REntityType : int32_t { REntityType_Rectangle, REntityType_AlphaBitmap, REntityType_Circle, REntityType_Text, }; struct REntity_AlphaBitmap { REntityType type; AlphaBitmap& bitmap; V3F32 pos; Color color; }; struct REntity_Rectangle { REntityType type; Rectangle rect; Color color; }; struct REntity_Circle { REntityType type; Circle circle; Color color; }; struct REntity_Text { REntityType type; std::u32string& text; Font& font; V3F32 pos; Color color; }; union REntity { REntityType type; REntity_AlphaBitmap bitmap; REntity_Rectangle rect; REntity_Circle circle; REntity_Text text; }; struct RSortEntry { float z; size_t entity_index; }; class Renderer { public: void Init(SDL_Window* window); /* core functions */ void Draw(); void Reset(); void Clear(Color color); void PushAlphaBitmap(AlphaBitmap& bitmap, V3F32 pos, Color color); void PushRectangle(Rectangle rect, Color color, float z); void PushCircle(Circle circle, Color color, float z); void PushText(std::u32string& text, Font& font, V3F32 pos, Color color); /* 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); public: SDL_Window* m_window; int32_t m_screen_w; int32_t m_screen_h; float m_camera_w; float m_camera_h; Color m_clear_color {}; std::vector m_render_entities; std::vector m_sort_entries; std::unique_ptr m_backend; friend class RSoftwareBackend; };