Exemplo n.º 1
0
        void SetCustomPassTarget(CommandBuffer cmd, RenderTargets targets)
        {
            RTHandle colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? targets.customColorBuffer : targets.cameraColorBuffer;
            RTHandle depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? targets.customDepthBuffer : targets.cameraDepthBuffer;

            CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, clearFlags);
        }
Exemplo n.º 2
0
        private void Update(EvaluationContext context)
        {
            BlendState.Value?.Dispose();
            var blendDesc = new BlendStateDescription()
            {
                AlphaToCoverageEnable  = AlphaToCoverageEnable.GetValue(context),
                IndependentBlendEnable = IndependentBlendEnable.GetValue(context),
            };

            if (RenderTargets.DirtyFlag.IsDirty)
            {
                _connectedDescriptions = RenderTargets.GetCollectedTypedInputs();
                RenderTargets.DirtyFlag.Clear();
            }

            for (int i = 0; i < _connectedDescriptions.Count; i++)
            {
                blendDesc.RenderTarget[i] = _connectedDescriptions[i].GetValue(context);
            }

            try
            {
                BlendState.Value = new BlendState(ResourceManager.Instance().Device, blendDesc); // todo: put into resource manager
            }
            catch (SharpDXException e)
            {
                Log.Error("Failed to create BlendState " + e.Message);
            }
        }
Exemplo n.º 3
0
        internal void ExecuteInternal(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResult, SharedRTManager rtManager, RenderTargets targets, CustomPassVolume owner)
        {
            this.owner               = owner;
            this.currentRTManager    = rtManager;
            this.currentRenderTarget = targets;
            this.currentHDCamera     = hdCamera;

            if (!isSetup)
            {
                Setup(renderContext, cmd);
                isSetup = true;
            }

            SetCustomPassTarget(cmd, targets);

            isExecuting = true;
            Execute(renderContext, cmd, hdCamera, cullingResult);
            isExecuting = false;

            // Set back the camera color buffer is we were using a custom buffer as target
            if (targetDepthBuffer != TargetBuffer.Camera)
            {
                CoreUtils.SetRenderTarget(cmd, targets.cameraColorBuffer);
            }
        }
Exemplo n.º 4
0
 public static void RunPostProcess(ref RenderTargets targets, out RenderTargetIdentifier source, out RenderTargetIdentifier dest)
 {
     source = targets.renderTargetIdentifier;
     dest   = targets.backupIdentifier;
     targets.backupIdentifier       = targets.renderTargetIdentifier;
     targets.renderTargetIdentifier = dest;
 }
Exemplo n.º 5
0
 public ResourceInfo(string filePath, ResourceTypes resourceType, RenderTargets renderTarget, int sequence, Environments environment, bool debug = false)
 {
     Environment  = environment;
     Path         = filePath;
     Type         = resourceType;
     RenderTarget = renderTarget;
     Sequence     = sequence;
     Debug        = debug;
 }
Exemplo n.º 6
0
    public static void RunPostProcess(ref RenderTargets targets, out int source, out int dest)
    {
        source = targets.renderTargetIdentifier;
        dest   = targets.backupIdentifier;
        int back = targets.backupIdentifier;

        targets.backupIdentifier       = targets.renderTargetIdentifier;
        targets.renderTargetIdentifier = back;
    }
