• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
resetErrors(const glw::Functions & gl)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 
resetStateES(const RenderContext & renderCtx,const ContextInfo & ctxInfo)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 		if (ctxInfo.isExtensionSupported("GL_EXT_sRGB_write_control"))
373 		{
374 			gl.enable		(GL_FRAMEBUFFER_SRGB);
375 		}
376 
377 		GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel operation state reset failed");
378 	}
379 
380 	// Framebuffer control.
381 	{
382 		gl.colorMask		(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
383 		gl.depthMask		(GL_TRUE);
384 		gl.stencilMask		(~0u);
385 
386 		gl.clearColor		(0.0f, 0.0f, 0.0f, 0.0f);
387 		gl.clearDepthf		(1.0f);
388 		gl.clearStencil		(0);
389 
390 		GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer control state reset failed");
391 	}
392 
393 	// Framebuffer state.
394 	{
395 		// \note Actually spec explictly says 0 but on some platforms (iOS) no default framebuffer exists.
396 		const deUint32		defaultFbo		= renderCtx.getDefaultFramebuffer();
397 		const deUint32		drawBuffer		= defaultFbo != 0 ? GL_COLOR_ATTACHMENT0 : GL_BACK;
398 		const deUint32		readBuffer		= defaultFbo != 0 ? GL_COLOR_ATTACHMENT0 : GL_BACK;
399 
400 		gl.bindFramebuffer(GL_FRAMEBUFFER, defaultFbo);
401 
402 		if (contextSupports(type, ApiType::es(3,0)))
403 		{
404 			gl.drawBuffers	(1, &drawBuffer);
405 			gl.readBuffer	(readBuffer);
406 		}
407 
408 		if (contextSupports(type, ApiType::es(3, 1)) && defaultFbo != 0)
409 		{
410 			gl.framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH,					0);
411 			gl.framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT,					0);
412 			gl.framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES,				0);
413 			gl.framebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS,	GL_FALSE);
414 			GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer default state reset failed");
415 		}
416 
417 		GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer state reset failed");
418 	}
419 
420 	// Renderbuffer state.
421 	{
422 		gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
423 		GLU_EXPECT_NO_ERROR(gl.getError(), "Renderbuffer state reset failed");
424 	}
425 
426 	// Pixel transfer state.
427 	{
428 		gl.pixelStorei(GL_UNPACK_ALIGNMENT,		4);
429 		gl.pixelStorei(GL_PACK_ALIGNMENT,		4);
430 
431 		if (contextSupports(type, ApiType::es(3,0)))
432 		{
433 			gl.pixelStorei(GL_UNPACK_IMAGE_HEIGHT,	0);
434 			gl.pixelStorei(GL_UNPACK_SKIP_IMAGES,	0);
435 			gl.pixelStorei(GL_UNPACK_ROW_LENGTH,	0);
436 			gl.pixelStorei(GL_UNPACK_SKIP_ROWS,		0);
437 			gl.pixelStorei(GL_UNPACK_SKIP_PIXELS,	0);
438 
439 			gl.pixelStorei(GL_PACK_ROW_LENGTH,		0);
440 			gl.pixelStorei(GL_PACK_SKIP_ROWS,		0);
441 			gl.pixelStorei(GL_PACK_SKIP_PIXELS,		0);
442 
443 			gl.bindBuffer(GL_PIXEL_PACK_BUFFER,		0);
444 			gl.bindBuffer(GL_PIXEL_UNPACK_BUFFER,	0);
445 		}
446 
447 		GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel transfer state reset failed");
448 	}
449 
450 	// Program object state.
451 	{
452 		gl.useProgram(0);
453 
454 		if (contextSupports(type, ApiType::es(3,0)))
455 		{
456 			int maxUniformBufferBindings = 0;
457 			gl.getIntegerv	(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
458 			gl.bindBuffer	(GL_UNIFORM_BUFFER,	0);
459 
460 			for (int ndx = 0; ndx < maxUniformBufferBindings; ndx++)
461 				gl.bindBufferBase(GL_UNIFORM_BUFFER, ndx, 0);
462 		}
463 
464 		if (contextSupports(type, ApiType::es(3,1)))
465 		{
466 			gl.bindProgramPipeline(0);
467 
468 			{
469 				int maxAtomicCounterBufferBindings = 0;
470 				gl.getIntegerv	(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &maxAtomicCounterBufferBindings);
471 				gl.bindBuffer	(GL_ATOMIC_COUNTER_BUFFER, 0);
472 
473 				for (int ndx = 0; ndx < maxAtomicCounterBufferBindings; ndx++)
474 					gl.bindBufferBase(GL_ATOMIC_COUNTER_BUFFER, ndx, 0);
475 			}
476 
477 			{
478 				int maxShaderStorageBufferBindings = 0;
479 				gl.getIntegerv	(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &maxShaderStorageBufferBindings);
480 				gl.bindBuffer	(GL_SHADER_STORAGE_BUFFER, 0);
481 
482 				for (int ndx = 0; ndx < maxShaderStorageBufferBindings; ndx++)
483 					gl.bindBufferBase(GL_SHADER_STORAGE_BUFFER, ndx, 0);
484 			}
485 		}
486 
487 		GLU_EXPECT_NO_ERROR(gl.getError(), "Program object state reset failed");
488 	}
489 
490 	// Vertex shader state.
491 	{
492 		int numVertexAttribArrays = 0;
493 		gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays);
494 
495 		for (int ndx = 0; ndx < numVertexAttribArrays; ndx++)
496 			gl.vertexAttrib4f(ndx, 0.0f, 0.0f, 0.0f, 1.0f);
497 
498 		GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex shader state reset failed");
499 	}
500 
501 	// Transform feedback state.
502 	if (contextSupports(type, ApiType::es(3,0)))
503 	{
504 		int				numTransformFeedbackSeparateAttribs	= 0;
505 		glw::GLboolean	transformFeedbackActive				= 0;
506 		gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,	&numTransformFeedbackSeparateAttribs);
507 		gl.getBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE,				&transformFeedbackActive);
508 
509 		if (transformFeedbackActive)
510 			gl.endTransformFeedback();
511 
512 		gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
513 
514 		for (int ndx = 0; ndx < numTransformFeedbackSeparateAttribs; ndx++)
515 			gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ndx, 0);
516 
517 		GLU_EXPECT_NO_ERROR(gl.getError(), "Transform feedback state reset failed");
518 	}
519 
520 	// Asynchronous query state.
521 	if (contextSupports(type, ApiType::es(3,0)))
522 	{
523 		static const deUint32 targets[] = { GL_ANY_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN };
524 
525 		for (int i = 0; i < DE_LENGTH_OF_ARRAY(targets); i++)
526 		{
527 			int queryActive = 0;
528 			gl.getQueryiv(targets[i], GL_CURRENT_QUERY, &queryActive);
529 
530 			if (queryActive != 0)
531 				gl.endQuery(targets[i]);
532 		}
533 
534 		GLU_EXPECT_NO_ERROR(gl.getError(), "Asynchronous query state reset failed");
535 	}
536 
537 	// Hints.
538 	{
539 		gl.hint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE);
540 
541 		if (contextSupports(type, ApiType::es(3,0)))
542 			gl.hint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_DONT_CARE);
543 
544 		GLU_EXPECT_NO_ERROR(gl.getError(), "Hints reset failed");
545 	}
546 
547 	// Compute.
548 	if (contextSupports(type, ApiType::es(3,1)))
549 	{
550 		gl.bindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
551 		GLU_EXPECT_NO_ERROR(gl.getError(), "Compute dispatch state reset failed");
552 	}
553 
554 	// Buffer copy state.
555 	if (contextSupports(type, ApiType::es(3,0)))
556 	{
557 		gl.bindBuffer(GL_COPY_READ_BUFFER,	0);
558 		gl.bindBuffer(GL_COPY_WRITE_BUFFER,	0);
559 
560 		GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer copy state reset failed");
561 	}
562 
563 	// Images.
564 	if (contextSupports(type, ApiType::es(3,1)))
565 	{
566 		int numImageUnits = 0;
567 		gl.getIntegerv(GL_MAX_IMAGE_UNITS, &numImageUnits);
568 
569 		for (int ndx = 0; ndx < numImageUnits; ndx++)
570 			gl.bindImageTexture(ndx, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI);
571 
572 		GLU_EXPECT_NO_ERROR(gl.getError(), "Image state reset failed");
573 	}
574 
575 	// Sample shading state.
576 	if (contextSupports(type, ApiType::es(3,1)) && ctxInfo.isExtensionSupported("GL_OES_sample_shading"))
577 	{
578 		gl.minSampleShading(0.0f);
579 		gl.disable(GL_SAMPLE_SHADING);
580 
581 		GLU_EXPECT_NO_ERROR(gl.getError(), "Sample shading state reset failed");
582 	}
583 
584 	// Debug state
585 	if (ctxInfo.isExtensionSupported("GL_KHR_debug"))
586 	{
587 		const bool entrypointsPresent =	gl.debugMessageControl	!= DE_NULL	&&
588 										gl.debugMessageCallback	!= DE_NULL	&&
589 										gl.popDebugGroup		!= DE_NULL;
590 
591 		// some drivers advertise GL_KHR_debug but give out null pointers. Silently ignore.
592 		if (entrypointsPresent)
593 		{
594 			int stackDepth = 0;
595 			gl.getIntegerv(GL_DEBUG_GROUP_STACK_DEPTH, &stackDepth);
596 			for (int ndx = 1; ndx < stackDepth; ++ndx)
597 				gl.popDebugGroup();
598 
599 			gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, DE_NULL, true);
600 			gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, DE_NULL, false);
601 			gl.debugMessageCallback(DE_NULL, DE_NULL);
602 
603 			if (type.getFlags() & glu::CONTEXT_DEBUG)
604 				gl.enable(GL_DEBUG_OUTPUT);
605 			else
606 				gl.disable(GL_DEBUG_OUTPUT);
607 			gl.disable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
608 
609 			GLU_EXPECT_NO_ERROR(gl.getError(), "Debug state reset failed");
610 		}
611 	}
612 
613 	// Primitive bounding box state.
614 	if (ctxInfo.isExtensionSupported("GL_EXT_primitive_bounding_box"))
615 	{
616 		gl.primitiveBoundingBox(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
617 		GLU_EXPECT_NO_ERROR(gl.getError(), "Primitive bounding box state reset failed");
618 	}
619 
620 	// Tessellation state
621 	if (ctxInfo.isExtensionSupported("GL_EXT_tessellation_shader"))
622 	{
623 		gl.patchParameteri(GL_PATCH_VERTICES, 3);
624 		GLU_EXPECT_NO_ERROR(gl.getError(), "Tessellation patch vertices state reset failed");
625 	}
626 
627 	// Advanced coherent blending
628 	if (ctxInfo.isExtensionSupported("GL_KHR_blend_equation_advanced_coherent"))
629 	{
630 		gl.enable(GL_BLEND_ADVANCED_COHERENT_KHR);
631 		GLU_EXPECT_NO_ERROR(gl.getError(), "Blend equation advanced coherent state reset failed");
632 	}
633 
634 	// Texture buffer
635 	if (ctxInfo.isExtensionSupported("GL_EXT_texture_buffer"))
636 	{
637 		gl.bindTexture(GL_TEXTURE_BUFFER, 0);
638 		gl.bindBuffer(GL_TEXTURE_BUFFER, 0);
639 		GLU_EXPECT_NO_ERROR(gl.getError(), "Texture buffer state reset failed");
640 	}
641 }
642 
resetStateGLCore(const RenderContext & renderCtx,const ContextInfo & ctxInfo)643 void resetStateGLCore (const RenderContext& renderCtx, const ContextInfo& ctxInfo)
644 {
645 	const glw::Functions&	gl		= renderCtx.getFunctions();
646 	const ContextType		type	= renderCtx.getType();
647 
648 	// Reset error state
649 	resetErrors(gl);
650 
651 	// Primitives and vertices state
652 	{
653 		if (contextSupports(type, glu::ApiType::core(4, 0)))
654 		{
655 			const float defaultTessLevels[]						= { 1.0f, 1.0f, 1.0f, 1.0f };
656 			gl.patchParameteri(GL_PATCH_VERTICES_EXT,			3);
657 			gl.patchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL,	defaultTessLevels);
658 			gl.patchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL,	defaultTessLevels);
659 		}
660 
661 		GLU_EXPECT_NO_ERROR(gl.getError(), "Primitives and vertices state reset failed");
662 	}
663 
664 	// Vertex attrib array state.
665 	{
666 		gl.bindVertexArray	(0);
667 		gl.bindBuffer		(GL_ARRAY_BUFFER,			0);
668 		gl.bindBuffer		(GL_ELEMENT_ARRAY_BUFFER,	0);
669 
670 		if (contextSupports(type, ApiType::core(3,1)))
671 		{
672 			gl.disable				(GL_PRIMITIVE_RESTART);
673 			gl.primitiveRestartIndex(0);
674 		}
675 
676 		GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex attrib array state reset failed");
677 	}
678 
679 	// Transformation state.
680 	{
681 		const tcu::RenderTarget&	renderTarget		= renderCtx.getRenderTarget();
682 		int							numUserClipPlanes	= 0;
683 
684 		gl.getIntegerv(GL_MAX_CLIP_DISTANCES, &numUserClipPlanes);
685 
686 		gl.viewport		(0, 0, renderTarget.getWidth(), renderTarget.getHeight());
687 		gl.depthRange	(0.0, 1.0);
688 
689 		for (int ndx = 0; ndx < numUserClipPlanes; ndx++)
690 			gl.disable(GL_CLIP_DISTANCE0+ndx);
691 
692 		if (contextSupports(type, ApiType::core(3,2)))
693 			gl.disable(GL_DEPTH_CLAMP);
694 
695 		//gl.bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
696 
697 		GLU_EXPECT_NO_ERROR(gl.getError(), "Transformation state reset failed");
698 	}
699 
700 	// Coloring
701 	{
702 		gl.clampColor(GL_CLAMP_READ_COLOR, GL_FIXED_ONLY);
703 
704 		if (contextSupports(type, ApiType::core(3,2)))
705 			gl.provokingVertex(GL_LAST_VERTEX_CONVENTION);
706 
707 		GLU_EXPECT_NO_ERROR(gl.getError(), "Coloring state reset failed");
708 	}
709 
710 	// Rasterization state
711 	{
712 		gl.disable			(GL_RASTERIZER_DISCARD);
713 		gl.pointSize		(1.0f);
714 		gl.pointParameterf	(GL_POINT_FADE_THRESHOLD_SIZE,	1.0f);
715 		gl.pointParameteri	(GL_POINT_SPRITE_COORD_ORIGIN,	GL_UPPER_LEFT);
716 		gl.lineWidth		(1.0f);
717 		gl.disable			(GL_LINE_SMOOTH);
718 		gl.disable			(GL_CULL_FACE);
719 		gl.cullFace			(GL_BACK);
720 		gl.frontFace		(GL_CCW);
721 		gl.disable			(GL_POLYGON_SMOOTH);
722 		gl.polygonOffset	(0.0f, 0.0f);
723 		gl.disable			(GL_POLYGON_OFFSET_POINT);
724 		gl.disable			(GL_POLYGON_OFFSET_LINE);
725 		gl.disable			(GL_POLYGON_OFFSET_FILL);
726 
727 		GLU_EXPECT_NO_ERROR(gl.getError(), "Rasterization state reset failed");
728 	}
729 
730 	// Multisampling state
731 	{
732 		gl.enable			(GL_MULTISAMPLE);
733 		gl.disable			(GL_SAMPLE_ALPHA_TO_COVERAGE);
734 		gl.disable			(GL_SAMPLE_ALPHA_TO_ONE);
735 		gl.disable			(GL_SAMPLE_COVERAGE);
736 		gl.sampleCoverage	(1.0f, GL_FALSE);
737 
738 		if (contextSupports(type, ApiType::core(3,2)))
739 		{
740 			int numSampleMaskWords = 0;
741 			gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &numSampleMaskWords);
742 
743 			gl.disable(GL_SAMPLE_MASK);
744 
745 			for (int ndx = 0; ndx < numSampleMaskWords; ndx++)
746 				gl.sampleMaski(ndx, ~0u);
747 		}
748 
749 		GLU_EXPECT_NO_ERROR(gl.getError(), "Multisampling state reset failed");
750 	}
751 
752 	// Texture state.
753 	// \todo [2013-04-08 pyry] Reset all levels?
754 	{
755 		const float	borderColor[]	= { 0.0f, 0.0f, 0.0f, 0.0f };
756 		int			numTexUnits		= 0;
757 		gl.getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numTexUnits);
758 
759 		gl.bindBuffer(GL_TEXTURE_BUFFER, 0);
760 
761 		for (int ndx = 0; ndx < numTexUnits; ndx++)
762 		{
763 			gl.activeTexture(GL_TEXTURE0 + ndx);
764 
765 			// Reset 1D texture.
766 			gl.bindTexture		(GL_TEXTURE_1D, 0);
767 			gl.texImage1D		(GL_TEXTURE_1D, 0, GL_RGBA, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
768 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER,		GL_LINEAR_MIPMAP_NEAREST);
769 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER,		GL_LINEAR);
770 			gl.texParameterfv	(GL_TEXTURE_1D, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
771 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S,			GL_REPEAT);
772 			gl.texParameterf	(GL_TEXTURE_1D, GL_TEXTURE_MIN_LOD,			-1000.0f);
773 			gl.texParameterf	(GL_TEXTURE_1D, GL_TEXTURE_MAX_LOD,			1000.0f);
774 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_BASE_LEVEL,		0);
775 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_MAX_LEVEL,		1000);
776 			gl.texParameterf	(GL_TEXTURE_1D, GL_TEXTURE_LOD_BIAS,		0.0f);
777 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
778 			gl.texParameteri	(GL_TEXTURE_1D, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
779 
780 			if (contextSupports(type, ApiType::core(3,3)))
781 			{
782 				gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_R,		GL_RED);
783 				gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
784 				gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
785 				gl.texParameteri(GL_TEXTURE_1D, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
786 			}
787 
788 			// Reset 2D texture.
789 			gl.bindTexture		(GL_TEXTURE_2D, 0);
790 			gl.texImage2D		(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
791 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,		GL_LINEAR_MIPMAP_NEAREST);
792 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,		GL_LINEAR);
793 			gl.texParameterfv	(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
794 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,			GL_REPEAT);
795 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,			GL_REPEAT);
796 			gl.texParameterf	(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD,			-1000.0f);
797 			gl.texParameterf	(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD,			1000.0f);
798 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL,		0);
799 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,		1000);
800 			gl.texParameterf	(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS,		0.0f);
801 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
802 			gl.texParameteri	(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
803 
804 			if (contextSupports(type, ApiType::core(3,3)))
805 			{
806 				gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R,		GL_RED);
807 				gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
808 				gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
809 				gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
810 			}
811 
812 			// Reset cube map texture.
813 			gl.bindTexture		(GL_TEXTURE_CUBE_MAP, 0);
814 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
815 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
816 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
817 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
818 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
819 			gl.texImage2D		(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
820 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,	GL_LINEAR_MIPMAP_NEAREST);
821 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,	GL_LINEAR);
822 			gl.texParameterfv	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
823 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,		GL_REPEAT);
824 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,		GL_REPEAT);
825 			gl.texParameterf	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_LOD,		-1000.0f);
826 			gl.texParameterf	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LOD,		1000.0f);
827 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL,	0);
828 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL,		1000);
829 			gl.texParameterf	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_LOD_BIAS,		0.0f);
830 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
831 			gl.texParameteri	(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
832 
833 			if (contextSupports(type, ApiType::core(3,3)))
834 			{
835 				gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_R,		GL_RED);
836 				gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
837 				gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
838 				gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
839 			}
840 
841 			// Reset 1D array texture.
842 			gl.bindTexture		(GL_TEXTURE_1D_ARRAY, 0);
843 			gl.texImage2D		(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
844 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER,	GL_LINEAR_MIPMAP_NEAREST);
845 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER,	GL_LINEAR);
846 			gl.texParameterfv	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
847 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S,		GL_REPEAT);
848 			gl.texParameterf	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_LOD,		-1000.0f);
849 			gl.texParameterf	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LOD,		1000.0f);
850 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BASE_LEVEL,	0);
851 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LEVEL,		1000);
852 			gl.texParameterf	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_LOD_BIAS,		0.0f);
853 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
854 			gl.texParameteri	(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
855 
856 			if (contextSupports(type, ApiType::core(3,3)))
857 			{
858 				gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_R,		GL_RED);
859 				gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
860 				gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
861 				gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
862 			}
863 
864 			// Reset 2D array texture.
865 			gl.bindTexture		(GL_TEXTURE_2D_ARRAY, 0);
866 			gl.texImage3D		(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
867 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,	GL_LINEAR_MIPMAP_NEAREST);
868 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,	GL_LINEAR);
869 			gl.texParameterfv	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
870 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S,		GL_REPEAT);
871 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T,		GL_REPEAT);
872 			gl.texParameterf	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD,		-1000.0f);
873 			gl.texParameterf	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD,		1000.0f);
874 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL,	0);
875 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL,		1000);
876 			gl.texParameterf	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS,		0.0f);
877 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
878 			gl.texParameteri	(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
879 
880 			if (contextSupports(type, ApiType::core(3,3)))
881 			{
882 				gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R,		GL_RED);
883 				gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
884 				gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
885 				gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
886 			}
887 
888 			// Reset 3D texture.
889 			gl.bindTexture		(GL_TEXTURE_3D, 0);
890 			gl.texImage3D		(GL_TEXTURE_3D, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
891 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER,		GL_LINEAR_MIPMAP_NEAREST);
892 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,		GL_LINEAR);
893 			gl.texParameterfv	(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
894 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S,			GL_REPEAT);
895 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T,			GL_REPEAT);
896 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R,			GL_REPEAT);
897 			gl.texParameterf	(GL_TEXTURE_3D, GL_TEXTURE_MIN_LOD,			-1000.0f);
898 			gl.texParameterf	(GL_TEXTURE_3D, GL_TEXTURE_MAX_LOD,			1000.0f);
899 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL,		0);
900 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL,		1000);
901 			gl.texParameterf	(GL_TEXTURE_3D, GL_TEXTURE_LOD_BIAS,		0.0f);
902 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
903 			gl.texParameteri	(GL_TEXTURE_3D, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
904 
905 			if (contextSupports(type, ApiType::core(3,3)))
906 			{
907 				gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R,		GL_RED);
908 				gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G,		GL_GREEN);
909 				gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B,		GL_BLUE);
910 				gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A,		GL_ALPHA);
911 			}
912 
913 			if (contextSupports(type, ApiType::core(3,1)))
914 			{
915 				// Reset rectangle texture.
916 				gl.bindTexture		(GL_TEXTURE_RECTANGLE, 0);
917 				gl.texImage2D		(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
918 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER,	GL_LINEAR);
919 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER,	GL_LINEAR);
920 				gl.texParameterfv	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_BORDER_COLOR,	&borderColor[0]);
921 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S,		GL_CLAMP_TO_EDGE);
922 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T,		GL_CLAMP_TO_EDGE);
923 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_BASE_LEVEL,	0);
924 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAX_LEVEL,	1000);
925 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_MODE,	GL_NONE);
926 				gl.texParameteri	(GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC,	GL_LEQUAL);
927 				// \todo [2013-06-17 pyry] Drivers don't accept GL_MIN_LOD, GL_MAX_LOD for rectangle textures. Is that okay?
928 
929 				if (contextSupports(type, ApiType::core(3,3)))
930 				{
931 					gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_R,	GL_RED);
932 					gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_G,	GL_GREEN);
933 					gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_B,	GL_BLUE);
934 					gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_A,	GL_ALPHA);
935 				}
936 
937 				// Reset buffer texture.
938 				gl.bindTexture	(GL_TEXTURE_BUFFER, 0);
939 				gl.texBuffer	(GL_TEXTURE_BUFFER, GL_R8, 0);
940 				// \todo [2013-05-04 pyry] Which parameters apply to buffer textures?
941 			}
942 
943 			if (contextSupports(type, ApiType::core(3,2)))
944 			{
945 				// Reset 2D multisample texture.
946 				gl.bindTexture				(GL_TEXTURE_2D_MULTISAMPLE, 0);
947 				gl.texImage2DMultisample	(GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 0, 0, GL_TRUE);
948 
949 				// Reset 2D multisample array texture.
950 				gl.bindTexture				(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0);
951 				gl.texImage3DMultisample	(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 0, 0, 0, GL_TRUE);
952 			}
953 		}
954 
955 		gl.activeTexture(GL_TEXTURE0);
956 
957 		if (contextSupports(type, ApiType::core(3,3)))
958 		{
959 			for (int ndx = 0; ndx < numTexUnits; ndx++)
960 				gl.bindSampler(ndx, 0);
961 
962 			gl.disable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
963 		}
964 
965 		GLU_EXPECT_NO_ERROR(gl.getError(), "Texture state reset failed");
966 	}
967 
968 	// Pixel operations.
969 	{
970 		const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget();
971 
972 		gl.disable		(GL_SCISSOR_TEST);
973 		gl.scissor		(0, 0, renderTarget.getWidth(), renderTarget.getHeight());
974 
975 		gl.disable		(GL_STENCIL_TEST);
976 		gl.stencilFunc	(GL_ALWAYS, 0, ~0u);
977 		gl.stencilOp	(GL_KEEP, GL_KEEP, GL_KEEP);
978 
979 		gl.disable		(GL_DEPTH_TEST);
980 		gl.depthFunc	(GL_LESS);
981 
982 		gl.disable		(GL_BLEND);
983 		gl.blendFunc	(GL_ONE, GL_ZERO);
984 		gl.blendEquation(GL_FUNC_ADD);
985 		gl.blendColor	(0.0f, 0.0f, 0.0f, 0.0f);
986 
987 		gl.disable		(GL_FRAMEBUFFER_SRGB);
988 		gl.enable		(GL_DITHER);
989 
990 		gl.disable		(GL_COLOR_LOGIC_OP);
991 		gl.logicOp		(GL_COPY);
992 
993 		GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel operation state reset failed");
994 	}
995 
996 	// Framebuffer control.
997 	{
998 		gl.colorMask		(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
999 		gl.depthMask		(GL_TRUE);
1000 		gl.stencilMask		(~0u);
1001 
1002 		gl.clearColor		(0.0f, 0.0f, 0.0f, 0.0f);
1003 		gl.clearDepth		(1.0);
1004 		gl.clearStencil		(0);
1005 
1006 		GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer control state reset failed");
1007 	}
1008 
1009 	// Framebuffer state.
1010 	{
1011 		const deUint32	framebuffer	= renderCtx.getDefaultFramebuffer();
1012 
1013 		gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1014 
1015 		if (framebuffer == 0)
1016 		{
1017 			gl.drawBuffer(GL_BACK);
1018 			gl.readBuffer(GL_BACK);
1019 
1020 			// This is a workaround for supporting single-buffered configurations.
1021 			// Since there is no other place where we need to know if we are dealing
1022 			// with single-buffered config, it is not worthwhile to add additional
1023 			// state into RenderContext for that.
1024 			if (gl.getError() != GL_NO_ERROR)
1025 			{
1026 				gl.drawBuffer(GL_FRONT);
1027 				gl.readBuffer(GL_FRONT);
1028 			}
1029 		}
1030 		else
1031 		{
1032 			gl.drawBuffer(GL_COLOR_ATTACHMENT0);
1033 			gl.readBuffer(GL_COLOR_ATTACHMENT0);
1034 		}
1035 
1036 		GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer state reset failed");
1037 	}
1038 
1039 	// Renderbuffer state.
1040 	{
1041 		gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
1042 		GLU_EXPECT_NO_ERROR(gl.getError(), "Renderbuffer state reset failed");
1043 	}
1044 
1045 	// Pixel transfer state.
1046 	{
1047 		gl.pixelStorei	(GL_UNPACK_SWAP_BYTES,		GL_FALSE);
1048 		gl.pixelStorei	(GL_UNPACK_LSB_FIRST,		GL_FALSE);
1049 		gl.pixelStorei	(GL_UNPACK_IMAGE_HEIGHT,	0);
1050 		gl.pixelStorei	(GL_UNPACK_SKIP_IMAGES,		0);
1051 		gl.pixelStorei	(GL_UNPACK_ROW_LENGTH,		0);
1052 		gl.pixelStorei	(GL_UNPACK_SKIP_ROWS,		0);
1053 		gl.pixelStorei	(GL_UNPACK_SKIP_PIXELS,		0);
1054 		gl.pixelStorei	(GL_UNPACK_ALIGNMENT,		4);
1055 
1056 		gl.pixelStorei	(GL_PACK_SWAP_BYTES,		GL_FALSE);
1057 		gl.pixelStorei	(GL_PACK_LSB_FIRST,			GL_FALSE);
1058 		gl.pixelStorei	(GL_PACK_IMAGE_HEIGHT,		0);
1059 		gl.pixelStorei	(GL_PACK_SKIP_IMAGES,		0);
1060 		gl.pixelStorei	(GL_PACK_ROW_LENGTH,		0);
1061 		gl.pixelStorei	(GL_PACK_SKIP_ROWS,			0);
1062 		gl.pixelStorei	(GL_PACK_SKIP_PIXELS,		0);
1063 		gl.pixelStorei	(GL_PACK_ALIGNMENT,			4);
1064 
1065 		gl.bindBuffer	(GL_PIXEL_PACK_BUFFER,		0);
1066 		gl.bindBuffer	(GL_PIXEL_UNPACK_BUFFER,	0);
1067 
1068 		GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel transfer state reset failed");
1069 	}
1070 
1071 	// Program object state.
1072 	{
1073 		gl.useProgram(0);
1074 
1075 		if (contextSupports(type, ApiType::core(3,1)))
1076 		{
1077 			int maxUniformBufferBindings = 0;
1078 			gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
1079 
1080 			gl.bindBuffer(GL_UNIFORM_BUFFER, 0);
1081 
1082 			for (int ndx = 0; ndx < maxUniformBufferBindings; ndx++)
1083 				gl.bindBufferBase(GL_UNIFORM_BUFFER, ndx, 0);
1084 		}
1085 
1086 		GLU_EXPECT_NO_ERROR(gl.getError(), "Program object state reset failed");
1087 	}
1088 
1089 	// Vertex shader state.
1090 	{
1091 		int numVertexAttribArrays = 0;
1092 		gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays);
1093 
1094 		for (int ndx = 0; ndx < numVertexAttribArrays; ndx++)
1095 			gl.vertexAttrib4f(ndx, 0.0f, 0.0f, 0.0f, 1.0f);
1096 
1097 		gl.disable(GL_VERTEX_PROGRAM_POINT_SIZE);
1098 
1099 		GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex shader state reset failed");
1100 	}
1101 
1102 	// Transform feedback state.
1103 	{
1104 		int numTransformFeedbackSeparateAttribs = 0;
1105 		gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &numTransformFeedbackSeparateAttribs);
1106 
1107 		if (contextSupports(type, ApiType::core(4,0)))
1108 		{
1109 			glw::GLboolean transformFeedbackActive = 0;
1110 			gl.getBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE, &transformFeedbackActive);
1111 
1112 			if (transformFeedbackActive)
1113 				gl.endTransformFeedback();
1114 		}
1115 
1116 		gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
1117 
1118 		for (int ndx = 0; ndx < numTransformFeedbackSeparateAttribs; ndx++)
1119 			gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ndx, 0);
1120 
1121 		GLU_EXPECT_NO_ERROR(gl.getError(), "Transform feedback state reset failed");
1122 	}
1123 
1124 	// Asynchronous query state.
1125 	{
1126 		deUint32	queryTargets[8];
1127 		int			numTargets		= 0;
1128 
1129 		queryTargets[numTargets++] = GL_PRIMITIVES_GENERATED;
1130 		queryTargets[numTargets++] = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN;
1131 		queryTargets[numTargets++] = GL_SAMPLES_PASSED;
1132 
1133 		DE_ASSERT(numTargets <= DE_LENGTH_OF_ARRAY(queryTargets));
1134 
1135 		for (int i = 0; i < numTargets; i++)
1136 		{
1137 			int queryActive = 0;
1138 			gl.getQueryiv(queryTargets[i], GL_CURRENT_QUERY, &queryActive);
1139 
1140 			if (queryActive != 0)
1141 				gl.endQuery(queryTargets[i]);
1142 		}
1143 
1144 		GLU_EXPECT_NO_ERROR(gl.getError(), "Asynchronous query state reset failed");
1145 	}
1146 
1147 	// Hints.
1148 	{
1149 		gl.hint(GL_LINE_SMOOTH_HINT,				GL_DONT_CARE);
1150 		gl.hint(GL_POLYGON_SMOOTH_HINT,				GL_DONT_CARE);
1151 		gl.hint(GL_TEXTURE_COMPRESSION_HINT,		GL_DONT_CARE);
1152 		gl.hint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT,	GL_DONT_CARE);
1153 
1154 		GLU_EXPECT_NO_ERROR(gl.getError(), "Hints reset failed");
1155 	}
1156 
1157 	// Buffer copy state.
1158 	if (contextSupports(type, ApiType::core(3,1)))
1159 	{
1160 		gl.bindBuffer(GL_COPY_READ_BUFFER,	0);
1161 		gl.bindBuffer(GL_COPY_WRITE_BUFFER,	0);
1162 
1163 		GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer copy state reset failed");
1164 	}
1165 
1166 	// Debug state
1167 	if (ctxInfo.isExtensionSupported("GL_KHR_debug"))
1168 	{
1169 		const bool entrypointsPresent =	gl.debugMessageControl	!= DE_NULL	&&
1170 										gl.debugMessageCallback	!= DE_NULL;
1171 
1172 		// some drivers advertise GL_KHR_debug but give out null pointers. Silently ignore.
1173 		if (entrypointsPresent)
1174 		{
1175 			gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, DE_NULL, true);
1176 			gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, DE_NULL, false);
1177 			gl.debugMessageCallback(DE_NULL, DE_NULL);
1178 
1179 			if (type.getFlags() & glu::CONTEXT_DEBUG)
1180 				gl.enable(GL_DEBUG_OUTPUT);
1181 			else
1182 				gl.disable(GL_DEBUG_OUTPUT);
1183 		}
1184 	}
1185 }
1186 
resetState(const RenderContext & renderCtx,const ContextInfo & ctxInfo)1187 void resetState (const RenderContext& renderCtx, const ContextInfo& ctxInfo)
1188 {
1189 	if (isContextTypeES(renderCtx.getType()))
1190 		resetStateES(renderCtx, ctxInfo);
1191 	else if (isContextTypeGLCore(renderCtx.getType()))
1192 		resetStateGLCore(renderCtx, ctxInfo);
1193 	else
1194 		throw tcu::InternalError("State reset requested for unsupported context type");
1195 }
1196 
1197 } // glu
1198