Esempio n. 1
0
        public static bool DumpErrors(
            this IOpenGl gl,
            [CallerFilePath] string?file      = null,
            [CallerMemberName] string?caller  = null,
            [CallerLineNumber] int lineNumber = 0)
        {
            bool result = false;

            while (true)
            {
                var err = gl.GetError();

                if (err == Gl.NoError)
                {
                    break;
                }

                result = true;
                Console.Write($"{file} - {caller} : {lineNumber} - ");

                switch (err)
                {
                case Gl.InvalidEnum: Console.WriteLine("GL_INVALID_ENUM"); break;

                case Gl.InvalidValue: Console.WriteLine("GL_INVALID_VALUE"); break;

                case Gl.InvalidOperation: Console.WriteLine("GL_INVALID_OPERATION"); break;

                case Gl.StackOverflow: Console.WriteLine("GL_STACK_OVERFLOW"); break;

                case Gl.StackUnderflow: Console.WriteLine("GL_STACK_UNDERFLOW"); break;

                case Gl.OutOfMemory: Console.WriteLine("GL_OUT_OF_MEMORY"); break;

                case Gl.InvalidFramebufferOperation: Console.WriteLine("GL_INVALID_FRAMEBUFFER_OPERATION"); break;

                case Gl.ContextLost: Console.WriteLine("GL_CONTEXT_LOST"); break;

                default: Console.WriteLine("Everything is fine. Nothing is broken."); break;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static bool TryLogErrors(
            this IOpenGl gl,
            ILogger logger,
            [CallerFilePath] string?file      = null,
            [CallerMemberName] string?caller  = null,
            [CallerLineNumber] int lineNumber = 0)
        {
            bool result = false;

            while (true)
            {
                var err = gl.GetError();

                if (err == Gl.NoError)
                {
                    break;
                }

                result = true;
                var errorEnum = err switch
                {
                    Gl.InvalidEnum => "GL_INVALID_ENUM",
                    Gl.InvalidValue => "GL_INVALID_VALUE",
                    Gl.InvalidOperation => "GL_INVALID_OPERATION",
                    Gl.StackOverflow => "GL_STACK_OVERFLOW",
                    Gl.StackUnderflow => "GL_STACK_UNDERFLOW",
                    Gl.OutOfMemory => "GL_OUT_OF_MEMORY",
                    Gl.InvalidFramebufferOperation => "GL_INVALID_FRAMEBUFFER_OPERATION",
                    Gl.ContextLost => "GL_CONTEXT_LOST",
                    _ => $"unknown error value: " + err
                };

                logger.LogError($"{file} - {caller} : {lineNumber} - {errorEnum}");
            }

            return(result);
        }
    }