Merge "Remove RenderableActor" into devel/master
[platform/core/uifw/dali-core.git] / dali / integration-api / shader-data.h
1 #ifndef __DALI_INTEGRATION_SHADER_DATA_H__
2 #define __DALI_INTEGRATION_SHADER_DATA_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/integration-api/resource-declarations.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34
35 class ShaderData;
36
37 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
38
39 /**
40  * ShaderData class.
41  * A container for shader source code and compiled binary byte code.
42  */
43 class ShaderData : public Dali::RefObject
44 {
45 public:
46
47   static const size_t UNINITIALISED_HASH_VALUE;
48
49   /**
50    * Constructor
51    * @param[in] vertexSource   Source code for vertex program
52    * @param[in] fragmentSource Source code for fragment program
53    */
54   ShaderData(const std::string& vertexSource, const std::string& fragmentSource)
55   : mShaderHash( UNINITIALISED_HASH_VALUE ),
56     mVertexShader(vertexSource),
57     mFragmentShader(fragmentSource)
58   { }
59
60 protected:
61   /**
62    * Protected Destructor
63    * A reference counted object may only be deleted by calling Unreference()
64    */
65   virtual ~ShaderData()
66   {
67     // vector releases its data
68   }
69
70 public: // API
71
72   /**
73    * Set hash value which is created with vertex and fragment shader code
74    * @param [in] shaderHash  hash key created with vertex and fragment shader code
75    */
76   void SetHashValue(size_t shaderHash)
77   {
78     DALI_ASSERT_DEBUG( shaderHash != 0 );
79     mShaderHash = shaderHash;
80   }
81
82   /**
83    * Get hash value which is created with vertex and fragment shader code
84    * @return shaderHash  hash key created with vertex and fragment shader code
85    */
86   size_t GetHashValue() const
87   {
88     DALI_ASSERT_DEBUG( mShaderHash != UNINITIALISED_HASH_VALUE );
89     return mShaderHash;
90   }
91
92   /**
93    * @return the vertex shader
94    */
95   const char* GetVertexShader() const
96   {
97     return mVertexShader.c_str();
98   }
99
100   /**
101    * @return the vertex shader
102    */
103   const char* GetFragmentShader() const
104   {
105     return mFragmentShader.c_str();
106   }
107
108   /**
109    * Check whether there is a compiled binary available
110    * @return true if this objects contains a compiled binary
111    */
112   bool HasBinary() const
113   {
114     return 0 != mBuffer.Size();
115   }
116
117   /**
118    * Allocate a buffer for the compiled binary bytecode
119    * @param[in] size  The size of the buffer in bytes
120    */
121   void AllocateBuffer( size_t size )
122   {
123     mBuffer.Resize( size );
124   }
125
126   /**
127    * Get the program buffer
128    * @return reference to the buffer
129    */
130   size_t GetBufferSize() const
131   {
132     return mBuffer.Size();
133   }
134
135   /**
136    * Get the data that the buffer points to
137    * @return raw pointer to the buffer data
138    */
139   unsigned char* GetBufferData()
140   {
141     DALI_ASSERT_DEBUG( mBuffer.Size() > 0 );
142     return &mBuffer[0];
143   }
144
145   /**
146    * Get the data that the buffer points to
147    * @return raw pointer to the buffer data
148    */
149   Dali::Vector<unsigned char>& GetBuffer()
150   {
151     return mBuffer;
152   }
153
154 private: // Not implemented
155
156   ShaderData(const ShaderData& other);            ///< no copying of this object
157   ShaderData& operator= (const ShaderData& rhs);  ///< no copying of this object
158
159 private: // Data
160
161   size_t                      mShaderHash;     ///< hash key created with vertex and fragment shader code
162   std::string                 mVertexShader;   ///< source code for vertex program
163   std::string                 mFragmentShader; ///< source code for fragment program
164   Dali::Vector<unsigned char> mBuffer;         ///< buffer containing compiled binary bytecode
165 };
166
167 } // namespace Integration
168
169 } // namespace Dali
170
171 #endif // __DALI_INTEGRATION_SHADER_DATA_H__