Support loading index-only data in gfx::mesh
This commit is contained in:
parent
f9dbc9138f
commit
8d4e29eb35
1 changed files with 52 additions and 0 deletions
|
|
@ -150,6 +150,20 @@ namespace psemek::gfx
|
||||||
template <typename Vertex, typename Index, std::size_t N>
|
template <typename Vertex, typename Index, std::size_t N>
|
||||||
void load(std::vector<Vertex> const & vertices, std::vector<geom::simplex<Index, N>> const & simplices, GLenum usage = gl::STREAM_DRAW);
|
void load(std::vector<Vertex> const & vertices, std::vector<geom::simplex<Index, N>> const & simplices, GLenum usage = gl::STREAM_DRAW);
|
||||||
|
|
||||||
|
// Index-only vertex data
|
||||||
|
|
||||||
|
template <typename Index>
|
||||||
|
void load_index(Index const * indices, std::size_t index_count, GLenum primitive_type, GLenum usage = gl::STREAM_DRAW);
|
||||||
|
|
||||||
|
template <typename Index>
|
||||||
|
void load_index(std::vector<Index> const & indices, GLenum primitive_type, GLenum usage = gl::STREAM_DRAW);
|
||||||
|
|
||||||
|
template <typename Index, std::size_t N>
|
||||||
|
void load_index(geom::simplex<Index, N> const * simplices, std::size_t simplex_count, GLenum usage = gl::STREAM_DRAW);
|
||||||
|
|
||||||
|
template <typename Index, std::size_t N>
|
||||||
|
void load_index(std::vector<geom::simplex<Index, N>> const & simplices, GLenum usage = gl::STREAM_DRAW);
|
||||||
|
|
||||||
// Instance data
|
// Instance data
|
||||||
|
|
||||||
template <typename Instance>
|
template <typename Instance>
|
||||||
|
|
@ -291,6 +305,44 @@ namespace psemek::gfx
|
||||||
load(vertices.data(), vertices.size(), simplices.data(), simplices.size(), usage);
|
load(vertices.data(), vertices.size(), simplices.data(), simplices.size(), usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Index>
|
||||||
|
void mesh::load_index(Index const * indices, std::size_t index_count, GLenum primitive_type, GLenum usage)
|
||||||
|
{
|
||||||
|
if (auto n = detail::get_primitive_type_vertex_count(primitive_type); n)
|
||||||
|
assert((index_count % (*n)) == 0);
|
||||||
|
|
||||||
|
if (!index_buffer_)
|
||||||
|
{
|
||||||
|
index_buffer_ = buffer{};
|
||||||
|
array_.bind();
|
||||||
|
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, index_buffer_.id());
|
||||||
|
}
|
||||||
|
index_buffer_.load(indices, index_count, usage);
|
||||||
|
info_.index_count_ = index_count;
|
||||||
|
info_.indexed_ = true;
|
||||||
|
info_.primitive_type_ = primitive_type;
|
||||||
|
info_.index_type_ = detail::index_type_to_gl_enum_v<Index>;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Index>
|
||||||
|
void mesh::load_index(std::vector<Index> const & indices, GLenum primitive_type, GLenum usage)
|
||||||
|
{
|
||||||
|
load_index(indices.data(), indices.size(), primitive_type, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Index, std::size_t N>
|
||||||
|
void mesh::load_index(geom::simplex<Index, N> const * simplices, std::size_t simplex_count, GLenum usage)
|
||||||
|
{
|
||||||
|
static_assert(sizeof(Index) * (N + 1) == sizeof(simplices[0]));
|
||||||
|
load_index(reinterpret_cast<Index const *>(simplices), simplex_count, detail::get_primitive_type<N>(), usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Index, std::size_t N>
|
||||||
|
void mesh::load_index(std::vector<geom::simplex<Index, N>> const & simplices, GLenum usage)
|
||||||
|
{
|
||||||
|
load_index(simplices.data(), simplices.size(), usage);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Instance>
|
template <typename Instance>
|
||||||
void mesh::load_instance(Instance const * instances, std::size_t count, GLenum usage)
|
void mesh::load_instance(Instance const * instances, std::size_t count, GLenum usage)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue