gen_texture_query_lod_tests.py 4.94 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
from __future__ import print_function
25
26
27
28
import os
import os.path
from textwrap import dedent

29
30
31
from mako.template import Template

SAMPLER_TYPE_TO_COORD_TYPE = {
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    'sampler1D':              'float',
    'isampler1D':             'float',
    'usampler1D':             'float',

    'sampler2D':              'vec2',
    'isampler2D':             'vec2',
    'usampler2D':             'vec2',

    'sampler3D':              'vec3',
    'isampler3D':             'vec3',
    'usampler3D':             'vec3',

    'samplerCube':            'vec3',
    'isamplerCube':           'vec3',
    'usamplerCube':           'vec3',

    'sampler1DArray':         'float',
    'isampler1DArray':        'float',
    'usampler1DArray':        'float',

    'sampler2DArray':         'vec2',
    'isampler2DArray':        'vec2',
    'usampler2DArray':        'vec2',

    'samplerCubeArray':       'vec3',
    'isamplerCubeArray':      'vec3',
    'usamplerCubeArray':      'vec3',

    'sampler1DShadow':        'float',
    'sampler2DShadow':        'vec2',
    'samplerCubeShadow':      'vec3',
    'sampler1DArrayShadow':   'float',
    'sampler2DArrayShadow':   'vec2',
    'samplerCubeArrayShadow': 'vec3',
66
67
}

68
REQUIREMENTS = {
69
70
    'ARB_texture_query_lod': {
        'version': '1.30',
71
        'extensions': 'GL_ARB_texture_query_lod'
72
73
74
    },
    'glsl-4.00': {
        'version': '4.00',
75
        'extensions': None
76
    }
77
78
}

79
TEMPLATE = Template(dedent("""\
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    /* [config]
    % if execution_stage == 'fs':
     * expect_result: pass
    % else:
     * expect_result: fail
    % endif
     * glsl_version: ${version}
    % if extensions:
     * require_extensions: ${" ".join(extensions)}
    % endif
     * [end config]
     */

    #version ${version.translate(None, '.')}
    % for extension in extensions:
    #extension ${extension} : enable
    % endfor

    uniform ${sampler_type} s;
    % if execution_stage == 'fs':
    varying ${coord_type} coord;
    % else:
    uniform ${coord_type} coord;
    % endif

    void main()
    {
        % if execution_stage == 'fs':
108
        gl_FragColor.xy = textureQuery${lod}(s, coord);
109
        % else:
110
        gl_Position.xy = textureQuery${lod}(s, coord);
111
112
        % endif
    }
113
114
"""))

115
116
117
118
119

def main():
    """Main function."""
    for api, requirement in REQUIREMENTS.iteritems():
        lod = 'Lod' if api == 'glsl-4.00' else 'LOD'
120
121
122
123
        dirname = os.path.join("spec", api.lower(), "compiler",
                               "built-in-functions")
        if not os.path.exists(dirname):
            os.makedirs(dirname)
124
125

        for sampler_type, coord_type in SAMPLER_TYPE_TO_COORD_TYPE.iteritems():
126
127
128
129
130
131
132
133
134
            requirements = [requirement['extensions']] if requirement['extensions'] else []

            # samplerCubeArray types are part GLSL 4.00
            # or GL_ARB_texture_cube_map_array.
            if api == "ARB_texture_query_lod" and sampler_type in [
                    'samplerCubeArray', 'isamplerCubeArray',
                    'usamplerCubeArray', 'samplerCubeArrayShadow']:
                requirements.append('GL_ARB_texture_cube_map_array')

135
136
137
            for execution_stage in ("vs", "fs"):
                file_extension = 'frag' if execution_stage == 'fs' else 'vert'
                filename = os.path.join(
138
                    dirname,
139
140
141
142
143
                    "textureQuery{0}-{1}.{2}".format(lod, sampler_type,
                                                     file_extension))
                print(filename)

                with open(filename, "w") as f:
144
145
146
147
148
149
150
                    f.write(TEMPLATE.render(
                        version=requirement['version'],
                        extensions=requirements,
                        execution_stage=execution_stage,
                        sampler_type=sampler_type,
                        coord_type=coord_type,
                        lod=lod))
151
152
153
154


if __name__ == '__main__':
    main()