From: Kimmo Hoikka Date: Wed, 25 Feb 2015 11:05:20 +0000 (-0800) Subject: Merge "Updates after Handle/Constrainable merge" into tizen X-Git-Tag: dali_1.0.32~13 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=6d762b4acd946b3d02e76c1805e7af9a1a5b1809;hp=4b38b709efae6ba534f7d336b70dabb74c804e03 Merge "Updates after Handle/Constrainable merge" into tizen --- diff --git a/dali-toolkit/dali-toolkit.h b/dali-toolkit/dali-toolkit.h index 942e62d..70f9652 100644 --- a/dali-toolkit/dali-toolkit.h +++ b/dali-toolkit/dali-toolkit.h @@ -111,6 +111,7 @@ #include #include #include +#include #include #include #include diff --git a/dali-toolkit/public-api/file.list b/dali-toolkit/public-api/file.list index 1b9307a..85a3702 100755 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@ -85,6 +85,7 @@ public_api_src_files = \ $(public_api_src_dir)/shader-effects/overlay-effect.cpp \ $(public_api_src_dir)/shader-effects/page-turn-book-spine-effect.cpp \ $(public_api_src_dir)/shader-effects/page-turn-effect.cpp \ + $(public_api_src_dir)/shader-effects/quadratic-bezier.cpp \ $(public_api_src_dir)/shader-effects/ripple-effect.cpp \ $(public_api_src_dir)/shader-effects/ripple2d-effect.cpp \ $(public_api_src_dir)/shader-effects/shear-effect.cpp \ @@ -250,6 +251,7 @@ public_api_shader_effects_header_files = \ $(public_api_src_dir)/shader-effects/overlay-effect.h \ $(public_api_src_dir)/shader-effects/page-turn-book-spine-effect.h \ $(public_api_src_dir)/shader-effects/page-turn-effect.h \ + $(public_api_src_dir)/shader-effects/quadratic-bezier.h \ $(public_api_src_dir)/shader-effects/ripple-effect.h \ $(public_api_src_dir)/shader-effects/ripple2d-effect.h \ $(public_api_src_dir)/shader-effects/shear-effect.h \ diff --git a/dali-toolkit/public-api/shader-effects/quadratic-bezier.cpp b/dali-toolkit/public-api/shader-effects/quadratic-bezier.cpp new file mode 100644 index 0000000..7c8965c --- /dev/null +++ b/dali-toolkit/public-api/shader-effects/quadratic-bezier.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +//CLASS HEADER +#include + +//EXTERNAL HEADERS +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace +{ +const char* POINT_PROPERTY_NAME( "uPoint" ); +const char* LINEWIDTH_PROPERTY_NAME( "uLineWidth" ); +const char* COLOR_PROPERTY_NAME( "uColor" ); +} // namespace + +QuadraticBezier::QuadraticBezier() +{ +} + +//Call the Parent copy constructor to add reference to the implementation for this object +QuadraticBezier::QuadraticBezier(ShaderEffect handle) +:ShaderEffect(handle) +{ +} + +QuadraticBezier::~QuadraticBezier() +{ +} + +QuadraticBezier QuadraticBezier::New(unsigned int pointCount, bool filled ) +{ + std::string vertexShader = DALI_COMPOSE_SHADER + ( + uniform mediump vec3 uPoint[MAX_POINT_COUNT];\n + varying highp vec2 vCoefficient; + void main()\n + {\n + int vertexId = int(aNormal.z);\n + gl_Position = uMvpMatrix * vec4(uPoint[vertexId], 1.0);\n + vCoefficient = aNormal.xy;\n + }\n + ); + + std::string fragmentShader; + + if( filled ) + { + fragmentShader = DALI_COMPOSE_SHADER + ( + varying highp vec2 vCoefficient;\n + + void main()\n + {\n + highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n + highp float Cdx = dFdx(C);\n + highp float Cdy = dFdy(C);\n + + highp float distance = float(C / sqrt(Cdx*Cdx + Cdy*Cdy));\n + + gl_FragColor = uColor;\n + highp float alpha = 0.5 - distance;\n + if( alpha < 0.0 )\n + discard;\n + + gl_FragColor.w = alpha;\n + }\n + ); + } + else + { + fragmentShader = DALI_COMPOSE_SHADER + ( + varying highp vec2 vCoefficient;\n + uniform lowp float uLineWidth;\n + + void main()\n + {\n + highp float C = (vCoefficient.x*vCoefficient.x-vCoefficient.y);\n + highp float Cdx = dFdx(C);\n + highp float Cdy = dFdy(C);\n + highp float distance = abs(float(C / sqrt(Cdx*Cdx + Cdy*Cdy)));\n + gl_FragColor = uColor*(uLineWidth-distance);\n + }\n + ); + } + + std::ostringstream vertexShaderPrefix; + vertexShaderPrefix << "#define MAX_POINT_COUNT "<< pointCount << "\n"; + + Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::NewWithPrefix( vertexShaderPrefix.str(),vertexShader, + "#extension GL_OES_standard_derivatives:enable\n", fragmentShader, + GEOMETRY_TYPE_UNTEXTURED_MESH ); + + Dali::Toolkit::QuadraticBezier handle( shaderEffectCustom ); + + //Set default uniform values + handle.SetUniform( COLOR_PROPERTY_NAME, Vector4(1.0f,1.0f,1.0f,1.0f) ); + if( !filled ) + { + //Set default line widht to 1 pixel + handle.SetUniform( LINEWIDTH_PROPERTY_NAME, 1.0f ); + } + + return handle; +} + +void QuadraticBezier::SetPoint(unsigned int index, const Vector3& position) +{ + SetUniform( GetPointPropertyName(index), position ); +} + +void QuadraticBezier::SetLineWidth( float width ) +{ + SetUniform( LINEWIDTH_PROPERTY_NAME, width ); +} + +void QuadraticBezier::SetColor( const Vector4& color ) +{ + SetUniform( COLOR_PROPERTY_NAME, color ); +} + +std::string QuadraticBezier::GetPointPropertyName(unsigned int index) const +{ + std::ostringstream propertyName; + propertyName< + +namespace Dali +{ + +namespace Toolkit +{ +/** + * @brief QuadraticBezier is a custom shader to render quadratic bezier curves and bounded regions. + * + * Implementation based on the paper "Resolution Independent Curve Rendering using Programmable Graphics Hardware" + * by Charles Loop and Jim Blinn. + * + * The coordinates of the control points is passed to the shader via uniforms. + * aNormal attribute is used to pass the coefficients of each control point (xy coordinates) as well as the vertex ID (z coordinate). + * A quadratic curve should have as normal for the first control point (0.0,0.0), (0.5,0.0) for the second and (1.0,1.0) for the third. + * Triangles that do not contain curves should have coordinates (0.0,1.0) for each control point in order to be filled properly. + */ + +class DALI_IMPORT_API QuadraticBezier : public ShaderEffect +{ +public: + + /** + * @brief Create an uninitialized QuadraticBezier; this can be initialized with QuadraticBezier::New(). + * + * Calling member functions with an uninitialized Dali::Object is not allowed. + */ + QuadraticBezier(); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~QuadraticBezier(); + + /** + * @brief Create an initialized QuadraticBezier. + * + * @param[in] pointCount The maximum number of vertices + * @param[in] filled Specify whether the the bounded region should be filled or not + * @return A handle to a newly allocated Dali resource. + */ + static QuadraticBezier New(unsigned int pointCount, bool filled ); + + /** + * @brief Set position coordinates for a point in the curve + * + * @param[in] index The index of the vertex + * @param[in] position The new position + */ + void SetPoint( unsigned int index, const Vector3& position ); + + /** + * @brief Set the width of the pathThis is only for not filled curves + * + * @param[in] width Width of the line in pixels + */ + void SetLineWidth( float width ); + + /** + * @brief Sets the color of the curve + * + * @param[in] color The new color + */ + void SetColor( const Vector4& color ); + + /** + * @brief Get the name of a the point property given its index + * + * @param[in] index Index of the vertex + * @return A std::string containing the property name + */ + std::string GetPointPropertyName( unsigned int index ) const; + + /** + * @brief Get the name of the line width property + * + * @return A std::string containing the property name + */ + std::string GetLineWidthPropertyName( ) const; + + /** + * @brief Get the name of the color property + * + * @return A std::string containing the property name + */ + std::string GetColorPropertyName( ) const; + +private: // Not intended for application developers + + DALI_INTERNAL QuadraticBezier(ShaderEffect handle); + +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_TOOLKIT_IMAGE_REGION_EFFECT_H__