void OnCompleteReadback(AsyncGPUReadbackRequest request)
    {
        if (request.hasError)
        {
            Debug.LogError("GPU readback error detected");
            return;
        }

        // This happens when the delayed async readback happens as we're exiting play mode
        if (instance == null || visibilityMaskTexture == null)
        {
            return;
        }

        // Read the color of the visibility mask texture to determine which visibility masks are active on cursor
        Texture2D visibilityMaskTex = new Texture2D(
            1,
            1,
            GraphicsFormatUtility.GetTextureFormat(visibilityMaskTexture.graphicsFormat),
            false
            );

        visibilityMaskTex.LoadRawTextureData(request.GetData <Color32>());
        visibilityMaskTex.Apply();

        // Only one pixel so we can sample at 0, 0
        Color sample = visibilityMaskTex.GetPixel(0, 0);

        visibilityMaskValue = DimensionShaderUtils.MaskValueFromSample(sample.linear);
    }
Esempio n. 2
0
 public SparseTexture(int width, int height, GraphicsFormat format, int mipCount)
 {
     if (ValidateFormat(format, FormatUsage.Sample))
     {
         Internal_Create(this, width, height, GraphicsFormatUtility.GetTextureFormat(format), GraphicsFormatUtility.IsSRGBFormat(format), mipCount);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Perform async read back from the provided source texture.
        /// </summary>
        /// <param name="src">Texture source to be used for the read back.</param>
        /// <param name="mipIndex">Index of the mipmap to be fetched.</param>
        /// <param name="dstFormat">Target TextureFormat of the data. If the target format is different from the format stored on the GPU, the conversion is automatic.</param>
        /// <param name="functor">Functor that will be invoked after the async read back request is complete.</param>
        /// <typeparam name="T">Type for the destination data buffer.</typeparam>
        /// <returns>Returns an AsynRequest</returns>
        public static AsyncRequest <object> Capture <T>(Texture src, int mipIndex, GraphicsFormat dstFormat, Func <AsyncRequest <object>, AsyncRequest <object> .Result> functor = null) where T : struct
        {
            var req = Manager.Instance.CreateRequest <AsyncRequest <object> >();

            if (GraphicsUtilities.SupportsAsyncReadback())
            {
                AsyncGPUReadback.Request(src, mipIndex, GraphicsFormatUtility.GetTextureFormat(dstFormat), (AsyncGPUReadbackRequest request) =>
                {
                    req.error = request.hasError;
                    if (!request.hasError)
                    {
                        req.data = request.GetData <T>().ToArray();
                        req.Enqueue(functor);
                        req.Execute();
                    }
                });
            }
            else
            {
                req.data = GraphicsUtilities.GetPixelsSlow(src as RenderTexture);
                req.Enqueue(functor);
                req.Execute();
            }

            return(req);
        }
Esempio n. 4
0
            public Texture2D To()
            {
                var       textureFormat = GraphicsFormatUtility.GetTextureFormat(m_format);
                var       srgb          = GraphicsFormatUtility.IsSRGBFormat(m_format);
                Texture2D texture       = new Texture2D(m_width, m_height, textureFormat, true, !srgb);

                texture.name = m_textureName;
                texture.LoadImage(m_bytes);
                texture.wrapMode = m_wrapMode;
                texture.Apply();
                return(texture);
            }
Esempio n. 5
0
        public static TextureFormat GetSupportedTextureFormat(GraphicsDeviceType type)
        {
            var graphicsFormat = GetSupportedGraphicsFormat(type);

            return(GraphicsFormatUtility.GetTextureFormat(graphicsFormat));
        }
Esempio n. 6
0
 protected static TextureFormat TextureFormatFor(Texture texture)
 {
     return(GraphicsFormatUtility.GetTextureFormat(texture.graphicsFormat));
 }
Esempio n. 7
0
 private static TextureFormat GetTextureFormat(Texture texture)
 {
     return(GraphicsFormatUtility.GetTextureFormat(texture.graphicsFormat));
 }