Commit f77f22f015ffafd94c7ed62af1c44fa731907ad7

Authored by seungho baek
1 parent 8571c331

Add Render Pass Tag example

Change-Id: I66ae1484075c4ef905556feb2a2dd41e700395c6
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
com.samsung.dali-demo.xml
... ... @@ -256,6 +256,9 @@
256 256 <ui-application appid="remote-image-loading.example" exec="/usr/apps/com.samsung.dali-demo/bin/remote-image-loading.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
257 257 <label>Remote Image</label>
258 258 </ui-application>
  259 + <ui-application appid="render-pass-tag.example" exec="/usr/apps/com.samsung.dali-demo/bin/render-pass-tag.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  260 + <label>Render Pass</label>
  261 + </ui-application>
259 262 <ui-application appid="renderer-stencil.example" exec="/usr/apps/com.samsung.dali-demo/bin/renderer-stencil.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
260 263 <label>Renderer Stencils</label>
261 264 </ui-application>
... ...
examples-reel/dali-examples-reel.cpp
... ... @@ -83,6 +83,7 @@ int DALI_EXPORT_API main(int argc, char** argv)
83 83 demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES));
84 84 demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR));
85 85 demo.AddExample(Example("remote-image-loading.example", DALI_DEMO_STR_TITLE_REMOTE_IMAGE));
  86 + demo.AddExample(Example("render-pass-tag.example", DALI_DEMO_STR_TITLE_RENDER_PASS_TAG));
