refactor: Update Renderer Logic and Introduce Direct Pixel Access Methods

- Removed direct renderer calls from LoadLinkGraphics and LoadAllGraphicsData to prepare for future renderer refactor.
- Added LockTexture and UnlockTexture methods to IRenderer and SDL2Renderer for direct pixel access, enhancing texture management capabilities.
- Updated CMake configuration to include the new SDL2Renderer source file, ensuring proper integration within the graphics backend.
This commit is contained in:
scawful
2025-10-07 14:39:36 -04:00
parent c6a581b202
commit b788d93071
5 changed files with 22 additions and 27 deletions

View File

@@ -73,6 +73,10 @@ public:
*/
virtual void DestroyTexture(TextureHandle texture) = 0;
// --- Direct Pixel Access ---
virtual bool LockTexture(TextureHandle texture, SDL_Rect* rect, void** pixels, int* pitch) = 0;
virtual void UnlockTexture(TextureHandle texture) = 0;
// --- Rendering Primitives ---
/**

View File

@@ -1,5 +1,6 @@
#include "app/gfx/backend/sdl2_renderer.h"
#include "absl/strings/str_format.h"
#include "app/gfx/bitmap.h"
namespace yaze {
namespace gfx {
@@ -76,6 +77,14 @@ void SDL2Renderer::DestroyTexture(TextureHandle texture) {
}
}
bool SDL2Renderer::LockTexture(TextureHandle texture, SDL_Rect* rect, void** pixels, int* pitch) {
return SDL_LockTexture(static_cast<SDL_Texture*>(texture), rect, pixels, pitch) == 0;
}
void SDL2Renderer::UnlockTexture(TextureHandle texture) {
SDL_UnlockTexture(static_cast<SDL_Texture*>(texture));
}
/**
* @brief Clears the screen with the current draw color.
*/

View File

@@ -29,6 +29,10 @@ public:
void UpdateTexture(TextureHandle texture, const Bitmap& bitmap) override;
void DestroyTexture(TextureHandle texture) override;
// --- Direct Pixel Access ---
bool LockTexture(TextureHandle texture, SDL_Rect* rect, void** pixels, int* pitch) override;
void UnlockTexture(TextureHandle texture) override;
// --- Rendering Primitives ---
void Clear() override;
void Present() override;

View File

@@ -15,6 +15,7 @@ set(
app/gfx/tilemap.cc
app/gfx/graphics_optimizer.cc
app/gfx/bpp_format_manager.cc
app/gfx/backend/sdl2_renderer.cc
)
# ==============================================================================