Skip to content

Commit

Permalink
gl: use macro HAS_ALPHA for fragment shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Sep 3, 2015
1 parent c8f5c2f commit 33f3f5e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 9 additions & 8 deletions src/VideoShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ const char* VideoShader::vertexShader() const
if (textureTarget() == GL_TEXTURE_RECTANGLE && d.video_format.isPlanar()) {
vert.prepend("#define MULTI_COORD\n");
#if YUVA_DONE
if (d.video_format.planeCount() == 4)
vert.prepend("#define PLANE_4\n");
if (d.video_format.hasAlpha())
vert.prepend("#define HAS_ALPHA\n");
#endif
}
return vert.constData();
Expand All @@ -218,22 +218,23 @@ const char* VideoShader::fragmentShader() const
qWarning("Empty fragment shader!");
return 0;
}
#if YUVA_DONE
if (d.video_format.planeCount() == 4) {
frag.prepend("#define PLANE_4\n");
}
#endif
const bool has_alpha = d.video_format.hasAlpha();
if (d.video_format.isPlanar()) {
if (d.video_format.bytesPerPixel(0) == 2) {
if (d.video_format.isBigEndian())
frag.prepend("#define LA_16BITS_BE\n");
else
frag.prepend("#define LA_16BITS_LE\n");
}
#if YUVA_DONE
if (has_alpha)
frag.prepend("#define HAS_ALPHA\n");
#endif
} else {
if (d.video_format.hasAlpha())
if (has_alpha)
frag.prepend("#define HAS_ALPHA\n");
}

if (d.texture_target == GL_TEXTURE_RECTANGLE) {
frag.prepend("#extension GL_ARB_texture_rectangle : enable\n"
"#define texture2D texture2DRect\n"
Expand Down
10 changes: 5 additions & 5 deletions src/shaders/planar.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ precision mediump float;
uniform sampler2D u_Texture0;
uniform sampler2D u_Texture1;
uniform sampler2D u_Texture2;
#ifdef PLANE_4
#ifdef HAS_ALPHA
uniform sampler2D u_Texture3;
#endif //PLANE_4
#endif //HAS_ALPHA
varying lowp vec2 v_TexCoords0;
#ifdef MULTI_COORD
varying lowp vec2 v_TexCoords1;
varying lowp vec2 v_TexCoords2;
#ifdef PLANE_4
#ifdef HAS_ALPHA
varying lowp vec2 v_TexCoords3;
#endif
#else
Expand Down Expand Up @@ -109,11 +109,11 @@ void main()
#endif //LA_16BITS
1)
, 0.0, 1.0) * u_opacity;
#ifdef PLANE_4
#ifdef HAS_ALPHA
#if LA_16BITS
gl_FragColor.a *= dot(texture2D(u_Texture3, v_TexCoords3).ra, t); //GL_LUMINANCE_ALPHA
#else //8bit
gl_FragColor.a *= texture2D(u_Texture3, v_TexCoords3).a; //GL_ALPHA
#endif //LA_16BITS
#endif //PLANE_4
#endif //HAS_ALPHA
}
4 changes: 2 additions & 2 deletions src/shaders/video.vert
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ attribute vec2 a_TexCoords1;
attribute vec2 a_TexCoords2;
varying vec2 v_TexCoords1;
varying vec2 v_TexCoords2;
#ifdef PLANE_4
#ifdef HAS_ALPHA
attribute vec2 a_TexCoords3;
varying vec2 v_TexCoords3;
#endif
Expand All @@ -39,7 +39,7 @@ void main() {
#ifdef MULTI_COORD
v_TexCoords1 = a_TexCoords1;
v_TexCoords2 = a_TexCoords2;
#ifdef PLANE_4
#ifdef HAS_ALPHA
v_TexCoords3 = a_TexCoords3;
#endif
#endif //MULTI_COORD
Expand Down

0 comments on commit 33f3f5e

Please sign in to comment.