Imported Debian version 2.4.3~trusty1
[deb_ffmpeg.git] / ffmpeg / libavdevice / opengl_enc_shaders.h
CommitLineData
2ba45a60
DM
1/*
2 * Copyright (c) 2014 Lukasz Marek
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef AVDEVICE_OPENGL_SHADERS_H
22#define AVDEVICE_OPENGL_SHADERS_H
23
24#include "libavutil/pixfmt.h"
25
26static const char * const FF_OPENGL_VERTEX_SHADER =
27 "uniform mat4 u_projectionMatrix;"
28 "uniform mat4 u_modelViewMatrix;"
29
30 "attribute vec4 a_position;"
31 "attribute vec2 a_textureCoords;"
32
33 "varying vec2 texture_coordinate;"
34
35 "void main()"
36 "{"
37 "gl_Position = u_projectionMatrix * (a_position * u_modelViewMatrix);"
38 "texture_coordinate = a_textureCoords;"
39 "}";
40
41/**
42 * Fragment shader for packet RGBA formats.
43 */
44static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PACKET =
45#if defined(GL_ES_VERSION_2_0)
46 "precision mediump float;"
47#endif
48 "uniform sampler2D u_texture0;"
49 "uniform mat4 u_colorMap;"
50
51 "varying vec2 texture_coordinate;"
52
53 "void main()"
54 "{"
55 "gl_FragColor = texture2D(u_texture0, texture_coordinate) * u_colorMap;"
56 "}";
57
58/**
59 * Fragment shader for packet RGB formats.
60 */
61static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PACKET =
62#if defined(GL_ES_VERSION_2_0)
63 "precision mediump float;"
64#endif
65 "uniform sampler2D u_texture0;"
66 "uniform mat4 u_colorMap;"
67
68 "varying vec2 texture_coordinate;"
69
70 "void main()"
71 "{"
72 "gl_FragColor = vec4((texture2D(u_texture0, texture_coordinate) * u_colorMap).rgb, 1.0);"
73 "}";
74
75/**
76 * Fragment shader for planar RGBA formats.
77 */
78static const char * const FF_OPENGL_FRAGMENT_SHADER_RGBA_PLANAR =
79#if defined(GL_ES_VERSION_2_0)
80 "precision mediump float;"
81#endif
82 "uniform sampler2D u_texture0;"
83 "uniform sampler2D u_texture1;"
84 "uniform sampler2D u_texture2;"
85 "uniform sampler2D u_texture3;"
86
87 "varying vec2 texture_coordinate;"
88
89 "void main()"
90 "{"
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);"
95 "}";
96
97/**
98 * Fragment shader for planar RGB formats.
99 */
100static const char * const FF_OPENGL_FRAGMENT_SHADER_RGB_PLANAR =
101#if defined(GL_ES_VERSION_2_0)
102 "precision mediump float;"
103#endif
104 "uniform sampler2D u_texture0;"
105 "uniform sampler2D u_texture1;"
106 "uniform sampler2D u_texture2;"
107
108 "varying vec2 texture_coordinate;"
109
110 "void main()"
111 "{"
112 "gl_FragColor = vec4(texture2D(u_texture0, texture_coordinate).r,"
113 "texture2D(u_texture1, texture_coordinate).r,"
114 "texture2D(u_texture2, texture_coordinate).r,"
115 "1.0);"
116 "}";
117
118/**
119 * Fragment shader for planar YUV formats.
120 */
121static const char * const FF_OPENGL_FRAGMENT_SHADER_YUV_PLANAR =
122#if defined(GL_ES_VERSION_2_0)
123 "precision mediump float;"
124#endif
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;"
130
131 "varying vec2 texture_coordinate;"
132
133 "void main()"
134 "{"
135 "vec3 yuv;"
136
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;"
140
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);"
144
145 "}";
146
147/**
148 * Fragment shader for planar YUVA formats.
149 */
150static const char * const FF_OPENGL_FRAGMENT_SHADER_YUVA_PLANAR =
151#if defined(GL_ES_VERSION_2_0)
152 "precision mediump float;"
153#endif
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;"
160
161 "varying vec2 texture_coordinate;"
162
163 "void main()"
164 "{"
165 "vec3 yuv;"
166
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;"
170
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);"
174 "}";
175
176static const char * const FF_OPENGL_FRAGMENT_SHADER_GRAY =
177#if defined(GL_ES_VERSION_2_0)
178 "precision mediump float;"
179#endif
180 "uniform sampler2D u_texture0;"
181 "varying vec2 texture_coordinate;"
182 "void main()"
183 "{"
184 "float c = texture2D(u_texture0, texture_coordinate).r;"
185 "gl_FragColor = vec4(c, c, c, 1.0);"
186 "}";
187
188#endif /* AVDEVICE_OPENGL_SHADERS_H */