예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonInputLayout"/> class.
 /// </summary>
 /// <param name="graphics">Graphics interface that created this object.</param>
 /// <param name="name">Name of the object.</param>
 /// <param name="shader">Vertex shader to bind the layout with.</param>
 internal GorgonInputLayout(GorgonGraphics graphics, string name, GorgonShader shader)
     : base(name)
 {
     Graphics = graphics;
     Shader   = shader;
     GorgonRenderStatistics.InputLayoutCount++;
 }
예제 #2
0
        /// <summary>
        /// Function to create an input layout object from a predefined type.
        /// </summary>
        /// <param name="name">The name of the input layout.</param>
        /// <param name="type">Type to evaluate.</param>
        /// <param name="shader">The shader that holds the input layout signature.</param>
        /// <returns>The input layout object to create.</returns>
        /// <exception cref="System.ArgumentException">Thrown when then <paramref name="name"/> parameter is an empty string.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="shader"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="type"/> parameter is NULL.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the name parameter is NULL.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the graphics context is deferred.</exception>
        /// <remarks>The shader parameter is used to compare input layout on the shader side with the input layout.  If the layout is mismatched, a warning will appear in the debug output.
        /// <para>Note that any shader can be used with the input layout as long as the shader contains the same layout for the input, i.e. there is no need to create a new layout for each shader if the element layouts are identical.</para>
        /// <para>This function should not be called from a deferred context.</para>
        /// </remarks>
        public GorgonInputLayout CreateInputLayout(string name, Type type, GorgonShader shader)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (shader == null)
            {
                throw new ArgumentNullException("shader");
            }

            var layout = new GorgonInputLayout(_graphics, name, shader);

            layout.InitializeFromType(type);

            _graphics.AddTrackedObject(layout);

            return(layout);
        }
예제 #3
0
        /// <summary>
        /// Function to re-seat a shader after it's been altered.
        /// </summary>
        /// <param name="shader">Shader to re-seat.</param>
        internal void Reseat(GorgonShader shader)
        {
            switch (shader.ShaderType)
            {
            case ShaderType.Vertex:
                if (VertexShader.Current == shader)
                {
                    VertexShader.Current = null;
                    VertexShader.Current = (GorgonVertexShader)shader;
                }
                break;

            case ShaderType.Pixel:
                if (PixelShader.Current == shader)
                {
                    PixelShader.Current = null;
                    PixelShader.Current = (GorgonPixelShader)shader;
                }
                break;

            case ShaderType.Geometry:
                if ((GeometryShader != null) && (GeometryShader.Current == shader))
                {
                    GeometryShader.Current = null;
                    GeometryShader.Current = (GorgonGeometryShader)shader;
                }
                break;

            case ShaderType.Compute:
                if ((ComputeShader != null) && (ComputeShader.Current == shader))
                {
                    ComputeShader.Current = null;
                    ComputeShader.Current = (GorgonComputeShader)shader;
                }
                break;

            case ShaderType.Hull:
                if ((HullShader != null) && (HullShader.Current == shader))
                {
                    HullShader.Current = null;
                    HullShader.Current = (GorgonHullShader)shader;
                }
                break;

            case ShaderType.Domain:
                if ((DomainShader != null) && (DomainShader.Current == shader))
                {
                    DomainShader.Current = null;
                    DomainShader.Current = (GorgonDomainShader)shader;
                }
                break;
            }

            // If we have multiple contexts, then we need to unbind from those as well.
            if ((_graphics.IsDeferred) || (_graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM5))
            {
                return;
            }

            foreach (var context in _graphics.GetTrackedObjectsOfType <GorgonGraphics>())
            {
                context.Shaders.Reseat(shader);
            }
        }
예제 #4
0
        /// <summary>
        /// Function to create an input layout object.
        /// </summary>
        /// <param name="name">The name of the input layout.</param>
        /// <param name="elements">The input elements to assign to the layout.</param>
        /// <param name="shader">The shader that holds the input layout signature.</param>
        /// <returns>The input layout object to create.</returns>
        /// <exception cref="System.ArgumentException">
        /// Thrown when then <paramref name="name"/> parameter is an empty string.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="elements"/> parameter is empty.</para>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="shader"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="elements"/> parameter is NULL.</para>
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="name"/> parameter is NULL.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the graphics context is deferred.</exception>
        /// <remarks>The shader parameter is used to compare input layout on the shader side with the input layout.  If the layout is mismatched, a warning will appear in the debug output.
        /// <para>Note that any shader can be used with the input layout as long as the shader contains the same layout for the input, i.e. there is no need to create a new layout for each shader if the element layouts are identical.</para>
        /// <para>This function should not be called from a deferred context.</para>
        /// </remarks>
        public GorgonInputLayout CreateInputLayout(string name, IList <GorgonInputElement> elements, GorgonShader shader)
        {
            if (_graphics.IsDeferred)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT);
            }

            if (shader == null)
            {
                throw new ArgumentNullException("shader");
            }

            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }

            if (elements.Count == 0)
            {
                throw new ArgumentException(Resources.GORGFX_PARAMETER_MUST_NOT_BE_EMPTY, "elements");
            }

            var layout = new GorgonInputLayout(_graphics, name, shader);

            layout.InitializeFromList(elements);

            _graphics.AddTrackedObject(layout);
            return(layout);
        }