diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-08 23:41:39 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-08 23:41:39 +0200 |
commit | 07d8adea58ec5b6b51704be1caf84012b0049313 (patch) | |
tree | d7f7571c766d0241b2e598a284ff5d396d9f66dc /main | |
parent | dcac3d7bd83c0cbdddae433e98598289bb1b06cd (diff) |
a
Diffstat (limited to 'main')
-rw-r--r-- | main/app.hpp | 6 | ||||
-rw-r--r-- | main/debug.cpp | 35 | ||||
-rw-r--r-- | main/main.cpp | 8 |
3 files changed, 49 insertions, 0 deletions
diff --git a/main/app.hpp b/main/app.hpp index c1b45af9..6f7e518c 100644 --- a/main/app.hpp +++ b/main/app.hpp @@ -9,6 +9,7 @@ #include "compat/enum-bitset.hpp" #include <Magnum/Timeline.h> #include <Magnum/Platform/Sdl2Application.h> +#include <Magnum/GL/DebugOutput.h> #include <memory> namespace Magnum::Examples { @@ -28,8 +29,12 @@ struct app final : Platform::Application void keyReleaseEvent(KeyEvent& event) override; void do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated); void draw_chunk(chunk& c); + void draw_wireframe(); void update_window_scale(Vector2i window_size); void viewportEvent(ViewportEvent& event) override; + void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, + GL::DebugOutput::Severity severity, const std::string& str) const; + void register_debug_callback(); enum class key : int { camera_up, camera_left, camera_right, camera_down, camera_reset, @@ -38,6 +43,7 @@ struct app final : Platform::Application }; chunk make_test_chunk(); + const void* const _dummy = (register_debug_callback(), nullptr); tile_shader _shader; tile_atlas_ floor1 = loader.tile_atlas("share/game/images/metal1.tga", {2, 2}); tile_atlas_ floor2 = loader.tile_atlas("share/game/images/floor1.tga", {4, 4}); diff --git a/main/debug.cpp b/main/debug.cpp new file mode 100644 index 00000000..7e7e3abf --- /dev/null +++ b/main/debug.cpp @@ -0,0 +1,35 @@ +#include "app.hpp" +#include <Magnum/GL/Renderer.h> + +namespace Magnum::Examples { + +using Feature = GL::Renderer::Feature; +using Severity = GL::DebugOutput::Severity; +using Type = GL::DebugOutput::Type; +using GL::Renderer; +using GL::DebugOutput; + +void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, + GL::DebugOutput::Severity severity, const std::string& str) const +{ + std::fputs(str.c_str(), stdout); + std::fputc('\n', stdout); + std::fflush(stdout); + std::puts(""); // put breakpoint here +} + +static void _debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, + GL::DebugOutput::Severity severity, const std::string& str, const void* self) +{ + static_cast<const app*>(self)->debug_callback(src, type, id, severity, str); +} + +void app::register_debug_callback() +{ + GL::Renderer::setFeature(Feature::DebugOutput, true); + GL::Renderer::setFeature(Feature::DebugOutputSynchronous, true); + GL::DebugOutput::setCallback(_debug_callback, this); + GL::DebugOutput::setEnabled(Severity::High, true); +} + +} // namespace Magnum::Examples diff --git a/main/main.cpp b/main/main.cpp index 2545865f..04ede3a9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -39,6 +39,7 @@ void app::drawEvent() { } draw_chunk(_chunk); + draw_wireframe(); swapBuffers(); redraw(); @@ -47,10 +48,17 @@ void app::drawEvent() { void app::draw_chunk(chunk& c) { + _shader.set_tint({1, 1, 1, 1}); _floor_mesh.draw(_shader, c); _wall_mesh.draw(_shader, c); } +void app::draw_wireframe() +{ + _shader.set_tint({1.f, 0, 0, 1.f}); + _wireframe_quad.draw(_shader, {{}, {TILE_SIZE[0], TILE_SIZE[1]}}); +} + } // namespace Magnum::Examples MAGNUM_APPLICATION_MAIN(Magnum::Examples::app) |