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