cache pointer texture.

This commit is contained in:
hecomi
2016-11-01 02:20:46 +09:00
parent 6ba381f5d4
commit 4350ac3953
+12 -4
View File
@@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using System.Collections.Generic;
namespace uDesktopDuplication namespace uDesktopDuplication
{ {
@@ -17,6 +18,8 @@ public class Cursor : MonoBehaviour
private Texture2D pointerTexture_; private Texture2D pointerTexture_;
private Material cursorMaterial_; private Material cursorMaterial_;
private Dictionary<Vector2, Texture2D> pointerTextures_ = new Dictionary<Vector2, Texture2D>();
void OnEnable() void OnEnable()
{ {
uddTexture_ = GetComponent<Texture>(); uddTexture_ = GetComponent<Texture>();
@@ -62,10 +65,15 @@ public class Cursor : MonoBehaviour
void UpdateTexture() void UpdateTexture()
{ {
pointerTexture_ = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false); var scale = new Vector2(monitor.pointerShapeWidth, monitor.pointerShapeHeight);
pointerTexture_.wrapMode = TextureWrapMode.Clamp; if (!pointerTextures_.ContainsKey(scale)) {
monitor.UpdatePointerTexture(pointerTexture_.GetNativeTexturePtr()); var texture = new Texture2D(monitor.pointerShapeWidth, monitor.pointerShapeHeight, TextureFormat.BGRA32, false);
cursorMaterial_.SetTexture("_MainTex", pointerTexture_); texture.wrapMode = TextureWrapMode.Clamp;
pointerTextures_.Add(scale, texture);
}
var pointerTexture = pointerTextures_[scale];
monitor.UpdatePointerTexture(pointerTexture.GetNativeTexturePtr());
cursorMaterial_.SetTexture("_MainTex", pointerTexture);
} }
void UpdateMaterial() void UpdateMaterial()