Commit 535c75f4 authored by enne's avatar enne Committed by Commit bot

cc: clang-format shader.cc

Previously this file could not be formatted because of all the shader
code in magic macros to make it less irritating to edit.  It turns out
"clang-format off" and "clang-format on" in comments make it possible to
selectively apply formatting, so do this for all the shaders.

R=danakj@chromium.org
BUG=none

Review URL: https://codereview.chromium.org/658153003

Cr-Commit-Position: refs/heads/master@{#299996}
parent 56be508a
......@@ -13,8 +13,9 @@
#define SHADER0(Src) #Src
#define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src))
#define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \
precision, SetFragmentSamplerType(sampler, SHADER0(Src)))
#define FRAGMENT_SHADER(Src) \
SetFragmentTexCoordPrecision(precision, \
SetFragmentSamplerType(sampler, SHADER0(Src)))
using gpu::gles2::GLES2Interface;
......@@ -35,12 +36,12 @@ static void GetProgramUniformLocations(GLES2Interface* context,
}
static std::string SetFragmentTexCoordPrecision(
TexCoordPrecision requested_precision, std::string shader_string) {
TexCoordPrecision requested_precision,
std::string shader_string) {
switch (requested_precision) {
case TexCoordPrecisionHigh:
DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
return
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
" #define TexCoordPrecision highp\n"
"#else\n"
" #define TexCoordPrecision mediump\n"
......@@ -48,8 +49,7 @@ static std::string SetFragmentTexCoordPrecision(
shader_string;
case TexCoordPrecisionMedium:
DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
return "#define TexCoordPrecision mediump\n" +
shader_string;
return "#define TexCoordPrecision mediump\n" + shader_string;
case TexCoordPrecisionNA:
DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos);
DCHECK_EQ(shader_string.find("texture2D"), std::string::npos);
......@@ -67,24 +67,24 @@ static std::string SetVertexTexCoordPrecision(const char* shader_string) {
// we are unlikely to be vertex shader bound when drawing large quads.
// Also, some vertex shaders mutate the texture coordinate in such a
// way that the effective precision might be lower than expected.
return "#define TexCoordPrecision highp\n" +
std::string(shader_string);
return "#define TexCoordPrecision highp\n" + std::string(shader_string);
}
TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
int *highp_threshold_cache,
int* highp_threshold_cache,
int highp_threshold_min,
int x, int y) {
int x,
int y) {
if (*highp_threshold_cache == 0) {
// Initialize range and precision with minimum spec values for when
// GetShaderPrecisionFormat is a test stub.
// TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat
// everywhere.
GLint range[2] = { 14, 14 };
GLint range[2] = {14, 14};
GLint precision = 10;
GLC(context, context->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER,
GL_MEDIUM_FLOAT,
range, &precision));
GLC(context,
context->GetShaderPrecisionFormat(
GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision));
*highp_threshold_cache = 1 << precision;
}
......@@ -94,29 +94,26 @@ TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
return TexCoordPrecisionMedium;
}
static std::string SetFragmentSamplerType(
SamplerType requested_type, std::string shader_string) {
static std::string SetFragmentSamplerType(SamplerType requested_type,
std::string shader_string) {
switch (requested_type) {
case SamplerType2D:
DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
return
"#define SamplerType sampler2D\n"
return "#define SamplerType sampler2D\n"
"#define TextureLookup texture2D\n" +
shader_string;
case SamplerType2DRect:
DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
return
"#extension GL_ARB_texture_rectangle : require\n"
return "#extension GL_ARB_texture_rectangle : require\n"
"#define SamplerType sampler2DRect\n"
"#define TextureLookup texture2DRect\n" +
shader_string;
case SamplerTypeExternalOES:
DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
return
"#extension GL_OES_EGL_image_external : require\n"
return "#extension GL_OES_EGL_image_external : require\n"
"#define SamplerType samplerExternalOES\n"
"#define TextureLookup texture2D\n" +
shader_string;
......@@ -138,21 +135,25 @@ TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
int highp_threshold_min,
const gfx::Point& max_coordinate) {
return TexCoordPrecisionRequired(context,
highp_threshold_cache, highp_threshold_min,
max_coordinate.x(), max_coordinate.y());
highp_threshold_cache,
highp_threshold_min,
max_coordinate.x(),
max_coordinate.y());
}
TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
int *highp_threshold_cache,
int* highp_threshold_cache,
int highp_threshold_min,
const gfx::Size& max_size) {
return TexCoordPrecisionRequired(context,
highp_threshold_cache, highp_threshold_min,
max_size.width(), max_size.height());
highp_threshold_cache,
highp_threshold_min,
max_size.width(),
max_size.height());
}
VertexShaderPosTex::VertexShaderPosTex()
: matrix_location_(-1) {}
VertexShaderPosTex::VertexShaderPosTex() : matrix_location_(-1) {
}
void VertexShaderPosTex::Init(GLES2Interface* context,
unsigned program,
......@@ -172,7 +173,9 @@ void VertexShaderPosTex::Init(GLES2Interface* context,
}
std::string VertexShaderPosTex::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute vec4 a_position;
attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
......@@ -181,19 +184,20 @@ std::string VertexShaderPosTex::GetShaderString() const {
gl_Position = matrix * a_position;
v_texCoord = a_texCoord;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset()
: matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {}
: matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {
}
void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"texScale",
"texOffset",
"matrix", "texScale", "texOffset",
};
int locations[arraysize(uniforms)];
......@@ -209,7 +213,9 @@ void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context,
}
std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
precision mediump float;
attribute vec4 a_position;
attribute TexCoordPrecision vec2 a_texCoord;
......@@ -221,11 +227,13 @@ std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const {
gl_Position = matrix * a_position;
v_texCoord = a_texCoord * texScale + texOffset;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderPos::VertexShaderPos()
: matrix_location_(-1) {}
VertexShaderPos::VertexShaderPos() : matrix_location_(-1) {
}
void VertexShaderPos::Init(GLES2Interface* context,
unsigned program,
......@@ -245,27 +253,28 @@ void VertexShaderPos::Init(GLES2Interface* context,
}
std::string VertexShaderPos::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute vec4 a_position;
uniform mat4 matrix;
void main() {
gl_Position = matrix * a_position;
}
void main() { gl_Position = matrix * a_position; }
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderPosTexTransform::VertexShaderPosTexTransform()
: matrix_location_(-1),
tex_transform_location_(-1),
vertex_opacity_location_(-1) {}
vertex_opacity_location_(-1) {
}
void VertexShaderPosTexTransform::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"texTransform",
"opacity",
"matrix", "texTransform", "opacity",
};
int locations[arraysize(uniforms)];
......@@ -281,7 +290,9 @@ void VertexShaderPosTexTransform::Init(GLES2Interface* context,
}
std::string VertexShaderPosTexTransform::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute vec4 a_position;
attribute TexCoordPrecision vec2 a_texCoord;
attribute float a_index;
......@@ -297,30 +308,35 @@ std::string VertexShaderPosTexTransform::GetShaderString() const {
v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
v_alpha = opacity[int(a_index)]; // NOLINT
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string VertexShaderPosTexIdentity::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute vec4 a_position;
varying TexCoordPrecision vec2 v_texCoord;
void main() {
gl_Position = a_position;
v_texCoord = (a_position.xy + vec2(1.0)) * 0.5;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderQuad::VertexShaderQuad()
: matrix_location_(-1),
quad_location_(-1) {}
: matrix_location_(-1), quad_location_(-1) {
}
void VertexShaderQuad::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"quad",
"matrix", "quad",
};
int locations[arraysize(uniforms)];
......@@ -336,10 +352,12 @@ void VertexShaderQuad::Init(GLES2Interface* context,
std::string VertexShaderQuad::GetShaderString() const {
#if defined(OS_ANDROID)
// TODO(epenner): Find the cause of this 'quad' uniform
// being missing if we don't add dummy variables.
// http://crbug.com/240602
// TODO(epenner): Find the cause of this 'quad' uniform
// being missing if we don't add dummy variables.
// http://crbug.com/240602
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -351,9 +369,13 @@ std::string VertexShaderQuad::GetShaderString() const {
gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
dummy_varying = dummy_uniform;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
#else
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -362,7 +384,9 @@ std::string VertexShaderQuad::GetShaderString() const {
vec2 pos = quad[int(a_index)]; // NOLINT
gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
#endif
}
......@@ -370,16 +394,14 @@ VertexShaderQuadAA::VertexShaderQuadAA()
: matrix_location_(-1),
viewport_location_(-1),
quad_location_(-1),
edge_location_(-1) {}
edge_location_(-1) {
}
void VertexShaderQuadAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"viewport",
"quad",
"edge",
"matrix", "viewport", "quad", "edge",
};
int locations[arraysize(uniforms)];
......@@ -396,7 +418,9 @@ void VertexShaderQuadAA::Init(GLES2Interface* context,
}
std::string VertexShaderQuadAA::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -413,13 +437,17 @@ std::string VertexShaderQuadAA::GetShaderString() const {
edge_dist[0] = vec4(dot(edge[0], screen_pos),
dot(edge[1], screen_pos),
dot(edge[2], screen_pos),
dot(edge[3], screen_pos)) * gl_Position.w;
dot(edge[3], screen_pos)) *
gl_Position.w;
edge_dist[1] = vec4(dot(edge[4], screen_pos),
dot(edge[5], screen_pos),
dot(edge[6], screen_pos),
dot(edge[7], screen_pos)) * gl_Position.w;
dot(edge[7], screen_pos)) *
gl_Position.w;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA()
......@@ -427,17 +455,14 @@ VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA()
viewport_location_(-1),
quad_location_(-1),
edge_location_(-1),
tex_transform_location_(-1) {}
tex_transform_location_(-1) {
}
void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"viewport",
"quad",
"edge",
"texTrans",
"matrix", "viewport", "quad", "edge", "texTrans",
};
int locations[arraysize(uniforms)];
......@@ -455,7 +480,9 @@ void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context,
}
std::string VertexShaderQuadTexTransformAA::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -474,28 +501,31 @@ std::string VertexShaderQuadTexTransformAA::GetShaderString() const {
edge_dist[0] = vec4(dot(edge[0], screen_pos),
dot(edge[1], screen_pos),
dot(edge[2], screen_pos),
dot(edge[3], screen_pos)) * gl_Position.w;
dot(edge[3], screen_pos)) *
gl_Position.w;
edge_dist[1] = vec4(dot(edge[4], screen_pos),
dot(edge[5], screen_pos),
dot(edge[6], screen_pos),
dot(edge[7], screen_pos)) * gl_Position.w;
dot(edge[7], screen_pos)) *
gl_Position.w;
v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderTile::VertexShaderTile()
: matrix_location_(-1),
quad_location_(-1),
vertex_tex_transform_location_(-1) {}
vertex_tex_transform_location_(-1) {
}
void VertexShaderTile::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"quad",
"vertexTexTransform",
"matrix", "quad", "vertexTexTransform",
};
int locations[arraysize(uniforms)];
......@@ -511,7 +541,9 @@ void VertexShaderTile::Init(GLES2Interface* context,
}
std::string VertexShaderTile::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -523,7 +555,9 @@ std::string VertexShaderTile::GetShaderString() const {
gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderTileAA::VertexShaderTileAA()
......@@ -531,17 +565,14 @@ VertexShaderTileAA::VertexShaderTileAA()
viewport_location_(-1),
quad_location_(-1),
edge_location_(-1),
vertex_tex_transform_location_(-1) {}
vertex_tex_transform_location_(-1) {
}
void VertexShaderTileAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"viewport",
"quad",
"edge",
"vertexTexTransform",
"matrix", "viewport", "quad", "edge", "vertexTexTransform",
};
int locations[arraysize(uniforms)];
......@@ -559,7 +590,9 @@ void VertexShaderTileAA::Init(GLES2Interface* context,
}
std::string VertexShaderTileAA::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute TexCoordPrecision vec4 a_position;
attribute float a_index;
uniform mat4 matrix;
......@@ -578,26 +611,29 @@ std::string VertexShaderTileAA::GetShaderString() const {
edge_dist[0] = vec4(dot(edge[0], screen_pos),
dot(edge[1], screen_pos),
dot(edge[2], screen_pos),
dot(edge[3], screen_pos)) * gl_Position.w;
dot(edge[3], screen_pos)) *
gl_Position.w;
edge_dist[1] = vec4(dot(edge[4], screen_pos),
dot(edge[5], screen_pos),
dot(edge[6], screen_pos),
dot(edge[7], screen_pos)) * gl_Position.w;
dot(edge[7], screen_pos)) *
gl_Position.w;
v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
VertexShaderVideoTransform::VertexShaderVideoTransform()
: matrix_location_(-1),
tex_matrix_location_(-1) {}
: matrix_location_(-1), tex_matrix_location_(-1) {
}
void VertexShaderVideoTransform::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"matrix",
"texMatrix",
"matrix", "texMatrix",
};
int locations[arraysize(uniforms)];
......@@ -612,7 +648,9 @@ void VertexShaderVideoTransform::Init(GLES2Interface* context,
}
std::string VertexShaderVideoTransform::GetShaderString() const {
// clang-format off
return VERTEX_SHADER(
// clang-format on
attribute vec4 a_position;
attribute TexCoordPrecision vec2 a_texCoord;
uniform mat4 matrix;
......@@ -623,19 +661,20 @@ std::string VertexShaderVideoTransform::GetShaderString() const {
v_texCoord =
vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentTexAlphaBinding::FragmentTexAlphaBinding()
: sampler_location_(-1),
alpha_location_(-1) {}
: sampler_location_(-1), alpha_location_(-1) {
}
void FragmentTexAlphaBinding::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"alpha",
"s_texture", "alpha",
};
int locations[arraysize(uniforms)];
......@@ -653,16 +692,14 @@ FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding()
: sampler_location_(-1),
alpha_location_(-1),
color_matrix_location_(-1),
color_offset_location_(-1) {}
color_offset_location_(-1) {
}
void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"alpha",
"colorMatrix",
"colorOffset",
"s_texture", "alpha", "colorMatrix", "colorOffset",
};
int locations[arraysize(uniforms)];
......@@ -678,8 +715,8 @@ void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context,
color_offset_location_ = locations[3];
}
FragmentTexOpaqueBinding::FragmentTexOpaqueBinding()
: sampler_location_(-1) {}
FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) {
}
void FragmentTexOpaqueBinding::Init(GLES2Interface* context,
unsigned program,
......@@ -699,8 +736,11 @@ void FragmentTexOpaqueBinding::Init(GLES2Interface* context,
}
std::string FragmentShaderRGBATexAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -709,12 +749,17 @@ std::string FragmentShaderRGBATexAlpha::GetShaderString(
vec4 texColor = TextureLookup(s_texture, v_texCoord);
gl_FragColor = texColor * alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -730,12 +775,17 @@ std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
texColor = clamp(texColor, 0.0, 1.0);
gl_FragColor = texColor * alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
......@@ -744,12 +794,17 @@ std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
vec4 texColor = TextureLookup(s_texture, v_texCoord);
gl_FragColor = texColor * v_alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
......@@ -759,20 +814,20 @@ std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString(
texColor.rgb *= texColor.a;
gl_FragColor = texColor * v_alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
: background_color_location_(-1),
sampler_location_(-1) {
: background_color_location_(-1), sampler_location_(-1) {
}
void FragmentTexBackgroundBinding::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"background_color",
"s_texture", "background_color",
};
int locations[arraysize(uniforms)];
......@@ -791,8 +846,11 @@ void FragmentTexBackgroundBinding::Init(GLES2Interface* context,
}
std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
......@@ -803,12 +861,17 @@ std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
texColor += background_color * (1.0 - texColor.a);
gl_FragColor = texColor * v_alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
varying float v_alpha;
......@@ -820,12 +883,17 @@ std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
texColor += background_color * (1.0 - texColor.a);
gl_FragColor = texColor * v_alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexOpaque::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -833,24 +901,31 @@ std::string FragmentShaderRGBATexOpaque::GetShaderString(
vec4 texColor = TextureLookup(s_texture, v_texCoord);
gl_FragColor = vec4(texColor.rgb, 1.0);
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATex::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
void main() {
gl_FragColor = TextureLookup(s_texture, v_texCoord);
}
void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); }
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -860,12 +935,17 @@ std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString(
gl_FragColor =
vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -873,19 +953,20 @@ std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString(
vec4 texColor = TextureLookup(s_texture, v_texCoord);
gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
: sampler_location_(-1),
alpha_location_(-1) {}
: sampler_location_(-1), alpha_location_(-1) {
}
void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"alpha",
"s_texture", "alpha",
};
int locations[arraysize(uniforms)];
......@@ -900,8 +981,11 @@ void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context,
}
std::string FragmentShaderRGBATexAlphaAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform float alpha;
......@@ -915,21 +999,22 @@ std::string FragmentShaderRGBATexAlphaAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = texColor * alpha * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
: sampler_location_(-1),
alpha_location_(-1),
fragment_tex_transform_location_(-1) {}
fragment_tex_transform_location_(-1) {
}
void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"alpha",
"fragmentTexTransform",
"s_texture", "alpha", "fragmentTexTransform",
};
int locations[arraysize(uniforms)];
......@@ -945,8 +1030,11 @@ void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context,
}
std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform float alpha;
......@@ -964,12 +1052,17 @@ std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = texColor * alpha * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform float alpha;
......@@ -985,27 +1078,26 @@ std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString(
vec4 d4 = min(edge_dist[0], edge_dist[1]);
vec2 d2 = min(d4.xz, d4.yw);
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) *
alpha * aa;
gl_FragColor =
vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
: sampler_location_(-1),
mask_sampler_location_(-1),
alpha_location_(-1),
mask_tex_coord_scale_location_(-1) {}
mask_tex_coord_scale_location_(-1) {
}
void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"s_mask",
"alpha",
"maskTexCoordScale",
"maskTexCoordOffset",
"s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset",
};
int locations[arraysize(uniforms)];
......@@ -1023,8 +1115,11 @@ void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context,
}
std::string FragmentShaderRGBATexAlphaMask::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -1040,7 +1135,9 @@ std::string FragmentShaderRGBATexAlphaMask::GetShaderString(
vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
gl_FragColor = texColor * alpha * maskColor.w;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
......@@ -1048,17 +1145,14 @@ FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
mask_sampler_location_(-1),
alpha_location_(-1),
mask_tex_coord_scale_location_(-1),
mask_tex_coord_offset_location_(-1) {}
mask_tex_coord_offset_location_(-1) {
}
void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"s_mask",
"alpha",
"maskTexCoordScale",
"maskTexCoordOffset",
"s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset",
};
int locations[arraysize(uniforms)];
......@@ -1076,8 +1170,11 @@ void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context,
}
std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform SamplerType s_mask;
......@@ -1098,7 +1195,9 @@ std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = texColor * alpha * maskColor.w * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaMaskColorMatrixAA::
......@@ -1108,7 +1207,8 @@ FragmentShaderRGBATexAlphaMaskColorMatrixAA::
alpha_location_(-1),
mask_tex_coord_scale_location_(-1),
color_matrix_location_(-1),
color_offset_location_(-1) {}
color_offset_location_(-1) {
}
void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
GLES2Interface* context,
......@@ -1141,8 +1241,11 @@ void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
}
std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform SamplerType s_mask;
......@@ -1170,7 +1273,9 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = texColor * alpha * maskColor.w * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaColorMatrixAA::
......@@ -1178,17 +1283,14 @@ FragmentShaderRGBATexAlphaColorMatrixAA::
: sampler_location_(-1),
alpha_location_(-1),
color_matrix_location_(-1),
color_offset_location_(-1) {}
color_offset_location_(-1) {
}
void FragmentShaderRGBATexAlphaColorMatrixAA::Init(
GLES2Interface* context,
void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"s_texture",
"alpha",
"colorMatrix",
"colorOffset",
"s_texture", "alpha", "colorMatrix", "colorOffset",
};
int locations[arraysize(uniforms)];
......@@ -1205,8 +1307,11 @@ void FragmentShaderRGBATexAlphaColorMatrixAA::Init(
}
std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform SamplerType s_texture;
uniform float alpha;
......@@ -1227,7 +1332,9 @@ std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = texColor * alpha * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderRGBATexAlphaMaskColorMatrix::
......@@ -1235,10 +1342,10 @@ FragmentShaderRGBATexAlphaMaskColorMatrix::
: sampler_location_(-1),
mask_sampler_location_(-1),
alpha_location_(-1),
mask_tex_coord_scale_location_(-1) {}
mask_tex_coord_scale_location_(-1) {
}
void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(
GLES2Interface* context,
void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
......@@ -1268,8 +1375,11 @@ void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(
}
std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
varying TexCoordPrecision vec2 v_texCoord;
uniform SamplerType s_texture;
......@@ -1292,7 +1402,9 @@ std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
gl_FragColor = texColor * alpha * maskColor.w;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderYUVVideo::FragmentShaderYUVVideo()
......@@ -1301,18 +1413,14 @@ FragmentShaderYUVVideo::FragmentShaderYUVVideo()
v_texture_location_(-1),
alpha_location_(-1),
yuv_matrix_location_(-1),
yuv_adj_location_(-1) {}
yuv_adj_location_(-1) {
}
void FragmentShaderYUVVideo::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"y_texture",
"u_texture",
"v_texture",
"alpha",
"yuv_matrix",
"yuv_adj",
"y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj",
};
int locations[arraysize(uniforms)];
......@@ -1330,9 +1438,11 @@ void FragmentShaderYUVVideo::Init(GLES2Interface* context,
yuv_adj_location_ = locations[5];
}
std::string FragmentShaderYUVVideo::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
precision mediump int;
varying TexCoordPrecision vec2 v_texCoord;
......@@ -1350,7 +1460,9 @@ std::string FragmentShaderYUVVideo::GetShaderString(
vec3 rgb = yuv_matrix * yuv;
gl_FragColor = vec4(rgb, 1.0) * alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
......@@ -1393,8 +1505,11 @@ void FragmentShaderYUVAVideo::Init(GLES2Interface* context,
}
std::string FragmentShaderYUVAVideo::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
precision mediump int;
varying TexCoordPrecision vec2 v_texCoord;
......@@ -1414,11 +1529,13 @@ std::string FragmentShaderYUVAVideo::GetShaderString(
vec3 rgb = yuv_matrix * yuv;
gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw);
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderColor::FragmentShaderColor()
: color_location_(-1) {}
FragmentShaderColor::FragmentShaderColor() : color_location_(-1) {
}
void FragmentShaderColor::Init(GLES2Interface* context,
unsigned program,
......@@ -1437,19 +1554,21 @@ void FragmentShaderColor::Init(GLES2Interface* context,
color_location_ = locations[0];
}
std::string FragmentShaderColor::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform vec4 color;
void main() {
gl_FragColor = color;
}
void main() { gl_FragColor = color; }
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderColorAA::FragmentShaderColorAA()
: color_location_(-1) {}
FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) {
}
void FragmentShaderColorAA::Init(GLES2Interface* context,
unsigned program,
......@@ -1468,9 +1587,11 @@ void FragmentShaderColorAA::Init(GLES2Interface* context,
color_location_ = locations[0];
}
std::string FragmentShaderColorAA::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision,
SamplerType sampler) const {
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
uniform vec4 color;
varying vec4 edge_dist[2]; // 8 edge distances.
......@@ -1481,22 +1602,22 @@ std::string FragmentShaderColorAA::GetShaderString(
float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
gl_FragColor = color * aa;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
FragmentShaderCheckerboard::FragmentShaderCheckerboard()
: alpha_location_(-1),
tex_transform_location_(-1),
frequency_location_(-1) {}
frequency_location_(-1) {
}
void FragmentShaderCheckerboard::Init(GLES2Interface* context,
unsigned program,
int* base_uniform_index) {
static const char* uniforms[] = {
"alpha",
"texTransform",
"frequency",
"color",
"alpha", "texTransform", "frequency", "color",
};
int locations[arraysize(uniforms)];
......@@ -1513,10 +1634,13 @@ void FragmentShaderCheckerboard::Init(GLES2Interface* context,
}
std::string FragmentShaderCheckerboard::GetShaderString(
TexCoordPrecision precision, SamplerType sampler) const {
TexCoordPrecision precision,
SamplerType sampler) const {
// Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
// by Munshi, Ginsburg, Shreiner.
// clang-format off
return FRAGMENT_SHADER(
// clang-format on
precision mediump float;
precision mediump int;
varying vec2 v_texCoord;
......@@ -1533,7 +1657,9 @@ std::string FragmentShaderCheckerboard::GetShaderString(
float picker = abs(coord.x - coord.y); // NOLINT
gl_FragColor = mix(color1, color2, picker) * alpha;
}
// clang-format off
); // NOLINT(whitespace/parens)
// clang-format on
}
} // namespace cc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment