Support mapping gfx::buffer (write-only)
This commit is contained in:
parent
77a32e444a
commit
28b4bad3a7
1 changed files with 17 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <psemek/gfx/gl.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
|
@ -41,8 +42,24 @@ namespace psemek::gfx
|
|||
load(data.data(), data.size(), usage);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> map()
|
||||
{
|
||||
if (auto p = mapped_.lock())
|
||||
return std::static_pointer_cast<T>(p);
|
||||
|
||||
bind();
|
||||
std::shared_ptr<T> p(reinterpret_cast<T *>(gl::MapBuffer(gl::ARRAY_BUFFER, gl::WRITE_ONLY)), [this](T *){
|
||||
bind();
|
||||
gl::UnmapBuffer(gl::ARRAY_BUFFER);
|
||||
});
|
||||
mapped_ = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint id_;
|
||||
std::weak_ptr<void> mapped_;
|
||||
|
||||
explicit buffer(std::nullptr_t);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue