sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | */ |
| 16 | |
| 17 | #include "GlesErrorCheckWrapper.h" |
| 18 | |
Mark Salyzyn | 6f773a0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | namespace uirenderer { |
| 23 | namespace debug { |
| 24 | |
| 25 | void GlesErrorCheckWrapper::assertNoErrors(const char* apicall) { |
| 26 | GLenum status = GL_NO_ERROR; |
| 27 | GLenum lastError = GL_NO_ERROR; |
| 28 | const char* lastErrorName = nullptr; |
| 29 | while ((status = mBase.glGetError_()) != GL_NO_ERROR) { |
| 30 | lastError = status; |
| 31 | switch (status) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 32 | case GL_INVALID_ENUM: |
| 33 | ALOGE("GL error: GL_INVALID_ENUM"); |
| 34 | lastErrorName = "GL_INVALID_ENUM"; |
| 35 | break; |
| 36 | case GL_INVALID_VALUE: |
| 37 | ALOGE("GL error: GL_INVALID_VALUE"); |
| 38 | lastErrorName = "GL_INVALID_VALUE"; |
| 39 | break; |
| 40 | case GL_INVALID_OPERATION: |
| 41 | ALOGE("GL error: GL_INVALID_OPERATION"); |
| 42 | lastErrorName = "GL_INVALID_OPERATION"; |
| 43 | break; |
| 44 | case GL_OUT_OF_MEMORY: |
| 45 | ALOGE("GL error: Out of memory!"); |
| 46 | lastErrorName = "GL_OUT_OF_MEMORY"; |
| 47 | break; |
| 48 | default: |
| 49 | ALOGE("GL error: 0x%x", status); |
| 50 | lastErrorName = "UNKNOWN"; |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 51 | } |
| 52 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | LOG_ALWAYS_FATAL_IF(lastError != GL_NO_ERROR, "%s error! %s (0x%x)", apicall, lastErrorName, |
| 54 | lastError); |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | #define API_ENTRY(x) GlesErrorCheckWrapper::x##_ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 58 | #define CALL_GL_API(x, ...) \ |
| 59 | mBase.x##_(__VA_ARGS__); \ |
| 60 | assertNoErrors(#x) |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 61 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 62 | #define CALL_GL_API_RETURN(x, ...) \ |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 63 | auto ret = mBase.x##_(__VA_ARGS__); \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 64 | assertNoErrors(#x); \ |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 65 | return ret |
| 66 | |
| 67 | #include "gles_stubs.in" |
| 68 | |
| 69 | #undef API_ENTRY |
| 70 | #undef CALL_GL_API |
| 71 | #undef CALL_GL_API_RETURN |
| 72 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 73 | } // namespace debug |
| 74 | } // namespace uirenderer |
| 75 | } // namespace android |