diff --git a/Source/OpenTK/Platform/Egl/Egl.cs b/Source/OpenTK/Platform/Egl/Egl.cs index 84bf38469..65307df7f 100644 --- a/Source/OpenTK/Platform/Egl/Egl.cs +++ b/Source/OpenTK/Platform/Egl/Egl.cs @@ -2,7 +2,7 @@ // // The Open Toolkit Library License // -// Copyright (c) 2006 - 2009 the Open Toolkit library. +// Copyright (c) 2006 - 2011 the Open Toolkit library. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -41,6 +41,15 @@ namespace OpenTK.Platform.Egl using EGLSurface = IntPtr; using EGLClientBuffer = IntPtr; + [Flags] + enum RenderableFlags + { + ES = Egl.OPENGL_ES_BIT, + ES2 = Egl.OPENGL_ES2_BIT, + GL = Egl.OPENGL_BIT, + VG = Egl.OPENVG_BIT, + } + static partial class Egl { public const int VERSION_1_0 = 1; diff --git a/Source/OpenTK/Platform/Egl/EglContext.cs b/Source/OpenTK/Platform/Egl/EglContext.cs index 2c183cbb9..208bd208c 100644 --- a/Source/OpenTK/Platform/Egl/EglContext.cs +++ b/Source/OpenTK/Platform/Egl/EglContext.cs @@ -61,7 +61,13 @@ class EglContext : EmbeddedGraphicsContext WindowInfo = window; - Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo); + // 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. + 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 (!Mode.Index.HasValue) throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); IntPtr config = Mode.Index.Value; diff --git a/Source/OpenTK/Platform/Egl/EglGraphicsMode.cs b/Source/OpenTK/Platform/Egl/EglGraphicsMode.cs index 3bd296039..b6f0a35e7 100644 --- a/Source/OpenTK/Platform/Egl/EglGraphicsMode.cs +++ b/Source/OpenTK/Platform/Egl/EglGraphicsMode.cs @@ -36,20 +36,28 @@ class EglGraphicsMode : IGraphicsMode { #region IGraphicsMode Members - public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo) + public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, + int samples, ColorFormat accum, int buffers, bool stereo) + { + // According to the EGL specs, the ES flag should select ES 1.0 or higher, which + // makes sense as a default. EglContext.cs checks + return SelectGraphicsMode(color, depth, stencil, samples, accum, buffers, stereo, + RenderableFlags.ES); + } + + #endregion + + #region Public Members + + 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[] attribList = new int[] { //Egl.SURFACE_TYPE, Egl.WINDOW_BIT, - - // Context creation will fail unless one of these bits is set. Hopefully, setting all bits will not - // cause any ugly side-effects. - // If this doesn't work, we'll have to use Egl.GetConfigs and implement our own selection logic, - // because we the exact ES version is not known when selecting a graphics context. - // (See WinGraphicsMode.cs for an selection logic implementation). - // Todo: add Egl.OPENVG_BIT here if we ever add OpenVG bindings. - Egl.RENDERABLE_TYPE, Egl.OPENGL_ES_BIT | Egl.OPENGL_ES2_BIT | Egl.OPENGL_BIT, + Egl.RENDERABLE_TYPE, (int)renderable_flags, Egl.RED_SIZE, color.Red, Egl.GREEN_SIZE, color.Green,