2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/devel-api/scripting/enum-helper.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/public-api/visuals/visual-properties.h>
29 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
43 DALI_ENUM_TO_STRING_TABLE_BEGIN( SHADER_HINT )
44 DALI_ENUM_TO_STRING_WITH_SCOPE( Shader::Hint, NONE )
45 DALI_ENUM_TO_STRING_WITH_SCOPE( Shader::Hint, OUTPUT_IS_TRANSPARENT )
46 DALI_ENUM_TO_STRING_WITH_SCOPE( Shader::Hint, MODIFIES_GEOMETRY )
47 DALI_ENUM_TO_STRING_TABLE_END( SHADER_HINT )
49 } // unnamed namespace
51 Internal::Visual::Base::Impl::Impl()
52 : mCustomShader(NULL),
58 Internal::Visual::Base::Impl::~Impl()
63 Internal::Visual::Base::Impl::CustomShader::CustomShader( const Property::Map& map )
65 mHints( Shader::Hint::NONE )
67 SetPropertyMap( map );
70 void Internal::Visual::Base::Impl::CustomShader::SetPropertyMap( const Property::Map& shaderMap )
72 mVertexShader.clear();
73 mFragmentShader.clear();
74 mGridSize = ImageDimensions( 1, 1 );
75 mHints = Shader::Hint::NONE;
77 Property::Value* vertexShaderValue = shaderMap.Find( Toolkit::Visual::Shader::Property::VERTEX_SHADER, CUSTOM_VERTEX_SHADER );
78 if( vertexShaderValue )
80 if( !vertexShaderValue->Get( mVertexShader ) )
82 DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string\n", CUSTOM_VERTEX_SHADER );
86 Property::Value* fragmentShaderValue = shaderMap.Find( Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, CUSTOM_FRAGMENT_SHADER );
87 if( fragmentShaderValue )
89 if( !fragmentShaderValue->Get( mFragmentShader ) )
91 DALI_LOG_ERROR( "'%s' parameter does not correctly specify a string\n", CUSTOM_FRAGMENT_SHADER );
95 Property::Value* subdivideXValue = shaderMap.Find( Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X, CUSTOM_SUBDIVIDE_GRID_X );
99 if( !subdivideXValue->Get( subdivideX ) || subdivideX < 1 )
101 DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1\n", CUSTOM_SUBDIVIDE_GRID_X );
105 mGridSize = ImageDimensions( subdivideX, mGridSize.GetY() );
109 Property::Value* subdivideYValue = shaderMap.Find( Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y, CUSTOM_SUBDIVIDE_GRID_Y );
110 if( subdivideYValue )
113 if( !subdivideYValue->Get( subdivideY ) || subdivideY < 1 )
115 DALI_LOG_ERROR( "'%s' parameter does not correctly specify a value greater than 1\n", CUSTOM_SUBDIVIDE_GRID_Y );
119 mGridSize = ImageDimensions( mGridSize.GetX(), subdivideY );
123 Property::Value* hintsValue = shaderMap.Find( Toolkit::Visual::Shader::Property::HINTS, CUSTOM_SHADER_HINTS );
126 if ( ! Scripting::GetBitmaskEnumerationProperty( *hintsValue, SHADER_HINT_TABLE, SHADER_HINT_TABLE_COUNT, mHints ) )
128 DALI_LOG_ERROR( "'%s' parameter does not correctly specify a hint or an array of hint strings\n", CUSTOM_SHADER_HINTS );
133 void Internal::Visual::Base::Impl::CustomShader::CreatePropertyMap( Property::Map& map ) const
135 if( !mVertexShader.empty() || !mFragmentShader.empty() )
137 Property::Map customShader;
138 if( !mVertexShader.empty() )
140 customShader.Insert( Toolkit::Visual::Shader::Property::VERTEX_SHADER, mVertexShader );
142 if( !mFragmentShader.empty() )
144 customShader.Insert( Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, mFragmentShader );
147 if( mGridSize.GetWidth() != 1 )
149 customShader.Insert( Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X, mGridSize.GetWidth() );
151 if( mGridSize.GetHeight() != 1 )
153 customShader.Insert( Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y, mGridSize.GetHeight() );
156 if( mHints != Dali::Shader::Hint::NONE )
158 customShader.Insert( Toolkit::Visual::Shader::Property::HINTS, static_cast< int >( mHints ) );
161 map.Insert( Toolkit::Visual::Property::SHADER, customShader );
165 } // namespace Internal
167 } // namespace Toolkit