'use strict';
exports.__esModule = true;
var _pixiGlCore = require('pixi-gl-core');
var _pixiGlCore2 = _interopRequireDefault(_pixiGlCore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* An object containing WebGL specific properties to be used by the WebGL renderer
*
* @class
* @private
* @memberof PIXI
*/
var WebGLGraphicsData = function () {
/**
* @param {WebGLRenderingContext} gl - The current WebGL drawing context
* @param {PIXI.Shader} shader - The shader
* @param {object} attribsState - The state for the VAO
*/
function WebGLGraphicsData(gl, shader, attribsState) {
_classCallCheck(this, WebGLGraphicsData);
/**
* The current WebGL drawing context
*
* @member {WebGLRenderingContext}
*/
this.gl = gl;
// TODO does this need to be split before uploading??
/**
* An array of color components (r,g,b)
* @member {number[]}
*/
this.color = [0, 0, 0]; // color split!
/**
* An array of points to draw
* @member {PIXI.Point[]}
*/
this.points = [];
/**
* The indices of the vertices
* @member {number[]}
*/
this.indices = [];
/**
* The main buffer
* @member {WebGLBuffer}
*/
this.buffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl);
/**
* The index buffer
* @member {WebGLBuffer}
*/
this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl);
/**
* Whether this graphics is dirty or not
* @member {boolean}
*/
this.dirty = true;
/**
* Whether this graphics is nativeLines or not
* @member {boolean}
*/
this.nativeLines = false;
this.glPoints = null;
this.glIndices = null;
/**
*
* @member {PIXI.Shader}
*/
this.shader = shader;
this.vao = new _pixiGlCore2.default.VertexArrayObject(gl, attribsState).addIndex(this.indexBuffer).addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0).addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4);
}
/**
* Resets the vertices and the indices
*/
WebGLGraphicsData.prototype.reset = function reset() {
this.points.length = 0;
this.indices.length = 0;
};
/**
* Binds the buffers and uploads the data
*/
WebGLGraphicsData.prototype.upload = function upload() {
this.glPoints = new Float32Array(this.points);
this.buffer.upload(this.glPoints);
this.glIndices = new Uint16Array(this.indices);
this.indexBuffer.upload(this.glIndices);
this.dirty = false;
};
/**
* Empties all the data
*/
WebGLGraphicsData.prototype.destroy = function destroy() {
this.color = null;
this.points = null;
this.indices = null;
this.vao.destroy();
this.buffer.destroy();
this.indexBuffer.destroy();
this.gl = null;
this.buffer = null;
this.indexBuffer = null;
this.glPoints = null;
this.glIndices = null;
};
return WebGLGraphicsData;
}();
exports.default = WebGLGraphicsData;
//# sourceMappingURL=WebGLGraphicsData.js.map