Removed legacy resource tracking / logging
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / gpu-buffer.h
1 #ifndef __DALI_INTERNAL_GPU_BUFFER_H__
2 #define __DALI_INTERNAL_GPU_BUFFER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/render/gl-resources/context.h>
22 #include <dali/internal/render/gl-resources/context-observer.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 /**
31  * Used to create and update a GPU memory buffer.
32  *
33  * The buffer can be used for storing vertex data, index arrays (indices)
34  * or pixel data (PBO).
35  *
36  * The buffer allows data to be stored in high-performance
37  * graphics memory on the server side and
38  * promotes efficient data transfer.
39  *
40  */
41 class GpuBuffer : public ContextObserver
42 {
43
44 public:
45
46   /**
47    * constructor
48    * @param context drawing context
49    * @param target the type of buffer to create (GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER)
50    * @param usage how the buffer will be used (see GL_STATIC_DRAW)
51    */
52   GpuBuffer(Context& context,GLenum target,GLenum usage);
53
54   /**
55    * Destructor
56    */
57   virtual ~GpuBuffer();
58
59   /**
60    *
61    * Creates or updates a buffer object and binds it to the target.
62    * @param size Specifies the size in bytes of the buffer object's new data store.
63    * @param data pointer to the data to load
64    *
65    */
66   void UpdateDataBuffer(GLsizeiptr size,const GLvoid *data);
67
68   /**
69    * Bind the buffer object to the target
70    * Will assert if the buffer size is zero
71    */
72   void Bind() const;
73
74   /**
75    * @return true if the GPU buffer is valid, i.e. its created and not empty
76    */
77   bool BufferIsValid() const;
78
79   /**
80    * Get the size of the buffer
81    * @return size
82    */
83   GLsizeiptr GetBufferSize() const
84   {
85     return mSize;
86   }
87
88 private: // From Context::Observer
89
90   /**
91    * @copydoc ContextObserver::GlContextToBeDestroyed
92    */
93   virtual void GlContextToBeDestroyed();
94
95   /**
96    * @copydoc ContextObserver::GlContextCreated
97    */
98   virtual void GlContextCreated();
99
100 private:
101
102   /**
103    * Perfoms a bind without checking the size of the buffer
104    * @param bufferId to bind
105    */
106   void BindNoChecks(GLuint bufferId) const;
107
108   GLsizeiptr         mCapacity;            ///< buffer capacity
109   GLsizeiptr         mSize;                ///< buffer size
110   Context&           mContext;             ///< dali drawing context
111   GLuint             mBufferId;            ///< buffer object name(id)
112   bool               mBufferCreated;       ///< whether buffer has been created
113   GLenum             mTarget;              ///< type of buffer (array/element)
114   GLenum             mUsage;               ///< how the buffer is used (read, read/write etc).
115 };
116
117 } // namespace Internal
118
119 } // namespace Dali
120
121 #endif // __DALI_INTERNAL_GPU_BUFFER_H__