… | |
… | |
9 | #include "oct.h" |
9 | #include "oct.h" |
10 | #include "view.h" |
10 | #include "view.h" |
11 | #include "material.h" |
11 | #include "material.h" |
12 | |
12 | |
13 | using namespace std; |
13 | using namespace std; |
|
|
14 | using namespace gl; |
14 | |
15 | |
15 | struct geometry |
16 | struct geometry |
16 | { |
17 | { |
17 | geometry *parent; |
18 | geometry *parent; |
18 | box bbox; |
19 | box bbox; |
… | |
… | |
26 | virtual void draw (view &ctx) = 0; |
27 | virtual void draw (view &ctx) = 0; |
27 | geometry (geometry *parent = 0) : parent(parent) { }; |
28 | geometry (geometry *parent = 0) : parent(parent) { }; |
28 | virtual ~geometry (); |
29 | virtual ~geometry (); |
29 | }; |
30 | }; |
30 | |
31 | |
31 | struct vertex1d |
|
|
32 | { |
|
|
33 | colour c; // colour |
|
|
34 | point p; // vertex |
|
|
35 | }; |
|
|
36 | |
|
|
37 | struct vertex2d |
|
|
38 | { |
|
|
39 | point p; // vertex |
|
|
40 | vec3 n; // normal |
|
|
41 | texc t; // texture |
|
|
42 | |
|
|
43 | vertex2d () { }; |
|
|
44 | vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
|
|
45 | }; |
|
|
46 | |
|
|
47 | struct geometry_opengl : geometry |
32 | struct geometry_opengl : geometry |
48 | { |
33 | { |
49 | GLuint list; // TODO: dynamic caching |
34 | GLuint list; // TODO: dynamic caching |
50 | |
35 | |
51 | geometry_opengl (); |
36 | geometry_opengl (); |
52 | ~geometry_opengl (); |
37 | ~geometry_opengl (); |
53 | }; |
38 | }; |
54 | |
39 | |
55 | template<GLenum type> |
40 | template<GLenum type> |
56 | struct geometry_opengl1d : geometry_opengl, vector<vertex1d> |
41 | struct geometry_opengl1d : geometry_opengl, vector<vertex_v3f> |
57 | { |
42 | { |
58 | void set (const vector<vertex1d> &v); |
43 | void set (const vector<vertex_v3f> &v); |
59 | void draw (view &ctx); |
44 | void draw (view &ctx); |
60 | }; |
45 | }; |
61 | |
46 | |
62 | template<GLenum type> |
47 | template<GLenum type> |
63 | struct geometry_opengl2d : geometry_opengl |
48 | struct geometry_opengl2d : geometry_opengl |
64 | { |
49 | { |
65 | material *m; |
50 | material *m; |
66 | |
51 | |
67 | geometry_opengl2d () : m(0) { }; |
52 | geometry_opengl2d () : m(0) { }; |
68 | |
53 | |
69 | void set (const vector<vertex2d> &v); |
54 | void set (const vector<vertex_t2f_n3f_v3f> &v); |
70 | void draw (view &ctx); |
55 | void draw (view &ctx); |
71 | }; |
56 | }; |
72 | |
57 | |
73 | typedef geometry_opengl1d<GL_POINTS> geometry_points; |
58 | typedef geometry_opengl1d<GL_POINTS> geometry_points; |
74 | typedef geometry_opengl1d<GL_LINES> geometry_lines; |
59 | typedef geometry_opengl1d<GL_LINES> geometry_lines; |
… | |
… | |
79 | typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan; |
64 | typedef geometry_opengl2d<GL_TRIANGLE_FAN> geometry_triangle_fan; |
80 | typedef geometry_opengl2d<GL_QUADS> geometry_quads; |
65 | typedef geometry_opengl2d<GL_QUADS> geometry_quads; |
81 | typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip; |
66 | typedef geometry_opengl2d<GL_QUAD_STRIP> geometry_quad_strip; |
82 | typedef geometry_opengl2d<GL_POLYGON> geometry_polygon; |
67 | typedef geometry_opengl2d<GL_POLYGON> geometry_polygon; |
83 | |
68 | |
84 | struct geometry_nurbs : geometry, vector<vertex2d> |
69 | struct geometry_nurbs : geometry, vector<vertex_t2f_n3f_v3f> |
85 | { |
70 | { |
86 | GLUnurbsObj *nurb; |
71 | GLUnurbsObj *nurb; |
87 | GLUtesselator *tess; |
72 | GLUtesselator *tess; |
88 | GLfloat ctlpoints[4][4][3]; |
73 | GLfloat ctlpoints[4][4][3]; |
89 | |
74 | |