1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Rbo state query tests.
22 *//*--------------------------------------------------------------------*/
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"
33 using namespace glw; // GLint and other GL types
34 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
46 void checkRenderbufferComponentSize (tcu::TestContext& testCtx, glu::CallLogWrapper& gl, int r, int g, int b, int a, int d, int s)
50 const int referenceSizes[] = {r, g, b, a, d, s};
51 const GLenum paramNames[] =
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
61 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(referenceSizes) == DE_LENGTH_OF_ARRAY(paramNames));
63 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(referenceSizes); ++ndx)
65 if (referenceSizes[ndx] == -1)
68 StateQueryMemoryWriteGuard<GLint> state;
69 gl.glGetRenderbufferParameteriv(GL_RENDERBUFFER, paramNames[ndx], &state);
71 if (!state.verifyValidity(testCtx))
74 if (state < referenceSizes[ndx])
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");
83 void checkIntEquals (tcu::TestContext& testCtx, GLint got, GLint expected)
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");
95 void checkRenderbufferParam (tcu::TestContext& testCtx, glu::CallLogWrapper& gl, GLenum pname, GLenum reference)
97 StateQueryMemoryWriteGuard<GLint> state;
98 gl.glGetRenderbufferParameteriv(GL_RENDERBUFFER, pname, &state);
100 if (state.verifyValidity(testCtx))
101 checkIntEquals(testCtx, state, reference);
104 class RboSizeCase : public ApiCase
107 RboSizeCase (Context& context, const char* name, const char* description)
108 : ApiCase(context, name, description)
114 de::Random rnd(0xabcdef);
116 GLuint renderbufferID = 0;
117 glGenRenderbuffers(1, &renderbufferID);
118 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
119 expectError(GL_NO_ERROR);
121 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_WIDTH, 0);
122 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_HEIGHT, 0);
123 expectError(GL_NO_ERROR);
125 int maxRenderbufferSize = 1;
126 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderbufferSize);
127 expectError(GL_NO_ERROR);
129 const int numIterations = 30;
130 for (int i = 0; i < numIterations; ++i)
132 const GLint w = rnd.getInt(0, maxRenderbufferSize);
133 const GLint h = rnd.getInt(0, maxRenderbufferSize);
135 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
136 expectError(GL_NO_ERROR);
138 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_WIDTH, w);
139 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_HEIGHT, h);
142 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
143 glDeleteRenderbuffers(1, &renderbufferID);
147 class RboInternalFormatCase : public ApiCase
150 RboInternalFormatCase (Context& context, const char* name, const char* description)
151 : ApiCase(context, name, description)
157 GLuint renderbufferID = 0;
158 glGenRenderbuffers(1, &renderbufferID);
159 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
160 expectError(GL_NO_ERROR);
162 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, GL_RGBA4);
163 expectError(GL_NO_ERROR);
165 const GLenum requiredColorformats[] =
167 GL_RGBA4, GL_RGB5_A1, GL_RGB565
170 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorformats); ++ndx)
172 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorformats[ndx], 1, 1);
173 expectError(GL_NO_ERROR);
175 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, requiredColorformats[ndx]);
178 glDeleteRenderbuffers(1, &renderbufferID);
182 class RboComponentSizeColorCase : public ApiCase
185 RboComponentSizeColorCase (Context& context, const char* name, const char* description)
186 : ApiCase(context, name, description)
192 GLuint renderbufferID = 0;
193 glGenRenderbuffers(1, &renderbufferID);
194 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
195 expectError(GL_NO_ERROR);
197 checkRenderbufferComponentSize(m_testCtx, *this, 0, 0, 0, 0, 0, 0);
198 expectError(GL_NO_ERROR);
200 const struct ColorFormat
202 GLenum internalFormat;
203 int bitsR, bitsG, bitsB, bitsA;
204 } requiredColorFormats[] =
206 { GL_RGBA4, 4, 4, 4, 4 },
207 { GL_RGB5_A1, 5, 5, 5, 1 },
208 { GL_RGB565, 5, 6, 5, 0 },
211 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorFormats); ++ndx)
213 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorFormats[ndx].internalFormat, 1, 1);
214 expectError(GL_NO_ERROR);
216 checkRenderbufferComponentSize(m_testCtx, *this, requiredColorFormats[ndx].bitsR, requiredColorFormats[ndx].bitsG, requiredColorFormats[ndx].bitsB, requiredColorFormats[ndx].bitsA, -1, -1);
219 glDeleteRenderbuffers(1, &renderbufferID);
223 class RboComponentSizeDepthCase : public ApiCase
226 RboComponentSizeDepthCase (Context& context, const char* name, const char* description)
227 : ApiCase(context, name, description)
235 GLuint renderbufferID = 0;
236 glGenRenderbuffers(1, &renderbufferID);
237 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
238 expectError(GL_NO_ERROR);
240 const struct DepthFormat
242 GLenum internalFormat;
245 } requiredDepthFormats[] =
247 { GL_DEPTH_COMPONENT16, 16, 0 },
250 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredDepthFormats); ++ndx)
252 glRenderbufferStorage(GL_RENDERBUFFER, requiredDepthFormats[ndx].internalFormat, 1, 1);
253 expectError(GL_NO_ERROR);
255 checkRenderbufferComponentSize(m_testCtx, *this, -1, -1, -1, -1, requiredDepthFormats[ndx].dbits, requiredDepthFormats[ndx].sbits);
258 // STENCIL_INDEX8 is required, in that case sBits >= 8
260 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 1, 1);
261 expectError(GL_NO_ERROR);
263 StateQueryMemoryWriteGuard<GLint> state;
264 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_STENCIL_SIZE, &state);
266 if (state.verifyValidity(m_testCtx) && state < 8)
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");
274 glDeleteRenderbuffers(1, &renderbufferID);
281 RboStateQueryTests::RboStateQueryTests (Context& context)
282 : TestCaseGroup(context, "rbo", "Rbo State Query tests")
286 void RboStateQueryTests::init (void)
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"));