KiCad PCB EDA Suite
utils.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <confirm.h> // DisplayError
26 
27 #include <GL/glew.h>
28 #include <stdexcept>
29 
30 int checkGlError( const std::string& aInfo, bool aThrow )
31 {
32  int result = glGetError();
33  wxString errorMsg;
34 
35  switch( result )
36  {
37  case GL_NO_ERROR:
38  // all good
39  break;
40 
41  case GL_INVALID_ENUM:
42  errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo );
43  break;
44 
45  case GL_INVALID_VALUE:
46  errorMsg = wxString::Format( "Error: %s: invalid value", aInfo );
47  break;
48 
49  case GL_INVALID_OPERATION:
50  errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo );
51  break;
52 
53  case GL_INVALID_FRAMEBUFFER_OPERATION:
54  errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo );
55  break;
56 
57  case GL_OUT_OF_MEMORY:
58  errorMsg = wxString::Format( "Error: %s: out of memory", aInfo );
59  break;
60 
61  case GL_STACK_UNDERFLOW:
62  errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo );
63  break;
64 
65  case GL_STACK_OVERFLOW:
66  errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo );
67  break;
68 
69  default:
70  errorMsg = wxString::Format( "Error: %s: unknown error", aInfo );
71  break;
72  }
73 
74  if( result != GL_NO_ERROR )
75  {
76  if( aThrow )
77  throw std::runtime_error( (const char*) errorMsg.char_str() );
78  else
79  DisplayError( nullptr, errorMsg );
80  }
81 
82  return result;
83 }
84 
This file is part of the common library.
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
Definition: utils.cpp:30
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69