import macro from 'vtk.js/Sources/macros';
const { vtkErrorMacro } = macro;
function vtkOpenGLTextureUnitManager(publicAPI, model) { model.classHierarchy.push('vtkOpenGLTextureUnitManager');
publicAPI.deleteTable = () => { for (let i = 0; i < model.numberOfTextureUnits; ++i) { if (model.textureUnits[i] === true) { vtkErrorMacro('some texture units were not properly released'); } } model.textureUnits = []; model.numberOfTextureUnits = 0; };
publicAPI.setContext = (ctx) => { if (model.context !== ctx) { if (model.context !== 0) { publicAPI.deleteTable(); } model.context = ctx; if (model.context) { model.numberOfTextureUnits = ctx.getParameter( ctx.MAX_TEXTURE_IMAGE_UNITS ); for (let i = 0; i < model.numberOfTextureUnits; ++i) { model.textureUnits[i] = false; } } publicAPI.modified(); } };
publicAPI.allocate = () => { for (let i = 0; i < model.numberOfTextureUnits; i++) { if (!publicAPI.isAllocated(i)) { model.textureUnits[i] = true; return i; } } return -1; };
publicAPI.allocateUnit = (unit) => { if (publicAPI.isAllocated(unit)) { return -1; }
model.textureUnits[unit] = true; return unit; };
publicAPI.isAllocated = (textureUnitId) => model.textureUnits[textureUnitId];
publicAPI.free = (val) => { model.textureUnits[val] = false; };
publicAPI.freeAll = () => { for (let i = 0; i < model.numberOfTextureUnits; ++i) { model.textureUnits[i] = false; } }; }
const DEFAULT_VALUES = { context: null, numberOfTextureUnits: 0, textureUnits: 0, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
model.textureUnits = [];
macro.get(publicAPI, model, ['numberOfTextureUnits']);
macro.setGet(publicAPI, model, ['context']);
vtkOpenGLTextureUnitManager(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkOpenGLTextureUnitManager' );
export default { newInstance, extend };
|