File: gen_external_templates.py

package info (click to toggle)
glm 0.9.3.3%2Bdfsg-0.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 12,064 kB
  • sloc: cpp: 14,510; xml: 1,819; python: 111; makefile: 5
file content (147 lines) | stat: -rw-r--r-- 5,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

__author__ = "eloraiby"
__date__ = "$5-Sep-2010 9:35:29 PM$"

atomic_types = ["unsigned char", "unsigned short", "unsigned int",
		 "signed char", "signed short", "signed int",
		 "float", "double"]


glsl_vector_types = ["tvec2", "tvec3", "tvec4"]
glsl_matrix_types = ["tmat2x2", "tmat2x3", "tmat2x4",
				"tmat3x2", "tmat3x3", "tmat3x4",
				"tmat4x2", "tmat4x3", "tmat4x4"]

glsl_matrix_member_operators = ["+=", "-=", "*=", "/="]
glsl_matrix_out_op_dic = {
						"tmat2x2":"tmat2x2",
						"tmat2x3":"tmat3x3",
						"tmat2x4":"tmat4x4",
						"tmat3x2":"tmat2x2",
						"tmat3x3":"tmat3x3",
						"tmat3x4":"tmat4x4",
						"tmat4x2":"tmat2x2",
						"tmat4x3":"tmat3x3",
						"tmat4x4":"tmat4x4",
						}

glsl_matrix_right_op_dic = {
						"tmat2x2":"tmat2x2",
						"tmat2x3":"tmat3x2",
						"tmat2x4":"tmat4x2",
						"tmat3x2":"tmat2x3",
						"tmat3x3":"tmat3x3",
						"tmat3x4":"tmat4x3",
						"tmat4x2":"tmat2x4",
						"tmat4x3":"tmat3x4",
						"tmat4x4":"tmat4x4",
						}
def gen_vectors():
	for v in glsl_vector_types:
		print
		print "//"
		print "// " + v + " type explicit instantiation"
		print "//"
		for a in atomic_types:
			print "template struct " + v + "<" + a + ">;"
		print

def gen_matrices_member_operators():
	for m in glsl_matrix_types:
		print
		print "//"
		print "// " + m + " type member operator instantiation"
		print "//"
		for a in atomic_types:
			#print "template " + m + "<" + a + ">::col_type;"
			#print "template " + m + "<" + a + ">::row_type;"
			
			for c in atomic_types:
				if a != c:
					print "template " + m + "<" + a + ">::" + m + "(" + m + "<" + c + "> const &m);"  
				
			"""for b in glsl_matrix_member_operators:
				for cm in atomic_types:
					print "template " + m + "<" + a + ">& " + m + "<" + a + ">::operator " + b + "( " + m + "<" + cm + "> const &m);"
					print "template " + m + "<" + a + ">& " + m + "<" + a + ">::operator " + b + "( " + cm + " const &s);"
			
 			"""
 			print
			print "//"
			print "// Binary operators"
			print "//"
			print "template " + m + "<" + a + "> operator + (" + m + "<" + a + "> const &m, " + a + " const &s);"
			if m == "tmat2x2" or m == "tmat3x3" or m == "tmat4x4":
				print "template " + m + "<" + a + "> operator + (" + a + " const &s, " + m + "<" + a + "> const &m);"
			print "template " + m + "<" + a + "> operator + (" + m + "<" + a + "> const &m1, " + m + "<" + a + "> const &m2);"
			
			print "template " + m + "<" + a + "> operator - (" + m + "<" + a + "> const &m, " + a + " const &s);"
			if m == "tmat2x2" or m == "tmat3x3" or m == "tmat4x4":
				print "template " + m + "<" + a + "> operator - (" + a + " const &s, " + m + "<" + a + "> const &m);"
			print "template " + m + "<" + a + "> operator - (" + m + "<" + a + "> const &m1, " + m + "<" + a + "> const &m2);"
			
			out_op = glsl_matrix_out_op_dic[m]
			right_op = glsl_matrix_right_op_dic[m]
			
			print "template " + m + "<" + a + "> operator * (" + m + "<" + a + "> const &m, " + a + " const &s);"
			if m == "tmat2x2" or m == "tmat3x3" or m == "tmat4x4":
				print "template " + m + "<" + a + "> operator * ( " + a + " const &s, " + m + "<" + a + "> const &m);"
			print "template " + out_op + "<" + a + "> operator * (" + m + "<" + a + "> const &m1, " + right_op + "<" + a + "> const &m2);"
			print "template " + m + "<" + a + ">::col_type" + " operator * ( " + m + "<" + a + "> const &m, " + m + "<" + a + ">::row_type" + " const &s);"
			print "template " + m + "<" + a + ">::row_type" + " operator * ( " + m + "<" + a + ">::col_type const &s, " + m + "<" + a + "> const &m);"
			
			print "template " + m + "<" + a + "> operator / (" + m + "<" + a + "> const &m, " + a + " const &s);"
			#print "template " + right_op + "<" + a + "> operator / ( " + a + " const &s, " + m + "<" + a + "> const &m);"
			
			if m == "tmat2x2" or m == "tmat3x3" or m == "tmat4x4":
				print "template " + m + "<" + a + "> operator / ( " + a + " const &s, " + m + "<" + a + "> const &m);"
				#print "template " + m + "<" + a + "> operator / (" + m + "<" + a + "> const &m1, " + m + "<" + a + "> const &m2);"
			else:
				print "template " + m + "<" + a + "> operator / ( " + a + " const &s, " + m + "<" + a + "> const &m);"

			#print "template " + m + "<" + a + ">" + " operator / ( " + m + "<" + a + "> const &m, " + a + " const &s);"
			#print "template " + m + "<" + a + ">" + " operator / ( " + a + " const &s, " + m + "<" + a + "> const &m);"
			
			print
			print "//"
			print "// Unary constant operators"
			print "//"
			print "template " + m + "<" + a + "> const operator -(" + m + "<" + a + "> const &m);"
			print "template " + m + "<" + a + "> const operator --(" + m + "<" + a + "> const &m, int);"
			print "template " + m + "<" + a + "> const operator ++(" + m + "<" + a + "> const &m, int);"
		
		print

def gen_matrices():
	for m in glsl_matrix_types:
		print
		print "//"
		print "// " + m + " type explicit instantiation"
		print "//"
		for a in atomic_types:
			print "template struct " + m + "<" + a + ">;"
		print
		
if __name__ == "__main__":
	print "//"
	print "// GLM External templates generator script version 0.1 for GLM core"
	print "//"
	print "// atomic types:", atomic_types
	print "// GLSL vector types:", glsl_vector_types;
	print "// GLSL matrix types:", glsl_matrix_types;
	print "//"
	print
	print "#include <glm/glm.hpp>"
	print
	print "namespace glm {"
	print "namespace detail {"
	

	gen_vectors()
	gen_matrices()
	gen_matrices_member_operators()

	print "} // namespace detail"
	print "} // namespace glm"