Convert more shaders in dali-toolkit and dali-scene-loader to use shader compilation... 03/251703/2
authorRichard Huang <r.huang@samsung.com>
Mon, 18 Jan 2021 17:13:40 +0000 (17:13 +0000)
committerRichard Huang <r.huang@samsung.com>
Mon, 18 Jan 2021 17:41:59 +0000 (17:41 +0000)
Change-Id: I0389814f16c3bb33d697fac6d1c73fec5aec87f4

28 files changed:
.gitignore
build/tizen/dali-scene-loader/CMakeLists.txt
dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag [new file with mode: 0644]
dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert [new file with mode: 0644]
dali-scene-loader/public-api/scene-definition.cpp
dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp
dali-toolkit/internal/controls/scene3d-view/gltf-shader.h [deleted file]
dali-toolkit/internal/controls/video-view/video-view-impl.cpp
dali-toolkit/internal/filters/blur-two-pass-filter.cpp
dali-toolkit/internal/filters/emboss-filter.cpp
dali-toolkit/internal/filters/spread-filter.cpp
dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag
dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert
dali-toolkit/internal/text/decorator/text-decorator.cpp
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-scroller.cpp
dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp
dali-toolkit/internal/visuals/arc/arc-visual.cpp
dali-toolkit/internal/visuals/border/border-visual.cpp
dali-toolkit/internal/visuals/color/color-visual.cpp
dali-toolkit/internal/visuals/gradient/gradient-visual.cpp
dali-toolkit/internal/visuals/image-visual-shader-factory.cpp
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/primitive/primitive-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp

