• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright (C) 2014 Red Hat Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  **************************************************************************/
24 #ifndef VREND_BLITTER_H
25 #define VREND_BLITTER_H
26 
27 /* shaders for blitting */
28 
29 #define HEADER_GL                               \
30    "#version 130\n"                             \
31    "// Blitter\n"                               \
32 
33 #define HEADER_GLES                             \
34    "#version 310 es\n"                          \
35    "// Blitter\n"                               \
36    "precision mediump float;\n"                 \
37 
38 #define HEADER_GLES_MS_ARRAY                             \
39    "#version 310 es\n"                          \
40    "// Blitter\n"                               \
41    "#extension GL_OES_texture_storage_multisample_2d_array: require\n" \
42    "precision mediump float;\n"                 \
43 
44 
45 #define VS_PASSTHROUGH_BODY                     \
46    "in vec4 arg0;\n"                            \
47    "in vec4 arg1;\n"                            \
48    "out vec4 tc;\n"                             \
49    "void main() {\n"                            \
50    "   gl_Position = arg0;\n"                   \
51    "   tc = arg1;\n"                            \
52    "}\n"
53 
54 #define VS_PASSTHROUGH_GL HEADER_GL VS_PASSTHROUGH_BODY
55 #define VS_PASSTHROUGH_GLES HEADER_GLES VS_PASSTHROUGH_BODY
56 
57 
58 #define FS_TEXFETCH_COL_BODY                    \
59    "%s"                                         \
60    "#define cvec4 %s\n"                         \
61    "uniform mediump %csampler%s samp;\n"        \
62    "in vec4 tc;\n"                              \
63    "out cvec4 FragColor;\n"                     \
64    "void main() {\n"                            \
65    "   cvec4 texel = texture(samp, tc%s);\n"    \
66    "   FragColor = cvec4(%s);\n"                \
67    "}\n"
68 
69 #define FS_TEXFETCH_COL_GLES_1D_BODY            \
70    "%s"                                         \
71    "#define cvec4 %s\n"                         \
72    "uniform mediump %csampler%s samp;\n"        \
73    "in vec4 tc;\n"                              \
74    "out cvec4 FragColor;\n"                     \
75    "void main() {\n"                            \
76    "   cvec4 texel = texture(samp, vec2(tc%s, 0.5));\n"    \
77    "   FragColor = cvec4(%s);\n"                \
78    "}\n"
79 
80 #define FS_TEXFETCH_COL_GL HEADER_GL FS_TEXFETCH_COL_BODY
81 #define FS_TEXFETCH_COL_GLES HEADER_GLES FS_TEXFETCH_COL_BODY
82 #define FS_TEXFETCH_COL_GLES_1D HEADER_GLES FS_TEXFETCH_COL_GLES_1D_BODY
83 
84 #define FS_TEXFETCH_COL_MSAA_BODY                       \
85    "%s"                                                 \
86    "#define cvec4 %s\n"                                 \
87    "uniform mediump %csampler%s samp;\n"                \
88    "in vec4 tc;\n"                                      \
89    "out cvec4 FragColor;\n"                             \
90    "void main() {\n"                                    \
91    "   const int num_samples = %d;\n"                   \
92    "   cvec4 texel = cvec4(0);\n"                       \
93    "   for (int i = 0; i < num_samples; ++i) \n"        \
94    "      texel += texelFetch(samp, %s(tc%s), i);\n"    \
95    "   texel = texel / cvec4(num_samples);\n"           \
96    "   FragColor = cvec4(%s);\n"                        \
97    "}\n"
98 
99 #define FS_TEXFETCH_COL_MSAA_GL HEADER_GL FS_TEXFETCH_COL_MSAA_BODY
100 #define FS_TEXFETCH_COL_MSAA_GLES HEADER_GLES FS_TEXFETCH_COL_MSAA_BODY
101 #define FS_TEXFETCH_COL_MSAA_ARRAY_GLES HEADER_GLES_MS_ARRAY FS_TEXFETCH_COL_MSAA_BODY
102 
103 #define FS_TEXFETCH_DS_BODY                             \
104    "uniform mediump sampler%s samp;\n"                          \
105    "in vec4 tc;\n"                                      \
106    "void main() {\n"                                    \
107    "   gl_FragDepth = float(texture(samp, tc%s).x);\n"  \
108    "}\n"
109 
110 #define FS_TEXFETCH_DS_GL HEADER_GL FS_TEXFETCH_DS_BODY
111 #define FS_TEXFETCH_DS_GLES HEADER_GLES FS_TEXFETCH_DS_BODY
112 
113 #define FS_TEXFETCH_DS_MSAA_BODY                                         \
114    "#extension GL_ARB_texture_multisample : enable\n"                    \
115    "uniform sampler%s samp;\n"                                           \
116    "in vec4 tc;\n"                                                       \
117    "void main() {\n"                                                     \
118    "   gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \
119    "}\n"
120 
121 #define FS_TEXFETCH_DS_MSAA_BODY_GLES                                     \
122    "uniform mediump sampler%s samp;\n"                                           \
123    "in vec4 tc;\n"                                                       \
124    "void main() {\n"                                                     \
125    "   gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \
126    "}\n"
127 
128 
129 #define FS_TEXFETCH_DS_MSAA_GL HEADER_GL FS_TEXFETCH_DS_MSAA_BODY
130 #define FS_TEXFETCH_DS_MSAA_GLES HEADER_GLES FS_TEXFETCH_DS_MSAA_BODY_GLES
131 #define FS_TEXFETCH_DS_MSAA_ARRAY_GLES HEADER_GLES_MS_ARRAY FS_TEXFETCH_DS_MSAA_BODY_GLES
132 
133 
134 #endif
135