45int checkGlError(
const std::string& aInfo,
const char* aFile,
int aLine,
bool aThrow )
57 errorMsg = wxString::Format(
"Error: %s: invalid enum", aInfo );
60 case GL_INVALID_VALUE:
61 errorMsg = wxString::Format(
"Error: %s: invalid value", aInfo );
64 case GL_INVALID_OPERATION:
65 errorMsg = wxString::Format(
"Error: %s: invalid operation", aInfo );
68 case GL_INVALID_FRAMEBUFFER_OPERATION:
70 GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
72 if( status != GL_FRAMEBUFFER_COMPLETE )
76 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
77 errorMsg =
"The framebuffer attachment points are incomplete.";
80 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
81 errorMsg =
"No images attached to the framebuffer.";
84 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
85 errorMsg =
"The framebuffer does not have at least one image attached to it.";
88 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
89 errorMsg =
"The framebuffer read buffer is incomplete.";
92 case GL_FRAMEBUFFER_UNSUPPORTED:
93 errorMsg =
"The combination of internal formats of the attached images violates "
94 "an implementation dependent set of restrictions.";
97 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
98 errorMsg =
"GL_RENDERBUFFER_SAMPLES is not the same for all attached render "
102 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
103 errorMsg =
"Framebuffer incomplete layer targets errors.";
106 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
107 errorMsg =
"Framebuffer attachments have different dimensions";
111 errorMsg.Printf(
"Unknown incomplete framebuffer error id %X", status );
116 errorMsg = wxString::Format(
"Error: %s: invalid framebuffer operation", aInfo );
121 case GL_OUT_OF_MEMORY:
122 errorMsg = wxString::Format(
"Error: %s: out of memory", aInfo );
125 case GL_STACK_UNDERFLOW:
126 errorMsg = wxString::Format(
"Error: %s: stack underflow", aInfo );
129 case GL_STACK_OVERFLOW:
130 errorMsg = wxString::Format(
"Error: %s: stack overflow", aInfo );
134 errorMsg = wxString::Format(
"Error: %s: unknown error", aInfo );
138 if(
result != GL_NO_ERROR )
143 "in file '%s' on line %d." ),
148 throw std::runtime_error( (
const char*) errorMsg.char_str() );
152 wxString msg = wxString::Format( wxT(
"glGetError() '%s' in file '%s' on line %d." ),
168 GLsizei aLength,
const GLchar* aMessage,
169 const void* aUserParam )
173 case GL_DEBUG_SEVERITY_HIGH:
176 case GL_DEBUG_SEVERITY_MEDIUM:
179 case GL_DEBUG_SEVERITY_LOW:
182 case GL_DEBUG_SEVERITY_NOTIFICATION:
192 glEnable( GL_DEBUG_OUTPUT );
197 glDisable( GL_DEBUG_OUTPUT );
207 GLint nvxAvailableKiB = 0;
208 GLint atiVboFreeKiB[4] = { 0, 0, 0, 0 };
210 if( GLAD_GL_NVX_gpu_memory_info )
211 glGetIntegerv( GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &nvxAvailableKiB );
213 if( GLAD_GL_ATI_meminfo )
214 glGetIntegerv( GL_VBO_FREE_MEMORY_ATI, atiVboFreeKiB );
220 auto bytes = []( GLint aKiB ) ->
size_t
222 return static_cast<size_t>( std::max( aKiB, 0 ) ) * 1024;
225 const char* version =
reinterpret_cast<const char*
>( glGetString( GL_VERSION ) );
229 if( GLAD_GL_ATI_meminfo && version && strstr( version,
" Mesa " ) )
230 return bytes( atiVboFreeKiB[0] ) +
bytes( atiVboFreeKiB[2] );
232 if( GLAD_GL_NVX_gpu_memory_info )
233 return bytes( nvxAvailableKiB );
235 if( GLAD_GL_ATI_meminfo )
236 return bytes( atiVboFreeKiB[0] );
250 const double margin = 1.0 + std::max( 0.0, aMarginFrac );
252 if(
static_cast<double>( aFreeVRAM ) >=
static_cast<double>( aOldBytes + aNewBytes ) * margin )
255 if(
static_cast<double>( aFreeVRAM ) >=
static_cast<double>( aNewBytes ) * margin )
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static const wxChar *const traceGalOpenGlError
Flag to enable debug output of the GAL OpenGL error checking.
The Cairo implementation of the graphics abstraction layer.
VRAM_RESIZE_STRATEGY
Strategy for growing a GPU vertex buffer, trading copy speed against peak video memory.
@ REFUSE
Neither path fits; the caller should fall back to software rendering.
@ GPU_COPY
Fast GPU-side copy; the old and new buffers are briefly co-resident.
@ RAM_STAGE
Stage through host memory so only the larger of the two buffers is resident.
VRAM_RESIZE_STRATEGY chooseResizeStrategy(size_t aFreeVRAM, size_t aOldBytes, size_t aNewBytes, double aMarginFrac)
Decide how to grow a GPU vertex buffer given the free video memory budget.
size_t queryFreeVideoMemoryBytes()
Query the amount of free video memory the driver reports.
static std::vector< uint8_t > bytes(const std::string &aText)
wxString result
Test unit parsing edge cases and error handling.
void enableGlDebug(bool aEnable)
Enable or disable OpenGL driver messages output.
static void GLAPIENTRY debugMsgCallback(GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity, GLsizei aLength, const GLchar *aMessage, const void *aUserParam)
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.