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