X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=examples%2Fray-marching%2Fray-marching-example.cpp;h=ed481e6b0ac1daf1f56a9ca5c95950ce3156069b;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hp=39caa42b116a69bb485b766a274396cedb31d502;hpb=b26d446b0cb6a316abc3a79d4fc70d0ae1b7994c;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/ray-marching/ray-marching-example.cpp b/examples/ray-marching/ray-marching-example.cpp index 39caa42..ed481e6 100644 --- a/examples/ray-marching/ray-marching-example.cpp +++ b/examples/ray-marching/ray-marching-example.cpp @@ -17,20 +17,20 @@ #include #include -#include "shared/view.h" -#include "shared/utility.h" -#include -#include #include +#include +#include +#include "shared/utility.h" +#include "shared/view.h" using namespace Dali; -using Dali::Toolkit::TextLabel; using Dali::Toolkit::Control; +using Dali::Toolkit::TextLabel; using Dali::Toolkit::ToolBar; -const char* BACKGROUND_IMAGE( "" ); -const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" ); -const char* APPLICATION_TITLE( "Ray Marching" ); +const char* BACKGROUND_IMAGE(""); +const char* TOOLBAR_IMAGE(DEMO_IMAGE_DIR "top-bar.png"); +const char* APPLICATION_TITLE("Ray Marching"); const char* SHADER_NAME("raymarch_sphere_shaded"); /** @@ -39,31 +39,31 @@ const char* SHADER_NAME("raymarch_sphere_shaded"); * @param output * @return */ -bool LoadShaderCode( const char* path, const char* filename, std::vector& output ) +bool LoadShaderCode(const char* path, const char* filename, std::vector& output) { - std::string fullpath( path ); + std::string fullpath(path); fullpath += filename; - Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY ); - FILE* file = fileStream.GetFile(); - if( !file ) + Dali::FileStream fileStream(fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY); + FILE* file = fileStream.GetFile(); + if(!file) { return false; } bool retValue = false; - if( !fseek( file, 0, SEEK_END ) ) + if(!fseek(file, 0, SEEK_END)) { - long int size = ftell( file ); + long int size = ftell(file); - if( ( size != -1L ) && - ( ! fseek( file, 0, SEEK_SET ) ) ) + if((size != -1L) && + (!fseek(file, 0, SEEK_SET))) { - output.resize( size + 1 ); - std::fill( output.begin(), output.end(), 0 ); - ssize_t result = fread( output.data(), size, 1, file ); + output.resize(size + 1); + std::fill(output.begin(), output.end(), 0); + ssize_t result = fread(output.data(), size, 1, file); - retValue = ( result >= 0 ); + retValue = (result >= 0); } } @@ -75,19 +75,19 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector& * @param shaderName * @return */ -Shader LoadShaders( const std::string& shaderName ) +Shader LoadShaders(const std::string& shaderName) { std::vector bufV, bufF; - std::string shaderVSH( shaderName ); - std::string shaderFSH( shaderName ); + std::string shaderVSH(shaderName); + std::string shaderFSH(shaderName); shaderVSH += ".vsh"; shaderFSH += ".fsh"; Shader shader; - if( LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV ) && - LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF ) ) + if(LoadShaderCode(DEMO_SHADER_DIR, shaderVSH.c_str(), bufV) && + LoadShaderCode(DEMO_SHADER_DIR, shaderFSH.c_str(), bufF)) { - shader = Shader::New( bufV.data(), bufF.data() ); + shader = Shader::New(bufV.data(), bufF.data()); } return shader; } @@ -97,12 +97,11 @@ Shader LoadShaders( const std::string& shaderName ) class RayMarchingExample : public ConnectionTracker { public: - - RayMarchingExample( Application& application ) - : mApplication( application ) + RayMarchingExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &RayMarchingExample::Create ); + mApplication.InitSignal().Connect(this, &RayMarchingExample::Create); } ~RayMarchingExample() @@ -111,33 +110,32 @@ public: } // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.GetRootLayer().TouchedSignal().Connect( this, &RayMarchingExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &RayMarchingExample::OnTouch); window.KeyEventSignal().Connect(this, &RayMarchingExample::OnKeyEvent); - window.SetBackgroundColor( Color::YELLOW ); + window.SetBackgroundColor(Color::YELLOW); // Creates a default view with a default tool bar. // The view is added to the window. - mContentLayer = DemoHelper::CreateView( application, - mView, - mToolBar, - BACKGROUND_IMAGE, - TOOLBAR_IMAGE, - APPLICATION_TITLE ); + mContentLayer = DemoHelper::CreateView(application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + APPLICATION_TITLE); // Add an extra space on the right to center the title text. - mToolBar.AddControl( Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT ); + mToolBar.AddControl(Actor::New(), DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT); AddContentLayer(); - } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { // quit the application mApplication.Quit(); @@ -151,7 +149,7 @@ public: { if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) { mApplication.Quit(); } @@ -164,38 +162,37 @@ public: Renderer CreateQuadRenderer() { // Create shader & geometry needed by Renderer - Shader shader = LoadShaders( SHADER_NAME ); + Shader shader = LoadShaders(SHADER_NAME); Property::Map vertexFormat; vertexFormat["aPosition"] = Property::VECTOR2; - VertexBuffer vertexBuffer = VertexBuffer::New( vertexFormat ); + VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat); - const float P( 0.5f ); + const float P(0.5f); const Vector2 vertices[] = { - Vector2( -P, -P ), - Vector2( +P, -P ), - Vector2( -P, +P ), - Vector2( +P, +P ) - }; + Vector2(-P, -P), + Vector2(+P, -P), + Vector2(-P, +P), + Vector2(+P, +P)}; - vertexBuffer.SetData( vertices, 4 ); + vertexBuffer.SetData(vertices, 4); // Instantiate quad geometry Geometry geometry = Geometry::New(); - geometry.AddVertexBuffer( vertexBuffer ); - geometry.SetType( Geometry::TRIANGLE_STRIP ); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_STRIP); // Create renderer - Renderer renderer = Renderer::New( geometry, shader ); + Renderer renderer = Renderer::New(geometry, shader); - renderer.RegisterProperty("uRadius", 0.0f ); - renderer.RegisterProperty("uAdjuster", -4.0f ); + renderer.RegisterProperty("uRadius", 0.0f); + renderer.RegisterProperty("uAdjuster", -4.0f); // Animate the sphere radius uniform and a generic uAdjust uniform currently used to move the light around Animation animation = Animation::New(8.0f); - animation.AnimateTo( Property(renderer,"uRadius"), 1.2f, AlphaFunction::BOUNCE); - animation.AnimateTo( Property(renderer,"uAdjuster"), 4.0f, AlphaFunction::BOUNCE); - animation.SetLooping( true ); + animation.AnimateTo(Property(renderer, "uRadius"), 1.2f, AlphaFunction::BOUNCE); + animation.AnimateTo(Property(renderer, "uAdjuster"), 4.0f, AlphaFunction::BOUNCE); + animation.SetLooping(true); animation.Play(); return renderer; @@ -205,30 +202,30 @@ public: { Window window = mApplication.GetWindow(); - //Create all the renderers + //Create all the renderers Renderer renderer = CreateQuadRenderer(); Actor actor = Actor::New(); - actor.AddRenderer( renderer ); + actor.AddRenderer(renderer); - actor.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER ); - actor.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER ); - actor.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS ); + actor.SetProperty(Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER); + actor.SetProperty(Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER); + actor.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS); - mContentLayer.Add( actor ); + mContentLayer.Add(actor); } private: - Application& mApplication; - Control mView; - Layer mContentLayer; - ToolBar mToolBar; + Application& mApplication; + Control mView; + Layer mContentLayer; + ToolBar mToolBar; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - RayMarchingExample test( application ); + Application application = Application::New(&argc, &argv); + RayMarchingExample test(application); application.MainLoop(); return 0; }