Refactor bitmap update methods to remove unnecessary parameters; simplify texture updating in Renderer and Bitmap classes

This commit is contained in:
scawful
2024-11-13 09:16:16 -05:00
parent 8e8b3ed2f7
commit 7798d769a5
5 changed files with 11 additions and 30 deletions

View File

@@ -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<SDL_Renderer> renderer) {
texture_ = std::shared_ptr<SDL_Texture>{
SDL_CreateTextureFromSurface(renderer.get(), surface_.get()),
SDL_Texture_Deleter{}};
}
void Bitmap::UpdateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = std::shared_ptr<SDL_Texture>{
SDL_CreateTextureFromSurface(renderer.get(), surface_.get()),
SDL_Texture_Deleter{}};
}
absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) {
if (surface_ == nullptr) {
return absl::FailedPreconditionError(