index aa38ad0..f31e277 100644 (file)
@@ -49,3 +49,5 @@ core
 compile_commands.json
 dali-toolkit/internal/graphics/generated/*
 dali-toolkit/internal/graphics/builtin-shader-extern-gen.h
+dali-scene-loader/internal/graphics/generated/*
+dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h
index dcab4a3..d3ebe7d 100644 (file)
@@ -144,6 +144,16 @@ if( ANDROID )
        target_link_libraries(${name} log)
 endif()
 
+# Generate source files for shaders
+SET(SHADER_SOURCE_DIR "${scene_loader_dir}/internal/graphics/shaders/")
+SET(SHADER_GENERATED_DIR "${scene_loader_dir}/internal/graphics/generated")
+EXECUTE_PROCESS( COMMAND bash -c "${repo_root_dir}/build/tizen/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}" )
+
+SET(GENERATED_SHADER_DIR ${scene_loader_dir}/internal/graphics/)
+SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
+             "${GENERATED_SHADER_DIR}/generated/"
+             "${GENERATED_SHADER_DIR}/builtin-shader-extern-gen.h")
+
 IF( INSTALL_CMAKE_MODULES )
        SET_TARGET_PROPERTIES( ${name}
                PROPERTIES
diff --git a/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag
new file mode 100644 (file)
index 0000000..a1153c9
--- /dev/null
@@ -0,0 +1,11 @@
+#version 300 es
+
+precision mediump float;
+flat in float vColor;
+out vec4 FragColor;
+
+void main()
+{
+  vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625));
+  FragColor = vec4(rgb, 1.);
+}
\ No newline at end of file
diff --git a/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert
new file mode 100644 (file)
index 0000000..98b6086
--- /dev/null
@@ -0,0 +1,13 @@
+#version 300 es
+
+precision mediump float;
+uniform mat4 uMvpMatrix;
+in vec3 aPosition;
+in float aColor;
+flat out float vColor;
+
+void main()
+{
+  vColor = aColor;
+  gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+}
\ No newline at end of file
index 409d285..54aa0c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -24,6 +24,7 @@
 #include "dali-scene-loader/public-api/blend-shape-details.h"
 #include "dali-scene-loader/public-api/utils.h"
 #include "dali-scene-loader/public-api/skinning-details.h"
+#include "dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h"
 
 //#define DEBUG_SCENE_DEFINITION
 //#define DEBUG_JOINTS
@@ -133,27 +134,6 @@ struct ResourceReflector : IResourceReflector
 
 
 #ifdef DEBUG_JOINTS
-const char* JOINT_DEBUG_VSH = "#version 300 es\n"
-DALI_COMPOSE_SHADER(
-  precision mediump float;
-  uniform mat4 uMvpMatrix;
-  in vec3 aPosition;
-  in float aColor;
-  flat out float vColor;
-  void main() {
-    vColor = aColor;
-    gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
-  });
-
-const char* JOINT_DEBUG_FSH = "#version 300 es\n"
-DALI_COMPOSE_SHADER(
-  precision mediump float;
-  flat in float vColor;
-  out vec4 FragColor;
-  void main() {
-    vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625));
-    FragColor = vec4(rgb, 1.);
-  });
 
 Shader sJointDebugShader;
 int sNumScenes = 0;
@@ -162,7 +142,7 @@ void EnsureJointDebugShaderCreated()
 {
   if (0 == sNumScenes)
   {
-    sJointDebugShader = Shader::New(JOINT_DEBUG_VSH, JOINT_DEBUG_FSH);
+    sJointDebugShader = Shader::New(SHADER_SCENE_LOADER_JOINT_DEBUG_VERT, SHADER_SCENE_LOADER_JOINT_DEBUG_FRAG);
   }
   ++sNumScenes;
 }
index 52dc236..959a39f 100644 (file)
 
 // CLASS HEADER
 #include <dali-toolkit/internal/controls/scene3d-view/gltf-loader.h>
-#include <dali-toolkit/internal/controls/scene3d-view/gltf-shader.h>
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -1503,35 +1503,35 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index )
     bool isEmissiveTexture = false;
 
     std::string VERTEX_SHADER, FRAGMENT_SHADER;
-    VERTEX_SHADER = GLES_VERSION_300;
-    VERTEX_SHADER += PHYSICALLY_BASED_VERTEX_SHADER;
-    FRAGMENT_SHADER = GLES_VERSION_300;
+    VERTEX_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data();
+    VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data();
+    FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data();
 
     bool useIBL = ( scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT );
     if( isMaterial )
     {
       MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
-      if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) )
+      if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, SHADER_GLTF_BASECOLOR_TEXTURE_DEF.data(), addIdx ) )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::BASECOLOR_SHADER );
         isBaseColorTexture = true;
       }
-      if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, DEFINE_METALLICROUGHNESS_TEXTURE, addIdx ) )
+      if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, SHADER_GLTF_METALLICROUGHNESS_TEXTURE_DEF.data(), addIdx ) )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::METALLICROUGHNESS_SHADER );
         isMetallicRoughnessTexture = true;
       }
-      if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, DEFINE_NORMAL_TEXTURE, addIdx ) )
+      if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, SHADER_GLTF_NORMAL_TEXTURE_DEF.data(), addIdx ) )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::NORMAL_SHADER );
         isNormalTexture = true;
       }
-      if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, DEFINE_OCCLUSION_TEXTURE, addIdx ) )
+      if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, SHADER_GLTF_OCCULUSION_TEXTURE_DEF.data(), addIdx ) )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::OCCLUSION_SHADER );
         isOcclusionTexture = true;
       }
-      if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, DEFINE_EMIT_TEXTURE, addIdx ) )
+      if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, SHADER_GLTF_EMIT_TEXTURE_DEF.data(), addIdx ) )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::EMIT_SHADER );
         isEmissiveTexture = true;
@@ -1540,7 +1540,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index )
       if( useIBL )
       {
         shaderTypeIndex += static_cast<int32_t>( ShaderType::IBL_SHADER );
-        FRAGMENT_SHADER += DEFINE_IBL_TEXTURE;
+        FRAGMENT_SHADER += SHADER_GLTF_IBL_TEXTURE_DEF.data();
 
         Sampler sampler = Sampler::New();
         sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
@@ -1567,7 +1567,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index )
       }
     }
 
-    FRAGMENT_SHADER += PHYSICALLY_BASED_FRAGMENT_SHADER;
+    FRAGMENT_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_FRAG.data();
     if( !mShaderCache[shaderTypeIndex] )
     {
       mShaderCache[shaderTypeIndex] = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-shader.h b/dali-toolkit/internal/controls/scene3d-view/gltf-shader.h
deleted file mode 100644 (file)
index e51b77c..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-#ifndef DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
-#define DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
-
-/*
- * Belows Vertex Shader and Fragment Shader code are based off glTF WebGL PBR.
- * https://github.com/KhronosGroup/glTF-WebGL-PBR/
- *
- * Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Internal
-{
-
-const char* GLES_VERSION_300 = {
-  "#version 300 es\n\n"
-  "precision highp float;\n\n"
-};
-
-const char* DEFINE_BASECOLOR_TEXTURE = {
-  "#define TEXTURE_BASECOLOR\n\n"
-  "uniform sampler2D uBaseColorSampler;\n"
-  "uniform int uBaseColorTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_METALLICROUGHNESS_TEXTURE = {
-  "#define TEXTURE_METALLICROUGHNESS\n\n"
-  "uniform sampler2D uMetallicRoughnessSampler;\n"
-  "uniform int uMetallicRoughnessTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_NORMAL_TEXTURE = {
-  "#define TEXTURE_NORMAL\n\n"
-  "uniform sampler2D uNormalSampler;\n"
-  "uniform float uNormalScale;\n"
-  "uniform int uNormalTexCoordIndex;\n\n"
-};
-
-const char* DEFINE_OCCLUSION_TEXTURE = {
-  "#define TEXTURE_OCCLUSION\n\n"
-  "uniform sampler2D uOcclusionSampler;\n"
-  "uniform int uOcclusionTexCoordIndex;\n"
-  "uniform float uOcclusionStrength;\n\n"
-};
-
-const char* DEFINE_EMIT_TEXTURE = {
-  "#define TEXTURE_EMIT\n\n"
-  "uniform sampler2D uEmissiveSampler;\n"
-  "uniform int uEmissiveTexCoordIndex;\n"
-  "uniform vec3 uEmissiveFactor;\n\n"
-};
-
-const char* DEFINE_IBL_TEXTURE = {
-  "#define TEXTURE_IBL\n\n"
-  "uniform sampler2D ubrdfLUT;\n"
-  "uniform samplerCube uDiffuseEnvSampler;\n"
-  "uniform samplerCube uSpecularEnvSampler;\n"
-  "uniform vec4 uScaleIBLAmbient;\n"
-  "uniform highp float uMipmapLevel;\n"
-};
-
-const char* PHYSICALLY_BASED_VERTEX_SHADER = {
-  "in highp vec3 aPosition;\n"
-  "in mediump vec2 aTexCoord0;\n"
-  "in mediump vec2 aTexCoord1;\n"
-  "in lowp vec3 aNormal;\n"
-  "in lowp vec4 aTangent;\n"
-  "in lowp vec4 aVertexColor;\n"
-
-  "uniform mediump vec3 uSize;\n"
-  "uniform mediump mat4 uModelMatrix;\n"
-  "uniform mediump mat4 uViewMatrix;\n"
-  "uniform mediump mat4 uProjection;\n"
-  "uniform lowp int uLightType;\n"
-  "uniform mediump vec3 uLightVector;\n"
-  "uniform lowp int uIsColor;\n"
-
-  "out lowp vec2 vUV[2];\n"
-  "out lowp mat3 vTBN;\n"
-  "out lowp vec4 vColor;\n"
-  "flat out int visLight;\n"
-  "out highp vec3 vLightDirection;\n"
-  "out highp vec3 vPositionToCamera;\n"
-
-  "void main()\n"
-  "{\n"
-  "  highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);\n"
-  "  highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );\n"
-  "  highp vec4 positionV = uViewMatrix * ( invY * positionW );\n"
-
-  "  vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );\n"
-  "  vPositionToCamera *= invY.xyz;\n"
-
-  "  lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;\n"
-  "  vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);\n"
-
-  "  vUV[0] = aTexCoord0;\n"
-  "  vUV[1] = aTexCoord1;\n"
-
-  "  visLight = 1;\n"
-  "  if( uLightType == 1 )\n"
-  "  {\n"
-  "    vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );\n"
-  "  }\n"
-  "  else if( uLightType == 2 )\n"
-  "  {\n"
-  "    vLightDirection = -( invY.xyz * uLightVector );\n"
-  "  }\n"
-  "  else\n"
-  "  {\n"
-  "    visLight = 0;\n"
-  "  }\n"
-
-  "  vColor = vec4( 1.0 );\n"
-  "  if( uIsColor == 1 )\n"
-  "  {\n"
-  "    vColor = aVertexColor;\n"
-  "  }\n"
-
-  "  gl_Position = uProjection * positionV;\n" // needs w for proper perspective correction
-  "  gl_Position = gl_Position/gl_Position.w;\n"
-  "}\n"
-};
-
-const char* PHYSICALLY_BASED_FRAGMENT_SHADER = {
-  "uniform lowp vec3 uLightColor;\n"
-  "uniform lowp vec4 uBaseColorFactor;\n"
-  "uniform lowp vec2 uMetallicRoughnessFactors;\n"
-  "uniform lowp int alphaMode;\n"
-  "uniform lowp float alphaCutoff;\n"
-
-  "in lowp vec2 vUV[2];\n"
-  "in lowp mat3 vTBN;\n"
-  "in lowp vec4 vColor;\n"
-  "flat in int visLight;\n"
-  "in highp vec3 vLightDirection;\n"
-  "in highp vec3 vPositionToCamera;\n"
-
-  "out vec4 FragColor;"
-
-  "struct PBRInfo\n"
-  "{\n"
-  "  mediump float NdotL;\n"                  // cos angle between normal and light direction
-  "  mediump float NdotV;\n"                  // cos angle between normal and view direction
-  "  mediump float NdotH;\n"                  // cos angle between normal and half vector
-  "  mediump float VdotH;\n"                  // cos angle between view direction and half vector
-  "  mediump vec3 reflectance0;\n"            // full reflectance color (normal incidence angle)
-  "  mediump vec3 reflectance90;\n"           // reflectance color at grazing angle
-  "  lowp float alphaRoughness;\n"         // roughness mapped to a more linear change in the roughness (proposed by [2])
-  "};\n"
-
-  "const float M_PI = 3.141592653589793;\n"
-  "const float c_MinRoughness = 0.04;\n"
-
-  "vec3 getNormal()\n"
-  "{\n"
-  "#ifdef TEXTURE_NORMAL\n"
-  "  lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;\n"
-  "  n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );\n"
-  "#else\n"
-  "  lowp vec3 n = normalize( vTBN[2].xyz );\n"
-  "#endif\n"
-  "  return n;\n"
-  "}\n"
-
-  "vec3 specularReflection( PBRInfo pbrInputs )\n"
-  "{\n"
-  "  return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );\n"
-  "}\n"
-
-  "float geometricOcclusion( PBRInfo pbrInputs )\n"
-  "{\n"
-  "  mediump float NdotL = pbrInputs.NdotL;\n"
-  "  mediump float NdotV = pbrInputs.NdotV;\n"
-  "  lowp float r = pbrInputs.alphaRoughness;\n"
-
-  "  lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n"
-  "  lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n"
-  "  return attenuationL * attenuationV;\n"
-  "}\n"
-
-  "float microfacetDistribution(PBRInfo pbrInputs)\n"
-  "{\n"
-  "  mediump float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;\n"
-  "  lowp float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;\n"
-  "  return roughnessSq / (M_PI * f * f);\n"
-  "}\n"
-
-  "vec3 linear( vec3 color )\n"
-  "{\n"
-  "  return pow(color,vec3(2.2));\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  // Metallic and Roughness material properties are packed together
-  // In glTF, these factors can be specified by fixed scalar values
-  // or from a metallic-roughness map
-  "  lowp float metallic = uMetallicRoughnessFactors.x;\n"
-  "  lowp float perceptualRoughness = uMetallicRoughnessFactors.y;\n"
-
-  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
-  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
-  "#ifdef TEXTURE_METALLICROUGHNESS\n"
-  "  lowp vec4 metrou = texture(uMetallicRoughnessSampler, vUV[uMetallicRoughnessTexCoordIndex]);\n"
-  "  metallic = metrou.b * metallic;\n"
-  "  perceptualRoughness = metrou.g * perceptualRoughness;\n"
-  "#endif\n"
-
-  "  metallic = clamp(metallic, 0.0, 1.0);\n"
-  "  perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n"
-  // Roughness is authored as perceptual roughness; as is convention,
-  // convert to material roughness by squaring the perceptual roughness [2].
-  "  lowp float alphaRoughness = perceptualRoughness * perceptualRoughness;\n"
-
-  "#ifdef TEXTURE_BASECOLOR\n"
-  // The albedo may be defined from a base texture or a flat color
-  "  lowp vec4 baseColor = texture(uBaseColorSampler, vUV[uBaseColorTexCoordIndex]) * uBaseColorFactor;\n"
-  "  baseColor = vec4(linear(baseColor.rgb), baseColor.w);\n"
-  "#else\n"
-  "  lowp vec4 baseColor = vColor * uBaseColorFactor;\n"
-  "#endif\n"
-
-  "  if( alphaMode == 0 )\n"
-  "  {\n"
-  "    baseColor.w = 1.0;\n"
-  "  }\n"
-  "  else if( alphaMode == 1 )\n"
-  "  {\n"
-  "    if( baseColor.w >= alphaCutoff )"
-  "    {\n"
-  "      baseColor.w = 1.0;\n"
-  "    }\n"
-  "    else\n"
-  "    {\n"
-  "      baseColor.w = 0.0;\n"
-  "    }\n"
-  "  }\n"
-
-  "  lowp vec3 f0 = vec3(0.04);\n"
-  "  lowp vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n"
-  "  diffuseColor *= ( 1.0 - metallic );\n"
-  "  lowp vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n"
-
-  // Compute reflectance.
-  "  lowp float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n"
-
-  // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
-  // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
-  "  lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n"
-  "  lowp vec3 specularEnvironmentR0 = specularColor.rgb;\n"
-  "  lowp vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n"
-
-  "  mediump vec3 n = getNormal();\n"                            // normal at surface point
-  "  mediump vec3 v = normalize(vPositionToCamera);\n"           // Vector from surface point to camera
-  "  mediump vec3 l = normalize(vLightDirection);\n"             // Vector from light to surface point
-  "  mediump vec3 h = normalize(l+v);\n"                         // Half vector between both l and v
-  "  mediump vec3 reflection = -normalize(reflect(v, n));\n"
-
-  "  mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);\n"
-  "  mediump float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n"
-  "  mediump float NdotH = dot(n, h);\n"
-  "  mediump float LdotH = dot(l, h);\n"
-  "  mediump float VdotH = dot(v, h);\n"
-
-  "  PBRInfo pbrInputs = PBRInfo(\n"
-  "    NdotL,\n"
-  "    NdotV,\n"
-  "    NdotH,\n"
-  "    VdotH,\n"
-  "    specularEnvironmentR0,\n"
-  "    specularEnvironmentR90,\n"
-  "    alphaRoughness\n"
-  "  );\n"
-
-  // Calculate the shading terms for the microfacet specular shading model
-  "  lowp vec3 color = vec3(0.0);\n"
-  "  if( visLight == 1 )\n"
-  "  {\n"
-  "    lowp vec3 F = specularReflection( pbrInputs );\n"
-  "    lowp float G = geometricOcclusion( pbrInputs );\n"
-  "    lowp float D = microfacetDistribution( pbrInputs );\n"
-
-  // Calculation of analytical lighting contribution
-  "    lowp vec3 diffuseContrib = ( 1.0 - F ) * ( diffuseColor / M_PI );\n"
-  "    lowp vec3 specContrib = F * G * D / ( 4.0 * NdotL * NdotV );\n"
-  // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
-  "    color = NdotL * uLightColor * (diffuseContrib + specContrib);\n"
-  "  }\n"
-
-  "#ifdef TEXTURE_IBL\n"
-  "  lowp float lod = ( perceptualRoughness * uMipmapLevel );\n"
-  // retrieve a scale and bias to F0. See [1], Figure 3
-  "  lowp vec3 brdf = linear( texture( ubrdfLUT, vec2( NdotV, 1.0 - perceptualRoughness ) ).rgb );\n"
-  "  lowp vec3 diffuseLight = linear( texture( uDiffuseEnvSampler, n ).rgb );\n"
-  "  lowp vec3 specularLight = linear( textureLod( uSpecularEnvSampler, reflection, lod ).rgb );\n"
-
-  "  lowp vec3 diffuse = diffuseLight * diffuseColor * uScaleIBLAmbient.x;\n"
-  "  lowp vec3 specular = specularLight * ( specularColor * brdf.x + brdf.y ) * uScaleIBLAmbient.y;\n"
-  "  color += ( diffuse + specular );\n"
-  "#endif\n"
-
-  "#ifdef TEXTURE_OCCLUSION\n"
-  "  lowp float ao = texture( uOcclusionSampler, vUV[uOcclusionTexCoordIndex] ).r;\n"
-  "  color = mix( color, color * ao, uOcclusionStrength );\n"
-  "#endif\n"
-
-  "#ifdef TEXTURE_EMIT\n"
-  "  lowp vec3 emissive = linear( texture( uEmissiveSampler, vUV[uEmissiveTexCoordIndex] ).rgb ) * uEmissiveFactor;\n"
-  "  color += emissive;\n"
-  "#endif\n"
-
-  "  FragColor = vec4( pow( color,vec3( 1.0 / 2.2 ) ), baseColor.a );\n"
-  "}\n"
-};
-
-} // namespace internal
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif // DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H
\ No newline at end of file
index 6956cb2..8052be2 100755 (executable)
@@ -34,6 +34,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -86,50 +87,6 @@ const char* const CUSTOM_FRAGMENT_SHADER( "fragmentShader" );
 const char* const DEFAULT_SAMPLER_TYPE_NAME( "sampler2D" );
 const char* const CUSTOM_SAMPLER_TYPE_NAME( "samplerExternalOES" );
 
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vertexPosition.xyz *= uSize;\n
-    gl_Position = uMvpMatrix * vertexPosition;\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = vec4(0.0);\n
-  }\n
-);
-
-const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  varying mediump vec2 vTexCoord;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  varying mediump vec2 sTexCoordRect;\n
-  void main()\n
-  {\n
-    gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n
-    vTexCoord = aPosition + vec2(0.5);\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
-  uniform lowp vec4 uColor;\n
-  varying mediump vec2 vTexCoord;\n
-  uniform samplerExternalOES sTexture;\n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
-  }\n
-);
-
 } // anonymous namepsace
 
 VideoView::VideoView( Dali::VideoSyncMode syncMode )
@@ -652,7 +609,7 @@ void VideoView::SetWindowSurfaceTarget()
   {
     // For underlay rendering mode, video display area have to be transparent.
     Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
-    Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+    Shader shader = Shader::New( SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG );
     mOverlayRenderer = Renderer::New( geometry, shader );
     mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
   }
@@ -856,7 +813,7 @@ Dali::Shader VideoView::CreateShader()
 
     if( !vertexShaderValue || !checkShader )
     {
-      vertexShader = VERTEX_SHADER_TEXTURE;
+      vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
     }
 
     Property::Value* fragmentShaderValue = mEffectPropertyMap.Find( CUSTOM_FRAGMENT_SHADER );
@@ -872,13 +829,13 @@ Dali::Shader VideoView::CreateShader()
 
     if( !fragmentShaderValue || !checkShader )
     {
-      fragmentShader += FRAGMENT_SHADER_TEXTURE;
+      fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
     }
   }
   else
   {
-    vertexShader = VERTEX_SHADER_TEXTURE;
-    fragmentShader += FRAGMENT_SHADER_TEXTURE;
+    vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
+    fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
   }
 
   return Dali::Shader::New( vertexShader, fragmentShader );
index e870650..f86ffd4 100644 (file)
@@ -28,6 +28,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -58,24 +59,6 @@ const float DEFAULT_KERNEL4[] = { 2.0f/16.0f, 1.5f/16.0f, 1.5f/16.0f, 1.5f/16.0f
                                   1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f, 0.5f/16.0f,
                                   0.5f/16.0f, 0.5f/16.0f, 0.5f/16.0f };
 
-const char* BLUR_TWO_PASS_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform vec2 uSampleOffsets[NUM_SAMPLES];\n"
- "uniform float uSampleWeights[NUM_SAMPLES];\n"
- "void main()\n"
- "{\n"
- "  vec4 color = vec4(0.0);\n"
- "  for( int i = 0; i < NUM_SAMPLES; ++i )\n"
- "  {\n"
- "    color += texture2D( sTexture, vTexCoord + uSampleOffsets[i] ) * uSampleWeights[i];\n"
- "  }\n"
- "  gl_FragColor = color;\n"
- "}\n"
-};
-
 std::string GetOffsetUniformName( int index )
 {
   std::ostringstream oss;
@@ -90,20 +73,6 @@ std::string GetWeightUniformName( int index )
   return oss.str();
 }
 
-const char* BLEND_TWO_IMAGES_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "uniform float uBlurStrength;\n "
- "uniform sampler2D sTexture;\n"
- "uniform sampler2D sEffect;\n"
- "varying mediump vec2 vTexCoord;\n"
- "void main()\n"
- "{\n"
- "  gl_FragColor = texture2D( sTexture, vTexCoord ) * uBlurStrength"
- "               + texture2D( sEffect, vTexCoord )*(1.0-uBlurStrength); \n"
- "}\n"
-};
-
 const char* const BLUR_STRENGTH_UNIFORM_NAME( "uBlurStrength"  );
 const char* const EFFECT_IMAGE_NAME( "sEffect" );
 
@@ -135,7 +104,7 @@ void BlurTwoPassFilter::Enable()
   // Set up blur-two-pass custom shader
   std::ostringstream sstream;
   sstream << "#define NUM_SAMPLES " << kernelSize << "\n";
-  sstream << BLUR_TWO_PASS_FRAGMENT_SOURCE;
+  sstream << SHADER_BLUR_TWO_PASS_SHADER_FRAG;
   std::string fragmentSource( sstream.str() );
 
   // create actor to render input with applied emboss effect
@@ -165,7 +134,7 @@ void BlurTwoPassFilter::Enable()
   mBlurredFrameBuffer.AttachColorTexture( blurredTexture );
 
   // create an actor to blend the blurred image and the input image with the given blur strength
-  Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, BLEND_TWO_IMAGES_FRAGMENT_SOURCE );
+  Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLUR_TWO_IMAGES_SHADER_FRAG );
   TextureSet textureSetForBlending = rendererForBlending.GetTextures();
   textureSetForBlending.SetTexture( 0u, blurredTexture );
   textureSetForBlending.SetTexture( 1u, mInputTexture );
index b1bd177..7ea7fe1 100644 (file)
@@ -28,6 +28,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -41,35 +42,6 @@ namespace Internal
 namespace
 {
 
-const char* EMBOSS_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform vec2 uTexScale;\n"
- "uniform vec3 uCoefficient;\n"
- "\n"
- "void main()\n"
- "{\n"
- "  vec4 color  = uCoefficient.x * texture2D( sTexture, vTexCoord + vec2(0.0, -uTexScale.y) );\n"
- "  color += uCoefficient.y * texture2D( sTexture, vTexCoord );\n"
- "  color += uCoefficient.z * texture2D( sTexture, vTexCoord + vec2(0.0, uTexScale.y) );\n"
- "  gl_FragColor = color;\n"
- "}\n"
-};
-
-const char* const COMPOSITE_FRAGMENT_SOURCE =
-{
-  "varying mediump vec2 vTexCoord;\n"
-  "uniform sampler2D sTexture;\n"
-  "uniform lowp vec4 uEffectColor;\n"
-  "void main()\n"
-  "{\n"
-  "  gl_FragColor = uEffectColor;\n"
-  "  gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;\n"
-  "}\n"
-};
-
 const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" );
 const char* const COEFFICIENT_UNIFORM_NAME( "uCoefficient" );
 const char* const COLOR_UNIFORM_NAME( "uEffectColor" );
@@ -103,7 +75,7 @@ void EmbossFilter::Enable()
   mActorForInput1.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale );
   mActorForInput1.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( 2.f, -1.f, -1.f ) );
   // set EMBOSS custom shader
-  Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE );
+  Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG );
   SetRendererTexture( renderer1, mInputTexture );
   mActorForInput1.AddRenderer( renderer1 );
   mRootActor.Add( mActorForInput1 );
@@ -114,7 +86,7 @@ void EmbossFilter::Enable()
   mActorForInput2.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale );
   mActorForInput2.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( -1.f, -1.f, 2.f ) );
   // set EMBOSS custom shader
-  Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE );
+  Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG );
   SetRendererTexture( renderer2, mInputTexture );
   mActorForInput2.AddRenderer( renderer2 );
   mRootActor.Add( mActorForInput2 );
@@ -126,12 +98,12 @@ void EmbossFilter::Enable()
 
   mRootActor.Add( mActorForComposite );
 
-  mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+  mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG );
   SetRendererTexture( mRendererForEmboss1, mFrameBufferForEmboss1 );
   mRendererForEmboss1.RegisterProperty( COLOR_UNIFORM_NAME, Color::BLACK );
   mActorForComposite.AddRenderer( mRendererForEmboss1 );
 
-  mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE );
+  mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG );
   SetRendererTexture( mRendererForEmboss2, mFrameBufferForEmboss2 );
   mRendererForEmboss2.RegisterProperty( COLOR_UNIFORM_NAME, Color::WHITE );
   mActorForComposite.AddRenderer( mRendererForEmboss2 );
index 5eb8a82..55b060b 100644 (file)
@@ -26,6 +26,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -39,26 +40,6 @@ namespace Internal
 namespace
 {
 
-const char* const SPREAD_FRAGMENT_SOURCE =
-{
- "precision highp float;\n"
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform int uSpread;\n"
- "uniform vec2 uTexScale;\n"
- "void main()\n"
- "{\n"
- "  vec4 color = texture2D( sTexture, vTexCoord);\n"
- "  for( int i = 1; i <= uSpread; ++i )\n"
- "  {\n"
- "    vec2 offset = uTexScale * float(i);\n"
- "    color = max( texture2D( sTexture, vTexCoord + offset), color );\n"
- "    color = max( texture2D( sTexture, vTexCoord - offset), color );\n"
- "  }\n"
- "  gl_FragColor = color;\n"
- "}\n"
-};
-
 const char* const SPREAD_UNIFORM_NAME( "uSpread" );
 const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" );
 
@@ -90,7 +71,7 @@ void SpreadFilter::Enable()
   mActorForInput.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread );
   mActorForInput.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 1.0f / mTargetSize.width, 0.0f ) );
 
-  Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE );
+  Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG );
   SetRendererTexture( rendererForInput, mInputTexture );
   mActorForInput.AddRenderer( rendererForInput );
 
@@ -106,7 +87,7 @@ void SpreadFilter::Enable()
   // register properties as shader uniforms
   mActorForHorz.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread );
   mActorForHorz.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 0.0f, 1.0f / mTargetSize.height ) );
-  Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE );
+  Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG );
   SetRendererTexture( rendererForHorz, textureForHorz );
   mActorForHorz.AddRenderer( rendererForHorz );
 
index 610b774..678a852 100644 (file)
@@ -1,7 +1,9 @@
+//Very simple fragment shader that merely applies the vertex shading to the color at each fragment.
+
 precision mediump float;
-varying mediump vec3vIllumination;
-uniform lowpvec4uColor;
-uniform lowpvec3mixColor;
+varying mediump vec3 vIllumination;
+uniform lowp vec4 uColor;
+uniform lowp vec3 mixColor;
 
 void main()
 {
index 6605bc6..6a1b758 100644 (file)
@@ -1,3 +1,5 @@
+//A simple shader that applies diffuse lighting to a mono-coloured object.
+
 attribute highp vec3 aPosition;
 attribute highp vec2 aTexCoord;
 attribute highp vec3 aNormal;
index 7016759..648c17a 100644 (file)
 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 #ifdef DEBUG_ENABLED
 #define DECORATOR_DEBUG
 
 #endif
 
-#define MAKE_SHADER(A)#A
-
-namespace
-{
-const char* VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec2    aPosition;
-uniform   highp mat4      uMvpMatrix;
-
-void main()
-{
-  mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
-  gl_Position = uMvpMatrix * position;
-}
-);
-
-const char* FRAGMENT_SHADER = MAKE_SHADER(
-uniform      lowp vec4 uColor;
-
-void main()
-{
-  gl_FragColor = uColor;
-}
-);
-}
-
 namespace Dali
 {
 namespace Internal
@@ -270,7 +246,7 @@ struct Decorator::Impl : public ConnectionTracker
     mHidePrimaryCursorAndGrabHandle( false )
   {
     mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
-    mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+    mHighlightShader = Shader::New( SHADER_TEXT_DECORATOR_SHADER_VERT, SHADER_TEXT_DECORATOR_SHADER_FRAG );
     SetupGestures();
   }
 
index 4fc28f8..80a1111 100755 (executable)
@@ -31,6 +31,7 @@
 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
 #include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
 #include <dali-toolkit/internal/text/text-view.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -42,52 +43,6 @@ namespace
   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING");
 #endif
 
-#define MAKE_SHADER(A)#A
-
-const char* VERTEX_SHADER = MAKE_SHADER(
-attribute mediump vec2    aPosition;
-attribute mediump vec2    aTexCoord;
-attribute mediump vec4    aColor;
-uniform   mediump vec2    uOffset;
-uniform     highp mat4    uMvpMatrix;
-varying   mediump vec2    vTexCoord;
-varying   mediump vec4    vColor;
-
-void main()
-{
-  mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
-  gl_Position = uMvpMatrix * position;
-  vTexCoord = aTexCoord;
-  vColor = aColor;
-}
-);
-
-const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
-uniform lowp    vec4      uColor;
-uniform lowp    vec4      textColorAnimatable;
-uniform         sampler2D sTexture;
-varying mediump vec2      vTexCoord;
-varying mediump vec4      vColor;
-
-void main()
-{
-  mediump vec4 color = texture2D( sTexture, vTexCoord );
-  gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r );
-}
-);
-
-const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
-uniform lowp    vec4      uColor;
-uniform lowp    vec4      textColorAnimatable;
-uniform         sampler2D sTexture;
-varying mediump vec2      vTexCoord;
-
-void main()
-{
-  gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable;
-}
-);
-
 const float ZERO( 0.0f );
 const float HALF( 0.5f );
 const float ONE( 1.0f );
@@ -696,7 +651,7 @@ struct AtlasRenderer::Impl
       // The glyph is an emoji and is not a shadow.
       if( !mShaderRgba )
       {
-        mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA );
+        mShaderRgba = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG );
       }
       shader = mShaderRgba;
     }
@@ -705,7 +660,7 @@ struct AtlasRenderer::Impl
       // The glyph is text or a shadow.
       if( !mShaderL8 )
       {
-        mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 );
+        mShaderL8 = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG );
       }
       shader = mShaderL8;
     }
index 6554a2c..da5e2e7 100644 (file)
@@ -35,6 +35,7 @@
 #include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
 #include <dali-toolkit/internal/text/text-run-container.h>
 #include <dali-toolkit/internal/text/text-selection-handle-controller.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 using namespace Dali;
 
@@ -45,32 +46,6 @@ namespace
 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
 #endif
 
-#define MAKE_SHADER(A)#A
-
-const char* VERTEX_SHADER_BACKGROUND = MAKE_SHADER(
-attribute mediump vec2    aPosition;
-attribute mediump vec4    aColor;
-varying   mediump vec4    vColor;
-uniform   highp mat4      uMvpMatrix;
-
-void main()
-{
-  mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
-  gl_Position = uMvpMatrix * position;
-  vColor = aColor;
-}
-);
-
-const char* FRAGMENT_SHADER_BACKGROUND = MAKE_SHADER(
-varying mediump vec4      vColor;
-uniform lowp    vec4      uColor;
-
-void main()
-{
-  gl_FragColor = vColor * uColor;
-}
-);
-
 struct BackgroundVertex
 {
   Vector2 mPosition;        ///< Vertex posiiton
@@ -2108,7 +2083,7 @@ Actor Controller::Impl::CreateBackgroundActor()
 
       if( !mShaderBackground )
       {
-        mShaderBackground = Shader::New( VERTEX_SHADER_BACKGROUND, FRAGMENT_SHADER_BACKGROUND );
+        mShaderBackground = Shader::New( SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_VERT, SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_FRAG );
       }
 
       Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, mShaderBackground );
index b2c1b19..d908d33 100755 (executable)
@@ -23,6 +23,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/text-scroller-interface.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -39,56 +40,6 @@ namespace
 
 const int MINIMUM_SCROLL_SPEED = 1; // Speed should be set by Property system.
 
-const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  varying highp vec2 vTexCoord;\n
-  uniform highp vec3 uSize;\n
-  uniform mediump float uDelta;\n
-  uniform mediump vec2 uTextureSize;\n
-  uniform mediump float uGap;\n
-  uniform mediump float uHorizontalAlign;\n
-  uniform mediump float uVerticalAlign;\n
-  \n
-  uniform highp   mat4 uMvpMatrix;\n
-  \n
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  void main()\n
-  {\n
-    mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );\n
-    mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );\n
-    \n
-    vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;\n
-    vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;\n
-    \n
-    mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );\n
-    \n
-    gl_Position = uMvpMatrix * vertexPosition;\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  varying highp vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    if ( vTexCoord.y > 1.0 )\n
-      discard;\n
-    \n
-    mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-    \n
-    gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
-  }\n
-);
-
 /**
  * @brief How the text should be aligned horizontally when scrolling the text.
  *
@@ -281,7 +232,7 @@ void TextScroller::SetParameters( Actor scrollingTextActor, Renderer renderer, T
   mTextureSet = mRenderer.GetTextures();
 
   // Set the shader and texture for scrolling
-  Shader shader = Shader::New( VERTEX_SHADER_SCROLL, FRAGMENT_SHADER, Shader::Hint::NONE );
+  Shader shader = Shader::New( SHADER_TEXT_SCROLLER_SHADER_VERT, SHADER_TEXT_SCROLLER_SHADER_FRAG, Shader::Hint::NONE );
   mRenderer.SetShader( shader );
   mRenderer.SetTextures( textureSet );
 
index 05d1724..9b4bc8c 100755 (executable)
@@ -25,6 +25,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -93,89 +94,6 @@ const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::DirectionType::T
 const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::Type    DEFAULT_ANIMATION_MOTION_TYPE    = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP;
 const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::Type    DEFAULT_ANIMATION_EASING_TYPE    = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR;
 
-const char* const BASIC_VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;
-  uniform highp   mat4 uMvpMatrix;
-  uniform highp   vec3 uSize;
-
-  uniform mediump vec2 start_point;
-  uniform mediump vec2 end_point;
-  uniform mediump vec2 rotate_center;
-  uniform mediump float rotate_angle;
-
-  varying mediump vec2 vTexCoord;
-  varying mediump vec2 vStart;
-  varying mediump vec2 vEnd;
-
-  vec2 rotate(vec2 x, vec2 c, float a)
-  {
-    vec2 d = x - c;
-    vec2 r = vec2(d.x * cos(a) - d.y * sin(a), d.x * sin(a) + d.y * cos(a));
-
-\n  #ifdef UNIT_TYPE_BOUNDING_BOX \n return r + c;             \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */
-\n  #ifdef UNIT_TYPE_USER         \n return (r + c) / uSize.x; \n #endif \n /* UnitType::USER_SPACE          */
-  }
-
-  //Visual size and offset
-  uniform mediump vec2 offset;
-  uniform highp vec2 size;
-  uniform mediump vec4 offsetSizeMode;
-  uniform mediump vec2 origin;
-  uniform mediump vec2 anchorPoint;
-
-  vec4 ComputeVertexPosition()
-  {
-    vec2 visualSize = mix( uSize.xy*size, size, offsetSizeMode.zw );
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
-  }
-
-  void main()
-  {
-    vStart = rotate( start_point, rotate_center, rotate_angle );
-    vEnd = rotate( end_point, rotate_center, rotate_angle );
-    gl_Position = uMvpMatrix * ComputeVertexPosition();
-
-\n  #ifdef UNIT_TYPE_BOUNDING_BOX \n vTexCoord = vec2(aPosition.x, -aPosition.y);                     \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */
-\n  #ifdef UNIT_TYPE_USER         \n vTexCoord = vec2(aPosition.x, -aPosition.y * uSize.y / uSize.x); \n #endif \n /* UnitType::USER_SPACE          */
-  }
-);
-
-const char* const BASIC_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;
-
-  uniform mediump vec4 start_color;
-  uniform mediump vec4 end_color;
-  uniform mediump float gradient_offset;
-
-  varying mediump vec2 vTexCoord;
-  varying mediump vec2 vStart;
-  varying mediump vec2 vEnd;
-
-  float get_position(vec2 x, vec2 s, vec2 e)
-  {
-    vec2 df = e - s;
-    vec2 dx = x - s;
-
-\n  #ifdef GRADIENT_TYPE_LINEAR \n return dot(dx,df)/dot(df,df);       \n #endif \n /* GradientType::LINEAR */
-\n  #ifdef GRADIENT_TYPE_RADIAL \n return sqrt(dot(dx,dx)/dot(df,df)); \n #endif \n /* GradientType::RADIAL */
-  }
-  float recalculate(float r)
-  {
-\n  #ifdef SPREAD_TYPE_REFLECT \n return 1.0 - abs(mod(r, 2.0) - 1.0); \n #endif \n /* SpreadType::REFLECT */
-\n  #ifdef SPREAD_TYPE_REPEAT  \n return fract(r);                     \n #endif \n /* SpreadType::REPEAT  */
-\n  #ifdef SPREAD_TYPE_CLAMP   \n return clamp(r, 0.0, 1.0);           \n #endif \n /* SpreadType::CLAMP   */
-  }
-
-  void main()
-  {
-    float r = get_position( vTexCoord, vStart, vEnd );
-    r = recalculate( r + gradient_offset );
-    vec4 color = mix( start_color, end_color, r );
-    gl_FragColor = color;
-  }
-);
-
 Property::Value GetStartValue( const Property::Map& map, Property::Index index, const char* const name )
 {
   // Get start value of animation parameter
@@ -737,10 +655,10 @@ Shader AnimatedGradientVisual::CreateShader()
   std::string frag;
 
   vert = "#define " + tagUnit + "\n"
-       + BASIC_VERTEX_SHADER;
+       + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_VERT.data();
   frag = "#define " + tagGrad + "\n"
        + "#define " + tagSpread + "\n"
-       + BASIC_FRAGMENT_SHADER;
+       + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_FRAG.data();
 
   shader = Shader::New( vert, frag );
   return shader;
index d694235..be58a9f 100644 (file)
@@ -28,6 +28,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -47,104 +48,6 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, BUTT )
 DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, ROUND )
 DALI_ENUM_TO_STRING_TABLE_END( CAP )
 
-const char* VERTEX_SHADER =
-  "INPUT mediump vec2 aPosition;\n"
-  "OUTPUT mediump vec2 vPosition;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  vPosition = aPosition* visualSize;\n"
-  "  return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "}\n";
-
-const char* FRAGMENT_SHADER_BUTT_CAP =
-  "INPUT mediump vec2 vPosition;\n"
-
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform mediump float thickness;\n"
-  "uniform mediump float radius;\n"
-  "uniform mediump float startAngle;\n"
-  "uniform mediump float sweepAngle;\n"
-
-  "const mediump float M_PI_OVER_2 = 1.57079632679;\n"
-  "const mediump float M_PI = 3.14159265359;\n"
-  "const mediump float M_PI_2 = 6.28318530718;\n"
-
-  "mediump float GetOpacity()\n"
-  "{\n"
-  "  mediump float start = radians( mod( startAngle, 360.0 ) );\n"
-  "  mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n"
-  "  mediump float dist = length( vPosition );\n"
-  "  if( angle <= radians( sweepAngle ) )\n"
-  "  {\n"
-  "    return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n"
-  "  }\n"
-  "  mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n"
-  "  mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );\n"
-  "  mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );\n"
-  "  mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n"
-  "  opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );\n"
-  "  return opacity;\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n"
-  "  OUT_COLOR.a *= GetOpacity();\n"
-  "}\n";
-
-const char* FRAGMENT_SHADER_ROUND_CAP =
-  "INPUT mediump vec2 vPosition;\n"
-
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform mediump float thickness;\n"
-  "uniform mediump float radius;\n"
-  "uniform mediump float startAngle;\n"
-  "uniform mediump float sweepAngle;\n"
-
-  "const mediump float M_PI_OVER_2 = 1.57079632679;\n"
-  "const mediump float M_PI_2 = 6.28318530718;\n"
-
-  "mediump float GetOpacity()\n"
-  "{\n"
-  "  mediump float start = radians( mod( startAngle, 360.0 ) );\n"
-  "  mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n"
-  "  mediump float dist = length( vPosition );\n"
-  "  if( angle <= radians( sweepAngle ) )\n"
-  "  {\n"
-  "    return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n"
-  "  }\n"
-  "  mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n"
-  "  mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );\n"
-  "  mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );\n"
-  "  return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n"
-  "  OUT_COLOR.a *= GetOpacity();\n"
-  "}\n";
-
 }
 
 ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -330,7 +233,7 @@ void ArcVisual::InitializeRenderer()
     shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BUTT_CAP );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_BUTT_CAP_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER, shader );
     }
   }
