Exemplo 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);
    }
Exemplo n.º 2
0
 private void DestroyView()
 {
     if (_uiView != null)
     {
         NoesisRenderer.Shutdown(_uiView);
         _uiView = null;
     }
 }
Exemplo n.º 3
0
    private void CreateView(FrameworkElement content)
    {
        if (_uiView == null)
        {
            // Send settings for the internal device, created by the first view
            SetRenderSettings();

            _uiView = new Noesis.View(content);
            NoesisRenderer.RegisterView(_uiView);
        }
    }
Exemplo n.º 4
0
    private void DestroyView()
    {
        if (_uiView != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_uiView, _commands);
            Graphics.ExecuteCommandBuffer(_commands);

            _uiView = null;
        }
    }
    public void OnDisable()
    {
        if (_viewPreview != null)
        {
            NoesisRenderer.Shutdown(_viewPreview);
        }

        if (_viewPreviewGUI != null)
        {
            NoesisRenderer.Shutdown(_viewPreviewGUI);
        }
    }
Exemplo n.º 6
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);
        }
    }
Exemplo n.º 7
0
        protected NoesisShader CreateShader()
        {
            string       name   = GetType().Name.Replace("Effect", ".noesiseffect");
            NoesisShader shader = NoesisShaderProvider.instance.GetShader(name);

            if (shader != null)
            {
                shader.effect = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Custom_Effect, shader.effect_bytecode);
                return(shader);
            }

            Log.Error($"Can't find asset '{name}' for class '{GetType().Name}'");
            return(null);
        }
Exemplo n.º 8
0
    private void CreateView(FrameworkElement content)
    {
        if (_uiView == null)
        {
            // Send settings for the internal device, created by the first view
            SetRenderSettings();

            _uiView = new Noesis.View(content);

            _commands.Clear();
            NoesisRenderer.RegisterView(_uiView, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }
    }
Exemplo n.º 9
0
    private void RenderOnscreen()
    {
        if (_uiView != null && _visible)
        {
            _commands.name = "Noesis.Onscreen";
            NoesisRenderer.RenderOnscreen(_uiView, FlipRender(), _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();

            GL.InvalidateState();

            _updatePending = true;
        }
    }
Exemplo n.º 10
0
    void OnPostRender()
    {
        if (_uiView != null && _visible)
        {
            NoesisRenderer.RenderOnscreen(_uiView, FlipRender());

            if (_texture != null)
            {
                _texture.DiscardContents(false, true);
            }

            _updatePending = true;
        }
    }
Exemplo n.º 11
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
        }
    }
Exemplo n.º 12
0
    public void OnDisable()
    {
        if (_viewPreview != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_viewPreview, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }

        if (_viewPreviewGUI != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_viewPreviewGUI, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }
    }
Exemplo n.º 13
0
    private void EndCameraRendering(ScriptableRenderContext context, Camera camera)
    {
        if (_camera == camera)
        {
            if (_uiView != null && _visible)
            {
                _commands.name = "Noesis.Onscreen";
                NoesisRenderer.RenderOnscreen(_uiView, FlipRender(), _commands);
                context.ExecuteCommandBuffer(_commands);
                _commands.Clear();

                // This Submit() is generating 'Missing Profiler.EndSample' when profiling under HDRP (Reported Case 1287027)
                context.Submit();
                GL.InvalidateState();
            }
        }
    }