Exemplo n.º 7
0
        void SetCustomPassTarget(CommandBuffer cmd, RenderTargets targets)
        {
            var cameraColorBuffer = IsMSAAEnabled(currentHDCamera) ? targets.cameraColorMSAABuffer : targets.cameraColorBuffer;

            RTHandle colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? targets.customColorBuffer : cameraColorBuffer;
            RTHandle depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? targets.customDepthBuffer : targets.cameraDepthBuffer;

            CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, clearFlags);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Pushes this render target on the given render state.
        /// </summary>
        /// <param name="renderState">The render state to push to.</param>
        /// <param name="mode"></param>
        internal void PushOnRenderState(RenderState renderState, PushRenderTargetMode mode)
        {
            // Store RenderTargets structures
            var prevRenderTargets = renderState.CurrentRenderTargets;
            var newRenderTargets  = new RenderTargets();

            // Handle color buffer
            if (mode.HasFlag(PushRenderTargetMode.UseOwnColorBuffer))
            {
                newRenderTargets.ColorBuffer = _colorBufferRenderTargetView;
            }
            else if (mode.HasFlag(PushRenderTargetMode.OvertakeColorBuffer))
            {
                newRenderTargets.ColorBuffer = prevRenderTargets.ColorBuffer;
            }

            // Handle depth-stencil buffer
            if (mode.HasFlag(PushRenderTargetMode.UseOwnDepthBuffer))
            {
                newRenderTargets.DepthStencilBuffer = _depthBufferView;
            }
            else if (mode.HasFlag(PushRenderTargetMode.OvertakeDepthBuffer))
            {
                newRenderTargets.DepthStencilBuffer = prevRenderTargets.DepthStencilBuffer;
            }

            // Handle object-id buffer
            if (mode.HasFlag(PushRenderTargetMode.UseOwnObjectIdBuffer))
            {
                newRenderTargets.ObjectIdBuffer = _objectIdBufferRenderTargetView;
            }
            else if (mode.HasFlag(PushRenderTargetMode.OvertakeObjectIdBuffer))
            {
                newRenderTargets.ObjectIdBuffer = prevRenderTargets.ObjectIdBuffer;
            }

            // Handle normal-depth buffer
            if (mode.HasFlag(PushRenderTargetMode.UseOwnNormalDepthBuffer))
            {
                newRenderTargets.NormalDepthBuffer = _normalDepthBufferRenderTargetView;
            }
            else if (mode.HasFlag(PushRenderTargetMode.OvertakeNormalDepthBuffer))
            {
                newRenderTargets.NormalDepthBuffer = prevRenderTargets.NormalDepthBuffer;
            }

            // Push new RenderTargets structure onto the rendering stack
            renderState.PushRenderTarget(
                newRenderTargets,
                _viewportF, renderState.Camera !, renderState.ViewInformation !);
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     foreach (var rt in RenderTargets)
     {
         rt.Dispose();
     }
     RenderTargets.Clear();
     if (DepthStencilState != null)
     {
         DepthStencilState.Dispose();
         DepthStencilState = null;
     }
     if (DepthStencilView != null)
     {
         DepthStencilView.Dispose();
         DepthStencilView = null;
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Adds one or more scripts (usually JavaScript) to a view if they have not been added already.
        /// </summary>
        /// <param name="renderTarget">Where to render the scripts.</param>
        /// <param name="scriptPaths">One or more script path URIs to add to the page.</param>
        public IHtmlContent Scripts(RenderTargets renderTarget, params string[] scriptPaths)
        {
            List <string> results = new List <string>();

            foreach (var path in scriptPaths)
            {
                var _ = Script(path, renderTarget).Render();
                if (!string.IsNullOrWhiteSpace(_))
                {
                    results.Add(_);
                }
            }
            if (results.Count == 0)
            {
                return(HtmlString.Empty);
            }
            return(new HtmlString(string.Join(string.Empty, results)));
        }
Exemplo n.º 11
0
        internal void ExecuteInternal(ScriptableRenderContext renderContext, CommandBuffer cmd, HDCamera camera, CullingResults cullingResult, RenderTargets targets)
        {
            if (!isSetup)
            {
                Setup(renderContext, cmd);
                isSetup = true;
            }

            SetCustomPassTarget(cmd, targets);

            currentRenderTarget = targets;
            isExecuting         = true;
            Execute(renderContext, cmd, camera, cullingResult);
            isExecuting = false;

            // Set back the camera color buffer is we were using a custom buffer as target
            if (targetDepthBuffer != TargetBuffer.Camera)
            {
                CoreUtils.SetRenderTarget(cmd, targets.cameraColorBuffer);
            }
        }
Exemplo n.º 12
0
 public RenderTargetView[] GetRenderTargetViews()
 {
     return(RenderTargets.Select(rt => rt.View).ToArray());
 }
Exemplo n.º 13
0
        public void AddRenderTarget(Texture2D tex)
        {
            var rtv = new RenderTarget(tex);

            RenderTargets.Add(rtv);
        }
Exemplo n.º 14
0
        public void AddRenderTarget(Format format)
        {
            var rtv = new RenderTarget(Width, Height, format);

            RenderTargets.Add(rtv);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Adds a resource to be output to the page.
        /// If the resource is already added then the matching resource is returned instead.
        /// </summary>
        /// <param name="resourcePath">A URI to the script to add to the page.</param>
        /// <param name="resourceType">The type of the resource returned from the given resource path.</param>
        /// <param name="renderTarget">Where to render the resource.</param>
        /// <param name="sequence">The order in which to render the resource in relation to other resources.</param>
        /// <param name="environment">One or more environments in which to render the resource.</param>
        /// <param name="debug">If true, outputs debug information as comments during rendering, otherwise nothing is output.</param>
        /// <returns>An existing resource if one matches, or a new resource if not.</returns>
        public virtual ResourceInfo Add(string resourcePath, ResourceTypes resourceType, RenderTargets renderTarget, int sequence, Environments environment = Environments.Any, bool debug = false)
        {
            // ... check if this exists first ...

            var resinfo = Find(null, resourcePath, _ActionContext);

            if (resinfo == null)
            {
                _Resources.Add(resinfo = new ResourceInfo(resourcePath, resourceType, renderTarget, sequence, environment, debug));
            }

            return(resinfo);
        }
Exemplo n.º 16
0
        // --------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Adds a script (usually JavaScript) to a view if it has not been added already.
        /// </summary>
        /// <param name="name">An name to use to represent this resource.  Typically this should be the file name and extension of the resource (minus any path information).
        /// You can use the other overloaded method to skip adding a name, and the resource path and file name (if any) will be used instead.
        /// If the name or resource path contains the typical ".min." name part, it will be ignored to make comparisons more consistent.
        /// </param>
        /// <param name="scriptPath">A URI to the script to add to the page.</param>
        /// <param name="renderTarget">Where to render the script.</param>
        public ResourceInfo Script(string name, string scriptPath, RenderTargets renderTarget = RenderTargets.Header)
        {
            return(XT.RequireResource(name, scriptPath, ResourceTypes.Script, renderTarget));
        }
Exemplo n.º 17
0
        public DynamicCubemap(int cubemapsize)
        {
            CubeMapSize = cubemapsize;

            // On commence par initialiser la description de la texture qui sera mise
            // à jour par cette classe
            TextureDescription = new Texture2DDescription()
            {
                Width             = CubeMapSize,
                Height            = CubeMapSize,
                MipLevels         = 0,
                ArraySize         = 6,          // Comme on cherche à créer une cubemap, ArraySize est à 6
                Format            = Format.R32G32B32A32_Float,
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube,
                SampleDescription = new SampleDescription
                {
                    Count   = 1,
                    Quality = 0
                }
            };

            //Création de la texture
            Texture = new Texture2D
                      (
                ApplicationDX11.Instance.Device,
                TextureDescription
                      );

            // Création d'un renderTargetDescription qui sera utilisé
            // par tout les autres RenderTargetView
            RenderTargetViewDescription rtvDesc = new RenderTargetViewDescription()
            {
                Format         = TextureDescription.Format,
                Dimension      = RenderTargetViewDimension.Texture2DArray,
                Texture2DArray = new RenderTargetViewDescription.Texture2DArrayResource()
                {
                    MipSlice  = 0,
                    ArraySize = 1,
                }
            };

            // Initialisation des 6 renderTargetView
            for (int i = 0; i < 6; i++)
            {
                // On utilise FirstArraySlice pour préciser sur quel "Slice", ou Texture,
                // on se trouve
                rtvDesc.Texture2DArray.FirstArraySlice = i;
                RenderTargetViews.Add(new RenderTargetView(ApplicationDX11.Instance.Device, Texture, rtvDesc));
            }

            // Initialisation du ShaderResourceView
            ShaderResourceViewDescription SRVDescription = new ShaderResourceViewDescription()
            {
                Format    = TextureDescription.Format,
                Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels       = 1,
                    MostDetailedMip = 0
                }
            };

            SRV = new ShaderResourceView(ApplicationDX11.Instance.Device, Texture, SRVDescription);

            // Création des renderTarget

            foreach (RenderTargetView view in RenderTargetViews)
            {
                RenderTargets.Add(new RenderTarget(view, CubeMapSize, CubeMapSize));
            }

            // Création de la transformation

            Transform = new Transform();

            // Création des caméras

            for (int i = 0; i < 6; i++)
            {
                Entity entity = new Entity();
                Camera cam    = entity.AddComponent <Camera>();

                cam.Initialize(new FrustumProjection(3.141592f / 2.0f, 1.0f, 0.1f, 1000.0f));
                cam.SetViewport(0, 0, CubeMapSize, cubemapsize);
                Cameras.Add(cam);
            }

            // Right Camera

            Cameras[0].m_transform.LookAt(new Vector3(1.0f, 0.0f, 0.0F), Transform.position_);

            // Left Camera

            Cameras[1].m_transform.LookAt(new Vector3(-1.0f, 0.0f, 0.0F), Transform.position_);

            // Up Camera

            Cameras[2].m_transform.LookAt(Vector3.Up + new Vector3(0.0f, 0.0f, 0.00001f), Transform.position_);

            // Down Camera

            Cameras[3].m_transform.LookAt(Vector3.Down + new Vector3(0.0f, 0.0f, 0.00001f), Transform.position_);

            // Forward Camera

            Cameras[4].m_transform.LookAt(Vector3.ForwardLH, Transform.position_);

            // Backward Camera

            Cameras[5].m_transform.LookAt(Vector3.BackwardLH, Transform.position_);

            ApplicationDX11.Instance.Cubemaps.Add(this);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Adds a CSS reference to a view if it has not been added already.
 /// </summary>
 /// <param name="cssPath">A URI to the script to add to the page.</param>
 /// <param name="renderTarget">Where to render the script.</param>
 public ResourceInfo CSS(string cssPath, RenderTargets renderTarget = RenderTargets.Header)
 {
     return(CSS(null, cssPath, renderTarget));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Adds a CSS reference to a view if it has not been added already.
 /// </summary>
 /// <param name="name">An name to use to represent this resource.  Typically this should be the file name and extension of the resource (minus any path information).
 /// You can use the other overloaded method to skip adding a name, and the resource path and file name (if any) will be used instead.
 /// If the name or resource path contains the typical ".min." name part, it will be ignored to make comparisons more consistent.
 /// </param>
 /// <param name="cssPath">A URI to the script to add to the page.</param>
 /// <param name="renderTarget">Where to render the script.</param>
 public ResourceInfo CSS(string name, string cssPath, RenderTargets renderTarget = RenderTargets.Header)
 {
     return(XT.RequireResource(name, cssPath, ResourceTypes.CSS, renderTarget));
 }
Exemplo n.º 20
0
        // -------------------------------------------------------------------------------------------------------------------

        public ResourceInfo SetTarget(RenderTargets target)
        {
            RenderTarget = target;
            return(this);
        }
Exemplo n.º 21
0
 /// <summary> Adds a required script (usually JavaScript) to this component, if it has not been added already. </summary>
 /// <typeparam name="T"> Generic type parameter. </typeparam>
 /// <param name="comp"> The comp to act on. </param>
 /// <param name="scriptPath"> A URI to the script to associated with this component. </param>
 /// <param name="renderTarget"> Where to render the script on a page when 'Render()' is called. </param>
 /// <param name="environment"> The environment. </param>
 /// <returns> Returns the type 'T' instance passed in as '<paramref name="comp"/>'. </returns>
 public static T RequireScript <T>(this T comp, string scriptPath, RenderTargets renderTarget, Environments environment)
     where T : class, ITagComponent
 {
     return(comp.RequireResource(scriptPath, ResourceTypes.Script, renderTarget, 0, environment));
 }
Exemplo n.º 22
0
 /// <summary> Adds a required script (usually JavaScript) to this component, if it has not been added already. </summary>
 /// <typeparam name="T"> Generic type parameter. </typeparam>
 /// <param name="comp"> The comp to act on. </param>
 /// <param name="scriptPath"> A URI to the script to associated with this component. </param>
 /// <param name="renderTarget"> (Optional) Where to render the script on a page when 'Render()' is called. </param>
 /// <param name="environmentName"> (Optional) Name of the environment. </param>
 /// <returns> A T. </returns>
 public static T RequireScript <T>(this T comp, string scriptPath, RenderTargets renderTarget = RenderTargets.Header, string environmentName = null)
     where T : class, IWebViewComponent
 {
     return(comp.RequireResource(scriptPath, ResourceTypes.Script, renderTarget, 0, environmentName));
 }
Exemplo n.º 23
0
        // --------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Adds a resource to a view if it has not been added yet.
        /// </summary>
        /// <param name="name">An name to use to represent this resource.  Typically this should be the file name and extension of the resource (minus any path information).</param>
        /// <param name="resourcePath">A URI to the script to add to the page.</param>
        /// <param name="resourceType">The type of the resource returned from the given resource path.</param>
        /// <param name="renderTarget">Where to render the resource.</param>
        public virtual ResourceInfo RequireResource(string name, string resourcePath, ResourceTypes resourceType, RenderTargets renderTarget = RenderTargets.Header)
        {
            var context = Page.Context;

            if (context == null)
            {
                throw new InvalidOperationException("RequireScript: No valid '{CDS}.View.Context' exists.");
            }

            // ... find the file location so we can validate based on the actual location of the file, and not a virtual path ...

            var actionContext = View.ViewContext;

            // ... next, update the global content resource list ...

            var resourceList = GetService <IResourceList>();

            if (resourceList == null)
            {
                throw new InvalidOperationException("The service type 'IResourceList' has no implementation (this is usually 'ResourceList').");
            }

            var resource = resourceList.Find(name, resourcePath, actionContext);

            if (resource == null)
            {
#if DEBUG
                var debug = true;
#else
                var debug = false;
#endif
                resource = resourceList.Add(name, resourcePath, resourceType, renderTarget, 0 /*x View.ActivationSequence*/, null, debug);
            }

            return(resource);
        }
Exemplo n.º 24
0
 /// <summary> Adds a required CSS reference to this component, if it has not been added already. </summary>
 /// <typeparam name="T"> Generic type parameter. </typeparam>
 /// <param name="comp"> The comp to act on. </param>
 /// <param name="cssPath"> A URI to the script to associated with this component. </param>
 /// <param name="renderTarget"> Where to render the CSS on a page when 'Render()' is called. </param>
 /// <param name="environment"> The environment. </param>
 /// <returns> A T. </returns>
 public static T RequireCSS <T>(this T comp, string cssPath, RenderTargets renderTarget, Environments environment)
     where T : class, IWebViewComponent
 {
     return(comp.RequireResource(cssPath, ResourceTypes.Script, renderTarget, 0, environment));
 }
Exemplo n.º 25
0
        /// <summary>
        ///     Adds a resource that is required for this component. If the resource is already added then the request is ignored.
        /// </summary>
        /// <exception cref="InvalidOperationException"> Thrown when the requested operation is invalid. </exception>
        /// <typeparam name="T"> Generic type parameter. </typeparam>
        /// <param name="comp"> The comp to act on. </param>
        /// <param name="resourcePath"> A URI to the script to add to the page. </param>
        /// <param name="resourceType"> The type of the resource returned from the given resource path. </param>
        /// <param name="renderTarget"> Where to render the resource. </param>
        /// <param name="sequence"> The sequence. </param>
        /// <param name="environment"> The environment. </param>
        /// <returns> A T. </returns>
        public static T RequireResource <T>(this T comp, string resourcePath, ResourceTypes resourceType, RenderTargets renderTarget, int sequence, Environments environment)
            where T : class, IWebViewComponent
        {
            if (comp.RequiredResources == null)
            {
                throw new InvalidOperationException("No view page was supplied for this component.");
            }

            comp.RequiredResources.Add(resourcePath, ResourceTypes.Script, renderTarget, sequence, environment);

            return(comp);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Adds a script (usually JavaScript) to a view if it has not been added already.
 /// </summary>
 /// <param name="scriptPath">A URI to the script to add to the page.</param>
 /// <param name="renderTarget">Where to render the script.</param>
 public ResourceInfo Script(string scriptPath, RenderTargets renderTarget = RenderTargets.Header)
 {
     return(Script(null, scriptPath, renderTarget));
 }