Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfBufferObject.cpp
1 #include "glfBufferObject.hh"
2 #include "glfException.hh"
3 
4 using namespace BIAS;
5 
6 glfBufferObject::glfBufferObject(GLenum target, GLenum queryName) :
7  target_(target), queryName_(queryName), bufferObjID_(0), boundRevertably_(false), previousBinding_(0)
8 {}
9 
11 {
12  glDeleteBuffers(1, &bufferObjID_);
13  bufferObjID_ = 0;
14  GLF_THROW_ON_OPENGL_ERROR_DEBUG;
15 }
16 
17 
19 {
20  if(bufferObjID_==0)
21  glGenBuffers(1, &bufferObjID_);
22  GLF_THROW_ON_OPENGL_ERROR_DEBUG;
23 }
24 
25 
27 {
28  BIASASSERT( bufferObjID_ != 0);
29  glBindBuffer(target_, bufferObjID_);
30  boundRevertably_ = false;
31  GLF_THROW_ON_OPENGL_ERROR_DEBUG;
32 }
33 
35 {
36  BIASASSERT( bufferObjID_ != 0);
37  glGetIntegerv(queryName_, &previousBinding_);
38  boundRevertably_ = true;
39  glBindBuffer(target_, bufferObjID_);
40  GLF_THROW_ON_OPENGL_ERROR_DEBUG;
41 }
42 
44 {
45  if(boundRevertably_) {
46  glBindBuffer(target_, previousBinding_);
47  boundRevertably_ = false;
48  GLF_THROW_ON_OPENGL_ERROR_DEBUG;
49  } else {
50  BIASWARN("Unable to revert binding! Use BindRevertable() without subsequent call to Bind()!");
51  }
52 }
53 
54 
56 UploadData(GLenum usageHint, GLsizeiptr size, GLvoid* data)
57 {
59  glBufferData(target_, size, data, usageHint);
60  GLF_THROW_ON_OPENGL_ERROR;
61  Revert();
62 }
63 
65 UploadData(float* data, unsigned int numElements, GLenum usageHint)
66 {
67  UploadData(usageHint, sizeof(float)*numElements, data);
68 }
69 
70 
71 // GLuint glfBufferObject::GetID()
72 // {
73 // return bufferObjID_;
74 // }
void UploadData(float *data, unsigned int numElements, GLenum usageHint=GL_STATIC_DRAW)
glfBufferObject(GLenum target, GLenum queryName)