Support rendering part of a mesh
This commit is contained in:
parent
3c215d6abb
commit
23de4a520e
1 changed files with 42 additions and 7 deletions
|
|
@ -8,6 +8,8 @@
|
||||||
#include <psemek/geom/simplex.hpp>
|
#include <psemek/geom/simplex.hpp>
|
||||||
#include <psemek/geom/matrix.hpp>
|
#include <psemek/geom/matrix.hpp>
|
||||||
|
|
||||||
|
#include <psemek/util/assert.hpp>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
@ -477,10 +479,17 @@ namespace psemek::gfx
|
||||||
|
|
||||||
void draw() const override
|
void draw() const override
|
||||||
{
|
{
|
||||||
if (count_ == 0) return;
|
draw(0, count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(GLsizei first, GLsizei count) const
|
||||||
|
{
|
||||||
|
assert(first + count <= count_);
|
||||||
|
|
||||||
|
if (count == 0) return;
|
||||||
|
|
||||||
gl::BindVertexArray(array_);
|
gl::BindVertexArray(array_);
|
||||||
gl::DrawArrays(primitive_type_, 0, count_);
|
gl::DrawArrays(primitive_type_, first, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLsizei count() const
|
GLsizei count() const
|
||||||
|
|
@ -599,10 +608,16 @@ namespace psemek::gfx
|
||||||
|
|
||||||
void draw() const override
|
void draw() const override
|
||||||
{
|
{
|
||||||
if (count_ == 0) return;
|
draw(0, count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(GLsizei first, GLsizei count) const
|
||||||
|
{
|
||||||
|
if (count == 0) return;
|
||||||
|
assert(first + count <= count_);
|
||||||
|
|
||||||
gl::BindVertexArray(array_);
|
gl::BindVertexArray(array_);
|
||||||
gl::DrawElements(primitive_type_, count_, index_type_, nullptr);
|
gl::DrawElements(primitive_type_, count, index_type_, reinterpret_cast<char const *>(0) + first * index_size(index_type_));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLsizei index_count() const
|
GLsizei index_count() const
|
||||||
|
|
@ -628,6 +643,18 @@ namespace psemek::gfx
|
||||||
GLenum primitive_type_;
|
GLenum primitive_type_;
|
||||||
|
|
||||||
indexed_mesh(int);
|
indexed_mesh(int);
|
||||||
|
|
||||||
|
static std::size_t index_size(GLenum type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case gl::UNSIGNED_BYTE: return 1;
|
||||||
|
case gl::UNSIGNED_SHORT: return 2;
|
||||||
|
case gl::UNSIGNED_INT: return 4;
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct instanced_mesh
|
struct instanced_mesh
|
||||||
|
|
@ -737,11 +764,19 @@ namespace psemek::gfx
|
||||||
|
|
||||||
void draw() const override
|
void draw() const override
|
||||||
{
|
{
|
||||||
if (count_ == 0) return;
|
draw(0, count_, instance_count_);
|
||||||
if (instance_count_ == 0) return;
|
}
|
||||||
|
|
||||||
|
void draw(GLsizei first, GLsizei count, GLsizei instance_count) const
|
||||||
|
{
|
||||||
|
assert(first + count <= count_);
|
||||||
|
assert(instance_count <= instance_count_);
|
||||||
|
|
||||||
|
if (count == 0) return;
|
||||||
|
if (instance_count == 0) return;
|
||||||
|
|
||||||
gl::BindVertexArray(array_);
|
gl::BindVertexArray(array_);
|
||||||
gl::DrawArraysInstanced(primitive_type_, 0, count_, instance_count_);
|
gl::DrawArraysInstanced(primitive_type_, first, count, instance_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLsizei count() const
|
GLsizei count() const
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue