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.
28 from mako
import exceptions
30 from templates
import template_file
31 from modules
import utils
33 TEMPLATE
= template_file(os
.path
.basename(os
.path
.splitext(__file__
)[0]),
34 'template.glsl_parser_test.mako')
36 SAMPLER_TYPE_TO_COORD_TYPE
= {
38 'isampler1D': 'float',
39 'usampler1D': 'float',
49 'samplerCube': 'vec3',
50 'isamplerCube': 'vec3',
51 'usamplerCube': 'vec3',
53 'sampler1DArray': 'float',
54 'isampler1DArray': 'float',
55 'usampler1DArray': 'float',
57 'sampler2DArray': 'vec2',
58 'isampler2DArray': 'vec2',
59 'usampler2DArray': 'vec2',
61 'samplerCubeArray': 'vec3',
62 'isamplerCubeArray': 'vec3',
63 'usamplerCubeArray': 'vec3',
65 'sampler1DShadow': 'float',
66 'sampler2DShadow': 'vec2',
67 'samplerCubeShadow': 'vec3',
68 'sampler1DArrayShadow': 'float',
69 'sampler2DArrayShadow': 'vec2',
70 'samplerCubeArrayShadow': 'vec3',
74 'ARB_texture_query_lod': {
76 'extensions': 'GL_ARB_texture_query_lod'
87 for api
, requirement
in REQUIREMENTS
.items():
88 lod
= 'Lod' if api
== 'glsl-4.00' else 'LOD'
89 dirname
= os
.path
.join("spec", api
.lower(), "compiler",
91 utils
.safe_makedirs(dirname
)
93 for sampler_type
, coord_type
in SAMPLER_TYPE_TO_COORD_TYPE
.items():
94 requirements
= [requirement
['extensions']] if requirement
['extensions'] else []
96 # samplerCubeArray types are part GLSL 4.00
97 # or GL_ARB_texture_cube_map_array.
98 if api
== "ARB_texture_query_lod" and sampler_type
in [
99 'samplerCubeArray', 'isamplerCubeArray',
100 'usamplerCubeArray', 'samplerCubeArrayShadow']:
101 requirements
.append('GL_ARB_texture_cube_map_array')
103 for execution_stage
in ("vs", "fs"):
104 file_extension
= 'frag' if execution_stage
== 'fs' else 'vert'
105 filename
= os
.path
.join(
107 "textureQuery{0}-{1}.{2}".format(lod
, sampler_type
,
111 with
open(filename
, "w") as f
:
113 f
.write(TEMPLATE
.render_unicode(
114 version
=requirement
['version'],
115 extensions
=requirements
,
116 execution_stage
=execution_stage
,
117 sampler_type
=sampler_type
,
118 coord_type
=coord_type
,
121 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
125 if __name__
== '__main__':