Просмотр исходного кода

Re-create Uint8 array views each frame

Dominic Szablewski 11 лет назад
Родитель
Сommit
2cdc812d74
1 измененных файлов: 9 добавлений и 9 удалений
  1. 9 9
      jsmpg.js

+ 9 - 9
jsmpg.js Просмотреть файл

565
 	if( this.gl ) {
565
 	if( this.gl ) {
566
 		this.gl.useProgram(this.program);
566
 		this.gl.useProgram(this.program);
567
 		this.gl.viewport(0, 0, this.width, this.height);
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
 	else {
569
 	else {
576
 		this.currentRGBA = this.canvasContext.getImageData(0, 0, this.width, this.height);
570
 		this.currentRGBA = this.canvasContext.getImageData(0, 0, this.width, this.height);
844
 
838
 
845
 jsmpeg.prototype.renderFrameGL = function() {
839
 jsmpeg.prototype.renderFrameGL = function() {
846
 	var gl = this.gl;
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
 	gl.activeTexture(gl.TEXTURE0);
848
 	gl.activeTexture(gl.TEXTURE0);
849
 	gl.bindTexture(gl.TEXTURE_2D, this.YTexture);
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
 	gl.activeTexture(gl.TEXTURE1);
853
 	gl.activeTexture(gl.TEXTURE1);
854
 	gl.bindTexture(gl.TEXTURE_2D, this.CBTexture);
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
 	gl.activeTexture(gl.TEXTURE2);
857
 	gl.activeTexture(gl.TEXTURE2);
858
 	gl.bindTexture(gl.TEXTURE_2D, this.CRTexture);
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
 	gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
861
 	gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
862
 };
862
 };