From f77f22f015ffafd94c7ed62af1c44fa731907ad7 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Tue, 13 Jun 2023 15:20:52 +0900 Subject: [PATCH] Add Render Pass Tag example Change-Id: I66ae1484075c4ef905556feb2a2dd41e700395c6 Signed-off-by: seungho baek --- com.samsung.dali-demo.xml | 3 + examples-reel/dali-examples-reel.cpp | 1 + .../render-pass-tag/render-pass-tag-example.cpp | 216 +++++++++++++++++++++ resources/po/en_GB.po | 3 + resources/po/en_US.po | 3 + shared/dali-demo-strings.h | 2 + 6 files changed, 228 insertions(+) create mode 100644 examples/render-pass-tag/render-pass-tag-example.cpp diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index f7fa4a5..52b1f24 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -256,6 +256,9 @@ + + + diff --git a/examples-reel/dali-examples-reel.cpp b/examples-reel/dali-examples-reel.cpp index 05231d6..b74f803 100644 --- a/examples-reel/dali-examples-reel.cpp +++ b/examples-reel/dali-examples-reel.cpp @@ -83,6 +83,7 @@ int DALI_EXPORT_API main(int argc, char** argv) demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); demo.AddExample(Example("remote-image-loading.example", DALI_DEMO_STR_TITLE_REMOTE_IMAGE)); + demo.AddExample(Example("render-pass-tag.example", DALI_DEMO_STR_TITLE_RENDER_PASS_TAG)); demo.AddExample(Example("rendering-basic-light.example", DALI_DEMO_STR_TITLE_BASIC_LIGHT)); demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE)); demo.AddExample(Example("rendering-triangle.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE)); diff --git a/examples/render-pass-tag/render-pass-tag-example.cpp b/examples/render-pass-tag/render-pass-tag-example.cpp new file mode 100644 index 0000000..fb912b6 --- /dev/null +++ b/examples/render-pass-tag/render-pass-tag-example.cpp @@ -0,0 +1,216 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +using namespace Dali; +using Dali::Toolkit::TextLabel; + +namespace +{ + +Geometry CreateQuadGeometry() +{ + // Create geometry -- unit square with whole of the texture mapped to it. + struct Vertex + { + Vector3 aPosition; + }; + + Vertex vertexData[] = { + {Vector3(-.5f, .5f, .0f)}, + {Vector3(.5f, .5f, .0f)}, + {Vector3(-.5f, -.5f, .0f)}, + {Vector3(.5f, -.5f, .0f)}, + }; + + VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map() + .Add("aPosition", Property::VECTOR3)); + vertexBuffer.SetData(vertexData, std::extent::value); + + Geometry geometry = Geometry::New(); + geometry.AddVertexBuffer(vertexBuffer); + geometry.SetType(Geometry::TRIANGLE_STRIP); + return geometry; +} + +const std::string_view SHADER_COLOR_TEST_SHADER_VERT{ + R"(INPUT mediump vec2 aPosition; +uniform highp mat4 uMvpMatrix; +uniform highp vec3 uSize; + +void main() +{ + gl_Position = uMvpMatrix * vec4(uSize.xy * aPosition, 0.0, 1.0); +} +)"}; + +const std::string_view SHADER_COLOR_TEST_SHADER_FRAG{ + R"( +void main() +{ + OUT_COLOR = vec4(0.0, 0.0, 1.0, 1.0); +} +)"}; + +const std::string_view SHADER_IMAGE_TEST_SHADER_VERT{ + R"(INPUT mediump vec2 aPosition; +OUTPUT mediump vec2 vTexCoord; + +uniform highp mat4 uMvpMatrix; +uniform highp vec3 uSize; + +void main() +{ + vTexCoord = vec2(0.5) + aPosition.xy; + gl_Position = uMvpMatrix * vec4(uSize.xy * aPosition, 0.0, 1.0); +} +)"}; + +const std::string_view SHADER_IMAGE_TEST_SHADER_FRAG{ + R"(INPUT mediump vec2 vTexCoord; +// +uniform sampler2D sColorTexture; +uniform sampler2D sTexture; + +void main() +{ + mediump vec2 texCoord = vTexCoord; + lowp vec4 textureColor = TEXTURE( sTexture, texCoord ) * TEXTURE( sColorTexture, texCoord ); + OUT_COLOR = textureColor; +} +)"}; + +static constexpr std::string_view SAMPLE_IMAGE_PASS(DEMO_IMAGE_DIR "gallery-medium-19.jpg"); +} // namespace + +// This example shows how to create and display Hello World! using a simple TextActor +// +class RenderPassTagController : public ConnectionTracker +{ +public: + RenderPassTagController(Application& application) + : mApplication(application) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect(this, &RenderPassTagController::Create); + } + + ~RenderPassTagController() = default; // Nothing to do in destructor + + // The Init signal is received once (only) during the Application lifetime + void Create(Application& application) + { + // Get a handle to the window + mWindow = application.GetWindow(); + mWindow.SetBackgroundColor(Color::WHITE); + + Dali::Toolkit::Control control = Dali::Toolkit::Control::New(); + control.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + control.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + control.SetProperty(Dali::Actor::Property::SIZE, Vector2(300.0f, 300.0f)); + mWindow.Add(control); + + Property::Map shader1; + shader1.Add("renderPassTag", 1); + shader1.Add("vertex", Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_TEST_SHADER_VERT.data()); + shader1.Add("fragment", Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_TEST_SHADER_FRAG.data()); + + Property::Map shader2; + shader2.Add("renderPassTag", 0); + shader2.Add("vertex", Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_TEST_SHADER_VERT.data()); + shader2.Add("fragment", Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_TEST_SHADER_FRAG.data()); + + Property::Array array; + array.PushBack(shader1); + array.PushBack(shader2); + + Dali::Shader shader = Dali::Shader::New(array); + Geometry geometry = CreateQuadGeometry(); + Renderer renderer = Renderer::New(geometry, shader); + control.AddRenderer(renderer); + + RenderTask renderTask = mWindow.GetRenderTaskList().CreateTask(); + renderTask.SetSourceActor(control); + renderTask.SetExclusive(false); + renderTask.SetInputEnabled(false); + renderTask.SetCullMode(false); + renderTask.SetClearEnabled(true); + renderTask.SetClearColor(Color::TRANSPARENT); + renderTask.SetRenderPassTag(1u); + + CameraActor cameraActor = Dali::CameraActor::New(Vector2(300.0f, 300.0f)); + float cameraDefaultZPosition = cameraActor.GetProperty(Dali::Actor::Property::POSITION_Z); + cameraActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(0.0f, 0.0f, cameraDefaultZPosition)); + cameraActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + cameraActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + renderTask.SetCameraActor(cameraActor); + mWindow.Add(cameraActor); + + Texture colorTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 300u, 300u); + FrameBuffer frameBuffer = FrameBuffer::New(300u, 300u, FrameBuffer::Attachment::NONE); + frameBuffer.AttachColorTexture(colorTexture); + + renderTask.SetFrameBuffer(frameBuffer); + + TextureSet textures = TextureSet::New(); + textures.SetTexture(0u, colorTexture); + + Texture texture = DemoHelper::LoadTexture(SAMPLE_IMAGE_PASS.data()); + textures.SetTexture(1u, texture); + + renderer.SetTextures(textures); + + // Respond to a touch anywhere on the window + mWindow.GetRootLayer().TouchedSignal().Connect(this, &RenderPassTagController::OnTouch); + + // Respond to key events + mWindow.KeyEventSignal().Connect(this, &RenderPassTagController::OnKeyEvent); + } + + bool OnTouch(Actor actor, const TouchEvent& touch) + { + // quit the application + mApplication.Quit(); + return true; + } + + void OnKeyEvent(const KeyEvent& event) + { + if(event.GetState() == KeyEvent::DOWN) + { + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) + { + mApplication.Quit(); + } + } + } + +private: + Application& mApplication; + Window mWindow; +}; + +int DALI_EXPORT_API main(int argc, char** argv) +{ + Application application = Application::New(&argc, &argv); + RenderPassTagController test(application); + application.MainLoop(); + return 0; +} diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po index 35c782c..3f66edc 100755 --- a/resources/po/en_GB.po +++ b/resources/po/en_GB.po @@ -280,6 +280,9 @@ msgstr "Visual Transitions" msgid "DALI_DEMO_STR_TITLE_REMOTE_IMAGE" msgstr "Remote Image" +msgid "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG" +msgstr "Render Pass Tag" + msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" msgstr "Textured cube" diff --git a/resources/po/en_US.po b/resources/po/en_US.po index 6d1a91f..925120f 100755 --- a/resources/po/en_US.po +++ b/resources/po/en_US.po @@ -289,6 +289,9 @@ msgstr "Visual Transitions" msgid "DALI_DEMO_STR_TITLE_REMOTE_IMAGE" msgstr "Remote Image" +msgid "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG" +msgstr "Render Pass Tag" + msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" msgstr "Textured cube" diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h index 1d6377f..03691c2 100644 --- a/shared/dali-demo-strings.h +++ b/shared/dali-demo-strings.h @@ -111,6 +111,7 @@ extern "C" #define DALI_DEMO_STR_TITLE_REFLECTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFLECTION") #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REMOTE_IMAGE") +#define DALI_DEMO_STR_TITLE_RENDER_PASS_TAG dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDER_PASS_TAG") #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE") #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 "C" #define DALI_DEMO_STR_TITLE_REFLECTION "Reflection" #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" #define DALI_DEMO_STR_TITLE_REMOTE_IMAGE "Remote Image" +#define DALI_DEMO_STR_TITLE_RENDER_PASS_TAG "Render Pass" #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE "Draw Triangle" #define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE "Draw Cube" -- 2.7.4