1/*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2014-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/**
25 */ /*!
26 * \file  es31cTextureStorageMultisampleTexStorage3DMultisampleTests.cpp
27 * \brief Implements conformance tests for glTexStorage3DMultisampleOES()
28 *        entry-points (ES3.1 only)
29 */ /*-------------------------------------------------------------------*/
30
31#include "es31cTextureStorageMultisampleTexStorage3DMultisampleTests.hpp"
32#include "gluContextInfo.hpp"
33#include "gluDefs.hpp"
34#include "glwEnums.hpp"
35#include "glwFunctions.hpp"
36#include "tcuRenderTarget.hpp"
37#include "tcuTestLog.hpp"
38
39#include <string>
40#include <vector>
41
42namespace glcts
43{
44/* Array holding color renderable internalformats used by the following tests:
45 * - "valid internalformat and samples values are accepted" test,
46 * - "requests to set up multisample color textures with unsupported number of samples are rejected" test.
47 */
48const glw::GLint color_renderable_internalformats[] = { GL_R8, GL_RGB565, GL_RGB10_A2UI, GL_SRGB8_ALPHA8, GL_R8I };
49
50/* Array holding depth renderable internalformats used by the following tests:
51 * - valid internalformat and samples values are accepted" test,
52 * - requests to set up multisample depth textures with unsupported number of samples are rejected" test.
53 */
54const glw::GLint depth_renderable_internalformats[] = { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT32F,
55														GL_DEPTH24_STENCIL8 };
56
57/* Array holding depth-stencil renderable internalformats used by the following tests:
58 * - valid internalformat and samples values are accepted" test,
59 * - requests to set up multisample stencil textures with unsupported number of samples are rejected" test.
60 */
61const glw::GLint depth_stencil_renderable_internalformats[] = { GL_DEPTH24_STENCIL8, GL_DEPTH32F_STENCIL8 };
62
63/* Array holding boolean values indicating possible fixed sample locations values. */
64const glw::GLboolean fixed_sample_locations_values[] = { GL_TRUE, GL_FALSE };
65
66/* Array holding supported internalformat values used by the following tests:
67 * - requests to set up multisample textures with valid and invalid number of samples" test.
68 */
69const glw::GLint supported_internalformats[] = { GL_R8,
70												 GL_RGB565,
71												 GL_RGB10_A2UI,
72												 GL_SRGB8_ALPHA8,
73												 GL_R8I,
74												 GL_DEPTH_COMPONENT16,
75												 GL_DEPTH_COMPONENT32F,
76												 GL_DEPTH24_STENCIL8,
77												 GL_DEPTH24_STENCIL8 };
78
79/* Array holding internalformats which are neither color-, stencil- nor depth-renderable,
80 * used by the following tests:
81 * - non color-, depth-, stencil-, renderable internalformats are rejected test.
82 */
83/* GL_SRGB8_ALPHA8 is renderable according to spec - replaced with GL_SRGB8 */
84/* GL_RGBA32F is renderable if EXT_color_buffer_float extension is supported - replaced with GL_RGB32F */
85/* GL_SRGB8 is renderable if extension NV_sRGB_formats is supported. */
86/* GL_R8_SNORM is renderable if extension EXT_render_snorm is supported - replace with GL_RGB8_SNORM*/
87const glw::GLint unsupported_internalformats[] = { GL_RGB8_SNORM, GL_RGB32F, GL_RGB32I };
88
89/** Constructor.
90 *
91 *  @param context CTS context handle.
92 **/
93InvalidTextureSizesAreRejectedValidAreAcceptedTest::InvalidTextureSizesAreRejectedValidAreAcceptedTest(Context& context)
94	: TestCase(context, "invalid_texture_sizes_are_rejected_valid_are_accepted_test",
95			   "Verifies gltexStorage3DMultisample() rejects invalid multisample "
96			   "texture sizes by generating GL_INVALID_VALUE error; border cases are correctly accepted.")
97	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
98	, max_texture_size(0)
99	, max_array_texture_layers(0)
100	, to_id_2d_array_1(0)
101	, to_id_2d_array_2(0)
102	, to_id_2d_array_3(0)
103{
104	/* Left blank on purpose */
105}
106
107/** Deinitializes ES objects created during test execution */
108void InvalidTextureSizesAreRejectedValidAreAcceptedTest::deinit()
109{
110	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
111
112	if (gl_oes_texture_multisample_2d_array_supported)
113	{
114		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
115		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
116	}
117
118	if (to_id_2d_array_1 != 0)
119	{
120		/* Delete texture object. */
121		gl.deleteTextures(1, &to_id_2d_array_1);
122
123		to_id_2d_array_1 = 0;
124	}
125
126	if (to_id_2d_array_2 != 0)
127	{
128		/* Delete texture object. */
129		gl.deleteTextures(1, &to_id_2d_array_2);
130
131		to_id_2d_array_2 = 0;
132	}
133
134	if (to_id_2d_array_3 != 0)
135	{
136		/* Delete texture object. */
137		gl.deleteTextures(1, &to_id_2d_array_3);
138
139		to_id_2d_array_3 = 0;
140	}
141
142	max_texture_size		 = 0;
143	max_array_texture_layers = 0;
144
145	/* Make sure no error was generated. */
146	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture objects deletion failed.");
147
148	/* Call base class' deinit() */
149	TestCase::deinit();
150}
151
152/** Initializes ES objects created during test execution */
153void InvalidTextureSizesAreRejectedValidAreAcceptedTest::initInternals()
154{
155	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
156
157	/* Generate first texture object. */
158	gl.genTextures(1, &to_id_2d_array_1);
159
160	/* Generate second texture object. */
161	gl.genTextures(1, &to_id_2d_array_2);
162
163	/* Generate third texture object. */
164	gl.genTextures(1, &to_id_2d_array_3);
165
166	/* Retrieve maximum 3D texture image dimensions. */
167	gl.getIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
168	gl.getIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &max_array_texture_layers);
169
170	/* Make sure no error was generated. */
171	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture objects creation failed.");
172}
173
174/** Executes test iteration.
175 *
176 *  @return Returns STOP when test has finished executing.
177 */
178tcu::TestNode::IterateResult InvalidTextureSizesAreRejectedValidAreAcceptedTest::iterate()
179{
180	gl_oes_texture_multisample_2d_array_supported =
181		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
182
183	if (!gl_oes_texture_multisample_2d_array_supported)
184	{
185		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
186
187		return STOP;
188	}
189
190	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
191
192	initInternals();
193
194	/* Check if texture objects were generated properly. */
195	TCU_CHECK_MSG(to_id_2d_array_1 != 0, "First texture object has not been generated.");
196	TCU_CHECK_MSG(to_id_2d_array_2 != 0, "Second texture object has not been generated.");
197	TCU_CHECK_MSG(to_id_2d_array_3 != 0, "Third texture object has not been generated.");
198
199	/* Make sure valid maximum 3d image dimensions were returned. */
200	TCU_CHECK_MSG(max_texture_size >= 2048, "Invalid GL_MAX_TEXTURE_SIZE was returned.");
201	TCU_CHECK_MSG(max_array_texture_layers >= 256, "Invalid GL_MAX_ARRAY_TEXTURE_LAYERS was returned.");
202
203	/* Bind texture object to_id_2d_array_1 to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
204	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id_2d_array_1);
205
206	/* Make sure no error was generated. */
207	glw::GLenum error_code = gl.getError();
208
209	GLU_EXPECT_NO_ERROR(error_code, "Unexpected error was generated when binding texture object to "
210									"GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target.");
211
212	/* Call gltexStorage3DMultisample() with invalid depth argument value (depth value cannot be negative). */
213	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 4, 4,
214							   0, /* Invalid depth argument value. */
215							   GL_TRUE);
216
217	/* Expect GL_INVALID_VALUE error code. */
218	error_code = gl.getError();
219
220	TCU_CHECK_MSG(error_code == GL_INVALID_VALUE,
221				  "gltexStorage3DMultisample() did not generate GL_INVALID_VALUE error.");
222
223	/* Call gltexStorage3DMultisample() with invalid depth argument value
224	 * (depth value cannot be greater than GL_MAX_TEXTURE_SIZE). */
225	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 4, 4,
226							   max_array_texture_layers + 1, /* Invalid depth argument value. */
227							   GL_TRUE);
228
229	/* Expect GL_INVALID_VALUE error code. */
230	error_code = gl.getError();
231
232	TCU_CHECK_MSG(error_code == GL_INVALID_VALUE,
233				  "gltexStorage3DMultisample() did not generate GL_INVALID_VALUE error.");
234
235	/* Set up a valid immutable 2D array multisample texture object using gltexStorage3DMultisample() call. */
236	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 4, 4, 1, GL_TRUE);
237
238	/* Make sure no error was generated. */
239	error_code = gl.getError();
240
241	GLU_EXPECT_NO_ERROR(error_code, "gltexStorage3DMultisample() reported unexpected error code.");
242
243	/* Bind texture object to_id_2d_array_2 to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
244	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id_2d_array_2);
245
246	/* Make sure no error was generated. */
247	error_code = gl.getError();
248
249	GLU_EXPECT_NO_ERROR(error_code, "Unexpected error was generated when binding texture object to "
250									"GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target.");
251
252	/* Set up a valid immutable 2D array multisample texture object using gltexStorage3DMultisample() call. */
253	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, 4, 4, max_array_texture_layers,
254							   GL_TRUE);
255
256	/* Make sure no error was generated. */
257	error_code = gl.getError();
258
259	GLU_EXPECT_NO_ERROR(error_code, "gltexStorage3DMultisample() reported unexpected error code.");
260
261	/* Bind texture object to_id_2d_array_3 to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
262	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id_2d_array_3);
263
264	/* Make sure no error was generated. */
265	error_code = gl.getError();
266
267	GLU_EXPECT_NO_ERROR(error_code, "Unexpected error was generated when binding texture object to "
268									"GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target.");
269
270	/* Call gltexStorage3DMultisample() with invalid width argument value
271	 * (width value cannot be greater than GL_MAX_3D_TEXTURE_SIZE). */
272	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8,
273							   max_texture_size + 1, /* Invalid width argument value. */
274							   max_texture_size, 2, GL_TRUE);
275
276	/* Expect GL_INVALID_VALUE error code. */
277	error_code = gl.getError();
278
279	TCU_CHECK_MSG(error_code == GL_INVALID_VALUE,
280				  "gltexStorage3DMultisample() did not generate GL_INVALID_VALUE error.");
281
282	/* Call gltexStorage3DMultisample() with invalid height argument value
283	 * (height value cannot be greater than GL_MAX_3D_TEXTURE_SIZE). */
284	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 2, GL_RGBA8, max_texture_size,
285							   max_texture_size + 1, /* Invalid height argument value. */
286							   2, GL_TRUE);
287
288	/* Expect GL_INVALID_VALUE error code. */
289	error_code = gl.getError();
290
291	TCU_CHECK_MSG(error_code == GL_INVALID_VALUE,
292				  "gltexStorage3DMultisample() did not generate GL_INVALID_VALUE error.");
293
294	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
295
296	return STOP;
297}
298
299/** Constructor.
300 *
301 *  @param context Rendering context handle.
302 **/
303MultisampleTextureTexStorage3DZeroSampleTest::MultisampleTextureTexStorage3DZeroSampleTest(Context& context)
304	: TestCase(context, "multisample_texture_tex_storage_3d_zero_sample",
305			   "Verifies TexStorage3DMultisample() rejects zero sample requests "
306			   "by generating a GL_INVALID_VALUE error.")
307	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
308	, to_id(0)
309{
310	/* Left blank on purpose */
311}
312
313/** Deinitializes ES objects created during test execution */
314void MultisampleTextureTexStorage3DZeroSampleTest::deinit()
315{
316	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
317
318	/* Unbind texture object bound to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES */
319	if (gl_oes_texture_multisample_2d_array_supported)
320	{
321		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
322	}
323
324	GLU_EXPECT_NO_ERROR(gl.getError(),
325						"Failed to unbind a texture object from GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target");
326
327	/* Delete texture object */
328	gl.deleteTextures(1, &to_id);
329
330	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete texture object");
331
332	to_id = 0;
333
334	/* Call base class deinitialization routine */
335	glcts::TestCase::deinit();
336}
337
338/** Initializes ES objects required for test execution */
339void MultisampleTextureTexStorage3DZeroSampleTest::initInternals()
340{
341	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
342
343	/* Generate texture object id */
344	gl.genTextures(1, &to_id);
345
346	GLU_EXPECT_NO_ERROR(gl.getError(), "glGenTextures() failed to generate texture");
347
348	/* Verify texture object has been generated properly */
349	if (to_id == 0)
350	{
351		TCU_FAIL("Texture object has not been generated properly");
352	}
353
354	/* Bind texture to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES */
355	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
356
357	GLU_EXPECT_NO_ERROR(gl.getError(), "glBindTexture() reported an error");
358}
359
360/** Executes test iteration.
361 *
362 *  @return Always STOP.
363 */
364tcu::TestNode::IterateResult MultisampleTextureTexStorage3DZeroSampleTest::iterate()
365{
366	gl_oes_texture_multisample_2d_array_supported =
367		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
368
369	if (!gl_oes_texture_multisample_2d_array_supported)
370	{
371		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
372
373		return STOP;
374	}
375
376	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
377
378	initInternals();
379
380	/* Issue call function for target GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES_, but provide zero for samples argument */
381	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0, GL_RGBA8, 1, 1, 1, true);
382
383	/* Check if the expected error code was reported */
384	glw::GLenum error_code = gl.getError();
385
386	if (error_code != GL_INVALID_VALUE)
387	{
388		TCU_FAIL("Invalid error code reported");
389	}
390
391	/* Test case passed */
392	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
393
394	return STOP;
395}
396
397/** Constructor.
398 *
399 *  @param context CTS context handle.
400 **/
401NonColorDepthStencilRenderableInternalformatsAreRejectedTest::
402	NonColorDepthStencilRenderableInternalformatsAreRejectedTest(Context& context)
403	: TestCase(context, "non_color_depth_stencil_renderable_internalformats_are_rejected_test",
404			   "Verifies gltexStorage3DMultisample() rejects internalformats which are not"
405			   " color-, depth-, nor stencil- renderable by generating GL_INVALID_ENUM error.")
406	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
407	, to_id(0)
408{
409	/* Left blank on purpose */
410}
411
412/** Deinitializes ES objects created during test execution */
413void NonColorDepthStencilRenderableInternalformatsAreRejectedTest::deinit()
414{
415	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
416
417	if (gl_oes_texture_multisample_2d_array_supported)
418	{
419		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
420		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
421	}
422	/* Delete texture object. */
423	gl.deleteTextures(1, &to_id);
424
425	to_id = 0;
426
427	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
428
429	/* Call base class' deinit() */
430	TestCase::deinit();
431}
432
433/** Initializes ES objects created during test execution */
434void NonColorDepthStencilRenderableInternalformatsAreRejectedTest::initInternals()
435{
436	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
437
438	/* Generate texture object id. */
439	gl.genTextures(1, &to_id);
440
441	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
442	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
443
444	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
445}
446
447/** Executes test iteration.
448 *
449 *  @return Returns STOP when test has finished executing.
450 */
451tcu::TestNode::IterateResult NonColorDepthStencilRenderableInternalformatsAreRejectedTest::iterate()
452{
453	gl_oes_texture_multisample_2d_array_supported =
454		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
455
456	if (!gl_oes_texture_multisample_2d_array_supported)
457	{
458		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
459
460		return STOP;
461	}
462
463	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
464
465	initInternals();
466
467	/* Check if texture object was generated properly. */
468	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
469
470	const int number_of_internalformats_to_check =
471		sizeof(unsupported_internalformats) / sizeof(unsupported_internalformats[0]);
472
473	/* Go through all requested internalformats. */
474	for (int internalformat_index = 0; internalformat_index < number_of_internalformats_to_check;
475		 internalformat_index++)
476	{
477		gl.texStorage3DMultisample(
478			GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 1,
479			unsupported_internalformats[internalformat_index], /* One of unsupported internalformats. */
480			1, 1, 1, true);
481
482		/* Expect GL_INVALID_ENUM error code. */
483		TCU_CHECK_MSG(gl.getError() == GL_INVALID_ENUM,
484					  "gltexStorage3DMultisample() did not generate GL_INVALID_ENUM error.");
485	} /* for each unsupported internalformat */
486
487	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
488
489	return STOP;
490}
491
492/** Constructor.
493 *
494 *  @param context CTS context handle.
495 **/
496RequestsToSetUpMultisampleColorTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
497	RequestsToSetUpMultisampleColorTexturesWithUnsupportedNumberOfSamplesAreRejectedTest(Context& context)
498	: TestCase(context,
499			   "requests_to_set_up_multisample_color_textures_with_unsupported_number_of_samples_are_rejected_test",
500			   "Verifies gltexStorage3DMultisample() rejects unsupported samples value by generating "
501			   "GL_INVALID_VALUE or GL_INVALID_OPEARATION error.")
502	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
503	, to_id(0)
504{
505	/* Left blank on purpose */
506}
507
508/** Deinitializes ES objects created during test execution */
509void RequestsToSetUpMultisampleColorTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::deinit()
510{
511	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
512
513	if (gl_oes_texture_multisample_2d_array_supported)
514	{
515		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
516		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
517	}
518
519	/* Delete texture object. */
520	gl.deleteTextures(1, &to_id);
521
522	to_id = 0;
523
524	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
525
526	/* Call base class' deinit() */
527	TestCase::deinit();
528}
529
530/** Initializes ES objects created during test execution */
531void RequestsToSetUpMultisampleColorTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::initInternals()
532{
533	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
534
535	/* Generate texture object id. */
536	gl.genTextures(1, &to_id);
537
538	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
539	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
540
541	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
542}
543
544/** Executes test iteration.
545 *
546 *  @return Returns STOP when test has finished executing.
547 */
548tcu::TestNode::IterateResult RequestsToSetUpMultisampleColorTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
549	iterate()
550{
551	gl_oes_texture_multisample_2d_array_supported =
552		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
553
554	if (!gl_oes_texture_multisample_2d_array_supported)
555	{
556		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
557
558		return STOP;
559	}
560
561	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
562
563	initInternals();
564
565	/* Check if texture object was generated properly. */
566	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
567
568	glw::GLint internalformat_specific_max_samples = 0;
569	glw::GLint max_color_texture_samples		   = 0;
570	glw::GLint max_samples						   = 0;
571	int		   number_of_color_renderable_internalformats_to_check =
572		sizeof(color_renderable_internalformats) / sizeof(color_renderable_internalformats[0]);
573	int number_of_fixed_sample_locations_values_to_check =
574		sizeof(fixed_sample_locations_values) / sizeof(fixed_sample_locations_values[0]);
575
576	/* Retrieve maximum color texture samples value. */
577	gl.getIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &max_color_texture_samples);
578
579	/* Expect no error was generated. */
580	GLU_EXPECT_NO_ERROR(gl.getError(), "Querying GL_MAX_COLOR_TEXTURE_SAMPLES value failed.");
581
582	/* Retrieve maximum samples value for an implementation. */
583	gl.getIntegerv(GL_MAX_SAMPLES, &max_samples);
584
585	/* Expect no error was generated. */
586	GLU_EXPECT_NO_ERROR(gl.getError(), "Querying GL_MAX_SAMPLES value failed.");
587
588	/* Go through all supported color renderable internal formats. */
589	for (int color_renderable_internalformat_index = 0;
590		 color_renderable_internalformat_index < number_of_color_renderable_internalformats_to_check;
591		 color_renderable_internalformat_index++)
592	{
593		/* Retrieve maximum amount of samples available for the combination of texture target and internalformat considered */
594		gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES,
595							   color_renderable_internalformats[color_renderable_internalformat_index], GL_SAMPLES, 1,
596							   &internalformat_specific_max_samples);
597
598		/* Expect no error was generated. */
599		GLU_EXPECT_NO_ERROR(gl.getError(), "Querying texture target-spcecific maximum sample value failed.");
600
601		/* Go through all possible sample locations values. */
602		for (int fixed_sample_locations_values_index = 0;
603			 fixed_sample_locations_values_index < number_of_fixed_sample_locations_values_to_check;
604			 fixed_sample_locations_values_index++)
605		{
606			glw::GLsizei samples = de::max(internalformat_specific_max_samples, max_color_texture_samples) + 1;
607
608			gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samples,
609									   color_renderable_internalformats[color_renderable_internalformat_index], 1, 1, 1,
610									   fixed_sample_locations_values[fixed_sample_locations_values_index]);
611
612			/* Expect GL_INVALID_OPERATION to be returned. */
613			TCU_CHECK_MSG(gl.getError() == GL_INVALID_OPERATION,
614						  "gltexStorage3DMultisample() did not generate GL_INVALID_OPERATION error.");
615
616			samples = internalformat_specific_max_samples + 1;
617			gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, internalformat_specific_max_samples + 1,
618									   color_renderable_internalformats[color_renderable_internalformat_index], 1, 1, 1,
619									   fixed_sample_locations_values[fixed_sample_locations_values_index]);
620
621			/* Expect GL_INVALID_OPERATION to be returned. */
622			TCU_CHECK_MSG(gl.getError() == GL_INVALID_OPERATION,
623						  "gltexStorage3DMultisample() did not generate GL_INVALID_OPERATION error.");
624
625		} /* for each fixed sample locations value */
626	}	 /* for each color renderable internalformat */
627
628	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
629
630	return STOP;
631}
632
633/** Constructor.
634 *
635 *  @param context CTS context handle.
636 **/
637RequestsToSetUpMultisampleDepthTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
638	RequestsToSetUpMultisampleDepthTexturesWithUnsupportedNumberOfSamplesAreRejectedTest(Context& context)
639	: TestCase(context,
640			   "requests_to_set_up_multisample_depth_textures_with_unsupported_number_of_samples_are_rejected_test",
641			   "Verifies gltexStorage3DMultisample() rejects unsupported samples "
642			   "value by generating GL_INVALID_VALUE or GL_INVALID_OPEARATION error.")
643	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
644	, to_id(0)
645{
646	/* Left blank on purpose */
647}
648
649/** Deinitializes ES objects created during test execution */
650void RequestsToSetUpMultisampleDepthTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::deinit()
651{
652	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
653
654	if (gl_oes_texture_multisample_2d_array_supported)
655	{
656		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
657		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
658	}
659
660	/* Delete texture object. */
661	gl.deleteTextures(1, &to_id);
662
663	to_id = 0;
664
665	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
666
667	/* Call base class' deinit() */
668	TestCase::deinit();
669}
670
671/** Initializes ES objects created during test execution */
672void RequestsToSetUpMultisampleDepthTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::initInternals()
673{
674	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
675
676	/* Generate texture object id. */
677	gl.genTextures(1, &to_id);
678
679	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
680	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
681
682	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
683}
684
685/** Executes test iteration.
686 *
687 *  @return Returns STOP when test has finished executing.
688 */
689tcu::TestNode::IterateResult RequestsToSetUpMultisampleDepthTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
690	iterate()
691{
692	gl_oes_texture_multisample_2d_array_supported =
693		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
694
695	if (!gl_oes_texture_multisample_2d_array_supported)
696	{
697		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
698
699		return STOP;
700	}
701
702	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
703
704	initInternals();
705
706	/* Check if texture object was generated properly. */
707	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
708
709	glw::GLint internalformat_specific_max_samples = 0;
710	glw::GLint max_depth_texture_samples		   = 0;
711	int		   number_of_depth_renderable_internalformats_to_check =
712		sizeof(depth_renderable_internalformats) / sizeof(depth_renderable_internalformats[0]);
713	int number_of_fixed_sample_locations_values_to_check =
714		sizeof(fixed_sample_locations_values) / sizeof(fixed_sample_locations_values[0]);
715
716	/* Retrieve maximum depth texture samples value. */
717	gl.getIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &max_depth_texture_samples);
718
719	/* Expect no error was generated. */
720	GLU_EXPECT_NO_ERROR(gl.getError(), "Querying maximum sample value failed.");
721
722	/* Go through all supported depth renderable internal formats. */
723	for (int depth_renderable_internalformat_index = 0;
724		 depth_renderable_internalformat_index < number_of_depth_renderable_internalformats_to_check;
725		 depth_renderable_internalformat_index++)
726	{
727		/* Retrieve maximum amount of samples available for the texture target considered */
728		gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES,
729							   depth_renderable_internalformats[depth_renderable_internalformat_index], GL_SAMPLES, 1,
730							   &internalformat_specific_max_samples);
731
732		/* Expect no error was generated. */
733		GLU_EXPECT_NO_ERROR(gl.getError(), "Querying texture target-spcecific maximum sample value failed.");
734
735		/* Go through all possible sample locations values. */
736		for (int fixed_sample_locations_values_index = 0;
737			 fixed_sample_locations_values_index < number_of_fixed_sample_locations_values_to_check;
738			 fixed_sample_locations_values_index++)
739		{
740			glw::GLsizei samples = de::max(internalformat_specific_max_samples, max_depth_texture_samples) + 1;
741
742			gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samples,
743									   depth_renderable_internalformats[depth_renderable_internalformat_index], 1, 1, 1,
744									   fixed_sample_locations_values[fixed_sample_locations_values_index]);
745
746			/* Expect GL_INVALID_OPERATION error code. */
747			TCU_CHECK_MSG(gl.getError() == GL_INVALID_OPERATION,
748						  "gltexStorage3DMultisample() did not generate GL_INVALID_OPERATION error.");
749
750		} /* for each fixed sample locations value */
751	}	 /* for each depth renderable internalformat */
752
753	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
754
755	return STOP;
756}
757
758/** Constructor.
759 *
760 *  @param context CTS context handle.
761 **/
762RequestsToSetUpMultisampleStencilTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
763	RequestsToSetUpMultisampleStencilTexturesWithUnsupportedNumberOfSamplesAreRejectedTest(Context& context)
764	: TestCase(context,
765			   "requests_to_set_up_multisample_stencil_textures_with_unsupported_number_of_samples_are_rejected_test",
766			   "Verifies gltexStorage3DMultisample() rejects unsupported samples value"
767			   " by generating GL_INVALID_VALUE or GL_INVALID_OPERATION error.")
768	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
769	, to_id(0)
770{
771	/* Left blank on purpose */
772}
773
774/** Deinitializes ES objects created during test execution */
775void RequestsToSetUpMultisampleStencilTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::deinit()
776{
777	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
778
779	if (gl_oes_texture_multisample_2d_array_supported)
780	{
781		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
782		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
783	}
784
785	/* Delete texture object. */
786	gl.deleteTextures(1, &to_id);
787
788	to_id = 0;
789
790	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
791
792	/* Call base class' deinit() */
793	TestCase::deinit();
794}
795
796/** Initializes ES objects created during test execution */
797void RequestsToSetUpMultisampleStencilTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::initInternals()
798{
799	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
800
801	/* Generate texture object id. */
802	gl.genTextures(1, &to_id);
803
804	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
805	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
806
807	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
808}
809
810/** Executes test iteration.
811 *
812 * @return Returns STOP when test has finished executing.
813 */
814tcu::TestNode::IterateResult RequestsToSetUpMultisampleStencilTexturesWithUnsupportedNumberOfSamplesAreRejectedTest::
815	iterate()
816{
817	gl_oes_texture_multisample_2d_array_supported =
818		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
819
820	if (!gl_oes_texture_multisample_2d_array_supported)
821	{
822		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
823
824		return STOP;
825	}
826
827	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
828
829	initInternals();
830
831	/* Check if texture object was generated properly. */
832	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
833
834	glw::GLint internalformat_specific_max_samples = 0;
835	glw::GLint max_depth_texture_samples		   = 0;
836	int		   number_of_depth_stencil_renderable_internalformats_to_check =
837		sizeof(depth_stencil_renderable_internalformats) / sizeof(depth_stencil_renderable_internalformats[0]);
838	int number_of_fixed_sample_locations_values_to_check =
839		sizeof(fixed_sample_locations_values) / sizeof(fixed_sample_locations_values[0]);
840
841	/* Retrieve maximum depth texture samples value. */
842	gl.getIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &max_depth_texture_samples);
843
844	/* Expect no error was generated. */
845	GLU_EXPECT_NO_ERROR(gl.getError(), "Querying maximum sample value failed.");
846
847	/* Go through all supported depth-stencil renderable internal formats. */
848	for (int depth_stencil_renderable_internalformat_index = 0;
849		 depth_stencil_renderable_internalformat_index < number_of_depth_stencil_renderable_internalformats_to_check;
850		 depth_stencil_renderable_internalformat_index++)
851	{
852		/* Retrieve maximum amount of samples available for the texture target considered */
853		gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES,
854							   depth_stencil_renderable_internalformats[depth_stencil_renderable_internalformat_index],
855							   GL_SAMPLES, 1, &internalformat_specific_max_samples);
856
857		/* Expect no error was generated. */
858		GLU_EXPECT_NO_ERROR(gl.getError(), "Querying texture target-spcecific maximum sample value failed.");
859
860		/* Go through all possible sample locations values. */
861		for (int fixed_sample_locations_values_index = 0;
862			 fixed_sample_locations_values_index < number_of_fixed_sample_locations_values_to_check;
863			 fixed_sample_locations_values_index++)
864		{
865			glw::GLsizei samples = de::max(internalformat_specific_max_samples, max_depth_texture_samples) + 1;
866
867			gl.texStorage3DMultisample(
868				GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, samples,
869				depth_stencil_renderable_internalformats[depth_stencil_renderable_internalformat_index], 1, 1, 1,
870				fixed_sample_locations_values[fixed_sample_locations_values_index]);
871
872			/* Expect GL_INVALID_OPERATION to be returned. */
873			TCU_CHECK_MSG(gl.getError() == GL_INVALID_OPERATION,
874						  "gltexStorage3DMultisample() did not generate GL_INVALID_OPERATION error.");
875
876		} /* for each fixed sample locations value */
877	}	 /* for each depth-stencil renderable internalformat */
878
879	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
880
881	return STOP;
882}
883
884/** Constructor.
885 *
886 *  @param context CTS context handle.
887 **/
888RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::
889	RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest(Context& context)
890	: TestCase(context, "requests_to_set_up_multisample_textures_with_valid_and_invalid_number_of_samples_test",
891			   "Verifies gltexStorage3DMultisample() rejects invalid samples value "
892			   "by generating GL_INVALID_OPEARATION error and works properly when samples value is valid.")
893	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
894	, to_id(0)
895{
896	/* Left blank on purpose */
897}
898
899/* Generates texture object and binds it to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
900void RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::createAssets()
901{
902	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
903
904	/* Generate texture object. */
905	gl.genTextures(1, &to_id);
906
907	/* Bind texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
908	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
909
910	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
911}
912
913/** Deinitializes ES objects created during test execution */
914void RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::deinit()
915{
916	if (to_id != 0)
917	{
918		/* Destroy created assets. */
919		releaseAssets();
920	}
921
922	/* Call base class' deinit() */
923	TestCase::deinit();
924}
925
926/* Unbinds and deletes texture object. */
927void RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::releaseAssets()
928{
929	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
930
931	if (gl_oes_texture_multisample_2d_array_supported)
932	{
933		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
934		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
935	}
936
937	/* Delete texture object. */
938	gl.deleteTextures(1, &to_id);
939
940	to_id = 0;
941
942	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
943}
944
945/** Executes test iteration.
946 *
947 *  @return Returns STOP when test has finished executing.
948 */
949tcu::TestNode::IterateResult RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::iterate()
950{
951	gl_oes_texture_multisample_2d_array_supported =
952		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
953
954	if (!gl_oes_texture_multisample_2d_array_supported)
955	{
956		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
957
958		return STOP;
959	}
960
961	const glw::Functions& gl								  = m_context.getRenderContext().getFunctions();
962	glw::GLint			  gl_max_samples_value				  = 0;
963	glw::GLint			  internalformat_specific_max_samples = 0;
964	int number_of_internalformats_to_check = sizeof(supported_internalformats) / sizeof(supported_internalformats[0]);
965
966	/* Retrieve maximum samples value for an implementation. */
967	gl.getIntegerv(GL_MAX_SAMPLES, &gl_max_samples_value);
968
969	/* Expect no error was generated. */
970	GLU_EXPECT_NO_ERROR(gl.getError(), "Querying GL_MAX_SAMPLES value failed.");
971
972	/* Go through all supported internal formats. */
973	for (int internalformat_index = 0; internalformat_index < number_of_internalformats_to_check;
974		 internalformat_index++)
975	{
976		/* Generate and bind texture object. */
977		RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::createAssets();
978
979		/* Check if texture object was generated properly. */
980		TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
981
982		/* Retrieve maximum amount of samples available for the texture target considered */
983		gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, supported_internalformats[internalformat_index],
984							   GL_SAMPLES, 1, &internalformat_specific_max_samples);
985
986		/* Expect no error was generated. */
987		GLU_EXPECT_NO_ERROR(gl.getError(), "Querying texture target-spcecific maximum sample value failed.");
988
989		/* Call gltexStorage3DMultisample() with valid samples value. */
990		gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, internalformat_specific_max_samples,
991								   supported_internalformats[internalformat_index], 1, 1, 1, GL_FALSE);
992
993		/* Expect no error was generated. */
994		GLU_EXPECT_NO_ERROR(gl.getError(), "gltexStorage3DMultisample() returned unexpected error code.");
995
996		/* Delete texture object. */
997		RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::releaseAssets();
998
999		/* Generate and bind texture object. */
1000		RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::createAssets();
1001
1002		/* Check if texture object was generated properly. */
1003		TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
1004
1005		/* Call gltexStorage3DMultisample() with invalid samples value. */
1006		gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, internalformat_specific_max_samples + 1,
1007								   supported_internalformats[internalformat_index], 1, 1, 1, GL_FALSE);
1008
1009		/* Expect GL_INVALID_OPERATION error code. */
1010		TCU_CHECK_MSG(gl.getError() == GL_INVALID_OPERATION,
1011					  "gltexStorage3DMultisample() did not generate GL_INVALID_OPERATION error.");
1012
1013		/* Delete texture object. */
1014		RequestsToSetUpMultisampleTexturesWithValidAndInvalidNumberOfSamplesTest::releaseAssets();
1015	} /* for each supported internalformat */
1016
1017	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1018
1019	return STOP;
1020}
1021
1022/** Constructor.
1023 *
1024 *  @param context CTS context handle.
1025 **/
1026Texture2DMultisampleTargetIsRejectedTest::Texture2DMultisampleTargetIsRejectedTest(Context& context)
1027	: TestCase(context, "texture_2D_multisample_target_is_rejected_test",
1028			   "Verifies gltexStorage3DMultisample() rejects GL_TEXTURE_2D_MULTISAMPLE "
1029			   "texture target by generating GL_INVALID_ENUM error.")
1030	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
1031	, to_id(0)
1032{
1033	/* Left blank on purpose */
1034}
1035
1036/** Deinitializes ES objects created during test execution */
1037void Texture2DMultisampleTargetIsRejectedTest::deinit()
1038{
1039	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1040
1041	/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE texture target. */
1042	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
1043
1044	/* Delete texture object. */
1045	gl.deleteTextures(1, &to_id);
1046
1047	to_id = 0;
1048
1049	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
1050
1051	/* Call base class' deinit() */
1052	TestCase::deinit();
1053}
1054
1055/** Initializes ES objects created during test execution */
1056void Texture2DMultisampleTargetIsRejectedTest::initInternals()
1057{
1058	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1059
1060	/* Generate texture object id. */
1061	gl.genTextures(1, &to_id);
1062
1063	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE texture target. */
1064	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE, to_id);
1065
1066	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
1067}
1068
1069/** Executes test iteration.
1070 *
1071 *  @return Returns STOP when test has finished executing.
1072 */
1073tcu::TestNode::IterateResult Texture2DMultisampleTargetIsRejectedTest::iterate()
1074{
1075	gl_oes_texture_multisample_2d_array_supported =
1076		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
1077
1078	if (!gl_oes_texture_multisample_2d_array_supported)
1079	{
1080		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
1081
1082		return STOP;
1083	}
1084
1085	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1086
1087	initInternals();
1088
1089	/* Check if texture object was generated properly. */
1090	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
1091
1092	/* Call gltexStorage3DMultisample() with invalid GL_TEXTURE_2D_MULTISAMPLE texture target argument. */
1093	gl.texStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE, /* invalid texture target */ 1, GL_RGBA8, 1, 1, 1, GL_FALSE);
1094
1095	/* Expect GL_INVALID_ENUM error code. */
1096	TCU_CHECK_MSG(gl.getError() == GL_INVALID_ENUM,
1097				  "gltexStorage3DMultisample() did not generate GL_INVALID_ENUM error.");
1098
1099	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1100
1101	return STOP;
1102}
1103
1104/** Constructor.
1105 *
1106 *  @param context CTS context handle.
1107 **/
1108ValidInternalformatAndSamplesValuesAreAcceptedTest::ValidInternalformatAndSamplesValuesAreAcceptedTest(Context& context)
1109	: TestCase(context, "valid_internalformats_are_accepted_test",
1110			   "Verifies gltexStorage3DMultisample() accepts multisample color/depth/stencil "
1111			   "textures with disabled/enabled fixed sample locations and valid internalformats.")
1112	, gl_oes_texture_multisample_2d_array_supported(GL_FALSE)
1113	, to_id(0)
1114{
1115	/* Left blank on purpose */
1116}
1117
1118/** Deinitializes ES objects created during test execution */
1119void ValidInternalformatAndSamplesValuesAreAcceptedTest::deinit()
1120{
1121	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1122
1123	if (gl_oes_texture_multisample_2d_array_supported)
1124	{
1125		/* Bind default texture object to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
1126		gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, 0);
1127	}
1128
1129	/* Delete texture object. */
1130	gl.deleteTextures(1, &to_id);
1131
1132	to_id = 0;
1133
1134	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object deletion failed.");
1135
1136	/* Call base class' deinit() */
1137	TestCase::deinit();
1138}
1139
1140/** Initializes ES objects created during test execution */
1141void ValidInternalformatAndSamplesValuesAreAcceptedTest::initInternals()
1142{
1143	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1144
1145	/* Generate texture object id. */
1146	gl.genTextures(1, &to_id);
1147
1148	/* Bind generated texture object ID to GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES texture target. */
1149	gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
1150
1151	GLU_EXPECT_NO_ERROR(gl.getError(), "Texture object initialization failed.");
1152}
1153
1154/** Executes test iteration.
1155 *
1156 *  @return Returns STOP when test has finished executing.
1157 */
1158tcu::TestNode::IterateResult ValidInternalformatAndSamplesValuesAreAcceptedTest::iterate()
1159{
1160	gl_oes_texture_multisample_2d_array_supported =
1161		m_context.getContextInfo().isExtensionSupported("GL_OES_texture_storage_multisample_2d_array");
1162
1163	if (!gl_oes_texture_multisample_2d_array_supported)
1164	{
1165		m_testCtx.setTestResult(QP_TEST_RESULT_NOT_SUPPORTED, "OES_texture_storage_multisample_2d_array");
1166
1167		return STOP;
1168	}
1169
1170	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
1171
1172	initInternals();
1173
1174	/* Check if texture object was generated properly. */
1175	TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
1176
1177	glw::GLint max_color_texture_samples = 0;
1178	glw::GLint max_depth_texture_samples = 0;
1179	const int  n_color_internalformats =
1180		sizeof(color_renderable_internalformats) / sizeof(color_renderable_internalformats[0]);
1181	const int n_depth_internalformats =
1182		sizeof(depth_renderable_internalformats) / sizeof(depth_renderable_internalformats[0]);
1183	const int n_fixed_sample_locations =
1184		sizeof(fixed_sample_locations_values) / sizeof(fixed_sample_locations_values[0]);
1185	const int n_stencil_internalformats =
1186		sizeof(depth_stencil_renderable_internalformats) / sizeof(depth_stencil_renderable_internalformats[0]);
1187
1188	/* Retrieve maximum color texture samples value. */
1189	gl.getIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &max_color_texture_samples);
1190	/* Retrieve maximum depth texture samples value. */
1191	gl.getIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &max_depth_texture_samples);
1192
1193	/* Expect no error was generated. */
1194	GLU_EXPECT_NO_ERROR(
1195		gl.getError(),
1196		"Querying maximum GL_MAX_COLOR_TEXTURE_SAMPLES and GL_MAX_DEPTH_TEXTURE_SAMPLES property values failed.");
1197
1198	for (unsigned int n_iteration = 0; n_iteration < 3 /* color/depth/stencil */; ++n_iteration)
1199	{
1200		const glw::GLint* internalformats						  = NULL;
1201		glw::GLint		  internalformat_specific_max_samples	 = 0;
1202		glw::GLint		  max_iteration_specific_gl_samples_value = 0;
1203		glw::GLint		  max_supported_samples_value			  = 0;
1204		int				  n_internalformats						  = 0;
1205
1206		switch (n_iteration)
1207		{
1208		case 0:
1209		{
1210			internalformats							= color_renderable_internalformats;
1211			max_iteration_specific_gl_samples_value = max_color_texture_samples;
1212			n_internalformats						= n_color_internalformats;
1213
1214			break;
1215		}
1216
1217		case 1:
1218		{
1219			internalformats							= depth_renderable_internalformats;
1220			max_iteration_specific_gl_samples_value = max_depth_texture_samples;
1221			n_internalformats						= n_depth_internalformats;
1222
1223			break;
1224		}
1225
1226		case 2:
1227		{
1228			internalformats							= depth_stencil_renderable_internalformats;
1229			max_iteration_specific_gl_samples_value = max_depth_texture_samples;
1230			n_internalformats						= n_stencil_internalformats;
1231
1232			break;
1233		}
1234
1235		default:
1236		{
1237			TCU_FAIL("Unrecognized iteration index");
1238		}
1239		} /* switch (n_iteration) */
1240
1241		/* Go through all requested internalformats. */
1242		for (int internalformat_index = 0; internalformat_index < n_internalformats; internalformat_index++)
1243		{
1244			/* Retrieve maximum amount of samples available for the combination of
1245			 * texture target and internalformat considered. */
1246			gl.getInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, internalformats[internalformat_index],
1247								   GL_SAMPLES, 1, &internalformat_specific_max_samples);
1248
1249			/* Expect no error was generated. */
1250			GLU_EXPECT_NO_ERROR(gl.getError(), "Querying texture target-spcecific maximum samples value failed.");
1251
1252			/* Choose maximum supported samples value. */
1253			max_supported_samples_value =
1254				de::min(internalformat_specific_max_samples, max_iteration_specific_gl_samples_value);
1255
1256			/* Go through all supported samples values. */
1257			for (glw::GLint n_samples = 1; n_samples <= max_supported_samples_value; n_samples++)
1258			{
1259				/* Go through all supported 'fixed_sample_locations' argument values. */
1260				for (int fixed_sample_location_value_index = 0;
1261					 fixed_sample_location_value_index < n_fixed_sample_locations; fixed_sample_location_value_index++)
1262				{
1263					/* Call gltexStorage3DMultisample() with valid arguments. */
1264					gl.texStorage3DMultisample(
1265						GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, n_samples, /* Iteration-specific sample value. */
1266						internalformats
1267							[internalformat_index], /* One of color/depth/stencil-renderable internalformats. */
1268						1,							/* width */
1269						1,							/* height */
1270						1,							/* depth */
1271						fixed_sample_locations_values[fixed_sample_location_value_index]);
1272
1273					/* Expect no error was generated. */
1274					GLU_EXPECT_NO_ERROR(gl.getError(), "gltexStorage3DMultisample() generated unexpected error.");
1275
1276					/* Delete texture object. */
1277					gl.deleteTextures(1, &to_id);
1278
1279					/* Generate texture object. */
1280					gl.genTextures(1, &to_id);
1281
1282					/* Check if texture object was generated properly. */
1283					TCU_CHECK_MSG(to_id != 0, "Texture object has not been generated.");
1284
1285					/* Re-bind texture object. */
1286					gl.bindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES, to_id);
1287
1288					/* Expect no error was generated. */
1289					GLU_EXPECT_NO_ERROR(gl.getError(), "Rebinding texture object generated unexpected error.");
1290				} /* for each fixed sample locations value (enabled/disabled). */
1291			}	 /* for each supported sample value. */
1292		}		  /* for each color/depth/stencil-renderable internalformat */
1293	}			  /* for color/depth/stencil interation */
1294
1295	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1296
1297	return STOP;
1298}
1299} /* glcts namespace */
1300