Ocean
Buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_GL_BUFFER_H
9 #define META_OCEAN_PLATFORM_GL_BUFFER_H
10 
11 #include "ocean/platform/gl/GL.h"
13 
14 namespace Ocean
15 {
16 
17 namespace Platform
18 {
19 
20 namespace GL
21 {
22 
23 /**
24  * This class implements the base class for all buffers.
25  * @ingroup platformgl
26  */
27 class OCEAN_PLATFORM_GL_EXPORT Buffer : public ContextAssociated
28 {
29  public:
30 
31  /**
32  * Destructs a buffer object.
33  */
34  virtual ~Buffer();
35 
36  /**
37  * Returns the size (the number of elements) this buffer holds.
38  * @return The number of elements
39  */
40  inline size_t size() const;
41 
42  /**
43  * Releases this vertex buffer object.
44  * @return True, if succeeded
45  */
46  bool release();
47 
48  /**
49  * Returns whether this object holds a valid vertex buffer.
50  * @return True, if so
51  */
52  explicit inline operator bool() const;
53 
54  protected:
55 
56  /**
57  * Creates a new vertex buffer object.
58  */
59  inline Buffer();
60 
61  /**
62  * Creates a new buffer object with associated context.
63  * @param context The associated context of the new buffer object
64  */
65  explicit inline Buffer(Context& context);
66 
67  protected:
68 
69  /// The id of the vertex buffer.
70  GLuint bufferId;
71 
72  /// The number of elements the vertex buffer holds.
73  size_t bufferSize;
74 };
75 
76 inline Buffer::Buffer() :
78  bufferId(0u),
79  bufferSize(0)
80 {
81  // nothing to do here
82 }
83 
84 inline Buffer::Buffer(Context& context) :
85  ContextAssociated(context),
86  bufferId(0u),
87  bufferSize(0)
88 {
89  // nothing to do here
90 }
91 
92 inline size_t Buffer::size() const
93 {
94  return bufferSize;
95 }
96 
97 inline Buffer::operator bool() const
98 {
99  return bufferId != 0u;
100 }
101 
102 }
103 
104 }
105 
106 }
107 
108 #endif // META_OCEAN_PLATFORM_GL_BUFFER_H
This class implements the base class for all buffers.
Definition: Buffer.h:28
bool release()
Releases this vertex buffer object.
Buffer()
Creates a new vertex buffer object.
Definition: Buffer.h:76
virtual ~Buffer()
Destructs a buffer object.
size_t size() const
Returns the size (the number of elements) this buffer holds.
Definition: Buffer.h:92
GLuint bufferId
The id of the vertex buffer.
Definition: Buffer.h:70
size_t bufferSize
The number of elements the vertex buffer holds.
Definition: Buffer.h:73
This class implements the base class for all object which have an associated context.
Definition: ContextAssociated.h:31
This class encapsulates an OpenGL context.
Definition: platform/gl/Context.h:29
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15