2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // From Shader Spec, ver. 1.20, rev. 6
30 // 8.5 Matrix Functions
33 mat2x3 matrixCompMult (mat2x3 m, mat2x3 n) {
34 return mat2x3 (m[0] * n[0], m[1] * n[1]);
37 mat2x4 matrixCompMult (mat2x4 m, mat2x4 n) {
38 return mat2x4 (m[0] * n[0], m[1] * n[1]);
41 mat3x2 matrixCompMult (mat3x2 m, mat3x2 n) {
42 return mat3x2 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
45 mat3x4 matrixCompMult (mat3x4 m, mat3x4 n) {
46 return mat3x4 (m[0] * n[0], m[1] * n[1], m[2] * n[2]);
49 mat4x2 matrixCompMult (mat4x2 m, mat4x2 n) {
50 return mat4x2 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
53 mat4x3 matrixCompMult (mat4x3 m, mat4x3 n) {
54 return mat4x3 (m[0] * n[0], m[1] * n[1], m[2] * n[2], m[3] * n[3]);
57 mat2 outerProduct (vec2 c, vec2 r) {
64 mat3 outerProduct (vec3 c, vec3 r) {
66 c.x * r.x, c.y * r.x, c.z * r.x,
67 c.x * r.y, c.y * r.y, c.z * r.y,
68 c.x * r.z, c.y * r.z, c.z * r.z
72 mat4 outerProduct (vec4 c, vec4 r) {
74 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
75 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y,
76 c.x * r.z, c.y * r.z, c.z * r.z, c.w * r.z,
77 c.x * r.w, c.y * r.w, c.z * r.w, c.w * r.w
81 mat2x3 outerProduct (vec3 c, vec2 r) {
83 c.x * r.x, c.y * r.x, c.z * r.x,
84 c.x * r.y, c.y * r.y, c.z * r.y
88 mat3x2 outerProduct (vec2 c, vec3 r) {
96 mat2x4 outerProduct (vec4 c, vec2 r) {
98 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
99 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y
103 mat4x2 outerProduct (vec2 c, vec4 r) {
105 c.x * r.x, c.y * r.x,
106 c.x * r.y, c.y * r.y,
107 c.x * r.z, c.y * r.z,
112 mat3x4 outerProduct (vec4 c, vec3 r) {
114 c.x * r.x, c.y * r.x, c.z * r.x, c.w * r.x,
115 c.x * r.y, c.y * r.y, c.z * r.y, c.w * r.y,
116 c.x * r.z, c.y * r.z, c.z * r.z, c.w * r.z
120 mat4x3 outerProduct (vec3 c, vec4 r) {
122 c.x * r.x, c.y * r.x, c.z * r.x,
123 c.x * r.y, c.y * r.y, c.z * r.y,
124 c.x * r.z, c.y * r.z, c.z * r.z,
125 c.x * r.w, c.y * r.w, c.z * r.w
129 mat2 transpose (mat2 m) {
136 mat3 transpose (mat3 m) {
138 m[0].x, m[1].x, m[2].x,
139 m[0].y, m[1].y, m[2].y,
140 m[0].z, m[1].z, m[2].z
144 mat4 transpose (mat4 m) {
146 m[0].x, m[1].x, m[2].x, m[3].x,
147 m[0].y, m[1].y, m[2].y, m[3].y,
148 m[0].z, m[1].z, m[2].z, m[3].z,
149 m[0].w, m[1].w, m[2].w, m[3].w
153 mat2x3 transpose (mat3x2 m) {
155 m[0].x, m[1].x, m[2].x,
156 m[0].y, m[1].y, m[2].y
160 mat3x2 transpose (mat2x3 m) {
168 mat2x4 transpose (mat4x2 m) {
170 m[0].x, m[1].x, m[2].x, m[3].x,
171 m[0].y, m[1].y, m[2].y, m[3].y
175 mat4x2 transpose (mat2x4 m) {
184 mat3x4 transpose (mat4x3 m) {
186 m[0].x, m[1].x, m[2].x, m[3].x,
187 m[0].y, m[1].y, m[2].y, m[3].y,
188 m[0].z, m[1].z, m[2].z, m[3].z
192 mat4x3 transpose (mat3x4 m) {
194 m[0].x, m[1].x, m[2].x,
195 m[0].y, m[1].y, m[2].y,
196 m[0].z, m[1].z, m[2].z,
197 m[0].w, m[1].w, m[2].w