Repository: google/filament
File: libs/filamat/src/MaterialBuilder.cpp (C++)

Code before:
    }

    // Add a default color output.
    if (mMaterialDomain == MaterialDomain::POST_PROCESS && mOutputs.empty()) {
        output(VariableQualifier::OUT,
                OutputTarget::COLOR, Precision::DEFAULT, OutputType::FLOAT4, "color");
    }

    if (mMaterialDomain == MaterialDomain::SURFACE) {
        if (mRequiredAttributes[COLOR] &&
            !mVariables[int(Variable::CUSTOM4)].name.empty()) {
            // both the color attribute and the custom4 variable are present, that's not supported
            slog.e << "Error: when the 'color' attribute is required 'Variable::CUSTOM4' is not supported." << io::endl;
            goto error;
        }
    }

    // TODO: maybe check MaterialDomain::COMPUTE has outputs

    if (mCustomSurfaceShading && mShading != Shading::LIT) {
        slog.e << "Error: customSurfaceShading can only be used with lit materials." << io::endl;
        goto error;
    }

    if (mApiLevel < 1 || mApiLevel > UNSTABLE_MATERIAL_API_LEVEL) {
        slog.e << "Error: api level can't be set below 1 or above unstable material level(" <<
                UNSTABLE_MATERIAL_API_LEVEL << ")" << io::endl;
        goto error;
    }

    // prepareToBuild must be called first, to populate mCodeGenPermutations.
    MaterialInfo info{};
    prepareToBuild(info);

    // check level features
    if (!checkMaterialLevelFeatures(info)) {
        goto error;
    }

    // Run checks, in order.
    // The call to findProperties populates mProperties and must come before runSemanticAnalysis.
    // Return an empty package to signal a failure to build the material.

    // For finding properties and running semantic analysis, we always use the same code gen
    // permutation. This is the first permutation generated with default arguments passed to matc.
    CodeGenParams const semanticCodeGenParams = {
            .shaderModel = ShaderModel::MOBILE,
            .targetApi = TargetApi::OPENGL,
            .targetLanguage = (info.featureLevel == FeatureLevel::FEATURE_LEVEL_0) ?
                              TargetLanguage::GLSL : TargetLanguage::SPIRV,
            .featureLevel = info.featureLevel,

Review comment (suggestion):
I think we're using the `LOG(ERROR) << ` syntax these days.

Code after:
    }

    // Add a default color output.
    if (mMaterialDomain == MaterialDomain::POST_PROCESS && mOutputs.empty()) {
        output(VariableQualifier::OUT,
                OutputTarget::COLOR, Precision::DEFAULT, OutputType::FLOAT4, "color");
    }

    if (mMaterialDomain == MaterialDomain::SURFACE) {
        if (mRequiredAttributes[COLOR] &&
            !mVariables[int(Variable::CUSTOM4)].name.empty()) {
            // both the color attribute and the custom4 variable are present, that's not supported
            slog.e << "Error: when the 'color' attribute is required 'Variable::CUSTOM4' is not supported." << io::endl;
            goto error;
        }
    }

    // TODO: maybe check MaterialDomain::COMPUTE has outputs

    if (mCustomSurfaceShading && mShading != Shading::LIT) {
        slog.e << "Error: customSurfaceShading can only be used with lit materials." << io::endl;
        goto error;
    }

    if (mApiLevel < 1 || mApiLevel > filament::UNSTABLE_MATERIAL_API_LEVEL) {
        slog.e << "Error: api level can't be set below 1 or above unstable material level(" <<
                filament::UNSTABLE_MATERIAL_API_LEVEL << ")" << io::endl;
        goto error;
    }

    // prepareToBuild must be called first, to populate mCodeGenPermutations.
    MaterialInfo info{};
    prepareToBuild(info);

    // check level features
    if (!checkMaterialLevelFeatures(info)) {
        goto error;
    }

    // Run checks, in order.
    // The call to findProperties populates mProperties and must come before runSemanticAnalysis.
    // Return an empty package to signal a failure to build the material.

    // For finding properties and running semantic analysis, we always use the same code gen
    // permutation. This is the first permutation generated with default arguments passed to matc.
    CodeGenParams const semanticCodeGenParams = {
            .shaderModel = ShaderModel::MOBILE,
            .targetApi = TargetApi::OPENGL,
            .targetLanguage = (info.featureLevel == FeatureLevel::FEATURE_LEVEL_0) ?
                              TargetLanguage::GLSL : TargetLanguage::SPIRV,
            .featureLevel = info.featureLevel,