qxLib
buffer_base.h
Go to the documentation of this file.
1 /**
2 
3  @file buffer_base.h
4  @author Khrapov
5  @date 19.01.2020
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
11 #include <qx/gl/ibuffer.h>
12 #include <qx/typedefs.h>
13 
14 namespace qx
15 {
16 
17 /**
18 
19  @class buffer_base
20  @brief Base OpenGL buffer object class
21  @details ~
22  @author Khrapov
23  @date 10.07.2020
24 
25 **/
26 class buffer_base : public IBuffer
27 {
28 public:
29  virtual ~buffer_base();
30 
31  QX_DECL_IBUFFER
32 
33  /**
34  @brief Defines a barrier ordering memory transactions
35  **/
36  virtual void MemBarrier();
37 
38  /**
39  @brief Allocate memory for the buffer
40  @param nSize - data size
41  @param pData - data pointer
42  @param eUsage - the expected usage pattern of the data store
43  **/
44  virtual void Allocate(GLsizeiptr nSize, const void* pData = nullptr, GLenum eUsage = GL_DYNAMIC_DRAW);
45 
46  /**
47  @brief Update buffer
48  @param pData - data pointer
49  @param nSize - data size
50  @param nOffset - offset from the buffer beginning
51  **/
52  virtual void Update(const void* pData, GLsizeiptr nSize, GLintptr nOffset = 0);
53 
54 protected:
55  /**
56  @brief Get buffer type
57  @retval - buffer type
58  **/
59  virtual GLenum GetBufferType() const = 0;
60 
61  /**
62  @brief Get buffer type barrier bit
63  @retval - buffer type barrier bit
64  **/
65  virtual GLbitfield GetBarrierBit() const = 0;
66 
67 private:
68  GLuint m_nBuffer = std::numeric_limits<GLuint>::max();
69 };
70 
71 #define QX_DECL_BUFFER_BASE \
72  virtual GLenum GetBufferType() const override; \
73  virtual GLbitfield GetBarrierBit() const override;
74 
75 } // namespace qx
76 
77 #include <qx/gl/buffer_base.inl>
OpenGL buffer interface.
Definition: ibuffer.h:26
Base OpenGL buffer object class.
Definition: buffer_base.h:27
virtual GLenum GetBufferType() const =0
Get buffer type.
virtual GLbitfield GetBarrierBit() const =0
Get buffer type barrier bit.
virtual void Allocate(GLsizeiptr nSize, const void *pData=nullptr, GLenum eUsage=GL_DYNAMIC_DRAW)
Allocate memory for the buffer.
Definition: buffer_base.inl:52
virtual QX_DECL_IBUFFER void MemBarrier()
Defines a barrier ordering memory transactions.
Definition: buffer_base.inl:47
virtual void Update(const void *pData, GLsizeiptr nSize, GLintptr nOffset=0)
Update buffer.
Definition: buffer_base.inl:57