1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 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 Texture level state query tests
22 *//*--------------------------------------------------------------------*/
24 #include "es31fTextureLevelStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "tcuTestLog.hpp"
27 #include "gluRenderContext.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "gluTextureUtil.hpp"
30 #include "gluStrUtil.hpp"
31 #include "gluContextInfo.hpp"
32 #include "glwFunctions.hpp"
33 #include "glwEnums.hpp"
34 #include "tcuTextureUtil.hpp"
35 #include "tcuFormatUtil.hpp"
36 #include "deStringUtil.hpp"
37 #include "deUniquePtr.hpp"
48 using namespace gls::StateQueryUtil;
51 static bool textureTypeHasDepth (glw::GLenum textureBindTarget)
53 switch (textureBindTarget)
55 case GL_TEXTURE_2D: return false;
56 case GL_TEXTURE_3D: return true;
57 case GL_TEXTURE_2D_ARRAY: return true;
58 case GL_TEXTURE_CUBE_MAP: return false;
59 case GL_TEXTURE_2D_MULTISAMPLE: return false;
60 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: return true;
61 case GL_TEXTURE_BUFFER: return false;
62 case GL_TEXTURE_CUBE_MAP_ARRAY: return true;
69 static bool textureTypeHasHeight (glw::GLenum textureBindTarget)
71 switch (textureBindTarget)
73 case GL_TEXTURE_2D: return true;
74 case GL_TEXTURE_3D: return true;
75 case GL_TEXTURE_2D_ARRAY: return true;
76 case GL_TEXTURE_CUBE_MAP: return true;
77 case GL_TEXTURE_2D_MULTISAMPLE: return true;
78 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: return true;
79 case GL_TEXTURE_BUFFER: return false;
80 case GL_TEXTURE_CUBE_MAP_ARRAY: return true;
87 static const char* getTextureTargetExtension (glw::GLenum target)
91 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: return "GL_OES_texture_storage_multisample_2d_array";
92 case GL_TEXTURE_BUFFER: return "GL_EXT_texture_buffer";
93 case GL_TEXTURE_CUBE_MAP_ARRAY: return "GL_EXT_texture_cube_map_array";
100 static bool isCoreTextureTarget (glw::GLenum target)
106 case GL_TEXTURE_2D_ARRAY:
107 case GL_TEXTURE_CUBE_MAP:
108 case GL_TEXTURE_2D_MULTISAMPLE:
116 struct TextureGenerationSpec
118 struct TextureLevelSpec
124 glw::GLenum internalFormat;
127 TextureLevelSpec (void)
132 , internalFormat (GL_RGBA)
138 glw::GLenum bindTarget;
139 glw::GLenum queryTarget;
141 bool fixedSamplePos; // !< fixed sample pos argument for multisample textures
143 int texBufferDataOffset;
144 int texBufferDataSize;
146 std::vector<TextureLevelSpec> levels;
147 std::string description;
149 TextureGenerationSpec (void)
151 , fixedSamplePos (true)
153 , texBufferDataOffset (0)
154 , texBufferDataSize (256)
155 , bindWholeArray (false)
159 struct IntegerPrinter
161 static std::string getIntegerName (int v) { return de::toString(v); }
162 static std::string getFloatName (float v) { return de::toString(v); }
165 struct PixelFormatPrinter
167 static std::string getIntegerName (int v) { return de::toString(glu::getPixelFormatStr(v)); }
168 static std::string getFloatName (float v) { return de::toString(glu::getPixelFormatStr((int)v)); }
171 template <typename Printer>
172 static bool verifyTextureLevelParameterEqualWithPrinter (glu::CallLogWrapper& gl, glw::GLenum target, int level, glw::GLenum pname, int refValue, QueryType type)
175 tcu::ResultCollector result (gl.getLog(), " // ERROR: ");
177 gl.getLog() << tcu::TestLog::Message << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting " << Printer::getIntegerName(refValue) << tcu::TestLog::EndMessage;
178 queryTextureLevelState(result, gl, type, target, level, pname, state);
180 if (state.isUndefined())
183 verifyInteger(result, state, refValue);
185 return result.getResult() == QP_TEST_RESULT_LAST;
188 static bool verifyTextureLevelParameterEqual (glu::CallLogWrapper& gl, glw::GLenum target, int level, glw::GLenum pname, int refValue, QueryType type)
190 return verifyTextureLevelParameterEqualWithPrinter<IntegerPrinter>(gl, target, level, pname, refValue, type);
193 static bool verifyTextureLevelParameterInternalFormatEqual (glu::CallLogWrapper& gl, glw::GLenum target, int level, glw::GLenum pname, int refValue, QueryType type)
195 return verifyTextureLevelParameterEqualWithPrinter<PixelFormatPrinter>(gl, target, level, pname, refValue, type);
198 static bool verifyTextureLevelParameterGreaterOrEqual (glu::CallLogWrapper& gl, glw::GLenum target, int level, glw::GLenum pname, int refValue, QueryType type)
201 tcu::ResultCollector result (gl.getLog(), " // ERROR: ");
203 gl.getLog() << tcu::TestLog::Message << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting " << refValue << " or greater" << tcu::TestLog::EndMessage;
204 queryTextureLevelState(result, gl, type, target, level, pname, state);
206 if (state.isUndefined())
209 verifyIntegerMin(result, state, refValue);
211 return result.getResult() == QP_TEST_RESULT_LAST;
214 static bool verifyTextureLevelParameterInternalFormatAnyOf (glu::CallLogWrapper& gl, glw::GLenum target, int level, glw::GLenum pname, const int* refValues, int numRefValues, QueryType type)
217 tcu::ResultCollector result (gl.getLog(), " // ERROR: ");
219 // Log what we try to do
221 tcu::MessageBuilder msg(&gl.getLog());
223 msg << "Verifying " << glu::getTextureLevelParameterStr(pname) << ", expecting any of {";
224 for (int ndx = 0; ndx < numRefValues; ++ndx)
228 msg << glu::getPixelFormatStr(refValues[ndx]);
231 msg << tcu::TestLog::EndMessage;
234 queryTextureLevelState(result, gl, type, target, level, pname, state);
235 if (state.isUndefined())
239 switch (state.getType())
241 case DATATYPE_INTEGER:
243 for (int ndx = 0; ndx < numRefValues; ++ndx)
244 if (state.getIntAccess() == refValues[ndx])
247 gl.getLog() << tcu::TestLog::Message << "Error: got " << state.getIntAccess() << ", (" << glu::getPixelFormatStr(state.getIntAccess()) << ")" << tcu::TestLog::EndMessage;
252 for (int ndx = 0; ndx < numRefValues; ++ndx)
253 if (state.getFloatAccess() == (float)refValues[ndx])
256 gl.getLog() << tcu::TestLog::Message << "Error: got " << state.getFloatAccess() << ", (" << glu::getPixelFormatStr((int)state.getFloatAccess()) << ")" << tcu::TestLog::EndMessage;
265 static bool isDepthFormat (const tcu::TextureFormat& fmt)
267 return fmt.order == tcu::TextureFormat::D || fmt.order == tcu::TextureFormat::DS;
270 static bool isColorRenderableFormat (glw::GLenum internalFormat)
272 return internalFormat == GL_RGB565 ||
273 internalFormat == GL_RGBA4 ||
274 internalFormat == GL_RGB5_A1 ||
275 internalFormat == GL_RGB10_A2 ||
276 internalFormat == GL_RGB10_A2UI ||
277 internalFormat == GL_SRGB8_ALPHA8 ||
278 internalFormat == GL_R8 ||
279 internalFormat == GL_RG8 ||
280 internalFormat == GL_RGB8 ||
281 internalFormat == GL_RGBA8 ||
282 internalFormat == GL_R8I ||
283 internalFormat == GL_RG8I ||
284 internalFormat == GL_RGBA8I ||
285 internalFormat == GL_R8UI ||
286 internalFormat == GL_RG8UI ||
287 internalFormat == GL_RGBA8UI ||
288 internalFormat == GL_R16I ||
289 internalFormat == GL_RG16I ||
290 internalFormat == GL_RGBA16I ||
291 internalFormat == GL_R16UI ||
292 internalFormat == GL_RG16UI ||
293 internalFormat == GL_RGBA16UI ||
294 internalFormat == GL_R32I ||
295 internalFormat == GL_RG32I ||
296 internalFormat == GL_RGBA32I ||
297 internalFormat == GL_R32UI ||
298 internalFormat == GL_RG32UI ||
299 internalFormat == GL_RGBA32UI;
302 static bool isRenderableFormat (glw::GLenum internalFormat)
304 return isColorRenderableFormat(internalFormat) ||
305 internalFormat == GL_DEPTH_COMPONENT16 ||
306 internalFormat == GL_DEPTH_COMPONENT24 ||
307 internalFormat == GL_DEPTH_COMPONENT32F ||
308 internalFormat == GL_DEPTH24_STENCIL8 ||
309 internalFormat == GL_DEPTH32F_STENCIL8;
312 static bool isTextureBufferFormat (glw::GLenum internalFormat)
314 return internalFormat == GL_R8 ||
315 internalFormat == GL_R16F ||
316 internalFormat == GL_R32F ||
317 internalFormat == GL_R8I ||
318 internalFormat == GL_R16I ||
319 internalFormat == GL_R32I ||
320 internalFormat == GL_R8UI ||
321 internalFormat == GL_R16UI ||
322 internalFormat == GL_R32UI ||
323 internalFormat == GL_RG8 ||
324 internalFormat == GL_RG16F ||
325 internalFormat == GL_RG32F ||
326 internalFormat == GL_RG8I ||
327 internalFormat == GL_RG16I ||
328 internalFormat == GL_RG32I ||
329 internalFormat == GL_RG8UI ||
330 internalFormat == GL_RG16UI ||
331 internalFormat == GL_RG32UI ||
332 internalFormat == GL_RGB32F ||
333 internalFormat == GL_RGB32I ||
334 internalFormat == GL_RGB32UI ||
335 internalFormat == GL_RGBA8 ||
336 internalFormat == GL_RGBA16F ||
337 internalFormat == GL_RGBA32F ||
338 internalFormat == GL_RGBA8I ||
339 internalFormat == GL_RGBA16I ||
340 internalFormat == GL_RGBA32I ||
341 internalFormat == GL_RGBA8UI ||
342 internalFormat == GL_RGBA16UI ||
343 internalFormat == GL_RGBA32UI;
346 static bool isLegalFormatForTarget (glw::GLenum target, glw::GLenum format)
348 const tcu::TextureFormat fmt = glu::mapGLInternalFormat(format);
350 if (target == GL_TEXTURE_3D && isDepthFormat(fmt))
352 if ((target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) && !isRenderableFormat(format))
354 if (target == GL_TEXTURE_BUFFER || !isTextureBufferFormat(format))
359 static bool isCompressionSupportedForTarget (glw::GLenum target)
361 return target == GL_TEXTURE_2D || target == GL_TEXTURE_2D_ARRAY;
364 static bool isMultisampleTarget (glw::GLenum target)
366 return target == GL_TEXTURE_2D_MULTISAMPLE || target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
369 static bool targetSupportsMipLevels (glw::GLenum target)
371 return target != GL_TEXTURE_2D_MULTISAMPLE &&
372 target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY &&
373 target != GL_TEXTURE_BUFFER;
376 static int getPixelSize (glw::GLenum internalFormat)
378 const tcu::TextureFormat fmt = glu::mapGLInternalFormat(internalFormat);
379 return fmt.getPixelSize();
382 static void generateColorTextureGenerationGroup (std::vector<TextureGenerationSpec>& group, glw::GLenum target, int maxSamples, glw::GLenum internalFormat)
384 const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
388 TextureGenerationSpec texGen;
389 texGen.bindTarget = target;
390 texGen.queryTarget = queryTarget;
391 texGen.immutable = true;
392 texGen.sampleCount = 0;
393 texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
395 group.push_back(texGen);
399 if (isMultisampleTarget(target))
402 TextureGenerationSpec texGen;
403 TextureGenerationSpec::TextureLevelSpec level;
405 texGen.bindTarget = target;
406 texGen.queryTarget = queryTarget;
407 texGen.immutable = true;
408 texGen.sampleCount = 1;
409 texGen.fixedSamplePos = false;
410 texGen.description = glu::getTextureTargetStr(target).toString() + ", low sample count";
414 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
416 level.internalFormat = internalFormat;
417 level.compressed = false;
419 texGen.levels.push_back(level);
420 group.push_back(texGen);
423 TextureGenerationSpec texGen;
424 TextureGenerationSpec::TextureLevelSpec level;
426 texGen.bindTarget = target;
427 texGen.queryTarget = queryTarget;
428 texGen.immutable = true;
429 texGen.sampleCount = maxSamples;
430 texGen.fixedSamplePos = false;
431 texGen.description = glu::getTextureTargetStr(target).toString() + ", high sample count";
435 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
437 level.internalFormat = internalFormat;
438 level.compressed = false;
440 texGen.levels.push_back(level);
441 group.push_back(texGen);
444 TextureGenerationSpec texGen;
445 TextureGenerationSpec::TextureLevelSpec level;
447 texGen.bindTarget = target;
448 texGen.queryTarget = queryTarget;
449 texGen.immutable = true;
450 texGen.sampleCount = maxSamples;
451 texGen.fixedSamplePos = true;
452 texGen.description = glu::getTextureTargetStr(target).toString() + ", fixed sample positions";
456 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
458 level.internalFormat = internalFormat;
459 level.compressed = false;
461 texGen.levels.push_back(level);
462 group.push_back(texGen);
465 else if (target == GL_TEXTURE_BUFFER)
469 TextureGenerationSpec texGen;
470 TextureGenerationSpec::TextureLevelSpec level;
471 const int baseSize = getPixelSize(internalFormat);
473 texGen.bindTarget = target;
474 texGen.queryTarget = queryTarget;
475 texGen.immutable = true;
476 texGen.description = glu::getTextureTargetStr(target).toString() + ", whole buffer";
477 texGen.texBufferDataOffset = 0;
478 texGen.texBufferDataSize = 32 * baseSize + (baseSize - 1);
479 texGen.bindWholeArray = true;
485 level.internalFormat = internalFormat;
486 level.compressed = false;
488 texGen.levels.push_back(level);
489 group.push_back(texGen);
493 TextureGenerationSpec texGen;
494 TextureGenerationSpec::TextureLevelSpec level;
495 const int baseSize = getPixelSize(internalFormat);
497 texGen.bindTarget = target;
498 texGen.queryTarget = queryTarget;
499 texGen.immutable = true;
500 texGen.description = glu::getTextureTargetStr(target).toString() + ", partial buffer";
501 texGen.texBufferDataOffset = 256;
502 texGen.texBufferDataSize = 16 * baseSize + (baseSize - 1);
503 texGen.bindWholeArray = false;
509 level.internalFormat = internalFormat;
510 level.compressed = false;
512 texGen.levels.push_back(level);
513 group.push_back(texGen);
520 TextureGenerationSpec texGen;
521 TextureGenerationSpec::TextureLevelSpec level;
523 texGen.bindTarget = target;
524 texGen.queryTarget = queryTarget;
525 texGen.immutable = true;
526 texGen.description = glu::getTextureTargetStr(target).toString() + ", immutable";
530 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
532 level.internalFormat = internalFormat;
533 level.compressed = false;
535 texGen.levels.push_back(level);
536 group.push_back(texGen);
540 TextureGenerationSpec texGen;
541 TextureGenerationSpec::TextureLevelSpec level;
543 texGen.bindTarget = target;
544 texGen.queryTarget = queryTarget;
545 texGen.immutable = false;
546 texGen.description = glu::getTextureTargetStr(target).toString() + ", mutable";
549 level.height = (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) ? (16) : (64);
550 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
552 level.internalFormat = internalFormat;
553 level.compressed = false;
555 texGen.levels.push_back(level);
556 group.push_back(texGen);
560 TextureGenerationSpec texGen;
561 TextureGenerationSpec::TextureLevelSpec level;
563 texGen.bindTarget = target;
564 texGen.queryTarget = queryTarget;
565 texGen.immutable = false;
566 texGen.description = glu::getTextureTargetStr(target).toString() + ", mip level 3";
569 level.height = (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) ? (4) : (8);
570 level.depth = (textureTypeHasDepth(texGen.bindTarget)) ? (6) : (0);
572 level.internalFormat = internalFormat;
573 level.compressed = false;
575 texGen.levels.push_back(level);
576 group.push_back(texGen);
581 static void generateInternalFormatTextureGenerationGroup (std::vector<TextureGenerationSpec>& group, glw::GLenum target)
583 const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
586 static const glw::GLenum internalFormats[] =
588 GL_R8, GL_R8_SNORM, GL_RG8, GL_RG8_SNORM, GL_RGB8, GL_RGB8_SNORM, GL_RGB565, GL_RGBA4, GL_RGB5_A1,
589 GL_RGBA8, GL_RGBA8_SNORM, GL_RGB10_A2, GL_RGB10_A2UI, GL_SRGB8, GL_SRGB8_ALPHA8, GL_R16F, GL_RG16F,
590 GL_RGB16F, GL_RGBA16F, GL_R32F, GL_RG32F, GL_RGB32F, GL_RGBA32F, GL_R11F_G11F_B10F, GL_RGB9_E5, GL_R8I,
591 GL_R8UI, GL_R16I, GL_R16UI, GL_R32I, GL_R32UI, GL_RG8I, GL_RG8UI, GL_RG16I, GL_RG16UI, GL_RG32I, GL_RG32UI,
592 GL_RGB8I, GL_RGB8UI, GL_RGB16I, GL_RGB16UI, GL_RGB32I, GL_RGB32UI, GL_RGBA8I, GL_RGBA8UI, GL_RGBA16I,
593 GL_RGBA16UI, GL_RGBA32I, GL_RGBA32UI,
595 GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT16,
596 GL_DEPTH32F_STENCIL8, GL_DEPTH24_STENCIL8
601 TextureGenerationSpec texGen;
602 texGen.bindTarget = target;
603 texGen.queryTarget = queryTarget;
604 texGen.immutable = true;
605 texGen.sampleCount = 0;
606 texGen.fixedSamplePos = true;
607 texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
609 group.push_back(texGen);
613 for (int internalFormatNdx = 0; internalFormatNdx < DE_LENGTH_OF_ARRAY(internalFormats); ++internalFormatNdx)
615 if (!isLegalFormatForTarget(target, internalFormats[internalFormatNdx]))
618 const int baseSize = getPixelSize(internalFormats[internalFormatNdx]);
619 TextureGenerationSpec texGen;
620 TextureGenerationSpec::TextureLevelSpec level;
622 texGen.bindTarget = target;
623 texGen.queryTarget = queryTarget;
624 texGen.immutable = true;
625 texGen.sampleCount = (isMultisampleTarget(target) ? (1) : (0));
626 texGen.description = glu::getTextureTargetStr(target).toString() + ", internal format " + glu::getPixelFormatName(internalFormats[internalFormatNdx]);
628 if (target == GL_TEXTURE_BUFFER)
630 texGen.texBufferDataOffset = 0;
631 texGen.texBufferDataSize = 32 * baseSize + (baseSize - 1);
632 texGen.bindWholeArray = true;
636 level.height = (textureTypeHasHeight(target)) ? (32) : (0);
637 level.depth = (textureTypeHasDepth(target)) ? (6) : (0);
639 level.internalFormat = internalFormats[internalFormatNdx];
640 level.compressed = false;
642 texGen.levels.push_back(level);
643 group.push_back(texGen);
646 // test mutable rgba8 with mip level 3
647 if (targetSupportsMipLevels(target))
649 TextureGenerationSpec texGen;
650 TextureGenerationSpec::TextureLevelSpec level;
652 texGen.bindTarget = target;
653 texGen.queryTarget = queryTarget;
654 texGen.immutable = false;
655 texGen.description = glu::getTextureTargetStr(target).toString() + ", internal format GL_RGBA8, mip level 3";
659 level.depth = (textureTypeHasDepth(target)) ? (6) : (0);
661 level.internalFormat = GL_RGBA8;
662 level.compressed = false;
664 texGen.levels.push_back(level);
665 group.push_back(texGen);
669 static void generateCompressedTextureGenerationGroup (std::vector<TextureGenerationSpec>& group, glw::GLenum target)
671 const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
675 TextureGenerationSpec texGen;
676 texGen.bindTarget = target;
677 texGen.queryTarget = queryTarget;
678 texGen.immutable = true;
679 texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
681 group.push_back(texGen);
685 if (isCompressionSupportedForTarget(target))
687 TextureGenerationSpec texGen;
688 TextureGenerationSpec::TextureLevelSpec level;
690 texGen.bindTarget = target;
691 texGen.queryTarget = queryTarget;
692 texGen.immutable = false;
693 texGen.description = glu::getTextureTargetStr(target).toString() + ", compressed";
697 level.depth = (target == GL_TEXTURE_2D_ARRAY) ? (2) : (0);
699 level.internalFormat = GL_COMPRESSED_RGB8_ETC2;
700 level.compressed = true;
702 texGen.levels.push_back(level);
703 group.push_back(texGen);
707 static void generateTextureBufferGenerationGroup (std::vector<TextureGenerationSpec>& group, glw::GLenum target)
709 const glw::GLenum queryTarget = (target == GL_TEXTURE_CUBE_MAP) ? (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) : (target);
713 TextureGenerationSpec texGen;
714 texGen.bindTarget = target;
715 texGen.queryTarget = queryTarget;
716 texGen.immutable = true;
717 texGen.sampleCount = 0;
718 texGen.description = glu::getTextureTargetStr(target).toString() + ", initial values";
720 group.push_back(texGen);
723 // actual specification tests are in texture_buffer tests, no need to do them here too
726 bool applyTextureGenerationSpec (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec, glw::GLuint& texBuffer)
730 DE_ASSERT(!(spec.immutable && spec.levels.size() > 1)); // !< immutable textures have only one level
732 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
734 const glu::TransferFormat transferFormat = (spec.levels[levelNdx].compressed) ? (glu::TransferFormat()) : (glu::getTransferFormat(glu::mapGLInternalFormat(spec.levels[levelNdx].internalFormat)));
736 if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
737 gl.glTexStorage2D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height);
738 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_3D)
739 gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
740 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
741 gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
742 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP)
743 gl.glTexStorage2D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height);
744 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_MULTISAMPLE)
745 gl.glTexStorage2DMultisample(spec.bindTarget, spec.sampleCount, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, (spec.fixedSamplePos) ? (GL_TRUE) : (GL_FALSE));
746 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
747 gl.glTexStorage3DMultisample(spec.bindTarget, spec.sampleCount, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, (spec.fixedSamplePos) ? (GL_TRUE) : (GL_FALSE));
748 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
749 gl.glTexStorage3D(spec.bindTarget, 1, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth);
750 else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
751 gl.glTexImage2D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, 0, transferFormat.format, transferFormat.dataType, DE_NULL);
752 else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_3D)
753 gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0, transferFormat.format, transferFormat.dataType, DE_NULL);
754 else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
755 gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0, transferFormat.format, transferFormat.dataType, DE_NULL);
756 else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP)
757 gl.glTexImage2D(spec.queryTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, 0, transferFormat.format, transferFormat.dataType, DE_NULL);
758 else if (!spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
759 gl.glTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0, transferFormat.format, transferFormat.dataType, DE_NULL);
760 else if (!spec.immutable && spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D)
762 DE_ASSERT(spec.levels[levelNdx].width == 32);
763 DE_ASSERT(spec.levels[levelNdx].height == 32);
764 DE_ASSERT(spec.levels[levelNdx].internalFormat == GL_COMPRESSED_RGB8_ETC2);
766 static const deUint8 buffer[64 * 8] = { 0 };
767 gl.glCompressedTexImage2D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, 0, sizeof(buffer), buffer);
769 else if (!spec.immutable && spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_2D_ARRAY)
771 DE_ASSERT(spec.levels[levelNdx].width == 32);
772 DE_ASSERT(spec.levels[levelNdx].height == 32);
773 DE_ASSERT(spec.levels[levelNdx].depth == 2);
774 DE_ASSERT(spec.levels[levelNdx].internalFormat == GL_COMPRESSED_RGB8_ETC2);
776 static const deUint8 buffer[64 * 8 * 2] = { 0 };
777 gl.glCompressedTexImage3D(spec.bindTarget, spec.levels[levelNdx].level, spec.levels[levelNdx].internalFormat, spec.levels[levelNdx].width, spec.levels[levelNdx].height, spec.levels[levelNdx].depth, 0, sizeof(buffer), buffer);
779 else if (spec.immutable && !spec.levels[levelNdx].compressed && spec.bindTarget == GL_TEXTURE_BUFFER)
781 gl.glGenBuffers(1, &texBuffer);
782 gl.glBindBuffer(GL_TEXTURE_BUFFER, texBuffer);
784 if (spec.bindWholeArray)
786 gl.glBufferData(GL_TEXTURE_BUFFER, spec.texBufferDataSize, DE_NULL, GL_STATIC_DRAW);
787 gl.glTexBuffer(GL_TEXTURE_BUFFER, spec.levels[levelNdx].internalFormat, texBuffer);
791 gl.glBufferData(GL_TEXTURE_BUFFER, spec.texBufferDataOffset + spec.texBufferDataSize, DE_NULL, GL_STATIC_DRAW);
792 gl.glTexBufferRange(GL_TEXTURE_BUFFER, spec.levels[levelNdx].internalFormat, texBuffer, spec.texBufferDataOffset, spec.texBufferDataSize);
799 const glw::GLenum err = gl.glGetError();
800 if (err != GL_NO_ERROR)
802 gl.getLog() << tcu::TestLog::Message
803 << "Texture specification failed, got " + glu::getErrorStr(err).toString()
804 << tcu::TestLog::EndMessage;
813 class TextureLevelCase : public TestCase
816 TextureLevelCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type);
817 ~TextureLevelCase (void);
821 IterateResult iterate (void);
824 void getFormatSamples (glw::GLenum internalFormat, std::vector<int>& samples);
825 bool testConfig (const TextureGenerationSpec& spec);
826 virtual bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec) = 0;
827 virtual void generateTestIterations (std::vector<TextureGenerationSpec>& iterations) = 0;
829 const QueryType m_type;
830 const glw::GLenum m_target;
831 glw::GLuint m_texture;
832 glw::GLuint m_texBuffer;
836 std::vector<TextureGenerationSpec> m_iterations;
837 bool m_allIterationsOk;
838 std::vector<int> m_failedIterations;
841 TextureLevelCase::TextureLevelCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
842 : TestCase (ctx, name, desc)
848 , m_allIterationsOk (true)
852 TextureLevelCase::~TextureLevelCase (void)
857 void TextureLevelCase::init (void)
859 if (!isCoreTextureTarget(m_target))
861 const char* const targetExtension = getTextureTargetExtension(m_target);
863 if (!m_context.getContextInfo().isExtensionSupported(targetExtension))
864 throw tcu::NotSupportedError("Test requires " + std::string(targetExtension) + " extension");
867 generateTestIterations(m_iterations);
869 for (int iterationNdx = 0; iterationNdx < (int)m_iterations.size(); ++iterationNdx)
870 DE_ASSERT(m_iterations[iterationNdx].bindTarget == m_target);
873 void TextureLevelCase::deinit (void)
877 m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texture);
882 m_context.getRenderContext().getFunctions().deleteTextures(1, &m_texBuffer);
887 void TextureLevelCase::getFormatSamples (glw::GLenum internalFormat, std::vector<int>& samples)
889 const glw::Functions gl = m_context.getRenderContext().getFunctions();
890 int sampleCount = -1;
892 if (!isMultisampleTarget(m_target))
895 gl.getInternalformativ(m_target, internalFormat, GL_NUM_SAMPLE_COUNTS, 1, &sampleCount);
898 throw tcu::TestError("internal format query failed");
900 samples.resize(sampleCount);
904 gl.getInternalformativ(m_target, internalFormat, GL_SAMPLES, sampleCount, &samples[0]);
905 GLU_EXPECT_NO_ERROR(gl.getError(), "get max samples");
909 TextureLevelCase::IterateResult TextureLevelCase::iterate (void)
911 const bool result = testConfig(m_iterations[m_iteration]);
915 m_failedIterations.push_back(m_iteration);
916 m_allIterationsOk = false;
919 if (++m_iteration < (int)m_iterations.size())
922 if (m_allIterationsOk)
923 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
926 tcu::MessageBuilder msg(&m_testCtx.getLog());
928 msg << "Following iteration(s) failed: ";
929 for (int ndx = 0; ndx < (int)m_failedIterations.size(); ++ndx)
933 msg << (m_failedIterations[ndx] + 1);
935 msg << tcu::TestLog::EndMessage;
937 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "One or more iterations failed");
942 bool TextureLevelCase::testConfig (const TextureGenerationSpec& spec)
944 const tcu::ScopedLogSection section(m_testCtx.getLog(), "Iteration", std::string() + "Iteration " + de::toString(m_iteration+1) + "/" + de::toString((int)m_iterations.size()) + " - " + spec.description);
945 glu::CallLogWrapper gl (m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
948 gl.enableLogging(true);
950 gl.glGenTextures(1, &m_texture);
951 gl.glBindTexture(spec.bindTarget, m_texture);
952 GLU_EXPECT_NO_ERROR(gl.glGetError(), "gen tex");
955 applyTextureGenerationSpec(gl, spec, m_texBuffer);
958 result = checkTextureState(gl, spec);
960 gl.glDeleteTextures(1, &m_texture);
965 gl.glDeleteTextures(1, &m_texBuffer);
972 /*--------------------------------------------------------------------*//*!
973 * \brief Test texture target
974 *//*--------------------------------------------------------------------*/
975 class TextureLevelCommonCase : public TextureLevelCase
978 TextureLevelCommonCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type);
981 virtual void generateTestIterations (std::vector<TextureGenerationSpec>& iterations);
984 TextureLevelCommonCase::TextureLevelCommonCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
985 : TextureLevelCase(ctx, name, desc, target, type)
989 void TextureLevelCommonCase::generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
991 const glw::GLenum internalFormat = GL_RGBA8;
993 std::vector<int> samples;
995 getFormatSamples(internalFormat, samples);
999 maxSamples = samples[0];
1001 generateColorTextureGenerationGroup(iterations, m_target, maxSamples, internalFormat);
1004 class TextureLevelSampleCase : public TextureLevelCommonCase
1007 TextureLevelSampleCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1008 : TextureLevelCommonCase(ctx, name, desc, target, type)
1013 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1015 const int queryLevel = (spec.levels.empty()) ? (0) : (spec.levels[0].level);
1016 const int refValue = (spec.levels.empty()) ? (0) : (spec.sampleCount);
1018 return verifyTextureLevelParameterGreaterOrEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_SAMPLES, refValue, m_type);
1022 class TextureLevelFixedSamplesCase : public TextureLevelCommonCase
1025 TextureLevelFixedSamplesCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1026 : TextureLevelCommonCase(ctx, name, desc, target, type)
1031 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1033 const int queryLevel = 0;
1034 const int refValue = (spec.levels.empty()) ? (1) : ((spec.fixedSamplePos) ? (1) : (0));
1036 return verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_FIXED_SAMPLE_LOCATIONS, refValue, m_type);
1040 class TextureLevelWidthCase : public TextureLevelCommonCase
1043 TextureLevelWidthCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1044 : TextureLevelCommonCase(ctx, name, desc, target, type)
1049 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1051 const int initialValue = 0;
1054 if (spec.levels.empty())
1056 const int queryLevel = 0;
1057 const int refValue = initialValue;
1059 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_WIDTH, refValue, m_type);
1063 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1065 const int queryLevel = spec.levels[levelNdx].level;
1066 const int refValue = spec.levels[levelNdx].width;
1068 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_WIDTH, refValue, m_type);
1076 class TextureLevelHeightCase : public TextureLevelCommonCase
1079 TextureLevelHeightCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1080 : TextureLevelCommonCase(ctx, name, desc, target, type)
1085 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1087 const int initialValue = 0;
1090 if (spec.levels.empty())
1092 const int queryLevel = 0;
1093 const int refValue = initialValue;
1095 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_HEIGHT, refValue, m_type);
1099 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1101 const int queryLevel = spec.levels[levelNdx].level;
1102 const int refValue = spec.levels[levelNdx].height;
1104 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_HEIGHT, refValue, m_type);
1112 class TextureLevelDepthCase : public TextureLevelCommonCase
1115 TextureLevelDepthCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1116 : TextureLevelCommonCase(ctx, name, desc, target, type)
1122 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1124 const int initialValue = 0;
1127 if (spec.levels.empty())
1129 const int queryLevel = 0;
1130 const int refValue = initialValue;
1132 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_DEPTH, refValue, m_type);
1136 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1138 const int queryLevel = spec.levels[levelNdx].level;
1139 const int refValue = spec.levels[levelNdx].depth;
1141 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_DEPTH, refValue, m_type);
1149 class TextureLevelInternalFormatCase : public TextureLevelCase
1152 TextureLevelInternalFormatCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1153 : TextureLevelCase(ctx, name, desc, target, type)
1158 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1160 generateInternalFormatTextureGenerationGroup(iterations, m_target);
1163 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1167 if (spec.levels.empty())
1169 const int queryLevel = 0;
1170 const int initialValues[2] = { GL_RGBA, GL_R8 };
1172 allOk &= verifyTextureLevelParameterInternalFormatAnyOf(gl, spec.queryTarget, queryLevel, GL_TEXTURE_INTERNAL_FORMAT, initialValues, DE_LENGTH_OF_ARRAY(initialValues), m_type);
1176 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1178 const int queryLevel = spec.levels[levelNdx].level;
1179 const int refValue = spec.levels[levelNdx].internalFormat;
1181 allOk &= verifyTextureLevelParameterInternalFormatEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_INTERNAL_FORMAT, refValue, m_type);
1189 class TextureLevelSizeCase : public TextureLevelCase
1192 TextureLevelSizeCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type, glw::GLenum pname);
1195 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations);
1196 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec);
1197 int getMinimumComponentResolution (glw::GLenum internalFormat);
1199 const glw::GLenum m_pname;
1202 TextureLevelSizeCase::TextureLevelSizeCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type, glw::GLenum pname)
1203 : TextureLevelCase (ctx, name, desc, target, type)
1208 void TextureLevelSizeCase::generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1210 generateInternalFormatTextureGenerationGroup(iterations, m_target);
1213 bool TextureLevelSizeCase::checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1217 if (spec.levels.empty())
1219 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, m_pname, 0, m_type);
1223 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1225 const int queryLevel = spec.levels[levelNdx].level;
1226 const int refValue = getMinimumComponentResolution(spec.levels[levelNdx].internalFormat);
1228 allOk &= verifyTextureLevelParameterGreaterOrEqual(gl, spec.queryTarget, queryLevel, m_pname, refValue, m_type);
1235 int TextureLevelSizeCase::getMinimumComponentResolution (glw::GLenum internalFormat)
1237 const tcu::TextureFormat format = glu::mapGLInternalFormat(internalFormat);
1238 const tcu::IVec4 channelBitDepth = tcu::getTextureFormatBitDepth(format);
1242 case GL_TEXTURE_RED_SIZE:
1243 if (format.order == tcu::TextureFormat::R ||
1244 format.order == tcu::TextureFormat::RG ||
1245 format.order == tcu::TextureFormat::RGB ||
1246 format.order == tcu::TextureFormat::RGBA ||
1247 format.order == tcu::TextureFormat::BGRA ||
1248 format.order == tcu::TextureFormat::ARGB ||
1249 format.order == tcu::TextureFormat::sRGB ||
1250 format.order == tcu::TextureFormat::sRGBA)
1251 return channelBitDepth[0];
1255 case GL_TEXTURE_GREEN_SIZE:
1256 if (format.order == tcu::TextureFormat::RG ||
1257 format.order == tcu::TextureFormat::RGB ||
1258 format.order == tcu::TextureFormat::RGBA ||
1259 format.order == tcu::TextureFormat::BGRA ||
1260 format.order == tcu::TextureFormat::ARGB ||
1261 format.order == tcu::TextureFormat::sRGB ||
1262 format.order == tcu::TextureFormat::sRGBA)
1263 return channelBitDepth[1];
1267 case GL_TEXTURE_BLUE_SIZE:
1268 if (format.order == tcu::TextureFormat::RGB ||
1269 format.order == tcu::TextureFormat::RGBA ||
1270 format.order == tcu::TextureFormat::BGRA ||
1271 format.order == tcu::TextureFormat::ARGB ||
1272 format.order == tcu::TextureFormat::sRGB ||
1273 format.order == tcu::TextureFormat::sRGBA)
1274 return channelBitDepth[2];
1278 case GL_TEXTURE_ALPHA_SIZE:
1279 if (format.order == tcu::TextureFormat::RGBA ||
1280 format.order == tcu::TextureFormat::BGRA ||
1281 format.order == tcu::TextureFormat::ARGB ||
1282 format.order == tcu::TextureFormat::sRGBA)
1283 return channelBitDepth[3];
1287 case GL_TEXTURE_DEPTH_SIZE:
1288 if (format.order == tcu::TextureFormat::D ||
1289 format.order == tcu::TextureFormat::DS)
1290 return channelBitDepth[0];
1294 case GL_TEXTURE_STENCIL_SIZE:
1295 if (format.order == tcu::TextureFormat::DS)
1296 return channelBitDepth[3];
1300 case GL_TEXTURE_SHARED_SIZE:
1301 if (internalFormat == GL_RGB9_E5)
1306 DE_ASSERT(DE_FALSE);
1311 class TextureLevelTypeCase : public TextureLevelCase
1314 TextureLevelTypeCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type, glw::GLenum pname);
1317 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations);
1318 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec);
1319 int getComponentType (glw::GLenum internalFormat);
1321 const glw::GLenum m_pname;
1324 TextureLevelTypeCase::TextureLevelTypeCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type, glw::GLenum pname)
1325 : TextureLevelCase (ctx, name, desc, target, type)
1330 void TextureLevelTypeCase::generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1332 generateInternalFormatTextureGenerationGroup(iterations, m_target);
1335 bool TextureLevelTypeCase::checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1339 if (spec.levels.empty())
1341 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, m_pname, GL_NONE, m_type);
1345 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1347 const int queryLevel = spec.levels[levelNdx].level;
1348 const int refValue = getComponentType(spec.levels[levelNdx].internalFormat);
1350 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, m_pname, refValue, m_type);
1357 int TextureLevelTypeCase::getComponentType (glw::GLenum internalFormat)
1359 const tcu::TextureFormat format = glu::mapGLInternalFormat(internalFormat);
1360 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
1361 glw::GLenum channelType = GL_NONE;
1363 // depth-stencil special cases
1364 if (format.type == tcu::TextureFormat::UNSIGNED_INT_24_8)
1366 if (m_pname == GL_TEXTURE_DEPTH_TYPE)
1367 return GL_UNSIGNED_NORMALIZED;
1371 else if (format.type == tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV)
1373 if (m_pname == GL_TEXTURE_DEPTH_TYPE)
1380 switch (channelClass)
1382 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: channelType = GL_SIGNED_NORMALIZED; break;
1383 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT: channelType = GL_UNSIGNED_NORMALIZED; break;
1384 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER: channelType = GL_INT; break;
1385 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER: channelType = GL_UNSIGNED_INT; break;
1386 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT: channelType = GL_FLOAT; break;
1388 DE_ASSERT(DE_FALSE);
1394 case GL_TEXTURE_RED_TYPE:
1395 if (format.order == tcu::TextureFormat::R ||
1396 format.order == tcu::TextureFormat::RG ||
1397 format.order == tcu::TextureFormat::RGB ||
1398 format.order == tcu::TextureFormat::RGBA ||
1399 format.order == tcu::TextureFormat::BGRA ||
1400 format.order == tcu::TextureFormat::ARGB ||
1401 format.order == tcu::TextureFormat::sRGB ||
1402 format.order == tcu::TextureFormat::sRGBA)
1407 case GL_TEXTURE_GREEN_TYPE:
1408 if (format.order == tcu::TextureFormat::RG ||
1409 format.order == tcu::TextureFormat::RGB ||
1410 format.order == tcu::TextureFormat::RGBA ||
1411 format.order == tcu::TextureFormat::BGRA ||
1412 format.order == tcu::TextureFormat::ARGB ||
1413 format.order == tcu::TextureFormat::sRGB ||
1414 format.order == tcu::TextureFormat::sRGBA)
1419 case GL_TEXTURE_BLUE_TYPE:
1420 if (format.order == tcu::TextureFormat::RGB ||
1421 format.order == tcu::TextureFormat::RGBA ||
1422 format.order == tcu::TextureFormat::BGRA ||
1423 format.order == tcu::TextureFormat::ARGB ||
1424 format.order == tcu::TextureFormat::sRGB ||
1425 format.order == tcu::TextureFormat::sRGBA)
1430 case GL_TEXTURE_ALPHA_TYPE:
1431 if (format.order == tcu::TextureFormat::RGBA ||
1432 format.order == tcu::TextureFormat::BGRA ||
1433 format.order == tcu::TextureFormat::ARGB ||
1434 format.order == tcu::TextureFormat::sRGBA)
1439 case GL_TEXTURE_DEPTH_TYPE:
1440 if (format.order == tcu::TextureFormat::D ||
1441 format.order == tcu::TextureFormat::DS)
1447 DE_ASSERT(DE_FALSE);
1452 class TextureLevelCompressedCase : public TextureLevelCase
1455 TextureLevelCompressedCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1456 : TextureLevelCase(ctx, name, desc, target, type)
1461 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1463 generateCompressedTextureGenerationGroup(iterations, m_target);
1466 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1470 if (spec.levels.empty())
1472 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_COMPRESSED, 0, m_type);
1476 for (int levelNdx = 0; levelNdx < (int)spec.levels.size(); ++levelNdx)
1478 const int queryLevel = spec.levels[levelNdx].level;
1479 const int refValue = (spec.levels[levelNdx].compressed) ? (1) : (0);
1481 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, queryLevel, GL_TEXTURE_COMPRESSED, refValue, m_type);
1489 class TextureLevelBufferDataStoreCase : public TextureLevelCase
1492 TextureLevelBufferDataStoreCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1493 : TextureLevelCase(ctx, name, desc, target, type)
1500 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_buffer"))
1501 throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1502 TextureLevelCase::init();
1505 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1507 generateTextureBufferGenerationGroup(iterations, m_target);
1510 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1514 if (spec.levels.empty())
1516 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING, 0, m_type);
1520 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING, m_texBuffer, m_type);
1527 class TextureLevelBufferDataOffsetCase : public TextureLevelCase
1530 TextureLevelBufferDataOffsetCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1531 : TextureLevelCase(ctx, name, desc, target, type)
1538 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_buffer"))
1539 throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1540 TextureLevelCase::init();
1543 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1545 generateTextureBufferGenerationGroup(iterations, m_target);
1548 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1552 if (spec.levels.empty())
1554 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_OFFSET, 0, m_type);
1558 const int refValue = spec.texBufferDataOffset;
1560 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_OFFSET, refValue, m_type);
1567 class TextureLevelBufferDataSizeCase : public TextureLevelCase
1570 TextureLevelBufferDataSizeCase (Context& ctx, const char* name, const char* desc, glw::GLenum target, QueryType type)
1571 : TextureLevelCase(ctx, name, desc, target, type)
1578 if (!m_context.getContextInfo().isExtensionSupported("GL_EXT_texture_buffer"))
1579 throw tcu::NotSupportedError("Test requires GL_EXT_texture_buffer extension");
1580 TextureLevelCase::init();
1583 void generateTestIterations (std::vector<TextureGenerationSpec>& iterations)
1585 generateTextureBufferGenerationGroup(iterations, m_target);
1588 bool checkTextureState (glu::CallLogWrapper& gl, const TextureGenerationSpec& spec)
1592 if (spec.levels.empty())
1594 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_SIZE, 0, m_type);
1598 const int refValue = spec.texBufferDataSize;
1600 allOk &= verifyTextureLevelParameterEqual(gl, spec.queryTarget, 0, GL_TEXTURE_BUFFER_SIZE, refValue, m_type);
1609 static const char* getVerifierSuffix (QueryType type)
1613 case QUERY_TEXTURE_LEVEL_FLOAT: return "_float";
1614 case QUERY_TEXTURE_LEVEL_INTEGER: return "_integer";
1616 DE_ASSERT(DE_FALSE);
1621 TextureLevelStateQueryTests::TextureLevelStateQueryTests (Context& context)
1622 : TestCaseGroup(context, "texture_level", "GetTexLevelParameter tests")
1626 TextureLevelStateQueryTests::~TextureLevelStateQueryTests (void)
1630 void TextureLevelStateQueryTests::init (void)
1632 static const QueryType verifiers[] =
1634 QUERY_TEXTURE_LEVEL_INTEGER,
1635 QUERY_TEXTURE_LEVEL_FLOAT,
1638 #define FOR_EACH_VERIFIER(X) \
1639 for (int verifierNdx = 0; verifierNdx < DE_LENGTH_OF_ARRAY(verifiers); ++verifierNdx) \
1641 const std::string verifierSuffix = getVerifierSuffix(verifiers[verifierNdx]); \
1642 const QueryType verifier = verifiers[verifierNdx]; \
1643 targetGroup->addChild(X); \
1649 } textureTargets[] =
1651 { "texture_2d", GL_TEXTURE_2D, },
1652 { "texture_3d", GL_TEXTURE_3D, },
1653 { "texture_2d_array", GL_TEXTURE_2D_ARRAY, },
1654 { "texture_cube_map", GL_TEXTURE_CUBE_MAP, },
1655 { "texture_2d_multisample", GL_TEXTURE_2D_MULTISAMPLE, },
1656 { "texture_2d_multisample_array", GL_TEXTURE_2D_MULTISAMPLE_ARRAY, }, // GL_OES_texture_storage_multisample_2d_array
1657 { "texture_buffer", GL_TEXTURE_BUFFER, }, // GL_EXT_texture_buffer
1658 { "texture_cube_array", GL_TEXTURE_CUBE_MAP_ARRAY, }, // GL_EXT_texture_cube_map_array
1661 for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(textureTargets); ++targetNdx)
1663 tcu::TestCaseGroup* const targetGroup = new tcu::TestCaseGroup(m_testCtx, textureTargets[targetNdx].name, textureTargets[targetNdx].name);
1664 addChild(targetGroup);
1666 FOR_EACH_VERIFIER(new TextureLevelSampleCase (m_context, ("samples" + verifierSuffix).c_str(), "Verify TEXTURE_SAMPLES", textureTargets[targetNdx].target, verifier));
1667 FOR_EACH_VERIFIER(new TextureLevelFixedSamplesCase (m_context, ("fixed_sample_locations" + verifierSuffix).c_str(), "Verify TEXTURE_FIXED_SAMPLE_LOCATIONS", textureTargets[targetNdx].target, verifier));
1668 FOR_EACH_VERIFIER(new TextureLevelWidthCase (m_context, ("width" + verifierSuffix).c_str(), "Verify TEXTURE_WIDTH", textureTargets[targetNdx].target, verifier));
1669 FOR_EACH_VERIFIER(new TextureLevelHeightCase (m_context, ("height" + verifierSuffix).c_str(), "Verify TEXTURE_HEIGHT", textureTargets[targetNdx].target, verifier));
1670 FOR_EACH_VERIFIER(new TextureLevelDepthCase (m_context, ("depth" + verifierSuffix).c_str(), "Verify TEXTURE_DEPTH", textureTargets[targetNdx].target, verifier));
1671 FOR_EACH_VERIFIER(new TextureLevelInternalFormatCase (m_context, ("internal_format" + verifierSuffix).c_str(), "Verify TEXTURE_INTERNAL_FORMAT", textureTargets[targetNdx].target, verifier));
1672 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("red_size" + verifierSuffix).c_str(), "Verify TEXTURE_RED_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_RED_SIZE));
1673 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("green_size" + verifierSuffix).c_str(), "Verify TEXTURE_GREEN_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_GREEN_SIZE));
1674 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("blue_size" + verifierSuffix).c_str(), "Verify TEXTURE_BLUE_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_BLUE_SIZE));
1675 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("alpha_size" + verifierSuffix).c_str(), "Verify TEXTURE_ALPHA_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_ALPHA_SIZE));
1676 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("depth_size" + verifierSuffix).c_str(), "Verify TEXTURE_DEPTH_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_DEPTH_SIZE));
1677 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("stencil_size" + verifierSuffix).c_str(), "Verify TEXTURE_STENCIL_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_STENCIL_SIZE));
1678 FOR_EACH_VERIFIER(new TextureLevelSizeCase (m_context, ("shared_size" + verifierSuffix).c_str(), "Verify TEXTURE_SHARED_SIZE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_SHARED_SIZE));
1679 FOR_EACH_VERIFIER(new TextureLevelTypeCase (m_context, ("red_type" + verifierSuffix).c_str(), "Verify TEXTURE_RED_TYPE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_RED_TYPE));
1680 FOR_EACH_VERIFIER(new TextureLevelTypeCase (m_context, ("green_type" + verifierSuffix).c_str(), "Verify TEXTURE_GREEN_TYPE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_GREEN_TYPE));
1681 FOR_EACH_VERIFIER(new TextureLevelTypeCase (m_context, ("blue_type" + verifierSuffix).c_str(), "Verify TEXTURE_BLUE_TYPE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_BLUE_TYPE));
1682 FOR_EACH_VERIFIER(new TextureLevelTypeCase (m_context, ("alpha_type" + verifierSuffix).c_str(), "Verify TEXTURE_ALPHA_TYPE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_ALPHA_TYPE));
1683 FOR_EACH_VERIFIER(new TextureLevelTypeCase (m_context, ("depth_type" + verifierSuffix).c_str(), "Verify TEXTURE_DEPTH_TYPE", textureTargets[targetNdx].target, verifier, GL_TEXTURE_DEPTH_TYPE));
1684 FOR_EACH_VERIFIER(new TextureLevelCompressedCase (m_context, ("compressed" + verifierSuffix).c_str(), "Verify TEXTURE_COMPRESSED", textureTargets[targetNdx].target, verifier));
1685 FOR_EACH_VERIFIER(new TextureLevelBufferDataStoreCase (m_context, ("buffer_data_store_binding" + verifierSuffix).c_str(), "Verify TEXTURE_BUFFER_DATA_STORE_BINDING", textureTargets[targetNdx].target, verifier));
1686 FOR_EACH_VERIFIER(new TextureLevelBufferDataOffsetCase (m_context, ("buffer_offset" + verifierSuffix).c_str(), "Verify TEXTURE_BUFFER_OFFSET", textureTargets[targetNdx].target, verifier));
1687 FOR_EACH_VERIFIER(new TextureLevelBufferDataSizeCase (m_context, ("buffer_size" + verifierSuffix).c_str(), "Verify TEXTURE_BUFFER_SIZE", textureTargets[targetNdx].target, verifier));
1690 #undef FOR_EACH_VERIFIER