xref: /aosp_15_r20/external/deqp/framework/opengl/gluStrUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _GLUSTRUTIL_HPP
2 #define _GLUSTRUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES Utilities
5  * ------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief OpenGL value to string utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "gluDefs.hpp"
27 #include "gluRenderContext.hpp"
28 #include "tcuFormatUtil.hpp"
29 
30 namespace glu
31 {
32 
33 // Internal format utilities.
34 namespace detail
35 {
36 
37 class EnumPointerFmt
38 {
39 public:
40     typedef const char *(*GetEnumNameFunc)(int value);
41 
42     const uint32_t *const value;
43     const uint32_t size;
44     const GetEnumNameFunc getName;
45 
EnumPointerFmt(const uint32_t * value_,uint32_t size_,GetEnumNameFunc getName_)46     EnumPointerFmt(const uint32_t *value_, uint32_t size_, GetEnumNameFunc getName_)
47         : value(value_)
48         , size(size_)
49         , getName(getName_)
50     {
51     }
52 };
53 
54 class BooleanPointerFmt
55 {
56 public:
57     const uint8_t *const value;
58     const uint32_t size;
59 
BooleanPointerFmt(const uint8_t * value_,uint32_t size_)60     BooleanPointerFmt(const uint8_t *value_, uint32_t size_) : value(value_), size(size_)
61     {
62     }
63 };
64 
65 class TextureUnitStr
66 {
67 public:
68     const uint32_t texUnit;
TextureUnitStr(uint32_t texUnit_)69     TextureUnitStr(uint32_t texUnit_) : texUnit(texUnit_)
70     {
71     }
72 };
73 
74 class TextureParameterValueStr
75 {
76 public:
77     const uint32_t param;
78     const int value;
TextureParameterValueStr(uint32_t param_,int value_)79     TextureParameterValueStr(uint32_t param_, int value_) : param(param_), value(value_)
80     {
81     }
82 };
83 
84 std::ostream &operator<<(std::ostream &str, const TextureUnitStr &unitStr);
85 std::ostream &operator<<(std::ostream &str, const TextureParameterValueStr &valueStr);
86 std::ostream &operator<<(std::ostream &str, const BooleanPointerFmt &fmt);
87 std::ostream &operator<<(std::ostream &str, const EnumPointerFmt &fmt);
88 
89 } // namespace detail
90 
getEnumPointerStr(const uint32_t * value,int32_t size,detail::EnumPointerFmt::GetEnumNameFunc getName)91 inline detail::EnumPointerFmt getEnumPointerStr(const uint32_t *value, int32_t size,
92                                                 detail::EnumPointerFmt::GetEnumNameFunc getName)
93 {
94     return detail::EnumPointerFmt(value, (uint32_t)de::max(0, size), getName);
95 }
96 
getBooleanPointerStr(const uint8_t * value,int32_t size)97 inline detail::BooleanPointerFmt getBooleanPointerStr(const uint8_t *value, int32_t size)
98 {
99     return detail::BooleanPointerFmt(value, (uint32_t)de::max(0, size));
100 }
101 
getTextureUnitStr(uint32_t unit)102 inline detail::TextureUnitStr getTextureUnitStr(uint32_t unit)
103 {
104     return detail::TextureUnitStr(unit);
105 }
getTextureParameterValueStr(uint32_t param,int value)106 inline detail::TextureParameterValueStr getTextureParameterValueStr(uint32_t param, int value)
107 {
108     return detail::TextureParameterValueStr(param, value);
109 }
110 detail::EnumPointerFmt getInvalidateAttachmentStr(const uint32_t *attachments, int numAttachments);
111 
112 std::ostream &operator<<(std::ostream &str, ApiType apiType);
113 std::ostream &operator<<(std::ostream &str, ContextType contextType);
114 
115 // prevent implicit conversions from bool to int.
116 //
117 // While it is well-defined that (int)true == GL_TRUE and (int)false == GL_FALSE,
118 // using these functions to convert non-GL-types suggests a that the calling code is
119 // mixing and matching GLboolean and bool types which may not be safe.
120 //
121 // \note return value is void to prevent compilation. Otherwise this would only break linking.
122 void getBooleanPointerStr(const bool *value, int32_t size); // delete
123 void getBooleanStr(bool);                                   // delete
124 void getBooleanName(bool);                                  // delete
125 
126 #include "gluStrUtilPrototypes.inl"
127 
128 } // namespace glu
129 
130 #endif // _GLUSTRUTIL_HPP
131