Use OpenGL ES and disable VSync by default to run on Raspberry Pis.

This commit is contained in:
Zachary Hall 2023-07-16 12:06:03 -07:00
parent 56cfe66f9c
commit ec7b3079a7
2 changed files with 14 additions and 2 deletions

View file

@ -126,7 +126,7 @@ int main(int, char**)
SDL_SetWindowIcon(window, icon); SDL_SetWindowIcon(window, icon);
SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context); SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync SDL_GL_SetSwapInterval(0); // Enable vsync
// Setup Dear ImGui context // Setup Dear ImGui context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
@ -194,6 +194,7 @@ int main(int, char**)
bool prefs_window = false; bool prefs_window = false;
bool theme_editor = false; bool theme_editor = false;
bool stopped = true; bool stopped = true;
bool vsync = false;
{ {
Json::Value config; Json::Value config;
std::ifstream stream; std::ifstream stream;
@ -213,6 +214,10 @@ int main(int, char**)
if (config.isMember("demo_window")) { if (config.isMember("demo_window")) {
show_demo_window = config["demo_window"].asBool(); show_demo_window = config["demo_window"].asBool();
} }
if (config.isMember("vsync")) {
vsync = config["vsync"].asBool();
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
}
stream.close(); stream.close();
} }
if (is_empty(Theme::themeDir)) { if (is_empty(Theme::themeDir)) {
@ -228,6 +233,7 @@ int main(int, char**)
} }
} }
} }
theme->Apply(accent_color);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file. // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage. // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
@ -349,6 +355,9 @@ int main(int, char**)
ImGui::SetNextWindowSizeConstraints(min_size, max_size); ImGui::SetNextWindowSizeConstraints(min_size, max_size);
ImGui::Begin("Preferences...", &prefs_window); ImGui::Begin("Preferences...", &prefs_window);
{ {
if (ImGui::Checkbox("Enable VSync", &vsync)) {
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
}
if (ImGui::Button(ICON_FK_MAGIC "Theme Editor", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), 0))) { if (ImGui::Button(ICON_FK_MAGIC "Theme Editor", ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), 0))) {
theme_editor = true; theme_editor = true;
} }
@ -364,6 +373,7 @@ int main(int, char**)
if (ImGui::Selectable(themePath.stem().c_str(), is_selected)) { if (ImGui::Selectable(themePath.stem().c_str(), is_selected)) {
delete theme; delete theme;
theme = new Theme(themePath); theme = new Theme(themePath);
theme->Apply(accent_color);
break; break;
} }
if (is_selected) { if (is_selected) {
@ -380,8 +390,8 @@ int main(int, char**)
} }
if (theme_editor) { if (theme_editor) {
Theme::ShowEditor(&theme_editor, theme); Theme::ShowEditor(&theme_editor, theme);
}
theme->Apply(accent_color); theme->Apply(accent_color);
}
fileDialog.Display(); fileDialog.Display();
if (fileDialog.HasSelected()) { if (fileDialog.HasSelected()) {
@ -439,6 +449,7 @@ int main(int, char**)
} }
config["accent_color"] = accent_color; config["accent_color"] = accent_color;
config["demo_window"] = show_demo_window; config["demo_window"] = show_demo_window;
config["vsync"] = vsync;
stream << config; stream << config;
stream.close(); stream.close();
} }

View file

@ -6,6 +6,7 @@ cmake = import('cmake')
if get_option('debug') if get_option('debug')
add_global_arguments('-DDEBUG', language: 'cpp') add_global_arguments('-DDEBUG', language: 'cpp')
endif endif
add_global_arguments('-DIMGUI_IMPL_OPENGL_ES2', language: 'cpp')
smx_opts = cmake.subproject_options() smx_opts = cmake.subproject_options()
smx_opts.add_cmake_defines({'SDL_MIXER_X_STATIC': true, 'SDL_MIXER_X_SHARED': false}) smx_opts.add_cmake_defines({'SDL_MIXER_X_STATIC': true, 'SDL_MIXER_X_SHARED': false})
smx_opts.set_override_option('c_std', 'c99') smx_opts.set_override_option('c_std', 'c99')