Convert more shaders in dali-toolkit and dali-scene-loader to use shader compilation...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / filters / blur-two-pass-filter.cpp
index a5adec7..f86ffd4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 // EXTERNAL INCLUDES
 #include <sstream>
 #include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/common/stage.h>
+#include <dali/devel-api/common/stage.h>
 #include <dali/public-api/object/property-map.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/rendering/renderer.h>
 
 // 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,13 +104,13 @@ 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
   mActorForInput = Actor::New();
   mActorForInput.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mActorForInput.SetSize( mTargetSize );
+  mActorForInput.SetProperty( Actor::Property::SIZE, mTargetSize );
   Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
   SetRendererTexture( rendererForInput, mInputTexture );
   mActorForInput.AddRenderer( rendererForInput );
@@ -154,7 +123,7 @@ void BlurTwoPassFilter::Enable()
   // create an actor to render mImageForHorz for vertical blur pass
   mActorForHorz = Actor::New();
   mActorForHorz.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mActorForHorz.SetSize( mTargetSize );
+  mActorForHorz.SetProperty( Actor::Property::SIZE, mTargetSize );
   Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
   SetRendererTexture( rendererForHorz, textureForHorz );
   mActorForHorz.AddRenderer( rendererForHorz );
@@ -165,13 +134,13 @@ 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 );
   mActorForBlending.AddRenderer( rendererForBlending );
   mActorForBlending.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mActorForBlending.SetSize( mTargetSize );
+  mActorForBlending.SetProperty( Actor::Property::SIZE, mTargetSize );
 
   for( int i = 0; i < kernelSize; ++i )
   {
@@ -257,15 +226,15 @@ void BlurTwoPassFilter::SetSize( const Vector2& size )
   mTargetSize = size;
   if( mActorForInput )
   {
-    mActorForInput.SetSize(mTargetSize);
+    mActorForInput.SetProperty( Actor::Property::SIZE, mTargetSize);
   }
   if( mActorForHorz )
   {
-    mActorForHorz.SetSize(mTargetSize);
+    mActorForHorz.SetProperty( Actor::Property::SIZE, mTargetSize);
   }
   if( mActorForBlending )
   {
-    mActorForBlending.SetSize(mTargetSize);
+    mActorForBlending.SetProperty( Actor::Property::SIZE, mTargetSize);
   }
 }