Allolib  1.0
C++ Components For Interactive Multimedia
al_BufferObject.hpp
1 #ifndef INCLUDE_AL_GRAPHICS_BUFFEROBJECT_HPP
2 #define INCLUDE_AL_GRAPHICS_BUFFEROBJECT_HPP
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
8  Copyright (C) 2012. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13 
14  Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16 
17  Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20 
21  Neither the name of the University of California nor the names of its
22  contributors may be used to endorse or promote products derived from
23  this software without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  POSSIBILITY OF SUCH DAMAGE.
36 
37 
38  File description:
39  GPU buffer object helper
40 
41  File author(s):
42  Lance Putnam, 2010, putnam.lance@gmail.com
43  Keehong Youn, 2017, younkeehong@gmail.com
44 
45 */
46 
47 #include "al/graphics/al_GPUObject.hpp"
48 #include "al/graphics/al_OpenGL.hpp"
49 
50 #include <vector>
51 #include <cstddef>
52 
53 namespace al {
54 
76 class BufferObject : public GPUObject {
77  public:
78  BufferObject();
79  virtual ~BufferObject();
80 
82  int size() const;
84  void bufferType(unsigned int v); // GL_ARRAY_BUFFER, ...
86  void usage(unsigned int v); // GL_DYNAMIC_DRAW, ...
87 
89  void bind();
91  void unbind() const;
92 
93  // size is in bytes, if a std::vector of vec4 with float type is to be sent,
94  // the call should be:
95  // my_buffer.data(my_vector.size() * 4 * sizeof(float), my_vector.data());
96  void data(size_t size, void const* src = NULL);
97  void subdata(int offset, int size, void const* src);
98 
99  // #ifdef AL_GRAPHICS_USE_OPENGL
100  /* Warning: these are not supported in OpenGL ES */
101 
103  // void mapMode(unsigned int v);
104 
106 
110  // void* map();
111 
113 
117  // bool map(void*& buf);
118 
121  // bool unmap();
122  // #endif
123 
124  protected:
125  unsigned int mType;
126  unsigned int mUsage;
127  // unsigned int mMapMode;
128  size_t mSize;
129  virtual void onCreate();
130  virtual void onDestroy();
131 };
132 
133 } // namespace al
134 #endif
void usage(unsigned int v)
Set buffer usage.
int size() const
Get buffer store size, in bytes.
void bind()
Bind buffer.
unsigned int mType
Set map mode.
virtual void onDestroy()
Called when currently assigned context is destroyed.
virtual void onCreate()
Called when currently assigned context is created.
void bufferType(unsigned int v)
Set buffer type.
void unbind() const
Unbind buffer.
Definition: al_App.hpp:23