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 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 8 | |
Geoff Lang | 46258e1 | 2017-04-10 12:28:34 -0400 | [diff] [blame^] | 9 | #include "test_utils/gl_raii.h" |
| 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | using namespace angle; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 12 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 13 | namespace |
| 14 | { |
| 15 | |
| 16 | void TexImageCubeMapFaces(GLint level, |
| 17 | GLenum internalformat, |
| 18 | GLsizei width, |
| 19 | GLenum format, |
| 20 | GLenum type, |
| 21 | void *pixels) |
| 22 | { |
| 23 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, internalformat, width, width, 0, format, |
| 24 | type, pixels); |
| 25 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, internalformat, width, width, 0, format, |
| 26 | type, pixels); |
| 27 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, internalformat, width, width, 0, format, |
| 28 | type, pixels); |
| 29 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, internalformat, width, width, 0, format, |
| 30 | type, pixels); |
| 31 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, internalformat, width, width, 0, format, |
| 32 | type, pixels); |
| 33 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, internalformat, width, width, 0, format, |
| 34 | type, pixels); |
| 35 | } |
| 36 | |
| 37 | class BaseMipmapTest : public ANGLETest |
| 38 | { |
| 39 | protected: |
| 40 | void clearAndDrawQuad(GLuint program, GLsizei viewportWidth, GLsizei viewportHeight) |
| 41 | { |
| 42 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 43 | glClear(GL_COLOR_BUFFER_BIT); |
| 44 | glViewport(0, 0, viewportWidth, viewportHeight); |
| 45 | ASSERT_GL_NO_ERROR(); |
| 46 | |
| 47 | drawQuad(program, "position", 0.0f); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | } // namespace |
| 52 | |
| 53 | class MipmapTest : public BaseMipmapTest |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 54 | { |
| 55 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 56 | MipmapTest() |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 57 | : m2DProgram(0), |
| 58 | mCubeProgram(0), |
| 59 | mTexture2D(0), |
| 60 | mTextureCube(0), |
| 61 | mLevelZeroBlueInitData(nullptr), |
| 62 | mLevelZeroWhiteInitData(nullptr), |
| 63 | mLevelOneInitData(nullptr), |
| 64 | mLevelTwoInitData(nullptr), |
| 65 | mOffscreenFramebuffer(0) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 66 | { |
| 67 | setWindowWidth(128); |
| 68 | setWindowHeight(128); |
| 69 | setConfigRedBits(8); |
| 70 | setConfigGreenBits(8); |
| 71 | setConfigBlueBits(8); |
| 72 | setConfigAlphaBits(8); |
| 73 | } |
| 74 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 75 | void setUp2DProgram() |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 76 | { |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 77 | // Vertex Shader source |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 78 | // clang-format off |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 79 | const std::string vs = SHADER_SOURCE |
| 80 | ( |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 81 | attribute vec4 position; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 82 | varying vec2 vTexCoord; |
| 83 | |
| 84 | void main() |
| 85 | { |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 86 | gl_Position = position; |
| 87 | vTexCoord = (position.xy * 0.5) + 0.5; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 88 | } |
| 89 | ); |
| 90 | |
| 91 | // Fragment Shader source |
| 92 | const std::string fs = SHADER_SOURCE |
| 93 | ( |
| 94 | precision mediump float; |
| 95 | |
| 96 | uniform sampler2D uTexture; |
| 97 | varying vec2 vTexCoord; |
| 98 | |
| 99 | void main() |
| 100 | { |
| 101 | gl_FragColor = texture2D(uTexture, vTexCoord); |
| 102 | } |
| 103 | ); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 104 | // clang-format on |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 105 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 106 | m2DProgram = CompileProgram(vs, fs); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 107 | ASSERT_NE(0u, m2DProgram); |
| 108 | } |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 109 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 110 | void setUpCubeProgram() |
| 111 | { |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 112 | // A simple vertex shader for the texture cube |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 113 | // clang-format off |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 114 | const std::string cubeVS = SHADER_SOURCE |
| 115 | ( |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 116 | attribute vec4 position; |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 117 | varying vec4 vPosition; |
| 118 | void main() |
| 119 | { |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 120 | gl_Position = position; |
| 121 | vPosition = position; |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 122 | } |
| 123 | ); |
| 124 | |
| 125 | // A very simple fragment shader to sample from the negative-Y face of a texture cube. |
| 126 | const std::string cubeFS = SHADER_SOURCE |
| 127 | ( |
| 128 | precision mediump float; |
| 129 | uniform samplerCube uTexture; |
| 130 | varying vec4 vPosition; |
| 131 | |
| 132 | void main() |
| 133 | { |
| 134 | gl_FragColor = textureCube(uTexture, vec3(vPosition.x, -1, vPosition.y)); |
| 135 | } |
| 136 | ); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 137 | // clang-format on |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 138 | |
| 139 | mCubeProgram = CompileProgram(cubeVS, cubeFS); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 140 | ASSERT_NE(0u, mCubeProgram); |
| 141 | } |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 142 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 143 | void SetUp() override |
| 144 | { |
| 145 | ANGLETest::SetUp(); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 146 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 147 | setUp2DProgram(); |
| 148 | |
| 149 | setUpCubeProgram(); |
Geoff Lang | 27359ff | 2015-06-02 15:42:04 -0400 | [diff] [blame] | 150 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 151 | mLevelZeroBlueInitData = createRGBInitData(getWindowWidth(), getWindowHeight(), 0, 0, 255); // Blue |
| 152 | mLevelZeroWhiteInitData = createRGBInitData(getWindowWidth(), getWindowHeight(), 255, 255, 255); // White |
| 153 | mLevelOneInitData = createRGBInitData((getWindowWidth() / 2), (getWindowHeight() / 2), 0, 255, 0); // Green |
| 154 | mLevelTwoInitData = createRGBInitData((getWindowWidth() / 4), (getWindowHeight() / 4), 255, 0, 0); // Red |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 155 | |
| 156 | glGenFramebuffers(1, &mOffscreenFramebuffer); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 157 | glGenTextures(1, &mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 158 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 159 | // Initialize the texture2D to be empty, and don't use mips. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 160 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 161 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 162 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 163 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 164 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 165 | ASSERT_EQ(getWindowWidth(), getWindowHeight()); |
| 166 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 167 | // Create a non-mipped texture cube. Set the negative-Y face to be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 168 | glGenTextures(1, &mTextureCube); |
| 169 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 170 | TexImageCubeMapFaces(0, GL_RGB, getWindowWidth(), GL_RGB, GL_UNSIGNED_BYTE, nullptr); |
| 171 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, getWindowWidth(), getWindowWidth(), |
| 172 | 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 173 | |
| 174 | // Complete the texture cube without mipmaps to start with. |
| 175 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 176 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 177 | |
| 178 | ASSERT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 181 | void TearDown() override |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 182 | { |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 183 | glDeleteProgram(m2DProgram); |
| 184 | glDeleteProgram(mCubeProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 185 | glDeleteFramebuffers(1, &mOffscreenFramebuffer); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 186 | glDeleteTextures(1, &mTexture2D); |
| 187 | glDeleteTextures(1, &mTextureCube); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 188 | |
Corentin Wallez | 254fcea | 2015-08-25 15:11:07 -0400 | [diff] [blame] | 189 | SafeDeleteArray(mLevelZeroBlueInitData); |
| 190 | SafeDeleteArray(mLevelZeroWhiteInitData); |
| 191 | SafeDeleteArray(mLevelOneInitData); |
| 192 | SafeDeleteArray(mLevelTwoInitData); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 193 | |
| 194 | ANGLETest::TearDown(); |
| 195 | } |
| 196 | |
| 197 | GLubyte *createRGBInitData(GLint width, GLint height, GLint r, GLint g, GLint b) |
| 198 | { |
| 199 | GLubyte *data = new GLubyte[3 * width * height]; |
| 200 | |
| 201 | for (int i = 0; i < width * height; i+=1) |
| 202 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 203 | data[3 * i + 0] = static_cast<GLubyte>(r); |
| 204 | data[3 * i + 1] = static_cast<GLubyte>(g); |
| 205 | data[3 * i + 2] = static_cast<GLubyte>(b); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return data; |
| 209 | } |
| 210 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 211 | void clearTextureLevel0(GLenum textarget, |
| 212 | GLuint texture, |
| 213 | GLfloat red, |
| 214 | GLfloat green, |
| 215 | GLfloat blue, |
| 216 | GLfloat alpha) |
| 217 | { |
| 218 | glBindFramebuffer(GL_FRAMEBUFFER, mOffscreenFramebuffer); |
| 219 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textarget, texture, 0); |
| 220 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 221 | glClearColor(red, green, blue, alpha); |
| 222 | glClear(GL_COLOR_BUFFER_BIT); |
| 223 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 226 | GLuint m2DProgram; |
| 227 | GLuint mCubeProgram; |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 228 | GLuint mTexture2D; |
| 229 | GLuint mTextureCube; |
Geoff Lang | 27359ff | 2015-06-02 15:42:04 -0400 | [diff] [blame] | 230 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 231 | GLubyte* mLevelZeroBlueInitData; |
| 232 | GLubyte* mLevelZeroWhiteInitData; |
| 233 | GLubyte* mLevelOneInitData; |
| 234 | GLubyte* mLevelTwoInitData; |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 235 | |
| 236 | private: |
| 237 | GLuint mOffscreenFramebuffer; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 240 | class MipmapTestES3 : public BaseMipmapTest |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 241 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 242 | protected: |
| 243 | MipmapTestES3() |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 244 | : mTexture(0), |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 245 | mArrayProgram(0), |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 246 | mTextureArraySliceUniformLocation(-1), |
| 247 | m3DProgram(0), |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 248 | mTexture3DSliceUniformLocation(-1), |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 249 | mTexture3DLODUniformLocation(-1), |
| 250 | m2DProgram(0) |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 251 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 252 | { |
| 253 | setWindowWidth(128); |
| 254 | setWindowHeight(128); |
| 255 | setConfigRedBits(8); |
| 256 | setConfigGreenBits(8); |
| 257 | setConfigBlueBits(8); |
| 258 | setConfigAlphaBits(8); |
| 259 | } |
| 260 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 261 | std::string vertexShaderSource() |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 262 | { |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 263 | // Don't put "#version ..." on its own line. See [cpp]p1: |
| 264 | // "If there are sequences of preprocessing tokens within the list of arguments that |
| 265 | // would otherwise act as preprocessing directives, the behavior is undefined" |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 266 | // clang-format off |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 267 | return SHADER_SOURCE |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 268 | ( #version 300 es\n |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 269 | precision highp float; |
| 270 | in vec4 position; |
| 271 | out vec2 texcoord; |
| 272 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 273 | void main() |
| 274 | { |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 275 | gl_Position = vec4(position.xy, 0.0, 1.0); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 276 | texcoord = (position.xy * 0.5) + 0.5; |
| 277 | } |
| 278 | ); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 279 | // clang-format on |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 280 | } |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 281 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 282 | void setUpArrayProgram() |
| 283 | { |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 284 | const std::string fragmentShaderSourceArray = SHADER_SOURCE |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 285 | ( #version 300 es\n |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 286 | precision highp float; |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 287 | uniform highp sampler2DArray tex; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 288 | uniform int slice; |
| 289 | in vec2 texcoord; |
| 290 | out vec4 out_FragColor; |
| 291 | |
| 292 | void main() |
| 293 | { |
| 294 | out_FragColor = texture(tex, vec3(texcoord, float(slice))); |
| 295 | } |
| 296 | ); |
| 297 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 298 | mArrayProgram = CompileProgram(vertexShaderSource(), fragmentShaderSourceArray); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 299 | if (mArrayProgram == 0) |
| 300 | { |
| 301 | FAIL() << "shader compilation failed."; |
| 302 | } |
| 303 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 304 | mTextureArraySliceUniformLocation = glGetUniformLocation(mArrayProgram, "slice"); |
| 305 | ASSERT_NE(-1, mTextureArraySliceUniformLocation); |
| 306 | |
| 307 | glUseProgram(mArrayProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 308 | glUseProgram(0); |
| 309 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 310 | } |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 311 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 312 | void setUp3DProgram() |
| 313 | { |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 314 | const std::string fragmentShaderSource3D = SHADER_SOURCE |
| 315 | ( #version 300 es\n |
| 316 | precision highp float; |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 317 | uniform highp sampler3D tex; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 318 | uniform float slice; |
| 319 | uniform float lod; |
| 320 | in vec2 texcoord; |
| 321 | out vec4 out_FragColor; |
| 322 | |
| 323 | void main() |
| 324 | { |
| 325 | out_FragColor = textureLod(tex, vec3(texcoord, slice), lod); |
| 326 | } |
| 327 | ); |
| 328 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 329 | m3DProgram = CompileProgram(vertexShaderSource(), fragmentShaderSource3D); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 330 | if (m3DProgram == 0) |
| 331 | { |
| 332 | FAIL() << "shader compilation failed."; |
| 333 | } |
| 334 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 335 | mTexture3DSliceUniformLocation = glGetUniformLocation(m3DProgram, "slice"); |
| 336 | ASSERT_NE(-1, mTexture3DSliceUniformLocation); |
| 337 | |
| 338 | mTexture3DLODUniformLocation = glGetUniformLocation(m3DProgram, "lod"); |
| 339 | ASSERT_NE(-1, mTexture3DLODUniformLocation); |
| 340 | |
| 341 | glUseProgram(m3DProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 342 | glUniform1f(mTexture3DLODUniformLocation, 0); |
| 343 | glUseProgram(0); |
| 344 | ASSERT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 347 | void setUp2DProgram() |
| 348 | { |
| 349 | // clang-format off |
| 350 | const std::string fragmentShaderSource2D = SHADER_SOURCE |
| 351 | ( #version 300 es\n |
| 352 | precision highp float; |
| 353 | uniform highp sampler2D tex; |
| 354 | in vec2 texcoord; |
| 355 | out vec4 out_FragColor; |
| 356 | |
| 357 | void main() |
| 358 | { |
| 359 | out_FragColor = texture(tex, texcoord); |
| 360 | } |
| 361 | ); |
| 362 | // clang-format on |
| 363 | |
| 364 | m2DProgram = CompileProgram(vertexShaderSource(), fragmentShaderSource2D); |
| 365 | ASSERT_NE(0u, m2DProgram); |
| 366 | |
| 367 | ASSERT_GL_NO_ERROR(); |
| 368 | } |
| 369 | |
| 370 | void setUpCubeProgram() |
| 371 | { |
| 372 | // A very simple fragment shader to sample from the negative-Y face of a texture cube. |
| 373 | // clang-format off |
| 374 | const std::string cubeFS = SHADER_SOURCE |
| 375 | ( #version 300 es\n |
| 376 | precision mediump float; |
| 377 | uniform samplerCube uTexture; |
| 378 | in vec2 texcoord; |
| 379 | out vec4 out_FragColor; |
| 380 | |
| 381 | void main() |
| 382 | { |
| 383 | out_FragColor = texture(uTexture, vec3(texcoord.x, -1, texcoord.y)); |
| 384 | } |
| 385 | ); |
| 386 | // clang-format on |
| 387 | |
| 388 | mCubeProgram = CompileProgram(vertexShaderSource(), cubeFS); |
| 389 | ASSERT_NE(0u, mCubeProgram); |
| 390 | |
| 391 | ASSERT_GL_NO_ERROR(); |
| 392 | } |
| 393 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 394 | void SetUp() override |
| 395 | { |
| 396 | ANGLETest::SetUp(); |
| 397 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 398 | glGenTextures(1, &mTexture); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 399 | ASSERT_GL_NO_ERROR(); |
| 400 | |
| 401 | setUpArrayProgram(); |
| 402 | setUp3DProgram(); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 403 | setUp2DProgram(); |
| 404 | setUpCubeProgram(); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void TearDown() override |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 408 | { |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 409 | glDeleteTextures(1, &mTexture); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 410 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 411 | glDeleteProgram(mArrayProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 412 | glDeleteProgram(m3DProgram); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 413 | glDeleteProgram(m2DProgram); |
| 414 | glDeleteProgram(mCubeProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 415 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 416 | ANGLETest::TearDown(); |
| 417 | } |
| 418 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 419 | GLuint mTexture; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 420 | |
| 421 | GLuint mArrayProgram; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 422 | GLint mTextureArraySliceUniformLocation; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 423 | |
| 424 | GLuint m3DProgram; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 425 | GLint mTexture3DSliceUniformLocation; |
| 426 | GLint mTexture3DLODUniformLocation; |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 427 | |
| 428 | GLuint m2DProgram; |
| 429 | |
| 430 | GLuint mCubeProgram; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | // This test uses init data for the first three levels of the texture. It passes the level 0 data in, then renders, then level 1, then renders, etc. |
| 434 | // This ensures that renderers using the zero LOD workaround (e.g. D3D11 FL9_3) correctly pass init data to the mipmapped texture, |
| 435 | // even if the the zero-LOD texture is currently in use. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 436 | TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 437 | { |
| 438 | // Pass in level zero init data. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 439 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 440 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
| 441 | ASSERT_GL_NO_ERROR(); |
| 442 | |
| 443 | // Disable mips. |
| 444 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 445 | |
| 446 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 447 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 448 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 449 | |
| 450 | // Draw a half-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 451 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 452 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 453 | |
| 454 | // Draw a quarter-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 455 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 456 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 457 | |
| 458 | // Complete the texture by initializing the remaining levels. |
| 459 | int n = 1; |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 460 | while (getWindowWidth() / (1U << n) >= 1) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 461 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 462 | glTexImage2D(GL_TEXTURE_2D, n, GL_RGB, getWindowWidth() / (1U << n), getWindowWidth() / (1U << n), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 463 | ASSERT_GL_NO_ERROR(); |
| 464 | n+=1; |
| 465 | } |
| 466 | |
| 467 | // Pass in level one init data. |
| 468 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelOneInitData); |
| 469 | ASSERT_GL_NO_ERROR(); |
| 470 | |
| 471 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 472 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 473 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 474 | |
| 475 | // Draw a half-sized quad, and check it's blue. We've not enabled mipmaps yet, so our init data for level one shouldn't be used. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 476 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 477 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 478 | |
| 479 | // Enable mipmaps. |
| 480 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 481 | |
| 482 | // Draw a half-sized quad, and check it's green. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 483 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 484 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 485 | |
| 486 | // Draw a quarter-sized quad, and check it's black, since we've not passed any init data for level two. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 487 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 488 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::black); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 489 | |
| 490 | // Pass in level two init data. |
| 491 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, getWindowWidth() / 4, getWindowHeight() / 4, 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelTwoInitData); |
| 492 | ASSERT_GL_NO_ERROR(); |
| 493 | |
| 494 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 495 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 496 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 497 | |
| 498 | // Draw a half-sized quad, and check it's green. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 499 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 500 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 501 | |
| 502 | // Draw a quarter-sized quad, and check it's red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 503 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 504 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 505 | |
| 506 | // Now disable mipmaps again, and render multiple sized quads. They should all be blue, since level 0 is blue. |
| 507 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 508 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 509 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 510 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 511 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 512 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 513 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 514 | |
| 515 | // Now reset level 0 to white, keeping mipmaps disabled. Then, render various sized quads. They should be white. |
| 516 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroWhiteInitData); |
| 517 | ASSERT_GL_NO_ERROR(); |
| 518 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 519 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 520 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 521 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 522 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 523 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 524 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::white); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 525 | |
| 526 | // Then enable mipmaps again. The quads should be white, green, red respectively. |
| 527 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 528 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 529 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 530 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 531 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 532 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 533 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 534 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | // This test generates (and uses) mipmaps on a texture using init data. D3D11 will use a non-renderable TextureStorage for this. |
| 538 | // The test then disables mips, renders to level zero of the texture, and reenables mips before using the texture again. |
| 539 | // To do this, D3D11 has to convert the TextureStorage into a renderable one. |
| 540 | // This test ensures that the conversion works correctly. |
| 541 | // In particular, on D3D11 Feature Level 9_3 it ensures that both the zero LOD workaround texture AND the 'normal' texture are copied during conversion. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 542 | TEST_P(MipmapTest, GenerateMipmapFromInitDataThenRender) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 543 | { |
| 544 | // Pass in initial data so the texture is blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 545 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 546 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
| 547 | |
| 548 | // Then generate the mips. |
| 549 | glGenerateMipmap(GL_TEXTURE_2D); |
| 550 | ASSERT_GL_NO_ERROR(); |
| 551 | |
| 552 | // Enable mipmaps. |
| 553 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 554 | |
| 555 | // Now draw the texture to various different sized areas. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 556 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 557 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 558 | |
| 559 | // Use mip level 1 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 560 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 561 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 562 | |
| 563 | // Use mip level 2 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 564 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 565 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 566 | |
| 567 | ASSERT_GL_NO_ERROR(); |
| 568 | |
| 569 | // Disable mips. Render a quad using the texture and ensure it's blue. |
| 570 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 571 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 572 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 573 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 574 | // Clear level 0 of the texture to red. |
| 575 | clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 1.0f, 0.0f, 0.0f, 1.0f); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 576 | |
| 577 | // Reenable mips, and try rendering different-sized quads. |
| 578 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 579 | |
| 580 | // Level 0 is now red, so this should render red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 581 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 582 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 583 | |
| 584 | // Use mip level 1, blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 585 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 586 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 587 | |
| 588 | // Use mip level 2, blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 589 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 590 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | // This test ensures that mips are correctly generated from a rendered image. |
| 594 | // In particular, on D3D11 Feature Level 9_3, the clear call will be performed on the zero-level texture, rather than the mipped one. |
| 595 | // The test ensures that the zero-level texture is correctly copied into the mipped texture before the mipmaps are generated. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 596 | TEST_P(MipmapTest, GenerateMipmapFromRenderedImage) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 597 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 598 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 599 | // Clear the texture to blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 600 | clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 0.0f, 0.0f, 1.0f, 1.0f); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 601 | |
| 602 | // Then generate the mips |
| 603 | glGenerateMipmap(GL_TEXTURE_2D); |
| 604 | ASSERT_GL_NO_ERROR(); |
| 605 | |
| 606 | // Enable mips. |
| 607 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 608 | |
| 609 | // Now draw the texture to various different sized areas. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 610 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 611 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 612 | |
| 613 | // Use mip level 1 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 614 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 615 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 616 | |
| 617 | // Use mip level 2 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 618 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 619 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // Test to ensure that rendering to a mipmapped texture works, regardless of whether mipmaps are enabled or not. |
| 623 | // TODO: This test hits a texture rebind bug in the D3D11 renderer. Fix this. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 624 | TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 625 | { |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 626 | // TODO(geofflang): Figure out why this is broken on AMD OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 627 | if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 628 | { |
Geoff Lang | 35b08e3 | 2015-06-03 11:22:07 -0400 | [diff] [blame] | 629 | std::cout << "Test skipped on Intel/AMD OpenGL." << std::endl; |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 630 | return; |
| 631 | } |
| 632 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 633 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 634 | |
| 635 | // Clear the texture to blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 636 | clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 0.0f, 0.0f, 1.0f, 1.0f); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 637 | |
| 638 | // Now, draw the texture to a quad that's the same size as the texture. This draws to the default framebuffer. |
| 639 | // The quad should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 640 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 641 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 642 | |
| 643 | // Now go back to the texture, and generate mips on it. |
| 644 | glGenerateMipmap(GL_TEXTURE_2D); |
| 645 | ASSERT_GL_NO_ERROR(); |
| 646 | |
| 647 | // Now try rendering the textured quad again. Note: we've not told GL to use the generated mips. |
| 648 | // The quad should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 649 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 650 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 651 | |
| 652 | // Now tell GL to use the generated mips. |
| 653 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 654 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 655 | |
| 656 | // Now render the textured quad again. It should be still be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 657 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 658 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 659 | |
| 660 | // Now render the textured quad to an area smaller than the texture (i.e. to force minification). This should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 661 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 662 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 663 | |
| 664 | // Now clear the texture to green. This just clears the top level. The lower mips should remain blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 665 | clearTextureLevel0(GL_TEXTURE_2D, mTexture2D, 0.0f, 1.0f, 0.0f, 1.0f); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 666 | |
| 667 | // Render a textured quad equal in size to the texture. This should be green, since we just cleared level 0. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 668 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 669 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 670 | |
| 671 | // Render a small textured quad. This forces minification, so should render blue (the color of levels 1+). |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 672 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 673 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 674 | |
| 675 | // Disable mipmaps again |
| 676 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 677 | ASSERT_GL_NO_ERROR(); |
| 678 | |
| 679 | // Render a textured quad equal in size to the texture. This should be green, the color of level 0 in the texture. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 680 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 681 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 682 | |
| 683 | // Render a small textured quad. This would force minification if mips were enabled, but they're not. Therefore, this should be green. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 684 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 685 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 686 | } |
| 687 | |
Geoff Lang | 46258e1 | 2017-04-10 12:28:34 -0400 | [diff] [blame^] | 688 | // Regression test for a bug that cause mipmaps to only generate using the top left corner as input. |
| 689 | TEST_P(MipmapTest, MipMapGenerationD3D9Bug) |
| 690 | { |
| 691 | if (!extensionEnabled("GL_EXT_texture_storage") || !extensionEnabled("GL_OES_rgb8_rgba8") || |
| 692 | !extensionEnabled("GL_ANGLE_texture_usage")) |
| 693 | { |
| 694 | std::cout << "Test skipped due to missing extensions." << std::endl; |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | const GLColor mip0Color[4] = { |
| 699 | GLColor::red, GLColor::green, GLColor::red, GLColor::green, |
| 700 | }; |
| 701 | const GLColor mip1Color = GLColor(127, 127, 0, 255); |
| 702 | |
| 703 | GLTexture texture; |
| 704 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 705 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE); |
| 706 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 707 | glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA8_OES, 2, 2); |
| 708 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, mip0Color); |
| 709 | glGenerateMipmap(GL_TEXTURE_2D); |
| 710 | |
| 711 | // Only draw to a 1 pixel viewport so the lower mip is used |
| 712 | clearAndDrawQuad(m2DProgram, 1, 1); |
| 713 | EXPECT_PIXEL_COLOR_NEAR(0, 0, mip1Color, 1.0); |
| 714 | } |
| 715 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 716 | // This test ensures that the level-zero workaround for TextureCubes (on D3D11 Feature Level 9_3) |
| 717 | // works as expected. It tests enabling/disabling mipmaps, generating mipmaps, and rendering to level zero. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 718 | TEST_P(MipmapTest, TextureCubeGeneralLevelZero) |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 719 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 720 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 721 | |
| 722 | // Draw. Since the negative-Y face's is blue, this should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 723 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 724 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 725 | |
| 726 | // Generate mipmaps, and render. This should be blue. |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 727 | glGenerateMipmap(GL_TEXTURE_CUBE_MAP); |
| 728 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 729 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 730 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 731 | |
| 732 | // Draw using a smaller viewport (to force a lower LOD of the texture). This should still be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 733 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 734 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 735 | |
| 736 | // Now clear the negative-Y face of the cube to red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 737 | clearTextureLevel0(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mTextureCube, 1.0f, 0.0f, 0.0f, 1.0f); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 738 | |
| 739 | // Draw using a full-size viewport. This should be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 740 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 741 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 742 | |
| 743 | // Draw using a quarter-size viewport, to force a lower LOD. This should be *BLUE*, since we only cleared level zero |
| 744 | // of the negative-Y face to red, and left its mipmaps blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 745 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 746 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 747 | |
| 748 | // Disable mipmaps again, and draw a to a quarter-size viewport. |
| 749 | // Since this should use level zero of the texture, this should be *RED*. |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 750 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 751 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 752 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | // This test ensures that rendering to level-zero of a TextureCube works as expected. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 756 | TEST_P(MipmapTest, TextureCubeRenderToLevelZero) |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 757 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 758 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 759 | |
| 760 | // Draw. Since the negative-Y face's is blue, this should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 761 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 762 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 763 | |
| 764 | // Now clear the negative-Y face of the cube to red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 765 | clearTextureLevel0(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mTextureCube, 1.0f, 0.0f, 0.0f, 1.0f); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 766 | |
| 767 | // Draw using a full-size viewport. This should be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 768 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 769 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 770 | |
| 771 | // Draw a to a quarter-size viewport. This should also be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 772 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 773 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 776 | // Creates a mipmapped 2D array texture with three layers, and calls ANGLE's GenerateMipmap. |
| 777 | // Then tests if the mipmaps are rendered correctly for all three layers. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 778 | TEST_P(MipmapTestES3, MipmapsForTextureArray) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 779 | { |
| 780 | int px = getWindowWidth() / 2; |
| 781 | int py = getWindowHeight() / 2; |
| 782 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 783 | glBindTexture(GL_TEXTURE_2D_ARRAY, mTexture); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 784 | |
| 785 | glTexStorage3D(GL_TEXTURE_2D_ARRAY, 5, GL_RGBA8, 16, 16, 3); |
| 786 | |
| 787 | // Fill the first layer with red |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 788 | std::vector<GLColor> pixelsRed(16 * 16, GLColor::red); |
| 789 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 790 | pixelsRed.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 791 | |
| 792 | // Fill the second layer with green |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 793 | std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green); |
| 794 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 795 | pixelsGreen.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 796 | |
| 797 | // Fill the third layer with blue |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 798 | std::vector<GLColor> pixelsBlue(16 * 16, GLColor::blue); |
| 799 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 800 | pixelsBlue.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 801 | |
| 802 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 803 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 804 | |
| 805 | EXPECT_GL_NO_ERROR(); |
| 806 | |
| 807 | glGenerateMipmap(GL_TEXTURE_2D_ARRAY); |
| 808 | |
| 809 | EXPECT_GL_NO_ERROR(); |
| 810 | |
| 811 | glUseProgram(mArrayProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 812 | |
| 813 | EXPECT_GL_NO_ERROR(); |
| 814 | |
| 815 | // Draw the first slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 816 | glUniform1i(mTextureArraySliceUniformLocation, 0); |
| 817 | drawQuad(mArrayProgram, "position", 0.5f); |
| 818 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 819 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 820 | |
| 821 | // Draw the second slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 822 | glUniform1i(mTextureArraySliceUniformLocation, 1); |
| 823 | drawQuad(mArrayProgram, "position", 0.5f); |
| 824 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 825 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 826 | |
| 827 | // Draw the third slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 828 | glUniform1i(mTextureArraySliceUniformLocation, 2); |
| 829 | drawQuad(mArrayProgram, "position", 0.5f); |
| 830 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 831 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::blue); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 834 | // Create a mipmapped 2D array texture with more layers than width / height, and call |
| 835 | // GenerateMipmap. |
| 836 | TEST_P(MipmapTestES3, MipmapForDeepTextureArray) |
| 837 | { |
| 838 | int px = getWindowWidth() / 2; |
| 839 | int py = getWindowHeight() / 2; |
| 840 | |
| 841 | glBindTexture(GL_TEXTURE_2D_ARRAY, mTexture); |
| 842 | |
| 843 | // Fill the whole texture with red. |
| 844 | std::vector<GLColor> pixelsRed(2 * 2 * 4, GLColor::red); |
| 845 | glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, 2, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 846 | pixelsRed.data()); |
| 847 | |
| 848 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 849 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 850 | |
| 851 | EXPECT_GL_NO_ERROR(); |
| 852 | |
| 853 | glGenerateMipmap(GL_TEXTURE_2D_ARRAY); |
| 854 | |
| 855 | EXPECT_GL_NO_ERROR(); |
| 856 | |
| 857 | glUseProgram(mArrayProgram); |
| 858 | |
| 859 | EXPECT_GL_NO_ERROR(); |
| 860 | |
| 861 | // Draw the first slice |
| 862 | glUniform1i(mTextureArraySliceUniformLocation, 0); |
| 863 | drawQuad(mArrayProgram, "position", 0.5f); |
| 864 | EXPECT_GL_NO_ERROR(); |
| 865 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
| 866 | |
| 867 | // Draw the fourth slice |
| 868 | glUniform1i(mTextureArraySliceUniformLocation, 3); |
| 869 | drawQuad(mArrayProgram, "position", 0.5f); |
| 870 | EXPECT_GL_NO_ERROR(); |
| 871 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
| 872 | } |
| 873 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 874 | // Creates a mipmapped 3D texture with two layers, and calls ANGLE's GenerateMipmap. |
| 875 | // Then tests if the mipmaps are rendered correctly for all two layers. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 876 | TEST_P(MipmapTestES3, MipmapsForTexture3D) |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 877 | { |
| 878 | int px = getWindowWidth() / 2; |
| 879 | int py = getWindowHeight() / 2; |
| 880 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 881 | glBindTexture(GL_TEXTURE_3D, mTexture); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 882 | |
| 883 | glTexStorage3D(GL_TEXTURE_3D, 5, GL_RGBA8, 16, 16, 2); |
| 884 | |
| 885 | // Fill the first layer with red |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 886 | std::vector<GLColor> pixelsRed(16 * 16, GLColor::red); |
| 887 | glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 888 | pixelsRed.data()); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 889 | |
| 890 | // Fill the second layer with green |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 891 | std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green); |
| 892 | glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 893 | pixelsGreen.data()); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 894 | |
| 895 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 896 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 897 | |
| 898 | EXPECT_GL_NO_ERROR(); |
| 899 | |
| 900 | glGenerateMipmap(GL_TEXTURE_3D); |
| 901 | |
| 902 | EXPECT_GL_NO_ERROR(); |
| 903 | |
| 904 | glUseProgram(m3DProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 905 | |
| 906 | EXPECT_GL_NO_ERROR(); |
| 907 | |
| 908 | // Mipmap level 0 |
| 909 | // Draw the first slice |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 910 | glUniform1f(mTexture3DLODUniformLocation, 0.); |
| 911 | glUniform1f(mTexture3DSliceUniformLocation, 0.25f); |
| 912 | drawQuad(m3DProgram, "position", 0.5f); |
| 913 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 914 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 915 | |
| 916 | // Draw the second slice |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 917 | glUniform1f(mTexture3DSliceUniformLocation, 0.75f); |
| 918 | drawQuad(m3DProgram, "position", 0.5f); |
| 919 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame] | 920 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 921 | |
| 922 | // Mipmap level 1 |
| 923 | // The second mipmap should only have one slice. |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 924 | glUniform1f(mTexture3DLODUniformLocation, 1.); |
| 925 | drawQuad(m3DProgram, "position", 0.5f); |
| 926 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 927 | EXPECT_PIXEL_NEAR(px, py, 127, 127, 0, 255, 1.0); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 928 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 929 | glUniform1f(mTexture3DSliceUniformLocation, 0.75f); |
| 930 | drawQuad(m3DProgram, "position", 0.5f); |
| 931 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 932 | EXPECT_PIXEL_NEAR(px, py, 127, 127, 0, 255, 1.0); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 933 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 934 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 935 | // Create a 2D texture with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays |
| 936 | // the same, and then sample levels 0 and 2. |
| 937 | // GLES 3.0.4 section 3.8.10: |
| 938 | // "Mipmap generation replaces texel array levels levelbase + 1 through q with arrays derived from |
| 939 | // the levelbase array, regardless of their previous contents. All other mipmap arrays, including |
| 940 | // the levelbase array, are left unchanged by this computation." |
| 941 | TEST_P(MipmapTestES3, GenerateMipmapBaseLevel) |
| 942 | { |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 943 | if (IsAMD() && IsDesktopOpenGL()) |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 944 | { |
| 945 | // Observed incorrect rendering on AMD, sampling level 2 returns black. |
| 946 | std::cout << "Test skipped on AMD OpenGL." << std::endl; |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | glBindTexture(GL_TEXTURE_2D, mTexture); |
| 951 | |
Jamie Madill | e1faacb | 2016-12-13 12:42:14 -0500 | [diff] [blame] | 952 | ASSERT_EQ(getWindowWidth(), getWindowHeight()); |
Olli Etuaho | fb80eaf | 2016-07-25 13:39:30 +0300 | [diff] [blame] | 953 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 954 | // Fill level 0 with blue |
| 955 | std::vector<GLColor> pixelsBlue(getWindowWidth() * getWindowHeight(), GLColor::blue); |
| 956 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 957 | GL_UNSIGNED_BYTE, pixelsBlue.data()); |
| 958 | |
| 959 | // Fill level 1 with red |
| 960 | std::vector<GLColor> pixelsRed(getWindowWidth() * getWindowHeight() / 4, GLColor::red); |
| 961 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0, |
| 962 | GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data()); |
| 963 | |
| 964 | // Fill level 2 with green |
| 965 | std::vector<GLColor> pixelsGreen(getWindowWidth() * getWindowHeight() / 16, GLColor::green); |
| 966 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, getWindowWidth() / 4, getWindowHeight() / 4, 0, |
| 967 | GL_RGBA, GL_UNSIGNED_BYTE, pixelsGreen.data()); |
| 968 | |
| 969 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 970 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 971 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1); |
| 972 | |
| 973 | EXPECT_GL_NO_ERROR(); |
| 974 | |
| 975 | // The blue level 0 should be untouched by this since base level is 1. |
| 976 | glGenerateMipmap(GL_TEXTURE_2D); |
| 977 | |
| 978 | EXPECT_GL_NO_ERROR(); |
| 979 | |
| 980 | // Draw using level 2. It should be set to red by GenerateMipmap. |
| 981 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
| 982 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
| 983 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 984 | // Draw using level 0. It should still be blue. |
| 985 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
| 986 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
| 987 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
| 988 | } |
| 989 | |
| 990 | // Create a cube map with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays |
| 991 | // the same, and then sample levels 0 and 2. |
| 992 | // GLES 3.0.4 section 3.8.10: |
| 993 | // "Mipmap generation replaces texel array levels levelbase + 1 through q with arrays derived from |
| 994 | // the levelbase array, regardless of their previous contents. All other mipmap arrays, including |
| 995 | // the levelbase array, are left unchanged by this computation." |
| 996 | TEST_P(MipmapTestES3, GenerateMipmapCubeBaseLevel) |
| 997 | { |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 998 | if (IsAMD() && IsDesktopOpenGL()) |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 999 | { |
| 1000 | // Observed incorrect rendering on AMD, sampling level 2 returns black. |
| 1001 | std::cout << "Test skipped on AMD OpenGL." << std::endl; |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | ASSERT_EQ(getWindowWidth(), getWindowHeight()); |
| 1006 | |
| 1007 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTexture); |
| 1008 | std::vector<GLColor> pixelsBlue(getWindowWidth() * getWindowWidth(), GLColor::blue); |
| 1009 | TexImageCubeMapFaces(0, GL_RGBA8, getWindowWidth(), GL_RGBA, GL_UNSIGNED_BYTE, |
| 1010 | pixelsBlue.data()); |
| 1011 | |
| 1012 | // Fill level 1 with red |
| 1013 | std::vector<GLColor> pixelsRed(getWindowWidth() * getWindowWidth() / 4, GLColor::red); |
| 1014 | TexImageCubeMapFaces(1, GL_RGBA8, getWindowWidth() / 2, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1015 | pixelsRed.data()); |
| 1016 | |
| 1017 | // Fill level 2 with green |
| 1018 | std::vector<GLColor> pixelsGreen(getWindowWidth() * getWindowWidth() / 16, GLColor::green); |
| 1019 | TexImageCubeMapFaces(2, GL_RGBA8, getWindowWidth() / 4, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1020 | pixelsGreen.data()); |
| 1021 | |
| 1022 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 1023 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1024 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 1); |
| 1025 | |
| 1026 | EXPECT_GL_NO_ERROR(); |
| 1027 | |
| 1028 | // The blue level 0 should be untouched by this since base level is 1. |
| 1029 | glGenerateMipmap(GL_TEXTURE_CUBE_MAP); |
| 1030 | |
| 1031 | EXPECT_GL_NO_ERROR(); |
| 1032 | |
| 1033 | // Draw using level 2. It should be set to red by GenerateMipmap. |
| 1034 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
| 1035 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
| 1036 | |
Corentin Wallez | c7f59d0 | 2016-06-20 10:12:08 -0400 | [diff] [blame] | 1037 | if (IsNVIDIA() && IsOpenGL()) |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 1038 | { |
| 1039 | // Observed incorrect rendering on NVIDIA, level zero seems to be incorrectly affected by |
| 1040 | // GenerateMipmap. |
| 1041 | std::cout << "Test partially skipped on NVIDIA OpenGL." << std::endl; |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | // Draw using level 0. It should still be blue. |
| 1046 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0); |
| 1047 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
| 1048 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
| 1049 | } |
| 1050 | |
| 1051 | // Create a texture with levels 0-2, call GenerateMipmap with max level 1 so that level 2 stays the |
| 1052 | // same, and then sample levels 1 and 2. |
| 1053 | // GLES 3.0.4 section 3.8.10: |
| 1054 | // "Mipmap generation replaces texel array levels levelbase + 1 through q with arrays derived from |
| 1055 | // the levelbase array, regardless of their previous contents. All other mipmap arrays, including |
| 1056 | // the levelbase array, are left unchanged by this computation." |
| 1057 | TEST_P(MipmapTestES3, GenerateMipmapMaxLevel) |
| 1058 | { |
| 1059 | glBindTexture(GL_TEXTURE_2D, mTexture); |
| 1060 | |
| 1061 | // Fill level 0 with blue |
| 1062 | std::vector<GLColor> pixelsBlue(getWindowWidth() * getWindowHeight(), GLColor::blue); |
| 1063 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 1064 | GL_UNSIGNED_BYTE, pixelsBlue.data()); |
| 1065 | |
| 1066 | // Fill level 1 with red |
| 1067 | std::vector<GLColor> pixelsRed(getWindowWidth() * getWindowHeight() / 4, GLColor::red); |
| 1068 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth() / 2, getWindowHeight() / 2, 0, |
| 1069 | GL_RGBA, GL_UNSIGNED_BYTE, pixelsRed.data()); |
| 1070 | |
| 1071 | // Fill level 2 with green |
| 1072 | std::vector<GLColor> pixelsGreen(getWindowWidth() * getWindowHeight() / 16, GLColor::green); |
| 1073 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, getWindowWidth() / 4, getWindowHeight() / 4, 0, |
| 1074 | GL_RGBA, GL_UNSIGNED_BYTE, pixelsGreen.data()); |
| 1075 | |
| 1076 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 1077 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1078 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); |
| 1079 | |
| 1080 | EXPECT_GL_NO_ERROR(); |
| 1081 | |
| 1082 | // The green level 2 should be untouched by this since max level is 1. |
| 1083 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1084 | |
| 1085 | EXPECT_GL_NO_ERROR(); |
| 1086 | |
| 1087 | // Draw using level 1. It should be set to blue by GenerateMipmap. |
| 1088 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
| 1089 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
| 1090 | |
| 1091 | // Draw using level 2. It should still be green. |
| 1092 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2); |
| 1093 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
| 1094 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::green); |
| 1095 | } |
| 1096 | |
| 1097 | // Call GenerateMipmap with out-of-range base level. The spec is interpreted so that an out-of-range |
| 1098 | // base level does not have a color-renderable/texture-filterable internal format, so the |
| 1099 | // GenerateMipmap call generates INVALID_OPERATION. GLES 3.0.4 section 3.8.10: |
| 1100 | // "If the levelbase array was not specified with an unsized internal format from table 3.3 or a |
| 1101 | // sized internal format that is both color-renderable and texture-filterable according to table |
| 1102 | // 3.13, an INVALID_OPERATION error is generated." |
| 1103 | TEST_P(MipmapTestES3, GenerateMipmapBaseLevelOutOfRange) |
| 1104 | { |
| 1105 | glBindTexture(GL_TEXTURE_2D, mTexture); |
| 1106 | |
| 1107 | // Fill level 0 with blue |
| 1108 | std::vector<GLColor> pixelsBlue(getWindowWidth() * getWindowHeight(), GLColor::blue); |
| 1109 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 1110 | GL_UNSIGNED_BYTE, pixelsBlue.data()); |
| 1111 | |
| 1112 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1000); |
| 1113 | |
| 1114 | EXPECT_GL_NO_ERROR(); |
| 1115 | |
| 1116 | // Expecting the out-of-range base level to be treated as not color-renderable and |
| 1117 | // texture-filterable. |
| 1118 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1119 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1120 | |
| 1121 | // Draw using level 0. It should still be blue. |
| 1122 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
| 1123 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1124 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1125 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
| 1126 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
| 1127 | } |
| 1128 | |
| 1129 | // Call GenerateMipmap with out-of-range base level on an immutable texture. The base level should |
| 1130 | // be clamped, so the call doesn't generate an error. |
| 1131 | TEST_P(MipmapTestES3, GenerateMipmapBaseLevelOutOfRangeImmutableTexture) |
| 1132 | { |
| 1133 | glBindTexture(GL_TEXTURE_2D, mTexture); |
| 1134 | |
| 1135 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1); |
| 1136 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); |
| 1137 | |
| 1138 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1000); |
| 1139 | |
| 1140 | EXPECT_GL_NO_ERROR(); |
| 1141 | |
| 1142 | // This is essentially a no-op, since the texture only has one level. |
| 1143 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1144 | |
| 1145 | EXPECT_GL_NO_ERROR(); |
| 1146 | |
| 1147 | // The only level of the texture should still be green. |
| 1148 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1149 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1150 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
| 1151 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green); |
| 1152 | } |
| 1153 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1154 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 1155 | // Note: we run these tests against 9_3 on WARP due to hardware driver issues on Win7 |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1156 | ANGLE_INSTANTIATE_TEST(MipmapTest, |
| 1157 | ES2_D3D9(), |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 1158 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 1159 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 1160 | ES2_D3D11_FL9_3_WARP(), |
| 1161 | ES2_OPENGL(), |
| 1162 | ES3_OPENGL(), |
| 1163 | ES2_OPENGLES(), |
| 1164 | ES3_OPENGLES()); |
| 1165 | ANGLE_INSTANTIATE_TEST(MipmapTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |