11#ifndef GLEMU_H
22#define GLEMU_H
3+
34namespace gle
45{
56 enum
67 {
7- ATTRIB_VERTEX = 0 ,
8- ATTRIB_COLOR = 1 ,
9- ATTRIB_TEXCOORD0 = 2 ,
10- ATTRIB_TEXCOORD1 = 3 ,
11- ATTRIB_NORMAL = 4 ,
12- ATTRIB_TANGENT = 5 ,
13- ATTRIB_BONEWEIGHT = 6 ,
14- ATTRIB_BONEINDEX = 7 ,
15- MAXATTRIBS = 8
8+ ATTRIB_VERTEX = 0 ,
9+ ATTRIB_COLOR = 1 ,
10+ ATTRIB_TEXCOORD0 = 2 ,
11+ ATTRIB_TEXCOORD1 = 3 ,
12+ ATTRIB_NORMAL = 4 ,
13+ ATTRIB_TANGENT = 5 ,
14+ ATTRIB_BONEWEIGHT = 6 ,
15+ ATTRIB_BONEINDEX = 7 ,
16+ MAXATTRIBS = 8
1617 };
1718
1819 extern const char * const attribnames[MAXATTRIBS];
@@ -25,66 +26,53 @@ namespace gle
2526 extern void begin (GLenum mode);
2627 extern void begin (GLenum mode, int numverts);
2728 extern void multidraw ();
28- extern void defattribs (const char *fmt);
2929 extern void defattrib (int type, int size, int format);
3030
31- #define GLE_DEFATTRIB (name, type, defaultsize, defaultformat ) \
32- static inline void def##name(int size = defaultsize, int format = defaultformat) { defattrib (type, size, format); }
33-
34- GLE_DEFATTRIB (vertex, ATTRIB_VERTEX, 3 , GL_FLOAT)
35- GLE_DEFATTRIB (color, ATTRIB_COLOR, 3 , GL_FLOAT)
36- GLE_DEFATTRIB (texcoord0, ATTRIB_TEXCOORD0, 2 , GL_FLOAT)
37- GLE_DEFATTRIB (texcoord1, ATTRIB_TEXCOORD1, 2 , GL_FLOAT)
38- GLE_DEFATTRIB (normal, ATTRIB_NORMAL, 3 , GL_FLOAT)
39- GLE_DEFATTRIB (tangent, ATTRIB_TANGENT, 4 , GL_FLOAT)
40- GLE_DEFATTRIB (boneweight, ATTRIB_BONEWEIGHT, 4 , GL_UNSIGNED_BYTE)
41- GLE_DEFATTRIB (boneindex, ATTRIB_BONEINDEX, 4 , GL_UNSIGNED_BYTE)
42-
43- #define GLE_INITATTRIB (name, index, suffix, type ) \
44- static inline void name##suffix(type x) { glVertexAttrib1##suffix##_ (index, x); } \
45- static inline void name##suffix(type x, type y) { glVertexAttrib2##suffix##_ (index, x, y); } \
46- static inline void name##suffix(type x, type y, type z) { glVertexAttrib3##suffix##_ (index, x, y, z); } \
47- static inline void name##suffix(type x, type y, type z, type w) { glVertexAttrib4##suffix##_ (index, x, y, z, w); }
48- #define GLE_INITATTRIBF (name, index ) \
49- GLE_INITATTRIB (name, index, f, float ) \
50- static inline void name (const vec &v) { glVertexAttrib3fv_ (index, v.v ); } \
51- static inline void name (const vec &v, float w) { glVertexAttrib4f_ (index, v.x , v.y , v.z , w); } \
52- static inline void name (const vec2 &v) { glVertexAttrib2fv_ (index, v.v ); } \
53- static inline void name (const vec4 &v) { glVertexAttrib4fv_ (index, v.v ); }
54- #define GLE_INITATTRIBN (name, index, suffix, type, defaultw ) \
55- static inline void name##suffix(type x, type y, type z, type w = defaultw) { glVertexAttrib4N##suffix##_ (index, x, y, z, w); }
56-
57- GLE_INITATTRIBF (vertex, ATTRIB_VERTEX)
58- GLE_INITATTRIBF (color, ATTRIB_COLOR)
59- GLE_INITATTRIBN (color, ATTRIB_COLOR, ub, uchar, 255 )
31+ static inline void defvertex (int size = 3 , int format = GL_FLOAT) { defattrib (ATTRIB_VERTEX, size, format); }
32+ static inline void defcolor (int size = 3 , int format = GL_FLOAT) { defattrib (ATTRIB_COLOR, size, format); }
33+ static inline void deftexcoord0 (int size = 2 , int format = GL_FLOAT) { defattrib (ATTRIB_TEXCOORD0, size, format); }
34+ static inline void defnormal (int size = 3 , int format = GL_FLOAT) { defattrib (ATTRIB_NORMAL, size, format); }
35+ static inline void deftangent (int size = 4 , int format = GL_FLOAT) { defattrib (ATTRIB_TANGENT, size, format); }
36+
37+ static inline void colorf (float x, float y, float z) { glVertexAttrib3f_ (ATTRIB_COLOR, x, y, z); }
38+ static inline void colorf (float x, float y, float z, float w) { glVertexAttrib4f_ (ATTRIB_COLOR, x, y, z, w); }
39+ static inline void color (const vec &v) { glVertexAttrib3fv_ (ATTRIB_COLOR, v.v ); }
40+ static inline void color (const vec &v, float w) { glVertexAttrib4f_ (ATTRIB_COLOR, v.x , v.y , v.z , w); }
41+ static inline void colorub (uchar x, uchar y, uchar z, uchar w = 255 ) { glVertexAttrib4Nub_ (ATTRIB_COLOR, x, y, z, w); }
6042 static inline void color (const bvec &v, uchar alpha = 255 ) { glVertexAttrib4Nub_ (ATTRIB_COLOR, v.x , v.y , v.z , alpha); }
6143 static inline void color (const bvec4 &v) { glVertexAttrib4Nubv_ (ATTRIB_COLOR, v.v ); }
62- GLE_INITATTRIBF (texcoord0, ATTRIB_TEXCOORD0)
63- GLE_INITATTRIBF (texcoord1, ATTRIB_TEXCOORD1)
64- static inline void normal (float x, float y, float z) { glVertexAttrib4f_ (ATTRIB_NORMAL, x, y, z, 0 .0f ); }
65- static inline void normal (const vec &v) { glVertexAttrib4f_ (ATTRIB_NORMAL, v.x , v.y , v.z , 0 .0f ); }
66- static inline void tangent (float x, float y, float z, float w = 1 .0f ) { glVertexAttrib4f_ (ATTRIB_TANGENT, x, y, z, w); }
67- static inline void tangent (const vec &v, float w = 1 .0f ) { glVertexAttrib4f_ (ATTRIB_TANGENT, v.x , v.y , v.z , w); }
68- static inline void tangent (const vec4 &v) { glVertexAttrib4fv_ (ATTRIB_TANGENT, v.v ); }
69-
70- #define GLE_ATTRIBPOINTER (name, index, defaultnormalized, defaultsize, defaulttype, prepare ) \
71- static inline void enable##name() { prepare; glEnableVertexAttribArray_ (index); } \
72- static inline void disable##name() { glDisableVertexAttribArray_ (index); } \
73- static inline void name##pointer(int stride, const void *data, GLenum type = defaulttype, int size = defaultsize, GLenum normalized = defaultnormalized) { \
74- prepare; \
75- glVertexAttribPointer_ (index, size, type, normalized, stride, data); \
76- }
7744
78- static inline void enableattrib (int index) { disable (); glEnableVertexAttribArray_ (index); }
79- static inline void disableattrib (int index) { glDisableVertexAttribArray_ (index); }
80- GLE_ATTRIBPOINTER (vertex, ATTRIB_VERTEX, GL_FALSE, 3 , GL_FLOAT, disable())
81- GLE_ATTRIBPOINTER (color, ATTRIB_COLOR, GL_TRUE, 4 , GL_UNSIGNED_BYTE, )
82- GLE_ATTRIBPOINTER (texcoord0, ATTRIB_TEXCOORD0, GL_FALSE, 2 , GL_FLOAT, )
83- GLE_ATTRIBPOINTER (texcoord1, ATTRIB_TEXCOORD1, GL_FALSE, 2 , GL_FLOAT, )
84- GLE_ATTRIBPOINTER (normal, ATTRIB_NORMAL, GL_TRUE, 3 , GL_FLOAT, )
85- GLE_ATTRIBPOINTER (tangent, ATTRIB_TANGENT, GL_TRUE, 4 , GL_FLOAT, )
86- GLE_ATTRIBPOINTER (boneweight, ATTRIB_BONEWEIGHT, GL_TRUE, 4 , GL_UNSIGNED_BYTE, )
87- GLE_ATTRIBPOINTER (boneindex, ATTRIB_BONEINDEX, GL_FALSE, 4 , GL_UNSIGNED_BYTE, )
45+ static inline void enablevertex () { disable (); glEnableVertexAttribArray_ (ATTRIB_VERTEX); }
46+ static inline void disablevertex () { glDisableVertexAttribArray_ (ATTRIB_VERTEX); }
47+ static inline void vertexpointer (int stride, const void *data, GLenum type = GL_FLOAT, int size = 3 , GLenum normalized = GL_FALSE) { disable (); glVertexAttribPointer_ (ATTRIB_VERTEX, size, type, normalized, stride, data); }
48+
49+ static inline void enablecolor () { ; glEnableVertexAttribArray_ (ATTRIB_COLOR); }
50+ static inline void disablecolor () { glDisableVertexAttribArray_ (ATTRIB_COLOR); }
51+ static inline void colorpointer (int stride, const void *data, GLenum type = GL_UNSIGNED_BYTE, int size = 4 , GLenum normalized = GL_TRUE) { ; glVertexAttribPointer_ (ATTRIB_COLOR, size, type, normalized, stride, data); }
52+
53+ static inline void enabletexcoord0 () { ; glEnableVertexAttribArray_ (ATTRIB_TEXCOORD0); }
54+ static inline void disabletexcoord0 () { glDisableVertexAttribArray_ (ATTRIB_TEXCOORD0); }
55+ static inline void texcoord0pointer (int stride, const void *data, GLenum type = GL_FLOAT, int size = 2 , GLenum normalized = GL_FALSE) { ; glVertexAttribPointer_ (ATTRIB_TEXCOORD0, size, type, normalized, stride, data); }
56+
57+ static inline void enabletexcoord1 () { ; glEnableVertexAttribArray_ (ATTRIB_TEXCOORD1); }
58+ static inline void disabletexcoord1 () { glDisableVertexAttribArray_ (ATTRIB_TEXCOORD1); }
59+ static inline void texcoord1pointer (int stride, const void *data, GLenum type = GL_FLOAT, int size = 2 , GLenum normalized = GL_FALSE) { ; glVertexAttribPointer_ (ATTRIB_TEXCOORD1, size, type, normalized, stride, data); }
60+
61+ static inline void enablenormal () { ; glEnableVertexAttribArray_ (ATTRIB_NORMAL); }
62+ static inline void disablenormal () { glDisableVertexAttribArray_ (ATTRIB_NORMAL); }
63+ static inline void normalpointer (int stride, const void *data, GLenum type = GL_FLOAT, int size = 3 , GLenum normalized = GL_TRUE) { ; glVertexAttribPointer_ (ATTRIB_NORMAL, size, type, normalized, stride, data); }
64+
65+ static inline void enabletangent () { ; glEnableVertexAttribArray_ (ATTRIB_TANGENT); }
66+ static inline void disabletangent () { glDisableVertexAttribArray_ (ATTRIB_TANGENT); }
67+ static inline void tangentpointer (int stride, const void *data, GLenum type = GL_FLOAT, int size = 4 , GLenum normalized = GL_TRUE) { ; glVertexAttribPointer_ (ATTRIB_TANGENT, size, type, normalized, stride, data); }
68+
69+ static inline void enableboneweight () { ; glEnableVertexAttribArray_ (ATTRIB_BONEWEIGHT); }
70+ static inline void disableboneweight () { glDisableVertexAttribArray_ (ATTRIB_BONEWEIGHT); }
71+ static inline void boneweightpointer (int stride, const void *data, GLenum type = GL_UNSIGNED_BYTE, int size = 4 , GLenum normalized = GL_TRUE) { ; glVertexAttribPointer_ (ATTRIB_BONEWEIGHT, size, type, normalized, stride, data); }
72+
73+ static inline void enableboneindex () { ; glEnableVertexAttribArray_ (ATTRIB_BONEINDEX); }
74+ static inline void disableboneindex () { glDisableVertexAttribArray_ (ATTRIB_BONEINDEX); }
75+ static inline void boneindexpointer (int stride, const void *data, GLenum type = GL_UNSIGNED_BYTE, int size = 4 , GLenum normalized = GL_FALSE) { ; glVertexAttribPointer_ (ATTRIB_BONEINDEX, size, type, normalized, stride, data); }
8876
8977 static inline void bindebo (GLuint ebo) { disable (); glBindBuffer_ (GL_ELEMENT_ARRAY_BUFFER, ebo); }
9078 static inline void clearebo () { glBindBuffer_ (GL_ELEMENT_ARRAY_BUFFER, 0 ); }
@@ -137,38 +125,23 @@ namespace gle
137125 }
138126 }
139127
140- template <size_t N, class T >
141- static inline void attribv (const T *v)
142- {
143- attribbuf.put ((const uchar *)v, N*sizeof (T));
144- }
128+ static inline void attribf (float x, float y) { attrib<float >(x, y); }
129+ static inline void attribf (float x, float y, float z) { attrib<float >(x, y, z); }
130+ static inline void attribf (float x, float y, float z, float w) { attrib<float >(x, y, z, w); }
131+ static inline void attribs (short x, short y) { attrib<short >(x, y); }
132+ static inline void attribs (short x, short y, short z) { attrib<short >(x, y, z); }
133+ static inline void attribs (short x, short y, short z, short w) { attrib<short >(x, y, z, w); }
134+ static inline void attribus (ushort x, ushort y) { attrib<ushort>(x, y); }
135+ static inline void attribus (ushort x, ushort y, ushort z) { attrib<ushort>(x, y, z); }
136+ static inline void attribus (ushort x, ushort y, ushort z, ushort w) { attrib<ushort>(x, y, z, w); }
137+ static inline void attribi (int x, int y) { attrib<int >(x, y); }
138+ static inline void attribi (int x, int y, int z) { attrib<int >(x, y, z); }
139+ static inline void attribi (int x, int y, int z, int w) { attrib<int >(x, y, z, w); }
140+ static inline void attribui (uint x, uint y) { attrib<uint>(x, y); }
141+ static inline void attribui (uint x, uint y, uint z) { attrib<uint>(x, y, z); }
142+ static inline void attribui (uint x, uint y, uint z, uint w) { attrib<uint>(x, y, z, w); }
145143
146- #define GLE_ATTRIB (suffix, type ) \
147- static inline void attrib##suffix(type x) { attrib<type>(x); } \
148- static inline void attrib##suffix(type x, type y) { attrib<type>(x, y); } \
149- static inline void attrib##suffix(type x, type y, type z) { attrib<type>(x, y, z); } \
150- static inline void attrib##suffix(type x, type y, type z, type w) { attrib<type>(x, y, z, w); }
151-
152- GLE_ATTRIB (f, float )
153- GLE_ATTRIB (d, double )
154- GLE_ATTRIB (b, char )
155- GLE_ATTRIB (ub, uchar)
156- GLE_ATTRIB (s, short )
157- GLE_ATTRIB (us, ushort)
158- GLE_ATTRIB (i, int )
159- GLE_ATTRIB (ui, uint)
160-
161- static inline void attrib (const vec &v) { attribf (v.x , v.y , v.z ); }
162144 static inline void attrib (const vec &v, float w) { attribf (v.x , v.y , v.z , w); }
163- static inline void attrib (const vec2 &v) { attribf (v.x , v.y ); }
164- static inline void attrib (const vec4 &v) { attribf (v.x , v.y , v.z , v.w ); }
165- static inline void attrib (const ivec &v) { attribi (v.x , v.y , v.z ); }
166- static inline void attrib (const ivec &v, int w) { attribi (v.x , v.y , v.z , w); }
167- static inline void attrib (const ivec2 &v) { attribi (v.x , v.y ); }
168- static inline void attrib (const ivec4 &v) { attribi (v.x , v.y , v.z , v.w ); }
169- static inline void attrib (const bvec &b) { attribub (b.x , b.y , b.z ); }
170- static inline void attrib (const bvec &b, uchar w) { attribub (b.x , b.y , b.z , w); }
171- static inline void attrib (const bvec4 &b) { attribub (b.x , b.y , b.z , b.w ); }
172145
173146 extern int end ();
174147
0 commit comments