1 //
2 // Copyright 2018 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_shader_texture_lod_test.cpp:
7 // Test for EXT_shader_texture_lod
8 //
9
10 #include "tests/test_utils/ShaderExtensionTest.h"
11
12 using EXTShaderTextureLodTest = sh::ShaderExtensionTest;
13
14 namespace
15 {
16 const char EXTPragma[] = "#extension GL_EXT_shader_texture_lod : require\n";
17
18 // Shader calling texture2DLodEXT()
19 const char ESSL100_TextureLodShader[] =
20 R"(
21 precision mediump float;
22 varying vec2 texCoord0v;
23 uniform float lod;
24 uniform sampler2D tex;
25 void main()
26 {
27 vec4 color = texture2DLodEXT(tex, texCoord0v, lod);
28 })";
29
30 // Extension flag is required to compile properly. Expect failure when it is
31 // not present.
TEST_P(EXTShaderTextureLodTest,CompileFailsWithoutExtension)32 TEST_P(EXTShaderTextureLodTest, CompileFailsWithoutExtension)
33 {
34 mResources.EXT_shader_texture_lod = 0;
35 InitializeCompiler();
36 EXPECT_FALSE(TestShaderCompile(EXTPragma));
37 }
38
39 // Extension directive is required to compile properly. Expect failure when
40 // it is not present.
TEST_P(EXTShaderTextureLodTest,CompileFailsWithExtensionWithoutPragma)41 TEST_P(EXTShaderTextureLodTest, CompileFailsWithExtensionWithoutPragma)
42 {
43 mResources.EXT_shader_texture_lod = 1;
44 InitializeCompiler();
45 EXPECT_FALSE(TestShaderCompile(""));
46 }
47
48 // With extension flag and extension directive, compiling succeeds.
49 // Also test that the extension directive state is reset correctly.
TEST_P(EXTShaderTextureLodTest,CompileSucceedsWithExtensionAndPragma)50 TEST_P(EXTShaderTextureLodTest, CompileSucceedsWithExtensionAndPragma)
51 {
52 mResources.EXT_shader_texture_lod = 1;
53 InitializeCompiler();
54 EXPECT_TRUE(TestShaderCompile(EXTPragma));
55 // Test reset functionality.
56 EXPECT_FALSE(TestShaderCompile(""));
57 EXPECT_TRUE(TestShaderCompile(EXTPragma));
58 }
59
60 // The SL #version 100 shaders that are correct work similarly
61 // in both GL2 and GL3, with and without the version string.
62 INSTANTIATE_TEST_SUITE_P(CorrectESSL100Shaders,
63 EXTShaderTextureLodTest,
64 Combine(Values(SH_GLES2_SPEC),
65 Values(sh::ESSLVersion100),
66 Values(ESSL100_TextureLodShader)));
67
68 } // anonymous namespace
69