Files
yaze/src/app/gfx/backend/sdl2_renderer.h
scawful c6a581b202 feat: Implement SDL2 Renderer as Concrete IRenderer Implementation
- Added IRenderer interface to define abstract rendering operations, decoupling application logic from specific rendering APIs.
- Implemented SDL2Renderer class, providing concrete methods for texture management, rendering primitives, and lifecycle management using SDL2.
- Introduced texture creation, updating, and destruction methods, along with rendering functions to clear the screen and present frames.
- Enhanced backend access for third-party library integration, ensuring flexibility in rendering operations.
2025-10-07 14:19:48 -04:00

52 lines
1.7 KiB
C++

#pragma once
#include "app/gfx/backend/irenderer.h"
#include "util/sdl_deleter.h"
namespace yaze {
namespace gfx {
/**
* @class SDL2Renderer
* @brief A concrete implementation of the IRenderer interface using SDL2.
*
* This class encapsulates all rendering logic that is specific to the SDL2_render API.
* It translates the abstract calls from the IRenderer interface into concrete SDL2 commands.
* This is the first step in abstracting the renderer, allowing the rest of the application
* to be independent of SDL2.
*/
class SDL2Renderer : public IRenderer {
public:
SDL2Renderer();
~SDL2Renderer() override;
// --- Lifecycle and Initialization ---
bool Initialize(SDL_Window* window) override;
void Shutdown() override;
// --- Texture Management ---
TextureHandle CreateTexture(int width, int height) override;
void UpdateTexture(TextureHandle texture, const Bitmap& bitmap) override;
void DestroyTexture(TextureHandle texture) override;
// --- Rendering Primitives ---
void Clear() override;
void Present() override;
void RenderCopy(TextureHandle texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect) override;
void SetRenderTarget(TextureHandle texture) override;
void SetDrawColor(SDL_Color color) override;
/**
* @brief Provides access to the underlying SDL_Renderer*.
* @return A void pointer that can be safely cast to an SDL_Renderer*.
*/
void* GetBackendRenderer() override { return renderer_.get(); }
private:
// The core SDL2 renderer object, managed by a unique_ptr with a custom deleter.
std::unique_ptr<SDL_Renderer, util::SDL_Deleter> renderer_;
};
} // namespace gfx
} // namespace yaze