JeVoisBase  1.0
JeVois Smart Embedded Machine Vision Toolkit Base Modules
OpenGL.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <sstream>
21 #include <jevois/Debug/Log.H>
22 
23 // OpenGL-ES seems to be available both for platform and regular host PCs
24 #include <EGL/egl.h>
25 #include <EGL/eglext.h>
26 #include <GLES2/gl2.h>
27 #include <GLES2/gl2ext.h>
28 
29 namespace jevoisbase
30 {
31  //! Function to write OpenGL errors in clear witout requiring GLUT
32  inline std::string opengl_error(int err)
33  {
34  switch (err)
35  {
36  case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
37  case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
38  case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
39  case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
40  case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
41  default: std::ostringstream ss; ss << "UNKNOWN(0x" << std::hex << err << '0'; return ss.str();
42  }
43  }
44 } // namespace jevoisbase
45 
46 //! Simple macro to check for OpenGL errors
47 /*! Inspired from here:
48  http://stackoverflow.com/questions/11256470/define-a-macro-to-facilitate-opengl-command-debugging */
49 #define GL_CHECK(stmt) do { stmt; GLenum _err = glGetError(); \
50  if (_err != GL_NO_ERROR) LFATAL("Error " << jevoisbase::opengl_error(_err) <<" in: " << #stmt); } while (0)
51 
52 //! Simple macro to check for OpenGL errors when a boolean result is expected
53 #define GL_CHECK_BOOL(stmt) do { int _result = stmt; if (_result == 0) LERROR("Failed: " #stmt); \
54  GLenum _err = glGetError(); \
55  if (_err != GL_NO_ERROR) LFATAL("Error " << jevoisbase::opengl_error(_err) <<" in: " << #stmt); } while (0)
std::string opengl_error(int err)
Function to write OpenGL errors in clear witout requiring GLUT.
Definition: OpenGL.H:32