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 "// Blitter\n" \ 31 "#version 130\n" \ 32 33 #define HEADER_GLES \ 34 "// Blitter\n" \ 35 "#version 310 es\n" \ 36 "precision mediump float;\n" \ 37 38 #define VS_PASSTHROUGH_BODY \ 39 "in vec4 arg0;\n" \ 40 "in vec4 arg1;\n" \ 41 "out vec4 tc;\n" \ 42 "void main() {\n" \ 43 " gl_Position = arg0;\n" \ 44 " tc = arg1;\n" \ 45 "}\n" 46 47 #define VS_PASSTHROUGH_GL HEADER_GL VS_PASSTHROUGH_BODY 48 #define VS_PASSTHROUGH_GLES HEADER_GLES VS_PASSTHROUGH_BODY 49 50 51 #define FS_TEXFETCH_COL_BODY \ 52 "%s" \ 53 "#define cvec4 %s\n" \ 54 "uniform mediump %csampler%s samp;\n" \ 55 "in vec4 tc;\n" \ 56 "out cvec4 FragColor;\n" \ 57 "void main() {\n" \ 58 " cvec4 texel = texture(samp, tc%s);\n" \ 59 " FragColor = cvec4(%s);\n" \ 60 "}\n" 61 62 #define FS_TEXFETCH_COL_GL HEADER_GL FS_TEXFETCH_COL_BODY 63 #define FS_TEXFETCH_COL_GLES HEADER_GLES FS_TEXFETCH_COL_BODY 64 65 66 #define FS_TEXFETCH_COL_MSAA_BODY \ 67 "%s" \ 68 "#define cvec4 %s\n" \ 69 "uniform mediump %csampler%s samp;\n" \ 70 "in vec4 tc;\n" \ 71 "out cvec4 FragColor;\n" \ 72 "void main() {\n" \ 73 " const int num_samples = %d;\n" \ 74 " cvec4 texel = cvec4(0);\n" \ 75 " for (int i = 0; i < num_samples; ++i) \n" \ 76 " texel += texelFetch(samp, %s(tc%s), i);\n" \ 77 " texel = texel / cvec4(num_samples);\n" \ 78 " FragColor = cvec4(%s);\n" \ 79 "}\n" 80 81 #define FS_TEXFETCH_COL_MSAA_GL HEADER_GL FS_TEXFETCH_COL_MSAA_BODY 82 #define FS_TEXFETCH_COL_MSAA_GLES HEADER_GLES FS_TEXFETCH_COL_MSAA_BODY 83 84 #define FS_TEXFETCH_DS_BODY \ 85 "uniform sampler%s samp;\n" \ 86 "in vec4 tc;\n" \ 87 "void main() {\n" \ 88 " gl_FragDepth = float(texture(samp, tc%s).x);\n" \ 89 "}\n" 90 91 #define FS_TEXFETCH_DS_GL HEADER_GL FS_TEXFETCH_DS_BODY 92 #define FS_TEXFETCH_DS_GLES HEADER_GLES FS_TEXFETCH_DS_BODY 93 94 95 #define FS_TEXFETCH_DS_MSAA_BODY \ 96 "#extension GL_ARB_texture_multisample : enable\n" \ 97 "uniform sampler%s samp;\n" \ 98 "in vec4 tc;\n" \ 99 "void main() {\n" \ 100 " gl_FragDepth = float(texelFetch(samp, %s(tc%s), int(tc.z)).x);\n" \ 101 "}\n" 102 103 #define FS_TEXFETCH_DS_MSAA_GL HEADER_GL FS_TEXFETCH_DS_MSAA_BODY 104 #define FS_TEXFETCH_DS_MSAA_GLES HEADER_GLES FS_TEXFETCH_DS_MSAA_BODY 105 106 107 #endif 108