Refactor mesh vertex size check
This commit is contained in:
parent
9e79bd1c40
commit
d4a7611ee5
2 changed files with 26 additions and 8 deletions
|
|
@ -384,6 +384,9 @@ namespace psemek::gfx
|
|||
template <typename T>
|
||||
static constexpr GLenum gl_type_v = gl_type<T>::value;
|
||||
|
||||
void check_vertex_size(std::size_t vertex_size, std::size_t stride);
|
||||
void check_instance_size(std::size_t instance_size, std::size_t stride);
|
||||
|
||||
}
|
||||
|
||||
struct mesh
|
||||
|
|
@ -412,8 +415,7 @@ namespace psemek::gfx
|
|||
template <typename Vertex>
|
||||
void load(Vertex const * vertices, std::size_t count, GLenum primitive_type, GLenum usage = gl::STREAM_DRAW)
|
||||
{
|
||||
if (sizeof(Vertex) != stride_)
|
||||
throw std::runtime_error("Vertex size not equal to sum of attribute sizes");
|
||||
detail::check_vertex_size(sizeof(Vertex), stride_);
|
||||
|
||||
switch (primitive_type)
|
||||
{
|
||||
|
|
@ -532,8 +534,7 @@ namespace psemek::gfx
|
|||
template <typename Vertex, typename Index>
|
||||
void load(Vertex const * vertices, std::size_t vertex_count, Index const * indices, std::size_t index_count, GLenum primitive_type, GLenum usage = gl::STREAM_DRAW)
|
||||
{
|
||||
if (sizeof(Vertex) != stride_)
|
||||
throw std::runtime_error("Vertex size not equal to sum of attribute sizes");
|
||||
detail::check_vertex_size(sizeof(Vertex), stride_);
|
||||
|
||||
switch (primitive_type)
|
||||
{
|
||||
|
|
@ -658,8 +659,7 @@ namespace psemek::gfx
|
|||
template <typename Vertex>
|
||||
void load(Vertex const * vertices, std::size_t count, GLenum primitive_type, GLenum usage = gl::STREAM_DRAW)
|
||||
{
|
||||
if (sizeof(Vertex) != stride_)
|
||||
throw std::runtime_error("Vertex size not equal to sum of attribute sizes");
|
||||
detail::check_vertex_size(sizeof(Vertex), stride_);
|
||||
|
||||
switch (primitive_type)
|
||||
{
|
||||
|
|
@ -722,8 +722,7 @@ namespace psemek::gfx
|
|||
template <typename Instance>
|
||||
void load_instance(Instance const * instances, std::size_t count, GLenum usage = gl::STREAM_DRAW)
|
||||
{
|
||||
if (sizeof(Instance) != instance_stride_)
|
||||
throw std::runtime_error("Instance size not equal to sum of instanced attribute sizes");
|
||||
detail::check_instance_size(sizeof(Instance), instance_stride_);
|
||||
|
||||
gl::BindBuffer(gl::ARRAY_BUFFER, instance_buffer_);
|
||||
gl::BufferData(gl::ARRAY_BUFFER, count * sizeof(Instance), instances, usage);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,27 @@
|
|||
#include <psemek/gfx/mesh.hpp>
|
||||
|
||||
#include <psemek/util/to_string.hpp>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
void check_vertex_size(std::size_t vertex_size, std::size_t stride)
|
||||
{
|
||||
if (vertex_size != stride)
|
||||
throw std::runtime_error(util::to_string("Vertex size (", vertex_size, ") not equal to sum of attribute sizes (", stride, ")"));
|
||||
}
|
||||
|
||||
void check_instance_size(std::size_t instance_size, std::size_t stride)
|
||||
{
|
||||
if (instance_size != stride)
|
||||
throw std::runtime_error(util::to_string("Instance size (", instance_size, ") not equal to sum of instanced attribute sizes (", stride, ")"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mesh mesh::null()
|
||||
{
|
||||
return mesh(0);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue