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 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 11 | class MipmapTest : public ANGLETest |
| 12 | { |
| 13 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | MipmapTest() |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 15 | : m2DProgram(0), |
| 16 | mCubeProgram(0), |
| 17 | mTexture2D(0), |
| 18 | mTextureCube(0), |
| 19 | mLevelZeroBlueInitData(nullptr), |
| 20 | mLevelZeroWhiteInitData(nullptr), |
| 21 | mLevelOneInitData(nullptr), |
| 22 | mLevelTwoInitData(nullptr), |
| 23 | mOffscreenFramebuffer(0) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 24 | { |
| 25 | setWindowWidth(128); |
| 26 | setWindowHeight(128); |
| 27 | setConfigRedBits(8); |
| 28 | setConfigGreenBits(8); |
| 29 | setConfigBlueBits(8); |
| 30 | setConfigAlphaBits(8); |
| 31 | } |
| 32 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 33 | void setUp2DProgram() |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 34 | { |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 35 | // Vertex Shader source |
| 36 | const std::string vs = SHADER_SOURCE |
| 37 | ( |
| 38 | attribute vec4 aPosition; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 39 | varying vec2 vTexCoord; |
| 40 | |
| 41 | void main() |
| 42 | { |
| 43 | gl_Position = aPosition; |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 44 | vTexCoord = (aPosition.xy * 0.5) + 0.5; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 45 | } |
| 46 | ); |
| 47 | |
| 48 | // Fragment Shader source |
| 49 | const std::string fs = SHADER_SOURCE |
| 50 | ( |
| 51 | precision mediump float; |
| 52 | |
| 53 | uniform sampler2D uTexture; |
| 54 | varying vec2 vTexCoord; |
| 55 | |
| 56 | void main() |
| 57 | { |
| 58 | gl_FragColor = texture2D(uTexture, vTexCoord); |
| 59 | } |
| 60 | ); |
| 61 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 62 | m2DProgram = CompileProgram(vs, fs); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 63 | ASSERT_NE(0u, m2DProgram); |
| 64 | } |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 65 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 66 | void setUpCubeProgram() |
| 67 | { |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 68 | // A simple vertex shader for the texture cube |
| 69 | const std::string cubeVS = SHADER_SOURCE |
| 70 | ( |
| 71 | attribute vec4 aPosition; |
| 72 | varying vec4 vPosition; |
| 73 | void main() |
| 74 | { |
| 75 | gl_Position = aPosition; |
| 76 | vPosition = aPosition; |
| 77 | } |
| 78 | ); |
| 79 | |
| 80 | // A very simple fragment shader to sample from the negative-Y face of a texture cube. |
| 81 | const std::string cubeFS = SHADER_SOURCE |
| 82 | ( |
| 83 | precision mediump float; |
| 84 | uniform samplerCube uTexture; |
| 85 | varying vec4 vPosition; |
| 86 | |
| 87 | void main() |
| 88 | { |
| 89 | gl_FragColor = textureCube(uTexture, vec3(vPosition.x, -1, vPosition.y)); |
| 90 | } |
| 91 | ); |
| 92 | |
| 93 | mCubeProgram = CompileProgram(cubeVS, cubeFS); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 94 | ASSERT_NE(0u, mCubeProgram); |
| 95 | } |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 96 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 97 | void SetUp() override |
| 98 | { |
| 99 | ANGLETest::SetUp(); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 100 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 101 | setUp2DProgram(); |
| 102 | |
| 103 | setUpCubeProgram(); |
Geoff Lang | 27359ff | 2015-06-02 15:42:04 -0400 | [diff] [blame] | 104 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 105 | mLevelZeroBlueInitData = createRGBInitData(getWindowWidth(), getWindowHeight(), 0, 0, 255); // Blue |
| 106 | mLevelZeroWhiteInitData = createRGBInitData(getWindowWidth(), getWindowHeight(), 255, 255, 255); // White |
| 107 | mLevelOneInitData = createRGBInitData((getWindowWidth() / 2), (getWindowHeight() / 2), 0, 255, 0); // Green |
| 108 | mLevelTwoInitData = createRGBInitData((getWindowWidth() / 4), (getWindowHeight() / 4), 255, 0, 0); // Red |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 109 | |
| 110 | glGenFramebuffers(1, &mOffscreenFramebuffer); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 111 | glGenTextures(1, &mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 112 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 113 | // Initialize the texture2D to be empty, and don't use mips. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 114 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 115 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 116 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 117 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 118 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 119 | // 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] | 120 | glGenTextures(1, &mTextureCube); |
| 121 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 122 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 123 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 124 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 125 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
| 126 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 127 | glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 128 | |
| 129 | // Complete the texture cube without mipmaps to start with. |
| 130 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 131 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 132 | |
| 133 | ASSERT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 136 | void TearDown() override |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 137 | { |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 138 | glDeleteProgram(m2DProgram); |
| 139 | glDeleteProgram(mCubeProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 140 | glDeleteFramebuffers(1, &mOffscreenFramebuffer); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 141 | glDeleteTextures(1, &mTexture2D); |
| 142 | glDeleteTextures(1, &mTextureCube); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 143 | |
Corentin Wallez | 254fcea | 2015-08-25 15:11:07 -0400 | [diff] [blame] | 144 | SafeDeleteArray(mLevelZeroBlueInitData); |
| 145 | SafeDeleteArray(mLevelZeroWhiteInitData); |
| 146 | SafeDeleteArray(mLevelOneInitData); |
| 147 | SafeDeleteArray(mLevelTwoInitData); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 148 | |
| 149 | ANGLETest::TearDown(); |
| 150 | } |
| 151 | |
| 152 | GLubyte *createRGBInitData(GLint width, GLint height, GLint r, GLint g, GLint b) |
| 153 | { |
| 154 | GLubyte *data = new GLubyte[3 * width * height]; |
| 155 | |
| 156 | for (int i = 0; i < width * height; i+=1) |
| 157 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 158 | data[3 * i + 0] = static_cast<GLubyte>(r); |
| 159 | data[3 * i + 1] = static_cast<GLubyte>(g); |
| 160 | data[3 * i + 2] = static_cast<GLubyte>(b); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | return data; |
| 164 | } |
| 165 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 166 | void clearAndDrawQuad(GLuint program, GLsizei viewportWidth, GLsizei viewportHeight) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 167 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 168 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 169 | glClear(GL_COLOR_BUFFER_BIT); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 170 | glViewport(0, 0, viewportWidth, viewportHeight); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 171 | ASSERT_GL_NO_ERROR(); |
| 172 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 173 | drawQuad(program, "aPosition", 0.0f); |
| 174 | } |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 175 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 176 | void clearTextureLevel0(GLenum textarget, |
| 177 | GLuint texture, |
| 178 | GLfloat red, |
| 179 | GLfloat green, |
| 180 | GLfloat blue, |
| 181 | GLfloat alpha) |
| 182 | { |
| 183 | glBindFramebuffer(GL_FRAMEBUFFER, mOffscreenFramebuffer); |
| 184 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textarget, texture, 0); |
| 185 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 186 | glClearColor(red, green, blue, alpha); |
| 187 | glClear(GL_COLOR_BUFFER_BIT); |
| 188 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 191 | GLuint m2DProgram; |
| 192 | GLuint mCubeProgram; |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 193 | GLuint mTexture2D; |
| 194 | GLuint mTextureCube; |
Geoff Lang | 27359ff | 2015-06-02 15:42:04 -0400 | [diff] [blame] | 195 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 196 | GLubyte* mLevelZeroBlueInitData; |
| 197 | GLubyte* mLevelZeroWhiteInitData; |
| 198 | GLubyte* mLevelOneInitData; |
| 199 | GLubyte* mLevelTwoInitData; |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 200 | |
| 201 | private: |
| 202 | GLuint mOffscreenFramebuffer; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 203 | }; |
| 204 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 205 | class MipmapTestES3 : public ANGLETest |
| 206 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 207 | protected: |
| 208 | MipmapTestES3() |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 209 | : mTextureArray(0), |
| 210 | mTexture3D(0), |
| 211 | mArrayProgram(0), |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 212 | mTextureArraySliceUniformLocation(-1), |
| 213 | m3DProgram(0), |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 214 | mTexture3DSliceUniformLocation(-1), |
| 215 | mTexture3DLODUniformLocation(-1) |
| 216 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 217 | { |
| 218 | setWindowWidth(128); |
| 219 | setWindowHeight(128); |
| 220 | setConfigRedBits(8); |
| 221 | setConfigGreenBits(8); |
| 222 | setConfigBlueBits(8); |
| 223 | setConfigAlphaBits(8); |
| 224 | } |
| 225 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 226 | std::string vertexShaderSource() |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 227 | { |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 228 | // Don't put "#version ..." on its own line. See [cpp]p1: |
| 229 | // "If there are sequences of preprocessing tokens within the list of arguments that |
| 230 | // would otherwise act as preprocessing directives, the behavior is undefined" |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 231 | // clang-format off |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 232 | return SHADER_SOURCE |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 233 | ( #version 300 es\n |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 234 | precision highp float; |
| 235 | in vec4 position; |
| 236 | out vec2 texcoord; |
| 237 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 238 | void main() |
| 239 | { |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 240 | gl_Position = vec4(position.xy, 0.0, 1.0); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 241 | texcoord = (position.xy * 0.5) + 0.5; |
| 242 | } |
| 243 | ); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 244 | // clang-format on |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 245 | } |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 246 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 247 | void setUpArrayProgram() |
| 248 | { |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 249 | const std::string fragmentShaderSourceArray = SHADER_SOURCE |
Austin Kinross | e8c8627 | 2015-01-15 18:55:36 -0800 | [diff] [blame] | 250 | ( #version 300 es\n |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 251 | precision highp float; |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 252 | uniform highp sampler2DArray tex; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 253 | uniform int slice; |
| 254 | in vec2 texcoord; |
| 255 | out vec4 out_FragColor; |
| 256 | |
| 257 | void main() |
| 258 | { |
| 259 | out_FragColor = texture(tex, vec3(texcoord, float(slice))); |
| 260 | } |
| 261 | ); |
| 262 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 263 | mArrayProgram = CompileProgram(vertexShaderSource(), fragmentShaderSourceArray); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 264 | if (mArrayProgram == 0) |
| 265 | { |
| 266 | FAIL() << "shader compilation failed."; |
| 267 | } |
| 268 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 269 | mTextureArraySliceUniformLocation = glGetUniformLocation(mArrayProgram, "slice"); |
| 270 | ASSERT_NE(-1, mTextureArraySliceUniformLocation); |
| 271 | |
| 272 | glUseProgram(mArrayProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 273 | glUseProgram(0); |
| 274 | ASSERT_GL_NO_ERROR(); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 275 | } |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 276 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 277 | void setUp3DProgram() |
| 278 | { |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 279 | const std::string fragmentShaderSource3D = SHADER_SOURCE |
| 280 | ( #version 300 es\n |
| 281 | precision highp float; |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 282 | uniform highp sampler3D tex; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 283 | uniform float slice; |
| 284 | uniform float lod; |
| 285 | in vec2 texcoord; |
| 286 | out vec4 out_FragColor; |
| 287 | |
| 288 | void main() |
| 289 | { |
| 290 | out_FragColor = textureLod(tex, vec3(texcoord, slice), lod); |
| 291 | } |
| 292 | ); |
| 293 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 294 | m3DProgram = CompileProgram(vertexShaderSource(), fragmentShaderSource3D); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 295 | if (m3DProgram == 0) |
| 296 | { |
| 297 | FAIL() << "shader compilation failed."; |
| 298 | } |
| 299 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 300 | mTexture3DSliceUniformLocation = glGetUniformLocation(m3DProgram, "slice"); |
| 301 | ASSERT_NE(-1, mTexture3DSliceUniformLocation); |
| 302 | |
| 303 | mTexture3DLODUniformLocation = glGetUniformLocation(m3DProgram, "lod"); |
| 304 | ASSERT_NE(-1, mTexture3DLODUniformLocation); |
| 305 | |
| 306 | glUseProgram(m3DProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 307 | glUniform1f(mTexture3DLODUniformLocation, 0); |
| 308 | glUseProgram(0); |
| 309 | ASSERT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 312 | void SetUp() override |
| 313 | { |
| 314 | ANGLETest::SetUp(); |
| 315 | |
| 316 | glGenTextures(1, &mTextureArray); |
| 317 | glGenTextures(1, &mTexture3D); |
| 318 | ASSERT_GL_NO_ERROR(); |
| 319 | |
| 320 | setUpArrayProgram(); |
| 321 | setUp3DProgram(); |
| 322 | } |
| 323 | |
| 324 | void TearDown() override |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 325 | { |
| 326 | glDeleteTextures(1, &mTextureArray); |
| 327 | glDeleteProgram(mArrayProgram); |
| 328 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 329 | glDeleteTextures(1, &mTexture3D); |
| 330 | glDeleteProgram(m3DProgram); |
| 331 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 332 | ANGLETest::TearDown(); |
| 333 | } |
| 334 | |
| 335 | GLuint mTextureArray; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 336 | GLuint mTexture3D; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 337 | |
| 338 | GLuint mArrayProgram; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 339 | GLint mTextureArraySliceUniformLocation; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 340 | |
| 341 | GLuint m3DProgram; |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 342 | GLint mTexture3DSliceUniformLocation; |
| 343 | GLint mTexture3DLODUniformLocation; |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | // 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. |
| 347 | // This ensures that renderers using the zero LOD workaround (e.g. D3D11 FL9_3) correctly pass init data to the mipmapped texture, |
| 348 | // even if the the zero-LOD texture is currently in use. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 349 | TEST_P(MipmapTest, DISABLED_ThreeLevelsInitData) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 350 | { |
| 351 | // Pass in level zero init data. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 352 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 353 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
| 354 | ASSERT_GL_NO_ERROR(); |
| 355 | |
| 356 | // Disable mips. |
| 357 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 358 | |
| 359 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 360 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 361 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 362 | |
| 363 | // Draw a half-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 364 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 365 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 366 | |
| 367 | // Draw a quarter-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 368 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 369 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 370 | |
| 371 | // Complete the texture by initializing the remaining levels. |
| 372 | int n = 1; |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 373 | while (getWindowWidth() / (1U << n) >= 1) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 374 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 375 | 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] | 376 | ASSERT_GL_NO_ERROR(); |
| 377 | n+=1; |
| 378 | } |
| 379 | |
| 380 | // Pass in level one init data. |
| 381 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, getWindowWidth() / 2, getWindowHeight() / 2, 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelOneInitData); |
| 382 | ASSERT_GL_NO_ERROR(); |
| 383 | |
| 384 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 385 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 386 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 387 | |
| 388 | // 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] | 389 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 390 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 391 | |
| 392 | // Enable mipmaps. |
| 393 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 394 | |
| 395 | // Draw a half-sized quad, and check it's green. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 396 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 397 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 398 | |
| 399 | // 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] | 400 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 401 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::black); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 402 | |
| 403 | // Pass in level two init data. |
| 404 | glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, getWindowWidth() / 4, getWindowHeight() / 4, 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelTwoInitData); |
| 405 | ASSERT_GL_NO_ERROR(); |
| 406 | |
| 407 | // Draw a full-sized quad, and check it's blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 408 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 409 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 410 | |
| 411 | // Draw a half-sized quad, and check it's green. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 412 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 413 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 414 | |
| 415 | // Draw a quarter-sized quad, and check it's red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 416 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 417 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 418 | |
| 419 | // Now disable mipmaps again, and render multiple sized quads. They should all be blue, since level 0 is blue. |
| 420 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 421 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 422 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 423 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 424 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 425 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 426 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 427 | |
| 428 | // Now reset level 0 to white, keeping mipmaps disabled. Then, render various sized quads. They should be white. |
| 429 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroWhiteInitData); |
| 430 | ASSERT_GL_NO_ERROR(); |
| 431 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 432 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 433 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 434 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 435 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 436 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 437 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::white); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 438 | |
| 439 | // Then enable mipmaps again. The quads should be white, green, red respectively. |
| 440 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 441 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 442 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 443 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::white); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 444 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 445 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::green); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 446 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 447 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | // This test generates (and uses) mipmaps on a texture using init data. D3D11 will use a non-renderable TextureStorage for this. |
| 451 | // The test then disables mips, renders to level zero of the texture, and reenables mips before using the texture again. |
| 452 | // To do this, D3D11 has to convert the TextureStorage into a renderable one. |
| 453 | // This test ensures that the conversion works correctly. |
| 454 | // 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] | 455 | TEST_P(MipmapTest, GenerateMipmapFromInitDataThenRender) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 456 | { |
| 457 | // Pass in initial data so the texture is blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 458 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 459 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, mLevelZeroBlueInitData); |
| 460 | |
| 461 | // Then generate the mips. |
| 462 | glGenerateMipmap(GL_TEXTURE_2D); |
| 463 | ASSERT_GL_NO_ERROR(); |
| 464 | |
| 465 | // Enable mipmaps. |
| 466 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 467 | |
| 468 | // Now draw the texture to various different sized areas. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 469 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 470 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 471 | |
| 472 | // Use mip level 1 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 473 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 474 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 475 | |
| 476 | // Use mip level 2 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 477 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 478 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 479 | |
| 480 | ASSERT_GL_NO_ERROR(); |
| 481 | |
| 482 | // Disable mips. Render a quad using the texture and ensure it's blue. |
| 483 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 484 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 485 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 486 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 487 | // Clear level 0 of the texture to red. |
| 488 | 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] | 489 | |
| 490 | // Reenable mips, and try rendering different-sized quads. |
| 491 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 492 | |
| 493 | // Level 0 is now red, so this should render red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 494 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 495 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 496 | |
| 497 | // Use mip level 1, blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 498 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 499 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 500 | |
| 501 | // Use mip level 2, blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 502 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 503 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // This test ensures that mips are correctly generated from a rendered image. |
| 507 | // In particular, on D3D11 Feature Level 9_3, the clear call will be performed on the zero-level texture, rather than the mipped one. |
| 508 | // 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] | 509 | TEST_P(MipmapTest, GenerateMipmapFromRenderedImage) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 510 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 511 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 512 | // Clear the texture to blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 513 | 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] | 514 | |
| 515 | // Then generate the mips |
| 516 | glGenerateMipmap(GL_TEXTURE_2D); |
| 517 | ASSERT_GL_NO_ERROR(); |
| 518 | |
| 519 | // Enable mips. |
| 520 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 521 | |
| 522 | // Now draw the texture to various different sized areas. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 523 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 524 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 525 | |
| 526 | // Use mip level 1 |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 527 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 2, getWindowHeight() / 2); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 528 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 4, getWindowHeight() / 4, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 529 | |
| 530 | // Use mip level 2 |
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::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | // Test to ensure that rendering to a mipmapped texture works, regardless of whether mipmaps are enabled or not. |
| 536 | // 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] | 537 | TEST_P(MipmapTest, RenderOntoLevelZeroAfterGenerateMipmap) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 538 | { |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 539 | // TODO(geofflang): Figure out why this is broken on AMD OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 540 | if ((IsAMD() || IsIntel()) && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 541 | { |
Geoff Lang | 35b08e3 | 2015-06-03 11:22:07 -0400 | [diff] [blame] | 542 | std::cout << "Test skipped on Intel/AMD OpenGL." << std::endl; |
Geoff Lang | f74fef5 | 2015-04-29 12:57:52 -0400 | [diff] [blame] | 543 | return; |
| 544 | } |
| 545 | |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 546 | glBindTexture(GL_TEXTURE_2D, mTexture2D); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 547 | |
| 548 | // Clear the texture to blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 549 | 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] | 550 | |
| 551 | // Now, draw the texture to a quad that's the same size as the texture. This draws to the default framebuffer. |
| 552 | // The quad should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 553 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 554 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 555 | |
| 556 | // Now go back to the texture, and generate mips on it. |
| 557 | glGenerateMipmap(GL_TEXTURE_2D); |
| 558 | ASSERT_GL_NO_ERROR(); |
| 559 | |
| 560 | // Now try rendering the textured quad again. Note: we've not told GL to use the generated mips. |
| 561 | // The quad should be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 562 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 563 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 564 | |
| 565 | // Now tell GL to use the generated mips. |
| 566 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
Corentin Wallez | 322653b | 2015-06-17 18:33:56 +0200 | [diff] [blame] | 567 | EXPECT_GL_NO_ERROR(); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 568 | |
| 569 | // Now render the textured quad again. It should be still be blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 570 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 571 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 572 | |
| 573 | // 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] | 574 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 575 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 576 | |
| 577 | // 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] | 578 | 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] | 579 | |
| 580 | // 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] | 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::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 583 | |
| 584 | // 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] | 585 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 586 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::blue); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 587 | |
| 588 | // Disable mipmaps again |
| 589 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 590 | ASSERT_GL_NO_ERROR(); |
| 591 | |
| 592 | // 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] | 593 | clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 594 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 595 | |
| 596 | // 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] | 597 | clearAndDrawQuad(m2DProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 598 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 8, getWindowHeight() / 8, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 601 | // This test ensures that the level-zero workaround for TextureCubes (on D3D11 Feature Level 9_3) |
| 602 | // 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] | 603 | TEST_P(MipmapTest, TextureCubeGeneralLevelZero) |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 604 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 605 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 606 | |
| 607 | // 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] | 608 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 609 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 610 | |
| 611 | // Generate mipmaps, and render. This should be blue. |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 612 | glGenerateMipmap(GL_TEXTURE_CUBE_MAP); |
| 613 | 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] | 614 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 615 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 616 | |
| 617 | // 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] | 618 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 619 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 620 | |
| 621 | // Now clear the negative-Y face of the cube to red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 622 | 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] | 623 | |
| 624 | // Draw using a full-size viewport. This should be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 625 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 626 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 627 | |
| 628 | // Draw using a quarter-size viewport, to force a lower LOD. This should be *BLUE*, since we only cleared level zero |
| 629 | // of the negative-Y face to red, and left its mipmaps blue. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 630 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 631 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 632 | |
| 633 | // Disable mipmaps again, and draw a to a quarter-size viewport. |
| 634 | // 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] | 635 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 636 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 637 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | // 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] | 641 | TEST_P(MipmapTest, TextureCubeRenderToLevelZero) |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 642 | { |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 643 | glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureCube); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 644 | |
| 645 | // 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] | 646 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 647 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 648 | |
| 649 | // Now clear the negative-Y face of the cube to red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 650 | 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] | 651 | |
| 652 | // Draw using a full-size viewport. This should be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 653 | clearAndDrawQuad(mCubeProgram, getWindowWidth(), getWindowHeight()); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 654 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 655 | |
| 656 | // Draw a to a quarter-size viewport. This should also be red. |
Olli Etuaho | b97a3e7 | 2016-04-13 14:31:52 +0300 | [diff] [blame] | 657 | clearAndDrawQuad(mCubeProgram, getWindowWidth() / 4, getWindowHeight() / 4); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 658 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
Austin Kinross | 62815bf | 2015-01-15 16:32:36 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 661 | // Creates a mipmapped 2D array texture with three layers, and calls ANGLE's GenerateMipmap. |
| 662 | // Then tests if the mipmaps are rendered correctly for all three layers. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 663 | TEST_P(MipmapTestES3, MipmapsForTextureArray) |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 664 | { |
| 665 | int px = getWindowWidth() / 2; |
| 666 | int py = getWindowHeight() / 2; |
| 667 | |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 668 | glBindTexture(GL_TEXTURE_2D_ARRAY, mTextureArray); |
| 669 | |
| 670 | glTexStorage3D(GL_TEXTURE_2D_ARRAY, 5, GL_RGBA8, 16, 16, 3); |
| 671 | |
| 672 | // Fill the first layer with red |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 673 | std::vector<GLColor> pixelsRed(16 * 16, GLColor::red); |
| 674 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 675 | pixelsRed.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 676 | |
| 677 | // Fill the second layer with green |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 678 | std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green); |
| 679 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 680 | pixelsGreen.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 681 | |
| 682 | // Fill the third layer with blue |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 683 | std::vector<GLColor> pixelsBlue(16 * 16, GLColor::blue); |
| 684 | glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 685 | pixelsBlue.data()); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 686 | |
| 687 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 688 | glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 689 | |
| 690 | EXPECT_GL_NO_ERROR(); |
| 691 | |
| 692 | glGenerateMipmap(GL_TEXTURE_2D_ARRAY); |
| 693 | |
| 694 | EXPECT_GL_NO_ERROR(); |
| 695 | |
| 696 | glUseProgram(mArrayProgram); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 697 | |
| 698 | EXPECT_GL_NO_ERROR(); |
| 699 | |
| 700 | // Draw the first slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 701 | glUniform1i(mTextureArraySliceUniformLocation, 0); |
| 702 | drawQuad(mArrayProgram, "position", 0.5f); |
| 703 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 704 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 705 | |
| 706 | // Draw the second slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 707 | glUniform1i(mTextureArraySliceUniformLocation, 1); |
| 708 | drawQuad(mArrayProgram, "position", 0.5f); |
| 709 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 710 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green); |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 711 | |
| 712 | // Draw the third slice |
Austin Kinross | 215b37a | 2014-12-22 12:56:07 -0800 | [diff] [blame] | 713 | glUniform1i(mTextureArraySliceUniformLocation, 2); |
| 714 | drawQuad(mArrayProgram, "position", 0.5f); |
| 715 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 716 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::blue); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | // Creates a mipmapped 3D texture with two layers, and calls ANGLE's GenerateMipmap. |
| 720 | // Then tests if the mipmaps are rendered correctly for all two layers. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 721 | TEST_P(MipmapTestES3, MipmapsForTexture3D) |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 722 | { |
| 723 | int px = getWindowWidth() / 2; |
| 724 | int py = getWindowHeight() / 2; |
| 725 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 726 | glBindTexture(GL_TEXTURE_3D, mTexture3D); |
| 727 | |
| 728 | glTexStorage3D(GL_TEXTURE_3D, 5, GL_RGBA8, 16, 16, 2); |
| 729 | |
| 730 | // Fill the first layer with red |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 731 | std::vector<GLColor> pixelsRed(16 * 16, GLColor::red); |
| 732 | glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 733 | pixelsRed.data()); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 734 | |
| 735 | // Fill the second layer with green |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 736 | std::vector<GLColor> pixelsGreen(16 * 16, GLColor::green); |
| 737 | glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 1, 16, 16, 1, GL_RGBA, GL_UNSIGNED_BYTE, |
| 738 | pixelsGreen.data()); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 739 | |
| 740 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 741 | glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 742 | |
| 743 | EXPECT_GL_NO_ERROR(); |
| 744 | |
| 745 | glGenerateMipmap(GL_TEXTURE_3D); |
| 746 | |
| 747 | EXPECT_GL_NO_ERROR(); |
| 748 | |
| 749 | glUseProgram(m3DProgram); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 750 | |
| 751 | EXPECT_GL_NO_ERROR(); |
| 752 | |
| 753 | // Mipmap level 0 |
| 754 | // Draw the first slice |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 755 | glUniform1f(mTexture3DLODUniformLocation, 0.); |
| 756 | glUniform1f(mTexture3DSliceUniformLocation, 0.25f); |
| 757 | drawQuad(m3DProgram, "position", 0.5f); |
| 758 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 759 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::red); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 760 | |
| 761 | // Draw the second slice |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 762 | glUniform1f(mTexture3DSliceUniformLocation, 0.75f); |
| 763 | drawQuad(m3DProgram, "position", 0.5f); |
| 764 | EXPECT_GL_NO_ERROR(); |
Olli Etuaho | 190028d | 2016-05-13 12:11:29 +0300 | [diff] [blame^] | 765 | EXPECT_PIXEL_COLOR_EQ(px, py, GLColor::green); |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 766 | |
| 767 | // Mipmap level 1 |
| 768 | // The second mipmap should only have one slice. |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 769 | glUniform1f(mTexture3DLODUniformLocation, 1.); |
| 770 | drawQuad(m3DProgram, "position", 0.5f); |
| 771 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 772 | 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] | 773 | |
Gregoire Payen de La Garanderie | 32334af | 2015-01-30 11:38:21 +0000 | [diff] [blame] | 774 | glUniform1f(mTexture3DSliceUniformLocation, 0.75f); |
| 775 | drawQuad(m3DProgram, "position", 0.5f); |
| 776 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 777 | 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] | 778 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 779 | |
| 780 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 781 | // 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] | 782 | ANGLE_INSTANTIATE_TEST(MipmapTest, |
| 783 | ES2_D3D9(), |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 784 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 785 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 786 | ES2_D3D11_FL9_3_WARP(), |
| 787 | ES2_OPENGL(), |
| 788 | ES3_OPENGL(), |
| 789 | ES2_OPENGLES(), |
| 790 | ES3_OPENGLES()); |
| 791 | ANGLE_INSTANTIATE_TEST(MipmapTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |