Skip to content

Commit

Permalink
EGL: address formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rupansh committed Jan 30, 2022
1 parent 924c9a4 commit fd64323
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
31 changes: 15 additions & 16 deletions SPB/Platform/EGL/EGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions SPB/Platform/EGL/EGLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -28,7 +31,8 @@ public EGLHelper(IntPtr display) {
}
}

public static void BindApi() {
public static void BindApi()
{
EGL.BindApi((int) EGL.Attribute.OPENGL_API);
}

Expand Down Expand Up @@ -88,7 +92,8 @@ public static List<int> 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());
}

Expand Down
3 changes: 1 addition & 2 deletions SPB/Platform/EGL/EGLOpenGLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
11 changes: 5 additions & 6 deletions SPB/Platform/EGL/EGLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions SPB/Platform/X11/X11Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -71,7 +74,8 @@ out visualId
out num_visuals
);

if (num_visuals != 1) {
if (num_visuals != 1)
{
throw new NotImplementedException();
}

Expand Down

0 comments on commit fd64323

Please sign in to comment.