Jason Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 1 | /* |
Kaiyi Li | 0c4aa72 | 2021-11-04 10:13:23 -0700 | [diff] [blame] | 2 | * 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 Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 16 | |
Jason Macnak | 76fe9c1 | 2023-01-18 10:08:36 -0800 | [diff] [blame] | 17 | #include "DebugGl.h" |
Jason Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 18 | |
Kaiyi Li | 0c4aa72 | 2021-11-04 10:13:23 -0700 | [diff] [blame] | 19 | #include <cstdarg> |
| 20 | |
Jason Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 21 | #include "OpenGLESDispatch/DispatchTables.h" |
| 22 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 23 | namespace gfxstream { |
| 24 | namespace gl { |
| 25 | |
Jason Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 26 | std::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 | |
| 36 | ScopedDebugGroup::ScopedDebugGroup(const std::string& message) { |
| 37 | s_gles2.glGetError(); |
| 38 | |
| 39 | bool groupPushed = false; |
| 40 | if (s_gles2.glPushDebugGroupKHR) { |
Kaiyi Li | 0c4aa72 | 2021-11-04 10:13:23 -0700 | [diff] [blame] | 41 | s_gles2.glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION_KHR, 0, message.size(), |
| 42 | message.c_str()); |
Jason Macnak | a82db25 | 2021-09-22 15:31:46 -0700 | [diff] [blame] | 43 | 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 | |
| 51 | ScopedDebugGroup::~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 Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace gl |
| 66 | } // namespace gfxstream |