2015-03-06 03:05:46 +00:00
using System ;
2014-06-08 23:30:34 +00:00
using BizHawk.Bizware.BizwareGL ;
2014-07-03 15:30:24 +00:00
2014-06-08 23:30:34 +00:00
namespace BizHawk.Client.Common
{
/// <summary>
2015-03-06 03:05:46 +00:00
/// This singleton class manages OpenGL contexts, in an effort to minimize context changes.
2014-06-08 23:30:34 +00:00
/// </summary>
public class GLManager
{
2015-03-06 03:05:46 +00:00
private GLManager ( )
2014-06-08 23:30:34 +00:00
{
2014-07-03 15:30:24 +00:00
2014-06-08 23:30:34 +00:00
}
2015-03-06 03:05:46 +00:00
public static GLManager Instance { get ; private set ; }
public static void CreateInstance ( )
{
if ( Instance ! = null ) throw new InvalidOperationException ( "Attempt to create more than one GLManager" ) ;
Instance = new GLManager ( ) ;
}
2014-06-08 23:30:34 +00:00
public ContextRef CreateGLContext ( )
{
2014-07-03 18:17:09 +00:00
var ret = new ContextRef
2014-06-08 23:30:34 +00:00
{
2014-07-03 18:17:09 +00:00
gl = new Bizware . BizwareGL . Drivers . OpenTK . IGL_TK ( )
2014-06-08 23:30:34 +00:00
} ;
return ret ;
}
public ContextRef GetContextForGraphicsControl ( GraphicsControl gc )
{
2014-07-03 18:17:09 +00:00
return new ContextRef
2014-06-08 23:30:34 +00:00
{
gc = gc
} ;
}
/// <summary>
/// This might not be a GL implementation. If it isnt GL, then setting it as active context is just NOP
/// </summary>
public ContextRef GetContextForIGL ( IGL gl )
{
2014-07-03 18:17:09 +00:00
return new ContextRef
2014-06-08 23:30:34 +00:00
{
gl = gl
} ;
}
ContextRef ActiveContext ;
public void Invalidate ( )
{
ActiveContext = null ;
}
public void Activate ( ContextRef cr )
{
if ( cr = = ActiveContext )
return ;
ActiveContext = cr ;
if ( cr . gc ! = null )
{
//TODO - this is checking the current context inside to avoid an extra NOP context change. make this optional or remove it, since we're tracking it here
2015-03-06 03:05:46 +00:00
cr . gc . Begin ( ) ;
2014-06-08 23:30:34 +00:00
}
if ( cr . gl ! = null )
{
if ( cr . gl is BizHawk . Bizware . BizwareGL . Drivers . OpenTK . IGL_TK )
( ( BizHawk . Bizware . BizwareGL . Drivers . OpenTK . IGL_TK ) cr . gl ) . MakeDefaultCurrent ( ) ;
}
}
public void Deactivate ( )
{
//this is here for future use and tracking purposes.. however.. instead of relying on this, we should just make sure we always activate what we need before we use it
}
public class ContextRef
{
public IGL gl ;
public GraphicsControl gc ;
}
}
}