AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/Emu/UguiVideoProvider.cs

143 lines
3.3 KiB
C#
Raw Normal View History

2024-07-04 21:06:41 +08:00
using MyNes.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
2024-07-04 21:06:41 +08:00
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
2024-07-04 21:06:41 +08:00
namespace AxibugEmuOnline.Client
{
public class UguiVideoProvider : MonoBehaviour, IVideoProvider
2024-07-04 21:06:41 +08:00
{
2024-07-17 12:50:18 +08:00
2024-07-04 21:06:41 +08:00
public string Name => "Unity UI Video";
public string ID => nameof(UguiVideoProvider).GetHashCode().ToString();
2024-07-17 12:50:18 +08:00
[SerializeField]
private NesCoreProxy m_coreProxy;
2024-07-16 16:30:20 +08:00
[SerializeField]
private RawImage m_drawCanvas;
[SerializeField]
private Text m_fpsText;
2024-07-19 15:17:26 +08:00
[SerializeField]
private Text m_nofity;
2024-07-16 16:30:20 +08:00
2024-07-05 11:48:35 +08:00
private Color[] m_texRawBuffer = new Color[256 * 240];
private Texture2D m_rawBufferWarper;
2024-07-04 21:06:41 +08:00
private RenderTexture m_drawRT;
2024-07-05 11:48:35 +08:00
private Color temp = Color.white;
2024-07-04 21:06:41 +08:00
2024-07-19 15:17:26 +08:00
private bool toggleOn;
2024-07-16 16:30:20 +08:00
2024-07-04 21:06:41 +08:00
public void Initialize()
{
m_rawBufferWarper = new Texture2D(256, 240);
2024-07-17 12:50:18 +08:00
}
2024-07-04 21:06:41 +08:00
2024-07-05 11:48:35 +08:00
public void GetColor(uint value, ref Color res)
2024-07-04 21:06:41 +08:00
{
var r = 0xFF0000 & value;
r >>= 16;
var b = 0xFF & value;
var g = 0xFF00 & value;
g >>= 8;
2024-07-05 11:48:35 +08:00
res.r = r / 255f;
res.g = g / 255f;
res.b = b / 255f;
2024-07-04 21:06:41 +08:00
}
2024-07-17 12:50:18 +08:00
public void Update()
2024-07-04 21:06:41 +08:00
{
2024-07-19 15:17:26 +08:00
if (toggleOn)
{
if (!m_drawCanvas.enabled) m_drawCanvas.enabled = true;
var colors = m_texRawBuffer;
m_rawBufferWarper.SetPixels(colors);
m_rawBufferWarper.Apply();
Graphics.Blit(m_rawBufferWarper, m_drawCanvas.texture as RenderTexture);
2024-07-16 16:30:20 +08:00
2024-07-19 15:17:26 +08:00
m_fpsText.text = $"fps:{m_coreProxy.AudioCom.FPS:00.00}";
}
else
{
if (m_drawCanvas.enabled) m_drawCanvas.enabled = false;
}
2024-07-04 21:06:41 +08:00
}
public void WriteErrorNotification(string message, bool instant)
{
2024-07-19 15:17:26 +08:00
m_nofity.text = message;
2024-07-04 21:06:41 +08:00
}
public void WriteInfoNotification(string message, bool instant)
{
2024-07-19 15:17:26 +08:00
m_nofity.text = message;
2024-07-04 21:06:41 +08:00
}
public void WriteWarningNotification(string message, bool instant)
{
2024-07-19 15:17:26 +08:00
m_nofity.text = message;
2024-07-04 21:06:41 +08:00
}
public void TakeSnapshotAs(string path, string format)
{
}
public void TakeSnapshot()
{
}
public void ShutDown()
{
}
public void SignalToggle(bool started)
{
2024-07-19 15:17:26 +08:00
toggleOn = started;
2024-07-04 21:06:41 +08:00
}
public void SubmitFrame(ref int[] buffer)
{
2024-07-05 11:48:35 +08:00
for (int i = 0; i < buffer.Length; i++)
{
GetColor((uint)buffer[i], ref temp);
m_texRawBuffer[i] = temp;
}
2024-07-04 21:06:41 +08:00
}
public void ResizeBegin()
{
}
public void ResizeEnd()
{
}
public void ApplyRegionChanges()
{
}
public void Resume()
{
}
public void ToggleAspectRatio(bool keep_aspect)
{
}
public void ToggleFPS(bool show_fps)
{
}
public void ApplyFilter()
{
}
}
}