Oops, my attachments were rejected, so I am pasting them here. Here is the Android Specific logic to create the EGL context:
using System;
using System.Drawing;
using gpx = OpenTK.Graphics;
using jgl = Javax.Microedition.Khronos.Egl;
using jgl10 = Javax.Microedition.Khronos.Egl.EGL10;
using Java.Interop;
namespace iFly.Vision3D
{
public static partial class OGL
{
private class _Control
{
private OGL.Control _owner;
private jgl.IEGL10 _EGL;
private jgl.EGLDisplay _display;
private jgl.EGLConfig[] _configList;
private jgl.EGLConfig _config;
private jgl.EGLContext _context;
private jgl.EGLSurface _surface;
private System.Threading.Thread _threadOwner;
private bool _isConfigured;
private Size _size = new Size(200, 120);
public _Control(OGL.Control ctrl)
{
_owner = ctrl;
}
public Size Size
{
get { return _size; }
set { _size = value; Configure(_size); }
}
public void MakeCurrent(bool forced)
{
if (!_isConfigured)
return; // too soon
_EGL.EglMakeCurrent(_display, _surface, _surface, _context);
}
public void Configure(Size size)
{
_size = size;
Initialize(null, size);
}
public bool Initialize(iGraphicsMode graphicsMode, Size size)
{
_size = size;
if (_config == null && graphicsMode != null)
{
int[] version = new int[2];
_EGL = jgl.EGLContext.EGL.JavaCast<jgl.IEGL10>();
_display = _EGL.EglGetDisplay(jgl10.EglDefaultDisplay);
_EGL.EglInitialize(_display, version);
const int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
int[] ctxAttr = new int[] { EGL_CONTEXT_CLIENT_VERSION, 2, jgl10.EglNone }; // also try: jgl10.EglVersion
_config = _ChooseConfig(graphicsMode); // Choosing a config is a little more complicated
_context = _EGL.EglCreateContext(_display, _config, jgl10.EglNoContext, ctxAttr);
}
int[] sfcAttr = new int[] { jgl10.EglWidth, _size.Width, jgl10.EglHeight, _size.Height, jgl10.EglNone };
_surface = _EGL.EglCreatePbufferSurface(_display, _config, sfcAttr);
_isConfigured = true;
MakeCurrent(true);
Log.Info(“OGL.Control.Initialize() - complete: {0}, {1}, {2}, {3}”, _size, _config, _surface, _display);
return true;
}
private jgl.EGLConfig _ChooseConfig(iGraphicsMode graphicsMode)
{
const int EGL_OPENGL_ES2_BIT = 4;
const int EGL_PBUFFER_BIT = 1;
int[] attribList = new int[] {
jgl10.EglRenderableType, EGL_OPENGL_ES2_BIT,
jgl10.EglSurfaceType, EGL_PBUFFER_BIT,
jgl10.EglDepthSize, graphicsMode.Depth,
jgl10.EglStencilSize, graphicsMode.Stencil,
jgl10.EglRedSize, graphicsMode.ColorFormat.Red,
jgl10.EglGreenSize, graphicsMode.ColorFormat.Green,
jgl10.EglBlueSize, graphicsMode.ColorFormat.Blue,
jgl10.EglAlphaSize, graphicsMode.ColorFormat.Alpha,
jgl10.EglSamples, graphicsMode.Samples,
jgl10.EglNone
};
// No error checking performed, minimum required code to elucidate logic
// Expand on this logic to be more selective in choosing a configuration
int[] numConfig = new int[1];
_EGL.EglChooseConfig(_display, attribList, null, 0, numConfig);
int configSize = numConfig[0];
_configList = new jgl.EGLConfig[configSize];
_EGL.EglChooseConfig(_display, attribList, _configList, configSize, numConfig);
return _configList[0]; // _configList.Length - 1]; // Best match is often the first one.
}
}
}
}