Merge Handle & Constrainable
[platform/core/uifw/dali-core.git] / dali / public-api / shader-effects / shader-effect.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/shader-effects/shader-effect.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/effects/shader-effect-impl.h>
23 #include <dali/internal/event/animation/constraint-impl.h>
24 #include <dali/public-api/animation/constraint.h>
25 #include <dali/public-api/math/vector2.h>
26
27 namespace Dali
28 {
29 const float ShaderEffect::DEFAULT_GRID_DENSITY = 40;
30
31 ShaderEffect::Extension::Extension()
32 {
33 }
34
35 ShaderEffect::Extension::~Extension()
36 {
37 }
38
39 ShaderEffect::ShaderEffect()
40 {
41 }
42
43 ShaderEffect::ShaderEffect(Internal::ShaderEffect* internal)
44 : Handle(internal)
45 {
46 }
47
48 ShaderEffect::~ShaderEffect()
49 {
50 }
51
52 ShaderEffect::ShaderEffect(const ShaderEffect& handle)
53 : Handle(handle)
54 {
55 }
56
57 ShaderEffect& ShaderEffect::operator=(const ShaderEffect& rhs)
58 {
59   BaseHandle::operator=(rhs);
60   return *this;
61 }
62
63 ShaderEffect ShaderEffect::New( const std::string& vertexShader, const std::string& fragmentShader, GeometryType type, GeometryHints hints)
64 {
65   Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
66
67   internal->SetPrograms( type, vertexShader, fragmentShader );
68
69   return ShaderEffect( internal.Get() );
70 }
71
72 ShaderEffect ShaderEffect::NewWithPrefix( const std::string& vertexShaderPrefix,
73                                           const std::string& vertexShader,
74                                           const std::string& fragmentShaderPrefix,
75                                           const std::string& fragmentShader,
76                                           GeometryType type,
77                                           GeometryHints hints)
78 {
79   Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
80
81   internal->SetPrograms( type, vertexShaderPrefix, fragmentShaderPrefix, vertexShader, fragmentShader );
82
83   return ShaderEffect( internal.Get() );
84 }
85
86 ShaderEffect ShaderEffect::New( const std::string& imageVertexShader,
87                                 const std::string& imageFragmentShader,
88                                 const std::string& textVertexShader,
89                                 const std::string& textFragmentShader,
90                                 GeometryHints hints)
91 {
92   Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
93
94   internal->SetPrograms( GEOMETRY_TYPE_IMAGE, imageVertexShader, imageFragmentShader );
95   internal->SetPrograms( GEOMETRY_TYPE_TEXT, textVertexShader, textFragmentShader );
96
97   return ShaderEffect( internal.Get() );
98 }
99
100 ShaderEffect ShaderEffect::New( const std::string& imageVertexShader,
101                                 const std::string& imageFragmentShader,
102                                 const std::string& textVertexShader,
103                                 const std::string& textFragmentShader,
104                                 const std::string& texturedMeshVertexShader,
105                                 const std::string& texturedMeshFragmentShader,
106                                 const std::string& meshVertexShader,
107                                 const std::string& meshFragmentShader,
108                                 GeometryHints hints)
109 {
110   Internal::ShaderEffectPtr internal = Internal::ShaderEffect::New( hints );
111
112   internal->SetPrograms( GEOMETRY_TYPE_IMAGE, imageVertexShader, imageFragmentShader );
113   internal->SetPrograms( GEOMETRY_TYPE_TEXT, textVertexShader, textFragmentShader );
114   internal->SetPrograms( GEOMETRY_TYPE_TEXTURED_MESH, texturedMeshVertexShader, texturedMeshFragmentShader );
115   internal->SetPrograms( GEOMETRY_TYPE_UNTEXTURED_MESH, meshVertexShader, meshFragmentShader );
116
117   return ShaderEffect( internal.Get() );
118 }
119
120 ShaderEffect ShaderEffect::DownCast( BaseHandle handle )
121 {
122   return ShaderEffect( dynamic_cast<Dali::Internal::ShaderEffect*>(handle.GetObjectPtr()) );
123 }
124
125 void ShaderEffect::SetEffectImage( Image image )
126 {
127   GetImplementation(*this).SetEffectImage( image );
128 }
129
130 void ShaderEffect::SetUniform( const std::string& name, float value, UniformCoordinateType uniformCoordinateType )
131 {
132   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
133 }
134
135 void ShaderEffect::SetUniform( const std::string& name, Vector2 value, UniformCoordinateType uniformCoordinateType )
136 {
137   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
138 }
139
140 void ShaderEffect::SetUniform( const std::string& name, Vector3 value, UniformCoordinateType uniformCoordinateType )
141 {
142   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
143 }
144
145 void ShaderEffect::SetUniform( const std::string& name, Vector4 value, UniformCoordinateType uniformCoordinateType )
146 {
147   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
148 }
149
150 void ShaderEffect::SetUniform( const std::string& name, const Matrix& value, UniformCoordinateType uniformCoordinateType )
151 {
152   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
153 }
154
155 void ShaderEffect::SetUniform( const std::string& name, const Matrix3& value, UniformCoordinateType uniformCoordinateType )
156 {
157   GetImplementation(*this).SetUniform( name, value, uniformCoordinateType );
158 }
159
160 void ShaderEffect::AttachExtension( ShaderEffect::Extension *object )
161 {
162   GetImplementation(*this).AttachExtension( object );
163 }
164
165 ShaderEffect::Extension& ShaderEffect::GetExtension()
166 {
167   return GetImplementation(*this).GetExtension();
168 }
169
170 const ShaderEffect::Extension& ShaderEffect::GetExtension() const
171 {
172   return GetImplementation(*this).GetExtension();
173 }
174
175 } // namespace Dali