satdump/src-ui/loading_screen.cpp

68 lines
2.2 KiB
C++
Raw Normal View History

2023-08-16 14:13:14 -04:00
#include "imgui/imgui.h"
#include "imgui/imgui_impl_glfw.h"
#include "imgui/imgui_impl_opengl3.h"
2023-11-06 11:39:38 -05:00
#ifndef IMGUI_IMPL_OPENGL_ES2
2023-11-06 09:17:59 -05:00
#include "imgui/imgui_impl_opengl2.h"
2023-11-06 11:39:38 -05:00
#endif
2023-08-16 14:13:14 -04:00
#include "loading_screen.h"
2023-08-17 21:05:15 -04:00
#include "loader/loader.h"
#include "core/style.h"
2023-08-16 14:13:14 -04:00
namespace satdump
{
2023-11-06 09:17:59 -05:00
LoadingScreenSink::LoadingScreenSink(GLFWwindow* window, float scale, GLFWimage* img, bool fallback_gl) : window{window},
scale{scale},
fallback_gl{fallback_gl}
2023-08-16 14:13:14 -04:00
{
macos_scale = style::macos_framebuffer_scale();
2023-08-16 14:13:14 -04:00
glGenTextures(1, &image_texture);
glBindTexture(GL_TEXTURE_2D, image_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->width, img->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
2023-08-17 21:05:15 -04:00
push_frame("Initializing");
2023-08-16 14:13:14 -04:00
}
LoadingScreenSink::~LoadingScreenSink()
{
}
void LoadingScreenSink::receive(slog::LogMsg log)
{
if (log.lvl == slog::LOG_INFO)
2023-08-17 21:05:15 -04:00
push_frame(log.str);
2023-08-16 14:13:14 -04:00
}
2023-08-17 21:05:15 -04:00
void LoadingScreenSink::push_frame(std::string str)
2023-08-16 14:13:14 -04:00
{
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
2023-11-06 11:39:38 -05:00
#ifndef IMGUI_IMPL_OPENGL_ES2
2023-11-06 09:17:59 -05:00
if(fallback_gl)
ImGui_ImplOpenGL2_NewFrame();
else
2023-11-06 11:39:38 -05:00
#endif
2023-11-06 09:17:59 -05:00
ImGui_ImplOpenGL3_NewFrame();
2023-08-16 14:13:14 -04:00
ImGui_ImplGlfw_NewFrame();
draw_loader(display_w / macos_scale, display_h / macos_scale, scale, &image_texture, str);
2023-08-16 14:13:14 -04:00
glViewport(0, 0, display_w, display_h);
glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
2023-11-06 11:39:38 -05:00
#ifndef IMGUI_IMPL_OPENGL_ES2
2023-11-06 09:17:59 -05:00
if(fallback_gl)
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
else
2023-11-06 11:39:38 -05:00
#endif
2023-11-06 09:17:59 -05:00
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
2023-08-16 14:13:14 -04:00
glfwSwapBuffers(window);
glfwPollEvents();
2023-08-16 14:13:14 -04:00
}
2023-08-16 15:00:06 -04:00
}