44int checkGlError(
const std::string& aInfo,
const char* aFile,
int aLine,
bool aThrow )
56 errorMsg = wxString::Format(
"Error: %s: invalid enum", aInfo );
59 case GL_INVALID_VALUE:
60 errorMsg = wxString::Format(
"Error: %s: invalid value", aInfo );
63 case GL_INVALID_OPERATION:
64 errorMsg = wxString::Format(
"Error: %s: invalid operation", aInfo );
67 case GL_INVALID_FRAMEBUFFER_OPERATION:
69 GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
71 if( status != GL_FRAMEBUFFER_COMPLETE )
75 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
76 errorMsg =
"The framebuffer attachment points are incomplete.";
79 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
80 errorMsg =
"No images attached to the framebuffer.";
83 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
84 errorMsg =
"The framebuffer does not have at least one image attached to it.";
87 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
88 errorMsg =
"The framebuffer read buffer is incomplete.";
91 case GL_FRAMEBUFFER_UNSUPPORTED:
92 errorMsg =
"The combination of internal formats of the attached images violates "
93 "an implementation dependent set of restrictions.";
96 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
97 errorMsg =
"GL_RENDERBUFFER_SAMPLES is not the same for all attached render "
101 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
102 errorMsg =
"Framebuffer incomplete layer targets errors.";
105 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
106 errorMsg =
"Framebuffer attachments have different dimensions";
110 errorMsg.Printf(
"Unknown incomplete framebuffer error id %X", status );
115 errorMsg = wxString::Format(
"Error: %s: invalid framebuffer operation", aInfo );
120 case GL_OUT_OF_MEMORY:
121 errorMsg = wxString::Format(
"Error: %s: out of memory", aInfo );
124 case GL_STACK_UNDERFLOW:
125 errorMsg = wxString::Format(
"Error: %s: stack underflow", aInfo );
128 case GL_STACK_OVERFLOW:
129 errorMsg = wxString::Format(
"Error: %s: stack overflow", aInfo );
133 errorMsg = wxString::Format(
"Error: %s: unknown error", aInfo );
137 if(
result != GL_NO_ERROR )
142 "in file '%s' on line %d." ),
147 throw std::runtime_error( (
const char*) errorMsg.char_str() );
151 wxString msg = wxString::Format( wxT(
"glGetError() '%s' in file '%s' on line %d." ),
166static void GLAPIENTRY
debugMsgCallback( GLenum aSource, GLenum aType, GLuint aId, GLenum aSeverity,
167 GLsizei aLength,
const GLchar* aMessage,
168 const void* aUserParam )
172 case GL_DEBUG_SEVERITY_HIGH:
175 case GL_DEBUG_SEVERITY_MEDIUM:
178 case GL_DEBUG_SEVERITY_LOW:
181 case GL_DEBUG_SEVERITY_NOTIFICATION:
191 glEnable( GL_DEBUG_OUTPUT );
196 glDisable( GL_DEBUG_OUTPUT );
206 GLint availableKiB = 0;
208 if( GLAD_GL_NVX_gpu_memory_info )
210 glGetIntegerv( GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &availableKiB );
212 else if( GLAD_GL_ATI_meminfo )
214 GLint
info[4] = { 0, 0, 0, 0 };
215 glGetIntegerv( GL_VBO_FREE_MEMORY_ATI,
info );
216 availableKiB =
info[0];
227 if( availableKiB <= 0 )
230 return static_cast<size_t>( availableKiB ) * 1024;
242 const double margin = 1.0 + std::max( 0.0, aMarginFrac );
244 if(
static_cast<double>( aFreeVRAM ) >=
static_cast<double>( aOldBytes + aNewBytes ) * margin )
247 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.
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.