Dali 3D User Interface Engine
material.cpp
Go to the documentation of this file.
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/devel-api/rendering/material.h> // Dali::Material
20 
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/rendering/material-impl.h> // Dali::Internal::Material
23 #include <dali/internal/event/rendering/sampler-impl.h> // Dali::Internal::Sampler
24 #include <dali/internal/event/rendering/shader-impl.h> // Dali::Internal::Shader
25 
26 namespace Dali
27 {
28 
30 {
32  material->SetShader( GetImplementation(shader) );
33 
34  return Material( material.Get() );
35 }
36 
38 {
39 }
40 
42 {
43 }
44 
45 Material::Material( const Material& handle )
46 : Handle( handle )
47 {
48 }
49 
51 {
52  return Material( dynamic_cast<Dali::Internal::Material*>(handle.GetObjectPtr()));
53 }
54 
56 {
57  BaseHandle::operator=( handle );
58  return *this;
59 }
60 
61 void Material::SetShader( Shader& shader )
62 {
63  DALI_ASSERT_ALWAYS( shader && "Shader handle is uninitialized" );
64  GetImplementation(*this).SetShader( GetImplementation( shader ) );
65 }
66 
68 {
69  Internal::Shader* shaderPtr( GetImplementation(*this).GetShader() );
70  return Dali::Shader( shaderPtr );
71 }
72 
73 int Material::AddTexture( Image image, const std::string& uniformName, Sampler sampler)
74 {
75  int index( -1 );
76  if( image )
77  {
78  Internal::ImagePtr imagePtr(&GetImplementation( image ));
79  Internal::SamplerPtr samplerPtr(0);
80  if( sampler )
81  {
82  samplerPtr = &GetImplementation( sampler );
83  }
84 
85  index = GetImplementation(*this).AddTexture( imagePtr, uniformName, samplerPtr );
86  }
87  else
88  {
89  DALI_LOG_ERROR("Error adding invalid texture %s to material", uniformName.c_str() );
90  }
91  return index;
92 }
93 
94 void Material::RemoveTexture( size_t index )
95 {
96  GetImplementation(*this).RemoveTexture( index );
97 }
98 
99 void Material::SetTextureImage( size_t index, Image image )
100 {
101  if( image )
102  {
103  Internal::Image* imagePtr(0);
104  imagePtr = &GetImplementation( image );
105  GetImplementation(*this).SetTextureImage( index, imagePtr );
106  }
107 }
108 
109 void Material::SetTextureSampler( size_t index, Sampler sampler )
110 {
111  Internal::Sampler* samplerPtr(0);
112  if( sampler )
113  {
114  samplerPtr = &GetImplementation( sampler );
115  }
116 
117  GetImplementation(*this).SetTextureSampler( index, samplerPtr );
118 }
119 
121 {
122  Internal::Sampler* samplerPtr( GetImplementation(*this).GetTextureSampler( index ) );
123  return Dali::Sampler( samplerPtr );
124 }
125 
126 void Material::SetTextureUniformName( size_t index, const std::string& uniformName )
127 {
128  GetImplementation(*this).SetTextureUniformName( index, uniformName );
129 }
130 
131 int Material::GetTextureIndex( const std::string& uniformName ) const
132 {
133  return GetImplementation(*this).GetTextureIndex( uniformName );
134 }
135 
136 Image Material::GetTexture( const std::string& uniformName ) const
137 {
138  Internal::Image* imagePtr( GetImplementation(*this).GetTexture( uniformName ) );
139  return Dali::Image( imagePtr );
140 }
141 
142 Image Material::GetTexture( size_t index ) const
143 {
144  Internal::Image* imagePtr( GetImplementation(*this).GetTexture( index ) );
145  return Dali::Image( imagePtr );
146 }
147 
148 std::size_t Material::GetNumberOfTextures() const
149 {
150  return GetImplementation(*this).GetNumberOfTextures();
151 }
152 
153 
155 : Handle( pointer )
156 {
157 }
158 
159 } //namespace Dali
Dali Docs Home
Read more about Dali