source: trunk/src/lol/base/types.h @ 3867

Last change on this file since 3867 was 3867, checked in by touky, 7 years ago

trying new helpers

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#pragma once
12
13#include <stdint.h>
14
15namespace lol
16{
17
18/* It’s nice to have single-word type names, so define this. */
19typedef long double ldouble;
20
21/* The “real” type used for real numbers. It’s a specialisation of the
22 * “Real” template class. */
23template<int N> class Real;
24typedef Real<16> real;
25
26/* The “half” type used for 16-bit floating point numbers. */
27class half;
28
29/*
30 * Forward declaration of vec_t, mat_t, cmplx_t, quat_t
31 */
32
33/* HACK: if this is declared int const, Visual Studio becomes unable
34 * to perform template argument deduction. */
35#define FULL_SWIZZLE (0)
36
37template<typename T, int N, int SWIZZLE = FULL_SWIZZLE> struct vec_t;
38template<typename T, int COLS, int ROWS> struct mat_t;
39template<typename T> struct cmplx_t;
40template<typename T> struct quat_t;
41template<typename T> struct dualquat_t;
42
43/*
44 * Generic GLSL-like type names
45 */
46
47#define _T(tleft, tright, suffix) \
48    typedef tleft half tright f16##suffix; \
49    typedef tleft float tright suffix; \
50    typedef tleft double tright d##suffix; \
51    typedef tleft ldouble tright f128##suffix; \
52    typedef tleft int8_t tright i8##suffix; \
53    typedef tleft uint8_t tright u8##suffix; \
54    typedef tleft int16_t tright i16##suffix; \
55    typedef tleft uint16_t tright u16##suffix; \
56    typedef tleft int32_t tright i##suffix; \
57    typedef tleft uint32_t tright u##suffix; \
58    typedef tleft int64_t tright i64##suffix; \
59    typedef tleft uint64_t tright u64##suffix; \
60    typedef tleft real tright r##suffix;
61
62/* Idiotic hack to put "," inside a macro argument */
63#define _C ,
64
65_T(vec_t<, _C 2>, vec2)
66_T(vec_t<, _C 3>, vec3)
67_T(vec_t<, _C 4>, vec4)
68_T(vec_t<, _C 5>, vec5)
69_T(vec_t<, _C 6>, vec6)
70_T(vec_t<, _C 7>, vec7)
71_T(vec_t<, _C 8>, vec8)
72_T(vec_t<, _C 9>, vec9)
73_T(vec_t<, _C 10>, vec10)
74_T(vec_t<, _C 11>, vec11)
75_T(vec_t<, _C 12>, vec12)
76
77_T(mat_t<, _C 2 _C 2>, mat2)
78_T(mat_t<, _C 3 _C 3>, mat3)
79_T(mat_t<, _C 4 _C 4>, mat4)
80
81_T(mat_t<, _C 2 _C 3>, mat2x3)
82_T(mat_t<, _C 2 _C 4>, mat2x4)
83_T(mat_t<, _C 3 _C 2>, mat3x2)
84_T(mat_t<, _C 3 _C 4>, mat3x4)
85_T(mat_t<, _C 4 _C 2>, mat4x2)
86_T(mat_t<, _C 4 _C 3>, mat4x3)
87
88_T(cmplx_t<, >, cmplx)
89_T(quat_t<, >, quat)
90_T(dualquat_t<, >, dualquat)
91
92#undef _C
93#undef _T
94
95/*
96* Practical useage typedefs
97*/
98typedef vec4 color;
99typedef vec2 spheric2;
100typedef vec3 spheric3;
101
102/*
103 * HLSL/Cg-compliant type names
104 */
105
106typedef vec2 float2;
107typedef vec3 float3;
108typedef vec4 float4;
109typedef vec5 float5;
110typedef vec6 float6;
111typedef vec7 float7;
112typedef vec8 float8;
113typedef vec9 float9;
114typedef vec10 float10;
115typedef vec11 float11;
116typedef vec12 float12;
117typedef mat2 float2x2;
118typedef mat3 float3x3;
119typedef mat4 float4x4;
120typedef mat2x3 float2x3;
121typedef mat2x4 float2x4;
122typedef mat3x2 float3x2;
123typedef mat3x4 float3x4;
124typedef mat4x2 float4x2;
125typedef mat4x3 float4x3;
126
127typedef f16vec2 half2;
128typedef f16vec3 half3;
129typedef f16vec4 half4;
130typedef f16mat2 half2x2;
131typedef f16mat3 half3x3;
132typedef f16mat4 half4x4;
133typedef f16mat2x3 half2x3;
134typedef f16mat2x4 half2x4;
135typedef f16mat3x2 half3x2;
136typedef f16mat3x4 half3x4;
137typedef f16mat4x2 half4x2;
138typedef f16mat4x3 half4x3;
139
140typedef ivec2 int2;
141typedef ivec3 int3;
142typedef ivec4 int4;
143typedef ivec5 int5;
144typedef ivec6 int6;
145typedef ivec7 int7;
146typedef ivec8 int8;
147typedef ivec9 int9;
148typedef ivec10 int10;
149typedef ivec11 int11;
150typedef ivec12 int12;
151typedef imat2 int2x2;
152typedef imat3 int3x3;
153typedef imat4 int4x4;
154typedef imat2x3 int2x3;
155typedef imat2x4 int2x4;
156typedef imat3x2 int3x2;
157typedef imat3x4 int3x4;
158typedef imat4x2 int4x2;
159typedef imat4x3 int4x3;
160
161} /* namespace lol */
162
Note: See TracBrowser for help on using the repository browser.