// IAEngine: 2D Game Engine by IA // Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #pragma once #include #include namespace ia::iae { class Renderer { public: struct Geometry { INT32 IndexCount{}; SDL_GPUBuffer *IndexBuffer; SDL_GPUBuffer *VertexBuffer; }; struct State { BOOL FlippedH{false}; BOOL FlippedV{false}; BOOL CameraRelative{true}; Color ColorOverlay{}; Vec2 TextureOffset{0.0f, 0.0f}; Vec2 Position{}; Vec2 Scale{}; FLOAT32 Rotation; SDL_Rect Scissor{}; SDL_GPUTexture *ActiveTexture{nullptr}; }; struct DrawEntry { UINT8 Layer{}; UINT16 SortIndex{}; State DrawState{}; Geometry *GeometryHandle{}; }; public: STATIC VOID Initialize(); STATIC VOID Terminate(); STATIC VOID BeginFrame(); STATIC VOID EndFrame(); STATIC VOID WaitForGPUIdle(); STATIC VOID OnScreenResize(IN INT32 newWidth, IN INT32 newHeight); STATIC VOID UpdateSceneScalingFactor(); public: STATIC Geometry *CreateGeometry(IN CONST Vector &vertices, IN CONST Vector &indices); STATIC VOID DestroyGeometry(IN Geometry *handle); STATIC VOID DrawGeometry(IN Geometry *handle, IN SDL_GPUTexture* texture, IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex); STATIC VOID DrawText(IN CONST String &text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex); STATIC SDL_GPUTextureFormat GetRenderTargetFormat(); STATIC SDL_GPUDevice *GetDevice() { return s_gpuDevice; } private: STATIC VOID Draw(IN CONST DrawEntry &entity); private: STATIC State s_state; STATIC INT32 s_screenWidth; STATIC INT32 s_screenHeight; STATIC SDL_GPUDevice *s_gpuDevice; STATIC Pipeline *s_geometryPipeline; STATIC Geometry *s_quadGeometry; STATIC Geometry *s_circleGeometry; STATIC Vector s_drawEntries; STATIC SDL_GPURenderPass *s_activeRenderPass; STATIC SDL_GPUCommandBuffer *s_activeCommandBuffer; STATIC SDL_GPUColorTargetInfo s_colorTargetInfo; STATIC class CameraComponent *s_activeCamera; STATIC BOOL s_ySortingEnabled; STATIC SDL_Rect s_defaultScissor; STATIC SDL_GPUViewport s_defaultViewport; STATIC Vec2 s_activeSceneDesignViewport; friend class Engine; }; } // namespace ia::iae