diff --git a/src/app/core/platform/renderer.h b/src/app/core/platform/renderer.h index e951d3bf..a2f735ec 100644 --- a/src/app/core/platform/renderer.h +++ b/src/app/core/platform/renderer.h @@ -42,16 +42,10 @@ class Renderer { auto renderer() -> SDL_Renderer * { return renderer_.get(); } - /** - * @brief Used to render a bitmap to the screen. - */ void RenderBitmap(gfx::Bitmap *bitmap) { bitmap->CreateTexture(renderer_.get()); } - /** - * @brief Used to update a bitmap on the screen. - */ void UpdateBitmap(gfx::Bitmap *bitmap) { bitmap->UpdateTexture(renderer_.get()); } @@ -64,6 +58,13 @@ class Renderer { RenderBitmap(&bitmap); } + void Clear() { + SDL_SetRenderDrawColor(renderer_.get(), 0x00, 0x00, 0x00, 0x00); + SDL_RenderClear(renderer_.get()); + } + + void Present() { SDL_RenderPresent(renderer_.get()); } + private: Renderer() = default; diff --git a/src/app/core/platform/sdl_deleter.h b/src/app/core/platform/sdl_deleter.h index 34ec9798..2552d1ba 100644 --- a/src/app/core/platform/sdl_deleter.h +++ b/src/app/core/platform/sdl_deleter.h @@ -3,8 +3,6 @@ #include -#include "app/core/platform/memory_tracker.h" - namespace yaze { namespace core { @@ -19,8 +17,7 @@ struct SDL_Deleter { // Custom deleter for SDL_Surface struct SDL_Surface_Deleter { void operator()(SDL_Surface* p) const { - if (p && !MemoryTracker::GetInstance().IsFreed(p)) { - MemoryTracker::GetInstance().TrackDeallocation(p); + if (p) { SDL_FreeSurface(p); } } @@ -29,8 +26,7 @@ struct SDL_Surface_Deleter { // Custom deleter for SDL_Texture struct SDL_Texture_Deleter { void operator()(SDL_Texture* p) const { - if (p && !MemoryTracker::GetInstance().IsFreed(p)) { - MemoryTracker::GetInstance().TrackDeallocation(p); + if (p) { SDL_DestroyTexture(p); } } diff --git a/src/app/gfx/texture_pool.h b/src/app/gfx/texture_pool.h deleted file mode 100644 index 1ec07f75..00000000 --- a/src/app/gfx/texture_pool.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef YAZE_APP_GFX_TEXTURE_POOL_H -#define YAZE_APP_GFX_TEXTURE_POOL_H - -#include - -#include -#include -#include - -namespace yaze { -namespace gfx { - -class TexturePool { - public: - static TexturePool& GetInstance() { - static TexturePool instance; - return instance; - } - - SDL_Texture* GetTexture(SDL_Renderer* renderer, int width, int height, - Uint32 format) { - std::string key = GenerateKey(width, height, format); - - // Check if we have a suitable texture in the pool - auto it = available_textures_.find(key); - if (it != available_textures_.end() && !it->second.empty()) { - SDL_Texture* texture = it->second.back(); - it->second.pop_back(); - return texture; - } - - // Create a new texture - return SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, - width, height); - } - - void ReturnTexture(SDL_Texture* texture, int width, int height, - Uint32 format) { - if (!texture) return; - - std::string key = GenerateKey(width, height, format); - available_textures_[key].push_back(texture); - } - - void Clear() { - for (auto& pair : available_textures_) { - for (SDL_Texture* texture : pair.second) { - SDL_DestroyTexture(texture); - } - } - available_textures_.clear(); - } - - private: - TexturePool() = default; - - std::string GenerateKey(int width, int height, Uint32 format) { - return std::to_string(width) + "x" + std::to_string(height) + "_" + - std::to_string(format); - } - - std::unordered_map> - available_textures_; -}; - -} // namespace gfx -} // namespace yaze - -#endif // YAZE_APP_GFX_TEXTURE_POOL_H