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

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

◆ checkGlError()

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 32 of file utils.cpp.

33 {
34  int result = glGetError();
35  wxString errorMsg;
36 
37  switch( result )
38  {
39  case GL_NO_ERROR:
40  // all good
41  break;
42 
43  case GL_INVALID_ENUM:
44  errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo );
45  break;
46 
47  case GL_INVALID_VALUE:
48  errorMsg = wxString::Format( "Error: %s: invalid value", aInfo );
49  break;
50 
51  case GL_INVALID_OPERATION:
52  errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo );
53  break;
54 
55  case GL_INVALID_FRAMEBUFFER_OPERATION:
56  {
57  GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
58 
59  if( status != GL_FRAMEBUFFER_COMPLETE_EXT )
60  {
61  switch( status )
62  {
63  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
64  errorMsg = "The framebuffer attachment points are incomplete.";
65  break;
66  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
67  errorMsg = "No images attached to the framebuffer.";
68  break;
69  case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
70  errorMsg = "The framebuffer does not have at least one image attached to it.";
71  break;
72  case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
73  errorMsg = "The framebuffer read buffer is incomplete.";
74  break;
75  case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
76  errorMsg = "The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.";
77  break;
78  case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
79  errorMsg = "GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers.";
80  break;
81  case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT:
82  errorMsg = "Framebuffer incomplete layer targets errors.";
83  break;
84  case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
85  errorMsg = "Framebuffer attachments have different dimensions";
86  break;
87  default:
88  errorMsg.Printf( "Unknown incomplete framebuffer error id %X", status );
89  }
90  }
91  else
92  errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo );
93  }
94  break;
95 
96  case GL_OUT_OF_MEMORY:
97  errorMsg = wxString::Format( "Error: %s: out of memory", aInfo );
98  break;
99 
100  case GL_STACK_UNDERFLOW:
101  errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo );
102  break;
103 
104  case GL_STACK_OVERFLOW:
105  errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo );
106  break;
107 
108  default:
109  errorMsg = wxString::Format( "Error: %s: unknown error", aInfo );
110  break;
111  }
112 
113  if( result != GL_NO_ERROR )
114  {
115  if( aThrow )
116  throw std::runtime_error( (const char*) errorMsg.char_str() );
117  else
118  DisplayErrorMessage( nullptr, "OpenGL error occurred", errorMsg );
119  }
120 
121  return result;
122 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
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:201

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().

◆ debugMsgCallback()

static void GLAPIENTRY debugMsgCallback ( GLenum  aSource,
GLenum  aType,
GLuint  aId,
GLenum  aSeverity,
GLsizei  aLength,
const GLchar *  aMessage,
const void *  aUserParam 
)
static

Definition at line 127 of file utils.cpp.

129 {
130  switch( aSeverity )
131  {
132  case GL_DEBUG_SEVERITY_HIGH: wxLogDebug( "OpenGL ERROR: " ); break;
133  case GL_DEBUG_SEVERITY_MEDIUM: wxLogDebug( "OpenGL WARNING: " ); break;
134  case GL_DEBUG_SEVERITY_LOW: wxLogDebug( "OpenGL INFO: " ); break;
135  case GL_DEBUG_SEVERITY_NOTIFICATION: return;
136  }
137 
138  wxLogDebug( "%s\n", aMessage );
139 }

Referenced by enableGlDebug().

◆ enableGlDebug()

void enableGlDebug ( bool  aEnable)

Enables/disables OpenGL driver messages output.

Parameters
aEnabledecides whether the message should be shown.

Definition at line 142 of file utils.cpp.

143 {
144  if( aEnable )
145  {
146  glEnable( GL_DEBUG_OUTPUT );
147  glDebugMessageCallback( (GLDEBUGPROC) debugMsgCallback, nullptr );
148  }
149  else
150  {
151  glDisable( GL_DEBUG_OUTPUT );
152  }
153 }
static void GLAPIENTRY debugMsgCallback(GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
Definition: utils.cpp:127

References debugMsgCallback().

Referenced by KIGFX::OPENGL_GAL::init().