Explorar el Código

Create array views for WebGL only once

Dominic Szablewski hace 11 años
padre
commit
6d304a1f5c
Se han modificado 1 ficheros con 9 adiciones y 9 borrados
  1. 9 9
      jsmpg.js

+ 9 - 9
jsmpg.js Ver fichero

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