|
|
@@ -26,9 +26,9 @@ var WebGLRenderer = function(options) {
|
|
26
|
26
|
var vertexAttr = null;
|
|
27
|
27
|
|
|
28
|
28
|
// Init buffers
|
|
29
|
|
- var vertexBuffer = gl.createBuffer();
|
|
|
29
|
+ this.vertexBuffer = gl.createBuffer();
|
|
30
|
30
|
var vertexCoords = new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]);
|
|
31
|
|
- gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
|
|
31
|
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
|
32
|
32
|
gl.bufferData(gl.ARRAY_BUFFER, vertexCoords, gl.STATIC_DRAW);
|
|
33
|
33
|
|
|
34
|
34
|
// Setup the main YCrCbToRGBA shader
|
|
|
@@ -57,6 +57,19 @@ var WebGLRenderer = function(options) {
|
|
57
|
57
|
this.shouldCreateUnclampedViews = !this.allowsClampedTextureData();
|
|
58
|
58
|
};
|
|
59
|
59
|
|
|
|
60
|
+WebGLRenderer.prototype.destroy = function() {
|
|
|
61
|
+ var gl = this.gl;
|
|
|
62
|
+
|
|
|
63
|
+ gl.deleteTexture(this.textureY);
|
|
|
64
|
+ gl.deleteTexture(this.textureCb);
|
|
|
65
|
+ gl.deleteTexture(this.textureCr);
|
|
|
66
|
+
|
|
|
67
|
+ gl.deleteProgram(this.program);
|
|
|
68
|
+ gl.deleteProgram(this.loadingProgram);
|
|
|
69
|
+
|
|
|
70
|
+ gl.deleteBuffer(this.vertexBuffer);
|
|
|
71
|
+};
|
|
|
72
|
+
|
|
60
|
73
|
WebGLRenderer.prototype.resize = function(width, height) {
|
|
61
|
74
|
this.width = width|0;
|
|
62
|
75
|
this.height = height|0;
|
|
|
@@ -121,8 +134,12 @@ WebGLRenderer.prototype.allowsClampedTextureData = function() {
|
|
121
|
134
|
|
|
122
|
135
|
WebGLRenderer.prototype.renderProgress = function(progress) {
|
|
123
|
136
|
var gl = this.gl;
|
|
|
137
|
+
|
|
|
138
|
+ gl.useProgram(this.loadingProgram);
|
|
|
139
|
+
|
|
124
|
140
|
var loc = gl.getUniformLocation(this.loadingProgram, 'progress');
|
|
125
|
141
|
gl.uniform1f(loc, progress);
|
|
|
142
|
+
|
|
126
|
143
|
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
127
|
144
|
};
|
|
128
|
145
|
|
|
|
@@ -144,7 +161,9 @@ WebGLRenderer.prototype.render = function(y, cb, cr) {
|
|
144
|
161
|
y = new Uint8Array(y.buffer),
|
|
145
|
162
|
cb = new Uint8Array(cb.buffer),
|
|
146
|
163
|
cr = new Uint8Array(cr.buffer);
|
|
147
|
|
- }
|
|
|
164
|
+ }
|
|
|
165
|
+
|
|
|
166
|
+ gl.useProgram(this.program);
|
|
148
|
167
|
|
|
149
|
168
|
this.updateTexture(gl.TEXTURE0, this.textureY, w, h, y);
|
|
150
|
169
|
this.updateTexture(gl.TEXTURE1, this.textureCb, w2, h2, cb);
|