File size: 1,503 Bytes
c0dce6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
export default class Attribute {
/**
* The parent MiniGL controller.
*
* @type {MiniGL}
* @private
*/
gl;
type;
buffer;
normalized = false;
/**
* @param {MiniGL} minigl
* @param {object} properties
*/
constructor(minigl, properties = {}) {
// Add additional properties.
Object.assign(this, properties);
// Set required properties.
this.gl = minigl;
this.type = this.gl.getContext().FLOAT;
this.buffer = this.gl.getContext().createBuffer();
this.update();
}
update() {
if (this.values) {
const context = this.gl.getContext();
context.bindBuffer(this.target, this.buffer);
context.bufferData(this.target, this.values, context.STATIC_DRAW);
}
}
attach(e, t) {
const context = this.gl.getContext();
const n = context.getAttribLocation(t, e);
if (this.target === context.ARRAY_BUFFER) {
context.enableVertexAttribArray(n);
context.vertexAttribPointer(n, this.size, this.type, this.normalized, 0, 0);
}
return n;
}
use(e) {
const context = this.gl.getContext();
context.bindBuffer(this.target, this.buffer);
if (this.target === context.ARRAY_BUFFER) {
context.enableVertexAttribArray(e);
context.vertexAttribPointer(e, this.size, this.type, this.normalized, 0, 0);
}
}
}
|