Explorar el Código

Attempt to cleanly free WebGL context

phoboslab hace 5 años
padre
commit
335b86f342
Se han modificado 1 ficheros con 13 adiciones y 4 borrados
  1. 13 4
      src/webgl.js

+ 13 - 4
src/webgl.js Ver fichero

@@ -65,13 +65,15 @@ var WebGLRenderer = function(options) {
65 65
 WebGLRenderer.prototype.destroy = function() {
66 66
 	var gl = this.gl;
67 67
 	
68
-	gl.deleteTexture(this.textureY);
69
-	gl.deleteTexture(this.textureCb);
70
-	gl.deleteTexture(this.textureCr);
68
+	this.deleteTexture(gl.TEXTURE0, this.textureY);
69
+	this.deleteTexture(gl.TEXTURE1, this.textureCb);
70
+	this.deleteTexture(gl.TEXTURE2, this.textureCr);
71 71
 
72
+	gl.useProgram(null);
72 73
 	gl.deleteProgram(this.program);
73 74
 	gl.deleteProgram(this.loadingProgram);
74 75
 
76
+	gl.bindBuffer(gl.ARRAY_BUFFER, null);
75 77
 	gl.deleteBuffer(this.vertexBuffer);
76 78
 
77 79
 	gl.getExtension('WEBGL_lose_context').loseContext();
@@ -197,7 +199,14 @@ WebGLRenderer.prototype.updateTexture = function(unit, texture, w, h, data) {
197 199
 			gl.LUMINANCE, gl.UNSIGNED_BYTE, data
198 200
 		);
199 201
 	}
200
-}
202
+};
203
+
204
+WebGLRenderer.prototype.deleteTexture = function(unit, texture) {
205
+	var gl = this.gl;
206
+	gl.activeTexture(unit);
207
+	gl.bindTexture(gl.TEXTURE_2D, null);
208
+	gl.deleteTexture(texture);
209
+};
201 210
 
202 211
 WebGLRenderer.IsSupported = function() {
203 212
 	try {