1 #ifndef __DALI_INTERNAL_GPU_BUFFER_H__
2 #define __DALI_INTERNAL_GPU_BUFFER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 #include <dali/internal/render/gl-resources/context.h>
22 #include <dali/internal/render/gl-resources/context-observer.h>
31 * Used to create and update a GPU memory buffer.
33 * The buffer can be used for storing vertex data, index arrays (indices)
34 * or pixel data (PBO).
36 * The buffer allows data to be stored in high-performance
37 * graphics memory on the server side and
38 * promotes efficient data transfer.
41 class GpuBuffer : public ContextObserver
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)
52 GpuBuffer(Context& context,GLenum target,GLenum usage);
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
66 void UpdateDataBuffer(GLsizeiptr size,const GLvoid *data);
69 * Bind the buffer object to the target
70 * Will assert if the buffer size is zero
75 * @return true if the GPU buffer is valid, i.e. its created and not empty
77 bool BufferIsValid() const;
80 * Get the size of the buffer
83 GLsizeiptr GetBufferSize() const
88 private: // From Context::Observer
91 * @copydoc ContextObserver::GlContextToBeDestroyed
93 virtual void GlContextToBeDestroyed();
96 * @copydoc ContextObserver::GlContextCreated
98 virtual void GlContextCreated();
103 * Perfoms a bind without checking the size of the buffer
104 * @param bufferId to bind
106 void BindNoChecks(GLuint bufferId) const;
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).
117 } // namespace Internal
121 #endif // __DALI_INTERNAL_GPU_BUFFER_H__