@@ -339,7 +242,7 @@ void ArcVisual::InitializeRenderer()
     shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUND_CAP );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_ROUND_CAP_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER, shader );
     }
   }
index 452fda9..f62afc3 100644 (file)
@@ -29,6 +29,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -44,74 +45,6 @@ namespace
 const char * const POSITION_ATTRIBUTE_NAME("aPosition");
 const char * const DRIFT_ATTRIBUTE_NAME("aDrift");
 const char * const INDEX_NAME("indices");
-
-const char* VERTEX_SHADER =
-  "INPUT mediump vec2 aPosition;\n"
-  "INPUT mediump vec2 aDrift;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-  "uniform mediump float borderSize;\n"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-
-  "vec2 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  vec2 position = ComputeVertexPosition() + aDrift*borderSize;\n"
-  "  gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n"
-  "}\n";
-
-const char* FRAGMENT_SHADER =
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec4 borderColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n"
-  "}\n";
-
-const char* VERTEX_SHADER_ANTI_ALIASING =
-  "INPUT mediump vec2 aPosition;\n"
-  "INPUT mediump vec2 aDrift;\n"
-  "OUTPUT mediump float vAlpha;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-  "uniform mediump float borderSize;\n"
-
-  "void main()\n"
-  "{\n"
-  "  vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);\n"
-  "  gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n"
-  "  vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5);"
-  "}\n";
-
-const char* FRAGMENT_SHADER_ANTI_ALIASING =
-  "INPUT mediump float vAlpha;\n"
-
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec4 borderColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform mediump float borderSize;\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n"
-  "  OUT_COLOR.a *= smoothstep(0.0, 1.5, vAlpha) * smoothstep( borderSize + 1.5, borderSize, vAlpha );\n"
-  "}\n";
 }
 
 BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -257,7 +190,7 @@ Shader BorderVisual::GetBorderShader()
     shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ANTI_ALIASING, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ANTI_ALIASING );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING, shader );
     }
   }
@@ -266,7 +199,7 @@ Shader BorderVisual::GetBorderShader()
     shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER, shader );
     }
   }
index 68dc04a..492f203 100644 (file)
@@ -31,6 +31,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -41,145 +42,6 @@ namespace Toolkit
 namespace Internal
 {
 
-namespace
-{
-
-const char* VERTEX_SHADER =
-  "INPUT mediump vec2 aPosition;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-  "uniform mediump vec2 extraSize;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "}\n";
-
-
-const char* FRAGMENT_SHADER =
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
-  "}\n";
-
-const char* VERTEX_SHADER_ROUNDED_CORNER =
-  "INPUT mediump vec2 aPosition;\n"
-  "OUTPUT mediump vec2 vPosition;\n"
-  "OUTPUT mediump vec2 vRectSize;\n"
-  "OUTPUT mediump float vCornerRadius;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec2 extraSize;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-  "uniform mediump float cornerRadius;\n"
-  "uniform mediump float cornerRadiusPolicy;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  mediump float minSize = min( visualSize.x, visualSize.y );\n"
-  "  vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n"
-  "  vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n"
-  "  vRectSize = visualSize / 2.0 - vCornerRadius;\n"
-  "  vPosition = aPosition* visualSize;\n"
-  "  return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "}\n";
-
-//float distance = length( max( abs( position - center ), size ) - size ) - radius;
-const char* FRAGMENT_SHADER_ROUNDED_CORNER =
-  "INPUT mediump vec2 vPosition;\n"
-  "INPUT mediump vec2 vRectSize;\n"
-  "INPUT mediump float vCornerRadius;\n"
-
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-
-  "void main()\n"
-  "{\n"
-  "  mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n"
-  "  OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
-  "  OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );\n"
-  "}\n";
-
-const char* VERTEX_SHADER_BLUR_EDGE =
-  "INPUT mediump vec2 aPosition;\n"
-  "OUTPUT mediump vec2 vPosition;\n"
-  "OUTPUT mediump vec2 vRectSize;\n"
-
-  "uniform highp   mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec2 extraSize;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-  "uniform mediump float blurRadius;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize + blurRadius * 2.0;\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  vRectSize = visualSize / 2.0;\n"
-  "  vPosition = aPosition* visualSize;\n"
-  "  return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "}\n";
-
-const char* FRAGMENT_SHADER_BLUR_EDGE =
-  "INPUT mediump vec2 vPosition;\n"
-  "INPUT mediump vec2 vRectSize;\n"
-
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform mediump float blurRadius;\n"
-
-  "void main()\n"
-  "{\n"
-  "  mediump vec2 blur = 1.0 - smoothstep( vRectSize - blurRadius * 2.0, vRectSize, abs( vPosition ) );\n"
-  "  OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n"
-  "  OUT_COLOR.a *= blur.x * blur.y;\n"
-  "}\n";
-
-}
-
 ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
 {
   ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) );
@@ -363,7 +225,7 @@ Shader ColorVisual::GetShader()
     shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_BLUR_EDGE, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BLUR_EDGE );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE, shader );
     }
   }
@@ -372,7 +234,7 @@ Shader ColorVisual::GetShader()
     shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER, shader );
     }
   }
@@ -381,7 +243,7 @@ Shader ColorVisual::GetShader()
     shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER );
     if( !shader )
     {
-      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER );
+      shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() );
       mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER, shader );
     }
   }
index b86f9a7..504b0e0 100644 (file)
 #include <dali-toolkit/internal/visuals/gradient/linear-gradient.h>
 #include <dali-toolkit/internal/visuals/gradient/radial-gradient.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-shader-vert.h>
 
 namespace Dali
 {
@@ -83,220 +91,34 @@ VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[][4] =
   }
 };
 
-const char* VERTEX_SHADER[] =
+const std::string_view VERTEX_SHADER[] =
 {
-// vertex shader for gradient units as OBJECT_BOUNDING_BOX
-DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump mat3 uAlignmentMatrix;\n
-  varying mediump vec2 vTexCoord;\n
-  \n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
-    \n
-    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-  }\n
-),
-
-// vertex shader for gradient units as USER_SPACE
-DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump mat3 uAlignmentMatrix;\n
-  varying mediump vec2 vTexCoord;\n
-  \n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vertexPosition.xyz *= uSize;\n
-    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-    \n
-    vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
-  }\n
-),
-
-// vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius
-DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump mat3 uAlignmentMatrix;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vPosition;\n
-  varying mediump vec2 vRectSize;\n
-  varying mediump float vCornerRadius;\n
-  \n
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-  uniform mediump float cornerRadius;\n
-  uniform mediump float cornerRadiusPolicy;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    mediump float minSize = min( visualSize.x, visualSize.y );\n
-    vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n
-    vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n
-    vRectSize = visualSize * 0.5 - vCornerRadius;\n
-    vPosition = aPosition * visualSize;\n
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
-    \n
-    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-  }\n
-),
-
-// vertex shader for gradient units as USER_SPACE with corner radius
-DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump mat3 uAlignmentMatrix;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vPosition;\n
-  varying mediump vec2 vRectSize;\n
-  varying mediump float vCornerRadius;\n
-  \n
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-  uniform mediump float cornerRadius;\n
-  uniform mediump float cornerRadiusPolicy;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    mediump float minSize = min( visualSize.x, visualSize.y );\n
-    vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n
-    vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n
-    vRectSize = visualSize * 0.5 - vCornerRadius;\n
-    vPosition = aPosition * visualSize;\n
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vertexPosition.xyz *= uSize;\n
-    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-    \n
-    vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n
-  }\n
-)
+  // vertex shader for gradient units as OBJECT_BOUNDING_BOX
+  SHADER_GRADIENT_VISUAL_BOUNDING_BOX_SHADER_VERT,
+
+  // vertex shader for gradient units as USER_SPACE
+  SHADER_GRADIENT_VISUAL_USER_SPACE_SHADER_VERT,
+
+  // vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius
+  SHADER_GRADIENT_VISUAL_BOUNDING_BOX_ROUNDED_CORNER_SHADER_VERT,
+
+  // vertex shader for gradient units as USER_SPACE with corner radius
+  SHADER_GRADIENT_VISUAL_USER_SPACE_ROUNDED_CORNER_SHADER_VERT
 };
 
-const char* FRAGMENT_SHADER[] =
+const std::string_view FRAGMENT_SHADER[] =
 {
-// fragment shader for linear gradient
-DALI_COMPOSE_SHADER(
-  uniform sampler2D sTexture;\n // sampler1D?
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  varying mediump vec2 vTexCoord;\n
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
-  }\n
-),
-
-// fragment shader for radial gradient
-DALI_COMPOSE_SHADER(
-  uniform sampler2D sTexture;\n // sampler1D?
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  varying mediump vec2 vTexCoord;\n
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
-  }\n
-),
-
-// fragment shader for linear gradient with corner radius
-DALI_COMPOSE_SHADER(
-  uniform sampler2D sTexture;\n // sampler1D?
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vPosition;\n
-  varying mediump vec2 vRectSize;\n
-  varying mediump float vCornerRadius;\n
-  \n
-  void main()\n
-  {\n
-    mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n
-    gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
-    gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n
-  }\n
-),
-
-// fragment shader for radial gradient with corner radius
-DALI_COMPOSE_SHADER(
-  uniform sampler2D sTexture;\n // sampler1D?
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vPosition;\n
-  varying mediump vec2 vRectSize;\n
-  varying mediump float vCornerRadius;\n
-  \n
-  void main()\n
-  {\n
-    mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n
-    gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n
-    gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n
-  }\n
-)
+  // fragment shader for linear gradient
+  SHADER_GRADIENT_VISUAL_LINEAR_SHADER_FRAG,
+
+  // fragment shader for radial gradient
+  SHADER_GRADIENT_VISUAL_RADIAL_SHADER_FRAG,
+
+  // fragment shader for linear gradient with corner radius
+  SHADER_GRADIENT_VISUAL_LINEAR_ROUNDED_CORNER_SHADER_FRAG,
+
+  // fragment shader for radial gradient with corner radius
+  SHADER_GRADIENT_VISUAL_RADIAL_ROUNDED_CORNER_SHADER_FRAG
 };
 
 Dali::WrapMode::Type GetWrapMode( Toolkit::GradientVisual::SpreadMethod::Type spread )
index 5bc09ce..523c374 100644 (file)
@@ -21,6 +21,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 #include <dali/integration-api/debug.h>
 
 namespace Dali
@@ -37,155 +38,6 @@ namespace
 
 const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
 
-const char* VERTEX_SHADER =
-  "INPUT mediump vec2 aPosition;\n"
-  "OUTPUT mediump vec2 vTexCoord;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-  "uniform mediump vec4 pixelArea;"
-  "//Visual size and offset\n"
-
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-  "uniform mediump vec2 extraSize;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-  "\n"
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "  vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n"
-  "}\n";
-
-const char* FRAGMENT_SHADER_NO_ATLAS =
-  "INPUT mediump vec2 vTexCoord;\n"
-
-  "uniform sampler2D sTexture;\n"
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform lowp float preMultipliedAlpha;\n"
-
-  "void main()\n"
-  "{\n"
-  "  OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n"
-  "}\n";
-
-
-const char* FRAGMENT_SHADER_ATLAS_CLAMP =
-  "INPUT mediump vec2 vTexCoord;\n"
-
-  "uniform sampler2D sTexture;\n"
-  "uniform mediump vec4 uAtlasRect;\n"
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform lowp float preMultipliedAlpha;\n"
-
-  "void main()\n"
-  "{\n"
-  "  mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw );\n"
-  "  OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n"
-  "}\n";
-
-
-const char* FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP =
-  "INPUT mediump vec2 vTexCoord;\n"
-
-  "uniform sampler2D sTexture;\n"
-  "uniform mediump vec4 uAtlasRect;\n"
-  "// WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT;"
-  "uniform lowp vec2 wrapMode;\n"
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform lowp float preMultipliedAlpha;\n"
-  "mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap )\n"
-
-  "{\n"
-  "  mediump float coord;\n"
-  "  if( wrap > 1.5 )\n // REFLECT"
-  "    coord = 1.0-abs(fract(coordinate*0.5)*2.0 - 1.0);\n"
-  "  else \n// warp == 0 or 1"
-  "    coord = mix(coordinate, fract( coordinate ), wrap);\n"
-  "  return clamp( mix(range.x, range.y, coord), range.x, range.y );"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ),"
-  "                                wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) );\n"
-  "  OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n"
-  "}\n";
-
-const char* VERTEX_SHADER_ROUNDED_CORNER =
-  "INPUT mediump vec2 aPosition;\n"
-  "OUTPUT mediump vec2 vTexCoord;\n"
-  "OUTPUT mediump vec2 vPosition;\n"
-  "OUTPUT mediump vec2 vRectSize;\n"
-  "OUTPUT mediump float vCornerRadius;\n"
-
-  "uniform highp mat4 uMvpMatrix;\n"
-  "uniform highp vec3 uSize;\n"
-  "uniform mediump vec4 pixelArea;"
-
-  "//Visual size and offset\n"
-  "uniform mediump vec2 offset;\n"
-  "uniform highp vec2 size;\n"
-  "uniform mediump vec4 offsetSizeMode;\n"
-  "uniform mediump vec2 origin;\n"
-  "uniform mediump vec2 anchorPoint;\n"
-  "uniform mediump float cornerRadius;\n"
-  "uniform mediump float cornerRadiusPolicy;\n"
-  "uniform mediump vec2 extraSize;\n"
-
-  "vec4 ComputeVertexPosition()\n"
-  "{\n"
-  "  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n"
-  "  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n"
-  "  mediump float minSize = min( visualSize.x, visualSize.y );\n"
-  "  vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n"
-  "  vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n"
-  "  vRectSize = visualSize * 0.5 - vCornerRadius;\n"
-  "  vPosition = aPosition* visualSize;\n"
-  "  return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n"
-  "}\n"
-
-  "void main()\n"
-  "{\n"
-  "  gl_Position = uMvpMatrix * ComputeVertexPosition();\n"
-  "  vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n"
-  "}\n";
-
-
-//float distance = length( max( abs( position - center ), size ) - size ) - radius;
-const char* FRAGMENT_SHADER_ROUNDED_CORNER =
-  "INPUT mediump vec2 vTexCoord;\n"
-  "INPUT mediump vec2 vPosition;\n"
-  "INPUT mediump vec2 vRectSize;\n"
-  "INPUT mediump float vCornerRadius;\n"
-
-  "uniform sampler2D sTexture;\n"
-  "uniform lowp vec4 uColor;\n"
-  "uniform lowp vec3 mixColor;\n"
-  "uniform lowp float preMultipliedAlpha;\n"
-
-  "void main()\n"
-  "{\n"
-  "  mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n"
-  "  mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );\n"
-
-  "  OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n"
-  "  OUT_COLOR.a *= opacity;\n"
-  "  OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n"
-  "}\n";
-
 // global string variable to caching complate vertex shader
 static std::string gVertexShader;
 
@@ -212,7 +64,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo
       shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP );
       if( !shader )
       {
-        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_CLAMP );
+        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+                              Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_CLAMP_SHADER_FRAG.data() );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
         factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP, shader );
       }
@@ -222,7 +75,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo
       shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP );
       if( !shader )
       {
-        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP );
+        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+                              Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_VARIOUS_WRAP_SHADER_FRAG.data() );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
         factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP, shader );
       }
@@ -235,7 +89,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo
       shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER );
       if( !shader )
       {
-        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER );
+        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(),
+                              Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
         factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, shader );
       }
@@ -245,7 +100,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo
       shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER );
       if( !shader )
       {
-        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS );
+        shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(),
+                              Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data() );
         shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
         factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER, shader );
       }
