KiCad PCB EDA Suite
utils.cpp File Reference
#include <confirm.h>
#include <GL/glew.h>
#include <stdexcept>

Go to the source code of this file.

Functions

int checkGlError (const std::string &aInfo, bool aThrow)
 Checks if one of recent OpenGL operations has failed. More...
 
static void GLAPIENTRY debugMsgCallback (GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
 
void enableGlDebug (bool aEnable)
 Enables/disables OpenGL driver messages output. More...
 

Function Documentation

int checkGlError ( const std::string &  aInfo,
bool  aThrow = true 
)

Checks if one of recent OpenGL operations has failed.

If so, it displays appropriate message, starting with aInfo string to give more details.

Parameters
aInfois the beginning of the error message.
aThrowan exception is thrown when true, otherwise only an error message is displayed.
Returns
GL_NO_ERROR in case of no errors or one of GL_ constants returned by glGetError().

Definition at line 30 of file utils.cpp.

References DisplayErrorMessage(), and Format().

Referenced by KIGFX::GPU_CACHED_MANAGER::BeginDrawing(), KIGFX::OPENGL_GAL::BeginDrawing(), KIGFX::OPENGL_COMPOSITOR::bindFb(), KIGFX::CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU(), KIGFX::CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM(), KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), KIGFX::CACHED_CONTAINER_GPU::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), KIGFX::ANTIALIASING_SUPERSAMPLING::Init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), KIGFX::ANTIALIASING_SMAA::loadShaders(), KIGFX::CACHED_CONTAINER_GPU::Map(), KIGFX::ANTIALIASING_SUPERSAMPLING::Present(), KIGFX::ANTIALIASING_SMAA::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::CACHED_CONTAINER_RAM::Unmap(), KIGFX::CACHED_CONTAINER_GPU::Unmap(), and KIGFX::ANTIALIASING_SMAA::updateUniforms().

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  DisplayErrorMessage( nullptr, "OpenGL error occurred", errorMsg );
80  }
81 
82  return result;
83 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:87
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
static void GLAPIENTRY debugMsgCallback ( GLenum  aSource,
GLenum  aType,
GLuint  aId,
GLenum  aSeverity,
GLsizei  aLength,
const GLchar *  aMessage,
const void *  aUserParam 
)
static

Definition at line 88 of file utils.cpp.

Referenced by enableGlDebug().

90 {
91  printf( "%s", aMessage );
92 }
void enableGlDebug ( bool  aEnable)

Enables/disables OpenGL driver messages output.

Parameters
aEnabledecides whether the message should be shown.

Definition at line 95 of file utils.cpp.

References debugMsgCallback().

96 {
97  if( aEnable )
98  {
99  glEnable( GL_DEBUG_OUTPUT );
100  glDebugMessageCallback( (GLDEBUGPROC) debugMsgCallback, nullptr );
101  }
102  else
103  {
104  glDisable( GL_DEBUG_OUTPUT );
105  }
106 }
static void GLAPIENTRY debugMsgCallback(GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
Definition: utils.cpp:88