#pragma once #include #include #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; V2F32 pos; Color color; }; struct REntity_Rectangle { REntityType type; Rectangle rect; Color color; }; struct REntity_Circle { REntityType type; Circle circle; Color color; }; struct REntity_String32 { REntityType type; String32Id id; Font& font; V2F32 pos; Color color; }; union REntity { REntityType type; REntity_AlphaBitmap bitmap; REntity_Rectangle rect; REntity_Circle circle; REntity_String32 string32; }; struct RSortEntry { uint32_t z; uint32_t entity_index; }; class Renderer { public: void Init(SDL_Window* window); /* core functions */ void Draw(); void Reset(); void SetClearColor(Color color); void SetScreenSize(int32_t w, int32_t h); void SetCameraSize(float w, float h); void PushAlphaBitmap(AlphaBitmap& bitmap, V2F32 pos, Color color, uint32_t z); void PushRectangle(Rectangle rect, Color color, uint32_t z); void PushCircle(Circle circle, Color color, uint32_t z); void PushString32(String32Id id, Font& font, V2F32 pos, Color color, uint32_t z); /* helper functions */ int32_t WorldXToScreenX(float x); int32_t WorldYToScreenY(float y); int32_t WorldWidthToScreenWidth(float w); int32_t WorldHeightToScreenHeight(float h); 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; };