forked from zillevdr/vdr-plugin-softhddevice-drm
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathopenglshader.h
More file actions
188 lines (175 loc) · 3.8 KB
/
Copy pathopenglshader.h
File metadata and controls
188 lines (175 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file openglshader.h
* Shader Definitions for OpenGL OSD
*
* @note This code was originally authored by Stefan Braun (see README),
* but there was never set any copyright info.
*
* @copyright 2025 - 2026 by Andreas Baierl. All Rights Reserved.
*
* @license{AGPL-3.0-or-later}
*/
#ifndef __SOFTHDDEVICE_OPENGLSHADER_H
#define __SOFTHDDEVICE_OPENGLSHADER_H
/********************************************************************************
* Shaders for Hardware Accelerated OpenGL OSD
*******************************************************************************/
/**
* @addtogroup osd
* @{
*/
/**
* Rectangle Vertex Shader
*/
const char *rectVertexShader =
"#version 100 \n\
\
attribute vec2 position; \
varying vec4 rectCol; \
uniform vec4 inColor; \
uniform mat4 projection; \
\
void main() \
{ \
gl_Position = projection * vec4(position.x, position.y, 0.0, 1.0); \
rectCol = inColor; \
} \
";
/**
* Rectangle Fragment Shader
*/
const char *rectFragmentShader =
"#version 100 \n\
precision mediump float; \
varying vec4 rectCol; \
\
void main() \
{ \
gl_FragColor = rectCol; \
} \
";
/**
* Texture Vertex Shader
*/
const char *textureVertexShader =
"#version 100 \n\
\
attribute vec2 position; \
attribute vec2 texCoords; \
\
varying vec2 TexCoords; \
varying vec4 alphaValue;\
varying vec4 bColorValue;\
\
uniform vec4 bColor; \
uniform mat4 projection; \
uniform vec4 alpha; \
\
void main() \
{ \
gl_Position = projection * vec4(position.x, position.y, 0.0, 1.0); \
TexCoords = texCoords; \
alphaValue = alpha; \
bColorValue = bColor; \
} \
";
/**
* Texture Fragment Shader
*/
const char *textureFragmentShader =
"#version 100 \n\
precision mediump float; \
varying vec2 TexCoords; \
varying vec4 alphaValue; \
varying vec4 bColorValue; \
\
uniform sampler2D screenTexture; \
\
float clamp_to_border_factor (vec2 coords) \
{ \
bvec2 out1 = greaterThan (coords, vec2 (1,1)); \
bvec2 out2 = lessThan (coords, vec2 (0,0)); \
bool do_clamp = (any (out1) || any (out2)); \
return float (!do_clamp); \
} \
\
void main() \
{ \
vec4 color = texture2D(screenTexture, TexCoords) * alphaValue; \
float f = clamp_to_border_factor (TexCoords); \
gl_FragColor = mix (bColorValue, color, f); \
} \
";
/**
* Texture Fragment Shader (swapped blue/red)
*
* In difference to the textureFragmentShader this one does
* a blue/red color component swap
*/
const char *textureFragmentShaderSwapBR =
"#version 100 \n\
precision mediump float; \
varying vec2 TexCoords; \
varying vec4 alphaValue; \
varying vec4 bColorValue; \
\
uniform sampler2D screenTexture; \
\
float clamp_to_border_factor (vec2 coords) \
{ \
bvec2 out1 = greaterThan (coords, vec2 (1,1)); \
bvec2 out2 = lessThan (coords, vec2 (0,0)); \
bool do_clamp = (any (out1) || any (out2)); \
return float (!do_clamp); \
} \
\
void main() \
{ \
vec4 color = texture2D(screenTexture, TexCoords) * alphaValue; \
vec4 color_swapped = vec4(color.b, color.g, color.r, color.a); \
float f = clamp_to_border_factor (TexCoords); \
gl_FragColor = mix (bColorValue, color_swapped, f); \
} \
";
/**
* Text Vertex Shader
*/
const char *textVertexShader =
"#version 100 \n\
\
attribute vec2 position; \
attribute vec2 texCoords; \
\
varying vec2 TexCoords; \
varying vec4 textColor; \
\
uniform mat4 projection; \
uniform vec4 inColor; \
\
void main() \
{ \
gl_Position = projection * vec4(position.x, position.y, 0.0, 1.0); \
TexCoords = texCoords; \
textColor = inColor; \
} \
";
/**
* Text Fragment Shader
*/
const char *textFragmentShader =
"#version 100 \n\
precision mediump float; \
varying vec2 TexCoords; \
varying vec4 textColor; \
\
uniform sampler2D glyphTexture; \
\
void main() \
{ \
vec4 sampled = vec4(1.0, 1.0, 1.0, texture2D(glyphTexture, TexCoords).r); \
gl_FragColor = textColor * sampled; \
} \
";
/** @} */
#endif