1 | #include <cmath> |
1 | #include <cmath> |
|
|
2 | |
|
|
3 | #include <GL/gl.h> |
|
|
4 | #include <GL/glext.h> |
2 | |
5 | |
3 | #include "oct.h" |
6 | #include "oct.h" |
4 | #include "view.h" |
7 | #include "view.h" |
5 | |
8 | |
6 | view::view () |
9 | view::view () |
… | |
… | |
65 | glTranslatef (-p.x, -p.y, -p.z); |
68 | glTranslatef (-p.x, -p.y, -p.z); |
66 | } |
69 | } |
67 | |
70 | |
68 | void view::begin () |
71 | void view::begin () |
69 | { |
72 | { |
|
|
73 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
74 | glDepthRange (0, 1. - (1. / pow (2., 16.))); |
|
|
75 | |
70 | vismap.clear (); |
76 | vismap.clear (); |
71 | vislist.clear (); |
77 | vislist.clear (); |
72 | |
78 | |
73 | generation++; |
79 | generation++; |
74 | |
80 | |
75 | reset_projection (); |
81 | reset_projection (); |
76 | |
82 | |
|
|
83 | for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i) |
|
|
84 | ; |
|
|
85 | farlist.clear (); |
|
|
86 | |
77 | // check occlusion queries here |
87 | // check occlusion queries here |
|
|
88 | #if 0 |
78 | for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i) |
89 | for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i) |
79 | //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query)); |
90 | //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query)); |
80 | occ_query_result ((*i)->occ_query); |
91 | occ_query_result ((*i)->occ_query); |
81 | |
92 | |
82 | checklist.clear (); |
93 | checklist.clear (); |
|
|
94 | #endif |
83 | |
95 | |
84 | world.detect_visibility (*this); |
96 | world.detect_visibility (*this); |
85 | } |
97 | } |
86 | |
98 | |
87 | void view::end () |
99 | void view::end () |
… | |
… | |
101 | glEnable (GL_POLYGON_OFFSET_FILL); |
113 | glEnable (GL_POLYGON_OFFSET_FILL); |
102 | glPolygonOffset (0, 1); |
114 | glPolygonOffset (0, 1); |
103 | glDepthFunc (GL_LESS); |
115 | glDepthFunc (GL_LESS); |
104 | glDisable (GL_LIGHTING); |
116 | glDisable (GL_LIGHTING); |
105 | glColorMask (0, 0, 0, 0); |
117 | glColorMask (0, 0, 0, 0); |
106 | //cgGLDisableProfile (vsh_profile); |
118 | cgGLEnableProfile (vsh_profile);// z-fighting?? |
107 | cgGLDisableProfile (fsh_profile); |
119 | cgGLDisableProfile (fsh_profile); |
108 | } |
120 | } |
109 | else |
121 | else |
110 | { |
122 | { |
111 | #if 0 |
|
|
112 | glEnable (GL_MINMAX); |
123 | glEnable (GL_MINMAX); |
113 | #endif |
|
|
114 | glDisable (GL_POLYGON_OFFSET_FILL); |
124 | glDisable (GL_POLYGON_OFFSET_FILL); |
115 | glDepthFunc (GL_LESS); |
125 | glDepthFunc (GL_LESS); |
116 | glDepthMask (0); |
126 | glDepthMask (0); |
117 | cgGLEnableProfile (vsh_profile); |
127 | cgGLEnableProfile (vsh_profile); |
118 | cgGLEnableProfile (fsh_profile); |
128 | cgGLEnableProfile (fsh_profile); |
… | |
… | |
121 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
131 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
122 | (*i)->display (*this); |
132 | (*i)->display (*this); |
123 | |
133 | |
124 | drawn.clear (); |
134 | drawn.clear (); |
125 | |
135 | |
|
|
136 | if (mode == view::LIGHTED) |
|
|
137 | { |
|
|
138 | glEnable (GL_DEPTH_CLAMP_NV); |
|
|
139 | glDepthFunc (GL_LESS); |
|
|
140 | glEnable (GL_COLOR_MATERIAL); |
|
|
141 | glDisable (GL_LIGHTING); |
|
|
142 | #if 1 |
|
|
143 | cgGLDisableProfile (vsh_profile); |
|
|
144 | cgGLDisableProfile (fsh_profile); |
|
|
145 | #endif |
|
|
146 | glShadeModel (GL_FLAT); |
|
|
147 | |
|
|
148 | static int count; count++; |
|
|
149 | if (farlist.size ()) |
|
|
150 | printf ("%d: size %d\n", count, farlist.size ()); |
|
|
151 | |
|
|
152 | for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i) |
|
|
153 | { |
|
|
154 | glColor3f (1 / (GLfloat)(i - farlist.begin()), 1, 1 / (GLfloat)(i - farlist.begin())); |
|
|
155 | (*i)->draw_bbox (*this); |
|
|
156 | } |
|
|
157 | |
|
|
158 | glEnable (GL_DEPTH_TEST); |
|
|
159 | glDisable (GL_DEPTH_CLAMP_NV); |
|
|
160 | glShadeModel (GL_SMOOTH); |
|
|
161 | } |
|
|
162 | |
126 | glColorMask (1, 1, 1, 0); |
163 | glColorMask (1, 1, 1, 0); |
127 | glDepthMask (1); |
164 | glDepthMask (1); |
|
|
165 | |
128 | } |
166 | } |
129 | |
167 | |
130 | |
168 | |