Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to mediump precision for device that doesn't support highp #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions Player/WebGLCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ H264bsdCanvas.prototype.isWebGL = function() {

if(!gl || typeof gl.getParameter !== "function") {
gl = null;
}
}

++nameIndex;
};
Expand Down Expand Up @@ -128,7 +128,7 @@ H264bsdCanvas.prototype.initProgram = function() {
'1.1643828125, 2.017234375, 0, -1.081390625,',
'0, 0, 0, 1',
');',

'void main(void) {',
'highp float y = texture2D(ySampler, textureCoord).r;',
'highp float u = texture2D(uSampler, textureCoord).r;',
Expand All @@ -137,6 +137,11 @@ H264bsdCanvas.prototype.initProgram = function() {
'}'
].join('\n');

var precisionFormat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
if(precisionFormat.precision <= 0) {
fragmentShaderScript = fragmentShaderScript.replace(/highp/g, 'mediump');
}

var vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, vertexShaderScript);
gl.compileShader(vertexShader);
Expand All @@ -160,7 +165,7 @@ H264bsdCanvas.prototype.initProgram = function() {
}

gl.useProgram(program);

this.shaderProgram = program;
};

Expand Down Expand Up @@ -253,7 +258,7 @@ H264bsdCanvas.prototype.drawNextOuptutPictureGL = function(width, height, croppi
var texturePosBuffer = this.texturePosBuffer;
var yTextureRef = this.yTextureRef;
var uTextureRef = this.uTextureRef;
var vTextureRef = this.vTextureRef;
var vTextureRef = this.vTextureRef;

if(croppingParams === null) {
gl.viewport(0, 0, width, height);
Expand Down Expand Up @@ -290,7 +295,7 @@ H264bsdCanvas.prototype.drawNextOuptutPictureGL = function(width, height, croppi
gl.bindTexture(gl.TEXTURE_2D, vTextureRef);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width/2, height/2, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, crData);

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

/**
Expand All @@ -313,7 +318,7 @@ H264bsdCanvas.prototype.drawNextOuptutPictureRGBA = function(width, height, crop
ctx.putImageData(imageData, -croppingParams.left, -croppingParams.top, 0, 0, croppingParams.width, croppingParams.height);
}
};

return H264bsdCanvas;
}));

}));