some small cleanup

This commit is contained in:
zeromus 2014-01-27 05:37:04 +00:00
parent 7417ea7b8f
commit 857dff9cf4
6 changed files with 49 additions and 112 deletions

View File

@ -1,8 +1,7 @@
using SlimDX.Direct3D9;
using BizHawk.Client.Common;
using BizHawk.Bizware.BizwareGL;
using SlimDX.DirectSound;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public static class GlobalWin
@ -11,8 +10,8 @@ namespace BizHawk.Client.EmuHawk
public static ToolManager Tools;
#if WINDOWS
public static DirectSound DSound;
public static Direct3D Direct3D;
#endif
public static IGL GL;
public static Sound Sound;
public static IRenderer RenderPanel;
public static OSDManager OSD = new OSDManager();

View File

@ -1341,69 +1341,6 @@ namespace BizHawk.Client.EmuHawk
}
}
// private void SyncPresentationMode()
// {
// GlobalWin.DisplayManager.Suspend();
//#if WINDOWS
// bool gdi = Global.Config.DisplayGDI || GlobalWin.Direct3D == null;
//#endif
// if (_renderTarget != null)
// {
// _renderTarget.Dispose();
// Controls.Remove(_renderTarget);
// }
// if (_retainedPanel != null)
// {
// _retainedPanel.Dispose();
// }
// if (GlobalWin.RenderPanel != null)
// {
// GlobalWin.RenderPanel.Dispose();
// }
//#if WINDOWS
// if (gdi)
//#endif
// _renderTarget = _retainedPanel = new RetainedViewportPanel();
//#if WINDOWS
// else _renderTarget = new ViewportPanel();
//#endif
// Controls.Add(_renderTarget);
// Controls.SetChildIndex(_renderTarget, 0);
// _renderTarget.Dock = DockStyle.Fill;
// _renderTarget.BackColor = Color.Black;
//#if WINDOWS
// if (gdi)
// {
//#endif
// GlobalWin.RenderPanel = new SysdrawingRenderPanel(_retainedPanel);
// _retainedPanel.ActivateThreaded();
//#if WINDOWS
// }
// else
// {
// try
// {
// var d3dPanel = new BizwareGLRenderPanel(_renderTarget);
// GlobalWin.RenderPanel = d3dPanel;
// }
// catch
// {
// Program.DisplayDirect3DError();
// GlobalWin.Direct3D.Dispose();
// GlobalWin.Direct3D = null;
// SyncPresentationMode();
// }
// }
//#endif
// GlobalWin.DisplayManager.Resume();
// }
private void SyncThrottle()
{

View File

@ -5,7 +5,6 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
#if WINDOWS
using SlimDX.Direct3D9;
using SlimDX.DirectSound;
using Microsoft.VisualBasic.ApplicationServices;
#endif
@ -76,16 +75,12 @@ namespace BizHawk.Client.EmuHawk
{
MessageBox.Show("Couldn't initialize DirectSound! Things may go poorly for you. Try changing your sound driver to 41khz instead of 48khz in mmsys.cpl.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try { GlobalWin.Direct3D = new Direct3D(); }
catch
{
//fallback to GDI rendering
if (!Global.Config.DisplayGDI)
DisplayDirect3DError();
}
#endif
//create IGL context.
//at some point in the future, we may need to select from several drivers
GlobalWin.GL = new BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK();
try
{
#if WINDOWS
@ -152,8 +147,7 @@ namespace BizHawk.Client.EmuHawk
{
if (GlobalWin.DSound != null && GlobalWin.DSound.Disposed == false)
GlobalWin.DSound.Dispose();
if (GlobalWin.Direct3D != null && GlobalWin.Direct3D.Disposed == false)
GlobalWin.Direct3D.Dispose();
GlobalWin.GL.Dispose();
GamePad.CloseAll();
}
#endif
@ -250,10 +244,7 @@ namespace BizHawk.Client.EmuHawk
}
}
public static void DisplayDirect3DError()
{
MessageBox.Show("Failure to initialize Direct3D, reverting to GDI+ display method. Change the option in Config > GUI or install DirectX web update.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endif
}
}

View File

@ -8,8 +8,6 @@ using System.Threading;
using System.Windows.Forms;
#if WINDOWS
using SlimDX;
using SlimDX.Direct3D9;
using d3d9font=SlimDX.Direct3D9.Font;
#endif
using BizHawk.Client.Common;
@ -17,7 +15,6 @@ using BizHawk.Bizware.BizwareGL;
namespace BizHawk.Client.EmuHawk
{
public interface IRenderer : IDisposable
{
void RenderOverlay(DisplaySurface surface);
@ -38,6 +35,24 @@ namespace BizHawk.Client.EmuHawk
//you might think it's cool to make this reusable for other windows, but it's probably a pipe dream. dont even try it. at least, refactor it into a simple render panel and some kind of NicePresentationWindow class
public class BizwareGLRenderPanel : IRenderer, IBlitter
{
public BizwareGLRenderPanel()
{
GL = GlobalWin.GL;
GraphicsControl = GL.CreateGraphicsControl();
Renderer = new GuiRenderer(GL);
//pass through these events to the form. we might need a more scalable solution for mousedown etc. for zapper and whatnot.
//http://stackoverflow.com/questions/547172/pass-through-mouse-events-to-parent-control (HTTRANSPARENT)
GraphicsControl.Control.MouseDoubleClick += (o, e) => HandleFullscreenToggle(o, e);
GraphicsControl.Control.MouseClick += (o, e) => GlobalWin.MainForm.MainForm_MouseClick(o, e);
using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png"))
TheOneFont = new StringRenderer(GL, xml, tex);
}
public void Dispose()
{
//this hasnt been analyzed real well yet
@ -66,27 +81,10 @@ namespace BizHawk.Client.EmuHawk
}
public BizwareGLRenderPanel()
{
if(gl == null)
gl = new BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK();
GraphicsControl = gl.CreateGraphicsControl();
Renderer = new GuiRenderer(gl);
//pass through these events to the form. we might need a more scalable solution for mousedown etc. for zapper and whatnot.
//http://stackoverflow.com/questions/547172/pass-through-mouse-events-to-parent-control (HTTRANSPARENT)
GraphicsControl.Control.MouseDoubleClick += (o, e) => HandleFullscreenToggle(o, e);
GraphicsControl.Control.MouseClick += (o, e) => GlobalWin.MainForm.MainForm_MouseClick(o, e);
using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png"))
TheOneFont = new StringRenderer(gl,xml,tex);
}
void IBlitter.Open()
{
Renderer.Begin(GraphicsControl.Control.ClientSize.Width, GraphicsControl.Control.ClientSize.Height);
Renderer.SetBlendState(gl.BlendNormal);
Renderer.SetBlendState(GL.BlendNormal);
ClipBounds = new sd.Rectangle(0, 0, NativeSize.Width, NativeSize.Height);
}
void IBlitter.Close() {
@ -109,7 +107,7 @@ namespace BizHawk.Client.EmuHawk
StringRenderer TheOneFont;
public Bizware.BizwareGL.GraphicsControl GraphicsControl;
static Bizware.BizwareGL.IGL gl;
static Bizware.BizwareGL.IGL GL;
GuiRenderer Renderer;
Texture2d LastSurfaceTexture;
@ -170,12 +168,12 @@ namespace BizHawk.Client.EmuHawk
if (sw != surface.Width || sh != surface.Height || LastSurfaceTexture == null)
{
LastSurfaceTexture = gl.LoadTexture(surface);
LastSurfaceTexture = GL.LoadTexture(surface);
LastSurfaceTexture.SetFilterNearest();
}
else
{
gl.LoadTextureData(LastSurfaceTexture, surface);
GL.LoadTextureData(LastSurfaceTexture, surface);
}
sw = surface.Width;
@ -195,14 +193,14 @@ namespace BizHawk.Client.EmuHawk
GraphicsControl.Begin();
if (!overlay)
{
gl.ClearColor(Color.Black); //TODO set from background color
gl.Clear(ClearBufferMask.ColorBufferBit);
GL.ClearColor(Color.Black); //TODO set from background color
GL.Clear(ClearBufferMask.ColorBufferBit);
}
Renderer.Begin(GraphicsControl.Control.ClientSize.Width, GraphicsControl.Control.ClientSize.Height);
if (overlay)
Renderer.SetBlendState(gl.BlendNormal);
else Renderer.SetBlendState(gl.BlendNone);
Renderer.SetBlendState(GL.BlendNormal);
else Renderer.SetBlendState(GL.BlendNone);
Renderer.Modelview.Translate(dx, dy);
Renderer.Modelview.Scale(finalScale);
Renderer.Draw(LastSurfaceTexture);

View File

@ -44,14 +44,26 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
public IGL_TK()
{
//make an 'offscreen context' so we can at least do things without having to create a window
OffscreenNativeWindow = new NativeWindow();
OffscreenNativeWindow.ClientSize = new sd.Size(8, 8);
this.GraphicsContext = new GraphicsContext(GraphicsMode.Default, OffscreenNativeWindow.WindowInfo, 2, 0, GraphicsContextFlags.Default);
MakeDefaultCurrent();
this.GraphicsContext.LoadAll(); //this is important for reasons unknown
//this is important for reasons unknown
this.GraphicsContext.LoadAll();
//misc initialization
CreateRenderStates();
}
void IDisposable.Dispose()
{
//TODO - a lot of analysis here
OffscreenNativeWindow.Dispose(); OffscreenNativeWindow = null;
GraphicsContext.Dispose(); GraphicsContext = null;
}
void IGL.Clear(ClearBufferMask mask)
{
GL.Clear((global::OpenTK.Graphics.OpenGL.ClearBufferMask)mask);

View File

@ -14,7 +14,7 @@ namespace BizHawk.Bizware.BizwareGL
/// TODO - This really needs to be split up into an internal and a user interface. so many of the functions are made to support the smart wrappers
/// Maybe make a method that returns an interface used for advanced methods (and IGL_TK could implement that as well and just "return this:")
/// </summary>
public interface IGL
public interface IGL : IDisposable
{
/// <summary>
/// Returns an a control optimized for drawing onto the screen.