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
#!/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
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 <testcase>\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 <testcase>\tFind and execute the given test case"
exit 2
}
opt_modules=0
opt_debug=0
opt_noFailedRerun="";
+opt_quiet="";
while true ; do
case "$1" in
-h|--help) usage ;;
-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 ;;
EOF
}
+function output_start
+{
+ start=`date +"%Y-%m-%d_%H_%M_%S"`
+ cat > tct-${1}-core-tests.xml <<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>
+<test_definition>
+<environment build_id="" device_id="localhost" device_model="" device_name="N/A" host="Ubuntu" manufacturer="" resolution="N/A" screen_size="N/A"><other /></environment>
+<summary test_plan_name="Empty test_plan_name"><start_at>$start</start_at><end_at>$start</end_at></summary>
+ <suite category="Core APIs" name="tct-$1-core-tests">
+ <set name="default" set_debug_msg="automated-tests.auto.suite_1_set_1.dlog">
+EOF
+}
+
+
+function output_end
+{
+ cat >> tct-${1}-core-tests.xml <<EOF
+ </set>
+ </suite>
+</test_definition>
+EOF
+}
+
+
if [ $opt_modules == 1 ] ; then
modules= get_modules
echo $modules
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
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
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
/*
- * 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.
#include <sys/wait.h>
#include <testcase.h>
-#include <time.h>
+#include <getopt.h>
#include <unistd.h>
-
+#include <algorithm>
#include <chrono>
+#include <cstdlib>
#include <cstring>
+#include <ctime>
+#include <fstream>
#include <map>
+#include <sstream>
#include <vector>
+using std::chrono::steady_clock;
+using std::chrono::system_clock;
+
namespace TestHarness
{
typedef std::map<int32_t, TestCase> RunningTestCases;
return slash;
}
-void SuppressLogOutput()
+std::vector<std::string> 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<std::string> 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<std::string>& 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 << "<testcase component=\"CoreAPI/" << testSuiteName << "/default\" execution_type=\"auto\" id=\""
+ << testCase.name << "\" purpose=\"\" result=\"" << (testCase.result == 0 ? "PASS" : "FAIL") << "\">" << std::endl
+ << "<description><test_script_entry test_script_expected_result=\"0\">"
+ << pathToExecutable << testCase.name << "</test_script_entry>" << std::endl
+ << "</description>"
+ << "<result_info><actual_result>" << (testCase.result == 0 ? "PASS" : "FAIL") << "</actual_result>" << std::endl
+ << "<start>" << startTime << "</start>"
+ << "<end>" << endTime << "</end>"
+ << "<stdout><![CDATA[]]></stdout>"
+ << "<stderr><![CDATA[" << testOutput << "]]></stderr></result_info></testcase>" << 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<TestCase> 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,
+ " <suite name=\"%s-tests\">\n"
+ " <total_case>%d</total_case>\n"
+ " <pass_case>%d</pass_case>\n"
+ " <pass_rate>%5.2f</pass_rate>\n"
+ " <fail_case>%d</fail_case>\n"
+ " <fail_rate>%5.2f</fail_rate>\n"
+ " <block_case>0</block_case>\n"
+ " <block_rate>0.00</block_rate>\n"
+ " <na_case>0</na_case>\n"
+ " <na_rate>0.00</na_rate>\n"
+ " </suite>\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)
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)
{
}
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");
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,
- " <suite name=\"%s\">\n"
- " <total_case>%d</total_case>\n"
- " <pass_case>%d</pass_case>\n"
- " <pass_rate>%5.2f</pass_rate>\n"
- " <fail_case>%d</fail_case>\n"
- " <fail_rate>%5.2f</fail_rate>\n"
- " <block_case>0</block_case>\n"
- " <block_rate>0.00</block_rate>\n"
- " <na_case>0</na_case>\n"
- " <na_rate>0.00</na_rate>\n"
- " </suite>\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++;
}
{
numFailures++;
}
+ if(!quiet)
+ {
+ OutputTestResult(ofs, processName, moduleName, testCase, startTime, endTime);
+ }
}
+ ofs.close();
OutputStatistics(processName, numPasses, numFailures);
}
// 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;
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)
{
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++;
{
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
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
}
}
+ if(!quiet)
+ {
+ OutputTestResults(processName, children);
+ }
+
OutputStatistics(processName, numPasses, numFailures);
if(reRunFailed)
printf("=");
}
printf("\n");
- RunTestCaseInChildProcess(tc_array[failedTestCases[i]], false);
+ int index = failedTestCases[i];
+ TestCase testCase(index, &tc_array[index]);
+ RunTestCaseInChildProcess(testCase, false);
}
}
" %s <testcase name>\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
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;
}
};
*/
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
-#include <string.h>
-#include <getopt.h>
-#include <stdlib.h>
#include <test-harness.h>
#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);
}
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
#include <dali-toolkit/devel-api/visuals/animated-image-visual-actions-devel.h>
#include "dummy-control.h"
.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 );
DALI_TEST_CHECK( value );
DALI_TEST_CHECK( value->Get<std::string>() == TEST_GIF_FILE_NAME );
+ value = resultMap.Find( DevelVisual::Property::CORNER_RADIUS, Property::FLOAT );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<float>(), 22.2f, TEST_LOCATION );
+
+ value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
+
// request AnimatedImageVisual with an URL
Visual::Base animatedImageVisual2 = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
resultMap.Clear();
.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 );
DALI_TEST_CHECK( value );
DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
+ value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<float>(), 50.0f, TEST_LOCATION );
+
+ value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::RELATIVE );
+
END_TEST;
}
.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 );
DALI_TEST_CHECK( value );
DALI_TEST_EQUALS( value->Get<int>(), 11, TEST_LOCATION );
+ value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS, "cornerRadius" );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<float>(), 50.5f, TEST_LOCATION );
+
+ value = resultMap.Find( Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, "cornerRadiusPolicy" );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == Visual::Transform::Policy::ABSOLUTE );
+
END_TEST;
}
{
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 );
}
END_TEST;
-}
\ No newline at end of file
+}
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 );
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 );
.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 );
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 );
tet_infoline( "UtcDaliAnimatedVectorImageVisualGetPropertyMap01" );
int startFrame = 1, endFrame = 3;
+ float cornerRadius = 50.0f;
Property::Array playRange;
playRange.PushBack( startFrame );
playRange.PushBack( endFrame );
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();
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() );
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
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;
}
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
--- /dev/null
+#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
--- /dev/null
+#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
/*
- * 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.
#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
#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;
{
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;
}
// CLASS HEADER
#include <dali-toolkit/internal/controls/scene3d-view/gltf-loader.h>
-#include <dali-toolkit/internal/controls/scene3d-view/gltf-shader.h>
// EXTERNAL INCLUDES
#include <dali/integration-api/debug.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/devel-api/adaptor-framework/file-stream.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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<int32_t>( 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<int32_t>( 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<int32_t>( 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<int32_t>( 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<int32_t>( ShaderType::EMIT_SHADER );
isEmissiveTexture = true;
if( useIBL )
{
shaderTypeIndex += static_cast<int32_t>( 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 );
}
}
- 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 );
+++ /dev/null
-#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
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 )
{
// 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 );
}
if( !vertexShaderValue || !checkShader )
{
- vertexShader = VERTEX_SHADER_TEXTURE;
+ vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
}
Property::Value* fragmentShaderValue = mEffectPropertyMap.Find( CUSTOM_FRAGMENT_SHADER );
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 );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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;
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" );
// 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
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 );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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" );
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 );
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 );
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 );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/control/control-renderers.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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" );
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 );
// 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 );
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 );
+ }
+}
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 );
}
void main()
{
gl_Position = uMvpMatrix * ComputeVertexPosition();
-}
\ No newline at end of file
+}
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 );
}
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 );
+ }
}
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 );
+ }
}
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 );
}
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
+}
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 );
}
{
gl_Position = uMvpMatrix * ComputeVertexPosition();
vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
-}
\ No newline at end of file
+}
+//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()
{
+//A simple shader that applies diffuse lighting to a mono-coloured object.
+
attribute highp vec3 aPosition;
attribute highp vec2 aTexCoord;
attribute highp vec3 aNormal;
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/internal/controls/image-view/image-view-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#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
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();
}
#include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
#include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
#include <dali-toolkit/internal/text/text-view.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
using namespace Dali::Toolkit;
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 );
// 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;
}
// 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;
}
#include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
#include <dali-toolkit/internal/text/text-run-container.h>
#include <dali-toolkit/internal/text/text-selection-handle-controller.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
using namespace Dali;
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
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 );
// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/text-scroller-interface.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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.
*
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 );
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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
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;
}
else
{
- shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, false );
+ shader = mImageVisualShaderFactory.GetShader( mFactoryCache, false, true, IsRoundedCornerRequired() );
}
Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 )
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 );
}
}
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 );
}
}
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 )
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 );
}
}
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 );
}
}
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 ) );
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 );
}
}
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 );
}
}
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 );
}
}
#include <dali-toolkit/internal/visuals/gradient/linear-gradient.h>
#include <dali-toolkit/internal/visuals/gradient/radial-gradient.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-bounding-box-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-linear-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-rounded-corner-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-radial-shader-frag.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-rounded-corner-shader-vert.h>
+#include <dali-toolkit/internal/graphics/generated/gradient-visual-user-space-shader-vert.h>
namespace Dali
{
}
};
-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 )
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
#include <dali/integration-api/debug.h>
namespace Dali
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;
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 );
}
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 );
}
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 );
}
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 );
}
{
if(gVertexShader.empty())
{
- gVertexShader = Dali::Shader::GetVertexShaderPrefix() + VERTEX_SHADER;
+ gVertexShader = Dali::Shader::GetVertexShaderPrefix() + SHADER_IMAGE_VISUAL_SHADER_VERT.data();
}
return gVertexShader;
{
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;
}
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 )
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" );
{
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();
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/rendering-addon.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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
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;
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 );
}
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 );
}
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() )
{
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 );
}
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
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 )
void PrimitiveVisual::CreateShader()
{
- mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ mShader = Shader::New( SHADER_PRIMITIVE_VISUAL_SHADER_VERT, SHADER_PRIMITIVE_VISUAL_SHADER_FRAG );
UpdateShaderUniforms();
}
Shader shader;
if( !mImpl->mCustomShader )
{
- shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, false );
+ shader = mImageVisualShaderFactory.GetShader( mFactoryCache, mAttemptAtlasing, true, IsRoundedCornerRequired() );
}
else
{
#include <dali-toolkit/internal/text/script-run.h>
#include <dali-toolkit/internal/text/text-enumerations-impl.h>
#include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
{
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
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
namespace Dali
{
{
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 )
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 );
}