forked from dlecocq/webglot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emptytexture.js
40 lines (30 loc) · 1.27 KB
/
emptytexture.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
/* http://learningwebgl.com/blog/?p=507
*/
function emptytexture(context, width, height) {
this.texture = null;
this.image = null;
this.gl = context;
this.width = 0;
this.height = 0;
this.initialize = function(width, height) {
this.width = width;
this.height = height;
this.texture = this.gl.createTexture();
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
var pixels = new WebGLFloatArray(width * height * 4);
//this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, width, height, 0, this.gl.RGBA, this.gl.FLOAT, pixels);
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, 0x8814, width, height, 0, this.gl.RGBA, this.gl.FLOAT, pixels);
this.gl.enable(this.gl.TEXTURE_2D);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_S_WRAP, this.gl.CLAMP);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_T_WRAP, this.gl.CLAMP);
this.gl.bindTexture(this.gl.TEXTURE_2D, null);
}
this.bind = function() {
this.gl.enable(this.gl.TEXTURE_2D);
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
}
this.initialize(width, height);
return this.texture;
}