[turbine] Make window render during resizing
This commit is contained in:
parent
f514b33b06
commit
22f8504e5a
@ -59,11 +59,11 @@ class Context {
|
|||||||
|
|
||||||
Context() noexcept = default;
|
Context() noexcept = default;
|
||||||
|
|
||||||
|
public:
|
||||||
Context(Context &other) noexcept = delete;
|
Context(Context &other) noexcept = delete;
|
||||||
Context(const Context &other) noexcept = delete;
|
Context(const Context &other) noexcept = delete;
|
||||||
Context(const Context &&other) noexcept = delete;
|
Context(const Context &&other) noexcept = delete;
|
||||||
|
|
||||||
public:
|
|
||||||
virtual inline ~Context() noexcept {
|
virtual inline ~Context() noexcept {
|
||||||
shutdown(*this);
|
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 {
|
static void handleGlfwError(int err, const char *desc) noexcept {
|
||||||
oxErrf("GLFW error ({}): {}\n", err, desc);
|
oxErrf("GLFW error ({}): {}\n", err, desc);
|
||||||
}
|
}
|
||||||
@ -93,9 +91,6 @@ static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexce
|
|||||||
ctx->uninterruptedRefreshes = 25;
|
ctx->uninterruptedRefreshes = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleGlfwWindowResize(GLFWwindow*, int, int) noexcept {
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
|
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
|
||||||
const auto ctx = static_cast<GlfwContext*>(glfwGetWindowUserPointer(window));
|
const auto ctx = static_cast<GlfwContext*>(glfwGetWindowUserPointer(window));
|
||||||
ctx->uninterruptedRefreshes = 25;
|
ctx->uninterruptedRefreshes = 25;
|
||||||
@ -216,13 +211,13 @@ ox::Error initGfx(Context &ctx) noexcept {
|
|||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||||
auto cstr = ox_malloca(ctx.keelCtx.appName.bytes() + 1, char);
|
auto cstr = ox_malloca(ctx.keelCtx.appName.bytes() + 1, char);
|
||||||
ox_strncpy(cstr.get(), ctx.keelCtx.appName.data(), ctx.keelCtx.appName.bytes());
|
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);
|
gctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr);
|
||||||
if (gctx.window == nullptr) {
|
if (gctx.window == nullptr) {
|
||||||
return OxError(1, "Could not open GLFW window");
|
return OxError(1, "Could not open GLFW window");
|
||||||
}
|
}
|
||||||
glfwSetCursorPosCallback(gctx.window, handleGlfwCursorPosEvent);
|
glfwSetCursorPosCallback(gctx.window, handleGlfwCursorPosEvent);
|
||||||
glfwSetMouseButtonCallback(gctx.window, handleGlfwMouseButtonEvent);
|
glfwSetMouseButtonCallback(gctx.window, handleGlfwMouseButtonEvent);
|
||||||
glfwSetWindowSizeCallback(gctx.window, handleGlfwWindowResize);
|
|
||||||
glfwSetKeyCallback(gctx.window, handleGlfwKeyEvent);
|
glfwSetKeyCallback(gctx.window, handleGlfwKeyEvent);
|
||||||
glfwSetWindowUserPointer(gctx.window, &ctx);
|
glfwSetWindowUserPointer(gctx.window, &ctx);
|
||||||
glfwMakeContextCurrent(gctx.window);
|
glfwMakeContextCurrent(gctx.window);
|
||||||
|
@ -14,6 +14,29 @@
|
|||||||
|
|
||||||
namespace turbine {
|
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 {
|
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
|
||||||
auto ctx = ox::make_unique<GlfwContext>();
|
auto ctx = ox::make_unique<GlfwContext>();
|
||||||
oxReturnError(keel::init(&ctx->keelCtx, std::move(fs), appName));
|
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();
|
ctx->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||||
glfwInit();
|
glfwInit();
|
||||||
oxReturnError(initGfx(*ctx));
|
oxReturnError(initGfx(*ctx));
|
||||||
|
glfwSetWindowSizeCallback(ctx->window, draw);
|
||||||
return ox::UPtr<Context>(ctx.release());
|
return ox::UPtr<Context>(ctx.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,21 +79,7 @@ ox::Error run(Context &ctx) noexcept {
|
|||||||
sleepTime = 10;
|
sleepTime = 10;
|
||||||
}
|
}
|
||||||
tickFps(gctx, ticks);
|
tickFps(gctx, ticks);
|
||||||
// draw start
|
draw(gctx);
|
||||||
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);
|
|
||||||
if (!gctx.constantRefresh) {
|
if (!gctx.constantRefresh) {
|
||||||
if (gctx.uninterruptedRefreshes) {
|
if (gctx.uninterruptedRefreshes) {
|
||||||
--gctx.uninterruptedRefreshes;
|
--gctx.uninterruptedRefreshes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user