summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-13 14:29:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-13 14:29:23 +0200
commitd109fa83bd9678fc3c9e21da48e90aa069ec1c7f (patch)
tree69d893868806d90bbbd5bf2ea36603616fa2e70b
parent67897701316d83495aed4baa94e96c9f84b818f8 (diff)
a
-rw-r--r--draw/floor-mesh.cpp1
-rw-r--r--draw/wall-mesh.cpp1
-rw-r--r--draw/wireframe-mesh.cpp2
-rw-r--r--draw/wireframe-mesh.hpp1
-rw-r--r--main/app.cpp2
-rw-r--r--main/app.hpp2
-rw-r--r--main/debug.cpp2
-rw-r--r--main/editor.hpp15
-rw-r--r--main/menu.cpp80
9 files changed, 72 insertions, 34 deletions
diff --git a/draw/floor-mesh.cpp b/draw/floor-mesh.cpp
index da8fe7f2..4c23a391 100644
--- a/draw/floor-mesh.cpp
+++ b/draw/floor-mesh.cpp
@@ -32,6 +32,7 @@ void floor_mesh::set_tile(quad_data& data, tile& x)
void floor_mesh::draw(tile_shader& shader, chunk& c)
{
+ _vertex_buffer.setData({nullptr, sizeof(quad_data) * TILE_COUNT}, Magnum::GL::BufferUsage::DynamicDraw); // orphan the buffer
std::array<quad_data, TILE_COUNT> data;
for (auto& [x, idx, pt] : c) {
set_tile(data[idx], x);
diff --git a/draw/wall-mesh.cpp b/draw/wall-mesh.cpp
index acd4ac75..81201598 100644
--- a/draw/wall-mesh.cpp
+++ b/draw/wall-mesh.cpp
@@ -39,6 +39,7 @@ void wall_mesh::maybe_add_tile(vertex_array& data, texture_array& textures, tile
void wall_mesh::draw(tile_shader& shader, chunk& c)
{
+ _vertex_buffer.setData({nullptr, sizeof(vertex_array)}, Magnum::GL::BufferUsage::DynamicDraw); // orphan the buffer
texture_array textures = {};
{
vertex_array data;
diff --git a/draw/wireframe-mesh.cpp b/draw/wireframe-mesh.cpp
index 32aa72aa..0b6846d7 100644
--- a/draw/wireframe-mesh.cpp
+++ b/draw/wireframe-mesh.cpp
@@ -29,7 +29,7 @@ GL::RectangleTexture mesh_base::make_constant_texture()
mesh_base::mesh_base(GL::MeshPrimitive primitive, Containers::ArrayView<const void> index_data,
std::size_t num_vertices, std::size_t num_indexes) :
- _vertex_buffer{Containers::Array<Vector3>{ValueInit, num_vertices}},
+ _vertex_buffer{Containers::Array<Vector3>{ValueInit, num_vertices}, GL::BufferUsage::DynamicDraw},
_texcoords_buffer{Containers::Array<Vector2>{ValueInit, num_vertices}},
_index_buffer{num_indexes == 0 ? GL::Buffer{NoCreate} : GL::Buffer{index_data}}
{
diff --git a/draw/wireframe-mesh.hpp b/draw/wireframe-mesh.hpp
index 3c0deb37..6c1a7d3f 100644
--- a/draw/wireframe-mesh.hpp
+++ b/draw/wireframe-mesh.hpp
@@ -55,6 +55,7 @@ wireframe_mesh<T>::wireframe_mesh() :
template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
{
+ _vertex_buffer.setData({nullptr, sizeof(Vector3) * T::num_vertices}, GL::BufferUsage::DynamicDraw); // orphan the buffer
_vertex_buffer.setSubData(0, x.make_vertex_array());
x.on_draw();
mesh_base::draw(shader);
diff --git a/main/app.cpp b/main/app.cpp
index ffebcc35..0c29abf1 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -23,7 +23,7 @@ app::app(const Arguments& arguments):
reset_camera_offset();
update_window_scale(windowSize());
setMinimalLoopPeriod(5);
- _imgui = ImGuiIntegration::Context(Vector2{windowSize()}/dpiScaling(), windowSize(), framebufferSize());
+ _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize());
setup_menu();
timeline.start();
}
diff --git a/main/app.hpp b/main/app.hpp
index 3efc390f..389dbef3 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -9,6 +9,7 @@
#include "draw/wireframe-quad.hpp"
#include "draw/wireframe-box.hpp"
#include "compat/enum-bitset.hpp"
+#include "editor.hpp"
#include <Magnum/Timeline.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/GL/DebugOutput.h>
@@ -74,6 +75,7 @@ struct app final : Platform::Application
Vector2 camera_offset;
enum_bitset<key> keys;
Magnum::Timeline timeline;
+ editor_mode _editor_mode = editor_mode{};
};
} // namespace floormat
diff --git a/main/debug.cpp b/main/debug.cpp
index ebf3c124..24deb775 100644
--- a/main/debug.cpp
+++ b/main/debug.cpp
@@ -71,7 +71,7 @@ void* app::register_debug_callback()
GL::DebugOutput::setCallback(_debug_callback, this);
GL::DebugOutput::setEnabled(true);
-#if 0
+#if 1
/* Disable rather spammy "Buffer detailed info" debug messages on NVidia drivers */
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
#endif
diff --git a/main/editor.hpp b/main/editor.hpp
new file mode 100644
index 00000000..af3934eb
--- /dev/null
+++ b/main/editor.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+namespace floormat {
+
+enum class editor_mode : unsigned char {
+ select, floors, walls,
+};
+
+struct editor_state final
+{
+ editor_mode mode = {};
+ bool dirty = false;
+};
+
+} // namespace floormat
diff --git a/main/menu.cpp b/main/menu.cpp
index 92f1b980..4762198f 100644
--- a/main/menu.cpp
+++ b/main/menu.cpp
@@ -4,29 +4,47 @@
namespace floormat {
-template<typename F>
+constexpr inline auto noop = []{};
+
struct raii_wrapper final
{
- raii_wrapper(F&& fn) : dtor{fn} {}
- [[no_unique_address]] F dtor;
+ using F = void(*)(void);
+ raii_wrapper(bool ok = false, F fn = noop) : dtor{fn}, ok{ok} {}
inline ~raii_wrapper() { dtor(); }
- raii_wrapper(const raii_wrapper<F>&) = delete;
- raii_wrapper<F>& operator=(const raii_wrapper<F>&) = delete;
+ raii_wrapper(const raii_wrapper&) = delete;
+ raii_wrapper& operator=(const raii_wrapper&) = delete;
+ raii_wrapper(raii_wrapper&& other) noexcept : dtor{other.dtor}, ok{other.ok} { other.dtor = noop; }
+ inline operator bool() const noexcept { return ok; }
+
+ [[no_unique_address]] F dtor;
+ const bool ok;
};
constexpr inline const auto* imgui_name = "floormat editor";
-[[nodiscard]] static auto gui_begin() {
- ImGui::Begin(imgui_name, nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_NoMove);
- return raii_wrapper{[]{ ImGui::End(); }};
+#if 0
+[[nodiscard]] static raii_wrapper gui_begin() {
+ using f = ImGuiWindowFlags_;
+ int flags = 0;
+ //flags |= ImGuiWindowFlags_AlwaysAutoResize;
+ flags |= f::ImGuiWindowFlags_NoDecoration;
+ if (ImGui::Begin(imgui_name, nullptr, flags))
+ return {true, []{ ImGui::End(); }};
+ else
+ return {};
}
-[[nodiscard]] static auto begin_main_menu() {
- ImGui::BeginMainMenuBar();
- return raii_wrapper{[] { ImGui::EndMainMenuBar(); }};
+#endif
+[[nodiscard]] static raii_wrapper begin_main_menu() {
+ if (ImGui::BeginMainMenuBar())
+ return raii_wrapper{true, [] { ImGui::EndMainMenuBar(); }};
+ else
+ return {};
}
-[[nodiscard]] static auto begin_menu(const char* name, bool enabled = true) {
- ImGui::BeginMenu(name, enabled);
- return raii_wrapper{[] { ImGui::EndMenu(); }};
+[[nodiscard]] static raii_wrapper begin_menu(const char* name, bool enabled = true) {
+ if (ImGui::BeginMenu(name, enabled))
+ return raii_wrapper{true, [] { ImGui::EndMenu(); }};
+ else
+ return {};
}
void app::setup_menu()
@@ -54,29 +72,29 @@ void app::draw_menu()
else if (!ImGui::GetIO().WantTextInput && isTextInputActive())
stopTextInput();
- auto b = gui_begin();
draw_menu_bar();
}
void app::draw_menu_bar()
{
- auto bm = begin_main_menu();
- {
- auto m = begin_menu("File");
- ImGui::MenuItem("Open");
- ImGui::MenuItem("Recent");
- ImGui::Separator();
- ImGui::MenuItem("Save");
- ImGui::MenuItem("Save as...");
- ImGui::Separator();
- ImGui::MenuItem("Close");
- }
+ if (auto b = begin_main_menu())
{
- auto m = begin_menu("Mode");
- ImGui::MenuItem("Select", "F1");
- ImGui::MenuItem("Floors", "F2");
- ImGui::MenuItem("Walls", "F3");
- ImGui::MenuItem("Floors", "F4");
+ if (auto b = begin_menu("File"))
+ {
+ ImGui::MenuItem("Open", "Ctrl+O");
+ ImGui::MenuItem("Recent");
+ ImGui::Separator();
+ ImGui::MenuItem("Save", "Ctrl+S");
+ ImGui::MenuItem("Save as...", "Ctrl+Shift+S");
+ ImGui::Separator();
+ ImGui::MenuItem("Close");
+ }
+ if (auto b = begin_menu("Mode"))
+ {
+ ImGui::MenuItem("Select", "F1", _editor_mode == editor_mode::select);
+ ImGui::MenuItem("Floors", "F2", _editor_mode == editor_mode::floors);
+ ImGui::MenuItem("Walls", "F3", _editor_mode == editor_mode::walls);
+ }
}
}