]> Dogcows Code - chaz/yoink/blob - src/moof/opengl.hh
pch support
[chaz/yoink] / src / moof / opengl.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_OPENGL_HH_
11 #define _MOOF_OPENGL_HH_
12
13 #if HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include <vector>
18
19 #include <SDL/SDL_opengl.h>
20
21 #include <moof/math.hh>
22
23
24 /**
25 * \file opengl.hh
26 * Defines macros for OpenGL functions that operate on scalars, vectors, and
27 * matrices.
28 */
29
30 // generic function arguments
31
32 #define ARGS_P const GLscalar* p
33 #define PASS_P p
34
35 #define ARGS_M const moof::matrix4& m
36 #define PASS_M m.data()
37
38 // ordinal function arguments
39
40 #define ARGS_S2 GLscalar a, GLscalar b
41 #define PASS_S2 a, 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
46
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()
53
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]
60
61 #if ENABLE_DOUBLE_PRECISION
62
63 #define OPENGL_GENERIC_FUNC(R, N, L) \
64 inline R gl##N(ARGS_##L) { gl##N##d(PASS_##L); }//
65
66 #define OPENGL_ORDINAL_FUNC(R, N, K) \
67 inline R gl##N(ARGS_##S##K) { gl##N##K##d(PASS_##S##K); } \
68 inline R gl##N(ARGS_##P##K) { gl##N##K##d##v(PASS_##P##K); }//
69
70 #else
71
72 #define OPENGL_GENERIC_FUNC(R, N, L) \
73 inline R gl##N(ARGS_##L) { gl##N##f(PASS_##L); }//
74
75 #define OPENGL_ORDINAL_FUNC(R, N, K) \
76 inline R gl##N(ARGS_##S##K) { gl##N##K##f(PASS_##S##K); } \
77 inline R gl##N(ARGS_##P##K) { gl##N##K##f##v(PASS_##P##K); }//
78
79 #endif
80
81 OPENGL_GENERIC_FUNC(void, LoadMatrix, P);
82 OPENGL_GENERIC_FUNC(void, LoadMatrix, M);
83 OPENGL_GENERIC_FUNC(void, MultMatrix, P);
84 OPENGL_GENERIC_FUNC(void, MultMatrix, M);
85
86 OPENGL_GENERIC_FUNC(void, Scale, S3);
87 OPENGL_GENERIC_FUNC(void, Scale, V3);
88 OPENGL_GENERIC_FUNC(void, Rotate, S4);
89 OPENGL_GENERIC_FUNC(void, Rotate, V4);
90 OPENGL_GENERIC_FUNC(void, Translate, S3);
91 OPENGL_GENERIC_FUNC(void, Translate, V3);
92
93 OPENGL_ORDINAL_FUNC(void, Color, 3);
94 OPENGL_ORDINAL_FUNC(void, Color, 4);
95
96 OPENGL_ORDINAL_FUNC(void, Vertex, 2);
97 OPENGL_ORDINAL_FUNC(void, Vertex, 3);
98 OPENGL_ORDINAL_FUNC(void, Vertex, 4);
99
100 OPENGL_ORDINAL_FUNC(void, TexCoord, 2);
101 OPENGL_ORDINAL_FUNC(void, TexCoord, 3);
102 OPENGL_ORDINAL_FUNC(void, TexCoord, 4);
103
104 OPENGL_GENERIC_FUNC(void, Rect, S4);
105 OPENGL_GENERIC_FUNC(void, Rect, V4);
106
107 inline void glMaterial(GLenum face, GLenum pname, moof::scalar s)
108 {
109 glMaterialf(face, pname, float(s));
110 }
111
112 inline void glMaterial(GLenum face, GLenum pname, const moof::vector4& v)
113 {
114 #if ENABLE_DOUBLE_PRECISION
115 float f[] = {v[0], v[1], v[2], v[3]};
116 glMaterialfv(face, pname, f);
117 #else
118 glMaterialfv(face, pname, v.data());
119 #endif
120 }
121
122 inline void glVertexPointer(const std::vector<moof::vector3>& v)
123 {
124 glVertexPointer(3, GL_SCALAR, 0, v[0].data());
125 }
126 inline void glTexCoordPointer(const std::vector<moof::vector2>& v)
127 {
128 glTexCoordPointer(2, GL_SCALAR, 0, v[0].data());
129 }
130
131 inline void glDrawElements(GLenum type, const std::vector<GLuint>& v)
132 {
133 glDrawElements(type, v.size(), GL_UNSIGNED_INT, &v[0]);
134 }
135
136 inline void glGetScalar(GLenum a, GLscalar* b)
137 {
138 #if ENABLE_DOUBLE_PRECISION
139 glGetDoublev(a, b);
140 #else
141 glGetFloatv(a, b);
142 #endif
143 }
144
145
146 #endif // _MOOF_OPENGL_HH_
147
This page took 0.035592 seconds and 4 git commands to generate.