-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (53 loc) · 1.79 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
var twgl_cc = {
/**
* Creates a ProgramInfo from 2 source paths.
* See http://twgljs.org/docs/module-twgl.html#.createProgramInfo.
* @param {String} vertexShaderPath
* @param {String} fragmentShaderPath
* @param {Object} options
* @returns {Object} Dictionary which has {twgl.ProgramInfo} under 'twgl' key, {cc.GLProgram} under 'cc' and {WebGLProgram} under 'webgl'
*/
createProgramInfo: function (vertexShaderPath, fragmentShaderPath, options) {
options || (options = {});
var shader = new cc.GLProgram(vertexShaderPath, fragmentShaderPath);
if (options.attribs) {
for (var attributeName in options.attribs) {
var index = options.attribs[attributeName];
shader.addAttribute(attributeName, index)
}
}
shader.link();
shader.updateUniforms();
shader.setUniformsForBuiltins();
if (options.attribPrefix !== false) {
twgl.setDefaults({attribPrefix: options.attribPrefix ? options.attribPrefix : 'a_'});
}
var programInfo = twgl.createProgramInfoFromProgram(this.gl, shader.getProgram());
return {
twgl: programInfo,
cc: shader,
webgl: shader.getProgram()
};
},
/**
* Creates a cocos2d Texture2D from path.
* @param {String} path
* @returns {cc.Texture2D}
*/
createTextureInfo: function (path) {
return cc.textureCache.addImage(path);
},
/**
* Binds texture.
* @param {cc.Texture2D} textureInfo
*/
bindTexture: function (textureInfo) {
return cc.glBindTexture2D(textureInfo);
}
};
Object.defineProperty(twgl_cc, 'gl', {
get: function () {
return cc._renderContext;
}
});
module.exports = twgl_cc;