summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/format_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/format_parser.py')
-rwxr-xr-xsrc/mesa/main/format_parser.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/mesa/main/format_parser.py b/src/mesa/main/format_parser.py
index 5e45c74de3e..522bce35682 100755
--- a/src/mesa/main/format_parser.py
+++ b/src/mesa/main/format_parser.py
@@ -102,6 +102,10 @@ class Channel:
"""Returns true if the size of this channel is a power of two."""
return is_power_of_two(self.size)
+ def datatype(self):
+ """Returns the datatype corresponding to a channel type and size"""
+ return _get_datatype(self.type, self.size)
+
class Swizzle:
"""Describes a swizzle operation.
@@ -469,6 +473,49 @@ class Format:
return channel
return None
+ def datatype(self):
+ """Returns the datatype corresponding to a format's channel type and size"""
+ if self.layout == PACKED:
+ if self.block_size() == 8:
+ return 'uint8_t'
+ if self.block_size() == 16:
+ return 'uint16_t'
+ if self.block_size() == 32:
+ return 'uint32_t'
+ else:
+ assert False
+ else:
+ return _get_datatype(self.channel_type(), self.channel_size())
+
+def _get_datatype(type, size):
+ if type == FLOAT:
+ if size == 32:
+ return 'float'
+ elif size == 16:
+ return 'uint16_t'
+ else:
+ assert False
+ elif type == UNSIGNED:
+ if size <= 8:
+ return 'uint8_t'
+ elif size <= 16:
+ return 'uint16_t'
+ elif size <= 32:
+ return 'uint32_t'
+ else:
+ assert False
+ elif type == SIGNED:
+ if size <= 8:
+ return 'int8_t'
+ elif size <= 16:
+ return 'int16_t'
+ elif size <= 32:
+ return 'int32_t'
+ else:
+ assert False
+ else:
+ assert False
+
def _parse_channels(fields, layout, colorspace, swizzle):
channels = []
for field in fields: