2 * Copyright (c) 2014 Lukasz Marek
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVDEVICE_OPENGL_SHADERS_H
22 #define AVDEVICE_OPENGL_SHADERS_H
24 #include "libavutil/pixfmt.h"
26 static const char * const FF_OPENGL_VERTEX_SHADER =
27 "uniform mat4 u_projectionMatrix;"
28 "uniform mat4 u_modelViewMatrix;"
30 "attribute vec4 a_position;"
31 "attribute vec2 a_textureCoords;"
33 "varying vec2 texture_coordinate;"
37 "gl_Position = u_projectionMatrix * (a_position * u_modelViewMatrix);"
38 "texture_coordinate = a_textureCoords;"
42 * Fragment shader for packet RGBA formats.
44 static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET =
45 #if defined(GL_ES_VERSION_2_0)
46 "precision mediump float;"
48 "uniform sampler2D u_texture0;"
49 "uniform mat4 u_colorMap;"
51 "varying vec2 texture_coordinate;"
55 "gl_FragColor = texture2D(u_texture0, texture_coordinate) * u_colorMap;"
59 * Fragment shader for packet RGB formats.
61 static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET =
62 #if defined(GL_ES_VERSION_2_0)
63 "precision mediump float;"
65 "uniform sampler2D u_texture0;"
66 "uniform mat4 u_colorMap;"
68 "varying vec2 texture_coordinate;"
72 "gl_FragColor = vec4((texture2D(u_texture0, texture_coordinate) * u_colorMap).rgb, 1.0);"
76 * Fragment shader for planar RGBA formats.
78 static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR =
79 #if defined(GL_ES_VERSION_2_0)
80 "precision mediump float;"
82 "uniform sampler2D u_texture0;"
83 "uniform sampler2D u_texture1;"
84 "uniform sampler2D u_texture2;"
85 "uniform sampler2D u_texture3;"
87 "varying vec2 texture_coordinate;"
91 "gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
92 "texture2D(u_texture1, texture_coordinate).r,"
93 "texture2D(u_texture2, texture_coordinate).r,"
94 "texture2D(u_texture3, texture_coordinate).r);"
98 * Fragment shader for planar RGB formats.
100 static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR =
101 #if defined(GL_ES_VERSION_2_0)
102 "precision mediump float;"
104 "uniform sampler2D u_texture0;"
105 "uniform sampler2D u_texture1;"
106 "uniform sampler2D u_texture2;"
108 "varying vec2 texture_coordinate;"
112 "gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
113 "texture2D(u_texture1, texture_coordinate).r,"
114 "texture2D(u_texture2, texture_coordinate).r,"
119 * Fragment shader for planar YUV formats.
121 static const char * const FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR =
122 #if defined(GL_ES_VERSION_2_0)
123 "precision mediump float;"
125 "uniform sampler2D u_texture0;"
126 "uniform sampler2D u_texture1;"
127 "uniform sampler2D u_texture2;"
128 "uniform float u_chroma_div_w;"
129 "uniform float u_chroma_div_h;"
131 "varying vec2 texture_coordinate;"
137 "yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
138 "yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
139 "yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
141 "gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
142 "0.0, -0.39173, 2.0170,"
143 "1.5958, -0.81290, 0.0) * yuv, 1.0), 0.0, 1.0);"
148 * Fragment shader for planar YUVA formats.
150 static const char * const FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR =
151 #if defined(GL_ES_VERSION_2_0)
152 "precision mediump float;"
154 "uniform sampler2D u_texture0;"
155 "uniform sampler2D u_texture1;"
156 "uniform sampler2D u_texture2;"
157 "uniform sampler2D u_texture3;"
158 "uniform float u_chroma_div_w;"
159 "uniform float u_chroma_div_h;"
161 "varying vec2 texture_coordinate;"
167 "yuv.r = texture2D(u_texture0, texture_coordinate).r - 0.0625;"
168 "yuv.g = texture2D(u_texture1, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
169 "yuv.b = texture2D(u_texture2, vec2(texture_coordinate.x / u_chroma_div_w, texture_coordinate.y / u_chroma_div_h)).r - 0.5;"
171 "gl_FragColor = clamp(vec4(mat3(1.1643, 1.16430, 1.1643,"
172 "0.0, -0.39173, 2.0170,"
173 "1.5958, -0.81290, 0.0) * yuv, texture2D(u_texture3, texture_coordinate).r), 0.0, 1.0);"
176 static const char * const FF_OPENGL_FRAGMENT_SHADER_GRAY =
177 #if defined(GL_ES_VERSION_2_0)
178 "precision mediump float;"
180 "uniform sampler2D u_texture0;"
181 "varying vec2 texture_coordinate;"
184 "float c = texture2D(u_texture0, texture_coordinate).r;"
185 "gl_FragColor = vec4(c, c, c, 1.0);"
188 #endif /* AVDEVICE_OPENGL_SHADERS_H */