Browse Source

Re-create Uint8 array views each frame

Dominic Szablewski 11 years ago
parent
commit
2cdc812d74
1 changed files with 9 additions and 9 deletions
  1. 9 9
      jsmpg.js

+ 9 - 9
jsmpg.js View File

@@ -565,12 +565,6 @@ jsmpeg.prototype.initBuffers = function() {
565 565
 	if( this.gl ) {
566 566
 		this.gl.useProgram(this.program);
567 567
 		this.gl.viewport(0, 0, this.width, this.height);
568
-
569
-		// WebGL doesn't like Uint8ClampedArrays, so we have to create a 
570
-		// Uint8Array view for each plane
571
-		this.currentYUint8 = new Uint8Array(this.currentY.buffer),
572
-		this.currentCrUint8 = new Uint8Array(this.currentCr.buffer),
573
-		this.currentCbUint8 = new Uint8Array(this.currentCb.buffer);
574 568
 	}
575 569
 	else {
576 570
 		this.currentRGBA = this.canvasContext.getImageData(0, 0, this.width, this.height);
@@ -844,19 +838,25 @@ jsmpeg.prototype.initWebGL = function() {
844 838
 
845 839
 jsmpeg.prototype.renderFrameGL = function() {
846 840
 	var gl = this.gl;
841
+
842
+	// WebGL doesn't like Uint8ClampedArrays, so we have to create a Uint8Array view for 
843
+	// each plane
844
+	var uint8Y = new Uint8Array(this.currentY.buffer),
845
+		uint8Cr = new Uint8Array(this.currentCr.buffer),
846
+		uint8Cb = new Uint8Array(this.currentCb.buffer);
847 847
 	
848 848
 	gl.activeTexture(gl.TEXTURE0);
849 849
 	gl.bindTexture(gl.TEXTURE_2D, this.YTexture);
850 850
 
851
-	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.codedWidth, this.height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentYUint8);
851
+	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.codedWidth, this.height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Y);
852 852
 	
853 853
 	gl.activeTexture(gl.TEXTURE1);
854 854
 	gl.bindTexture(gl.TEXTURE_2D, this.CBTexture);
855
-	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentCrUint8);
855
+	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Cr);
856 856
 	
857 857
 	gl.activeTexture(gl.TEXTURE2);
858 858
 	gl.bindTexture(gl.TEXTURE_2D, this.CRTexture);
859
-	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentCbUint8);
859
+	gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Cb);
860 860
 	
861 861
 	gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
862 862
 };