Exemplo n.º 14
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 CreateViewIcon()
    {
        try
        {
            FrameworkElement root = GetRootIcon();
            _viewIcon = Noesis.GUI.CreateView(root);
            _viewIcon.SetFlags(IsGL() ? 0 : RenderFlags.FlipY);

            _commands.Clear();
            NoesisRenderer.RegisterView(_viewIcon, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }
Exemplo n.º 16
0
    void OnPostRender()
    {
        if (_uiView != null && _visible)
        {
            _commands.Clear();
            _commands.name = "NoesisView_Onscreen";
            NoesisRenderer.RenderOnscreen(_uiView, FlipRender(), _commands);
            Graphics.ExecuteCommandBuffer(_commands);

            GL.InvalidateState();

            if (_texture != null)
            {
                _texture.DiscardContents(false, true);
            }
        }
    }
Exemplo n.º 17
0
        protected NoesisShader CreateShader()
        {
            string       name   = GetType().Name.Replace("Brush", ".noesisbrush");
            NoesisShader shader = NoesisShaderProvider.instance.GetShader(name);

            if (shader != null)
            {
                shader.brush_path    = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Path_Pattern, shader.brush_path_bytecode);
                shader.brush_path_aa = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Path_AA_Pattern, shader.brush_path_aa_bytecode);
                shader.brush_sdf     = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.SDF_Pattern, shader.brush_sdf_bytecode);
                shader.brush_opacity = NoesisRenderer.CreatePixelShader((byte)Shader.Enum.Opacity_Pattern, shader.brush_opacity_bytecode);
                return(shader);
            }

            Log.Error($"Can't find asset '{name}' for class '{GetType().Name}'");
            return(null);
        }
Exemplo n.º 18
0
    private void CreatePreviewView()
    {
        try
        {
            NoesisXaml       xaml = (NoesisXaml)target;
            FrameworkElement root = xaml.Load() as FrameworkElement;
            _viewPreview = Noesis.GUI.CreateView(root);
            _viewPreview.SetFlags(IsGL() ? 0 : RenderFlags.FlipY);

            NoesisRenderer.RegisterView(_viewPreview, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }
Exemplo n.º 19
0
    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);
        }
    }
Exemplo n.º 20
0
    private void CreatePreviewGUIView()
    {
        try
        {
            NoesisXaml       xaml  = (NoesisXaml)target;
            FrameworkElement root  = xaml.Load() as FrameworkElement;
            View.RenderFlags flags = DeviceIsD3D() ? View.RenderFlags.FlipY : 0;

            if (root != null)
            {
                _viewPreviewGUI = Noesis.GUI.CreateView(root);
                _viewPreviewGUI.SetFlags(flags);
                NoesisRenderer.RegisterView(_viewPreviewGUI);
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }
Exemplo n.º 21
0
    private void CreateView(FrameworkElement content)
    {
        if (_uiView == null)
        {
            // Send settings for the internal device, created by the first view
            NoesisRenderer.SetRenderSettings();

            _uiView = new Noesis.View(content);
            _uiView.SetTessellationMaxPixelError(_tessellationMaxPixelError);
            _uiView.SetFlags(_renderFlags);

            _commands.name = "";
            NoesisRenderer.RegisterView(_uiView, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();

        #if UNITY_EDITOR
            UnityEditor.AssemblyReloadEvents.beforeAssemblyReload += DestroyView;
        #endif
        }
    }
    public void OnDisable()
    {
        if (_view != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_view, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }

        if (_viewIcon != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_viewIcon, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
        }

        if (NoesisSettings.IsNoesisEnabled())
        {
            UnregisterFont();
        }
    }
Exemplo n.º 23
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
            }
        }
    }
Exemplo n.º 24
0
    private void CreatePreviewGUIView()
    {
        // Avoid logging parse errors twice by muting them when generating thumbnails
        NoesisUnity.MuteLog();

        try
        {
            NoesisXaml       xaml = (NoesisXaml)target;
            FrameworkElement root = xaml.Load() as FrameworkElement;
            _viewPreviewGUI = Noesis.GUI.CreateView(root);
            _viewPreviewGUI.SetFlags(IsGL() ? 0 : RenderFlags.FlipY);

            NoesisRenderer.RegisterView(_viewPreviewGUI, _commands);
            Graphics.ExecuteCommandBuffer(_commands);
            _commands.Clear();
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }

        NoesisUnity.UnmuteLog();
    }
    public override void OnPreviewSettings()
    {
        string[] options = new string[_faces.Count];
        int[]    values  = new int[_faces.Count];

        for (int i = 0; i < _faces.Count; i++)
        {
            options[i] = "Face " + i;
            values[i]  = i;
        }

        int index = EditorGUILayout.IntPopup(_index, options, values);

        if (index != _index && _view != null)
        {
            _commands.Clear();
            NoesisRenderer.UnregisterView(_view, _commands);
            Graphics.ExecuteCommandBuffer(_commands);

            _index = index;
            CreateView();
        }
    }