summaryrefslogtreecommitdiffhomepage
path: root/draw
diff options
context:
space:
mode:
Diffstat (limited to 'draw')
-rw-r--r--draw/anim.cpp25
-rw-r--r--draw/anim.hpp8
-rw-r--r--draw/wall.cpp36
3 files changed, 46 insertions, 23 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index 0b69e4dd..0e913d08 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -1,25 +1,36 @@
#include "anim.hpp"
#include "anim-atlas.hpp"
#include "shaders/tile.hpp"
+#include "wireframe.hpp"
+#include "quad-floor.hpp"
namespace floormat {
-anim_mesh::anim_mesh() = default;
+anim_mesh::anim_mesh()
+{
+ _mesh.setCount(6)
+ .addVertexBuffer(_vertex_buffer, 0, tile_shader::TextureCoordinates{})
+ .addVertexBuffer(_positions_buffer, 0, tile_shader::Position{})
+ .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort);
+ CORRADE_INTERNAL_ASSERT(_mesh.isIndexed());
+}
std::array<UnsignedShort, 6> anim_mesh::make_index_array()
{
- using u16 = std::uint16_t;
return {{
- (u16)0, (u16)1, (u16)2,
- (u16)2, (u16)1, (u16)3,
+ 0, 1, 2,
+ 2, 1, 3,
}};
}
-void anim_mesh::draw(local_coords xy, const anim_atlas& atlas, const anim_frame& frame)
+void anim_mesh::draw(tile_shader& shader, const anim_atlas& atlas, const anim_frame& frame, local_coords xy)
{
- const auto center_ = Vector3(xy.x, xy.y, 0.f) * TILE_SIZE;
- const auto pos = atlas.frame_quad(center_, frame);
+ const auto center = Vector3(xy.x, xy.y, 0.f) * TILE_SIZE;
+ const auto pos = atlas.frame_quad(center, frame);
_positions_buffer.setSubData(0, pos);
+ const auto texcoords = atlas.texcoords_for_frame(frame);
+ _vertex_buffer.setSubData(0, texcoords);
+ shader.draw(_mesh);
}
} // namespace floormat
diff --git a/draw/anim.hpp b/draw/anim.hpp
index 60a4e839..85c73bcb 100644
--- a/draw/anim.hpp
+++ b/draw/anim.hpp
@@ -9,17 +9,18 @@
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Buffer.h>
-namespace floormat::Serialize { struct anim_atlas; struct anim_frame; }
+namespace floormat::Serialize { struct anim_frame; }
namespace floormat {
+struct tile_shader;
struct anim_atlas;
using anim_frame = Serialize::anim_frame;
struct anim_mesh final
{
anim_mesh();
- void draw(local_coords pos, const anim_atlas& atlas, const anim_frame& frame);
+ void draw(tile_shader& shader, const anim_atlas& atlas, const anim_frame& frame, local_coords pos);
private:
struct vertex_data final { Vector2 texcoords; };
@@ -27,10 +28,9 @@ private:
static std::array<UnsignedShort, 6> make_index_array();
-
GL::Mesh _mesh;
GL::Buffer _vertex_buffer{quad_data{}, Magnum::GL::BufferUsage::DynamicDraw},
- _index_buffer{make_index_array()}, _positions_buffer{quad_data{}};
+ _index_buffer{make_index_array()}, _positions_buffer{std::array<Vector3, 4>{}};
};
} // namespace floormat
diff --git a/draw/wall.cpp b/draw/wall.cpp
index 42d62e49..68f78821 100644
--- a/draw/wall.cpp
+++ b/draw/wall.cpp
@@ -53,19 +53,31 @@ void wall_mesh::draw(tile_shader& shader, chunk& c)
const GL::Texture2D* last_texture = nullptr;
Magnum::GL::MeshView mesh{_mesh};
- for (std::size_t i = 0; i < COUNT; i++)
+ for (std::size_t idx = 0; idx < TILE_COUNT; idx++)
{
- auto* const tex = textures[i];
- if (!tex)
- continue;
- mesh.setCount(quad_index_count);
- mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*COUNT - 1);
- if (tex != last_texture)
- tex->bind(0);
- last_texture = tex;
- shader.draw(mesh);
- if (auto a = c[i].scenery())
- _anim_mesh.draw(local_coords{i}, *a.atlas, a.atlas->frame(a.frame.r, a.frame.frame));
+ for (std::size_t i = idx*2; i <= idx*2+1; i++)
+ if (auto* const tex = textures[i]; tex)
+ {
+ mesh.setCount(quad_index_count);
+ mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*COUNT - 1);
+ if (tex != last_texture)
+ tex->bind(0);
+ last_texture = tex;
+ shader.draw(mesh);
+ }
+ if (auto a = c[idx].scenery(); a.atlas)
+ {
+ auto& tex = a.atlas->texture();
+ if (&tex != last_texture)
+ tex.bind(0);
+ last_texture = &a.atlas->texture();
+ auto frame = a.frame;
+#if 0
+ static std::uint8_t f = 0;
+ frame.frame = f++ % a.atlas->info().nframes;
+#endif
+ _anim_mesh.draw(shader, *a.atlas, a.atlas->frame(a.frame.r, frame.frame), local_coords{idx});
+ }
}
}