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 cube array texture.
842 gl.bindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
843 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
844 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
845 gl.texParameterfv(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
846 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
847 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
848 gl.texParameterf(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f);
849 gl.texParameterf(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f);
850 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
851 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000);
852 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE);
853 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
854
855 if (contextSupports(type, ApiType::core(3,3)))
856 {
857 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
858 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
859 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
860 gl.texParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
861 }
862
863 // Reset 1D array texture.
864 gl.bindTexture (GL_TEXTURE_1D_ARRAY, 0);
865 gl.texImage2D (GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
866 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
867 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
868 gl.texParameterfv (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
869 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
870 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f);
871 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f);
872 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
873 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000);
874 gl.texParameterf (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_LOD_BIAS, 0.0f);
875 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE);
876 gl.texParameteri (GL_TEXTURE_1D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
877
878 if (contextSupports(type, ApiType::core(3,3)))
879 {
880 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
881 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
882 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
883 gl.texParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
884 }
885
886 // Reset 2D array texture.
887 gl.bindTexture (GL_TEXTURE_2D_ARRAY, 0);
888 gl.texImage3D (GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
889 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
890 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
891 gl.texParameterfv (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
892 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT);
893 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT);
894 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, -1000.0f);
895 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 1000.0f);
896 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
897 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000);
898 gl.texParameterf (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 0.0f);
899 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE);
900 gl.texParameteri (GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
901
902 if (contextSupports(type, ApiType::core(3,3)))
903 {
904 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
905 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
906 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
907 gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
908 }
909
910 // Reset 3D texture.
911 gl.bindTexture (GL_TEXTURE_3D, 0);
912 gl.texImage3D (GL_TEXTURE_3D, 0, GL_RGBA, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
913 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
914 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
915 gl.texParameterfv (GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
916 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
917 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
918 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
919 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_MIN_LOD, -1000.0f);
920 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_MAX_LOD, 1000.0f);
921 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
922 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 1000);
923 gl.texParameterf (GL_TEXTURE_3D, GL_TEXTURE_LOD_BIAS, 0.0f);
924 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
925 gl.texParameteri (GL_TEXTURE_3D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
926
927 if (contextSupports(type, ApiType::core(3,3)))
928 {
929 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED);
930 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
931 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
932 gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
933 }
934
935 if (contextSupports(type, ApiType::core(3,1)))
936 {
937 // Reset rectangle texture.
938 gl.bindTexture (GL_TEXTURE_RECTANGLE, 0);
939 gl.texImage2D (GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL);
940 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
941 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
942 gl.texParameterfv (GL_TEXTURE_RECTANGLE, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
943 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
944 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
945 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_BASE_LEVEL, 0);
946 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAX_LEVEL, 1000);
947 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_MODE, GL_NONE);
948 gl.texParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
949 // \todo [2013-06-17 pyry] Drivers don't accept GL_MIN_LOD, GL_MAX_LOD for rectangle textures. Is that okay?
950
951 if (contextSupports(type, ApiType::core(3,3)))
952 {
953 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_R, GL_RED);
954 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
955 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
956 gl.texParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
957 }
958
959 // Reset buffer texture.
960 gl.bindTexture (GL_TEXTURE_BUFFER, 0);
961 gl.texBuffer (GL_TEXTURE_BUFFER, GL_R8, 0);
962 // \todo [2013-05-04 pyry] Which parameters apply to buffer textures?
963 }
964
965 if (contextSupports(type, ApiType::core(3,2)))
966 {
967 // Reset 2D multisample texture.
968 gl.bindTexture (GL_TEXTURE_2D_MULTISAMPLE, 0);
969 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_R, GL_RED);
970 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
971 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
972 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
973 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_BASE_LEVEL, 0);
974 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAX_LEVEL, 1000);
975 gl.texImage2DMultisample (GL_TEXTURE_2D_MULTISAMPLE, 1, GL_RGBA8, 0, 0, GL_TRUE);
976
977 // Reset 2D multisample array texture.
978 gl.bindTexture (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 0);
979 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_R, GL_RED);
980 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
981 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
982 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
983 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
984 gl.texParameteri (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, GL_TEXTURE_MAX_LEVEL, 1000);
985 gl.texImage3DMultisample (GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, GL_RGBA8, 0, 0, 0, GL_TRUE);
986 }
987 }
988
989 gl.activeTexture(GL_TEXTURE0);
990
991 if (contextSupports(type, ApiType::core(3,3)))
992 {
993 for (int ndx = 0; ndx < numTexUnits; ndx++)
994 gl.bindSampler(ndx, 0);
995
996 gl.disable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
997 }
998
999 GLU_EXPECT_NO_ERROR(gl.getError(), "Texture state reset failed");
1000 }
1001
1002 // Pixel operations.
1003 {
1004 const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget();
1005
1006 gl.disable (GL_SCISSOR_TEST);
1007 gl.scissor (0, 0, renderTarget.getWidth(), renderTarget.getHeight());
1008
1009 gl.disable (GL_STENCIL_TEST);
1010 gl.stencilFunc (GL_ALWAYS, 0, ~0u);
1011 gl.stencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
1012
1013 gl.disable (GL_DEPTH_TEST);
1014 gl.depthFunc (GL_LESS);
1015
1016 gl.disable (GL_BLEND);
1017 gl.blendFunc (GL_ONE, GL_ZERO);
1018 gl.blendEquation(GL_FUNC_ADD);
1019 gl.blendColor (0.0f, 0.0f, 0.0f, 0.0f);
1020
1021 gl.disable (GL_FRAMEBUFFER_SRGB);
1022 gl.enable (GL_DITHER);
1023
1024 gl.disable (GL_COLOR_LOGIC_OP);
1025 gl.logicOp (GL_COPY);
1026
1027 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel operation state reset failed");
1028 }
1029
1030 // Framebuffer control.
1031 {
1032 gl.colorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1033 gl.depthMask (GL_TRUE);
1034 gl.stencilMask (~0u);
1035
1036 gl.clearColor (0.0f, 0.0f, 0.0f, 0.0f);
1037 gl.clearDepth (1.0);
1038 gl.clearStencil (0);
1039
1040 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer control state reset failed");
1041 }
1042
1043 // Framebuffer state.
1044 {
1045 const deUint32 framebuffer = renderCtx.getDefaultFramebuffer();
1046
1047 gl.bindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1048
1049 if (framebuffer == 0)
1050 {
1051 gl.drawBuffer(GL_BACK);
1052 gl.readBuffer(GL_BACK);
1053
1054 // This is a workaround for supporting single-buffered configurations.
1055 // Since there is no other place where we need to know if we are dealing
1056 // with single-buffered config, it is not worthwhile to add additional
1057 // state into RenderContext for that.
1058 if (gl.getError() != GL_NO_ERROR)
1059 {
1060 gl.drawBuffer(GL_FRONT);
1061 gl.readBuffer(GL_FRONT);
1062 }
1063 }
1064 else
1065 {
1066 gl.drawBuffer(GL_COLOR_ATTACHMENT0);
1067 gl.readBuffer(GL_COLOR_ATTACHMENT0);
1068 }
1069
1070 GLU_EXPECT_NO_ERROR(gl.getError(), "Framebuffer state reset failed");
1071 }
1072
1073 // Renderbuffer state.
1074 {
1075 gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
1076 GLU_EXPECT_NO_ERROR(gl.getError(), "Renderbuffer state reset failed");
1077 }
1078
1079 // Pixel transfer state.
1080 {
1081 gl.pixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
1082 gl.pixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
1083 gl.pixelStorei (GL_UNPACK_IMAGE_HEIGHT, 0);
1084 gl.pixelStorei (GL_UNPACK_SKIP_IMAGES, 0);
1085 gl.pixelStorei (GL_UNPACK_ROW_LENGTH, 0);
1086 gl.pixelStorei (GL_UNPACK_SKIP_ROWS, 0);
1087 gl.pixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
1088 gl.pixelStorei (GL_UNPACK_ALIGNMENT, 4);
1089
1090 gl.pixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE);
1091 gl.pixelStorei (GL_PACK_LSB_FIRST, GL_FALSE);
1092 gl.pixelStorei (GL_PACK_IMAGE_HEIGHT, 0);
1093 gl.pixelStorei (GL_PACK_SKIP_IMAGES, 0);
1094 gl.pixelStorei (GL_PACK_ROW_LENGTH, 0);
1095 gl.pixelStorei (GL_PACK_SKIP_ROWS, 0);
1096 gl.pixelStorei (GL_PACK_SKIP_PIXELS, 0);
1097 gl.pixelStorei (GL_PACK_ALIGNMENT, 4);
1098
1099 gl.bindBuffer (GL_PIXEL_PACK_BUFFER, 0);
1100 gl.bindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
1101
1102 GLU_EXPECT_NO_ERROR(gl.getError(), "Pixel transfer state reset failed");
1103 }
1104
1105 // Program object state.
1106 {
1107 gl.useProgram(0);
1108
1109 if (contextSupports(type, ApiType::core(3,1)))
1110 {
1111 int maxUniformBufferBindings = 0;
1112 gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
1113
1114 gl.bindBuffer(GL_UNIFORM_BUFFER, 0);
1115
1116 for (int ndx = 0; ndx < maxUniformBufferBindings; ndx++)
1117 gl.bindBufferBase(GL_UNIFORM_BUFFER, ndx, 0);
1118 }
1119
1120 GLU_EXPECT_NO_ERROR(gl.getError(), "Program object state reset failed");
1121 }
1122
1123 // Vertex shader state.
1124 {
1125 int numVertexAttribArrays = 0;
1126 gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &numVertexAttribArrays);
1127
1128 for (int ndx = 0; ndx < numVertexAttribArrays; ndx++)
1129 gl.vertexAttrib4f(ndx, 0.0f, 0.0f, 0.0f, 1.0f);
1130
1131 gl.disable(GL_VERTEX_PROGRAM_POINT_SIZE);
1132
1133 GLU_EXPECT_NO_ERROR(gl.getError(), "Vertex shader state reset failed");
1134 }
1135
1136 // Transform feedback state.
1137 {
1138 int numTransformFeedbackSeparateAttribs = 0;
1139 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &numTransformFeedbackSeparateAttribs);
1140
1141 if (contextSupports(type, ApiType::core(4,0)))
1142 {
1143 glw::GLboolean transformFeedbackActive = 0;
1144 gl.getBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE, &transformFeedbackActive);
1145
1146 if (transformFeedbackActive)
1147 gl.endTransformFeedback();
1148 }
1149
1150 gl.bindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
1151
1152 for (int ndx = 0; ndx < numTransformFeedbackSeparateAttribs; ndx++)
1153 gl.bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ndx, 0);
1154
1155 GLU_EXPECT_NO_ERROR(gl.getError(), "Transform feedback state reset failed");
1156 }
1157
1158 // Asynchronous query state.
1159 {
1160 deUint32 queryTargets[8];
1161 int numTargets = 0;
1162
1163 queryTargets[numTargets++] = GL_PRIMITIVES_GENERATED;
1164 queryTargets[numTargets++] = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN;
1165 queryTargets[numTargets++] = GL_SAMPLES_PASSED;
1166
1167 DE_ASSERT(numTargets <= DE_LENGTH_OF_ARRAY(queryTargets));
1168
1169 for (int i = 0; i < numTargets; i++)
1170 {
1171 int queryActive = 0;
1172 gl.getQueryiv(queryTargets[i], GL_CURRENT_QUERY, &queryActive);
1173
1174 if (queryActive != 0)
1175 gl.endQuery(queryTargets[i]);
1176 }
1177
1178 GLU_EXPECT_NO_ERROR(gl.getError(), "Asynchronous query state reset failed");
1179 }
1180
1181 // Hints.
1182 {
1183 gl.hint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
1184 gl.hint(GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);
1185 gl.hint(GL_TEXTURE_COMPRESSION_HINT, GL_DONT_CARE);
1186 gl.hint(GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_DONT_CARE);
1187
1188 GLU_EXPECT_NO_ERROR(gl.getError(), "Hints reset failed");
1189 }
1190
1191 // Buffer copy state.
1192 if (contextSupports(type, ApiType::core(3,1)))
1193 {
1194 gl.bindBuffer(GL_COPY_READ_BUFFER, 0);
1195 gl.bindBuffer(GL_COPY_WRITE_BUFFER, 0);
1196
1197 GLU_EXPECT_NO_ERROR(gl.getError(), "Buffer copy state reset failed");
1198 }
1199
1200 // Images.
1201 if (contextSupports(type, ApiType::core(4,4)))
1202 {
1203 int numImageUnits = 0;
1204 gl.getIntegerv(GL_MAX_IMAGE_UNITS, &numImageUnits);
1205
1206 for (int ndx = 0; ndx < numImageUnits; ndx++)
1207 gl.bindImageTexture(ndx, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R8);
1208
1209 GLU_EXPECT_NO_ERROR(gl.getError(), "Image state reset failed");
1210 }
1211
1212 // Sample shading state.
1213 if (contextSupports(type, ApiType::core(4,0)))
1214 {
1215 gl.minSampleShading(0.0f);
1216 gl.disable(GL_SAMPLE_SHADING);
1217
1218 GLU_EXPECT_NO_ERROR(gl.getError(), "Sample shading state reset failed");
1219 }
1220
1221 // Debug state
1222 if (ctxInfo.isExtensionSupported("GL_KHR_debug"))
1223 {
1224 const bool entrypointsPresent = gl.debugMessageControl != DE_NULL &&
1225 gl.debugMessageCallback != DE_NULL;
1226
1227 // some drivers advertise GL_KHR_debug but give out null pointers. Silently ignore.
1228 if (entrypointsPresent)
1229 {
1230 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, DE_NULL, true);
1231 gl.debugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, DE_NULL, false);
1232 gl.debugMessageCallback(DE_NULL, DE_NULL);
1233
1234 if (type.getFlags() & glu::CONTEXT_DEBUG)
1235 gl.enable(GL_DEBUG_OUTPUT);
1236 else
1237 gl.disable(GL_DEBUG_OUTPUT);
1238 }
1239 }
1240 }
1241
resetState(const RenderContext & renderCtx,const ContextInfo & ctxInfo)1242 void resetState (const RenderContext& renderCtx, const ContextInfo& ctxInfo)
1243 {
1244 if (isContextTypeES(renderCtx.getType()))
1245 resetStateES(renderCtx, ctxInfo);
1246 else if (isContextTypeGLCore(renderCtx.getType()))
1247 resetStateGLCore(renderCtx, ctxInfo);
1248 else if (isContextTypeGLCompatibility(renderCtx.getType())) {
1249 // TODO: handle reset state correctly for compatibility profile
1250 resetStateGLCore(renderCtx, ctxInfo);
1251 } else
1252 throw tcu::InternalError("State reset requested for unsupported context type");
1253 }
1254
1255 } // glu
1256