xref: /aosp_15_r20/external/deqp/framework/opengl/gluCallLogWrapper.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief GL call wrapper for logging.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "gluCallLogWrapper.hpp"
25 #include "gluStrUtil.hpp"
26 #include "glwFunctions.hpp"
27 #include "glwEnums.hpp"
28 
29 using tcu::TestLog;
30 using tcu::toHex;
31 
32 namespace glu
33 {
34 
CallLogWrapper(const glw::Functions & gl,tcu::TestLog & log)35 CallLogWrapper::CallLogWrapper(const glw::Functions &gl, tcu::TestLog &log) : m_gl(gl), m_log(log), m_enableLog(false)
36 {
37 }
38 
~CallLogWrapper(void)39 CallLogWrapper::~CallLogWrapper(void)
40 {
41 }
42 
43 template <typename T>
getPointerStr(const T * arr,uint32_t size)44 inline tcu::Format::ArrayPointer<T> getPointerStr(const T *arr, uint32_t size)
45 {
46     return tcu::formatArray(arr, (int)size);
47 }
48 
49 template <typename T>
getPointerStr(const T * arr,int size)50 inline tcu::Format::ArrayPointer<T> getPointerStr(const T *arr, int size)
51 {
52     return tcu::formatArray(arr, de::max(size, 0));
53 }
54 
55 // String formatter.
56 
57 class StringFmt
58 {
59 public:
60     const glw::GLchar *str;
StringFmt(const glw::GLchar * str_)61     StringFmt(const glw::GLchar *str_) : str(str_)
62     {
63     }
64 };
65 
operator <<(std::ostream & str,StringFmt fmt)66 inline std::ostream &operator<<(std::ostream &str, StringFmt fmt)
67 {
68     return str << (fmt.str ? (const char *)fmt.str : "NULL");
69 }
70 
getStringStr(const char * value)71 inline StringFmt getStringStr(const char *value)
72 {
73     return StringFmt(value);
74 }
getStringStr(const glw::GLubyte * value)75 inline StringFmt getStringStr(const glw::GLubyte *value)
76 {
77     return StringFmt((const char *)value);
78 }
79 
80 // Framebuffer parameter pointer formatter.
81 
82 class FboParamPtrFmt
83 {
84 public:
85     uint32_t param;
86     const int *value;
87 
FboParamPtrFmt(uint32_t param_,const int * value_)88     FboParamPtrFmt(uint32_t param_, const int *value_) : param(param_), value(value_)
89     {
90     }
91 };
92 
operator <<(std::ostream & str,FboParamPtrFmt fmt)93 std::ostream &operator<<(std::ostream &str, FboParamPtrFmt fmt)
94 {
95     if (fmt.value)
96     {
97         switch (fmt.param)
98         {
99         case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
100             return str << tcu::Format::Enum<int, 2>(getFramebufferAttachmentTypeName, *fmt.value);
101 
102         case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
103             return str << tcu::Format::Enum<int, 2>(getCubeMapFaceName, *fmt.value);
104 
105         case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
106             return str << tcu::Format::Enum<int, 2>(getTypeName, *fmt.value);
107 
108         case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
109             return str << tcu::Format::Enum<int, 2>(getFramebufferColorEncodingName, *fmt.value);
110 
111         case GL_FRAMEBUFFER_ATTACHMENT_LAYERED:
112             return str << tcu::Format::Enum<int, 2>(getBooleanName, *fmt.value);
113 
114         case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
115         case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
116         case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
117         case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
118         case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
119         case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
120         case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
121         case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
122         case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
123             return str << *fmt.value;
124 
125         default:
126             return str << tcu::toHex(*fmt.value);
127         }
128     }
129     else
130         return str << "(null)";
131 }
132 
getFramebufferAttachmentParameterValueStr(uint32_t param,const int * value)133 inline FboParamPtrFmt getFramebufferAttachmentParameterValueStr(uint32_t param, const int *value)
134 {
135     return FboParamPtrFmt(param, value);
136 }
137 
138 #include "gluQueryUtil.inl"
139 #include "gluCallLogUtil.inl"
140 
141 // API entry-point implementations are auto-generated
142 #include "gluCallLogWrapper.inl"
143 
144 } // namespace glu
145