3 # Copyright 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
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sub license, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice (including the
14 # next paragraph) shall be included in all copies or substantial portions
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 # IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 import format_parser
as parser
28 def get_gl_base_format(fmat
):
29 if fmat
.name
== 'MESA_FORMAT_NONE':
31 elif fmat
.name
in ['MESA_FORMAT_YCBCR', 'MESA_FORMAT_YCBCR_REV']:
32 return 'GL_YCBCR_MESA'
33 elif fmat
.has_channel('r'):
34 if fmat
.has_channel('g'):
35 if fmat
.has_channel('b'):
36 if fmat
.has_channel('a'):
44 elif fmat
.has_channel('l'):
45 if fmat
.has_channel('a'):
46 return 'GL_LUMINANCE_ALPHA'
49 elif fmat
.has_channel('a') and fmat
.num_channels() == 1:
51 elif fmat
.has_channel('z'):
52 if fmat
.has_channel('s'):
53 return 'GL_DEPTH_STENCIL'
55 return 'GL_DEPTH_COMPONENT'
56 elif fmat
.has_channel('s'):
57 return 'GL_STENCIL_INDEX'
58 elif fmat
.has_channel('i') and fmat
.num_channels() == 1:
61 sys
.exit("error, could not determine base format for {0}, check swizzle".format(fmat
.name
));
63 def get_gl_data_type(fmat
):
64 if fmat
.is_compressed():
65 if 'FLOAT' in fmat
.name
:
67 elif 'SIGNED' in fmat
.name
or 'SNORM' in fmat
.name
:
68 return 'GL_SIGNED_NORMALIZED'
70 return 'GL_UNSIGNED_NORMALIZED'
71 elif fmat
.name
in ['MESA_FORMAT_YCBCR', 'MESA_FORMAT_YCBCR_REV']:
72 return 'GL_UNSIGNED_NORMALIZED'
75 for chan
in fmat
.channels
:
76 if chan
.type == 'x' and len(fmat
.channels
) > 1:
77 continue # We can do better
78 elif chan
.name
== 's' and fmat
.has_channel('z'):
79 continue # We'll use the type from the depth instead
84 if channel
.type == parser
.UNSIGNED
:
86 return 'GL_UNSIGNED_NORMALIZED'
88 return 'GL_UNSIGNED_INT'
89 elif channel
.type == parser
.SIGNED
:
91 return 'GL_SIGNED_NORMALIZED'
94 elif channel
.type == parser
.FLOAT
:
96 elif channel
.type == parser
.VOID
:
101 def get_channel_bits(fmat
, chan_name
):
102 if fmat
.is_compressed():
103 # These values are pretty-much bogus, but OpenGL requires that we
104 # return an "approximate" number of bits.
105 if fmat
.layout
== 's3tc':
106 return 4 if fmat
.has_channel(chan_name
) else 0
107 elif fmat
.layout
== 'fxt1':
108 if chan_name
in 'rgb':
110 elif chan_name
== 'a':
111 return 1 if fmat
.has_channel('a') else 0
114 elif fmat
.layout
in ('rgtc', 'latc'):
115 return 8 if fmat
.has_channel(chan_name
) else 0
116 elif fmat
.layout
in ('etc1', 'etc2'):
117 if fmat
.name
.endswith('_ALPHA1') and chan_name
== 'a':
120 bits
= 11 if fmat
.name
.endswith('11_EAC') else 8
121 return bits
if fmat
.has_channel(chan_name
) else 0
122 elif fmat
.layout
== 'bptc':
123 bits
= 16 if fmat
.name
.endswith('_FLOAT') else 8
124 return bits
if fmat
.has_channel(chan_name
) else 0
125 elif fmat
.layout
== 'astc':
126 bits
= 16 if 'RGBA' in fmat
.name
else 8
127 return bits
if fmat
.has_channel(chan_name
) else 0
131 # Uncompressed textures
132 for chan
in fmat
.channels
:
133 if chan
.name
== chan_name
:
137 formats
= parser
.parse(sys
.argv
[1])
141 * Mesa 3-D graphics library
143 * Copyright (c) 2014 Intel Corporation
145 * Permission is hereby granted, free of charge, to any person obtaining a
146 * copy of this software and associated documentation files (the "Software"),
147 * to deal in the Software without restriction, including without limitation
148 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
149 * and/or sell copies of the Software, and to permit persons to whom the
150 * Software is furnished to do so, subject to the following conditions:
152 * The above copyright notice and this permission notice shall be included
153 * in all copies or substantial portions of the Software.
155 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
156 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
157 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
158 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
159 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
160 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
161 * OTHER DEALINGS IN THE SOFTWARE.
165 * This file is AUTOGENERATED by format_info.py. Do not edit it
166 * manually or commit it into version control.
169 static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
175 print ' {0},'.format(fmat
.name
)
176 print ' "{0}",'.format(fmat
.name
)
177 print ' {0},'.format('MESA_FORMAT_LAYOUT_' + fmat
.layout
.upper())
178 print ' {0},'.format(get_gl_base_format(fmat
))
179 print ' {0},'.format(get_gl_data_type(fmat
))
181 bits
= [ get_channel_bits(fmat
, name
) for name
in ['r', 'g', 'b', 'a']]
182 print ' {0},'.format(', '.join(map(str, bits
)))
183 bits
= [ get_channel_bits(fmat
, name
) for name
in ['l', 'i', 'z', 's']]
184 print ' {0},'.format(', '.join(map(str, bits
)))
186 print ' {0:d},'.format(fmat
.colorspace
== 'srgb')
188 print ' {0}, {1}, {2},'.format(fmat
.block_width
, fmat
.block_height
,
189 int(fmat
.block_size() / 8))
191 print ' {{ {0} }},'.format(', '.join(map(str, fmat
.swizzle
)))
193 chan
= fmat
.array_element()
194 norm
= chan
.norm
or chan
.type == parser
.FLOAT
195 print ' MESA_ARRAY_FORMAT({0}),'.format(', '.join([
198 str(int(chan
.type == parser
.FLOAT
)),
200 str(len(fmat
.channels
)),
201 str(fmat
.swizzle
[0]),
202 str(fmat
.swizzle
[1]),
203 str(fmat
.swizzle
[2]),
204 str(fmat
.swizzle
[3]),