1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Rbo state query tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "es2fRboStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es2fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 #include "deRandom.hpp"
31 #include "deMath.h"
32
33 using namespace glw; // GLint and other GL types
34 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
35
36
37 namespace deqp
38 {
39 namespace gles2
40 {
41 namespace Functional
42 {
43 namespace
44 {
45
checkRenderbufferComponentSize(tcu::TestContext & testCtx,glu::CallLogWrapper & gl,int r,int g,int b,int a,int d,int s)46 void checkRenderbufferComponentSize (tcu::TestContext& testCtx, glu::CallLogWrapper& gl, int r, int g, int b, int a, int d, int s)
47 {
48 using tcu::TestLog;
49
50 const int referenceSizes[] = {r, g, b, a, d, s};
51 const GLenum paramNames[] =
52 {
53 GL_RENDERBUFFER_RED_SIZE,
54 GL_RENDERBUFFER_GREEN_SIZE,
55 GL_RENDERBUFFER_BLUE_SIZE,
56 GL_RENDERBUFFER_ALPHA_SIZE,
57 GL_RENDERBUFFER_DEPTH_SIZE,
58 GL_RENDERBUFFER_STENCIL_SIZE
59 };
60
61 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(referenceSizes) == DE_LENGTH_OF_ARRAY(paramNames));
62
63 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(referenceSizes); ++ndx)
64 {
65 if (referenceSizes[ndx] == -1)
66 continue;
67
68 StateQueryMemoryWriteGuard<GLint> state;
69 gl.glGetRenderbufferParameteriv(GL_RENDERBUFFER, paramNames[ndx], &state);
70
71 if (!state.verifyValidity(testCtx))
72 return;
73
74 if (state < referenceSizes[ndx])
75 {
76 testCtx.getLog() << TestLog::Message << "// ERROR: Expected greater or equal to " << referenceSizes[ndx] << "; got " << state << TestLog::EndMessage;
77 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
78 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
79 }
80 }
81 }
82
checkIntEquals(tcu::TestContext & testCtx,GLint got,GLint expected)83 void checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
84 {
85 using tcu::TestLog;
86
87 if (got != expected)
88 {
89 testCtx.getLog() << TestLog::Message << "// ERROR: Expected " << expected << "; got " << got << TestLog::EndMessage;
90 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
91 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
92 }
93 }
94
checkRenderbufferParam(tcu::TestContext & testCtx,glu::CallLogWrapper & gl,GLenum pname,GLenum reference)95 void checkRenderbufferParam (tcu::TestContext& testCtx, glu::CallLogWrapper& gl, GLenum pname, GLenum reference)
96 {
97 StateQueryMemoryWriteGuard<GLint> state;
98 gl.glGetRenderbufferParameteriv(GL_RENDERBUFFER, pname, &state);
99
100 if (state.verifyValidity(testCtx))
101 checkIntEquals(testCtx, state, reference);
102 }
103
104 class RboSizeCase : public ApiCase
105 {
106 public:
RboSizeCase(Context & context,const char * name,const char * description)107 RboSizeCase (Context& context, const char* name, const char* description)
108 : ApiCase(context, name, description)
109 {
110 }
111
test(void)112 void test (void)
113 {
114 de::Random rnd(0xabcdef);
115
116 GLuint renderbufferID = 0;
117 glGenRenderbuffers(1, &renderbufferID);
118 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
119 expectError(GL_NO_ERROR);
120
121 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_WIDTH, 0);
122 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_HEIGHT, 0);
123 expectError(GL_NO_ERROR);
124
125 int maxRenderbufferSize = 1;
126 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
127 expectError(GL_NO_ERROR);
128
129 const int numIterations = 30;
130 for (int i = 0; i < numIterations; ++i)
131 {
132 const GLint w = rnd.getInt(0, maxRenderbufferSize);
133 const GLint h = rnd.getInt(0, maxRenderbufferSize);
134
135 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
136 expectError(GL_NO_ERROR);
137
138 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_WIDTH, w);
139 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_HEIGHT, h);
140 }
141
142 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
143 glDeleteRenderbuffers(1, &renderbufferID);
144 }
145 };
146
147 class RboInternalFormatCase : public ApiCase
148 {
149 public:
RboInternalFormatCase(Context & context,const char * name,const char * description)150 RboInternalFormatCase (Context& context, const char* name, const char* description)
151 : ApiCase(context, name, description)
152 {
153 }
154
test(void)155 void test (void)
156 {
157 GLuint renderbufferID = 0;
158 glGenRenderbuffers(1, &renderbufferID);
159 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
160 expectError(GL_NO_ERROR);
161
162 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, GL_RGBA4);
163 expectError(GL_NO_ERROR);
164
165 const GLenum requiredColorformats[] =
166 {
167 GL_RGBA4, GL_RGB5_A1, GL_RGB565
168 };
169
170 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorformats); ++ndx)
171 {
172 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorformats[ndx], 1, 1);
173 expectError(GL_NO_ERROR);
174
175 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, requiredColorformats[ndx]);
176 }
177
178 glDeleteRenderbuffers(1, &renderbufferID);
179 }
180 };
181
182 class RboComponentSizeColorCase : public ApiCase
183 {
184 public:
RboComponentSizeColorCase(Context & context,const char * name,const char * description)185 RboComponentSizeColorCase (Context& context, const char* name, const char* description)
186 : ApiCase(context, name, description)
187 {
188 }
189
test(void)190 void test (void)
191 {
192 GLuint renderbufferID = 0;
193 glGenRenderbuffers(1, &renderbufferID);
194 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
195 expectError(GL_NO_ERROR);
196
197 checkRenderbufferComponentSize(m_testCtx, *this, 0, 0, 0, 0, 0, 0);
198 expectError(GL_NO_ERROR);
199
200 const struct ColorFormat
201 {
202 GLenum internalFormat;
203 int bitsR, bitsG, bitsB, bitsA;
204 } requiredColorFormats[] =
205 {
206 { GL_RGBA4, 4, 4, 4, 4 },
207 { GL_RGB5_A1, 5, 5, 5, 1 },
208 { GL_RGB565, 5, 6, 5, 0 },
209 };
210
211 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorFormats); ++ndx)
212 {
213 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorFormats[ndx].internalFormat, 1, 1);
214 expectError(GL_NO_ERROR);
215
216 checkRenderbufferComponentSize(m_testCtx, *this, requiredColorFormats[ndx].bitsR, requiredColorFormats[ndx].bitsG, requiredColorFormats[ndx].bitsB, requiredColorFormats[ndx].bitsA, -1, -1);
217 }
218
219 glDeleteRenderbuffers(1, &renderbufferID);
220 }
221 };
222
223 class RboComponentSizeDepthCase : public ApiCase
224 {
225 public:
RboComponentSizeDepthCase(Context & context,const char * name,const char * description)226 RboComponentSizeDepthCase (Context& context, const char* name, const char* description)
227 : ApiCase(context, name, description)
228 {
229 }
230
test(void)231 void test (void)
232 {
233 using tcu::TestLog;
234
235 GLuint renderbufferID = 0;
236 glGenRenderbuffers(1, &renderbufferID);
237 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
238 expectError(GL_NO_ERROR);
239
240 const struct DepthFormat
241 {
242 GLenum internalFormat;
243 int dbits;
244 int sbits;
245 } requiredDepthFormats[] =
246 {
247 { GL_DEPTH_COMPONENT16, 16, 0 },
248 };
249
250 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredDepthFormats); ++ndx)
251 {
252 glRenderbufferStorage(GL_RENDERBUFFER, requiredDepthFormats[ndx].internalFormat, 1, 1);
253 expectError(GL_NO_ERROR);
254
255 checkRenderbufferComponentSize(m_testCtx, *this, -1, -1, -1, -1, requiredDepthFormats[ndx].dbits, requiredDepthFormats[ndx].sbits);
256 }
257
258 // STENCIL_INDEX8 is required, in that case sBits >= 8
259 {
260 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 1, 1);
261 expectError(GL_NO_ERROR);
262
263 StateQueryMemoryWriteGuard<GLint> state;
264 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_STENCIL_SIZE, &state);
265
266 if (state.verifyValidity(m_testCtx) && state < 8)
267 {
268 m_testCtx.getLog() << TestLog::Message << "// ERROR: Expected greater or equal to 8; got " << state << TestLog::EndMessage;
269 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
270 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
271 }
272 }
273
274 glDeleteRenderbuffers(1, &renderbufferID);
275 }
276 };
277
278 } // anonymous
279
280
RboStateQueryTests(Context & context)281 RboStateQueryTests::RboStateQueryTests (Context& context)
282 : TestCaseGroup(context, "rbo", "Rbo State Query tests")
283 {
284 }
285
init(void)286 void RboStateQueryTests::init (void)
287 {
288 addChild(new RboSizeCase (m_context, "renderbuffer_size", "RENDERBUFFER_WIDTH and RENDERBUFFER_HEIGHT"));
289 addChild(new RboInternalFormatCase (m_context, "renderbuffer_internal_format", "RENDERBUFFER_INTERNAL_FORMAT"));
290 addChild(new RboComponentSizeColorCase (m_context, "renderbuffer_component_size_color", "RENDERBUFFER_x_SIZE"));
291 addChild(new RboComponentSizeDepthCase (m_context, "renderbuffer_component_size_depth", "RENDERBUFFER_x_SIZE"));
292 }
293
294 } // Functional
295 } // gles2
296 } // deqp
297