1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program OpenGL ES Utilities 3 * ------------------------------------------------ 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief OpenGL State Reset. 22 *//*--------------------------------------------------------------------*/ 23 24 #include "gluStateReset.hpp" 25 #include "gluContextInfo.hpp" 26 #include "gluRenderContext.hpp" 27 #include "tcuRenderTarget.hpp" 28 #include "glwFunctions.hpp" 29 #include "glwEnums.hpp" 30 #include "deUniquePtr.hpp" 31 32 namespace glu 33 { 34 namespace 35 { 36 enum 37 { 38 MAX_ERROR_COUNT = 10 39 }; 40 41 void resetErrors (const glw::Functions& gl) 42 { 43 size_t errorNdx = 0; 44 45 for (errorNdx = 0; errorNdx < MAX_ERROR_COUNT; errorNdx++) 46 { 47 if (gl.getError() == GL_NONE) 48 break; 49 } 50 51 if (errorNdx == MAX_ERROR_COUNT) 52 TCU_FAIL("Couldn't reset error state"); 53 } 54 55 } 56 57 void resetStateES (const RenderContext& renderCtx, const ContextInfo& ctxInfo) 58 { 59 const glw::Functions& gl = renderCtx.getFunctions(); 60 const ContextType type = renderCtx.getType(); 61 62 // Reset error state 63 resetErrors(gl); 64 65 DE_ASSERT(isContextTypeES(type)); 66 67 // Vertex attrib array state. 68 { 69 int numVertexAttribArrays = 0; 70 gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays); 71 72 gl.bindBuffer (GL_ARRAY_BUFFER, 0); 73 gl.bindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); 74 75 if (contextSupports(type, ApiType::es(3,0))) 76 { 77 gl.bindVertexArray (0); 78 gl.disable (GL_PRIMITIVE_RESTART_FIXED_INDEX); 79 } 80 81 if (contextSupports(type, ApiType::es(3,1))) 82 gl.bindBuffer(GL_DRAW_INDIRECT_BUFFER, 0); 83 84 for (int ndx = 0; ndx < numVertexAttribArrays; ndx++) 85 { 86 gl.disableVertexAttribArray (ndx); 87 gl.vertexAttribPointer (ndx, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL); 88 89 if (contextSupports(type, ApiType::es(3,0))) 90 gl.vertexAttribDivisor(ndx, 0); 91 } 92 93 GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex attrib array state reset failed"); 94 } 95 96 // Transformation state. 97 { 98 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget(); 99 100 gl.viewport (0, 0, renderTarget.getWidth(), renderTarget.getHeight()); 101 gl.depthRangef (0.0f, 1.0f); 102 103 if (contextSupports(type, ApiType::es(3,0))) 104 gl.bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); 105 106 GLU_EXPECT_NO_ERROR(gl.getError(), "Transformation state reset failed"); 107 } 108 109 // Rasterization state 110 { 111 gl.lineWidth (1.0f); 112 gl.disable (GL_CULL_FACE); 113 gl.cullFace (GL_BACK); 114 gl.frontFace (GL_CCW); 115 gl.polygonOffset(0.0f, 0.0f); 116 gl.disable (GL_POLYGON_OFFSET_FILL); 117 118 if (contextSupports(type, ApiType::es(3,0))) 119 gl.disable(GL_RASTERIZER_DISCARD); 120 121 GLU_EXPECT_NO_ERROR(gl.getError(), "Rasterization state reset failed"); 122 } 123 124 // Multisampling state 125 { 126 gl.disable (GL_SAMPLE_ALPHA_TO_COVERAGE); 127 gl.disable (GL_SAMPLE_COVERAGE); 128 gl.sampleCoverage (1.0f, GL_FALSE); 129 130 if (contextSupports(type, ApiType::es(3,1))) 131 { 132 int numSampleMaskWords = 0; 133 gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &numSampleMaskWords); 134 135 gl.disable(GL_SAMPLE_MASK); 136 137 for (int ndx = 0; ndx < numSampleMaskWords; ndx++) 138 gl.sampleMaski(ndx, ~0u); 139 } 140 141 GLU_EXPECT_NO_ERROR(gl.getError(), "Multisampling state reset failed"); 142 } 143 144 // Texture state. 145 // \todo [2013-04-08 pyry] Reset all levels? 146 { 147 const float borderColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; 148 int numTexUnits = 0; 149 gl.getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numTexUnits); 150 151 for (int ndx = 0; ndx < numTexUnits; ndx++) 152 { 153 gl.activeTexture(GL_TEXTURE0 + ndx); 154 155 // Reset 2D texture. 156 gl.bindTexture(GL_TEXTURE_2D, 0); 157 gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 158 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 159 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 160 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 161 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 162 163 if (contextSupports(type, ApiType::es(3,0))) 164 { 165 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); 166 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 167 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 168 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 169 gl.texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000.0f); 170 gl.texParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000.0f); 171 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 172 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); 173 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 174 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 175 } 176 177 if (contextSupports(type, ApiType::es(3,1))) 178 gl.texParameteri(GL_TEXTURE_2D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); 179 180 if (ctxInfo.isExtensionSupported("GL_EXT_texture_border_clamp")) 181 gl.texParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 182 183 // Reset cube map texture. 184 gl.bindTexture(GL_TEXTURE_CUBE_MAP, 0); 185 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 186 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 187 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 188 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 189 gl.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 190 gl.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 191 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 192 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 193 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); 194 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); 195 196 if (contextSupports(type, ApiType::es(3,0))) 197 { 198 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_R, GL_RED); 199 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 200 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 201 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 202 gl.texParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_LOD, -1000.0f); 203 gl.texParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LOD, 1000.0f); 204 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0); 205 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 1000); 206 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_NONE); 207 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 208 } 209 210 if (contextSupports(type, ApiType::es(3,1))) 211 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); 212 213 if (ctxInfo.isExtensionSupported("GL_EXT_texture_border_clamp")) 214 gl.texParameterfv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 215 216 if (contextSupports(type, ApiType::es(3,0))) 217 { 218 // Reset 2D array texture. 219 gl.bindTexture(GL_TEXTURE_2D_ARRAY, 0); 220 gl.texImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 221 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 222 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 223 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); 224 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); 225 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); 226 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 227 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 228 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 229 gl.texParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f); 230 gl.texParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f); 231 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); 232 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000); 233 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE); 234 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 235 236 if (ctxInfo.isExtensionSupported("GL_EXT_texture_border_clamp")) 237 gl.texParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 238 } 239 240 if (contextSupports(type, ApiType::es(3,1))) 241 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); 242 243 if (contextSupports(type, ApiType::es(3,0))) 244 { 245 // Reset 3D texture. 246 gl.bindTexture(GL_TEXTURE_3D, 0); 247 gl.texImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 248 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 249 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 250 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); 251 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); 252 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); 253 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED); 254 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 255 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 256 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 257 gl.texParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_LOD, -1000.0f); 258 gl.texParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAX_LOD, 1000.0f); 259 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); 260 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1000); 261 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 262 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 263 264 if (ctxInfo.isExtensionSupported("GL_EXT_texture_border_clamp")) 265 gl.texParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 266 } 267 268 if (contextSupports(type, ApiType::es(3,1))) 269 gl.texParameteri(GL_TEXTURE_3D, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT); 270 271 if (contextSupports(type, ApiType::es(3,1))) 272 { 273 // Reset multisample textures. 274 gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); 275 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_R, GL_RED); 276 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 277 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 278 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 279 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BASE_LEVEL, 0); 280 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAX_LEVEL, 1000); 281 } 282 283 if (ctxInfo.isExtensionSupported("GL_OES_texture_storage_multisample_2d_array")) 284 { 285 gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0); 286 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); 287 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 288 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 289 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 290 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); 291 gl.texParameteri(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000); 292 } 293 294 if (ctxInfo.isExtensionSupported("GL_EXT_texture_cube_map_array")) 295 { 296 // Reset cube array texture. 297 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0); 298 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 299 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 300 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); 301 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); 302 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); 303 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 304 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 305 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 306 gl.texParameterf(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f); 307 gl.texParameterf(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f); 308 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); 309 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000); 310 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE); 311 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 312 313 if (ctxInfo.isExtensionSupported("GL_EXT_texture_border_clamp")) 314 gl.texParameterfv(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 315 } 316 } 317 318 gl.activeTexture(GL_TEXTURE0); 319 320 if (contextSupports(type, ApiType::es(3,0))) 321 { 322 for (int ndx = 0; ndx < numTexUnits; ndx++) 323 gl.bindSampler(ndx, 0); 324 } 325 326 GLU_EXPECT_NO_ERROR(gl.getError(), "Texture state reset failed"); 327 } 328 329 // Resetting state using non-indexed variants should be enough, but some 330 // implementations have bugs so we need to make sure indexed state gets 331 // set back to initial values. 332 if (ctxInfo.isExtensionSupported("GL_EXT_draw_buffers_indexed")) 333 { 334 int numDrawBuffers = 0; 335 336 gl.getIntegerv(GL_MAX_DRAW_BUFFERS, &numDrawBuffers); 337 338 for (int drawBufferNdx = 0; drawBufferNdx < numDrawBuffers; drawBufferNdx++) 339 { 340 gl.disablei (GL_BLEND, drawBufferNdx); 341 gl.blendFunci (drawBufferNdx, GL_ONE, GL_ZERO); 342 gl.blendEquationi (drawBufferNdx, GL_FUNC_ADD); 343 gl.colorMaski (drawBufferNdx, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 344 } 345 346 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to reset indexed draw buffer state"); 347 } 348 349 // Pixel operations. 350 { 351 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget(); 352 353 gl.disable (GL_SCISSOR_TEST); 354 gl.scissor (0, 0, renderTarget.getWidth(), renderTarget.getHeight()); 355 356 gl.disable (GL_STENCIL_TEST); 357 gl.stencilFunc (GL_ALWAYS, 0, ~0u); 358 gl.stencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 359 360 gl.disable (GL_DEPTH_TEST); 361 gl.depthFunc (GL_LESS); 362 363 gl.disable (GL_BLEND); 364 gl.blendFunc (GL_ONE, GL_ZERO); 365 gl.blendEquation(GL_FUNC_ADD); 366 gl.blendColor (0.0f, 0.0f, 0.0f, 0.0f); 367 368 gl.enable (GL_DITHER); 369 370 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel operation state reset failed"); 371 } 372 373 // Framebuffer control. 374 { 375 gl.colorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 376 gl.depthMask (GL_TRUE); 377 gl.stencilMask (~0u); 378 379 gl.clearColor (0.0f, 0.0f, 0.0f, 0.0f); 380 gl.clearDepthf (1.0f); 381 gl.clearStencil (0); 382 383 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer control state reset failed"); 384 } 385 386 // Framebuffer state. 387 { 388 // \note Actually spec explictly says 0 but on some platforms (iOS) no default framebuffer exists. 389 const deUint32 defaultFbo = renderCtx.getDefaultFramebuffer(); 390 const deUint32 drawBuffer = defaultFbo != 0 ? GL_COLOR_ATTACHMENT0 : GL_BACK; 391 const deUint32 readBuffer = defaultFbo != 0 ? GL_COLOR_ATTACHMENT0 : GL_BACK; 392 393 gl.bindFramebuffer(GL_FRAMEBUFFER, defaultFbo); 394 395 if (contextSupports(type, ApiType::es(3,0))) 396 { 397 gl.drawBuffers (1, &drawBuffer); 398 gl.readBuffer (readBuffer); 399 } 400 401 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer state reset failed"); 402 } 403 404 // Renderbuffer state. 405 { 406 gl.bindRenderbuffer(GL_RENDERBUFFER, 0); 407 GLU_EXPECT_NO_ERROR(gl.getError(), "Renderbuffer state reset failed"); 408 } 409 410 // Pixel transfer state. 411 { 412 gl.pixelStorei(GL_UNPACK_ALIGNMENT, 4); 413 gl.pixelStorei(GL_PACK_ALIGNMENT, 4); 414 415 if (contextSupports(type, ApiType::es(3,0))) 416 { 417 gl.pixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); 418 gl.pixelStorei(GL_UNPACK_SKIP_IMAGES, 0); 419 gl.pixelStorei(GL_UNPACK_ROW_LENGTH, 0); 420 gl.pixelStorei(GL_UNPACK_SKIP_ROWS, 0); 421 gl.pixelStorei(GL_UNPACK_SKIP_PIXELS, 0); 422 423 gl.pixelStorei(GL_PACK_ROW_LENGTH, 0); 424 gl.pixelStorei(GL_PACK_SKIP_ROWS, 0); 425 gl.pixelStorei(GL_PACK_SKIP_PIXELS, 0); 426 427 gl.bindBuffer(GL_PIXEL_PACK_BUFFER, 0); 428 gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 429 } 430 431 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel transfer state reset failed"); 432 } 433 434 // Program object state. 435 { 436 gl.useProgram(0); 437 438 if (contextSupports(type, ApiType::es(3,0))) 439 { 440 int maxUniformBufferBindings = 0; 441 gl.getIntegerv (GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings); 442 gl.bindBuffer (GL_UNIFORM_BUFFER, 0); 443 444 for (int ndx = 0; ndx < maxUniformBufferBindings; ndx++) 445 gl.bindBufferBase(GL_UNIFORM_BUFFER, ndx, 0); 446 } 447 448 if (contextSupports(type, ApiType::es(3,1))) 449 { 450 gl.bindProgramPipeline(0); 451 452 { 453 int maxAtomicCounterBufferBindings = 0; 454 gl.getIntegerv (GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &maxAtomicCounterBufferBindings); 455 gl.bindBuffer (GL_ATOMIC_COUNTER_BUFFER, 0); 456 457 for (int ndx = 0; ndx < maxAtomicCounterBufferBindings; ndx++) 458 gl.bindBufferBase(GL_ATOMIC_COUNTER_BUFFER, ndx, 0); 459 } 460 461 { 462 int maxShaderStorageBufferBindings = 0; 463 gl.getIntegerv (GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &maxShaderStorageBufferBindings); 464 gl.bindBuffer (GL_SHADER_STORAGE_BUFFER, 0); 465 466 for (int ndx = 0; ndx < maxShaderStorageBufferBindings; ndx++) 467 gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, ndx, 0); 468 } 469 } 470 471 GLU_EXPECT_NO_ERROR(gl.getError(), "Program object state reset failed"); 472 } 473 474 // Vertex shader state. 475 { 476 int numVertexAttribArrays = 0; 477 gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays); 478 479 for (int ndx = 0; ndx < numVertexAttribArrays; ndx++) 480 gl.vertexAttrib4f(ndx, 0.0f, 0.0f, 0.0f, 1.0f); 481 482 GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex shader state reset failed"); 483 } 484 485 // Transform feedback state. 486 if (contextSupports(type, ApiType::es(3,0))) 487 { 488 int numTransformFeedbackSeparateAttribs = 0; 489 glw::GLboolean transformFeedbackActive = 0; 490 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &numTransformFeedbackSeparateAttribs); 491 gl.getBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE, &transformFeedbackActive); 492 493 if (transformFeedbackActive) 494 gl.endTransformFeedback(); 495 496 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0); 497 498 for (int ndx = 0; ndx < numTransformFeedbackSeparateAttribs; ndx++) 499 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ndx, 0); 500 501 GLU_EXPECT_NO_ERROR(gl.getError(), "Transform feedback state reset failed"); 502 } 503 504 // Asynchronous query state. 505 if (contextSupports(type, ApiType::es(3,0))) 506 { 507 static const deUint32 targets[] = { GL_ANY_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN }; 508 509 for (int i = 0; i < DE_LENGTH_OF_ARRAY(targets); i++) 510 { 511 int queryActive = 0; 512 gl.getQueryiv(targets[i], GL_CURRENT_QUERY, &queryActive); 513 514 if (queryActive != 0) 515 gl.endQuery(targets[i]); 516 } 517 518 GLU_EXPECT_NO_ERROR(gl.getError(), "Asynchronous query state reset failed"); 519 } 520 521 // Hints. 522 { 523 gl.hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); 524 525 if (contextSupports(type, ApiType::es(3,0))) 526 gl.hint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_DONT_CARE); 527 528 GLU_EXPECT_NO_ERROR(gl.getError(), "Hints reset failed"); 529 } 530 531 // Compute. 532 if (contextSupports(type, ApiType::es(3,1))) 533 { 534 gl.bindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0); 535 GLU_EXPECT_NO_ERROR(gl.getError(), "Compute dispatch state reset failed"); 536 } 537 538 // Buffer copy state. 539 if (contextSupports(type, ApiType::es(3,0))) 540 { 541 gl.bindBuffer(GL_COPY_READ_BUFFER, 0); 542 gl.bindBuffer(GL_COPY_WRITE_BUFFER, 0); 543 544 GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer copy state reset failed"); 545 } 546 547 // Images. 548 if (contextSupports(type, ApiType::es(3,1))) 549 { 550 int numImageUnits = 0; 551 gl.getIntegerv(GL_MAX_IMAGE_UNITS, &numImageUnits); 552 553 for (int ndx = 0; ndx < numImageUnits; ndx++) 554 gl.bindImageTexture(ndx, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI); 555 556 GLU_EXPECT_NO_ERROR(gl.getError(), "Image state reset failed"); 557 } 558 559 // Sample shading state. 560 if (contextSupports(type, ApiType::es(3,1)) && ctxInfo.isExtensionSupported("GL_OES_sample_shading")) 561 { 562 gl.minSampleShading(0.0f); 563 gl.disable(GL_SAMPLE_SHADING); 564 565 GLU_EXPECT_NO_ERROR(gl.getError(), "Sample shading state reset failed"); 566 } 567 568 // Debug state 569 if (ctxInfo.isExtensionSupported("GL_KHR_debug")) 570 { 571 const bool entrypointsPresent = gl.debugMessageControl != DE_NULL && 572 gl.debugMessageCallback != DE_NULL && 573 gl.popDebugGroup != DE_NULL; 574 575 // some drivers advertise GL_KHR_debug but give out null pointers. Silently ignore. 576 if (entrypointsPresent) 577 { 578 int stackDepth = 0; 579 gl.getIntegerv(GL_DEBUG_GROUP_STACK_DEPTH, &stackDepth); 580 for (int ndx = 1; ndx < stackDepth; ++ndx) 581 gl.popDebugGroup(); 582 583 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, DE_NULL, true); 584 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, DE_NULL, false); 585 gl.debugMessageCallback(DE_NULL, DE_NULL); 586 587 if (type.getFlags() & glu::CONTEXT_DEBUG) 588 gl.enable(GL_DEBUG_OUTPUT); 589 else 590 gl.disable(GL_DEBUG_OUTPUT); 591 gl.disable(GL_DEBUG_OUTPUT_SYNCHRONOUS); 592 593 GLU_EXPECT_NO_ERROR(gl.getError(), "Debug state reset failed"); 594 } 595 } 596 597 // Primitive bounding box state. 598 if (ctxInfo.isExtensionSupported("GL_EXT_primitive_bounding_box")) 599 { 600 gl.primitiveBoundingBox(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); 601 GLU_EXPECT_NO_ERROR(gl.getError(), "Primitive bounding box state reset failed"); 602 } 603 604 // Tessellation state 605 if (ctxInfo.isExtensionSupported("GL_EXT_tessellation_shader")) 606 { 607 gl.patchParameteri(GL_PATCH_VERTICES, 3); 608 GLU_EXPECT_NO_ERROR(gl.getError(), "Tessellation patch vertices state reset failed"); 609 } 610 611 // Advanced coherent blending 612 if (ctxInfo.isExtensionSupported("GL_KHR_blend_equation_advanced_coherent")) 613 { 614 gl.enable(GL_BLEND_ADVANCED_COHERENT_KHR); 615 GLU_EXPECT_NO_ERROR(gl.getError(), "Blend equation advanced coherent state reset failed"); 616 } 617 618 // Texture buffer 619 if (ctxInfo.isExtensionSupported("GL_EXT_texture_buffer")) 620 { 621 gl.bindTexture(GL_TEXTURE_BUFFER, 0); 622 gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 623 GLU_EXPECT_NO_ERROR(gl.getError(), "Texture buffer state reset failed"); 624 } 625 } 626 627 void resetStateGLCore (const RenderContext& renderCtx, const ContextInfo& ctxInfo) 628 { 629 const glw::Functions& gl = renderCtx.getFunctions(); 630 const ContextType type = renderCtx.getType(); 631 632 // Reset error state 633 resetErrors(gl); 634 635 // Vertex attrib array state. 636 { 637 gl.bindVertexArray (0); 638 gl.bindBuffer (GL_ARRAY_BUFFER, 0); 639 gl.bindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); 640 641 if (contextSupports(type, ApiType::core(3,1))) 642 { 643 gl.disable (GL_PRIMITIVE_RESTART); 644 gl.primitiveRestartIndex(0); 645 } 646 647 GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex attrib array state reset failed"); 648 } 649 650 // Transformation state. 651 { 652 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget(); 653 int numUserClipPlanes = 0; 654 655 gl.getIntegerv(GL_MAX_CLIP_DISTANCES, &numUserClipPlanes); 656 657 gl.viewport (0, 0, renderTarget.getWidth(), renderTarget.getHeight()); 658 gl.depthRange (0.0, 1.0); 659 660 for (int ndx = 0; ndx < numUserClipPlanes; ndx++) 661 gl.disable(GL_CLIP_DISTANCE0+ndx); 662 663 if (contextSupports(type, ApiType::core(3,2))) 664 gl.disable(GL_DEPTH_CLAMP); 665 666 //gl.bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); 667 668 GLU_EXPECT_NO_ERROR(gl.getError(), "Transformation state reset failed"); 669 } 670 671 // Coloring 672 { 673 gl.clampColor(GL_CLAMP_READ_COLOR, GL_FIXED_ONLY); 674 675 if (contextSupports(type, ApiType::core(3,2))) 676 gl.provokingVertex(GL_LAST_VERTEX_CONVENTION); 677 678 GLU_EXPECT_NO_ERROR(gl.getError(), "Coloring state reset failed"); 679 } 680 681 // Rasterization state 682 { 683 gl.disable (GL_RASTERIZER_DISCARD); 684 gl.pointSize (1.0f); 685 gl.pointParameterf (GL_POINT_FADE_THRESHOLD_SIZE, 1.0f); 686 gl.pointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT); 687 gl.lineWidth (1.0f); 688 gl.disable (GL_LINE_SMOOTH); 689 gl.disable (GL_CULL_FACE); 690 gl.cullFace (GL_BACK); 691 gl.frontFace (GL_CCW); 692 gl.disable (GL_POLYGON_SMOOTH); 693 gl.polygonOffset (0.0f, 0.0f); 694 gl.disable (GL_POLYGON_OFFSET_POINT); 695 gl.disable (GL_POLYGON_OFFSET_LINE); 696 gl.disable (GL_POLYGON_OFFSET_FILL); 697 698 GLU_EXPECT_NO_ERROR(gl.getError(), "Rasterization state reset failed"); 699 } 700 701 // Multisampling state 702 { 703 gl.enable (GL_MULTISAMPLE); 704 gl.disable (GL_SAMPLE_ALPHA_TO_COVERAGE); 705 gl.disable (GL_SAMPLE_ALPHA_TO_ONE); 706 gl.disable (GL_SAMPLE_COVERAGE); 707 gl.sampleCoverage (1.0f, GL_FALSE); 708 709 if (contextSupports(type, ApiType::core(3,2))) 710 { 711 int numSampleMaskWords = 0; 712 gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &numSampleMaskWords); 713 714 gl.disable(GL_SAMPLE_MASK); 715 716 for (int ndx = 0; ndx < numSampleMaskWords; ndx++) 717 gl.sampleMaski(ndx, ~0u); 718 } 719 720 GLU_EXPECT_NO_ERROR(gl.getError(), "Multisampling state reset failed"); 721 } 722 723 // Texture state. 724 // \todo [2013-04-08 pyry] Reset all levels? 725 { 726 const float borderColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; 727 int numTexUnits = 0; 728 gl.getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numTexUnits); 729 730 gl.bindBuffer(GL_TEXTURE_BUFFER, 0); 731 732 for (int ndx = 0; ndx < numTexUnits; ndx++) 733 { 734 gl.activeTexture(GL_TEXTURE0 + ndx); 735 736 // Reset 1D texture. 737 gl.bindTexture (GL_TEXTURE_1D, 0); 738 gl.texImage1D (GL_TEXTURE_1D, 0, GL_RGBA, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 739 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 740 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 741 gl.texParameterfv (GL_TEXTURE_1D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 742 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); 743 gl.texParameterf (GL_TEXTURE_1D, GL_TEXTURE_MIN_LOD, -1000.0f); 744 gl.texParameterf (GL_TEXTURE_1D, GL_TEXTURE_MAX_LOD, 1000.0f); 745 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_BASE_LEVEL, 0); 746 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL, 1000); 747 gl.texParameterf (GL_TEXTURE_1D, GL_TEXTURE_LOD_BIAS, 0.0f); 748 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 749 gl.texParameteri (GL_TEXTURE_1D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 750 751 if (contextSupports(type, ApiType::core(3,3))) 752 { 753 gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_R, GL_RED); 754 gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 755 gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 756 gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 757 } 758 759 // Reset 2D texture. 760 gl.bindTexture (GL_TEXTURE_2D, 0); 761 gl.texImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 762 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 763 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 764 gl.texParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 765 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 766 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 767 gl.texParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000.0f); 768 gl.texParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000.0f); 769 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 770 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); 771 gl.texParameterf (GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0.0f); 772 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 773 gl.texParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 774 775 if (contextSupports(type, ApiType::core(3,3))) 776 { 777 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED); 778 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 779 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 780 gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 781 } 782 783 // Reset cube map texture. 784 gl.bindTexture (GL_TEXTURE_CUBE_MAP, 0); 785 gl.texImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 786 gl.texImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 787 gl.texImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 788 gl.texImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 789 gl.texImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 790 gl.texImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 791 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 792 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 793 gl.texParameterfv (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 794 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT); 795 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT); 796 gl.texParameterf (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_LOD, -1000.0f); 797 gl.texParameterf (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LOD, 1000.0f); 798 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0); 799 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 1000); 800 gl.texParameterf (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_LOD_BIAS, 0.0f); 801 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_NONE); 802 gl.texParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 803 804 if (contextSupports(type, ApiType::core(3,3))) 805 { 806 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_R, GL_RED); 807 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 808 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 809 gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 810 } 811 812 // Reset 1D array texture. 813 gl.bindTexture (GL_TEXTURE_1D_ARRAY, 0); 814 gl.texImage2D (GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 815 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 816 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 817 gl.texParameterfv (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 818 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); 819 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f); 820 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f); 821 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); 822 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000); 823 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_LOD_BIAS, 0.0f); 824 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE); 825 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 826 827 if (contextSupports(type, ApiType::core(3,3))) 828 { 829 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); 830 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 831 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 832 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 833 } 834 835 // Reset 2D array texture. 836 gl.bindTexture (GL_TEXTURE_2D_ARRAY, 0); 837 gl.texImage3D (GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 838 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 839 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 840 gl.texParameterfv (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 841 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT); 842 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT); 843 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f); 844 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f); 845 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); 846 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000); 847 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 0.0f); 848 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE); 849 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 850 851 if (contextSupports(type, ApiType::core(3,3))) 852 { 853 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED); 854 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 855 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 856 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 857 } 858 859 // Reset 3D texture. 860 gl.bindTexture (GL_TEXTURE_3D, 0); 861 gl.texImage3D (GL_TEXTURE_3D, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 862 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 863 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 864 gl.texParameterfv (GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 865 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); 866 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); 867 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); 868 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_MIN_LOD, -1000.0f); 869 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_MAX_LOD, 1000.0f); 870 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); 871 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1000); 872 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_LOD_BIAS, 0.0f); 873 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_COMPARE_MODE, GL_NONE); 874 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 875 876 if (contextSupports(type, ApiType::core(3,3))) 877 { 878 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED); 879 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 880 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 881 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 882 } 883 884 if (contextSupports(type, ApiType::core(3,1))) 885 { 886 // Reset rectangle texture. 887 gl.bindTexture (GL_TEXTURE_RECTANGLE, 0); 888 gl.texImage2D (GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL); 889 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 890 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 891 gl.texParameterfv (GL_TEXTURE_RECTANGLE, GL_TEXTURE_BORDER_COLOR, &borderColor[0]); 892 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 893 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 894 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_BASE_LEVEL, 0); 895 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAX_LEVEL, 1000); 896 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_MODE, GL_NONE); 897 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); 898 // \todo [2013-06-17 pyry] Drivers don't accept GL_MIN_LOD, GL_MAX_LOD for rectangle textures. Is that okay? 899 900 if (contextSupports(type, ApiType::core(3,3))) 901 { 902 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_R, GL_RED); 903 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_G, GL_GREEN); 904 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_B, GL_BLUE); 905 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_A, GL_ALPHA); 906 } 907 908 // Reset buffer texture. 909 gl.bindTexture (GL_TEXTURE_BUFFER, 0); 910 gl.texBuffer (GL_TEXTURE_BUFFER, GL_R8, 0); 911 // \todo [2013-05-04 pyry] Which parameters apply to buffer textures? 912 } 913 914 if (contextSupports(type, ApiType::core(3,2))) 915 { 916 // Reset 2D multisample texture. 917 gl.bindTexture (GL_TEXTURE_2D_MULTISAMPLE, 0); 918 gl.texImage2DMultisample (GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 0, 0, GL_TRUE); 919 920 // Reset 2D multisample array texture. 921 gl.bindTexture (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0); 922 gl.texImage3DMultisample (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 0, 0, 0, GL_TRUE); 923 } 924 } 925 926 gl.activeTexture(GL_TEXTURE0); 927 928 if (contextSupports(type, ApiType::core(3,3))) 929 { 930 for (int ndx = 0; ndx < numTexUnits; ndx++) 931 gl.bindSampler(ndx, 0); 932 933 gl.disable(GL_TEXTURE_CUBE_MAP_SEAMLESS); 934 } 935 936 GLU_EXPECT_NO_ERROR(gl.getError(), "Texture state reset failed"); 937 } 938 939 // Pixel operations. 940 { 941 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget(); 942 943 gl.disable (GL_SCISSOR_TEST); 944 gl.scissor (0, 0, renderTarget.getWidth(), renderTarget.getHeight()); 945 946 gl.disable (GL_STENCIL_TEST); 947 gl.stencilFunc (GL_ALWAYS, 0, ~0u); 948 gl.stencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 949 950 gl.disable (GL_DEPTH_TEST); 951 gl.depthFunc (GL_LESS); 952 953 gl.disable (GL_BLEND); 954 gl.blendFunc (GL_ONE, GL_ZERO); 955 gl.blendEquation(GL_FUNC_ADD); 956 gl.blendColor (0.0f, 0.0f, 0.0f, 0.0f); 957 958 gl.disable (GL_FRAMEBUFFER_SRGB); 959 gl.enable (GL_DITHER); 960 961 gl.disable (GL_COLOR_LOGIC_OP); 962 gl.logicOp (GL_COPY); 963 964 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel operation state reset failed"); 965 } 966 967 // Framebuffer control. 968 { 969 gl.colorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 970 gl.depthMask (GL_TRUE); 971 gl.stencilMask (~0u); 972 973 gl.clearColor (0.0f, 0.0f, 0.0f, 0.0f); 974 gl.clearDepth (1.0); 975 gl.clearStencil (0); 976 977 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer control state reset failed"); 978 } 979 980 // Framebuffer state. 981 { 982 // \todo [2013-04-05 pyry] Single-buffered rendering: use GL_FRONT 983 deUint32 framebuffer = renderCtx.getDefaultFramebuffer(); 984 deUint32 drawReadBuffer = framebuffer == 0 ? GL_BACK : GL_COLOR_ATTACHMENT0; 985 986 gl.bindFramebuffer (GL_FRAMEBUFFER, renderCtx.getDefaultFramebuffer()); 987 gl.drawBuffer (drawReadBuffer); 988 gl.readBuffer (drawReadBuffer); 989 990 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer state reset failed"); 991 } 992 993 // Renderbuffer state. 994 { 995 gl.bindRenderbuffer(GL_RENDERBUFFER, 0); 996 GLU_EXPECT_NO_ERROR(gl.getError(), "Renderbuffer state reset failed"); 997 } 998 999 // Pixel transfer state. 1000 { 1001 gl.pixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); 1002 gl.pixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); 1003 gl.pixelStorei (GL_UNPACK_IMAGE_HEIGHT, 0); 1004 gl.pixelStorei (GL_UNPACK_SKIP_IMAGES, 0); 1005 gl.pixelStorei (GL_UNPACK_ROW_LENGTH, 0); 1006 gl.pixelStorei (GL_UNPACK_SKIP_ROWS, 0); 1007 gl.pixelStorei (GL_UNPACK_SKIP_PIXELS, 0); 1008 gl.pixelStorei (GL_UNPACK_ALIGNMENT, 4); 1009 1010 gl.pixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE); 1011 gl.pixelStorei (GL_PACK_LSB_FIRST, GL_FALSE); 1012 gl.pixelStorei (GL_PACK_IMAGE_HEIGHT, 0); 1013 gl.pixelStorei (GL_PACK_SKIP_IMAGES, 0); 1014 gl.pixelStorei (GL_PACK_ROW_LENGTH, 0); 1015 gl.pixelStorei (GL_PACK_SKIP_ROWS, 0); 1016 gl.pixelStorei (GL_PACK_SKIP_PIXELS, 0); 1017 gl.pixelStorei (GL_PACK_ALIGNMENT, 4); 1018 1019 gl.bindBuffer (GL_PIXEL_PACK_BUFFER, 0); 1020 gl.bindBuffer (GL_PIXEL_UNPACK_BUFFER, 0); 1021 1022 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel transfer state reset failed"); 1023 } 1024 1025 // Program object state. 1026 { 1027 gl.useProgram(0); 1028 1029 if (contextSupports(type, ApiType::core(3,1))) 1030 { 1031 int maxUniformBufferBindings = 0; 1032 gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings); 1033 1034 gl.bindBuffer(GL_UNIFORM_BUFFER, 0); 1035 1036 for (int ndx = 0; ndx < maxUniformBufferBindings; ndx++) 1037 gl.bindBufferBase(GL_UNIFORM_BUFFER, ndx, 0); 1038 } 1039 1040 GLU_EXPECT_NO_ERROR(gl.getError(), "Program object state reset failed"); 1041 } 1042 1043 // Vertex shader state. 1044 { 1045 int numVertexAttribArrays = 0; 1046 gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays); 1047 1048 for (int ndx = 0; ndx < numVertexAttribArrays; ndx++) 1049 gl.vertexAttrib4f(ndx, 0.0f, 0.0f, 0.0f, 1.0f); 1050 1051 gl.disable(GL_VERTEX_PROGRAM_POINT_SIZE); 1052 1053 GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex shader state reset failed"); 1054 } 1055 1056 // Transform feedback state. 1057 { 1058 int numTransformFeedbackSeparateAttribs = 0; 1059 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &numTransformFeedbackSeparateAttribs); 1060 1061 if (contextSupports(type, ApiType::core(4,0))) 1062 { 1063 glw::GLboolean transformFeedbackActive = 0; 1064 gl.getBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE, &transformFeedbackActive); 1065 1066 if (transformFeedbackActive) 1067 gl.endTransformFeedback(); 1068 } 1069 1070 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0); 1071 1072 for (int ndx = 0; ndx < numTransformFeedbackSeparateAttribs; ndx++) 1073 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ndx, 0); 1074 1075 GLU_EXPECT_NO_ERROR(gl.getError(), "Transform feedback state reset failed"); 1076 } 1077 1078 // Asynchronous query state. 1079 { 1080 deUint32 queryTargets[8]; 1081 int numTargets = 0; 1082 1083 queryTargets[numTargets++] = GL_PRIMITIVES_GENERATED; 1084 queryTargets[numTargets++] = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN; 1085 queryTargets[numTargets++] = GL_SAMPLES_PASSED; 1086 1087 DE_ASSERT(numTargets <= DE_LENGTH_OF_ARRAY(queryTargets)); 1088 1089 for (int i = 0; i < numTargets; i++) 1090 { 1091 int queryActive = 0; 1092 gl.getQueryiv(queryTargets[i], GL_CURRENT_QUERY, &queryActive); 1093 1094 if (queryActive != 0) 1095 gl.endQuery(queryTargets[i]); 1096 } 1097 1098 GLU_EXPECT_NO_ERROR(gl.getError(), "Asynchronous query state reset failed"); 1099 } 1100 1101 // Hints. 1102 { 1103 gl.hint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); 1104 gl.hint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE); 1105 gl.hint(GL_TEXTURE_COMPRESSION_HINT, GL_DONT_CARE); 1106 gl.hint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_DONT_CARE); 1107 1108 GLU_EXPECT_NO_ERROR(gl.getError(), "Hints reset failed"); 1109 } 1110 1111 // Buffer copy state. 1112 if (contextSupports(type, ApiType::core(3,1))) 1113 { 1114 gl.bindBuffer(GL_COPY_READ_BUFFER, 0); 1115 gl.bindBuffer(GL_COPY_WRITE_BUFFER, 0); 1116 1117 GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer copy state reset failed"); 1118 } 1119 1120 // Debug state 1121 if (ctxInfo.isExtensionSupported("GL_KHR_debug")) 1122 { 1123 const bool entrypointsPresent = gl.debugMessageControl != DE_NULL && 1124 gl.debugMessageCallback != DE_NULL; 1125 1126 // some drivers advertise GL_KHR_debug but give out null pointers. Silently ignore. 1127 if (entrypointsPresent) 1128 { 1129 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, DE_NULL, true); 1130 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, DE_NULL, false); 1131 gl.debugMessageCallback(DE_NULL, DE_NULL); 1132 1133 if (type.getFlags() & glu::CONTEXT_DEBUG) 1134 gl.enable(GL_DEBUG_OUTPUT); 1135 else 1136 gl.disable(GL_DEBUG_OUTPUT); 1137 } 1138 } 1139 } 1140 1141 void resetState (const RenderContext& renderCtx, const ContextInfo& ctxInfo) 1142 { 1143 if (isContextTypeES(renderCtx.getType())) 1144 resetStateES(renderCtx, ctxInfo); 1145 else if (isContextTypeGLCore(renderCtx.getType())) 1146 resetStateGLCore(renderCtx, ctxInfo); 1147 else 1148 throw tcu::InternalError("State reset requested for unsupported context type"); 1149 } 1150 1151 } // glu 1152