Exemplo n.º 1
0
        /// <summary>
        /// Loads and pre-processes a shader source file.
        /// </summary>
        /// <param name="assetManager">The AssetManager to be used to resolve the asset paths.</param>
        /// <param name="shaderPath">The path of the shader source file.</param>
        /// <param name="shaderIncludePaths">The resulting list of included file paths referenced by the shader.</param>
        public static string Process(AssetManager assetManager,
                                     string shaderPath,
                                     out List <string> shaderIncludePaths)
        {
            // Uses ZString as a StringBuilder alternative to reduce heap allocations.
            // Uses ReadOnlyMemory<char> instead of string where possible for slightly better performance.

            // TODO: This needs more testing with larger asset libraries down the road.
            // System.Text.StringBuilder is slightly faster in my testing, but uses a lot more heap allocations.
            // If the time difference is non-negligible for larger asset files, it may be beneficial to switch back to
            // System.Text.StringBuilder since shaders are only pre-processed when they're loaded, so the heap
            // allocations aren't really an issue.

            Utf16ValueStringBuilder stringBuilder = ZString.CreateStringBuilder();

            shaderIncludePaths = new List <string>();

            PreprocessShaderSource(assetManager,
                                   ref stringBuilder,
                                   shaderPath,
                                   shaderIncludePaths = new List <string>(),
                                   new Stack <string>());

            string result = stringBuilder.ToString();

            return(result);
        }
Exemplo n.º 2
0
 public override string ToString()
 {
     return(_sb.ToString());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Converts the value of this instance to a system.String.
 /// </summary>
 /// <remarks>
 /// <see cref="Utf16ValueStringBuilder"/> creates the string from the buffer.
 /// Using <i>string.Create</i> here does not bring better results.
 /// </remarks>
 public override string ToString() => _vsb.ToString();