Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2526)

Unified Diff: cc/shader.cc

Issue 12314003: cc: Use highp precision for texture coordinates if available (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use GL_FRAGMENT_PRECISION_HIGH properly Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/shader.cc
diff --git a/cc/shader.cc b/cc/shader.cc
index c52423103e8b2a96b6cfdec9abc48787406d546e..9a6a991cc57c85d5ae23bc86bf66bd36e3193df6 100644
--- a/cc/shader.cc
+++ b/cc/shader.cc
@@ -9,7 +9,7 @@
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
#define SHADER0(Src) #Src
-#define SHADER(Src) SHADER0(Src)
+#define SHADER(Src) fixShader(SHADER0(Src))
using WebKit::WebGraphicsContext3D;
@@ -30,6 +30,15 @@ static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p
}
}
+static std::string fixShader(const char* shaderString) {
Vangelis Kokkevis 2013/02/21 07:47:35 nit: please use a more descriptive name for this f
+ return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
+ "#define TexCoordPrecision highp\n"
+ "#else\n"
+ "#define TexCoordPrecision mediump\n"
+ "#endif\n" +
+ std::string(shaderString);
+}
+
}
VertexShaderPosTex::VertexShaderPosTex()
@@ -54,9 +63,9 @@ std::string VertexShaderPosTex::getShaderString() const
{
return SHADER(
attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec2 a_texCoord;
Vangelis Kokkevis 2013/02/21 07:47:35 I wonder if we should leave the vertex shaders alo
Sami 2013/02/21 11:47:38 Right. We could add a VERTEX_SHADER and FRAGMENT_S
brianderson 2013/02/21 23:05:55 Hmm, I had VERTEX_SHADER and FRAGMENT_SHADER macro
uniform mat4 matrix;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
void main()
{
gl_Position = matrix * a_position;
@@ -91,10 +100,10 @@ std::string VertexShaderPosTexYUVStretch::getShaderString() const
return SHADER(
precision mediump float;
attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
- varying vec2 v_texCoord;
- uniform vec2 texScale;
+ varying TexCoordPrecision vec2 v_texCoord;
+ uniform TexCoordPrecision vec2 texScale;
void main()
{
gl_Position = matrix * a_position;
@@ -161,17 +170,17 @@ std::string VertexShaderPosTexTransform::getShaderString() const
{
return SHADER(
attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec2 a_texCoord;
attribute float a_index;
uniform mat4 matrix[8];
- uniform vec4 texTransform[8];
+ uniform TexCoordPrecision vec4 texTransform[8];
uniform float opacity[32];
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
void main()
{
gl_Position = matrix[int(a_index * 0.25)] * a_position;
- vec4 texTrans = texTransform[int(a_index * 0.25)];
+ TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)];
v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
v_alpha = opacity[int(a_index)];
}
@@ -182,7 +191,7 @@ std::string VertexShaderPosTexIdentity::getShaderString() const
{
return SHADER(
attribute vec4 a_position;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
void main()
{
gl_Position = a_position;
@@ -220,16 +229,16 @@ void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
std::string VertexShaderQuad::getShaderString() const
{
return SHADER(
- attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec4 a_position;
+ attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
- uniform vec2 point[4];
- uniform vec2 texScale;
- varying vec2 v_texCoord;
+ uniform TexCoordPrecision vec2 point[4];
+ uniform TexCoordPrecision vec2 texScale;
+ varying TexCoordPrecision vec2 v_texCoord;
void main()
{
- vec2 complement = abs(a_texCoord - 1.0);
- vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
+ TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0);
+ TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
pos.xy += (complement.x * complement.y) * point[0];
pos.xy += (a_texCoord.x * complement.y) * point[1];
pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
@@ -267,12 +276,12 @@ void VertexShaderTile::init(WebGraphicsContext3D* context, unsigned program, boo
std::string VertexShaderTile::getShaderString() const
{
return SHADER(
- attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec4 a_position;
+ attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
- uniform vec2 point[4];
- uniform vec4 vertexTexTransform;
- varying vec2 v_texCoord;
+ uniform TexCoordPrecision vec2 point[4];
+ uniform TexCoordPrecision vec4 vertexTexTransform;
+ varying TexCoordPrecision vec2 v_texCoord;
void main()
{
vec2 complement = abs(a_texCoord - 1.0);
@@ -312,10 +321,10 @@ std::string VertexShaderVideoTransform::getShaderString() const
{
return SHADER(
attribute vec4 a_position;
- attribute vec2 a_texCoord;
+ attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
- uniform mat4 texMatrix;
- varying vec2 v_texCoord;
+ uniform TexCoordPrecision mat4 texMatrix;
+ varying TexCoordPrecision vec2 v_texCoord;
void main()
{
gl_Position = matrix * a_position;
@@ -367,7 +376,7 @@ std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
uniform sampler2D s_texture;
void main()
@@ -394,22 +403,23 @@ bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
std::string FragmentShaderOESImageExternal::getShaderString() const
{
// Cannot use the SHADER() macro because of the '#' char
- return "#extension GL_OES_EGL_image_external : require \n"
+ return fixShader(
+ "#extension GL_OES_EGL_image_external : require \n"
"precision mediump float;\n"
- "varying vec2 v_texCoord;\n"
+ "varying TexCoordPrecision vec2 v_texCoord;\n"
"uniform samplerExternalOES s_texture;\n"
"void main()\n"
"{\n"
" vec4 texColor = texture2D(s_texture, v_texCoord);\n"
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w);\n"
- "}\n";
+ "}\n");
}
std::string FragmentShaderRGBATexAlpha::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform float alpha;
void main()
@@ -424,7 +434,7 @@ std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
uniform sampler2D s_texture;
void main()
@@ -439,38 +449,40 @@ std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const
{
// This must be paired with VertexShaderPosTexTransform to pick up the texTransform uniform.
// The necessary #extension preprocessing directive breaks the SHADER and SHADER0 macros.
- return "#extension GL_ARB_texture_rectangle : require\n"
+ return fixShader(
+ "#extension GL_ARB_texture_rectangle : require\n"
"precision mediump float;\n"
- "varying vec2 v_texCoord;\n"
+ "varying TexCoordPrecision vec2 v_texCoord;\n"
"varying float v_alpha;\n"
- "uniform vec4 texTransform;\n"
+ "uniform TexCoordPrecision vec4 texTransform;\n"
"uniform sampler2DRect s_texture;\n"
"void main()\n"
"{\n"
" vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, texTransform.w - v_texCoord.y));\n"
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha;\n"
- "}\n";
+ "}\n");
}
std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const
{
- return "#extension GL_ARB_texture_rectangle : require\n"
+ return fixShader(
+ "#extension GL_ARB_texture_rectangle : require\n"
"precision mediump float;\n"
- "varying vec2 v_texCoord;\n"
+ "varying TexCoordPrecision vec2 v_texCoord;\n"
"varying float v_alpha;\n"
"uniform sampler2DRect s_texture;\n"
"void main()\n"
"{\n"
" vec4 texColor = texture2DRect(s_texture, v_texCoord);\n"
" gl_FragColor = texColor * v_alpha;\n"
- "}\n";
+ "}\n");
}
std::string FragmentShaderRGBATexOpaque::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
void main()
{
@@ -484,7 +496,7 @@ std::string FragmentShaderRGBATex::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
void main()
{
@@ -497,7 +509,7 @@ std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform float alpha;
void main()
@@ -512,7 +524,7 @@ std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
void main()
{
@@ -550,7 +562,7 @@ std::string FragmentShaderRGBATexAlphaAA::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform float alpha;
uniform vec3 edge[8];
@@ -602,14 +614,14 @@ std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform float alpha;
- uniform vec4 fragmentTexTransform;
+ uniform TexCoordPrecision vec4 fragmentTexTransform;
uniform vec3 edge[8];
void main()
{
- vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy;
+ TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy;
vec4 texColor = texture2D(s_texture, texCoord);
vec3 pos = vec3(gl_FragCoord.xy, 1);
float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
@@ -629,14 +641,14 @@ std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform float alpha;
- uniform vec4 fragmentTexTransform;
+ uniform TexCoordPrecision vec4 fragmentTexTransform;
uniform vec3 edge[8];
void main()
{
- vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy;
+ TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + fragmentTexTransform.xy;
vec4 texColor = texture2D(s_texture, texCoord);
vec3 pos = vec3(gl_FragCoord.xy, 1);
float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
@@ -685,16 +697,16 @@ std::string FragmentShaderRGBATexAlphaMask::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform sampler2D s_mask;
- uniform vec2 maskTexCoordScale;
- uniform vec2 maskTexCoordOffset;
+ uniform TexCoordPrecision vec2 maskTexCoordScale;
+ uniform TexCoordPrecision vec2 maskTexCoordOffset;
uniform float alpha;
void main()
{
vec4 texColor = texture2D(s_texture, v_texCoord);
- vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
+ TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
vec4 maskColor = texture2D(s_mask, maskTexCoord);
gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w;
}
@@ -737,17 +749,17 @@ std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const
{
return SHADER(
precision mediump float;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D s_texture;
uniform sampler2D s_mask;
- uniform vec2 maskTexCoordScale;
- uniform vec2 maskTexCoordOffset;
+ uniform TexCoordPrecision vec2 maskTexCoordScale;
+ uniform TexCoordPrecision vec2 maskTexCoordOffset;
uniform float alpha;
uniform vec3 edge[8];
void main()
{
vec4 texColor = texture2D(s_texture, v_texCoord);
- vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
+ TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
vec4 maskColor = texture2D(s_mask, maskTexCoord);
vec3 pos = vec3(gl_FragCoord.xy, 1);
float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
@@ -803,7 +815,7 @@ std::string FragmentShaderYUVVideo::getShaderString() const
return SHADER(
precision mediump float;
precision mediump int;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform sampler2D y_texture;
uniform sampler2D u_texture;
uniform sampler2D v_texture;
@@ -885,7 +897,7 @@ std::string FragmentShaderCheckerboard::getShaderString() const
return SHADER(
precision mediump float;
precision mediump int;
- varying vec2 v_texCoord;
+ varying TexCoordPrecision vec2 v_texCoord;
uniform float alpha;
uniform float frequency;
uniform vec4 texTransform;
@@ -894,7 +906,7 @@ std::string FragmentShaderCheckerboard::getShaderString() const
{
vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0);
vec4 color2 = color;
- vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
+ TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
float picker = abs(coord.x - coord.y);
gl_FragColor = mix(color1, color2, picker) * alpha;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698