//static List<WeakReference<FBORenderContext>> renderContextList = new List<WeakReference<FBORenderContext>>();
//public FBORenderContext()
//{
// renderContextList.Add(new WeakReference<FBORenderContext>(this));
//}
//public override void Destroy()
//{
// bool found = false;
// WeakReference<FBORenderContext> target = null;
// for (int index = 0; index < renderContextList.Count; index++)
// {
// target = renderContextList[index];
// FBORenderContext context;
// if (target.TryGetTarget(out context))
// {
// if (context == this)
// { break; }
// }
// }
// if (found)
// {
// renderContextList.Remove(target);
// }
// base.Destroy();
//}
//public static FBORenderContext GetCurrentRenderContext()
//{
// IntPtr renderContext = Win32.wglGetCurrentContext();
//}
/// <summary>
/// Creates the render context provider. Must also create the OpenGL extensions.
/// </summary>
/// <param name="openGLVersion">The desired OpenGL version.</param>
/// <param name="gl">The OpenGL context.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitDepth">The bit depth.</param>
/// <param name="parameter">The parameter</param>
/// <returns></returns>
public override bool Create(GLVersion openGLVersion, int width, int height, int bitDepth, object parameter)
{
// Call the base class.
base.Create(openGLVersion, width, height, bitDepth, parameter);
uint[] ids = new uint[1];
// First, create the frame buffer and bind it.
ids = new uint[1];
OpenGL.GetDelegateFor <OpenGL.glGenFramebuffersEXT>()(1, ids);
frameBufferId = ids[0];
OpenGL.GetDelegateFor <OpenGL.glBindFramebufferEXT>()(OpenGL.GL_FRAMEBUFFER_EXT, frameBufferId);
// Create the colour render buffer and bind it, then allocate storage for it.
OpenGL.GetDelegateFor <OpenGL.glGenRenderbuffersEXT>()(1, ids);
colourRenderBufferId = ids[0];
OpenGL.GetDelegateFor <OpenGL.glBindRenderbufferEXT>()(OpenGL.GL_RENDERBUFFER_EXT, colourRenderBufferId);
OpenGL.GetDelegateFor <OpenGL.glRenderbufferStorageEXT>()(OpenGL.GL_RENDERBUFFER_EXT, OpenGL.GL_RGBA, width, height);
// Create the depth render buffer and bind it, then allocate storage for it.
OpenGL.GetDelegateFor <OpenGL.glGenRenderbuffersEXT>()(1, ids);
depthRenderBufferId = ids[0];
OpenGL.GetDelegateFor <OpenGL.glBindRenderbufferEXT>()(OpenGL.GL_RENDERBUFFER_EXT, depthRenderBufferId);
OpenGL.GetDelegateFor <OpenGL.glRenderbufferStorageEXT>()(OpenGL.GL_RENDERBUFFER_EXT, OpenGL.GL_DEPTH_COMPONENT24, width, height);
// Set the render buffer for colour and depth.
OpenGL.GetDelegateFor <OpenGL.glFramebufferRenderbufferEXT>()(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_COLOR_ATTACHMENT0_EXT,
OpenGL.GL_RENDERBUFFER_EXT, colourRenderBufferId);
OpenGL.GetDelegateFor <OpenGL.glFramebufferRenderbufferEXT>()(OpenGL.GL_FRAMEBUFFER_EXT, OpenGL.GL_DEPTH_ATTACHMENT_EXT,
OpenGL.GL_RENDERBUFFER_EXT, depthRenderBufferId);
dibSectionDeviceContext = Win32.CreateCompatibleDC(DeviceContextHandle);
// Create the DIB section.
dibSection.Create(dibSectionDeviceContext, width, height, bitDepth);
return(true);
}