Beispiel #1
0
        /// <summary>
        /// Adds an attachment to the renderer description.
        /// </summary>
        /// <param name="attachment">The attachment description to add.</param>
        /// <returns>The same object, to faciliate chaining.</returns>
        public RendererDescription AddAttachment(AttachmentDescription attachment)
        {
            // Self-validation
            if (!attachment.TryValidate(out var error))
            {
                throw new ArgumentException($"Bad attachment description - {error}");
            }

            // Validate against other attachments
            if (_attachments.Count > 0)
            {
                if (attachment.SubpassCount != _attachments[^ 1].SubpassCount)
                {
                    throw new ArgumentException("Bad attachment description - wrong subpass count");
                }
                int aidx = 0;
                foreach (var att in _attachments)
                {
                    if (attachment.IsDepth && att.IsDepth)
                    {
                        var dupOut = att.Uses.Where((use, idx) => (use == AttachmentUse.Output) && (use == attachment.Uses[idx]));
                        if (dupOut.Any())
                        {
                            throw new ArgumentException("Bad attachment description - duplicate depth/stencil output");
                        }
                    }
                    ++aidx;
                }
            }

            // Add description and return
            _attachments.Add(attachment);
            return(this);
        }
Beispiel #2
0
 /// <summary>
 /// Starts a new renderer description with the given attachments.
 /// </summary>
 /// <param name="attachment">The first attachment of the description, which sets the subpass count.</param>
 /// <param name="otherAttachments">The additional attachment descriptions.</param>
 public RendererDescription(AttachmentDescription attachment, params AttachmentDescription[] otherAttachments)
 {
     _attachments = new(otherAttachments.Length + 1);
     AddAttachment(attachment);
     foreach (var att in otherAttachments)
     {
         AddAttachment(att);
     }
 }