/// <summary> /// Starts recording. /// </summary> public void Record() { _state = RecorderState.Recording; #if EM_URP EM_GIFRecorderFeature.SetBlitRT(TargetCamera, null); #endif }
void OnDestroy() { _state = RecorderState.Stopped; FlushMemory(); #if EM_URP EM_GIFRecorderFeature.SetBlitRT(TargetCamera, null); #endif }
private void LateUpdate() { if (_state != RecorderState.Recording) { return; } pastTime += Time.unscaledDeltaTime; if (pastTime >= timePerFrame) { pastTime -= timePerFrame; RenderTexture targetBlitRT = EM_GIFRecorderFeature.GetBlitRT(TargetCamera); if (targetBlitRT != null) { //Enqueue last frame blit result recordedFrames.Enqueue(targetBlitRT); } RenderTexture tempRT = null; // Recycle old frames -> discard old content if (recordedFrames.Count >= maxFrameCount) { tempRT = recordedFrames.Dequeue(); } if (tempRT == null) { tempRT = new RenderTexture(_width, _height, 0, RenderTextureFormat.ARGB32); tempRT.wrapMode = TextureWrapMode.Clamp; tempRT.filterMode = FilterMode.Bilinear; tempRT.anisoLevel = 0; } else { // Discard the reused RT's content before rendering new content into it // to avoid a "restore" operation, which is costly on many mobile GPUs and // multi-GPU systems and will cause Unity to issue a warning. tempRT.DiscardContents(); } EM_GIFRecorderFeature.SetBlitRT(TargetCamera, tempRT); } }