@@ -259,7 +115,7 @@ std::string_view ImageVisualShaderFactory::GetVertexShaderSource()
 {
   if(gVertexShader.empty())
   {
-    gVertexShader = Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER;
+    gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data();
   }
 
   return gVertexShader;
@@ -269,7 +125,7 @@ std::string_view ImageVisualShaderFactory::GetFragmentShaderSource()
 {
   if(gFragmentShaderNoAtlas.empty())
   {
-    gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS;
+    gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data();
   }
   return gFragmentShaderNoAtlas;
 }
index 4d6a4cd..f34f66c 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -94,253 +95,6 @@ DALI_ENUM_TO_STRING_TABLE_END( SHADING_MODE )
 const char * const OBJECT_MATRIX_UNIFORM_NAME( "uObjectMatrix" );
 const char * const STAGE_OFFSET_UNIFORM_NAME( "uStageOffset" );
 
-//Shaders
-//If a shader requires certain textures, they must be listed in order,
-//as detailed in the TextureIndex enum documentation.
-
-//A basic shader that doesn't use textures at all.
-const char* SIMPLE_VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute highp vec3 aPosition;\n
-  attribute highp vec3 aNormal;\n
-  varying mediump vec3 vIllumination;\n
-  uniform mediump vec3 uSize;\n
-  uniform mediump mat4 uMvpMatrix;\n
-  uniform mediump mat4 uModelView;\n
-  uniform mediump mat4 uViewMatrix;\n
-  uniform mediump mat3 uNormalMatrix;
-  uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 lightPosition;\n
-  uniform mediump vec2 uStageOffset;\n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform mediump vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    float scaleFactor = min( visualSize.x, visualSize.y );\n
-    vec3 originFlipY =  vec3(origin.x, -origin.y, 0.0);
-    vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
-    vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
-    return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    vec4 normalisedVertexPosition = ComputeVertexPosition();\n
-    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-
-    //Illumination in Model-View space - Transform attributes and uniforms\n
-    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
-    vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
-
-    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
-    mvLightPosition = uViewMatrix * mvLightPosition;\n
-    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
-    float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
-    vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
-    gl_Position = vertexPosition;\n
-  }\n
-);
-
-//Fragment shader corresponding to the texture-less shader.
-const char* SIMPLE_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;\n
-  varying mediump vec3 vIllumination;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  uniform lowp float preMultipliedAlpha;\n
-
-  void main()\n
-  {\n
-    gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ) * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
-//Diffuse and specular illumination shader with albedo texture. Texture is index 0.
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute highp vec3 aPosition;\n
-  attribute highp vec2 aTexCoord;\n
-  attribute highp vec3 aNormal;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec3 vIllumination;\n
-  varying mediump float vSpecular;\n
-  uniform mediump vec3 uSize;\n
-  uniform mediump mat4 uMvpMatrix;\n
-  uniform mediump mat4 uModelView;
-  uniform mediump mat4 uViewMatrix;\n
-  uniform mediump mat3 uNormalMatrix;
-  uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 lightPosition;\n
-  uniform mediump vec2 uStageOffset;\n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform mediump vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    float scaleFactor = min( visualSize.x, visualSize.y );\n
-    vec3 originFlipY =  vec3(origin.x, -origin.y, 0.0);
-    vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
-    vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
-    return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
-  }\n
-
-  void main()
-  {\n
-    vec4 normalisedVertexPosition = ComputeVertexPosition();\n
-    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-
-    //Illumination in Model-View space - Transform attributes and uniforms\n
-    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
-    vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );\n
-
-    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
-    mvLightPosition = uViewMatrix * mvLightPosition;\n
-    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
-    vec3 viewDirection = normalize( -mvVertexPosition.xyz );
-
-    float lightDiffuse = dot( vectorToLight, normal );\n
-    lightDiffuse = max( 0.0,lightDiffuse );\n
-    vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
-    vec3 reflectDirection = reflect( -vectorToLight, normal );
-    vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 );
-
-    vTexCoord = aTexCoord;\n
-    gl_Position = vertexPosition;\n
-  }\n
-);
-
-//Fragment shader corresponding to the diffuse and specular illumination shader with albedo texture
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec3 vIllumination;\n
-  varying mediump float vSpecular;\n
-  uniform sampler2D sDiffuse;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  uniform lowp float preMultipliedAlpha;\n
-
-  void main()\n
-  {\n
-    vec4 texture = texture2D( sDiffuse, vTexCoord );\n
-    vec4 visualMixColor = vec4( mixColor, 1.0 );\n
-    gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb * visualMixColor.rgb + vSpecular * 0.3, texture.a * uColor.a * visualMixColor.a );\n
-  }\n
-);
-
-//Diffuse and specular illumination shader with albedo texture, normal map and gloss map shader.
-//Diffuse (albedo) texture is index 0, normal is 1, gloss is 2. They must be declared in this order.
-const char* NORMAL_MAP_VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute highp vec3 aPosition;\n
-  attribute highp vec2 aTexCoord;\n
-  attribute highp vec3 aNormal;\n
-  attribute highp vec3 aTangent;\n
-  attribute highp vec3 aBiNormal;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec3 vLightDirection;\n
-  varying mediump vec3 vHalfVector;\n
-  uniform mediump vec3 uSize;\n
-  uniform mediump mat4 uMvpMatrix;\n
-  uniform mediump mat4 uModelView;
-  uniform mediump mat4 uViewMatrix;\n
-  uniform mediump mat3 uNormalMatrix;
-  uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 lightPosition;\n
-  uniform mediump vec2 uStageOffset;\n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform mediump vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    float scaleFactor = min( visualSize.x, visualSize.y );\n
-    vec3 originFlipY =  vec3(origin.x, -origin.y, 0.0);
-    vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
-    vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
-    return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
-  }\n
-
-  void main()
-  {\n
-    vec4 normalisedVertexPosition = ComputeVertexPosition();\n
-    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-
-    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
-
-    vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
-    vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
-    vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
-
-    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
-    mvLightPosition = uViewMatrix * mvLightPosition;\n
-    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-    vLightDirection.x = dot( vectorToLight, tangent );
-    vLightDirection.y = dot( vectorToLight, binormal );
-    vLightDirection.z = dot( vectorToLight, normal );
-
-    vec3 viewDirection = normalize( -mvVertexPosition.xyz );
-    vec3 halfVector = normalize( viewDirection + vectorToLight );
-    vHalfVector.x = dot( halfVector, tangent );
-    vHalfVector.y = dot( halfVector, binormal );
-    vHalfVector.z = dot( halfVector, normal );
-
-    vTexCoord = aTexCoord;\n
-    gl_Position = vertexPosition;\n
-  }\n
-);
-
-//Fragment shader corresponding to the shader that uses all textures (diffuse, normal and gloss maps)
-const char* NORMAL_MAP_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec3 vLightDirection;\n
-  varying mediump vec3 vHalfVector;\n
-  uniform sampler2D sDiffuse;\n
-  uniform sampler2D sNormal;\n
-  uniform sampler2D sGloss;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  uniform lowp float preMultipliedAlpha;\n
-
-  void main()\n
-  {\n
-    vec4 texture = texture2D( sDiffuse, vTexCoord );\n
-    vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );\n
-    vec4 glossMap = texture2D( sGloss, vTexCoord );\n
-    vec4 visualMixColor = vec4( mixColor, 1.0 );\n
-
-    float lightDiffuse = max( 0.0, dot( normal, normalize( vLightDirection ) ) );\n
-    lightDiffuse = lightDiffuse * 0.5 + 0.5;\n
-
-    float shininess = pow ( max ( dot ( normalize( vHalfVector ), normal ), 0.0 ), 16.0 )  ;
-
-    gl_FragColor = vec4( texture.rgb * uColor.rgb * visualMixColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a * visualMixColor.a );\n
-  }\n
-);
-
 } // unnamed namespace
 
 MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -564,7 +318,7 @@ void MeshVisual::InitializeRenderer()
 void MeshVisual::SupplyEmptyGeometry()
 {
   mGeometry = Geometry::New();
-  mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+  mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG );
   mImpl->mRenderer = Renderer::New( mGeometry, mShader );
 
   DALI_LOG_ERROR( "Initialisation error in mesh visual.\n" );
@@ -588,15 +342,15 @@ void MeshVisual::CreateShader()
 {
   if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING )
   {
-    mShader = Shader::New( NORMAL_MAP_VERTEX_SHADER, NORMAL_MAP_FRAGMENT_SHADER );
+    mShader = Shader::New( SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_VERT, SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_FRAG );
   }
   else if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING )
   {
-    mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+    mShader = Shader::New( SHADER_MESH_VISUAL_SHADER_VERT, SHADER_MESH_VISUAL_SHADER_FRAG );
   }
   else //Textureless
   {
-    mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER );
+    mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG );
   }
 
   UpdateShaderUniforms();
