Beispiel #1
0
        public static nint GetConfig(EGLDisplay display, int[] desiredConfig)
        {
            int num_configs;
            var configs = new nint[1];

            if (!Egl.eglChooseConfig(display, desiredConfig, configs, 1, out num_configs) || num_configs < 1)
            {
                throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", Egl.eglGetError()));
            }
            return(configs[0]);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public static string GetExtensions(EGLDisplay display) => Egl.QueryString(display, Definition.EXTENSIONS);
Beispiel #4
0
 public static string GetVendor(EGLDisplay display) => Egl.QueryString(display, Definition.VENDOR);
Beispiel #5
0
 public static string GetVersion(EGLDisplay display) => Egl.QueryString(display, Definition.VERSION);
Beispiel #6
0
        public static nint[] GetAllConfigs(EGLDisplay display, int[] desiredConfig)
        {
            int num_configs;

            if (!Egl.eglChooseConfig(display, desiredConfig, null, 0, out num_configs) || num_configs == 0)
            {
                throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", Egl.eglGetError()));
            }

            var configs = new nint[num_configs];

            if (!Egl.eglChooseConfig(display, null, configs, num_configs, out num_configs))
            {
                throw new NotSupportedException(String.Format("[EGL] Failed to retrieve GraphicsMode, error {0}", Egl.eglGetError()));
            }
            return(configs);
        }