From 7798d769a5d14334746fb7aaa943b12f6bcfb74c Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 13 Nov 2024 09:16:16 -0500 Subject: [PATCH] Refactor bitmap update methods to remove unnecessary parameters; simplify texture updating in Renderer and Bitmap classes --- src/app/core/platform/renderer.h | 4 ++-- src/app/editor/dungeon/dungeon_editor.cc | 4 ++-- src/app/editor/graphics/graphics_editor.cc | 4 ++-- src/app/gfx/bitmap.cc | 23 +++------------------- src/app/gfx/bitmap.h | 6 ++---- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/app/core/platform/renderer.h b/src/app/core/platform/renderer.h index b7a834d4..3e67b38b 100644 --- a/src/app/core/platform/renderer.h +++ b/src/app/core/platform/renderer.h @@ -52,8 +52,8 @@ class Renderer { /** * @brief Used to update a bitmap on the screen. */ - void UpdateBitmap(gfx::Bitmap *bitmap, bool use_sdl_update = false) { - bitmap->UpdateTexture(renderer_.get(), use_sdl_update); + void UpdateBitmap(gfx::Bitmap *bitmap) { + bitmap->UpdateTexture(renderer_.get()); } absl::Status CreateAndRenderBitmap(int width, int height, int depth, diff --git a/src/app/editor/dungeon/dungeon_editor.cc b/src/app/editor/dungeon/dungeon_editor.cc index dacbf4b1..cbedd60b 100644 --- a/src/app/editor/dungeon/dungeon_editor.cc +++ b/src/app/editor/dungeon/dungeon_editor.cc @@ -119,14 +119,14 @@ absl::Status DungeonEditor::RefreshGraphics() { int block = rooms_[current_room_id_].blocks()[i]; RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( current_palette_group_[current_palette_id_], 0)); - Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block], true); + Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]); } auto sprites_aux1_pal_group = rom()->palette_group().sprites_aux1; for (int i = 9; i < 16; i++) { int block = rooms_[current_room_id_].blocks()[i]; RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( sprites_aux1_pal_group[current_palette_id_], 0)); - Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block], true); + Renderer::GetInstance().UpdateBitmap(&graphics_bin_[block]); } return absl::OkStatus(); } diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index c00a58e1..60a632f8 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -294,7 +294,7 @@ absl::Status GraphicsEditor::UpdateGfxTabView() { auto draw_tile_event = [&]() { current_sheet_canvas_.DrawTileOnBitmap(tile_size_, ¤t_bitmap, current_color_); - Renderer::GetInstance().UpdateBitmap(¤t_bitmap, true); + Renderer::GetInstance().UpdateBitmap(¤t_bitmap); }; current_sheet_canvas_.UpdateColorPainter( @@ -373,7 +373,7 @@ absl::Status GraphicsEditor::UpdatePaletteColumn() { ->data()[current_sheet_] .ApplyPaletteWithTransparent(palette, edit_palette_sub_index_)); Renderer::GetInstance().UpdateBitmap( - &rom()->mutable_gfx_sheets()->data()[current_sheet_], true); + &rom()->mutable_gfx_sheets()->data()[current_sheet_]); refresh_graphics_ = false; } } diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 3fc195f7..890574a0 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -307,7 +307,7 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) { SDL_UnlockTexture(texture_.get()); } -void Bitmap::UpdateTexture(SDL_Renderer *renderer, bool use_sdl_update) { +void Bitmap::UpdateTexture(SDL_Renderer *renderer) { SDL_Surface *converted_surface = SDL_ConvertSurfaceFormat(surface_.get(), SDL_PIXELFORMAT_ARGB8888, 0); if (converted_surface) { @@ -319,28 +319,11 @@ void Bitmap::UpdateTexture(SDL_Renderer *renderer, bool use_sdl_update) { SDL_LockTexture(texture_.get(), nullptr, (void **)&texture_pixels, &converted_surface_->pitch); - if (use_sdl_update) { - SDL_UpdateTexture(texture_.get(), nullptr, converted_surface_->pixels, - converted_surface_->pitch); - } else { - memcpy(texture_pixels, converted_surface_->pixels, - converted_surface_->h * converted_surface_->pitch); - } + memcpy(texture_pixels, converted_surface_->pixels, + converted_surface_->h * converted_surface_->pitch); SDL_UnlockTexture(texture_.get()); } -void Bitmap::CreateTexture(std::shared_ptr renderer) { - texture_ = std::shared_ptr{ - SDL_CreateTextureFromSurface(renderer.get(), surface_.get()), - SDL_Texture_Deleter{}}; -} - -void Bitmap::UpdateTexture(std::shared_ptr renderer) { - texture_ = std::shared_ptr{ - SDL_CreateTextureFromSurface(renderer.get(), surface_.get()), - SDL_Texture_Deleter{}}; -} - absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) { if (surface_ == nullptr) { return absl::FailedPreconditionError( diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 68a6e365..48a97312 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -108,14 +108,12 @@ class Bitmap { * Converts the surface from a RGB to ARGB format. * Uses SDL_TEXTUREACCESS_STREAMING to allow for live updates. */ - void CreateTexture(std::shared_ptr renderer); + void CreateTexture(SDL_Renderer *renderer); /** * @brief Updates the underlying SDL_Texture when it already exists. */ - void UpdateTexture(std::shared_ptr renderer); - void CreateTexture(SDL_Renderer *renderer); - void UpdateTexture(SDL_Renderer *renderer, bool use_sdl_update = false); + void UpdateTexture(SDL_Renderer *renderer); /** * @brief Copy color data from the SnesPalette into the SDL_Palette