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 // gl_enum_utils.cpp:
7 // Utility functions for converting GLenums to string.
8
9 #include "libANGLE/gl_enum_utils.h"
10
11 #include <iomanip>
12
13 namespace gl
14 {
15 const char kUnknownGLenumString[] = "EnumUnknown";
16
OutputGLenumString(std::ostream & out,GLenumGroup enumGroup,unsigned int value)17 void OutputGLenumString(std::ostream &out, GLenumGroup enumGroup, unsigned int value)
18 {
19 const char *enumStr = GLenumToString(enumGroup, value);
20 if (enumStr != kUnknownGLenumString)
21 {
22 out << enumStr;
23 return;
24 }
25
26 if (enumGroup != GLenumGroup::DefaultGroup)
27 {
28 // Retry with the "Default" group
29 enumStr = GLenumToString(GLenumGroup::DefaultGroup, value);
30 if (enumStr != kUnknownGLenumString)
31 {
32 out << enumStr;
33 return;
34 }
35 }
36
37 out << std::hex << "0x" << std::setfill('0') << std::setw(4) << value << std::dec;
38 }
39
OutputGLbitfieldString(std::ostream & out,GLenumGroup enumGroup,unsigned int value)40 void OutputGLbitfieldString(std::ostream &out, GLenumGroup enumGroup, unsigned int value)
41 {
42 out << GLbitfieldToString(enumGroup, value);
43 }
44
GLbooleanToString(unsigned int value)45 const char *GLbooleanToString(unsigned int value)
46 {
47 switch (value)
48 {
49 case 0x0:
50 return "GL_FALSE";
51 case 0x1:
52 return "GL_TRUE";
53 default:
54 return kUnknownGLenumString;
55 }
56 }
57 } // namespace gl
58