From acdace16824b741948b02da0bcc7d0d059c7f683 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 9 Oct 2022 03:11:56 +0200 Subject: a --- main/debug.cpp | 14 ++++++++------ main/main.cpp | 7 ++++++- src/wireframe-mesh.cpp | 35 +++++++++++++---------------------- src/wireframe-mesh.hpp | 19 ++++++------------- 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/main/debug.cpp b/main/debug.cpp index c7eeaebf..d312bd5f 100644 --- a/main/debug.cpp +++ b/main/debug.cpp @@ -15,7 +15,7 @@ using GL::DebugOutput; void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id, Severity severity, Containers::StringView str) const { - static thread_local Magnum::Timeline t{}; + static thread_local auto t = progn(auto t = Magnum::Timeline{}; t.start(); return t; ); [[maybe_unused]] volatile auto _type = type; [[maybe_unused]] volatile auto _id = id; @@ -27,14 +27,16 @@ void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type if (!std::strncmp(str.data(), prefix.data(), prefix.size()-1)) str = str.exceptPrefix(prefix.size()-1); + printf("%12.2f ", (double)t.previousFrameTime() * 1000); + switch (severity) { using enum GL::DebugOutput::Severity; - case Notification: std::fputs("[DEBUG] ", stdout); break; - case Low: std::fputs("[INFO ] ", stdout); break; - case Medium: std::fputs("[NOTICE] ", stdout); break; - case High: std::fputs("[ERROR] ", stdout); break; - default: std::fputs("[?????] ", stdout); break; + case Notification: std::fputs("DEBUG ", stdout); break; + case Low: std::fputs("INFO ", stdout); break; + case Medium: std::fputs("NOTICE ", stdout); break; + case High: std::fputs("ERROR ", stdout); break; + default: std::fputs("????? ", stdout); break; } std::puts(str.data()); diff --git a/main/main.cpp b/main/main.cpp index 2696dc79..523d16c0 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,4 +1,6 @@ #include "app.hpp" +#include "tile-defs.hpp" +#include #include #include #include @@ -54,8 +56,11 @@ void app::draw_chunk(chunk& c) void app::draw_wireframe() { + constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1]; + constexpr float N = TILE_MAX_DIM/2.f; + const Vector3 center {(float)(X*N), (float)(Y*N), 0}; _shader.set_tint({1.f, 1.f, 0, 1.f}); - _wireframe_quad.draw(_shader, {{10, 10, 0}, {TILE_SIZE[0], TILE_SIZE[1]}}); + _wireframe_quad.draw(_shader, {center, {TILE_SIZE[0], TILE_SIZE[1]}}); _shader.set_tint({1, 1, 1, 1}); } diff --git a/src/wireframe-mesh.cpp b/src/wireframe-mesh.cpp index 1332c682..e03723bf 100644 --- a/src/wireframe-mesh.cpp +++ b/src/wireframe-mesh.cpp @@ -1,6 +1,7 @@ #include "wireframe-mesh.hpp" #include "shaders/tile-shader.hpp" #include "tile-atlas.hpp" +#include "compat/assert.hpp" #include #include #include @@ -31,23 +32,13 @@ GL::RectangleTexture wireframe::null::make_constant_texture() quad::vertex_array quad::make_vertex_array() const { -#if 0 - constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1]; - constexpr float Z = 0; + constexpr auto X = TILE_SIZE[0]*.5f, Y = TILE_SIZE[1]*.5f; return {{ - { -X + center[0], -Y + center[1], Z + center[2] }, - { X + center[0], -Y + center[1], Z + center[2] }, - { X + center[0], Y + center[1], Z + center[2] }, - { -X + center[0], Y + center[1], Z + center[2] }, + { -X + center[0], -Y + center[1], center[2] }, + { X + center[0], -Y + center[1], center[2] }, + { X + center[0], Y + center[1], center[2] }, + { -X + center[0], Y + center[1], center[2] }, }}; -#else - return tile_atlas::floor_quad(center, {TILE_SIZE[0], TILE_SIZE[1]}); -#endif -} - -quad::index_array quad::make_index_array() -{ - return tile_atlas::indices(0); } quad::quad(Vector3 center, Vector2 size) : center(center), size(size) {} @@ -58,17 +49,17 @@ namespace Magnum::Examples { template wireframe_mesh::wireframe_mesh() { - _mesh.setCount((int)T::num_indexes) - .addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{}) - .addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{}) - .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); + _mesh.setCount((int)T::num_vertices) + .setPrimitive(T::primitive) + .addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{}) + .addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{}); } template void wireframe_mesh::draw(tile_shader& shader, T x) { - GL::Renderer::setLineWidth(2); - _vertex_buffer.setSubData(0, x.make_vertex_array()); - _index_buffer.setSubData(0, x.make_index_array()); + GL::Renderer::setLineWidth(3); + auto array = x.make_vertex_array(); + _vertex_buffer.setSubData(0, array); _texture.bind(0); shader.draw(_mesh); } diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp index 2a7cf10c..26dfb9ec 100644 --- a/src/wireframe-mesh.hpp +++ b/src/wireframe-mesh.hpp @@ -19,38 +19,32 @@ namespace wireframe template concept traits = requires (const T& x) { {T::num_vertices} -> std::convertible_to; - {T::num_indexes} -> std::convertible_to; {x.primitive} -> std::convertible_to; {x.make_vertex_array() } -> std::same_as>; - {x.make_index_array() } -> std::same_as>; }; struct null final { static constexpr auto primitive = GL::MeshPrimitive::Triangles; - static constexpr std::size_t num_vertices = 0, num_indexes = 0; + static constexpr std::size_t num_vertices = 0; static GL::RectangleTexture make_constant_texture(); static std::array make_vertex_array() { return {}; } - static std::array make_index_array() { return {}; } }; struct quad final { quad(Vector3 center, Vector2 size); - constexpr quad() = default; - static constexpr std::size_t num_vertices = 4, num_indexes = 6; - static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::Triangles; + static constexpr std::size_t num_vertices = 4; + static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; - using index_array = std::array; vertex_array make_vertex_array() const; - static index_array make_index_array() ; private: - Vector3 center = {}; - Vector2 size = { TILE_SIZE[0], TILE_SIZE[1] }; + Vector3 center; + Vector2 size; }; } // namespace wireframe @@ -63,8 +57,7 @@ struct wireframe_mesh final private: GL::Buffer _vertex_buffer{std::array{}, GL::BufferUsage::DynamicDraw}, - _texcoords_buffer{std::array{}, GL::BufferUsage::DynamicDraw}, - _index_buffer{std::array{}, GL::BufferUsage::DynamicDraw}; + _texcoords_buffer{std::array{}, GL::BufferUsage::DynamicDraw}; GL::RectangleTexture _texture = wireframe::null::make_constant_texture(); GL::Mesh _mesh; }; -- cgit v1.2.3