From 4350ac3953d0f753f8770f1a9f8bff7b10629c8d Mon Sep 17 00:00:00 2001 From: hecomi Date: Tue, 1 Nov 2016 02:20:46 +0900 Subject: [PATCH] cache pointer texture. --- Assets/uDesktopDuplication/Scripts/Cursor.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Assets/uDesktopDuplication/Scripts/Cursor.cs b/Assets/uDesktopDuplication/Scripts/Cursor.cs index 1681ef4..a85eb6d 100644 --- a/Assets/uDesktopDuplication/Scripts/Cursor.cs +++ b/Assets/uDesktopDuplication/Scripts/Cursor.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System.Collections.Generic; namespace uDesktopDuplication { @@ -17,6 +18,8 @@ public class Cursor : MonoBehaviour private Texture2D pointerTexture_; private Material cursorMaterial_; + private Dictionary pointerTextures_ = new Dictionary(); + void OnEnable() { uddTexture_ = GetComponent(); @@ -62,10 +65,15 @@ public class Cursor : MonoBehaviour void UpdateTexture() { - pointerTexture_ = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false); - pointerTexture_.wrapMode = TextureWrapMode.Clamp; - monitor.UpdatePointerTexture(pointerTexture_.GetNativeTexturePtr()); - cursorMaterial_.SetTexture("_MainTex", pointerTexture_); + var scale = new Vector2(monitor.pointerShapeWidth, monitor.pointerShapeHeight); + if (!pointerTextures_.ContainsKey(scale)) { + var texture = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false); + texture.wrapMode = TextureWrapMode.Clamp; + pointerTextures_.Add(scale, texture); + } + var pointerTexture = pointerTextures_[scale]; + monitor.UpdatePointerTexture(pointerTexture.GetNativeTexturePtr()); + cursorMaterial_.SetTexture("_MainTex", pointerTexture); } void UpdateMaterial()