From 2ce6af8668be21138858d543612c3d7664c9921b Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 15 Jan 2025 15:41:34 +0900 Subject: [PATCH] Make UniformBlockExample use Dali::UniformBlock Let we make uColorArray as shared uniform, so make we don't allocate and register for whole 1024 array per each renderer. Change-Id: If95316620be3857ff55d885df004e89309c86927 Signed-off-by: Eunki, Hong --- .../shaders/uniform-block-alt.frag | 8 +- .../uniform-blocks/shaders/uniform-block.frag | 9 +- .../uniform-blocks/uniform-blocks-example.cpp | 84 +++++++++++-------- 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/examples/uniform-blocks/shaders/uniform-block-alt.frag b/examples/uniform-blocks/shaders/uniform-block-alt.frag index 6e0192b6c..eae30f956 100644 --- a/examples/uniform-blocks/shaders/uniform-block-alt.frag +++ b/examples/uniform-blocks/shaders/uniform-block-alt.frag @@ -1,9 +1,13 @@ //@version 100 -UNIFORM_BLOCK FragmentBlock +UNIFORM_BLOCK SharedFragmentBlock { - UNIFORM lowp vec4 uColor; UNIFORM mediump vec4 uColorArray[1024]; +}; + +UNIFORM_BLOCK FragmentBlock +{ + UNIFORM lowp vec4 uColor; UNIFORM mediump int uColorIndex; }; diff --git a/examples/uniform-blocks/shaders/uniform-block.frag b/examples/uniform-blocks/shaders/uniform-block.frag index 714793534..e0ec6cf66 100644 --- a/examples/uniform-blocks/shaders/uniform-block.frag +++ b/examples/uniform-blocks/shaders/uniform-block.frag @@ -1,10 +1,13 @@ //@version 100 +UNIFORM_BLOCK SharedFragmentBlock +{ + UNIFORM mediump vec4 uColorArray[1024]; +}; + UNIFORM_BLOCK FragmentBlock { -UNIFORM lowp vec4 uColor; -UNIFORM mediump vec4 uColorArray[1024]; -UNIFORM mediump int uColorIndex; + UNIFORM mediump int uColorIndex; }; void main() diff --git a/examples/uniform-blocks/uniform-blocks-example.cpp b/examples/uniform-blocks/uniform-blocks-example.cpp index 34a787198..b115b42fb 100644 --- a/examples/uniform-blocks/uniform-blocks-example.cpp +++ b/examples/uniform-blocks/uniform-blocks-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2025 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. @@ -16,16 +16,15 @@ */ #include +#include -#include "generated/uniform-block-vert.h" -#include "generated/uniform-block-frag.h" #include "generated/uniform-block-alt-frag.h" +#include "generated/uniform-block-frag.h" +#include "generated/uniform-block-vert.h" using namespace Dali; using Dali::Toolkit::TextLabel; - - /** * This application tests that shaders with uniform blocks work as expected. */ @@ -48,12 +47,14 @@ public: Window window = application.GetWindow(); window.SetBackgroundColor(Color::WHITE); + mUniformBlocks = UniformBlock::New("SharedFragmentBlock"); + CreateShader(0); CreateGeometry(); CreateRenderer(); mFirstActor = window.GetRootLayer().GetChildCount(); - for(int i=0; i<200; ++i) + for(int i = 0; i < 200; ++i) { AddActor(i); } @@ -70,30 +71,32 @@ public: bool OnTick() { - static int index=200; - Window window = mApplication.GetWindow(); - Layer layer = window.GetRootLayer(); - Actor child = layer.GetChildAt(mFirstActor); + static int index = 200; + Window window = mApplication.GetWindow(); + Layer layer = window.GetRootLayer(); + Actor child = layer.GetChildAt(mFirstActor); UnparentAndReset(child); AddActor(index); - index = (index+1)%1024; + index = (index + 1) % 1024; return true; } bool OnTouch(Actor actor, const TouchEvent& touch) { - static int testNumber=0; + static int testNumber = 0; if(touch.GetState(0) == PointState::STARTED) { testNumber++; - if(testNumber >=2) + if(testNumber >= 2) + { mApplication.Quit(); + } CreateShader(testNumber); - mRenderer = Renderer::New(mGeometry, mShader); + CreateRenderer(); Actor parent = mApplication.GetWindow().GetRootLayer(); - for(uint32_t i=0; i