fix the spelling in whole piglit
[piglit.git] / generated_tests / modules / types.py
blob73c21de68b3b9763b36202d98560137c7de1a7e4
1 # encoding=utf-8
2 # Copyright © 2016 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Classes describing various GLSL types.
24 These classes do not contain values themselves, rather they describe the GLSL
25 types.
27 Included are representations of Matrices, Vectors, and Scalars as containers,
28 and Ints, Uints, Floats, and Doubles as types. This can easily be expanded to
29 include more types, and the corresponding containers.
31 Although the classes that implement these representations are not marked as
32 private, most consumers will be happier using the provided constants than using
33 the classes themselves. Probably the only real use for the types is to do type
34 checking.
36 """
38 from .utils import lazy_property
41 class Container(object):
42 """A Base class for GLSL container.
44 It provides the following attributes:
45 name -- The string formatted name of the container
46 scalar -- True if the type is scalar
47 vector -- True if the type is vector
48 matrix -- True if the type is matrix
49 type -- A Type object that is the type contained by the container
50 rows -- The number of rows the container has. Scalars return 1
51 columns -- The number of rows container has. Scalars and Vectors return 1
53 """
54 def __init__(self, name, is_scalar=False, is_vector=False, is_matrix=False,
55 rows=1, columns=1, contains=None):
56 assert all(isinstance(x, bool)
57 for x in [is_scalar, is_vector, is_matrix]), \
58 'is_scalar, is_vector, and is_matrix must be bools'
59 assert [is_scalar, is_vector, is_matrix].count(True) == 1, \
60 'A type must be exactly one of: scalar, vector, matrix'
61 assert isinstance(contains, Type), 'contains must be a type instance'
62 assert isinstance(name, str), 'name must be string'
63 assert columns is None or isinstance(columns, int), \
64 'columns must be an int if provided'
65 assert rows is None or isinstance(rows, int), \
66 'row must be an int if provided'
68 self.name = name
69 self.scalar = is_scalar
70 self.vector = is_vector
71 self.matrix = is_matrix
72 self.type = contains
73 self.rows = rows
74 self.columns = columns
77 class Scalar(Container):
78 """A base class for Scalar types."""
79 def __init__(self, name, contains):
80 super(Scalar, self).__init__(name, is_scalar=True, contains=contains)
83 class Vector(Container):
84 """A base class for Vector Containers."""
85 def __init__(self, name, rows, contains):
86 assert isinstance(rows, int), 'rows must be an integer'
87 assert rows in [2, 3, 4], 'vecs can only be 2-4 in GLSL'
89 super(Vector, self).__init__(name, is_vector=True, rows=rows,
90 contains=contains)
93 class Matrix(Container):
94 """A base class for vectory Containers."""
95 def __init__(self, name, columns, rows, contains):
96 assert isinstance(rows, int), 'rows must be an integer'
97 assert isinstance(columns, int), 'columns must be an integer'
98 assert rows in [2, 3, 4], 'Matrix rows can only be 2-4 in GLSL'
99 assert columns in [2, 3, 4], 'Matrix columns can only be 2-4 in GLSL'
101 super(Matrix, self).__init__(name, is_matrix=True, rows=rows,
102 columns=columns, contains=contains)
104 @lazy_property
105 def square(self):
106 return self.columns == self.rows
109 class Type(object):
110 """Class representing a GLSL type.
112 Provides the following interfaces currently:
113 integer -- True if the type is an integer type
114 signed -- True if the type is a signed type
115 float -- True if the type is a floating point type
116 size -- The integer size of the type (8, 16, 32, 64, 128, etc)
117 name -- A formatted string name of the type. (float, double, int64, ...)
120 def __init__(self, name, integer=False, signed=False, floating=False,
121 size=None):
122 assert [integer, floating].count(True) == 1, \
123 'Type can onnly be float or int'
124 assert integer or (float and signed), 'Floats cannot be unsigned'
125 assert isinstance(size, int), 'size must be an int'
127 self.name = name
128 self.integer = integer
129 self.signed = signed
130 self.float = floating
131 self.size = size
134 # pylint: disable=bad-whitespace
135 # Type definitions, these are used internally by the Scalar/Vector/Matrix
136 # constructs
137 INT_TYPE = Type('int', integer=True, signed=True, size=32)
138 UINT_TYPE = Type('uint', integer=True, signed=False, size=32)
139 FLOAT_TYPE = Type('float', floating=True, signed=True, size=32)
140 DOUBLE_TYPE = Type('double', floating=True, signed=True, size=64)
142 # Container definitions
143 INT = Scalar('int', INT_TYPE)
144 UINT = Scalar('uint', UINT_TYPE)
145 FLOAT = Scalar('float', FLOAT_TYPE)
146 DOUBLE = Scalar('double', DOUBLE_TYPE)
148 VEC2 = Vector('vec2', 2, FLOAT_TYPE)
149 VEC3 = Vector('vec3', 3, FLOAT_TYPE)
150 VEC4 = Vector('vec4', 4, FLOAT_TYPE)
152 IVEC2 = Vector('ivec2', 2, INT_TYPE)
153 IVEC3 = Vector('ivec3', 3, INT_TYPE)
154 IVEC4 = Vector('ivec4', 4, INT_TYPE)
156 UVEC2 = Vector('uvec2', 2, UINT_TYPE)
157 UVEC3 = Vector('uvec3', 3, UINT_TYPE)
158 UVEC4 = Vector('uvec4', 4, UINT_TYPE)
160 DVEC2 = Vector('dvec2', 2, DOUBLE_TYPE)
161 DVEC3 = Vector('dvec3', 3, DOUBLE_TYPE)
162 DVEC4 = Vector('dvec4', 4, DOUBLE_TYPE)
164 MAT2 = Matrix('mat2', 2, 2, FLOAT_TYPE)
165 MAT3 = Matrix('mat3', 3, 3, FLOAT_TYPE)
166 MAT4 = Matrix('mat4', 4, 4, FLOAT_TYPE)
167 MAT2X2 = Matrix('mat2x2', 2, 2, FLOAT_TYPE)
168 MAT2X3 = Matrix('mat2x3', 2, 3, FLOAT_TYPE)
169 MAT2X4 = Matrix('mat2x4', 2, 4, FLOAT_TYPE)
170 MAT3X2 = Matrix('mat3x2', 3, 2, FLOAT_TYPE)
171 MAT3X3 = Matrix('mat3x3', 3, 3, FLOAT_TYPE)
172 MAT3X4 = Matrix('mat3x4', 3, 4, FLOAT_TYPE)
173 MAT4X2 = Matrix('mat4x2', 4, 2, FLOAT_TYPE)
174 MAT4X3 = Matrix('mat4x3', 4, 3, FLOAT_TYPE)
175 MAT4X4 = Matrix('mat4x4', 4, 4, FLOAT_TYPE)
177 DMAT2 = Matrix('dmat2', 2, 2, DOUBLE_TYPE)
178 DMAT3 = Matrix('dmat3', 3, 3, DOUBLE_TYPE)
179 DMAT4 = Matrix('dmat4', 4, 4, DOUBLE_TYPE)
180 DMAT2X2 = Matrix('dmat2x2', 2, 2, DOUBLE_TYPE)
181 DMAT2X3 = Matrix('dmat2x3', 2, 3, DOUBLE_TYPE)
182 DMAT2X4 = Matrix('dmat2x4', 2, 4, DOUBLE_TYPE)
183 DMAT3X2 = Matrix('dmat3x2', 3, 2, DOUBLE_TYPE)
184 DMAT3X3 = Matrix('dmat3x3', 3, 3, DOUBLE_TYPE)
185 DMAT3X4 = Matrix('dmat3x4', 3, 4, DOUBLE_TYPE)
186 DMAT4X2 = Matrix('dmat4x2', 4, 2, DOUBLE_TYPE)
187 DMAT4X3 = Matrix('dmat4x3', 4, 3, DOUBLE_TYPE)
188 DMAT4X4 = Matrix('dmat4x4', 4, 4, DOUBLE_TYPE)
189 # pylint: enable=bad-whitespace