Fix issues with vbos and binding. Also fix issue with multiple definition of explicit template specialization
This commit is contained in:
parent
aad6db9b29
commit
089ab7539c
@ -93,7 +93,7 @@ namespace graphics{
|
|||||||
gl_buffer* get_bound_buffer()const;
|
gl_buffer* get_bound_buffer()const;
|
||||||
GLenum get_bound_id()const;
|
GLenum get_bound_id()const;
|
||||||
private:
|
private:
|
||||||
static void copy_buffer(const vbo& src, vbo& dest);
|
static void copy_buffer(vbo& dest, const vbo& src);
|
||||||
};
|
};
|
||||||
|
|
||||||
//RAII wrapper for mapping vbo's
|
//RAII wrapper for mapping vbo's
|
||||||
@ -234,47 +234,6 @@ namespace graphics{
|
|||||||
return m_data[i];
|
return m_data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_vbo_map<void>::scoped_vbo_map(const vbo& v, gl_buffer& targ, vbo::maptype m):
|
|
||||||
m_owner(&v)
|
|
||||||
{
|
|
||||||
m_owner->bind_lock(targ);
|
|
||||||
m_data = reinterpret_cast<pointer>(glMapBuffer(m_owner->get_bound_id(), static_cast<GLenum>(m)));
|
|
||||||
}
|
|
||||||
scoped_vbo_map<void>::scoped_vbo_map(scoped_vbo_map&& m):
|
|
||||||
m_data(std::exchange(m.m_data, nullptr)),
|
|
||||||
m_owner(m.m_owner){}
|
|
||||||
scoped_vbo_map<void>::~scoped_vbo_map(){
|
|
||||||
if(m_data){
|
|
||||||
glUnmapBuffer(m_owner->get_bound_id());
|
|
||||||
m_owner->bind_unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scoped_vbo_map<void>& scoped_vbo_map<void>::operator=(scoped_vbo_map&& m){
|
|
||||||
std::swap(m_data, m.m_data);
|
|
||||||
std::swap(m_owner, m.m_owner);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
auto scoped_vbo_map<void>::length()const -> size_type{
|
|
||||||
GLint64 retval;
|
|
||||||
glGetBufferParameteri64v(m_owner->get_bound_id(), GL_BUFFER_MAP_LENGTH, &retval);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
auto scoped_vbo_map<void>::release() -> pointer{
|
|
||||||
return std::exchange(m_data, nullptr);
|
|
||||||
}
|
|
||||||
scoped_vbo_map<void>::operator pointer(){
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
scoped_vbo_map<void>::operator const_pointer()const{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
auto scoped_vbo_map<void>::raw() -> pointer{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
auto scoped_vbo_map<void>::raw()const -> const_pointer{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "graphics/gl_include.hpp"
|
#include "graphics/gl_include.hpp"
|
||||||
|
|
||||||
|
#include <utility> //exchange
|
||||||
|
|
||||||
namespace graphics{
|
namespace graphics{
|
||||||
|
|
||||||
buffer_iface::buffer_iface(const buffer_iface&):
|
buffer_iface::buffer_iface(const buffer_iface&):
|
||||||
@ -54,8 +56,10 @@ namespace graphics{
|
|||||||
bool buffer_iface::bind(gl_buffer& b)const{
|
bool buffer_iface::bind(gl_buffer& b)const{
|
||||||
if(b.is_locked())
|
if(b.is_locked())
|
||||||
return false;
|
return false;
|
||||||
if(m_bound)
|
if(m_bound){
|
||||||
m_bound->bind(nullptr);
|
gl_buffer* tmp = std::exchange(m_bound, nullptr);
|
||||||
|
tmp->bind(nullptr);
|
||||||
|
}
|
||||||
m_bound = &b;
|
m_bound = &b;
|
||||||
m_bound->bind(this);
|
m_bound->bind(this);
|
||||||
return true;
|
return true;
|
||||||
@ -94,8 +98,10 @@ namespace graphics{
|
|||||||
gl_buffer::gl_buffer(GLenum buf):
|
gl_buffer::gl_buffer(GLenum buf):
|
||||||
m_buffer(buf){}
|
m_buffer(buf){}
|
||||||
void gl_buffer::bind(const buffer_iface* newbind){
|
void gl_buffer::bind(const buffer_iface* newbind){
|
||||||
if(bound)
|
if(bound){
|
||||||
bound->unbind();
|
const buffer_iface* tmp = std::exchange(bound, nullptr);
|
||||||
|
tmp->unbind();
|
||||||
|
}
|
||||||
bound = newbind;
|
bound = newbind;
|
||||||
}
|
}
|
||||||
void gl_buffer::lock(bool b){
|
void gl_buffer::lock(bool b){
|
||||||
|
|||||||
@ -24,11 +24,11 @@
|
|||||||
namespace graphics{
|
namespace graphics{
|
||||||
|
|
||||||
vbo::vbo(size_t size, usage t):
|
vbo::vbo(size_t size, usage t):
|
||||||
m_buffer_size(size)
|
m_buffer_size(0)
|
||||||
{
|
{
|
||||||
glGenBuffers(1, &m_buffer);
|
glGenBuffers(1, &m_buffer);
|
||||||
bind(buffer::copy_write);
|
bind(buffer::copy_write);
|
||||||
glBufferData(m_bi.get_bound_id(), m_buffer_size, NULL, static_cast<GLenum>(t));
|
glBufferData(m_bi.get_bound_id(), size, NULL, static_cast<GLenum>(t));
|
||||||
}
|
}
|
||||||
vbo::vbo(const vbo& v):
|
vbo::vbo(const vbo& v):
|
||||||
m_buffer_size(v.m_buffer_size),
|
m_buffer_size(v.m_buffer_size),
|
||||||
@ -59,6 +59,8 @@ namespace graphics{
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
bool vbo::bind(gl_buffer& buf)const{
|
bool vbo::bind(gl_buffer& buf)const{
|
||||||
|
if(get_bound_id() == buf.get_buffer_id())
|
||||||
|
return true;
|
||||||
if(!m_bi.bind(buf))
|
if(!m_bi.bind(buf))
|
||||||
return false;
|
return false;
|
||||||
glBindBuffer(buf.get_buffer_id(), m_buffer);
|
glBindBuffer(buf.get_buffer_id(), m_buffer);
|
||||||
@ -121,10 +123,53 @@ namespace graphics{
|
|||||||
return static_cast<usage>(retval);
|
return static_cast<usage>(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vbo::copy_buffer(const vbo& src, vbo& dest){
|
void vbo::copy_buffer(vbo& dest, const vbo& src){
|
||||||
size_t bytes = util::min(dest.get_cap(), src.get_size());
|
size_t bytes = util::min(dest.get_cap(), src.get_size());
|
||||||
dest.bind(buffer::copy_write);
|
dest.bind(buffer::copy_write);
|
||||||
scoped_vbo_map<void> data(src, buffer::copy_read, maptype::READ);
|
scoped_vbo_map<void> data(src, buffer::copy_read, maptype::READ);
|
||||||
dest.buffer(data, bytes);
|
dest.buffer(data, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
scoped_vbo_map<void>::scoped_vbo_map(const vbo& v, gl_buffer& targ, vbo::maptype m):
|
||||||
|
m_owner(&v)
|
||||||
|
{
|
||||||
|
m_owner->bind_lock(targ);
|
||||||
|
m_data = reinterpret_cast<pointer>(glMapBuffer(m_owner->get_bound_id(), static_cast<GLenum>(m)));
|
||||||
|
}
|
||||||
|
scoped_vbo_map<void>::scoped_vbo_map(scoped_vbo_map&& m):
|
||||||
|
m_data(std::exchange(m.m_data, nullptr)),
|
||||||
|
m_owner(m.m_owner){}
|
||||||
|
scoped_vbo_map<void>::~scoped_vbo_map(){
|
||||||
|
if(m_data){
|
||||||
|
glUnmapBuffer(m_owner->get_bound_id());
|
||||||
|
m_owner->bind_unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scoped_vbo_map<void>& scoped_vbo_map<void>::operator=(scoped_vbo_map&& m){
|
||||||
|
std::swap(m_data, m.m_data);
|
||||||
|
std::swap(m_owner, m.m_owner);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
auto scoped_vbo_map<void>::length()const -> size_type{
|
||||||
|
GLint64 retval;
|
||||||
|
glGetBufferParameteri64v(m_owner->get_bound_id(), GL_BUFFER_MAP_LENGTH, &retval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
auto scoped_vbo_map<void>::release() -> pointer{
|
||||||
|
return std::exchange(m_data, nullptr);
|
||||||
|
}
|
||||||
|
scoped_vbo_map<void>::operator pointer(){
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
scoped_vbo_map<void>::operator const_pointer()const{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
auto scoped_vbo_map<void>::raw() -> pointer{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
auto scoped_vbo_map<void>::raw()const -> const_pointer{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user