1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.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 Internal Format Query tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es3fInternalFormatQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es3fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
32 using namespace glw; // GLint and other GL types
33 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
44 class SamplesCase : public ApiCase
47 SamplesCase(Context& context, const char* name, const char* description, GLenum internalFormat, bool isIntegerInternalFormat)
48 : ApiCase (context, name, description)
49 , m_internalFormat (internalFormat)
50 , m_isIntegerInternalFormat (isIntegerInternalFormat)
58 StateQueryMemoryWriteGuard<GLint> sampleCounts;
59 glGetInternalformativ(GL_RENDERBUFFER, m_internalFormat, GL_NUM_SAMPLE_COUNTS, 1, &sampleCounts);
60 expectError(GL_NO_ERROR);
62 if (!sampleCounts.verifyValidity(m_testCtx))
65 m_testCtx.getLog() << TestLog::Message << "// sample counts is " << sampleCounts << TestLog::EndMessage;
67 if (sampleCounts == 0)
70 std::vector<GLint> samples;
71 samples.resize(sampleCounts, -1);
72 glGetInternalformativ(GL_RENDERBUFFER, m_internalFormat, GL_SAMPLES, sampleCounts, &samples[0]);
73 expectError(GL_NO_ERROR);
75 GLint prevSampleCount = 0;
76 GLint sampleCount = 0;
77 for (size_t ndx = 0; ndx < samples.size(); ++ndx, prevSampleCount = sampleCount)
79 sampleCount = samples[ndx];
81 // sample count must be > 0
84 m_testCtx.getLog() << TestLog::Message << "// ERROR: Expected sample count to be at least one; got " << sampleCount << TestLog::EndMessage;
85 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
86 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid value");
89 // samples must be ordered descending
90 if (ndx != 0 && !(sampleCount < prevSampleCount))
92 m_testCtx.getLog() << TestLog::Message
93 << "// ERROR: Expected sample count to be ordered in descending order;"
94 << "got " << prevSampleCount << " at index " << (ndx - 1) << ", and " << sampleCount << " at index " << ndx << TestLog::EndMessage;
95 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
96 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid order");
100 if (!m_isIntegerInternalFormat)
102 // the maximum value in SAMPLES is guaranteed to be at least the value of MAX_SAMPLES
103 StateQueryMemoryWriteGuard<GLint> maxSamples;
104 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
105 expectError(GL_NO_ERROR);
107 if (maxSamples.verifyValidity(m_testCtx))
109 const GLint maximumFormatSampleCount = samples[0];
110 if (!(maximumFormatSampleCount >= maxSamples))
112 m_testCtx.getLog() << TestLog::Message << "// ERROR: Expected maximum value in SAMPLES (" << maximumFormatSampleCount << ") to be at least the value of MAX_SAMPLES (" << maxSamples << ")" << TestLog::EndMessage;
113 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
114 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid maximum sample count");
121 const GLenum m_internalFormat;
122 const bool m_isIntegerInternalFormat;
125 class SamplesBufferSizeCase : public ApiCase
128 SamplesBufferSizeCase(Context& context, const char* name, const char* description, GLenum internalFormat)
129 : ApiCase (context, name, description)
130 , m_internalFormat (internalFormat)
138 StateQueryMemoryWriteGuard<GLint> sampleCounts;
139 glGetInternalformativ(GL_RENDERBUFFER, m_internalFormat, GL_NUM_SAMPLE_COUNTS, 1, &sampleCounts);
140 expectError(GL_NO_ERROR);
142 if (!sampleCounts.verifyValidity(m_testCtx))
145 // test with bufSize = 0
146 GLint queryTargetValue = -1;
147 glGetInternalformativ(GL_RENDERBUFFER, m_internalFormat, GL_NUM_SAMPLE_COUNTS, 0, &queryTargetValue);
148 expectError(GL_NO_ERROR);
150 if (queryTargetValue != -1)
152 m_testCtx.getLog() << TestLog::Message << "// ERROR: Expected output variable not to be written to." << TestLog::EndMessage;
153 if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
154 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "got invalid write");
159 GLenum m_internalFormat;
165 InternalFormatQueryTests::InternalFormatQueryTests (Context& context)
166 : TestCaseGroup(context, "internal_format", "Internal Format Query tests.")
170 void InternalFormatQueryTests::init (void)
172 const struct InternalFormat
176 bool isIntegerFormat;
177 } internalFormats[] =
179 // color renderable and unsized
180 // \note These unsized formats seem to allowed by the spec, but they are not useful in any way. (You can't create a renderbuffer with such internalFormat)
181 { "rgba", GL_RGBA, false },
182 { "rgb", GL_RGB, false },
185 { "r8", GL_R8, false },
186 { "rg8", GL_RG8, false },
187 { "rgb8", GL_RGB8, false },
188 { "rgb565", GL_RGB565, false },
189 { "rgba4", GL_RGBA4, false },
190 { "rgb5_a1", GL_RGB5_A1, false },
191 { "rgba8", GL_RGBA8, false },
192 { "rgb10_a2", GL_RGB10_A2, false },
193 { "rgb10_a2ui", GL_RGB10_A2UI, true },
194 { "srgb8_alpha8", GL_SRGB8_ALPHA8, false },
195 { "r8i", GL_R8I, true },
196 { "r8ui", GL_R8UI, true },
197 { "r16i", GL_R16I, true },
198 { "r16ui", GL_R16UI, true },
199 { "r32i", GL_R32I, true },
200 { "r32ui", GL_R32UI, true },
201 { "rg8i", GL_RG8I, true },
202 { "rg8ui", GL_RG8UI, true },
203 { "rg16i", GL_RG16I, true },
204 { "rg16ui", GL_RG16UI, true },
205 { "rg32i", GL_RG32I, true },
206 { "rg32ui", GL_RG32UI, true },
207 { "rgba8i", GL_RGBA8I, true },
208 { "rgba8ui", GL_RGBA8UI, true },
209 { "rgba16i", GL_RGBA16I, true },
210 { "rgba16ui", GL_RGBA16UI, true },
211 { "rgba32i", GL_RGBA32I, true },
212 { "rgba32ui", GL_RGBA32UI, true },
215 { "depth_component16", GL_DEPTH_COMPONENT16, false },
216 { "depth_component24", GL_DEPTH_COMPONENT24, false },
217 { "depth_component32f", GL_DEPTH_COMPONENT32F, false },
218 { "depth24_stencil8", GL_DEPTH24_STENCIL8, false },
219 { "depth32f_stencil8", GL_DEPTH32F_STENCIL8, false },
221 // stencil renderable
222 { "stencil_index8", GL_STENCIL_INDEX8, false }
223 // DEPTH24_STENCIL8, duplicate
224 // DEPTH32F_STENCIL8 duplicate
227 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(internalFormats); ++ndx)
229 const InternalFormat internalFormat = internalFormats[ndx];
231 addChild(new SamplesCase(m_context, (std::string(internalFormat.name) + "_samples").c_str(), "SAMPLES and NUM_SAMPLE_COUNTS", internalFormat.format, internalFormat.isIntegerFormat));
234 addChild(new SamplesBufferSizeCase(m_context, "rgba8_samples_buffer", "SAMPLES bufSize parameter", GL_RGBA8));