public static AsyncGPUReadbackRequest Request(Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_Texture_3(src, mipIndex, x, width, y, height, z, depth, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
        static public AsyncGPUReadbackRequest Request(GraphicsBuffer src, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest request = Request_Internal_GraphicsBuffer_1(src);

            SetUpScriptingRequest(request, callback);
            return(request);
        }
        public static AsyncGPUReadbackRequest Request(GraphicsBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_GraphicsBuffer_2(src, size, offset, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
        static public AsyncGPUReadbackRequest Request(Texture src, int mipIndex, TextureFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest request = Request_Internal_Texture_2(src, mipIndex, dstFormat);

            SetUpScriptingRequest(request, callback);
            return(request);
        }
Пример #5
0
    IEnumerator SceneToTexture()
    {
        // Run through everything and render each camera
        // setup variables if not done already
        for (int i = 0; i < instances; i++)
        {
            // Connect camera to renderTexture and render
            cameras[i].targetTexture = renderTextures[i];
            cameras[i].Render();
            RenderTexture.active = renderTextures[i];

            // Asynchrously request rendertexture data from GPU
            UnityEngine.Rendering.AsyncGPUReadbackRequest request = UnityEngine.Rendering.AsyncGPUReadback.Request(renderTextures[i], 0);
            while (!request.done)
            {
                yield return(new WaitForEndOfFrame());
            }
            pixels[i] = request.GetData <byte>().ToArray();

            // We want to get our pixel data in png form, which requires creating a new texture2D
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
            tex.LoadImage(pixels[i]);
            pixels[i] = tex.EncodeToPNG();

            // Clean-up
            RenderTexture.active = null;
        }
    }
        public static AsyncGPUReadbackRequest Request(Texture src, int mipIndex = 0, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_Texture_1(src, mipIndex, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
Пример #7
0
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Rendering.AsyncGPUReadbackRequest o;
         o = new UnityEngine.Rendering.AsyncGPUReadbackRequest();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
        static public AsyncGPUReadbackRequest Request(Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, TextureFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest request = Request_Internal_Texture_4(src, mipIndex, x, width, y, height, z, depth, dstFormat);

            SetUpScriptingRequest(request, callback);
            return(request);
        }
        public static AsyncGPUReadbackRequest Request(ComputeBuffer src, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_ComputeBuffer_1(src, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
        static public AsyncGPUReadbackRequest Request(ComputeBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadbackRequest request = Request_Internal_ComputeBuffer_2(src, size, offset);

            SetUpScriptingRequest(request, callback);
            return(request);
        }
        private AtomicSafetyHandle GetSafetyHandle()
        {
            AtomicSafetyHandle result;

            AsyncGPUReadbackRequest.GetSafetyHandle_Injected(ref this, out result);
            return(result);
        }
        public unsafe static AsyncGPUReadbackRequest RequestIntoNativeSlice <T>(ref NativeSlice <T> output, GraphicsBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
        {
            AsyncRequestNativeArrayData asyncRequestNativeArrayData = AsyncRequestNativeArrayData.CreateAndCheckAccess <T>(output);
            AsyncGPUReadbackRequest     result = AsyncGPUReadback.Request_Internal_GraphicsBuffer_2(src, size, offset, &asyncRequestNativeArrayData);

            result.SetScriptingCallback(callback);
            return(result);
        }
        public static AsyncGPUReadbackRequest Request(Texture src, int mipIndex, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadback.ValidateFormat(src, dstFormat);
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_Texture_2(src, mipIndex, dstFormat, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
        public unsafe static AsyncGPUReadbackRequest RequestIntoNativeSlice <T>(ref NativeSlice <T> output, Texture src, int mipIndex = 0, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
        {
            AsyncRequestNativeArrayData asyncRequestNativeArrayData = AsyncRequestNativeArrayData.CreateAndCheckAccess <T>(output);
            AsyncGPUReadbackRequest     result = AsyncGPUReadback.Request_Internal_Texture_1(src, mipIndex, &asyncRequestNativeArrayData);

            result.SetScriptingCallback(callback);
            return(result);
        }
        public static AsyncGPUReadbackRequest Request(Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null)
        {
            AsyncGPUReadback.ValidateFormat(src, dstFormat);
            AsyncGPUReadbackRequest result = AsyncGPUReadback.Request_Internal_Texture_4(src, mipIndex, x, width, y, height, z, depth, dstFormat, null);

            result.SetScriptingCallback(callback);
            return(result);
        }
        public unsafe static AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, ComputeBuffer src, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
        {
            AsyncRequestNativeArrayData asyncRequestNativeArrayData = AsyncRequestNativeArrayData.CreateAndCheckAccess <T>(output);
            AsyncGPUReadbackRequest     result = AsyncGPUReadback.Request_Internal_ComputeBuffer_1(src, &asyncRequestNativeArrayData);

            result.SetScriptingCallback(callback);
            return(result);
        }
 static public AsyncGPUReadbackRequest Request(GraphicsBuffer src, Action <AsyncGPUReadbackRequest> callback = null)
 {
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_GraphicsBuffer_1(src, null);
         request.SetScriptingCallback(callback);
         return(request);
     }
 }
        public unsafe static AsyncGPUReadbackRequest RequestIntoNativeSlice <T>(ref NativeSlice <T> output, Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
        {
            AsyncGPUReadback.ValidateFormat(src, dstFormat);
            AsyncRequestNativeArrayData asyncRequestNativeArrayData = AsyncRequestNativeArrayData.CreateAndCheckAccess <T>(output);
            AsyncGPUReadbackRequest     result = AsyncGPUReadback.Request_Internal_Texture_4(src, mipIndex, x, width, y, height, z, depth, dstFormat, &asyncRequestNativeArrayData);

            result.SetScriptingCallback(callback);
            return(result);
        }
 static public AsyncGPUReadbackRequest Request(ComputeBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null)
 {
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_ComputeBuffer_2(src, size, offset, null);
         request.SetScriptingCallback(callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, Texture src, int mipIndex = 0, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_Texture_5(src, mipIndex, output.GetUnsafePtr(), output.Length * UnsafeUtility.SizeOf <T>());
         SetUpScriptingRequest(request, callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, GraphicsBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_GraphicsBuffer_4(src, size, offset, output.GetUnsafePtr(), output.Length * UnsafeUtility.SizeOf <T>());
         SetUpScriptingRequest(request, callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeSlice <T>(ref NativeSlice <T> output, ComputeBuffer src, int size, int offset, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     unsafe
     {
         var data = AsyncRequestNativeArrayData.CreateAndCheckAccess(output);
         AsyncGPUReadbackRequest request = Request_Internal_ComputeBuffer_2(src, size, offset, &data);
         request.SetScriptingCallback(callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, GraphicsBuffer src, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     unsafe
     {
         var data = AsyncRequestNativeArrayData.CreateAndCheckAccess(output);
         AsyncGPUReadbackRequest request = Request_Internal_GraphicsBuffer_1(src, &data);
         request.SetScriptingCallback(callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     ValidateFormat(src, dstFormat);
     unsafe
     {
         AsyncGPUReadbackRequest request = Request_Internal_Texture_7(src, mipIndex, x, width, y, height, z, depth, dstFormat, output.GetUnsafePtr(), output.Length * UnsafeUtility.SizeOf <T>());
         SetUpScriptingRequest(request, callback);
         return(request);
     }
 }
 static public AsyncGPUReadbackRequest RequestIntoNativeArray <T>(ref NativeArray <T> output, Texture src, int mipIndex, GraphicsFormat dstFormat, Action <AsyncGPUReadbackRequest> callback = null) where T : struct
 {
     ValidateFormat(src, dstFormat);
     unsafe
     {
         var data = AsyncRequestNativeArrayData.CreateAndCheckAccess(output);
         AsyncGPUReadbackRequest request = Request_Internal_Texture_2(src, mipIndex, dstFormat, &data);
         request.SetScriptingCallback(callback);
         return(request);
     }
 }
Пример #26
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Rendering.AsyncGPUReadbackRequest o;
         o = new UnityEngine.Rendering.AsyncGPUReadbackRequest();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    protected void LateUpdate()
    {
        bool needSendCommand = false;

        if (m_AsyncGPUReadbackRequest.done)
        {
            if (!m_AsyncGPUReadbackRequest.hasError)
            {
                Unity.Collections.NativeArray <RoleResult> resultBuffers = m_AsyncGPUReadbackRequest.GetData <RoleResult>();
                resultBuffers.CopyTo(m_RoleResults);
                for (int iResult = 0; iResult < m_RoleResults.Length; ++iResult)
                {
                    if (m_RoleResults[iResult].IsArrival == INT_TRUE)
                    {
                        m_RoleCommands[iResult].MoveTo = RandPositionOnGround();
                        needSendCommand = true;
                    }
                }
            }
            else
            {
                Debug.LogError("AsyncGPUReadback Error");
            }
            m_AsyncGPUReadbackRequest = UnityEngine.Rendering.AsyncGPUReadback.Request(m_CB_RoleResult);
        }

        if (needSendCommand)
        {
            m_CB_RoleCommand.SetData(m_RoleCommands);
        }
        MovementComputeShader.SetFloat(SHADER_PROPERTYID_DELTATIME, Time.deltaTime);

        MovementComputeShader.Dispatch(m_CS_UpdateKernel, RoleCount, 1, 1);

        Draw(MainCamera);
    }
 private unsafe static extern void Request_Internal_Texture_2_Injected(Texture src, int mipIndex, GraphicsFormat dstFormat, AsyncRequestNativeArrayData *data, out AsyncGPUReadbackRequest ret);
 private unsafe static extern void Request_Internal_Texture_4_Injected(Texture src, int mipIndex, int x, int width, int y, int height, int z, int depth, GraphicsFormat dstFormat, AsyncRequestNativeArrayData *data, out AsyncGPUReadbackRequest ret);
 static private void SetUpScriptingRequest(AsyncGPUReadbackRequest request, Action <AsyncGPUReadbackRequest> callback)
 {
     request.SetScriptingCallback(callback);
     request.CreateSafetyHandle();
 }