1 #ifndef __DALI_INTEGRATION_SHADER_DATA_H__
2 #define __DALI_INTEGRATION_SHADER_DATA_H__
5 * Copyright (c) 2014 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/vector-wrapper.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
48 * @param[in] vertexSource Source code for vertex program
49 * @param[in] fragmentSource Source code for fragment program
51 ShaderData(const std::string& vertexSource, const std::string& fragmentSource)
53 mVertexShader(vertexSource),
54 mFragmentShader(fragmentSource),
60 * Protected Destructor
61 * A reference counted object may only be deleted by calling Unreference()
65 // vector releases its data
71 * Set hash value which is created with vertex and fragment shader code
72 * @param [in] shaderHash hash key created with vertex and fragment shader code
74 void SetHashValue(size_t shaderHash)
76 mShaderHash = shaderHash;
80 * Get hash value which is created with vertex and fragment shader code
81 * @return shaderHash hash key created with vertex and fragment shader code
89 * @return the vertex shader
91 const char* GetVertexShader()
93 return mVertexShader.c_str();
97 * @return the vertex shader
99 const char* GetFragmentShader()
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 if( size > mBuffer.size() )
121 mBuffer.resize( size );
126 * Get the program buffer
127 * @return reference to the buffer
129 size_t GetBufferSize()
131 return mBuffer.size();
135 * Get the data that the buffer points to
136 * @return raw pointer to the buffer data
138 unsigned char* GetBufferData()
140 DALI_ASSERT_DEBUG( mBuffer.size() > 0 );
145 * Get the data that the buffer points to
146 * @TODO TO BE REMOVED WHEN PLATFORM ABSTRACTION FOR SHADER LOAD/STORE IS FIXED
147 * @return raw pointer to the buffer data
149 std::vector<unsigned char>& GetBuffer()
155 * Set the resource id
158 void SetResourceId( ResourceId resourceId )
160 mResourceId = resourceId;
164 * Get the resource id
167 ResourceId GetResourceId()
172 private: // Not implemented
174 ShaderData(const ShaderData& other); ///< no copying of this object
175 ShaderData& operator= (const ShaderData& rhs); ///< no copying of this object
179 size_t mShaderHash; ///< hash key created with vertex and fragment shader code
180 std::string mVertexShader; ///< source code for vertex program
181 std::string mFragmentShader; ///< source code for fragment program
182 std::vector<unsigned char> mBuffer; ///< buffer containing compiled binary bytecode
183 ResourceId mResourceId; ///< resource id
187 } // namespace Integration
191 #endif // __DALI_INTEGRATION_SHADER_DATA_H__