summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-08 23:41:39 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-08 23:41:39 +0200
commit07d8adea58ec5b6b51704be1caf84012b0049313 (patch)
treed7f7571c766d0241b2e598a284ff5d396d9f66dc
parentdcac3d7bd83c0cbdddae433e98598289bb1b06cd (diff)
a
-rw-r--r--main/app.hpp6
-rw-r--r--main/debug.cpp35
-rw-r--r--main/main.cpp8
-rw-r--r--src/tile-atlas.cpp2
-rw-r--r--src/wireframe-mesh.cpp12
-rw-r--r--src/wireframe-mesh.hpp3
6 files changed, 59 insertions, 7 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)
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index 917c60bc..95e01bfa 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -17,7 +17,7 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve
tex_.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Linear)
- .setMaxAnisotropy(0)
+ .setMaxAnisotropy(1)
.setStorage(GL::textureFormat(image.format()), image.size())
.setSubImage({}, image);
}
diff --git a/src/wireframe-mesh.cpp b/src/wireframe-mesh.cpp
index 8d5d259f..03378c02 100644
--- a/src/wireframe-mesh.cpp
+++ b/src/wireframe-mesh.cpp
@@ -5,21 +5,23 @@
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/PixelFormat.h>
+#include <Magnum/PixelStorage.h>
#include <Magnum/Trade/ImageData.h>
+#include <Magnum/ImageFlags.h>
namespace Magnum::Examples::wireframe
{
GL::RectangleTexture wireframe::null::make_constant_texture()
{
- Trade::ImageData2D img{PixelFormat::RGBA8UI, {1, 1}, // NOLINT(misc-const-correctness)
+ Trade::ImageData2D img{PixelStorage{}.setImageHeight(1).setRowLength(1),
+ PixelFormat::RGBA8UI, {1, 1},
Containers::Array<char>{Corrade::DirectInit, 4, (char)(unsigned char)255}};
-
GL::RectangleTexture tex;
tex.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
.setMinificationFilter(GL::SamplerFilter::Nearest)
- .setMaxAnisotropy(0)
+ .setMaxAnisotropy(1)
.setStorage(GL::textureFormat(img.format()), img.size())
.setSubImage({}, std::move(img));
return tex;
@@ -29,12 +31,13 @@ quad::vertex_array quad::make_vertex_array() const
{
constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1];
constexpr float Z = 0;
- return {{
+ vertex_array ret = {{
{ -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] },
}};
+ return ret;
}
quad::quad(Vector3 center, Vector2 size) : center(center), size(size) {}
@@ -46,6 +49,7 @@ namespace Magnum::Examples {
template <wireframe::traits T> wireframe_mesh<T>::wireframe_mesh()
{
_mesh.setCount((int)T::num_vertices)
+ .setPrimitive(T::primitive)
.addVertexBuffer(_texcoords_buffer, 0, tile_shader::TextureCoordinates{})
.addVertexBuffer(_vertex_buffer, 0, tile_shader::Position{});
CORRADE_INTERNAL_ASSERT(!_mesh.isIndexed());
diff --git a/src/wireframe-mesh.hpp b/src/wireframe-mesh.hpp
index 855e673a..7a6892c2 100644
--- a/src/wireframe-mesh.hpp
+++ b/src/wireframe-mesh.hpp
@@ -24,7 +24,6 @@ concept traits = requires (const T& x) {
{x.make_vertex_array() } -> std::same_as<std::array<Vector3, T::num_vertices>>;
};
-
struct null final
{
static constexpr auto primitive = GL::MeshPrimitive::Triangles;
@@ -58,7 +57,7 @@ struct wireframe_mesh final
void draw(tile_shader& shader, T traits);
private:
- GL::Buffer _vertex_buffer{}, _texcoords_buffer{std::array<Vector2, T::num_vertices>{}};
+ GL::Buffer _vertex_buffer{std::array<Vector3, T::num_vertices>{}}, _texcoords_buffer{std::array<Vector2, T::num_vertices>{}};
GL::RectangleTexture _texture = wireframe::null::make_constant_texture();
GL::Mesh _mesh;
};