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