rev |
line source |
nuclear@1
|
1 #include "opengl.h"
|
nuclear@1
|
2 #include "geom.h"
|
nuclear@1
|
3
|
nuclear@1
|
4 #ifdef SINGLE_PRECISION_MATH
|
nuclear@1
|
5 #define ELEM_TYPE GL_FLOAT
|
nuclear@1
|
6 #else
|
nuclear@1
|
7 #define ELEM_TYPE GL_DOUBLE
|
nuclear@1
|
8 #endif
|
nuclear@1
|
9
|
nuclear@3
|
10 void draw_mesh(unsigned int prim, int num_verts, const Vertex *vbuf, const unsigned int *ibuf, int attr_tang_loc)
|
nuclear@1
|
11 {
|
nuclear@1
|
12 glEnableClientState(GL_VERTEX_ARRAY);
|
nuclear@1
|
13 glVertexPointer(3, ELEM_TYPE, sizeof *vbuf, &vbuf->pos);
|
nuclear@1
|
14
|
nuclear@1
|
15 glEnableClientState(GL_NORMAL_ARRAY);
|
nuclear@1
|
16 glNormalPointer(ELEM_TYPE, sizeof *vbuf, &vbuf->norm);
|
nuclear@1
|
17
|
nuclear@1
|
18 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
nuclear@1
|
19 glTexCoordPointer(2, ELEM_TYPE, sizeof *vbuf, &vbuf->tc);
|
nuclear@1
|
20
|
nuclear@3
|
21 if(attr_tang_loc >= 0) {
|
nuclear@3
|
22 glEnableVertexAttribArrayARB(attr_tang_loc);
|
nuclear@3
|
23 glVertexAttribPointerARB(attr_tang_loc, 3, ELEM_TYPE, GL_FALSE, sizeof *vbuf, &vbuf->tang);
|
nuclear@3
|
24 }
|
nuclear@3
|
25
|
nuclear@1
|
26 if(ibuf) {
|
nuclear@1
|
27 glDrawElements(prim, num_verts, GL_UNSIGNED_INT, ibuf);
|
nuclear@1
|
28 } else {
|
nuclear@1
|
29 glDrawArrays(prim, 0, num_verts);
|
nuclear@1
|
30 }
|
nuclear@1
|
31
|
nuclear@1
|
32 glDisableClientState(GL_VERTEX_ARRAY);
|
nuclear@1
|
33 glDisableClientState(GL_NORMAL_ARRAY);
|
nuclear@1
|
34 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
nuclear@3
|
35
|
nuclear@3
|
36 if(attr_tang_loc >= 0) {
|
nuclear@3
|
37 glDisableVertexAttribArrayARB(attr_tang_loc);
|
nuclear@3
|
38 }
|
nuclear@1
|
39 #if 0
|
nuclear@1
|
40 glBegin(GL_QUADS);
|
nuclear@1
|
41 for(int i=0; i<count; i++) {
|
nuclear@1
|
42 for(int j=0; j<4; j++) {
|
nuclear@1
|
43 const Vertex *v = vbuf + ibuf[i * 4 + j];
|
nuclear@1
|
44 glNormal3f(v->norm.x, v->norm.y, v->norm.z);
|
nuclear@1
|
45 glVertex3f(v->pos.x, v->pos.y, v->pos.z);
|
nuclear@1
|
46 }
|
nuclear@1
|
47 }
|
nuclear@1
|
48 glEnd();
|
nuclear@1
|
49 #endif
|
nuclear@1
|
50 }
|