• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
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
22  */ /*-------------------------------------------------------------------*/
23 
24 /* Includes. */
25 #include "gl4cES31CompatibilityTests.hpp"
26 #include "gluContextInfo.hpp"
27 #include "gluDefs.hpp"
28 #include "gluRenderContext.hpp"
29 #include "gluStrUtil.hpp"
30 #include "tcuTestLog.hpp"
31 
32 /******************************** Test Group Implementation       ********************************/
33 
34 /** @brief ES3.1 Compatibility tests group constructor.
35  *
36  *  @param [in] context     OpenGL context.
37  */
Tests(deqp::Context & context)38 gl4cts::es31compatibility::Tests::Tests(deqp::Context& context)
39 	: TestCaseGroup(context, "es_31_compatibility", "ES3.1 Compatibility Test Suite")
40 {
41 	/* Intentionally left blank */
42 }
43 
44 /** @brief ES3.1 Compatibility Tests initializer. */
init()45 void gl4cts::es31compatibility::Tests::init()
46 {
47 	/* New tests. */
48 	addChild(new gl4cts::es31compatibility::ShaderCompilationCompatibilityTests(m_context));
49 	addChild(new gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest(m_context));
50 
51 	/* Ported tests. */
52 	addChild(new gl4cts::es31compatibility::SampleVariablesTests(m_context, glu::GLSL_VERSION_310_ES));
53 	addChild(new gl4cts::es31compatibility::ShaderImageLoadStoreTests(m_context));
54 	addChild(new gl4cts::es31compatibility::ShaderStorageBufferObjectTests(m_context));
55 }
56 
57 /******************************** Shader Compilation Compatibility Tests Implementation   ********************************/
58 
59 /** @brief ShaderCompilationCompatibilityTests constructor.
60  *
61  *  @param [in] context     OpenGL context.
62  */
ShaderCompilationCompatibilityTests(deqp::Context & context)63 gl4cts::es31compatibility::ShaderCompilationCompatibilityTests::ShaderCompilationCompatibilityTests(
64 	deqp::Context& context)
65 	: deqp::TestCase(context, "shader_compilation", "Shader Compilation Compatibility Test")
66 {
67 }
68 
69 /** @brief ShaderCompilationCompatibilityTests test cases iterations.
70  */
iterate()71 tcu::TestNode::IterateResult gl4cts::es31compatibility::ShaderCompilationCompatibilityTests::iterate()
72 {
73 	/* Shortcut for GL functionality. */
74 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
75 
76 	/* OpenGL support query. */
77 	bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
78 	bool is_arb_es31_compatibility = m_context.getContextInfo().isExtensionSupported("GL_ARB_ES3_1_compatibility");
79 
80 	/* Running tests. */
81 	bool is_ok	= true;
82 	bool is_error = false;
83 
84 	glw::GLuint shader = 0;
85 
86 	/* Test */
87 	try
88 	{
89 		if (is_at_least_gl_45 || is_arb_es31_compatibility)
90 		{
91 			for (glw::GLsizei i = 0; i < s_shaders_count; ++i)
92 			{
93 				/* Shader compilation. */
94 				shader = gl.createShader(s_shaders[i].type);
95 
96 				GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
97 
98 				if (0 == shader)
99 				{
100 					throw 0;
101 				}
102 
103 				gl.shaderSource(shader, 1, &(s_shaders[i].source), NULL);
104 
105 				GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
106 
107 				gl.compileShader(shader);
108 
109 				GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
110 
111 				/* Checking for errors. */
112 				glw::GLint status = GL_FALSE;
113 
114 				gl.getShaderiv(shader, GL_COMPILE_STATUS, &status);
115 				GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
116 
117 				if (GL_FALSE == status)
118 				{
119 					/* Setup result. */
120 					is_ok = false;
121 
122 					/* Getting compilation informations. */
123 					glw::GLint log_size = 0;
124 
125 					gl.getShaderiv(shader, GL_INFO_LOG_LENGTH, &log_size);
126 
127 					GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
128 
129 					if (log_size)
130 					{
131 						glw::GLchar* log = new glw::GLchar[log_size];
132 
133 						if (log)
134 						{
135 							memset(log, 0, log_size);
136 
137 							gl.getShaderInfoLog(shader, log_size, DE_NULL, log);
138 
139 							/* Logging. */
140 							m_context.getTestContext().getLog() << tcu::TestLog::Message << "Compilation of "
141 																<< s_shaders[i].type_name
142 																<< " shader have failed.\n Shader source was:\n"
143 																<< s_shaders[i].source << "\nCompillation log:\n"
144 																<< log << tcu::TestLog::EndMessage;
145 
146 							delete[] log;
147 
148 							GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog() call failed.");
149 						}
150 					}
151 				}
152 
153 				/* Cleanup. */
154 				gl.deleteShader(shader);
155 
156 				shader = 0;
157 
158 				GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteShader call failed.");
159 			}
160 		}
161 	}
162 	catch (...)
163 	{
164 		is_ok	= false;
165 		is_error = true;
166 	}
167 
168 	/* Cleanup. */
169 	if (0 != shader)
170 	{
171 		gl.deleteShader(shader);
172 
173 		shader = 0;
174 	}
175 
176 	/* Result's setup and logging. */
177 	if (is_ok)
178 	{
179 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
180 	}
181 	else
182 	{
183 		if (is_error)
184 		{
185 			m_context.getTestContext().getLog() << tcu::TestLog::Message
186 												<< "Internal error has occured during the Shader Version Test."
187 												<< tcu::TestLog::EndMessage;
188 
189 			m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Test error.");
190 		}
191 		else
192 		{
193 			m_context.getTestContext().getLog() << tcu::TestLog::Message << "The Shader Version Test has failed."
194 												<< tcu::TestLog::EndMessage;
195 
196 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
197 		}
198 	}
199 
200 	return STOP;
201 }
202 
203 const gl4cts::es31compatibility::ShaderCompilationCompatibilityTests::TestShader
204 	gl4cts::es31compatibility::ShaderCompilationCompatibilityTests::s_shaders[] = {
205 		{ /* Shader for testing ES 3.1 version string support.*/
206 		  GL_VERTEX_SHADER, "vertex", "#version 310 es\n"
207 									  "\n"
208 									  "void main()\n"
209 									  "{\n"
210 									  "    gl_Position = vec4(1.0);\n"
211 									  "}\n" },
212 		{ /* Shader for testing ES 3.1 version string support.*/
213 		  GL_FRAGMENT_SHADER, "fragment", "#version 310 es\n"
214 										  "\n"
215 										  "out highp vec4 color;"
216 										  "\n"
217 										  "void main()\n"
218 										  "{\n"
219 										  "    color = vec4(1.0);\n"
220 										  "}\n" },
221 		{ /* Shader for testing that gl_HelperInvocation variable is supported.*/
222 		  GL_FRAGMENT_SHADER, "fragment", "#version 310 es\n"
223 										  "\n"
224 										  "out highp vec4 color;"
225 										  "\n"
226 										  "void main()\n"
227 										  "{\n"
228 										  "    if(gl_HelperInvocation)\n"
229 										  "    {\n"
230 										  "        color = vec4(1.0);\n"
231 										  "    }\n"
232 										  "    else\n"
233 										  "    {\n"
234 										  "        color = vec4(0.0);\n"
235 										  "    }\n"
236 										  "}\n" },
237 		{ /* Shader for testing ES 3.1 version string support.*/
238 		  GL_COMPUTE_SHADER, "compute",
239 		  "#version 310 es\n"
240 		  "\n"
241 		  "layout(local_size_x = 128) in;\n"
242 		  "layout(std140, binding = 0) buffer Output\n"
243 		  "{\n"
244 		  "    uint elements[];\n"
245 		  "} output_data;\n"
246 		  "\n"
247 		  "void main()\n"
248 		  "{\n"
249 		  "    output_data.elements[gl_GlobalInvocationID.x] = gl_GlobalInvocationID.x * gl_GlobalInvocationID.x;\n"
250 		  "}\n" }
251 	};
252 
253 const glw::GLsizei gl4cts::es31compatibility::ShaderCompilationCompatibilityTests::s_shaders_count =
254 	sizeof(s_shaders) / sizeof(s_shaders[0]);
255 
256 /******************************** Shader Functional Compatibility Test Implementation   ********************************/
257 
258 /** @brief Shader Functional Compatibility Test constructor.
259  *
260  *  @param [in] context     OpenGL context.
261  */
ShaderFunctionalCompatibilityTest(deqp::Context & context)262 gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::ShaderFunctionalCompatibilityTest(deqp::Context& context)
263 	: deqp::TestCase(context, "shader_functional", "Shader Functional Compatibility Test")
264 	, m_po_id(0)
265 	, m_fbo_id(0)
266 	, m_rbo_id(0)
267 	, m_vao_id(0)
268 {
269 }
270 
271 /** @brief ShaderCompilationCompatibilityTests test cases iterations.
272  */
iterate()273 tcu::TestNode::IterateResult gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::iterate()
274 {
275 	/* OpenGL support query. */
276 	bool is_at_least_gl_45 = (glu::contextSupports(m_context.getRenderContext().getType(), glu::ApiType::core(4, 5)));
277 	bool is_arb_es31_compatibility = m_context.getContextInfo().isExtensionSupported("GL_ARB_ES3_1_compatibility");
278 
279 	/* Running tests. */
280 	bool is_ok	= true;
281 	bool is_error = false;
282 
283 	/* Test */
284 	try
285 	{
286 		if (is_at_least_gl_45 || is_arb_es31_compatibility)
287 		{
288 			createFramebufferAndVertexArrayObject();
289 
290 			for (glw::GLsizei i = 0; i < s_shaders_count; ++i)
291 			{
292 				if (!createProgram(s_shaders[i]))
293 				{
294 					is_ok = false;
295 
296 					continue; /* if createProgram failed we shall omit this iteration */
297 				}
298 
299 				is_ok &= test();
300 
301 				cleanProgram();
302 			}
303 
304 			cleanFramebufferAndVertexArrayObject();
305 		}
306 	}
307 	catch (...)
308 	{
309 		/* Result setup. */
310 		is_ok	= false;
311 		is_error = true;
312 
313 		/* Cleanup. */
314 		cleanProgram();
315 		cleanFramebufferAndVertexArrayObject();
316 	}
317 
318 	/* Result's setup. */
319 	if (is_ok)
320 	{
321 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
322 	}
323 	else
324 	{
325 		if (is_error)
326 		{
327 			m_context.getTestContext().getLog() << tcu::TestLog::Message
328 												<< "Internal error has occured during the Shader Version Test."
329 												<< tcu::TestLog::EndMessage;
330 
331 			m_testCtx.setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, "Test error.");
332 		}
333 		else
334 		{
335 			m_context.getTestContext().getLog() << tcu::TestLog::Message << "The Shader Version Test has failed."
336 												<< tcu::TestLog::EndMessage;
337 
338 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
339 		}
340 	}
341 
342 	return STOP;
343 }
344 
345 /** @brief Create program object
346  *
347  *  @note Program object is going to be stored into m_po_id.
348  *        If building succeeded program will be set current (glUseProgram).
349  *
350  *  @param [in] shader_source   Shader source to be builded.
351  *
352  *  @return True if succeeded, false otherwise.
353  */
createProgram(const struct Shader shader_source)354 bool gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::createProgram(const struct Shader shader_source)
355 {
356 	/* Shortcut for GL functionality. */
357 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
358 
359 	struct _Shader
360 	{
361 		const glw::GLchar* const* source;
362 		const glw::GLenum		  type;
363 		glw::GLuint				  id;
364 	} shader[] = { { shader_source.vertex, GL_VERTEX_SHADER, 0 }, { shader_source.fragment, GL_FRAGMENT_SHADER, 0 } };
365 
366 	glw::GLuint const shader_count = sizeof(shader) / sizeof(shader[0]);
367 
368 	try
369 	{
370 		/* Make sure m_po_id is cleaned. */
371 		if (m_po_id)
372 		{
373 			cleanProgram();
374 		}
375 
376 		/* Create program. */
377 		m_po_id = gl.createProgram();
378 		GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateProgram call failed.");
379 
380 		/* Shader compilation. */
381 
382 		for (glw::GLuint i = 0; i < shader_count; ++i)
383 		{
384 			if (DE_NULL != shader[i].source)
385 			{
386 				shader[i].id = gl.createShader(shader[i].type);
387 
388 				GLU_EXPECT_NO_ERROR(gl.getError(), "glCreateShader call failed.");
389 
390 				gl.attachShader(m_po_id, shader[i].id);
391 
392 				GLU_EXPECT_NO_ERROR(gl.getError(), "glAttachShader call failed.");
393 
394 				gl.shaderSource(shader[i].id, 3, shader[i].source, NULL);
395 
396 				GLU_EXPECT_NO_ERROR(gl.getError(), "glShaderSource call failed.");
397 
398 				gl.compileShader(shader[i].id);
399 
400 				GLU_EXPECT_NO_ERROR(gl.getError(), "glCompileShader call failed.");
401 
402 				glw::GLint status = GL_FALSE;
403 
404 				gl.getShaderiv(shader[i].id, GL_COMPILE_STATUS, &status);
405 				GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv call failed.");
406 
407 				if (GL_FALSE == status)
408 				{
409 					glw::GLint log_size = 0;
410 
411 					gl.getShaderiv(shader[i].id, GL_INFO_LOG_LENGTH, &log_size);
412 
413 					GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderiv() call failed.");
414 
415 					if (log_size)
416 					{
417 						glw::GLchar* log = new glw::GLchar[log_size];
418 
419 						if (log)
420 						{
421 							memset(log, 0, log_size);
422 
423 							gl.getShaderInfoLog(shader[i].id, log_size, DE_NULL, log);
424 
425 							m_context.getTestContext().getLog()
426 								<< tcu::TestLog::Message << "Compilation of shader has failed.\nShader source:\n"
427 								<< shader[i].source[0] << shader[i].source[1] << shader[i].source[2]
428 								<< "\nCompillation log:\n"
429 								<< log << tcu::TestLog::EndMessage;
430 
431 							delete[] log;
432 
433 							GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog() call failed.");
434 						}
435 					}
436 
437 					throw 0;
438 				}
439 			}
440 		}
441 
442 		/* Link. */
443 		gl.linkProgram(m_po_id);
444 
445 		GLU_EXPECT_NO_ERROR(gl.getError(), "glLinkProgram call failed.");
446 
447 		glw::GLint status = GL_FALSE;
448 
449 		gl.getProgramiv(m_po_id, GL_LINK_STATUS, &status);
450 
451 		if (GL_TRUE == status)
452 		{
453 			for (glw::GLuint i = 0; i < shader_count; ++i)
454 			{
455 				if (shader[i].id)
456 				{
457 					gl.detachShader(m_po_id, shader[i].id);
458 
459 					GLU_EXPECT_NO_ERROR(gl.getError(), "glDetachShader call failed.");
460 				}
461 			}
462 		}
463 		else
464 		{
465 			glw::GLint log_size = 0;
466 
467 			gl.getProgramiv(m_po_id, GL_INFO_LOG_LENGTH, &log_size);
468 
469 			GLU_EXPECT_NO_ERROR(gl.getError(), "glGetProgramiv() call failed.");
470 
471 			if (log_size)
472 			{
473 				glw::GLchar* log = new glw::GLchar[log_size];
474 
475 				if (log)
476 				{
477 					memset(log, 0, log_size);
478 
479 					gl.getProgramInfoLog(m_po_id, log_size, DE_NULL, log);
480 
481 					m_context.getTestContext().getLog() << tcu::TestLog::Message
482 														<< "Linkage of shader program has failed.\nLinkage log:\n"
483 														<< log << tcu::TestLog::EndMessage;
484 
485 					delete[] log;
486 
487 					GLU_EXPECT_NO_ERROR(gl.getError(), "glGetShaderInfoLog() call failed.");
488 				}
489 			}
490 
491 			throw 0;
492 		}
493 	}
494 	catch (...)
495 	{
496 		if (m_po_id)
497 		{
498 			gl.deleteProgram(m_po_id);
499 
500 			m_po_id = 0;
501 		}
502 	}
503 
504 	for (glw::GLuint i = 0; i < shader_count; ++i)
505 	{
506 		if (0 != shader[i].id)
507 		{
508 			gl.deleteShader(shader[i].id);
509 
510 			shader[i].id = 0;
511 		}
512 	}
513 
514 	if (m_po_id)
515 	{
516 		gl.useProgram(m_po_id);
517 
518 		GLU_EXPECT_NO_ERROR(gl.getError(), "glUseProgram call failed.");
519 
520 		return true;
521 	}
522 
523 	return false;
524 }
525 
526 /** @brief Create framebuffer and vertex array object.
527  *
528  *  @note Frembuffer will be stored in m_fbo_id and m_rbo_id.
529  *        Vertex array object will be stored in m_vao_id.
530  *        Function will throw 0 if erro has occured.
531  */
createFramebufferAndVertexArrayObject()532 void gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::createFramebufferAndVertexArrayObject()
533 {
534 	/* Shortcut for GL functionality. */
535 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
536 
537 	/* Prepare framebuffer. */
538 	gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
539 	GLU_EXPECT_NO_ERROR(gl.getError(), "glClearColor call failed.");
540 
541 	gl.genFramebuffers(1, &m_fbo_id);
542 	GLU_EXPECT_NO_ERROR(gl.getError(), "glGenFramebuffers call failed.");
543 
544 	gl.genRenderbuffers(1, &m_rbo_id);
545 	GLU_EXPECT_NO_ERROR(gl.getError(), "glGenRenderbuffers call failed.");
546 
547 	gl.bindFramebuffer(GL_FRAMEBUFFER, m_fbo_id);
548 	GLU_EXPECT_NO_ERROR(gl.getError(), "glBindFramebuffer call failed.");
549 
550 	gl.bindRenderbuffer(GL_RENDERBUFFER, m_rbo_id);
551 	GLU_EXPECT_NO_ERROR(gl.getError(), "glBindRenderbuffer call failed.");
552 
553 	gl.renderbufferStorage(GL_RENDERBUFFER, GL_R8, 1 /* x size */, 1 /* y size */);
554 	GLU_EXPECT_NO_ERROR(gl.getError(), "glRenderbufferStorage call failed.");
555 
556 	gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_rbo_id);
557 	GLU_EXPECT_NO_ERROR(gl.getError(), "glFramebufferRenderbuffer call failed.");
558 
559 	/* Check if all went ok. */
560 	if (gl.checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
561 	{
562 		throw 0;
563 	}
564 
565 	/* View Setup. */
566 	gl.viewport(0, 0, 1 /* x size */, 1 /* y size */);
567 	GLU_EXPECT_NO_ERROR(gl.getError(), "glViewport call failed.");
568 
569 	/* Create and bind empty vertex array object. */
570 	gl.genVertexArrays(1, &m_vao_id);
571 	GLU_EXPECT_NO_ERROR(gl.getError(), "glGenVertexArrays() call failed.");
572 
573 	if (0 == m_vao_id)
574 	{
575 		throw 0;
576 	}
577 
578 	gl.bindVertexArray(m_vao_id);
579 	GLU_EXPECT_NO_ERROR(gl.getError(), "glBindVertexArray() call failed.");
580 }
581 
582 /** @brief Run test case.
583  *
584  *  @note Test case run in following order:
585  *         *  clear screen with 0 value (color setup in createFramebufferAndVertexArrayObject);
586  *         *  draw full screen quad;
587  *         *  fetch pixel from screen using glReadPixel (view is 1x1 pixel in size);
588  *         *  compare results (1.0f is expected as the result of the shader).
589  */
test()590 bool gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::test()
591 {
592 	/* Shortcut for GL functionality. */
593 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
594 
595 	/* Make sure objects are cleaned. */
596 	if (m_fbo_id || m_rbo_id || m_vao_id)
597 	{
598 		cleanFramebufferAndVertexArrayObject();
599 	}
600 
601 	/* Drawing quad which shall output result. */
602 	gl.clear(GL_COLOR_BUFFER_BIT);
603 	GLU_EXPECT_NO_ERROR(gl.getError(), "glClear() call failed.");
604 
605 	gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4);
606 	GLU_EXPECT_NO_ERROR(gl.getError(), "glDrawArrays() call failed.");
607 
608 	/* Fetching result. */
609 	glw::GLfloat red = -1.f;
610 
611 	gl.readPixels(0, 0, 1, 1, GL_RED, GL_FLOAT, &red);
612 	GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels() call failed.");
613 
614 	if (de::abs(1.f - red) <= 0.125 /* Precision. */)
615 	{
616 		return true;
617 	}
618 
619 	return false;
620 }
621 
622 /** @brief Release program object.
623  */
cleanProgram()624 void gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::cleanProgram()
625 {
626 	/* Shortcut for GL functionality. */
627 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
628 
629 	/* Deleting program. */
630 	if (m_po_id)
631 	{
632 		gl.useProgram(0);
633 
634 		gl.deleteProgram(m_po_id);
635 
636 		m_po_id = 0;
637 	}
638 }
639 
640 /** @brief Release framebuffer, renderbuffer and vertex array objects.
641  */
cleanFramebufferAndVertexArrayObject()642 void gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::cleanFramebufferAndVertexArrayObject()
643 {
644 	/* Shortcut for GL functionality. */
645 	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
646 
647 	/* Deleting view. */
648 	if (m_fbo_id)
649 	{
650 		gl.deleteFramebuffers(1, &m_fbo_id);
651 
652 		m_fbo_id = 0;
653 	}
654 
655 	if (m_rbo_id)
656 	{
657 		gl.deleteRenderbuffers(1, &m_rbo_id);
658 
659 		m_rbo_id = 0;
660 	}
661 
662 	if (m_vao_id)
663 	{
664 		gl.deleteVertexArrays(1, &m_vao_id);
665 
666 		m_vao_id = 0;
667 	}
668 }
669 
670 const glw::GLchar* gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::s_shader_version = "#version 310 es\n";
671 
672 const glw::GLchar* gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::s_vertex_shader_body =
673 	"\n"
674 	"out highp float dummy;\n"
675 	"\n"
676 	"void main()\n"
677 	"{\n"
678 	"    switch(gl_VertexID % 4)\n"
679 	"    {\n"
680 	"    case 0:\n"
681 	"       gl_Position = vec4(-1.0, -1.0,  0.0,  1.0);\n"
682 	"       break;\n"
683 	"    case 1:\n"
684 	"       gl_Position = vec4( 1.0, -1.0,  0.0,  1.0);\n"
685 	"       break;\n"
686 	"    case 2:\n"
687 	"       gl_Position = vec4(-1.0,  1.0,  0.0,  1.0);\n"
688 	"       break;\n"
689 	"    case 3:\n"
690 	"       gl_Position = vec4( 1.0,  1.0,  0.0,  1.0);\n"
691 	"       break;\n"
692 	"    }\n"
693 	"\n"
694 	"    dummy = float(gl_VertexID % 4);\n   /* Always less than 4. */"
695 	"}\n";
696 
697 const glw::GLchar* gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::s_fragment_shader_body =
698 	"\n"
699 	"in highp float dummy;\n"
700 	"\n"
701 	"out highp vec4 result;\n"
702 	"\n"
703 	"void main()\n"
704 	"{\n"
705 	"    TTYPE a = LEFT;\n"
706 	"    TTYPE b = RIGHT;\n"
707 	"    BTYPE c = BDATA && BTYPE(dummy < 4.0);\n    /* Making sure that expression is not compile time constant. */"
708 	"\n"
709 	"    TTYPE mixed = mix(a, b, c);\n"
710 	"\n"
711 	"    if(REFERENCE == mixed)\n"
712 	"    {\n"
713 	"        result = vec4(1.0);\n"
714 	"    }\n"
715 	"    else\n"
716 	"    {\n"
717 	"        result = vec4(0.0);\n"
718 	"    }\n"
719 	"}\n";
720 
721 const struct gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::Shader
722 	gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::s_shaders[] = {
723 		{ { s_shader_version, "", s_vertex_shader_body },
724 		  { s_shader_version, "#define TTYPE        highp int\n"
725 							  "#define BTYPE        bool\n"
726 							  "#define LEFT        -1\n"
727 							  "#define RIGHT       -2\n"
728 							  "#define BDATA        true\n"
729 							  "#define REFERENCE   -2\n",
730 			s_fragment_shader_body } },
731 		{ { s_shader_version, "", s_vertex_shader_body },
732 		  { s_shader_version, "#define TTYPE        highp uint\n"
733 							  "#define BTYPE        bool\n"
734 							  "#define LEFT         1u\n"
735 							  "#define RIGHT        2u\n"
736 							  "#define BDATA        true\n"
737 							  "#define REFERENCE    2u\n",
738 			s_fragment_shader_body } },
739 		{ { s_shader_version, "", s_vertex_shader_body },
740 		  { s_shader_version, "#define TTYPE        mediump int\n"
741 							  "#define BTYPE        bool\n"
742 							  "#define LEFT        -1\n"
743 							  "#define RIGHT       -2\n"
744 							  "#define BDATA        true\n"
745 							  "#define REFERENCE   -2\n",
746 			s_fragment_shader_body } },
747 		{ { s_shader_version, "", s_vertex_shader_body },
748 		  { s_shader_version, "#define TTYPE        mediump uint\n"
749 							  "#define BTYPE        bool\n"
750 							  "#define LEFT         1u\n"
751 							  "#define RIGHT        2u\n"
752 							  "#define BDATA        true\n"
753 							  "#define REFERENCE    2u\n",
754 			s_fragment_shader_body } },
755 		{ { s_shader_version, "", s_vertex_shader_body },
756 		  { s_shader_version, "#define TTYPE        lowp int\n"
757 							  "#define BTYPE        bool\n"
758 							  "#define LEFT        -1\n"
759 							  "#define RIGHT       -2\n"
760 							  "#define BDATA        true\n"
761 							  "#define REFERENCE   -2\n",
762 			s_fragment_shader_body } },
763 		{ { s_shader_version, "", s_vertex_shader_body },
764 		  { s_shader_version, "#define TTYPE        lowp uint\n"
765 							  "#define BTYPE        bool\n"
766 							  "#define LEFT         1u\n"
767 							  "#define RIGHT        2u\n"
768 							  "#define BDATA        true\n"
769 							  "#define REFERENCE    2u\n",
770 			s_fragment_shader_body } },
771 		{ { s_shader_version, "", s_vertex_shader_body },
772 		  { s_shader_version, "#define TTYPE        bool\n"
773 							  "#define BTYPE        bool\n"
774 							  "#define LEFT         false\n"
775 							  "#define RIGHT        true\n"
776 							  "#define BDATA        true\n"
777 							  "#define REFERENCE    true\n",
778 			s_fragment_shader_body } },
779 		{ { s_shader_version, "", s_vertex_shader_body },
780 		  { s_shader_version, "#define TTYPE        highp ivec2\n"
781 							  "#define BTYPE        bvec2\n"
782 							  "#define LEFT         ivec2(-1, -2)\n"
783 							  "#define RIGHT        ivec2(-3, -4)\n"
784 							  "#define BDATA        bvec2(true, false)\n"
785 							  "#define REFERENCE    ivec2(-3, -2)\n",
786 			s_fragment_shader_body } },
787 		{ { s_shader_version, "", s_vertex_shader_body },
788 		  { s_shader_version, "#define TTYPE        highp uvec2\n"
789 							  "#define BTYPE        bvec2\n"
790 							  "#define LEFT         uvec2(1, 2)\n"
791 							  "#define RIGHT        uvec2(3, 4)\n"
792 							  "#define BDATA        bvec2(true, false)\n"
793 							  "#define REFERENCE    uvec2(3, 2)\n",
794 			s_fragment_shader_body } },
795 		{ { s_shader_version, "", s_vertex_shader_body },
796 		  { s_shader_version, "#define TTYPE        mediump ivec2\n"
797 							  "#define BTYPE        bvec2\n"
798 							  "#define LEFT         ivec2(-1, -2)\n"
799 							  "#define RIGHT        ivec2(-3, -4)\n"
800 							  "#define BDATA        bvec2(true, false)\n"
801 							  "#define REFERENCE    ivec2(-3, -2)\n",
802 			s_fragment_shader_body } },
803 		{ { s_shader_version, "", s_vertex_shader_body },
804 		  { s_shader_version, "#define TTYPE        mediump uvec2\n"
805 							  "#define BTYPE        bvec2\n"
806 							  "#define LEFT         uvec2(1, 2)\n"
807 							  "#define RIGHT        uvec2(3, 4)\n"
808 							  "#define BDATA        bvec2(true, false)\n"
809 							  "#define REFERENCE    uvec2(3, 2)\n",
810 			s_fragment_shader_body } },
811 		{ { s_shader_version, "", s_vertex_shader_body },
812 		  { s_shader_version, "#define TTYPE        lowp ivec2\n"
813 							  "#define BTYPE        bvec2\n"
814 							  "#define LEFT         ivec2(-1, -2)\n"
815 							  "#define RIGHT        ivec2(-3, -4)\n"
816 							  "#define BDATA        bvec2(true, false)\n"
817 							  "#define REFERENCE    ivec2(-3, -2)\n",
818 			s_fragment_shader_body } },
819 		{ { s_shader_version, "", s_vertex_shader_body },
820 		  { s_shader_version, "#define TTYPE        lowp uvec2\n"
821 							  "#define BTYPE        bvec2\n"
822 							  "#define LEFT         uvec2(1, 2)\n"
823 							  "#define RIGHT        uvec2(3, 4)\n"
824 							  "#define BDATA        bvec2(true, false)\n"
825 							  "#define REFERENCE    uvec2(3, 2)\n",
826 			s_fragment_shader_body } },
827 		{ { s_shader_version, "", s_vertex_shader_body },
828 		  { s_shader_version, "#define TTYPE        bvec2\n"
829 							  "#define BTYPE        bvec2\n"
830 							  "#define LEFT         bvec2(true,  true)\n"
831 							  "#define RIGHT        bvec2(false, false)\n"
832 							  "#define BDATA        bvec2(true,  false)\n"
833 							  "#define REFERENCE    bvec2(false, true)\n",
834 			s_fragment_shader_body } },
835 		{ { s_shader_version, "", s_vertex_shader_body },
836 		  { s_shader_version, "#define TTYPE        highp ivec3\n"
837 							  "#define BTYPE        bvec3\n"
838 							  "#define LEFT         ivec3(-1, -2, -3)\n"
839 							  "#define RIGHT        ivec3(-4, -5, -6)\n"
840 							  "#define BDATA        bvec3(true, false, true)\n"
841 							  "#define REFERENCE    ivec3(-4, -2, -6)\n",
842 			s_fragment_shader_body } },
843 		{ { s_shader_version, "", s_vertex_shader_body },
844 		  { s_shader_version, "#define TTYPE        highp uvec3\n"
845 							  "#define BTYPE        bvec3\n"
846 							  "#define LEFT         uvec3(1, 2, 3)\n"
847 							  "#define RIGHT        uvec3(4, 5, 6)\n"
848 							  "#define BDATA        bvec3(true, false, true)\n"
849 							  "#define REFERENCE    uvec3(4, 2, 6)\n",
850 			s_fragment_shader_body } },
851 		{ { s_shader_version, "", s_vertex_shader_body },
852 		  { s_shader_version, "#define TTYPE        mediump ivec3\n"
853 							  "#define BTYPE        bvec3\n"
854 							  "#define LEFT         ivec3(-1, -2, -3)\n"
855 							  "#define RIGHT        ivec3(-4, -5, -6)\n"
856 							  "#define BDATA        bvec3(true, false, true)\n"
857 							  "#define REFERENCE    ivec3(-4, -2, -6)\n",
858 			s_fragment_shader_body } },
859 		{ { s_shader_version, "", s_vertex_shader_body },
860 		  { s_shader_version, "#define TTYPE        mediump uvec3\n"
861 							  "#define BTYPE        bvec3\n"
862 							  "#define LEFT         uvec3(1, 2, 3)\n"
863 							  "#define RIGHT        uvec3(4, 5, 6)\n"
864 							  "#define BDATA        bvec3(true, false, true)\n"
865 							  "#define REFERENCE    uvec3(4, 2, 6)\n",
866 			s_fragment_shader_body } },
867 		{ { s_shader_version, "", s_vertex_shader_body },
868 		  { s_shader_version, "#define TTYPE        lowp ivec3\n"
869 							  "#define BTYPE        bvec3\n"
870 							  "#define LEFT         ivec3(-1, -2, -3)\n"
871 							  "#define RIGHT        ivec3(-4, -5, -6)\n"
872 							  "#define BDATA        bvec3(true, false, true)\n"
873 							  "#define REFERENCE    ivec3(-4, -2, -6)\n",
874 			s_fragment_shader_body } },
875 		{ { s_shader_version, "", s_vertex_shader_body },
876 		  { s_shader_version, "#define TTYPE        lowp uvec3\n"
877 							  "#define BTYPE        bvec3\n"
878 							  "#define LEFT         uvec3(1, 2, 3)\n"
879 							  "#define RIGHT        uvec3(4, 5, 6)\n"
880 							  "#define BDATA        bvec3(true, false, true)\n"
881 							  "#define REFERENCE    uvec3(4, 2, 6)\n",
882 			s_fragment_shader_body } },
883 		{ { s_shader_version, "", s_vertex_shader_body },
884 		  { s_shader_version, "#define TTYPE        bvec3\n"
885 							  "#define BTYPE        bvec3\n"
886 							  "#define LEFT         bvec3(true,  true, true)\n"
887 							  "#define RIGHT        bvec3(false, false, false)\n"
888 							  "#define BDATA        bvec3(true,  false, true)\n"
889 							  "#define REFERENCE    bvec3(false, true, false)\n",
890 			s_fragment_shader_body } },
891 		{ { s_shader_version, "", s_vertex_shader_body },
892 		  { s_shader_version, "#define TTYPE        highp ivec4\n"
893 							  "#define BTYPE        bvec4\n"
894 							  "#define LEFT         ivec4(-1, -2, -3, -4)\n"
895 							  "#define RIGHT        ivec4(-5, -6, -7, -8)\n"
896 							  "#define BDATA        bvec4(true, false, true, false)\n"
897 							  "#define REFERENCE    ivec4(-5, -2, -7, -4)\n",
898 			s_fragment_shader_body } },
899 		{ { s_shader_version, "", s_vertex_shader_body },
900 		  { s_shader_version, "#define TTYPE        highp uvec4\n"
901 							  "#define BTYPE        bvec4\n"
902 							  "#define LEFT         uvec4(1, 2, 3, 4)\n"
903 							  "#define RIGHT        uvec4(5, 6, 7, 8)\n"
904 							  "#define BDATA        bvec4(true, false, true, false)\n"
905 							  "#define REFERENCE    uvec4(5, 2, 7, 4)\n",
906 			s_fragment_shader_body } },
907 		{ { s_shader_version, "", s_vertex_shader_body },
908 		  { s_shader_version, "#define TTYPE        mediump ivec4\n"
909 							  "#define BTYPE        bvec4\n"
910 							  "#define LEFT         ivec4(-1, -2, -3, -4)\n"
911 							  "#define RIGHT        ivec4(-5, -6, -7, -8)\n"
912 							  "#define BDATA        bvec4(true, false, true, false)\n"
913 							  "#define REFERENCE    ivec4(-5, -2, -7, -4)\n",
914 			s_fragment_shader_body } },
915 		{ { s_shader_version, "", s_vertex_shader_body },
916 		  { s_shader_version, "#define TTYPE        mediump uvec4\n"
917 							  "#define BTYPE        bvec4\n"
918 							  "#define LEFT         uvec4(1, 2, 3, 4)\n"
919 							  "#define RIGHT        uvec4(5, 6, 7, 8)\n"
920 							  "#define BDATA        bvec4(true, false, true, false)\n"
921 							  "#define REFERENCE    uvec4(5, 2, 7, 4)\n",
922 			s_fragment_shader_body } },
923 		{ { s_shader_version, "", s_vertex_shader_body },
924 		  { s_shader_version, "#define TTYPE        lowp ivec4\n"
925 							  "#define BTYPE        bvec4\n"
926 							  "#define LEFT         ivec4(-1, -2, -3, -4)\n"
927 							  "#define RIGHT        ivec4(-5, -6, -7, -8)\n"
928 							  "#define BDATA        bvec4(true, false, true, false)\n"
929 							  "#define REFERENCE    ivec4(-5, -2, -7, -4)\n",
930 			s_fragment_shader_body } },
931 		{ { s_shader_version, "", s_vertex_shader_body },
932 		  { s_shader_version, "#define TTYPE        lowp uvec4\n"
933 							  "#define BTYPE        bvec4\n"
934 							  "#define LEFT         uvec4(1, 2, 3, 4)\n"
935 							  "#define RIGHT        uvec4(5, 6, 7, 8)\n"
936 							  "#define BDATA        bvec4(true, false, true, false)\n"
937 							  "#define REFERENCE    uvec4(5, 2, 7, 4)\n",
938 			s_fragment_shader_body } },
939 		{ { s_shader_version, "", s_vertex_shader_body },
940 		  { s_shader_version, "#define TTYPE        bvec4\n"
941 							  "#define BTYPE        bvec4\n"
942 							  "#define LEFT         bvec4(true,  true,  true,  true)\n"
943 							  "#define RIGHT        bvec4(false, false, false, false)\n"
944 							  "#define BDATA        bvec4(true,  false, true,  false)\n"
945 							  "#define REFERENCE    bvec4(false, true,  false, true)\n",
946 			s_fragment_shader_body } }
947 	};
948 
949 const glw::GLsizei gl4cts::es31compatibility::ShaderFunctionalCompatibilityTest::s_shaders_count =
950 	sizeof(s_shaders) / sizeof(s_shaders[0]);
951