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

128 lines
2.9 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
{
public string Name => "Unity UI Video";
public string ID => nameof(UguiVideoProvider).GetHashCode().ToString();
2024-07-16 16:30:20 +08:00
[SerializeField]
private RawImage m_drawCanvas;
[SerializeField]
private Text m_fpsText;
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-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-16 16:30:20 +08:00
m_drawCanvas.texture = RenderTexture.GetTemporary(256, 240, 0, UnityEngine.Experimental.Rendering.GraphicsFormat.B8G8R8A8_UNorm);
}
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-05 11:24:59 +08:00
public void Update()
2024-07-04 21:06:41 +08:00
{
2024-07-05 11:48:35 +08:00
var colors = m_texRawBuffer;
2024-07-04 21:06:41 +08:00
m_rawBufferWarper.SetPixels(colors);
m_rawBufferWarper.Apply();
2024-07-16 16:30:20 +08:00
Graphics.Blit(m_rawBufferWarper, m_drawCanvas.texture as RenderTexture);
m_fpsText.text = $"Audio:{NesCoreProxy.Instance.AudioCom.FPS}";
2024-07-04 21:06:41 +08:00
}
public void WriteErrorNotification(string message, bool instant)
{
}
public void WriteInfoNotification(string message, bool instant)
{
}
public void WriteWarningNotification(string message, bool instant)
{
}
public void TakeSnapshotAs(string path, string format)
{
}
public void TakeSnapshot()
{
}
public void ShutDown()
{
}
public void SignalToggle(bool started)
{
}
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()
{
}
}
}