Blender  V2.93
glew-mx.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2014 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "glew-mx.h"
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 
29 #define CASE_CODE_RETURN_STR(code) \
30  case code: \
31  return #code;
32 
33 static const char *get_glew_error_enum_string(GLenum error)
34 {
35  switch (error) {
36  CASE_CODE_RETURN_STR(GLEW_OK) /* also GLEW_NO_ERROR */
37  CASE_CODE_RETURN_STR(GLEW_ERROR_NO_GL_VERSION)
38  CASE_CODE_RETURN_STR(GLEW_ERROR_GL_VERSION_10_ONLY)
39  CASE_CODE_RETURN_STR(GLEW_ERROR_GLX_VERSION_11_ONLY)
40 #ifdef WITH_GLEW_ES
41  CASE_CODE_RETURN_STR(GLEW_ERROR_NOT_GLES_VERSION)
42  CASE_CODE_RETURN_STR(GLEW_ERROR_GLES_VERSION)
43  CASE_CODE_RETURN_STR(GLEW_ERROR_NO_EGL_VERSION)
44  CASE_CODE_RETURN_STR(GLEW_ERROR_EGL_VERSION_10_ONLY)
45 #endif
46  default:
47  return NULL;
48  }
49 }
50 
51 GLenum glew_chk(GLenum error, const char *file, int line, const char *text)
52 {
53  if (error != GLEW_OK) {
54  const char *code = get_glew_error_enum_string(error);
55  const char *msg = (const char *)glewGetErrorString(error);
56 
57  if (error == GLEW_ERROR_NO_GL_VERSION)
58  return GLEW_OK;
59 
60 #ifndef NDEBUG
61  fprintf(stderr,
62  "%s(%d):[%s] -> GLEW Error (0x%04X): %s: %s\n",
63  file,
64  line,
65  text,
66  error,
67  code ? code : "<no symbol>",
68  msg ? msg : "<no message>");
69 #else
70  (void)file;
71  (void)line;
72  (void)text;
73  fprintf(stderr,
74  "GLEW Error (0x%04X): %s: %s\n",
75  error,
76  code ? code : "<no symbol>",
77  msg ? msg : "<no message>");
78 #endif
79  }
80 
81  return error;
82 }
FILE * file
GLenum glew_chk(GLenum error, const char *file, int line, const char *text)
Definition: glew-mx.c:51
static const char * get_glew_error_enum_string(GLenum error)
Definition: glew-mx.c:33
#define CASE_CODE_RETURN_STR(code)
Definition: glew-mx.c:29
static void error(const char *str)
Definition: meshlaplacian.c:65