| 31 | |
| 32 | # Unpack a tuple of the given format, from the data |
| 33 | def unpackData(fmt, data): |
| 34 | # We don't handle 'special' formats - typically bit-packed such as 10:10:10:2 |
| 35 | if fmt.Special(): |
| 36 | raise RuntimeError("Packed formats are not supported!") |
| 37 | |
| 38 | formatChars = {} |
| 39 | # 012345678 |
| 40 | formatChars[rd.CompType.UInt] = "xBHxIxxxL" |
| 41 | formatChars[rd.CompType.SInt] = "xbhxixxxl" |
| 42 | formatChars[rd.CompType.Float] = "xxexfxxxd" # only 2, 4 and 8 are valid |
| 43 | |
| 44 | # These types have identical decodes, but we might post-process them |
| 45 | formatChars[rd.CompType.UNorm] = formatChars[rd.CompType.UInt] |
| 46 | formatChars[rd.CompType.UScaled] = formatChars[rd.CompType.UInt] |
| 47 | formatChars[rd.CompType.SNorm] = formatChars[rd.CompType.SInt] |
| 48 | formatChars[rd.CompType.SScaled] = formatChars[rd.CompType.SInt] |
| 49 | |
| 50 | # We need to fetch compCount components |
| 51 | vertexFormat = str(fmt.compCount) + formatChars[fmt.compType][fmt.compByteWidth] |
| 52 | |
| 53 | # Unpack the data |
| 54 | value = struct.unpack_from(vertexFormat, data, 0) |
| 55 | |
| 56 | # If the format needs post-processing such as normalisation, do that now |
| 57 | if fmt.compType == rd.CompType.UNorm: |
| 58 | divisor = float((2 ** (fmt.compByteWidth * 8)) - 1) |
| 59 | value = tuple(float(i) / divisor for i in value) |
| 60 | elif fmt.compType == rd.CompType.SNorm: |
| 61 | maxNeg = -float(2 ** (fmt.compByteWidth * 8)) / 2 |
| 62 | divisor = float(-(maxNeg-1)) |
| 63 | value = tuple((float(i) if (i == maxNeg) else (float(i) / divisor)) for i in value) |
| 64 | |
| 65 | # If the format is BGRA, swap the two components |
| 66 | if fmt.BGRAOrder(): |
| 67 | value = tuple(value[i] for i in [2, 1, 0, 3]) |
| 68 | |
| 69 | return value |
| 70 | |
| 71 | # Get a list of MeshData objects describing the vertex inputs at this draw |
| 72 | def getMeshInputs(controller, draw): |