Remember memory size in gfx::buffer
This commit is contained in:
parent
11af452b16
commit
6d5a01921c
1 changed files with 13 additions and 1 deletions
|
|
@ -21,8 +21,10 @@ namespace psemek::gfx
|
|||
|
||||
basic_buffer(basic_buffer && other)
|
||||
: id_{other.id_}
|
||||
, size_{other.size_}
|
||||
{
|
||||
other.id_ = 0;
|
||||
other.size_ = 0;
|
||||
}
|
||||
|
||||
basic_buffer & operator = (basic_buffer && other)
|
||||
|
|
@ -31,8 +33,10 @@ namespace psemek::gfx
|
|||
return *this;
|
||||
|
||||
reset();
|
||||
id_ = std::move(other.id_);
|
||||
id_ = other.id_;
|
||||
size_ = other.size_;
|
||||
other.id_ = 0;
|
||||
other.size_ = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -68,12 +72,14 @@ namespace psemek::gfx
|
|||
if (id_)
|
||||
gl::DeleteBuffers(1, &id_);
|
||||
id_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void load(void const * data, std::size_t size, GLenum usage = gl::STREAM_DRAW)
|
||||
{
|
||||
bind();
|
||||
gl::BufferData(Target, size, data, usage);
|
||||
size_ = size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -142,6 +148,11 @@ namespace psemek::gfx
|
|||
load_subdata(offset, data.data(), data.size());
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T[]> map()
|
||||
{
|
||||
|
|
@ -159,6 +170,7 @@ namespace psemek::gfx
|
|||
|
||||
private:
|
||||
GLuint id_ = 0;
|
||||
std::size_t size_ = 0;
|
||||
std::weak_ptr<void> mapped_;
|
||||
|
||||
explicit basic_buffer(std::nullptr_t)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue