2024-07-30 18:53:36 +08:00
|
|
|
|
using System;
|
2024-07-31 17:40:32 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
|
|
|
{
|
|
|
|
|
public class VideoProvider : MonoBehaviour
|
|
|
|
|
{
|
2024-08-06 16:03:17 +08:00
|
|
|
|
public NesEmulator NesEmu;
|
2024-09-13 13:28:33 +08:00
|
|
|
|
public Canvas DrawCanvas;
|
2024-08-06 16:03:17 +08:00
|
|
|
|
|
2024-07-30 11:57:09 +08:00
|
|
|
|
public RawImage Image;
|
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
private UInt32[] wrapTexBuffer;
|
2024-07-31 17:40:32 +08:00
|
|
|
|
private IntPtr wrapTexBufferPointer;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
private Texture2D wrapTex;
|
2024-08-02 10:58:04 +08:00
|
|
|
|
private int TexBufferSize;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
|
2024-08-09 15:47:44 +08:00
|
|
|
|
private Texture2D pPal;
|
2024-08-29 17:20:01 +08:00
|
|
|
|
|
2024-09-13 13:28:33 +08:00
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
DrawCanvas.worldCamera = Camera.main;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 15:47:44 +08:00
|
|
|
|
public void SetDrawData(uint[] screenData, byte[] lineColorMode, int screenWidth, int screenHeight)
|
2024-07-30 11:57:09 +08:00
|
|
|
|
{
|
2024-07-31 17:40:32 +08:00
|
|
|
|
if (wrapTex == null)
|
|
|
|
|
{
|
2024-08-16 10:39:51 +08:00
|
|
|
|
//wrapTex = new Texture2D(272, 240, TextureFormat.BGRA32, false);
|
|
|
|
|
wrapTex = new Texture2D(272, 240, TextureFormat.RGBA32, false);
|
2024-08-09 15:47:44 +08:00
|
|
|
|
wrapTex.filterMode = FilterMode.Point;
|
|
|
|
|
wrapTexBuffer = screenData;
|
|
|
|
|
|
2024-07-31 17:40:32 +08:00
|
|
|
|
// <20>̶<EFBFBD><CCB6><EFBFBD><EFBFBD>飬<EFBFBD><E9A3AC>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>
|
|
|
|
|
GCHandle handle = GCHandle.Alloc(wrapTexBuffer, GCHandleType.Pinned);
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
wrapTexBufferPointer = handle.AddrOfPinnedObject();
|
2024-08-14 13:09:22 +08:00
|
|
|
|
|
|
|
|
|
Image.texture = wrapTex;
|
2024-08-09 15:47:44 +08:00
|
|
|
|
Image.material.SetTexture("_MainTex", wrapTex);
|
2024-08-02 10:58:04 +08:00
|
|
|
|
|
|
|
|
|
TexBufferSize = wrapTexBuffer.Length * 4;
|
2024-07-30 18:53:36 +08:00
|
|
|
|
|
2024-08-09 15:47:44 +08:00
|
|
|
|
var palRaw = PaletteDefine.m_cnPalette[0];
|
2024-08-16 10:39:51 +08:00
|
|
|
|
//pPal = new Texture2D(palRaw.Length, 1, TextureFormat.BGRA32, 1, true);
|
|
|
|
|
pPal = new Texture2D(palRaw.Length, 1, TextureFormat.RGBA32, false);
|
2024-08-09 15:47:44 +08:00
|
|
|
|
pPal.filterMode = FilterMode.Point;
|
|
|
|
|
for (int i = 0; i < palRaw.Length; i++)
|
2024-07-30 18:53:36 +08:00
|
|
|
|
{
|
2024-08-09 15:47:44 +08:00
|
|
|
|
uint colorRaw = palRaw[i];
|
|
|
|
|
var argbColor = BitConverter.GetBytes(colorRaw);
|
|
|
|
|
Color temp = Color.white;
|
2024-08-14 13:09:22 +08:00
|
|
|
|
temp.r = argbColor[2] / 255f;
|
|
|
|
|
temp.g = argbColor[1] / 255f;
|
|
|
|
|
temp.b = argbColor[0] / 255f;
|
2024-08-09 15:47:44 +08:00
|
|
|
|
temp.a = 1;
|
|
|
|
|
pPal.SetPixel(i, 0, temp);
|
2024-07-30 18:53:36 +08:00
|
|
|
|
}
|
2024-08-09 15:47:44 +08:00
|
|
|
|
pPal.Apply();
|
|
|
|
|
Image.material.SetTexture("_PalTex", pPal);
|
2024-07-30 18:53:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 10:58:04 +08:00
|
|
|
|
wrapTex.LoadRawTextureData(wrapTexBufferPointer, TexBufferSize);
|
2024-07-30 11:57:09 +08:00
|
|
|
|
wrapTex.Apply();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|