@@ -1149,6 +1149,62 @@ TEST_P(MipmapTestES3, GenerateMipmapBaseLevel)
1149
1149
EXPECT_PIXEL_COLOR_EQ (getWindowWidth () / 2 , getWindowHeight () / 2 , GLColor::blue);
1150
1150
}
1151
1151
1152
+ // Test that generating mipmaps doesn't discard updates staged to out-of-range mips.
1153
+ TEST_P (MipmapTestES3, GenerateMipmapPreservesOutOfRangeMips)
1154
+ {
1155
+ // http://anglebug.com/4782
1156
+ ANGLE_SKIP_TEST_IF (IsOpenGL () && IsWindows () && (IsAMD () || IsIntel ()));
1157
+
1158
+ constexpr GLint kTextureSize = 16 ;
1159
+ const std::vector<GLColor> kLevel0Data (kTextureSize * kTextureSize , GLColor::red);
1160
+ const std::vector<GLColor> kLevel1Data (kTextureSize * kTextureSize , GLColor::green);
1161
+ const std::vector<GLColor> kLevel6Data (kTextureSize * kTextureSize , GLColor::blue);
1162
+
1163
+ // Initialize a 16x16 RGBA8 texture with red, green and blue for levels 0, 1 and 6 respectively.
1164
+ GLTexture tex;
1165
+ glBindTexture (GL_TEXTURE_2D, tex);
1166
+ glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA, kTextureSize , kTextureSize , 0 , GL_RGBA,
1167
+ GL_UNSIGNED_BYTE, kLevel0Data .data ());
1168
+ glTexImage2D (GL_TEXTURE_2D, 1 , GL_RGBA, kTextureSize , kTextureSize , 0 , GL_RGBA,
1169
+ GL_UNSIGNED_BYTE, kLevel1Data .data ());
1170
+ glTexImage2D (GL_TEXTURE_2D, 6 , GL_RGBA, kTextureSize , kTextureSize , 0 , GL_RGBA,
1171
+ GL_UNSIGNED_BYTE, kLevel6Data .data ());
1172
+ ASSERT_GL_NO_ERROR ();
1173
+
1174
+ // Set base level to 1, and generate mipmaps. Levels 1 through 5 will be green.
1175
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1 );
1176
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1177
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1178
+
1179
+ glGenerateMipmap (GL_TEXTURE_2D);
1180
+ ASSERT_GL_NO_ERROR ();
1181
+
1182
+ // Verify that the mips are all green.
1183
+ for (int mip = 0 ; mip < 5 ; ++mip)
1184
+ {
1185
+ int scale = 1 << mip;
1186
+ clearAndDrawQuad (m2DProgram, getWindowWidth () / scale, getWindowHeight () / scale);
1187
+ EXPECT_PIXEL_COLOR_EQ (getWindowWidth () / scale / 2 , getWindowHeight () / scale / 2 ,
1188
+ kLevel1Data [0 ]);
1189
+ }
1190
+
1191
+ // Verify that level 0 is red. TODO: setting MAX_LEVEL should be unnecessary, but is needed to
1192
+ // work around a bug in the Vulkan backend. http://anglebug.com/4780
1193
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0 );
1194
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0 );
1195
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1196
+
1197
+ clearAndDrawQuad (m2DProgram, getWindowWidth (), getWindowHeight ());
1198
+ EXPECT_PIXEL_COLOR_EQ (getWindowWidth () / 2 , getWindowHeight () / 2 , kLevel0Data [0 ]);
1199
+
1200
+ // Verify that level 6 is blue.
1201
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6 );
1202
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 6 );
1203
+
1204
+ clearAndDrawQuad (m2DProgram, getWindowWidth (), getWindowHeight ());
1205
+ EXPECT_PIXEL_COLOR_EQ (getWindowWidth () / 2 , getWindowHeight () / 2 , kLevel6Data [0 ]);
1206
+ }
1207
+
1152
1208
// Create a cube map with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays
1153
1209
// the same, and then sample levels 0 and 2.
1154
1210
// GLES 3.0.4 section 3.8.10:
0 commit comments