         { HEX: 0506 "Invalid framebuffer operation" }
     } at "Unknown error" or ;
 
-TUPLE: gl-error code string ;
+TUPLE: gl-error function code string ;
 
 TUPLE: gl-error-log
     { function word initial: t }


gl-error-log [ V{ } clone ] initialize

: <gl-error> ( code -- gl-error )
    dup error>string \ gl-error boa ; inline

: <gl-error-log> ( function code -- gl-error-log )
    <gl-error> now gl-error-log boa ;

: gl-error-code ( -- code/f )
    glGetError dup 0 = [ drop f ] when ; inline

: gl-error ( -- )
    gl-error-code [ <gl-error> throw ] [ ] if* ;

: log-gl-error ( function -- )
    gl-error-code [ <gl-error-log> gl-error-log get push ] [ drop ] if* ;

    V{ } clone gl-error-log set ;

: throw-gl-errors ( -- )
    [ '[ @ _ (gl-error) ] ] annotate-gl-functions ;

: log-gl-errors ( -- )
    [ '[ @ _ log-gl-error ] ] annotate-gl-functions ;
