summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-04-08 21:56:15 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-04-08 21:56:58 +0200
commit12d26cd1cb550eb79f48534bf0d26d1ffb63f0fe (patch)
treef49ebe79e3e484e8c64774b0c39a5801bbfaddfb
parent53940c48b32cfe045bdd26df33788cc480b39d90 (diff)
first_frame wip
-rw-r--r--floormat/main.hpp1
-rw-r--r--main/ctor.cpp1
-rw-r--r--main/draw.cpp40
-rw-r--r--main/main-impl.hpp6
4 files changed, 38 insertions, 10 deletions
diff --git a/floormat/main.hpp b/floormat/main.hpp
index 8239a05a..59039152 100644
--- a/floormat/main.hpp
+++ b/floormat/main.hpp
@@ -98,6 +98,7 @@ protected:
Vector2 _dpi_scale{ 1, 1 }, _virtual_scale{ 1, 1 };
Vector2i _framebuffer_size;
bool _do_render_vobjs : 1 = true;
+ bool _first_frame : 1 = true;
};
} // namespace floormat
diff --git a/main/ctor.cpp b/main/ctor.cpp
index 402e7db0..35968535 100644
--- a/main/ctor.cpp
+++ b/main/ctor.cpp
@@ -30,6 +30,7 @@ class world& main_impl::reset_world(class world&& w) noexcept
{
arrayResize(_clickable_scenery, 0);
_world = move(w);
+ _first_frame = true;
return _world;
}
diff --git a/main/draw.cpp b/main/draw.cpp
index 42cf4082..e5fb9e69 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -16,15 +16,14 @@ namespace floormat {
namespace {
size_t bad_frame_counter = 0; // NOLINT
+constexpr auto clear_color = 0x222222ff_rgbaf;
} // namespace
-
-void main_impl::do_update()
+void main_impl::do_update(const Ns& dtʹ)
{
constexpr auto eps = 1e-5f;
constexpr auto max_dt = Milliseconds*100;
- const auto dtʹ = timeline.update();
const auto dt = dtʹ > max_dt ? max_dt : dtʹ;
if (float secs{Time::to_seconds(dt)}; secs > eps)
{
@@ -45,22 +44,47 @@ void main_impl::do_update()
app.update(dt);
}
-void main_impl::drawEvent()
+void main_impl::clear_framebuffer()
{
- _shader.set_tint({1, 1, 1, 1});
-
- constexpr auto clear_color = 0x222222ff_rgbaf;
#ifdef FM_USE_DEPTH32
framebuffer.fb.clearColor(0, clear_color);
#else
GL::defaultFramebuffer.clearColor(clear_color);
#endif
+}
+
+void main_impl::cache_draw_on_startup()
+{
+ _shader.set_tint({1, 1, 1, 1});
+ clear_framebuffer();
+ for (int i = 0; i < 3; i++)
+ {
+ do_update(Ns{1});
+ draw_world();
+ }
+ clear_framebuffer();
+ (void)timeline.update();
+ swapBuffers();
+ redraw();
+}
+
+void main_impl::drawEvent()
+{
+ if (_first_frame) [[unlikely]]
+ {
+ _first_frame = false;
+ cache_draw_on_startup();
+ }
+
+ _shader.set_tint({1, 1, 1, 1});
+
+ clear_framebuffer();
draw_world();
app.draw();
GL::Renderer::flush();
- do_update();
+ do_update(timeline.update());
#ifdef FM_USE_DEPTH32
GL::Framebuffer::blit(framebuffer.fb, GL::defaultFramebuffer, framebuffer.fb.viewport(), GL::FramebufferBlit::Color);
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index 66f143d1..9d3eef43 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -85,10 +85,12 @@ struct main_impl final : Platform::Sdl2Application, floormat_main
[[maybe_unused]] void keyPressEvent(KeyEvent& event) override;
[[maybe_unused]] void keyReleaseEvent(KeyEvent& event) override;
[[maybe_unused]] void anyEvent(SDL_Event& event) override;
-
+
+ void cache_draw_on_startup();
+ void clear_framebuffer();
void drawEvent() override;
void bind() noexcept override;
- void do_update();
+ void do_update(const Ns& dt);
struct meshes meshes() noexcept override;
bool is_text_input_active() const noexcept override;