86 87 demo.AddExample(Example("rendering-basic-light.example", DALI_DEMO_STR_TITLE_BASIC_LIGHT));
87 88 demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE));
88 89 demo.AddExample(Example("rendering-triangle.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE));
... ...
examples/render-pass-tag/render-pass-tag-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +#include <dali-toolkit/dali-toolkit.h>
  19 +#include <dali/dali.h>
  20 +#include <shared/utility.h>
  21 +
  22 +using namespace Dali;
  23 +using Dali::Toolkit::TextLabel;
  24 +
  25 +namespace
  26 +{
  27 +
  28 +Geometry CreateQuadGeometry()
  29 +{
  30 + // Create geometry -- unit square with whole of the texture mapped to it.
  31 + struct Vertex
  32 + {
  33 + Vector3 aPosition;
  34 + };
  35 +
  36 + Vertex vertexData[] = {
  37 + {Vector3(-.5f, .5f, .0f)},
  38 + {Vector3(.5f, .5f, .0f)},
  39 + {Vector3(-.5f, -.5f, .0f)},
  40 + {Vector3(.5f, -.5f, .0f)},
  41 + };
  42 +
  43 + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map()
  44 + .Add("aPosition", Property::VECTOR3));
  45 + vertexBuffer.SetData(vertexData, std::extent<decltype(vertexData)>::value);
  46 +
  47 + Geometry geometry = Geometry::New();
  48 + geometry.AddVertexBuffer(vertexBuffer);
  49 + geometry.SetType(Geometry::TRIANGLE_STRIP);
  50 + return geometry;
  51 +}
  52 +
  53 +const std::string_view SHADER_COLOR_TEST_SHADER_VERT{
  54 + R"(INPUT mediump vec2 aPosition;
  55 +uniform highp mat4 uMvpMatrix;
  56 +uniform highp vec3 uSize;
  57 +
  58 +void main()
  59 +{
  60 + gl_Position = uMvpMatrix * vec4(uSize.xy * aPosition, 0.0, 1.0);
  61 +}
  62 +)"};
  63 +
  64 +const std::string_view SHADER_COLOR_TEST_SHADER_FRAG{
  65 + R"(
  66 +void main()
  67 +{
  68 + OUT_COLOR = vec4(0.0, 0.0, 1.0, 1.0);
  69 +}
  70 +)"};
  71 +
  72 +const std::string_view SHADER_IMAGE_TEST_SHADER_VERT{
  73 + R"(INPUT mediump vec2 aPosition;
  74 +OUTPUT mediump vec2 vTexCoord;
  75 +
  76 +uniform highp mat4 uMvpMatrix;
  77 +uniform highp vec3 uSize;
  78 +
  79 +void main()
  80 +{
  81 + vTexCoord = vec2(0.5) + aPosition.xy;
  82 + gl_Position = uMvpMatrix * vec4(uSize.xy * aPosition, 0.0, 1.0);
  83 +}
  84 +)"};
  85 +
  86 +const std::string_view SHADER_IMAGE_TEST_SHADER_FRAG{
  87 + R"(INPUT mediump vec2 vTexCoord;
  88 +//
  89 +uniform sampler2D sColorTexture;
  90 +uniform sampler2D sTexture;
  91 +
  92 +void main()
  93 +{
  94 + mediump vec2 texCoord = vTexCoord;
  95 + lowp vec4 textureColor = TEXTURE( sTexture, texCoord ) * TEXTURE( sColorTexture, texCoord );
  96 + OUT_COLOR = textureColor;
  97 +}
  98 +)"};
  99 +
  100 +static constexpr std::string_view SAMPLE_IMAGE_PASS(DEMO_IMAGE_DIR "gallery-medium-19.jpg");
  101 +} // namespace
  102 +
  103 +// This example shows how to create and display Hello World! using a simple TextActor
  104 +//
  105 +class RenderPassTagController : public ConnectionTracker
  106 +{
  107 +public:
  108 + RenderPassTagController(Application& application)
  109 + : mApplication(application)
  110 + {
  111 + // Connect to the Application's Init signal
  112 + mApplication.InitSignal().Connect(this, &RenderPassTagController::Create);
  113 + }
  114 +
  115 + ~RenderPassTagController() = default; // Nothing to do in destructor
  116 +
  117 + // The Init signal is received once (only) during the Application lifetime
  118 + void Create(Application& application)
  119 + {
  120 + // Get a handle to the window
  121 + mWindow = application.GetWindow();
  122 + mWindow.SetBackgroundColor(Color::WHITE);
  123 +
  124 + Dali::Toolkit::Control control = Dali::Toolkit::Control::New();
  125 + control.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
  126 + control.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
  127 + control.SetProperty(Dali::Actor::Property::SIZE, Vector2(300.0f, 300.0f));
  128 + mWindow.Add(control);
  129 +
  130 + Property::Map shader1;
  131 + shader1.Add("renderPassTag", 1);
  132 + shader1.Add("vertex", Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_TEST_SHADER_VERT.data());
  133 + shader1.Add("fragment", Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_TEST_SHADER_FRAG.data());
  134 +
  135 + Property::Map shader2;
  136 + shader2.Add("renderPassTag", 0);
  137 + shader2.Add("vertex", Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_TEST_SHADER_VERT.data());
  138 + shader2.Add("fragment", Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_TEST_SHADER_FRAG.data());
  139 +
  140 + Property::Array array;
  141 + array.PushBack(shader1);
  142 + array.PushBack(shader2);
  143 +
  144 + Dali::Shader shader = Dali::Shader::New(array);
  145 + Geometry geometry = CreateQuadGeometry();
  146 + Renderer renderer = Renderer::New(geometry, shader);
  147 + control.AddRenderer(renderer);
  148 +
  149 + RenderTask renderTask = mWindow.GetRenderTaskList().CreateTask();
  150 + renderTask.SetSourceActor(control);
  151 + renderTask.SetExclusive(false);
  152 + renderTask.SetInputEnabled(false);
  153 + renderTask.SetCullMode(false);
  154 + renderTask.SetClearEnabled(true);
  155 + renderTask.SetClearColor(Color::TRANSPARENT);
  156 + renderTask.SetRenderPassTag(1u);
  157 +
  158 + CameraActor cameraActor = Dali::CameraActor::New(Vector2(300.0f, 300.0f));
  159 + float cameraDefaultZPosition = cameraActor.GetProperty<float>(Dali::Actor::Property::POSITION_Z);
  160 + cameraActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(0.0f, 0.0f, cameraDefaultZPosition));
  161 + cameraActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
  162 + cameraActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
  163 + renderTask.SetCameraActor(cameraActor);
  164 + mWindow.Add(cameraActor);
  165 +
  166 + Texture colorTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 300u, 300u);
  167 + FrameBuffer frameBuffer = FrameBuffer::New(300u, 300u, FrameBuffer::Attachment::NONE);
  168 + frameBuffer.AttachColorTexture(colorTexture);
  169 +
  170 + renderTask.SetFrameBuffer(frameBuffer);
  171 +
  172 + TextureSet textures = TextureSet::New();
  173 + textures.SetTexture(0u, colorTexture);
  174 +
  175 + Texture texture = DemoHelper::LoadTexture(SAMPLE_IMAGE_PASS.data());
  176 + textures.SetTexture(1u, texture);
  177 +
  178 + renderer.SetTextures(textures);
  179 +
  180 + // Respond to a touch anywhere on the window
  181 + mWindow.GetRootLayer().TouchedSignal().Connect(this, &RenderPassTagController::OnTouch);
  182 +
  183 + // Respond to key events
  184 + mWindow.KeyEventSignal().Connect(this, &RenderPassTagController::OnKeyEvent);
  185 + }
  186 +
  187 + bool OnTouch(Actor actor, const TouchEvent& touch)
  188 + {
  189 + // quit the application
  190 + mApplication.Quit();
  191 + return true;
  192 + }
  193 +
  194 + void OnKeyEvent(const KeyEvent& event)
  195 + {
  196 + if(event.GetState() == KeyEvent::DOWN)
  197 + {
  198 + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
  199 + {
  200 + mApplication.Quit();
  201 + }
  202 + }
  203 + }
  204 +
  205 +private:
  206 + Application& mApplication;
  207 + Window mWindow;
  208 +};
  209 +
  210 +int DALI_EXPORT_API main(int argc, char** argv)
  211 +{
  212 + Application application = Application::New(&argc, &argv);
  213 + RenderPassTagController test(application);
  214 + application.MainLoop();
  215 + return 0;
  216 +}
