License conversion from Flora to Apache 2.0
[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) 2014 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/vector-wrapper.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33
34 class ShaderData;
35
36 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
37
38 /**
39  * ShaderData class.
40  * A container for shader source code and compiled binary byte code
41  */
42 class DALI_IMPORT_API ShaderData : public Dali::RefObject
43 {
44 public:
45   /**
46    * Constructor
47    * @param[in] vertexSource   Source code for vertex program
48    * @param[in] fragmentSource Source code for fragment program
49    */
50   ShaderData(const std::string& vertexSource, const std::string& fragmentSource);
51
52 protected:
53   /**
54    * Protected Destructor
55    * A reference counted object may only be deleted by calling Unreference()
56    */
57   virtual ~ShaderData();
58
59 public:
60   /**
61    * Check whether there is a compiled binary available
62    * @return true if this objects contains a compiled binary
63    */
64   bool HasBinary() const;
65
66   /**
67    * Allocate a buffer for the compiled binary bytecode
68    * @param[in] size  The size of the buffer in bytes
69    */
70   void AllocateBuffer(const unsigned int size);
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) { mShaderHash = shaderHash; }
77
78   /**
79    * Get hash value which is created with vertex and fragment shader code
80    * @return shaderHash  hash key created with vertex and fragment shader code
81    */
82   size_t GetHashValue() { return mShaderHash; }
83
84 private:
85   ShaderData(const ShaderData& other);            ///< defined private to prevent use
86   ShaderData& operator= (const ShaderData& rhs);  ///< defined private to prevent use
87
88 public: // Attributes
89   size_t                     mShaderHash;         ///< hash key created with vertex and fragment shader code
90   const std::string          vertexShader;        ///< source code for vertex program
91   const std::string          fragmentShader;      ///< source code for fragment program
92   std::vector<unsigned char> buffer;              ///< buffer containing compiled binary bytecode
93 };
94
95 } // namespace Integration
96
97 } // namespace Dali
98
99 #endif // __DALI_INTEGRATION_SHADER_DATA_H__