2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/dali.h>
20 #include <dali/integration-api/testing.h>
21 #include <dali/internal/graphics/gles-impl/gles-graphics-shader.h>
22 #include <test-graphics-application.h>
24 int UtcDaliGlesStripLegacyCodeIfNeededTest1(void)
26 TestGraphicsApplication application;
29 Dali::Graphics::ShaderCreateInfo info;
30 info.SetPipelineStage(Dali::Graphics::PipelineStage::VERTEX_SHADER);
31 std::string vertexShader =
35 info.SetShaderVersion(100);
36 info.SetSourceData(vertexShader.data());
37 info.SetSourceSize(vertexShader.size());
38 info.SetSourceMode(Dali::Graphics::ShaderSourceMode::TEXT);
42 Graphics::GLES::ShaderImpl::StripLegacyCodeIfNeeded(info, dataIndex, dataSize);
44 DALI_TEST_EQUALS(dataIndex, 0, TEST_LOCATION);
45 DALI_TEST_EQUALS(dataSize, vertexShader.size(), TEST_LOCATION);
51 int UtcDaliGlesStripLegacyCodeTestDifferentPrefix(void)
53 TestGraphicsApplication application;
55 std::string vertexShader =
59 std::string somePrefix =
60 "This is some prefix\n";
62 auto newVertexPrefix = Dali::Integration::Test::GenerateTaggedShaderPrefix(somePrefix);
64 Dali::Graphics::ShaderCreateInfo info;
65 info.SetPipelineStage(Dali::Graphics::PipelineStage::VERTEX_SHADER);
67 std::string prefixedVertexShader = newVertexPrefix + vertexShader;
69 info.SetShaderVersion(100);
70 info.SetSourceData(prefixedVertexShader.data());
71 info.SetSourceSize(prefixedVertexShader.size());
72 info.SetSourceMode(Dali::Graphics::ShaderSourceMode::TEXT);
76 Graphics::GLES::ShaderImpl::StripLegacyCodeIfNeeded(info, dataIndex, dataSize);
78 auto index = prefixedVertexShader.find("//@version");
80 DALI_TEST_EQUALS(dataIndex, index, TEST_LOCATION);
82 // should match original shader size
83 DALI_TEST_EQUALS(dataSize, vertexShader.size(), TEST_LOCATION);
89 int UtcDaliGlesStripLegacyCodeIfNeededTest2(void)
91 TestGraphicsApplication application;
93 std::string vertexShader =
97 auto vertexPrefix = Dali::Shader::GetVertexShaderPrefix();
100 Dali::Graphics::ShaderCreateInfo info;
101 info.SetPipelineStage(Dali::Graphics::PipelineStage::VERTEX_SHADER);
103 std::string prefixedVertexShader = Dali::Shader::GetVertexShaderPrefix() + vertexShader;
105 info.SetShaderVersion(100);
106 info.SetSourceData(prefixedVertexShader.data());
107 info.SetSourceSize(prefixedVertexShader.size());
108 info.SetSourceMode(Dali::Graphics::ShaderSourceMode::TEXT);
111 size_t dataIndex = 0;
112 Graphics::GLES::ShaderImpl::StripLegacyCodeIfNeeded(info, dataIndex, dataSize);
114 DALI_TEST_EQUALS(dataIndex, vertexPrefix.length(), TEST_LOCATION);
116 // should match original shader size
117 DALI_TEST_EQUALS(dataSize, vertexShader.size(), TEST_LOCATION);
123 int UtcDaliGlesLegacyCodeTest(void)
125 TestGraphicsApplication application;
127 std::string vertexShader =
131 std::string somePrefix =
132 "This is some prefix\n";
134 auto newVertexPrefix = Dali::Integration::Test::GenerateTaggedShaderPrefix(somePrefix);
136 Dali::Graphics::ShaderCreateInfo info;
137 info.SetPipelineStage(Dali::Graphics::PipelineStage::VERTEX_SHADER);
139 std::string prefixedVertexShader = newVertexPrefix + vertexShader;
141 info.SetShaderVersion(0);
142 info.SetSourceData(prefixedVertexShader.data());
143 info.SetSourceSize(prefixedVertexShader.size());
144 info.SetSourceMode(Dali::Graphics::ShaderSourceMode::TEXT);
147 size_t dataIndex = 0;
148 Graphics::GLES::ShaderImpl::StripLegacyCodeIfNeeded(info, dataIndex, dataSize);
150 auto index = prefixedVertexShader.find("#version");
152 DALI_TEST_EQUALS(dataIndex, index, TEST_LOCATION);
154 // should match original shader size
155 DALI_TEST_EQUALS(dataSize, vertexShader.size(), TEST_LOCATION);