Exemple #1
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            this.comp = null;

            if (activeCamera != null)
            {
                activeCamera.renderCallback -= ReadCamera;
            }
            activeCamera = null;

            if (cameraTexture.IsCreated())
            {
                cameraTexture.Release();
            }
            UnityEngine.GameObject.Destroy(cameraTexture);
            cameraTexture = null;

            UnityEngine.GameObject.Destroy(imageObject);
            imageObject = null;
            UnityEngine.GameObject.Destroy(imageMaterial);
            imageMaterial = null;

            variableRegistrar.ReleaseResources();

            //if (renderFrames > 0)
            //{
            //    double msPerFrame = 1000.0 * (double)(renderStopwatch.ElapsedTicks) / (double)(renderFrames * Stopwatch.Frequency);
            //    Utility.LogMessage(this, "Camera page {0}: {1} frames rendered, {2:0.0}ms/frame",
            //        name, renderFrames, msPerFrame);
            //}
        }
Exemple #2
0
        /// <summary>
        /// Callback used to select active cameras
        /// </summary>
        private void CameraSelectCallback(double dontCare)
        {
            try
            {
                // This can return null at startup when the VC hasn't had a chance
                // to run.  Unfortunately, that means we have to call this callback
                // every time the camera should be enabled.
                MASCamera newCamera = comp.vc.FindCameraModule(cameraSelector.AsString());
                if (activeCamera != null)
                {
                    activeCamera.renderCallback -= ReadCamera;
                }
                activeCamera = newCamera;
                if (activeCamera != null)
                {
                    if (pageEnabled)
                    {
                        activeCamera.UpdateFlightComputer(comp);
                        activeCamera.renderCallback += ReadCamera;
                    }
                }
                else if (!coroutineActive)
                {
                    comp.StartCoroutine(CameraSelectCoroutine());
                }

                if (activeCamera == null)
                {
                    ApplyMissingCamera();
                }
            }
            catch
            {
                if (activeCamera != null)
                {
                    activeCamera.renderCallback -= ReadCamera;
                }

                activeCamera = null;
            }
        }
Exemple #3
0
        /// <summary>
        /// Callback to process the rentex sent by the camera.
        /// </summary>
        /// <param name="rentex">The source texture.</param>
        /// <param name="postProcShader">The post-processing shader applied by the current camera's active mode.</param>
        private void ReadCamera(RenderTexture rentex, Material postProcShader)
        {
            if (rentex == null)
            {
                activeCamera = null;
                return;
            }

            cameraTexture.DiscardContents();
            renderStopwatch.Start();
            if (monitorMaterial == null)
            {
                if (postProcShader == null)
                {
                    Graphics.Blit(rentex, cameraTexture);
                }
                else
                {
                    Graphics.Blit(rentex, cameraTexture, postProcShader);
                }
            }
            else
            {
                if (postProcShader == null)
                {
                    Graphics.Blit(rentex, cameraTexture, monitorMaterial);
                }
                else
                {
                    RenderTexture tmp = RenderTexture.GetTemporary(rentexWidth, rentexHeight, 24);
                    Graphics.Blit(rentex, tmp, postProcShader);
                    Graphics.Blit(tmp, cameraTexture, monitorMaterial);
                    tmp.Release();
                }
            }
            renderStopwatch.Stop();
            ++renderFrames;
        }