public static void DumpAllConf(EGLDisplay display, int[] desiredConfig) { Console.Write("EGL Configs"); nint[] configs = ContextExtension.GetAllConfigs(display, desiredConfig); int[] attribs = new int[] { (int)Definitions.Attribute.BufferSize, Definition.RED_SIZE, Definition.GREEN_SIZE, Definition.BLUE_SIZE, Definition.ALPHA_SIZE, (int)Definitions.Attribute.DepthSize, Definition.WIDTH, Definition.HEIGHT, (int)Definitions.Attribute.Samples, (int)Definitions.Attribute.SampleBuffers, (int)Definitions.Attribute.RenderableType, (int)Definitions.Attribute.SurfaceType, (int)Definitions.Attribute.Level, (int)Definitions.Attribute.ConfigCaveat, }; for (int i = 0; i < configs.Length; i++) { nint conf = configs[i]; Console.Write("{0,-3}:", i); for (int j = 0; j < attribs.Length; j++) { int value; Egl.eglGetConfigAttrib(display, conf, attribs[j], out value); Console.Write((j == 0 ? string.Empty : ", ") + "{0} = {1}", Egl.EglConstToString((int)attribs[j]), value); } Console.Write("\n"); } }
public static (EGLDisplay display, EGLContext context, EGLSurface surface, EGLConfig config, int major, int minor) CrateContext(GBM.Gbm gbm, RenderableSurfaceType surfaceType) { (EGLDisplay display, EGLContext context, EGLSurface surface, EGLConfig config, int major, int minor)result; const uint EGL_PLATFORM_GBM_KHR = 0x31D7; var handler = ContextExtension.OffScreenExtensions.Contains("EGL_EXT_platform_base") ? (GetPlatformDisplayEXTHandler)Marshal.GetDelegateForFunctionPointer(Egl.eglGetProcAddress("eglGetPlatformDisplayEXT"), typeof(GetPlatformDisplayEXTHandler)) : null; result.display = handler is null?Egl.eglGetDisplay((nint)gbm.Device.Handle) : handler(EGL_PLATFORM_GBM_KHR, (nint)gbm.Device.Handle, null); if (result.display == IntPtr.Zero) { throw new NotSupportedException("[EGL] GetDisplay failed.: " + Egl.eglGetError()); } if (!Egl.eglInitialize(result.display, out result.major, out result.minor)) { throw new NotSupportedException("[EGL] Failed to initialize EGL display. Error code: " + Egl.eglGetError()); } var isModifiersSupported = GetExtensions(result.display).Contains("EGL_EXT_image_dma_buf_import_modifiers"); if (!Egl.eglBindAPI(RenderApi.GLES)) { throw new NotSupportedException("[EGL] Failed to bind EGL Api: " + Egl.eglGetError()); } var desiredConfig = new[] { Definition.SURFACE_TYPE, (int)surfaceType, Definition.RENDERABLE_TYPE, Definition.OPENGL_ES3_BIT, Definition.RED_SIZE, 8, Definition.GREEN_SIZE, 8, Definition.BLUE_SIZE, 8, Definition.ALPHA_SIZE, 8, Definition.STENCIL_SIZE, 8, Definition.SAMPLE_BUFFERS, 0, Definition.SAMPLES, 0, Definition.NONE }; result.config = ContextExtension.GetConfig(result.display, desiredConfig); var contextAttrib = new[] { Definition.CONTEXT_CLIENT_VERSION, 3, Definition.NONE }; result.context = Egl.CreateContext(result.display, result.config, IntPtr.Zero, contextAttrib); if (result.context == IntPtr.Zero) { throw new NotSupportedException(String.Format("[EGL] Failed to create egl context, error {0}.", Egl.eglGetError())); } result.surface = Egl.eglCreateWindowSurface(result.display, result.config, gbm.Surface.Handle, null); if (result.surface == IntPtr.Zero) { throw new NotSupportedException(String.Format("[EGL] Failed to create egl surface, error {0}.", Egl.eglGetError())); } if (!Egl.eglMakeCurrent(result.display, result.surface, result.surface, result.context)) { throw new NotSupportedException(String.Format("[EGL] Failed to make current, error {0}.", Egl.eglGetError())); } return(result); }