Skip to content

Commit

Permalink
Render a black screen as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jul 6, 2024
1 parent 03ada1c commit b4448be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
15 changes: 14 additions & 1 deletion source/gfx/SplashScreenDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ constexpr uint8_t s_texturePixelShaderCompiled[] = {
0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

/** empty png as fallback */
uint8_t empty_png[119] = {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
0x08, 0x02, 0x00, 0x00, 0x00, 0xFD, 0xD4, 0x9A, 0x73, 0x00, 0x00, 0x00,
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00,
0x00, 0x04, 0x67, 0x41, 0x4D, 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC,
0x61, 0x05, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00,
0x16, 0x25, 0x00, 0x00, 0x16, 0x25, 0x01, 0x49, 0x52, 0x24, 0xF0, 0x00,
0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x18, 0x57, 0x63, 0x40, 0x02,
0x0C, 0x0C, 0x00, 0x00, 0x0E, 0x00, 0x01, 0x7A, 0xB1, 0xB9, 0x30, 0x00,
0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82};

static GX2Texture *LoadImageAsTexture(std::string_view path) {
std::vector<uint8_t> buffer;
if (LoadFileIntoBuffer(std::string(path).append("splash.png"), buffer)) {
Expand All @@ -115,7 +128,7 @@ static GX2Texture *LoadImageAsTexture(std::string_view path) {
return texture;
}
}
return nullptr;
return PNG_LoadTexture(empty_png);
}

SplashScreenDrawer::SplashScreenDrawer(std::string_view splash_base_path) {
Expand Down
14 changes: 5 additions & 9 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ int32_t main(int32_t argc, char **argv) {
basePath = argv[0];
}

if (existsAsFile(basePath + "/splash.png") || existsAsFile(basePath + "/splash.tga")) {
GfxInit();
{
SplashScreenDrawer splashScreenDrawer(basePath + "/");
splashScreenDrawer.Draw();
}
GfxShutdown();
} else {
DEBUG_FUNCTION_LINE_INFO("No splash.png or splash.tga found in \"%s\". Skipping splash screen.", basePath.c_str());
GfxInit();
{
SplashScreenDrawer splashScreenDrawer(basePath + "/");
splashScreenDrawer.Draw();
}
GfxShutdown();

deinitLogging();

Expand Down
11 changes: 0 additions & 11 deletions source/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,3 @@
#include <vector>

bool LoadFileIntoBuffer(std::string_view path, std::vector<uint8_t> &buffer);

static inline bool existsAsFile(std::string_view path) {
struct stat st {};
if (stat(path.data(), &st) >= 0 && S_ISREG(st.st_mode)) {
DEBUG_FUNCTION_LINE_VERBOSE("\"%s\" exists", path.data());
return true;
} else {
DEBUG_FUNCTION_LINE_VERBOSE("\"%s\" doesn't exists", path.data());
}
return false;
}

0 comments on commit b4448be

Please sign in to comment.