blob: 3e8eaedae6976f4906f50c8ada2b4a1261881c58 [file] [log] [blame]
Jason Macnaka82db252021-09-22 15:31:46 -07001/*
Kaiyi Li0c4aa722021-11-04 10:13:23 -07002 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jason Macnaka82db252021-09-22 15:31:46 -070016
Jason Macnak76fe9c12023-01-18 10:08:36 -080017#include "DebugGl.h"
Jason Macnaka82db252021-09-22 15:31:46 -070018
Kaiyi Li0c4aa722021-11-04 10:13:23 -070019#include <cstdarg>
20
Jason Macnaka82db252021-09-22 15:31:46 -070021#include "OpenGLESDispatch/DispatchTables.h"
22
Jason Macnaked0c9e62023-03-30 15:58:24 -070023namespace gfxstream {
24namespace gl {
25
Jason Macnaka82db252021-09-22 15:31:46 -070026std::string formatString(const char* format, ...) {
27 char buf[1024];
28 va_list args;
29 va_start(args, format);
30 vsnprintf(buf, 1024, format, args);
31 std::string ret(buf);
32 va_end(args);
33 return ret;
34}
35
36ScopedDebugGroup::ScopedDebugGroup(const std::string& message) {
37 s_gles2.glGetError();
38
39 bool groupPushed = false;
40 if (s_gles2.glPushDebugGroupKHR) {
Kaiyi Li0c4aa722021-11-04 10:13:23 -070041 s_gles2.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 0, message.size(),
42 message.c_str());
Jason Macnaka82db252021-09-22 15:31:46 -070043 groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
44 }
45 if (s_gles2.glPushDebugGroup && !groupPushed) {
46 s_gles2.glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, message.size(), message.c_str());
47 groupPushed = s_gles2.glGetError() == GL_NO_ERROR;
48 }
49}
50
51ScopedDebugGroup::~ScopedDebugGroup() {
52 s_gles2.glGetError();
53
54 bool groupPopped = false;
55 if (s_gles2.glPopDebugGroupKHR) {
56 s_gles2.glPopDebugGroupKHR();
57 groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
58 }
59 if (s_gles2.glPopDebugGroup && !groupPopped) {
60 s_gles2.glPopDebugGroup();
61 groupPopped = s_gles2.glGetError() == GL_NO_ERROR;
62 }
Jason Macnaked0c9e62023-03-30 15:58:24 -070063}
64
65} // namespace gl
66} // namespace gfxstream