13c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport sys
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport random
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport operator
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport itertools
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyryfrom genutil import *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyryrandom.seed(1234567)
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyryindices = xrange(sys.maxint)
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Constructors:
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - scalars types
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * int <-> float <-> bool (also float(float) etc.)
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * to bool: zero means false, others true
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * from bool: false==0, true==1
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * \todo [petri] float<->int rounding rules?
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - scalar type from vector
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * choose the first component
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - vectors & matrices
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * vector from scalar: broadcast to all components
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * matrix from scalar: broadcast scalar to diagonal, other components zero
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * vector from vector: copy existing components
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#     + illegal: vector from smaller vector
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * mat from mat: copy existing components, other components from identity matrix
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * from components: consumed by-component in column-major order, must have same
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#     number of components,
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#     + note: vec4(mat2) valid
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#     \todo [petri] Implement!
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - notes:
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * type conversions are always allowed: mat3(ivec3, bvec3, bool, int, float) is valid!
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Accessors:
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - vector components
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * .xyzw, .rgba, .stpq
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * illegal to mix
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * now allowed for scalar types
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * legal to chain: vec4.rgba.xyzw.stpq
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * illegal to select more than 4 components
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * array indexing with [] operator
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * can also write!
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - matrix columns
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * [] accessor
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * note: mat4[0].x = 1.0; vs mat4[0][0] = 1.0; ??
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#   * out-of-bounds accesses
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# \todo [petri] Accessors!
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Spec issues:
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - constructing larger vector from smaller: vec3(vec2) ?
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# - base type and size conversion at same time: vec4(bool), int(vec3) allowed?
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineVec(comps):
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res = []
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for ndx in range(len(comps[0])):
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#		for x in comps:
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#			print x[ndx].toFloat().getScalars() ,
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scalars = reduce(operator.add, [x[ndx].toFloat().getScalars() for x in comps])
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#		print "->", scalars
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res.append(Vec.fromScalarList(scalars))
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineIVec(comps):
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res = []
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for ndx in range(len(comps[0])):
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res.append(Vec.fromScalarList(reduce(operator.add, [x[ndx].toInt().getScalars() for x in comps])))
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineBVec(comps):
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res = []
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for ndx in range(len(comps[0])):
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res.append(Vec.fromScalarList(reduce(operator.add, [x[ndx].toBool().getScalars() for x in comps])))
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineMat(numCols, numRows, comps):
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res = []
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for ndx in range(len(comps[0])):
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		scalars = reduce(operator.add, [x[ndx].toFloat().getScalars() for x in comps])
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		res.append(Mat(numCols, numRows, scalars))
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineMat2(comps):		return combineMat(2, 2, comps)
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineMat3(comps):		return combineMat(3, 3, comps)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef combineMat4(comps):		return combineMat(4, 4, comps)
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# 0 \+ [f*f for f in lst]
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# r = 0 \+ [f in lst -> f*f]
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# r = 0 \+ lst
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Templates.
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrys_simpleCaseTemplate = """
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrycase ${{NAME}}
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	values
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		${{VALUES}}
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	both ""
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		precision mediump float;
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		precision mediump int;
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		${DECLARATIONS}
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void main()
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${SETUP}
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${{OP}}
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${OUTPUT}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	""
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryend
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry"""[1:]
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrys_simpleIllegalCaseTemplate = """
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrycase ${{NAME}}
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	expect compile_fail
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	values {}
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	both ""
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		precision mediump float;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		precision mediump int;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		${DECLARATIONS}
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		void main()
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${SETUP}
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${{OP}}
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			${OUTPUT}
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	""
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryend
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry"""[1:]
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SimpleCase(ShaderCase):
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __init__(self, name, inputs, outputs, op):
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.name		= name
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.inputs		= inputs
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outputs	= outputs
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.op			= op
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __str__(self):
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params = {
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"NAME":		self.name,
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"VALUES":	genValues(self.inputs, self.outputs),
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"OP":		self.op
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return fillTemplate(s_simpleCaseTemplate, params)
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ConversionCase(ShaderCase):
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __init__(self, inValues, convFunc):
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		outValues = convFunc(inValues)
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		inType	= inValues[0].typeString()
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		outType	= outValues[0].typeString()
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.name		= "%s_to_%s" % (inType, outType)
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.op			= "out0 = %s(in0);" % outType
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.inputs		= [("%s in0" % inType, inValues)]
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outputs	= [("%s out0" % outType, outValues)]
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __str__(self):
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params = {
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"NAME":		self.name,
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"VALUES":	genValues(self.inputs, self.outputs),
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"OP":		self.op
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return fillTemplate(s_simpleCaseTemplate, params)
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass IllegalConversionCase(ShaderCase):
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __init__(self, inValue, outValue):
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		inType	= inValue.typeString()
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		outType	= outValue.typeString()
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.name		= "%s_to_%s" % (inType, outType)
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.op			= "%s in0 = %s;\n%s out0 = %s(in0);" % (inType, str(inValue), outType, outType)
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.inType		= inType
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outType	= outType
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __str__(self):
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params = {
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"NAME":		self.name,
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"OP":		self.op
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return fillTemplate(s_simpleIllegalCaseTemplate, params)
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass CombineCase(ShaderCase):
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __init__(self, inComps, combFunc):
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.inComps	= inComps
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outValues	= combFunc(inComps)
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outType	= self.outValues[0].typeString()
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		inTypes = [values[0].typeString() for values in inComps]
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.name		= "%s_to_%s" % ("_".join(inTypes), self.outType)
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.inputs		= [("%s in%s" % (comp[0].typeString(), ndx), comp) for (comp, ndx) in zip(inComps, indices)]
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.outputs	= [("%s out0" % self.outType, self.outValues)]
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		self.op			= "out0 = %s(%s);" % (self.outType, ", ".join(["in%d" % x for x in range(len(inComps))]))
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	def __str__(self):
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		params = {
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"NAME":		self.name,
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"VALUES":	genValues(self.inputs, self.outputs),
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			"OP":		self.op
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		return fillTemplate(s_simpleCaseTemplate, params)
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# CASE DECLARATIONS
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinFloat	= [Scalar(x) for x in [0.0, 1.0, 2.0, 3.5, -0.5, -8.25, -20.125, 36.8125]]
2093c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinInt	= [Scalar(x) for x in [0, 1, 2, 5, 8, 11, -12, -66, -192, 255]]
2103c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinBool	= [Scalar(x) for x in [True, False]]
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinVec4	= [Vec4(0.0, 0.5, 0.75, 0.825), Vec4(1.0, 1.25, 1.125, 1.75),
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Vec4(-0.5, -2.25, -4.875, 9.0), Vec4(-32.0, 64.0, -51.0, 24.0),
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Vec4(-0.75, -1.0/31.0, 1.0/19.0, 1.0/4.0)]
2153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinVec3	= toVec3(inVec4)
2163c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinVec2	= toVec2(inVec4)
2173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinIVec4	= toIVec4(inVec4)
2183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinIVec3	= toIVec3(inVec4)
2193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinIVec2	= toIVec2(inVec4)
2203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinBVec4	= [Vec4(True, False, False, True), Vec4(False, False, False, True), Vec4(False, True, False, False), Vec4(True, True, True, True), Vec4(False, False, False, False)]
2213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinBVec3	= toBVec3(inBVec4)
2223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinBVec2	= toBVec2(inBVec4)
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# \todo [petri] Enable large values when epsilon adapts to the values.
2253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinMat4	= [Mat4(1.0, 0.0, 0.0, 0.0,  0.0, 1.0, 0.0, 0.0,  0.0, 0.0, 1.0, 0.0,  0.0, 0.0, 0.0, 1.0),
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat4(6.5, 12.5, -0.75, 9.975,  32.0, 1.0/48.0, -8.425, -6.542,  1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0,  -6.725, -0.5, -0.0125, 9.975),
2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   #Mat4(128.0, 256.0, -512.0, -1024.0,  2048.0, -4096.0, 8192.0, -8192.0,  192.0, -384.0, 768.0, -1536.0,  8192.0, -8192.0, 6144.0, -6144.0)
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   ]
2293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinMat3	= [Mat3(1.0, 0.0, 0.0,  0.0, 1.0, 0.0,  0.0, 0.0, 1.0),
2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat3(6.5, 12.5, -0.75,  32.0, 1.0/32.0, 1.0/64.0,  1.0/8.0, 1.0/16.0, 1.0/32.0),
2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   #Mat3(-18.725, -0.5, -0.0125,  19.975, -0.25, -17.75,  9.25, 65.125, -21.425),
2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   #Mat3(128.0, -4096.0, -8192.0,  192.0, 768.0, -1536.0,  8192.0, 6144.0, -6144.0)
2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   ]
2343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryinMat2	= [Mat2(1.0, 0.0,  0.0, 1.0),
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat2(6.5, 12.5,  -0.75, 9.975),
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat2(6.5, 12.5,  -0.75, 9.975),
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat2(8.0, 16.0,  -24.0, -16.0),
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat2(1.0/8.0, 1.0/16.0,  1.0/32.0, 1.0/64.0),
2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   Mat2(-18.725, -0.5,  -0.0125, 19.975),
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   #Mat2(128.0, -4096.0,  192.0, -1536.0),
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   #Mat2(-1536.0, 8192.0,  6144.0, -6144.0)
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		   ]
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef genConversionCases(inValueList, convFuncList):
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	combinations = list(itertools.product(inValueList, convFuncList))
2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return [ConversionCase(inValues, convFunc) for (inValues, convFunc) in combinations]
2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef genIllegalConversionCases(inValueList, outValueList):
2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	inValues	= [x[0] for x in inValueList]
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	outValues	= [x[0] for x in outValueList]
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	combinations = list(itertools.product(inValues, outValues))
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return [IllegalConversionCase(inVal, outVal) for (inVal, outVal) in combinations]
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef shuffleSubLists(outer):
2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return [shuffled(inner) for inner in outer]
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Generate all combinations of CombineCases.
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# inTupleList	a list of tuples of value-lists
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# combFuncList	a list of comb* functions to combine
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef genComponentCases(inCompLists, combFuncList):
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	res = []
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	for comps in inCompLists:
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		maxLen = reduce(max, [len(values) for values in comps])
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		comps = [repeatToLength(values, maxLen) for values in comps]
2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		comps = [shuffled(values) for values in comps]
2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for combFunc in combFuncList:
2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			res += [CombineCase(comps, combFunc)]
2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return res
2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2703c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases = []
2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Scalar-to-scalar conversions.
2733c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("scalar_to_scalar", "Scalar to Scalar Conversions",
2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inFloat, inInt, inBool], [toFloat, toInt, toBool])))
2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Scalar-to-vector conversions.
2773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("scalar_to_vector", "Scalar to Vector Conversions",
2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inFloat, inInt, inBool], [toVec2, toVec3, toVec4, toIVec2, toIVec3, toIVec4, toBVec2, toBVec3, toBVec4])))
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Vector-to-scalar conversions.
2813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("vector_to_scalar", "Vector to Scalar Conversions",
2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inVec2, inVec3, inVec4, inIVec2, inIVec3, inIVec4, inBVec2, inBVec3, inBVec4], [toFloat, toInt, toBool])))
2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Illegal vector-to-vector conversions (to longer vec).
2853c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("vector_illegal", "Illegal Vector Conversions",
2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genIllegalConversionCases([inVec2, inIVec2, inBVec2], [inVec3, inIVec3, inBVec3, inVec4, inIVec4, inBVec4]) +\
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genIllegalConversionCases([inVec3, inIVec3, inBVec3], [inVec4, inIVec4, inBVec4])))
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Vector-to-vector conversions (type conversions, downcasts).
2903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("vector_to_vector", "Vector to Vector Conversions",
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inVec4, inIVec4, inBVec4], [toVec4, toVec3, toVec2, toIVec4, toIVec3, toIVec2, toBVec4, toBVec3, toBVec2]) +\
2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inVec3, inIVec3, inBVec3], [toVec3, toVec2, toIVec3, toIVec2, toBVec3, toBVec2]) +\
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inVec2, inIVec2, inBVec2], [toVec2, toIVec2, toBVec2])))
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Scalar-to-matrix.
2963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("scalar_to_matrix", "Scalar to Matrix Conversions",
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inFloat, inInt, inBool], [toMat4, toMat3, toMat2])))
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Vector-to-matrix.
3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#allConversionCases += genConversionCases([inVec4, inIVec4, inBVec4], [toMat4])
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#allConversionCases += genConversionCases([inVec3, inIVec3, inBVec3], [toMat3])
3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#allConversionCases += genConversionCases([inVec2, inIVec2, inBVec2], [toMat2])
3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Matrix-to-matrix.
3053c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("matrix_to_matrix", "Matrix to Matrix Conversions",
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genConversionCases([inMat4, inMat3, inMat2], [toMat4, toMat3, toMat2])))
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Vector-from-components, matrix-from-components.
3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryin2Comp 	= [[inFloat, inFloat], [inInt, inInt], [inBool, inBool], [inFloat, inInt], [inFloat, inBool], [inInt, inBool]]
3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryin3Comp 	= [[inFloat, inFloat, inFloat], [inInt, inInt, inInt], [inBool, inBool, inBool], [inBool, inFloat, inInt], [inVec2, inBool], [inBVec2, inFloat], [inBVec2, inInt], [inBool, inIVec2]]
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryin4Comp 	= [[inVec2, inVec2], [inBVec2, inBVec2], [inFloat, inFloat, inFloat, inFloat], [inInt, inInt, inInt, inInt], [inBool, inBool, inBool, inBool], [inBool, inFloat, inInt, inBool], [inVec2, inIVec2], [inVec2, inBVec2], [inBVec3, inFloat], [inVec3, inFloat], [inInt, inIVec2, inInt], [inBool, inFloat, inIVec2]]
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyryin9Comp 	= [[inVec3, inVec3, inVec3], [inIVec3, inIVec3, inIVec3], [inVec2, inIVec2, inFloat, inFloat, inInt, inBool, inBool], [inBool, inFloat, inInt, inVec2, inBool, inBVec2, inFloat], [inBool, inBVec2, inInt, inVec4, inBool], [inFloat, inBVec4, inIVec2, inBool, inBool]]
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryin16Comp	= [[inVec4, inVec4, inVec4, inVec4], [inIVec4, inIVec4, inIVec4, inIVec4], [inBVec4, inBVec4, inBVec4, inBVec4], [inFloat, inIVec3, inBVec3, inVec4, inIVec2, inFloat, inVec2]]
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("vector_combine", "Vector Combine Constructors",
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in4Comp, [combineVec, combineIVec, combineBVec]) +\
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in3Comp, [combineVec, combineIVec, combineBVec]) +\
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in2Comp, [combineVec, combineIVec, combineBVec])))
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3203c827367444ee418f129b2c238299f49d3264554Jarkko PoyryallConversionCases.append(CaseGroup("matrix_combine", "Matrix Combine Constructors",
3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in4Comp, [combineMat2]) +\
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in9Comp, [combineMat3]) +\
3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	genComponentCases(in16Comp, [combineMat4])
3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	))
3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry# Main program.
3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryif __name__ == "__main__":
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	print "Generating shader case files."
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	writeAllCases("conversions.test", allConversionCases)
331