blob: 0167268e35192362eccdb0f97e6355eba84d911d [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 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
Jamie Madill14718762016-09-06 15:56:54 -04007#include "common/mathutil.h"
Corentin Wallezd3970de2015-05-14 11:07:48 -04008#include "test_utils/ANGLETest.h"
Olli Etuaho989cac32016-06-08 16:18:49 -07009#include "test_utils/gl_raii.h"
Jamie Madillf67115c2014-04-22 13:14:05 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madillfa05f602015-05-07 13:47:11 -040013namespace
14{
15
Vincent Lang25ab4512016-05-13 18:13:59 +020016// Take a pixel, and reset the components not covered by the format to default
Geoff Langf607c602016-09-21 11:46:48 -040017// values. In particular, the default value for the alpha component is 255
Vincent Lang25ab4512016-05-13 18:13:59 +020018// (1.0 as unsigned normalized fixed point value).
Geoff Langf607c602016-09-21 11:46:48 -040019GLColor SliceFormatColor(GLenum format, GLColor full)
Vincent Lang25ab4512016-05-13 18:13:59 +020020{
21 switch (format)
22 {
23 case GL_RED:
Geoff Langf607c602016-09-21 11:46:48 -040024 return GLColor(full.R, 0, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020025 case GL_RG:
Geoff Langf607c602016-09-21 11:46:48 -040026 return GLColor(full.R, full.G, 0, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020027 case GL_RGB:
Geoff Langf607c602016-09-21 11:46:48 -040028 return GLColor(full.R, full.G, full.B, 255u);
Vincent Lang25ab4512016-05-13 18:13:59 +020029 case GL_RGBA:
30 return full;
31 default:
Jamie Madille1faacb2016-12-13 12:42:14 -050032 EXPECT_TRUE(false);
Geoff Langf607c602016-09-21 11:46:48 -040033 return GLColor::white;
Vincent Lang25ab4512016-05-13 18:13:59 +020034 }
Vincent Lang25ab4512016-05-13 18:13:59 +020035}
36
Olli Etuaho4a8329f2016-01-11 17:12:57 +020037class TexCoordDrawTest : public ANGLETest
Jamie Madillf67115c2014-04-22 13:14:05 -040038{
Jamie Madillbc393df2015-01-29 13:46:07 -050039 protected:
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020040 TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0)
Jamie Madillf67115c2014-04-22 13:14:05 -040041 {
42 setWindowWidth(128);
43 setWindowHeight(128);
44 setConfigRedBits(8);
45 setConfigGreenBits(8);
46 setConfigBlueBits(8);
47 setConfigAlphaBits(8);
48 }
49
Olli Etuaho4a8329f2016-01-11 17:12:57 +020050 virtual std::string getVertexShaderSource()
Jamie Madillf67115c2014-04-22 13:14:05 -040051 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +030052 return
53 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -040054 attribute vec4 position;
55 varying vec2 texcoord;
56
57 void main()
58 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020059 gl_Position = vec4(position.xy, 0.0, 1.0);
Geoff Langc41e42d2014-04-28 10:58:16 -040060 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030061 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +020062 }
Geoff Langc41e42d2014-04-28 10:58:16 -040063
Olli Etuaho4a8329f2016-01-11 17:12:57 +020064 virtual std::string getFragmentShaderSource() = 0;
65
Olli Etuahoa1c917f2016-04-06 13:50:03 +030066 virtual void setUpProgram()
Olli Etuaho4a8329f2016-01-11 17:12:57 +020067 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +020068 const std::string vertexShaderSource = getVertexShaderSource();
69 const std::string fragmentShaderSource = getFragmentShaderSource();
70
71 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
72 ASSERT_NE(0u, mProgram);
73 ASSERT_GL_NO_ERROR();
Olli Etuahoa1c917f2016-04-06 13:50:03 +030074 }
75
76 void SetUp() override
77 {
78 ANGLETest::SetUp();
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020079
80 setUpFramebuffer();
Olli Etuaho4a8329f2016-01-11 17:12:57 +020081 }
82
83 void TearDown() override
84 {
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020085 glBindFramebuffer(GL_FRAMEBUFFER, 0);
86 glDeleteFramebuffers(1, &mFramebuffer);
87 glDeleteTextures(1, &mFramebufferColorTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +020088 glDeleteProgram(mProgram);
89 ANGLETest::TearDown();
90 }
91
Olli Etuaho51f1c0f2016-01-13 16:16:24 +020092 void setUpFramebuffer()
93 {
94 // We use an FBO to work around an issue where the default framebuffer applies SRGB
95 // conversion (particularly known to happen incorrectly on Intel GL drivers). It's not
96 // clear whether this issue can even be fixed on all backends. For example GLES 3.0.4 spec
97 // section 4.4 says that the format of the default framebuffer is entirely up to the window
98 // system, so it might be SRGB, and GLES 3.0 doesn't have a "FRAMEBUFFER_SRGB" to turn off
99 // SRGB conversion like desktop GL does.
100 // TODO(oetuaho): Get rid of this if the underlying issue is fixed.
101 glGenFramebuffers(1, &mFramebuffer);
102 glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
103
104 glGenTextures(1, &mFramebufferColorTexture);
105 glBindTexture(GL_TEXTURE_2D, mFramebufferColorTexture);
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
107 GL_UNSIGNED_BYTE, nullptr);
108 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
109 mFramebufferColorTexture, 0);
110 ASSERT_GL_NO_ERROR();
111 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
112 glBindTexture(GL_TEXTURE_2D, 0);
113 }
114
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200115 // Returns the created texture ID.
116 GLuint create2DTexture()
117 {
118 GLuint texture2D;
119 glGenTextures(1, &texture2D);
120 glBindTexture(GL_TEXTURE_2D, texture2D);
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200122 EXPECT_GL_NO_ERROR();
123 return texture2D;
124 }
125
126 GLuint mProgram;
Olli Etuaho51f1c0f2016-01-13 16:16:24 +0200127 GLuint mFramebuffer;
128
129 private:
130 GLuint mFramebufferColorTexture;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200131};
132
133class Texture2DTest : public TexCoordDrawTest
134{
135 protected:
136 Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {}
137
138 std::string getFragmentShaderSource() override
139 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300140 return
141 R"(precision highp float;
Geoff Langc41e42d2014-04-28 10:58:16 -0400142 uniform sampler2D tex;
143 varying vec2 texcoord;
144
145 void main()
146 {
147 gl_FragColor = texture2D(tex, texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300148 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200149 }
Geoff Langc41e42d2014-04-28 10:58:16 -0400150
Olli Etuaho96963162016-03-21 11:54:33 +0200151 virtual const char *getTextureUniformName() { return "tex"; }
152
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300153 void setUpProgram() override
154 {
155 TexCoordDrawTest::setUpProgram();
156 mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName());
157 ASSERT_NE(-1, mTexture2DUniformLocation);
158 }
159
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200160 void SetUp() override
161 {
162 TexCoordDrawTest::SetUp();
163 mTexture2D = create2DTexture();
Jamie Madilld4cfa572014-07-08 10:00:32 -0400164
Jamie Madill9aca0592014-10-06 16:26:59 -0400165 ASSERT_GL_NO_ERROR();
Jamie Madillf67115c2014-04-22 13:14:05 -0400166 }
167
Jamie Madillfa05f602015-05-07 13:47:11 -0400168 void TearDown() override
Jamie Madillf67115c2014-04-22 13:14:05 -0400169 {
Jamie Madilld4cfa572014-07-08 10:00:32 -0400170 glDeleteTextures(1, &mTexture2D);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200171 TexCoordDrawTest::TearDown();
Jamie Madillf67115c2014-04-22 13:14:05 -0400172 }
173
Jamie Madillbc393df2015-01-29 13:46:07 -0500174 // Tests CopyTexSubImage with floating point textures of various formats.
175 void testFloatCopySubImage(int sourceImageChannels, int destImageChannels)
176 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300177 setUpProgram();
178
Martin Radev1be913c2016-07-11 17:59:16 +0300179 if (getClientMajorVersion() < 3)
Geoff Langfbfa47c2015-03-31 11:26:00 -0400180 {
Yunchao He9550c602018-02-13 14:47:05 +0800181 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") ||
182 !extensionEnabled("GL_OES_texture_float"));
Geoff Langc4e93662017-05-01 10:45:59 -0400183
Yunchao He9550c602018-02-13 14:47:05 +0800184 ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) &&
185 !extensionEnabled("GL_EXT_texture_rg"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400186
Yunchao He9550c602018-02-13 14:47:05 +0800187 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
188 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400189
Yunchao He9550c602018-02-13 14:47:05 +0800190 ANGLE_SKIP_TEST_IF(destImageChannels == 4 &&
191 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192
Yunchao He9550c602018-02-13 14:47:05 +0800193 ANGLE_SKIP_TEST_IF(destImageChannels <= 2);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194 }
195 else
196 {
Yunchao He9550c602018-02-13 14:47:05 +0800197 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float"));
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198
Yunchao He9550c602018-02-13 14:47:05 +0800199 ANGLE_SKIP_TEST_IF(destImageChannels == 3 &&
200 !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"));
Geoff Langfbfa47c2015-03-31 11:26:00 -0400201 }
202
Jamie Madill50cf2be2018-06-15 09:46:57 -0400203 // clang-format off
Jamie Madillbc393df2015-01-29 13:46:07 -0500204 GLfloat sourceImageData[4][16] =
205 {
206 { // R
207 1.0f,
208 0.0f,
209 0.0f,
210 1.0f
211 },
212 { // RG
213 1.0f, 0.0f,
214 0.0f, 1.0f,
215 0.0f, 0.0f,
216 1.0f, 1.0f
217 },
218 { // RGB
219 1.0f, 0.0f, 0.0f,
220 0.0f, 1.0f, 0.0f,
221 0.0f, 0.0f, 1.0f,
222 1.0f, 1.0f, 0.0f
223 },
224 { // RGBA
225 1.0f, 0.0f, 0.0f, 1.0f,
226 0.0f, 1.0f, 0.0f, 1.0f,
227 0.0f, 0.0f, 1.0f, 1.0f,
228 1.0f, 1.0f, 0.0f, 1.0f
229 },
230 };
Jamie Madill50cf2be2018-06-15 09:46:57 -0400231 // clang-format on
Jamie Madillbc393df2015-01-29 13:46:07 -0500232
Jamie Madill50cf2be2018-06-15 09:46:57 -0400233 GLenum imageFormats[] = {
234 GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F,
Jamie Madillbc393df2015-01-29 13:46:07 -0500235 };
236
Jamie Madill50cf2be2018-06-15 09:46:57 -0400237 GLenum sourceUnsizedFormats[] = {
238 GL_RED, GL_RG, GL_RGB, GL_RGBA,
Jamie Madillbc393df2015-01-29 13:46:07 -0500239 };
240
241 GLuint textures[2];
242
243 glGenTextures(2, textures);
244
Jamie Madill50cf2be2018-06-15 09:46:57 -0400245 GLfloat *imageData = sourceImageData[sourceImageChannels - 1];
246 GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500247 GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1];
Jamie Madill50cf2be2018-06-15 09:46:57 -0400248 GLenum destImageFormat = imageFormats[destImageChannels - 1];
Jamie Madillbc393df2015-01-29 13:46:07 -0500249
250 glBindTexture(GL_TEXTURE_2D, textures[0]);
Geoff Langc4e93662017-05-01 10:45:59 -0400251 if (getClientMajorVersion() >= 3)
252 {
253 glTexStorage2D(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
254 }
255 else
256 {
257 glTexStorage2DEXT(GL_TEXTURE_2D, 1, sourceImageFormat, 2, 2);
258 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500259 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
261 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, sourceUnsizedFormat, GL_FLOAT, imageData);
262
hendrikwb27f79a2015-03-04 11:26:46 -0800263 if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg"))
Jamie Madillbc393df2015-01-29 13:46:07 -0500264 {
265 // This is not supported
266 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
267 }
268 else
269 {
270 ASSERT_GL_NO_ERROR();
271 }
272
273 GLuint fbo;
274 glGenFramebuffers(1, &fbo);
275 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
276 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
277
278 glBindTexture(GL_TEXTURE_2D, textures[1]);
Geoff Langc4e93662017-05-01 10:45:59 -0400279 if (getClientMajorVersion() >= 3)
280 {
281 glTexStorage2D(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
282 }
283 else
284 {
285 glTexStorage2DEXT(GL_TEXTURE_2D, 1, destImageFormat, 2, 2);
286 }
Jamie Madillbc393df2015-01-29 13:46:07 -0500287 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
288 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
289
290 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
291 ASSERT_GL_NO_ERROR();
292
293 glBindFramebuffer(GL_FRAMEBUFFER, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200294 drawQuad(mProgram, "position", 0.5f);
Jamie Madillbc393df2015-01-29 13:46:07 -0500295
296 int testImageChannels = std::min(sourceImageChannels, destImageChannels);
297
Olli Etuahoa314b612016-03-10 16:43:00 +0200298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Jamie Madillbc393df2015-01-29 13:46:07 -0500299 if (testImageChannels > 1)
300 {
301 EXPECT_PIXEL_EQ(getWindowHeight() - 1, 0, 0, 255, 0, 255);
302 EXPECT_PIXEL_EQ(getWindowHeight() - 1, getWindowWidth() - 1, 255, 255, 0, 255);
303 if (testImageChannels > 2)
304 {
305 EXPECT_PIXEL_EQ(0, getWindowWidth() - 1, 0, 0, 255, 255);
306 }
307 }
308
309 glDeleteFramebuffers(1, &fbo);
310 glDeleteTextures(2, textures);
311
312 ASSERT_GL_NO_ERROR();
313 }
314
Jamie Madilld4cfa572014-07-08 10:00:32 -0400315 GLuint mTexture2D;
Jamie Madilld4cfa572014-07-08 10:00:32 -0400316 GLint mTexture2DUniformLocation;
Jamie Madillf67115c2014-04-22 13:14:05 -0400317};
318
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200319class Texture2DTestES3 : public Texture2DTest
320{
321 protected:
322 Texture2DTestES3() : Texture2DTest() {}
323
324 std::string getVertexShaderSource() override
325 {
326 return std::string(
327 "#version 300 es\n"
328 "out vec2 texcoord;\n"
329 "in vec4 position;\n"
330 "void main()\n"
331 "{\n"
332 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
333 " texcoord = (position.xy * 0.5) + 0.5;\n"
334 "}\n");
335 }
336
337 std::string getFragmentShaderSource() override
338 {
339 return std::string(
340 "#version 300 es\n"
341 "precision highp float;\n"
342 "uniform highp sampler2D tex;\n"
343 "in vec2 texcoord;\n"
344 "out vec4 fragColor;\n"
345 "void main()\n"
346 "{\n"
347 " fragColor = texture(tex, texcoord);\n"
348 "}\n");
349 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300350
351 void SetUp() override
352 {
353 Texture2DTest::SetUp();
354 setUpProgram();
355 }
Olli Etuahoa7416ff2016-01-18 12:22:55 +0200356};
357
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200358class Texture2DIntegerAlpha1TestES3 : public Texture2DTest
359{
360 protected:
361 Texture2DIntegerAlpha1TestES3() : Texture2DTest() {}
362
363 std::string getVertexShaderSource() override
364 {
365 return std::string(
366 "#version 300 es\n"
367 "out vec2 texcoord;\n"
368 "in vec4 position;\n"
369 "void main()\n"
370 "{\n"
371 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
372 " texcoord = (position.xy * 0.5) + 0.5;\n"
373 "}\n");
374 }
375
376 std::string getFragmentShaderSource() override
377 {
378 return std::string(
379 "#version 300 es\n"
380 "precision highp float;\n"
381 "uniform highp isampler2D tex;\n"
382 "in vec2 texcoord;\n"
383 "out vec4 fragColor;\n"
384 "void main()\n"
385 "{\n"
386 " vec4 green = vec4(0, 1, 0, 1);\n"
387 " vec4 black = vec4(0, 0, 0, 0);\n"
388 " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n"
389 "}\n");
390 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300391
392 void SetUp() override
393 {
394 Texture2DTest::SetUp();
395 setUpProgram();
396 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200397};
398
399class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest
400{
401 protected:
402 Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {}
403
404 std::string getVertexShaderSource() override
405 {
406 return std::string(
407 "#version 300 es\n"
408 "out vec2 texcoord;\n"
409 "in vec4 position;\n"
410 "void main()\n"
411 "{\n"
412 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
413 " texcoord = (position.xy * 0.5) + 0.5;\n"
414 "}\n");
415 }
416
417 std::string getFragmentShaderSource() override
418 {
419 return std::string(
420 "#version 300 es\n"
421 "precision highp float;\n"
422 "uniform highp usampler2D tex;\n"
423 "in vec2 texcoord;\n"
424 "out vec4 fragColor;\n"
425 "void main()\n"
426 "{\n"
427 " vec4 green = vec4(0, 1, 0, 1);\n"
428 " vec4 black = vec4(0, 0, 0, 0);\n"
429 " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n"
430 "}\n");
431 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300432
433 void SetUp() override
434 {
435 Texture2DTest::SetUp();
436 setUpProgram();
437 }
Olli Etuaho6ee394a2016-02-18 13:30:09 +0200438};
439
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200440class Texture2DTestWithDrawScale : public Texture2DTest
Jamie Madill2453dbc2015-07-14 11:35:42 -0400441{
442 protected:
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200443 Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {}
444
445 std::string getVertexShaderSource() override
Jamie Madill2453dbc2015-07-14 11:35:42 -0400446 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300447 return
448 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200449 attribute vec4 position;
450 varying vec2 texcoord;
451
452 uniform vec2 drawScale;
453
454 void main()
455 {
456 gl_Position = vec4(position.xy * drawScale, 0.0, 1.0);
457 texcoord = (position.xy * 0.5) + 0.5;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300458 })";
Jamie Madill2453dbc2015-07-14 11:35:42 -0400459 }
460
461 void SetUp() override
462 {
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200463 Texture2DTest::SetUp();
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300464
465 setUpProgram();
466
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200467 mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale");
468 ASSERT_NE(-1, mDrawScaleUniformLocation);
Jamie Madill2453dbc2015-07-14 11:35:42 -0400469
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200470 glUseProgram(mProgram);
471 glUniform2f(mDrawScaleUniformLocation, 1.0f, 1.0f);
472 glUseProgram(0);
473 ASSERT_GL_NO_ERROR();
474 }
475
476 GLint mDrawScaleUniformLocation;
477};
478
Olli Etuaho4644a202016-01-12 15:12:53 +0200479class Sampler2DAsFunctionParameterTest : public Texture2DTest
480{
481 protected:
482 Sampler2DAsFunctionParameterTest() : Texture2DTest() {}
483
484 std::string getFragmentShaderSource() override
485 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300486 return
487 R"(precision highp float;
Olli Etuaho4644a202016-01-12 15:12:53 +0200488 uniform sampler2D tex;
489 varying vec2 texcoord;
490
491 vec4 computeFragColor(sampler2D aTex)
492 {
493 return texture2D(aTex, texcoord);
494 }
495
496 void main()
497 {
498 gl_FragColor = computeFragColor(tex);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300499 })";
Olli Etuaho4644a202016-01-12 15:12:53 +0200500 }
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300501
502 void SetUp() override
503 {
504 Texture2DTest::SetUp();
505 setUpProgram();
506 }
Olli Etuaho4644a202016-01-12 15:12:53 +0200507};
508
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200509class TextureCubeTest : public TexCoordDrawTest
510{
511 protected:
512 TextureCubeTest()
513 : TexCoordDrawTest(),
514 mTexture2D(0),
515 mTextureCube(0),
516 mTexture2DUniformLocation(-1),
517 mTextureCubeUniformLocation(-1)
518 {
519 }
520
521 std::string getFragmentShaderSource() override
522 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300523 return
524 R"(precision highp float;
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200525 uniform sampler2D tex2D;
526 uniform samplerCube texCube;
527 varying vec2 texcoord;
528
529 void main()
530 {
531 gl_FragColor = texture2D(tex2D, texcoord);
532 gl_FragColor += textureCube(texCube, vec3(texcoord, 0));
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300533 })";
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200534 }
535
536 void SetUp() override
537 {
538 TexCoordDrawTest::SetUp();
539
540 glGenTextures(1, &mTextureCube);
541 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Geoff Langc4e93662017-05-01 10:45:59 -0400542 for (GLenum face = 0; face < 6; face++)
543 {
544 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA, 1, 1, 0, GL_RGBA,
545 GL_UNSIGNED_BYTE, nullptr);
546 }
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200547 EXPECT_GL_NO_ERROR();
548
549 mTexture2D = create2DTexture();
550
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300551 setUpProgram();
552
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200553 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
554 ASSERT_NE(-1, mTexture2DUniformLocation);
555 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
556 ASSERT_NE(-1, mTextureCubeUniformLocation);
557 }
558
559 void TearDown() override
560 {
561 glDeleteTextures(1, &mTextureCube);
562 TexCoordDrawTest::TearDown();
563 }
564
565 GLuint mTexture2D;
566 GLuint mTextureCube;
567 GLint mTexture2DUniformLocation;
568 GLint mTextureCubeUniformLocation;
569};
570
Martin Radev7e2c0d32017-09-15 14:25:42 +0300571class TextureCubeTestES3 : public ANGLETest
572{
573 protected:
574 TextureCubeTestES3() {}
575};
576
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200577class SamplerArrayTest : public TexCoordDrawTest
578{
579 protected:
580 SamplerArrayTest()
581 : TexCoordDrawTest(),
582 mTexture2DA(0),
583 mTexture2DB(0),
584 mTexture0UniformLocation(-1),
585 mTexture1UniformLocation(-1)
586 {
587 }
588
589 std::string getFragmentShaderSource() override
590 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300591 return
592 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200593 uniform highp sampler2D tex2DArray[2];
594 varying vec2 texcoord;
595 void main()
596 {
597 gl_FragColor = texture2D(tex2DArray[0], texcoord);
598 gl_FragColor += texture2D(tex2DArray[1], texcoord);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300599 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200600 }
601
602 void SetUp() override
603 {
604 TexCoordDrawTest::SetUp();
605
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300606 setUpProgram();
607
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200608 mTexture0UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[0]");
609 ASSERT_NE(-1, mTexture0UniformLocation);
610 mTexture1UniformLocation = glGetUniformLocation(mProgram, "tex2DArray[1]");
611 ASSERT_NE(-1, mTexture1UniformLocation);
612
613 mTexture2DA = create2DTexture();
614 mTexture2DB = create2DTexture();
615 ASSERT_GL_NO_ERROR();
616 }
617
618 void TearDown() override
619 {
620 glDeleteTextures(1, &mTexture2DA);
621 glDeleteTextures(1, &mTexture2DB);
622 TexCoordDrawTest::TearDown();
623 }
624
625 void testSamplerArrayDraw()
626 {
627 GLubyte texData[4];
628 texData[0] = 0;
629 texData[1] = 60;
630 texData[2] = 0;
631 texData[3] = 255;
632
633 glActiveTexture(GL_TEXTURE0);
634 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
635 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
636
637 texData[1] = 120;
638 glActiveTexture(GL_TEXTURE1);
639 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
640 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
641 EXPECT_GL_ERROR(GL_NO_ERROR);
642
643 glUseProgram(mProgram);
644 glUniform1i(mTexture0UniformLocation, 0);
645 glUniform1i(mTexture1UniformLocation, 1);
646 drawQuad(mProgram, "position", 0.5f);
647 EXPECT_GL_NO_ERROR();
648
649 EXPECT_PIXEL_NEAR(0, 0, 0, 180, 0, 255, 2);
650 }
651
652 GLuint mTexture2DA;
653 GLuint mTexture2DB;
654 GLint mTexture0UniformLocation;
655 GLint mTexture1UniformLocation;
656};
657
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200658class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest
659{
660 protected:
661 SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {}
662
663 std::string getFragmentShaderSource() override
664 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300665 return
666 R"(precision mediump float;
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200667 uniform highp sampler2D tex2DArray[2];
668 varying vec2 texcoord;
669
670 vec4 computeFragColor(highp sampler2D aTex2DArray[2])
671 {
672 return texture2D(aTex2DArray[0], texcoord) + texture2D(aTex2DArray[1], texcoord);
673 }
674
675 void main()
676 {
677 gl_FragColor = computeFragColor(tex2DArray);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300678 })";
Olli Etuaho2173db3d2016-01-12 13:55:14 +0200679 }
680};
681
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200682class Texture2DArrayTestES3 : public TexCoordDrawTest
683{
684 protected:
685 Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {}
686
687 std::string getVertexShaderSource() override
688 {
689 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400690 "#version 300 es\n"
691 "out vec2 texcoord;\n"
692 "in vec4 position;\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200693 "void main()\n"
694 "{\n"
695 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
696 " texcoord = (position.xy * 0.5) + 0.5;\n"
697 "}\n");
698 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400699
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200700 std::string getFragmentShaderSource() override
701 {
702 return std::string(
Jamie Madill2453dbc2015-07-14 11:35:42 -0400703 "#version 300 es\n"
704 "precision highp float;\n"
Olli Etuaho183d7e22015-11-20 15:59:09 +0200705 "uniform highp sampler2DArray tex2DArray;\n"
Jamie Madill2453dbc2015-07-14 11:35:42 -0400706 "in vec2 texcoord;\n"
707 "out vec4 fragColor;\n"
708 "void main()\n"
709 "{\n"
710 " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n"
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200711 "}\n");
712 }
Jamie Madill2453dbc2015-07-14 11:35:42 -0400713
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200714 void SetUp() override
715 {
716 TexCoordDrawTest::SetUp();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400717
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300718 setUpProgram();
719
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200720 mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray");
Jamie Madill2453dbc2015-07-14 11:35:42 -0400721 ASSERT_NE(-1, mTextureArrayLocation);
722
723 glGenTextures(1, &m2DArrayTexture);
724 ASSERT_GL_NO_ERROR();
725 }
726
727 void TearDown() override
728 {
729 glDeleteTextures(1, &m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +0200730 TexCoordDrawTest::TearDown();
Jamie Madill2453dbc2015-07-14 11:35:42 -0400731 }
732
733 GLuint m2DArrayTexture;
Jamie Madill2453dbc2015-07-14 11:35:42 -0400734 GLint mTextureArrayLocation;
735};
736
Olli Etuahobce743a2016-01-15 17:18:28 +0200737class TextureSizeTextureArrayTest : public TexCoordDrawTest
738{
739 protected:
740 TextureSizeTextureArrayTest()
741 : TexCoordDrawTest(),
742 mTexture2DA(0),
743 mTexture2DB(0),
744 mTexture0Location(-1),
745 mTexture1Location(-1)
746 {
747 }
748
749 std::string getVertexShaderSource() override
750 {
Olli Etuaho5804dc82018-04-13 14:11:46 +0300751 return std::string(essl3_shaders::vs::Simple());
Olli Etuahobce743a2016-01-15 17:18:28 +0200752 }
753
754 std::string getFragmentShaderSource() override
755 {
756 return std::string(
757 "#version 300 es\n"
758 "precision highp float;\n"
759 "uniform highp sampler2D tex2DArray[2];\n"
760 "out vec4 fragColor;\n"
761 "void main()\n"
762 "{\n"
763 " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n"
764 " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n"
765 " fragColor = vec4(red, green, 0.0, 1.0);\n"
766 "}\n");
767 }
768
769 void SetUp() override
770 {
771 TexCoordDrawTest::SetUp();
772
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300773 setUpProgram();
774
Olli Etuahobce743a2016-01-15 17:18:28 +0200775 mTexture0Location = glGetUniformLocation(mProgram, "tex2DArray[0]");
776 ASSERT_NE(-1, mTexture0Location);
777 mTexture1Location = glGetUniformLocation(mProgram, "tex2DArray[1]");
778 ASSERT_NE(-1, mTexture1Location);
779
780 mTexture2DA = create2DTexture();
781 mTexture2DB = create2DTexture();
782 ASSERT_GL_NO_ERROR();
783 }
784
785 void TearDown() override
786 {
787 glDeleteTextures(1, &mTexture2DA);
788 glDeleteTextures(1, &mTexture2DB);
789 TexCoordDrawTest::TearDown();
790 }
791
792 GLuint mTexture2DA;
793 GLuint mTexture2DB;
794 GLint mTexture0Location;
795 GLint mTexture1Location;
796};
797
Olli Etuahoa314b612016-03-10 16:43:00 +0200798class Texture3DTestES3 : public TexCoordDrawTest
799{
800 protected:
801 Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {}
802
803 std::string getVertexShaderSource() override
804 {
805 return std::string(
806 "#version 300 es\n"
807 "out vec2 texcoord;\n"
808 "in vec4 position;\n"
809 "void main()\n"
810 "{\n"
811 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
812 " texcoord = (position.xy * 0.5) + 0.5;\n"
813 "}\n");
814 }
815
816 std::string getFragmentShaderSource() override
817 {
818 return std::string(
819 "#version 300 es\n"
820 "precision highp float;\n"
821 "uniform highp sampler3D tex3D;\n"
822 "in vec2 texcoord;\n"
823 "out vec4 fragColor;\n"
824 "void main()\n"
825 "{\n"
826 " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n"
827 "}\n");
828 }
829
830 void SetUp() override
831 {
832 TexCoordDrawTest::SetUp();
833
834 glGenTextures(1, &mTexture3D);
835
836 setUpProgram();
837
838 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
839 ASSERT_NE(-1, mTexture3DUniformLocation);
840 }
841
842 void TearDown() override
843 {
844 glDeleteTextures(1, &mTexture3D);
845 TexCoordDrawTest::TearDown();
846 }
847
848 GLuint mTexture3D;
849 GLint mTexture3DUniformLocation;
850};
851
Olli Etuaho1a679902016-01-14 12:21:47 +0200852class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest
853{
854 protected:
855 ShadowSamplerPlusSampler3DTestES3()
856 : TexCoordDrawTest(),
857 mTextureShadow(0),
858 mTexture3D(0),
859 mTextureShadowUniformLocation(-1),
860 mTexture3DUniformLocation(-1),
861 mDepthRefUniformLocation(-1)
862 {
863 }
864
865 std::string getVertexShaderSource() override
866 {
867 return std::string(
868 "#version 300 es\n"
869 "out vec2 texcoord;\n"
870 "in vec4 position;\n"
871 "void main()\n"
872 "{\n"
873 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
874 " texcoord = (position.xy * 0.5) + 0.5;\n"
875 "}\n");
876 }
877
878 std::string getFragmentShaderSource() override
879 {
880 return std::string(
881 "#version 300 es\n"
882 "precision highp float;\n"
883 "uniform highp sampler2DShadow tex2DShadow;\n"
884 "uniform highp sampler3D tex3D;\n"
885 "in vec2 texcoord;\n"
886 "uniform float depthRef;\n"
887 "out vec4 fragColor;\n"
888 "void main()\n"
889 "{\n"
890 " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n"
891 " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n"
892 "}\n");
893 }
894
895 void SetUp() override
896 {
897 TexCoordDrawTest::SetUp();
898
899 glGenTextures(1, &mTexture3D);
900
901 glGenTextures(1, &mTextureShadow);
902 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
904
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300905 setUpProgram();
906
Olli Etuaho1a679902016-01-14 12:21:47 +0200907 mTextureShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
908 ASSERT_NE(-1, mTextureShadowUniformLocation);
909 mTexture3DUniformLocation = glGetUniformLocation(mProgram, "tex3D");
910 ASSERT_NE(-1, mTexture3DUniformLocation);
911 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
912 ASSERT_NE(-1, mDepthRefUniformLocation);
913 }
914
915 void TearDown() override
916 {
917 glDeleteTextures(1, &mTextureShadow);
918 glDeleteTextures(1, &mTexture3D);
919 TexCoordDrawTest::TearDown();
920 }
921
922 GLuint mTextureShadow;
923 GLuint mTexture3D;
924 GLint mTextureShadowUniformLocation;
925 GLint mTexture3DUniformLocation;
926 GLint mDepthRefUniformLocation;
927};
928
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200929class SamplerTypeMixTestES3 : public TexCoordDrawTest
930{
931 protected:
932 SamplerTypeMixTestES3()
933 : TexCoordDrawTest(),
934 mTexture2D(0),
935 mTextureCube(0),
936 mTexture2DShadow(0),
937 mTextureCubeShadow(0),
938 mTexture2DUniformLocation(-1),
939 mTextureCubeUniformLocation(-1),
940 mTexture2DShadowUniformLocation(-1),
941 mTextureCubeShadowUniformLocation(-1),
942 mDepthRefUniformLocation(-1)
943 {
944 }
945
946 std::string getVertexShaderSource() override
947 {
948 return std::string(
949 "#version 300 es\n"
950 "out vec2 texcoord;\n"
951 "in vec4 position;\n"
952 "void main()\n"
953 "{\n"
954 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
955 " texcoord = (position.xy * 0.5) + 0.5;\n"
956 "}\n");
957 }
958
959 std::string getFragmentShaderSource() override
960 {
961 return std::string(
962 "#version 300 es\n"
963 "precision highp float;\n"
964 "uniform highp sampler2D tex2D;\n"
965 "uniform highp samplerCube texCube;\n"
966 "uniform highp sampler2DShadow tex2DShadow;\n"
967 "uniform highp samplerCubeShadow texCubeShadow;\n"
968 "in vec2 texcoord;\n"
969 "uniform float depthRef;\n"
970 "out vec4 fragColor;\n"
971 "void main()\n"
972 "{\n"
973 " fragColor = texture(tex2D, texcoord);\n"
974 " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n"
975 " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n"
976 " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * "
977 "0.125);\n"
978 "}\n");
979 }
980
981 void SetUp() override
982 {
983 TexCoordDrawTest::SetUp();
984
985 glGenTextures(1, &mTexture2D);
986 glGenTextures(1, &mTextureCube);
987
988 glGenTextures(1, &mTexture2DShadow);
989 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
990 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
991
992 glGenTextures(1, &mTextureCubeShadow);
993 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
994 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
995
Olli Etuahoa1c917f2016-04-06 13:50:03 +0300996 setUpProgram();
997
Olli Etuahoc8c99a02016-01-14 16:47:22 +0200998 mTexture2DUniformLocation = glGetUniformLocation(mProgram, "tex2D");
999 ASSERT_NE(-1, mTexture2DUniformLocation);
1000 mTextureCubeUniformLocation = glGetUniformLocation(mProgram, "texCube");
1001 ASSERT_NE(-1, mTextureCubeUniformLocation);
1002 mTexture2DShadowUniformLocation = glGetUniformLocation(mProgram, "tex2DShadow");
1003 ASSERT_NE(-1, mTexture2DShadowUniformLocation);
1004 mTextureCubeShadowUniformLocation = glGetUniformLocation(mProgram, "texCubeShadow");
1005 ASSERT_NE(-1, mTextureCubeShadowUniformLocation);
1006 mDepthRefUniformLocation = glGetUniformLocation(mProgram, "depthRef");
1007 ASSERT_NE(-1, mDepthRefUniformLocation);
1008
1009 ASSERT_GL_NO_ERROR();
1010 }
1011
1012 void TearDown() override
1013 {
1014 glDeleteTextures(1, &mTexture2D);
1015 glDeleteTextures(1, &mTextureCube);
1016 glDeleteTextures(1, &mTexture2DShadow);
1017 glDeleteTextures(1, &mTextureCubeShadow);
1018 TexCoordDrawTest::TearDown();
1019 }
1020
1021 GLuint mTexture2D;
1022 GLuint mTextureCube;
1023 GLuint mTexture2DShadow;
1024 GLuint mTextureCubeShadow;
1025 GLint mTexture2DUniformLocation;
1026 GLint mTextureCubeUniformLocation;
1027 GLint mTexture2DShadowUniformLocation;
1028 GLint mTextureCubeShadowUniformLocation;
1029 GLint mDepthRefUniformLocation;
1030};
1031
Olli Etuaho96963162016-03-21 11:54:33 +02001032class SamplerInStructTest : public Texture2DTest
1033{
1034 protected:
1035 SamplerInStructTest() : Texture2DTest() {}
1036
1037 const char *getTextureUniformName() override { return "us.tex"; }
1038
1039 std::string getFragmentShaderSource() override
1040 {
1041 return std::string(
1042 "precision highp float;\n"
1043 "struct S\n"
1044 "{\n"
1045 " vec4 a;\n"
1046 " highp sampler2D tex;\n"
1047 "};\n"
1048 "uniform S us;\n"
1049 "varying vec2 texcoord;\n"
1050 "void main()\n"
1051 "{\n"
1052 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n"
1053 "}\n");
1054 }
1055
1056 void runSamplerInStructTest()
1057 {
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001058 setUpProgram();
1059
Olli Etuaho96963162016-03-21 11:54:33 +02001060 glActiveTexture(GL_TEXTURE0);
1061 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001062 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1063 &GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001064 drawQuad(mProgram, "position", 0.5f);
Olli Etuahoa314b612016-03-10 16:43:00 +02001065 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuaho96963162016-03-21 11:54:33 +02001066 }
1067};
1068
1069class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest
1070{
1071 protected:
1072 SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {}
1073
1074 std::string getFragmentShaderSource() override
1075 {
1076 return std::string(
1077 "precision highp float;\n"
1078 "struct S\n"
1079 "{\n"
1080 " vec4 a;\n"
1081 " highp sampler2D tex;\n"
1082 "};\n"
1083 "uniform S us;\n"
1084 "varying vec2 texcoord;\n"
1085 "vec4 sampleFrom(S s) {\n"
1086 " return texture2D(s.tex, texcoord + s.a.x);\n"
1087 "}\n"
1088 "void main()\n"
1089 "{\n"
1090 " gl_FragColor = sampleFrom(us);\n"
1091 "}\n");
1092 }
1093};
1094
1095class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest
1096{
1097 protected:
1098 SamplerInStructArrayAsFunctionParameterTest() : SamplerInStructTest() {}
1099
1100 const char *getTextureUniformName() override { return "us[0].tex"; }
1101
1102 std::string getFragmentShaderSource() override
1103 {
1104 return std::string(
1105 "precision highp float;\n"
1106 "struct S\n"
1107 "{\n"
1108 " vec4 a;\n"
1109 " highp sampler2D tex;\n"
1110 "};\n"
1111 "uniform S us[1];\n"
1112 "varying vec2 texcoord;\n"
1113 "vec4 sampleFrom(S s) {\n"
1114 " return texture2D(s.tex, texcoord + s.a.x);\n"
1115 "}\n"
1116 "void main()\n"
1117 "{\n"
1118 " gl_FragColor = sampleFrom(us[0]);\n"
1119 "}\n");
1120 }
1121};
1122
1123class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest
1124{
1125 protected:
1126 SamplerInNestedStructAsFunctionParameterTest() : SamplerInStructTest() {}
1127
1128 const char *getTextureUniformName() override { return "us[0].sub.tex"; }
1129
1130 std::string getFragmentShaderSource() override
1131 {
1132 return std::string(
1133 "precision highp float;\n"
1134 "struct SUB\n"
1135 "{\n"
1136 " vec4 a;\n"
1137 " highp sampler2D tex;\n"
1138 "};\n"
1139 "struct S\n"
1140 "{\n"
1141 " SUB sub;\n"
1142 "};\n"
1143 "uniform S us[1];\n"
1144 "varying vec2 texcoord;\n"
1145 "vec4 sampleFrom(SUB s) {\n"
1146 " return texture2D(s.tex, texcoord + s.a.x);\n"
1147 "}\n"
1148 "void main()\n"
1149 "{\n"
1150 " gl_FragColor = sampleFrom(us[0].sub);\n"
1151 "}\n");
1152 }
1153};
1154
1155class SamplerInStructAndOtherVariableTest : public SamplerInStructTest
1156{
1157 protected:
1158 SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {}
1159
1160 std::string getFragmentShaderSource() override
1161 {
1162 return std::string(
1163 "precision highp float;\n"
1164 "struct S\n"
1165 "{\n"
1166 " vec4 a;\n"
1167 " highp sampler2D tex;\n"
1168 "};\n"
1169 "uniform S us;\n"
1170 "uniform float us_tex;\n"
1171 "varying vec2 texcoord;\n"
1172 "void main()\n"
1173 "{\n"
1174 " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n"
1175 "}\n");
1176 }
1177};
1178
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001179TEST_P(Texture2DTest, NegativeAPISubImage)
Jamie Madillf67115c2014-04-22 13:14:05 -04001180{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001181 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Jamie Madillf67115c2014-04-22 13:14:05 -04001182 EXPECT_GL_ERROR(GL_NO_ERROR);
1183
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001184 setUpProgram();
1185
Jamie Madill50cf2be2018-06-15 09:46:57 -04001186 const GLubyte *pixels[20] = {0};
Jamie Madillf67115c2014-04-22 13:14:05 -04001187 glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1188 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Langc51642b2016-11-14 16:18:26 -05001189
1190 if (extensionEnabled("GL_EXT_texture_storage"))
1191 {
1192 // Create a 1-level immutable texture.
1193 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2);
1194
1195 // Try calling sub image on the second level.
1196 glTexSubImage2D(GL_TEXTURE_2D, 1, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1197 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1198 }
Jamie Madillf67115c2014-04-22 13:14:05 -04001199}
Geoff Langc41e42d2014-04-28 10:58:16 -04001200
John Bauman18319182016-09-28 14:22:27 -07001201// Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error.
1202TEST_P(Texture2DTest, QueryBinding)
1203{
1204 glBindTexture(GL_TEXTURE_2D, 0);
1205 EXPECT_GL_ERROR(GL_NO_ERROR);
1206
1207 GLint textureBinding;
1208 glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
1209 EXPECT_GL_NO_ERROR();
1210 EXPECT_EQ(0, textureBinding);
1211
1212 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &textureBinding);
1213 if (extensionEnabled("GL_OES_EGL_image_external") ||
1214 extensionEnabled("GL_NV_EGL_stream_consumer_external"))
1215 {
1216 EXPECT_GL_NO_ERROR();
1217 EXPECT_EQ(0, textureBinding);
1218 }
1219 else
1220 {
1221 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1222 }
1223}
1224
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001225TEST_P(Texture2DTest, ZeroSizedUploads)
Geoff Langc41e42d2014-04-28 10:58:16 -04001226{
Jamie Madilld4cfa572014-07-08 10:00:32 -04001227 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Geoff Langc41e42d2014-04-28 10:58:16 -04001228 EXPECT_GL_ERROR(GL_NO_ERROR);
1229
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001230 setUpProgram();
1231
Geoff Langc41e42d2014-04-28 10:58:16 -04001232 // Use the texture first to make sure it's in video memory
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001233 glUseProgram(mProgram);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001234 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001235 drawQuad(mProgram, "position", 0.5f);
Geoff Langc41e42d2014-04-28 10:58:16 -04001236
Jamie Madill50cf2be2018-06-15 09:46:57 -04001237 const GLubyte *pixel[4] = {0};
Geoff Langc41e42d2014-04-28 10:58:16 -04001238
1239 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1240 EXPECT_GL_NO_ERROR();
1241
1242 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1243 EXPECT_GL_NO_ERROR();
1244
1245 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1246 EXPECT_GL_NO_ERROR();
1247}
Jamie Madilld4cfa572014-07-08 10:00:32 -04001248
1249// Test drawing with two texture types, to trigger an ANGLE bug in validation
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001250TEST_P(TextureCubeTest, CubeMapBug)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001251{
1252 glActiveTexture(GL_TEXTURE0);
1253 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1254 glActiveTexture(GL_TEXTURE1);
1255 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1256 EXPECT_GL_ERROR(GL_NO_ERROR);
1257
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001258 glUseProgram(mProgram);
1259 glUniform1i(mTexture2DUniformLocation, 0);
1260 glUniform1i(mTextureCubeUniformLocation, 1);
1261 drawQuad(mProgram, "position", 0.5f);
Jamie Madilld4cfa572014-07-08 10:00:32 -04001262 EXPECT_GL_NO_ERROR();
1263}
Jamie Madill9aca0592014-10-06 16:26:59 -04001264
Olli Etuaho53a2da12016-01-11 15:43:32 +02001265// Test drawing with two texture types accessed from the same shader and check that the result of
1266// drawing is correct.
1267TEST_P(TextureCubeTest, CubeMapDraw)
1268{
1269 GLubyte texData[4];
1270 texData[0] = 0;
1271 texData[1] = 60;
1272 texData[2] = 0;
1273 texData[3] = 255;
1274
1275 glActiveTexture(GL_TEXTURE0);
1276 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1277 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1278
1279 glActiveTexture(GL_TEXTURE1);
1280 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
1281 texData[1] = 120;
1282 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1283 texData);
1284 EXPECT_GL_ERROR(GL_NO_ERROR);
1285
1286 glUseProgram(mProgram);
1287 glUniform1i(mTexture2DUniformLocation, 0);
1288 glUniform1i(mTextureCubeUniformLocation, 1);
1289 drawQuad(mProgram, "position", 0.5f);
1290 EXPECT_GL_NO_ERROR();
1291
1292 int px = getWindowWidth() - 1;
1293 int py = 0;
1294 EXPECT_PIXEL_NEAR(px, py, 0, 180, 0, 255, 2);
1295}
1296
Olli Etuaho4644a202016-01-12 15:12:53 +02001297TEST_P(Sampler2DAsFunctionParameterTest, Sampler2DAsFunctionParameter)
1298{
1299 glActiveTexture(GL_TEXTURE0);
1300 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1301 GLubyte texData[4];
1302 texData[0] = 0;
1303 texData[1] = 128;
1304 texData[2] = 0;
1305 texData[3] = 255;
1306 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texData);
1307 glUseProgram(mProgram);
1308 glUniform1i(mTexture2DUniformLocation, 0);
1309 drawQuad(mProgram, "position", 0.5f);
1310 EXPECT_GL_NO_ERROR();
1311
1312 EXPECT_PIXEL_NEAR(0, 0, 0, 128, 0, 255, 2);
1313}
1314
Olli Etuaho2173db3d2016-01-12 13:55:14 +02001315// Test drawing with two textures passed to the shader in a sampler array.
1316TEST_P(SamplerArrayTest, SamplerArrayDraw)
1317{
1318 testSamplerArrayDraw();
1319}
1320
1321// Test drawing with two textures passed to the shader in a sampler array which is passed to a
1322// user-defined function in the shader.
1323TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter)
1324{
1325 testSamplerArrayDraw();
1326}
1327
Jamie Madill9aca0592014-10-06 16:26:59 -04001328// Copy of a test in conformance/textures/texture-mips, to test generate mipmaps
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001329TEST_P(Texture2DTestWithDrawScale, MipmapsTwice)
Jamie Madill9aca0592014-10-06 16:26:59 -04001330{
Luc Ferronaf883622018-06-08 15:57:31 -04001331 // TODO(lucferron): Diagnose and fix
1332 // http://anglebug.com/2653
1333 ANGLE_SKIP_TEST_IF(IsVulkan());
1334
Jamie Madill9aca0592014-10-06 16:26:59 -04001335 int px = getWindowWidth() / 2;
1336 int py = getWindowHeight() / 2;
1337
1338 glActiveTexture(GL_TEXTURE0);
1339 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1340
Olli Etuahoa314b612016-03-10 16:43:00 +02001341 std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001342
Olli Etuahoa314b612016-03-10 16:43:00 +02001343 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1346 glGenerateMipmap(GL_TEXTURE_2D);
1347
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001348 glUseProgram(mProgram);
Jamie Madill9aca0592014-10-06 16:26:59 -04001349 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001350 glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f);
1351 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001352 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001353 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red);
Jamie Madill9aca0592014-10-06 16:26:59 -04001354
Olli Etuahoa314b612016-03-10 16:43:00 +02001355 std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue);
Jamie Madill9aca0592014-10-06 16:26:59 -04001356
Olli Etuahoa314b612016-03-10 16:43:00 +02001357 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1358 pixelsBlue.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001359 glGenerateMipmap(GL_TEXTURE_2D);
1360
Olli Etuahoa314b612016-03-10 16:43:00 +02001361 std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001362
Olli Etuahoa314b612016-03-10 16:43:00 +02001363 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1364 pixelsGreen.data());
Jamie Madill9aca0592014-10-06 16:26:59 -04001365 glGenerateMipmap(GL_TEXTURE_2D);
1366
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001367 drawQuad(mProgram, "position", 0.5f);
Jamie Madill9aca0592014-10-06 16:26:59 -04001368
1369 EXPECT_GL_NO_ERROR();
Olli Etuahoa314b612016-03-10 16:43:00 +02001370 EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green);
Jamie Madill9aca0592014-10-06 16:26:59 -04001371}
Jamie Madillf8fccb32014-11-12 15:05:26 -05001372
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001373// Test creating a FBO with a cube map render target, to test an ANGLE bug
1374// https://code.google.com/p/angleproject/issues/detail?id=849
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001375TEST_P(TextureCubeTest, CubeMapFBO)
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001376{
Luc Ferronaf883622018-06-08 15:57:31 -04001377 // TODO(jmadill): Cube map render targets. http://anglebug.com/2470
1378 ANGLE_SKIP_TEST_IF(IsVulkan());
1379
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001380 GLuint fbo;
1381 glGenFramebuffers(1, &fbo);
1382 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1383
1384 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
Jamie Madill50cf2be2018-06-15 09:46:57 -04001385 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
1386 mTextureCube, 0);
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001387
Corentin Wallez322653b2015-06-17 18:33:56 +02001388 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
Jamie Madilleb32a2e2014-12-10 14:27:53 -05001389
1390 glDeleteFramebuffers(1, &fbo);
1391
1392 EXPECT_GL_NO_ERROR();
1393}
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001394
Jamie Madill50cf2be2018-06-15 09:46:57 -04001395// Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a
1396// default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001397TEST_P(Texture2DTest, TexStorage)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001398{
Luc Ferron7348fc52018-05-09 07:17:16 -04001399 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage"));
Geoff Langc4e93662017-05-01 10:45:59 -04001400
Jamie Madill50cf2be2018-06-15 09:46:57 -04001401 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001402 int height = getWindowHeight();
1403
1404 GLuint tex2D;
1405 glGenTextures(1, &tex2D);
1406 glActiveTexture(GL_TEXTURE0);
1407 glBindTexture(GL_TEXTURE_2D, tex2D);
1408
1409 // Fill with red
1410 std::vector<GLubyte> pixels(3 * 16 * 16);
1411 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1412 {
1413 pixels[pixelId * 3 + 0] = 255;
1414 pixels[pixelId * 3 + 1] = 0;
1415 pixels[pixelId * 3 + 2] = 0;
1416 }
1417
1418 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001419 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1420 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
Geoff Langc4e93662017-05-01 10:45:59 -04001421 if (getClientMajorVersion() >= 3)
1422 {
1423 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1424 }
1425 else
1426 {
1427 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1428 }
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001429
1430 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1431 // glTexSubImage2D should take into account that the image is dirty.
1432 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());
1433 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1434 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1435
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001436 setUpProgram();
1437
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001438 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001439 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001440 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001441 glDeleteTextures(1, &tex2D);
1442 EXPECT_GL_NO_ERROR();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001443 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
Geoff Langfbfa47c2015-03-31 11:26:00 -04001444
1445 // Validate that the region of the texture without data has an alpha of 1.0
Jamie Madill05b35b22017-10-03 09:01:44 -04001446 angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4);
1447 EXPECT_EQ(255, pixel.A);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001448}
1449
Jamie Madill50cf2be2018-06-15 09:46:57 -04001450// Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has
1451// initialized the image with a default color.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001452TEST_P(Texture2DTest, TexStorageWithPBO)
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001453{
1454 if (extensionEnabled("NV_pixel_buffer_object"))
1455 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04001456 int width = getWindowWidth();
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001457 int height = getWindowHeight();
1458
1459 GLuint tex2D;
1460 glGenTextures(1, &tex2D);
1461 glActiveTexture(GL_TEXTURE0);
1462 glBindTexture(GL_TEXTURE_2D, tex2D);
1463
1464 // Fill with red
1465 std::vector<GLubyte> pixels(3 * 16 * 16);
1466 for (size_t pixelId = 0; pixelId < 16 * 16; ++pixelId)
1467 {
1468 pixels[pixelId * 3 + 0] = 255;
1469 pixels[pixelId * 3 + 1] = 0;
1470 pixels[pixelId * 3 + 2] = 0;
1471 }
1472
1473 // Read 16x16 region from red backbuffer to PBO
1474 GLuint pbo;
1475 glGenBuffers(1, &pbo);
1476 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
1477 glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * 16 * 16, pixels.data(), GL_STATIC_DRAW);
1478
1479 // ANGLE internally uses RGBA as the DirectX format for RGB images
Jamie Madill50cf2be2018-06-15 09:46:57 -04001480 // therefore glTexStorage2DEXT initializes the image to a default color to get a consistent
1481 // alpha color. The data is kept in a CPU-side image and the image is marked as dirty.
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001482 glTexStorage2DEXT(GL_TEXTURE_2D, 1, GL_RGB8, 16, 16);
1483
1484 // Initializes the color of the upper-left 8x8 pixels, leaves the other pixels untouched.
1485 // glTexSubImage2D should take into account that the image is dirty.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001486 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1489
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001490 setUpProgram();
1491
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001492 glUseProgram(mProgram);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001493 glUniform1i(mTexture2DUniformLocation, 0);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001494 drawQuad(mProgram, "position", 0.5f);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001495 glDeleteTextures(1, &tex2D);
Olli Etuaho19d48db2016-01-13 14:43:21 +02001496 glDeleteBuffers(1, &pbo);
Gregoire Payen de La Garanderie88fe1ad2015-01-19 15:09:26 +00001497 EXPECT_GL_NO_ERROR();
1498 EXPECT_PIXEL_EQ(3 * width / 4, 3 * height / 4, 0, 0, 0, 255);
1499 EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255);
1500 }
1501}
Jamie Madillbc393df2015-01-29 13:46:07 -05001502
1503// See description on testFloatCopySubImage
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001504TEST_P(Texture2DTest, CopySubImageFloat_R_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001505{
1506 testFloatCopySubImage(1, 1);
1507}
1508
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001509TEST_P(Texture2DTest, CopySubImageFloat_RG_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001510{
1511 testFloatCopySubImage(2, 1);
1512}
1513
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001514TEST_P(Texture2DTest, CopySubImageFloat_RG_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001515{
1516 testFloatCopySubImage(2, 2);
1517}
1518
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001519TEST_P(Texture2DTest, CopySubImageFloat_RGB_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001520{
1521 testFloatCopySubImage(3, 1);
1522}
1523
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001524TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001525{
1526 testFloatCopySubImage(3, 2);
1527}
1528
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001529TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001530{
Yunchao He9550c602018-02-13 14:47:05 +08001531 // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346)
1532 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04001533
Yunchao He9550c602018-02-13 14:47:05 +08001534 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1535 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001536
Jamie Madillbc393df2015-01-29 13:46:07 -05001537 testFloatCopySubImage(3, 3);
1538}
1539
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001540TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R)
Jamie Madillbc393df2015-01-29 13:46:07 -05001541{
1542 testFloatCopySubImage(4, 1);
1543}
1544
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001545TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG)
Jamie Madillbc393df2015-01-29 13:46:07 -05001546{
1547 testFloatCopySubImage(4, 2);
1548}
1549
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001550TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB)
Jamie Madillbc393df2015-01-29 13:46:07 -05001551{
Yunchao He9550c602018-02-13 14:47:05 +08001552 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1553 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001554
Jamie Madillbc393df2015-01-29 13:46:07 -05001555 testFloatCopySubImage(4, 3);
1556}
1557
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001558TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA)
Jamie Madillbc393df2015-01-29 13:46:07 -05001559{
Luc Ferronf786b702018-07-10 11:01:43 -04001560 // TODO(lucferron): This test fails only on linux and intel.
1561 // http://anglebug.com/2726
1562 ANGLE_SKIP_TEST_IF(IsVulkan() && IsLinux() && IsIntel());
1563
Yunchao He9550c602018-02-13 14:47:05 +08001564 // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284)
1565 ANGLE_SKIP_TEST_IF(IsD3D11_FL93());
Austin Kinrossd544cc92016-01-11 15:26:42 -08001566
Jamie Madillbc393df2015-01-29 13:46:07 -05001567 testFloatCopySubImage(4, 4);
1568}
Austin Kinross07285142015-03-26 11:36:16 -07001569
Jamie Madill50cf2be2018-06-15 09:46:57 -04001570// Port of
1571// https://www.khronos.org/registry/webgl/conformance-suites/1.0.3/conformance/textures/texture-npot.html
1572// Run against GL_ALPHA/UNSIGNED_BYTE format, to ensure that D3D11 Feature Level 9_3 correctly
1573// handles GL_ALPHA
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001574TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE)
Austin Kinross07285142015-03-26 11:36:16 -07001575{
1576 const int npotTexSize = 5;
Jamie Madill50cf2be2018-06-15 09:46:57 -04001577 const int potTexSize = 4; // Should be less than npotTexSize
Austin Kinross07285142015-03-26 11:36:16 -07001578 GLuint tex2D;
1579
1580 if (extensionEnabled("GL_OES_texture_npot"))
1581 {
1582 // This test isn't applicable if texture_npot is enabled
1583 return;
1584 }
1585
Olli Etuahoa1c917f2016-04-06 13:50:03 +03001586 setUpProgram();
1587
Austin Kinross07285142015-03-26 11:36:16 -07001588 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1589
Austin Kinross5faa15b2016-01-11 13:32:48 -08001590 // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1.
1591 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1592
Austin Kinross07285142015-03-26 11:36:16 -07001593 glActiveTexture(GL_TEXTURE0);
1594 glGenTextures(1, &tex2D);
1595 glBindTexture(GL_TEXTURE_2D, tex2D);
1596
Till Rathmannc1551dc2018-08-15 17:04:49 +02001597 const std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize, 64);
Austin Kinross07285142015-03-26 11:36:16 -07001598
1599 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1601
1602 // Check that an NPOT texture not on level 0 generates INVALID_VALUE
Jamie Madill50cf2be2018-06-15 09:46:57 -04001603 glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1604 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001605 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1606
1607 // Check that an NPOT texture on level 0 succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001608 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA,
1609 GL_UNSIGNED_BYTE, pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001610 EXPECT_GL_NO_ERROR();
1611
1612 // Check that generateMipmap fails on NPOT
1613 glGenerateMipmap(GL_TEXTURE_2D);
1614 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1615
1616 // Check that nothing is drawn if filtering is not correct for NPOT
1617 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1618 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1620 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1621 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001622 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001623 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1624
1625 // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255
1626 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1627 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1628 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
1629 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001630 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001631 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255);
1632
1633 // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw
1634 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1635 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001636 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001637 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1638
1639 // Check that glTexImage2D for POT texture succeeds
Jamie Madill50cf2be2018-06-15 09:46:57 -04001640 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE,
1641 pixels.data());
Austin Kinross07285142015-03-26 11:36:16 -07001642 EXPECT_GL_NO_ERROR();
1643
1644 // Check that generateMipmap for an POT texture succeeds
1645 glGenerateMipmap(GL_TEXTURE_2D);
1646 EXPECT_GL_NO_ERROR();
1647
1648 // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw
1649 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1650 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1651 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1652 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1653 glClear(GL_COLOR_BUFFER_BIT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001654 drawQuad(mProgram, "position", 1.0f);
Austin Kinross07285142015-03-26 11:36:16 -07001655 EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64);
1656 EXPECT_GL_NO_ERROR();
1657}
Jamie Madillfa05f602015-05-07 13:47:11 -04001658
Austin Kinross08528e12015-10-07 16:24:40 -07001659// Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions.
1660// ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02001661TEST_P(Texture2DTest, NPOTSubImageParameters)
Austin Kinross08528e12015-10-07 16:24:40 -07001662{
1663 glActiveTexture(GL_TEXTURE0);
1664 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1665
1666 // Create an 8x8 (i.e. power-of-two) texture.
1667 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1668 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
1669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1670 glGenerateMipmap(GL_TEXTURE_2D);
1671
1672 // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture.
1673 // This should always work, even if GL_OES_texture_npot isn't active.
Geoff Langfb052642017-10-24 13:42:09 -04001674 std::array<GLColor, 3 * 3> data;
1675 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data());
Austin Kinross08528e12015-10-07 16:24:40 -07001676
1677 EXPECT_GL_NO_ERROR();
1678}
1679
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001680// Test to check that texture completeness is determined correctly when the texture base level is
1681// greater than 0, and also that level 0 is not sampled when base level is greater than 0.
1682TEST_P(Texture2DTestES3, DrawWithBaseLevel1)
1683{
1684 glActiveTexture(GL_TEXTURE0);
1685 glBindTexture(GL_TEXTURE_2D, mTexture2D);
Olli Etuahoa314b612016-03-10 16:43:00 +02001686
1687 std::vector<GLColor> texDataRed(4u * 4u, GLColor::red);
1688 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1689 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1690 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1691 texDataGreen.data());
1692 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1693 texDataGreen.data());
Olli Etuahoa7416ff2016-01-18 12:22:55 +02001694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1695 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1696 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1697
1698 EXPECT_GL_NO_ERROR();
1699
1700 drawQuad(mProgram, "position", 0.5f);
1701
Olli Etuahoa314b612016-03-10 16:43:00 +02001702 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1703}
1704
1705// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1706// have images defined.
1707TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined)
1708{
Yunchao He9550c602018-02-13 14:47:05 +08001709 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1710 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1711
Olli Etuahoa314b612016-03-10 16:43:00 +02001712 glActiveTexture(GL_TEXTURE0);
1713 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1714 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1715 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1716 texDataGreen.data());
1717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1721
1722 EXPECT_GL_NO_ERROR();
1723
1724 drawQuad(mProgram, "position", 0.5f);
1725
1726 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1727}
1728
Olli Etuahoe8528d82016-05-16 17:50:52 +03001729// Test that drawing works correctly when level 0 is undefined and base level is 1.
1730TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined)
1731{
Yunchao He9550c602018-02-13 14:47:05 +08001732 // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array.
1733 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
1734
Olli Etuahoe8528d82016-05-16 17:50:52 +03001735 glActiveTexture(GL_TEXTURE0);
1736 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1737 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1738 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1739 texDataGreen.data());
1740 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1741 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1742 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1744
1745 EXPECT_GL_NO_ERROR();
1746
1747 // Texture is incomplete.
1748 drawQuad(mProgram, "position", 0.5f);
1749 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1750
1751 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1752 texDataGreen.data());
1753
1754 // Texture is now complete.
1755 drawQuad(mProgram, "position", 0.5f);
1756 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1757}
1758
Olli Etuahoa314b612016-03-10 16:43:00 +02001759// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1760// dimensions that don't fit the images inside the range.
1761// GLES 3.0.4 section 3.8.13 Texture completeness
1762TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1763{
Olli Etuahoa314b612016-03-10 16:43:00 +02001764 glActiveTexture(GL_TEXTURE0);
1765 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1766 std::vector<GLColor> texDataRed(8u * 8u, GLColor::red);
1767 std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green);
1768 std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan);
1769
1770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1772
1773 // Two levels that are initially unused.
1774 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data());
1775 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1776 texDataCyan.data());
1777
1778 // One level that is used - only this level should affect completeness.
1779 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1780 texDataGreen.data());
1781
1782 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1783 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1784
1785 EXPECT_GL_NO_ERROR();
1786
1787 drawQuad(mProgram, "position", 0.5f);
1788
1789 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1790
Yunchao He2f23f352018-02-11 22:11:37 +08001791 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001792
1793 // Switch the level that is being used to the cyan level 2.
1794 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
1795 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
1796
1797 EXPECT_GL_NO_ERROR();
1798
1799 drawQuad(mProgram, "position", 0.5f);
1800
1801 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1802}
1803
1804// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1805// have images defined.
1806TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined)
1807{
Olli Etuahoa314b612016-03-10 16:43:00 +02001808 glActiveTexture(GL_TEXTURE0);
1809 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1810 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1811 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1812 texDataGreen.data());
1813 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1814 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1815 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1816 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1817
1818 EXPECT_GL_NO_ERROR();
1819
1820 drawQuad(mProgram, "position", 0.5f);
1821
1822 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1823}
1824
1825// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1826// dimensions that don't fit the images inside the range.
1827// GLES 3.0.4 section 3.8.13 Texture completeness
1828TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1829{
Olli Etuahoa314b612016-03-10 16:43:00 +02001830 glActiveTexture(GL_TEXTURE0);
1831 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1832 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1833 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1834 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1835
1836 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1837 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1838
1839 // Two levels that are initially unused.
1840 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1841 texDataRed.data());
1842 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1843 texDataCyan.data());
1844
1845 // One level that is used - only this level should affect completeness.
1846 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1847 texDataGreen.data());
1848
1849 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1);
1850 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
1851
1852 EXPECT_GL_NO_ERROR();
1853
1854 drawQuad(mProgram, "position", 0.5f);
1855
1856 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1857
Yunchao He2f23f352018-02-11 22:11:37 +08001858 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
Olli Etuahoa314b612016-03-10 16:43:00 +02001859
1860 // Switch the level that is being used to the cyan level 2.
1861 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2);
1862 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2);
1863
1864 EXPECT_GL_NO_ERROR();
1865
1866 drawQuad(mProgram, "position", 0.5f);
1867
1868 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1869}
1870
1871// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not
1872// have images defined.
1873TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined)
1874{
Olli Etuahoa314b612016-03-10 16:43:00 +02001875 glActiveTexture(GL_TEXTURE0);
1876 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
1877 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1878 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1879 texDataGreen.data());
1880 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1881 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1882 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1883 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1884
1885 EXPECT_GL_NO_ERROR();
1886
1887 drawQuad(mProgram, "position", 0.5f);
1888
1889 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1890}
1891
1892// Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have
1893// dimensions that don't fit the images inside the range.
1894// GLES 3.0.4 section 3.8.13 Texture completeness
1895TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions)
1896{
Olli Etuahoa314b612016-03-10 16:43:00 +02001897 glActiveTexture(GL_TEXTURE0);
1898 glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
1899 std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
1900 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1901 std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan);
1902
1903 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1904 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1905
1906 // Two levels that are initially unused.
1907 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1908 texDataRed.data());
1909 glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1910 texDataCyan.data());
1911
1912 // One level that is used - only this level should affect completeness.
1913 glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1914 texDataGreen.data());
1915
1916 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1);
1917 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1);
1918
1919 EXPECT_GL_NO_ERROR();
1920
1921 drawQuad(mProgram, "position", 0.5f);
1922
1923 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1924
Yunchao He2f23f352018-02-11 22:11:37 +08001925 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL());
1926
Yunchao He9550c602018-02-13 14:47:05 +08001927 // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base
1928 // level was changed.
1929 ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES()));
Olli Etuahoa314b612016-03-10 16:43:00 +02001930
1931 // Switch the level that is being used to the cyan level 2.
1932 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2);
1933 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2);
1934
1935 EXPECT_GL_NO_ERROR();
1936
1937 drawQuad(mProgram, "position", 0.5f);
1938
1939 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
1940}
1941
1942// Test that texture completeness is updated if texture max level changes.
1943// GLES 3.0.4 section 3.8.13 Texture completeness
1944TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel)
1945{
Olli Etuahoa314b612016-03-10 16:43:00 +02001946 glActiveTexture(GL_TEXTURE0);
1947 glBindTexture(GL_TEXTURE_2D, mTexture2D);
1948 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
1949
1950 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1951 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1952
1953 // A level that is initially unused.
1954 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1955 texDataGreen.data());
1956
1957 // One level that is initially used - only this level should affect completeness.
1958 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1959 texDataGreen.data());
1960
1961 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1963
1964 EXPECT_GL_NO_ERROR();
1965
1966 drawQuad(mProgram, "position", 0.5f);
1967
1968 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1969
1970 // Switch the max level to level 1. The levels within the used range now have inconsistent
1971 // dimensions and the texture should be incomplete.
1972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
1973
1974 EXPECT_GL_NO_ERROR();
1975
1976 drawQuad(mProgram, "position", 0.5f);
1977
1978 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
1979}
1980
1981// Test that 3D texture completeness is updated if texture max level changes.
1982// GLES 3.0.4 section 3.8.13 Texture completeness
1983TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel)
1984{
Olli Etuahoa314b612016-03-10 16:43:00 +02001985 glActiveTexture(GL_TEXTURE0);
1986 glBindTexture(GL_TEXTURE_3D, mTexture3D);
1987 std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green);
1988
1989 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1990 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
1991
1992 // A level that is initially unused.
1993 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1994 texDataGreen.data());
1995
1996 // One level that is initially used - only this level should affect completeness.
1997 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1998 texDataGreen.data());
1999
2000 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
2001 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2002
2003 EXPECT_GL_NO_ERROR();
2004
2005 drawQuad(mProgram, "position", 0.5f);
2006
2007 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2008
2009 // Switch the max level to level 1. The levels within the used range now have inconsistent
2010 // dimensions and the texture should be incomplete.
2011 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1);
2012
2013 EXPECT_GL_NO_ERROR();
2014
2015 drawQuad(mProgram, "position", 0.5f);
2016
2017 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2018}
2019
2020// Test that texture completeness is updated if texture base level changes.
2021// GLES 3.0.4 section 3.8.13 Texture completeness
2022TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel)
2023{
Olli Etuahoa314b612016-03-10 16:43:00 +02002024 glActiveTexture(GL_TEXTURE0);
2025 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2026 std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green);
2027
2028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2029 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2030
2031 // Two levels that are initially unused.
2032 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2033 texDataGreen.data());
2034 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2035 texDataGreen.data());
2036
2037 // One level that is initially used - only this level should affect completeness.
2038 glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2039 texDataGreen.data());
2040
2041 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
2042 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
2043
2044 EXPECT_GL_NO_ERROR();
2045
2046 drawQuad(mProgram, "position", 0.5f);
2047
2048 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2049
2050 // Switch the base level to level 1. The levels within the used range now have inconsistent
2051 // dimensions and the texture should be incomplete.
2052 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2053
2054 EXPECT_GL_NO_ERROR();
2055
2056 drawQuad(mProgram, "position", 0.5f);
2057
2058 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2059}
2060
2061// Test that texture is not complete if base level is greater than max level.
2062// GLES 3.0.4 section 3.8.13 Texture completeness
2063TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel)
2064{
Olli Etuahoa314b612016-03-10 16:43:00 +02002065 glActiveTexture(GL_TEXTURE0);
2066 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2067
2068 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2069 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2070
2071 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2072
2073 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2074 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2075
2076 EXPECT_GL_NO_ERROR();
2077
2078 drawQuad(mProgram, "position", 0.5f);
2079
2080 // Texture should be incomplete.
2081 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2082}
2083
2084// Test that immutable texture base level and max level are clamped.
2085// GLES 3.0.4 section 3.8.10 subsection Mipmapping
2086TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange)
2087{
Olli Etuahoa314b612016-03-10 16:43:00 +02002088 glActiveTexture(GL_TEXTURE0);
2089 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2090
2091 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2093
2094 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1);
2095
2096 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2097
2098 // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level
2099 // should be clamped to [base_level, levels - 1].
2100 // GLES 3.0.4 section 3.8.10 subsection Mipmapping
2101 // In the case of this test, those rules make the effective base level and max level 0.
2102 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2104
2105 EXPECT_GL_NO_ERROR();
2106
2107 drawQuad(mProgram, "position", 0.5f);
2108
2109 // Texture should be complete.
2110 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2111}
2112
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002113// Test that changing base level works when it affects the format of the texture.
2114TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel)
2115{
Yunchao He9550c602018-02-13 14:47:05 +08002116 // Observed rendering corruption on NVIDIA OpenGL.
2117 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL());
2118
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002119 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
Yunchao He9550c602018-02-13 14:47:05 +08002120
2121 // Observed incorrect rendering on AMD OpenGL.
2122 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL());
Olli Etuaho87fc71c2016-05-11 14:25:21 +03002123
2124 glActiveTexture(GL_TEXTURE0);
2125 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2126 std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan);
2127 std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green);
2128
2129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2131
2132 // RGBA8 level that's initially unused.
2133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2134 texDataCyan.data());
2135
2136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
2138
2139 // RG8 level that's initially used, with consistent dimensions with level 0 but a different
2140 // format. It reads green channel data from the green and alpha channels of texDataGreen
2141 // (this is a bit hacky but works).
2142 glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data());
2143
2144 EXPECT_GL_NO_ERROR();
2145
2146 drawQuad(mProgram, "position", 0.5f);
2147
2148 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2149
2150 // Switch the texture to use the cyan level 0 with the RGBA format.
2151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
2153
2154 EXPECT_GL_NO_ERROR();
2155
2156 drawQuad(mProgram, "position", 0.5f);
2157
2158 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
2159}
2160
Olli Etuahoa314b612016-03-10 16:43:00 +02002161// Test that setting a texture image works when base level is out of range.
2162TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange)
2163{
2164 glActiveTexture(GL_TEXTURE0);
2165 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2166
2167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2168 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2169
2170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000);
2171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000);
2172
2173 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green);
2174
2175 EXPECT_GL_NO_ERROR();
2176
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
2178
2179 drawQuad(mProgram, "position", 0.5f);
2180
2181 // Texture should be complete.
2182 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Olli Etuahoa7416ff2016-01-18 12:22:55 +02002183}
2184
Jamie Madill50cf2be2018-06-15 09:46:57 -04002185// In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG
2186// RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures
2187// with these formats does not work as expected.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002188TEST_P(Texture2DArrayTestES3, RedefineInittableArray)
Jamie Madill2453dbc2015-07-14 11:35:42 -04002189{
2190 std::vector<GLubyte> pixelData;
2191 for (size_t count = 0; count < 5000; count++)
2192 {
2193 pixelData.push_back(0u);
2194 pixelData.push_back(255u);
2195 pixelData.push_back(0u);
2196 }
2197
2198 glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002199 glUseProgram(mProgram);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002200 glUniform1i(mTextureArrayLocation, 0);
2201
2202 // The first draw worked correctly.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002203 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2204 &pixelData[0]);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002205
2206 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2207 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2208 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
2209 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002210 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002211 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002212
2213 // The dimension of the respecification must match the original exactly to trigger the bug.
Jamie Madill50cf2be2018-06-15 09:46:57 -04002214 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE,
2215 &pixelData[0]);
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002216 drawQuad(mProgram, "position", 1.0f);
Olli Etuahoa314b612016-03-10 16:43:00 +02002217 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madill2453dbc2015-07-14 11:35:42 -04002218
2219 ASSERT_GL_NO_ERROR();
2220}
2221
Olli Etuaho1a679902016-01-14 12:21:47 +02002222// Test shadow sampler and regular non-shadow sampler coexisting in the same shader.
2223// This test is needed especially to confirm that sampler registers get assigned correctly on
2224// the HLSL backend even when there's a mix of different HLSL sampler and texture types.
2225TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw)
2226{
2227 glActiveTexture(GL_TEXTURE0);
2228 glBindTexture(GL_TEXTURE_3D, mTexture3D);
2229 GLubyte texData[4];
2230 texData[0] = 0;
2231 texData[1] = 60;
2232 texData[2] = 0;
2233 texData[3] = 255;
2234 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2235
2236 glActiveTexture(GL_TEXTURE1);
2237 glBindTexture(GL_TEXTURE_2D, mTextureShadow);
2238 GLfloat depthTexData[1];
2239 depthTexData[0] = 0.5f;
2240 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2241 depthTexData);
2242
2243 glUseProgram(mProgram);
2244 glUniform1f(mDepthRefUniformLocation, 0.3f);
2245 glUniform1i(mTexture3DUniformLocation, 0);
2246 glUniform1i(mTextureShadowUniformLocation, 1);
2247
2248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2249 drawQuad(mProgram, "position", 0.5f);
2250 EXPECT_GL_NO_ERROR();
2251 // The shader writes 0.5 * <comparison result (1.0)> + <texture color>
2252 EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2);
2253
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER);
2255 drawQuad(mProgram, "position", 0.5f);
2256 EXPECT_GL_NO_ERROR();
2257 // The shader writes 0.5 * <comparison result (0.0)> + <texture color>
2258 EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2);
2259}
2260
Olli Etuahoc8c99a02016-01-14 16:47:22 +02002261// Test multiple different sampler types in the same shader.
2262// This test makes sure that even if sampler / texture registers get grouped together based on type
2263// or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer
2264// still has the right register index information for each ESSL sampler.
2265// The tested ESSL samplers have the following types in D3D11 HLSL:
2266// sampler2D: Texture2D + SamplerState
2267// samplerCube: TextureCube + SamplerState
2268// sampler2DShadow: Texture2D + SamplerComparisonState
2269// samplerCubeShadow: TextureCube + SamplerComparisonState
2270TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
2271{
2272 glActiveTexture(GL_TEXTURE0);
2273 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2274 GLubyte texData[4];
2275 texData[0] = 0;
2276 texData[1] = 0;
2277 texData[2] = 120;
2278 texData[3] = 255;
2279 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
2280
2281 glActiveTexture(GL_TEXTURE1);
2282 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube);
2283 texData[0] = 0;
2284 texData[1] = 90;
2285 texData[2] = 0;
2286 texData[3] = 255;
2287 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1);
2288 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
2289 texData);
2290
2291 glActiveTexture(GL_TEXTURE2);
2292 glBindTexture(GL_TEXTURE_2D, mTexture2DShadow);
2293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2294 GLfloat depthTexData[1];
2295 depthTexData[0] = 0.5f;
2296 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT,
2297 depthTexData);
2298
2299 glActiveTexture(GL_TEXTURE3);
2300 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow);
2301 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
2302 depthTexData[0] = 0.2f;
2303 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1);
2304 glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
2305 depthTexData);
2306
2307 EXPECT_GL_NO_ERROR();
2308
2309 glUseProgram(mProgram);
2310 glUniform1f(mDepthRefUniformLocation, 0.3f);
2311 glUniform1i(mTexture2DUniformLocation, 0);
2312 glUniform1i(mTextureCubeUniformLocation, 1);
2313 glUniform1i(mTexture2DShadowUniformLocation, 2);
2314 glUniform1i(mTextureCubeShadowUniformLocation, 3);
2315
2316 drawQuad(mProgram, "position", 0.5f);
2317 EXPECT_GL_NO_ERROR();
2318 // The shader writes:
2319 // <texture 2d color> +
2320 // <cube map color> +
2321 // 0.25 * <comparison result (1.0)> +
2322 // 0.125 * <comparison result (0.0)>
2323 EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2);
2324}
2325
Olli Etuahobce743a2016-01-15 17:18:28 +02002326// Test different base levels on textures accessed through the same sampler array.
2327// Calling textureSize() on the samplers hits the D3D sampler metadata workaround.
2328TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray)
2329{
Yunchao He9550c602018-02-13 14:47:05 +08002330 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2331
Olli Etuahobce743a2016-01-15 17:18:28 +02002332 glActiveTexture(GL_TEXTURE0);
2333 glBindTexture(GL_TEXTURE_2D, mTexture2DA);
2334 GLsizei size = 64;
2335 for (GLint level = 0; level < 7; ++level)
2336 {
2337 ASSERT_LT(0, size);
2338 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2339 nullptr);
2340 size = size / 2;
2341 }
2342 ASSERT_EQ(0, size);
2343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
2344
2345 glActiveTexture(GL_TEXTURE1);
2346 glBindTexture(GL_TEXTURE_2D, mTexture2DB);
2347 size = 128;
2348 for (GLint level = 0; level < 8; ++level)
2349 {
2350 ASSERT_LT(0, size);
2351 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2352 nullptr);
2353 size = size / 2;
2354 }
2355 ASSERT_EQ(0, size);
2356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3);
2357 EXPECT_GL_NO_ERROR();
2358
2359 glUseProgram(mProgram);
2360 glUniform1i(mTexture0Location, 0);
2361 glUniform1i(mTexture1Location, 1);
2362
Olli Etuaho5804dc82018-04-13 14:11:46 +03002363 drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f);
Olli Etuahobce743a2016-01-15 17:18:28 +02002364 EXPECT_GL_NO_ERROR();
2365 // Red channel: width of level 1 of texture A: 32.
2366 // Green channel: width of level 3 of texture B: 16.
2367 EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2);
2368}
2369
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002370// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2371// ES 3.0.4 table 3.24
2372TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1)
2373{
2374 glActiveTexture(GL_TEXTURE0);
2375 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2376 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
2377 EXPECT_GL_NO_ERROR();
2378
2379 drawQuad(mProgram, "position", 0.5f);
2380
2381 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2382}
2383
2384// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2385// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002386TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002387{
Luc Ferron5164b792018-03-06 09:10:12 -05002388 setUpProgram();
2389
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002390 glActiveTexture(GL_TEXTURE0);
2391 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2392 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr);
2393 EXPECT_GL_NO_ERROR();
2394
2395 drawQuad(mProgram, "position", 0.5f);
2396
2397 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2398}
2399
Luc Ferron5164b792018-03-06 09:10:12 -05002400// Validate that every component of the pixel will be equal to the luminance value we've set
2401// and that the alpha channel will be 1 (or 255 to be exact).
2402TEST_P(Texture2DTest, TextureLuminanceRGBSame)
2403{
2404 setUpProgram();
2405
2406 glActiveTexture(GL_TEXTURE0);
2407 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2408 uint8_t pixel = 50;
2409 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel);
2410 EXPECT_GL_NO_ERROR();
2411
2412 drawQuad(mProgram, "position", 0.5f);
2413
2414 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255));
2415}
2416
2417// Validate that every component of the pixel will be equal to the luminance value we've set
2418// and that the alpha channel will be the second component.
2419TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame)
2420{
2421 setUpProgram();
2422
2423 glActiveTexture(GL_TEXTURE0);
2424 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2425 uint8_t pixel[] = {50, 25};
2426 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA,
2427 GL_UNSIGNED_BYTE, pixel);
2428 EXPECT_GL_NO_ERROR();
2429
2430 drawQuad(mProgram, "position", 0.5f);
2431
2432 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1]));
2433}
2434
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002435// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2436// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002437TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002438{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002439 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2440 ANGLE_SKIP_TEST_IF(IsD3D9());
2441 ANGLE_SKIP_TEST_IF(IsVulkan());
Luc Ferron5164b792018-03-06 09:10:12 -05002442
2443 setUpProgram();
2444
Luc Ferrond8c632c2018-04-10 12:31:44 -04002445 glActiveTexture(GL_TEXTURE0);
2446 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2447 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr);
2448 EXPECT_GL_NO_ERROR();
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002449
Luc Ferrond8c632c2018-04-10 12:31:44 -04002450 drawQuad(mProgram, "position", 0.5f);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002451
Luc Ferrond8c632c2018-04-10 12:31:44 -04002452 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002453}
2454
2455// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2456// ES 3.0.4 table 3.24
Luc Ferron5164b792018-03-06 09:10:12 -05002457TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1)
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002458{
Luc Ferrond8c632c2018-04-10 12:31:44 -04002459 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
2460 ANGLE_SKIP_TEST_IF(IsD3D9());
2461 ANGLE_SKIP_TEST_IF(IsVulkan());
2462 ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES());
2463 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed
2464 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Luc Ferron5164b792018-03-06 09:10:12 -05002465
Luc Ferrond8c632c2018-04-10 12:31:44 -04002466 setUpProgram();
Luc Ferron5164b792018-03-06 09:10:12 -05002467
Luc Ferrond8c632c2018-04-10 12:31:44 -04002468 glActiveTexture(GL_TEXTURE0);
2469 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2470 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr);
2471 EXPECT_GL_NO_ERROR();
Yunchao He9550c602018-02-13 14:47:05 +08002472
Luc Ferrond8c632c2018-04-10 12:31:44 -04002473 drawQuad(mProgram, "position", 0.5f);
Yuly Novikovafcec832016-06-21 22:19:51 -04002474
Luc Ferrond8c632c2018-04-10 12:31:44 -04002475 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002476}
2477
2478// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2479// ES 3.0.4 table 3.24
2480TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1)
2481{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002482 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2483
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002484 glActiveTexture(GL_TEXTURE0);
2485 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2486 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr);
2487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2489 EXPECT_GL_NO_ERROR();
2490
2491 drawQuad(mProgram, "position", 0.5f);
2492
2493 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2494}
2495
2496// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2497// ES 3.0.4 table 3.24
2498TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1)
2499{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002500 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2501
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002502 glActiveTexture(GL_TEXTURE0);
2503 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2504
2505 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr);
2506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2507 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2508 EXPECT_GL_NO_ERROR();
2509
2510 drawQuad(mProgram, "position", 0.5f);
2511
2512 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2513}
2514
2515// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2516// ES 3.0.4 table 3.24
2517TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1)
2518{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002519 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2520
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002521 glActiveTexture(GL_TEXTURE0);
2522 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2523 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr);
2524 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2525 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2526 EXPECT_GL_NO_ERROR();
2527
2528 drawQuad(mProgram, "position", 0.5f);
2529
2530 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2531}
2532
2533// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2534// ES 3.0.4 table 3.24
2535TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1)
2536{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002537 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2538
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002539 glActiveTexture(GL_TEXTURE0);
2540 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2541 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr);
2542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2544 EXPECT_GL_NO_ERROR();
2545
2546 drawQuad(mProgram, "position", 0.5f);
2547
2548 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2549}
2550
2551// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2552// ES 3.0.4 table 3.24
2553TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1)
2554{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002555 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2556
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002557 glActiveTexture(GL_TEXTURE0);
2558 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2559 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr);
2560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2562 EXPECT_GL_NO_ERROR();
2563
2564 drawQuad(mProgram, "position", 0.5f);
2565
2566 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2567}
2568
2569// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2570// ES 3.0.4 table 3.24
2571TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1)
2572{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08002573 ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX());
2574
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002575 glActiveTexture(GL_TEXTURE0);
2576 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2577 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr);
2578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2580 EXPECT_GL_NO_ERROR();
2581
2582 drawQuad(mProgram, "position", 0.5f);
2583
2584 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2585}
2586
2587// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2588// ES 3.0.4 table 3.24
2589TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1)
2590{
2591 glActiveTexture(GL_TEXTURE0);
2592 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2593 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr);
2594 EXPECT_GL_NO_ERROR();
2595
2596 drawQuad(mProgram, "position", 0.5f);
2597
2598 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2599}
2600
2601// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2602// ES 3.0.4 table 3.24
2603TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1)
2604{
2605 glActiveTexture(GL_TEXTURE0);
2606 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2607 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV,
2608 nullptr);
2609 EXPECT_GL_NO_ERROR();
2610
2611 drawQuad(mProgram, "position", 0.5f);
2612
2613 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2614}
2615
2616// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2617// ES 3.0.4 table 3.24
2618TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1)
2619{
Yunchao He9550c602018-02-13 14:47:05 +08002620 // Seems to fail on OSX 10.12 Intel.
2621 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Jamie Madillbb1db482017-01-10 10:48:32 -05002622
Yuly Novikov49886892018-01-23 21:18:27 -05002623 // http://anglebug.com/2190
2624 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2625
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002626 glActiveTexture(GL_TEXTURE0);
2627 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2628 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr);
2629 EXPECT_GL_NO_ERROR();
2630
2631 drawQuad(mProgram, "position", 0.5f);
2632
2633 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2634}
2635
2636// When sampling a texture without an alpha channel, "1" is returned as the alpha value.
2637// ES 3.0.4 table 3.24
2638TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1)
2639{
Yunchao He9550c602018-02-13 14:47:05 +08002640 // Seems to fail on OSX 10.12 Intel.
2641 ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL());
Corentin Wallez9e3c6152016-03-29 21:58:33 -04002642
Yuly Novikov49886892018-01-23 21:18:27 -05002643 // http://anglebug.com/2190
2644 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL());
2645
Olli Etuaho6ee394a2016-02-18 13:30:09 +02002646 glActiveTexture(GL_TEXTURE0);
2647 glBindTexture(GL_TEXTURE_2D, mTexture2D);
2648 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr);
2649 EXPECT_GL_NO_ERROR();
2650
2651 drawQuad(mProgram, "position", 0.5f);
2652
2653 EXPECT_PIXEL_ALPHA_EQ(0, 0, 255);
2654}
2655
Olli Etuaho96963162016-03-21 11:54:33 +02002656// Use a sampler in a uniform struct.
2657TEST_P(SamplerInStructTest, SamplerInStruct)
2658{
2659 runSamplerInStructTest();
2660}
2661
2662// Use a sampler in a uniform struct that's passed as a function parameter.
2663TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter)
2664{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002665 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002666 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Geoff Lang8fcdf6e2016-09-16 10:45:30 -04002667
Olli Etuaho96963162016-03-21 11:54:33 +02002668 runSamplerInStructTest();
2669}
2670
2671// Use a sampler in a uniform struct array with a struct from the array passed as a function
2672// parameter.
2673TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter)
2674{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002675 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002676 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2677
Olli Etuaho96963162016-03-21 11:54:33 +02002678 runSamplerInStructTest();
2679}
2680
2681// Use a sampler in a struct inside a uniform struct with the nested struct passed as a function
2682// parameter.
2683TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter)
2684{
Yuly Novikovad6c0452016-06-24 22:24:37 -04002685 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08002686 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
2687
Olli Etuaho96963162016-03-21 11:54:33 +02002688 runSamplerInStructTest();
2689}
2690
2691// Make sure that there isn't a name conflict between sampler extracted from a struct and a
2692// similarly named uniform.
2693TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable)
2694{
2695 runSamplerInStructTest();
2696}
2697
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002698class TextureLimitsTest : public ANGLETest
2699{
2700 protected:
2701 struct RGBA8
2702 {
2703 uint8_t R, G, B, A;
2704 };
2705
2706 TextureLimitsTest()
2707 : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0)
2708 {
2709 setWindowWidth(128);
2710 setWindowHeight(128);
2711 setConfigRedBits(8);
2712 setConfigGreenBits(8);
2713 setConfigBlueBits(8);
2714 setConfigAlphaBits(8);
2715 }
2716
2717 ~TextureLimitsTest()
2718 {
2719 if (mProgram != 0)
2720 {
2721 glDeleteProgram(mProgram);
2722 mProgram = 0;
2723
2724 if (!mTextures.empty())
2725 {
2726 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]);
2727 }
2728 }
2729 }
2730
2731 void SetUp() override
2732 {
2733 ANGLETest::SetUp();
2734
2735 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures);
2736 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures);
2737 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures);
2738
2739 ASSERT_GL_NO_ERROR();
2740 }
2741
2742 void compileProgramWithTextureCounts(const std::string &vertexPrefix,
2743 GLint vertexTextureCount,
2744 GLint vertexActiveTextureCount,
2745 const std::string &fragPrefix,
2746 GLint fragmentTextureCount,
2747 GLint fragmentActiveTextureCount)
2748 {
2749 std::stringstream vertexShaderStr;
2750 vertexShaderStr << "attribute vec2 position;\n"
2751 << "varying vec4 color;\n"
2752 << "varying vec2 texCoord;\n";
2753
2754 for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex)
2755 {
2756 vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n";
2757 }
2758
2759 vertexShaderStr << "void main() {\n"
2760 << " gl_Position = vec4(position, 0, 1);\n"
2761 << " texCoord = (position * 0.5) + 0.5;\n"
2762 << " color = vec4(0);\n";
2763
2764 for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex)
2765 {
2766 vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex
2767 << ", texCoord);\n";
2768 }
2769
2770 vertexShaderStr << "}";
2771
2772 std::stringstream fragmentShaderStr;
2773 fragmentShaderStr << "varying mediump vec4 color;\n"
2774 << "varying mediump vec2 texCoord;\n";
2775
2776 for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex)
2777 {
2778 fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n";
2779 }
2780
2781 fragmentShaderStr << "void main() {\n"
2782 << " gl_FragColor = color;\n";
2783
2784 for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex)
2785 {
2786 fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex
2787 << ", texCoord);\n";
2788 }
2789
2790 fragmentShaderStr << "}";
2791
2792 const std::string &vertexShaderSource = vertexShaderStr.str();
2793 const std::string &fragmentShaderSource = fragmentShaderStr.str();
2794
2795 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
2796 }
2797
2798 RGBA8 getPixel(GLint texIndex)
2799 {
2800 RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3),
2801 0, 255u};
2802 return pixel;
2803 }
2804
2805 void initTextures(GLint tex2DCount, GLint texCubeCount)
2806 {
2807 GLint totalCount = tex2DCount + texCubeCount;
2808 mTextures.assign(totalCount, 0);
2809 glGenTextures(totalCount, &mTextures[0]);
2810 ASSERT_GL_NO_ERROR();
2811
2812 std::vector<RGBA8> texData(16 * 16);
2813
2814 GLint texIndex = 0;
2815 for (; texIndex < tex2DCount; ++texIndex)
2816 {
2817 texData.assign(texData.size(), getPixel(texIndex));
2818 glActiveTexture(GL_TEXTURE0 + texIndex);
2819 glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]);
2820 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2821 &texData[0]);
2822 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2823 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2824 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2825 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2826 }
2827
2828 ASSERT_GL_NO_ERROR();
2829
2830 for (; texIndex < texCubeCount; ++texIndex)
2831 {
2832 texData.assign(texData.size(), getPixel(texIndex));
2833 glActiveTexture(GL_TEXTURE0 + texIndex);
2834 glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]);
2835 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2836 GL_UNSIGNED_BYTE, &texData[0]);
2837 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2838 GL_UNSIGNED_BYTE, &texData[0]);
2839 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2840 GL_UNSIGNED_BYTE, &texData[0]);
2841 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2842 GL_UNSIGNED_BYTE, &texData[0]);
2843 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2844 GL_UNSIGNED_BYTE, &texData[0]);
2845 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
2846 GL_UNSIGNED_BYTE, &texData[0]);
2847 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2848 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2849 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2850 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2851 }
2852
2853 ASSERT_GL_NO_ERROR();
2854 }
2855
2856 void testWithTextures(GLint vertexTextureCount,
2857 const std::string &vertexTexturePrefix,
2858 GLint fragmentTextureCount,
2859 const std::string &fragmentTexturePrefix)
2860 {
2861 // Generate textures
2862 initTextures(vertexTextureCount + fragmentTextureCount, 0);
2863
2864 glUseProgram(mProgram);
2865 RGBA8 expectedSum = {0};
2866 for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex)
2867 {
2868 std::stringstream uniformNameStr;
2869 uniformNameStr << vertexTexturePrefix << texIndex;
2870 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04002871 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002872 ASSERT_NE(-1, location);
2873
2874 glUniform1i(location, texIndex);
2875 RGBA8 contribution = getPixel(texIndex);
2876 expectedSum.R += contribution.R;
2877 expectedSum.G += contribution.G;
2878 }
2879
2880 for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex)
2881 {
2882 std::stringstream uniformNameStr;
2883 uniformNameStr << fragmentTexturePrefix << texIndex;
2884 const std::string &uniformName = uniformNameStr.str();
Jamie Madill50cf2be2018-06-15 09:46:57 -04002885 GLint location = glGetUniformLocation(mProgram, uniformName.c_str());
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002886 ASSERT_NE(-1, location);
2887
2888 glUniform1i(location, texIndex + vertexTextureCount);
2889 RGBA8 contribution = getPixel(texIndex + vertexTextureCount);
2890 expectedSum.R += contribution.R;
2891 expectedSum.G += contribution.G;
2892 }
2893
2894 ASSERT_GE(256u, expectedSum.G);
2895
2896 drawQuad(mProgram, "position", 0.5f);
2897 ASSERT_GL_NO_ERROR();
2898 EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255);
2899 }
2900
2901 GLuint mProgram;
2902 std::vector<GLuint> mTextures;
2903 GLint mMaxVertexTextures;
2904 GLint mMaxFragmentTextures;
2905 GLint mMaxCombinedTextures;
2906};
2907
2908// Test rendering with the maximum vertex texture units.
2909TEST_P(TextureLimitsTest, MaxVertexTextures)
2910{
2911 compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0);
2912 ASSERT_NE(0u, mProgram);
2913 ASSERT_GL_NO_ERROR();
2914
2915 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2916}
2917
2918// Test rendering with the maximum fragment texture units.
2919TEST_P(TextureLimitsTest, MaxFragmentTextures)
2920{
2921 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures);
2922 ASSERT_NE(0u, mProgram);
2923 ASSERT_GL_NO_ERROR();
2924
2925 testWithTextures(mMaxFragmentTextures, "tex", 0, "tex");
2926}
2927
2928// Test rendering with maximum combined texture units.
2929TEST_P(TextureLimitsTest, MaxCombinedTextures)
2930{
Luc Ferronaf883622018-06-08 15:57:31 -04002931 // TODO(lucferron): Diagnose and fix
2932 // http://anglebug.com/2654
2933 ANGLE_SKIP_TEST_IF(IsVulkan());
2934
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002935 GLint vertexTextures = mMaxVertexTextures;
2936
2937 if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures)
2938 {
2939 vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures;
2940 }
2941
2942 compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex",
2943 mMaxFragmentTextures, mMaxFragmentTextures);
2944 ASSERT_NE(0u, mProgram);
2945 ASSERT_GL_NO_ERROR();
2946
2947 testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex");
2948}
2949
2950// Negative test for exceeding the number of vertex textures
2951TEST_P(TextureLimitsTest, ExcessiveVertexTextures)
2952{
2953 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0,
2954 0);
2955 ASSERT_EQ(0u, mProgram);
2956}
2957
2958// Negative test for exceeding the number of fragment textures
2959TEST_P(TextureLimitsTest, ExcessiveFragmentTextures)
2960{
2961 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1,
2962 mMaxFragmentTextures + 1);
2963 ASSERT_EQ(0u, mProgram);
2964}
2965
2966// Test active vertex textures under the limit, but excessive textures specified.
2967TEST_P(TextureLimitsTest, MaxActiveVertexTextures)
2968{
Luc Ferronaf883622018-06-08 15:57:31 -04002969 // TODO(lucferron): Diagnose and fix
2970 // http://anglebug.com/2654
2971 ANGLE_SKIP_TEST_IF(IsVulkan());
2972
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002973 compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0);
2974 ASSERT_NE(0u, mProgram);
2975 ASSERT_GL_NO_ERROR();
2976
2977 testWithTextures(mMaxVertexTextures, "tex", 0, "tex");
2978}
2979
2980// Test active fragment textures under the limit, but excessive textures specified.
2981TEST_P(TextureLimitsTest, MaxActiveFragmentTextures)
2982{
Luc Ferronaf883622018-06-08 15:57:31 -04002983 // TODO(lucferron): Diagnose and fix
2984 // http://anglebug.com/2654
2985 ANGLE_SKIP_TEST_IF(IsVulkan());
2986
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002987 compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4,
2988 mMaxFragmentTextures);
2989 ASSERT_NE(0u, mProgram);
2990 ASSERT_GL_NO_ERROR();
2991
2992 testWithTextures(0, "tex", mMaxFragmentTextures, "tex");
2993}
2994
2995// Negative test for pointing two sampler uniforms of different types to the same texture.
Olli Etuaho4a8329f2016-01-11 17:12:57 +02002996// GLES 2.0.25 section 2.10.4 page 39.
Jamie Madill3d3d2f22015-09-23 16:47:51 -04002997TEST_P(TextureLimitsTest, TextureTypeConflict)
2998{
2999 const std::string &vertexShader =
3000 "attribute vec2 position;\n"
3001 "varying float color;\n"
3002 "uniform sampler2D tex2D;\n"
3003 "uniform samplerCube texCube;\n"
3004 "void main() {\n"
3005 " gl_Position = vec4(position, 0, 1);\n"
3006 " vec2 texCoord = (position * 0.5) + 0.5;\n"
3007 " color = texture2D(tex2D, texCoord).x;\n"
3008 " color += textureCube(texCube, vec3(texCoord, 0)).x;\n"
3009 "}";
3010 const std::string &fragmentShader =
3011 "varying mediump float color;\n"
3012 "void main() {\n"
3013 " gl_FragColor = vec4(color, 0, 0, 1);\n"
3014 "}";
3015
3016 mProgram = CompileProgram(vertexShader, fragmentShader);
3017 ASSERT_NE(0u, mProgram);
3018
3019 initTextures(1, 0);
3020
3021 glUseProgram(mProgram);
3022 GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D");
3023 ASSERT_NE(-1, tex2DLocation);
3024 GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube");
3025 ASSERT_NE(-1, texCubeLocation);
3026
3027 glUniform1i(tex2DLocation, 0);
3028 glUniform1i(texCubeLocation, 0);
3029 ASSERT_GL_NO_ERROR();
3030
3031 drawQuad(mProgram, "position", 0.5f);
3032 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3033}
3034
Vincent Lang25ab4512016-05-13 18:13:59 +02003035class Texture2DNorm16TestES3 : public Texture2DTestES3
3036{
3037 protected:
3038 Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {}
3039
3040 void SetUp() override
3041 {
3042 Texture2DTestES3::SetUp();
3043
3044 glActiveTexture(GL_TEXTURE0);
3045 glGenTextures(3, mTextures);
3046 glGenFramebuffers(1, &mFBO);
3047 glGenRenderbuffers(1, &mRenderbuffer);
3048
3049 for (size_t textureIndex = 0; textureIndex < 3; textureIndex++)
3050 {
3051 glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]);
3052 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3053 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3054 }
3055
3056 glBindTexture(GL_TEXTURE_2D, 0);
3057
3058 ASSERT_GL_NO_ERROR();
3059 }
3060
3061 void TearDown() override
3062 {
3063 glDeleteTextures(3, mTextures);
3064 glDeleteFramebuffers(1, &mFBO);
3065 glDeleteRenderbuffers(1, &mRenderbuffer);
3066
3067 Texture2DTestES3::TearDown();
3068 }
3069
3070 void testNorm16Texture(GLint internalformat, GLenum format, GLenum type)
3071 {
Geoff Langf607c602016-09-21 11:46:48 -04003072 GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35;
3073 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003074
3075 setUpProgram();
3076
3077 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3078 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0],
3079 0);
3080
3081 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
3082 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr);
3083
3084 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
Geoff Langf607c602016-09-21 11:46:48 -04003085 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003086
3087 EXPECT_GL_NO_ERROR();
3088
3089 drawQuad(mProgram, "position", 0.5f);
3090
Geoff Langf607c602016-09-21 11:46:48 -04003091 GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8);
Vincent Lang25ab4512016-05-13 18:13:59 +02003092
Jamie Madill50cf2be2018-06-15 09:46:57 -04003093 EXPECT_PIXEL_COLOR_EQ(0, 0,
3094 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3095 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003096
3097 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3098
3099 ASSERT_GL_NO_ERROR();
3100 }
3101
3102 void testNorm16Render(GLint internalformat, GLenum format, GLenum type)
3103 {
Jamie Madill50cf2be2018-06-15 09:46:57 -04003104 GLushort pixelValue = 0x6A35;
Geoff Langf607c602016-09-21 11:46:48 -04003105 GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue};
Vincent Lang25ab4512016-05-13 18:13:59 +02003106
3107 setUpProgram();
3108
3109 glBindTexture(GL_TEXTURE_2D, mTextures[1]);
3110 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr);
3111
3112 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
3113 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1],
3114 0);
3115
3116 glBindTexture(GL_TEXTURE_2D, mTextures[2]);
Geoff Langf607c602016-09-21 11:46:48 -04003117 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData);
Vincent Lang25ab4512016-05-13 18:13:59 +02003118
3119 EXPECT_GL_NO_ERROR();
3120
3121 drawQuad(mProgram, "position", 0.5f);
3122
Geoff Langf607c602016-09-21 11:46:48 -04003123 GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8);
Jamie Madill50cf2be2018-06-15 09:46:57 -04003124 EXPECT_PIXEL_COLOR_EQ(0, 0,
3125 SliceFormatColor(format, GLColor(expectedValue, expectedValue,
3126 expectedValue, expectedValue)));
Vincent Lang25ab4512016-05-13 18:13:59 +02003127
3128 glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer);
3129 glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1);
3130 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3131 mRenderbuffer);
3132 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3133 EXPECT_GL_NO_ERROR();
3134
3135 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3136 glClear(GL_COLOR_BUFFER_BIT);
3137
3138 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
3139
Geoff Langf607c602016-09-21 11:46:48 -04003140 EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white));
Vincent Lang25ab4512016-05-13 18:13:59 +02003141
3142 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3143
3144 ASSERT_GL_NO_ERROR();
3145 }
3146
3147 GLuint mTextures[3];
3148 GLuint mFBO;
3149 GLuint mRenderbuffer;
3150};
3151
3152// Test texture formats enabled by the GL_EXT_texture_norm16 extension.
3153TEST_P(Texture2DNorm16TestES3, TextureNorm16Test)
3154{
Yunchao He9550c602018-02-13 14:47:05 +08003155 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16"));
Vincent Lang25ab4512016-05-13 18:13:59 +02003156
3157 testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3158 testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3159 testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT);
3160 testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3161 testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT);
3162 testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT);
3163 testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT);
3164 testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT);
3165
3166 testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT);
3167 testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT);
3168 testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT);
3169}
3170
Olli Etuaho95faa232016-06-07 14:01:53 -07003171// Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads.
3172// GLES 3.0.4 section 3.8.3.
3173TEST_P(Texture2DTestES3, UnpackSkipImages2D)
3174{
Yunchao He8e5ba8b2018-02-05 17:52:27 +08003175 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL());
3176
Yuly Novikov3c754192016-06-27 19:36:41 -04003177 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed
Yunchao He9550c602018-02-13 14:47:05 +08003178 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
Olli Etuaho95faa232016-06-07 14:01:53 -07003179
3180 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3181 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3182 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3183 ASSERT_GL_NO_ERROR();
3184
3185 // SKIP_IMAGES should not have an effect on uploading 2D textures
3186 glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000);
3187 ASSERT_GL_NO_ERROR();
3188
3189 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3190
3191 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3192 pixelsGreen.data());
3193 ASSERT_GL_NO_ERROR();
3194
3195 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE,
3196 pixelsGreen.data());
3197 ASSERT_GL_NO_ERROR();
3198
3199 glUseProgram(mProgram);
3200 drawQuad(mProgram, "position", 0.5f);
3201 ASSERT_GL_NO_ERROR();
3202
3203 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3204}
3205
Olli Etuaho989cac32016-06-08 16:18:49 -07003206// Test that skip defined in unpack parameters is taken into account when determining whether
3207// unpacking source extends outside unpack buffer bounds.
3208TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds)
3209{
3210 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3211 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3212 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3213 ASSERT_GL_NO_ERROR();
3214
3215 GLBuffer buf;
3216 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3217 std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green);
3218 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3219 GL_DYNAMIC_COPY);
3220 ASSERT_GL_NO_ERROR();
3221
3222 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3223 ASSERT_GL_NO_ERROR();
3224
3225 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
3226 ASSERT_GL_NO_ERROR();
3227
3228 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3229 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3230
3231 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
3232 glPixelStorei(GL_UNPACK_SKIP_ROWS, 1);
3233 ASSERT_GL_NO_ERROR();
3234
3235 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3236 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3237}
3238
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003239// Test that unpacking rows that overlap in a pixel unpack buffer works as expected.
3240TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer)
3241{
Yunchao He9550c602018-02-13 14:47:05 +08003242 ANGLE_SKIP_TEST_IF(IsD3D11());
3243
3244 // Incorrect rendering results seen on OSX AMD.
3245 ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD());
Olli Etuaho218cf9e2016-05-20 13:55:24 +03003246
3247 const GLuint width = 8u;
3248 const GLuint height = 8u;
3249 const GLuint unpackRowLength = 5u;
3250 const GLuint unpackSkipPixels = 1u;
3251
3252 setWindowWidth(width);
3253 setWindowHeight(height);
3254
3255 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3258 ASSERT_GL_NO_ERROR();
3259
3260 GLBuffer buf;
3261 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get());
3262 std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels,
3263 GLColor::green);
3264
3265 for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel)
3266 {
3267 pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255);
3268 }
3269
3270 glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(),
3271 GL_DYNAMIC_COPY);
3272 ASSERT_GL_NO_ERROR();
3273
3274 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
3275 glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
3276 ASSERT_GL_NO_ERROR();
3277
3278 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
3279 ASSERT_GL_NO_ERROR();
3280
3281 glUseProgram(mProgram);
3282 drawQuad(mProgram, "position", 0.5f);
3283 ASSERT_GL_NO_ERROR();
3284
3285 GLuint windowPixelCount = getWindowWidth() * getWindowHeight();
3286 std::vector<GLColor> actual(windowPixelCount, GLColor::black);
3287 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
3288 actual.data());
3289 std::vector<GLColor> expected(windowPixelCount, GLColor::green);
3290 EXPECT_EQ(expected, actual);
3291}
3292
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003293template <typename T>
3294T UNorm(double value)
3295{
3296 return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max()));
3297}
3298
3299// Test rendering a depth texture with mipmaps.
3300TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps)
3301{
Zhenyao Moe520d7c2017-01-13 13:46:49 -08003302 // TODO(cwallez) this is failing on Intel Win7 OpenGL.
3303 // TODO(zmo) this is faling on Win Intel HD 530 Debug.
3304 // http://anglebugs.com/1706
Yunchao He9550c602018-02-13 14:47:05 +08003305 ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows());
Corentin Walleze731d8a2016-09-07 10:56:25 -04003306
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003307 const int size = getWindowWidth();
3308
3309 auto dim = [size](int level) { return size >> level; };
Jamie Madill14718762016-09-06 15:56:54 -04003310 int levels = gl::log2(size);
Jamie Madill9e3d7aa2016-09-02 15:19:43 -04003311
3312 glActiveTexture(GL_TEXTURE0);
3313 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3314 glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size);
3315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3319 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3320 ASSERT_GL_NO_ERROR();
3321
3322 glUseProgram(mProgram);
3323 glUniform1i(mTexture2DUniformLocation, 0);
3324
3325 std::vector<unsigned char> expected;
3326
3327 for (int level = 0; level < levels; ++level)
3328 {
3329 double value = (static_cast<double>(level) / static_cast<double>(levels - 1));
3330 expected.push_back(UNorm<unsigned char>(value));
3331
3332 int levelDim = dim(level);
3333
3334 ASSERT_GT(levelDim, 0);
3335
3336 std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value));
3337 glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT,
3338 GL_UNSIGNED_INT, initData.data());
3339 }
3340 ASSERT_GL_NO_ERROR();
3341
3342 for (int level = 0; level < levels; ++level)
3343 {
3344 glViewport(0, 0, dim(level), dim(level));
3345 drawQuad(mProgram, "position", 0.5f);
3346 GLColor actual = ReadColor(0, 0);
3347 EXPECT_NEAR(expected[level], actual.R, 10u);
3348 }
3349
3350 ASSERT_GL_NO_ERROR();
3351}
3352
Jamie Madill7ffdda92016-09-08 13:26:51 -04003353// Tests unpacking into the unsized GL_ALPHA format.
3354TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer)
3355{
Jamie Madill7ffdda92016-09-08 13:26:51 -04003356 // Initialize the texure.
3357 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3358 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA,
3359 GL_UNSIGNED_BYTE, nullptr);
3360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3361 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3362
3363 std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127);
3364
3365 // Pull in the color data from the unpack buffer.
Jamie Madill2e600342016-09-19 13:56:40 -04003366 GLBuffer unpackBuffer;
Jamie Madill7ffdda92016-09-08 13:26:51 -04003367 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3368 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3369 glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(),
3370 GL_STATIC_DRAW);
3371
3372 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA,
3373 GL_UNSIGNED_BYTE, nullptr);
3374
3375 // Clear to a weird color to make sure we're drawing something.
3376 glClearColor(0.5f, 0.8f, 1.0f, 0.2f);
3377 glClear(GL_COLOR_BUFFER_BIT);
3378
3379 // Draw with the alpha texture and verify.
3380 drawQuad(mProgram, "position", 0.5f);
Jamie Madill7ffdda92016-09-08 13:26:51 -04003381
3382 ASSERT_GL_NO_ERROR();
3383 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1);
3384}
3385
Jamie Madill2e600342016-09-19 13:56:40 -04003386// Ensure stale unpack data doesn't propagate in D3D11.
3387TEST_P(Texture2DTestES3, StaleUnpackData)
3388{
3389 // Init unpack buffer.
3390 GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2;
3391 std::vector<GLColor> pixels(pixelCount, GLColor::red);
3392
3393 GLBuffer unpackBuffer;
3394 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
3395 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get());
3396 GLsizei bufferSize = pixelCount * sizeof(GLColor);
3397 glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW);
3398
3399 // Create from unpack buffer.
3400 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3401 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0,
3402 GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3404 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3405
3406 drawQuad(mProgram, "position", 0.5f);
3407
3408 ASSERT_GL_NO_ERROR();
3409 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3410
3411 // Fill unpack with green, recreating buffer.
3412 pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green);
3413 GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor);
3414 glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW);
3415
3416 // Reinit texture with green.
3417 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA,
3418 GL_UNSIGNED_BYTE, nullptr);
3419
3420 drawQuad(mProgram, "position", 0.5f);
3421
3422 ASSERT_GL_NO_ERROR();
3423 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3424}
3425
Geoff Langfb7685f2017-11-13 11:44:11 -05003426// Ensure that texture parameters passed as floats that are converted to ints are rounded before
3427// validating they are less than 0.
3428TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation)
3429{
3430 GLTexture texture;
3431 glBindTexture(GL_TEXTURE_2D, texture);
3432
3433 // Use a negative number that will round to zero when converted to an integer
3434 // According to the spec(2.3.1 Data Conversion For State - Setting Commands):
3435 // "Validation of values performed by state-setting commands is performed after conversion,
3436 // unless specified otherwise for a specific command."
3437 GLfloat param = -7.30157126e-07f;
3438 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param);
3439 EXPECT_GL_NO_ERROR();
3440
3441 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param);
3442 EXPECT_GL_NO_ERROR();
3443}
3444
Jamie Madillf097e232016-11-05 00:44:15 -04003445// This test covers a D3D format redefinition bug for 3D textures. The base level format was not
3446// being properly checked, and the texture storage of the previous texture format was persisting.
3447// This would result in an ASSERT in debug and incorrect rendering in release.
3448// See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html.
3449TEST_P(Texture3DTestES3, FormatRedefinitionBug)
3450{
3451 GLTexture tex;
3452 glBindTexture(GL_TEXTURE_3D, tex.get());
3453 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3454
3455 GLFramebuffer framebuffer;
3456 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3457 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0);
3458
3459 glCheckFramebufferStatus(GL_FRAMEBUFFER);
3460
3461 std::vector<uint8_t> pixelData(100, 0);
3462
3463 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
3464 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
3465 pixelData.data());
3466
3467 ASSERT_GL_NO_ERROR();
3468}
3469
Corentin Wallezd2627992017-04-28 17:17:03 -04003470// Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture
3471TEST_P(Texture3DTestES3, BasicUnpackBufferOOB)
3472{
3473 // 2D tests
3474 {
3475 GLTexture tex;
3476 glBindTexture(GL_TEXTURE_2D, tex.get());
3477
3478 GLBuffer pbo;
3479 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3480
3481 // Test OOB
3482 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW);
3483 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3484 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3485
3486 // Test OOB
3487 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW);
3488 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3489 ASSERT_GL_NO_ERROR();
3490 }
3491
3492 // 3D tests
3493 {
3494 GLTexture tex;
3495 glBindTexture(GL_TEXTURE_3D, tex.get());
3496
3497 GLBuffer pbo;
3498 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get());
3499
3500 // Test OOB
3501 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr,
3502 GL_STATIC_DRAW);
3503 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3504 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3505
3506 // Test OOB
3507 glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW);
3508 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3509 ASSERT_GL_NO_ERROR();
3510 }
3511}
3512
Jamie Madill3ed60422017-09-07 11:32:52 -04003513// Tests behaviour with a single texture and multiple sampler objects.
3514TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers)
3515{
3516 GLint maxTextureUnits = 0;
3517 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
3518 ANGLE_SKIP_TEST_IF(maxTextureUnits < 4);
3519
3520 constexpr int kSize = 16;
3521
3522 // Make a single-level texture, fill it with red.
3523 std::vector<GLColor> redColors(kSize * kSize, GLColor::red);
3524 GLTexture tex;
3525 glBindTexture(GL_TEXTURE_2D, tex);
3526 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3527 redColors.data());
3528 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3529 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3530
3531 // Simple sanity check.
3532 draw2DTexturedQuad(0.5f, 1.0f, true);
3533 ASSERT_GL_NO_ERROR();
3534 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3535
3536 // Bind texture to unit 1 with a sampler object making it incomplete.
3537 GLSampler sampler;
3538 glBindSampler(0, sampler);
3539 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3540 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3541
3542 // Make a mipmap texture, fill it with blue.
3543 std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue);
3544 GLTexture mipmapTex;
3545 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3546 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3547 blueColors.data());
3548 glGenerateMipmap(GL_TEXTURE_2D);
3549
3550 // Draw with the sampler, expect blue.
3551 draw2DTexturedQuad(0.5f, 1.0f, true);
3552 ASSERT_GL_NO_ERROR();
3553 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
3554
3555 // Simple multitexturing program.
3556 const std::string vs =
3557 "#version 300 es\n"
3558 "in vec2 position;\n"
3559 "out vec2 texCoord;\n"
3560 "void main()\n"
3561 "{\n"
3562 " gl_Position = vec4(position, 0, 1);\n"
3563 " texCoord = position * 0.5 + vec2(0.5);\n"
3564 "}";
3565 const std::string fs =
3566 "#version 300 es\n"
3567 "precision mediump float;\n"
3568 "in vec2 texCoord;\n"
3569 "uniform sampler2D tex1;\n"
3570 "uniform sampler2D tex2;\n"
3571 "uniform sampler2D tex3;\n"
3572 "uniform sampler2D tex4;\n"
3573 "out vec4 color;\n"
3574 "void main()\n"
3575 "{\n"
3576 " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n"
3577 " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n"
3578 "}";
3579
3580 ANGLE_GL_PROGRAM(program, vs, fs);
3581
3582 std::array<GLint, 4> texLocations = {
3583 {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"),
3584 glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}};
3585 for (GLint location : texLocations)
3586 {
3587 ASSERT_NE(-1, location);
3588 }
3589
3590 // Init the uniform data.
3591 glUseProgram(program);
3592 for (GLint location = 0; location < 4; ++location)
3593 {
3594 glUniform1i(texLocations[location], location);
3595 }
3596
3597 // Initialize four samplers
3598 GLSampler samplers[4];
3599
3600 // 0: non-mipped.
3601 glBindSampler(0, samplers[0]);
3602 glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3603 glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3604
3605 // 1: mipped.
3606 glBindSampler(1, samplers[1]);
3607 glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3608 glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3609
3610 // 2: non-mipped.
3611 glBindSampler(2, samplers[2]);
3612 glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3613 glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3614
3615 // 3: mipped.
3616 glBindSampler(3, samplers[3]);
3617 glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3618 glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3619
3620 // Bind two blue mipped textures and two single layer textures, should all draw.
3621 glActiveTexture(GL_TEXTURE0);
3622 glBindTexture(GL_TEXTURE_2D, tex);
3623
3624 glActiveTexture(GL_TEXTURE1);
3625 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3626
3627 glActiveTexture(GL_TEXTURE2);
3628 glBindTexture(GL_TEXTURE_2D, tex);
3629
3630 glActiveTexture(GL_TEXTURE3);
3631 glBindTexture(GL_TEXTURE_2D, mipmapTex);
3632
3633 ASSERT_GL_NO_ERROR();
3634
3635 drawQuad(program, "position", 0.5f);
3636 ASSERT_GL_NO_ERROR();
3637 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2);
3638
3639 // Bind four single layer textures, two should be incomplete.
3640 glActiveTexture(GL_TEXTURE1);
3641 glBindTexture(GL_TEXTURE_2D, tex);
3642
3643 glActiveTexture(GL_TEXTURE3);
3644 glBindTexture(GL_TEXTURE_2D, tex);
3645
3646 drawQuad(program, "position", 0.5f);
3647 ASSERT_GL_NO_ERROR();
3648 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2);
3649}
3650
Martin Radev7e2c0d32017-09-15 14:25:42 +03003651// The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start
3652// always at level 0 instead of the base level resulting in an incomplete texture if the faces at
3653// level 0 are not created. The test creates a cubemap texture, specifies the images only for mip
3654// level 1 filled with white color, updates the base level to be 1 and renders a quad. The program
3655// samples the cubemap using a direction vector (1,1,1).
3656TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1)
3657{
Yunchao He2f23f352018-02-11 22:11:37 +08003658 // Check http://anglebug.com/2155.
3659 ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA());
3660
Martin Radev7e2c0d32017-09-15 14:25:42 +03003661 const std::string vs =
3662 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003663 precision mediump float;
3664 in vec3 pos;
3665 void main() {
3666 gl_Position = vec4(pos, 1.0);
3667 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003668
3669 const std::string fs =
3670 R"(#version 300 es
Olli Etuahoa20af6d2017-09-18 13:32:29 +03003671 precision mediump float;
3672 out vec4 color;
3673 uniform samplerCube uTex;
3674 void main(){
3675 color = texture(uTex, vec3(1.0));
3676 })";
Martin Radev7e2c0d32017-09-15 14:25:42 +03003677 ANGLE_GL_PROGRAM(program, vs, fs);
3678 glUseProgram(program);
3679
3680 glUniform1i(glGetUniformLocation(program, "uTex"), 0);
3681 glActiveTexture(GL_TEXTURE0);
3682
3683 GLTexture cubeTex;
3684 glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex);
3685
3686 const int kFaceWidth = 1;
3687 const int kFaceHeight = 1;
3688 std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF);
3689 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3690 GL_UNSIGNED_BYTE, texData.data());
3691 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3692 GL_UNSIGNED_BYTE, texData.data());
3693 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3694 GL_UNSIGNED_BYTE, texData.data());
3695 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3696 GL_UNSIGNED_BYTE, texData.data());
3697 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3698 GL_UNSIGNED_BYTE, texData.data());
3699 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA,
3700 GL_UNSIGNED_BYTE, texData.data());
3701 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3702 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3703 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
3704 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
3705 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
3706 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1);
3707
3708 drawQuad(program, "pos", 0.5f, 1.0f, true);
3709 ASSERT_GL_NO_ERROR();
3710
3711 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3712}
3713
Jiawei Shao3c43b4d2018-02-23 11:08:28 +08003714// Verify that using negative texture base level and max level generates GL_INVALID_VALUE.
3715TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel)
3716{
3717 GLuint texture = create2DTexture();
3718
3719 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1);
3720 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3721
3722 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1);
3723 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3724
3725 glDeleteTextures(1, &texture);
3726 EXPECT_GL_NO_ERROR();
3727}
3728
Olli Etuaho023371b2018-04-24 17:43:32 +03003729// Test setting base level after calling generateMipmap on a LUMA texture.
3730// Covers http://anglebug.com/2498
3731TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA)
3732{
3733 glActiveTexture(GL_TEXTURE0);
3734 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3735
3736 constexpr const GLsizei kWidth = 8;
3737 constexpr const GLsizei kHeight = 8;
3738 std::array<GLubyte, kWidth * kHeight * 2> whiteData;
3739 whiteData.fill(255u);
3740
3741 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA,
3742 GL_UNSIGNED_BYTE, whiteData.data());
3743 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
3744 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3745 glGenerateMipmap(GL_TEXTURE_2D);
3746 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
3747 EXPECT_GL_NO_ERROR();
3748
3749 drawQuad(mProgram, "position", 0.5f);
3750 EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white);
3751}
3752
Till Rathmannc1551dc2018-08-15 17:04:49 +02003753// Covers a bug in the D3D11 backend: http://anglebug.com/2772
3754// When using a sampler the texture was created as if it has mipmaps,
3755// regardless what you specified in GL_TEXTURE_MIN_FILTER via
3756// glSamplerParameteri() -- mistakenly the default value
3757// GL_NEAREST_MIPMAP_LINEAR or the value set via glTexParameteri() was
3758// evaluated.
3759// If you didn't provide mipmaps and didn't let the driver generate them
3760// this led to not sampling your texture data when minification occurred.
3761TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
3762{
3763 const std::string vs =
3764 "#version 300 es\n"
3765 "out vec2 texcoord;\n"
3766 "in vec4 position;\n"
3767 "void main()\n"
3768 "{\n"
3769 " gl_Position = vec4(position.xy * 0.1, 0.0, 1.0);\n"
3770 " texcoord = (position.xy * 0.5) + 0.5;\n"
3771 "}\n";
3772
3773 const std::string fs =
3774 "#version 300 es\n"
3775 "precision highp float;\n"
3776 "uniform highp sampler2D tex;\n"
3777 "in vec2 texcoord;\n"
3778 "out vec4 fragColor;\n"
3779 "void main()\n"
3780 "{\n"
3781 " fragColor = texture(tex, texcoord);\n"
3782 "}\n";
3783 ANGLE_GL_PROGRAM(program, vs, fs);
3784
3785 GLSampler sampler;
3786 glBindSampler(0, sampler);
3787 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3788 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3789
3790 glActiveTexture(GL_TEXTURE0);
3791 glBindTexture(GL_TEXTURE_2D, mTexture2D);
3792
3793 const GLsizei texWidth = getWindowWidth();
3794 const GLsizei texHeight = getWindowHeight();
3795 const std::vector<GLColor> whiteData(texWidth * texHeight, GLColor::white);
3796
3797 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3798 whiteData.data());
3799 EXPECT_GL_NO_ERROR();
3800
3801 drawQuad(program, "position", 0.5f);
3802 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, angle::GLColor::white);
3803}
3804
Jamie Madill50cf2be2018-06-15 09:46:57 -04003805// Use this to select which configurations (e.g. which renderer, which GLES major version) these
3806// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05003807ANGLE_INSTANTIATE_TEST(Texture2DTest,
3808 ES2_D3D9(),
3809 ES2_D3D11(),
3810 ES2_D3D11_FL9_3(),
3811 ES2_OPENGL(),
Luc Ferron5164b792018-03-06 09:10:12 -05003812 ES2_OPENGLES(),
3813 ES2_VULKAN());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003814ANGLE_INSTANTIATE_TEST(TextureCubeTest,
3815 ES2_D3D9(),
3816 ES2_D3D11(),
Geoff Langf7480ad2017-10-24 11:46:02 -04003817 ES2_D3D11_FL10_0(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003818 ES2_D3D11_FL9_3(),
3819 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003820 ES2_OPENGLES(),
3821 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003822ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale,
3823 ES2_D3D9(),
3824 ES2_D3D11(),
3825 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003826 ES2_OPENGL(),
Luc Ferronaf883622018-06-08 15:57:31 -04003827 ES2_OPENGLES(),
3828 ES2_VULKAN());
Olli Etuaho51f1c0f2016-01-13 16:16:24 +02003829ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest,
3830 ES2_D3D9(),
3831 ES2_D3D11(),
3832 ES2_D3D11_FL9_3(),
Geoff Lange0cc2a42016-01-20 10:58:17 -05003833 ES2_OPENGL(),
3834 ES2_OPENGLES());
3835ANGLE_INSTANTIATE_TEST(SamplerArrayTest,
3836 ES2_D3D9(),
3837 ES2_D3D11(),
3838 ES2_D3D11_FL9_3(),
3839 ES2_OPENGL(),
3840 ES2_OPENGLES());
3841ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest,
3842 ES2_D3D9(),
3843 ES2_D3D11(),
3844 ES2_D3D11_FL9_3(),
3845 ES2_OPENGL(),
3846 ES2_OPENGLES());
3847ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahoa314b612016-03-10 16:43:00 +02003848ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuaho6ee394a2016-02-18 13:30:09 +02003849ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3850ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3,
3851 ES3_D3D11(),
3852 ES3_OPENGL(),
3853 ES3_OPENGLES());
Geoff Lange0cc2a42016-01-20 10:58:17 -05003854ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3,
3855 ES3_D3D11(),
3856 ES3_OPENGL(),
3857 ES3_OPENGLES());
3858ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
3859ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Olli Etuahobce743a2016-01-15 17:18:28 +02003860ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
Olli Etuaho96963162016-03-21 11:54:33 +02003861ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
3862 ES2_D3D11(),
3863 ES2_D3D11_FL9_3(),
3864 ES2_D3D9(),
3865 ES2_OPENGL(),
3866 ES2_OPENGLES());
3867ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest,
3868 ES2_D3D11(),
3869 ES2_D3D11_FL9_3(),
3870 ES2_D3D9(),
3871 ES2_OPENGL(),
3872 ES2_OPENGLES());
3873ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest,
3874 ES2_D3D11(),
3875 ES2_D3D11_FL9_3(),
3876 ES2_D3D9(),
3877 ES2_OPENGL(),
3878 ES2_OPENGLES());
3879ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest,
3880 ES2_D3D11(),
3881 ES2_D3D11_FL9_3(),
3882 ES2_D3D9(),
3883 ES2_OPENGL(),
3884 ES2_OPENGLES());
3885ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest,
3886 ES2_D3D11(),
3887 ES2_D3D11_FL9_3(),
3888 ES2_D3D9(),
3889 ES2_OPENGL(),
3890 ES2_OPENGLES());
Luc Ferronaf883622018-06-08 15:57:31 -04003891ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN());
Vincent Lang25ab4512016-05-13 18:13:59 +02003892ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Martin Radev7e2c0d32017-09-15 14:25:42 +03003893ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04003894
Jamie Madill7ffdda92016-09-08 13:26:51 -04003895} // anonymous namespace