index 6dcf020..8bbdb09 100644 (file)
@@ -33,6 +33,7 @@
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/rendering-addon.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -45,128 +46,6 @@ namespace Internal
 
 namespace
 {
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vMaskTexCoord;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n
-  uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n
-  \n
-
-  // Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-  uniform mediump vec2 extraSize;\n
-
-  void main()\n
-  {\n
-    mediump vec2 fixedFactor  = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n
-    mediump vec2 stretch      = vec2( uNinePatchFactorsX[ int( ( aPosition.x       ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y       ) * 0.5 ) ].y );\n
-    \n
-    mediump vec2 fixedTotal   = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n
-    mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n
-    \n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    \n
-    mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );\n
-    mediump vec4 vertexPosition = gridPosition;\n
-    vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );\n
-    vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-    \n
-    vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n
-    vMaskTexCoord = gridPosition.xy / visualSize;\n
-    \n
-    gl_Position = vertexPosition;\n
-  }\n
-);
-
-const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER(
-    attribute mediump vec2 aPosition;\n
-    varying mediump vec2 vTexCoord;\n
-    varying mediump vec2 vMaskTexCoord;\n
-    uniform highp   mat4 uMvpMatrix;\n
-    uniform highp   vec3 uSize;\n
-    uniform mediump vec2 uFixed[ 3 ];\n
-    uniform mediump vec2 uStretchTotal;\n
-    \n
-    //Visual size and offset
-    uniform mediump vec2 offset;\n
-    uniform highp   vec2 size;\n
-    uniform mediump vec4 offsetSizeMode;\n
-    uniform mediump vec2 origin;\n
-    uniform mediump vec2 anchorPoint;\n
-    uniform mediump vec2 extraSize;\n
-    \n
-    void main()\n
-    {\n
-      vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n
-      vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-      \n
-      mediump vec2 size         = visualSize.xy;\n
-      \n
-      mediump vec2 fixedFactor  = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y  + 1.0 ) * 0.5 ) ].y );\n
-      mediump vec2 stretch      = floor( aPosition * 0.5 );\n
-      mediump vec2 fixedTotal   = uFixed[ 2 ];\n
-      \n
-      mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n
-      mediump vec4 vertexPosition = gridPosition;\n
-      vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n
-      vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;\n
-      \n
-      vertexPosition = uMvpMatrix * vertexPosition;\n
-      \n
-      vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n
-      \n
-      vMaskTexCoord = gridPosition.xy / size;\n
-      gl_Position = vertexPosition;\n
-    }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  uniform lowp float preMultipliedAlpha;\n
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
-const char* FRAGMENT_MASK_SHADER = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  varying mediump vec2 vMaskTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform sampler2D sMask;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  uniform lowp float preMultipliedAlpha;\n
-  uniform mediump float auxiliaryImageAlpha;\n
-  \n
-  void main()\n
-  {\n
-      // Where mask image is transparent, all of background image must show through.
-      // where mask image is opaque, only mask should be shown
-      // where mask is translucent, less of background should be shown.
-      // auxiliaryImageAlpha controls how much of mask is visible
-
-      mediump vec4 color = texture2D( sTexture, vTexCoord );\n
-      mediump vec4 mask  = texture2D( sMask, vMaskTexCoord );\n
-
-      mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha)
-                                + mask.rgb*mask.a * auxiliaryImageAlpha;\n
-      gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
 
 /**
  * @brief Creates the geometry formed from the vertices and indices
@@ -562,8 +441,8 @@ Shader NPatchVisual::CreateShader()
   NPatchUtility::StretchRanges::SizeType xStretchCount = 0;
   NPatchUtility::StretchRanges::SizeType yStretchCount = 0;
 
-  auto fragmentShader = mAuxiliaryPixelBuffer ? FRAGMENT_MASK_SHADER
-                                              : FRAGMENT_SHADER;
+  auto fragmentShader = mAuxiliaryPixelBuffer ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG
+                                              : SHADER_NPATCH_VISUAL_SHADER_FRAG;
   auto shaderType = mAuxiliaryPixelBuffer ? VisualFactoryCache::NINE_PATCH_MASK_SHADER
                                           : VisualFactoryCache::NINE_PATCH_SHADER;
 
@@ -582,7 +461,7 @@ Shader NPatchVisual::CreateShader()
       shader = mFactoryCache.GetShader( shaderType );
       if( DALI_UNLIKELY( !shader ) )
       {
-        shader = Shader::New( VERTEX_SHADER_3X3, fragmentShader );
+        shader = Shader::New( SHADER_NPATCH_VISUAL_3X3_SHADER_VERT, fragmentShader );
         // Only cache vanilla 9 patch shaders
         mFactoryCache.SaveShader( shaderType, shader );
       }
@@ -592,7 +471,7 @@ Shader NPatchVisual::CreateShader()
       std::stringstream vertexShader;
       vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n"
                    << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n"
-                   << VERTEX_SHADER;
+                   << SHADER_NPATCH_VISUAL_SHADER_VERT;
 
       shader = Shader::New( vertexShader.str(), fragmentShader );
     }
@@ -611,7 +490,7 @@ Shader NPatchVisual::CreateShader()
     if( ( xStretchCount == 1 && yStretchCount == 1 ) ||
         ( xStretchCount == 0 && yStretchCount == 0 ) )
     {
-      const char* vertexShader = VERTEX_SHADER_3X3;
+      const char* vertexShader = SHADER_NPATCH_VISUAL_3X3_SHADER_VERT.data();
 
       if( !mImpl->mCustomShader->mVertexShader.empty() )
       {
@@ -624,7 +503,7 @@ Shader NPatchVisual::CreateShader()
       std::stringstream vertexShader;
       vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n"
                    << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n"
-                   << VERTEX_SHADER;
+                   << SHADER_NPATCH_VISUAL_SHADER_VERT;
 
       shader = Shader::New( vertexShader.str(), fragmentShader, hints );
     }
index 21c9064..7ad7bf5 100644 (file)
@@ -29,6 +29,7 @@
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -92,74 +93,6 @@ const char * const POSITION( "aPosition");
 const char * const NORMAL( "aNormal" );
 const char * const INDICES( "aIndices" );
 
-//A simple shader that applies diffuse lighting to a mono-coloured object.
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute highp   vec3 aPosition;\n
-  attribute highp   vec2 aTexCoord;\n
-  attribute highp   vec3 aNormal;\n
-  varying   mediump vec3 vIllumination;\n
-  uniform   mediump vec3 uSize;\n
-  uniform   mediump vec3 uObjectDimensions;\n
-  uniform   mediump mat4 uMvpMatrix;\n
-  uniform   mediump mat4 uModelView;\n
-  uniform   mediump mat4 uViewMatrix;\n
-  uniform   mediump mat3 uNormalMatrix;\n
-  uniform   mediump mat4 uObjectMatrix;\n
-  uniform   mediump vec3 lightPosition;\n
-  uniform   mediump vec2 uStageOffset;\n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform mediump vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    float scaleFactor = min( visualSize.x / uObjectDimensions.x, visualSize.y / uObjectDimensions.y );\n
-    vec3 originFlipY =  vec3(origin.x, -origin.y, 0.0);
-    vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
-    vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n
-
-    return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    vec4 normalisedVertexPosition = ComputeVertexPosition();\n
-    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-
-     //Illumination in Model-View space - Transform attributes and uniforms\n
-     vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
-     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
-
-     vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
-     mvLightPosition = uViewMatrix * mvLightPosition;\n
-     vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
-
-     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
-     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
-
-     gl_Position = vertexPosition;\n
-  }\n
-);
-
-//Very simple fragment shader that merely applies the vertex shading to the color at each fragment.
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;\n
-  varying   mediump vec3  vIllumination;\n
-  uniform   lowp    vec4  uColor;\n
-  uniform   lowp    vec3  mixColor;\n
-  void main()\n
-  {\n
-      vec4 baseColor = vec4(mixColor, 1.0) * uColor;\n
-    gl_FragColor = vec4( vIllumination.rgb * baseColor.rgb, baseColor.a );\n
-  }\n
-);
-
 } // unnamed namespace
 
 PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -478,7 +411,7 @@ void PrimitiveVisual::UpdateShaderUniforms()
 
 void PrimitiveVisual::CreateShader()
 {
-  mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+  mShader = Shader::New( SHADER_PRIMITIVE_VISUAL_SHADER_VERT, SHADER_PRIMITIVE_VISUAL_SHADER_FRAG );
   UpdateShaderUniforms();
 }
 
index f8d5f53..29b18a1 100755 (executable)
@@ -41,6 +41,7 @@
 #include <dali-toolkit/internal/text/script-run.h>
 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -55,151 +56,6 @@ namespace
 {
 const Vector4 FULL_TEXTURE_RECT( 0.f, 0.f, 1.f, 1.f );
 
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform highp   mat4 uMvpMatrix;\n
-  uniform highp   vec3 uSize;\n
-  uniform mediump vec4 pixelArea;\n
-
-  varying mediump vec2 vTexCoord;\n
-
-  //Visual size and offset
-  uniform mediump vec2 offset;\n
-  uniform highp   vec2 size;\n
-  uniform mediump vec4 offsetSizeMode;\n
-  uniform mediump vec2 origin;\n
-  uniform mediump vec2 anchorPoint;\n
-
-  vec4 ComputeVertexPosition()\n
-  {\n
-    vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-    vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-    return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-  }\n
-
-  void main()\n
-  {\n
-    gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-    vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uTextColorAnimatable;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n
-
-    // Set the color of the text to what it is animated to.
-    gl_FragColor = uTextColorAnimatable * textTexture * uColor * vec4( mixColor, 1.0 );
-  }\n
-);
-
-const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-
-    gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );
-  }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform sampler2D sStyle;\n
-  uniform lowp vec4 uTextColorAnimatable;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n
-    mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
-
-    // Draw the text as overlay above the style
-    gl_FragColor = ( uTextColorAnimatable * textTexture + styleTexture * ( 1.0 - uTextColorAnimatable.a * textTexture ) ) * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform sampler2D sStyle;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-    mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
-
-    // Draw the text as overlay above the style
-    gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform sampler2D sMask;\n
-  uniform lowp vec4 uTextColorAnimatable;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-    mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n
-
-    // Set the color of non-transparent pixel in text to what it is animated to.
-    // Markup text with multiple text colors are not animated (but can be supported later on if required).
-    // Emoji color are not animated.
-    mediump float vstep = step( 0.0001, textTexture.a );\n
-    textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture );\n
-
-    // Draw the text as overlay above the style
-    gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform sampler2D sStyle;\n
-  uniform sampler2D sMask;\n
-  uniform lowp float uHasMultipleTextColors;\n
-  uniform lowp vec4 uTextColorAnimatable;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n
-    mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n
-    mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n
-
-    // Set the color of non-transparent pixel in text to what it is animated to.
-    // Markup text with multiple text colors are not animated (but can be supported later on if required).
-    // Emoji color are not animated.
-    mediump float vstep = step( 0.0001, textTexture.a );\n
-    textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * ( 1.0 - uHasMultipleTextColors ) );\n
-
-    // Draw the text as overlay above the style
-    gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n
-  }\n
-);
-
 /**
  * Return Property index for the given string key
  * param[in] stringKey the string index key
@@ -929,7 +785,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT, shader );
     }
@@ -940,7 +796,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_WITH_STYLE_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE, shader );
     }
@@ -950,7 +806,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT, shader );
     }
@@ -960,7 +816,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE, shader );
     }
@@ -970,7 +826,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_EMOJI_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI, shader );
     }
@@ -980,7 +836,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult
     shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI );
     if( !shader )
     {
-      shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI );
+      shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI_SHADER_FRAG );
       shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT );
       factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI, shader );
     }
index 3707465..f563fc1 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 
 namespace Dali
 {
@@ -39,43 +40,6 @@ namespace
 {
 const char * const POSITION_ATTRIBUTE_NAME("aPosition");
 const char * const INDEX_NAME("indices");
-
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-attribute mediump vec2  aPosition;\n
-uniform   highp   mat4  uMvpMatrix;\n
-uniform   highp   vec3  uSize;\n
-\n
-
-//Visual size and offset
-uniform mediump vec2 offset;\n
-uniform highp   vec2 size;\n
-uniform mediump vec4 offsetSizeMode;\n
-uniform mediump vec2 origin;\n
-uniform mediump vec2 anchorPoint;\n
-
-vec4 ComputeVertexPosition()\n
-{\n
-  vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
-  vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
-  return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
-}\n
-
-void main()\n
-{\n
-  gl_Position = uMvpMatrix * ComputeVertexPosition();\n
-}\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec3 mixColor;\n
-\n
-void main()\n
-{\n
-  gl_FragColor = uColor * vec4( mixColor, 1.0 );\n
-}\n
-);
-
 }
 
 WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -183,7 +147,7 @@ void WireframeVisual::InitializeRenderer()
   Shader shader = mFactoryCache.GetShader( VisualFactoryCache::WIREFRAME_SHADER );
   if( !shader )
   {
-    shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+    shader = Shader::New( SHADER_WIREFRAME_VISUAL_SHADER_VERT, SHADER_WIREFRAME_VISUAL_SHADER_FRAG );
     mFactoryCache.SaveShader( VisualFactoryCache::WIREFRAME_SHADER, shader );
   }