blob: 8d11c1905da3d8141939e504f950d7feb28ad166 [file] [log] [blame]
sergeyv8bd5edf2016-05-13 15:03:35 -07001/*
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 Salyzyn6f773a02016-09-28 16:15:30 -070019#include <log/log.h>
sergeyv8bd5edf2016-05-13 15:03:35 -070020
21namespace android {
22namespace uirenderer {
23namespace debug {
24
25void 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 Reck1bcacfd2017-11-03 10:12:19 -070032 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";
sergeyv8bd5edf2016-05-13 15:03:35 -070051 }
52 }
John Reck1bcacfd2017-11-03 10:12:19 -070053 LOG_ALWAYS_FATAL_IF(lastError != GL_NO_ERROR, "%s error! %s (0x%x)", apicall, lastErrorName,
54 lastError);
sergeyv8bd5edf2016-05-13 15:03:35 -070055}
56
57#define API_ENTRY(x) GlesErrorCheckWrapper::x##_
John Reck1bcacfd2017-11-03 10:12:19 -070058#define CALL_GL_API(x, ...) \
59 mBase.x##_(__VA_ARGS__); \
60 assertNoErrors(#x)
sergeyv8bd5edf2016-05-13 15:03:35 -070061
John Reck1bcacfd2017-11-03 10:12:19 -070062#define CALL_GL_API_RETURN(x, ...) \
sergeyv8bd5edf2016-05-13 15:03:35 -070063 auto ret = mBase.x##_(__VA_ARGS__); \
John Reck1bcacfd2017-11-03 10:12:19 -070064 assertNoErrors(#x); \
sergeyv8bd5edf2016-05-13 15:03:35 -070065 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 Reck1bcacfd2017-11-03 10:12:19 -070073} // namespace debug
74} // namespace uirenderer
75} // namespace android