-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (55 loc) · 1.54 KB
/
index.js
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
65
66
67
68
69
/**
* Expose `shader`
*/
module.exports = shader;
/**
* shader
* @param {WebGLRenderingContext} context A WebGL rendering context.
* @return {Shader} Shader
*/
function shader (context) {
/**
* Create a shader.
* @param {Object} options Options for creating the shader.
* @param {Number} [options.type] The WebGL type of the shader.
* @param {String} [options.source] The source text of the shader.
* @return {v3.Shader} A Shader instance.
* @api public
*/
function Shader (options) {
var options = options || {};
var type = options.type;
var source = options.source;
var shader = context.createShader(type);
context.shaderSource(shader, source);
context.compileShader(shader);
var valid = context.getShaderParameter(shader, context.COMPILE_STATUS);
var log = context.getShaderInfoLog(shader);
this.shader = shader;
this.type = type;
this.source = source;
this.valid = valid;
this.log = log;
};
/**
* Shader.create
* Create a shader.
* @param {Object} options Options for creating the shader.
* @param {Number} [options.type] The WebGL type of the shader.
* @param {String} [options.source] The source text of the shader.
* @return {v3.Shader} A shader.
* @api public
*/
Shader.create = function (options) {
return new Shader(options);
};
/**
* Shader#destroy
* Destroy this shader.
* @api public
*/
Shader.prototype.destroy = function () {
context.deleteShader(this.shader);
};
return Shader;
};