2014-01-15 11:24:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-01-24 17:46:35 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi;
|
2014-01-15 11:24:47 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Emulation.Cores.Nintendo.N64
|
|
|
|
|
{
|
2014-05-13 00:31:32 +00:00
|
|
|
|
internal class N64VideoProvider : IVideoProvider, IDisposable
|
2014-01-15 11:24:47 +00:00
|
|
|
|
{
|
|
|
|
|
private int[] frameBuffer;
|
2014-01-24 17:46:35 +00:00
|
|
|
|
private mupen64plusVideoApi api;
|
2014-01-15 11:24:47 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates N64 Video system with mupen64plus backend
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="api">mupen64plus DLL that is used</param>
|
2014-01-24 17:46:35 +00:00
|
|
|
|
public N64VideoProvider(mupen64plusApi core, VideoPluginSettings videosettings)
|
2014-01-15 11:24:47 +00:00
|
|
|
|
{
|
2014-01-24 17:46:35 +00:00
|
|
|
|
this.api = new mupen64plusVideoApi(core, videosettings);
|
2014-01-15 11:24:47 +00:00
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
|
|
|
|
api.GetScreenDimensions(ref width, ref height);
|
2014-05-12 23:54:27 +00:00
|
|
|
|
|
|
|
|
|
SetBufferSize(
|
|
|
|
|
width > videosettings.Width ? width : videosettings.Width,
|
|
|
|
|
height > videosettings.Height ? height : videosettings.Height
|
|
|
|
|
);
|
2014-01-24 17:46:35 +00:00
|
|
|
|
|
2014-06-10 22:21:40 +00:00
|
|
|
|
core.BeforeRender += DoVideoFrame;
|
2014-01-15 11:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] GetVideoBuffer()
|
|
|
|
|
{
|
|
|
|
|
return frameBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int VirtualWidth { get { return BufferWidth; } }
|
2014-04-30 23:48:37 +00:00
|
|
|
|
public int VirtualHeight { get { return BufferHeight; } }
|
2014-01-15 11:24:47 +00:00
|
|
|
|
public int BufferWidth { get; private set; }
|
|
|
|
|
public int BufferHeight { get; private set; }
|
|
|
|
|
public int BackgroundColor { get { return 0; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches current frame buffer from mupen64
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DoVideoFrame()
|
|
|
|
|
{
|
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
|
|
|
|
api.GetScreenDimensions(ref width, ref height);
|
|
|
|
|
if (width != BufferWidth || height != BufferHeight)
|
|
|
|
|
{
|
|
|
|
|
SetBufferSize(width, height);
|
|
|
|
|
}
|
2014-05-13 00:31:32 +00:00
|
|
|
|
|
2014-01-15 11:24:47 +00:00
|
|
|
|
api.Getm64pFrameBuffer(frameBuffer, ref width, ref height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a new width and height for frame buffer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">New width in pixels</param>
|
|
|
|
|
/// <param name="height">New height in pixels</param>
|
|
|
|
|
private void SetBufferSize(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
BufferHeight = height;
|
|
|
|
|
BufferWidth = width;
|
|
|
|
|
frameBuffer = new int[width * height];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
api = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|