Skip to content

Commit

Permalink
Create array views for WebGL only once
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Nov 4, 2014
1 parent d780c59 commit 6d304a1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions jsmpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ jsmpeg.prototype.initBuffers = function() {

if( this.gl ) {
this.gl.useProgram(this.program);

// WebGL doesn't like Uint8ClampedArrays, so we have to create a
// Uint8Array view for each plane
this.currentYUint8 = new Uint8Array(this.currentY.buffer),
this.currentCrUint8 = new Uint8Array(this.currentCr.buffer),
this.currentCbUint8 = new Uint8Array(this.currentCb.buffer);
}
else {
this.currentRGBA = this.canvasContext.getImageData(0, 0, this.width, this.height);
Expand Down Expand Up @@ -837,25 +843,19 @@ jsmpeg.prototype.initWebGL = function() {

jsmpeg.prototype.renderFrameGL = function() {
var gl = this.gl;

// WebGL doesn't like Uint8ClampedArrays, so we have to create a Uint8Array view for
// each plane
var uint8Y = new Uint8Array(this.currentY.buffer),
uint8Cr = new Uint8Array(this.currentCr.buffer),
uint8Cb = new Uint8Array(this.currentCb.buffer);

gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, this.YTexture);

gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.codedWidth, this.height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Y);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.codedWidth, this.height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentYUint8);

gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, this.CBTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Cr);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentCrUint8);

gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, this.CRTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, uint8Cb);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, this.halfWidth, this.height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, this.currentCbUint8);

gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
};
Expand Down

0 comments on commit 6d304a1

Please sign in to comment.