{"version":3,"sources":["Attribute.js","Detector.js","Drawable.js","Extensions.js","FloatTexFramebuffer.js","Framebuffer.js","Geometry.js","GL.js","Ibo.js","ImageUtil.js","InstancedDrawable.js","PostProcessing.js","Program.js","Shader.js","Shape.js","Texture.js","Uniform.js","Vbo.js","WebGLCanvasPool.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC3FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACrTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACnFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC3FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC1CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC1EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC3FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AChIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC7HA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACrKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACxIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC1DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACnFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC/IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC9FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"phigl.js","sourcesContent":["phina.namespace(function() {\n\n /**\n * GLSL Attribute variable.\n * @constructor phigl.Attribute\n * @param {WebGLRenderingContext} gl context\n * @param {phigl.Program} program\n * @param {string} name\n * @param {number} type\n */\n phina.define(\"phigl.Attribute\", {\n\n /** \n * @type {WebGLRenderingContext}\n * @memberOf phigl.Attribute.prototype\n */\n gl: null,\n /**\n * @type {string}\n * @memberOf phigl.Attribute.prototype\n */\n name: null,\n\n _location: null,\n _type: null,\n _ptype: null,\n _offset: 0,\n\n init: function(gl, program, name, type) {\n this.gl = gl;\n this.name = name;\n\n this._location = gl.getAttribLocation(program, name);\n if (this._location == -1) {\n throw \"attribute \" + name + \" not found\";\n }\n // this.enable();\n\n this._type = type;\n switch (type) {\n case gl.BOOL:\n this.size = 1;\n this._ptype = gl.BOOL;\n break;\n case gl.FLOAT:\n this.size = 1;\n this._ptype = gl.FLOAT;\n break;\n case gl.FLOAT_VEC2:\n this.size = 2;\n this._ptype = gl.FLOAT;\n break;\n case gl.FLOAT_VEC3:\n this.size = 3;\n this._ptype = gl.FLOAT;\n break;\n case gl.FLOAT_VEC4:\n this.size = 4;\n this._ptype = gl.FLOAT;\n break;\n }\n },\n\n /**\n * set stride\n * @memberOf phigl.Attribute.prototype\n * @param {number} stride\n * @return {this}\n */\n specify: function(stride) {\n // console.log(\"attribute\", this.name, this._location);\n var gl = this.gl;\n gl.vertexAttribPointer(this._location, this.size, this._ptype, false, stride, this._offset);\n return this;\n },\n\n enable: function() {\n var gl = this.gl;\n gl.enableVertexAttribArray(this._location);\n return this;\n },\n\n disable: function() {\n var gl = this.gl;\n gl.disableVertexAttribArray(this._location);\n return this;\n },\n\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * GLSL Attribute variable.\n * @constructor phigl.Detector\n */\n phina.define(\"phigl.Detector\", {\n _static: {\n \n /**\n * @memberOf phigl.Detector\n * @property {boolean}\n */\n isEnable: (function() {\n try {\n var canvas = document.createElement('canvas');\n var gl = canvas.getContext(\"webgl\") || canvas.getContext(\"experimental-webgl\");\n return !!(window.WebGLRenderingContext && gl && gl.getShaderPrecisionFormat);\n } catch (e) {\n return false;\n }\n })(),\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * drawable object.\n * \n * @constructor phigl.Drawable\n * @param {WebGLRenderingContext} gl context\n * @param {WebGLExtension?} extVao value of gl.getExtension('OES_vertex_array_object')\n * @extends {phina.util.EventDispatcher}\n */\n phina.define(\"phigl.Drawable\", {\n superClass: \"phina.util.EventDispatcher\",\n\n /**\n * @type {WebGLRenderingContext}\n * @memberOf phigl.Drawable.prototype\n */\n gl: null,\n /**\n * @type {WebGLExtension}\n * @memberOf phigl.Drawable.prototype\n */\n extVao: null,\n\n /**\n * @type {phigl.Program}\n * @memberOf phigl.Drawable.prototype\n */\n program: null,\n /**\n * @type {phigl.Ibo}\n * @memberOf phigl.Drawable.prototype\n */\n indices: null,\n /**\n * @type {Array.}\n * @memberOf phigl.Drawable.prototype\n */\n attributes: null,\n /**\n * @type {number}\n * @memberOf phigl.Drawable.prototype\n */\n stride: 0,\n /**\n * @type {Object.}\n * @memberOf phigl.Drawable.prototype\n */\n uniforms: null,\n /**\n * @type {phigl.Vbo}\n * @memberOf phigl.Drawable.prototype\n */\n vbo: null,\n /**\n * drawElements method 1st parameter\n * @type {number}\n * @memberOf phigl.Drawable.prototype\n */\n drawMode: 0,\n /**\n * @type {WebGLVertexArrayObjectOES}\n * @memberOf phigl.Drawable.prototype\n */\n vao: null,\n\n init: function(gl, extVao) {\n this.superInit();\n this.gl = gl;\n this.extVao = extVao;\n this.attributes = [];\n this.uniforms = {};\n this.drawMode = gl.TRIANGLES;\n },\n\n /**\n * @param {number} mode\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setDrawMode: function(mode) {\n this.drawMode = mode;\n return this;\n },\n\n /**\n * @param {phigl.Program} program\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setProgram: function(program) {\n this.program = program;\n program.use();\n this.uniforms.$extend(program._uniforms);\n return this;\n },\n\n /**\n * @param {Array.} value\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setIndexValues: function(value) {\n if (!this.indices) this.indices = phigl.Ibo(this.gl);\n this.indices.set(value);\n return this;\n },\n\n /**\n * @param {phigl.Ibo} ibo\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setIndexBuffer: function(ibo) {\n this.indices = ibo;\n return this;\n },\n\n /**\n * @param {Array.} names\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n declareAttributes: function(names) {\n names = Array.prototype.concat.apply([], arguments);\n\n var stride = 0;\n for (var i = 0; i < names.length; i++) {\n var attr = names[i];\n if (typeof attr === \"string\") attr = this.program.getAttribute(attr);\n this.attributes.push(attr);\n attr._offset = stride;\n stride += attr.size * 4;\n }\n this.stride = stride;\n return this;\n },\n\n setAttributes: function(names) {\n console.warn(\"deprecated\");\n return this.declareAttributes(names);\n },\n\n /**\n * @param {Array.} data\n * @param {number=} usage default = gl.STATIC_DRAW\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setAttributeData: function(data, usage) {\n if (!this.vbo) {\n this.vbo = phigl.Vbo(this.gl, usage);\n }\n this.vbo.set(data);\n\n this.vbo.bind();\n var stride = this.stride;\n this.attributes.forEach(function(v, i) { v.specify(stride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n /**\n * @param {Array.} dataArray [{ unitSize: n, data: [number] }, ...]\n * @param {number=} usage default = gl.STATIC_DRAW\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setAttributeDataArray: function(dataArray, usage) {\n if (!this.vbo) {\n this.vbo = phigl.Vbo(this.gl, usage);\n }\n this.vbo.setAsInterleavedArray(dataArray);\n\n this.vbo.bind();\n var stride = this.stride;\n this.attributes.forEach(function(v, i) { v.specify(stride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n /**\n * @param {phigl.Vbo} vbo\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n setAttributeVbo: function(vbo) {\n this.vbo = vbo;\n\n this.vbo.bind();\n var stride = this.stride;\n this.attributes.forEach(function(v, i) { v.specify(stride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n /**\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n createVao: function() {\n var gl = this.gl;\n var stride = this.stride;\n\n if (!this.extVao) this.extVao = phigl.Extensions.getVertexArrayObject(gl);\n if (!this.vao) this.vao = this.extVao.createVertexArrayOES();\n\n this.extVao.bindVertexArrayOES(this.vao);\n\n if (this.indices) this.indices.bind();\n\n if (this.vbo) this.vbo.bind();\n this.attributes.forEach(function(v, i) {\n v.specify(stride);\n gl.enableVertexAttribArray(v._location);\n });\n\n this.extVao.bindVertexArrayOES(null);\n\n phigl.Ibo.unbind(gl);\n phigl.Vbo.unbind(gl);\n\n return this;\n },\n\n /**\n * @param {Array.} names\n * @memberOf phigl.Drawable.prototype\n * @return {this}\n */\n declareUniforms: function(names) {\n names = Array.prototype.concat.apply([], arguments);\n\n var program = this.program;\n var map = Array.prototype.reduce.call(names, function(m, name) {\n m[name] = program.getUniform(name);\n return m;\n }, {});\n this.uniforms.$extend(map);\n return this;\n },\n\n setUniforms: function(names) {\n console.warn(\"deprecated\");\n return this.declareUniforms(names);\n },\n\n /**\n * @memberOf phigl.Drawable.prototype\n */\n draw: function() {\n // console.log(\"-- begin\");\n\n var gl = this.gl;\n var ext = this.extVao;\n\n this.program.use();\n\n if (this.vao) {\n ext.bindVertexArrayOES(this.vao);\n } else {\n if (this.indices) this.indices.bind();\n if (this.vbo) this.vbo.bind();\n var stride = this.stride;\n this.attributes.forEach(function(v, i) {\n v.enable();\n v.specify(stride);\n });\n }\n\n this.uniforms.forIn(function(k, v) { v.assign() });\n\n this.flare(\"predraw\");\n this.gl.drawElements(this.drawMode, this.indices.length, gl.UNSIGNED_SHORT, 0);\n this.flare(\"postdraw\");\n\n if (this.vao) {\n ext.bindVertexArrayOES(null);\n } else {\n phigl.Ibo.unbind(gl);\n phigl.Vbo.unbind(gl);\n }\n\n this.attributes.forEach(function(v, i) {\n v.disable();\n });\n this.uniforms.forIn(function(k, v) { v.reassign() });\n\n // console.log(\"-- end\");\n },\n\n delete: function() {\n var gl = this.gl;\n var ext = this.ext;\n\n this.program.delete();\n if (this.vao) {\n ext.deleteVertexArrayOES(this.vao);\n } else {\n this.indices.delete();\n this.vbo.delete();\n }\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.Extensions\n */\n phina.define(\"phigl.Extensions\", {\n\n _static: {\n\n getVertexArrayObject: function(gl) {\n return this._get(gl, \"OES_vertex_array_object\");\n },\n\n getInstancedArrays: function(gl) {\n return this._get(gl, \"ANGLE_instanced_arrays\");\n },\n\n _get: function(gl, name) {\n var ext = gl.getExtension(name);\n if (ext) {\n return ext;\n } else {\n throw name + \" is not supported\";\n }\n }\n },\n\n });\n\n});","phina.namespace(function() {\r\n\r\n /**\r\n * @constructor phigl.FloatTexFramebuffer\r\n * @param {WebGLRenderingContext} gl context\r\n * @param {number} width\r\n * @param {number} height\r\n */\r\n phina.define(\"phigl.FloatTexFramebuffer\", {\r\n gl: null,\r\n \r\n /**\r\n * @type {phigl.Texture}\r\n * @memberOf phigl.FloatTexFramebuffer.prototype\r\n */\r\n texture: null,\r\n\r\n _framebuffer: null,\r\n _texture: null,\r\n\r\n init: function(gl, width, height, options) {\r\n options = options || {};\r\n\r\n this.gl = gl;\r\n this.width = width;\r\n this.height = height;\r\n\r\n this._framebuffer = gl.createFramebuffer();\r\n\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);\r\n\r\n // // depth_stencil\r\n // this._depthStencilRenderbuffer = gl.createRenderbuffer();\r\n // gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilRenderbuffer);\r\n // gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);\r\n // gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilRenderbuffer);\r\n\r\n // color\r\n this.texture = phigl.Texture(gl);\r\n this._texture = this.texture._texture;\r\n gl.bindTexture(gl.TEXTURE_2D, this._texture);\r\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT, null);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, options.magFilter || gl.NEAREST);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, options.minFilter || gl.NEAREST);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._texture, 0);\r\n\r\n // reset\r\n gl.bindTexture(gl.TEXTURE_2D, null);\r\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\r\n },\r\n\r\n /**\r\n * @memberOf phigl.FloatTexFramebuffer.prototype\r\n * @return {this}\r\n */\r\n bind: function() {\r\n var gl = this.gl;\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);\r\n gl.viewport(0, 0, this.width, this.height);\r\n return this;\r\n },\r\n\r\n delete: function() {\r\n var gl = this.gl;\r\n gl.deleteFramebuffer(this._framebuffer);\r\n this.texture.delete();\r\n },\r\n\r\n _static: {\r\n /**\r\n * @memberOf phigl.FloatTexFramebuffer\r\n * @param {WebGLRenderingContext} gl context\r\n */\r\n unbind: function(gl) {\r\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\r\n },\r\n },\r\n });\r\n\r\n});\r\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.Framebuffer\n * @param {WebGLRenderingContext} gl context\n * @param {number} width\n * @param {number} height\n */\n phina.define(\"phigl.Framebuffer\", {\n gl: null,\n \n /**\n * @type {phigl.Texture}\n * @memberOf phigl.Framebuffer.prototype\n */\n texture: null,\n\n _framebuffer: null,\n _depthRenderbuffer: null,\n _texture: null,\n\n init: function(gl, width, height, options) {\n options = options || {};\n\n this.gl = gl;\n this.width = width;\n this.height = height;\n\n this._framebuffer = gl.createFramebuffer();\n\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);\n\n // depth_stencil\n this._depthStencilRenderbuffer = gl.createRenderbuffer();\n gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthStencilRenderbuffer);\n gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);\n gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._depthStencilRenderbuffer);\n\n // // stencil\n // this._stencilRenderbuffer = gl.createRenderbuffer();\n // gl.bindRenderbuffer(gl.RENDERBUFFER, this._stencilRenderbuffer);\n // gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, width, height);\n // gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._stencilRenderbuffer);\n\n // color\n this.texture = phigl.Texture(gl);\n this._texture = this.texture._texture;\n gl.bindTexture(gl.TEXTURE_2D, this._texture);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, options.magFilter || gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, options.minFilter || gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._texture, 0);\n\n // reset\n gl.bindTexture(gl.TEXTURE_2D, null);\n gl.bindRenderbuffer(gl.RENDERBUFFER, null);\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n },\n\n /**\n * @memberOf phigl.Framebuffer.prototype\n * @return {this}\n */\n bind: function() {\n var gl = this.gl;\n gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);\n gl.viewport(0, 0, this.width, this.height);\n return this;\n },\n\n delete: function() {\n var gl = this.gl;\n gl.deleteFramebuffer(this._framebuffer);\n gl.deleteRenderbuffer(this._depthStencilRenderbuffer);\n this.texture.delete();\n },\n\n _static: {\n /**\n * @memberOf phigl.Framebuffer\n * @param {WebGLRenderingContext} gl context\n */\n unbind: function(gl) {\n gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n },\n },\n });\n\n});\n","phina.namespace(function() {\n\n phina.define(\"phigl.Geometry\", {\n\n positions: null,\n normals: null,\n uvs: null,\n indices: null,\n\n init: function(options) {},\n\n setTo: function(drawable) {\n var atributeNames = [];\n var attributeDataArray = [];\n if (this.positions) {\n atributeNames.push(\"position\");\n attributeDataArray.push({ unitSize: 3, data: this.positions });\n }\n if (this.normals) {\n atributeNames.push(\"normal\");\n attributeDataArray.push({ unitSize: 3, data: this.normals });\n }\n if (this.uvs) {\n atributeNames.push(\"uv\");\n attributeDataArray.push({ unitSize: 2, data: this.uvs });\n }\n\n drawable\n .declareAttributes(atributeNames)\n .setAttributeDataArray(attributeDataArray)\n .setIndexValues(this.indices);\n\n return this;\n },\n\n });\n\n phigl.Drawable.prototype.$method(\"setGeometry\", function(geometry) {\n geometry.setTo(this);\n return this;\n });\n\n});","phina.namespace(function() {\n\n phina.define(\"phigl.GL\", {\n _static: {\n getId: function(gl) {\n if (gl.id == null) {\n gl.id = \"phigl-WebGLRenderingContext-\" + (new Date()).getTime().toString(16) + Math.floor(Math.random() * 1000).toString(16);\n }\n return gl.id;\n },\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.Ibo\n * @param {WebGLRenderingContext} gl context\n */\n phina.define(\"phigl.Ibo\", {\n\n /**\n * @memberOf phigl.Ibo.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.Ibo.prototype\n */\n length: 0,\n\n _buffer: null,\n\n init: function(gl) {\n this.gl = gl;\n this._buffer = gl.createBuffer();\n },\n\n /**\n * @memberOf phigl.Ibo.prototype\n */\n set: function(data) {\n var gl = this.gl;\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._buffer);\n gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array(data), gl.STATIC_DRAW);\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);\n this.length = data.length;\n return this;\n },\n\n /**\n * @memberOf phigl.Ibo.prototype\n */\n bind: function() {\n this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this._buffer);\n return this;\n },\n\n /**\n * @memberOf phigl.Ibo.prototype\n */\n delete: function() {\n this.gl.deleteBuffer(this._buffer);\n },\n\n _static: {\n unbind: function(gl) {\n gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);\n return this;\n },\n },\n\n _accessor: {\n /**\n * @memberOf phigl.Ibo.prototype\n */\n value: {\n get: function() {\n return null;\n },\n set: function(v) {\n this.set(v);\n },\n },\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.ImageUtil\n */\n phina.define(\"phigl.ImageUtil\", {\n\n init: function() {},\n\n _static: {\n\n calcSizePowOf2: function(origWidth, origHeight) {\n var asp = origWidth / origHeight;\n\n var width = Math.pow(2, Math.ceil(Math.log2(origWidth)));\n var height = Math.pow(2, Math.ceil(Math.log2(origHeight)));\n\n var fitW = asp > width / height;\n\n if (fitW) {\n var h = width / asp;\n return {\n srcX: 0,\n srcY: (height - h) * 0.5,\n srcWidth: width,\n srcHeight: h,\n width: width,\n height: height,\n };\n } else {\n var w = height * asp;\n return {\n srcX: (width - w) * 0.5,\n srcY: 0,\n srcWidth: w,\n srcHeight: height,\n width: width,\n height: height,\n };\n }\n },\n\n /**\n * @memberOf phigl.ImageUtil\n */\n resizePowOf2: function(options) {\n options = ({}).$safe(options, {\n dst: null,\n });\n\n var src = options.src;\n if (typeof(src) == \"string\") {\n src = phina.asset.AssetManager.get(\"image\", src);\n }\n\n var dst = options.dst || phina.graphics.Canvas();\n var fitW = src.domElement.width < src.domElement.height;\n var asp = src.domElement.width / src.domElement.height;\n\n if (Math.sqrt(src.domElement.width) % 1 === 0 && Math.sqrt(src.domElement.height) % 1 === 0) {\n return src;\n }\n\n dst.clear();\n\n var width = Math.pow(2, Math.ceil(Math.log2(src.domElement.width)));\n var height = Math.pow(2, Math.ceil(Math.log2(src.domElement.height)));\n dst.domElement.width = width;\n dst.domElement.height = height;\n\n if (fitW) {\n var h = width / asp;\n dst.context.drawImage(src.domElement,\n 0, 0, src.domElement.width, src.domElement.height,\n 0, (height - h) * 0.5, width, h\n );\n } else {\n var w = height * asp;\n dst.context.drawImage(src.domElement,\n 0, 0, src.domElement.width, src.domElement.height,\n (width - w) * 0.5, 0, w, height\n );\n }\n\n return dst;\n },\n\n },\n\n });\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.InstancedDrawable\n * @extends {phigl.Drawable}\n * @param {WebGLRenderingContext} gl context\n * @param {WebGLExtension?} extVao value of gl.getExtension('ANGLE_instanced_arrays')\n */\n phina.define(\"phigl.InstancedDrawable\", {\n superClass: \"phigl.Drawable\",\n\n instanceAttributes: null,\n ext: null,\n\n instanceVbo: null,\n instanceStride: 0,\n\n init: function(gl, extInstancedArrays) {\n this.superInit(gl);\n this.ext = extInstancedArrays;\n this.instanceAttributes = [];\n },\n\n declareInstanceAttributes: function(names) {\n names = Array.prototype.concat.apply([], arguments);\n\n var gl = this.gl;\n var ext = this.ext;\n\n var stride = 0;\n for (var i = 0; i < names.length; i++) {\n var attr = names[i];\n if (typeof attr === \"string\") attr = this.program.getAttribute(attr);\n this.instanceAttributes.push(attr);\n attr._offset = stride;\n stride += attr.size * 4;\n }\n this.instanceStride = stride;\n\n return this;\n },\n\n setInstanceAttributes: function(names) {\n console.warn(\"deprecated\");\n return this.declareInstanceAttributes(names);\n },\n \n setInstanceAttributeVbo: function(vbo) {\n this.instanceVbo = vbo;\n\n this.instanceVbo.bind();\n var iStride = this.instanceStride;\n this.instanceAttributes.forEach(function(v, i) { v.specify(iStride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n setInstanceAttributeData: function(data) {\n if (!this.instanceVbo) this.instanceVbo = phigl.Vbo(this.gl, this.gl.DYNAMIC_DRAW);\n this.instanceVbo.set(data);\n\n this.instanceVbo.bind();\n var iStride = this.instanceStride;\n this.instanceAttributes.forEach(function(v, i) { v.specify(iStride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n setInstanceAttributeDataArray: function(dataArray) {\n if (!this.instanceVbo) this.instanceVbo = phigl.Vbo(this.gl);\n this.instanceVbo.setAsInterleavedArray(dataArray);\n\n this.instanceVbo.bind();\n var iStride = this.instanceStride;\n this.instanceAttributes.forEach(function(v, i) { v.specify(iStride) });\n phigl.Vbo.unbind(this.gl);\n\n return this;\n },\n\n createVao: function() {\n return this;\n },\n\n draw: function(instanceCount) {\n var gl = this.gl;\n var ext = this.ext;\n\n this.program.use();\n\n if (this.indices) this.indices.bind();\n if (this.vbo) this.vbo.bind();\n var stride = this.stride;\n this.attributes.forEach(function(v, i) {\n v.enable();\n v.specify(stride);\n });\n\n if (this.instanceVbo) this.instanceVbo.bind();\n var iStride = this.instanceStride;\n this.instanceAttributes.forEach(function(v, i) {\n v.enable();\n v.specify(iStride);\n ext.vertexAttribDivisorANGLE(v._location, 1);\n });\n\n this.uniforms.forIn(function(k, v) { v.assign() });\n\n this.flare(\"predraw\");\n this.ext.drawElementsInstancedANGLE(this.drawMode, this.indices.length, gl.UNSIGNED_SHORT, 0, instanceCount);\n this.flare(\"postdraw\");\n\n this.attributes.forEach(function(v, i) {\n v.disable();\n });\n this.instanceAttributes.forEach(function(v, i) {\n v.disable();\n ext.vertexAttribDivisorANGLE(v._location, 0);\n });\n phigl.Ibo.unbind(gl);\n phigl.Vbo.unbind(gl);\n },\n\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.PostProcessing\n */\n phina.define(\"phigl.PostProcessing\", {\n\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n drawer: null,\n\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n width: 0,\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n height: 0,\n\n init: function(gl, shader, uniforms, width, height) {\n this.gl = gl;\n\n if (typeof(shader) == \"string\") {\n shader = phigl.PostProcessing.createProgram(gl, shader);\n }\n width = width || 256;\n height = height || 256;\n uniforms = uniforms || [];\n\n var sqWidth = Math.pow(2, Math.ceil(Math.log2(width)));\n var sqHeight = Math.pow(2, Math.ceil(Math.log2(height)));\n\n this.drawer = phigl.Drawable(gl)\n .setDrawMode(gl.TRIANGLE_STRIP)\n .setProgram(shader)\n .setIndexValues([0, 1, 2, 3])\n .setAttributes(\"position\", \"uv\")\n .setAttributeData([\n //\n -1, +1, 0, height / sqHeight,\n //\n +1, +1, width / sqWidth, height / sqHeight,\n //\n -1, -1, 0, 0,\n // \n +1, -1, width / sqWidth, 0,\n ])\n .setUniforms([\"texture\", \"canvasSize\"].concat(uniforms));\n\n this.width = width;\n this.height = height;\n this.sqWidth = sqWidth;\n this.sqHeight = sqHeight;\n },\n\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n render: function(texture, uniformValues) {\n var gl = this.gl;\n\n this.drawer.uniforms.texture.setValue(0).setTexture(texture);\n this.drawer.uniforms.canvasSize.value = [this.sqWidth, this.sqHeight];\n if (uniformValues) this.setUniforms(uniformValues);\n this.drawer.draw();\n\n return this;\n },\n\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n setUniforms: function(uniformValues) {\n var uniforms = this.drawer.uniforms;\n uniformValues.forIn(function(k, v) {\n uniforms[k].value = v;\n });\n },\n\n /**\n * @memberOf phigl.PostProcessing.prototype\n */\n calcCoord: function(x, y) {\n return [x / this.sqWidth, (this.height - y) / this.sqHeight];\n },\n\n _static: {\n /**\n * @memberOf phigl.PostProcessing\n */\n vertexShaderSource: [\n \"attribute vec2 position;\",\n \"attribute vec2 uv;\",\n\n \"varying vec2 vUv;\",\n\n \"void main(void) {\",\n \" vUv = uv;\",\n \" gl_Position = vec4(position, 0.0, 1.0);\",\n \"}\",\n ].join(\"\\n\"),\n\n /**\n * @memberOf phigl.PostProcessing\n */\n createProgram: function(gl, fragmentShader) {\n var vertexShader = phigl.VertexShader(gl);\n vertexShader.data = this.vertexShaderSource;\n\n return phigl.Program(gl)\n .attach(vertexShader)\n .attach(fragmentShader)\n .link();\n },\n },\n\n });\n\n});\n","phina.namespace(function() {\n var id = 0;\n\n /**\n * @constructor phigl.Program\n * @param {WebGLRenderingContext} gl context\n */\n phina.define(\"phigl.Program\", {\n\n _static: {\n /**\n * @memberOf phigl.Program\n */\n currentUsing: null,\n },\n\n /**\n * @memberOf phigl.Program.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.Program.prototype\n */\n linked: false,\n\n _program: null,\n\n _vbo: null,\n\n _attributes: null,\n _uniforms: null,\n\n _shaders: null,\n\n init: function(gl) {\n this.gl = gl;\n\n this._program = gl.createProgram();\n this._program._id = id++;\n this.linked = false;\n\n this._attributes = {};\n this._uniforms = {};\n\n this._shaders = [];\n },\n\n /**\n * @param {string|phigl.Shader} shader\n * @memberOf phigl.Program.prototype\n * @return {this}\n */\n attach: function(shader) {\n var gl = this.gl;\n\n if (typeof shader === \"string\") {\n shader = phina.asset.AssetManager.get(\"vertexShader\", shader) || phina.asset.AssetManager.get(\"fragmentShader\", shader);\n }\n\n if (!shader.compiled) {\n shader.compile(gl);\n }\n\n gl.attachShader(this._program, shader._shader);\n\n this._shaders.push(shader);\n\n return this;\n },\n\n /**\n * @memberOf phigl.Program.prototype\n * @return {this}\n */\n link: function() {\n var gl = this.gl;\n\n gl.linkProgram(this._program);\n gl.validateProgram(this._program);\n\n if (gl.getProgramParameter(this._program, gl.LINK_STATUS)) {\n\n var attrCount = gl.getProgramParameter(this._program, gl.ACTIVE_ATTRIBUTES);\n for (var i = 0; i < attrCount; i++) {\n var attr = gl.getActiveAttrib(this._program, i);\n this.getAttribute(attr.name, attr.type);\n }\n\n var uniCount = gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);\n for (var i = 0; i < uniCount; i++) {\n var uni = gl.getActiveUniform(this._program, i);\n if (uni.size > 1) {\n for (var j = 0; j < uni.size; j++) {\n var name = uni.name.replace(\"[0]\", \"[\" + j + \"]\");\n this.getUniform(name, uni.type);\n }\n } else {\n this.getUniform(uni.name, uni.type);\n }\n }\n\n this.linked = true;\n return this;\n } else {\n this.linked = false;\n throw gl.getProgramInfoLog(this._program);\n }\n },\n\n /**\n * @param {string} name\n * @param {number} type\n * @memberOf phigl.Program.prototype\n * @return {phigl.Attribute}\n */\n getAttribute: function(name, type) {\n if (!this._attributes[name]) {\n this._attributes[name] = phigl.Attribute(this.gl, this._program, name, type);\n }\n return this._attributes[name];\n },\n\n /**\n * @param {string} name\n * @param {number} type\n * @memberOf phigl.Program.prototype\n * @return {phigl.Uniform}\n */\n getUniform: function(name, type) {\n if (!this._uniforms[name]) {\n this._uniforms[name] = phigl.Uniform(this.gl, this._program, name, type);\n }\n return this._uniforms[name];\n },\n\n /**\n * @memberOf phigl.Program.prototype\n * @return {this}\n */\n use: function() {\n if (phigl.Program.currentUsing === this) return this;\n this.gl.useProgram(this._program);\n phigl.Program.currentUsing = this;\n return this;\n },\n\n /**\n * @memberOf phigl.Program.prototype\n * @return {this}\n */\n delete: function() {\n var gl = this.gl;\n var program = this._program;\n this._shaders.forEach(function(shader) {\n gl.detachShader(program, shader._shader);\n });\n this._shaders.forEach(function(shader) {\n gl.deleteShader(shader._shader);\n });\n gl.deleteProgram(program);\n return this;\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.Shader\n * @extends {phina.asset.File}\n */\n phina.define(\"phigl.Shader\", {\n superClass: \"phina.asset.File\",\n\n /**\n * @memberOf phigl.Shader.prototype\n */\n type: null,\n /**\n * @memberOf phigl.Shader.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.Shader.prototype\n */\n compiled: false,\n /**\n * @memberOf phigl.Shader.prototype\n */\n assetType: null,\n\n _shader: null,\n\n init: function() {\n this.superInit();\n this.compiled = false;\n this.assetType = null;\n },\n\n setSource: function(text) {\n this.data = text;\n return this;\n },\n\n /**\n * @memberOf phigl.Shader.prototype\n */\n compile: function(gl) {\n this._resolveInclude();\n\n this.gl = gl;\n\n this.type = this._type(gl);\n\n this._shader = gl.createShader(this.type);\n gl.shaderSource(this._shader, this.data);\n gl.compileShader(this._shader);\n\n if (gl.getShaderParameter(this._shader, gl.COMPILE_STATUS)) {\n this.compiled = true;\n return this;\n } else {\n this.compiled = false;\n throw gl.getShaderInfoLog(this._shader);\n }\n },\n\n _resolveInclude: function() {\n const lines = this.data.split(/(\\n|\\r\\n)/);\n const includes = lines.map((line, index) => {\n if (line.startsWith(\"// \")) {\n const name = line.replace(\"// \", \"\").trim();\n const code = phina.asset.AssetManager.get(this.assetType, name);\n if (code == null) {\n throw `そんなシェーダーないです (${name})`;\n } else {\n return code.data;\n }\n } else {\n return line;\n }\n });\n this.data = includes.join(\"\\n\");\n },\n\n _type: function(gl) {\n return 0;\n },\n\n delete: function() {\n this.gl.deleteShader(this._shader);\n },\n });\n\n /**\n * @constructor phigl.VertexShader\n * @extends {phigl.Shader}\n */\n phina.define(\"phigl.VertexShader\", {\n superClass: \"phigl.Shader\",\n\n init: function() {\n this.superInit();\n this.assetType = \"vertexShader\";\n },\n\n _type: function(gl) {\n return gl.VERTEX_SHADER;\n },\n });\n phina.asset.AssetLoader.assetLoadFunctions[\"vertexShader\"] = function(key, path) {\n var shader = phigl.VertexShader();\n return shader.load({\n path: path,\n });\n };\n\n /**\n * @constructor phigl.FragmentShader\n * @extends {phigl.Shader}\n */\n phina.define(\"phigl.FragmentShader\", {\n superClass: \"phigl.Shader\",\n\n init: function() {\n this.superInit();\n this.assetType = \"fragmentShader\";\n },\n\n _type: function(gl) {\n return gl.FRAGMENT_SHADER;\n },\n });\n phina.asset.AssetLoader.assetLoadFunctions[\"fragmentShader\"] = function(key, path) {\n var shader = phigl.FragmentShader();\n return shader.load({\n path: path,\n });\n };\n\n});\n","phina.namespace(function() {\n\n phina.define(\"phigl.PlaneXY\", {\n superClass: \"phigl.Geometry\",\n\n init: function(options) {\n this.superInit(options);\n options = ({}).$safe(options, phigl.PlaneXY.defaults);\n\n this.width = options.width;\n this.height = options.height;\n this.normalsEnabled = options.normalsEnabled;\n\n this.positions = [\n // 左上\n options.width * -0.5, options.height * +0.5, 0,\n // 左下\n options.width * -0.5, options.height * -0.5, 0,\n // 右上\n options.width * +0.5, options.height * +0.5, 0,\n // 右下\n options.width * +0.5, options.height * -0.5, 0,\n ];\n if (this.normalsEnabled) {\n this.normals = [\n // 左上\n 0, 0, 1,\n // 左下\n 0, 0, 1,\n // 右上\n 0, 0, 1,\n // 右下\n 0, 0, 1,\n ];\n }\n this.uvs = [\n // 左上\n 0, 1,\n // 左下\n 0, 0,\n // 右上\n 1, 1,\n // 右下\n 1, 0,\n ];\n this.indices = [0, 1, 2, 2, 1, 3];\n },\n\n _static: {\n defaults: {\n width: 1,\n height: 1,\n normalsEnabled: true,\n },\n },\n\n });\n\n});","phina.namespace(function() {\n\n /**\n * @constructor phigl.Texture\n * @param {WebGLRenderingContext} gl context\n * @param {(string|phina.asset.Texture|phina.graphics.Canvas)=} image context\n */\n phina.define(\"phigl.Texture\", {\n\n /**\n * @memberOf phigl.Texture.prototype\n */\n gl: null,\n\n _texture: null,\n\n init: function(gl, image, funcSetting) {\n this.gl = gl;\n this._texture = gl.createTexture();\n if (image) {\n this.setImage(image, funcSetting);\n }\n },\n\n /**\n * @memberOf phigl.Texture.prototype\n * @param {string|phina.asset.Texture|phina.graphics.Canvas} image context\n */\n setImage: function(image, funcSetting) {\n var gl = this.gl;\n\n if (typeof image === \"string\") {\n image = phina.asset.AssetManager.get(\"image\", image);\n }\n funcSetting = funcSetting || function(gl) {\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\n gl.generateMipmap(gl.TEXTURE_2D);\n };\n\n gl.bindTexture(gl.TEXTURE_2D, this._texture);\n funcSetting(gl);\n gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image.domElement);\n\n gl.bindTexture(gl.TEXTURE_2D, null);\n\n return this;\n },\n\n /**\n * @memberOf phigl.Texture.prototype\n * @param {number} unitIndex\n */\n bind: function(unitIndex) {\n var gl = this.gl;\n gl.activeTexture(gl[\"TEXTURE\" + (unitIndex || 0)]);\n gl.bindTexture(gl.TEXTURE_2D, this._texture);\n return this;\n },\n\n /**\n * @memberOf phigl.Texture.prototype\n */\n delete: function() {\n this.gl.deleteTexture(this._texture);\n },\n \n _static: {\n /**\n * @memberOf phigl.Texture\n * @param {WebGLRenderingContext} gl context\n */\n unbind: function(gl) {\n gl.bindTexture(gl.TEXTURE_2D, null);\n return this;\n },\n },\n });\n\n});\n","phina.namespace(function() {\n\n /**\n * @constructor phigl.Uniform\n * @param {WebGLRenderingContext} gl context\n */\n phina.define(\"phigl.Uniform\", {\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.Uniform.prototype\n */\n name: null,\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n texture: null,\n\n _location: null,\n _value: null,\n _type: null,\n _uniformMethod: null,\n\n init: function(gl, program, name, type) {\n this.gl = gl;\n this.name = name;\n\n this._location = gl.getUniformLocation(program, name);\n this._type = type;\n\n switch (type) {\n case gl.BOOL:\n this._uniformMethod = \"uniform1i\";\n break;\n case gl.FLOAT:\n this._uniformMethod = \"uniform1f\";\n break;\n case gl.FLOAT_VEC2:\n this._uniformMethod = \"uniform2fv\";\n break;\n case gl.FLOAT_VEC3:\n this._uniformMethod = \"uniform3fv\";\n break;\n case gl.FLOAT_VEC4:\n this._uniformMethod = \"uniform4fv\";\n break;\n case gl.FLOAT_MAT2:\n this._uniformMethod = \"uniformMatrix2fv\";\n break;\n case gl.FLOAT_MAT3:\n this._uniformMethod = \"uniformMatrix3fv\";\n break;\n case gl.FLOAT_MAT4:\n this._uniformMethod = \"uniformMatrix4fv\";\n break;\n case gl.SAMPLER_2D:\n this._uniformMethod = \"uniform1i\";\n break;\n }\n },\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n setValue: function(value) {\n this._value = value;\n return this;\n },\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n setTexture: function(texture) {\n if (typeof(texture) == \"string\") {\n texture = phigl.Texture(this.gl, texture);\n }\n this.texture = texture;\n return this;\n },\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n assign: function() {\n var gl = this.gl;\n\n switch (this._type) {\n case gl.BOOL:\n case gl.FLOAT:\n case gl.FLOAT_VEC2:\n case gl.FLOAT_VEC3:\n case gl.FLOAT_VEC4:\n gl[this._uniformMethod](this._location, this._value);\n break;\n case gl.FLOAT_MAT2:\n case gl.FLOAT_MAT3:\n case gl.FLOAT_MAT4:\n gl[this._uniformMethod](this._location, false, this._value);\n break;\n case gl.SAMPLER_2D:\n if (this.texture) this.texture.bind(this._value);\n gl[this._uniformMethod](this._location, this._value);\n break;\n }\n\n return this;\n },\n\n /**\n * @memberOf phigl.Uniform.prototype\n */\n reassign: function() {\n var gl = this.gl;\n\n switch (this._type) {\n case gl.SAMPLER_2D:\n if (this.texture) phigl.Texture.unbind(gl);\n break;\n }\n\n return this;\n },\n\n _accessor: {\n /**\n * @memberOf phigl.Uniform.prototype\n */\n value: {\n get: function() {\n return this._value;\n },\n set: function(v) {\n this.setValue(v);\n },\n },\n },\n });\n\n});\n","phina.namespace(function() {\n var i = 0;\n\n /**\n * @constructor phigl.Vbo\n * @param {WebGLRenderingContext} gl context\n */\n phina.define(\"phigl.Vbo\", {\n\n /**\n * @memberOf phigl.Vbo.prototype\n */\n gl: null,\n /**\n * @memberOf phigl.Vbo.prototype\n */\n usage: null,\n _vbo: null,\n\n /**\n * @memberOf phigl.Vbo.prototype\n */\n array: null,\n\n init: function(gl, usage) {\n this.gl = gl;\n this.usage = usage || gl.STATIC_DRAW;\n this._vbo = gl.createBuffer();\n this._vbo._id = i++;\n },\n\n /**\n * @memberOf phigl.Vbo.prototype\n */\n set: function(data) {\n var gl = this.gl;\n if (this.array) {\n this.array.set(data);\n } else {\n this.array = new Float32Array(data);\n }\n gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);\n gl.bufferData(gl.ARRAY_BUFFER, this.array, this.usage);\n gl.bindBuffer(gl.ARRAY_BUFFER, null);\n return this;\n },\n\n /**\n * @param {Array.} dataArray [{ unitSize: n, data: [number] }, ...]\n * @memberOf phigl.Vbo.prototype\n */\n setAsInterleavedArray: function(dataArray) {\n var dataCount = dataArray.length;\n var vertexCount = dataArray[0].data.length / dataArray[0].unitSize;\n var interleavedArray = [];\n for (var i = 0; i < vertexCount; i++) {\n for (var j = 0; j < dataCount; j++) {\n var d = dataArray[j];\n for (var k = 0; k < d.unitSize; k++) {\n interleavedArray.push(d.data[i * d.unitSize + k]);\n }\n }\n }\n return this.set(interleavedArray);\n },\n\n /**\n * @memberOf phigl.Vbo.prototype\n */\n bind: function() {\n var gl = this.gl;\n gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);\n // console.log(\"bindBuffer\", this._vbo, this.array.length);\n return this;\n },\n\n /**\n * @memberOf phigl.Vbo.prototype\n */\n delete: function() {\n this.gl.deleteBuffer(this._vbo);\n },\n\n _static: {\n /**\n * @memberOf phigl.Vbo\n */\n unbind: function(gl) {\n gl.bindBuffer(gl.ARRAY_BUFFER, null);\n // console.log(\"unbind\")\n },\n },\n\n });\n});","phina.namespace(function() {\n\n phina.define(\"phigl.WebGLCanvasPool\", {\n\n _pool: null,\n _actives: null,\n\n webglParameters: null,\n\n init: function() {\n this._pool = [];\n this._actives = [];\n\n this.webglParameters = {};\n },\n\n create: function() {\n const canvas = document.createElement(\"canvas\");\n const gl = canvas.getContext(\"webgl\", this.webglParameters);\n canvas.webglId = phigl.GL.getId(gl);\n return canvas;\n },\n\n get: function() {\n if (this._pool.length === 0) {\n const canvas = this.create();\n const self = this;\n canvas.release = function() {\n self.dispose(this);\n };\n this._pool.push(canvas);\n }\n\n const result = this._pool.shift();\n this._actives.push(result);\n return result;\n },\n\n dispose: function(canvas) {\n if (this._actives.contains(canvas)) {\n this._actives.erase(canvas);\n this._pool.push(canvas);\n }\n },\n\n });\n\n});\n"]}