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 // OES_texture_cube_map_array_test.cpp:
7 // Test for the [OES/EXT]_texture_cube_map_array extension
8 //
9
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "gtest/gtest.h"
13 #include "tests/test_utils/ShaderCompileTreeTest.h"
14
15 using namespace sh;
16
17 class TextureCubeMapArrayTestNoExt : public ShaderCompileTreeTest
18 {
19 protected:
getShaderType() const20 ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const21 ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
22 };
23
24 class OESTextureCubeMapArrayTest : public TextureCubeMapArrayTestNoExt
25 {
26 protected:
initResources(ShBuiltInResources * resources)27 void initResources(ShBuiltInResources *resources) override
28 {
29 resources->OES_texture_cube_map_array = 1;
30 }
31 };
32
33 class EXTTextureCubeMapArrayTest : public TextureCubeMapArrayTestNoExt
34 {
35 protected:
initResources(ShBuiltInResources * resources)36 void initResources(ShBuiltInResources *resources) override
37 {
38 resources->EXT_texture_cube_map_array = 1;
39 }
40 };
41
42 // Check that if the extension is not supported, trying to use the features without having an
43 // extension directive fails.
TEST_F(TextureCubeMapArrayTestNoExt,MissingExtensionDirective)44 TEST_F(TextureCubeMapArrayTestNoExt, MissingExtensionDirective)
45 {
46 const std::string &shaderString =
47 R"(
48 precision mediump float;
49 uniform highp isamplerCubeArray u_sampler;
50 void main()
51 {
52 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
53 })";
54 if (compile(shaderString))
55 {
56 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
57 }
58 }
59
60 // Check that if the extension is not supported, trying to use the features without having an
61 // extension directive fails.
TEST_F(OESTextureCubeMapArrayTest,MissingExtensionDirective)62 TEST_F(OESTextureCubeMapArrayTest, MissingExtensionDirective)
63 {
64 const std::string &shaderString =
65 R"(
66 precision mediump float;
67 uniform highp isamplerCubeArray u_sampler;
68 void main()
69 {
70 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
71 })";
72 if (compile(shaderString))
73 {
74 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
75 }
76 }
77
78 // Check that if the extension is not supported, trying to use the features without having an
79 // extension directive fails.
TEST_F(EXTTextureCubeMapArrayTest,MissingExtensionDirective)80 TEST_F(EXTTextureCubeMapArrayTest, MissingExtensionDirective)
81 {
82 const std::string &shaderString =
83 R"(
84 precision mediump float;
85 uniform highp isamplerCubeArray u_sampler;
86 void main()
87 {
88 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
89 })";
90 if (compile(shaderString))
91 {
92 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
93 }
94 }
95
96 // Check that if the extension is enabled, trying to use the features without the extension
97 // enabled fails.
TEST_F(TextureCubeMapArrayTestNoExt,ExtensionEnabledOES)98 TEST_F(TextureCubeMapArrayTestNoExt, ExtensionEnabledOES)
99 {
100 const std::string &shaderString =
101 R"(#version 310 es
102 #extension GL_OES_texture_cube_map_array : enable
103 precision mediump float;
104 uniform highp isamplerCubeArray u_sampler;
105 void main()
106 {
107 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
108 })";
109 if (compile(shaderString))
110 {
111 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
112 }
113 }
114
115 // Check that if the extension supported and enabled, using the features succeeds.
TEST_F(OESTextureCubeMapArrayTest,ExtensionEnabledOES)116 TEST_F(OESTextureCubeMapArrayTest, ExtensionEnabledOES)
117 {
118 const std::string &shaderString =
119 R"(#version 310 es
120 #extension GL_OES_texture_cube_map_array : enable
121 precision mediump float;
122 uniform highp isamplerCubeArray u_sampler;
123 void main()
124 {
125 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
126 })";
127 if (!compile(shaderString))
128 {
129 FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
130 }
131 }
132
133 // Check that if the extension is enabled, trying to use the features without the extension
134 // enabled fails.
TEST_F(EXTTextureCubeMapArrayTest,ExtensionEnabledOES)135 TEST_F(EXTTextureCubeMapArrayTest, ExtensionEnabledOES)
136 {
137 const std::string &shaderString =
138 R"(#version 310 es
139 #extension GL_OES_texture_cube_map_array : enable
140 precision mediump float;
141 uniform highp isamplerCubeArray u_sampler;
142 void main()
143 {
144 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
145 })";
146 if (compile(shaderString))
147 {
148 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
149 }
150 }
151
152 // Check that if the extension is enabled, trying to use the features without the extension
153 // enabled fails.
TEST_F(TextureCubeMapArrayTestNoExt,ExtensionEnabledEXT)154 TEST_F(TextureCubeMapArrayTestNoExt, ExtensionEnabledEXT)
155 {
156 const std::string &shaderString =
157 R"(#version 310 es
158 #extension GL_EXT_texture_cube_map_array : enable
159 precision mediump float;
160 uniform highp isamplerCubeArray u_sampler;
161 void main()
162 {
163 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
164 })";
165 if (compile(shaderString))
166 {
167 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
168 }
169 }
170
171 // Check that if the extension is enabled, trying to use the features without the extension
172 // enabled fails.
TEST_F(OESTextureCubeMapArrayTest,ExtensionEnabledEXT)173 TEST_F(OESTextureCubeMapArrayTest, ExtensionEnabledEXT)
174 {
175 const std::string &shaderString =
176 R"(#version 310 es
177 #extension GL_EXT_texture_cube_map_array : enable
178 precision mediump float;
179 uniform highp isamplerCubeArray u_sampler;
180 void main()
181 {
182 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
183 })";
184 if (compile(shaderString))
185 {
186 FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
187 }
188 }
189
190 // Check that if the extension supported and enabled, using the features succeeds.
TEST_F(EXTTextureCubeMapArrayTest,ExtensionEnabledEXT)191 TEST_F(EXTTextureCubeMapArrayTest, ExtensionEnabledEXT)
192 {
193 const std::string &shaderString =
194 R"(#version 310 es
195 #extension GL_EXT_texture_cube_map_array : enable
196 precision mediump float;
197 uniform highp isamplerCubeArray u_sampler;
198 void main()
199 {
200 vec4 color = vec4(texture(u_sampler, vec4(0, 0, 0, 0)));
201 })";
202 if (!compile(shaderString))
203 {
204 FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
205 }
206 }
207