Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Attributes
omni::visual::VertexVBO Class Reference

Utility class for storing and drawing VBO data. More...

#include <VertexVBO.h>

Collaboration diagram for omni::visual::VertexVBO:
Collaboration graph
[legend]

Public Types

typedef std::vector< Vertex > vertex_buffer_type
 Vertex buffer type. More...
 
typedef std::vector< uint32_t > index_buffer_type
 Index buffer type. More...
 

Public Member Functions

 VertexVBO ()
 
 VertexVBO (vertex_buffer_type const &_vertices, index_buffer_type const &_indices)
 
void buffer (vertex_buffer_type const &_vertices, index_buffer_type const &_indices)
 Copy buffers to GPU. More...
 
void bind () const
 Bind buffer for drawing. More...
 
void draw () const
 Draw buffer as triangles. More...
 
void draw (uint32_t _numIndices, GLuint _drawType=GL_TRIANGLES) const
 Draw specific indices from buffer as triangles. More...
 
void unbind () const
 Unbind buffer. More...
 
template<typename... ARGS>
void bindAndDraw (ARGS &&..._args) const
 
size_t numIndices () const
 Return number of indices in this buffer. More...
 
size_t numTriangles () const
 Number of triangles = number of indices / 3. More...
 
VBO const & vertexVbo () const
 Return vertex vertex buffer object. More...
 
VBO const & indexVbo () const
 Return index vertex buffer object. More...
 

Private Attributes

size_t numIndices_ = 0
 
std::unique_ptr< VBOvertexVbo_
 
std::unique_ptr< VBOindexVbo_
 

Detailed Description

Utility class for storing and drawing VBO data.

Member Typedef Documentation

typedef std::vector<uint32_t> omni::visual::VertexVBO::index_buffer_type

Index buffer type.

typedef std::vector<Vertex> omni::visual::VertexVBO::vertex_buffer_type

Vertex buffer type.

Constructor & Destructor Documentation

omni::visual::VertexVBO::VertexVBO ( )
26 {}
omni::visual::VertexVBO::VertexVBO ( vertex_buffer_type const &  _vertices,
index_buffer_type const &  _indices 
)
29  {
30  buffer(_vertices, _indices);
31  }
void buffer(vertex_buffer_type const &_vertices, index_buffer_type const &_indices)
Copy buffers to GPU.
Definition: VertexVBO.cpp:33

Member Function Documentation

void omni::visual::VertexVBO::bind ( ) const

Bind buffer for drawing.

60  {
61  withCurrentContext([this](QOpenGLFunctions& _)
62  {
63  _.glBindBuffer(GL_ARRAY_BUFFER, vertexVbo_->id());
64  _.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVbo_->id());
65 
66  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
67  glEnableClientState(GL_NORMAL_ARRAY);
68  glEnableClientState(GL_VERTEX_ARRAY);
69  });
70  }
std::unique_ptr< VBO > indexVbo_
Definition: VertexVBO.h:85
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
std::unique_ptr< VBO > vertexVbo_
Definition: VertexVBO.h:85
template<typename... ARGS>
void omni::visual::VertexVBO::bindAndDraw ( ARGS &&...  _args) const
inline
63  {
64  bind();
65  draw(_args ...);
66  unbind();
67  }
void unbind() const
Unbind buffer.
Definition: VertexVBO.cpp:90
void draw() const
Draw buffer as triangles.
Definition: VertexVBO.cpp:72
void bind() const
Bind buffer for drawing.
Definition: VertexVBO.cpp:60
void omni::visual::VertexVBO::buffer ( vertex_buffer_type const &  _vertices,
index_buffer_type const &  _indices 
)

Copy buffers to GPU.

34  {
35  vertexVbo_.reset(new VBO());
36  indexVbo_.reset(new VBO());
37 
38  withCurrentContext([&](QOpenGLFunctions& _)
39  {
40 
41  // bind VBO in order to use
42  _.glBindBuffer(GL_ARRAY_BUFFER, vertexVbo_->id());
43  {
44  _.glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(Vertex),
45  _vertices.data(), GL_STATIC_DRAW);
46  }
47  _.glBindBuffer(GL_ARRAY_BUFFER, 0);
48 
49  _.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVbo_->id());
50  {
51  _.glBufferData(GL_ELEMENT_ARRAY_BUFFER,
52  _indices.size() * sizeof(GLuint), _indices.data(),
53  GL_STATIC_DRAW);
54  }
55  _.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
56  numIndices_ = _indices.size();
57  });
58  }
std::unique_ptr< VBO > indexVbo_
Definition: VertexVBO.h:85
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
std::unique_ptr< VBO > vertexVbo_
Definition: VertexVBO.h:85
size_t numIndices_
Definition: VertexVBO.h:84
void omni::visual::VertexVBO::draw ( ) const

Draw buffer as triangles.

72  {
74  }
void draw() const
Draw buffer as triangles.
Definition: VertexVBO.cpp:72
size_t numIndices_
Definition: VertexVBO.h:84
void omni::visual::VertexVBO::draw ( uint32_t  _numIndices,
GLuint  _drawType = GL_TRIANGLES 
) const

Draw specific indices from buffer as triangles.

76  {
77  if ((_numElements < 4) || (_numElements > numIndices_)) {
78  return;
79  }
80  withCurrentContext([&](QOpenGLFunctions& _)
81  {
82  glTexCoordPointer(3, GL_FLOAT, sizeof(Vertex),
83  (void *)Vertex::texCoordOffset());
84  glNormalPointer(GL_FLOAT, sizeof(Vertex), (void *)Vertex::normalOffset());
85  glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void *)Vertex::posOffset());
86  _.glDrawElements(_drawType, _numElements - 4, GL_UNSIGNED_INT, 0);
87  });
88  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
size_t numIndices_
Definition: VertexVBO.h:84
VBO const & omni::visual::VertexVBO::indexVbo ( ) const

Return index vertex buffer object.

110  {
111  return *indexVbo_;
112  }
std::unique_ptr< VBO > indexVbo_
Definition: VertexVBO.h:85
size_t omni::visual::VertexVBO::numIndices ( ) const

Return number of indices in this buffer.

102  {
103  return numIndices_;
104  }
size_t numIndices_
Definition: VertexVBO.h:84
size_t omni::visual::VertexVBO::numTriangles ( ) const
inline

Number of triangles = number of indices / 3.

73  {
74  return numIndices() / 3;
75  }
size_t numIndices() const
Return number of indices in this buffer.
Definition: VertexVBO.cpp:102
void omni::visual::VertexVBO::unbind ( ) const

Unbind buffer.

90  {
91  withCurrentContext([this](QOpenGLFunctions& _)
92  {
93  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
94  glDisableClientState(GL_NORMAL_ARRAY);
95  glDisableClientState(GL_VERTEX_ARRAY);
96 
97  _.glBindBuffer(GL_ARRAY_BUFFER, 0);
98  _.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
99  });
100  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
VBO const & omni::visual::VertexVBO::vertexVbo ( ) const

Return vertex vertex buffer object.

106  {
107  return *vertexVbo_;
108  }
std::unique_ptr< VBO > vertexVbo_
Definition: VertexVBO.h:85

Field Documentation

std::unique_ptr<VBO> omni::visual::VertexVBO::indexVbo_
private
size_t omni::visual::VertexVBO::numIndices_ = 0
private
std::unique_ptr<VBO> omni::visual::VertexVBO::vertexVbo_
private

The documentation for this class was generated from the following files: