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  es31cTextureStorageMultisampleSampleMaskiTests.cpp
27  * \brief Implements conformance tests for glSampleMaski() (ES3.1 only)
28  */ /*-------------------------------------------------------------------*/
29 
30 #include "es31cTextureStorageMultisampleSampleMaskiTests.hpp"
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuRenderTarget.hpp"
36 #include "tcuTestLog.hpp"
37 
38 #include <string>
39 #include <vector>
40 
41 namespace glcts
42 {
43 /** Constructor.
44  *
45  *  @param context Rendering context handle.
46  **/
47 MultisampleTextureSampleMaskiIndexLowerThanGLMaxSampleMaskWordsTest::
MultisampleTextureSampleMaskiIndexLowerThanGLMaxSampleMaskWordsTest(Context & context)48 	MultisampleTextureSampleMaskiIndexLowerThanGLMaxSampleMaskWordsTest(Context& context)
49 	: TestCase(context, "multisample_texture_sample_maski_index_lower_than_gl_max_sample_mask_words",
50 			   "Verifies glSampleMaski() correctly accepts index arguments up to GL_MAX_SAMPLE_MASK_WORDS-1 value")
51 {
52 	/* Left blank on purpose */
53 }
54 
55 /** Executes test iteration.
56  *
57  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
58  */
iterate()59 tcu::TestNode::IterateResult MultisampleTextureSampleMaskiIndexLowerThanGLMaxSampleMaskWordsTest::iterate()
60 {
61 	/* Get GL_MAX_SAMPLE_MASK_WORDS value */
62 	const glw::Functions& gl							 = m_context.getRenderContext().getFunctions();
63 	glw::GLint			  gl_max_sample_mask_words_value = 0;
64 
65 	gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &gl_max_sample_mask_words_value);
66 
67 	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to retrieve GL_MAX_SAMPLE_MASK_WORDS value");
68 
69 	/* Issue the calls */
70 	for (int sample_mask = 0; sample_mask < gl_max_sample_mask_words_value; ++sample_mask)
71 	{
72 		gl.sampleMaski(sample_mask, 0);
73 
74 		GLU_EXPECT_NO_ERROR(gl.getError(), "An error was reported despite a valid glSampleMaski() call.");
75 	}
76 
77 	/* Test case passed */
78 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
79 
80 	return STOP;
81 }
82 
83 /** Constructor.
84  *
85  *  @param context Rendering context handle.
86  **/
87 MultisampleTextureSampleMaskiIndexEqualToGLMaxSampleMaskWordsTest::
MultisampleTextureSampleMaskiIndexEqualToGLMaxSampleMaskWordsTest(Context & context)88 	MultisampleTextureSampleMaskiIndexEqualToGLMaxSampleMaskWordsTest(Context& context)
89 	: TestCase(context, "multisample_texture_sample_maski_index_equal_gl_max_sample_mask_words",
90 			   "Verifies glSampleMaski() rejects index equal to GL_MAX_SAMPLE_MASK_WORDS value")
91 {
92 	/* Left blank on purpose */
93 }
94 
95 /** Executes test iteration.
96  *
97  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
98  */
iterate()99 tcu::TestNode::IterateResult MultisampleTextureSampleMaskiIndexEqualToGLMaxSampleMaskWordsTest::iterate()
100 {
101 	/* Get GL_MAX_SAMPLE_MASK_WORDS value */
102 	const glw::Functions& gl							 = m_context.getRenderContext().getFunctions();
103 	glw::GLint			  gl_max_sample_mask_words_value = 0;
104 
105 	gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &gl_max_sample_mask_words_value);
106 
107 	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to retrieve GL_MAX_SAMPLE_MASK_WORDS value");
108 
109 	/* Issue call with valid parameters, but invalid index equal to GL_MAX_SAMPLE_MASK_WORDS value */
110 	gl.sampleMaski(gl_max_sample_mask_words_value, 0);
111 
112 	if (gl.getError() != GL_INVALID_VALUE)
113 	{
114 		TCU_FAIL("Invalid error code reported");
115 	}
116 
117 	/* Test case passed */
118 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
119 
120 	return STOP;
121 }
122 
123 /** Constructor.
124  *
125  *  @param context Rendering context handle.
126  **/
MultisampleTextureSampleMaskiGettersTest(Context & context)127 MultisampleTextureSampleMaskiGettersTest::MultisampleTextureSampleMaskiGettersTest(Context& context)
128 	: TestCase(context, "multisample_texture_sample_maski_getters",
129 			   "Verifies valid glSampleMaski() calls modify GL_SAMPLE_MASK_VALUE "
130 			   "property value reported by glGetIntegeri_v()")
131 {
132 	/* Left blank on purpose */
133 }
134 
135 /** Executes test iteration.
136  *
137  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
138  */
iterate()139 tcu::TestNode::IterateResult MultisampleTextureSampleMaskiGettersTest::iterate()
140 {
141 	/* Get GL_MAX_SAMPLE_MASK_WORDS value */
142 	const glw::Functions& gl							 = m_context.getRenderContext().getFunctions();
143 	glw::GLint			  gl_max_sample_mask_words_value = 0;
144 
145 	gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &gl_max_sample_mask_words_value);
146 
147 	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to retrieve GL_MAX_SAMPLE_MASK_WORDS value");
148 
149 	/* Iterate over valid index & mask values */
150 	const glw::GLuint  valid_masks[] = { 0, 0xFFFFFFFF, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF };
151 	const unsigned int n_valid_masks = sizeof(valid_masks) / sizeof(valid_masks[0]);
152 
153 	for (int index = 0; index < gl_max_sample_mask_words_value; ++index)
154 	{
155 		for (unsigned int n_mask = 0; n_mask < n_valid_masks; ++n_mask)
156 		{
157 			glw::GLint mask = valid_masks[n_mask];
158 
159 			/* Make sure a valid glSampleMaski() call does not result in an error */
160 			gl.sampleMaski(index, mask);
161 
162 			GLU_EXPECT_NO_ERROR(gl.getError(), "A valid glSampleMaski() call resulted in an error");
163 
164 			/* Check the property value as reported by implementation */
165 			glw::GLint int_value = -1;
166 
167 			gl.getIntegeri_v(GL_SAMPLE_MASK_VALUE, index, &int_value);
168 			GLU_EXPECT_NO_ERROR(gl.getError(), "A valid glGetIntegeri_v() call resulted in an error");
169 
170 			if (int_value != mask)
171 			{
172 				TCU_FAIL("Invalid sample mask reported");
173 			}
174 		} /* for (all masks) */
175 	}	 /* for (all valid index argument values) */
176 
177 	/* Test case passed */
178 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
179 
180 	return STOP;
181 }
182 
183 /** Constructor.
184  *
185  *  @param context Rendering context handle.
186  **/
187 MultisampleTextureSampleMaskiIndexGreaterGLMaxSampleMaskWordsTest::
MultisampleTextureSampleMaskiIndexGreaterGLMaxSampleMaskWordsTest(Context & context)188 	MultisampleTextureSampleMaskiIndexGreaterGLMaxSampleMaskWordsTest(Context& context)
189 	: TestCase(context, "multisample_texture_sample_maski_index_greater_gl_max_sample_mask_words",
190 			   "Verifies glSampleMaski() rejects index greater than GL_MAX_SAMPLE_MASK_WORDS value")
191 {
192 	/* Left blank on purpose */
193 }
194 
195 /** Executes test iteration.
196  *
197  *  @return Returns STOP when test has finished executing, CONTINUE if more iterations are needed.
198  */
iterate()199 tcu::TestNode::IterateResult MultisampleTextureSampleMaskiIndexGreaterGLMaxSampleMaskWordsTest::iterate()
200 {
201 	/* Get GL_MAX_SAMPLE_MASK_WORDS value */
202 	const glw::Functions& gl							 = m_context.getRenderContext().getFunctions();
203 	glw::GLint			  gl_max_sample_mask_words_value = 0;
204 
205 	gl.getIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &gl_max_sample_mask_words_value);
206 
207 	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to retrieve GL_MAX_SAMPLE_MASK_WORDS value");
208 
209 	/* Issue call with valid parameters, but invalid index greater than GL_MAX_SAMPLE_MASK_WORDS value */
210 	gl.sampleMaski(gl_max_sample_mask_words_value + 1, 0);
211 
212 	if (gl.getError() != GL_INVALID_VALUE)
213 	{
214 		TCU_FAIL("Invalid error code reported");
215 	}
216 
217 	/* Test case passed */
218 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
219 
220 	return STOP;
221 }
222 } /* glcts namespace */
223