]>
Dogcows Code - chaz/yoink/blob - src/moof/opengl.hh
3367bc8616ddcf569dfa78261bec5f90b9432462
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_OPENGL_HH_
13 #define _MOOF_OPENGL_HH_
17 * Defines macros for OpenGL functions that operate on scalars, vectors,
25 #include <SDL/SDL_opengl.h>
27 #include <moof/math.hh>
30 // generic function arguments
32 #define ARGS_P const GLscalar* p
35 #define ARGS_M const moof::matrix4& m
36 #define PASS_M m.data()
38 // ordinal function arguments
40 #define ARGS_S2 GLscalar a, GLscalar b
42 #define ARGS_S3 GLscalar a, GLscalar b, GLscalar c
43 #define PASS_S3 a, b, c
44 #define ARGS_S4 GLscalar a, GLscalar b, GLscalar c, GLscalar d
45 #define PASS_S4 a, b, c, d
47 #define ARGS_P2 const moof::vector2& p
48 #define PASS_P2 p.data()
49 #define ARGS_P3 const moof::vector3& p
50 #define PASS_P3 p.data()
51 #define ARGS_P4 const moof::vector4& p
52 #define PASS_P4 p.data()
54 #define ARGS_V2 const moof::vector2& v
55 #define PASS_V2 v[0], v[1]
56 #define ARGS_V3 const moof::vector3& v
57 #define PASS_V3 v[0], v[1], v[2]
58 #define ARGS_V4 const moof::vector4& v
59 #define PASS_V4 v[0], v[1], v[2], v[3]
62 #if ENABLE_DOUBLE_PRECISION
64 #define OPENGL_GENERIC_FUNC(R, N, L) \
65 inline R gl##N(ARGS_##L) { gl##N##d(PASS_##L); }//
67 #define OPENGL_ORDINAL_FUNC(R, N, K) \
68 inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \
69 inline R gl##N(ARGS_##P##K) { gl##N##K##d##v(PASS_##P##K); }//
73 #define OPENGL_GENERIC_FUNC(R, N, L) \
74 inline R gl##N(ARGS_##L) { gl##N##f(PASS_##L); }//
76 #define OPENGL_ORDINAL_FUNC(R, N, K) \
77 inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \
78 inline R gl##N(ARGS_##P##K) { gl##N##K##f##v(PASS_##P##K); }//
83 OPENGL_GENERIC_FUNC(void, LoadMatrix
, P
);
84 OPENGL_GENERIC_FUNC(void, LoadMatrix
, M
);
85 OPENGL_GENERIC_FUNC(void, MultMatrix
, P
);
86 OPENGL_GENERIC_FUNC(void, MultMatrix
, M
);
88 OPENGL_GENERIC_FUNC(void, Scale
, S3
);
89 OPENGL_GENERIC_FUNC(void, Scale
, V3
);
90 OPENGL_GENERIC_FUNC(void, Rotate
, S4
);
91 OPENGL_GENERIC_FUNC(void, Rotate
, V4
);
92 OPENGL_GENERIC_FUNC(void, Translate
, S3
);
93 OPENGL_GENERIC_FUNC(void, Translate
, V3
);
95 OPENGL_ORDINAL_FUNC(void, Color
, 3);
96 OPENGL_ORDINAL_FUNC(void, Color
, 4);
98 OPENGL_ORDINAL_FUNC(void, Vertex
, 2);
99 OPENGL_ORDINAL_FUNC(void, Vertex
, 3);
100 OPENGL_ORDINAL_FUNC(void, Vertex
, 4);
102 OPENGL_ORDINAL_FUNC(void, TexCoord
, 2);
103 OPENGL_ORDINAL_FUNC(void, TexCoord
, 3);
104 OPENGL_ORDINAL_FUNC(void, TexCoord
, 4);
106 OPENGL_GENERIC_FUNC(void, Rect
, S4
);
107 OPENGL_GENERIC_FUNC(void, Rect
, V4
);
110 inline void glMaterial(GLenum face
, GLenum pname
, moof::scalar s
)
112 glMaterialf(face
, pname
, float(s
));
115 inline void glMaterial(GLenum face
, GLenum pname
, const moof::vector4
& v
)
117 #if ENABLE_DOUBLE_PRECISION
118 float f
[] = {v
[0], v
[1], v
[2], v
[3]};
119 glMaterialfv(face
, pname
, f
);
121 glMaterialfv(face
, pname
, v
.data());
125 inline void glVertexPointer(const std::vector
<moof::vector3
>& v
)
127 glVertexPointer(3, GL_SCALAR
, 0, v
[0].data());
129 inline void glTexCoordPointer(const std::vector
<moof::vector2
>& v
)
131 glTexCoordPointer(2, GL_SCALAR
, 0, v
[0].data());
134 inline void glDrawElements(GLenum type
, const std::vector
<GLuint
>& v
)
136 glDrawElements(type
, v
.size(), GL_UNSIGNED_INT
, &v
[0]);
140 #if ENABLE_DOUBLE_PRECISION
141 inline void glGetScalar(GLenum a
, GLscalar
* b
) { glGetDoublev(a
, b
); }
143 inline void glGetScalar(GLenum a
, GLscalar
* b
) { glGetFloatv(a
, b
); }
147 #endif // _MOOF_OPENGL_HH_
This page took 0.040078 seconds and 3 git commands to generate.