1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // FormatPrintTest:
7 // Prints all format support info
8 //
9
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/angle_test_instantiate.h"
12 // 'None' is defined as 'struct None {};' in
13 // third_party/googletest/src/googletest/include/gtest/internal/gtest-type-util.h.
14 // But 'None' is also defined as a numeric constant 0L in <X11/X.h>.
15 // So we need to include ANGLETest.h first to avoid this conflict.
16
17 #include "common/gl_enum_utils.h"
18 #include "libANGLE/Context.h"
19 #include "libANGLE/Display.h"
20 #include "libANGLE/formatutils.h"
21 #include "util/EGLWindow.h"
22
23 using namespace angle;
24
25 namespace
26 {
27
28 class FormatPrintTest : public ANGLETest<>
29 {};
30
31 // This test enumerates all sized and unsized GL formats and prints out support information
32 // This test omits unsupported formats
33 // The output is csv parseable and has a header and a new line.
34 // Each row consists of:
35 // (InternalFormat,Type,texturable,filterable,textureAttachmentSupported,renderBufferSupported)
TEST_P(FormatPrintTest,PrintAllSupportedFormats)36 TEST_P(FormatPrintTest, PrintAllSupportedFormats)
37 {
38 // Hack the angle!
39 egl::Display *display = static_cast<egl::Display *>(getEGLWindow()->getDisplay());
40 gl::ContextID contextID = {
41 static_cast<GLuint>(reinterpret_cast<uintptr_t>(getEGLWindow()->getContext()))};
42 gl::Context *context = display->getContext(contextID);
43 const gl::InternalFormatInfoMap &allSupportedFormats = gl::GetInternalFormatMap();
44
45 std::cout << std::endl
46 << "InternalFormat,Type,Texturable,Filterable,Texture attachment,Renderbuffer"
47 << std::endl
48 << std::endl;
49
50 for (const auto &internalFormat : allSupportedFormats)
51 {
52 for (const auto &typeFormatPair : internalFormat.second)
53 {
54 bool textureSupport = typeFormatPair.second.textureSupport(context->getClientVersion(),
55 context->getExtensions());
56 bool filterSupport = typeFormatPair.second.filterSupport(context->getClientVersion(),
57 context->getExtensions());
58 bool textureAttachmentSupport = typeFormatPair.second.textureAttachmentSupport(
59 context->getClientVersion(), context->getExtensions());
60 bool renderbufferSupport = typeFormatPair.second.renderbufferSupport(
61 context->getClientVersion(), context->getExtensions());
62
63 // Skip if not supported
64 // A format is not supported if the only feature bit enabled is "filterSupport"
65 if (!(textureSupport || textureAttachmentSupport || renderbufferSupport))
66 {
67 continue;
68 }
69
70 // Lookup enum strings from enum
71 std::stringstream resultStringStream;
72 gl::OutputGLenumString(resultStringStream, gl::GLESEnum::InternalFormat,
73 internalFormat.first);
74 resultStringStream << ",";
75 gl::OutputGLenumString(resultStringStream, gl::GLESEnum::PixelType,
76 typeFormatPair.first);
77 resultStringStream << ",";
78
79 // able to be sampled from, see GLSL sampler variables
80 if (textureSupport)
81 {
82 resultStringStream << "texturable";
83 }
84 resultStringStream << ",";
85
86 // able to be linearly filtered (GL_LINEAR)
87 if (filterSupport)
88 {
89 resultStringStream << "filterable";
90 }
91 resultStringStream << ",";
92
93 // a texture with this can be used for glFramebufferTexture2D
94 if (textureAttachmentSupport)
95 {
96 resultStringStream << "textureAttachmentSupported";
97 }
98 resultStringStream << ",";
99
100 // usable with glFramebufferRenderbuffer, glRenderbufferStorage,
101 // glNamedRenderbufferStorage
102 if (renderbufferSupport)
103 {
104 resultStringStream << "renderbufferSupported";
105 }
106
107 std::cout << resultStringStream.str() << std::endl;
108 }
109 }
110 }
111
112 ANGLE_INSTANTIATE_TEST(FormatPrintTest, ES2_VULKAN(), ES3_VULKAN());
113 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FormatPrintTest);
114
115 } // anonymous namespace
116