1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // EXT_shadow_samplers_test.cpp:
7 // Test for EXT_shadow_samplers
8 //
9
10 #include "tests/test_utils/ShaderExtensionTest.h"
11
12 using EXTShadowSamplersTest = sh::ShaderExtensionTest;
13
14 namespace
15 {
16 const char EXTPragma[] = "#extension GL_EXT_shadow_samplers : require\n";
17
18 // Shader calling shadow2DEXT()
19 const char ESSL100_ShadowSamplersShader[] =
20 R"(
21 precision mediump float;
22 varying vec3 texCoord0v;
23 uniform sampler2DShadow tex;
24 void main()
25 {
26 float color = shadow2DEXT(tex, texCoord0v);
27 })";
28
29 // Extension flag is required to compile properly. Expect failure when it is
30 // not present.
TEST_P(EXTShadowSamplersTest,CompileFailsWithoutExtension)31 TEST_P(EXTShadowSamplersTest, CompileFailsWithoutExtension)
32 {
33 mResources.EXT_shadow_samplers = 0;
34 InitializeCompiler();
35 EXPECT_FALSE(TestShaderCompile(EXTPragma));
36 }
37
38 // Extension directive is required to compile properly. Expect failure when
39 // it is not present.
TEST_P(EXTShadowSamplersTest,CompileFailsWithExtensionWithoutPragma)40 TEST_P(EXTShadowSamplersTest, CompileFailsWithExtensionWithoutPragma)
41 {
42 mResources.EXT_shadow_samplers = 1;
43 InitializeCompiler();
44 EXPECT_FALSE(TestShaderCompile(""));
45 }
46
47 // With extension flag and extension directive, compiling succeeds.
48 // Also test that the extension directive state is reset correctly.
TEST_P(EXTShadowSamplersTest,CompileSucceedsWithExtensionAndPragma)49 TEST_P(EXTShadowSamplersTest, CompileSucceedsWithExtensionAndPragma)
50 {
51 mResources.EXT_shadow_samplers = 1;
52 InitializeCompiler();
53 EXPECT_TRUE(TestShaderCompile(EXTPragma));
54 // Test reset functionality.
55 EXPECT_FALSE(TestShaderCompile(""));
56 EXPECT_TRUE(TestShaderCompile(EXTPragma));
57 }
58
59 // The SL #version 100 shaders that are correct work similarly
60 // in both GL2 and GL3, with and without the version string.
61 INSTANTIATE_TEST_SUITE_P(CorrectESSL100Shaders,
62 EXTShadowSamplersTest,
63 Combine(Values(SH_GLES2_SPEC),
64 Values(sh::ESSLVersion100),
65 Values(ESSL100_ShadowSamplersShader)));
66
67 } // anonymous namespace