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."""
30 from mako
import exceptions
32 from templates
import template_dir
33 from modules
import utils
35 TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
37 INTERPOLATION_MODES
= [
47 'gl_FrontSecondaryColor',
48 'gl_BackSecondaryColor'
51 VS_VARIABLES_FRONT_ONLY
= [
53 'gl_FrontSecondaryColor',
57 'gl_FrontColor': 'gl_BackColor',
58 'gl_BackColor': 'gl_FrontColor',
59 'gl_FrontSecondaryColor': 'gl_BackSecondaryColor',
60 'gl_BackSecondaryColor': 'gl_FrontSecondaryColor'
63 VS_TO_FS_VARIABLE_MAP
= {
64 'gl_FrontColor': 'gl_Color',
65 'gl_BackColor': 'gl_Color',
66 'gl_FrontSecondaryColor': 'gl_SecondaryColor',
67 'gl_BackSecondaryColor': 'gl_SecondaryColor'
71 def make_fs_vs_tests(fs_mode
, vs_mode
, dirname
):
72 if vs_mode
== fs_mode
:
75 for var
in VS_VARIABLES
:
76 filename
= os
.path
.join(
78 '{0}-{1}-{2}-{3}.shader_test'.format(
79 vs_mode
, var
, fs_mode
,
80 VS_TO_FS_VARIABLE_MAP
[var
]))
83 with
open(filename
, 'w') as f
:
85 f
.write(TEMPLATES
.get_template('vs-fs.shader_test.mako').render_unicode(
89 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
91 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
95 def make_vs_unused_tests(vs_mode
, dirname
):
96 if vs_mode
== 'default':
99 for var
in VS_VARIABLES
:
100 filename
= os
.path
.join(
102 '{0}-{1}-unused-{2}.shader_test'.format(
104 VS_TO_FS_VARIABLE_MAP
[var
]))
107 with
open(filename
, 'w') as f
:
110 TEMPLATES
.get_template('vs-unused.shader_test.mako').render_unicode(
114 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
118 def make_fs_unused_tests(fs_mode
, vs_mode
, dirname
):
119 if fs_mode
== 'default':
122 for var
in VS_VARIABLES_FRONT_ONLY
:
123 filename
= os
.path
.join(
125 'unused-{0}-{1}-{2}.shader_test'.format(
127 VS_TO_FS_VARIABLE_MAP
[var
]))
130 with
open(filename
, 'w') as f
:
132 f
.write(TEMPLATES
.get_template('fs-unused.shader_test.mako').render_unicode(
136 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
138 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
142 def make_vs_fs_unused_tests(fs_mode
, vs_mode
, dirname
):
143 if vs_mode
== fs_mode
:
146 for var
in VS_VARIABLES
:
147 filename
= os
.path
.join(
149 'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
150 vs_mode
, var
, fs_mode
,
151 VS_TO_FS_VARIABLE_MAP
[var
]))
154 with
open(filename
, 'w') as f
:
156 f
.write(TEMPLATES
.get_template(
157 'fs-vs-unused.shader_test.mako').render_unicode(
161 fs_variable
=VS_TO_FS_VARIABLE_MAP
[var
]))
163 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
167 def make_vs_fs_flip_tests(fs_mode
, vs_mode
, dirname
):
168 if vs_mode
== fs_mode
:
171 for this_side
in VS_VARIABLES
:
172 other_side
= OTHER_SIDE_MAP
[this_side
]
173 filename
= os
.path
.join(
175 '{0}-{1}-{2}-{3}.shader_test'.format(
176 vs_mode
, this_side
, fs_mode
, other_side
))
179 with
open(filename
, 'w') as f
:
181 f
.write(TEMPLATES
.get_template(
182 'vs-fs-flip.shader_test.mako').render_unicode(
184 this_side_variable
=this_side
,
185 other_side_variable
=other_side
,
187 fs_variable
=VS_TO_FS_VARIABLE_MAP
[this_side
]))
189 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
195 dirname
= os
.path
.join('spec', 'glsl-1.30', 'linker',
196 'interpolation-qualifiers')
197 utils
.safe_makedirs(dirname
)
199 for fs_mode
, vs_mode
in itertools
.product(INTERPOLATION_MODES
, repeat
=2):
200 make_fs_vs_tests(fs_mode
, vs_mode
, dirname
)
201 make_vs_unused_tests(vs_mode
, dirname
)
202 make_fs_unused_tests(fs_mode
, vs_mode
, dirname
)
203 make_vs_fs_unused_tests(fs_mode
, vs_mode
, dirname
)
204 make_vs_fs_flip_tests(fs_mode
, vs_mode
, dirname
)
207 if __name__
== '__main__':