summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--floor-mesh.hpp2
-rw-r--r--main.cpp7
-rw-r--r--tile-atlas.cpp4
-rw-r--r--wall-mesh.cpp26
-rw-r--r--wall-mesh.hpp4
5 files changed, 35 insertions, 8 deletions
diff --git a/floor-mesh.hpp b/floor-mesh.hpp
index 3bfbee3a..edb3b403 100644
--- a/floor-mesh.hpp
+++ b/floor-mesh.hpp
@@ -29,7 +29,7 @@ private:
static const std::array<std::array<Vector3, 4>, TILE_COUNT> _position_data;
GL::Mesh _mesh;
- GL::Buffer _vertex_buffer{std::array<quad_data, TILE_COUNT>{} /*, Magnum::GL::BufferUsage::DynamicDraw*/},
+ GL::Buffer _vertex_buffer{std::array<quad_data, TILE_COUNT>{}, Magnum::GL::BufferUsage::DynamicDraw},
_index_buffer{_index_data},
_positions_buffer{_position_data};
diff --git a/main.cpp b/main.cpp
index 6da96648..0c1034a1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,6 +4,7 @@
#include "tile.hpp"
#include "chunk.hpp"
#include "floor-mesh.hpp"
+#include "wall-mesh.hpp"
#include "compat/defs.hpp"
#include <bitset>
@@ -65,6 +66,7 @@ struct app final : Platform::Application
loader.tile_atlas("../share/game/images/metal2.tga", {2, 2});
chunk _chunk = make_test_chunk();
floor_mesh _floor_mesh;
+ wall_mesh _wall_mesh;
Vector2 camera_offset;
enum_bitset<key> keys;
@@ -75,11 +77,15 @@ using namespace Math::Literals;
chunk app::make_test_chunk()
{
+ constexpr auto N = TILE_MAX_DIM;
chunk c;
c.foreach_tile([&, this](tile& x, std::size_t k, local_coords) {
const auto& atlas = floor1;
x.ground_image = { atlas, (std::uint8_t)(k % atlas->size()) };
});
+ c[{N/2 + 1, N/2}].wall_north = { wall1, 0 };
+ c[{N/2 + 1, N/2 + 1}].wall_north = { wall1, 0 };
+ c[{N/2, N/2}].wall_north = { wall1, 0 };
return c;
}
@@ -92,6 +98,7 @@ void app::update_window_scale()
void app::draw_chunk(chunk& c)
{
_floor_mesh.draw(_shader, c);
+ _wall_mesh.draw(_shader, c);
}
app::app(const Arguments& arguments):
diff --git a/tile-atlas.cpp b/tile-atlas.cpp
index 07f59696..eb550e34 100644
--- a/tile-atlas.cpp
+++ b/tile-atlas.cpp
@@ -50,7 +50,7 @@ vertex_array_type tile_atlas::floor_quad(Vector3 center, Vector2 size)
}};
}
-vertex_array_type tile_atlas::wall_quad_W(Vector3 center, Vector3 size)
+vertex_array_type tile_atlas::wall_quad_N(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
@@ -83,7 +83,7 @@ vertex_array_type tile_atlas::wall_quad_E(Vector3 center, Vector3 size)
}};
}
-vertex_array_type tile_atlas::wall_quad_N(Vector3 center, Vector3 size)
+vertex_array_type tile_atlas::wall_quad_W(Vector3 center, Vector3 size)
{
float x = size[0]*.5f, y = size[1]*.5f, z = size[2];
return {{
diff --git a/wall-mesh.cpp b/wall-mesh.cpp
index 843f7073..31399aed 100644
--- a/wall-mesh.cpp
+++ b/wall-mesh.cpp
@@ -48,22 +48,42 @@ void wall_mesh::draw(tile_shader& shader, chunk& c)
c.foreach_tile([&](tile& x, std::size_t, local_coords pt) {
maybe_add_tile(data, textures, pos, x, pt);
});
- _vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos));
+ //_vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos));
+ _vertex_buffer.setData(data, Magnum::GL::BufferUsage::DynamicDraw);
}
const GL::Texture2D* last_texture = nullptr;
+#if 0
+ if (pos > 0)
+ {
+ Magnum::GL::MeshView mesh{_mesh};
+ mesh.setCount((int)(pos * quad_index_count));
+ mesh.setIndexRange(0);
+ textures[0]->bind(0);
+ shader.draw(mesh);
+ }
+#elif 0
+ if (pos > 0)
+ {
+ textures[0]->bind(0);
+ shader.draw(_mesh);
+ }
+#else
Magnum::GL::MeshView mesh{_mesh};
- mesh.setCount(quad_index_count);
for (std::size_t i = 0; i < pos; i++)
{
auto* const tex = textures[i];
CORRADE_INTERNAL_ASSERT(tex != nullptr);
+ mesh.setCount(quad_index_count);
mesh.setIndexRange((int)(i*quad_index_count), 0, quad_index_count*COUNT - 1);
+ //mesh.setIndexRange((int)(i*quad_index_count));
+ //Debug{} << "draw " << "i:" << i << "count:" << quad_index_count << "range:" << (i*quad_index_count);
if (tex != last_texture)
tex->bind(0);
last_texture = tex;
+ shader.draw(mesh);
}
- shader.draw(mesh);
+#endif
}
decltype(wall_mesh::_index_data) wall_mesh::make_index_array()
diff --git a/wall-mesh.hpp b/wall-mesh.hpp
index 1a9bb4e8..ef73e02b 100644
--- a/wall-mesh.hpp
+++ b/wall-mesh.hpp
@@ -27,7 +27,7 @@ private:
struct vertex final {
typename texcoords_array::value_type texcoords;
- typename position_array::value_type position;
+ typename position_array::value_type position;
};
using quad = std::array<vertex, 4>;
@@ -40,7 +40,7 @@ private:
tile_image& img, const position_array& positions);
GL::Mesh _mesh;
- GL::Buffer _vertex_buffer{vertex_array{}, Magnum::GL::BufferUsage::StaticDraw},
+ GL::Buffer _vertex_buffer{vertex_array{}, Magnum::GL::BufferUsage::DynamicDraw},
_index_buffer{_index_data, Magnum::GL::BufferUsage::StaticDraw};
static const std::array<std::array<UnsignedShort, 6>, COUNT> _index_data;