add CRIWARE support.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e43bf2102ffb8146a97ee8251425939
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cceabf142838dcb4a8a13baa3d5f491a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 CRI Middleware Co., Ltd.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if UNITY_EDITOR_OSX || (!UNITY_EDITOR && UNITY_STANDALONE_OSX)
|
||||
using UnityEngine;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace CriWare {
|
||||
|
||||
namespace CriMana.Detail
|
||||
{
|
||||
public static partial class AutoResisterRendererResourceFactories
|
||||
{
|
||||
[RendererResourceFactoryPriority(7000)]
|
||||
public class RendererResourceFactoryOSXH264Yuv : RendererResourceFactory
|
||||
{
|
||||
public override RendererResource CreateRendererResource(int playerId, MovieInfo movieInfo, bool additive, Shader userShader)
|
||||
{
|
||||
bool isCodecSuitable = movieInfo.codecType == CodecType.H264;
|
||||
bool isSuitable = isCodecSuitable;
|
||||
return isSuitable
|
||||
? new RendererResourceOSXH264Yuv(playerId, movieInfo, additive, userShader)
|
||||
: null;
|
||||
}
|
||||
|
||||
protected override void OnDisposeManaged()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisposeUnmanaged()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RendererResourceOSXH264Yuv : RendererResource
|
||||
{
|
||||
private int width;
|
||||
private int height;
|
||||
private int playerId;
|
||||
private bool useUserShader;
|
||||
private Vector4 movieTextureST = Vector4.zero;
|
||||
private Texture2D[] textures;
|
||||
private RenderTexture[] renderTextures;
|
||||
System.IntPtr[] nativePtrs;
|
||||
private bool isStoppingForSeek = false;
|
||||
private bool isStartTriggered = true;
|
||||
private bool hasRenderedNewFrame = false;
|
||||
|
||||
public RendererResourceOSXH264Yuv(int playerId, MovieInfo movieInfo, bool additive, Shader userShader)
|
||||
{
|
||||
this.width = (int)movieInfo.width;
|
||||
this.height = (int)movieInfo.height;
|
||||
this.playerId = playerId;
|
||||
this.hasAlpha = movieInfo.hasAlpha;
|
||||
this.additive = additive;
|
||||
this.useUserShader = userShader != null;
|
||||
|
||||
if (userShader != null) {
|
||||
shader = userShader;
|
||||
} else {
|
||||
string shaderName = "CriMana/OSXH264Yuv";
|
||||
shader = Shader.Find(shaderName);
|
||||
}
|
||||
|
||||
if (hasAlpha) {
|
||||
nativePtrs = new System.IntPtr[2];
|
||||
} else {
|
||||
nativePtrs = new System.IntPtr[1];
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisposeManaged()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisposeUnmanaged()
|
||||
{
|
||||
DisposeTextures(textures);
|
||||
DisposeTextures(renderTextures);
|
||||
textures = null;
|
||||
renderTextures = null;
|
||||
currentMaterial = null;
|
||||
}
|
||||
|
||||
public override bool IsPrepared()
|
||||
{ return true; }
|
||||
|
||||
public override bool ContinuePreparing()
|
||||
{ return true; }
|
||||
|
||||
public override bool IsSuitable(int playerId, MovieInfo movieInfo, bool additive, Shader userShader)
|
||||
{
|
||||
bool isCodecSuitable = movieInfo.codecType == CodecType.H264;
|
||||
bool isAlphaSuitable = hasAlpha == movieInfo.hasAlpha;
|
||||
bool isAdditiveSuitable = this.additive == additive;
|
||||
bool isShaderSuitable = this.useUserShader ? (userShader == shader) : true;
|
||||
return isCodecSuitable && isAlphaSuitable && isAdditiveSuitable && isShaderSuitable;
|
||||
}
|
||||
|
||||
public override bool OnPlayerStopForSeek()
|
||||
{
|
||||
isStoppingForSeek = true;
|
||||
isStartTriggered = false;
|
||||
if (renderTextures != null || textures == null) {
|
||||
return true;
|
||||
}
|
||||
renderTextures = new RenderTexture[hasAlpha ? 2 : 1];
|
||||
for (int i = 0; i < renderTextures.Length; i++) {
|
||||
Texture2D baseTexture = textures[i];
|
||||
RenderTexture texture = new RenderTexture(baseTexture.width, baseTexture.height, 0,
|
||||
i == 0 ? RenderTextureFormat.ARGB32 : RenderTextureFormat.R8);
|
||||
texture.Create();
|
||||
Graphics.Blit(baseTexture, texture);
|
||||
renderTextures[i] = texture;
|
||||
}
|
||||
forceUpdateMaterialTextures(renderTextures);
|
||||
DisposeTextures(textures);
|
||||
textures = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnPlayerStart()
|
||||
{
|
||||
isStartTriggered = true;
|
||||
}
|
||||
|
||||
public override bool HasRenderedNewFrame()
|
||||
{
|
||||
return hasRenderedNewFrame;
|
||||
}
|
||||
|
||||
private void forceUpdateMaterialTextures(Texture[] newTextures)
|
||||
{
|
||||
if (currentMaterial != null) {
|
||||
currentMaterial.mainTexture = newTextures[0];
|
||||
currentMaterial.SetTexture("_TextureRGB", newTextures[0]);
|
||||
if (hasAlpha) {
|
||||
currentMaterial.SetTexture("_TextureA", newTextures[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void AttachToPlayer(int playerId)
|
||||
{
|
||||
// reset texture if exist
|
||||
DisposeTextures(textures);
|
||||
textures = null;
|
||||
hasRenderedNewFrame = false;
|
||||
}
|
||||
|
||||
public override bool UpdateFrame(int playerId, FrameInfo frameInfo, ref bool frameDrop)
|
||||
{
|
||||
bool isFrameUpdated = CRIWARE9061FF01(playerId, 0, null, frameInfo, ref frameDrop);
|
||||
if (isFrameUpdated && !frameDrop) {
|
||||
UpdateMovieTextureST(frameInfo.dispWidth, frameInfo.dispHeight);
|
||||
}
|
||||
|
||||
return isFrameUpdated;
|
||||
}
|
||||
|
||||
public override bool UpdateMaterial(Material material)
|
||||
{
|
||||
if (currentMaterial != material) {
|
||||
if (textures != null || isStoppingForSeek) {
|
||||
currentMaterial = material;
|
||||
SetupStaticMaterialProperties();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
material.SetVector("_MovieTexture_ST", movieTextureST);
|
||||
if (textures != null && !isStoppingForSeek) {
|
||||
material.SetTexture("_TextureRGB", textures[0]);
|
||||
if (hasAlpha) {
|
||||
material.SetTexture("_TextureA", textures[1]);
|
||||
}
|
||||
DisposeTextures(renderTextures);
|
||||
renderTextures = null;
|
||||
hasRenderedNewFrame = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateMovieTextureST(System.UInt32 dispWidth, System.UInt32 dispHeight)
|
||||
{
|
||||
float uScale = (dispWidth != width) ? (float)(dispWidth - 0.5f) / width : 1.0f;
|
||||
float vScale = (dispHeight != height) ? (float)(dispHeight - 0.5f) / height : 1.0f;
|
||||
movieTextureST.x = uScale;
|
||||
movieTextureST.y = -vScale;
|
||||
movieTextureST.z = 0.0f;
|
||||
movieTextureST.w = vScale;
|
||||
}
|
||||
|
||||
public override void UpdateTextures()
|
||||
{
|
||||
for (int i = 0; i < nativePtrs.Length; i++) {
|
||||
nativePtrs[i] = System.IntPtr.Zero;
|
||||
}
|
||||
bool isTextureUpdated = CRIWAREDA63C3D7(playerId, nativePtrs.Length, nativePtrs);
|
||||
if (isTextureUpdated && nativePtrs[0] != System.IntPtr.Zero && isStartTriggered) {
|
||||
if (textures == null) {
|
||||
textures = new Texture2D[2];
|
||||
textures[0] = Texture2D.CreateExternalTexture(width, height, TextureFormat.BGRA32, false, false, nativePtrs[0]);
|
||||
textures[0].wrapMode = TextureWrapMode.Clamp;
|
||||
if (hasAlpha) {
|
||||
textures[1] = Texture2D.CreateExternalTexture(width, height, TextureFormat.R8, false, false, nativePtrs[1]);
|
||||
textures[1].wrapMode = TextureWrapMode.Clamp;
|
||||
}
|
||||
} else {
|
||||
textures[0].UpdateExternalTexture(nativePtrs[0]);
|
||||
if (hasAlpha) {
|
||||
textures[1].UpdateExternalTexture(nativePtrs[1]);
|
||||
}
|
||||
}
|
||||
isStoppingForSeek = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace CriWare
|
||||
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90d607173f1704c988704d3aed98260c
|
||||
timeCreated: 1461031521
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18b37d25e817cb04f88473c6a7eb1f7f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d05e68ec8b2ea84f9fc2b883101751e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9586ec280901aae4d876151aee8ab969
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
Shader "CriMana/OSXH264Yuv"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
[HideInInspector] _MovieTexture_ST ("MovieTexture_ST", Vector) = (1.0, 1.0, 0, 0)
|
||||
[HideInInspector] _TextureRGB("TextureRGB", 2D) = "white" {}
|
||||
[HideInInspector] _TextureA("TextureA", 2D) = "white" {}
|
||||
[HideInInspector] _SrcBlendMode("SrcBlendMode", Int) = 0
|
||||
[HideInInspector] _DstBlendMode("DstBlendMode", Int) = 0
|
||||
[HideInInspector] _CullMode("CullMode", Int) = 2
|
||||
[HideInInspector] _ZWriteMode("ZWriteMode", Int) = 1
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue" = "Transparent"
|
||||
"PreviewType"="Plane"
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_SrcBlendMode] [_DstBlendMode]
|
||||
Cull [_CullMode]
|
||||
ZWrite [_ZWriteMode]
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#pragma multi_compile _ CRI_ALPHA_MOVIE
|
||||
#pragma multi_compile _ CRI_APPLY_TARGET_ALPHA
|
||||
#pragma multi_compile _ CRI_LINEAR_COLORSPACE
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
#ifdef CRI_APPLY_TARGET_ALPHA
|
||||
float4 color : COLOR;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
#ifdef CRI_APPLY_TARGET_ALPHA
|
||||
float4 color : COLOR;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
float4 _MovieTexture_ST;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = (TRANSFORM_TEX(v.texcoord, _MainTex) * _MovieTexture_ST.xy) + _MovieTexture_ST.zw;
|
||||
#ifdef CRI_APPLY_TARGET_ALPHA
|
||||
o.color = v.color;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
sampler2D _TextureRGB;
|
||||
#ifdef CRI_ALPHA_MOVIE
|
||||
sampler2D _TextureA;
|
||||
#endif
|
||||
fixed _Transparency;
|
||||
|
||||
fixed4 frag(v2f i) : COLOR
|
||||
{
|
||||
fixed4 color = tex2D(_TextureRGB, i.uv);
|
||||
#ifdef CRI_ALPHA_MOVIE
|
||||
fixed4 alpha = tex2D(_TextureA, i.uv);
|
||||
color.a = alpha.r;
|
||||
#endif
|
||||
#ifdef CRI_LINEAR_COLORSPACE
|
||||
color.rgb = pow(max(color.rgb, 0), 2.2);
|
||||
#endif
|
||||
#ifdef CRI_APPLY_TARGET_ALPHA
|
||||
color.a = color.a * i.color.a;
|
||||
#endif
|
||||
color.a *= 1 - _Transparency;
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ecadf8cf71554c599b839bc4a1933ec
|
||||
timeCreated: 1461226273
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user