1 #ifndef __DALI_INTERNAL_SHADER_DATA_H__
2 #define __DALI_INTERNAL_SHADER_DATA_H__
5 * Copyright (c) 2018 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/public-api/rendering/shader.h> // ShaderHints
36 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
40 * A container for shader source code and compiled binary byte code.
42 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, const Dali::Shader::Hint::Value hints)
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 DALI_ASSERT_DEBUG( shaderHash != size_t(-1) );
77 mShaderHash = shaderHash;
81 * Get hash value which is created with vertex and fragment shader code
82 * @return shaderHash hash key created with vertex and fragment shader code
84 size_t GetHashValue() const
86 DALI_ASSERT_DEBUG( mShaderHash != size_t(-1) );
91 * @return the vertex shader
93 const char* GetVertexShader() const
95 return mVertexShader.c_str();
99 * @return the vertex shader
101 const char* GetFragmentShader() const
103 return mFragmentShader.c_str();
109 Dali::Shader::Hint::Value GetHints() const
114 * Check whether there is a compiled binary available
115 * @return true if this objects contains a compiled binary
117 bool HasBinary() const
119 return 0 != mBuffer.Size();
123 * Allocate a buffer for the compiled binary bytecode
124 * @param[in] size The size of the buffer in bytes
126 void AllocateBuffer( std::size_t size )
128 mBuffer.Resize( size );
132 * Get the program buffer
133 * @return reference to the buffer
135 std::size_t GetBufferSize() const
137 return mBuffer.Size();
141 * Get the data that the buffer points to
142 * @return raw pointer to the buffer data
144 uint8_t* GetBufferData()
146 DALI_ASSERT_DEBUG( mBuffer.Size() > 0 );
151 * Get the data that the buffer points to
152 * @return raw pointer to the buffer data
154 Dali::Vector<uint8_t>& GetBuffer()
159 private: // Not implemented
161 ShaderData(const ShaderData& other); ///< no copying of this object
162 ShaderData& operator= (const ShaderData& rhs); ///< no copying of this object
166 std::size_t mShaderHash; ///< hash key created with vertex and fragment shader code
167 std::string mVertexShader; ///< source code for vertex program
168 std::string mFragmentShader; ///< source code for fragment program
169 Dali::Shader::Hint::Value mHints; ///< take a hint
170 Dali::Vector<uint8_t> mBuffer; ///< buffer containing compiled binary bytecode
174 } // namespace Integration
178 #endif // __DALI_INTERNAL_SHADER_DATA_H__