"use strict";
cc._RF.push(module, 'f59dfvtcmxPmrcnbzPGsWOM', 'page_effect_assembler_base');
// OP13/script/page_effect_assembler_base.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var PageEffectAssemblerBase = /** @class */ (function (_super) {
    __extends(PageEffectAssemblerBase, _super);
    function PageEffectAssemblerBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        // 普通四边形的属性，根据实际的顶点格式、数量调整
        _this.verticesCount = 4;
        _this.indicesCount = 6;
        _this.floatsPerVert = 5;
        _this.colorOffset = 4;
        _this.renderData = null;
        return _this;
    }
    Object.defineProperty(PageEffectAssemblerBase.prototype, "verticesFloats", {
        get: function () {
            return this.verticesCount * this.floatsPerVert;
        },
        enumerable: false,
        configurable: true
    });
    PageEffectAssemblerBase.prototype.getBuffer = function () {
        //@ts-ignore
        return cc.renderer._handle.getBuffer("mesh", this.getVfmt());
    };
    PageEffectAssemblerBase.prototype.getVfmt = function () {
        // to be overwrite
        return null;
    };
    PageEffectAssemblerBase.prototype.updateColor = function (comp, color) {
        var uintVerts = this.renderData.uintVDatas[0];
        if (!uintVerts)
            return;
        color = color != null ? color : comp.node.color._val;
        var floatsPerVert = this.floatsPerVert;
        var colorOffset = this.colorOffset;
        for (var i = colorOffset, l = uintVerts.length; i < l; i += floatsPerVert) {
            uintVerts[i] = color;
        }
    };
    PageEffectAssemblerBase.prototype.updateIsFront = function (comp, dataOffset) {
        var verts = this.renderData.vDatas[0];
        var index = 0;
        var floatsPerVert = this.floatsPerVert;
        for (var i = 0, n = this.verticesCount; i < n; ++i) {
            index = i * floatsPerVert;
            var isFirstVert = i % 2 === 0;
            var firstVertX = isFirstVert ? verts[index] : verts[index - floatsPerVert];
            var secondVertX = isFirstVert ? verts[index + floatsPerVert] : verts[index];
            var isFront = firstVertX < secondVertX ? 1.0 : 0.0;
            verts[index + dataOffset] = isFront;
        }
    };
    PageEffectAssemblerBase.prototype.initData = function () {
        //@ts-ignore
        this.renderData = new cc.RenderData();
        this.renderData.init(this);
        var data = this.renderData;
        // createFlexData支持创建指定格式的renderData
        data.createFlexData(0, this.verticesCount, this.indicesCount, this.getVfmt());
        // 顶点数固定的情况下索引不变化
        var indices = data.iDatas[0];
        var count = indices.length / 6;
        for (var i = 0, idx = 0; i < count; i++) {
            var vertextID = i * 4;
            indices[idx++] = vertextID;
            indices[idx++] = vertextID + 1;
            indices[idx++] = vertextID + 2;
            indices[idx++] = vertextID + 1;
            indices[idx++] = vertextID + 3;
            indices[idx++] = vertextID + 2;
        }
    };
    PageEffectAssemblerBase.prototype.fillBuffers = function (comp, renderer) {
        var renderData = this.renderData;
        var vData = renderData.vDatas[0];
        var iData = renderData.iDatas[0];
        var buffer = this.getBuffer();
        var offsetInfo = buffer.request(this.verticesCount, this.indicesCount);
        var vertexOffset = offsetInfo.byteOffset >> 2, vbuf = buffer._vData;
        if (vData.length + vertexOffset > vbuf.length) {
            vbuf.set(vData.subarray(0, vbuf.length - vertexOffset), vertexOffset);
        }
        else {
            vbuf.set(vData, vertexOffset);
        }
        var ibuf = buffer._iData, indiceOffset = offsetInfo.indiceOffset, vertexId = offsetInfo.vertexOffset;
        for (var i = 0, l = iData.length; i < l; i++) {
            ibuf[indiceOffset++] = vertexId + iData[i];
        }
    };
    return PageEffectAssemblerBase;
}(cc.Assembler));
exports.default = PageEffectAssemblerBase;

cc._RF.pop();