gfx cleanup

This commit is contained in:
scawful
2024-08-13 18:04:41 -04:00
parent c26a5b4a5e
commit 327985b1c9
3 changed files with 16 additions and 6 deletions

View File

@@ -235,6 +235,11 @@ void Bitmap::Create(int width, int height, int depth, const Bytes &data) {
void Bitmap::Create(int width, int height, int depth, int format, void Bitmap::Create(int width, int height, int depth, int format,
const Bytes &data) { const Bytes &data) {
if (data.empty()) {
SDL_Log("Bitmap data is empty\n");
active_ = false;
return;
}
active_ = true; active_ = true;
width_ = width; width_ = width;
height_ = height; height_ = height;
@@ -246,6 +251,11 @@ void Bitmap::Create(int width, int height, int depth, int format,
SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_, SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_,
GetSnesPixelFormat(format)), GetSnesPixelFormat(format)),
SDL_Surface_Deleter()); SDL_Surface_Deleter());
if (surface_ == nullptr) {
SDL_Log("SDL_CreateRGBSurfaceWithFormat failed: %s\n", SDL_GetError());
active_ = false;
return;
}
surface_->pixels = pixel_data_; surface_->pixels = pixel_data_;
active_ = true; active_ = true;
} }
@@ -355,7 +365,7 @@ absl::Status Bitmap::ApplyPalette(const SnesPalette &palette) {
sdl_palette->colors[i].a = pal_color.rgb().w; sdl_palette->colors[i].a = pal_color.rgb().w;
} }
SDL_LockSurface(surface_.get()); SDL_LockSurface(surface_.get());
SDL_RETURN_IF_ERROR() // SDL_RETURN_IF_ERROR()
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -379,7 +389,7 @@ absl::Status Bitmap::ApplyPaletteFromPaletteGroup(const SnesPalette &palette,
} }
} }
SDL_LockSurface(surface_.get()); SDL_LockSurface(surface_.get());
SDL_RETURN_IF_ERROR() // SDL_RETURN_IF_ERROR()
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -404,7 +414,7 @@ absl::Status Bitmap::ApplyPaletteWithTransparent(const SnesPalette &palette,
i++; i++;
} }
SDL_LockSurface(surface_.get()); SDL_LockSurface(surface_.get());
SDL_RETURN_IF_ERROR() // SDL_RETURN_IF_ERROR()
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -206,7 +206,7 @@ class Bitmap {
bool modified_ = false; bool modified_ = false;
void *texture_pixels = nullptr; void *texture_pixels = nullptr;
uchar *pixel_data_; uint8_t *pixel_data_ = nullptr;
Bytes data_; Bytes data_;
std::vector<uint8_t> png_data_; std::vector<uint8_t> png_data_;

View File

@@ -151,14 +151,14 @@ class SnesPalette {
void operator()(int i, const SnesColor& color) { void operator()(int i, const SnesColor& color) {
if (i >= colors.size()) { if (i >= colors.size()) {
std::cout << SNESPalette: Index out of bounds << std::endl; std::cout << "SNESPalette: Index out of bounds" << std::endl;
} }
colors[i] = color; colors[i] = color;
} }
void operator()(int i, const ImVec4& color) { void operator()(int i, const ImVec4& color) {
if (i >= colors.size()) { if (i >= colors.size()) {
std::cout << SNESPalette: Index out of bounds << std::endl; std::cout << "SNESPalette: Index out of bounds" << std::endl;
return; return;
} }
colors[i].set_rgb(color); colors[i].set_rgb(color);