private void OnUpdate() { if (_queue.Count == 0 || (_task != null && _task.Enabled)) { return; } // TODO: add delay when processing the requests to reduce perf impact (eg. 0.2s before actual rendering) // Setup pipeline if (_atlases == null) { _atlases = new List <Atlas>(4); } if (_output == null) { _output = GPUDevice.Instance.CreateTexture("CameraCutMedia.Output"); var desc = GPUTextureDescription.New2D(Width, Height, PixelFormat.R8G8B8A8_UNorm); _output.Init(ref desc); } if (_task == null) { _task = Object.New <SceneRenderTask>(); _task.Output = _output; _task.Begin += OnBegin; _task.End += OnEnd; } // Kick off the rendering _task.Enabled = true; }
/// <summary> /// Synchronizes size of the back buffer with the size of the control. /// </summary> public void SyncBackbufferSize() { float scale = ResolutionScale * Platform.DpiScale; int width = Mathf.CeilToInt(Width * scale); int height = Mathf.CeilToInt(Height * scale); if (_backBuffer == null || _backBuffer.Width == width && _backBuffer.Height == height) { return; } if (width < 1 || height < 1) { _backBuffer.ReleaseGPU(); Object.Destroy(ref _backBufferOld); return; } // Cache old backbuffer to remove flickering effect if (_backBufferOld == null && _backBuffer.IsAllocated) { _backBufferOld = _backBuffer; _backBuffer = GPUDevice.Instance.CreateTexture(); } // Set timeout to remove old buffer _oldBackbufferLiveTimeLeft = 3; // Resize backbuffer var desc = GPUTextureDescription.New2D(width, height, BackBufferFormat); _backBuffer.Init(ref desc); _task.Output = _backBuffer; }
public override void Initialize() { _output = GPUDevice.CreateTexture(); _cachedSize = SizeGetter(); var description = GPUTextureDescription.New2D(_cachedSize.X, _cachedSize.Y, PixelFormat.R8G8B8A8_UNorm); _output.Init(ref description); _outputPromise.SetResult(_output); Task.Render = OnRender; Task.Enabled = true; }
/// <inheritdoc /> public override void OnInit() { // Create cache folder if (!Directory.Exists(_cacheFolder)) { Directory.CreateDirectory(_cacheFolder); } // Find atlases in a Editor cache directory var files = Directory.GetFiles(_cacheFolder, "cache_*.flax", SearchOption.TopDirectoryOnly); int atlases = 0; for (int i = 0; i < files.Length; i++) { // Load asset var asset = FlaxEngine.Content.LoadAsync(files[i]); if (asset == null) { continue; } // Validate type if (asset is PreviewsCache atlas) { // Cache atlas atlases++; _cache.Add(atlas); } else { // Skip asset Editor.LogWarning(string.Format("Asset \'{0}\' is inside Editor\'s private directory for Assets Thumbnails Cache. Please move it.", asset.Path)); } } Editor.Log(string.Format("Previews cache count: {0} (capacity for {1} icons)", atlases, atlases * PreviewsCache.AssetIconsPerAtlas)); // Prepare at least one atlas if (_cache.Count == 0) { GetValidAtlas(); } // Create render task but disabled for now _output = GPUDevice.Instance.CreateTexture("ThumbnailsOutput"); var desc = GPUTextureDescription.New2D(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize, PreviewsCache.AssetIconsAtlasFormat); _output.Init(ref desc); _task = Object.New <RenderTask>(); _task.Order = 50; // Render this task later _task.Enabled = false; _task.Render += OnRender; }
public override void Initialize() { StringBuilder sb = new StringBuilder(512); ETrackedPropertyError error = ETrackedPropertyError.TrackedProp_Success; uint ret = _vrSystem.GetStringTrackedDeviceProperty( OVR.k_unTrackedDeviceIndex_Hmd, ETrackedDeviceProperty.Prop_TrackingSystemName_String, sb, 512u, ref error); if (error != ETrackedPropertyError.TrackedProp_Success) { _deviceName = "<Unknown OpenVR Device>"; } else { _deviceName = sb.ToString(); } uint eyeWidth = 0; uint eyeHeight = 0; _vrSystem.GetRecommendedRenderTargetSize(ref eyeWidth, ref eyeHeight); _leftEyeGT = GPUDevice.CreateTexture(); var descLeftEye = GPUTextureDescription.New2D((int)eyeWidth, (int)eyeHeight, 1, PixelFormat.R8G8B8A8_UNorm, msaaLevel: _options.EyeRenderTargetSampleCount); _leftEyeGT.Init(ref descLeftEye); _rightEyeGT = GPUDevice.CreateTexture(); var descRightEye = GPUTextureDescription.New2D((int)eyeWidth, (int)eyeHeight, 1, PixelFormat.R8G8B8A8_UNorm, msaaLevel: _options.EyeRenderTargetSampleCount); _rightEyeGT.Init(ref descRightEye); Matrix eyeToHeadLeft = ToSysMatrix(_vrSystem.GetEyeToHeadTransform(EVREye.Eye_Left)); Matrix.Invert(ref eyeToHeadLeft, out _headToEyeLeft); Matrix eyeToHeadRight = ToSysMatrix(_vrSystem.GetEyeToHeadTransform(EVREye.Eye_Right)); Matrix.Invert(ref eyeToHeadRight, out _headToEyeRight); // Default RH matrices /*_projLeft = ToSysMatrix(_vrSystem.GetProjectionMatrix(EVREye.Eye_Left, 0.1f, 10000f)); * _projRight = ToSysMatrix(_vrSystem.GetProjectionMatrix(EVREye.Eye_Right, 0.1f, 10000f));*/ // Build LH projection matrices (https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetProjectionRaw) float pLeft = 0; float pRight = 0; float pTop = 0; float pBottom = 0; // Default values float zNear = 0.1f; float zFar = 20000f; _vrSystem.GetProjectionRaw(EVREye.Eye_Left, ref pLeft, ref pRight, ref pTop, ref pBottom); _projLeft = Matrix.PerspectiveOffCenter(pLeft * zNear, pRight * zNear, pBottom * zNear * -1f, pTop * zNear * -1f, zNear, zFar); _vrSystem.GetProjectionRaw(EVREye.Eye_Right, ref pLeft, ref pRight, ref pTop, ref pBottom); _projRight = Matrix.PerspectiveOffCenter(pLeft * zNear, pRight * zNear, pBottom * zNear * -1f, pTop * zNear * -1f, zNear, zFar); }