Browse Source

Moved GL/EGL errors to separate enumeration

pull/2205/head
mstr2 7 years ago
parent
commit
4c4e72ab86
  1. 21
      src/Avalonia.OpenGL/EglErrors.cs
  2. 3
      src/Avalonia.OpenGL/GlConsts.cs
  3. 15
      src/Avalonia.OpenGL/GlErrors.cs
  4. 30
      src/Avalonia.OpenGL/OpenGlException.cs

21
src/Avalonia.OpenGL/EglErrors.cs

@ -0,0 +1,21 @@
namespace Avalonia.OpenGL
{
public enum EglErrors
{
EGL_SUCCESS = EglConsts.EGL_SUCCESS,
EGL_NOT_INITIALIZED = EglConsts.EGL_NOT_INITIALIZED,
EGL_BAD_ACCESS = EglConsts.EGL_BAD_ACCESS,
EGL_BAD_ALLOC = EglConsts.EGL_BAD_ALLOC,
EGL_BAD_ATTRIBUTE = EglConsts.EGL_BAD_ATTRIBUTE,
EGL_BAD_CONTEXT = EglConsts.EGL_BAD_CONTEXT,
EGL_BAD_CONFIG = EglConsts.EGL_BAD_CONFIG,
EGL_BAD_CURRENT_SURFACE = EglConsts.EGL_BAD_CURRENT_SURFACE,
EGL_BAD_DISPLAY = EglConsts.EGL_BAD_DISPLAY,
EGL_BAD_SURFACE = EglConsts.EGL_BAD_SURFACE,
EGL_BAD_MATCH = EglConsts.EGL_BAD_MATCH,
EGL_BAD_PARAMETER = EglConsts.EGL_BAD_PARAMETER,
EGL_BAD_NATIVE_PIXMAP = EglConsts.EGL_BAD_NATIVE_PIXMAP,
EGL_BAD_NATIVE_WINDOW = EglConsts.EGL_BAD_NATIVE_WINDOW,
EGL_CONTEXT_LOST = EglConsts.EGL_CONTEXT_LOST
}
}

3
src/Avalonia.OpenGL/GlConsts.cs

@ -456,12 +456,15 @@ namespace Avalonia.OpenGL
public const int GL_RENDERER = 0x1F01; public const int GL_RENDERER = 0x1F01;
public const int GL_VERSION = 0x1F02; public const int GL_VERSION = 0x1F02;
public const int GL_EXTENSIONS = 0x1F03; public const int GL_EXTENSIONS = 0x1F03;
public const int GL_NO_ERROR = 0;
public const int GL_INVALID_ENUM = 0x0500; public const int GL_INVALID_ENUM = 0x0500;
public const int GL_INVALID_VALUE = 0x0501; public const int GL_INVALID_VALUE = 0x0501;
public const int GL_INVALID_OPERATION = 0x0502; public const int GL_INVALID_OPERATION = 0x0502;
public const int GL_STACK_OVERFLOW = 0x0503; public const int GL_STACK_OVERFLOW = 0x0503;
public const int GL_STACK_UNDERFLOW = 0x0504; public const int GL_STACK_UNDERFLOW = 0x0504;
public const int GL_OUT_OF_MEMORY = 0x0505; public const int GL_OUT_OF_MEMORY = 0x0505;
public const int GL_INVALID_FRAMEBUFFER_OPERATION = 0x0506;
public const int GL_CONTEXT_LOST = 0x0507;
public const int GL_CURRENT_BIT = 0x00000001; public const int GL_CURRENT_BIT = 0x00000001;
public const int GL_POINT_BIT = 0x00000002; public const int GL_POINT_BIT = 0x00000002;
public const int GL_LINE_BIT = 0x00000004; public const int GL_LINE_BIT = 0x00000004;

15
src/Avalonia.OpenGL/GlErrors.cs

@ -0,0 +1,15 @@
namespace Avalonia.OpenGL
{
public enum GlErrors
{
GL_NO_ERROR = GlConsts.GL_NO_ERROR,
GL_INVALID_ENUM = GlConsts.GL_INVALID_ENUM,
GL_INVALID_VALUE = GlConsts.GL_INVALID_VALUE,
GL_INVALID_OPERATION = GlConsts.GL_INVALID_OPERATION,
GL_INVALID_FRAMEBUFFER_OPERATION = GlConsts.GL_INVALID_FRAMEBUFFER_OPERATION,
GL_STACK_OVERFLOW = GlConsts.GL_STACK_OVERFLOW,
GL_STACK_UNDERFLOW = GlConsts.GL_STACK_UNDERFLOW,
GL_OUT_OF_MEMORY = GlConsts.GL_OUT_OF_MEMORY,
GL_CONTEXT_LOST = GlConsts.GL_CONTEXT_LOST
}
}

30
src/Avalonia.OpenGL/OpenGlException.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Reflection;
namespace Avalonia.OpenGL namespace Avalonia.OpenGL
{ {
@ -18,33 +17,26 @@ namespace Avalonia.OpenGL
public static OpenGlException GetFormattedException(string funcName, EglInterface egl) public static OpenGlException GetFormattedException(string funcName, EglInterface egl)
{ {
return GetFormattedException(typeof(EglConsts).GetFields(), funcName, 0x3000, 0x301F, egl.GetError()); return GetFormattedException(typeof(EglErrors), funcName, egl.GetError());
} }
public static OpenGlException GetFormattedException(string funcName, GlInterface gl) public static OpenGlException GetFormattedException(string funcName, GlInterface gl)
{ {
return GetFormattedException(typeof(GlConsts).GetFields(), funcName, 0x0500, 0x0505, gl.GetError()); return GetFormattedException(typeof(GlErrors), funcName, gl.GetError());
} }
private static OpenGlException GetFormattedException( private static OpenGlException GetFormattedException(Type consts, string funcName, int errorCode)
FieldInfo[] fields, string funcName, int minValue, int maxValue, int errorCode)
{ {
foreach (var field in fields) try
{ {
int value = (int)field.GetValue(null); string errorName = Enum.GetName(consts, errorCode);
if (value < minValue || value > maxValue) return new OpenGlException(
{ $"{funcName} failed with error {errorName} (0x{errorCode.ToString("X")})", errorCode);
continue; }
} catch (ArgumentException)
{
if (value == errorCode) return new OpenGlException($"{funcName} failed with error 0x{errorCode.ToString("X")}", errorCode);
{
return new OpenGlException(
$"{funcName} failed with error {field.Name} (0x{errorCode.ToString("X")})", errorCode);
}
} }
return new OpenGlException($"{funcName} failed with error 0x{errorCode.ToString("X")}", errorCode);
} }
} }
} }

Loading…
Cancel
Save