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 const int numIterations = 30;
126 for (int i = 0; i < numIterations; ++i)
128 const GLint w = rnd.getInt(0, 128);
129 const GLint h = rnd.getInt(0, 128);
131 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
132 expectError(GL_NO_ERROR);
134 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_WIDTH, w);
135 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_HEIGHT, h);
138 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
139 glDeleteRenderbuffers(1, &renderbufferID);
143 class RboInternalFormatCase : public ApiCase
146 RboInternalFormatCase (Context& context, const char* name, const char* description)
147 : ApiCase(context, name, description)
153 GLuint renderbufferID = 0;
154 glGenRenderbuffers(1, &renderbufferID);
155 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
156 expectError(GL_NO_ERROR);
158 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, GL_RGBA4);
159 expectError(GL_NO_ERROR);
161 const GLenum requiredColorformats[] =
163 GL_RGBA4, GL_RGB5_A1, GL_RGB565
166 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorformats); ++ndx)
168 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorformats[ndx], 1, 1);
169 expectError(GL_NO_ERROR);
171 checkRenderbufferParam(m_testCtx, *this, GL_RENDERBUFFER_INTERNAL_FORMAT, requiredColorformats[ndx]);
174 glDeleteRenderbuffers(1, &renderbufferID);
178 class RboComponentSizeColorCase : public ApiCase
181 RboComponentSizeColorCase (Context& context, const char* name, const char* description)
182 : ApiCase(context, name, description)
188 GLuint renderbufferID = 0;
189 glGenRenderbuffers(1, &renderbufferID);
190 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
191 expectError(GL_NO_ERROR);
193 checkRenderbufferComponentSize(m_testCtx, *this, 0, 0, 0, 0, 0, 0);
194 expectError(GL_NO_ERROR);
196 const struct ColorFormat
198 GLenum internalFormat;
199 int bitsR, bitsG, bitsB, bitsA;
200 } requiredColorFormats[] =
202 { GL_RGBA4, 4, 4, 4, 4 },
203 { GL_RGB5_A1, 5, 5, 5, 1 },
204 { GL_RGB565, 5, 6, 5, 0 },
207 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredColorFormats); ++ndx)
209 glRenderbufferStorage(GL_RENDERBUFFER, requiredColorFormats[ndx].internalFormat, 1, 1);
210 expectError(GL_NO_ERROR);
212 checkRenderbufferComponentSize(m_testCtx, *this, requiredColorFormats[ndx].bitsR, requiredColorFormats[ndx].bitsG, requiredColorFormats[ndx].bitsB, requiredColorFormats[ndx].bitsA, -1, -1);
215 glDeleteRenderbuffers(1, &renderbufferID);
219 class RboComponentSizeDepthCase : public ApiCase
222 RboComponentSizeDepthCase (Context& context, const char* name, const char* description)
223 : ApiCase(context, name, description)
231 GLuint renderbufferID = 0;
232 glGenRenderbuffers(1, &renderbufferID);
233 glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID);
234 expectError(GL_NO_ERROR);
236 const struct DepthFormat
238 GLenum internalFormat;
241 } requiredDepthFormats[] =
243 { GL_DEPTH_COMPONENT16, 16, 0 },
246 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(requiredDepthFormats); ++ndx)
248 glRenderbufferStorage(GL_RENDERBUFFER, requiredDepthFormats[ndx].internalFormat, 1, 1);
249 expectError(GL_NO_ERROR);
251 checkRenderbufferComponentSize(m_testCtx, *this, -1, -1, -1, -1, requiredDepthFormats[ndx].dbits, requiredDepthFormats[ndx].sbits);
254 // STENCIL_INDEX8 is required, in that case sBits >= 8
256 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 1, 1);
257 expectError(GL_NO_ERROR);
259 StateQueryMemoryWriteGuard<GLint> state;
260 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_STENCIL_SIZE, &state);
262 if (state.verifyValidity(m_testCtx) && state < 8)
264 m_testCtx.getLog() << TestLog::Message << "// ERROR: Expected greater or equal to 8; got " << state << TestLog::EndMessage;
265 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
266 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
270 glDeleteRenderbuffers(1, &renderbufferID);
277 RboStateQueryTests::RboStateQueryTests (Context& context)
278 : TestCaseGroup(context, "rbo", "Rbo State Query tests")
282 void RboStateQueryTests::init (void)
284 addChild(new RboSizeCase (m_context, "renderbuffer_size", "RENDERBUFFER_WIDTH and RENDERBUFFER_HEIGHT"));
285 addChild(new RboInternalFormatCase (m_context, "renderbuffer_internal_format", "RENDERBUFFER_INTERNAL_FORMAT"));
286 addChild(new RboComponentSizeColorCase (m_context, "renderbuffer_component_size_color", "RENDERBUFFER_x_SIZE"));
287 addChild(new RboComponentSizeDepthCase (m_context, "renderbuffer_component_size_depth", "RENDERBUFFER_x_SIZE"));