interpolation-qualifier-built-in-variable.py 5.78 KB
Newer Older
1 2
# coding=utf-8
#
3
# Copyright © 2013, 2014 Intel Corporation
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

24 25
"""Generate interpolation-qualifier tests."""

26
from __future__ import print_function, division, absolute_import
27
import os
28
import itertools
29

30
from templates import template_dir
31
from modules import utils
32 33

TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
34

35
INTERPOLATION_MODES = [
36 37 38 39 40 41
    'flat',
    'noperspective',
    'smooth',
    'default'
]

42
VS_VARIABLES = [
43 44 45 46 47 48
    'gl_FrontColor',
    'gl_BackColor',
    'gl_FrontSecondaryColor',
    'gl_BackSecondaryColor'
]

49
VS_VARIABLES_FRONT_ONLY = [
50 51 52 53
    'gl_FrontColor',
    'gl_FrontSecondaryColor',
]

54
OTHER_SIDE_MAP = {
55 56 57 58 59 60
    'gl_FrontColor': 'gl_BackColor',
    'gl_BackColor': 'gl_FrontColor',
    'gl_FrontSecondaryColor': 'gl_BackSecondaryColor',
    'gl_BackSecondaryColor': 'gl_FrontSecondaryColor'
}

61
VS_TO_FS_VARIABLE_MAP = {
62 63 64 65 66 67 68
    'gl_FrontColor': 'gl_Color',
    'gl_BackColor': 'gl_Color',
    'gl_FrontSecondaryColor': 'gl_SecondaryColor',
    'gl_BackSecondaryColor': 'gl_SecondaryColor'
}


69 70 71 72
def make_fs_vs_tests(fs_mode, vs_mode, dirname):
    if vs_mode == fs_mode:
        return

73
    for var in VS_VARIABLES:
74 75 76 77
        filename = os.path.join(
            dirname,
            '{0}-{1}-{2}-{3}.shader_test'.format(
                vs_mode, var, fs_mode,
78
                VS_TO_FS_VARIABLE_MAP[var]))
79 80 81
        print(filename)

        with open(filename, 'w') as f:
82
            f.write(TEMPLATES.get_template('vs-fs.shader_test.mako').render_unicode(
83 84 85
                vs_mode=vs_mode,
                vs_variable=var,
                fs_mode=fs_mode,
86
                fs_variable=VS_TO_FS_VARIABLE_MAP[var]))
87 88 89 90 91 92


def make_vs_unused_tests(vs_mode, dirname):
    if vs_mode == 'default':
        return

93
    for var in VS_VARIABLES:
94 95
        filename = os.path.join(
            dirname,
96 97 98
            '{0}-{1}-unused-{2}.shader_test'.format(
                vs_mode, var,
                VS_TO_FS_VARIABLE_MAP[var]))
99 100 101 102
        print(filename)

        with open(filename, 'w') as f:
            f.write(
103
                TEMPLATES.get_template('vs-unused.shader_test.mako').render_unicode(
104 105 106 107 108 109 110 111
                    vs_mode=vs_mode,
                    vs_variable=var))


def make_fs_unused_tests(fs_mode, vs_mode, dirname):
    if fs_mode == 'default':
        return

112
    for var in VS_VARIABLES_FRONT_ONLY:
113 114 115 116
        filename = os.path.join(
            dirname,
            'unused-{0}-{1}-{2}.shader_test'.format(
                var, fs_mode,
117
                VS_TO_FS_VARIABLE_MAP[var]))
118 119 120
        print(filename)

        with open(filename, 'w') as f:
121
            f.write(TEMPLATES.get_template('fs-unused.shader_test.mako').render_unicode(
122 123 124
                vs_mode=vs_mode,
                vs_variable=var,
                fs_mode=fs_mode,
125
                fs_variable=VS_TO_FS_VARIABLE_MAP[var]))
126 127 128 129 130 131


def make_vs_fs_unused_tests(fs_mode, vs_mode, dirname):
    if vs_mode == fs_mode:
        return

132
    for var in VS_VARIABLES:
133 134 135 136
        filename = os.path.join(
            dirname,
            'unused-{0}-{1}-unused-{2}-{3}.shader_test'.format(
                vs_mode, var, fs_mode,
137
                VS_TO_FS_VARIABLE_MAP[var]))
138 139 140 141
        print(filename)

        with open(filename, 'w') as f:
            f.write(TEMPLATES.get_template(
142
                'fs-vs-unused.shader_test.mako').render_unicode(
143 144 145
                    vs_mode=vs_mode,
                    vs_variable=var,
                    fs_mode=fs_mode,
146
                    fs_variable=VS_TO_FS_VARIABLE_MAP[var]))
147 148 149 150 151 152


def make_vs_fs_flip_tests(fs_mode, vs_mode, dirname):
    if vs_mode == fs_mode:
        return

153 154
    for this_side in VS_VARIABLES:
        other_side = OTHER_SIDE_MAP[this_side]
155 156 157 158 159 160 161 162
        filename = os.path.join(
            dirname,
            '{0}-{1}-{2}-{3}.shader_test'.format(
                vs_mode, this_side, fs_mode, other_side))
        print(filename)

        with open(filename, 'w') as f:
            f.write(TEMPLATES.get_template(
163
                'vs-fs-flip.shader_test.mako').render_unicode(
164 165 166 167
                    vs_mode=vs_mode,
                    this_side_variable=this_side,
                    other_side_variable=other_side,
                    fs_mode=fs_mode,
168
                    fs_variable=VS_TO_FS_VARIABLE_MAP[this_side]))
169 170


171 172 173 174
def main():
    """main function."""
    dirname = os.path.join('spec', 'glsl-1.30', 'linker',
                           'interpolation-qualifiers')
175
    utils.safe_makedirs(dirname)
176

177
    for fs_mode, vs_mode in itertools.product(INTERPOLATION_MODES, repeat=2):
178 179 180 181 182
        make_fs_vs_tests(fs_mode, vs_mode, dirname)
        make_vs_unused_tests(vs_mode, dirname)
        make_fs_unused_tests(fs_mode, vs_mode, dirname)
        make_vs_fs_unused_tests(fs_mode, vs_mode, dirname)
        make_vs_fs_flip_tests(fs_mode, vs_mode, dirname)
183 184 185 186


if __name__ == '__main__':
    main()