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 "unwrap_gles.h" 18 19 #include <EGL/egl.h> 20 #include <EGL/eglext.h> 21 #include <GLES/gl.h> 22 #include <GLES/glext.h> 23 #include <GLES2/gl2.h> 24 #include <GLES2/gl2ext.h> 25 #include <GLES3/gl3.h> 26 #include <GLES3/gl31.h> 27 #include <GLES3/gl32.h> 28 29 #include <cutils/log.h> 30 31 void assertNoGlErrors(const char* apicall) { 32 GLenum status = GL_NO_ERROR; 33 GLenum lastError = GL_NO_ERROR; 34 const char* lastErrorName = nullptr; 35 while ((status = glGetError()) != GL_NO_ERROR) { 36 lastError = status; 37 switch (status) { 38 case GL_INVALID_ENUM: 39 ALOGE("GL error: GL_INVALID_ENUM"); 40 lastErrorName = "GL_INVALID_ENUM"; 41 break; 42 case GL_INVALID_VALUE: 43 ALOGE("GL error: GL_INVALID_VALUE"); 44 lastErrorName = "GL_INVALID_VALUE"; 45 break; 46 case GL_INVALID_OPERATION: 47 ALOGE("GL error: GL_INVALID_OPERATION"); 48 lastErrorName = "GL_INVALID_OPERATION"; 49 break; 50 case GL_OUT_OF_MEMORY: 51 ALOGE("GL error: Out of memory!"); 52 lastErrorName = "GL_OUT_OF_MEMORY"; 53 break; 54 default: 55 ALOGE("GL error: 0x%x", status); 56 lastErrorName = "UNKNOWN"; 57 } 58 } 59 LOG_ALWAYS_FATAL_IF(lastError != GL_NO_ERROR, 60 "%s error! %s (0x%x)", apicall, lastErrorName, lastError); 61 } 62 63 #define API_ENTRY(x) wrap_##x 64 #define CALL_GL_API(x, ...) x(__VA_ARGS__); assertNoGlErrors(#x) 65 #define CALL_GL_API_RETURN(x, ...) auto ret = x(__VA_ARGS__);\ 66 assertNoGlErrors(#x);\ 67 return ret 68 69 extern "C" { 70 #include <gl2_api.in> 71 #include <gl2ext_api.in> 72 73 // libGLESv2 handles these specially, so they are not in gl2_api.in 74 75 void API_ENTRY(glGetBooleanv)(GLenum pname, GLboolean *data) { 76 CALL_GL_API(glGetBooleanv, pname, data); 77 } 78 void API_ENTRY(glGetFloatv)(GLenum pname, GLfloat *data) { 79 CALL_GL_API(glGetFloatv, pname, data); 80 } 81 void API_ENTRY(glGetIntegerv)(GLenum pname, GLint *data) { 82 CALL_GL_API(glGetIntegerv, pname, data); 83 } 84 const GLubyte * API_ENTRY(glGetString)(GLenum name) { 85 CALL_GL_API_RETURN(glGetString, name); 86 } 87 const GLubyte * API_ENTRY(glGetStringi)(GLenum name, GLuint index) { 88 CALL_GL_API_RETURN(glGetStringi, name, index); 89 } 90 void API_ENTRY(glGetInteger64v)(GLenum pname, GLint64 *data) { 91 CALL_GL_API(glGetInteger64v, pname, data); 92 } 93 } 94