... ...
resources/po/en_GB.po
... ... @@ -280,6 +280,9 @@ msgstr &quot;Visual Transitions&quot;
280 280 msgid "DALI_DEMO_STR_TITLE_REMOTE_IMAGE"
281 281 msgstr "Remote Image"
282 282  
  283 +msgid "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG"
  284 +msgstr "Render Pass Tag"
  285 +
283 286 msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE"
284 287 msgstr "Textured cube"
285 288  
... ...
resources/po/en_US.po
... ... @@ -289,6 +289,9 @@ msgstr &quot;Visual Transitions&quot;
289 289 msgid "DALI_DEMO_STR_TITLE_REMOTE_IMAGE"
290 290 msgstr "Remote Image"
291 291  
  292 +msgid "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG"
  293 +msgstr "Render Pass Tag"
  294 +
292 295 msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE"
293 296 msgstr "Textured cube"
294 297  
... ...
shared/dali-demo-strings.h
... ... @@ -111,6 +111,7 @@ extern &quot;C&quot;
111 111 #define DALI_DEMO_STR_TITLE_REFLECTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFLECTION")
112 112 #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION")
113 113 #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REMOTE_IMAGE")
  114 +#define DALI_DEMO_STR_TITLE_RENDER_PASS_TAG dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG")
114 115 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE")
115 116 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE")
116 117 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE")
... ... @@ -226,6 +227,7 @@ extern &quot;C&quot;
226 227 #define DALI_DEMO_STR_TITLE_REFLECTION "Reflection"
227 228 #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect"
228 229 #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE "Remote Image"
  230 +#define DALI_DEMO_STR_TITLE_RENDER_PASS_TAG "Render Pass"
229 231 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line"
230 232 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE "Draw Triangle"
231 233 #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE "Draw Cube"
... ...