int swap_interval = 1; // Default interval is defined as 1 in EGL. #endregion #region Constructors public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } EglContext shared = (EglContext)sharedContext; WindowInfo = window; // Select an EGLConfig that matches the desired mode. We cannot use the 'mode' // parameter directly, since it may have originated on a different system (e.g. GLX) // and it may not support the desired renderer. Renderable = major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES; Mode = new EglGraphicsMode().SelectGraphicsMode(window, mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, Renderable); if (!Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } IntPtr config = Mode.Index.Value; if (window.Surface == IntPtr.Zero) { window.CreateWindowSurface(config); } int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; HandleAsEGLContext = Egl.CreateContext(window.Display, config, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list); MakeCurrent(window); }
bool vsync = true; // Default vsync value is defined as 1 (true) in EGL. #endregion #region Constructors public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } EglContext shared = (EglContext)sharedContext; int dummy_major, dummy_minor; if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor)) { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } WindowInfo = window; Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo); if (!Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } EGLConfig config = new EGLConfig(mode.Index.Value); if (window.Surface.Handle == EGLSurface.None.Handle) { window.CreateWindowSurface(config); } int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; HandleAsEGLContext = Egl.CreateContext(window.Display, config, shared != null ? shared.HandleAsEGLContext : EGLContext.None, attrib_list); MakeCurrent(window); }
public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } EglContext eglContext = (EglContext)sharedContext; int major1; int minor1; if (!Egl.Initialize(window.Display, out major1, out minor1)) { throw new GraphicsContextException(string.Format("Failed to initialize EGL, error {0}.", (object)Egl.GetError())); } this.WindowInfo = window; this.Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES); if (!this.Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } IntPtr config = this.Mode.Index.Value; if (window.Surface == IntPtr.Zero) { window.CreateWindowSurface(config); } int[] attrib_list = new int[3] { 12440, major, 12344 }; this.HandleAsEGLContext = Egl.CreateContext(window.Display, config, eglContext != null ? eglContext.HandleAsEGLContext : IntPtr.Zero, attrib_list); this.MakeCurrent((IWindowInfo)window); }
public override void MakeCurrent(IWindowInfo window) { // Ignore 'window', unless it actually is an EGL window. In other words, // trying to make the EglContext current on a non-EGL window will do, // nothing (the EglContext will remain current on the previous EGL window // or the window it was constructed on (which may not be EGL)). if (window != null) { if (window is EglWindowInfo) { WindowInfo = (EglWindowInfo)window; } if (!Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext)) { throw new GraphicsContextException(string.Format("Failed to make context {0} current. Error: {1}", Handle, Egl.GetError())); } } else { Egl.MakeCurrent(WindowInfo.Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { X11WindowInfo x11WindowInfo = (X11WindowInfo)window; EglWindowInfo window1 = new EglWindowInfo(x11WindowInfo.WindowHandle, Egl.GetDisplay(x11WindowInfo.Display)); return((IGraphicsContext) new EglContext(handle, window1, shareContext, major, minor, flags)); }
public override IntPtr GetAddress(string function) { return(Egl.GetProcAddress(function)); }
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags) { X11WindowInfo x11_win = (X11WindowInfo)window; EglWindowInfo egl_win = new OpenTK.Platform.Egl.EglWindowInfo(x11_win.WindowHandle, Egl.GetDisplay(x11_win.Display)); return(new EglContext(handle, egl_win, shareContext, major, minor, flags)); }
//public void CreatePixmapSurface(EGLConfig config) //{ // Surface = Egl.CreatePixmapSurface(Display, config, Handle, null); //} public void CreatePbufferSurface(IntPtr config) { int[] attribs = new int[] { Egl.NONE }; Surface = Egl.CreatePbufferSurface(Display, config, attribs); if (Surface == IntPtr.Zero) { throw new GraphicsContextException(String.Format( "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); } }
public GraphicsMode SelectGraphicsMode(EglWindowInfo window, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderable_flags) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { Egl.SURFACE_TYPE, Egl.WINDOW_BIT, Egl.RENDERABLE_TYPE, (int)renderable_flags, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, Egl.NONE, }; IntPtr display = window.Display; int num_configs; if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs) || num_configs == 0) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } // See what we really got IntPtr active_config = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); int sample_buffers; Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); return(new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false)); }
int swap_interval = 1; // Default interval is defined as 1 in EGL. #endregion #region Constructors public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } EglContext shared = GetSharedEglContext(sharedContext); WindowInfo = window; // Select an EGLConfig that matches the desired mode. We cannot use the 'mode' // parameter directly, since it may have originated on a different system (e.g. GLX) // and it may not support the desired renderer. Renderable = RenderableFlags.GL; if ((flags & GraphicsContextFlags.Embedded) != 0) { switch (major) { case 3: Renderable = RenderableFlags.ES3; break; case 2: Renderable = RenderableFlags.ES2; break; default: Renderable = RenderableFlags.ES; break; } } RenderApi api = (Renderable & RenderableFlags.GL) != 0 ? RenderApi.GL : RenderApi.ES; Debug.Print("[EGL] Binding {0} rendering API.", api); if (!Egl.BindAPI(api)) { Debug.Print("[EGL] Failed to bind rendering API. Error: {0}", Egl.GetError()); } bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0; SurfaceType surface_type = offscreen ? SurfaceType.PBUFFER_BIT : SurfaceType.WINDOW_BIT; Mode = new EglGraphicsMode().SelectGraphicsMode(surface_type, window.Display, mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, Renderable, (flags & GraphicsContextFlags.AngleFullscreen) > 0); if (!Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } IntPtr config = Mode.Index.Value; if (window.Surface == IntPtr.Zero) { if (!offscreen) { window.CreateWindowSurface(config); } else { window.CreatePbufferSurface(config); } } int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; var share_context = shared != null ? shared.HandleAsEGLContext : IntPtr.Zero; try { HandleAsEGLContext = Egl.CreateContext(window.Display, config, share_context, attrib_list); GraphicsContextFlags = flags; MakeCurrent(window); } catch { window.DestroySurface(); throw; } }
public EglWindowInfo(IntPtr handle, IntPtr display, IntPtr surface) { Handle = handle; Surface = surface; if (display == IntPtr.Zero) { display = Egl.GetDisplay(IntPtr.Zero); } Display = display; int dummyMajor, dummyMinor; if (!Egl.Initialize(Display, out dummyMajor, out dummyMinor)) { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } }
public void MakeCurrent(EGLSurface surface) { Egl.MakeCurrent(Display, surface, surface, EglContext.HandleAsEGLContext); }
public static IntPtr CreateContext(IntPtr dpy, IntPtr config, IntPtr share_context, int[] attrib_list) { IntPtr context = Egl.eglCreateContext(dpy, config, share_context, attrib_list); if (context == IntPtr.Zero) { throw new GraphicsContextException(string.Format("Failed to create EGL context, error: {0}.", (object)Egl.GetError())); } else { return(context); } }
public void CreateWindowSurface(IntPtr config) { this.Surface = Egl.CreateWindowSurface(this.Display, config, this.Handle, (int[])null); if (this.Surface == IntPtr.Zero) { throw new GraphicsContextException(string.Format("[Error] Failed to create EGL window surface, error {0}.", (object)Egl.GetError())); } }
//public void CreatePixmapSurface(EGLConfig config) //{ // Surface = Egl.CreatePixmapSurface(Display, config, Handle, null); //} public void CreatePbufferSurface(IntPtr config) { Surface = Egl.CreatePbufferSurface(Display, config, null); }
int swap_interval = 1; // Default interval is defined as 1 in EGL. #endregion #region Constructors public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } WindowInfo = window; // Select an EGLConfig that matches the desired mode. We cannot use the 'mode' // parameter directly, since it may have originated on a different system (e.g. GLX) // and it may not support the desired renderer. Renderable = RenderableFlags.GL; if ((flags & GraphicsContextFlags.Embedded) != 0) { switch (major) { case 3: Renderable = RenderableFlags.ES3; break; case 2: Renderable = RenderableFlags.ES2; break; default: Renderable = RenderableFlags.ES; break; } } RenderApi api = (Renderable & RenderableFlags.GL) != 0 ? RenderApi.GL : RenderApi.ES; Debug.Print("[EGL] Binding {0} rendering API.", api); if (!Egl.BindAPI(api)) { Debug.Print("[EGL] Failed to bind rendering API. Error: {0}", Egl.GetError()); } Mode = new EglGraphicsMode().SelectGraphicsMode(window, mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, Renderable); if (!Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } IntPtr config = Mode.Index.Value; if (window.Surface == IntPtr.Zero) { window.CreateWindowSurface(config); } int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; HandleAsEGLContext = Egl.CreateContext(window.Display, config, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, attrib_list); }
IntPtr TryInitEglDisplay(IWindowInfo window, ref int major, ref int minor, ref GraphicsContextFlags flags) { //see https://github.com/Microsoft/angle/wiki/Initializing-ANGLE-on-D3D11-Feature-Level-9 //IntPtr egl_display1 = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[]{ // Egl.PLATFORM_ANGLE_TYPE_ANGLE, // Egl.PLATFORM_ANGLE_TYPE_D3D11_ANGLE, // Egl.PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, // Egl.PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, // Egl.NONE, //}); //if (!Egl.Initialize(egl_display1, out int m1, out int m2)) //{ //} //1. use default openTK default WinWindowInfo win_win = (WinWindowInfo)window; bool success = false; int eglMajor, eglMinor; IntPtr egl_display = IntPtr.Zero; if (isFirstTimeEval) { isFirstTimeEval = false; egl_display = GetDisplay(win_win.DeviceContext); success = Egl.Initialize(egl_display, out eglMajor, out eglMinor); //------------------- //we found that some old machine can't init with D3D11 //so ... we use D3D9 instead if (!success) { egl_display = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[] { Egl.PLATFORM_ANGLE_TYPE_ANGLE, Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE, Egl.NONE, }); if (Egl.Initialize(egl_display, out eglMajor, out eglMinor)) { useD3D9Only = true; success = true; //in this case major = 2; //GLES2 minor = 1; flags = flags & ~GraphicsContextFlags.AngleD3D11; //can't use D3D11 } else { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } } } else { //not first time if (useD3D9Only) { //no D3D11 egl_display = Egl.GetPlatformDisplayEXT(Egl.PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new int[] { Egl.PLATFORM_ANGLE_TYPE_ANGLE, Egl.PLATFORM_ANGLE_TYPE_D3D9_ANGLE, Egl.NONE, }); if (Egl.Initialize(egl_display, out eglMajor, out eglMinor)) { useD3D9Only = true; success = true; //in this case major = 2; //GLES2 minor = 1; flags = flags & ~GraphicsContextFlags.AngleD3D11; //can't use D3D11 } else { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } } else { //use D3D11 egl_display = GetDisplay(win_win.DeviceContext); success = Egl.Initialize(egl_display, out eglMajor, out eglMinor); //------------------- //we found that some old machine can't init with D3D11 //so ... we use D3D9 instead if (!success) { //??? throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } } } return(egl_display); }
bool vsync = true; // Default vsync value is defined as 1 (true) in EGL. public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) { if (mode == null) { throw new ArgumentNullException("mode"); } if (window == null) { throw new ArgumentNullException("window"); } //EglContext shared = (EglContext)sharedContext; //old version EglContext shared = sharedContext as EglContext; int dummy_major, dummy_minor; if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor)) { throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError())); } WindowInfo = window; Egl.BindAPI(0x30A0); //bind EGL_OPENGL_ES_API var eglGfxMode = new EglGraphicsMode(); eglGfxMode.window = window; Mode = eglGfxMode.SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo); if (!Mode.Index.HasValue) { throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); } IntPtr config = Mode.Index.Value; if (window.Surface == IntPtr.Zero) { window.CreateWindowSurface(config); } int[] attrib_list = new int[] { //key,value Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE }; HandleAsEGLContext = Egl.CreateContext(window.Display, config, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list); MakeCurrent(window); }
public override void SwapBuffers() { Egl.SwapBuffers(WindowInfo.Display, WindowInfo.Surface); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderable_flags) { IntPtr[] configs = new IntPtr[1]; int[] attrib_list = new int[17] { 12352, (int)renderable_flags, 12324, color.Red, 12323, color.Green, 12322, color.Blue, 12321, color.Alpha, 12325, depth > 0 ? depth : 0, 12326, stencil > 0 ? stencil : 0, 12337, samples > 0 ? samples : 0, 12344 }; IntPtr display = Egl.GetDisplay(IntPtr.Zero); int major; int minor; if (!Egl.Initialize(display, out major, out minor)) { throw new GraphicsModeException(string.Format("Failed to initialize display connection, error {0}", (object)Egl.GetError())); } int num_config; if (!Egl.ChooseConfig(display, attrib_list, configs, configs.Length, out num_config) || num_config == 0) { throw new GraphicsModeException(string.Format("Failed to retrieve GraphicsMode, error {0}", (object)Egl.GetError())); } IntPtr config = configs[0]; int red; Egl.GetConfigAttrib(display, config, 12324, out red); int green; Egl.GetConfigAttrib(display, config, 12323, out green); int blue; Egl.GetConfigAttrib(display, config, 12322, out blue); int alpha; Egl.GetConfigAttrib(display, config, 12321, out alpha); int depth1; Egl.GetConfigAttrib(display, config, 12325, out depth1); int stencil1; Egl.GetConfigAttrib(display, config, 12326, out stencil1); int num; Egl.GetConfigAttrib(display, config, 12337, out num); Egl.GetConfigAttrib(display, config, 12337, out samples); return(new GraphicsMode(new IntPtr?(config), new ColorFormat(red, green, blue, alpha), depth1, stencil1, num > 0 ? samples : 0, (ColorFormat)0, 2, false)); }
public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr bufferSurface) { int[] attribs = new int[] { Egl.WIDTH, width, Egl.HEIGHT, height, Egl.TEXTURE_TARGET, Egl.TEXTURE_2D, Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA, Egl.NONE }; bufferSurface = Egl.CreatePbufferSurface(Display, config, attribs); if (bufferSurface == IntPtr.Zero) { throw new GraphicsContextException(String.Format( "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError())); } }
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() { return(delegate { return new ContextHandle(Egl.GetCurrentContext()); }); }
public void CreateWindowSurface(IntPtr config) { Surface = Egl.CreateWindowSurface(Display, config, Handle, IntPtr.Zero); if (Surface == IntPtr.Zero) { throw new GraphicsContextException(String.Format( "[EGL] Failed to create window surface, error {0}.", Egl.GetError())); } }
public GraphicsMode SelectGraphicsMode(SurfaceType surfaceType, IntPtr display, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderableFlags) { var configs = new IntPtr[1]; var attribList = new[] { Egl.SURFACE_TYPE, (int)surfaceType, Egl.RENDERABLE_TYPE, (int)renderableFlags, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, Egl.NONE }; int numConfigs; if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out numConfigs) || numConfigs == 0) { throw new GraphicsModeException($"Failed to retrieve GraphicsMode, error {Egl.GetError()}"); } // See what we really got var activeConfig = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, activeConfig, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, activeConfig, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, activeConfig, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, activeConfig, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, activeConfig, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, activeConfig, Egl.STENCIL_SIZE, out s); int sampleBuffers; Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out sampleBuffers); Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out samples); return(new GraphicsMode(activeConfig, new ColorFormat(r, g, b, a), d, s, sampleBuffers > 0 ? samples : 0, 0, 2, false)); }
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { //Egl.SURFACE_TYPE, Egl.WINDOW_BIT, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, //Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, //------------ Egl.NONE, }; // Todo: what if we don't wish to use the default display? IntPtr display = Egl.GetDisplay(IntPtr.Zero); int major, minor; if (!Egl.Initialize(display, out major, out minor)) { throw new GraphicsModeException(String.Format("Failed to initialize display connection, error {0}", Egl.GetError())); } int num_configs; if (!Egl.GetConfigs(display, null, 0, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode configurations, error {0}", Egl.GetError())); } if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } // See what we really got IntPtr active_config = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); int sample_buffers; Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); return(new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false)); }
public override void SwapBuffers() { if (!Egl.SwapBuffers(WindowInfo.Display, WindowInfo.Surface)) { throw new GraphicsContextException(string.Format("Failed to swap buffers for context {0} current. Error: {1}", Handle, Egl.GetError())); } }
public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list) { IntPtr ptr = eglCreateContext(dpy, config, share_context, attrib_list); if (ptr == IntPtr.Zero) { throw new GraphicsContextException(String.Format("Failed to create EGL context, error: {0}.", Egl.GetError())); } return(ptr); }
public GraphicsMode SelectGraphicsMode(SurfaceType surface_type, IntPtr display, ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo, RenderableFlags renderable_flags, bool fullscreen) { IntPtr[] configs = new IntPtr[1]; int[] attribList = new int[] { Egl.SURFACE_TYPE, (int)surface_type, Egl.RENDERABLE_TYPE, (int)renderable_flags, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green, Egl.BLUE_SIZE, color.Blue, Egl.ALPHA_SIZE, color.Alpha, Egl.DEPTH_SIZE, depth > 0 ? depth : 0, Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0, Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, Egl.SAMPLES, samples > 0 ? samples : 0, Egl.FULLSCREEN_ANGLE, fullscreen ? Egl.TRUE : Egl.FALSE, Egl.NONE, }; int num_configs; if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out num_configs)) { throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError())); } if (num_configs == 0) { if (depth > 0) { return(SelectGraphicsMode(surface_type, display, color, 0, stencil, samples, accum, buffers, stereo, renderable_flags, fullscreen)); } throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, no fitting configurations, error {0}", Egl.GetError())); } // See what we really got IntPtr active_config = configs[0]; int r, g, b, a; Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r); Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g); Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b); Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a); int d, s; Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d); Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s); int sample_buffers; Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers); Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples); return(new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false)); }