@openhps/core
Version:
Open Hybrid Positioning System - Core component
89 lines (84 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _DataMap = _interopRequireDefault(require("./DataMap.js"));
var _Constants = require("./Constants.js");
var _constants = require("../../constants.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This renderer module manages geometry attributes.
*
* @private
* @augments DataMap
*/
class Attributes extends _DataMap.default {
/**
* Constructs a new attribute management component.
*
* @param {Backend} backend - The renderer's backend.
*/
constructor(backend) {
super();
/**
* The renderer's backend.
*
* @type {Backend}
*/
this.backend = backend;
}
/**
* Deletes the data for the given attribute.
*
* @param {BufferAttribute} attribute - The attribute.
* @return {Object|null} The deleted attribute data.
*/
delete(attribute) {
const attributeData = super.delete(attribute);
if (attributeData !== null) {
this.backend.destroyAttribute(attribute);
}
return attributeData;
}
/**
* Updates the given attribute. This method creates attribute buffers
* for new attributes and updates data for existing ones.
*
* @param {BufferAttribute} attribute - The attribute to update.
* @param {number} type - The attribute type.
*/
update(attribute, type) {
const data = this.get(attribute);
if (data.version === undefined) {
if (type === _Constants.AttributeType.VERTEX) {
this.backend.createAttribute(attribute);
} else if (type === _Constants.AttributeType.INDEX) {
this.backend.createIndexAttribute(attribute);
} else if (type === _Constants.AttributeType.STORAGE) {
this.backend.createStorageAttribute(attribute);
} else if (type === _Constants.AttributeType.INDIRECT) {
this.backend.createIndirectStorageAttribute(attribute);
}
data.version = this._getBufferAttribute(attribute).version;
} else {
const bufferAttribute = this._getBufferAttribute(attribute);
if (data.version < bufferAttribute.version || bufferAttribute.usage === _constants.DynamicDrawUsage) {
this.backend.updateAttribute(attribute);
data.version = bufferAttribute.version;
}
}
}
/**
* Utility method for handling interleaved buffer attributes correctly.
* To process them, their `InterleavedBuffer` is returned.
*
* @param {BufferAttribute} attribute - The attribute.
* @return {BufferAttribute|InterleavedBuffer}
*/
_getBufferAttribute(attribute) {
if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
return attribute;
}
}
var _default = exports.default = Attributes;