namespace
{
-const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
+const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
} // namespace
void utc_gaussian_blur_view_startup(void)
Stage::GetCurrent().Add(view);
view.Activate();
- FrameBufferImage renderTarget = FrameBufferImage::New( 480.0f, 800.0f, Pixel::RGB888 );
- view.SetUserImageAndOutputRenderTarget(ResourceImage::New(TEST_IMAGE_FILE_NAME), renderTarget);
+ PixelData pixels = Toolkit::SyncImageLoader::Load( TEST_IMAGE_FILE_NAME );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
+ texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
+
+ FrameBuffer renderTarget = FrameBuffer::New( 480, 800, FrameBuffer::Attachment::NONE );
+ view.SetUserImageAndOutputRenderTarget(texture, renderTarget);
DALI_TEST_CHECK( view.GetBlurredRenderTarget() == renderTarget );
END_TEST;
}
int UtcDaliGaussianBlurViewFinishedSignalN(void)
{
ToolkitTestApplication application;
- tet_infoline("UtcDaliGaussianBlurViewSetGetRenderTarget");
+ tet_infoline("UtcDaliGaussianBlurViewFinishedSignalN");
Toolkit::GaussianBlurView view = Toolkit::GaussianBlurView::New(5, 1.5f, Pixel::RGB888, 0.5f, 0.5f, true);
DALI_TEST_CHECK( view );
{
const int BLUR_LEVELS = 3;
const int RENDER_FRAME_INTERVAL = 16;
-const char* TEST_IMAGE_FILE_NAME("image.png");
+static const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
static bool gObjectCreatedCallBackCalled;
static void TestCallback(BaseHandle handle)
{
return time;
}
-Image CreateSolidColorImage( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
+Texture CreateSolidColorTexture( ToolkitTestApplication& application, const Vector4& color, unsigned int width, unsigned int height )
{
- BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
-
- // Create the image
- PixelBuffer* pixbuf = imageData.GetBuffer();
unsigned int size = width * height;
+ uint8_t* pixbuf = new uint8_t[size*4];
for( size_t i = 0; i < size; i++ )
- {
- pixbuf[i*4+0] = 0xFF * color.r;
- pixbuf[i*4+1] = 0xFF * color.g;
- pixbuf[i*4+2] = 0xFF * color.b;
- pixbuf[i*4+3] = 0xFF * color.a;
- }
- imageData.Update();
+ {
+ pixbuf[i*4+0] = 0xFF * color.r;
+ pixbuf[i*4+1] = 0xFF * color.g;
+ pixbuf[i*4+2] = 0xFF * color.b;
+ pixbuf[i*4+3] = 0xFF * color.a;
+ }
- application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE );
- application.SendNotification();
- application.Render(RENDER_FRAME_INTERVAL);
- application.Render(RENDER_FRAME_INTERVAL);
- application.SendNotification();
+ PixelData pixels = PixelData::New( pixbuf, size, width, height, Pixel::RGBA8888, PixelData::ReleaseFunction::DELETE_ARRAY );
- return imageData;
-}
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
+ texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
-void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
-{
- Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
- Integration::ResourcePointer resource(bitmap);
- bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
+ return texture;
}
class SignalHandler : public Dali::ConnectionTracker
}
-int UtcDaliSuperBlurViewSetImage(void)
+int UtcDaliSuperBlurViewSetTexture(void)
{
ToolkitTestApplication application;
- tet_infoline(" UtcDaliSuperBlurViewSetImage ");
+ tet_infoline(" UtcDaliSuperBlurViewSetTexture ");
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
blurView.SetSize( 100.f, 100.f );
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
- blurView.SetImage( inputImage );
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
// start multiple guassian blur call, each guassian blur creates two render tasks
DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
{
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
Stage::GetCurrent().Add( blurView );
Wait(application);
DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
END_TEST;
}
-int UtcDaliSuperBlurViewSetImage2(void)
+int UtcDaliSuperBlurViewSetTexture2(void)
{
ToolkitTestApplication application;
Stage stage = Stage::GetCurrent();
- tet_infoline(" UtcDaliSuperBlurViewSetImage2 - test setting a second image ");
+ tet_infoline(" UtcDaliSuperBlurViewSetTexture2 - test setting a second texture ");
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
blurView.SetSize( 100.f, 100.f );
- tet_infoline("Call SetImage and add blurview to stage");
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
- blurView.SetImage( inputImage );
+ tet_infoline("Call SetTexture and add blurview to stage");
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
// start multiple guassian blur call, each guassian blur creates two render tasks
DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
{
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
stage.Add( blurView );
Wait(application);
DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
tet_infoline("Test that there are no render tasks remaining");
DALI_TEST_EQUALS(blurView.GetRendererCount(), 0, TEST_LOCATION );
- tet_infoline("Call SetImage a second time and add blurview back to stage");
- Image inputImage2 = CreateSolidColorImage( application, Color::CYAN, 50, 50 );
- blurView.SetImage( inputImage2 );
+ tet_infoline("Call SetTexture a second time and add blurview back to stage");
+ Texture inputTexture2 = CreateSolidColorTexture( application, Color::CYAN, 50, 50 );
+ blurView.SetTexture( inputTexture2 );
// start multiple guassian blur call, each guassian blur creates two render tasks
DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
{
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
Stage::GetCurrent().Add( blurView );
Wait(application);
DALI_TEST_EQUALS(blurView.GetRendererCount(), BLUR_LEVELS+1, TEST_LOCATION );
tet_infoline(" UtcDaliSuperBlurViewSetProperty ");
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
Stage::GetCurrent().Add( blurView );
blurView.SetSize( 100.f, 100.f );
- tet_infoline(" Set property map. Set height and width large enough to avoid atlassing");
- int width(512);
- int height(513);
- LoadBitmapResource( application.GetPlatform(), width, height );
-
- Property::Map propertyMap;
- propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
- propertyMap["width"] = width;
- propertyMap["height"] = height;
-
// Will create ResourceImage
- blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
+ blurView.SetProperty(SuperBlurView::Property::IMAGE_URL, TEST_IMAGE_FILE_NAME);
Wait(application);
// start multiple guassian blur call, each guassian blur creates two render tasks
- DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
+
+ unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
+ DALI_TEST_CHECK( count == 1+BLUR_LEVELS*2 );
Wait(application);
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
blurView.SetSize( 100.f, 100.f );
- tet_infoline(" Set property map.");
- int width(512);
- int height(513); // Value large enough to avoid future atlassing
- LoadBitmapResource( application.GetPlatform(), width, height );
-
- Property::Map propertyMap;
- propertyMap["filename"] = TEST_IMAGE_FILE_NAME ;
- propertyMap["width"] = width;
- propertyMap["height"] = height;
-
- // Will create ResourceImage
- blurView.SetProperty(SuperBlurView::Property::IMAGE, propertyMap);
+ blurView.SetProperty(SuperBlurView::Property::IMAGE_URL, TEST_IMAGE_FILE_NAME);
Wait(application);
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
Stage::GetCurrent().Add( blurView );
- Property::Value imageProperty = blurView.GetProperty(SuperBlurView::Property::IMAGE);
- Property::Map* map = imageProperty.GetMap();
- DALI_TEST_CHECK( map != NULL );
- if( map )
- {
- Property::Map& mapRef = *map;
- DALI_TEST_EQUALS( mapRef["filename"], TEST_IMAGE_FILE_NAME, TEST_LOCATION );
- }
+ std::string imageUrl = blurView.GetProperty<std::string>( SuperBlurView::Property::IMAGE_URL );
+ DALI_TEST_EQUALS( imageUrl, TEST_IMAGE_FILE_NAME, TEST_LOCATION );
END_TEST;
}
END_TEST;
}
-int UtcDaliSuperBlurViewGetBlurredImage(void)
+int UtcDaliSuperBlurViewGetBlurredTexture(void)
{
ToolkitTestApplication application;
- tet_infoline( "UtcDaliSuperBlurViewGetBlurredImage" );
+ tet_infoline( "UtcDaliSuperBlurViewGetBlurredTexture" );
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
blurView.SetSize( 100.f,100.f );
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 100, 100 );
- blurView.SetImage( inputImage );
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 100, 100 );
+ blurView.SetTexture( inputTexture );
Wait(application, 200); // Make sure all the gaussian blur finished
- Image image1 = blurView.GetBlurredImage( 1 );
- DALI_TEST_CHECK( image1 );
+ Texture texture1 = blurView.GetBlurredTexture( 1 );
+ DALI_TEST_CHECK( texture1 );
- Image image2 = blurView.GetBlurredImage( 2 );
- DALI_TEST_EQUALS( image2.GetWidth(), 25u, TEST_LOCATION );
- DALI_TEST_EQUALS( image2.GetHeight(), 25u, TEST_LOCATION );
+ Texture texture2 = blurView.GetBlurredTexture( 2 );
+ DALI_TEST_EQUALS( texture2.GetWidth(), 25u, TEST_LOCATION );
+ DALI_TEST_EQUALS( texture2.GetHeight(), 25u, TEST_LOCATION );
- Image image3 = blurView.GetBlurredImage( 3 );
- DALI_TEST_CHECK( FrameBufferImage::DownCast( image3 ) );
+ Texture texture3 = blurView.GetBlurredTexture( 3 );
+ DALI_TEST_CHECK( texture3 );
END_TEST;
}
SuperBlurView blurView = SuperBlurView::New( BLUR_LEVELS );
blurView.SetSize( 100.f, 100.f );
- Image inputImage = CreateSolidColorImage( application, Color::GREEN, 50, 50 );
- blurView.SetImage( inputImage );
+ Texture inputTexture = CreateSolidColorTexture( application, Color::GREEN, 50, 50 );
+ blurView.SetTexture( inputTexture );
// start multiple guassian blur call, each guassian blur creates two render tasks
DALI_TEST_CHECK( Stage::GetCurrent().GetRenderTaskList().GetTaskCount() == 1+BLUR_LEVELS*2);
SignalHandler signalHandler;
blurView.BlurFinishedSignal().Connect(&signalHandler, &SignalHandler::Callback);
- // create image renderers for the original image and each blurred image
+ // create renderers for the original image and each blurred image
Stage::GetCurrent().Add( blurView );
Wait(application, 1000);
GetImpl(*this).Deactivate();
}
-void GaussianBlurView::SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget)
+void GaussianBlurView::SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget)
{
GetImpl(*this).SetUserImageAndOutputRenderTarget(inputImage, outputRenderTarget);
}
return GetImpl(*this).GetBlurStrengthPropertyIndex();
}
-FrameBufferImage GaussianBlurView::GetBlurredRenderTarget() const
+FrameBuffer GaussianBlurView::GetBlurredRenderTarget() const
{
return GetImpl(*this).GetBlurredRenderTarget();
}
// EXTERNAL INCLUDES
#include <dali/public-api/actors/camera-actor.h>
#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/images/frame-buffer-image.h>
+#include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/rendering/texture.h>
#include <dali/public-api/render-tasks/render-task.h>
// INTERNAL INCLUDES
* @param outputRenderTarget A render target to receive the blurred result. Passing NULL is allowed. See also GetBlurredRenderTarget().
* @pre This object was created with a New( ... ) call where the blurUserImage argument was set to true. If this was not the case an exception will be thrown.
*/
- void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
+ void SetUserImageAndOutputRenderTarget(Dali::Texture inputImage, Dali::FrameBuffer outputRenderTarget);
/**
* @brief Get the index of the property that can be used to fade the blur in / out.
* @return A handle on the blurred image, contained in a render target.
* @pre The user must call Activate() before the render target will be returned.
*/
- FrameBufferImage GetBlurredRenderTarget() const;
+ Dali::FrameBuffer GetBlurredRenderTarget() const;
/**
* @brief Set background color for the view. The background will be filled with this color.
VerifyCustomActorPointer<Internal::SuperBlurView>( internal );
}
-void SuperBlurView::SetImage(Image inputImage)
+void SuperBlurView::SetTexture( Texture texture )
{
- GetImpl(*this).SetImage( inputImage );
+ GetImpl(*this).SetTexture( texture );
}
Property::Index SuperBlurView::GetBlurStrengthPropertyIndex() const
return GetImpl(*this).BlurFinishedSignal();
}
-Image SuperBlurView::GetBlurredImage( unsigned int level )
+Texture SuperBlurView::GetBlurredTexture( unsigned int level )
{
- return GetImpl(*this).GetBlurredImage( level );
+ return GetImpl(*this).GetBlurredTexture( level );
}
} // namespace Toolkit
*/
// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/texture.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control.h>
* Stage::GetCurrent().Add(blurView);\n
*
* // Set the input image
- * ResourceImage image = ResourceImage::New(...);\n
- * blurView.SetImage(image);\n
+ * blurView.SetProperty( SuperBlurView::Property::IMAGE_URL, url );\n
*
* // animate the strength of the blur - this can fade between no blur and full blur. .\n
* Animation blurAnimation = Animation::New( ... );\n
{
enum
{
- IMAGE = PROPERTY_START_INDEX, ///< name "image", @see SetImage, type Map
+ IMAGE_URL = PROPERTY_START_INDEX, ///< name "imageUrl", @see SetTexture, type String
};
};
/**
* @brief Create an initialized SuperBlurView.
*
- * @param[in] blurLevels The final blur strength level. It decides how many filtering passes are used to create the group of blurred images.
+ * @param[in] blurLevels The final blur strength level. It decides how many filtering passes are used to create the group of blurred textures.
* @return A handle to a newly allocated Dali resource
*/
static SuperBlurView New( unsigned int blurLevels );
static SuperBlurView DownCast( BaseHandle handle );
/**
- * @brief Sets a custom image to be blurred.
+ * @brief Sets a custom texture to be blurred.
*
- * @param[in] inputImage The image that the user wishes to blur
+ * @param[in] texture The texture that the user wishes to blur
*/
- void SetImage(Image inputImage);
+ void SetTexture( Texture texture );
/**
* @brief Get the index of the property that can be used to fade the blur in / out.
Dali::Property::Index GetBlurStrengthPropertyIndex() const;
/**
- * @brief Set the blur strength to display the image.
+ * @brief Set the blur strength to display the texture.
*
- * @param[in] blurStrength The blur strength used to display the image.
+ * @param[in] blurStrength The blur strength used to display the texture.
*/
void SetBlurStrength( float blurStrength );
SuperBlurViewSignal& BlurFinishedSignal();
/**
- * @brief Get the blurred image.
+ * @brief Get the blurred texture.
*
* Should wait for the BlurFinishedSignal before calling this method.
- * @param[in] level Indicate which blurred image to get, must be a value between 1 and blurLevels
- * @return The level-th blurred image
+ * @param[in] level Indicate which blurred texture to get, must be a value between 1 and blurLevels
+ * @return The level-th blurred texture
*/
- Image GetBlurredImage( unsigned int level );
+ Texture GetBlurredTexture( unsigned int level );
public: // Not intended for application developers
// create off screen buffer of new size to render our child actors to
mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat );
- mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat );
- FrameBufferImage mBlurExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat );
- mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat );
+ mBloomExtractTarget = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight) );
+ mBloomExtractTarget.AttachColorTexture( texture );
+
+ FrameBuffer blurExtractTarget = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight) );
+ blurExtractTarget.AttachColorTexture( texture );
+
+ mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat );
//////////////////////////////////////////////////////
// Point actors and render tasks at new render targets
mBloomExtractImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, visualMap );
// set GaussianBlurView to blur our extracted bloom
- mGaussianBlurView.SetUserImageAndOutputRenderTarget(mBloomExtractTarget, mBlurExtractTarget);
+ mGaussianBlurView.SetUserImageAndOutputRenderTarget( mBloomExtractTarget.GetColorTexture(), blurExtractTarget );
// use the completed blur in the first buffer and composite with the original child actors render
mCompositeImageView.SetImage( mRenderTargetForRenderingChildren );
visualMap[ Toolkit::Visual::Property::SHADER ] = customShader;
mCompositeImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, visualMap );
TextureSet textureSet = mCompositeImageView.GetRendererAt(0).GetTextures();
- TextureSetImage( textureSet, 1u, mBlurExtractTarget );
+ textureSet.SetTexture( 1u, blurExtractTarget.GetColorTexture() );
// set up target actor for rendering result, i.e. the blurred image
mTargetImageView.SetImage(mOutputRenderTarget);
mBloomExtractTask.SetInputEnabled( false );
mBloomExtractTask.SetClearEnabled( true );
mBloomExtractTask.SetCameraActor(mRenderDownsampledCamera);
- mBloomExtractTask.SetTargetFrameBuffer( mBloomExtractTarget );
+ mBloomExtractTask.SetFrameBuffer( mBloomExtractTarget );
// GaussianBlurView tasks must be created here, so they are executed in the correct order with respect to BloomView tasks
GetImpl(mGaussianBlurView).CreateRenderTasks();
#include <cmath>
#include <dali/public-api/actors/camera-actor.h>
#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/public-api/images/frame-buffer-image.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
/////////////////////////////////////////////////////////////
// for extracting bright parts of image to an offscreen target
- FrameBufferImage mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
+ FrameBuffer mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
RenderTask mBloomExtractTask;
Toolkit::ImageView mBloomExtractImageView;
#include <dali/public-api/common/stage.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/property-buffer.h>
+#include <dali/public-api/rendering/renderer.h>
+#include <dali/public-api/rendering/shader.h>
#include <dali/public-api/render-tasks/render-task-list.h>
#include <dali/integration-api/debug.h>
// 2 modes:
// 1st mode, this control has a tree of actors (use Add() to add children) that are rendered and blurred.
// mRenderChildrenTask renders children to FB mRenderTargetForRenderingChildren
-// mHorizBlurTask renders mImageViewHorizBlur Actor showing FB mRenderTargetForRenderingChildren into FB mRenderTarget2
-// mVertBlurTask renders mImageViewVertBlur Actor showing FB mRenderTarget2 into FB mRenderTarget1
-// mCompositeTask renders mImageViewComposite Actor showing FB mRenderTarget1 into FB mRenderTargetForRenderingChildren
+// mHorizBlurTask renders mHorizBlurActor Actor showing FB mRenderTargetForRenderingChildren into FB mRenderTarget2
+// mVertBlurTask renders mVertBlurActor Actor showing FB mRenderTarget2 into FB mRenderTarget1
+// mCompositeTask renders mCompositingActor Actor showing FB mRenderTarget1 into FB mRenderTargetForRenderingChildren
//
// 2nd mode, an image is blurred and rendered to a supplied target framebuffer
-// mHorizBlurTask renders mImageViewHorizBlur Actor showing mUserInputImage into FB mRenderTarget2
-// mVertBlurTask renders mImageViewVertBlur Actor showing mRenderTarget2 into FB mUserOutputRenderTarget
+// mHorizBlurTask renders mHorizBlurActor Actor showing mUserInputImage into FB mRenderTarget2
+// mVertBlurTask renders mVertBlurActor Actor showing mRenderTarget2 into FB mUserOutputRenderTarget
//
// Only this 2nd mode handles ActivateOnce
const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
-const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE =
- "varying mediump vec2 vTexCoord;\n"
- "uniform sampler2D sTexture;\n"
- "uniform lowp vec4 uColor;\n"
- "uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n"
- "uniform mediump float uSampleWeights[NUM_SAMPLES];\n"
-
- "void main()\n"
- "{\n"
- " mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];\n"
- " for (int i=1; i<NUM_SAMPLES; ++i)\n"
- " {\n"
- " col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];\n"
- " }\n"
- " gl_FragColor = col;\n"
- "}\n";
+#define DALI_COMPOSE_SHADER(STR) #STR
+
+const char * const BASIC_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ attribute mediump vec2 aPosition;\n
+ attribute mediump vec2 aTexture;\n
+ varying mediump vec2 vTexCoord;\n
+ uniform mediump mat4 uMvpMatrix;\n
+ uniform mediump vec3 uSize;\n
+ \n
+ void main()\n
+ {\n
+ mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);\n
+ vTexCoord = aTexture;\n
+ gl_Position = uMvpMatrix * vertexPosition;\n
+ }\n
+);
+
+const char * const BASIC_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ varying mediump vec2 vTexCoord;\n
+ uniform sampler2D sTexture;\n
+ uniform vec4 uColor;\n
+ \n
+ void main()\n
+ {\n
+ gl_FragColor = texture2D(sTexture, vTexCoord);\n
+ gl_FragColor *= uColor;
+ }\n
+);
+
+const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
+ varying mediump vec2 vTexCoord;\n
+ uniform sampler2D sTexture;\n
+ uniform lowp vec4 uColor;\n
+ uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n
+ uniform mediump float uSampleWeights[NUM_SAMPLES];\n
+
+ void main()\n
+ {\n
+ mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];\n
+ for (int i=1; i<NUM_SAMPLES; ++i)\n
+ {\n
+ col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];\n
+ }\n
+ gl_FragColor = col;\n
+ }\n
+);
+
+Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc )
+{
+ Shader shader = Shader::New( vertexSrc, fragmentSrc );
+
+ Geometry texturedQuadGeometry = Geometry::New();
+
+ struct VertexPosition { Vector2 position; };
+ struct VertexTexture { Vector2 texture; };
+
+ VertexPosition positionArray[] =
+ {
+ { Vector2( -0.5f, -0.5f ) },
+ { Vector2( 0.5f, -0.5f ) },
+ { Vector2( -0.5f, 0.5f ) },
+ { Vector2( 0.5f, 0.5f ) }
+ };
+ uint32_t numberOfVertices = sizeof(positionArray)/sizeof(VertexPosition);
+
+ VertexTexture uvArray[] =
+ {
+ { Vector2( 0.0f, 0.0f ) },
+ { Vector2( 1.0f, 0.0f ) },
+ { Vector2( 0.0f, 1.0f ) },
+ { Vector2( 1.0f, 1.0f ) }
+ };
+
+ Property::Map positionVertexFormat;
+ positionVertexFormat["aPosition"] = Property::VECTOR2;
+ PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
+ positionVertices.SetData( positionArray, numberOfVertices );
+ texturedQuadGeometry.AddVertexBuffer( positionVertices );
+
+ Property::Map textureVertexFormat;
+ textureVertexFormat["aTexture"] = Property::VECTOR2;
+ PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
+ textureVertices.SetData( uvArray, numberOfVertices );
+ texturedQuadGeometry.AddVertexBuffer( textureVertices );
+
+ const uint16_t indices[] = { 0, 3, 1, 0, 2, 3 };
+ texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
+
+ Renderer renderer = Renderer::New( texturedQuadGeometry, shader );
+
+ TextureSet textureSet = TextureSet::New();
+ renderer.SetTextures( textureSet );
+
+ return renderer;
+}
+
+void SetTexture( Actor actor, Texture texture )
+{
+ if( Renderer renderer = actor.GetRendererAt(0) )
+ {
+ TextureSet textureSet = renderer.GetTextures();
+ textureSet.SetTexture( 0u, texture );
+ }
+}
+
+void SetTexture( Actor actor, FrameBuffer frameBuffer )
+{
+ if( frameBuffer )
+ {
+ SetTexture( actor, frameBuffer.GetColorTexture() );
+ }
+}
} // namespace
mChildrenRoot.Remove(child);
}
-void GaussianBlurView::SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget)
+void GaussianBlurView::SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget)
{
// can only do this if the GaussianBlurView object was created with this parameter set
DALI_ASSERT_ALWAYS(mBlurUserImage);
mUserInputImage = inputImage;
- mImageViewHorizBlur.SetImage( mUserInputImage );
- mImageViewHorizBlur.SetProperty( Toolkit::ImageView::Property::IMAGE, mCustomShader );
+
+ SetTexture( mHorizBlurActor, inputImage );
mUserOutputRenderTarget = outputRenderTarget;
}
-FrameBufferImage GaussianBlurView::GetBlurredRenderTarget() const
+FrameBuffer GaussianBlurView::GetBlurredRenderTarget() const
{
if(!mUserOutputRenderTarget)
{
//////////////////////////////////////////////////////
// Create shaders
- std::ostringstream horizFragmentShaderStringStream;
- horizFragmentShaderStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
- horizFragmentShaderStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
- Property::Map source;
- source[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = horizFragmentShaderStringStream.str();
- mCustomShader[ Toolkit::Visual::Property::SHADER ] = source;
+ std::ostringstream fragmentStringStream;
+ fragmentStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
+ fragmentStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
+ std::string fragmentSource(fragmentStringStream.str());
//////////////////////////////////////////////////////
// Create actors
- // Create an image view for performing a horizontal blur on the texture
- mImageViewHorizBlur = Toolkit::ImageView::New();
- mImageViewHorizBlur.SetParentOrigin(ParentOrigin::CENTER);
+ // Create an actor for performing a horizontal blur on the texture
+ mHorizBlurActor = Actor::New();
+ mHorizBlurActor.SetParentOrigin(ParentOrigin::CENTER);
+ Renderer renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
+ mHorizBlurActor.AddRenderer( renderer );
- // Create an image view for performing a vertical blur on the texture
- mImageViewVertBlur = Toolkit::ImageView::New();
- mImageViewVertBlur.SetParentOrigin(ParentOrigin::CENTER);
+ // Create an actor for performing a vertical blur on the texture
+ mVertBlurActor = Actor::New();
+ mVertBlurActor.SetParentOrigin(ParentOrigin::CENTER);
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
+ mVertBlurActor.AddRenderer( renderer );
// Register a property that the user can control to fade the blur in / out via the GaussianBlurView object
Actor self = Self();
// Create an image view for compositing the blur and the original child actors render
if(!mBlurUserImage)
{
- mImageViewComposite = Toolkit::ImageView::New();
- mImageViewComposite.SetParentOrigin(ParentOrigin::CENTER);
- mImageViewComposite.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value
+ mCompositingActor = Actor::New();
+ mCompositingActor.SetParentOrigin(ParentOrigin::CENTER);
+ mCompositingActor.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE );
+ mCompositingActor.AddRenderer( renderer );
- Constraint blurStrengthConstraint = Constraint::New<float>( mImageViewComposite, Actor::Property::COLOR_ALPHA, EqualToConstraint());
+ Constraint blurStrengthConstraint = Constraint::New<float>( mCompositingActor, Actor::Property::COLOR_ALPHA, EqualToConstraint());
blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) );
blurStrengthConstraint.Apply();
// Create an image view for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
- mTargetActor = Toolkit::ImageView::New();
+ mTargetActor = Actor::New();
mTargetActor.SetParentOrigin(ParentOrigin::CENTER);
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE );
+ mTargetActor.AddRenderer( renderer );
//////////////////////////////////////////////////////
// Create cameras for the renders corresponding to the view size
mRenderFullSizeCamera.SetInvertYAxis( true );
mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER);
-
//////////////////////////////////////////////////////
// Connect to actor tree
- mInternalRoot.Add( mImageViewComposite );
+ mInternalRoot.Add( mCompositingActor );
mInternalRoot.Add( mTargetActor );
mInternalRoot.Add( mRenderFullSizeCamera );
}
-
//////////////////////////////////////////////////////
// Create camera for the renders corresponding to the (potentially downsampled) render targets' size
mRenderDownsampledCamera = CameraActor::New();
mRenderDownsampledCamera.SetInvertYAxis( true );
mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER);
-
//////////////////////////////////////////////////////
// Connect to actor tree
Self().Add( mChildrenRoot );
Self().Add( mInternalRoot );
- mInternalRoot.Add( mImageViewHorizBlur );
- mInternalRoot.Add( mImageViewVertBlur );
+ mInternalRoot.Add( mHorizBlurActor );
+ mInternalRoot.Add( mVertBlurActor );
mInternalRoot.Add( mRenderDownsampledCamera );
}
if( !mBlurUserImage )
{
- mImageViewComposite.SetSize(targetSize);
+ mCompositingActor.SetSize(targetSize);
mTargetActor.SetSize(targetSize);
// Children render camera must move when GaussianBlurView object is resized. This is since we cannot change render target size - so we need to remap the child actors' rendering
mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
// create offscreen buffer of new size to render our child actors to
- mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat );
+ mRenderTargetForRenderingChildren = FrameBuffer::New( mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height) );
+ mRenderTargetForRenderingChildren.AttachColorTexture( texture );
- // Set image view for performing a horizontal blur on the texture
- mImageViewHorizBlur.SetImage( mRenderTargetForRenderingChildren );
- mImageViewHorizBlur.SetProperty( Toolkit::ImageView::Property::IMAGE, mCustomShader );
+ // Set actor for performing a horizontal blur
+ SetTexture( mHorizBlurActor, mRenderTargetForRenderingChildren );
// Create offscreen buffer for vert blur pass
- mRenderTarget1 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat );
+ mRenderTarget1 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
+ mRenderTarget1.AttachColorTexture( texture );
// use the completed blur in the first buffer and composite with the original child actors render
- mImageViewComposite.SetImage( mRenderTarget1 );
+ SetTexture( mCompositingActor, mRenderTarget1 );
// set up target actor for rendering result, i.e. the blurred image
- mTargetActor.SetImage(mRenderTargetForRenderingChildren);
+ SetTexture( mTargetActor, mRenderTargetForRenderingChildren );
}
// Create offscreen buffer for horiz blur pass
- mRenderTarget2 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat );
+ mRenderTarget2 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
+ mRenderTarget2.AttachColorTexture( texture );
// size needs to match render target
- mImageViewHorizBlur.SetSize(mDownsampledWidth, mDownsampledHeight);
+ mHorizBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight);
// size needs to match render target
- mImageViewVertBlur.SetImage( mRenderTarget2 );
- mImageViewVertBlur.SetProperty( Toolkit::ImageView::Property::IMAGE, mCustomShader );
- mImageViewVertBlur.SetSize(mDownsampledWidth, mDownsampledHeight);
+ mVertBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight);
+ SetTexture( mVertBlurActor, mRenderTarget2 );
// set gaussian blur up for new sized render targets
SetShaderConstants();
mRenderChildrenTask.SetClearColor( mBackgroundColor );
mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera);
- mRenderChildrenTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren );
+ mRenderChildrenTask.SetFrameBuffer( mRenderTargetForRenderingChildren );
}
// perform a horizontal blur targeting the second buffer
mHorizBlurTask = taskList.CreateTask();
- mHorizBlurTask.SetSourceActor( mImageViewHorizBlur );
+ mHorizBlurTask.SetSourceActor( mHorizBlurActor );
mHorizBlurTask.SetExclusive(true);
mHorizBlurTask.SetInputEnabled( false );
mHorizBlurTask.SetClearEnabled( true );
mHorizBlurTask.SetClearColor( mBackgroundColor );
mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera);
- mHorizBlurTask.SetTargetFrameBuffer( mRenderTarget2 );
+ mHorizBlurTask.SetFrameBuffer( mRenderTarget2 );
if( mRenderOnce && mBlurUserImage )
{
mHorizBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
// use the second buffer and perform a horizontal blur targeting the first buffer
mVertBlurTask = taskList.CreateTask();
- mVertBlurTask.SetSourceActor( mImageViewVertBlur );
+ mVertBlurTask.SetSourceActor( mVertBlurActor );
mVertBlurTask.SetExclusive(true);
mVertBlurTask.SetInputEnabled( false );
mVertBlurTask.SetClearEnabled( true );
mVertBlurTask.SetCameraActor(mRenderDownsampledCamera);
if(mUserOutputRenderTarget)
{
- mVertBlurTask.SetTargetFrameBuffer( mUserOutputRenderTarget );
+ mVertBlurTask.SetFrameBuffer( mUserOutputRenderTarget );
}
else
{
- mVertBlurTask.SetTargetFrameBuffer( mRenderTarget1 );
+ mVertBlurTask.SetFrameBuffer( mRenderTarget1 );
}
if( mRenderOnce && mBlurUserImage )
{
if(!mBlurUserImage)
{
mCompositeTask = taskList.CreateTask();
- mCompositeTask.SetSourceActor( mImageViewComposite );
+ mCompositeTask.SetSourceActor( mCompositingActor );
mCompositeTask.SetExclusive(true);
mCompositeTask.SetInputEnabled( false );
mCompositeTask.SetCameraActor(mRenderFullSizeCamera);
- mCompositeTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren );
+ mCompositeTask.SetFrameBuffer( mRenderTargetForRenderingChildren );
}
}
Vector2 yAxis(0.0f, 1.0f);
for (i = 0; i < mNumSamples; ++i )
{
- mImageViewHorizBlur.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis );
- mImageViewHorizBlur.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
+ mHorizBlurActor.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis );
+ mHorizBlurActor.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
- mImageViewVertBlur.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis );
- mImageViewVertBlur.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
+ mVertBlurActor.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis );
+ mVertBlurActor.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
}
delete[] uvOffsets;
void ActivateOnce();
void Deactivate();
- void SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget);
+ void SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget);
Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
- FrameBufferImage GetBlurredRenderTarget() const;
+ FrameBuffer GetBlurredRenderTarget() const;
/// @copydoc Dali::Toolkit::GaussianBlurView::SetBackgroundColor(const Vector4&)
void SetBackgroundColor( const Vector4& color );
/////////////////////////////////////////////////////////////
// for rendering all user added children to offscreen target
- FrameBufferImage mRenderTargetForRenderingChildren;
+ FrameBuffer mRenderTargetForRenderingChildren;
RenderTask mRenderChildrenTask;
/////////////////////////////////////////////////////////////
// for rendering separated blur passes to offscreen targets
- FrameBufferImage mRenderTarget1;
- FrameBufferImage mRenderTarget2;
+ FrameBuffer mRenderTarget1;
+ FrameBuffer mRenderTarget2;
- Toolkit::ImageView mImageViewHorizBlur;
- Toolkit::ImageView mImageViewVertBlur;
-
- Property::Map mCustomShader;
+ Actor mHorizBlurActor;
+ Actor mVertBlurActor;
RenderTask mHorizBlurTask;
RenderTask mVertBlurTask;
/////////////////////////////////////////////////////////////
// for compositing blur and children renders to offscreen target
- Toolkit::ImageView mImageViewComposite;
+ Actor mCompositingActor;
RenderTask mCompositeTask;
/////////////////////////////////////////////////////////////
// for holding blurred result
- Toolkit::ImageView mTargetActor;
+ Actor mTargetActor;
/////////////////////////////////////////////////////////////
// for animating fade in / out of blur, hiding internal implementation but allowing user to set via GaussianBlurView interface
/////////////////////////////////////////////////////////////
// User can specify image to blur and output target, so we can use GaussianBlurView for arbitrary blur processes
- Image mUserInputImage;
- FrameBufferImage mUserOutputRenderTarget;
+ Texture mUserInputImage;
+ FrameBuffer mUserOutputRenderTarget;
Dali::Toolkit::GaussianBlurView::GaussianBlurViewSignal mFinishedSignal; ///< Signal emitted when blur has completed.
#include <dali/integration-api/debug.h>
// INTERNAL_INCLUDES
+#include <dali-toolkit/public-api/image-loader/sync-image-loader.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
Vector2 mRange;
};
+#define DALI_COMPOSE_SHADER(STR) #STR
+
+const char * const BASIC_VERTEX_SOURCE = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ attribute mediump vec2 aPosition;\n
+ attribute mediump vec2 aTexture;\n
+ varying mediump vec2 vTexCoord;\n
+ uniform mediump mat4 uMvpMatrix;\n
+ uniform mediump vec3 uSize;\n
+ \n
+ void main()\n
+ {\n
+ mediump vec4 vertexPosition = vec4(aPosition * uSize.xy, 0.0, 1.0);\n
+ vTexCoord = aTexture;\n
+ gl_Position = uMvpMatrix * vertexPosition;\n
+ }\n
+);
+
+const char * const BASIC_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
+ precision mediump float;\n
+ varying mediump vec2 vTexCoord;\n
+ uniform sampler2D sTexture;\n
+ uniform vec4 uColor;\n
+ \n
+ void main()\n
+ {\n
+ gl_FragColor = texture2D(sTexture, vTexCoord);\n
+ gl_FragColor *= uColor;
+ }\n
+);
+
+Renderer CreateRenderer( const char* vertexSrc, const char* fragmentSrc )
+{
+ Shader shader = Shader::New( vertexSrc, fragmentSrc );
+
+ Geometry texturedQuadGeometry = Geometry::New();
+
+ struct VertexPosition { Vector2 position; };
+ struct VertexTexture { Vector2 texture; };
+
+ VertexPosition positionArray[] =
+ {
+ { Vector2( -0.5f, -0.5f ) },
+ { Vector2( 0.5f, -0.5f ) },
+ { Vector2( -0.5f, 0.5f ) },
+ { Vector2( 0.5f, 0.5f ) }
+ };
+ uint32_t numberOfVertices = sizeof(positionArray)/sizeof(VertexPosition);
+
+ VertexTexture uvArray[] =
+ {
+ { Vector2( 0.0f, 0.0f ) },
+ { Vector2( 1.0f, 0.0f ) },
+ { Vector2( 0.0f, 1.0f ) },
+ { Vector2( 1.0f, 1.0f ) }
+ };
+
+ Property::Map positionVertexFormat;
+ positionVertexFormat["aPosition"] = Property::VECTOR2;
+ PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
+ positionVertices.SetData( positionArray, numberOfVertices );
+ texturedQuadGeometry.AddVertexBuffer( positionVertices );
+
+ Property::Map textureVertexFormat;
+ textureVertexFormat["aTexture"] = Property::VECTOR2;
+ PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
+ textureVertices.SetData( uvArray, numberOfVertices );
+ texturedQuadGeometry.AddVertexBuffer( textureVertices );
+
+ const uint16_t indices[] = { 0, 3, 1, 0, 2, 3 };
+ texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
+
+ Renderer renderer = Renderer::New( texturedQuadGeometry, shader );
+
+ TextureSet textureSet = TextureSet::New();
+ renderer.SetTextures( textureSet );
+
+ return renderer;
+}
+
+void SetRendererTexture( Renderer& renderer, Texture& texture )
+{
+ if( renderer )
+ {
+ TextureSet textureSet = renderer.GetTextures();
+ textureSet.SetTexture( 0u, texture );
+ }
+}
+
+void SetRendererTexture( Renderer& renderer, FrameBuffer& frameBuffer )
+{
+ if( frameBuffer )
+ {
+ Texture texture = frameBuffer.GetColorTexture();
+ SetRendererTexture( renderer, texture );
+ }
+}
+
} // namespace
namespace Dali
// Setup properties, signals and actions using the type-registry.
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::SuperBlurView, Toolkit::Control, Create )
-DALI_PROPERTY_REGISTRATION( Toolkit, SuperBlurView, "image", MAP, IMAGE )
+DALI_PROPERTY_REGISTRATION( Toolkit, SuperBlurView, "imageUrl", STRING, IMAGE_URL )
DALI_TYPE_REGISTRATION_END()
{
DALI_ASSERT_ALWAYS( mBlurLevels > 0 && " Minimal blur level is one, otherwise no blur is needed" );
mGaussianBlurView.assign( blurLevels, Toolkit::GaussianBlurView() );
- mBlurredImage.assign( blurLevels, FrameBufferImage() );
- mVisuals.assign( blurLevels+1, Toolkit::Visual::Base() );
+ mBlurredImage.assign( blurLevels, FrameBuffer() );
+ mRenderers.assign( blurLevels+1, Dali::Renderer() );
}
SuperBlurView::~SuperBlurView()
void SuperBlurView::OnInitialize()
{
- mBlurStrengthPropertyIndex = Self().RegisterProperty( "blurStrength", 0.f );
+ Actor self( Self() );
+
+ mBlurStrengthPropertyIndex = self.RegisterProperty( "blurStrength", 0.f );
}
-void SuperBlurView::SetImage(Image inputImage)
+void SuperBlurView::SetTexture( Texture texture )
{
- mInputImage = inputImage;
+ mInputTexture = texture;
+
if( mTargetSize == Vector2::ZERO )
{
return;
Actor self( Self() );
- mVisuals[0] = Toolkit::VisualFactory::Get().CreateVisual( mInputImage );
- DevelControl::RegisterVisual( *this, 0, mVisuals[0], 0 ); // Will clean up previously registered visuals for this index.
- // custom shader is not applied on the original image.
+ BlurTexture( 0, mInputTexture );
+ SetRendererTexture( mRenderers[0], texture );
- BlurImage( 0, inputImage);
- for(unsigned int i=1; i<mBlurLevels;i++)
+ unsigned int i = 1;
+ for(; i<mBlurLevels; i++)
{
- BlurImage( i, mBlurredImage[i-1]);
+ BlurTexture( i, mBlurredImage[i-1].GetColorTexture() );
+ SetRendererTexture( mRenderers[i], mBlurredImage[i-1] );
}
- mResourcesCleared = false;
-}
+ SetRendererTexture( mRenderers[i], mBlurredImage[i-1] );
-Image SuperBlurView::GetImage()
-{
- return mInputImage;
+ mResourcesCleared = false;
}
Property::Index SuperBlurView::GetBlurStrengthPropertyIndex() const
return mBlurFinishedSignal;
}
-Image SuperBlurView::GetBlurredImage( unsigned int level )
+Texture SuperBlurView::GetBlurredTexture( unsigned int level )
{
DALI_ASSERT_ALWAYS( level>0 && level<=mBlurLevels );
- return mBlurredImage[level-1];
+
+ FrameBuffer frameBuffer = mBlurredImage[level-1];
+
+ return frameBuffer.GetColorTexture();
}
-void SuperBlurView::BlurImage( unsigned int idx, Image image )
+void SuperBlurView::BlurTexture( unsigned int idx, Texture texture )
{
DALI_ASSERT_ALWAYS( mGaussianBlurView.size()>idx );
mGaussianBlurView[idx] = Toolkit::GaussianBlurView::New( GAUSSIAN_BLUR_DEFAULT_NUM_SAMPLES+GAUSSIAN_BLUR_NUM_SAMPLES_INCREMENTATION*idx,
mGaussianBlurView[idx].SetParentOrigin(ParentOrigin::CENTER);
mGaussianBlurView[idx].SetSize(mTargetSize);
Stage::GetCurrent().Add( mGaussianBlurView[idx] );
- mGaussianBlurView[idx].SetUserImageAndOutputRenderTarget( image, mBlurredImage[idx] );
+
+ mGaussianBlurView[idx].SetUserImageAndOutputRenderTarget( texture, mBlurredImage[idx] );
+
mGaussianBlurView[idx].ActivateOnce();
if( idx == mBlurLevels-1 )
{
mResourcesCleared = true;
}
}
-void SuperBlurView::SetShaderEffect( Toolkit::Visual::Base& visual )
-{
- Property::Map shaderMap;
- std::stringstream verterShaderString;
- shaderMap[ "fragmentShader" ] = FRAGMENT_SHADER;
-
- Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
- visualImpl.SetCustomShader( shaderMap );
-}
void SuperBlurView::OnSizeSet( const Vector3& targetSize )
{
for( unsigned int i = 1; i <= mBlurLevels; i++ )
{
float exponent = static_cast<float>(i);
- mBlurredImage[i-1] = FrameBufferImage::New( mTargetSize.width/std::pow(2.f,exponent) , mTargetSize.height/std::pow(2.f,exponent),
- GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT );
- mVisuals[i] = Toolkit::VisualFactory::Get().CreateVisual( mBlurredImage[i - 1] );
- DevelControl::RegisterVisual( *this, i, mVisuals[i], int( i ) ); // Will clean up existing visual with same index.
- SetShaderEffect( mVisuals[i] );
+ unsigned int width = mTargetSize.width/std::pow(2.f,exponent);
+ unsigned int height = mTargetSize.height/std::pow(2.f,exponent);
+
+ mBlurredImage[i-1] = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, GAUSSIAN_BLUR_RENDER_TARGET_PIXEL_FORMAT, unsigned(width), unsigned(height) );
+ mBlurredImage[i-1].AttachColorTexture( texture );
}
- if( mInputImage )
+ if( mInputTexture )
{
- SetImage( mInputImage );
+ SetTexture( mInputTexture );
}
}
Control::OnStageConnection( depth );
Actor self = Self();
- for(unsigned int i=0; i<=mBlurLevels;i++)
+
+ for(unsigned int i=0; i<mBlurLevels+1;i++)
{
- // Note that the renderer indices are depending on the order they been added to the actor
- // which might be different from the blur level of its texture.
- // We can check the depth index of the renderer to know which blurred image it renders.
- // All visuals WILL have renderers at this point as we are simply creating visuals with an Image handle.
- Renderer renderer = self.GetRendererAt( i );
- int depthIndex = renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX);
- if( depthIndex > 0 )
+ mRenderers[i] = CreateRenderer( BASIC_VERTEX_SOURCE, FRAGMENT_SHADER );
+ mRenderers[i].SetProperty( Dali::Renderer::Property::DEPTH_INDEX, (int)i );
+ self.AddRenderer( mRenderers[i] );
+
+ if( i > 0 )
{
+ Renderer renderer = mRenderers[i];
Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f );
- Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, depthIndex-1) );
+ Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, i-1) );
constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) );
constraint.Apply();
}
}
+
+ if( mInputTexture )
+ {
+ SetRendererTexture( mRenderers[0], mInputTexture );
+ unsigned int i = 1;
+ for(; i<mBlurLevels; i++)
+ {
+ SetRendererTexture( mRenderers[i], mBlurredImage[i-1] );
+ }
+ SetRendererTexture( mRenderers[i], mBlurredImage[i-1] );
+ }
+}
+
+void SuperBlurView::OnStageDisconnection()
+{
+ for(unsigned int i=0; i<mBlurLevels+1;i++)
+ {
+ Self().RemoveRenderer( mRenderers[i] );
+ mRenderers[i].Reset();
+ }
+
+ Control::OnStageDisconnection();
}
Vector3 SuperBlurView::GetNaturalSize()
{
- if( mInputImage )
+ if( mInputTexture )
{
- return Vector3( mInputImage.GetWidth(), mInputImage.GetHeight(), 0.f );
+ return Vector3( mInputTexture.GetWidth(), mInputTexture.GetHeight(), 0.f );
}
return Vector3::ZERO;
}
{
SuperBlurView& superBlurViewImpl( GetImpl( superBlurView ) );
- if( propertyIndex == Toolkit::SuperBlurView::Property::IMAGE )
+ if( propertyIndex == Toolkit::SuperBlurView::Property::IMAGE_URL )
{
- Dali::Image image = Scripting::NewImage( value );
- if ( image )
+ value.Get( superBlurViewImpl.mUrl );
+
+ PixelData pixels = SyncImageLoader::Load( superBlurViewImpl.mUrl );
+
+ if ( pixels )
{
- superBlurViewImpl.SetImage( image );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
+ texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
+
+ superBlurViewImpl.SetTexture( texture );
}
else
{
{
SuperBlurView& superBlurViewImpl( GetImpl( blurView ) );
- if( propertyIndex == Toolkit::SuperBlurView::Property::IMAGE )
+ if( propertyIndex == Toolkit::SuperBlurView::Property::IMAGE_URL )
{
- Property::Map map;
- Image inputImage = superBlurViewImpl.GetImage();
- if( inputImage )
- {
- Scripting::CreatePropertyMap( inputImage, map );
- }
- value = Property::Value( map );
+ value = superBlurViewImpl.mUrl;
}
}
*
*/
+// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/rendering/renderer.h>
+
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
/**
* @copydoc Dali::Toolkit::SuperBlurView::SetImage
*/
- void SetImage(Image inputImage);
-
- /**
- * Get the image for blurring.
- * @return The image for blurring.
- */
- Image GetImage();
+ void SetTexture( Texture texture );
/**
* @copydoc Dali::Toolkit::SuperBlurView::GetBlurStrengthPropertyIndex
Dali::Toolkit::SuperBlurView::SuperBlurViewSignal& BlurFinishedSignal();
/**
- * @copydoc Dali::Toolkit::SuperBlurView::GetBlurredImage
+ * @copydoc Dali::Toolkit::SuperBlurView::GetBlurredTexture
*/
- Image GetBlurredImage( unsigned int level );
+ Texture GetBlurredTexture( unsigned int level );
// Properties
virtual void OnStageConnection( int depth );
/**
+ * @copydoc CustomActorImpl::OnStageDisconnection()
+ */
+ virtual void OnStageDisconnection();
+
+ /**
* @copydoc CustomActorImpl::GetNaturalSize()
*/
virtual Vector3 GetNaturalSize();
/**
* Carry out the idx-th pass of blurring
* @param[in] idx The blur pass index
- * @param[in] image The input image for the current blurring, it is either the original image or the blurred image from the previous pass
+ * @param[in] texture The input texture for the current blurring, it is either the original image or the blurred texture from the previous pass
*/
- void BlurImage( unsigned int idx, Image image );
+ void BlurTexture( unsigned int idx, Texture texture );
/**
* Signal handler to tell when the last blur view completes
*/
void ClearBlurResource();
- /**
- * Sets shader effect on the control renderer
- * @param[in,out] Sets custom shader effect on the given visual
- */
- void SetShaderEffect( Toolkit::Visual::Base& visual );
-
private:
std::vector<Toolkit::GaussianBlurView> mGaussianBlurView;
- std::vector<FrameBufferImage> mBlurredImage;
- std::vector<Toolkit::Visual::Base> mVisuals;
- Image mInputImage;
+ std::vector<FrameBuffer> mBlurredImage;
+ std::vector<Renderer> mRenderers;
+ Texture mInputTexture;
Vector2 mTargetSize;
Toolkit::SuperBlurView::SuperBlurViewSignal mBlurFinishedSignal; ///< Signal emitted when blur has completed.
+ std::string mUrl;
Property::Index mBlurStrengthPropertyIndex;
unsigned int mBlurLevels;
bool mResourcesCleared;
};
-} // namespace Internal
+}
// Helpers for public-api forwarding methods
inline Toolkit::Internal::SuperBlurView& GetImpl( Toolkit::SuperBlurView& obj )
return static_cast<const Toolkit::Internal::SuperBlurView&>(handle);
}
-} // namespace Toolkit
+}
-} // namespace Dali
+}
#endif // DALI_TOOLKIT_INTERNAL_SUPER_BLUR_VIEW_H