summaryrefslogtreecommitdiff
path: root/src/shared/glemu.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/glemu.h')
-rw-r--r--src/shared/glemu.h54
1 files changed, 11 insertions, 43 deletions
diff --git a/src/shared/glemu.h b/src/shared/glemu.h
index e4f4d26..be4ea9f 100644
--- a/src/shared/glemu.h
+++ b/src/shared/glemu.h
@@ -1,7 +1,5 @@
-namespace gle
-{
- enum
- {
+namespace gle {
+ enum {
ATTRIB_VERTEX = 0,
ATTRIB_COLOR = 1,
ATTRIB_TEXCOORD0 = 2,
@@ -12,22 +10,17 @@ namespace gle
ATTRIB_BONEINDEX = 7,
MAXATTRIBS = 8
};
-
extern const char * const attribnames[MAXATTRIBS];
extern ucharbuf attribbuf;
-
extern int enabled;
extern void forcedisable();
static inline void disable() { if(enabled) forcedisable(); }
-
extern void begin(GLenum mode);
extern void begin(GLenum mode, int numverts);
extern void defattribs(const char *fmt);
extern void defattrib(int type, int size, int format);
-
#define GLE_DEFATTRIB(name, type, defaultsize, defaultformat) \
static inline void def##name(int size = defaultsize, int format = defaultformat) { defattrib(type, size, format); }
-
GLE_DEFATTRIB(vertex, ATTRIB_VERTEX, 3, GL_FLOAT)
GLE_DEFATTRIB(color, ATTRIB_COLOR, 3, GL_FLOAT)
GLE_DEFATTRIB(texcoord0, ATTRIB_TEXCOORD0, 2, GL_FLOAT)
@@ -36,7 +29,6 @@ namespace gle
GLE_DEFATTRIB(tangent, ATTRIB_TANGENT, 4, GL_FLOAT)
GLE_DEFATTRIB(boneweight, ATTRIB_BONEWEIGHT, 4, GL_UNSIGNED_BYTE)
GLE_DEFATTRIB(boneindex, ATTRIB_BONEINDEX, 4, GL_UNSIGNED_BYTE)
-
#define GLE_INITATTRIB(name, index, suffix, type) \
static inline void name##suffix(type x) { glVertexAttrib1##suffix##_(index, x); } \
static inline void name##suffix(type x, type y) { glVertexAttrib2##suffix##_(index, x, y); } \
@@ -50,7 +42,6 @@ namespace gle
static inline void name(const vec4 &v) { glVertexAttrib4fv_(index, v.v); }
#define GLE_INITATTRIBN(name, index, suffix, type, defaultw) \
static inline void name##suffix(type x, type y, type z, type w = defaultw) { glVertexAttrib4N##suffix##_(index, x, y, z, w); }
-
GLE_INITATTRIBF(vertex, ATTRIB_VERTEX)
GLE_INITATTRIBF(color, ATTRIB_COLOR)
static inline void color(const bvec4 &v) { glVertexAttrib4Nubv_(ATTRIB_COLOR, v.v); }
@@ -63,7 +54,6 @@ namespace gle
static inline void tangent(float x, float y, float z, float w = 1.0f) { glVertexAttrib4f_(ATTRIB_TANGENT, x, y, z, w); }
static inline void tangent(const vec &v, float w = 1.0f) { glVertexAttrib4f_(ATTRIB_TANGENT, v.x, v.y, v.z, w); }
static inline void tangent(const vec4 &v) { glVertexAttrib4fv_(ATTRIB_TANGENT, v.v); }
-
#define GLE_ATTRIBPOINTER(name, index, defaultnormalized, defaultsize, defaulttype, prepare) \
static inline void enable##name() { prepare; glEnableVertexAttribArray_(index); } \
static inline void disable##name() { glDisableVertexAttribArray_(index); } \
@@ -71,7 +61,6 @@ namespace gle
prepare; \
glVertexAttribPointer_(index, size, type, normalized, stride, data); \
}
-
static inline void enableattrib(int index) { disable(); glEnableVertexAttribArray_(index); }
static inline void disableattrib(int index) { glDisableVertexAttribArray_(index); }
GLE_ATTRIBPOINTER(vertex, ATTRIB_VERTEX, GL_FALSE, 3, GL_FLOAT, disable())
@@ -82,50 +71,37 @@ namespace gle
GLE_ATTRIBPOINTER(tangent, ATTRIB_TANGENT, GL_TRUE, 4, GL_FLOAT, )
GLE_ATTRIBPOINTER(boneweight, ATTRIB_BONEWEIGHT, GL_TRUE, 4, GL_UNSIGNED_BYTE, )
GLE_ATTRIBPOINTER(boneindex, ATTRIB_BONEINDEX, GL_FALSE, 4, GL_UNSIGNED_BYTE, )
-
static inline void bindebo(GLuint ebo) { disable(); glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, ebo); }
static inline void clearebo() { glBindBuffer_(GL_ELEMENT_ARRAY_BUFFER, 0); }
static inline void bindvbo(GLuint vbo) { disable(); glBindBuffer_(GL_ARRAY_BUFFER, vbo); }
static inline void clearvbo() { glBindBuffer_(GL_ARRAY_BUFFER, 0); }
-
template<class T>
- static inline void attrib(T x)
- {
- if(attribbuf.check(sizeof(T)))
- {
+ static inline void attrib(T x) {
+ if(attribbuf.check(sizeof(T))) {
T *buf = (T *)attribbuf.pad(sizeof(T));
buf[0] = x;
}
}
-
template<class T>
- static inline void attrib(T x, T y)
- {
- if(attribbuf.check(2*sizeof(T)))
- {
+ static inline void attrib(T x, T y) {
+ if(attribbuf.check(2*sizeof(T))) {
T *buf = (T *)attribbuf.pad(2*sizeof(T));
buf[0] = x;
buf[1] = y;
}
}
-
template<class T>
- static inline void attrib(T x, T y, T z)
- {
- if(attribbuf.check(3*sizeof(T)))
- {
+ static inline void attrib(T x, T y, T z) {
+ if(attribbuf.check(3*sizeof(T))) {
T *buf = (T *)attribbuf.pad(3*sizeof(T));
buf[0] = x;
buf[1] = y;
buf[2] = z;
}
}
-
template<class T>
- static inline void attrib(T x, T y, T z, T w)
- {
- if(attribbuf.check(4*sizeof(T)))
- {
+ static inline void attrib(T x, T y, T z, T w) {
+ if(attribbuf.check(4*sizeof(T))) {
T *buf = (T *)attribbuf.pad(4*sizeof(T));
buf[0] = x;
buf[1] = y;
@@ -133,19 +109,15 @@ namespace gle
buf[3] = w;
}
}
-
template<size_t N, class T>
- static inline void attribv(const T *v)
- {
+ static inline void attribv(const T *v) {
attribbuf.put((const uchar *)v, N*sizeof(T));
}
-
#define GLE_ATTRIB(suffix, type) \
static inline void attrib##suffix(type x) { attrib<type>(x); } \
static inline void attrib##suffix(type x, type y) { attrib<type>(x, y); } \
static inline void attrib##suffix(type x, type y, type z) { attrib<type>(x, y, z); } \
static inline void attrib##suffix(type x, type y, type z, type w) { attrib<type>(x, y, z, w); }
-
GLE_ATTRIB(f, float)
GLE_ATTRIB(d, double)
GLE_ATTRIB(b, char)
@@ -154,7 +126,6 @@ namespace gle
GLE_ATTRIB(us, ushort)
GLE_ATTRIB(i, int)
GLE_ATTRIB(ui, uint)
-
static inline void attrib(const vec &v) { attribf(v.x, v.y, v.z); }
static inline void attrib(const vec &v, float w) { attribf(v.x, v.y, v.z, w); }
static inline void attrib(const vec2 &v) { attribf(v.x, v.y); }
@@ -166,14 +137,11 @@ namespace gle
static inline void attrib(const bvec &b) { attribub(b.x, b.y, b.z); }
static inline void attrib(const bvec &b, uchar w) { attribub(b.x, b.y, b.z, w); }
static inline void attrib(const bvec4 &b) { attribub(b.x, b.y, b.z, b.w); }
-
extern void multidraw();
extern int end();
-
extern void enablequads();
extern void disablequads();
extern void drawquads(int offset, int count);
-
extern void setup();
extern void cleanup();
}