Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 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 Madill | 1471876 | 2016-09-06 15:56:54 -0400 | [diff] [blame] | 7 | #include "common/mathutil.h" |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 8 | #include "test_utils/ANGLETest.h" |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 9 | #include "test_utils/gl_raii.h" |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 12 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | namespace |
| 14 | { |
| 15 | |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 16 | // Take a pixel, and reset the components not covered by the format to default |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 17 | // values. In particular, the default value for the alpha component is 255 |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 18 | // (1.0 as unsigned normalized fixed point value). |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 19 | GLColor SliceFormatColor(GLenum format, GLColor full) |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 20 | { |
| 21 | switch (format) |
| 22 | { |
| 23 | case GL_RED: |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 24 | return GLColor(full.R, 0, 0, 255u); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 25 | case GL_RG: |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 26 | return GLColor(full.R, full.G, 0, 255u); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 27 | case GL_RGB: |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 28 | return GLColor(full.R, full.G, full.B, 255u); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 29 | case GL_RGBA: |
| 30 | return full; |
| 31 | default: |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 32 | EXPECT_TRUE(false); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 33 | return GLColor::white; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 34 | } |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 37 | class TexCoordDrawTest : public ANGLETest |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 38 | { |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 39 | protected: |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 40 | TexCoordDrawTest() : ANGLETest(), mProgram(0), mFramebuffer(0), mFramebufferColorTexture(0) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 41 | { |
| 42 | setWindowWidth(128); |
| 43 | setWindowHeight(128); |
| 44 | setConfigRedBits(8); |
| 45 | setConfigGreenBits(8); |
| 46 | setConfigBlueBits(8); |
| 47 | setConfigAlphaBits(8); |
| 48 | } |
| 49 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 50 | virtual std::string getVertexShaderSource() |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 51 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 52 | return |
| 53 | R"(precision highp float; |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 54 | attribute vec4 position; |
| 55 | varying vec2 texcoord; |
| 56 | |
| 57 | void main() |
| 58 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 59 | gl_Position = vec4(position.xy, 0.0, 1.0); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 60 | texcoord = (position.xy * 0.5) + 0.5; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 61 | })"; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 62 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 63 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 64 | virtual std::string getFragmentShaderSource() = 0; |
| 65 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 66 | virtual void setUpProgram() |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 67 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 68 | 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void SetUp() override |
| 77 | { |
| 78 | ANGLETest::SetUp(); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 79 | |
| 80 | setUpFramebuffer(); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void TearDown() override |
| 84 | { |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 85 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 86 | glDeleteFramebuffers(1, &mFramebuffer); |
| 87 | glDeleteTextures(1, &mFramebufferColorTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 88 | glDeleteProgram(mProgram); |
| 89 | ANGLETest::TearDown(); |
| 90 | } |
| 91 | |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 92 | 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 115 | // Returns the created texture ID. |
| 116 | GLuint create2DTexture() |
| 117 | { |
| 118 | GLuint texture2D; |
| 119 | glGenTextures(1, &texture2D); |
| 120 | glBindTexture(GL_TEXTURE_2D, texture2D); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 121 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 122 | EXPECT_GL_NO_ERROR(); |
| 123 | return texture2D; |
| 124 | } |
| 125 | |
| 126 | GLuint mProgram; |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 127 | GLuint mFramebuffer; |
| 128 | |
| 129 | private: |
| 130 | GLuint mFramebufferColorTexture; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | class Texture2DTest : public TexCoordDrawTest |
| 134 | { |
| 135 | protected: |
| 136 | Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {} |
| 137 | |
| 138 | std::string getFragmentShaderSource() override |
| 139 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 140 | return |
| 141 | R"(precision highp float; |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 142 | uniform sampler2D tex; |
| 143 | varying vec2 texcoord; |
| 144 | |
| 145 | void main() |
| 146 | { |
| 147 | gl_FragColor = texture2D(tex, texcoord); |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 148 | })"; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 149 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 150 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 151 | virtual const char *getTextureUniformName() { return "tex"; } |
| 152 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 153 | void setUpProgram() override |
| 154 | { |
| 155 | TexCoordDrawTest::setUpProgram(); |
| 156 | mTexture2DUniformLocation = glGetUniformLocation(mProgram, getTextureUniformName()); |
| 157 | ASSERT_NE(-1, mTexture2DUniformLocation); |
| 158 | } |
| 159 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 160 | void SetUp() override |
| 161 | { |
| 162 | TexCoordDrawTest::SetUp(); |
| 163 | mTexture2D = create2DTexture(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 164 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 165 | ASSERT_GL_NO_ERROR(); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 166 | } |
| 167 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 168 | void TearDown() override |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 169 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 170 | glDeleteTextures(1, &mTexture2D); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 171 | TexCoordDrawTest::TearDown(); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 174 | // Tests CopyTexSubImage with floating point textures of various formats. |
| 175 | void testFloatCopySubImage(int sourceImageChannels, int destImageChannels) |
| 176 | { |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 177 | setUpProgram(); |
| 178 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 179 | if (getClientMajorVersion() < 3) |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 180 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 181 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage") || |
| 182 | !extensionEnabled("GL_OES_texture_float")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 183 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 184 | ANGLE_SKIP_TEST_IF((sourceImageChannels < 3 || destImageChannels < 3) && |
| 185 | !extensionEnabled("GL_EXT_texture_rg")); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 186 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 187 | ANGLE_SKIP_TEST_IF(destImageChannels == 3 && |
| 188 | !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb")); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 189 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 190 | ANGLE_SKIP_TEST_IF(destImageChannels == 4 && |
| 191 | !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba")); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 192 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 193 | ANGLE_SKIP_TEST_IF(destImageChannels <= 2); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 194 | } |
| 195 | else |
| 196 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 197 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_color_buffer_float")); |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 198 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 199 | ANGLE_SKIP_TEST_IF(destImageChannels == 3 && |
| 200 | !extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb")); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 203 | // clang-format off |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 204 | 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 Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 231 | // clang-format on |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 232 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 233 | GLenum imageFormats[] = { |
| 234 | GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F, |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 235 | }; |
| 236 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 237 | GLenum sourceUnsizedFormats[] = { |
| 238 | GL_RED, GL_RG, GL_RGB, GL_RGBA, |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | GLuint textures[2]; |
| 242 | |
| 243 | glGenTextures(2, textures); |
| 244 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 245 | GLfloat *imageData = sourceImageData[sourceImageChannels - 1]; |
| 246 | GLenum sourceImageFormat = imageFormats[sourceImageChannels - 1]; |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 247 | GLenum sourceUnsizedFormat = sourceUnsizedFormats[sourceImageChannels - 1]; |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 248 | GLenum destImageFormat = imageFormats[destImageChannels - 1]; |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 249 | |
| 250 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 251 | 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 Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 259 | 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 | |
hendrikw | b27f79a | 2015-03-04 11:26:46 -0800 | [diff] [blame] | 263 | if (sourceImageChannels < 3 && !extensionEnabled("GL_EXT_texture_rg")) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 264 | { |
| 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 Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 279 | 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 Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 287 | 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 294 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 295 | |
| 296 | int testImageChannels = std::min(sourceImageChannels, destImageChannels); |
| 297 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 298 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 299 | 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 Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 315 | GLuint mTexture2D; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 316 | GLint mTexture2DUniformLocation; |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 317 | }; |
| 318 | |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 319 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 350 | |
| 351 | void SetUp() override |
| 352 | { |
| 353 | Texture2DTest::SetUp(); |
| 354 | setUpProgram(); |
| 355 | } |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 356 | }; |
| 357 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 358 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 391 | |
| 392 | void SetUp() override |
| 393 | { |
| 394 | Texture2DTest::SetUp(); |
| 395 | setUpProgram(); |
| 396 | } |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 432 | |
| 433 | void SetUp() override |
| 434 | { |
| 435 | Texture2DTest::SetUp(); |
| 436 | setUpProgram(); |
| 437 | } |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 438 | }; |
| 439 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 440 | class Texture2DTestWithDrawScale : public Texture2DTest |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 441 | { |
| 442 | protected: |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 443 | Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {} |
| 444 | |
| 445 | std::string getVertexShaderSource() override |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 446 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 447 | return |
| 448 | R"(precision highp float; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 449 | 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 458 | })"; |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void SetUp() override |
| 462 | { |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 463 | Texture2DTest::SetUp(); |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 464 | |
| 465 | setUpProgram(); |
| 466 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 467 | mDrawScaleUniformLocation = glGetUniformLocation(mProgram, "drawScale"); |
| 468 | ASSERT_NE(-1, mDrawScaleUniformLocation); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 469 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 470 | 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 Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 479 | class Sampler2DAsFunctionParameterTest : public Texture2DTest |
| 480 | { |
| 481 | protected: |
| 482 | Sampler2DAsFunctionParameterTest() : Texture2DTest() {} |
| 483 | |
| 484 | std::string getFragmentShaderSource() override |
| 485 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 486 | return |
| 487 | R"(precision highp float; |
Olli Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 488 | 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 499 | })"; |
Olli Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 500 | } |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 501 | |
| 502 | void SetUp() override |
| 503 | { |
| 504 | Texture2DTest::SetUp(); |
| 505 | setUpProgram(); |
| 506 | } |
Olli Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 507 | }; |
| 508 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 509 | class 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 523 | return |
| 524 | R"(precision highp float; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 525 | 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 533 | })"; |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | void SetUp() override |
| 537 | { |
| 538 | TexCoordDrawTest::SetUp(); |
| 539 | |
| 540 | glGenTextures(1, &mTextureCube); |
| 541 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 542 | 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 547 | EXPECT_GL_NO_ERROR(); |
| 548 | |
| 549 | mTexture2D = create2DTexture(); |
| 550 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 551 | setUpProgram(); |
| 552 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 553 | 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 Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 571 | class TextureCubeTestES3 : public ANGLETest |
| 572 | { |
| 573 | protected: |
| 574 | TextureCubeTestES3() {} |
| 575 | }; |
| 576 | |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 577 | class 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 591 | return |
| 592 | R"(precision mediump float; |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 593 | 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 599 | })"; |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void SetUp() override |
| 603 | { |
| 604 | TexCoordDrawTest::SetUp(); |
| 605 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 606 | setUpProgram(); |
| 607 | |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 608 | 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 Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 658 | class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest |
| 659 | { |
| 660 | protected: |
| 661 | SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {} |
| 662 | |
| 663 | std::string getFragmentShaderSource() override |
| 664 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 665 | return |
| 666 | R"(precision mediump float; |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 667 | 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 678 | })"; |
Olli Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 679 | } |
| 680 | }; |
| 681 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 682 | class 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 Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 690 | "#version 300 es\n" |
| 691 | "out vec2 texcoord;\n" |
| 692 | "in vec4 position;\n" |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 693 | "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 Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 699 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 700 | std::string getFragmentShaderSource() override |
| 701 | { |
| 702 | return std::string( |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 703 | "#version 300 es\n" |
| 704 | "precision highp float;\n" |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 705 | "uniform highp sampler2DArray tex2DArray;\n" |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 706 | "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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 711 | "}\n"); |
| 712 | } |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 713 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 714 | void SetUp() override |
| 715 | { |
| 716 | TexCoordDrawTest::SetUp(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 717 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 718 | setUpProgram(); |
| 719 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 720 | mTextureArrayLocation = glGetUniformLocation(mProgram, "tex2DArray"); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 721 | 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 730 | TexCoordDrawTest::TearDown(); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | GLuint m2DArrayTexture; |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 734 | GLint mTextureArrayLocation; |
| 735 | }; |
| 736 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 737 | class 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 Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 751 | return std::string(essl3_shaders::vs::Simple()); |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 752 | } |
| 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 773 | setUpProgram(); |
| 774 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 775 | 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 Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 798 | class 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 Etuaho | 1a67990 | 2016-01-14 12:21:47 +0200 | [diff] [blame] | 852 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 905 | setUpProgram(); |
| 906 | |
Olli Etuaho | 1a67990 | 2016-01-14 12:21:47 +0200 | [diff] [blame] | 907 | 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 Etuaho | c8c99a0 | 2016-01-14 16:47:22 +0200 | [diff] [blame] | 929 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 996 | setUpProgram(); |
| 997 | |
Olli Etuaho | c8c99a0 | 2016-01-14 16:47:22 +0200 | [diff] [blame] | 998 | 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 Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 1032 | class 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1058 | setUpProgram(); |
| 1059 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 1060 | glActiveTexture(GL_TEXTURE0); |
| 1061 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1062 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1063 | &GLColor::green); |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 1064 | drawQuad(mProgram, "position", 0.5f); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1065 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 1066 | } |
| 1067 | }; |
| 1068 | |
| 1069 | class 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 | |
| 1095 | class 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 | |
| 1123 | class 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 | |
| 1155 | class 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1179 | TEST_P(Texture2DTest, NegativeAPISubImage) |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 1180 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1181 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 1182 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 1183 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1184 | setUpProgram(); |
| 1185 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1186 | const GLubyte *pixels[20] = {0}; |
Jamie Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 1187 | glTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 1188 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 1189 | |
| 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 Madill | f67115c | 2014-04-22 13:14:05 -0400 | [diff] [blame] | 1199 | } |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1200 | |
John Bauman | 1831918 | 2016-09-28 14:22:27 -0700 | [diff] [blame] | 1201 | // Test that querying GL_TEXTURE_BINDING* doesn't cause an unexpected error. |
| 1202 | TEST_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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1225 | TEST_P(Texture2DTest, ZeroSizedUploads) |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1226 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1227 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1228 | EXPECT_GL_ERROR(GL_NO_ERROR); |
| 1229 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1230 | setUpProgram(); |
| 1231 | |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1232 | // Use the texture first to make sure it's in video memory |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1233 | glUseProgram(mProgram); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1234 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1235 | drawQuad(mProgram, "position", 0.5f); |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1236 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1237 | const GLubyte *pixel[4] = {0}; |
Geoff Lang | c41e42d | 2014-04-28 10:58:16 -0400 | [diff] [blame] | 1238 | |
| 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 Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1248 | |
| 1249 | // Test drawing with two texture types, to trigger an ANGLE bug in validation |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1250 | TEST_P(TextureCubeTest, CubeMapBug) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1251 | { |
| 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1258 | glUseProgram(mProgram); |
| 1259 | glUniform1i(mTexture2DUniformLocation, 0); |
| 1260 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 1261 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1262 | EXPECT_GL_NO_ERROR(); |
| 1263 | } |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1264 | |
Olli Etuaho | 53a2da1 | 2016-01-11 15:43:32 +0200 | [diff] [blame] | 1265 | // Test drawing with two texture types accessed from the same shader and check that the result of |
| 1266 | // drawing is correct. |
| 1267 | TEST_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 Etuaho | 4644a20 | 2016-01-12 15:12:53 +0200 | [diff] [blame] | 1297 | TEST_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 Etuaho | 2173db3d | 2016-01-12 13:55:14 +0200 | [diff] [blame] | 1315 | // Test drawing with two textures passed to the shader in a sampler array. |
| 1316 | TEST_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. |
| 1323 | TEST_P(SamplerArrayAsFunctionParameterTest, SamplerArrayAsFunctionParameter) |
| 1324 | { |
| 1325 | testSamplerArrayDraw(); |
| 1326 | } |
| 1327 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1328 | // Copy of a test in conformance/textures/texture-mips, to test generate mipmaps |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1329 | TEST_P(Texture2DTestWithDrawScale, MipmapsTwice) |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1330 | { |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 1331 | // TODO(lucferron): Diagnose and fix |
| 1332 | // http://anglebug.com/2653 |
| 1333 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1334 | |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1335 | int px = getWindowWidth() / 2; |
| 1336 | int py = getWindowHeight() / 2; |
| 1337 | |
| 1338 | glActiveTexture(GL_TEXTURE0); |
| 1339 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1340 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1341 | std::vector<GLColor> pixelsRed(16u * 16u, GLColor::red); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1342 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1343 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1344 | 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1348 | glUseProgram(mProgram); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1349 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1350 | glUniform2f(mDrawScaleUniformLocation, 0.0625f, 0.0625f); |
| 1351 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1352 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1353 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1354 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1355 | std::vector<GLColor> pixelsBlue(16u * 16u, GLColor::blue); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1356 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1357 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1358 | pixelsBlue.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1359 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1360 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1361 | std::vector<GLColor> pixelsGreen(16u * 16u, GLColor::green); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1362 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1363 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1364 | pixelsGreen.data()); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1365 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1366 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1367 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1368 | |
| 1369 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1370 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green); |
Jamie Madill | 9aca059 | 2014-10-06 16:26:59 -0400 | [diff] [blame] | 1371 | } |
Jamie Madill | f8fccb3 | 2014-11-12 15:05:26 -0500 | [diff] [blame] | 1372 | |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1373 | // 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1375 | TEST_P(TextureCubeTest, CubeMapFBO) |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1376 | { |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 1377 | // TODO(jmadill): Cube map render targets. http://anglebug.com/2470 |
| 1378 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1379 | |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1380 | GLuint fbo; |
| 1381 | glGenFramebuffers(1, &fbo); |
| 1382 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 1383 | |
| 1384 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1385 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
| 1386 | mTextureCube, 0); |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1387 | |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 1388 | EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
Jamie Madill | eb32a2e | 2014-12-10 14:27:53 -0500 | [diff] [blame] | 1389 | |
| 1390 | glDeleteFramebuffers(1, &fbo); |
| 1391 | |
| 1392 | EXPECT_GL_NO_ERROR(); |
| 1393 | } |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1394 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1395 | // Test that glTexSubImage2D works properly when glTexStorage2DEXT has initialized the image with a |
| 1396 | // default color. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1397 | TEST_P(Texture2DTest, TexStorage) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1398 | { |
Luc Ferron | 7348fc5 | 2018-05-09 07:17:16 -0400 | [diff] [blame] | 1399 | ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_texture_storage")); |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 1400 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1401 | int width = getWindowWidth(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1402 | 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 Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1419 | // 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 Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 1421 | 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 Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1429 | |
| 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 Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1436 | setUpProgram(); |
| 1437 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1438 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1439 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1440 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1441 | glDeleteTextures(1, &tex2D); |
| 1442 | EXPECT_GL_NO_ERROR(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1443 | EXPECT_PIXEL_EQ(width / 4, height / 4, 255, 0, 0, 255); |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 1444 | |
| 1445 | // Validate that the region of the texture without data has an alpha of 1.0 |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1446 | angle::GLColor pixel = ReadColor(3 * width / 4, 3 * height / 4); |
| 1447 | EXPECT_EQ(255, pixel.A); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1450 | // Test that glTexSubImage2D combined with a PBO works properly when glTexStorage2DEXT has |
| 1451 | // initialized the image with a default color. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1452 | TEST_P(Texture2DTest, TexStorageWithPBO) |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1453 | { |
| 1454 | if (extensionEnabled("NV_pixel_buffer_object")) |
| 1455 | { |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1456 | int width = getWindowWidth(); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1457 | 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 Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1480 | // 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 Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1482 | 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 He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1486 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, nullptr); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1487 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1488 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1489 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1490 | setUpProgram(); |
| 1491 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1492 | glUseProgram(mProgram); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1493 | glUniform1i(mTexture2DUniformLocation, 0); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1494 | drawQuad(mProgram, "position", 0.5f); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1495 | glDeleteTextures(1, &tex2D); |
Olli Etuaho | 19d48db | 2016-01-13 14:43:21 +0200 | [diff] [blame] | 1496 | glDeleteBuffers(1, &pbo); |
Gregoire Payen de La Garanderie | 88fe1ad | 2015-01-19 15:09:26 +0000 | [diff] [blame] | 1497 | 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 Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1502 | |
| 1503 | // See description on testFloatCopySubImage |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1504 | TEST_P(Texture2DTest, CopySubImageFloat_R_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1505 | { |
| 1506 | testFloatCopySubImage(1, 1); |
| 1507 | } |
| 1508 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1509 | TEST_P(Texture2DTest, CopySubImageFloat_RG_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1510 | { |
| 1511 | testFloatCopySubImage(2, 1); |
| 1512 | } |
| 1513 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1514 | TEST_P(Texture2DTest, CopySubImageFloat_RG_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1515 | { |
| 1516 | testFloatCopySubImage(2, 2); |
| 1517 | } |
| 1518 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1519 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1520 | { |
| 1521 | testFloatCopySubImage(3, 1); |
| 1522 | } |
| 1523 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1524 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1525 | { |
| 1526 | testFloatCopySubImage(3, 2); |
| 1527 | } |
| 1528 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1529 | TEST_P(Texture2DTest, CopySubImageFloat_RGB_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1530 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1531 | // TODO(cwallez): Fix on Linux Intel drivers (http://anglebug.com/1346) |
| 1532 | ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux()); |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 1533 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1534 | // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284) |
| 1535 | ANGLE_SKIP_TEST_IF(IsD3D11_FL93()); |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1536 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1537 | testFloatCopySubImage(3, 3); |
| 1538 | } |
| 1539 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1540 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_R) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1541 | { |
| 1542 | testFloatCopySubImage(4, 1); |
| 1543 | } |
| 1544 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1545 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RG) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1546 | { |
| 1547 | testFloatCopySubImage(4, 2); |
| 1548 | } |
| 1549 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1550 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGB) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1551 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1552 | // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284) |
| 1553 | ANGLE_SKIP_TEST_IF(IsD3D11_FL93()); |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1554 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1555 | testFloatCopySubImage(4, 3); |
| 1556 | } |
| 1557 | |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1558 | TEST_P(Texture2DTest, CopySubImageFloat_RGBA_RGBA) |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1559 | { |
Luc Ferron | fa7503c | 2018-05-08 11:25:06 -0400 | [diff] [blame] | 1560 | // TODO(lucferron): copySubImage isn't implemented yet. |
| 1561 | // http://anglebug.com/2501 |
| 1562 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1563 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1564 | // Ignore SDK layers messages on D3D11 FL 9.3 (http://anglebug.com/1284) |
| 1565 | ANGLE_SKIP_TEST_IF(IsD3D11_FL93()); |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 1566 | |
Jamie Madill | bc393df | 2015-01-29 13:46:07 -0500 | [diff] [blame] | 1567 | testFloatCopySubImage(4, 4); |
| 1568 | } |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1569 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1570 | // 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 Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1574 | TEST_P(Texture2DTest, TextureNPOT_GL_ALPHA_UBYTE) |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1575 | { |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 1576 | // TODO(lucferron): DIRTY_BIT_UNPACK_STATE isn't implemented on Vulkan yet. |
| 1577 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1578 | |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1579 | const int npotTexSize = 5; |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1580 | const int potTexSize = 4; // Should be less than npotTexSize |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1581 | GLuint tex2D; |
| 1582 | |
| 1583 | if (extensionEnabled("GL_OES_texture_npot")) |
| 1584 | { |
| 1585 | // This test isn't applicable if texture_npot is enabled |
| 1586 | return; |
| 1587 | } |
| 1588 | |
Olli Etuaho | a1c917f | 2016-04-06 13:50:03 +0300 | [diff] [blame] | 1589 | setUpProgram(); |
| 1590 | |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1591 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 1592 | |
Austin Kinross | 5faa15b | 2016-01-11 13:32:48 -0800 | [diff] [blame] | 1593 | // Default unpack alignment is 4. The values of 'pixels' below needs it to be 1. |
| 1594 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 1595 | |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1596 | glActiveTexture(GL_TEXTURE0); |
| 1597 | glGenTextures(1, &tex2D); |
| 1598 | glBindTexture(GL_TEXTURE_2D, tex2D); |
| 1599 | |
| 1600 | std::vector<GLubyte> pixels(1 * npotTexSize * npotTexSize); |
| 1601 | for (size_t pixelId = 0; pixelId < npotTexSize * npotTexSize; ++pixelId) |
| 1602 | { |
| 1603 | pixels[pixelId] = 64; |
| 1604 | } |
| 1605 | |
| 1606 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1607 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1608 | |
| 1609 | // Check that an NPOT texture not on level 0 generates INVALID_VALUE |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1610 | glTexImage2D(GL_TEXTURE_2D, 1, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, |
| 1611 | GL_UNSIGNED_BYTE, pixels.data()); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1612 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 1613 | |
| 1614 | // Check that an NPOT texture on level 0 succeeds |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1615 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, npotTexSize, npotTexSize, 0, GL_ALPHA, |
| 1616 | GL_UNSIGNED_BYTE, pixels.data()); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1617 | EXPECT_GL_NO_ERROR(); |
| 1618 | |
| 1619 | // Check that generateMipmap fails on NPOT |
| 1620 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1621 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1622 | |
| 1623 | // Check that nothing is drawn if filtering is not correct for NPOT |
| 1624 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1625 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1626 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1627 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1628 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1629 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1630 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 1631 | |
| 1632 | // NPOT texture with TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255 |
| 1633 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1634 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1635 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); |
| 1636 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1637 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1638 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 255); |
| 1639 | |
| 1640 | // NPOT texture with TEXTURE_MIN_FILTER set to LINEAR should draw |
| 1641 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1642 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1643 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1644 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 1645 | |
| 1646 | // Check that glTexImage2D for POT texture succeeds |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 1647 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, potTexSize, potTexSize, 0, GL_ALPHA, GL_UNSIGNED_BYTE, |
| 1648 | pixels.data()); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1649 | EXPECT_GL_NO_ERROR(); |
| 1650 | |
| 1651 | // Check that generateMipmap for an POT texture succeeds |
| 1652 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1653 | EXPECT_GL_NO_ERROR(); |
| 1654 | |
| 1655 | // POT texture with TEXTURE_MIN_FILTER set to LINEAR_MIPMAP_LINEAR should draw |
| 1656 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1657 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1658 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1659 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1660 | glClear(GL_COLOR_BUFFER_BIT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1661 | drawQuad(mProgram, "position", 1.0f); |
Austin Kinross | 0728514 | 2015-03-26 11:36:16 -0700 | [diff] [blame] | 1662 | EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 64); |
| 1663 | EXPECT_GL_NO_ERROR(); |
| 1664 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1665 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1666 | // Test to ensure that glTexSubImage2D always accepts data for non-power-of-two subregions. |
| 1667 | // ANGLE previously rejected this if GL_OES_texture_npot wasn't active, which is incorrect. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 1668 | TEST_P(Texture2DTest, NPOTSubImageParameters) |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1669 | { |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 1670 | // TODO(lucferron): Generate mipmap on vulkan isn't implemented yet. Re-enable this when it |
| 1671 | // is. |
| 1672 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 1673 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1674 | glActiveTexture(GL_TEXTURE0); |
| 1675 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1676 | |
| 1677 | // Create an 8x8 (i.e. power-of-two) texture. |
| 1678 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1679 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 1680 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1681 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1682 | |
| 1683 | // Supply a 3x3 (i.e. non-power-of-two) subimage to the texture. |
| 1684 | // This should always work, even if GL_OES_texture_npot isn't active. |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 1685 | std::array<GLColor, 3 * 3> data; |
| 1686 | glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, data.data()); |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1687 | |
| 1688 | EXPECT_GL_NO_ERROR(); |
| 1689 | } |
| 1690 | |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 1691 | // Test to check that texture completeness is determined correctly when the texture base level is |
| 1692 | // greater than 0, and also that level 0 is not sampled when base level is greater than 0. |
| 1693 | TEST_P(Texture2DTestES3, DrawWithBaseLevel1) |
| 1694 | { |
| 1695 | glActiveTexture(GL_TEXTURE0); |
| 1696 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1697 | |
| 1698 | std::vector<GLColor> texDataRed(4u * 4u, GLColor::red); |
| 1699 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data()); |
| 1700 | std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green); |
| 1701 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1702 | texDataGreen.data()); |
| 1703 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1704 | texDataGreen.data()); |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 1705 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1706 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1707 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1708 | |
| 1709 | EXPECT_GL_NO_ERROR(); |
| 1710 | |
| 1711 | drawQuad(mProgram, "position", 0.5f); |
| 1712 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1713 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1714 | } |
| 1715 | |
| 1716 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not |
| 1717 | // have images defined. |
| 1718 | TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeUndefined) |
| 1719 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1720 | // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array. |
| 1721 | ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL()); |
| 1722 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1723 | glActiveTexture(GL_TEXTURE0); |
| 1724 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1725 | std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green); |
| 1726 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1727 | texDataGreen.data()); |
| 1728 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1729 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1730 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1731 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1732 | |
| 1733 | EXPECT_GL_NO_ERROR(); |
| 1734 | |
| 1735 | drawQuad(mProgram, "position", 0.5f); |
| 1736 | |
| 1737 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1738 | } |
| 1739 | |
Olli Etuaho | e8528d8 | 2016-05-16 17:50:52 +0300 | [diff] [blame] | 1740 | // Test that drawing works correctly when level 0 is undefined and base level is 1. |
| 1741 | TEST_P(Texture2DTestES3, DrawWithLevelZeroUndefined) |
| 1742 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1743 | // Observed crashing on AMD. Oddly the crash only happens with 2D textures, not 3D or array. |
| 1744 | ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL()); |
| 1745 | |
Olli Etuaho | e8528d8 | 2016-05-16 17:50:52 +0300 | [diff] [blame] | 1746 | glActiveTexture(GL_TEXTURE0); |
| 1747 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1748 | std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green); |
| 1749 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1750 | texDataGreen.data()); |
| 1751 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1752 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1753 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1754 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); |
| 1755 | |
| 1756 | EXPECT_GL_NO_ERROR(); |
| 1757 | |
| 1758 | // Texture is incomplete. |
| 1759 | drawQuad(mProgram, "position", 0.5f); |
| 1760 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); |
| 1761 | |
| 1762 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1763 | texDataGreen.data()); |
| 1764 | |
| 1765 | // Texture is now complete. |
| 1766 | drawQuad(mProgram, "position", 0.5f); |
| 1767 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1768 | } |
| 1769 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1770 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have |
| 1771 | // dimensions that don't fit the images inside the range. |
| 1772 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 1773 | TEST_P(Texture2DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions) |
| 1774 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1775 | glActiveTexture(GL_TEXTURE0); |
| 1776 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1777 | std::vector<GLColor> texDataRed(8u * 8u, GLColor::red); |
| 1778 | std::vector<GLColor> texDataGreen(2u * 2u, GLColor::green); |
| 1779 | std::vector<GLColor> texDataCyan(2u * 2u, GLColor::cyan); |
| 1780 | |
| 1781 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1782 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1783 | |
| 1784 | // Two levels that are initially unused. |
| 1785 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, texDataRed.data()); |
| 1786 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1787 | texDataCyan.data()); |
| 1788 | |
| 1789 | // One level that is used - only this level should affect completeness. |
| 1790 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1791 | texDataGreen.data()); |
| 1792 | |
| 1793 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1794 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1795 | |
| 1796 | EXPECT_GL_NO_ERROR(); |
| 1797 | |
| 1798 | drawQuad(mProgram, "position", 0.5f); |
| 1799 | |
| 1800 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1801 | |
Yunchao He | 2f23f35 | 2018-02-11 22:11:37 +0800 | [diff] [blame] | 1802 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL()); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1803 | |
| 1804 | // Switch the level that is being used to the cyan level 2. |
| 1805 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2); |
| 1806 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); |
| 1807 | |
| 1808 | EXPECT_GL_NO_ERROR(); |
| 1809 | |
| 1810 | drawQuad(mProgram, "position", 0.5f); |
| 1811 | |
| 1812 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan); |
| 1813 | } |
| 1814 | |
| 1815 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not |
| 1816 | // have images defined. |
| 1817 | TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeUndefined) |
| 1818 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1819 | glActiveTexture(GL_TEXTURE0); |
| 1820 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 1821 | std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green); |
| 1822 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1823 | texDataGreen.data()); |
| 1824 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1825 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1826 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1827 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1828 | |
| 1829 | EXPECT_GL_NO_ERROR(); |
| 1830 | |
| 1831 | drawQuad(mProgram, "position", 0.5f); |
| 1832 | |
| 1833 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1834 | } |
| 1835 | |
| 1836 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have |
| 1837 | // dimensions that don't fit the images inside the range. |
| 1838 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 1839 | TEST_P(Texture3DTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions) |
| 1840 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1841 | glActiveTexture(GL_TEXTURE0); |
| 1842 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 1843 | std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red); |
| 1844 | std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green); |
| 1845 | std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan); |
| 1846 | |
| 1847 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1848 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1849 | |
| 1850 | // Two levels that are initially unused. |
| 1851 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1852 | texDataRed.data()); |
| 1853 | glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1854 | texDataCyan.data()); |
| 1855 | |
| 1856 | // One level that is used - only this level should affect completeness. |
| 1857 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1858 | texDataGreen.data()); |
| 1859 | |
| 1860 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 1); |
| 1861 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1862 | |
| 1863 | EXPECT_GL_NO_ERROR(); |
| 1864 | |
| 1865 | drawQuad(mProgram, "position", 0.5f); |
| 1866 | |
| 1867 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1868 | |
Yunchao He | 2f23f35 | 2018-02-11 22:11:37 +0800 | [diff] [blame] | 1869 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL()); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1870 | |
| 1871 | // Switch the level that is being used to the cyan level 2. |
| 1872 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 2); |
| 1873 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 2); |
| 1874 | |
| 1875 | EXPECT_GL_NO_ERROR(); |
| 1876 | |
| 1877 | drawQuad(mProgram, "position", 0.5f); |
| 1878 | |
| 1879 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan); |
| 1880 | } |
| 1881 | |
| 1882 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range do not |
| 1883 | // have images defined. |
| 1884 | TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeUndefined) |
| 1885 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1886 | glActiveTexture(GL_TEXTURE0); |
| 1887 | glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture); |
| 1888 | std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green); |
| 1889 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1890 | texDataGreen.data()); |
| 1891 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1892 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1893 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1); |
| 1894 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1); |
| 1895 | |
| 1896 | EXPECT_GL_NO_ERROR(); |
| 1897 | |
| 1898 | drawQuad(mProgram, "position", 0.5f); |
| 1899 | |
| 1900 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1901 | } |
| 1902 | |
| 1903 | // Test that drawing works correctly when levels outside the BASE_LEVEL/MAX_LEVEL range have |
| 1904 | // dimensions that don't fit the images inside the range. |
| 1905 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 1906 | TEST_P(Texture2DArrayTestES3, DrawWithLevelsOutsideRangeWithInconsistentDimensions) |
| 1907 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1908 | glActiveTexture(GL_TEXTURE0); |
| 1909 | glBindTexture(GL_TEXTURE_3D, m2DArrayTexture); |
| 1910 | std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red); |
| 1911 | std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green); |
| 1912 | std::vector<GLColor> texDataCyan(2u * 2u * 2u, GLColor::cyan); |
| 1913 | |
| 1914 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1915 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1916 | |
| 1917 | // Two levels that are initially unused. |
| 1918 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1919 | texDataRed.data()); |
| 1920 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 2, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1921 | texDataCyan.data()); |
| 1922 | |
| 1923 | // One level that is used - only this level should affect completeness. |
| 1924 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1925 | texDataGreen.data()); |
| 1926 | |
| 1927 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 1); |
| 1928 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1); |
| 1929 | |
| 1930 | EXPECT_GL_NO_ERROR(); |
| 1931 | |
| 1932 | drawQuad(mProgram, "position", 0.5f); |
| 1933 | |
| 1934 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1935 | |
Yunchao He | 2f23f35 | 2018-02-11 22:11:37 +0800 | [diff] [blame] | 1936 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsOpenGL()); |
| 1937 | |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 1938 | // NVIDIA was observed drawing color 0,0,0,0 instead of the texture color after the base |
| 1939 | // level was changed. |
| 1940 | ANGLE_SKIP_TEST_IF(IsNVIDIA() && (IsOpenGL() || IsOpenGLES())); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1941 | |
| 1942 | // Switch the level that is being used to the cyan level 2. |
| 1943 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 2); |
| 1944 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 2); |
| 1945 | |
| 1946 | EXPECT_GL_NO_ERROR(); |
| 1947 | |
| 1948 | drawQuad(mProgram, "position", 0.5f); |
| 1949 | |
| 1950 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan); |
| 1951 | } |
| 1952 | |
| 1953 | // Test that texture completeness is updated if texture max level changes. |
| 1954 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 1955 | TEST_P(Texture2DTestES3, TextureCompletenessChangesWithMaxLevel) |
| 1956 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1957 | glActiveTexture(GL_TEXTURE0); |
| 1958 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 1959 | std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green); |
| 1960 | |
| 1961 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1962 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1963 | |
| 1964 | // A level that is initially unused. |
| 1965 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1966 | texDataGreen.data()); |
| 1967 | |
| 1968 | // One level that is initially used - only this level should affect completeness. |
| 1969 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1970 | texDataGreen.data()); |
| 1971 | |
| 1972 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
| 1973 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); |
| 1974 | |
| 1975 | EXPECT_GL_NO_ERROR(); |
| 1976 | |
| 1977 | drawQuad(mProgram, "position", 0.5f); |
| 1978 | |
| 1979 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 1980 | |
| 1981 | // Switch the max level to level 1. The levels within the used range now have inconsistent |
| 1982 | // dimensions and the texture should be incomplete. |
| 1983 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1984 | |
| 1985 | EXPECT_GL_NO_ERROR(); |
| 1986 | |
| 1987 | drawQuad(mProgram, "position", 0.5f); |
| 1988 | |
| 1989 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); |
| 1990 | } |
| 1991 | |
| 1992 | // Test that 3D texture completeness is updated if texture max level changes. |
| 1993 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 1994 | TEST_P(Texture3DTestES3, Texture3DCompletenessChangesWithMaxLevel) |
| 1995 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 1996 | glActiveTexture(GL_TEXTURE0); |
| 1997 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 1998 | std::vector<GLColor> texDataGreen(2u * 2u * 2u, GLColor::green); |
| 1999 | |
| 2000 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2001 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 2002 | |
| 2003 | // A level that is initially unused. |
| 2004 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 1, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2005 | texDataGreen.data()); |
| 2006 | |
| 2007 | // One level that is initially used - only this level should affect completeness. |
| 2008 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2009 | texDataGreen.data()); |
| 2010 | |
| 2011 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); |
| 2012 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0); |
| 2013 | |
| 2014 | EXPECT_GL_NO_ERROR(); |
| 2015 | |
| 2016 | drawQuad(mProgram, "position", 0.5f); |
| 2017 | |
| 2018 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2019 | |
| 2020 | // Switch the max level to level 1. The levels within the used range now have inconsistent |
| 2021 | // dimensions and the texture should be incomplete. |
| 2022 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1); |
| 2023 | |
| 2024 | EXPECT_GL_NO_ERROR(); |
| 2025 | |
| 2026 | drawQuad(mProgram, "position", 0.5f); |
| 2027 | |
| 2028 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); |
| 2029 | } |
| 2030 | |
| 2031 | // Test that texture completeness is updated if texture base level changes. |
| 2032 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 2033 | TEST_P(Texture2DTestES3, TextureCompletenessChangesWithBaseLevel) |
| 2034 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2035 | glActiveTexture(GL_TEXTURE0); |
| 2036 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2037 | std::vector<GLColor> texDataGreen(8u * 8u, GLColor::green); |
| 2038 | |
| 2039 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2040 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 2041 | |
| 2042 | // Two levels that are initially unused. |
| 2043 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2044 | texDataGreen.data()); |
| 2045 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2046 | texDataGreen.data()); |
| 2047 | |
| 2048 | // One level that is initially used - only this level should affect completeness. |
| 2049 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2050 | texDataGreen.data()); |
| 2051 | |
| 2052 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2); |
| 2053 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); |
| 2054 | |
| 2055 | EXPECT_GL_NO_ERROR(); |
| 2056 | |
| 2057 | drawQuad(mProgram, "position", 0.5f); |
| 2058 | |
| 2059 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2060 | |
| 2061 | // Switch the base level to level 1. The levels within the used range now have inconsistent |
| 2062 | // dimensions and the texture should be incomplete. |
| 2063 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 2064 | |
| 2065 | EXPECT_GL_NO_ERROR(); |
| 2066 | |
| 2067 | drawQuad(mProgram, "position", 0.5f); |
| 2068 | |
| 2069 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); |
| 2070 | } |
| 2071 | |
| 2072 | // Test that texture is not complete if base level is greater than max level. |
| 2073 | // GLES 3.0.4 section 3.8.13 Texture completeness |
| 2074 | TEST_P(Texture2DTestES3, TextureBaseLevelGreaterThanMaxLevel) |
| 2075 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2076 | glActiveTexture(GL_TEXTURE0); |
| 2077 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2078 | |
| 2079 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2080 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2081 | |
| 2082 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); |
| 2083 | |
| 2084 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000); |
| 2085 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); |
| 2086 | |
| 2087 | EXPECT_GL_NO_ERROR(); |
| 2088 | |
| 2089 | drawQuad(mProgram, "position", 0.5f); |
| 2090 | |
| 2091 | // Texture should be incomplete. |
| 2092 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); |
| 2093 | } |
| 2094 | |
| 2095 | // Test that immutable texture base level and max level are clamped. |
| 2096 | // GLES 3.0.4 section 3.8.10 subsection Mipmapping |
| 2097 | TEST_P(Texture2DTestES3, ImmutableTextureBaseLevelOutOfRange) |
| 2098 | { |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2099 | glActiveTexture(GL_TEXTURE0); |
| 2100 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2101 | |
| 2102 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2103 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2104 | |
| 2105 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1); |
| 2106 | |
| 2107 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); |
| 2108 | |
| 2109 | // For immutable-format textures, base level should be clamped to [0, levels - 1], and max level |
| 2110 | // should be clamped to [base_level, levels - 1]. |
| 2111 | // GLES 3.0.4 section 3.8.10 subsection Mipmapping |
| 2112 | // In the case of this test, those rules make the effective base level and max level 0. |
| 2113 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000); |
| 2114 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000); |
| 2115 | |
| 2116 | EXPECT_GL_NO_ERROR(); |
| 2117 | |
| 2118 | drawQuad(mProgram, "position", 0.5f); |
| 2119 | |
| 2120 | // Texture should be complete. |
| 2121 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2122 | } |
| 2123 | |
Olli Etuaho | 87fc71c | 2016-05-11 14:25:21 +0300 | [diff] [blame] | 2124 | // Test that changing base level works when it affects the format of the texture. |
| 2125 | TEST_P(Texture2DTestES3, TextureFormatChangesWithBaseLevel) |
| 2126 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2127 | // Observed rendering corruption on NVIDIA OpenGL. |
| 2128 | ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGL()); |
| 2129 | |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2130 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL()); |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2131 | |
| 2132 | // Observed incorrect rendering on AMD OpenGL. |
| 2133 | ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL()); |
Olli Etuaho | 87fc71c | 2016-05-11 14:25:21 +0300 | [diff] [blame] | 2134 | |
| 2135 | glActiveTexture(GL_TEXTURE0); |
| 2136 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2137 | std::vector<GLColor> texDataCyan(4u * 4u, GLColor::cyan); |
| 2138 | std::vector<GLColor> texDataGreen(4u * 4u, GLColor::green); |
| 2139 | |
| 2140 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2141 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 2142 | |
| 2143 | // RGBA8 level that's initially unused. |
| 2144 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2145 | texDataCyan.data()); |
| 2146 | |
| 2147 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 2148 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); |
| 2149 | |
| 2150 | // RG8 level that's initially used, with consistent dimensions with level 0 but a different |
| 2151 | // format. It reads green channel data from the green and alpha channels of texDataGreen |
| 2152 | // (this is a bit hacky but works). |
| 2153 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RG8, 2, 2, 0, GL_RG, GL_UNSIGNED_BYTE, texDataGreen.data()); |
| 2154 | |
| 2155 | EXPECT_GL_NO_ERROR(); |
| 2156 | |
| 2157 | drawQuad(mProgram, "position", 0.5f); |
| 2158 | |
| 2159 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 2160 | |
| 2161 | // Switch the texture to use the cyan level 0 with the RGBA format. |
| 2162 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
| 2163 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); |
| 2164 | |
| 2165 | EXPECT_GL_NO_ERROR(); |
| 2166 | |
| 2167 | drawQuad(mProgram, "position", 0.5f); |
| 2168 | |
| 2169 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan); |
| 2170 | } |
| 2171 | |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2172 | // Test that setting a texture image works when base level is out of range. |
| 2173 | TEST_P(Texture2DTestES3, SetImageWhenBaseLevelOutOfRange) |
| 2174 | { |
| 2175 | glActiveTexture(GL_TEXTURE0); |
| 2176 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2177 | |
| 2178 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2179 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2180 | |
| 2181 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 10000); |
| 2182 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 10000); |
| 2183 | |
| 2184 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); |
| 2185 | |
| 2186 | EXPECT_GL_NO_ERROR(); |
| 2187 | |
| 2188 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
| 2189 | |
| 2190 | drawQuad(mProgram, "position", 0.5f); |
| 2191 | |
| 2192 | // Texture should be complete. |
| 2193 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
Olli Etuaho | a7416ff | 2016-01-18 12:22:55 +0200 | [diff] [blame] | 2194 | } |
| 2195 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 2196 | // In the D3D11 renderer, we need to initialize some texture formats, to fill empty channels. EG |
| 2197 | // RBA->RGBA8, with 1.0 in the alpha channel. This test covers a bug where redefining array textures |
| 2198 | // with these formats does not work as expected. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2199 | TEST_P(Texture2DArrayTestES3, RedefineInittableArray) |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 2200 | { |
| 2201 | std::vector<GLubyte> pixelData; |
| 2202 | for (size_t count = 0; count < 5000; count++) |
| 2203 | { |
| 2204 | pixelData.push_back(0u); |
| 2205 | pixelData.push_back(255u); |
| 2206 | pixelData.push_back(0u); |
| 2207 | } |
| 2208 | |
| 2209 | glBindTexture(GL_TEXTURE_2D_ARRAY, m2DArrayTexture); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2210 | glUseProgram(mProgram); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 2211 | glUniform1i(mTextureArrayLocation, 0); |
| 2212 | |
| 2213 | // The first draw worked correctly. |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 2214 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, |
| 2215 | &pixelData[0]); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 2216 | |
| 2217 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2218 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2219 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 2220 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2221 | drawQuad(mProgram, "position", 1.0f); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2222 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 2223 | |
| 2224 | // The dimension of the respecification must match the original exactly to trigger the bug. |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 2225 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 4, 4, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, |
| 2226 | &pixelData[0]); |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 2227 | drawQuad(mProgram, "position", 1.0f); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 2228 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
Jamie Madill | 2453dbc | 2015-07-14 11:35:42 -0400 | [diff] [blame] | 2229 | |
| 2230 | ASSERT_GL_NO_ERROR(); |
| 2231 | } |
| 2232 | |
Olli Etuaho | 1a67990 | 2016-01-14 12:21:47 +0200 | [diff] [blame] | 2233 | // Test shadow sampler and regular non-shadow sampler coexisting in the same shader. |
| 2234 | // This test is needed especially to confirm that sampler registers get assigned correctly on |
| 2235 | // the HLSL backend even when there's a mix of different HLSL sampler and texture types. |
| 2236 | TEST_P(ShadowSamplerPlusSampler3DTestES3, ShadowSamplerPlusSampler3DDraw) |
| 2237 | { |
| 2238 | glActiveTexture(GL_TEXTURE0); |
| 2239 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 2240 | GLubyte texData[4]; |
| 2241 | texData[0] = 0; |
| 2242 | texData[1] = 60; |
| 2243 | texData[2] = 0; |
| 2244 | texData[3] = 255; |
| 2245 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 2246 | |
| 2247 | glActiveTexture(GL_TEXTURE1); |
| 2248 | glBindTexture(GL_TEXTURE_2D, mTextureShadow); |
| 2249 | GLfloat depthTexData[1]; |
| 2250 | depthTexData[0] = 0.5f; |
| 2251 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 2252 | depthTexData); |
| 2253 | |
| 2254 | glUseProgram(mProgram); |
| 2255 | glUniform1f(mDepthRefUniformLocation, 0.3f); |
| 2256 | glUniform1i(mTexture3DUniformLocation, 0); |
| 2257 | glUniform1i(mTextureShadowUniformLocation, 1); |
| 2258 | |
| 2259 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 2260 | drawQuad(mProgram, "position", 0.5f); |
| 2261 | EXPECT_GL_NO_ERROR(); |
| 2262 | // The shader writes 0.5 * <comparison result (1.0)> + <texture color> |
| 2263 | EXPECT_PIXEL_NEAR(0, 0, 128, 188, 128, 255, 2); |
| 2264 | |
| 2265 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GREATER); |
| 2266 | drawQuad(mProgram, "position", 0.5f); |
| 2267 | EXPECT_GL_NO_ERROR(); |
| 2268 | // The shader writes 0.5 * <comparison result (0.0)> + <texture color> |
| 2269 | EXPECT_PIXEL_NEAR(0, 0, 0, 60, 0, 255, 2); |
| 2270 | } |
| 2271 | |
Olli Etuaho | c8c99a0 | 2016-01-14 16:47:22 +0200 | [diff] [blame] | 2272 | // Test multiple different sampler types in the same shader. |
| 2273 | // This test makes sure that even if sampler / texture registers get grouped together based on type |
| 2274 | // or otherwise get shuffled around in the HLSL backend of the shader translator, the D3D renderer |
| 2275 | // still has the right register index information for each ESSL sampler. |
| 2276 | // The tested ESSL samplers have the following types in D3D11 HLSL: |
| 2277 | // sampler2D: Texture2D + SamplerState |
| 2278 | // samplerCube: TextureCube + SamplerState |
| 2279 | // sampler2DShadow: Texture2D + SamplerComparisonState |
| 2280 | // samplerCubeShadow: TextureCube + SamplerComparisonState |
| 2281 | TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw) |
| 2282 | { |
| 2283 | glActiveTexture(GL_TEXTURE0); |
| 2284 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2285 | GLubyte texData[4]; |
| 2286 | texData[0] = 0; |
| 2287 | texData[1] = 0; |
| 2288 | texData[2] = 120; |
| 2289 | texData[3] = 255; |
| 2290 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); |
| 2291 | |
| 2292 | glActiveTexture(GL_TEXTURE1); |
| 2293 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
| 2294 | texData[0] = 0; |
| 2295 | texData[1] = 90; |
| 2296 | texData[2] = 0; |
| 2297 | texData[3] = 255; |
| 2298 | glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1, 1); |
| 2299 | glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2300 | texData); |
| 2301 | |
| 2302 | glActiveTexture(GL_TEXTURE2); |
| 2303 | glBindTexture(GL_TEXTURE_2D, mTexture2DShadow); |
| 2304 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 2305 | GLfloat depthTexData[1]; |
| 2306 | depthTexData[0] = 0.5f; |
| 2307 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, 1, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 2308 | depthTexData); |
| 2309 | |
| 2310 | glActiveTexture(GL_TEXTURE3); |
| 2311 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCubeShadow); |
| 2312 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); |
| 2313 | depthTexData[0] = 0.2f; |
| 2314 | glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_DEPTH_COMPONENT32F, 1, 1); |
| 2315 | glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, |
| 2316 | depthTexData); |
| 2317 | |
| 2318 | EXPECT_GL_NO_ERROR(); |
| 2319 | |
| 2320 | glUseProgram(mProgram); |
| 2321 | glUniform1f(mDepthRefUniformLocation, 0.3f); |
| 2322 | glUniform1i(mTexture2DUniformLocation, 0); |
| 2323 | glUniform1i(mTextureCubeUniformLocation, 1); |
| 2324 | glUniform1i(mTexture2DShadowUniformLocation, 2); |
| 2325 | glUniform1i(mTextureCubeShadowUniformLocation, 3); |
| 2326 | |
| 2327 | drawQuad(mProgram, "position", 0.5f); |
| 2328 | EXPECT_GL_NO_ERROR(); |
| 2329 | // The shader writes: |
| 2330 | // <texture 2d color> + |
| 2331 | // <cube map color> + |
| 2332 | // 0.25 * <comparison result (1.0)> + |
| 2333 | // 0.125 * <comparison result (0.0)> |
| 2334 | EXPECT_PIXEL_NEAR(0, 0, 64, 154, 184, 255, 2); |
| 2335 | } |
| 2336 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 2337 | // Test different base levels on textures accessed through the same sampler array. |
| 2338 | // Calling textureSize() on the samplers hits the D3D sampler metadata workaround. |
| 2339 | TEST_P(TextureSizeTextureArrayTest, BaseLevelVariesInTextureArray) |
| 2340 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2341 | ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11()); |
| 2342 | |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 2343 | glActiveTexture(GL_TEXTURE0); |
| 2344 | glBindTexture(GL_TEXTURE_2D, mTexture2DA); |
| 2345 | GLsizei size = 64; |
| 2346 | for (GLint level = 0; level < 7; ++level) |
| 2347 | { |
| 2348 | ASSERT_LT(0, size); |
| 2349 | glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2350 | nullptr); |
| 2351 | size = size / 2; |
| 2352 | } |
| 2353 | ASSERT_EQ(0, size); |
| 2354 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 2355 | |
| 2356 | glActiveTexture(GL_TEXTURE1); |
| 2357 | glBindTexture(GL_TEXTURE_2D, mTexture2DB); |
| 2358 | size = 128; |
| 2359 | for (GLint level = 0; level < 8; ++level) |
| 2360 | { |
| 2361 | ASSERT_LT(0, size); |
| 2362 | glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2363 | nullptr); |
| 2364 | size = size / 2; |
| 2365 | } |
| 2366 | ASSERT_EQ(0, size); |
| 2367 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3); |
| 2368 | EXPECT_GL_NO_ERROR(); |
| 2369 | |
| 2370 | glUseProgram(mProgram); |
| 2371 | glUniform1i(mTexture0Location, 0); |
| 2372 | glUniform1i(mTexture1Location, 1); |
| 2373 | |
Olli Etuaho | 5804dc8 | 2018-04-13 14:11:46 +0300 | [diff] [blame] | 2374 | drawQuad(mProgram, essl3_shaders::PositionAttrib(), 0.5f); |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 2375 | EXPECT_GL_NO_ERROR(); |
| 2376 | // Red channel: width of level 1 of texture A: 32. |
| 2377 | // Green channel: width of level 3 of texture B: 16. |
| 2378 | EXPECT_PIXEL_NEAR(0, 0, 32, 16, 0, 255, 2); |
| 2379 | } |
| 2380 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2381 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2382 | // ES 3.0.4 table 3.24 |
| 2383 | TEST_P(Texture2DTestES3, TextureRGBImplicitAlpha1) |
| 2384 | { |
| 2385 | glActiveTexture(GL_TEXTURE0); |
| 2386 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2387 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); |
| 2388 | EXPECT_GL_NO_ERROR(); |
| 2389 | |
| 2390 | drawQuad(mProgram, "position", 0.5f); |
| 2391 | |
| 2392 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2393 | } |
| 2394 | |
| 2395 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2396 | // ES 3.0.4 table 3.24 |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2397 | TEST_P(Texture2DTest, TextureLuminanceImplicitAlpha1) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2398 | { |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2399 | setUpProgram(); |
| 2400 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2401 | glActiveTexture(GL_TEXTURE0); |
| 2402 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2403 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, nullptr); |
| 2404 | EXPECT_GL_NO_ERROR(); |
| 2405 | |
| 2406 | drawQuad(mProgram, "position", 0.5f); |
| 2407 | |
| 2408 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2409 | } |
| 2410 | |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2411 | // Validate that every component of the pixel will be equal to the luminance value we've set |
| 2412 | // and that the alpha channel will be 1 (or 255 to be exact). |
| 2413 | TEST_P(Texture2DTest, TextureLuminanceRGBSame) |
| 2414 | { |
| 2415 | setUpProgram(); |
| 2416 | |
| 2417 | glActiveTexture(GL_TEXTURE0); |
| 2418 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2419 | uint8_t pixel = 50; |
| 2420 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &pixel); |
| 2421 | EXPECT_GL_NO_ERROR(); |
| 2422 | |
| 2423 | drawQuad(mProgram, "position", 0.5f); |
| 2424 | |
| 2425 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel, pixel, pixel, 255)); |
| 2426 | } |
| 2427 | |
| 2428 | // Validate that every component of the pixel will be equal to the luminance value we've set |
| 2429 | // and that the alpha channel will be the second component. |
| 2430 | TEST_P(Texture2DTest, TextureLuminanceAlphaRGBSame) |
| 2431 | { |
| 2432 | setUpProgram(); |
| 2433 | |
| 2434 | glActiveTexture(GL_TEXTURE0); |
| 2435 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2436 | uint8_t pixel[] = {50, 25}; |
| 2437 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 1, 1, 0, GL_LUMINANCE_ALPHA, |
| 2438 | GL_UNSIGNED_BYTE, pixel); |
| 2439 | EXPECT_GL_NO_ERROR(); |
| 2440 | |
| 2441 | drawQuad(mProgram, "position", 0.5f); |
| 2442 | |
| 2443 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor(pixel[0], pixel[0], pixel[0], pixel[1])); |
| 2444 | } |
| 2445 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2446 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2447 | // ES 3.0.4 table 3.24 |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2448 | TEST_P(Texture2DTest, TextureLuminance32ImplicitAlpha1) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2449 | { |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2450 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float")); |
| 2451 | ANGLE_SKIP_TEST_IF(IsD3D9()); |
| 2452 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2453 | |
| 2454 | setUpProgram(); |
| 2455 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2456 | glActiveTexture(GL_TEXTURE0); |
| 2457 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2458 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_FLOAT, nullptr); |
| 2459 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2460 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2461 | drawQuad(mProgram, "position", 0.5f); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2462 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2463 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2467 | // ES 3.0.4 table 3.24 |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2468 | TEST_P(Texture2DTest, TextureLuminance16ImplicitAlpha1) |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2469 | { |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2470 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float")); |
| 2471 | ANGLE_SKIP_TEST_IF(IsD3D9()); |
| 2472 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 2473 | ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES()); |
| 2474 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1420 is fixed |
| 2475 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2476 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2477 | setUpProgram(); |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 2478 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2479 | glActiveTexture(GL_TEXTURE0); |
| 2480 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2481 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 1, 1, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, nullptr); |
| 2482 | EXPECT_GL_NO_ERROR(); |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2483 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2484 | drawQuad(mProgram, "position", 0.5f); |
Yuly Novikov | afcec83 | 2016-06-21 22:19:51 -0400 | [diff] [blame] | 2485 | |
Luc Ferron | d8c632c | 2018-04-10 12:31:44 -0400 | [diff] [blame] | 2486 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2490 | // ES 3.0.4 table 3.24 |
| 2491 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB8UIImplicitAlpha1) |
| 2492 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2493 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2494 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2495 | glActiveTexture(GL_TEXTURE0); |
| 2496 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2497 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, nullptr); |
| 2498 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2499 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2500 | EXPECT_GL_NO_ERROR(); |
| 2501 | |
| 2502 | drawQuad(mProgram, "position", 0.5f); |
| 2503 | |
| 2504 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2505 | } |
| 2506 | |
| 2507 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2508 | // ES 3.0.4 table 3.24 |
| 2509 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB8IImplicitAlpha1) |
| 2510 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2511 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2512 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2513 | glActiveTexture(GL_TEXTURE0); |
| 2514 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2515 | |
| 2516 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8I, 1, 1, 0, GL_RGB_INTEGER, GL_BYTE, nullptr); |
| 2517 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2518 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2519 | EXPECT_GL_NO_ERROR(); |
| 2520 | |
| 2521 | drawQuad(mProgram, "position", 0.5f); |
| 2522 | |
| 2523 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2524 | } |
| 2525 | |
| 2526 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2527 | // ES 3.0.4 table 3.24 |
| 2528 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB16UIImplicitAlpha1) |
| 2529 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2530 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2531 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2532 | glActiveTexture(GL_TEXTURE0); |
| 2533 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2534 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, nullptr); |
| 2535 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2536 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2537 | EXPECT_GL_NO_ERROR(); |
| 2538 | |
| 2539 | drawQuad(mProgram, "position", 0.5f); |
| 2540 | |
| 2541 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2542 | } |
| 2543 | |
| 2544 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2545 | // ES 3.0.4 table 3.24 |
| 2546 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB16IImplicitAlpha1) |
| 2547 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2548 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2549 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2550 | glActiveTexture(GL_TEXTURE0); |
| 2551 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2552 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16I, 1, 1, 0, GL_RGB_INTEGER, GL_SHORT, nullptr); |
| 2553 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2554 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2555 | EXPECT_GL_NO_ERROR(); |
| 2556 | |
| 2557 | drawQuad(mProgram, "position", 0.5f); |
| 2558 | |
| 2559 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2560 | } |
| 2561 | |
| 2562 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2563 | // ES 3.0.4 table 3.24 |
| 2564 | TEST_P(Texture2DUnsignedIntegerAlpha1TestES3, TextureRGB32UIImplicitAlpha1) |
| 2565 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2566 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2567 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2568 | glActiveTexture(GL_TEXTURE0); |
| 2569 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2570 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32UI, 1, 1, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, nullptr); |
| 2571 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2572 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2573 | EXPECT_GL_NO_ERROR(); |
| 2574 | |
| 2575 | drawQuad(mProgram, "position", 0.5f); |
| 2576 | |
| 2577 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2578 | } |
| 2579 | |
| 2580 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2581 | // ES 3.0.4 table 3.24 |
| 2582 | TEST_P(Texture2DIntegerAlpha1TestES3, TextureRGB32IImplicitAlpha1) |
| 2583 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 2584 | ANGLE_SKIP_TEST_IF(IsIntel() && IsOSX()); |
| 2585 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2586 | glActiveTexture(GL_TEXTURE0); |
| 2587 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2588 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32I, 1, 1, 0, GL_RGB_INTEGER, GL_INT, nullptr); |
| 2589 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2590 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2591 | EXPECT_GL_NO_ERROR(); |
| 2592 | |
| 2593 | drawQuad(mProgram, "position", 0.5f); |
| 2594 | |
| 2595 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2596 | } |
| 2597 | |
| 2598 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2599 | // ES 3.0.4 table 3.24 |
| 2600 | TEST_P(Texture2DTestES3, TextureRGBSNORMImplicitAlpha1) |
| 2601 | { |
| 2602 | glActiveTexture(GL_TEXTURE0); |
| 2603 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2604 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8_SNORM, 1, 1, 0, GL_RGB, GL_BYTE, nullptr); |
| 2605 | EXPECT_GL_NO_ERROR(); |
| 2606 | |
| 2607 | drawQuad(mProgram, "position", 0.5f); |
| 2608 | |
| 2609 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2610 | } |
| 2611 | |
| 2612 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2613 | // ES 3.0.4 table 3.24 |
| 2614 | TEST_P(Texture2DTestES3, TextureRGB9E5ImplicitAlpha1) |
| 2615 | { |
| 2616 | glActiveTexture(GL_TEXTURE0); |
| 2617 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2618 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB9_E5, 1, 1, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, |
| 2619 | nullptr); |
| 2620 | EXPECT_GL_NO_ERROR(); |
| 2621 | |
| 2622 | drawQuad(mProgram, "position", 0.5f); |
| 2623 | |
| 2624 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2625 | } |
| 2626 | |
| 2627 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2628 | // ES 3.0.4 table 3.24 |
| 2629 | TEST_P(Texture2DTestES3, TextureCOMPRESSEDRGB8ETC2ImplicitAlpha1) |
| 2630 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2631 | // Seems to fail on OSX 10.12 Intel. |
| 2632 | ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL()); |
Jamie Madill | bb1db48 | 2017-01-10 10:48:32 -0500 | [diff] [blame] | 2633 | |
Yuly Novikov | 4988689 | 2018-01-23 21:18:27 -0500 | [diff] [blame] | 2634 | // http://anglebug.com/2190 |
| 2635 | ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL()); |
| 2636 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2637 | glActiveTexture(GL_TEXTURE0); |
| 2638 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2639 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB8_ETC2, 1, 1, 0, 8, nullptr); |
| 2640 | EXPECT_GL_NO_ERROR(); |
| 2641 | |
| 2642 | drawQuad(mProgram, "position", 0.5f); |
| 2643 | |
| 2644 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2645 | } |
| 2646 | |
| 2647 | // When sampling a texture without an alpha channel, "1" is returned as the alpha value. |
| 2648 | // ES 3.0.4 table 3.24 |
| 2649 | TEST_P(Texture2DTestES3, TextureCOMPRESSEDSRGB8ETC2ImplicitAlpha1) |
| 2650 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2651 | // Seems to fail on OSX 10.12 Intel. |
| 2652 | ANGLE_SKIP_TEST_IF(IsOSX() && IsIntel() && IsOpenGL()); |
Corentin Wallez | 9e3c615 | 2016-03-29 21:58:33 -0400 | [diff] [blame] | 2653 | |
Yuly Novikov | 4988689 | 2018-01-23 21:18:27 -0500 | [diff] [blame] | 2654 | // http://anglebug.com/2190 |
| 2655 | ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA() && IsDesktopOpenGL()); |
| 2656 | |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 2657 | glActiveTexture(GL_TEXTURE0); |
| 2658 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 2659 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_SRGB8_ETC2, 1, 1, 0, 8, nullptr); |
| 2660 | EXPECT_GL_NO_ERROR(); |
| 2661 | |
| 2662 | drawQuad(mProgram, "position", 0.5f); |
| 2663 | |
| 2664 | EXPECT_PIXEL_ALPHA_EQ(0, 0, 255); |
| 2665 | } |
| 2666 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 2667 | // Use a sampler in a uniform struct. |
| 2668 | TEST_P(SamplerInStructTest, SamplerInStruct) |
| 2669 | { |
| 2670 | runSamplerInStructTest(); |
| 2671 | } |
| 2672 | |
| 2673 | // Use a sampler in a uniform struct that's passed as a function parameter. |
| 2674 | TEST_P(SamplerInStructAsFunctionParameterTest, SamplerInStructAsFunctionParameter) |
| 2675 | { |
Yuly Novikov | ad6c045 | 2016-06-24 22:24:37 -0400 | [diff] [blame] | 2676 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2677 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); |
Geoff Lang | 8fcdf6e | 2016-09-16 10:45:30 -0400 | [diff] [blame] | 2678 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 2679 | runSamplerInStructTest(); |
| 2680 | } |
| 2681 | |
| 2682 | // Use a sampler in a uniform struct array with a struct from the array passed as a function |
| 2683 | // parameter. |
| 2684 | TEST_P(SamplerInStructArrayAsFunctionParameterTest, SamplerInStructArrayAsFunctionParameter) |
| 2685 | { |
Yuly Novikov | ad6c045 | 2016-06-24 22:24:37 -0400 | [diff] [blame] | 2686 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2687 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); |
| 2688 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 2689 | runSamplerInStructTest(); |
| 2690 | } |
| 2691 | |
| 2692 | // Use a sampler in a struct inside a uniform struct with the nested struct passed as a function |
| 2693 | // parameter. |
| 2694 | TEST_P(SamplerInNestedStructAsFunctionParameterTest, SamplerInNestedStructAsFunctionParameter) |
| 2695 | { |
Yuly Novikov | ad6c045 | 2016-06-24 22:24:37 -0400 | [diff] [blame] | 2696 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1427 is fixed |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 2697 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); |
| 2698 | |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 2699 | runSamplerInStructTest(); |
| 2700 | } |
| 2701 | |
| 2702 | // Make sure that there isn't a name conflict between sampler extracted from a struct and a |
| 2703 | // similarly named uniform. |
| 2704 | TEST_P(SamplerInStructAndOtherVariableTest, SamplerInStructAndOtherVariable) |
| 2705 | { |
| 2706 | runSamplerInStructTest(); |
| 2707 | } |
| 2708 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2709 | class TextureLimitsTest : public ANGLETest |
| 2710 | { |
| 2711 | protected: |
| 2712 | struct RGBA8 |
| 2713 | { |
| 2714 | uint8_t R, G, B, A; |
| 2715 | }; |
| 2716 | |
| 2717 | TextureLimitsTest() |
| 2718 | : mProgram(0), mMaxVertexTextures(0), mMaxFragmentTextures(0), mMaxCombinedTextures(0) |
| 2719 | { |
| 2720 | setWindowWidth(128); |
| 2721 | setWindowHeight(128); |
| 2722 | setConfigRedBits(8); |
| 2723 | setConfigGreenBits(8); |
| 2724 | setConfigBlueBits(8); |
| 2725 | setConfigAlphaBits(8); |
| 2726 | } |
| 2727 | |
| 2728 | ~TextureLimitsTest() |
| 2729 | { |
| 2730 | if (mProgram != 0) |
| 2731 | { |
| 2732 | glDeleteProgram(mProgram); |
| 2733 | mProgram = 0; |
| 2734 | |
| 2735 | if (!mTextures.empty()) |
| 2736 | { |
| 2737 | glDeleteTextures(static_cast<GLsizei>(mTextures.size()), &mTextures[0]); |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | |
| 2742 | void SetUp() override |
| 2743 | { |
| 2744 | ANGLETest::SetUp(); |
| 2745 | |
| 2746 | glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mMaxVertexTextures); |
| 2747 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mMaxFragmentTextures); |
| 2748 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextures); |
| 2749 | |
| 2750 | ASSERT_GL_NO_ERROR(); |
| 2751 | } |
| 2752 | |
| 2753 | void compileProgramWithTextureCounts(const std::string &vertexPrefix, |
| 2754 | GLint vertexTextureCount, |
| 2755 | GLint vertexActiveTextureCount, |
| 2756 | const std::string &fragPrefix, |
| 2757 | GLint fragmentTextureCount, |
| 2758 | GLint fragmentActiveTextureCount) |
| 2759 | { |
| 2760 | std::stringstream vertexShaderStr; |
| 2761 | vertexShaderStr << "attribute vec2 position;\n" |
| 2762 | << "varying vec4 color;\n" |
| 2763 | << "varying vec2 texCoord;\n"; |
| 2764 | |
| 2765 | for (GLint textureIndex = 0; textureIndex < vertexTextureCount; ++textureIndex) |
| 2766 | { |
| 2767 | vertexShaderStr << "uniform sampler2D " << vertexPrefix << textureIndex << ";\n"; |
| 2768 | } |
| 2769 | |
| 2770 | vertexShaderStr << "void main() {\n" |
| 2771 | << " gl_Position = vec4(position, 0, 1);\n" |
| 2772 | << " texCoord = (position * 0.5) + 0.5;\n" |
| 2773 | << " color = vec4(0);\n"; |
| 2774 | |
| 2775 | for (GLint textureIndex = 0; textureIndex < vertexActiveTextureCount; ++textureIndex) |
| 2776 | { |
| 2777 | vertexShaderStr << " color += texture2D(" << vertexPrefix << textureIndex |
| 2778 | << ", texCoord);\n"; |
| 2779 | } |
| 2780 | |
| 2781 | vertexShaderStr << "}"; |
| 2782 | |
| 2783 | std::stringstream fragmentShaderStr; |
| 2784 | fragmentShaderStr << "varying mediump vec4 color;\n" |
| 2785 | << "varying mediump vec2 texCoord;\n"; |
| 2786 | |
| 2787 | for (GLint textureIndex = 0; textureIndex < fragmentTextureCount; ++textureIndex) |
| 2788 | { |
| 2789 | fragmentShaderStr << "uniform sampler2D " << fragPrefix << textureIndex << ";\n"; |
| 2790 | } |
| 2791 | |
| 2792 | fragmentShaderStr << "void main() {\n" |
| 2793 | << " gl_FragColor = color;\n"; |
| 2794 | |
| 2795 | for (GLint textureIndex = 0; textureIndex < fragmentActiveTextureCount; ++textureIndex) |
| 2796 | { |
| 2797 | fragmentShaderStr << " gl_FragColor += texture2D(" << fragPrefix << textureIndex |
| 2798 | << ", texCoord);\n"; |
| 2799 | } |
| 2800 | |
| 2801 | fragmentShaderStr << "}"; |
| 2802 | |
| 2803 | const std::string &vertexShaderSource = vertexShaderStr.str(); |
| 2804 | const std::string &fragmentShaderSource = fragmentShaderStr.str(); |
| 2805 | |
| 2806 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
| 2807 | } |
| 2808 | |
| 2809 | RGBA8 getPixel(GLint texIndex) |
| 2810 | { |
| 2811 | RGBA8 pixel = {static_cast<uint8_t>(texIndex & 0x7u), static_cast<uint8_t>(texIndex >> 3), |
| 2812 | 0, 255u}; |
| 2813 | return pixel; |
| 2814 | } |
| 2815 | |
| 2816 | void initTextures(GLint tex2DCount, GLint texCubeCount) |
| 2817 | { |
| 2818 | GLint totalCount = tex2DCount + texCubeCount; |
| 2819 | mTextures.assign(totalCount, 0); |
| 2820 | glGenTextures(totalCount, &mTextures[0]); |
| 2821 | ASSERT_GL_NO_ERROR(); |
| 2822 | |
| 2823 | std::vector<RGBA8> texData(16 * 16); |
| 2824 | |
| 2825 | GLint texIndex = 0; |
| 2826 | for (; texIndex < tex2DCount; ++texIndex) |
| 2827 | { |
| 2828 | texData.assign(texData.size(), getPixel(texIndex)); |
| 2829 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 2830 | glBindTexture(GL_TEXTURE_2D, mTextures[texIndex]); |
| 2831 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 2832 | &texData[0]); |
| 2833 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2834 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2835 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2836 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 2837 | } |
| 2838 | |
| 2839 | ASSERT_GL_NO_ERROR(); |
| 2840 | |
| 2841 | for (; texIndex < texCubeCount; ++texIndex) |
| 2842 | { |
| 2843 | texData.assign(texData.size(), getPixel(texIndex)); |
| 2844 | glActiveTexture(GL_TEXTURE0 + texIndex); |
| 2845 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextures[texIndex]); |
| 2846 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2847 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2848 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2849 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2850 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2851 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2852 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2853 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2854 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2855 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2856 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 16, 16, 0, GL_RGBA, |
| 2857 | GL_UNSIGNED_BYTE, &texData[0]); |
| 2858 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 2859 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 2860 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2861 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 2862 | } |
| 2863 | |
| 2864 | ASSERT_GL_NO_ERROR(); |
| 2865 | } |
| 2866 | |
| 2867 | void testWithTextures(GLint vertexTextureCount, |
| 2868 | const std::string &vertexTexturePrefix, |
| 2869 | GLint fragmentTextureCount, |
| 2870 | const std::string &fragmentTexturePrefix) |
| 2871 | { |
| 2872 | // Generate textures |
| 2873 | initTextures(vertexTextureCount + fragmentTextureCount, 0); |
| 2874 | |
| 2875 | glUseProgram(mProgram); |
| 2876 | RGBA8 expectedSum = {0}; |
| 2877 | for (GLint texIndex = 0; texIndex < vertexTextureCount; ++texIndex) |
| 2878 | { |
| 2879 | std::stringstream uniformNameStr; |
| 2880 | uniformNameStr << vertexTexturePrefix << texIndex; |
| 2881 | const std::string &uniformName = uniformNameStr.str(); |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 2882 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2883 | ASSERT_NE(-1, location); |
| 2884 | |
| 2885 | glUniform1i(location, texIndex); |
| 2886 | RGBA8 contribution = getPixel(texIndex); |
| 2887 | expectedSum.R += contribution.R; |
| 2888 | expectedSum.G += contribution.G; |
| 2889 | } |
| 2890 | |
| 2891 | for (GLint texIndex = 0; texIndex < fragmentTextureCount; ++texIndex) |
| 2892 | { |
| 2893 | std::stringstream uniformNameStr; |
| 2894 | uniformNameStr << fragmentTexturePrefix << texIndex; |
| 2895 | const std::string &uniformName = uniformNameStr.str(); |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 2896 | GLint location = glGetUniformLocation(mProgram, uniformName.c_str()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2897 | ASSERT_NE(-1, location); |
| 2898 | |
| 2899 | glUniform1i(location, texIndex + vertexTextureCount); |
| 2900 | RGBA8 contribution = getPixel(texIndex + vertexTextureCount); |
| 2901 | expectedSum.R += contribution.R; |
| 2902 | expectedSum.G += contribution.G; |
| 2903 | } |
| 2904 | |
| 2905 | ASSERT_GE(256u, expectedSum.G); |
| 2906 | |
| 2907 | drawQuad(mProgram, "position", 0.5f); |
| 2908 | ASSERT_GL_NO_ERROR(); |
| 2909 | EXPECT_PIXEL_EQ(0, 0, expectedSum.R, expectedSum.G, 0, 255); |
| 2910 | } |
| 2911 | |
| 2912 | GLuint mProgram; |
| 2913 | std::vector<GLuint> mTextures; |
| 2914 | GLint mMaxVertexTextures; |
| 2915 | GLint mMaxFragmentTextures; |
| 2916 | GLint mMaxCombinedTextures; |
| 2917 | }; |
| 2918 | |
| 2919 | // Test rendering with the maximum vertex texture units. |
| 2920 | TEST_P(TextureLimitsTest, MaxVertexTextures) |
| 2921 | { |
| 2922 | compileProgramWithTextureCounts("tex", mMaxVertexTextures, mMaxVertexTextures, "tex", 0, 0); |
| 2923 | ASSERT_NE(0u, mProgram); |
| 2924 | ASSERT_GL_NO_ERROR(); |
| 2925 | |
| 2926 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 2927 | } |
| 2928 | |
| 2929 | // Test rendering with the maximum fragment texture units. |
| 2930 | TEST_P(TextureLimitsTest, MaxFragmentTextures) |
| 2931 | { |
| 2932 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures, mMaxFragmentTextures); |
| 2933 | ASSERT_NE(0u, mProgram); |
| 2934 | ASSERT_GL_NO_ERROR(); |
| 2935 | |
| 2936 | testWithTextures(mMaxFragmentTextures, "tex", 0, "tex"); |
| 2937 | } |
| 2938 | |
| 2939 | // Test rendering with maximum combined texture units. |
| 2940 | TEST_P(TextureLimitsTest, MaxCombinedTextures) |
| 2941 | { |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 2942 | // TODO(lucferron): Diagnose and fix |
| 2943 | // http://anglebug.com/2654 |
| 2944 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 2945 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2946 | GLint vertexTextures = mMaxVertexTextures; |
| 2947 | |
| 2948 | if (vertexTextures + mMaxFragmentTextures > mMaxCombinedTextures) |
| 2949 | { |
| 2950 | vertexTextures = mMaxCombinedTextures - mMaxFragmentTextures; |
| 2951 | } |
| 2952 | |
| 2953 | compileProgramWithTextureCounts("vtex", vertexTextures, vertexTextures, "ftex", |
| 2954 | mMaxFragmentTextures, mMaxFragmentTextures); |
| 2955 | ASSERT_NE(0u, mProgram); |
| 2956 | ASSERT_GL_NO_ERROR(); |
| 2957 | |
| 2958 | testWithTextures(vertexTextures, "vtex", mMaxFragmentTextures, "ftex"); |
| 2959 | } |
| 2960 | |
| 2961 | // Negative test for exceeding the number of vertex textures |
| 2962 | TEST_P(TextureLimitsTest, ExcessiveVertexTextures) |
| 2963 | { |
| 2964 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 1, mMaxVertexTextures + 1, "tex", 0, |
| 2965 | 0); |
| 2966 | ASSERT_EQ(0u, mProgram); |
| 2967 | } |
| 2968 | |
| 2969 | // Negative test for exceeding the number of fragment textures |
| 2970 | TEST_P(TextureLimitsTest, ExcessiveFragmentTextures) |
| 2971 | { |
| 2972 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 1, |
| 2973 | mMaxFragmentTextures + 1); |
| 2974 | ASSERT_EQ(0u, mProgram); |
| 2975 | } |
| 2976 | |
| 2977 | // Test active vertex textures under the limit, but excessive textures specified. |
| 2978 | TEST_P(TextureLimitsTest, MaxActiveVertexTextures) |
| 2979 | { |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 2980 | // TODO(lucferron): Diagnose and fix |
| 2981 | // http://anglebug.com/2654 |
| 2982 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 2983 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2984 | compileProgramWithTextureCounts("tex", mMaxVertexTextures + 4, mMaxVertexTextures, "tex", 0, 0); |
| 2985 | ASSERT_NE(0u, mProgram); |
| 2986 | ASSERT_GL_NO_ERROR(); |
| 2987 | |
| 2988 | testWithTextures(mMaxVertexTextures, "tex", 0, "tex"); |
| 2989 | } |
| 2990 | |
| 2991 | // Test active fragment textures under the limit, but excessive textures specified. |
| 2992 | TEST_P(TextureLimitsTest, MaxActiveFragmentTextures) |
| 2993 | { |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 2994 | // TODO(lucferron): Diagnose and fix |
| 2995 | // http://anglebug.com/2654 |
| 2996 | ANGLE_SKIP_TEST_IF(IsVulkan()); |
| 2997 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 2998 | compileProgramWithTextureCounts("tex", 0, 0, "tex", mMaxFragmentTextures + 4, |
| 2999 | mMaxFragmentTextures); |
| 3000 | ASSERT_NE(0u, mProgram); |
| 3001 | ASSERT_GL_NO_ERROR(); |
| 3002 | |
| 3003 | testWithTextures(0, "tex", mMaxFragmentTextures, "tex"); |
| 3004 | } |
| 3005 | |
| 3006 | // Negative test for pointing two sampler uniforms of different types to the same texture. |
Olli Etuaho | 4a8329f | 2016-01-11 17:12:57 +0200 | [diff] [blame] | 3007 | // GLES 2.0.25 section 2.10.4 page 39. |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 3008 | TEST_P(TextureLimitsTest, TextureTypeConflict) |
| 3009 | { |
| 3010 | const std::string &vertexShader = |
| 3011 | "attribute vec2 position;\n" |
| 3012 | "varying float color;\n" |
| 3013 | "uniform sampler2D tex2D;\n" |
| 3014 | "uniform samplerCube texCube;\n" |
| 3015 | "void main() {\n" |
| 3016 | " gl_Position = vec4(position, 0, 1);\n" |
| 3017 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 3018 | " color = texture2D(tex2D, texCoord).x;\n" |
| 3019 | " color += textureCube(texCube, vec3(texCoord, 0)).x;\n" |
| 3020 | "}"; |
| 3021 | const std::string &fragmentShader = |
| 3022 | "varying mediump float color;\n" |
| 3023 | "void main() {\n" |
| 3024 | " gl_FragColor = vec4(color, 0, 0, 1);\n" |
| 3025 | "}"; |
| 3026 | |
| 3027 | mProgram = CompileProgram(vertexShader, fragmentShader); |
| 3028 | ASSERT_NE(0u, mProgram); |
| 3029 | |
| 3030 | initTextures(1, 0); |
| 3031 | |
| 3032 | glUseProgram(mProgram); |
| 3033 | GLint tex2DLocation = glGetUniformLocation(mProgram, "tex2D"); |
| 3034 | ASSERT_NE(-1, tex2DLocation); |
| 3035 | GLint texCubeLocation = glGetUniformLocation(mProgram, "texCube"); |
| 3036 | ASSERT_NE(-1, texCubeLocation); |
| 3037 | |
| 3038 | glUniform1i(tex2DLocation, 0); |
| 3039 | glUniform1i(texCubeLocation, 0); |
| 3040 | ASSERT_GL_NO_ERROR(); |
| 3041 | |
| 3042 | drawQuad(mProgram, "position", 0.5f); |
| 3043 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 3044 | } |
| 3045 | |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3046 | class Texture2DNorm16TestES3 : public Texture2DTestES3 |
| 3047 | { |
| 3048 | protected: |
| 3049 | Texture2DNorm16TestES3() : Texture2DTestES3(), mTextures{0, 0, 0}, mFBO(0), mRenderbuffer(0) {} |
| 3050 | |
| 3051 | void SetUp() override |
| 3052 | { |
| 3053 | Texture2DTestES3::SetUp(); |
| 3054 | |
| 3055 | glActiveTexture(GL_TEXTURE0); |
| 3056 | glGenTextures(3, mTextures); |
| 3057 | glGenFramebuffers(1, &mFBO); |
| 3058 | glGenRenderbuffers(1, &mRenderbuffer); |
| 3059 | |
| 3060 | for (size_t textureIndex = 0; textureIndex < 3; textureIndex++) |
| 3061 | { |
| 3062 | glBindTexture(GL_TEXTURE_2D, mTextures[textureIndex]); |
| 3063 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 3064 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 3065 | } |
| 3066 | |
| 3067 | glBindTexture(GL_TEXTURE_2D, 0); |
| 3068 | |
| 3069 | ASSERT_GL_NO_ERROR(); |
| 3070 | } |
| 3071 | |
| 3072 | void TearDown() override |
| 3073 | { |
| 3074 | glDeleteTextures(3, mTextures); |
| 3075 | glDeleteFramebuffers(1, &mFBO); |
| 3076 | glDeleteRenderbuffers(1, &mRenderbuffer); |
| 3077 | |
| 3078 | Texture2DTestES3::TearDown(); |
| 3079 | } |
| 3080 | |
| 3081 | void testNorm16Texture(GLint internalformat, GLenum format, GLenum type) |
| 3082 | { |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3083 | GLushort pixelValue = (type == GL_SHORT) ? 0x7FFF : 0x6A35; |
| 3084 | GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue}; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3085 | |
| 3086 | setUpProgram(); |
| 3087 | |
| 3088 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
| 3089 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0], |
| 3090 | 0); |
| 3091 | |
| 3092 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 3093 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16_EXT, 1, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT, nullptr); |
| 3094 | |
| 3095 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3096 | glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3097 | |
| 3098 | EXPECT_GL_NO_ERROR(); |
| 3099 | |
| 3100 | drawQuad(mProgram, "position", 0.5f); |
| 3101 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3102 | GLubyte expectedValue = (type == GL_SHORT) ? 0xFF : static_cast<GLubyte>(pixelValue >> 8); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3103 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 3104 | EXPECT_PIXEL_COLOR_EQ(0, 0, |
| 3105 | SliceFormatColor(format, GLColor(expectedValue, expectedValue, |
| 3106 | expectedValue, expectedValue))); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3107 | |
| 3108 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 3109 | |
| 3110 | ASSERT_GL_NO_ERROR(); |
| 3111 | } |
| 3112 | |
| 3113 | void testNorm16Render(GLint internalformat, GLenum format, GLenum type) |
| 3114 | { |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 3115 | GLushort pixelValue = 0x6A35; |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3116 | GLushort imageData[] = {pixelValue, pixelValue, pixelValue, pixelValue}; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3117 | |
| 3118 | setUpProgram(); |
| 3119 | |
| 3120 | glBindTexture(GL_TEXTURE_2D, mTextures[1]); |
| 3121 | glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, nullptr); |
| 3122 | |
| 3123 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
| 3124 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[1], |
| 3125 | 0); |
| 3126 | |
| 3127 | glBindTexture(GL_TEXTURE_2D, mTextures[2]); |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3128 | glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 1, 1, 0, format, type, imageData); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3129 | |
| 3130 | EXPECT_GL_NO_ERROR(); |
| 3131 | |
| 3132 | drawQuad(mProgram, "position", 0.5f); |
| 3133 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3134 | GLubyte expectedValue = static_cast<GLubyte>(pixelValue >> 8); |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 3135 | EXPECT_PIXEL_COLOR_EQ(0, 0, |
| 3136 | SliceFormatColor(format, GLColor(expectedValue, expectedValue, |
| 3137 | expectedValue, expectedValue))); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3138 | |
| 3139 | glBindRenderbuffer(GL_RENDERBUFFER, mRenderbuffer); |
| 3140 | glRenderbufferStorage(GL_RENDERBUFFER, internalformat, 1, 1); |
| 3141 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, |
| 3142 | mRenderbuffer); |
| 3143 | glBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 3144 | EXPECT_GL_NO_ERROR(); |
| 3145 | |
| 3146 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
| 3147 | glClear(GL_COLOR_BUFFER_BIT); |
| 3148 | |
| 3149 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); |
| 3150 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 3151 | EXPECT_PIXEL_COLOR_EQ(0, 0, SliceFormatColor(format, GLColor::white)); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3152 | |
| 3153 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 3154 | |
| 3155 | ASSERT_GL_NO_ERROR(); |
| 3156 | } |
| 3157 | |
| 3158 | GLuint mTextures[3]; |
| 3159 | GLuint mFBO; |
| 3160 | GLuint mRenderbuffer; |
| 3161 | }; |
| 3162 | |
| 3163 | // Test texture formats enabled by the GL_EXT_texture_norm16 extension. |
| 3164 | TEST_P(Texture2DNorm16TestES3, TextureNorm16Test) |
| 3165 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 3166 | ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_norm16")); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3167 | |
| 3168 | testNorm16Texture(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT); |
| 3169 | testNorm16Texture(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT); |
| 3170 | testNorm16Texture(GL_RGB16_EXT, GL_RGB, GL_UNSIGNED_SHORT); |
| 3171 | testNorm16Texture(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT); |
| 3172 | testNorm16Texture(GL_R16_SNORM_EXT, GL_RED, GL_SHORT); |
| 3173 | testNorm16Texture(GL_RG16_SNORM_EXT, GL_RG, GL_SHORT); |
| 3174 | testNorm16Texture(GL_RGB16_SNORM_EXT, GL_RGB, GL_SHORT); |
| 3175 | testNorm16Texture(GL_RGBA16_SNORM_EXT, GL_RGBA, GL_SHORT); |
| 3176 | |
| 3177 | testNorm16Render(GL_R16_EXT, GL_RED, GL_UNSIGNED_SHORT); |
| 3178 | testNorm16Render(GL_RG16_EXT, GL_RG, GL_UNSIGNED_SHORT); |
| 3179 | testNorm16Render(GL_RGBA16_EXT, GL_RGBA, GL_UNSIGNED_SHORT); |
| 3180 | } |
| 3181 | |
Olli Etuaho | 95faa23 | 2016-06-07 14:01:53 -0700 | [diff] [blame] | 3182 | // Test that UNPACK_SKIP_IMAGES doesn't have an effect on 2D texture uploads. |
| 3183 | // GLES 3.0.4 section 3.8.3. |
| 3184 | TEST_P(Texture2DTestES3, UnpackSkipImages2D) |
| 3185 | { |
Yunchao He | 8e5ba8b | 2018-02-05 17:52:27 +0800 | [diff] [blame] | 3186 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows() && IsDesktopOpenGL()); |
| 3187 | |
Yuly Novikov | 3c75419 | 2016-06-27 19:36:41 -0400 | [diff] [blame] | 3188 | // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1429 is fixed |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 3189 | ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); |
Olli Etuaho | 95faa23 | 2016-06-07 14:01:53 -0700 | [diff] [blame] | 3190 | |
| 3191 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3192 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 3193 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 3194 | ASSERT_GL_NO_ERROR(); |
| 3195 | |
| 3196 | // SKIP_IMAGES should not have an effect on uploading 2D textures |
| 3197 | glPixelStorei(GL_UNPACK_SKIP_IMAGES, 1000); |
| 3198 | ASSERT_GL_NO_ERROR(); |
| 3199 | |
| 3200 | std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green); |
| 3201 | |
| 3202 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 3203 | pixelsGreen.data()); |
| 3204 | ASSERT_GL_NO_ERROR(); |
| 3205 | |
| 3206 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, |
| 3207 | pixelsGreen.data()); |
| 3208 | ASSERT_GL_NO_ERROR(); |
| 3209 | |
| 3210 | glUseProgram(mProgram); |
| 3211 | drawQuad(mProgram, "position", 0.5f); |
| 3212 | ASSERT_GL_NO_ERROR(); |
| 3213 | |
| 3214 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3215 | } |
| 3216 | |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 3217 | // Test that skip defined in unpack parameters is taken into account when determining whether |
| 3218 | // unpacking source extends outside unpack buffer bounds. |
| 3219 | TEST_P(Texture2DTestES3, UnpackSkipPixelsOutOfBounds) |
| 3220 | { |
| 3221 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3222 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 3223 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 3224 | ASSERT_GL_NO_ERROR(); |
| 3225 | |
| 3226 | GLBuffer buf; |
| 3227 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get()); |
| 3228 | std::vector<GLColor> pixelsGreen(128u * 128u, GLColor::green); |
| 3229 | glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(), |
| 3230 | GL_DYNAMIC_COPY); |
| 3231 | ASSERT_GL_NO_ERROR(); |
| 3232 | |
| 3233 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 3234 | ASSERT_GL_NO_ERROR(); |
| 3235 | |
| 3236 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1); |
| 3237 | ASSERT_GL_NO_ERROR(); |
| 3238 | |
| 3239 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 3240 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 3241 | |
| 3242 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); |
| 3243 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 1); |
| 3244 | ASSERT_GL_NO_ERROR(); |
| 3245 | |
| 3246 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 3247 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 3248 | } |
| 3249 | |
Olli Etuaho | 218cf9e | 2016-05-20 13:55:24 +0300 | [diff] [blame] | 3250 | // Test that unpacking rows that overlap in a pixel unpack buffer works as expected. |
| 3251 | TEST_P(Texture2DTestES3, UnpackOverlappingRowsFromUnpackBuffer) |
| 3252 | { |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 3253 | ANGLE_SKIP_TEST_IF(IsD3D11()); |
| 3254 | |
| 3255 | // Incorrect rendering results seen on OSX AMD. |
| 3256 | ANGLE_SKIP_TEST_IF(IsOSX() && IsAMD()); |
Olli Etuaho | 218cf9e | 2016-05-20 13:55:24 +0300 | [diff] [blame] | 3257 | |
| 3258 | const GLuint width = 8u; |
| 3259 | const GLuint height = 8u; |
| 3260 | const GLuint unpackRowLength = 5u; |
| 3261 | const GLuint unpackSkipPixels = 1u; |
| 3262 | |
| 3263 | setWindowWidth(width); |
| 3264 | setWindowHeight(height); |
| 3265 | |
| 3266 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3267 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 3268 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 3269 | ASSERT_GL_NO_ERROR(); |
| 3270 | |
| 3271 | GLBuffer buf; |
| 3272 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buf.get()); |
| 3273 | std::vector<GLColor> pixelsGreen((height - 1u) * unpackRowLength + width + unpackSkipPixels, |
| 3274 | GLColor::green); |
| 3275 | |
| 3276 | for (GLuint skippedPixel = 0u; skippedPixel < unpackSkipPixels; ++skippedPixel) |
| 3277 | { |
| 3278 | pixelsGreen[skippedPixel] = GLColor(255, 0, 0, 255); |
| 3279 | } |
| 3280 | |
| 3281 | glBufferData(GL_PIXEL_UNPACK_BUFFER, pixelsGreen.size() * 4u, pixelsGreen.data(), |
| 3282 | GL_DYNAMIC_COPY); |
| 3283 | ASSERT_GL_NO_ERROR(); |
| 3284 | |
| 3285 | glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength); |
| 3286 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels); |
| 3287 | ASSERT_GL_NO_ERROR(); |
| 3288 | |
| 3289 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 3290 | ASSERT_GL_NO_ERROR(); |
| 3291 | |
| 3292 | glUseProgram(mProgram); |
| 3293 | drawQuad(mProgram, "position", 0.5f); |
| 3294 | ASSERT_GL_NO_ERROR(); |
| 3295 | |
| 3296 | GLuint windowPixelCount = getWindowWidth() * getWindowHeight(); |
| 3297 | std::vector<GLColor> actual(windowPixelCount, GLColor::black); |
| 3298 | glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, |
| 3299 | actual.data()); |
| 3300 | std::vector<GLColor> expected(windowPixelCount, GLColor::green); |
| 3301 | EXPECT_EQ(expected, actual); |
| 3302 | } |
| 3303 | |
Jamie Madill | 9e3d7aa | 2016-09-02 15:19:43 -0400 | [diff] [blame] | 3304 | template <typename T> |
| 3305 | T UNorm(double value) |
| 3306 | { |
| 3307 | return static_cast<T>(value * static_cast<double>(std::numeric_limits<T>::max())); |
| 3308 | } |
| 3309 | |
| 3310 | // Test rendering a depth texture with mipmaps. |
| 3311 | TEST_P(Texture2DTestES3, DepthTexturesWithMipmaps) |
| 3312 | { |
Zhenyao Mo | e520d7c | 2017-01-13 13:46:49 -0800 | [diff] [blame] | 3313 | // TODO(cwallez) this is failing on Intel Win7 OpenGL. |
| 3314 | // TODO(zmo) this is faling on Win Intel HD 530 Debug. |
| 3315 | // http://anglebugs.com/1706 |
Yunchao He | 9550c60 | 2018-02-13 14:47:05 +0800 | [diff] [blame] | 3316 | ANGLE_SKIP_TEST_IF(IsIntel() && IsWindows()); |
Corentin Wallez | e731d8a | 2016-09-07 10:56:25 -0400 | [diff] [blame] | 3317 | |
Jamie Madill | 9e3d7aa | 2016-09-02 15:19:43 -0400 | [diff] [blame] | 3318 | const int size = getWindowWidth(); |
| 3319 | |
| 3320 | auto dim = [size](int level) { return size >> level; }; |
Jamie Madill | 1471876 | 2016-09-06 15:56:54 -0400 | [diff] [blame] | 3321 | int levels = gl::log2(size); |
Jamie Madill | 9e3d7aa | 2016-09-02 15:19:43 -0400 | [diff] [blame] | 3322 | |
| 3323 | glActiveTexture(GL_TEXTURE0); |
| 3324 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3325 | glTexStorage2D(GL_TEXTURE_2D, levels, GL_DEPTH_COMPONENT24, size, size); |
| 3326 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 3327 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3328 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 3329 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 3330 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 3331 | ASSERT_GL_NO_ERROR(); |
| 3332 | |
| 3333 | glUseProgram(mProgram); |
| 3334 | glUniform1i(mTexture2DUniformLocation, 0); |
| 3335 | |
| 3336 | std::vector<unsigned char> expected; |
| 3337 | |
| 3338 | for (int level = 0; level < levels; ++level) |
| 3339 | { |
| 3340 | double value = (static_cast<double>(level) / static_cast<double>(levels - 1)); |
| 3341 | expected.push_back(UNorm<unsigned char>(value)); |
| 3342 | |
| 3343 | int levelDim = dim(level); |
| 3344 | |
| 3345 | ASSERT_GT(levelDim, 0); |
| 3346 | |
| 3347 | std::vector<unsigned int> initData(levelDim * levelDim, UNorm<unsigned int>(value)); |
| 3348 | glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, levelDim, levelDim, GL_DEPTH_COMPONENT, |
| 3349 | GL_UNSIGNED_INT, initData.data()); |
| 3350 | } |
| 3351 | ASSERT_GL_NO_ERROR(); |
| 3352 | |
| 3353 | for (int level = 0; level < levels; ++level) |
| 3354 | { |
| 3355 | glViewport(0, 0, dim(level), dim(level)); |
| 3356 | drawQuad(mProgram, "position", 0.5f); |
| 3357 | GLColor actual = ReadColor(0, 0); |
| 3358 | EXPECT_NEAR(expected[level], actual.R, 10u); |
| 3359 | } |
| 3360 | |
| 3361 | ASSERT_GL_NO_ERROR(); |
| 3362 | } |
| 3363 | |
Jamie Madill | 7ffdda9 | 2016-09-08 13:26:51 -0400 | [diff] [blame] | 3364 | // Tests unpacking into the unsized GL_ALPHA format. |
| 3365 | TEST_P(Texture2DTestES3, UnsizedAlphaUnpackBuffer) |
| 3366 | { |
Jamie Madill | 7ffdda9 | 2016-09-08 13:26:51 -0400 | [diff] [blame] | 3367 | // Initialize the texure. |
| 3368 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3369 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, getWindowWidth(), getWindowHeight(), 0, GL_ALPHA, |
| 3370 | GL_UNSIGNED_BYTE, nullptr); |
| 3371 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3372 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3373 | |
| 3374 | std::vector<GLubyte> bufferData(getWindowWidth() * getWindowHeight(), 127); |
| 3375 | |
| 3376 | // Pull in the color data from the unpack buffer. |
Jamie Madill | 2e60034 | 2016-09-19 13:56:40 -0400 | [diff] [blame] | 3377 | GLBuffer unpackBuffer; |
Jamie Madill | 7ffdda9 | 2016-09-08 13:26:51 -0400 | [diff] [blame] | 3378 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 3379 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get()); |
| 3380 | glBufferData(GL_PIXEL_UNPACK_BUFFER, getWindowWidth() * getWindowHeight(), bufferData.data(), |
| 3381 | GL_STATIC_DRAW); |
| 3382 | |
| 3383 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth(), getWindowHeight(), GL_ALPHA, |
| 3384 | GL_UNSIGNED_BYTE, nullptr); |
| 3385 | |
| 3386 | // Clear to a weird color to make sure we're drawing something. |
| 3387 | glClearColor(0.5f, 0.8f, 1.0f, 0.2f); |
| 3388 | glClear(GL_COLOR_BUFFER_BIT); |
| 3389 | |
| 3390 | // Draw with the alpha texture and verify. |
| 3391 | drawQuad(mProgram, "position", 0.5f); |
Jamie Madill | 7ffdda9 | 2016-09-08 13:26:51 -0400 | [diff] [blame] | 3392 | |
| 3393 | ASSERT_GL_NO_ERROR(); |
| 3394 | EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 127, 1); |
| 3395 | } |
| 3396 | |
Jamie Madill | 2e60034 | 2016-09-19 13:56:40 -0400 | [diff] [blame] | 3397 | // Ensure stale unpack data doesn't propagate in D3D11. |
| 3398 | TEST_P(Texture2DTestES3, StaleUnpackData) |
| 3399 | { |
| 3400 | // Init unpack buffer. |
| 3401 | GLsizei pixelCount = getWindowWidth() * getWindowHeight() / 2; |
| 3402 | std::vector<GLColor> pixels(pixelCount, GLColor::red); |
| 3403 | |
| 3404 | GLBuffer unpackBuffer; |
| 3405 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 3406 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer.get()); |
| 3407 | GLsizei bufferSize = pixelCount * sizeof(GLColor); |
| 3408 | glBufferData(GL_PIXEL_UNPACK_BUFFER, bufferSize, pixels.data(), GL_STATIC_DRAW); |
| 3409 | |
| 3410 | // Create from unpack buffer. |
| 3411 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3412 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0, |
| 3413 | GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3414 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3415 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3416 | |
| 3417 | drawQuad(mProgram, "position", 0.5f); |
| 3418 | |
| 3419 | ASSERT_GL_NO_ERROR(); |
| 3420 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 3421 | |
| 3422 | // Fill unpack with green, recreating buffer. |
| 3423 | pixels.assign(getWindowWidth() * getWindowHeight(), GLColor::green); |
| 3424 | GLsizei size2 = getWindowWidth() * getWindowHeight() * sizeof(GLColor); |
| 3425 | glBufferData(GL_PIXEL_UNPACK_BUFFER, size2, pixels.data(), GL_STATIC_DRAW); |
| 3426 | |
| 3427 | // Reinit texture with green. |
| 3428 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, getWindowWidth() / 2, getWindowHeight() / 2, GL_RGBA, |
| 3429 | GL_UNSIGNED_BYTE, nullptr); |
| 3430 | |
| 3431 | drawQuad(mProgram, "position", 0.5f); |
| 3432 | |
| 3433 | ASSERT_GL_NO_ERROR(); |
| 3434 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); |
| 3435 | } |
| 3436 | |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 3437 | // Ensure that texture parameters passed as floats that are converted to ints are rounded before |
| 3438 | // validating they are less than 0. |
| 3439 | TEST_P(Texture2DTestES3, TextureBaseMaxLevelRoundingValidation) |
| 3440 | { |
| 3441 | GLTexture texture; |
| 3442 | glBindTexture(GL_TEXTURE_2D, texture); |
| 3443 | |
| 3444 | // Use a negative number that will round to zero when converted to an integer |
| 3445 | // According to the spec(2.3.1 Data Conversion For State - Setting Commands): |
| 3446 | // "Validation of values performed by state-setting commands is performed after conversion, |
| 3447 | // unless specified otherwise for a specific command." |
| 3448 | GLfloat param = -7.30157126e-07f; |
| 3449 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, param); |
| 3450 | EXPECT_GL_NO_ERROR(); |
| 3451 | |
| 3452 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, param); |
| 3453 | EXPECT_GL_NO_ERROR(); |
| 3454 | } |
| 3455 | |
Jamie Madill | f097e23 | 2016-11-05 00:44:15 -0400 | [diff] [blame] | 3456 | // This test covers a D3D format redefinition bug for 3D textures. The base level format was not |
| 3457 | // being properly checked, and the texture storage of the previous texture format was persisting. |
| 3458 | // This would result in an ASSERT in debug and incorrect rendering in release. |
| 3459 | // See http://anglebug.com/1609 and WebGL 2 test conformance2/misc/views-with-offsets.html. |
| 3460 | TEST_P(Texture3DTestES3, FormatRedefinitionBug) |
| 3461 | { |
| 3462 | GLTexture tex; |
| 3463 | glBindTexture(GL_TEXTURE_3D, tex.get()); |
| 3464 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3465 | |
| 3466 | GLFramebuffer framebuffer; |
| 3467 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 3468 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex.get(), 0, 0); |
| 3469 | |
| 3470 | glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 3471 | |
| 3472 | std::vector<uint8_t> pixelData(100, 0); |
| 3473 | |
| 3474 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB565, 1, 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr); |
| 3475 | glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, |
| 3476 | pixelData.data()); |
| 3477 | |
| 3478 | ASSERT_GL_NO_ERROR(); |
| 3479 | } |
| 3480 | |
Corentin Wallez | d262799 | 2017-04-28 17:17:03 -0400 | [diff] [blame] | 3481 | // Test basic pixel unpack buffer OOB checks when uploading to a 2D or 3D texture |
| 3482 | TEST_P(Texture3DTestES3, BasicUnpackBufferOOB) |
| 3483 | { |
| 3484 | // 2D tests |
| 3485 | { |
| 3486 | GLTexture tex; |
| 3487 | glBindTexture(GL_TEXTURE_2D, tex.get()); |
| 3488 | |
| 3489 | GLBuffer pbo; |
| 3490 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get()); |
| 3491 | |
| 3492 | // Test OOB |
| 3493 | glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 - 1, nullptr, GL_STATIC_DRAW); |
| 3494 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3495 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 3496 | |
| 3497 | // Test OOB |
| 3498 | glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2, nullptr, GL_STATIC_DRAW); |
| 3499 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3500 | ASSERT_GL_NO_ERROR(); |
| 3501 | } |
| 3502 | |
| 3503 | // 3D tests |
| 3504 | { |
| 3505 | GLTexture tex; |
| 3506 | glBindTexture(GL_TEXTURE_3D, tex.get()); |
| 3507 | |
| 3508 | GLBuffer pbo; |
| 3509 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.get()); |
| 3510 | |
| 3511 | // Test OOB |
| 3512 | glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2 - 1, nullptr, |
| 3513 | GL_STATIC_DRAW); |
| 3514 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3515 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 3516 | |
| 3517 | // Test OOB |
| 3518 | glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLColor) * 2 * 2 * 2, nullptr, GL_STATIC_DRAW); |
| 3519 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 3520 | ASSERT_GL_NO_ERROR(); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Jamie Madill | 3ed6042 | 2017-09-07 11:32:52 -0400 | [diff] [blame] | 3524 | // Tests behaviour with a single texture and multiple sampler objects. |
| 3525 | TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers) |
| 3526 | { |
| 3527 | GLint maxTextureUnits = 0; |
| 3528 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
| 3529 | ANGLE_SKIP_TEST_IF(maxTextureUnits < 4); |
| 3530 | |
| 3531 | constexpr int kSize = 16; |
| 3532 | |
| 3533 | // Make a single-level texture, fill it with red. |
| 3534 | std::vector<GLColor> redColors(kSize * kSize, GLColor::red); |
| 3535 | GLTexture tex; |
| 3536 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3537 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 3538 | redColors.data()); |
| 3539 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3540 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3541 | |
| 3542 | // Simple sanity check. |
| 3543 | draw2DTexturedQuad(0.5f, 1.0f, true); |
| 3544 | ASSERT_GL_NO_ERROR(); |
| 3545 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 3546 | |
| 3547 | // Bind texture to unit 1 with a sampler object making it incomplete. |
| 3548 | GLSampler sampler; |
| 3549 | glBindSampler(0, sampler); |
| 3550 | glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 3551 | glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3552 | |
| 3553 | // Make a mipmap texture, fill it with blue. |
| 3554 | std::vector<GLColor> blueColors(kSize * kSize, GLColor::blue); |
| 3555 | GLTexture mipmapTex; |
| 3556 | glBindTexture(GL_TEXTURE_2D, mipmapTex); |
| 3557 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 3558 | blueColors.data()); |
| 3559 | glGenerateMipmap(GL_TEXTURE_2D); |
| 3560 | |
| 3561 | // Draw with the sampler, expect blue. |
| 3562 | draw2DTexturedQuad(0.5f, 1.0f, true); |
| 3563 | ASSERT_GL_NO_ERROR(); |
| 3564 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 3565 | |
| 3566 | // Simple multitexturing program. |
| 3567 | const std::string vs = |
| 3568 | "#version 300 es\n" |
| 3569 | "in vec2 position;\n" |
| 3570 | "out vec2 texCoord;\n" |
| 3571 | "void main()\n" |
| 3572 | "{\n" |
| 3573 | " gl_Position = vec4(position, 0, 1);\n" |
| 3574 | " texCoord = position * 0.5 + vec2(0.5);\n" |
| 3575 | "}"; |
| 3576 | const std::string fs = |
| 3577 | "#version 300 es\n" |
| 3578 | "precision mediump float;\n" |
| 3579 | "in vec2 texCoord;\n" |
| 3580 | "uniform sampler2D tex1;\n" |
| 3581 | "uniform sampler2D tex2;\n" |
| 3582 | "uniform sampler2D tex3;\n" |
| 3583 | "uniform sampler2D tex4;\n" |
| 3584 | "out vec4 color;\n" |
| 3585 | "void main()\n" |
| 3586 | "{\n" |
| 3587 | " color = (texture(tex1, texCoord) + texture(tex2, texCoord) \n" |
| 3588 | " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n" |
| 3589 | "}"; |
| 3590 | |
| 3591 | ANGLE_GL_PROGRAM(program, vs, fs); |
| 3592 | |
| 3593 | std::array<GLint, 4> texLocations = { |
| 3594 | {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"), |
| 3595 | glGetUniformLocation(program, "tex3"), glGetUniformLocation(program, "tex4")}}; |
| 3596 | for (GLint location : texLocations) |
| 3597 | { |
| 3598 | ASSERT_NE(-1, location); |
| 3599 | } |
| 3600 | |
| 3601 | // Init the uniform data. |
| 3602 | glUseProgram(program); |
| 3603 | for (GLint location = 0; location < 4; ++location) |
| 3604 | { |
| 3605 | glUniform1i(texLocations[location], location); |
| 3606 | } |
| 3607 | |
| 3608 | // Initialize four samplers |
| 3609 | GLSampler samplers[4]; |
| 3610 | |
| 3611 | // 0: non-mipped. |
| 3612 | glBindSampler(0, samplers[0]); |
| 3613 | glSamplerParameteri(samplers[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3614 | glSamplerParameteri(samplers[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3615 | |
| 3616 | // 1: mipped. |
| 3617 | glBindSampler(1, samplers[1]); |
| 3618 | glSamplerParameteri(samplers[1], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 3619 | glSamplerParameteri(samplers[1], GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3620 | |
| 3621 | // 2: non-mipped. |
| 3622 | glBindSampler(2, samplers[2]); |
| 3623 | glSamplerParameteri(samplers[2], GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3624 | glSamplerParameteri(samplers[2], GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3625 | |
| 3626 | // 3: mipped. |
| 3627 | glBindSampler(3, samplers[3]); |
| 3628 | glSamplerParameteri(samplers[3], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 3629 | glSamplerParameteri(samplers[3], GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3630 | |
| 3631 | // Bind two blue mipped textures and two single layer textures, should all draw. |
| 3632 | glActiveTexture(GL_TEXTURE0); |
| 3633 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3634 | |
| 3635 | glActiveTexture(GL_TEXTURE1); |
| 3636 | glBindTexture(GL_TEXTURE_2D, mipmapTex); |
| 3637 | |
| 3638 | glActiveTexture(GL_TEXTURE2); |
| 3639 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3640 | |
| 3641 | glActiveTexture(GL_TEXTURE3); |
| 3642 | glBindTexture(GL_TEXTURE_2D, mipmapTex); |
| 3643 | |
| 3644 | ASSERT_GL_NO_ERROR(); |
| 3645 | |
| 3646 | drawQuad(program, "position", 0.5f); |
| 3647 | ASSERT_GL_NO_ERROR(); |
| 3648 | EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 255, 2); |
| 3649 | |
| 3650 | // Bind four single layer textures, two should be incomplete. |
| 3651 | glActiveTexture(GL_TEXTURE1); |
| 3652 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3653 | |
| 3654 | glActiveTexture(GL_TEXTURE3); |
| 3655 | glBindTexture(GL_TEXTURE_2D, tex); |
| 3656 | |
| 3657 | drawQuad(program, "position", 0.5f); |
| 3658 | ASSERT_GL_NO_ERROR(); |
| 3659 | EXPECT_PIXEL_NEAR(0, 0, 128, 0, 0, 255, 2); |
| 3660 | } |
| 3661 | |
Martin Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 3662 | // The test is added to cover http://anglebug.com/2153. Cubemap completeness checks used to start |
| 3663 | // always at level 0 instead of the base level resulting in an incomplete texture if the faces at |
| 3664 | // level 0 are not created. The test creates a cubemap texture, specifies the images only for mip |
| 3665 | // level 1 filled with white color, updates the base level to be 1 and renders a quad. The program |
| 3666 | // samples the cubemap using a direction vector (1,1,1). |
| 3667 | TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1) |
| 3668 | { |
Yunchao He | 2f23f35 | 2018-02-11 22:11:37 +0800 | [diff] [blame] | 3669 | // Check http://anglebug.com/2155. |
| 3670 | ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA()); |
| 3671 | |
Martin Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 3672 | const std::string vs = |
| 3673 | R"(#version 300 es |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 3674 | precision mediump float; |
| 3675 | in vec3 pos; |
| 3676 | void main() { |
| 3677 | gl_Position = vec4(pos, 1.0); |
| 3678 | })"; |
Martin Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 3679 | |
| 3680 | const std::string fs = |
| 3681 | R"(#version 300 es |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame] | 3682 | precision mediump float; |
| 3683 | out vec4 color; |
| 3684 | uniform samplerCube uTex; |
| 3685 | void main(){ |
| 3686 | color = texture(uTex, vec3(1.0)); |
| 3687 | })"; |
Martin Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 3688 | ANGLE_GL_PROGRAM(program, vs, fs); |
| 3689 | glUseProgram(program); |
| 3690 | |
| 3691 | glUniform1i(glGetUniformLocation(program, "uTex"), 0); |
| 3692 | glActiveTexture(GL_TEXTURE0); |
| 3693 | |
| 3694 | GLTexture cubeTex; |
| 3695 | glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTex); |
| 3696 | |
| 3697 | const int kFaceWidth = 1; |
| 3698 | const int kFaceHeight = 1; |
| 3699 | std::vector<uint32_t> texData(kFaceWidth * kFaceHeight, 0xFFFFFFFF); |
| 3700 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3701 | GL_UNSIGNED_BYTE, texData.data()); |
| 3702 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3703 | GL_UNSIGNED_BYTE, texData.data()); |
| 3704 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3705 | GL_UNSIGNED_BYTE, texData.data()); |
| 3706 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3707 | GL_UNSIGNED_BYTE, texData.data()); |
| 3708 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3709 | GL_UNSIGNED_BYTE, texData.data()); |
| 3710 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 1, GL_RGBA8, kFaceWidth, kFaceHeight, 0, GL_RGBA, |
| 3711 | GL_UNSIGNED_BYTE, texData.data()); |
| 3712 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 3713 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 3714 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 3715 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 3716 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 3717 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1); |
| 3718 | |
| 3719 | drawQuad(program, "pos", 0.5f, 1.0f, true); |
| 3720 | ASSERT_GL_NO_ERROR(); |
| 3721 | |
| 3722 | EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white); |
| 3723 | } |
| 3724 | |
Jiawei Shao | 3c43b4d | 2018-02-23 11:08:28 +0800 | [diff] [blame] | 3725 | // Verify that using negative texture base level and max level generates GL_INVALID_VALUE. |
| 3726 | TEST_P(Texture2DTestES3, NegativeTextureBaseLevelAndMaxLevel) |
| 3727 | { |
| 3728 | GLuint texture = create2DTexture(); |
| 3729 | |
| 3730 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, -1); |
| 3731 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 3732 | |
| 3733 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, -1); |
| 3734 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 3735 | |
| 3736 | glDeleteTextures(1, &texture); |
| 3737 | EXPECT_GL_NO_ERROR(); |
| 3738 | } |
| 3739 | |
Olli Etuaho | 023371b | 2018-04-24 17:43:32 +0300 | [diff] [blame] | 3740 | // Test setting base level after calling generateMipmap on a LUMA texture. |
| 3741 | // Covers http://anglebug.com/2498 |
| 3742 | TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA) |
| 3743 | { |
| 3744 | glActiveTexture(GL_TEXTURE0); |
| 3745 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
| 3746 | |
| 3747 | constexpr const GLsizei kWidth = 8; |
| 3748 | constexpr const GLsizei kHeight = 8; |
| 3749 | std::array<GLubyte, kWidth * kHeight * 2> whiteData; |
| 3750 | whiteData.fill(255u); |
| 3751 | |
| 3752 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, kWidth, kHeight, 0, GL_LUMINANCE_ALPHA, |
| 3753 | GL_UNSIGNED_BYTE, whiteData.data()); |
| 3754 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 3755 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 3756 | glGenerateMipmap(GL_TEXTURE_2D); |
| 3757 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 3758 | EXPECT_GL_NO_ERROR(); |
| 3759 | |
| 3760 | drawQuad(mProgram, "position", 0.5f); |
| 3761 | EXPECT_PIXEL_COLOR_EQ(0, 0, angle::GLColor::white); |
| 3762 | } |
| 3763 | |
Jamie Madill | 50cf2be | 2018-06-15 09:46:57 -0400 | [diff] [blame^] | 3764 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 3765 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3766 | ANGLE_INSTANTIATE_TEST(Texture2DTest, |
| 3767 | ES2_D3D9(), |
| 3768 | ES2_D3D11(), |
| 3769 | ES2_D3D11_FL9_3(), |
| 3770 | ES2_OPENGL(), |
Luc Ferron | 5164b79 | 2018-03-06 09:10:12 -0500 | [diff] [blame] | 3771 | ES2_OPENGLES(), |
| 3772 | ES2_VULKAN()); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3773 | ANGLE_INSTANTIATE_TEST(TextureCubeTest, |
| 3774 | ES2_D3D9(), |
| 3775 | ES2_D3D11(), |
Geoff Lang | f7480ad | 2017-10-24 11:46:02 -0400 | [diff] [blame] | 3776 | ES2_D3D11_FL10_0(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3777 | ES2_D3D11_FL9_3(), |
| 3778 | ES2_OPENGL(), |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 3779 | ES2_OPENGLES(), |
| 3780 | ES2_VULKAN()); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 3781 | ANGLE_INSTANTIATE_TEST(Texture2DTestWithDrawScale, |
| 3782 | ES2_D3D9(), |
| 3783 | ES2_D3D11(), |
| 3784 | ES2_D3D11_FL9_3(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3785 | ES2_OPENGL(), |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 3786 | ES2_OPENGLES(), |
| 3787 | ES2_VULKAN()); |
Olli Etuaho | 51f1c0f | 2016-01-13 16:16:24 +0200 | [diff] [blame] | 3788 | ANGLE_INSTANTIATE_TEST(Sampler2DAsFunctionParameterTest, |
| 3789 | ES2_D3D9(), |
| 3790 | ES2_D3D11(), |
| 3791 | ES2_D3D11_FL9_3(), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3792 | ES2_OPENGL(), |
| 3793 | ES2_OPENGLES()); |
| 3794 | ANGLE_INSTANTIATE_TEST(SamplerArrayTest, |
| 3795 | ES2_D3D9(), |
| 3796 | ES2_D3D11(), |
| 3797 | ES2_D3D11_FL9_3(), |
| 3798 | ES2_OPENGL(), |
| 3799 | ES2_OPENGLES()); |
| 3800 | ANGLE_INSTANTIATE_TEST(SamplerArrayAsFunctionParameterTest, |
| 3801 | ES2_D3D9(), |
| 3802 | ES2_D3D11(), |
| 3803 | ES2_D3D11_FL9_3(), |
| 3804 | ES2_OPENGL(), |
| 3805 | ES2_OPENGLES()); |
| 3806 | ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Olli Etuaho | a314b61 | 2016-03-10 16:43:00 +0200 | [diff] [blame] | 3807 | ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Olli Etuaho | 6ee394a | 2016-02-18 13:30:09 +0200 | [diff] [blame] | 3808 | ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
| 3809 | ANGLE_INSTANTIATE_TEST(Texture2DUnsignedIntegerAlpha1TestES3, |
| 3810 | ES3_D3D11(), |
| 3811 | ES3_OPENGL(), |
| 3812 | ES3_OPENGLES()); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 3813 | ANGLE_INSTANTIATE_TEST(ShadowSamplerPlusSampler3DTestES3, |
| 3814 | ES3_D3D11(), |
| 3815 | ES3_OPENGL(), |
| 3816 | ES3_OPENGLES()); |
| 3817 | ANGLE_INSTANTIATE_TEST(SamplerTypeMixTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
| 3818 | ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Olli Etuaho | bce743a | 2016-01-15 17:18:28 +0200 | [diff] [blame] | 3819 | ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL()); |
Olli Etuaho | 9696316 | 2016-03-21 11:54:33 +0200 | [diff] [blame] | 3820 | ANGLE_INSTANTIATE_TEST(SamplerInStructTest, |
| 3821 | ES2_D3D11(), |
| 3822 | ES2_D3D11_FL9_3(), |
| 3823 | ES2_D3D9(), |
| 3824 | ES2_OPENGL(), |
| 3825 | ES2_OPENGLES()); |
| 3826 | ANGLE_INSTANTIATE_TEST(SamplerInStructAsFunctionParameterTest, |
| 3827 | ES2_D3D11(), |
| 3828 | ES2_D3D11_FL9_3(), |
| 3829 | ES2_D3D9(), |
| 3830 | ES2_OPENGL(), |
| 3831 | ES2_OPENGLES()); |
| 3832 | ANGLE_INSTANTIATE_TEST(SamplerInStructArrayAsFunctionParameterTest, |
| 3833 | ES2_D3D11(), |
| 3834 | ES2_D3D11_FL9_3(), |
| 3835 | ES2_D3D9(), |
| 3836 | ES2_OPENGL(), |
| 3837 | ES2_OPENGLES()); |
| 3838 | ANGLE_INSTANTIATE_TEST(SamplerInNestedStructAsFunctionParameterTest, |
| 3839 | ES2_D3D11(), |
| 3840 | ES2_D3D11_FL9_3(), |
| 3841 | ES2_D3D9(), |
| 3842 | ES2_OPENGL(), |
| 3843 | ES2_OPENGLES()); |
| 3844 | ANGLE_INSTANTIATE_TEST(SamplerInStructAndOtherVariableTest, |
| 3845 | ES2_D3D11(), |
| 3846 | ES2_D3D11_FL9_3(), |
| 3847 | ES2_D3D9(), |
| 3848 | ES2_OPENGL(), |
| 3849 | ES2_OPENGLES()); |
Luc Ferron | af88362 | 2018-06-08 15:57:31 -0400 | [diff] [blame] | 3850 | ANGLE_INSTANTIATE_TEST(TextureLimitsTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN()); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 3851 | ANGLE_INSTANTIATE_TEST(Texture2DNorm16TestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Martin Radev | 7e2c0d3 | 2017-09-15 14:25:42 +0300 | [diff] [blame] | 3852 | ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 3853 | |
Jamie Madill | 7ffdda9 | 2016-09-08 13:26:51 -0400 | [diff] [blame] | 3854 | } // anonymous namespace |