function checkPrecision(source)
{
    if (!source) return '';

    const lines = source.split('\n');

    let commentOpen = false;

    for (let i = 0; i < lines.length; ++i)
    {
        const line = lines[i].trim();
        const firstChars = line.substring(0, 2);

        // line comment, ignore
        if (firstChars === '//') continue;

        // start of block comment, set flag
        if (firstChars === '/*')
        {
            commentOpen = true;
        }

        // if comment open, check if this line ends it. If not continue
        if (commentOpen)
        {
            if (line.indexOf('*/') !== -1)
            {
                commentOpen = false;
            }

            continue;
        }

        // not in a comment, check if precision is set
        if (line.substring(0, 9) !== 'precision')
        {
            return `precision ${Shader.PRECISION.DEFAULT} float;\n\n${source}`;
        }
    }

    return source;
}
/**
 * Ensures that the source of the program has precision specified.
 *
 * @ignore
 * @param {string} source - The source to check.
 * @return {string} The potentially modified source.
 */
Ensures that the source of the program has precision specified.
@ignore
@param {string} source - The source to check.
@return {string} The potentially modified source.
Ensures that the source of the program has precision specified . @ignore @param { string } source - The source to check . @return { string } The potentially modified source .
function checkPrecision(source)
{
    if (!source) return '';
    const lines = source.split('\n');
    let commentOpen = false;
    for (let i = 0; i < lines.length; ++i)
    {
        const line = lines[i].trim();
        const firstChars = line.substring(0, 2);
        if (firstChars === '//') continue;
        if (firstChars === '/*')
        {
            commentOpen = true;
        }
        if (commentOpen)
        {
            if (line.indexOf('*/') !== -1)
            {
                commentOpen = false;
            }
            continue;
        }
        if (line.substring(0, 9) !== 'precision')
        {
            return `precision ${Shader.PRECISION.DEFAULT} float;\n\n${source}`;
        }
    }
    return source;
}
function checkPrecision ( source ) { if ( ! source ) return '' ; const lines = source . split ( '\n' ) ; let commentOpen = false ; for ( let i = 0 ; i < lines . length ; ++ i ) { const line = lines [ i ] . trim ( ) ; const firstChars = line . substring ( 0 , 2 ) ; if ( firstChars === '//' ) continue ; if ( firstChars === '/*' ) { commentOpen = true ; } if ( commentOpen ) { if ( line . indexOf ( '*/' ) !== - 1 ) { commentOpen = false ; } continue ; } if ( line . substring ( 0 , 9 ) !== 'precision' ) { return ` ${ Shader . PRECISION . DEFAULT } \n \n ${ source } ` ; } } return source ; }
Ensures that the source of the program has precision specified.
Ensures that the source of the program has precision specified .
// line comment, ignore // start of block comment, set flag // if comment open, check if this line ends it. If not continue // not in a comment, check if precision is set