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 "libANGLE/Context.h"
18 #include "libANGLE/capture/gl_enum_utils.h"
19 #include "libANGLE/formatutils.h"
20 #include "util/EGLWindow.h"
21 
22 using namespace angle;
23 
24 namespace
25 {
26 
27 class FormatPrintTest : public ANGLETest
28 {};
29 
30 // This test enumerates all sized and unsized GL formats and prints out support information
31 // This test omits unsupported formats
32 // The output is csv parseable and has a header and a new line.
33 // Each row consists of:
34 // (InternalFormat,Type,texturable,filterable,textureAttachmentSupported,renderBufferSupported)
TEST_P(FormatPrintTest,PrintAllSupportedFormats)35 TEST_P(FormatPrintTest, PrintAllSupportedFormats)
36 {
37     // Hack the angle!
38     gl::Context *context = static_cast<gl::Context *>(getEGLWindow()->getContext());
39     const gl::InternalFormatInfoMap &allSupportedFormats = gl::GetInternalFormatMap();
40 
41     std::cout << std::endl
42               << "InternalFormat,Type,Texturable,Filterable,Texture attachment,Renderbuffer"
43               << std::endl
44               << std::endl;
45 
46     for (const auto &internalFormat : allSupportedFormats)
47     {
48         for (const auto &typeFormatPair : internalFormat.second)
49         {
50             bool textureSupport = typeFormatPair.second.textureSupport(context->getClientVersion(),
51                                                                        context->getExtensions());
52             bool filterSupport  = typeFormatPair.second.filterSupport(context->getClientVersion(),
53                                                                      context->getExtensions());
54             bool textureAttachmentSupport = typeFormatPair.second.textureAttachmentSupport(
55                 context->getClientVersion(), context->getExtensions());
56             bool renderbufferSupport = typeFormatPair.second.renderbufferSupport(
57                 context->getClientVersion(), context->getExtensions());
58 
59             // Skip if not supported
60             // A format is not supported if the only feature bit enabled is "filterSupport"
61             if (!(textureSupport || textureAttachmentSupport || renderbufferSupport))
62             {
63                 continue;
64             }
65 
66             // Lookup enum strings from enum
67             std::stringstream resultStringStream;
68             gl::OutputGLenumString(resultStringStream, gl::GLenumGroup::InternalFormat,
69                                    internalFormat.first);
70             resultStringStream << ",";
71             gl::OutputGLenumString(resultStringStream, gl::GLenumGroup::PixelType,
72                                    typeFormatPair.first);
73             resultStringStream << ",";
74 
75             // able to be sampled from, see GLSL sampler variables
76             if (textureSupport)
77             {
78                 resultStringStream << "texturable";
79             }
80             resultStringStream << ",";
81 
82             // able to be linearly filtered (GL_LINEAR)
83             if (filterSupport)
84             {
85                 resultStringStream << "filterable";
86             }
87             resultStringStream << ",";
88 
89             // a texture with this can be used for glFramebufferTexture2D
90             if (textureAttachmentSupport)
91             {
92                 resultStringStream << "textureAttachmentSupported";
93             }
94             resultStringStream << ",";
95 
96             // usable with glFramebufferRenderbuffer, glRenderbufferStorage,
97             // glNamedRenderbufferStorage
98             if (renderbufferSupport)
99             {
100                 resultStringStream << "renderbufferSupported";
101             }
102 
103             std::cout << resultStringStream.str() << std::endl;
104         }
105     }
106 }
107 
108 ANGLE_INSTANTIATE_TEST(FormatPrintTest, ES2_VULKAN(), ES3_VULKAN());
109 
110 }  // anonymous namespace
111 
112 // Included here to fix a compile error due to white box tests using angle_end2end_tests_main.
RegisterContextCompatibilityTests()113 void RegisterContextCompatibilityTests() {}
114