From fd64323426efac608943d0ac518939897c93ff7b Mon Sep 17 00:00:00 2001 From: rupansh Date: Sun, 30 Jan 2022 22:27:26 +0530 Subject: [PATCH] EGL: address formatting issues --- SPB/Platform/EGL/EGL.cs | 31 ++++++++++++++-------------- SPB/Platform/EGL/EGLHelper.cs | 15 +++++++++----- SPB/Platform/EGL/EGLOpenGLContext.cs | 3 +-- SPB/Platform/EGL/EGLWindow.cs | 11 +++++----- SPB/Platform/X11/X11Helper.cs | 10 ++++++--- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/SPB/Platform/EGL/EGL.cs b/SPB/Platform/EGL/EGL.cs index a478b7f..46279d2 100644 --- a/SPB/Platform/EGL/EGL.cs +++ b/SPB/Platform/EGL/EGL.cs @@ -107,25 +107,24 @@ internal enum RenderTypeMask : int public enum ErrorCode : int { - EGL_SUCCESS = 0x3000, - EGL_NOT_INITIALIZED = 0x3001, - EGL_BAD_ACCESS = 0x3002, - EGL_BAD_ALLOC = 0x3003, - EGL_BAD_ATTRIBUTE = 0x3004, - EGL_BAD_CONFIG = 0x3005, - EGL_BAD_CONTEXT = 0x3006, - EGL_BAD_CURRENT_SURFACE = 0x3007, - EGL_BAD_DISPLAY = 0x3008, - EGL_BAD_MATCH = 0x3009, - EGL_BAD_NATIVE_PIXMAP = 0x300A, - EGL_BAD_NATIVE_WINDOW = 0x300B, - EGL_BAD_PARAMETER = 0x300C, - EGL_BAD_SURFACE = 0x300D, - EGL_CONTEXT_LOST = 0x300E + SUCCESS = 0x3000, + NOT_INITIALIZED = 0x3001, + BAD_ACCESS = 0x3002, + BAD_ALLOC = 0x3003, + BAD_ATTRIBUTE = 0x3004, + BAD_CONFIG = 0x3005, + BAD_CONTEXT = 0x3006, + BAD_CURRENT_SURFACE = 0x3007, + BAD_DISPLAY = 0x3008, + BAD_MATCH = 0x3009, + BAD_NATIVE_PIXMAP = 0x300A, + BAD_NATIVE_WINDOW = 0x300B, + BAD_PARAMETER = 0x300C, + BAD_SURFACE = 0x300D, + CONTEXT_LOST = 0x300E } - internal sealed class ARB { public enum ContextFlags : int diff --git a/SPB/Platform/EGL/EGLHelper.cs b/SPB/Platform/EGL/EGLHelper.cs index 19e2580..3de04f7 100644 --- a/SPB/Platform/EGL/EGLHelper.cs +++ b/SPB/Platform/EGL/EGLHelper.cs @@ -12,13 +12,16 @@ public sealed class EGLHelper public static IntPtr _eglDisplay; private static bool init; - public IntPtr eglDisplay { - get { + public IntPtr eglDisplay + { + get + { return _eglDisplay; } } - public EGLHelper(IntPtr display) { + public EGLHelper(IntPtr display) + { if (!init) { unsafe { _eglDisplay = EGL.GetPlatformDisplay((int)EGL.Attribute.PLATFORM_X11_KHR, display, (IntPtr *)IntPtr.Zero.ToPointer()); @@ -28,7 +31,8 @@ public EGLHelper(IntPtr display) { } } - public static void BindApi() { + public static void BindApi() + { EGL.BindApi((int) EGL.Attribute.OPENGL_API); } @@ -88,7 +92,8 @@ public static List FramebufferFormatToVisualAttribute(FramebufferFormat for return result; } - public unsafe IntPtr eglWindowSurface(IntPtr nativeWindowHandle, IntPtr fbConfig) { + public unsafe IntPtr EGLWindowSurface(IntPtr nativeWindowHandle, IntPtr fbConfig) + { return EGL.CreateWindowSurface(eglDisplay, fbConfig, nativeWindowHandle, (IntPtr *)IntPtr.Zero.ToPointer()); } diff --git a/SPB/Platform/EGL/EGLOpenGLContext.cs b/SPB/Platform/EGL/EGLOpenGLContext.cs index 68b4914..bf34fab 100644 --- a/SPB/Platform/EGL/EGLOpenGLContext.cs +++ b/SPB/Platform/EGL/EGLOpenGLContext.cs @@ -88,8 +88,7 @@ public override void Initialize(NativeWindowBase window = null) if (ContextHandle == IntPtr.Zero) { - Console.WriteLine("ERR {0}", EGL.GetError()); - throw new ContextException("CreateContext() failed."); + throw new ContextException(String.Format("CreateContext() failed: {0}", EGL.GetError())); } } diff --git a/SPB/Platform/EGL/EGLWindow.cs b/SPB/Platform/EGL/EGLWindow.cs index 6bcb63c..b0b4282 100644 --- a/SPB/Platform/EGL/EGLWindow.cs +++ b/SPB/Platform/EGL/EGLWindow.cs @@ -17,27 +17,26 @@ public sealed class EGLWindow : SwappableNativeWindowBase private EGLHelper _helper; private IntPtr _surface = IntPtr.Zero; - public EGLWindow(NativeHandle displayHandle, NativeHandle windowHandle) { + public EGLWindow(NativeHandle displayHandle, NativeHandle windowHandle) + { DisplayHandle = displayHandle; WindowHandle = windowHandle; _swapInterval = 1; } - public IntPtr EGLSurface(EGLHelper helper, IntPtr fbConfig) { + public IntPtr EGLSurface(EGLHelper helper, IntPtr fbConfig) + { if (_surface != IntPtr.Zero) { return _surface; } _helper = helper; - _surface = _helper.eglWindowSurface(WindowHandle.RawHandle, fbConfig); + _surface = _helper.EGLWindowSurface(WindowHandle.RawHandle, fbConfig); return _surface; } public override uint SwapInterval { - // TODO: check extension support - // TODO: support MESA and SGI - // TODO: use glXQueryDrawable to query swap interval when GLX_EXT_swap_control is supported. get { return _swapInterval; diff --git a/SPB/Platform/X11/X11Helper.cs b/SPB/Platform/X11/X11Helper.cs index a53488c..d6d97e5 100644 --- a/SPB/Platform/X11/X11Helper.cs +++ b/SPB/Platform/X11/X11Helper.cs @@ -42,11 +42,14 @@ private static unsafe NativeHandle CreateX11Window(NativeHandle display, X11.XVi return new NativeHandle(rawWindowHandle); } - public static EGLWindow CreateEGLWindow(NativeHandle display, FramebufferFormat format, int x, int y, int width, int height) { + + public static EGLWindow CreateEGLWindow(NativeHandle display, FramebufferFormat format, int x, int y, int width, int height) + { EGLHelper helper = new EGLHelper(display.RawHandle); EGLHelper.BindApi(); IntPtr fbConfig = helper.SelectFBConfig(format); - if (fbConfig == IntPtr.Zero) { + if (fbConfig == IntPtr.Zero) + { throw new NotImplementedException(); } @@ -71,7 +74,8 @@ out visualId out num_visuals ); - if (num_visuals != 1) { + if (num_visuals != 1) + { throw new NotImplementedException(); }