//输入数据接口案例 public void UpdateData(IntPtr ptr, int texid, int w, int h, UpdateDataMode mode) { if (mode == UpdateDataMode.NV21) { FaceunityWorker.SetNV21Input(ptr, 0, w, h); } else if (mode == UpdateDataMode.Dual) { FaceunityWorker.SetDualInput(ptr, texid, 0, w, h); } else if (mode == UpdateDataMode.Image) { FaceunityWorker.SetImage(ptr, 0, false, w, h); } else if (mode == UpdateDataMode.ImageTexId) { FaceunityWorker.SetImageTexId(texid, 0, w, h); } if (m_tex_created == false) { m_fu_texid = FaceunityWorker.fu_GetNamaTextureId(); if (m_fu_texid > 0) { m_rendered_tex = Texture2D.CreateExternalTexture(w, h, TextureFormat.RGBA32, false, true, (IntPtr)m_fu_texid); Debug.LogFormat("Texture2D.CreateExternalTexture:{0}\n", m_fu_texid); if (RawImg_BackGroud != null) { RawImg_BackGroud.texture = m_rendered_tex; RawImg_BackGroud.gameObject.SetActive(true); Debug.Log("m_rendered_tex: " + m_rendered_tex.GetNativeTexturePtr()); } m_tex_created = true; } } }
/// <summary> /// 往SDK输入数据并根据返回的纹理ID新建一个纹理,绑定在UI上,这个返回不是即时的,首次输入数据后真正执行是在GL.IssuePluginEvent执行的时候,因此纹理ID会在下一帧返回 /// </summary> /// <param name="ptr">输入数据buffer的指针</param> /// <param name="tex_id">输入数据的纹理ID</param> /// <param name="w">该帧图片的宽</param> /// <param name="h">该帧图片的高</param> /// <param name="mode"></param> public void UpdateData(IntPtr ptr, int tex_id, int w, int h, UpdateDataMode mode) { if (mode == UpdateDataMode.None || (ptr == IntPtr.Zero && tex_id == 0) || (w == 0 && h == 0)) { return; } if (mode == UpdateDataMode.RGBABuffer) { FaceunityWorker.SetImage(ptr, 0, false, w, h); } else if (mode == UpdateDataMode.BGRABuffer) { FaceunityWorker.SetImage(ptr, 0, true, w, h); } else if (mode == UpdateDataMode.TexID) { FaceunityWorker.SetImageTexId(tex_id, 0, w, h); } else if (mode == UpdateDataMode.NV21Buffer) { FaceunityWorker.SetNV21Input(ptr, 0, w, h); } else if (mode == UpdateDataMode.NV21BufferAndTexID) { FaceunityWorker.SetDualInput(ptr, tex_id, 0, w, h); } else if (mode == UpdateDataMode.YUV420Buffer) { FaceunityWorker.SetYUVInput(ptr, 0, w, h); } if (_m_tex_created == false) { var fu_texid = FaceunityWorker.fu_GetNamaTextureId(); if (fu_texid > 0) { if (NeedSwitchWidthHeight()) { _m_rendered_tex = Texture2D.CreateExternalTexture(h, w, TextureFormat.RGBA32, false, true, (IntPtr)fu_texid); } else { _m_rendered_tex = Texture2D.CreateExternalTexture(w, h, TextureFormat.RGBA32, false, true, (IntPtr)fu_texid); } if (rawimg_backgroud != null) { rawimg_backgroud.texture = _m_rendered_tex; } _m_tex_created = true; } } }