/**
 * Vertex color mixin
 *
 * @param BaseCls - Base class to mix in
 * @returns Mixed class
 *
 * @public
 */ function mixinVertexColor(BaseCls) {
    if (BaseCls.vertexColorMixed) {
        return BaseCls;
    }
    let FEATURE_VERTEX_COLOR = 0;
    const cls = class extends BaseCls {
        static vertexColorMixed = true;
        constructor(){
            super();
        }
        copyFrom(other) {
            super.copyFrom(other);
            this.vertexColor = other.vertexColor;
        }
        /** Albedo color */ get vertexColor() {
            return this.featureUsed(FEATURE_VERTEX_COLOR);
        }
        set vertexColor(val) {
            this.useFeature(FEATURE_VERTEX_COLOR, !!val);
        }
        vertexShader(scope) {
            super.vertexShader(scope);
            if (this.needFragmentColor()) {
                if (this.vertexColor) {
                    if (scope.$getVertexAttrib('diffuse')) {
                        throw new Error('mixinVertexColor.vertexShader(): diffuse vertex stream already defined');
                    }
                    scope.$inputs.zDiffuse = scope.$builder.vec4().attrib('diffuse');
                    scope.$outputs.zOutDiffuse = scope.$inputs.zDiffuse;
                }
            }
        }
        getVertexColor(scope) {
            if (!this.needFragmentColor()) {
                throw new Error('mixinVertexColor.getVertexColor(): No need to calculate albedo color, make sure needFragmentColor() returns true');
            }
            if (scope.$builder.shaderKind === 'fragment') {
                return scope.$inputs.zOutDiffuse;
            } else {
                return scope.$inputs.zDiffuse;
            }
        }
    };
    FEATURE_VERTEX_COLOR = cls.defineFeature();
    return cls;
}

export { mixinVertexColor };
//# sourceMappingURL=vertexcolor.js.map
