Added a GlWindow example 23/316723/7
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 17 Dec 2024 10:42:57 +0000 (10:42 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Sat, 25 Jan 2025 00:46:43 +0000 (00:46 +0000)
Change-Id: I44b97051792d2b6a1b64591fa591dbf633286ba6

com.samsung.dali-demo.xml
examples-reel/dali-examples-reel.cpp
examples/direct-rendering/README.md
examples/gl-window/README.md [new file with mode: 0644]
examples/gl-window/dependencies.cmake [new file with mode: 0644]
examples/gl-window/gl-window-example.cpp [new file with mode: 0644]
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h

index a52460cd35a4c57ea07c695e45e43b236a69a7e2..d83bbcca22bb5f8aeaac125ca9f0cbcd2d9bc048 100644 (file)
        <ui-application appid="gestures.example" exec="/usr/apps/com.samsung.dali-demo/bin/gestures.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Gestures</label>
        </ui-application>
+       <ui-application appid="gl-window.example" exec="/usr/apps/com.samsung.dali-demo/bin/gl-window.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
+               <label>GL Window</label>
+       </ui-application>
        <ui-application appid="gradients.example" exec="/usr/apps/com.samsung.dali-demo/bin/gradients.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Color Gradient</label>
        </ui-application>
index d701af0a234d6367851bc0cbd3ce3c82b9d8c061..236c694ef625ee52b34e331561d33585cd86196b 100644 (file)
@@ -64,6 +64,7 @@ int DALI_EXPORT_API main(int argc, char** argv)
   demo.AddExample(Example("focus-integration.example", DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION));
   demo.AddExample(Example("gaussian-blur-view.example", DALI_DEMO_STR_TITLE_GAUSSIAN_BLUR_VIEW));
   demo.AddExample(Example("gestures.example", DALI_DEMO_STR_TITLE_GESTURES));
+  demo.AddExample(Example("gl-window.example", DALI_DEMO_STR_TITLE_GL_WINDOW));
   demo.AddExample(Example("gradients.example", DALI_DEMO_STR_TITLE_COLOR_GRADIENT));
   demo.AddExample(Example("hello-world.example", DALI_DEMO_STR_TITLE_HELLO_WORLD));
   demo.AddExample(Example("image-policies.example", DALI_DEMO_STR_TITLE_IMAGE_POLICIES));
index 47ceb56c57601a57c1fc94c45556c5e2c27c5eaf..0b9bcdeede807caf3ab3448ea8db23fa38d8863b 100644 (file)
@@ -17,4 +17,6 @@ demo will create isolated GL context for custom rendering.
 DR_THREAD_ENABLED (default: 0) - threaded rendering. Runs custom rendering code on a separate
 thread. This method implicitly creates an offscreen buffer to render into.
 
-MAX_CUBES - allows change number of cubes to render
\ No newline at end of file
+MAX_CUBES - allows change number of cubes to render
+
+**Please note:** native-renderer.cpp/h are used by gl-window.example as well.
\ No newline at end of file
diff --git a/examples/gl-window/README.md b/examples/gl-window/README.md
new file mode 100644 (file)
index 0000000..08c004e
--- /dev/null
@@ -0,0 +1,9 @@
+# GL Window Example
+
+This is an example showing how to use a GL Window in DALi.
+
+A GL Window allows injecting native drawing calls using GL API into the
+DALi rendering pipeline so developers can execute custom code in a separate window.
+This demo shows a bunch of cubes rendered by the custom GL code.
+
+**Please note:** native-renderer.cpp/h are used from direct-rendering.example.
\ No newline at end of file
diff --git a/examples/gl-window/dependencies.cmake b/examples/gl-window/dependencies.cmake
new file mode 100644 (file)
index 0000000..c3c3ade
--- /dev/null
@@ -0,0 +1,8 @@
+IF(ANDROID)
+  SET(EXTRA_EXAMPLE_LDFLAGS -lGLESv3)
+ELSEIF(NOT WIN32 AND NOT APPLE)
+  PKG_CHECK_MODULES(GLESV2 REQUIRED glesv2)
+  SET(EXTRA_EXAMPLE_LDFLAGS ${GLESV2_LIBRARIES})
+ENDIF()
+
+TARGET_SOURCES(${EXAMPLE}.example PRIVATE "${EXAMPLES_SRC_DIR}/direct-rendering/native-renderer.cpp")
diff --git a/examples/gl-window/gl-window-example.cpp b/examples/gl-window/gl-window-example.cpp
new file mode 100644 (file)
index 0000000..92acb1c
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2024 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 <dali-toolkit/dali-toolkit.h>
+#include <dali/devel-api/adaptor-framework/gl-window.h>
+#include "../direct-rendering/native-renderer.h"
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+class GlWindowExample : public ConnectionTracker
+{
+public:
+  explicit GlWindowExample(Application& application)
+  : mApplication(application)
+  {
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect(this, &GlWindowExample::Create);
+  }
+
+  ~GlWindowExample() override = default; // Nothing to do in destructor
+
+  void Create(Application& application)
+  {
+    // Get a handle to the window
+    Dali::Window window = application.GetWindow();
+    window.SetBackgroundColor(Color::WHITE);
+    window.KeyEventSignal().Connect(this, &GlWindowExample::OnKeyEvent);
+    window.GetRootLayer().TouchedSignal().Connect(this, &GlWindowExample::OnTouch);
+
+    // Create a textLabel to add to our main window
+    auto textLabel = Handle::New<TextLabel>(
+      {
+        {TextLabel::Property::TEXT, "Touch here to Exit"},
+        {TextLabel::Property::TEXT_COLOR, Color::BLACK},
+        {TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER},
+        {TextLabel::Property::VERTICAL_ALIGNMENT, VerticalAlignment::CENTER},
+        {Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER},
+        {Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER},
+        {Dali::Actor::Property::NAME, "label"},
+      });
+    window.Add(textLabel);
+
+    // Create GL Window and give it the same size as the main window
+    CreateGlWindow(window.GetSize());
+
+    // Resize main window to double the textLabel size so the GL Window takes focus
+    auto textSize = textLabel.GetNaturalSize() * 2.0f;
+    window.SetSize({uint32_t(textSize.width), uint32_t(textSize.y)});
+  }
+
+  int CreateGlWindow(const Vector2& windowSize)
+  {
+    auto w = windowSize.width;
+    auto h = windowSize.height;
+
+    NativeRenderer::CreateInfo info{};
+    info.clearColor = {0, 0, 0, 0};
+    info.name       = "GLWindow";
+    info.offscreen  = false;
+    info.viewportX  = 0;
+    info.viewportY  = 0;
+    info.width      = w;
+    info.height     = h;
+    info.threaded   = false;
+
+    mRenderer            = std::make_unique<NativeRenderer>(info);
+    mGlInitCallback      = MakeCallback(mRenderer.get(), &NativeRenderer::GlViewInitCallback);
+    mGlRenderCallback    = MakeCallback(mRenderer.get(), &NativeRenderer::GlViewRenderCallback);
+    mGlTerminateCallback = MakeCallback(mRenderer.get(), &NativeRenderer::GlViewTerminateCallback);
+
+    // Create GlVWindow with callbacks
+    mGlWindow = GlWindow::New();
+    mGlWindow.RegisterGlCallbacks(mGlInitCallback, mGlRenderCallback, mGlTerminateCallback);
+    mGlWindow.SetGraphicsConfig(true, false, 0, GlWindow::GlesVersion::VERSION_3_0);
+    mGlWindow.SetPositionSize(PositionSize(0, 0, w, h));
+    mGlWindow.SetRenderingMode(GlWindow::RenderingMode::CONTINUOUS);
+    mGlWindow.KeyEventSignal().Connect(this, &GlWindowExample::OnKeyEvent);
+    return 0;
+  }
+
+  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;
+  Dali::GlWindow                  mGlWindow;
+  std::unique_ptr<NativeRenderer> mRenderer{};
+
+  CallbackBase* mGlInitCallback{nullptr};
+  CallbackBase* mGlRenderCallback{nullptr};
+  CallbackBase* mGlTerminateCallback{nullptr};
+};
+
+int DALI_EXPORT_API main(int argc, char** argv)
+{
+  Application     application = Application::New(&argc, &argv);
+  GlWindowExample example(application);
+  application.MainLoop();
+  return 0;
+}
index 541d6b7a0094a2ac07ffcd3880114228861848e5..a8e9d98cb6aa0331c336e57d7bd9fa8cc8d5ffd2 100755 (executable)
@@ -103,6 +103,9 @@ msgstr "Flexbox Playground"
 msgid "DALI_DEMO_STR_TITLE_FRAME_CALLBACK"
 msgstr "Frame Callback"
 
+msgid "DALI_DEMO_STR_TITLE_GL_WINDOW"
+msgstr "GL Window"
+
 msgid "DALI_DEMO_STR_TITLE_HELLO_WORLD"
 msgstr "Hello World"
 
index d43fdf5769faf52eb1e3b6ac651f17b019379e03..98cee83e67ba23b7ac56442f4e175a2357020c48 100755 (executable)
@@ -109,6 +109,9 @@ msgstr "Flexbox Playground"
 msgid "DALI_DEMO_STR_TITLE_FRAME_CALLBACK"
 msgstr "Frame Callback"
 
+msgid "DALI_DEMO_STR_TITLE_GL_WINDOW"
+msgstr "GL Window"
+
 msgid "DALI_DEMO_STR_TITLE_HELLO_WORLD"
 msgstr "Hello World"
 
index 82e03ebe63c8acf9ce1e9cbe38fa196a6c261453..f2c1b21c3b1072b9784736693be62b93fdb6eac1 100644 (file)
@@ -74,6 +74,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND")
 #define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION")
 #define DALI_DEMO_STR_TITLE_FRAME_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FRAME_CALLBACK")
+#define DALI_DEMO_STR_TITLE_GL_WINDOW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_GL_WINDOW")
 #define DALI_DEMO_STR_TITLE_HELLO_WORLD dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HELLO_WORLD")
 #define DALI_DEMO_STR_TITLE_HOMESCREEN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_HOMESCREEN")
 #define DALI_DEMO_STR_TITLE_IMAGE_POLICIES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_IMAGE_POLICIES")
@@ -200,6 +201,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND "Flexbox Playground"
 #define DALI_DEMO_STR_TITLE_FOCUS_INTEGRATION "Focus Integration"
 #define DALI_DEMO_STR_TITLE_FRAME_CALLBACK "Frame Callback"
+#define DALI_DEMO_STR_TITLE_GL_WINDOW "GL Window"
 #define DALI_DEMO_STR_TITLE_HELLO_WORLD "Hello World"
 #define DALI_DEMO_STR_TITLE_HOMESCREEN "Homescreen Benchmark"
 #define DALI_DEMO_STR_TITLE_IMAGE_POLICIES "Image Policies"