Exemple #1
0
        /// <summary>
        /// Function to unbind a constant buffer from all shaders.
        /// </summary>
        /// <param name="constantBuffer">The constant buffer to unbind.</param>
        internal void UnbindConstantBuffer(GorgonConstantBuffer constantBuffer)
        {
            PixelShader.ConstantBuffers.Unbind(constantBuffer);
            VertexShader.ConstantBuffers.Unbind(constantBuffer);
            if (GeometryShader != null)
            {
                GeometryShader.ConstantBuffers.Unbind(constantBuffer);
            }
            if (ComputeShader != null)
            {
                ComputeShader.ConstantBuffers.Unbind(constantBuffer);
            }
            if (HullShader != null)
            {
                HullShader.ConstantBuffers.Unbind(constantBuffer);
            }
            if (DomainShader != null)
            {
                DomainShader.ConstantBuffers.Unbind(constantBuffer);
            }

            // 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.UnbindConstantBuffer(constantBuffer);
            }
        }
Exemple #2
0
        /// <summary>
        /// Function to create a constant buffer.
        /// </summary>
        /// <param name="name">The name of the constant buffer.</param>
        /// <param name="settings">The settings for the buffer.</param>
        /// <param name="stream">[Optional] Stream used to initialize the buffer.</param>
        /// <returns>A new constant buffer.</returns>
        /// <remarks>The size of the buffer must be a multiple of 16.
        /// <para>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="settings"/> parameter is NULL.</para>
        /// </exception>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception>
        /// <exception cref="System.DataMisalignedException">Thrown when the <see cref="GorgonLibrary.Graphics.GorgonConstantBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is not a multiple of 16.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the buffer size is less than 16 bytes.</exception>
        public GorgonConstantBuffer CreateConstantBuffer(string name, GorgonConstantBufferSettings settings, GorgonDataStream stream = null)
        {
            if (_graphics.IsDeferred)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT);
            }

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

            if ((settings.Usage == BufferUsage.Immutable) && ((stream == null) || (stream.Length == 0)))
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA);
            }

            ValidateConstantBufferSettings(settings);

            var buffer = new GorgonConstantBuffer(_graphics, name, settings);

            buffer.Initialize(stream);

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