[turbine] Make window render during resizing

This commit is contained in:
Gary Talent 2023-07-16 14:16:52 -05:00
parent f514b33b06
commit 22f8504e5a
3 changed files with 27 additions and 22 deletions

@ -59,11 +59,11 @@ class Context {
Context() noexcept = default;
public:
Context(Context &other) noexcept = delete;
Context(const Context &other) noexcept = delete;
Context(const Context &&other) noexcept = delete;
public:
virtual inline ~Context() noexcept {
shutdown(*this);
}

@ -34,8 +34,6 @@ void removeDrawer(Context &ctx, Drawer *cd) noexcept {
}
constexpr auto Scale = 5;
static void handleGlfwError(int err, const char *desc) noexcept {
oxErrf("GLFW error ({}): {}\n", err, desc);
}
@ -93,9 +91,6 @@ static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexce
ctx->uninterruptedRefreshes = 25;
}
static void handleGlfwWindowResize(GLFWwindow*, int, int) noexcept {
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
const auto ctx = static_cast<GlfwContext*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
@ -216,13 +211,13 @@ ox::Error initGfx(Context &ctx) noexcept {
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
auto cstr = ox_malloca(ctx.keelCtx.appName.bytes() + 1, char);
ox_strncpy(cstr.get(), ctx.keelCtx.appName.data(), ctx.keelCtx.appName.bytes());
constexpr auto Scale = 5;
gctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr);
if (gctx.window == nullptr) {
return OxError(1, "Could not open GLFW window");
}
glfwSetCursorPosCallback(gctx.window, handleGlfwCursorPosEvent);
glfwSetMouseButtonCallback(gctx.window, handleGlfwMouseButtonEvent);
glfwSetWindowSizeCallback(gctx.window, handleGlfwWindowResize);
glfwSetKeyCallback(gctx.window, handleGlfwKeyEvent);
glfwSetWindowUserPointer(gctx.window, &ctx);
glfwMakeContextCurrent(gctx.window);

@ -14,6 +14,29 @@
namespace turbine {
static void draw(GlfwContext &gctx) noexcept {
// draw start
if constexpr(turbine::config::ImGuiEnabled) {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
for (auto d : gctx.drawers) {
d->draw(gctx);
}
if constexpr(turbine::config::ImGuiEnabled) {
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// draw end
glfwSwapBuffers(gctx.window);
}
static void draw(GLFWwindow *window, int, int) noexcept {
auto &gctx = *static_cast<GlfwContext*>(glfwGetWindowUserPointer(window));
draw(gctx);
}
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
auto ctx = ox::make_unique<GlfwContext>();
oxReturnError(keel::init(&ctx->keelCtx, std::move(fs), appName));
@ -21,6 +44,7 @@ ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> fs, ox::CRStringView
ctx->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
glfwInit();
oxReturnError(initGfx(*ctx));
glfwSetWindowSizeCallback(ctx->window, draw);
return ox::UPtr<Context>(ctx.release());
}
@ -55,21 +79,7 @@ ox::Error run(Context &ctx) noexcept {
sleepTime = 10;
}
tickFps(gctx, ticks);
// draw start
if constexpr(turbine::config::ImGuiEnabled) {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}
for (auto d : gctx.drawers) {
d->draw(gctx);
}
if constexpr(turbine::config::ImGuiEnabled) {
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// draw end
glfwSwapBuffers(gctx.window);
draw(gctx);
if (!gctx.constantRefresh) {
if (gctx.uninterruptedRefreshes) {
--gctx.uninterruptedRefreshes;