void Start() { cam = GetComponent <Camera>(); if (cam == null) { cam = GameObject.FindObjectOfType <Camera>(); } if (cam == null) { Debug.LogError("No camera found"); } if (material == null) { material = new Material(Shader.Find("AR/MatDisplay")); } foregroundMaterial = new Material(material); foregroundMaterial.renderQueue = 4005; backgroundMaterial = new Material(material); backgroundMaterial.renderQueue = 500; for (int i = 0; i < matDisplays.Length; i++) { matDisplays[i] = new MatDrawer(); texDisplays[i] = new MatDrawer(); } convertMat = new Mat(); Clear(); started = true; }
public static void DisplayTexture(Texture2D texture, MatDisplaySettings properties) { MatDrawer uDispl = texDisplays[texDisplayCount++]; uDispl.texture = texture; uDispl.Activate(properties); }
public static unsafe void DisplayImageData(IntPtr ptr, int width, int height, int channels, MatDisplaySettings properties) { if (width * height <= 0) { throw new Exception("[MatDisplay] invalid extends: width=" + width + ", height=" + height); } if (!isValid) { return; } int len = width * height * channels; TextureFormat format = ChannelsToFormat(channels); MatDrawer uDispl = null; //Reuse displ foreach (MatDrawer displ in matDisplays) { if (!displ.active) { if (displ.texture != null && format == displ.texture.format && height == displ.texture.height && width == displ.texture.width) { uDispl = displ; } } } if (uDispl == null) { //Find new display foreach (MatDrawer displ in matDisplays) { if (displ.texture == null) { uDispl = displ; displ.texture = new Texture2D(width, height, format, false); displ.channels = channels; break; } } } if (uDispl == null) { Debug.LogError("Too many mat displays"); return; } //Update texture data uDispl.flipY = false; uDispl.texture.LoadRawTextureData(ptr, len); uDispl.texture.Apply(); //Activate display for rendering uDispl.Activate(properties); }