3a13458ddcf6ca83ed5ca1e8ebb9e4801678da17
[platform/core/uifw/dali-core.git] / dali / public-api / shader-effects / material.cpp
1 /*
2  * Copyright (c) 2015 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/material.h>  // Dali::Material
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/effects/material-impl.h> // Dali::Internal::Material
23 #include <dali/internal/event/effects/sampler-impl.h> // Dali::Internal::Sampler
24 #include <dali/internal/event/effects/shader-impl.h> // Dali::Internal::Shader
25
26 namespace Dali
27 {
28
29 Material Material::New( Shader shader )
30 {
31   // TODO: MESH_REWORK
32   Internal::MaterialPtr material = Internal::Material::New();
33   material->SetShader( GetImplementation(shader) );
34
35   return Material( material.Get() );
36 }
37
38 Material::Material()
39 {
40 }
41
42 Material::~Material()
43 {
44 }
45
46 Material::Material( const Material& handle )
47 : Handle( handle )
48 {
49 }
50
51 Material Material::DownCast( BaseHandle handle )
52 {
53   return Material( dynamic_cast<Dali::Internal::Material*>(handle.GetObjectPtr()));
54 }
55
56 Material& Material::operator=( const Material& handle )
57 {
58   BaseHandle::operator=( handle );
59   return *this;
60 }
61
62 void Material::SetShader( Shader& shader )
63 {
64   DALI_ASSERT_ALWAYS( shader && "Shader handle is uninitialized" );
65   GetImplementation(*this).SetShader( GetImplementation( shader ) );
66 }
67
68 void Material::AddSampler( Sampler& sampler )
69 {
70   DALI_ASSERT_ALWAYS( sampler && "Sampler handle is uninitialized" );
71   GetImplementation(*this).AddSampler( GetImplementation( sampler ) );
72 }
73
74 std::size_t Material::GetNumberOfSamplers() const
75 {
76   return GetImplementation(*this).GetNumberOfSamplers();
77 }
78
79 void Material::RemoveSampler( std::size_t index )
80 {
81   GetImplementation(*this).RemoveSampler( index );
82 }
83
84 void Material::SetFaceCullingMode( FaceCullingMode cullingMode )
85 {
86   GetImplementation(*this).SetFaceCullingMode( cullingMode );
87 }
88
89 void Material::SetBlendMode( BlendingMode::Type mode )
90 {
91   GetImplementation(*this).SetBlendMode( mode );
92 }
93
94 BlendingMode::Type Material::GetBlendMode() const
95 {
96   return GetImplementation(*this).GetBlendMode();
97 }
98
99 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgba,
100                              BlendingFactor::Type destFactorRgba )
101 {
102   GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
103 }
104
105 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
106                              BlendingFactor::Type destFactorRgb,
107                              BlendingFactor::Type srcFactorAlpha,
108                              BlendingFactor::Type destFactorAlpha )
109 {
110   GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
111 }
112
113 void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
114                              BlendingFactor::Type& destFactorRgb,
115                              BlendingFactor::Type& srcFactorAlpha,
116                              BlendingFactor::Type& destFactorAlpha ) const
117 {
118   GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
119 }
120
121 void Material::SetBlendEquation( BlendingEquation::Type equationRgba )
122 {
123   GetImplementation(*this).SetBlendEquation( equationRgba );
124 }
125
126 void Material::SetBlendEquation( BlendingEquation::Type equationRgb,
127                                  BlendingEquation::Type equationAlpha )
128 {
129   GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
130 }
131
132 void Material::GetBlendEquation( BlendingEquation::Type& equationRgb,
133                                  BlendingEquation::Type& equationAlpha ) const
134 {
135   GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
136 }
137
138 void Material::SetBlendColor( const Vector4& color )
139 {
140   GetImplementation(*this).SetBlendColor( color );
141 }
142
143 const Vector4& Material::GetBlendColor() const
144 {
145   return GetImplementation(*this).GetBlendColor();
146 }
147
148 Material::Material( Internal::Material* pointer )
149 : Handle( pointer )
150 {
151 }
152
153 } //namespace Dali