void SendRenderTexture(RenderTexture source) { if (currentSenderName != senderName) { DisposePlugin(); } // Plugin lazy initialization if (_plugin == System.IntPtr.Zero) { _plugin = PluginEntry.CreateSender(senderName, source.width, source.height); currentSenderName = senderName; if (_plugin == System.IntPtr.Zero) { return; // Spout may not be ready. } } // Shared texture lazy initialization if (_sharedTexture == null) { var ptr = PluginEntry.GetTexturePointer(_plugin); if (ptr != System.IntPtr.Zero) { _sharedTexture = Texture2D.CreateExternalTexture( PluginEntry.GetTextureWidth(_plugin), PluginEntry.GetTextureHeight(_plugin), TextureFormat.ARGB32, false, false, ptr ); _sharedTexture.hideFlags = HideFlags.DontSave; } } // Shared texture update if (_sharedTexture != null) { // Blit shader lazy initialization if (_blitMaterial == null) { _blitMaterial = new Material(Shader.Find("Hidden/Spout/Blit")); _blitMaterial.hideFlags = HideFlags.DontSave; } // Blit shader parameters _blitMaterial.SetFloat("_ClearAlpha", _alphaSupport ? 0 : 1); // We can't directly blit to the shared texture (as it lacks // render buffer functionality), so we temporarily allocate a // render texture as a middleman, blit the source to it, then // copy it to the shared texture using the CopyTexture API. var tempRT = RenderTexture.GetTemporary (_sharedTexture.width, _sharedTexture.height); Graphics.Blit(source, tempRT, _blitMaterial, 0); Graphics.CopyTexture(tempRT, _sharedTexture); RenderTexture.ReleaseTemporary(tempRT); } }
void SendRenderTexture(RenderTexture source) { // Plugin lazy initialization if (_plugin == System.IntPtr.Zero) { _plugin = PluginEntry.CreateSender(name, source.width, source.height); if (_plugin == System.IntPtr.Zero) { return; // Spout may not be ready. } } // Shared texture lazy initialization //TextureFormat format = TextureFormat.ARGB32; // TABULA: original KlakSpout, DX11 only TextureFormat format = TextureFormat.BGRA32; // TABULA: FaçadeSignage compatibilty, DX9/DX11 if (_sharedTexture == null) { var ptr = PluginEntry.GetTexturePointer(_plugin); if (ptr != System.IntPtr.Zero) { _sharedTexture = Texture2D.CreateExternalTexture( PluginEntry.GetTextureWidth(_plugin), PluginEntry.GetTextureHeight(_plugin), format, false, false, ptr ); _sharedTexture.hideFlags = HideFlags.DontSave; } } // Shared texture update if (_sharedTexture != null) { // Blit shader lazy initialization if (_blitMaterial == null) { _blitMaterial = new Material(Shader.Find("Hidden/Spout/Blit")); _blitMaterial.hideFlags = HideFlags.DontSave; } // Blit shader parameters _blitMaterial.SetFloat("_ClearAlpha", _alphaSupport ? 0 : 1); // We can't directly blit to the shared texture (as it lacks // render buffer functionality), so we temporarily allocate a // render texture as a middleman, blit the source to it, then // copy it to the shared texture using the CopyTexture API. var tempRT = RenderTexture.GetTemporary (_sharedTexture.width, _sharedTexture.height, 0, RenderTextureFormat.BGRA32); // tabula: using BGRA32 also for temp Graphics.Blit(source, tempRT, _blitMaterial, 0); Graphics.CopyTexture(tempRT, _sharedTexture); RenderTexture.ReleaseTemporary(tempRT); } }
void OnEnable() { _camera = GetComponent <Camera>(); if (_resolution.x == 0) { _resolution.x = Screen.width; } if (_resolution.y == 0) { _resolution.y = Screen.height; } _sender = PluginEntry.CreateSender(name, _resolution.x, _resolution.y); }
void OnEnable() { var camera = GetComponent <Camera>(); _sender = PluginEntry.CreateSender(name, camera.pixelWidth, camera.pixelHeight); }