3 # Copyright © 2013, 2014 Intel Corporation
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:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
24 """Generate interpolation-qualifier tests."""
29 from templates
import template_dir
30 from modules
import utils
32 TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
34 INTERPOLATION_MODES
= [
44 'gl_FrontSecondaryColor',
45 'gl_BackSecondaryColor'
48 VS_VARIABLES_FRONT_ONLY
= [
50 'gl_FrontSecondaryColor',
54 'gl_FrontColor': 'gl_BackColor',
55 'gl_BackColor': 'gl_FrontColor',
56 'gl_FrontSecondaryColor': 'gl_BackSecondaryColor',
57 'gl_BackSecondaryColor': 'gl_FrontSecondaryColor'
60 VS_TO_FS_VARIABLE_MAP
= {
61 'gl_FrontColor': 'gl_Color',
62 'gl_BackColor': 'gl_Color',
63 'gl_FrontSecondaryColor': 'gl_SecondaryColor',
64 'gl_BackSecondaryColor': 'gl_SecondaryColor'
68 def make_fs_vs_tests(fs_mode
, vs_mode
, dirname
):
69 if vs_mode
== fs_mode
:
72 for var
in VS_VARIABLES
:
73 filename
= os
.path
.join(
75 '{0}-{1}-{2}-{3}.shader_test'.format(
76 vs_mode
, var
, fs_mode
,
77 VS_TO_FS_VARIABLE_MAP
[var
]))
80 with
open(filename
, 'w') as f
:
81 f
.write(TEMPLATES
.get_template('vs-fs.shader_test.mako').render_unicode(
85 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
88 def make_vs_unused_tests(vs_mode
, dirname
):
89 if vs_mode
== 'default':
92 for var
in VS_VARIABLES
:
93 filename
= os
.path
.join(
95 '{0}-{1}-unused-{2}.shader_test'.format(
97 VS_TO_FS_VARIABLE_MAP
[var
]))
100 with
open(filename
, 'w') as f
:
102 TEMPLATES
.get_template('vs-unused.shader_test.mako').render_unicode(
107 def make_fs_unused_tests(fs_mode
, vs_mode
, dirname
):
108 if fs_mode
== 'default':
111 for var
in VS_VARIABLES_FRONT_ONLY
:
112 filename
= os
.path
.join(
114 'unused-{0}-{1}-{2}.shader_test'.format(
116 VS_TO_FS_VARIABLE_MAP
[var
]))
119 with
open(filename
, 'w') as f
:
120 f
.write(TEMPLATES
.get_template('fs-unused.shader_test.mako').render_unicode(
124 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
127 def make_vs_fs_unused_tests(fs_mode
, vs_mode
, dirname
):
128 if vs_mode
== fs_mode
:
131 for var
in VS_VARIABLES
:
132 filename
= os
.path
.join(
134 'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
135 vs_mode
, var
, fs_mode
,
136 VS_TO_FS_VARIABLE_MAP
[var
]))
139 with
open(filename
, 'w') as f
:
140 f
.write(TEMPLATES
.get_template(
141 'fs-vs-unused.shader_test.mako').render_unicode(
145 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
148 def make_vs_fs_flip_tests(fs_mode
, vs_mode
, dirname
):
149 if vs_mode
== fs_mode
:
152 for this_side
in VS_VARIABLES
:
153 other_side
= OTHER_SIDE_MAP
[this_side
]
154 filename
= os
.path
.join(
156 '{0}-{1}-{2}-{3}.shader_test'.format(
157 vs_mode
, this_side
, fs_mode
, other_side
))
160 with
open(filename
, 'w') as f
:
161 f
.write(TEMPLATES
.get_template(
162 'vs-fs-flip.shader_test.mako').render_unicode(
164 this_side_variable
=this_side
,
165 other_side_variable
=other_side
,
167 fs_variable
=VS_TO_FS_VARIABLE_MAP
[this_side
]))
172 dirname
= os
.path
.join('spec', 'glsl-1.30', 'linker',
173 'interpolation-qualifiers')
174 utils
.safe_makedirs(dirname
)
176 for fs_mode
, vs_mode
in itertools
.product(INTERPOLATION_MODES
, repeat
=2):
177 make_fs_vs_tests(fs_mode
, vs_mode
, dirname
)
178 make_vs_unused_tests(vs_mode
, dirname
)
179 make_fs_unused_tests(fs_mode
, vs_mode
, dirname
)
180 make_vs_fs_unused_tests(fs_mode
, vs_mode
, dirname
)
181 make_vs_fs_flip_tests(fs_mode
, vs_mode
, dirname
)
184 if __name__
== '__main__':