Esempio n. 1
0
    private RenderTexture RenderPreview(Noesis.View view, int width, int height)
    {
        try
        {
            if (CanRender() && view != null && view.Content != null)
            {
                NoesisRenderer.SetRenderSettings();

                view.SetSize(width, height);
                view.Update(0.0f);

                FlushMetalEncoder(_commands);
                NoesisRenderer.RenderOffscreen(view, _commands);

                RenderTexture rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 8);
                _commands.SetRenderTarget(rt);
                _commands.ClearRenderTarget(true, true, UnityEngine.Color.clear, 0.0f);
                NoesisRenderer.RenderOnscreen(view, false, _commands);

                Graphics.ExecuteCommandBuffer(_commands);
                _commands.Clear();
                GL.InvalidateState();

                RenderTexture.ReleaseTemporary(rt);
                return(rt);
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }

        return(null);
    }
Esempio n. 2
0
    void RenderOffscreen()
    {
        if (_uiView != null && _visible)
        {
            NoesisRenderer.RenderOffscreen(_uiView);

            // Unity should restore the render target at this point but sometimes (for example a scene without lights)
            // it doesn't. We use this hack to flush the active render target and force unity to set the camera RT afterward
            RenderTexture surface = RenderTexture.GetTemporary(1, 1);
            Graphics.SetRenderTarget(surface);
            RenderTexture.ReleaseTemporary(surface);
        }
    }
Esempio n. 3
0
    private void ExternalUpdateInternal()
    {
        if (_uiView != null && _visible)
        {
#if UNITY_EDITOR
            // Make sure render queue is flushed to avoid memory growing
            // Under normal circumstances this counter will be 0, but if for example we are in
            // Play mode and the Game view is hidden (by switching to Scene View) then we need to
            // force an Update in the render to clear the queue
            if (_pendingUpdates > 4)
            {
                RenderOffscreen();
            }
#endif
            UpdateSize();
            UpdateInputs();
            NoesisUnity.IME.Update(_uiView);
            NoesisUnity.TouchKeyboard.Update();
            Noesis_UnityUpdate();
            _needsRendering = _uiView.Update(_useRealTimeClock ? Time.realtimeSinceStartup : Time.time);

            if (_camera == null && _texture != null)
            {
                if (_continuousRendering || _needsRendering)
                {
                    _commands.name = "Noesis.Texture";
                    NoesisRenderer.RenderOffscreen(_uiView, _commands);
                    _commands.SetRenderTarget(_texture, LoadAction.DontCare, StoreAction.Store, LoadAction.DontCare, StoreAction.DontCare);
                    _commands.ClearRenderTarget(true, true, UnityEngine.Color.clear, 0.0f);
                    NoesisRenderer.RenderOnscreen(_uiView, !IsGL(), _commands);
                    Graphics.ExecuteCommandBuffer(_commands);
                    _commands.Clear();

                    GL.InvalidateState();
                    _texture.DiscardContents(false, true);
                }
            }
        #if UNITY_EDITOR
            else
            {
                if (_needsRendering)
                {
                    _pendingUpdates++;
                }
            }
        #endif
        }
    }
Esempio n. 4
0
    private void RenderOffscreen()
    {
        if (_uiView != null && _visible)
        {
            _commands.name = "Noesis.Offscreen";
            NoesisRenderer.RenderOffscreen(_uiView, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();

            GL.InvalidateState();
            ForceRestoreCameraRenderTarget();

        #if UNITY_EDITOR
            _pendingUpdates = 0;
        #endif
        }
    }
    private void OnPreRender()
    {
        if (_uiView != null && _visible)
        {
            _commands.Clear();
            _commands.name = "NoesisView_Offscreen";
            NoesisRenderer.RenderOffscreen(_uiView, _commands);
            Graphics.ExecuteCommandBuffer(_commands);

            // CommandBuffer.IssuePluginEventAndData does not invalidate state (CommandBuffer.IssuePluginEvent does)
            GL.InvalidateState();

            // Unity should restore the render target at this point but sometimes (for example a scene without lights)
            // it doesn't. We use this hack to flush the active render target and force unity to set the camera RT afterward
            RenderTexture surface = RenderTexture.GetTemporary(1, 1);
            Graphics.SetRenderTarget(surface);
            RenderTexture.ReleaseTemporary(surface);
        }
    }
Esempio n. 6
0
    private void BeginCameraRendering(ScriptableRenderContext context, Camera camera)
    {
        if (_camera == camera)
        {
            if (_uiView != null && _visible)
            {
                _commands.name = "Noesis.Offscreen";
                NoesisRenderer.RenderOffscreen(_uiView, _commands);
                context.ExecuteCommandBuffer(_commands);
                _commands.Clear();

                context.Submit();
                GL.InvalidateState();
                ForceRestoreCameraRenderTarget();

            #if UNITY_EDITOR
                _pendingUpdates = 0;
            #endif
            }
        }
    }