1 #ifndef __DALI_INTERNAL_SHADER_DATA_H__
2 #define __DALI_INTERNAL_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>
35 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
39 * A container for shader source code and compiled binary byte code.
41 class ShaderData : public Dali::RefObject
47 * @param[in] vertexSource Source code for vertex program
48 * @param[in] fragmentSource Source code for fragment program
50 ShaderData(const std::string& vertexSource, const std::string& fragmentSource)
52 mVertexShader(vertexSource),
53 mFragmentShader(fragmentSource)
58 * Protected Destructor
59 * A reference counted object may only be deleted by calling Unreference()
63 // vector releases its data
69 * Set hash value which is created with vertex and fragment shader code
70 * @param [in] shaderHash hash key created with vertex and fragment shader code
72 void SetHashValue(size_t shaderHash)
74 DALI_ASSERT_DEBUG( shaderHash != size_t(-1) );
75 mShaderHash = shaderHash;
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
82 size_t GetHashValue() const
84 DALI_ASSERT_DEBUG( mShaderHash != size_t(-1) );
89 * @return the vertex shader
91 const char* GetVertexShader() const
93 return mVertexShader.c_str();
97 * @return the vertex shader
99 const char* GetFragmentShader() const
101 return mFragmentShader.c_str();
105 * Check whether there is a compiled binary available
106 * @return true if this objects contains a compiled binary
108 bool HasBinary() const
110 return 0 != mBuffer.Size();
114 * Allocate a buffer for the compiled binary bytecode
115 * @param[in] size The size of the buffer in bytes
117 void AllocateBuffer( size_t size )
119 mBuffer.Resize( size );
123 * Get the program buffer
124 * @return reference to the buffer
126 size_t GetBufferSize() const
128 return mBuffer.Size();
132 * Get the data that the buffer points to
133 * @return raw pointer to the buffer data
135 unsigned char* GetBufferData()
137 DALI_ASSERT_DEBUG( mBuffer.Size() > 0 );
142 * Get the data that the buffer points to
143 * @return raw pointer to the buffer data
145 Dali::Vector<unsigned char>& GetBuffer()
150 private: // Not implemented
152 ShaderData(const ShaderData& other); ///< no copying of this object
153 ShaderData& operator= (const ShaderData& rhs); ///< no copying of this object
157 size_t mShaderHash; ///< hash key created with vertex and fragment shader code
158 std::string mVertexShader; ///< source code for vertex program
159 std::string mFragmentShader; ///< source code for fragment program
160 Dali::Vector<unsigned char> mBuffer; ///< buffer containing compiled binary bytecode
163 } // namespace Integration
167 #endif // __DALI_INTERNAL_SHADER_DATA_H__