feat: Implement lazy initialization for Emulator and Renderer

- Updated Emulator to support optional lazy initialization of the renderer, enhancing flexibility during runtime.
- Introduced a new method in IRenderer for creating textures with specific pixel formats, improving texture management for the emulator.
- Refactored texture command processing in Arena to handle empty queues more gracefully.
- Enhanced SDL2Renderer to support the new texture creation method, ensuring compatibility with emulator requirements.
This commit is contained in:
scawful
2025-10-07 17:49:27 -04:00
parent 6c331f1fd0
commit 0c3c8ebca7
7 changed files with 63 additions and 13 deletions

View File

@@ -33,7 +33,7 @@ void Arena::QueueTextureCommand(TextureCommandType type, Bitmap* bitmap) {
}
void Arena::ProcessTextureQueue(IRenderer* renderer) {
if (!renderer_) return;
if (!renderer_ || texture_command_queue_.empty()) return;
for (const auto& command : texture_command_queue_) {
switch (command.type) {

View File

@@ -60,6 +60,16 @@ public:
*/
virtual TextureHandle CreateTexture(int width, int height) = 0;
/**
* @brief Creates a new texture with a specific pixel format.
* @param width The width of the texture in pixels.
* @param height The height of the texture in pixels.
* @param format The SDL pixel format (e.g., SDL_PIXELFORMAT_ARGB8888).
* @param access The texture access pattern (e.g., SDL_TEXTUREACCESS_STREAMING).
* @return An abstract TextureHandle to the newly created texture, or nullptr on failure.
*/
virtual TextureHandle CreateTextureWithFormat(int width, int height, uint32_t format, int access) = 0;
/**
* @brief Updates a texture with the pixel data from a Bitmap.
* @param texture The handle of the texture to update.

View File

@@ -50,6 +50,16 @@ TextureHandle SDL2Renderer::CreateTexture(int width, int height) {
);
}
/**
* @brief Creates an SDL_Texture with a specific pixel format and access pattern.
* This is useful for specialized textures like emulator PPU output.
*/
TextureHandle SDL2Renderer::CreateTextureWithFormat(int width, int height, uint32_t format, int access) {
return static_cast<TextureHandle>(
SDL_CreateTexture(renderer_.get(), format, access, width, height)
);
}
/**
* @brief Updates an SDL_Texture with data from a Bitmap.
* This involves converting the bitmap's surface to the correct format and updating the texture.

View File

@@ -26,6 +26,7 @@ public:
// --- Texture Management ---
TextureHandle CreateTexture(int width, int height) override;
TextureHandle CreateTextureWithFormat(int width, int height, uint32_t format, int access) override;
void UpdateTexture(TextureHandle texture, const Bitmap& bitmap) override;
void DestroyTexture(TextureHandle texture) override;