1 #ifndef __DALI_INTEGRATION_SHADER_DATA_H__
2 #define __DALI_INTEGRATION_SHADER_DATA_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
37 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
41 * A container for shader source code and compiled binary byte code.
43 class ShaderData : public Dali::RefObject
47 static const size_t UNINITIALISED_HASH_VALUE;
51 * @param[in] vertexSource Source code for vertex program
52 * @param[in] fragmentSource Source code for fragment program
54 ShaderData(const std::string& vertexSource, const std::string& fragmentSource)
55 : mShaderHash( UNINITIALISED_HASH_VALUE ),
56 mVertexShader(vertexSource),
57 mFragmentShader(fragmentSource)
62 * Protected Destructor
63 * A reference counted object may only be deleted by calling Unreference()
67 // vector releases its data
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
76 void SetHashValue(size_t shaderHash)
78 DALI_ASSERT_DEBUG( shaderHash != 0 );
79 mShaderHash = shaderHash;
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
86 size_t GetHashValue() const
88 DALI_ASSERT_DEBUG( mShaderHash != UNINITIALISED_HASH_VALUE );
93 * @return the vertex shader
95 const char* GetVertexShader() const
97 return mVertexShader.c_str();
101 * @return the vertex shader
103 const char* GetFragmentShader() const
105 return mFragmentShader.c_str();
109 * Check whether there is a compiled binary available
110 * @return true if this objects contains a compiled binary
112 bool HasBinary() const
114 return 0 != mBuffer.Size();
118 * Allocate a buffer for the compiled binary bytecode
119 * @param[in] size The size of the buffer in bytes
121 void AllocateBuffer( size_t size )
123 mBuffer.Resize( size );
127 * Get the program buffer
128 * @return reference to the buffer
130 size_t GetBufferSize() const
132 return mBuffer.Size();
136 * Get the data that the buffer points to
137 * @return raw pointer to the buffer data
139 unsigned char* GetBufferData()
141 DALI_ASSERT_DEBUG( mBuffer.Size() > 0 );
146 * Get the data that the buffer points to
147 * @return raw pointer to the buffer data
149 Dali::Vector<unsigned char>& GetBuffer()
154 private: // Not implemented
156 ShaderData(const ShaderData& other); ///< no copying of this object
157 ShaderData& operator= (const ShaderData& rhs); ///< no copying of this object
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
167 } // namespace Integration
171 #endif // __DALI_INTEGRATION_SHADER_DATA_H__