summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--draw/anim.cpp10
-rw-r--r--draw/anim.hpp2
-rw-r--r--main/draw.cpp37
-rw-r--r--main/main-impl.hpp20
-rw-r--r--scenery/door-close.json1
-rw-r--r--src/character.cpp6
-rw-r--r--src/scenery.cpp19
7 files changed, 81 insertions, 14 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index 0d1f2827..119bd6c6 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -96,10 +96,11 @@ void anim_mesh::draw(tile_shader& shader, const Vector2i& win_size, chunk& c, st
}
if (e.is_dynamic())
{
- const auto depth = e.depth_offset();
- const auto depth1 = depth[1]*TILE_MAX_DIM + depth[0];
+ const auto depth0 = e.depth_offset();
+ const auto depth1 = depth0[1]*TILE_MAX_DIM + depth0[0];
+ const auto depth = tile_shader::depth_value(e.coord.local(), depth1);
//Debug{} << "draw-dyn" << e.atlas->name() << e.ordinal() << Vector2i(e.coord.local());
- draw(shader, atlas, e.r, e.frame, e.coord.local(), e.offset, depth1 + tile_shader::scenery_depth_offset);
+ draw(shader, atlas, e.r, e.frame, e.coord.local(), e.offset, depth);
last = nullptr;
}
else
@@ -137,10 +138,9 @@ void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t
shader.draw(_mesh);
}
-void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth_offset)
+void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth)
{
const auto pos = Vector3(xy) * TILE_SIZE + Vector3(Vector2(offset), 0);
- const float depth = tile_shader::depth_value(xy, depth_offset);
draw(shader, atlas, r, frame, pos, depth);
}
diff --git a/draw/anim.hpp b/draw/anim.hpp
index 96c1de7e..eaa191f5 100644
--- a/draw/anim.hpp
+++ b/draw/anim.hpp
@@ -28,7 +28,7 @@ struct anim_mesh final
void draw(tile_shader& shader, const Vector2i& win_size, chunk& c, std::vector<clickable>& list);
void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, const Vector3& pos, float depth);
- void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth_offset);
+ void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float dpeth);
static void add_clickable(tile_shader& shader, const Vector2i& win_size,
entity* s_, const chunk::topo_sort_data& data,
std::vector<clickable>& list);
diff --git a/main/draw.cpp b/main/draw.cpp
index f87f2e9c..521cad30 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -8,6 +8,8 @@
#include <Corrade/Containers/ArrayView.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Renderer.h>
+#include <Magnum/GL/RenderbufferFormat.h>
+#include <Magnum/GL/TextureFormat.h>
#include <Magnum/Math/Color.h>
#include <algorithm>
#include <thread>
@@ -20,6 +22,27 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept
_virtual_scale = Vector2(fb_size) / Vector2(win_size);
update_window_state();
_shader.set_scale(Vector2{fb_size});
+
+ GL::defaultFramebuffer.bind();
+
+#ifdef FM_USE_DEPTH32
+ {
+ framebuffer.fb = GL::Framebuffer{{ {}, fb_size }};
+
+ framebuffer.color = GL::Texture2D{};
+ framebuffer.color.setStorage(1, GL::TextureFormat::RGBA8, fb_size);
+ framebuffer.depth = GL::Renderbuffer{};
+ framebuffer.depth.setStorage(GL::RenderbufferFormat::DepthComponent32F, fb_size);
+
+ framebuffer.fb.attachTexture(GL::Framebuffer::ColorAttachment{0}, framebuffer.color, 0);
+ framebuffer.fb.attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, framebuffer.depth);
+ framebuffer.fb.clearColor(0, Color4{0.f, 0.f, 0.f, 1.f});
+ framebuffer.fb.clearDepth(0);
+
+ framebuffer.fb.bind();
+ }
+#endif
+
GL::defaultFramebuffer.setViewport({{}, fb_size });
// -- state ---
@@ -109,7 +132,11 @@ void main_impl::draw_world() noexcept
}
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
- GL::defaultFramebuffer.clearDepthStencil(0, 0);
+#ifdef FM_USE_DEPTH32
+ framebuffer.fb.clearDepth(0);
+#else
+ GL::defaultFramebuffer.clearDepth(0);
+#endif
for (int16_t y = miny; y <= maxy; y++)
for (int16_t x = minx; x <= maxx; x++)
{
@@ -193,7 +220,11 @@ void main_impl::drawEvent()
{
_shader.set_tint({1, 1, 1, 1});
const auto clear_color = 0x222222ff_rgbaf;
+#ifdef FM_USE_DEPTH32
+ framebuffer.fb.clearColor(0, clear_color);
+#else
GL::defaultFramebuffer.clearColor(clear_color);
+#endif
draw_world();
GL::Renderer::disable(GL::Renderer::Feature::DepthTest);
}
@@ -203,6 +234,10 @@ void main_impl::drawEvent()
do_update();
+#ifdef FM_USE_DEPTH32
+ GL::Framebuffer::blit(framebuffer.fb, GL::defaultFramebuffer, framebuffer.fb.viewport(), GL::FramebufferBlit::Color);
+#endif
+
swapBuffers();
redraw();
diff --git a/main/main-impl.hpp b/main/main-impl.hpp
index dae4286e..859f2a8f 100644
--- a/main/main-impl.hpp
+++ b/main/main-impl.hpp
@@ -14,6 +14,14 @@
#include <Magnum/GL/DebugOutput.h>
#include <Magnum/Platform/Sdl2Application.h>
+//#define FM_USE_DEPTH32
+
+#ifdef FM_USE_DEPTH32
+#include <Magnum/GL/Framebuffer.h>
+#include <Magnum/GL/Renderbuffer.h>
+#include <Magnum/GL/Texture.h>
+#endif
+
namespace floormat {
struct floormat_app;
@@ -23,6 +31,14 @@ struct clickable;
struct main_impl final : Platform::Sdl2Application, floormat_main
{
+#ifdef FM_USE_DEPTH32
+ struct Framebuffer final {
+ GL::Framebuffer fb{NoCreate};
+ GL::Renderbuffer depth{NoCreate};
+ GL::Texture2D color{NoCreate};
+ };
+#endif
+
explicit main_impl(floormat_app& app, fm_settings&& opts, int& argc, char** argv) noexcept;
~main_impl() noexcept override;
@@ -86,6 +102,10 @@ private:
floor_mesh _floor_mesh;
wall_mesh _wall_mesh;
anim_mesh _anim_mesh;
+#ifdef FM_USE_DEPTH32
+ Framebuffer framebuffer;
+#endif
+
struct {
float value = 0;
float jitter = 0;
diff --git a/scenery/door-close.json b/scenery/door-close.json
index 24fcf4ee..475b688c 100644
--- a/scenery/door-close.json
+++ b/scenery/door-close.json
@@ -3,7 +3,6 @@
"fps": 24,
"groups": [
{
- "depth-offset": "128 x 128",
"frames": [
{
"ground": "126 x 121",
diff --git a/src/character.cpp b/src/character.cpp
index 7934d1b3..5e42d4e8 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -3,6 +3,7 @@
#include "loader/loader.hpp"
#include "src/world.hpp"
#include "src/entity.hpp"
+#include "shaders/tile.hpp"
#include "src/RTree-search.hpp"
#include <cmath>
#include <utility>
@@ -128,7 +129,10 @@ void character::set_keys(bool L, bool R, bool U, bool D)
b_D = D;
}
-Vector2 character::depth_offset() const { return {}; }
+Vector2 character::depth_offset() const
+{
+ return Vector2(tile_shader::character_depth_offset, 0);
+}
Vector2 character::ordinal_offset(Vector2b offset) const
{
diff --git a/src/scenery.cpp b/src/scenery.cpp
index ff78bfa8..873dcf93 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -3,6 +3,7 @@
#include "chunk.hpp"
#include "compat/assert.hpp"
#include "world.hpp"
+#include "shaders/tile.hpp"
#include "src/rotation.inl"
#include <algorithm>
@@ -89,16 +90,24 @@ Vector2 scenery::ordinal_offset(Vector2b offset) const
Vector2 scenery::depth_offset() const
{
+ constexpr auto sc_offset = tile_shader::scenery_depth_offset;
constexpr auto inv_tile_size = 1.f/TILE_SIZE2;
Vector2 ret;
+ ret += Vector2(atlas->group(r).depth_offset) * inv_tile_size;
if (sc_type == scenery_type::door)
{
- constexpr auto door_offset = Vector2b(-bTILE_SIZE[0], 0);
- const auto offset = rotate_point(door_offset, rotation::N, r);
- ret += Vector2(offset);
+ const bool is_open = frame != atlas->info().nframes-1;
+ ret += Vector2(is_open ? sc_offset : -sc_offset, 0);
+ constexpr auto off_opened = Vector2(-1, 0);
+ constexpr auto off_closed = Vector2(0, 0);
+ const auto vec = is_open ? off_opened : off_closed;
+ const auto offset = rotate_point(vec, rotation::N, r);
+ ret += offset;
}
- ret += Vector2(atlas->group(r).depth_offset);
- return ret * inv_tile_size;
+ else
+ ret += Vector2(sc_offset, 0);
+
+ return ret;
}
bool scenery::activate(size_t)