From: JIYUN YANG Date: Fri, 22 Jan 2021 10:14:36 +0000 (+0000) Subject: Merge "Implement some new ewk apis in web view." into devel/master X-Git-Tag: dali_2.0.11~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=70510385d88cfbd5c232117d8436ca74c523e172;hp=d30d320c158f38d9c1ff49e01627467d3950698d Merge "Implement some new ewk apis in web view." into devel/master --- diff --git a/.gitignore b/.gitignore index aa38ad0..f31e277 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ core compile_commands.json dali-toolkit/internal/graphics/generated/* dali-toolkit/internal/graphics/builtin-shader-extern-gen.h +dali-scene-loader/internal/graphics/generated/* +dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h diff --git a/automated-tests/execute.sh b/automated-tests/execute.sh index add0e78..adee84b 100755 --- a/automated-tests/execute.sh +++ b/automated-tests/execute.sh @@ -1,6 +1,6 @@ #!/bin/bash -TEMP=`getopt -o dhsSmf --long debug,help,failnorerun,serial,tct,modules -n 'execute.sh' -- "$@"` +TEMP=`getopt -o dhsSmfq --long debug,help,failnorerun,quiet,serial,tct,modules -n 'execute.sh' -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi @@ -9,13 +9,14 @@ eval set -- "$TEMP" function usage { - echo -e "Usage: execute.sh [-d][-s|-S|-r] [module|testcase]" + echo -e "Usage: execute.sh [-d][-s|-S|-r][-q] [module|testcase]" echo -e " execute.sh\t\tExecute test cases from all modules in parallel" echo -e " execute.sh -f \tExecute test cases from all modules in parallel without rerunning failed test cases" echo -e " execute.sh -d \tDebug testcase" echo -e " execute.sh [module]\tExecute test cases from the given module in parallel" echo -e " execute.sh -s [module]\t\tExecute test cases in serial using Testkit-Lite" echo -e " execute.sh -S [module]\t\tExecute test cases in serial" + echo -e " execute.sh -q|--quiet ...\tExecute test cases, but don't write output" echo -e " execute.sh \tFind and execute the given test case" exit 2 } @@ -25,6 +26,7 @@ opt_serial="" opt_modules=0 opt_debug=0 opt_noFailedRerun=""; +opt_quiet=""; while true ; do case "$1" in -h|--help) usage ;; @@ -32,6 +34,7 @@ while true ; do -s|--tct) opt_tct=1 ; shift ;; -f|--nofailedrerun) opt_noFailedRerun="-f" ; shift ;; -S|--serial) opt_serial="-s" ; shift ;; + -q|--quiet) opt_quiet="-q" ; shift ;; -m|--modules) opt_modules=1 ; shift ;; --) shift; break;; *) echo "Internal error $1!" ; exit 1 ;; @@ -67,6 +70,31 @@ function summary_end EOF } +function output_start +{ + start=`date +"%Y-%m-%d_%H_%M_%S"` + cat > tct-${1}-core-tests.xml < + + + +$start$start + + +EOF +} + + +function output_end +{ + cat >> tct-${1}-core-tests.xml < + + +EOF +} + + if [ $opt_modules == 1 ] ; then modules= get_modules echo $modules @@ -118,7 +146,9 @@ else do echo -e "$ASCII_BOLD" echo -e "Executing $mod$ASCII_RESET" - dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun + output_start $mod + dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun $opt_quiet + output_end $mod done summary_end @@ -128,7 +158,9 @@ else summary_start module=$1 shift; - dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $* + output_start ${module} + dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $opt_quiet $* + output_end ${module} summary_end else diff --git a/automated-tests/src/dali-scene-loader-internal/tct-dali-scene-loader-internal-core.cpp b/automated-tests/src/dali-scene-loader-internal/tct-dali-scene-loader-internal-core.cpp index 9dea347..7bfea6e 100644 --- a/automated-tests/src/dali-scene-loader-internal/tct-dali-scene-loader-internal-core.cpp +++ b/automated-tests/src/dali-scene-loader-internal/tct-dali-scene-loader-internal-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-scene-loader-internal-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-scene-loader/tct-dali-scene-loader-core.cpp b/automated-tests/src/dali-scene-loader/tct-dali-scene-loader-core.cpp index 90b7a2c..5b79502 100644 --- a/automated-tests/src/dali-scene-loader/tct-dali-scene-loader-core.cpp +++ b/automated-tests/src/dali-scene-loader/tct-dali-scene-loader-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-scene-loader-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-toolkit-internal/tct-dali-toolkit-internal-core.cpp b/automated-tests/src/dali-toolkit-internal/tct-dali-toolkit-internal-core.cpp index 39ed044..fe0ed63 100644 --- a/automated-tests/src/dali-toolkit-internal/tct-dali-toolkit-internal-core.cpp +++ b/automated-tests/src/dali-toolkit-internal/tct-dali-toolkit-internal-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-toolkit-internal-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-toolkit-styling/tct-dali-toolkit-styling-core.cpp b/automated-tests/src/dali-toolkit-styling/tct-dali-toolkit-styling-core.cpp index ef04d46..16b61c2 100644 --- a/automated-tests/src/dali-toolkit-styling/tct-dali-toolkit-styling-core.cpp +++ b/automated-tests/src/dali-toolkit-styling/tct-dali-toolkit-styling-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-toolkit-styling-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-toolkit-third-party/tct-dali-toolkit-third-party-core.cpp b/automated-tests/src/dali-toolkit-third-party/tct-dali-toolkit-third-party-core.cpp index d188f08..779e56b 100644 --- a/automated-tests/src/dali-toolkit-third-party/tct-dali-toolkit-third-party-core.cpp +++ b/automated-tests/src/dali-toolkit-third-party/tct-dali-toolkit-third-party-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-toolkit-third-party-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp index b53630d..587d4a5 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -22,14 +22,21 @@ #include #include -#include +#include #include - +#include #include +#include #include +#include +#include #include +#include #include +using std::chrono::steady_clock; +using std::chrono::system_clock; + namespace TestHarness { typedef std::map RunningTestCases; @@ -48,18 +55,185 @@ const char* basename(const char* path) return slash; } -void SuppressLogOutput() +std::vector Split(const std::string& aString, char delimiter) { - // Close stdout and stderr to suppress the log output - close(STDOUT_FILENO); // File descriptor number for stdout is 1 - close(STDERR_FILENO); // File descriptor number for stderr is 2 + std::vector tokens; + std::string token; + std::istringstream tokenStream(aString); + while(std::getline(tokenStream, token, delimiter)) + { + tokens.push_back(token); + } + return tokens; +} - // The POSIX specification requires that /dev/null must be provided, - // The open function always chooses the lowest unused file descriptor - // It is sufficient for stdout to be writable. - open("/dev/null", O_WRONLY); // Redirect file descriptor number 1 (i.e. stdout) to /dev/null - // When stderr is opened it must be both readable and writable. - open("/dev/null", O_RDWR); // Redirect file descriptor number 2 (i.e. stderr) to /dev/null +std::string Join(const std::vector& tokens, char delimiter) +{ + std::ostringstream oss; + + unsigned int delimiterCount = 0; + for(auto& token : tokens) + { + oss << token; + if(delimiterCount < tokens.size() - 1) + { + oss << delimiter; + } + ++delimiterCount; + } + return oss.str(); +} + +std::string ChildOutputFilename(int pid) +{ + std::ostringstream os; + os << "/tmp/tct-child." << pid; + return os.str(); +} + +std::string TestModuleFilename(const char* processName) +{ + auto pathComponents = Split(processName, '/'); + auto aModule = pathComponents.back(); + aModule += "-tests.xml"; + return aModule; +} + +std::string TestModuleName(const char* processName) +{ + auto pathComponents = Split(processName, '/'); + auto aModule = pathComponents.back(); + auto moduleComponents = Split(aModule, '-'); + + moduleComponents[1][0] = std::toupper(moduleComponents[1][0]); + moduleComponents[2][0] = std::toupper(moduleComponents[2][0]); + + std::ostringstream oss; + for(unsigned int i = 1; i < moduleComponents.size() - 1; ++i) // [0]=tct, [n-1]=core + { + oss << moduleComponents[i]; + + if(i > 1 && i < moduleComponents.size() - 2) // skip first and last delimiter + { + oss << '-'; + } + } + + return oss.str(); +} + +std::string ReadAndEscape(std::string filename) +{ + std::ostringstream os; + std::ifstream ifs; + ifs.open(filename, std::ifstream::in); + while(ifs.good()) + { + std::string line; + std::getline(ifs, line); + for(auto c : line) + { + switch(c) + { + case '<': + os << "<"; + break; + case '>': + os << ">"; + break; + case '&': + os << "&"; + break; + default: + os << c; + break; + } + } + os << "\\" + << "n"; + } + ifs.close(); + return os.str(); +} + +void OutputTestResult( + std::ofstream& ofs, + const char* pathToExecutable, + std::string testSuiteName, + TestCase& testCase, + std::string startTime, + std::string endTime) +{ + std::string outputFilename = ChildOutputFilename(testCase.childPid); + std::string testOutput = ReadAndEscape(outputFilename); + + ofs << "" << std::endl + << "" + << pathToExecutable << testCase.name << "" << std::endl + << "" + << "" << (testCase.result == 0 ? "PASS" : "FAIL") << "" << std::endl + << "" << startTime << "" + << "" << endTime << "" + << "" + << "" << std::endl; + + unlink(outputFilename.c_str()); +} + +void OutputTestResults(const char* processName, RunningTestCases& children) +{ + std::ofstream ofs; + std::string filename = TestModuleFilename(processName); + std::string moduleName = TestModuleName(processName); + ofs.open(filename, std::ofstream::out | std::ofstream::app); + + // Sort completed cases by original test case id + std::vector childTestCases; + childTestCases.reserve(children.size()); + for(auto& element : children) childTestCases.push_back(element.second); + std::sort(childTestCases.begin(), childTestCases.end(), [](const TestCase& a, const TestCase& b) { + return a.testCase < b.testCase; + }); + + const int BUFSIZE = 256; + char buffer[BUFSIZE]; + for(auto& testCase : childTestCases) + { + auto tt = system_clock::to_time_t(testCase.startSystemTime); + strftime(buffer, BUFSIZE, "%c", localtime(&tt)); + std::string startTime(buffer); + OutputTestResult(ofs, processName, moduleName, testCase, startTime, startTime); + } + + ofs.close(); +} + +void OutputStatistics(const char* processName, int32_t numPasses, int32_t numFailures) +{ + FILE* fp = fopen("summary.xml", "a"); + if(fp != NULL) + { + fprintf(fp, + " \n" + " %d\n" + " %d\n" + " %5.2f\n" + " %d\n" + " %5.2f\n" + " 0\n" + " 0.00\n" + " 0\n" + " 0.00\n" + " \n", + basename(processName), + numPasses + numFailures, + numPasses, + (float)numPasses * 100.0f / (numPasses + numFailures), + numFailures, + (float)numFailures * 100.0f / (numPasses + numFailures)); + fclose(fp); + } } int32_t RunTestCase(struct ::testcase_s& testCase) @@ -89,35 +263,55 @@ int32_t RunTestCase(struct ::testcase_s& testCase) return result; } -int32_t RunTestCaseInChildProcess(struct ::testcase_s& testCase, bool suppressOutput) +int32_t RunTestCaseRedirectOutput(TestCase& testCase, bool suppressOutput) +{ + // Executing in child process + // Close stdout and stderr to suppress the log output + close(STDOUT_FILENO); // File descriptor number for stdout is 1 + + // The POSIX specification requires that /dev/null must be provided, + // The open function always chooses the lowest unused file descriptor + // It is sufficient for stdout to be writable. + open("/dev/null", O_WRONLY); // Redirect file descriptor number 1 (i.e. stdout) to /dev/null + + fflush(stderr); + close(STDERR_FILENO); + if(suppressOutput) + { + stderr = fopen("/dev/null", "w+"); // Redirect fd 2 to /dev/null + } + else + { + // When stderr is opened it must be both readable and writable. + std::string childOutputFilename = ChildOutputFilename(getpid()); + stderr = fopen(childOutputFilename.c_str(), "w+"); + } + + int32_t status = RunTestCase(*testCase.tctPtr); + + fflush(stderr); + fclose(stderr); + + return status; +} + +int32_t RunTestCaseInChildProcess(TestCase& testCase, bool redirect) { int32_t testResult = EXIT_STATUS_TESTCASE_FAILED; int32_t pid = fork(); if(pid == 0) // Child process { - if(suppressOutput) + if(redirect) { - SuppressLogOutput(); + int status = RunTestCaseRedirectOutput(testCase, false); + exit(status); } else { - printf("\n"); - for(int32_t i = 0; i < 80; ++i) printf("#"); - printf("\nTC: %s\n", testCase.name); - fflush(stdout); + int status = RunTestCase(*testCase.tctPtr); + exit(status); } - - int32_t status = RunTestCase(testCase); - - if(!suppressOutput) - { - fflush(stdout); - fflush(stderr); - fclose(stdout); - fclose(stderr); - } - exit(status); } else if(pid == -1) { @@ -126,8 +320,9 @@ int32_t RunTestCaseInChildProcess(struct ::testcase_s& testCase, bool suppressOu } else // Parent process { - int32_t status = 0; - int32_t childPid = waitpid(pid, &status, 0); + int32_t status = 0; + int32_t childPid = waitpid(pid, &status, 0); + testCase.childPid = childPid; if(childPid == -1) { perror("waitpid"); @@ -167,43 +362,32 @@ int32_t RunTestCaseInChildProcess(struct ::testcase_s& testCase, bool suppressOu return testResult; } -void OutputStatistics(const char* processName, int32_t numPasses, int32_t numFailures) +int32_t RunAll(const char* processName, ::testcase tc_array[], bool quiet) { - FILE* fp = fopen("summary.xml", "a"); - if(fp != NULL) + int32_t numFailures = 0; + int32_t numPasses = 0; + std::ofstream ofs; + std::string filename = TestModuleFilename(processName); + std::string moduleName = TestModuleName(processName); + ofs.open(filename, std::ofstream::out | std::ofstream::app); + const int BUFSIZE = 256; + char buffer[BUFSIZE]; + + // Run test cases in child process( to handle signals ), but run serially. + for(uint32_t i = 0; tc_array[i].name; i++) { - fprintf(fp, - " \n" - " %d\n" - " %d\n" - " %5.2f\n" - " %d\n" - " %5.2f\n" - " 0\n" - " 0.00\n" - " 0\n" - " 0.00\n" - " \n", - basename(processName), - numPasses + numFailures, - numPasses, - (float)numPasses / (numPasses + numFailures), - numFailures, - (float)numFailures / (numPasses + numFailures)); - fclose(fp); - } -} + auto tt = system_clock::to_time_t(system_clock::now()); + strftime(buffer, BUFSIZE, "%c", localtime(&tt)); + std::string startTime(buffer); -int32_t RunAll(const char* processName, ::testcase tc_array[]) -{ - int32_t numFailures = 0; - int32_t numPasses = 0; + TestCase testCase(i, &tc_array[i]); + testCase.result = RunTestCaseInChildProcess(testCase, quiet); - // Run test cases in child process( to kill output/handle signals ), but run serially. - for(uint32_t i = 0; tc_array[i].name; i++) - { - int32_t result = RunTestCaseInChildProcess(tc_array[i], false); - if(result == 0) + tt = system_clock::to_time_t(system_clock::now()); + strftime(buffer, BUFSIZE, "%c", localtime(&tt)); + std::string endTime(buffer); + + if(testCase.result == 0) { numPasses++; } @@ -211,7 +395,12 @@ int32_t RunAll(const char* processName, ::testcase tc_array[]) { numFailures++; } + if(!quiet) + { + OutputTestResult(ofs, processName, moduleName, testCase, startTime, endTime); + } } + ofs.close(); OutputStatistics(processName, numPasses, numFailures); @@ -219,7 +408,7 @@ int32_t RunAll(const char* processName, ::testcase tc_array[]) } // Constantly runs up to MAX_NUM_CHILDREN processes -int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool reRunFailed) +int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool reRunFailed, bool quiet) { int32_t numFailures = 0; int32_t numPasses = 0; @@ -241,8 +430,9 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re int32_t pid = fork(); if(pid == 0) // Child process { - SuppressLogOutput(); - exit(RunTestCase(tc_array[nextTestCase])); + TestCase testCase(nextTestCase, &tc_array[nextTestCase]); + int status = RunTestCaseRedirectOutput(testCase, quiet); + exit(status); } else if(pid == -1) { @@ -252,7 +442,9 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re else // Parent process { TestCase tc(nextTestCase, tc_array[nextTestCase].name); - tc.startTime = std::chrono::steady_clock::now(); + tc.startTime = steady_clock::now(); + tc.startSystemTime = system_clock::now(); + tc.childPid = pid; children[pid] = tc; nextTestCase++; @@ -289,11 +481,12 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re { if(WIFEXITED(status)) { - int32_t testResult = WEXITSTATUS(status); - if(testResult) + auto& testCase = children[childPid]; + testCase.result = WEXITSTATUS(status); + if(testCase.result) { - printf("Test case %s failed: %d\n", children[childPid].testCaseName, testResult); - failedTestCases.push_back(children[childPid].testCase); + printf("Test case %s failed: %d\n", testCase.name, testCase.result); + failedTestCases.push_back(testCase.testCase); numFailures++; } else @@ -310,7 +503,8 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re RunningTestCases::iterator iter = children.find(childPid); if(iter != children.end()) { - printf("Test case %s exited with signal %s\n", iter->second.testCaseName, strsignal(status)); + printf("Test case %s exited with signal %s\n", iter->second.name, strsignal(status)); + iter->second.result = 1; failedTestCases.push_back(iter->second.testCase); } else @@ -324,6 +518,11 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re } } + if(!quiet) + { + OutputTestResults(processName, children); + } + OutputStatistics(processName, numPasses, numFailures); if(reRunFailed) @@ -338,7 +537,9 @@ int32_t RunAllInParallel(const char* processName, ::testcase tc_array[], bool re printf("="); } printf("\n"); - RunTestCaseInChildProcess(tc_array[failedTestCases[i]], false); + int index = failedTestCases[i]; + TestCase testCase(index, &tc_array[index]); + RunTestCaseInChildProcess(testCase, false); } } @@ -368,11 +569,62 @@ void Usage(const char* program) " %s \t\t Execute a test case\n" " %s \t\t Execute all test cases in parallel\n" " %s -r\t\t Execute all test cases in parallel, rerunning failed test cases\n" - " %s -s\t\t Execute all test cases serially\n", + " %s -s\t\t Execute all test cases serially\n" + " %s -q\t\t Run without output\n", + program, program, program, program, program); } +int RunTests(int argc, char* const argv[], ::testcase tc_array[]) +{ + int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; + const char* optString = "sfq"; + bool optRerunFailed(true); + bool optRunSerially(false); + bool optQuiet(false); + + int nextOpt = 0; + do + { + nextOpt = getopt(argc, argv, optString); + switch(nextOpt) + { + case 'f': + optRerunFailed = false; + break; + case 's': + optRunSerially = true; + break; + case 'q': + optQuiet = true; + break; + case '?': + TestHarness::Usage(argv[0]); + exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); + break; + } + } while(nextOpt != -1); + + if(optind == argc) // no testcase name in argument list + { + if(optRunSerially) + { + result = TestHarness::RunAll(argv[0], tc_array, optQuiet); + } + else + { + result = TestHarness::RunAllInParallel(argv[0], tc_array, optRerunFailed, optQuiet); + } + } + else + { + // optind is index of next argument - interpret as testcase name + result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); + } + return result; +} + } // namespace TestHarness diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h index b210918..554846f 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.h @@ -41,33 +41,63 @@ const int32_t MAX_NUM_CHILDREN(16); struct TestCase { int32_t testCase; - const char* testCaseName; + const char* name; std::chrono::steady_clock::time_point startTime; + std::chrono::system_clock::time_point startSystemTime; + int32_t result; + pid_t childPid{0}; + testcase* tctPtr; + TestCase(int32_t index, testcase* testCase) + : testCase(index), + name(testCase->name), + startTime(), + startSystemTime(), + result(0), + childPid(0), + tctPtr(testCase) + { + } TestCase() : testCase(0), - testCaseName(NULL), - startTime() + name(NULL), + startTime(), + startSystemTime(), + result(0), + childPid(0), + tctPtr(nullptr) { } TestCase(int32_t tc, const char* name) : testCase(tc), - testCaseName(name), - startTime() + name(name), + startTime(), + startSystemTime(), + result(0), + childPid(0), + tctPtr(nullptr) { } TestCase(const TestCase& rhs) : testCase(rhs.testCase), - testCaseName(rhs.testCaseName), - startTime(rhs.startTime) + name(rhs.name), + startTime(rhs.startTime), + startSystemTime(rhs.startSystemTime), + result(rhs.result), + childPid(rhs.childPid), + tctPtr(rhs.tctPtr) { } TestCase& operator=(const TestCase& rhs) { - testCase = rhs.testCase; - testCaseName = rhs.testCaseName; - startTime = rhs.startTime; + testCase = rhs.testCase; + name = rhs.name; + startTime = rhs.startTime; + startSystemTime = rhs.startSystemTime; + result = rhs.result; + childPid = rhs.childPid; + tctPtr = rhs.tctPtr; return *this; } }; @@ -109,6 +139,14 @@ int32_t FindAndRunTestCase(::testcase tc_array[], const char* testCaseName); */ void Usage(const char* program); +/** + * Main function. + * @param[in] argc Argument count + * @param[in] argv Argument vector + * @param[in] tc_array Array of test cases + */ +int RunTests(int argc, char* const argv[], ::testcase tc_array[]); + } // namespace TestHarness #endif diff --git a/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.cpp b/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.cpp index 5e64bd3..6d6077b 100644 --- a/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.cpp +++ b/automated-tests/src/dali-toolkit/tct-dali-toolkit-core.cpp @@ -1,51 +1,7 @@ -#include -#include -#include #include #include "tct-dali-toolkit-core.h" int main(int argc, char * const argv[]) { - int result = TestHarness::EXIT_STATUS_BAD_ARGUMENT; - - const char* optString = "sf"; - bool optRerunFailed(true); - bool optRunSerially(false); - - int nextOpt = 0; - do - { - nextOpt = getopt( argc, argv, optString ); - switch(nextOpt) - { - case 'f': - optRerunFailed = false; - break; - case 's': - optRunSerially = true; - break; - case '?': - TestHarness::Usage(argv[0]); - exit(TestHarness::EXIT_STATUS_BAD_ARGUMENT); - break; - } - } while( nextOpt != -1 ); - - if( optind == argc ) // no testcase name in argument list - { - if( optRunSerially ) - { - result = TestHarness::RunAll( argv[0], tc_array ); - } - else - { - result = TestHarness::RunAllInParallel( argv[0], tc_array, optRerunFailed ); - } - } - else - { - // optind is index of next argument - interpret as testcase name - result = TestHarness::FindAndRunTestCase(tc_array, argv[optind]); - } - return result; + return TestHarness::RunTests(argc, argv, tc_array); } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp index 3d538cd..243a73b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include "dummy-control.h" @@ -74,7 +75,9 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ) .Add( ImageVisual::Property::PIXEL_AREA, Vector4() ) .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::REPEAT ) - .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT )); + .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::DEFAULT ) + .Add( DevelVisual::Property::CORNER_RADIUS, 22.2f ) + .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -87,6 +90,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap01(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get() == TEST_GIF_FILE_NAME ); + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 22.2f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::ABSOLUTE ); + // request AnimatedImageVisual with an URL Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() ); resultMap.Clear(); @@ -124,7 +135,9 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) .Add( "frameDelay", 200 ) .Add( "pixelArea", Vector4() ) .Add( "wrapModeU", WrapMode::REPEAT ) - .Add( "wrapModeV", WrapMode::DEFAULT )); + .Add( "wrapModeV", WrapMode::DEFAULT ) + .Add( "cornerRadius", 50.0f ) + .Add( "cornerRadiusPolicy", Visual::Transform::Policy::RELATIVE )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -159,6 +172,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap02(void) DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), 11, TEST_LOCATION ); + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 50.0f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::RELATIVE ); + END_TEST; } @@ -183,7 +204,8 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) .Add( "frameDelay", 200 ) .Add( "pixelArea", Vector4() ) .Add( "wrapModeU", WrapMode::REPEAT ) - .Add( "wrapModeV", WrapMode::DEFAULT )); + .Add( "wrapModeV", WrapMode::DEFAULT ) + .Add( "cornerRadius", 50.5f )); Property::Map resultMap; animatedImageVisual.CreatePropertyMap( resultMap ); @@ -218,6 +240,14 @@ int UtcDaliAnimatedImageVisualGetPropertyMap03(void) DALI_TEST_CHECK( value ); DALI_TEST_EQUALS( value->Get(), 11, TEST_LOCATION ); + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get(), 50.5f, TEST_LOCATION ); + + value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get() == Visual::Transform::Policy::ABSOLUTE ); + END_TEST; } @@ -271,12 +301,14 @@ int UtcDaliAnimatedImageVisualSynchronousLoading(void) { Property::Map propertyMap; - propertyMap.Insert(Visual::Property::TYPE, Visual::ANIMATED_IMAGE ); - propertyMap.Insert(ImageVisual::Property::URL, TEST_GIF_FILE_NAME ); - propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2); - propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2); - propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20); - propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true); + propertyMap.Insert( Visual::Property::TYPE, Visual::ANIMATED_IMAGE ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_GIF_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::BATCH_SIZE, 2 ); + propertyMap.Insert( ImageVisual::Property::CACHE_SIZE, 2 ); + propertyMap.Insert( ImageVisual::Property::FRAME_DELAY, 20 ); + propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true ); + propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS, 0.23f ); + propertyMap.Insert( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::ABSOLUTE ); VisualFactory factory = VisualFactory::Get(); Visual::Base visual = factory.CreateVisual( propertyMap ); @@ -1273,4 +1305,4 @@ int UtcDaliAnimatedImageVisualPlayback(void) } END_TEST; -} \ No newline at end of file +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp index 534aeb6..42a9e91 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-AnimatedVectorImageVisual.cpp @@ -139,7 +139,8 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual03(void) propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ) + .Add( DevelVisual::Property::CORNER_RADIUS, 50.0f ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -170,6 +171,7 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) tet_infoline( "UtcDaliVisualFactoryGetAnimatedVectorImageVisual04: Request animated vector image visual with a Property::Map" ); int startFrame = 1, endFrame = 3; + float cornerRadius = 50.0f; Property::Array playRange; playRange.PushBack( startFrame ); playRange.PushBack( endFrame ); @@ -181,7 +183,8 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) .Add( "playRange", playRange ) .Add( "stopBehavior", DevelImageVisual::StopBehavior::FIRST_FRAME ) .Add( "loopingMode", DevelImageVisual::LoopingMode::AUTO_REVERSE ) - .Add( "redrawInScalingDown", false ); + .Add( "redrawInScalingDown", false ) + .Add( "cornerRadius", cornerRadius ); Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap ); DALI_TEST_CHECK( visual ); @@ -237,6 +240,14 @@ int UtcDaliVisualFactoryGetAnimatedVectorImageVisual04(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get< bool >() == false ); + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get< float >(), cornerRadius, TEST_LOCATION ); + + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::ABSOLUTE ); + actor.Unparent( ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -249,6 +260,7 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) tet_infoline( "UtcDaliAnimatedVectorImageVisualGetPropertyMap01" ); int startFrame = 1, endFrame = 3; + float cornerRadius = 50.0f; Property::Array playRange; playRange.PushBack( startFrame ); playRange.PushBack( endFrame ); @@ -257,7 +269,9 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) propertyMap.Add( Toolkit::Visual::Property::TYPE, DevelVisual::ANIMATED_VECTOR_IMAGE ) .Add( ImageVisual::Property::URL, TEST_VECTOR_IMAGE_FILE_NAME ) .Add( DevelImageVisual::Property::LOOP_COUNT, 3 ) - .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ); + .Add( DevelImageVisual::Property::PLAY_RANGE, playRange ) + .Add( DevelVisual::Property::CORNER_RADIUS, cornerRadius ) + .Add( DevelVisual::Property::CORNER_RADIUS_POLICY, Visual::Transform::Policy::RELATIVE); // request AnimatedVectorImageVisual with a property map VisualFactory factory = VisualFactory::Get(); @@ -317,6 +331,14 @@ int UtcDaliAnimatedVectorImageVisualGetPropertyMap01(void) DALI_TEST_CHECK( value ); DALI_TEST_CHECK( value->Get< bool >() == true ); // Check default value + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT ); + DALI_TEST_CHECK( value ); + DALI_TEST_EQUALS( value->Get< float >(), cornerRadius, TEST_LOCATION ); + + value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" ); + DALI_TEST_CHECK( value ); + DALI_TEST_CHECK( value->Get< int >() == Visual::Transform::Policy::RELATIVE ); + // request AnimatedVectorImageVisual with an URL Visual::Base visual2 = factory.CreateVisual( TEST_VECTOR_IMAGE_FILE_NAME, ImageDimensions() ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 6f3fa6a..761e88e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -3617,6 +3617,8 @@ int UtcDaliVisualRoundedCorner(void) application.Render(); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); } // color visual 1 @@ -3759,8 +3761,114 @@ int UtcDaliVisualRoundedCorner(void) application.Render(); DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); } + // animated image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 24.0f; + + properties[Visual::Property::TYPE] = Visual::ANIMATED_IMAGE; + properties[ImageVisual::Property::URL] = TEST_GIF_FILE_NAME; + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius + 10.0f; // Dummy Input + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius; + properties["cornerRadiusPolicy"] = Toolkit::Visual::Transform::Policy::ABSOLUTE; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); + } + + // vector image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 27.0f; + + properties[Visual::Property::TYPE] = Visual::SVG; + properties[ImageVisual::Property::URL] = TEST_SVG_FILE_NAME; + properties[DevelVisual::Property::CORNER_RADIUS] = cornerRadius; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + // Default corner radius policy is absolute. + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::ABSOLUTE ), true, TEST_LOCATION ); + } + + // animated vector image visual + { + VisualFactory factory = VisualFactory::Get(); + Property::Map properties; + float cornerRadius = 1.3f; + + properties[Visual::Property::TYPE] = DevelVisual::ANIMATED_VECTOR_IMAGE; + properties[ImageVisual::Property::URL] = TEST_VECTOR_IMAGE_FILE_NAME; + properties["cornerRadius"] = cornerRadius; + properties[DevelVisual::Property::CORNER_RADIUS_POLICY] = Toolkit::Visual::Transform::Policy::RELATIVE; + + Visual::Base visual = factory.CreateVisual( properties ); + + // trigger creation through setting on stage + DummyControl dummy = DummyControl::New( true ); + Impl::DummyControl& dummyImpl = static_cast< Impl::DummyControl& >( dummy.GetImplementation() ); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + dummy.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + application.GetScene().Add( dummy ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadius", cornerRadius ), true, TEST_LOCATION ); + DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue< float >( "cornerRadiusPolicy", Toolkit::Visual::Transform::Policy::RELATIVE ), true, TEST_LOCATION ); + } + + END_TEST; } diff --git a/build/tizen/dali-scene-loader/CMakeLists.txt b/build/tizen/dali-scene-loader/CMakeLists.txt index dcab4a3..d3ebe7d 100644 --- a/build/tizen/dali-scene-loader/CMakeLists.txt +++ b/build/tizen/dali-scene-loader/CMakeLists.txt @@ -144,6 +144,16 @@ if( ANDROID ) target_link_libraries(${name} log) endif() +# Generate source files for shaders +SET(SHADER_SOURCE_DIR "${scene_loader_dir}/internal/graphics/shaders/") +SET(SHADER_GENERATED_DIR "${scene_loader_dir}/internal/graphics/generated") +EXECUTE_PROCESS( COMMAND bash -c "${repo_root_dir}/build/tizen/shader-generator.sh ${SHADER_SOURCE_DIR} ${SHADER_GENERATED_DIR}" ) + +SET(GENERATED_SHADER_DIR ${scene_loader_dir}/internal/graphics/) +SET_PROPERTY(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + "${GENERATED_SHADER_DIR}/generated/" + "${GENERATED_SHADER_DIR}/builtin-shader-extern-gen.h") + IF( INSTALL_CMAKE_MODULES ) SET_TARGET_PROPERTIES( ${name} PROPERTIES diff --git a/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag new file mode 100644 index 0000000..a1153c9 --- /dev/null +++ b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.frag @@ -0,0 +1,11 @@ +#version 300 es + +precision mediump float; +flat in float vColor; +out vec4 FragColor; + +void main() +{ + vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625)); + FragColor = vec4(rgb, 1.); +} \ No newline at end of file diff --git a/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert new file mode 100644 index 0000000..98b6086 --- /dev/null +++ b/dali-scene-loader/internal/graphics/shaders/scene-loader-joint-debug.vert @@ -0,0 +1,13 @@ +#version 300 es + +precision mediump float; +uniform mat4 uMvpMatrix; +in vec3 aPosition; +in float aColor; +flat out float vColor; + +void main() +{ + vColor = aColor; + gl_Position = uMvpMatrix * vec4(aPosition, 1.0); +} \ No newline at end of file diff --git a/dali-scene-loader/public-api/scene-definition.cpp b/dali-scene-loader/public-api/scene-definition.cpp index 409d285..54aa0c9 100644 --- a/dali-scene-loader/public-api/scene-definition.cpp +++ b/dali-scene-loader/public-api/scene-definition.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -24,6 +24,7 @@ #include "dali-scene-loader/public-api/blend-shape-details.h" #include "dali-scene-loader/public-api/utils.h" #include "dali-scene-loader/public-api/skinning-details.h" +#include "dali-scene-loader/internal/graphics/builtin-shader-extern-gen.h" //#define DEBUG_SCENE_DEFINITION //#define DEBUG_JOINTS @@ -133,27 +134,6 @@ struct ResourceReflector : IResourceReflector #ifdef DEBUG_JOINTS -const char* JOINT_DEBUG_VSH = "#version 300 es\n" -DALI_COMPOSE_SHADER( - precision mediump float; - uniform mat4 uMvpMatrix; - in vec3 aPosition; - in float aColor; - flat out float vColor; - void main() { - vColor = aColor; - gl_Position = uMvpMatrix * vec4(aPosition, 1.0); - }); - -const char* JOINT_DEBUG_FSH = "#version 300 es\n" -DALI_COMPOSE_SHADER( - precision mediump float; - flat in float vColor; - out vec4 FragColor; - void main() { - vec3 rgb = vec3(fract(vColor), fract(vColor * 0.00390625), fract(vColor * 0.00390625 * 0.00390625)); - FragColor = vec4(rgb, 1.); - }); Shader sJointDebugShader; int sNumScenes = 0; @@ -162,7 +142,7 @@ void EnsureJointDebugShaderCreated() { if (0 == sNumScenes) { - sJointDebugShader = Shader::New(JOINT_DEBUG_VSH, JOINT_DEBUG_FSH); + sJointDebugShader = Shader::New(SHADER_SCENE_LOADER_JOINT_DEBUG_VERT, SHADER_SCENE_LOADER_JOINT_DEBUG_FRAG); } ++sNumScenes; } diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp index 52dc236..959a39f 100644 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp @@ -17,12 +17,12 @@ // CLASS HEADER #include -#include // EXTERNAL INCLUDES #include #include #include +#include namespace Dali { @@ -1503,35 +1503,35 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) bool isEmissiveTexture = false; std::string VERTEX_SHADER, FRAGMENT_SHADER; - VERTEX_SHADER = GLES_VERSION_300; - VERTEX_SHADER += PHYSICALLY_BASED_VERTEX_SHADER; - FRAGMENT_SHADER = GLES_VERSION_300; + VERTEX_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data(); + VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data(); + FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data(); bool useIBL = ( scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT ); if( isMaterial ) { MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; - if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) ) + if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, SHADER_GLTF_BASECOLOR_TEXTURE_DEF.data(), addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::BASECOLOR_SHADER ); isBaseColorTexture = true; } - if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, DEFINE_METALLICROUGHNESS_TEXTURE, addIdx ) ) + if( SetTextureAndSampler( textureSet, materialInfo.metallicRoughnessTexture.index, FRAGMENT_SHADER, SHADER_GLTF_METALLICROUGHNESS_TEXTURE_DEF.data(), addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::METALLICROUGHNESS_SHADER ); isMetallicRoughnessTexture = true; } - if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, DEFINE_NORMAL_TEXTURE, addIdx ) ) + if( SetTextureAndSampler( textureSet, materialInfo.normalTexture.index, FRAGMENT_SHADER, SHADER_GLTF_NORMAL_TEXTURE_DEF.data(), addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::NORMAL_SHADER ); isNormalTexture = true; } - if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, DEFINE_OCCLUSION_TEXTURE, addIdx ) ) + if( SetTextureAndSampler( textureSet, materialInfo.occlusionTexture.index, FRAGMENT_SHADER, SHADER_GLTF_OCCULUSION_TEXTURE_DEF.data(), addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::OCCLUSION_SHADER ); isOcclusionTexture = true; } - if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, DEFINE_EMIT_TEXTURE, addIdx ) ) + if( SetTextureAndSampler( textureSet, materialInfo.emissiveTexture.index, FRAGMENT_SHADER, SHADER_GLTF_EMIT_TEXTURE_DEF.data(), addIdx ) ) { shaderTypeIndex += static_cast( ShaderType::EMIT_SHADER ); isEmissiveTexture = true; @@ -1540,7 +1540,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) if( useIBL ) { shaderTypeIndex += static_cast( ShaderType::IBL_SHADER ); - FRAGMENT_SHADER += DEFINE_IBL_TEXTURE; + FRAGMENT_SHADER += SHADER_GLTF_IBL_TEXTURE_DEF.data(); Sampler sampler = Sampler::New(); sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); @@ -1567,7 +1567,7 @@ Actor Loader::AddNode( Scene3dView& scene3dView, uint32_t index ) } } - FRAGMENT_SHADER += PHYSICALLY_BASED_FRAGMENT_SHADER; + FRAGMENT_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_FRAG.data(); if( !mShaderCache[shaderTypeIndex] ) { mShaderCache[shaderTypeIndex] = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-shader.h b/dali-toolkit/internal/controls/scene3d-view/gltf-shader.h deleted file mode 100644 index e51b77c..0000000 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-shader.h +++ /dev/null @@ -1,346 +0,0 @@ -#ifndef DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H -#define DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H - -/* - * Belows Vertex Shader and Fragment Shader code are based off glTF WebGL PBR. - * https://github.com/KhronosGroup/glTF-WebGL-PBR/ - * - * Copyright (c) 2016-2017 Mohamad Moneimne and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ - -const char* GLES_VERSION_300 = { - "#version 300 es\n\n" - "precision highp float;\n\n" -}; - -const char* DEFINE_BASECOLOR_TEXTURE = { - "#define TEXTURE_BASECOLOR\n\n" - "uniform sampler2D uBaseColorSampler;\n" - "uniform int uBaseColorTexCoordIndex;\n\n" -}; - -const char* DEFINE_METALLICROUGHNESS_TEXTURE = { - "#define TEXTURE_METALLICROUGHNESS\n\n" - "uniform sampler2D uMetallicRoughnessSampler;\n" - "uniform int uMetallicRoughnessTexCoordIndex;\n\n" -}; - -const char* DEFINE_NORMAL_TEXTURE = { - "#define TEXTURE_NORMAL\n\n" - "uniform sampler2D uNormalSampler;\n" - "uniform float uNormalScale;\n" - "uniform int uNormalTexCoordIndex;\n\n" -}; - -const char* DEFINE_OCCLUSION_TEXTURE = { - "#define TEXTURE_OCCLUSION\n\n" - "uniform sampler2D uOcclusionSampler;\n" - "uniform int uOcclusionTexCoordIndex;\n" - "uniform float uOcclusionStrength;\n\n" -}; - -const char* DEFINE_EMIT_TEXTURE = { - "#define TEXTURE_EMIT\n\n" - "uniform sampler2D uEmissiveSampler;\n" - "uniform int uEmissiveTexCoordIndex;\n" - "uniform vec3 uEmissiveFactor;\n\n" -}; - -const char* DEFINE_IBL_TEXTURE = { - "#define TEXTURE_IBL\n\n" - "uniform sampler2D ubrdfLUT;\n" - "uniform samplerCube uDiffuseEnvSampler;\n" - "uniform samplerCube uSpecularEnvSampler;\n" - "uniform vec4 uScaleIBLAmbient;\n" - "uniform highp float uMipmapLevel;\n" -}; - -const char* PHYSICALLY_BASED_VERTEX_SHADER = { - "in highp vec3 aPosition;\n" - "in mediump vec2 aTexCoord0;\n" - "in mediump vec2 aTexCoord1;\n" - "in lowp vec3 aNormal;\n" - "in lowp vec4 aTangent;\n" - "in lowp vec4 aVertexColor;\n" - - "uniform mediump vec3 uSize;\n" - "uniform mediump mat4 uModelMatrix;\n" - "uniform mediump mat4 uViewMatrix;\n" - "uniform mediump mat4 uProjection;\n" - "uniform lowp int uLightType;\n" - "uniform mediump vec3 uLightVector;\n" - "uniform lowp int uIsColor;\n" - - "out lowp vec2 vUV[2];\n" - "out lowp mat3 vTBN;\n" - "out lowp vec4 vColor;\n" - "flat out int visLight;\n" - "out highp vec3 vLightDirection;\n" - "out highp vec3 vPositionToCamera;\n" - - "void main()\n" - "{\n" - " highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0);\n" - " highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 );\n" - " highp vec4 positionV = uViewMatrix * ( invY * positionW );\n" - - " vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) );\n" - " vPositionToCamera *= invY.xyz;\n" - - " lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w;\n" - " vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal);\n" - - " vUV[0] = aTexCoord0;\n" - " vUV[1] = aTexCoord1;\n" - - " visLight = 1;\n" - " if( uLightType == 1 )\n" - " {\n" - " vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w );\n" - " }\n" - " else if( uLightType == 2 )\n" - " {\n" - " vLightDirection = -( invY.xyz * uLightVector );\n" - " }\n" - " else\n" - " {\n" - " visLight = 0;\n" - " }\n" - - " vColor = vec4( 1.0 );\n" - " if( uIsColor == 1 )\n" - " {\n" - " vColor = aVertexColor;\n" - " }\n" - - " gl_Position = uProjection * positionV;\n" // needs w for proper perspective correction - " gl_Position = gl_Position/gl_Position.w;\n" - "}\n" -}; - -const char* PHYSICALLY_BASED_FRAGMENT_SHADER = { - "uniform lowp vec3 uLightColor;\n" - "uniform lowp vec4 uBaseColorFactor;\n" - "uniform lowp vec2 uMetallicRoughnessFactors;\n" - "uniform lowp int alphaMode;\n" - "uniform lowp float alphaCutoff;\n" - - "in lowp vec2 vUV[2];\n" - "in lowp mat3 vTBN;\n" - "in lowp vec4 vColor;\n" - "flat in int visLight;\n" - "in highp vec3 vLightDirection;\n" - "in highp vec3 vPositionToCamera;\n" - - "out vec4 FragColor;" - - "struct PBRInfo\n" - "{\n" - " mediump float NdotL;\n" // cos angle between normal and light direction - " mediump float NdotV;\n" // cos angle between normal and view direction - " mediump float NdotH;\n" // cos angle between normal and half vector - " mediump float VdotH;\n" // cos angle between view direction and half vector - " mediump vec3 reflectance0;\n" // full reflectance color (normal incidence angle) - " mediump vec3 reflectance90;\n" // reflectance color at grazing angle - " lowp float alphaRoughness;\n" // roughness mapped to a more linear change in the roughness (proposed by [2]) - "};\n" - - "const float M_PI = 3.141592653589793;\n" - "const float c_MinRoughness = 0.04;\n" - - "vec3 getNormal()\n" - "{\n" - "#ifdef TEXTURE_NORMAL\n" - " lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb;\n" - " n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) );\n" - "#else\n" - " lowp vec3 n = normalize( vTBN[2].xyz );\n" - "#endif\n" - " return n;\n" - "}\n" - - "vec3 specularReflection( PBRInfo pbrInputs )\n" - "{\n" - " return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 );\n" - "}\n" - - "float geometricOcclusion( PBRInfo pbrInputs )\n" - "{\n" - " mediump float NdotL = pbrInputs.NdotL;\n" - " mediump float NdotV = pbrInputs.NdotV;\n" - " lowp float r = pbrInputs.alphaRoughness;\n" - - " lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n" - " lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n" - " return attenuationL * attenuationV;\n" - "}\n" - - "float microfacetDistribution(PBRInfo pbrInputs)\n" - "{\n" - " mediump float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;\n" - " lowp float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;\n" - " return roughnessSq / (M_PI * f * f);\n" - "}\n" - - "vec3 linear( vec3 color )\n" - "{\n" - " return pow(color,vec3(2.2));\n" - "}\n" - - "void main()\n" - "{\n" - // Metallic and Roughness material properties are packed together - // In glTF, these factors can be specified by fixed scalar values - // or from a metallic-roughness map - " lowp float metallic = uMetallicRoughnessFactors.x;\n" - " lowp float perceptualRoughness = uMetallicRoughnessFactors.y;\n" - - // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel. - // This layout intentionally reserves the 'r' channel for (optional) occlusion map data - "#ifdef TEXTURE_METALLICROUGHNESS\n" - " lowp vec4 metrou = texture(uMetallicRoughnessSampler, vUV[uMetallicRoughnessTexCoordIndex]);\n" - " metallic = metrou.b * metallic;\n" - " perceptualRoughness = metrou.g * perceptualRoughness;\n" - "#endif\n" - - " metallic = clamp(metallic, 0.0, 1.0);\n" - " perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n" - // Roughness is authored as perceptual roughness; as is convention, - // convert to material roughness by squaring the perceptual roughness [2]. - " lowp float alphaRoughness = perceptualRoughness * perceptualRoughness;\n" - - "#ifdef TEXTURE_BASECOLOR\n" - // The albedo may be defined from a base texture or a flat color - " lowp vec4 baseColor = texture(uBaseColorSampler, vUV[uBaseColorTexCoordIndex]) * uBaseColorFactor;\n" - " baseColor = vec4(linear(baseColor.rgb), baseColor.w);\n" - "#else\n" - " lowp vec4 baseColor = vColor * uBaseColorFactor;\n" - "#endif\n" - - " if( alphaMode == 0 )\n" - " {\n" - " baseColor.w = 1.0;\n" - " }\n" - " else if( alphaMode == 1 )\n" - " {\n" - " if( baseColor.w >= alphaCutoff )" - " {\n" - " baseColor.w = 1.0;\n" - " }\n" - " else\n" - " {\n" - " baseColor.w = 0.0;\n" - " }\n" - " }\n" - - " lowp vec3 f0 = vec3(0.04);\n" - " lowp vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n" - " diffuseColor *= ( 1.0 - metallic );\n" - " lowp vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n" - - // Compute reflectance. - " lowp float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n" - - // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. - // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. - " lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n" - " lowp vec3 specularEnvironmentR0 = specularColor.rgb;\n" - " lowp vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n" - - " mediump vec3 n = getNormal();\n" // normal at surface point - " mediump vec3 v = normalize(vPositionToCamera);\n" // Vector from surface point to camera - " mediump vec3 l = normalize(vLightDirection);\n" // Vector from light to surface point - " mediump vec3 h = normalize(l+v);\n" // Half vector between both l and v - " mediump vec3 reflection = -normalize(reflect(v, n));\n" - - " mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);\n" - " mediump float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n" - " mediump float NdotH = dot(n, h);\n" - " mediump float LdotH = dot(l, h);\n" - " mediump float VdotH = dot(v, h);\n" - - " PBRInfo pbrInputs = PBRInfo(\n" - " NdotL,\n" - " NdotV,\n" - " NdotH,\n" - " VdotH,\n" - " specularEnvironmentR0,\n" - " specularEnvironmentR90,\n" - " alphaRoughness\n" - " );\n" - - // Calculate the shading terms for the microfacet specular shading model - " lowp vec3 color = vec3(0.0);\n" - " if( visLight == 1 )\n" - " {\n" - " lowp vec3 F = specularReflection( pbrInputs );\n" - " lowp float G = geometricOcclusion( pbrInputs );\n" - " lowp float D = microfacetDistribution( pbrInputs );\n" - - // Calculation of analytical lighting contribution - " lowp vec3 diffuseContrib = ( 1.0 - F ) * ( diffuseColor / M_PI );\n" - " lowp vec3 specContrib = F * G * D / ( 4.0 * NdotL * NdotV );\n" - // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) - " color = NdotL * uLightColor * (diffuseContrib + specContrib);\n" - " }\n" - - "#ifdef TEXTURE_IBL\n" - " lowp float lod = ( perceptualRoughness * uMipmapLevel );\n" - // retrieve a scale and bias to F0. See [1], Figure 3 - " lowp vec3 brdf = linear( texture( ubrdfLUT, vec2( NdotV, 1.0 - perceptualRoughness ) ).rgb );\n" - " lowp vec3 diffuseLight = linear( texture( uDiffuseEnvSampler, n ).rgb );\n" - " lowp vec3 specularLight = linear( textureLod( uSpecularEnvSampler, reflection, lod ).rgb );\n" - - " lowp vec3 diffuse = diffuseLight * diffuseColor * uScaleIBLAmbient.x;\n" - " lowp vec3 specular = specularLight * ( specularColor * brdf.x + brdf.y ) * uScaleIBLAmbient.y;\n" - " color += ( diffuse + specular );\n" - "#endif\n" - - "#ifdef TEXTURE_OCCLUSION\n" - " lowp float ao = texture( uOcclusionSampler, vUV[uOcclusionTexCoordIndex] ).r;\n" - " color = mix( color, color * ao, uOcclusionStrength );\n" - "#endif\n" - - "#ifdef TEXTURE_EMIT\n" - " lowp vec3 emissive = linear( texture( uEmissiveSampler, vUV[uEmissiveTexCoordIndex] ).rgb ) * uEmissiveFactor;\n" - " color += emissive;\n" - "#endif\n" - - " FragColor = vec4( pow( color,vec3( 1.0 / 2.2 ) ), baseColor.a );\n" - "}\n" -}; - -} // namespace internal - -} // namespace Toolkit - -} // namespace Dali - -#endif // DALI_TOOLKIT_INTERNAL_GLTF_SHADER_H \ No newline at end of file diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp index 6956cb2..8052be2 100755 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace Dali { @@ -86,50 +87,6 @@ const char* const CUSTOM_FRAGMENT_SHADER( "fragmentShader" ); const char* const DEFAULT_SAMPLER_TYPE_NAME( "sampler2D" ); const char* const CUSTOM_SAMPLER_TYPE_NAME( "samplerExternalOES" ); -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - \n - void main()\n - {\n - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n - vertexPosition.xyz *= uSize;\n - gl_Position = uMvpMatrix * vertexPosition;\n - }\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - \n - void main()\n - {\n - gl_FragColor = vec4(0.0);\n - }\n -); - -const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying mediump vec2 vTexCoord;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - varying mediump vec2 sTexCoordRect;\n - void main()\n - {\n - gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n - vTexCoord = aPosition + vec2(0.5);\n - }\n -); - -const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( - uniform lowp vec4 uColor;\n - varying mediump vec2 vTexCoord;\n - uniform samplerExternalOES sTexture;\n - void main()\n - {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n - }\n -); - } // anonymous namepsace VideoView::VideoView( Dali::VideoSyncMode syncMode ) @@ -652,7 +609,7 @@ void VideoView::SetWindowSurfaceTarget() { // For underlay rendering mode, video display area have to be transparent. Geometry geometry = VisualFactoryCache::CreateQuadGeometry(); - Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + Shader shader = Shader::New( SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG ); mOverlayRenderer = Renderer::New( geometry, shader ); mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); } @@ -856,7 +813,7 @@ Dali::Shader VideoView::CreateShader() if( !vertexShaderValue || !checkShader ) { - vertexShader = VERTEX_SHADER_TEXTURE; + vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data(); } Property::Value* fragmentShaderValue = mEffectPropertyMap.Find( CUSTOM_FRAGMENT_SHADER ); @@ -872,13 +829,13 @@ Dali::Shader VideoView::CreateShader() if( !fragmentShaderValue || !checkShader ) { - fragmentShader += FRAGMENT_SHADER_TEXTURE; + fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data(); } } else { - vertexShader = VERTEX_SHADER_TEXTURE; - fragmentShader += FRAGMENT_SHADER_TEXTURE; + vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data(); + fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data(); } return Dali::Shader::New( vertexShader, fragmentShader ); diff --git a/dali-toolkit/internal/filters/blur-two-pass-filter.cpp b/dali-toolkit/internal/filters/blur-two-pass-filter.cpp index e870650..f86ffd4 100644 --- a/dali-toolkit/internal/filters/blur-two-pass-filter.cpp +++ b/dali-toolkit/internal/filters/blur-two-pass-filter.cpp @@ -28,6 +28,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -58,24 +59,6 @@ const float DEFAULT_KERNEL4[] = { 2.0f/16.0f, 1.5f/16.0f, 1.5f/16.0f, 1.5f/16.0f 1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f, 0.5f/16.0f, 0.5f/16.0f, 0.5f/16.0f, 0.5f/16.0f }; -const char* BLUR_TWO_PASS_FRAGMENT_SOURCE = -{ - "precision highp float;\n" - "varying mediump vec2 vTexCoord;\n" - "uniform sampler2D sTexture;\n" - "uniform vec2 uSampleOffsets[NUM_SAMPLES];\n" - "uniform float uSampleWeights[NUM_SAMPLES];\n" - "void main()\n" - "{\n" - " vec4 color = vec4(0.0);\n" - " for( int i = 0; i < NUM_SAMPLES; ++i )\n" - " {\n" - " color += texture2D( sTexture, vTexCoord + uSampleOffsets[i] ) * uSampleWeights[i];\n" - " }\n" - " gl_FragColor = color;\n" - "}\n" -}; - std::string GetOffsetUniformName( int index ) { std::ostringstream oss; @@ -90,20 +73,6 @@ std::string GetWeightUniformName( int index ) return oss.str(); } -const char* BLEND_TWO_IMAGES_FRAGMENT_SOURCE = -{ - "precision highp float;\n" - "uniform float uBlurStrength;\n " - "uniform sampler2D sTexture;\n" - "uniform sampler2D sEffect;\n" - "varying mediump vec2 vTexCoord;\n" - "void main()\n" - "{\n" - " gl_FragColor = texture2D( sTexture, vTexCoord ) * uBlurStrength" - " + texture2D( sEffect, vTexCoord )*(1.0-uBlurStrength); \n" - "}\n" -}; - const char* const BLUR_STRENGTH_UNIFORM_NAME( "uBlurStrength" ); const char* const EFFECT_IMAGE_NAME( "sEffect" ); @@ -135,7 +104,7 @@ void BlurTwoPassFilter::Enable() // Set up blur-two-pass custom shader std::ostringstream sstream; sstream << "#define NUM_SAMPLES " << kernelSize << "\n"; - sstream << BLUR_TWO_PASS_FRAGMENT_SOURCE; + sstream << SHADER_BLUR_TWO_PASS_SHADER_FRAG; std::string fragmentSource( sstream.str() ); // create actor to render input with applied emboss effect @@ -165,7 +134,7 @@ void BlurTwoPassFilter::Enable() mBlurredFrameBuffer.AttachColorTexture( blurredTexture ); // create an actor to blend the blurred image and the input image with the given blur strength - Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, BLEND_TWO_IMAGES_FRAGMENT_SOURCE ); + Renderer rendererForBlending = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_BLUR_TWO_IMAGES_SHADER_FRAG ); TextureSet textureSetForBlending = rendererForBlending.GetTextures(); textureSetForBlending.SetTexture( 0u, blurredTexture ); textureSetForBlending.SetTexture( 1u, mInputTexture ); diff --git a/dali-toolkit/internal/filters/emboss-filter.cpp b/dali-toolkit/internal/filters/emboss-filter.cpp index b1bd177..7ea7fe1 100644 --- a/dali-toolkit/internal/filters/emboss-filter.cpp +++ b/dali-toolkit/internal/filters/emboss-filter.cpp @@ -28,6 +28,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -41,35 +42,6 @@ namespace Internal namespace { -const char* EMBOSS_FRAGMENT_SOURCE = -{ - "precision highp float;\n" - "varying mediump vec2 vTexCoord;\n" - "uniform sampler2D sTexture;\n" - "uniform vec2 uTexScale;\n" - "uniform vec3 uCoefficient;\n" - "\n" - "void main()\n" - "{\n" - " vec4 color = uCoefficient.x * texture2D( sTexture, vTexCoord + vec2(0.0, -uTexScale.y) );\n" - " color += uCoefficient.y * texture2D( sTexture, vTexCoord );\n" - " color += uCoefficient.z * texture2D( sTexture, vTexCoord + vec2(0.0, uTexScale.y) );\n" - " gl_FragColor = color;\n" - "}\n" -}; - -const char* const COMPOSITE_FRAGMENT_SOURCE = -{ - "varying mediump vec2 vTexCoord;\n" - "uniform sampler2D sTexture;\n" - "uniform lowp vec4 uEffectColor;\n" - "void main()\n" - "{\n" - " gl_FragColor = uEffectColor;\n" - " gl_FragColor.a *= texture2D( sTexture, vTexCoord).a;\n" - "}\n" -}; - const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" ); const char* const COEFFICIENT_UNIFORM_NAME( "uCoefficient" ); const char* const COLOR_UNIFORM_NAME( "uEffectColor" ); @@ -103,7 +75,7 @@ void EmbossFilter::Enable() mActorForInput1.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale ); mActorForInput1.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( 2.f, -1.f, -1.f ) ); // set EMBOSS custom shader - Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE ); + Renderer renderer1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG ); SetRendererTexture( renderer1, mInputTexture ); mActorForInput1.AddRenderer( renderer1 ); mRootActor.Add( mActorForInput1 ); @@ -114,7 +86,7 @@ void EmbossFilter::Enable() mActorForInput2.RegisterProperty( TEX_SCALE_UNIFORM_NAME, textureScale ); mActorForInput2.RegisterProperty( COEFFICIENT_UNIFORM_NAME, Vector3( -1.f, -1.f, 2.f ) ); // set EMBOSS custom shader - Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, EMBOSS_FRAGMENT_SOURCE ); + Renderer renderer2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_SHADER_FRAG ); SetRendererTexture( renderer2, mInputTexture ); mActorForInput2.AddRenderer( renderer2 ); mRootActor.Add( mActorForInput2 ); @@ -126,12 +98,12 @@ void EmbossFilter::Enable() mRootActor.Add( mActorForComposite ); - mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE ); + mRendererForEmboss1 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG ); SetRendererTexture( mRendererForEmboss1, mFrameBufferForEmboss1 ); mRendererForEmboss1.RegisterProperty( COLOR_UNIFORM_NAME, Color::BLACK ); mActorForComposite.AddRenderer( mRendererForEmboss1 ); - mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, COMPOSITE_FRAGMENT_SOURCE ); + mRendererForEmboss2 = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_EMBOSS_FILTER_COMPOSITE_SHADER_FRAG ); SetRendererTexture( mRendererForEmboss2, mFrameBufferForEmboss2 ); mRendererForEmboss2.RegisterProperty( COLOR_UNIFORM_NAME, Color::WHITE ); mActorForComposite.AddRenderer( mRendererForEmboss2 ); diff --git a/dali-toolkit/internal/filters/spread-filter.cpp b/dali-toolkit/internal/filters/spread-filter.cpp index 5eb8a82..55b060b 100644 --- a/dali-toolkit/internal/filters/spread-filter.cpp +++ b/dali-toolkit/internal/filters/spread-filter.cpp @@ -26,6 +26,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -39,26 +40,6 @@ namespace Internal namespace { -const char* const SPREAD_FRAGMENT_SOURCE = -{ - "precision highp float;\n" - "varying mediump vec2 vTexCoord;\n" - "uniform sampler2D sTexture;\n" - "uniform int uSpread;\n" - "uniform vec2 uTexScale;\n" - "void main()\n" - "{\n" - " vec4 color = texture2D( sTexture, vTexCoord);\n" - " for( int i = 1; i <= uSpread; ++i )\n" - " {\n" - " vec2 offset = uTexScale * float(i);\n" - " color = max( texture2D( sTexture, vTexCoord + offset), color );\n" - " color = max( texture2D( sTexture, vTexCoord - offset), color );\n" - " }\n" - " gl_FragColor = color;\n" - "}\n" -}; - const char* const SPREAD_UNIFORM_NAME( "uSpread" ); const char* const TEX_SCALE_UNIFORM_NAME( "uTexScale" ); @@ -90,7 +71,7 @@ void SpreadFilter::Enable() mActorForInput.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread ); mActorForInput.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 1.0f / mTargetSize.width, 0.0f ) ); - Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE ); + Renderer rendererForInput = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG ); SetRendererTexture( rendererForInput, mInputTexture ); mActorForInput.AddRenderer( rendererForInput ); @@ -106,7 +87,7 @@ void SpreadFilter::Enable() // register properties as shader uniforms mActorForHorz.RegisterProperty( SPREAD_UNIFORM_NAME, mSpread ); mActorForHorz.RegisterProperty( TEX_SCALE_UNIFORM_NAME, Vector2( 0.0f, 1.0f / mTargetSize.height ) ); - Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SPREAD_FRAGMENT_SOURCE ); + Renderer rendererForHorz = CreateRenderer( BASIC_VERTEX_SOURCE, SHADER_SPREAD_FILTER_SHADER_FRAG ); SetRendererTexture( rendererForHorz, textureForHorz ); mActorForHorz.AddRenderer( rendererForHorz ); diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag index d68e66f..4654ab4 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.frag @@ -7,7 +7,19 @@ uniform lowp vec3 mixColor; void main() { - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius; OUT_COLOR = vec4(mixColor, 1.0) * uColor; - OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist ); -} \ No newline at end of file + mediump vec2 diff = abs( vPosition ) - vRectSize; + mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius; + if( dist > 1.0 ) + { + OUT_COLOR.a = 0.0; + } + else if( dist > -1.0 ) + { + if( min( diff.x, diff.y ) < 0.0) + { + dist += min( diff.x, diff.y ) / vCornerRadius; + } + OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist ); + } +} diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert index f4bc1ad..33216e5 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/color-visual-rounded-corner-shader.vert @@ -24,6 +24,7 @@ vec4 ComputeVertexPosition() vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min( vCornerRadius, minSize * 0.5 ); vRectSize = visualSize / 2.0 - vCornerRadius; + vCornerRadius = max( vCornerRadius, 1.0 ); vPosition = aPosition* visualSize; return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 ); } @@ -31,4 +32,4 @@ vec4 ComputeVertexPosition() void main() { gl_Position = uMvpMatrix * ComputeVertexPosition(); -} \ No newline at end of file +} diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert index 79724e7..144fa81 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-bounding-box-rounded-corner-shader.vert @@ -24,6 +24,7 @@ vec4 ComputeVertexPosition() vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min( vCornerRadius, minSize * 0.5 ); vRectSize = visualSize * 0.5 - vCornerRadius; + vCornerRadius = max( vCornerRadius, 1.0 ); vPosition = aPosition * visualSize; return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 ); } diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag index 61984eb..548367c 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-linear-rounded-corner-shader.frag @@ -8,7 +8,19 @@ varying mediump float vCornerRadius; void main() { - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius; gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor; - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist ); + mediump vec2 diff = abs( vPosition ) - vRectSize; + mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius; + if( dist > 1.0 ) + { + gl_FragColor = vec4( 0.0 ); + } + else if( dist > -1.0 ) + { + if( min( diff.x, diff.y ) < 0.0 ) + { + dist += min( diff.x, diff.y ) / vCornerRadius; + } + gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist ); + } } diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag index 0ae8163..10bf0fe 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-radial-rounded-corner-shader.frag @@ -8,7 +8,19 @@ varying mediump float vCornerRadius; void main() { - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius; gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor; - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist ); + mediump vec2 diff = abs( vPosition ) - vRectSize; + mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius; + if( dist > 1.0 ) + { + gl_FragColor = vec4( 0.0 ); + } + else if( dist > -1.0 ) + { + if( min( diff.x, diff.y ) < 0.0) + { + dist += min( diff.x, diff.y ) / vCornerRadius; + } + gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist ); + } } diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert index 38f05fb..f383185 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-user-space-rounded-corner-shader.vert @@ -24,6 +24,7 @@ vec4 ComputeVertexPosition() vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min( vCornerRadius, minSize * 0.5 ); vRectSize = visualSize * 0.5 - vCornerRadius; + vCornerRadius = max( vCornerRadius, 1.0 ); vPosition = aPosition * visualSize; return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 ); } diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag index 1e3a1a7..0e2c1d8 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.frag @@ -10,10 +10,23 @@ uniform lowp float preMultipliedAlpha; void main() { - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius; - mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist ); + mediump vec2 diff = abs( vPosition ) - vRectSize; + mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius; + mediump float opacity = 1.0; + if( dist > 1.0 ) + { + opacity = 0.0; + } + else if( dist > -1.0 ) + { + if( min( diff.x, diff.y ) < 0.0 ) + { + dist += min( diff.x, diff.y ) / vCornerRadius; + } + opacity = 1.0 - smoothstep( -1.0, 1.0, dist ); + } OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 ); OUT_COLOR.a *= opacity; OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha ); -} \ No newline at end of file +} diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert index d4b129e..0bd3530 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/image-visual-rounded-corner-shader.vert @@ -26,6 +26,7 @@ vec4 ComputeVertexPosition() vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min( vCornerRadius, minSize * 0.5 ); vRectSize = visualSize * 0.5 - vCornerRadius; + vCornerRadius = max( vCornerRadius, 1.0 ); vPosition = aPosition* visualSize; return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 ); } @@ -34,4 +35,4 @@ void main() { gl_Position = uMvpMatrix * ComputeVertexPosition(); vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) ); -} \ No newline at end of file +} diff --git a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag index 610b774..678a852 100644 --- a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.frag @@ -1,7 +1,9 @@ +//Very simple fragment shader that merely applies the vertex shading to the color at each fragment. + precision mediump float; -varying mediump vec3vIllumination; -uniform lowpvec4uColor; -uniform lowpvec3mixColor; +varying mediump vec3 vIllumination; +uniform lowp vec4 uColor; +uniform lowp vec3 mixColor; void main() { diff --git a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert index 6605bc6..6a1b758 100644 --- a/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/primitive-visual-shader.vert @@ -1,3 +1,5 @@ +//A simple shader that applies diffuse lighting to a mono-coloured object. + attribute highp vec3 aPosition; attribute highp vec2 aTexCoord; attribute highp vec3 aNormal; diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index 7016759..648c17a 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -34,37 +34,13 @@ #include #include #include +#include #ifdef DEBUG_ENABLED #define DECORATOR_DEBUG #endif -#define MAKE_SHADER(A)#A - -namespace -{ -const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -uniform highp mat4 uMvpMatrix; - -void main() -{ - mediump vec4 position = vec4( aPosition, 0.0, 1.0 ); - gl_Position = uMvpMatrix * position; -} -); - -const char* FRAGMENT_SHADER = MAKE_SHADER( -uniform lowp vec4 uColor; - -void main() -{ - gl_FragColor = uColor; -} -); -} - namespace Dali { namespace Internal @@ -270,7 +246,7 @@ struct Decorator::Impl : public ConnectionTracker mHidePrimaryCursorAndGrabHandle( false ) { mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2; - mHighlightShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mHighlightShader = Shader::New( SHADER_TEXT_DECORATOR_SHADER_VERT, SHADER_TEXT_DECORATOR_SHADER_FRAG ); SetupGestures(); } diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index 4fc28f8..80a1111 100755 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; @@ -42,52 +43,6 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_RENDERING"); #endif -#define MAKE_SHADER(A)#A - -const char* VERTEX_SHADER = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute mediump vec2 aTexCoord; -attribute mediump vec4 aColor; -uniform mediump vec2 uOffset; -uniform highp mat4 uMvpMatrix; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 ); - gl_Position = uMvpMatrix * position; - vTexCoord = aTexCoord; - vColor = aColor; -} -); - -const char* FRAGMENT_SHADER_L8 = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform lowp vec4 textColorAnimatable; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; -varying mediump vec4 vColor; - -void main() -{ - mediump vec4 color = texture2D( sTexture, vTexCoord ); - gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, uColor.a * vColor.a * textColorAnimatable.a * color.r ); -} -); - -const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER( -uniform lowp vec4 uColor; -uniform lowp vec4 textColorAnimatable; -uniform sampler2D sTexture; -varying mediump vec2 vTexCoord; - -void main() -{ - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable; -} -); - const float ZERO( 0.0f ); const float HALF( 0.5f ); const float ONE( 1.0f ); @@ -696,7 +651,7 @@ struct AtlasRenderer::Impl // The glyph is an emoji and is not a shadow. if( !mShaderRgba ) { - mShaderRgba = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_RGBA ); + mShaderRgba = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_RGBA_SHADER_FRAG ); } shader = mShaderRgba; } @@ -705,7 +660,7 @@ struct AtlasRenderer::Impl // The glyph is text or a shadow. if( !mShaderL8 ) { - mShaderL8 = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_L8 ); + mShaderL8 = Shader::New( SHADER_TEXT_ATLAS_SHADER_VERT, SHADER_TEXT_ATLAS_L8_SHADER_FRAG ); } shader = mShaderL8; } diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 6554a2c..da5e2e7 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace Dali; @@ -45,32 +46,6 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS"); #endif -#define MAKE_SHADER(A)#A - -const char* VERTEX_SHADER_BACKGROUND = MAKE_SHADER( -attribute mediump vec2 aPosition; -attribute mediump vec4 aColor; -varying mediump vec4 vColor; -uniform highp mat4 uMvpMatrix; - -void main() -{ - mediump vec4 position = vec4( aPosition, 0.0, 1.0 ); - gl_Position = uMvpMatrix * position; - vColor = aColor; -} -); - -const char* FRAGMENT_SHADER_BACKGROUND = MAKE_SHADER( -varying mediump vec4 vColor; -uniform lowp vec4 uColor; - -void main() -{ - gl_FragColor = vColor * uColor; -} -); - struct BackgroundVertex { Vector2 mPosition; ///< Vertex posiiton @@ -2108,7 +2083,7 @@ Actor Controller::Impl::CreateBackgroundActor() if( !mShaderBackground ) { - mShaderBackground = Shader::New( VERTEX_SHADER_BACKGROUND, FRAGMENT_SHADER_BACKGROUND ); + mShaderBackground = Shader::New( SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_VERT, SHADER_TEXT_CONTROLLER_BACKGROUND_SHADER_FRAG ); } Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, mShaderBackground ); diff --git a/dali-toolkit/internal/text/text-scroller.cpp b/dali-toolkit/internal/text/text-scroller.cpp index b2c1b19..d908d33 100755 --- a/dali-toolkit/internal/text/text-scroller.cpp +++ b/dali-toolkit/internal/text/text-scroller.cpp @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -39,56 +40,6 @@ namespace const int MINIMUM_SCROLL_SPEED = 1; // Speed should be set by Property system. -const char* VERTEX_SHADER_SCROLL = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying highp vec2 vTexCoord;\n - uniform highp vec3 uSize;\n - uniform mediump float uDelta;\n - uniform mediump vec2 uTextureSize;\n - uniform mediump float uGap;\n - uniform mediump float uHorizontalAlign;\n - uniform mediump float uVerticalAlign;\n - \n - uniform highp mat4 uMvpMatrix;\n - \n - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - void main()\n - {\n - mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );\n - mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );\n - \n - vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;\n - vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;\n - \n - mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );\n - \n - gl_Position = uMvpMatrix * vertexPosition;\n - }\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - varying highp vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - if ( vTexCoord.y > 1.0 )\n - discard;\n - \n - mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n - \n - gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 ); - }\n -); - /** * @brief How the text should be aligned horizontally when scrolling the text. * @@ -281,7 +232,7 @@ void TextScroller::SetParameters( Actor scrollingTextActor, Renderer renderer, T mTextureSet = mRenderer.GetTextures(); // Set the shader and texture for scrolling - Shader shader = Shader::New( VERTEX_SHADER_SCROLL, FRAGMENT_SHADER, Shader::Hint::NONE ); + Shader shader = Shader::New( SHADER_TEXT_SCROLLER_SHADER_VERT, SHADER_TEXT_SCROLLER_SHADER_FRAG, Shader::Hint::NONE ); mRenderer.SetShader( shader ); mRenderer.SetTextures( textureSet ); diff --git a/dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp b/dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp index 05d1724..9b4bc8c 100755 --- a/dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-gradient/animated-gradient-visual.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace Dali { @@ -93,89 +94,6 @@ const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::DirectionType::T const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::Type DEFAULT_ANIMATION_MOTION_TYPE = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP; const Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::Type DEFAULT_ANIMATION_EASING_TYPE = Toolkit::DevelAnimatedGradientVisual::AnimationParameter::EasingType::LINEAR; -const char* const BASIC_VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition; - uniform highp mat4 uMvpMatrix; - uniform highp vec3 uSize; - - uniform mediump vec2 start_point; - uniform mediump vec2 end_point; - uniform mediump vec2 rotate_center; - uniform mediump float rotate_angle; - - varying mediump vec2 vTexCoord; - varying mediump vec2 vStart; - varying mediump vec2 vEnd; - - vec2 rotate(vec2 x, vec2 c, float a) - { - vec2 d = x - c; - vec2 r = vec2(d.x * cos(a) - d.y * sin(a), d.x * sin(a) + d.y * cos(a)); - -\n #ifdef UNIT_TYPE_BOUNDING_BOX \n return r + c; \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */ -\n #ifdef UNIT_TYPE_USER \n return (r + c) / uSize.x; \n #endif \n /* UnitType::USER_SPACE */ - } - - //Visual size and offset - uniform mediump vec2 offset; - uniform highp vec2 size; - uniform mediump vec4 offsetSizeMode; - uniform mediump vec2 origin; - uniform mediump vec2 anchorPoint; - - vec4 ComputeVertexPosition() - { - vec2 visualSize = mix( uSize.xy*size, size, offsetSizeMode.zw ); - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy ); - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 ); - } - - void main() - { - vStart = rotate( start_point, rotate_center, rotate_angle ); - vEnd = rotate( end_point, rotate_center, rotate_angle ); - gl_Position = uMvpMatrix * ComputeVertexPosition(); - -\n #ifdef UNIT_TYPE_BOUNDING_BOX \n vTexCoord = vec2(aPosition.x, -aPosition.y); \n #endif \n /* UnitType::OBJECT_BOUNDING_BOX */ -\n #ifdef UNIT_TYPE_USER \n vTexCoord = vec2(aPosition.x, -aPosition.y * uSize.y / uSize.x); \n #endif \n /* UnitType::USER_SPACE */ - } -); - -const char* const BASIC_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - precision mediump float; - - uniform mediump vec4 start_color; - uniform mediump vec4 end_color; - uniform mediump float gradient_offset; - - varying mediump vec2 vTexCoord; - varying mediump vec2 vStart; - varying mediump vec2 vEnd; - - float get_position(vec2 x, vec2 s, vec2 e) - { - vec2 df = e - s; - vec2 dx = x - s; - -\n #ifdef GRADIENT_TYPE_LINEAR \n return dot(dx,df)/dot(df,df); \n #endif \n /* GradientType::LINEAR */ -\n #ifdef GRADIENT_TYPE_RADIAL \n return sqrt(dot(dx,dx)/dot(df,df)); \n #endif \n /* GradientType::RADIAL */ - } - float recalculate(float r) - { -\n #ifdef SPREAD_TYPE_REFLECT \n return 1.0 - abs(mod(r, 2.0) - 1.0); \n #endif \n /* SpreadType::REFLECT */ -\n #ifdef SPREAD_TYPE_REPEAT \n return fract(r); \n #endif \n /* SpreadType::REPEAT */ -\n #ifdef SPREAD_TYPE_CLAMP \n return clamp(r, 0.0, 1.0); \n #endif \n /* SpreadType::CLAMP */ - } - - void main() - { - float r = get_position( vTexCoord, vStart, vEnd ); - r = recalculate( r + gradient_offset ); - vec4 color = mix( start_color, end_color, r ); - gl_FragColor = color; - } -); - Property::Value GetStartValue( const Property::Map& map, Property::Index index, const char* const name ) { // Get start value of animation parameter @@ -737,10 +655,10 @@ Shader AnimatedGradientVisual::CreateShader() std::string frag; vert = "#define " + tagUnit + "\n" - + BASIC_VERTEX_SHADER; + + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_VERT.data(); frag = "#define " + tagGrad + "\n" + "#define " + tagSpread + "\n" - + BASIC_FRAGMENT_SHADER; + + SHADER_ANIMATED_GRADIENT_VISUAL_SHADER_FRAG.data(); shader = Shader::New( vert, frag ); return shader; diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index a2d102a..db97880 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -293,7 +293,7 @@ void AnimatedVectorImageVisual::DoSetOnScene( Actor& actor ) } else { - shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, false ); + shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, IsRoundedCornerRequired() ); } Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY ); diff --git a/dali-toolkit/internal/visuals/arc/arc-visual.cpp b/dali-toolkit/internal/visuals/arc/arc-visual.cpp index d694235..be58a9f 100644 --- a/dali-toolkit/internal/visuals/arc/arc-visual.cpp +++ b/dali-toolkit/internal/visuals/arc/arc-visual.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace Dali { @@ -47,104 +48,6 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, BUTT ) DALI_ENUM_TO_STRING_WITH_SCOPE( DevelArcVisual::Cap, ROUND ) DALI_ENUM_TO_STRING_TABLE_END( CAP ) -const char* VERTEX_SHADER = - "INPUT mediump vec2 aPosition;\n" - "OUTPUT mediump vec2 vPosition;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " vPosition = aPosition* visualSize;\n" - " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - "}\n"; - -const char* FRAGMENT_SHADER_BUTT_CAP = - "INPUT mediump vec2 vPosition;\n" - - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform mediump float thickness;\n" - "uniform mediump float radius;\n" - "uniform mediump float startAngle;\n" - "uniform mediump float sweepAngle;\n" - - "const mediump float M_PI_OVER_2 = 1.57079632679;\n" - "const mediump float M_PI = 3.14159265359;\n" - "const mediump float M_PI_2 = 6.28318530718;\n" - - "mediump float GetOpacity()\n" - "{\n" - " mediump float start = radians( mod( startAngle, 360.0 ) );\n" - " mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n" - " mediump float dist = length( vPosition );\n" - " if( angle <= radians( sweepAngle ) )\n" - " {\n" - " return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n" - " }\n" - " mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n" - " mediump vec2 q0 = vec2( dist * cos( start - M_PI_OVER_2 ), dist * sin( start - M_PI_OVER_2 ) );\n" - " mediump vec2 q1 = vec2( dist * cos( end - M_PI_OVER_2 ), dist * sin( end - M_PI_OVER_2 ) );\n" - " mediump float opacity = 1.0 - smoothstep( 0.0, 2.0, min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n" - " opacity *= step( 0.0, thickness / 2.0 - abs( dist - radius ) );\n" - " return opacity;\n" - "}\n" - - "void main()\n" - "{\n" - " OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n" - " OUT_COLOR.a *= GetOpacity();\n" - "}\n"; - -const char* FRAGMENT_SHADER_ROUND_CAP = - "INPUT mediump vec2 vPosition;\n" - - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform mediump float thickness;\n" - "uniform mediump float radius;\n" - "uniform mediump float startAngle;\n" - "uniform mediump float sweepAngle;\n" - - "const mediump float M_PI_OVER_2 = 1.57079632679;\n" - "const mediump float M_PI_2 = 6.28318530718;\n" - - "mediump float GetOpacity()\n" - "{\n" - " mediump float start = radians( mod( startAngle, 360.0 ) );\n" - " mediump float angle = mod( atan( vPosition.y, vPosition.x ) + M_PI_OVER_2 - start, M_PI_2 );\n" - " mediump float dist = length( vPosition );\n" - " if( angle <= radians( sweepAngle ) )\n" - " {\n" - " return smoothstep( -1.0, 1.0, thickness / 2.0 - ( abs( dist - radius ) ) );\n" - " }\n" - " mediump float end = radians( mod( startAngle + sweepAngle, 360.0 ) );\n" - " mediump vec2 q0 = vec2( radius * cos( start - M_PI_OVER_2 ), radius * sin( start - M_PI_OVER_2 ) );\n" - " mediump vec2 q1 = vec2( radius * cos( end - M_PI_OVER_2 ), radius * sin( end - M_PI_OVER_2 ) );\n" - " return smoothstep( -1.0, 1.0, thickness / 2.0 - min( length( vPosition - q0 ), length( vPosition - q1 ) ) );\n" - "}\n" - - "void main()\n" - "{\n" - " OUT_COLOR = vec4( mixColor, 1.0 ) * uColor;\n" - " OUT_COLOR.a *= GetOpacity();\n" - "}\n"; - } ArcVisualPtr ArcVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -330,7 +233,7 @@ void ArcVisual::InitializeRenderer() shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BUTT_CAP ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_BUTT_CAP_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::ARC_BUTT_CAP_SHADER, shader ); } } @@ -339,7 +242,7 @@ void ArcVisual::InitializeRenderer() shader = mFactoryCache.GetShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUND_CAP ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_ARC_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_ARC_VISUAL_ROUND_CAP_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::ARC_ROUND_CAP_SHADER, shader ); } } diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index 452fda9..f62afc3 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-visual.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace Dali { @@ -44,74 +45,6 @@ namespace const char * const POSITION_ATTRIBUTE_NAME("aPosition"); const char * const DRIFT_ATTRIBUTE_NAME("aDrift"); const char * const INDEX_NAME("indices"); - -const char* VERTEX_SHADER = - "INPUT mediump vec2 aPosition;\n" - "INPUT mediump vec2 aDrift;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - "uniform mediump float borderSize;\n" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - - "vec2 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " return (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy;\n" - "}\n" - - "void main()\n" - "{\n" - " vec2 position = ComputeVertexPosition() + aDrift*borderSize;\n" - " gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n" - "}\n"; - -const char* FRAGMENT_SHADER = - "uniform lowp vec4 uColor;\n" - "uniform lowp vec4 borderColor;\n" - "uniform lowp vec3 mixColor;\n" - - "void main()\n" - "{\n" - " OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n" - "}\n"; - -const char* VERTEX_SHADER_ANTI_ALIASING = - "INPUT mediump vec2 aPosition;\n" - "INPUT mediump vec2 aDrift;\n" - "OUTPUT mediump float vAlpha;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - "uniform mediump float borderSize;\n" - - "void main()\n" - "{\n" - " vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);\n" - " gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n" - " vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5);" - "}\n"; - -const char* FRAGMENT_SHADER_ANTI_ALIASING = - "INPUT mediump float vAlpha;\n" - - "uniform lowp vec4 uColor;\n" - "uniform lowp vec4 borderColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform mediump float borderSize;\n" - - "void main()\n" - "{\n" - " OUT_COLOR = vec4(mixColor, 1.0) * borderColor * uColor;\n" - " OUT_COLOR.a *= smoothstep(0.0, 1.5, vAlpha) * smoothstep( borderSize + 1.5, borderSize, vAlpha );\n" - "}\n"; } BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -257,7 +190,7 @@ Shader BorderVisual::GetBorderShader() shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ANTI_ALIASING, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ANTI_ALIASING ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_ANTI_ALIASING_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER_ANTI_ALIASING, shader ); } } @@ -266,7 +199,7 @@ Shader BorderVisual::GetBorderShader() shader = mFactoryCache.GetShader( VisualFactoryCache::BORDER_SHADER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_BORDER_VISUAL_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::BORDER_SHADER, shader ); } } diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 68dc04a..492f203 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace Dali { @@ -41,145 +42,6 @@ namespace Toolkit namespace Internal { -namespace -{ - -const char* VERTEX_SHADER = - "INPUT mediump vec2 aPosition;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - "uniform mediump vec2 extraSize;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - "}\n"; - - -const char* FRAGMENT_SHADER = - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - - "void main()\n" - "{\n" - " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n" - "}\n"; - -const char* VERTEX_SHADER_ROUNDED_CORNER = - "INPUT mediump vec2 aPosition;\n" - "OUTPUT mediump vec2 vPosition;\n" - "OUTPUT mediump vec2 vRectSize;\n" - "OUTPUT mediump float vCornerRadius;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec2 extraSize;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - "uniform mediump float cornerRadius;\n" - "uniform mediump float cornerRadiusPolicy;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " mediump float minSize = min( visualSize.x, visualSize.y );\n" - " vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n" - " vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n" - " vRectSize = visualSize / 2.0 - vCornerRadius;\n" - " vPosition = aPosition* visualSize;\n" - " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - "}\n"; - -//float distance = length( max( abs( position - center ), size ) - size ) - radius; -const char* FRAGMENT_SHADER_ROUNDED_CORNER = - "INPUT mediump vec2 vPosition;\n" - "INPUT mediump vec2 vRectSize;\n" - "INPUT mediump float vCornerRadius;\n" - - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - - "void main()\n" - "{\n" - " mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n" - " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n" - " OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );\n" - "}\n"; - -const char* VERTEX_SHADER_BLUR_EDGE = - "INPUT mediump vec2 aPosition;\n" - "OUTPUT mediump vec2 vPosition;\n" - "OUTPUT mediump vec2 vRectSize;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec2 extraSize;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - "uniform mediump float blurRadius;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize + blurRadius * 2.0;\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " vRectSize = visualSize / 2.0;\n" - " vPosition = aPosition* visualSize;\n" - " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - "}\n"; - -const char* FRAGMENT_SHADER_BLUR_EDGE = - "INPUT mediump vec2 vPosition;\n" - "INPUT mediump vec2 vRectSize;\n" - - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform mediump float blurRadius;\n" - - "void main()\n" - "{\n" - " mediump vec2 blur = 1.0 - smoothstep( vRectSize - blurRadius * 2.0, vRectSize, abs( vPosition ) );\n" - " OUT_COLOR = vec4(mixColor, 1.0) * uColor;\n" - " OUT_COLOR.a *= blur.x * blur.y;\n" - "}\n"; - -} - ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) { ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) ); @@ -363,7 +225,7 @@ Shader ColorVisual::GetShader() shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_BLUR_EDGE, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_BLUR_EDGE ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_BLUR_EDGE_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_BLUR_EDGE, shader ); } } @@ -372,7 +234,7 @@ Shader ColorVisual::GetShader() shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER, shader ); } } @@ -381,7 +243,7 @@ Shader ColorVisual::GetShader() shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(), Dali::Shader::GetFragmentShaderPrefix() + SHADER_COLOR_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() ); mFactoryCache.SaveShader( VisualFactoryCache::COLOR_SHADER_ROUNDED_CORNER, shader ); } } diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index b86f9a7..504b0e0 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -36,6 +36,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include namespace Dali { @@ -83,220 +91,34 @@ VisualFactoryCache::ShaderType SHADER_TYPE_TABLE[][4] = } }; -const char* VERTEX_SHADER[] = +const std::string_view VERTEX_SHADER[] = { -// vertex shader for gradient units as OBJECT_BOUNDING_BOX -DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump mat3 uAlignmentMatrix;\n - varying mediump vec2 vTexCoord;\n - \n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n - vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n - \n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - }\n -), - -// vertex shader for gradient units as USER_SPACE -DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump mat3 uAlignmentMatrix;\n - varying mediump vec2 vTexCoord;\n - \n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n - vertexPosition.xyz *= uSize;\n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - \n - vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n - }\n -), - -// vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius -DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump mat3 uAlignmentMatrix;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vPosition;\n - varying mediump vec2 vRectSize;\n - varying mediump float vCornerRadius;\n - \n - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump float cornerRadius;\n - uniform mediump float cornerRadiusPolicy;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - mediump float minSize = min( visualSize.x, visualSize.y );\n - vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n - vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n - vRectSize = visualSize * 0.5 - vCornerRadius;\n - vPosition = aPosition * visualSize;\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n - vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n - \n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - }\n -), - -// vertex shader for gradient units as USER_SPACE with corner radius -DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump mat3 uAlignmentMatrix;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vPosition;\n - varying mediump vec2 vRectSize;\n - varying mediump float vCornerRadius;\n - \n - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump float cornerRadius;\n - uniform mediump float cornerRadiusPolicy;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - mediump float minSize = min( visualSize.x, visualSize.y );\n - vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n - vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n - vRectSize = visualSize * 0.5 - vCornerRadius;\n - vPosition = aPosition * visualSize;\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n - vertexPosition.xyz *= uSize;\n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - \n - vTexCoord = (uAlignmentMatrix*vertexPosition.xyw).xy;\n - }\n -) + // vertex shader for gradient units as OBJECT_BOUNDING_BOX + SHADER_GRADIENT_VISUAL_BOUNDING_BOX_SHADER_VERT, + + // vertex shader for gradient units as USER_SPACE + SHADER_GRADIENT_VISUAL_USER_SPACE_SHADER_VERT, + + // vertex shader for gradient units as OBJECT_BOUNDING_BOX with corner radius + SHADER_GRADIENT_VISUAL_BOUNDING_BOX_ROUNDED_CORNER_SHADER_VERT, + + // vertex shader for gradient units as USER_SPACE with corner radius + SHADER_GRADIENT_VISUAL_USER_SPACE_ROUNDED_CORNER_SHADER_VERT }; -const char* FRAGMENT_SHADER[] = +const std::string_view FRAGMENT_SHADER[] = { -// fragment shader for linear gradient -DALI_COMPOSE_SHADER( - uniform sampler2D sTexture;\n // sampler1D? - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - varying mediump vec2 vTexCoord;\n - \n - void main()\n - {\n - gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - }\n -), - -// fragment shader for radial gradient -DALI_COMPOSE_SHADER( - uniform sampler2D sTexture;\n // sampler1D? - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - varying mediump vec2 vTexCoord;\n - \n - void main()\n - {\n - gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - }\n -), - -// fragment shader for linear gradient with corner radius -DALI_COMPOSE_SHADER( - uniform sampler2D sTexture;\n // sampler1D? - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vPosition;\n - varying mediump vec2 vRectSize;\n - varying mediump float vCornerRadius;\n - \n - void main()\n - {\n - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n - gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n - }\n -), - -// fragment shader for radial gradient with corner radius -DALI_COMPOSE_SHADER( - uniform sampler2D sTexture;\n // sampler1D? - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vPosition;\n - varying mediump vec2 vRectSize;\n - varying mediump float vCornerRadius;\n - \n - void main()\n - {\n - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n - gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n - }\n -) + // fragment shader for linear gradient + SHADER_GRADIENT_VISUAL_LINEAR_SHADER_FRAG, + + // fragment shader for radial gradient + SHADER_GRADIENT_VISUAL_RADIAL_SHADER_FRAG, + + // fragment shader for linear gradient with corner radius + SHADER_GRADIENT_VISUAL_LINEAR_ROUNDED_CORNER_SHADER_FRAG, + + // fragment shader for radial gradient with corner radius + SHADER_GRADIENT_VISUAL_RADIAL_ROUNDED_CORNER_SHADER_FRAG }; Dali::WrapMode::Type GetWrapMode( Toolkit::GradientVisual::SpreadMethod::Type spread ) diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp index 5bc09ce..523c374 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include +#include #include namespace Dali @@ -37,155 +38,6 @@ namespace const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); -const char* VERTEX_SHADER = - "INPUT mediump vec2 aPosition;\n" - "OUTPUT mediump vec2 vTexCoord;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - "uniform mediump vec4 pixelArea;" - "//Visual size and offset\n" - - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - "uniform mediump vec2 extraSize;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - "\n" - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - " vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n" - "}\n"; - -const char* FRAGMENT_SHADER_NO_ATLAS = - "INPUT mediump vec2 vTexCoord;\n" - - "uniform sampler2D sTexture;\n" - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform lowp float preMultipliedAlpha;\n" - - "void main()\n" - "{\n" - " OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n" - "}\n"; - - -const char* FRAGMENT_SHADER_ATLAS_CLAMP = - "INPUT mediump vec2 vTexCoord;\n" - - "uniform sampler2D sTexture;\n" - "uniform mediump vec4 uAtlasRect;\n" - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform lowp float preMultipliedAlpha;\n" - - "void main()\n" - "{\n" - " mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw );\n" - " OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n" - "}\n"; - - -const char* FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP = - "INPUT mediump vec2 vTexCoord;\n" - - "uniform sampler2D sTexture;\n" - "uniform mediump vec4 uAtlasRect;\n" - "// WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT;" - "uniform lowp vec2 wrapMode;\n" - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform lowp float preMultipliedAlpha;\n" - "mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap )\n" - - "{\n" - " mediump float coord;\n" - " if( wrap > 1.5 )\n // REFLECT" - " coord = 1.0-abs(fract(coordinate*0.5)*2.0 - 1.0);\n" - " else \n// warp == 0 or 1" - " coord = mix(coordinate, fract( coordinate ), wrap);\n" - " return clamp( mix(range.x, range.y, coord), range.x, range.y );" - "}\n" - - "void main()\n" - "{\n" - " mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x )," - " wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) );\n" - " OUT_COLOR = TEXTURE( sTexture, texCoord ) * uColor * vec4( mixColor, 1.0 );\n" - "}\n"; - -const char* VERTEX_SHADER_ROUNDED_CORNER = - "INPUT mediump vec2 aPosition;\n" - "OUTPUT mediump vec2 vTexCoord;\n" - "OUTPUT mediump vec2 vPosition;\n" - "OUTPUT mediump vec2 vRectSize;\n" - "OUTPUT mediump float vCornerRadius;\n" - - "uniform highp mat4 uMvpMatrix;\n" - "uniform highp vec3 uSize;\n" - "uniform mediump vec4 pixelArea;" - - "//Visual size and offset\n" - "uniform mediump vec2 offset;\n" - "uniform highp vec2 size;\n" - "uniform mediump vec4 offsetSizeMode;\n" - "uniform mediump vec2 origin;\n" - "uniform mediump vec2 anchorPoint;\n" - "uniform mediump float cornerRadius;\n" - "uniform mediump float cornerRadiusPolicy;\n" - "uniform mediump vec2 extraSize;\n" - - "vec4 ComputeVertexPosition()\n" - "{\n" - " vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n" - " vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n" - " mediump float minSize = min( visualSize.x, visualSize.y );\n" - " vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);\n" - " vCornerRadius = min( vCornerRadius, minSize * 0.5 );\n" - " vRectSize = visualSize * 0.5 - vCornerRadius;\n" - " vPosition = aPosition* visualSize;\n" - " return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n" - "}\n" - - "void main()\n" - "{\n" - " gl_Position = uMvpMatrix * ComputeVertexPosition();\n" - " vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n" - "}\n"; - - -//float distance = length( max( abs( position - center ), size ) - size ) - radius; -const char* FRAGMENT_SHADER_ROUNDED_CORNER = - "INPUT mediump vec2 vTexCoord;\n" - "INPUT mediump vec2 vPosition;\n" - "INPUT mediump vec2 vRectSize;\n" - "INPUT mediump float vCornerRadius;\n" - - "uniform sampler2D sTexture;\n" - "uniform lowp vec4 uColor;\n" - "uniform lowp vec3 mixColor;\n" - "uniform lowp float preMultipliedAlpha;\n" - - "void main()\n" - "{\n" - " mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n" - " mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );\n" - - " OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n" - " OUT_COLOR.a *= opacity;\n" - " OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n" - "}\n"; - // global string variable to caching complate vertex shader static std::string gVertexShader; @@ -212,7 +64,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_CLAMP ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(), + Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_CLAMP_SHADER_FRAG.data() ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_DEFAULT_WRAP, shader ); } @@ -222,7 +75,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ATLAS_VARIOUS_WRAP ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(), + Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ATLAS_VARIOUS_WRAP_SHADER_FRAG.data() ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ATLAS_CUSTOM_WRAP, shader ); } @@ -235,7 +89,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER_ROUNDED_CORNER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_ROUNDED_CORNER ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_VERT.data(), + Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_ROUNDED_CORNER_SHADER_FRAG.data() ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER_ROUNDED_CORNER, shader ); } @@ -245,7 +100,8 @@ Shader ImageVisualShaderFactory::GetShader( VisualFactoryCache& factoryCache, bo shader = factoryCache.GetShader( VisualFactoryCache::IMAGE_SHADER ); if( !shader ) { - shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER, Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS ); + shader = Shader::New( Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(), + Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data() ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::IMAGE_SHADER, shader ); } @@ -259,7 +115,7 @@ std::string_view ImageVisualShaderFactory::GetVertexShaderSource() { if(gVertexShader.empty()) { - gVertexShader = Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER; + gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data(); } return gVertexShader; @@ -269,7 +125,7 @@ std::string_view ImageVisualShaderFactory::GetFragmentShaderSource() { if(gFragmentShaderNoAtlas.empty()) { - gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + FRAGMENT_SHADER_NO_ATLAS; + gFragmentShaderNoAtlas = Dali::Shader::GetFragmentShaderPrefix() + SHADER_IMAGE_VISUAL_NO_ATLAS_SHADER_FRAG.data(); } return gFragmentShaderNoAtlas; } diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp index 4d6a4cd..f34f66c 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace Dali { @@ -94,253 +95,6 @@ DALI_ENUM_TO_STRING_TABLE_END( SHADING_MODE ) const char * const OBJECT_MATRIX_UNIFORM_NAME( "uObjectMatrix" ); const char * const STAGE_OFFSET_UNIFORM_NAME( "uStageOffset" ); -//Shaders -//If a shader requires certain textures, they must be listed in order, -//as detailed in the TextureIndex enum documentation. - -//A basic shader that doesn't use textures at all. -const char* SIMPLE_VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute highp vec3 aPosition;\n - attribute highp vec3 aNormal;\n - varying mediump vec3 vIllumination;\n - uniform mediump vec3 uSize;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump mat4 uModelView;\n - uniform mediump mat4 uViewMatrix;\n - uniform mediump mat3 uNormalMatrix; - uniform mediump mat4 uObjectMatrix;\n - uniform mediump vec3 lightPosition;\n - uniform mediump vec2 uStageOffset;\n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - float scaleFactor = min( visualSize.x, visualSize.y );\n - vec3 originFlipY = vec3(origin.x, -origin.y, 0.0); - vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0); - vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n - return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n - }\n - - void main()\n - {\n - vec4 normalisedVertexPosition = ComputeVertexPosition();\n - vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - - //Illumination in Model-View space - Transform attributes and uniforms\n - vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n - vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n - - vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n - mvLightPosition = uViewMatrix * mvLightPosition;\n - vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n - - float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n - vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n - - gl_Position = vertexPosition;\n - }\n -); - -//Fragment shader corresponding to the texture-less shader. -const char* SIMPLE_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - precision mediump float;\n - varying mediump vec3 vIllumination;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - - void main()\n - {\n - gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a ) * vec4( mixColor, 1.0 );\n - }\n -); - -//Diffuse and specular illumination shader with albedo texture. Texture is index 0. -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute highp vec3 aPosition;\n - attribute highp vec2 aTexCoord;\n - attribute highp vec3 aNormal;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec3 vIllumination;\n - varying mediump float vSpecular;\n - uniform mediump vec3 uSize;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump mat4 uModelView; - uniform mediump mat4 uViewMatrix;\n - uniform mediump mat3 uNormalMatrix; - uniform mediump mat4 uObjectMatrix;\n - uniform mediump vec3 lightPosition;\n - uniform mediump vec2 uStageOffset;\n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - float scaleFactor = min( visualSize.x, visualSize.y );\n - vec3 originFlipY = vec3(origin.x, -origin.y, 0.0); - vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0); - vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n - return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n - }\n - - void main() - {\n - vec4 normalisedVertexPosition = ComputeVertexPosition();\n - vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - - //Illumination in Model-View space - Transform attributes and uniforms\n - vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n - vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );\n - - vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n - mvLightPosition = uViewMatrix * mvLightPosition;\n - vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n - - vec3 viewDirection = normalize( -mvVertexPosition.xyz ); - - float lightDiffuse = dot( vectorToLight, normal );\n - lightDiffuse = max( 0.0,lightDiffuse );\n - vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n - - vec3 reflectDirection = reflect( -vectorToLight, normal ); - vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 ); - - vTexCoord = aTexCoord;\n - gl_Position = vertexPosition;\n - }\n -); - -//Fragment shader corresponding to the diffuse and specular illumination shader with albedo texture -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - precision mediump float;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec3 vIllumination;\n - varying mediump float vSpecular;\n - uniform sampler2D sDiffuse;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - - void main()\n - {\n - vec4 texture = texture2D( sDiffuse, vTexCoord );\n - vec4 visualMixColor = vec4( mixColor, 1.0 );\n - gl_FragColor = vec4( vIllumination.rgb * texture.rgb * uColor.rgb * visualMixColor.rgb + vSpecular * 0.3, texture.a * uColor.a * visualMixColor.a );\n - }\n -); - -//Diffuse and specular illumination shader with albedo texture, normal map and gloss map shader. -//Diffuse (albedo) texture is index 0, normal is 1, gloss is 2. They must be declared in this order. -const char* NORMAL_MAP_VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute highp vec3 aPosition;\n - attribute highp vec2 aTexCoord;\n - attribute highp vec3 aNormal;\n - attribute highp vec3 aTangent;\n - attribute highp vec3 aBiNormal;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec3 vLightDirection;\n - varying mediump vec3 vHalfVector;\n - uniform mediump vec3 uSize;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump mat4 uModelView; - uniform mediump mat4 uViewMatrix;\n - uniform mediump mat3 uNormalMatrix; - uniform mediump mat4 uObjectMatrix;\n - uniform mediump vec3 lightPosition;\n - uniform mediump vec2 uStageOffset;\n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - float scaleFactor = min( visualSize.x, visualSize.y );\n - vec3 originFlipY = vec3(origin.x, -origin.y, 0.0); - vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0); - vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n - return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n - }\n - - void main() - {\n - vec4 normalisedVertexPosition = ComputeVertexPosition();\n - vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - - vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n - - vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent ); - vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal ); - vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal ); - - vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n - mvLightPosition = uViewMatrix * mvLightPosition;\n - vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n - vLightDirection.x = dot( vectorToLight, tangent ); - vLightDirection.y = dot( vectorToLight, binormal ); - vLightDirection.z = dot( vectorToLight, normal ); - - vec3 viewDirection = normalize( -mvVertexPosition.xyz ); - vec3 halfVector = normalize( viewDirection + vectorToLight ); - vHalfVector.x = dot( halfVector, tangent ); - vHalfVector.y = dot( halfVector, binormal ); - vHalfVector.z = dot( halfVector, normal ); - - vTexCoord = aTexCoord;\n - gl_Position = vertexPosition;\n - }\n -); - -//Fragment shader corresponding to the shader that uses all textures (diffuse, normal and gloss maps) -const char* NORMAL_MAP_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - precision mediump float;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec3 vLightDirection;\n - varying mediump vec3 vHalfVector;\n - uniform sampler2D sDiffuse;\n - uniform sampler2D sNormal;\n - uniform sampler2D sGloss;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - - void main()\n - {\n - vec4 texture = texture2D( sDiffuse, vTexCoord );\n - vec3 normal = normalize( texture2D( sNormal, vTexCoord ).xyz * 2.0 - 1.0 );\n - vec4 glossMap = texture2D( sGloss, vTexCoord );\n - vec4 visualMixColor = vec4( mixColor, 1.0 );\n - - float lightDiffuse = max( 0.0, dot( normal, normalize( vLightDirection ) ) );\n - lightDiffuse = lightDiffuse * 0.5 + 0.5;\n - - float shininess = pow ( max ( dot ( normalize( vHalfVector ), normal ), 0.0 ), 16.0 ) ; - - gl_FragColor = vec4( texture.rgb * uColor.rgb * visualMixColor.rgb * lightDiffuse + shininess * glossMap.rgb, texture.a * uColor.a * visualMixColor.a );\n - }\n -); - } // unnamed namespace MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -564,7 +318,7 @@ void MeshVisual::InitializeRenderer() void MeshVisual::SupplyEmptyGeometry() { mGeometry = Geometry::New(); - mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER ); + mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG ); mImpl->mRenderer = Renderer::New( mGeometry, mShader ); DALI_LOG_ERROR( "Initialisation error in mesh visual.\n" ); @@ -588,15 +342,15 @@ void MeshVisual::CreateShader() { if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING ) { - mShader = Shader::New( NORMAL_MAP_VERTEX_SHADER, NORMAL_MAP_FRAGMENT_SHADER ); + mShader = Shader::New( SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_VERT, SHADER_MESH_VISUAL_NORMAL_MAP_SHADER_FRAG ); } else if( mShadingMode == Toolkit::MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING ) { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New( SHADER_MESH_VISUAL_SHADER_VERT, SHADER_MESH_VISUAL_SHADER_FRAG ); } else //Textureless { - mShader = Shader::New( SIMPLE_VERTEX_SHADER, SIMPLE_FRAGMENT_SHADER ); + mShader = Shader::New( SHADER_MESH_VISUAL_SIMPLE_SHADER_VERT, SHADER_MESH_VISUAL_SIMPLE_SHADER_FRAG ); } UpdateShaderUniforms(); diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 6dcf020..8bbdb09 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Dali { @@ -45,128 +46,6 @@ namespace Internal namespace { -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n - uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n - \n - - // Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump vec2 extraSize;\n - - void main()\n - {\n - mediump vec2 fixedFactor = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n - mediump vec2 stretch = vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );\n - \n - mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n - mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n - \n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - \n - mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );\n - mediump vec4 vertexPosition = gridPosition;\n - vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );\n - vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - \n - vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n - vMaskTexCoord = gridPosition.xy / visualSize;\n - \n - gl_Position = vertexPosition;\n - }\n -); - -const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump vec2 uFixed[ 3 ];\n - uniform mediump vec2 uStretchTotal;\n - \n - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - uniform mediump vec2 extraSize;\n - \n - void main()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - \n - mediump vec2 size = visualSize.xy;\n - \n - mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );\n - mediump vec2 stretch = floor( aPosition * 0.5 );\n - mediump vec2 fixedTotal = uFixed[ 2 ];\n - \n - mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n - mediump vec4 vertexPosition = gridPosition;\n - vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n - vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;\n - \n - vertexPosition = uMvpMatrix * vertexPosition;\n - \n - vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n - \n - vMaskTexCoord = gridPosition.xy / size;\n - gl_Position = vertexPosition;\n - }\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - \n - void main()\n - {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n - }\n -); - -const char* FRAGMENT_MASK_SHADER = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - varying mediump vec2 vMaskTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sMask;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - uniform lowp float preMultipliedAlpha;\n - uniform mediump float auxiliaryImageAlpha;\n - \n - void main()\n - {\n - // Where mask image is transparent, all of background image must show through. - // where mask image is opaque, only mask should be shown - // where mask is translucent, less of background should be shown. - // auxiliaryImageAlpha controls how much of mask is visible - - mediump vec4 color = texture2D( sTexture, vTexCoord );\n - mediump vec4 mask = texture2D( sMask, vMaskTexCoord );\n - - mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha) - + mask.rgb*mask.a * auxiliaryImageAlpha;\n - gl_FragColor = vec4(mixedColor,1.0) * uColor * vec4( mixColor, 1.0 );\n - }\n -); /** * @brief Creates the geometry formed from the vertices and indices @@ -562,8 +441,8 @@ Shader NPatchVisual::CreateShader() NPatchUtility::StretchRanges::SizeType xStretchCount = 0; NPatchUtility::StretchRanges::SizeType yStretchCount = 0; - auto fragmentShader = mAuxiliaryPixelBuffer ? FRAGMENT_MASK_SHADER - : FRAGMENT_SHADER; + auto fragmentShader = mAuxiliaryPixelBuffer ? SHADER_NPATCH_VISUAL_MASK_SHADER_FRAG + : SHADER_NPATCH_VISUAL_SHADER_FRAG; auto shaderType = mAuxiliaryPixelBuffer ? VisualFactoryCache::NINE_PATCH_MASK_SHADER : VisualFactoryCache::NINE_PATCH_SHADER; @@ -582,7 +461,7 @@ Shader NPatchVisual::CreateShader() shader = mFactoryCache.GetShader( shaderType ); if( DALI_UNLIKELY( !shader ) ) { - shader = Shader::New( VERTEX_SHADER_3X3, fragmentShader ); + shader = Shader::New( SHADER_NPATCH_VISUAL_3X3_SHADER_VERT, fragmentShader ); // Only cache vanilla 9 patch shaders mFactoryCache.SaveShader( shaderType, shader ); } @@ -592,7 +471,7 @@ Shader NPatchVisual::CreateShader() std::stringstream vertexShader; vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n" << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n" - << VERTEX_SHADER; + << SHADER_NPATCH_VISUAL_SHADER_VERT; shader = Shader::New( vertexShader.str(), fragmentShader ); } @@ -611,7 +490,7 @@ Shader NPatchVisual::CreateShader() if( ( xStretchCount == 1 && yStretchCount == 1 ) || ( xStretchCount == 0 && yStretchCount == 0 ) ) { - const char* vertexShader = VERTEX_SHADER_3X3; + const char* vertexShader = SHADER_NPATCH_VISUAL_3X3_SHADER_VERT.data(); if( !mImpl->mCustomShader->mVertexShader.empty() ) { @@ -624,7 +503,7 @@ Shader NPatchVisual::CreateShader() std::stringstream vertexShader; vertexShader << "#define FACTOR_SIZE_X " << xStretchCount + 2 << "\n" << "#define FACTOR_SIZE_Y " << yStretchCount + 2 << "\n" - << VERTEX_SHADER; + << SHADER_NPATCH_VISUAL_SHADER_VERT; shader = Shader::New( vertexShader.str(), fragmentShader, hints ); } diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp index 21c9064..7ad7bf5 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace Dali { @@ -92,74 +93,6 @@ const char * const POSITION( "aPosition"); const char * const NORMAL( "aNormal" ); const char * const INDICES( "aIndices" ); -//A simple shader that applies diffuse lighting to a mono-coloured object. -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute highp vec3 aPosition;\n - attribute highp vec2 aTexCoord;\n - attribute highp vec3 aNormal;\n - varying mediump vec3 vIllumination;\n - uniform mediump vec3 uSize;\n - uniform mediump vec3 uObjectDimensions;\n - uniform mediump mat4 uMvpMatrix;\n - uniform mediump mat4 uModelView;\n - uniform mediump mat4 uViewMatrix;\n - uniform mediump mat3 uNormalMatrix;\n - uniform mediump mat4 uObjectMatrix;\n - uniform mediump vec3 lightPosition;\n - uniform mediump vec2 uStageOffset;\n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform mediump vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - float scaleFactor = min( visualSize.x / uObjectDimensions.x, visualSize.y / uObjectDimensions.y );\n - vec3 originFlipY = vec3(origin.x, -origin.y, 0.0); - vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0); - vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);\n - - return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );\n - }\n - - void main()\n - {\n - vec4 normalisedVertexPosition = ComputeVertexPosition();\n - vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n - vertexPosition = uMvpMatrix * vertexPosition;\n - - //Illumination in Model-View space - Transform attributes and uniforms\n - vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n - vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n - - vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n - mvLightPosition = uViewMatrix * mvLightPosition;\n - vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n - - float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n - vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n - - gl_Position = vertexPosition;\n - }\n -); - -//Very simple fragment shader that merely applies the vertex shading to the color at each fragment. -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( - precision mediump float;\n - varying mediump vec3 vIllumination;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - void main()\n - {\n - vec4 baseColor = vec4(mixColor, 1.0) * uColor;\n - gl_FragColor = vec4( vIllumination.rgb * baseColor.rgb, baseColor.a );\n - }\n -); - } // unnamed namespace PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -478,7 +411,7 @@ void PrimitiveVisual::UpdateShaderUniforms() void PrimitiveVisual::CreateShader() { - mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mShader = Shader::New( SHADER_PRIMITIVE_VISUAL_SHADER_VERT, SHADER_PRIMITIVE_VISUAL_SHADER_FRAG ); UpdateShaderUniforms(); } diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 09d8de2..bce5c27 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -141,7 +141,7 @@ void SvgVisual::DoSetOnScene( Actor& actor ) Shader shader; if( !mImpl->mCustomShader ) { - shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, false ); + shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired() ); } else { diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index f8d5f53..29b18a1 100755 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -41,6 +41,7 @@ #include #include #include +#include namespace Dali { @@ -55,151 +56,6 @@ namespace { const Vector4 FULL_TEXTURE_RECT( 0.f, 0.f, 1.f, 1.f ); -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec2 aPosition;\n - uniform highp mat4 uMvpMatrix;\n - uniform highp vec3 uSize;\n - uniform mediump vec4 pixelArea;\n - - varying mediump vec2 vTexCoord;\n - - //Visual size and offset - uniform mediump vec2 offset;\n - uniform highp vec2 size;\n - uniform mediump vec4 offsetSizeMode;\n - uniform mediump vec2 origin;\n - uniform mediump vec2 anchorPoint;\n - - vec4 ComputeVertexPosition()\n - {\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n - }\n - - void main()\n - {\n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n - vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );\n - }\n -); - -const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform lowp vec4 uTextColorAnimatable;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n - - // Set the color of the text to what it is animated to. - gl_FragColor = uTextColorAnimatable * textTexture * uColor * vec4( mixColor, 1.0 ); - }\n -); - -const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n - - gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 ); - }\n -); - -const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sStyle;\n - uniform lowp vec4 uTextColorAnimatable;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump float textTexture = texture2D( sTexture, vTexCoord ).r;\n - mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n - - // Draw the text as overlay above the style - gl_FragColor = ( uTextColorAnimatable * textTexture + styleTexture * ( 1.0 - uTextColorAnimatable.a * textTexture ) ) * uColor * vec4( mixColor, 1.0 );\n - }\n -); - -const char* FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sStyle;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n - mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n - - // Draw the text as overlay above the style - gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n - }\n -); - -const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sMask;\n - uniform lowp vec4 uTextColorAnimatable;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n - mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n - - // Set the color of non-transparent pixel in text to what it is animated to. - // Markup text with multiple text colors are not animated (but can be supported later on if required). - // Emoji color are not animated. - mediump float vstep = step( 0.0001, textTexture.a );\n - textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture );\n - - // Draw the text as overlay above the style - gl_FragColor = textTexture * uColor * vec4( mixColor, 1.0 );\n - }\n -); - -const char* FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI = DALI_COMPOSE_SHADER( - varying mediump vec2 vTexCoord;\n - uniform sampler2D sTexture;\n - uniform sampler2D sStyle;\n - uniform sampler2D sMask;\n - uniform lowp float uHasMultipleTextColors;\n - uniform lowp vec4 uTextColorAnimatable;\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n - \n - void main()\n - {\n - mediump vec4 textTexture = texture2D( sTexture, vTexCoord );\n - mediump vec4 styleTexture = texture2D( sStyle, vTexCoord );\n - mediump float maskTexture = texture2D( sMask, vTexCoord ).r;\n - - // Set the color of non-transparent pixel in text to what it is animated to. - // Markup text with multiple text colors are not animated (but can be supported later on if required). - // Emoji color are not animated. - mediump float vstep = step( 0.0001, textTexture.a );\n - textTexture.rgb = mix( textTexture.rgb, uTextColorAnimatable.rgb, vstep * maskTexture * ( 1.0 - uHasMultipleTextColors ) );\n - - // Draw the text as overlay above the style - gl_FragColor = ( textTexture + styleTexture * ( 1.0 - textTexture.a ) ) * uColor * vec4( mixColor, 1.0 );\n - }\n -); - /** * Return Property index for the given string key * param[in] stringKey the string index key @@ -929,7 +785,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT, shader ); } @@ -940,7 +796,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_MULTI_COLOR_TEXT_WITH_STYLE_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE, shader ); } @@ -950,7 +806,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT, shader ); } @@ -960,7 +816,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE, shader ); } @@ -970,7 +826,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_EMOJI_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI, shader ); } @@ -980,7 +836,7 @@ Shader TextVisual::GetTextShader( VisualFactoryCache& factoryCache, bool hasMult shader = factoryCache.GetShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI ); + shader = Shader::New( SHADER_TEXT_VISUAL_SHADER_VERT, SHADER_TEXT_VISUAL_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI_SHADER_FRAG ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); factoryCache.SaveShader( VisualFactoryCache::TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI, shader ); } diff --git a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp index 3707465..f563fc1 100644 --- a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp +++ b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace Dali { @@ -39,43 +40,6 @@ namespace { const char * const POSITION_ATTRIBUTE_NAME("aPosition"); const char * const INDEX_NAME("indices"); - -const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( -attribute mediump vec2 aPosition;\n -uniform highp mat4 uMvpMatrix;\n -uniform highp vec3 uSize;\n -\n - -//Visual size and offset -uniform mediump vec2 offset;\n -uniform highp vec2 size;\n -uniform mediump vec4 offsetSizeMode;\n -uniform mediump vec2 origin;\n -uniform mediump vec2 anchorPoint;\n - -vec4 ComputeVertexPosition()\n -{\n - vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n - vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n -}\n - -void main()\n -{\n - gl_Position = uMvpMatrix * ComputeVertexPosition();\n -}\n -); - -const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(\n - uniform lowp vec4 uColor;\n - uniform lowp vec3 mixColor;\n -\n -void main()\n -{\n - gl_FragColor = uColor * vec4( mixColor, 1.0 );\n -}\n -); - } WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties ) @@ -183,7 +147,7 @@ void WireframeVisual::InitializeRenderer() Shader shader = mFactoryCache.GetShader( VisualFactoryCache::WIREFRAME_SHADER ); if( !shader ) { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + shader = Shader::New( SHADER_WIREFRAME_VISUAL_SHADER_VERT, SHADER_WIREFRAME_VISUAL_SHADER_FRAG ); mFactoryCache.SaveShader( VisualFactoryCache::WIREFRAME_SHADER, shader ); }