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-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-11-14 12:02:11 +08:00
|
|
|
public unsafe 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;
|
|
|
|
|
2024-11-14 12:02:11 +08:00
|
|
|
wrapTexBufferPointer = (IntPtr)screenData;
|
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
|
|
|
|
2024-11-14 12:02:11 +08:00
|
|
|
TexBufferSize = screenWidth * screenHeight * 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.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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|