예제 #1
0
    public static void DisplayTexture(Texture2D texture, MatDisplaySettings properties)
    {
        MatDrawer uDispl = texDisplays[texDisplayCount++];

        uDispl.texture = texture;
        uDispl.Activate(properties);
    }
예제 #2
0
    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);
    }