ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
(Generate patch)

Comparing libgender/view.C (file contents):
Revision 1.4 by root, Mon Oct 4 07:04:58 2004 UTC vs.
Revision 1.36 by root, Sat Oct 9 02:08:29 2004 UTC

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
6draw_context::draw_context (view &v) 9 static GLenum gl_error;
7: v(v), l(0), mode(LIGHTED) 10view::view ()
11: gamma(1.0)
8{ 12{
9} 13}
10 14
11draw_context::~draw_context () 15view::~view ()
12{ 16{
13} 17}
14 18
15bool draw_context::may_draw (entity_base *e) 19bool view::may_draw (const entity *e)
16{ 20{
17 if (drawn.find (e) != drawn.end ()) 21 if (drawn.find (e) != drawn.end ())
18 return false; 22 return false;
19 23
20 drawn.insert (e); 24 drawn.insert (e);
21 return true; 25 return true;
22} 26}
23 27
24void view::draw (draw_context &ctx) 28void view::reset_projection ()
25{ 29{
30 renormalize (orig, p);
31
32 glViewport (0, 0, w, h);
33
34 glMatrixMode (GL_PROJECTION);
35 glLoadIdentity ();
36
37 gl_error = glGetError ();
38 GLdouble aspect = (GLdouble)w/h;
39 GLdouble zNear = 1.;
40 GLdouble zFar = 500.;
41
42 gl_error = glGetError ();
43 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
44 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
45
46 gl_error = glGetError ();
47 d = normalize (d);//D
48 u = normalize (u);//D
49 vec3 rz = -d;
50 vec3 rx = cross (u, rz);
51 vec3 ry = cross (rz, rx);
52 gl_error = glGetError ();
53
54 matrix &m = projection;
55 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
56 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
57 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
58 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
59 gl_error = glGetError ();
60
61 glMultMatrixf ((GLfloat *)m.data);
62
63 gl_error = glGetError ();
64 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
65
66 gl_error = glGetError ();
67 frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) );
68 frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) );
69 frustum.b = plane ( m(3,0) + m(1,0), m(3,1) + m(1,1), m(3,2) + m(1,2), m(3,3) + m(1,3) );
70 frustum.t = plane ( m(3,0) - m(1,0), m(3,1) - m(1,1), m(3,2) - m(1,2), m(3,3) - m(1,3) );
71 frustum.n = plane ( m(3,0) + m(2,0), m(3,1) + m(2,1), m(3,2) + m(2,2), m(3,3) + m(2,3) );
72 frustum.f = plane ( m(3,0) - m(2,0), m(3,1) - m(2,1), m(3,2) - m(2,2), m(3,3) - m(2,3) );
73
74 gl_error = glGetError ();
75 glMatrixMode (GL_MODELVIEW);
76 glLoadIdentity ();
77 glTranslatef (-p.x, -p.y, -p.z);
78 gl_error = glGetError ();
79}
80
81void view::begin ()
82{
83 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84 glDepthRange (0, 1. - (1. / pow (2., 16.)));
85
86 vismap.clear ();
87 vislist.clear ();
88
89 generation++;
90
91 reset_projection ();
92
93 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
94 ;
95
96 farlist.clear ();
97
26 // check occlusion queries here 98 // check occlusion queries here
99#if 0
100 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
101 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
102 occ_query_result ((*i)->occ_query);
27 103
28 ctx.generation++; 104 checklist.clear ();
105#endif
29 106
30 //renormalize (orig, p); 107 world.detect_visibility (*this);
108}
31 109
32 if (ctx.mode == draw_context::DEPTH) 110void view::end ()
111{
112 vismap.clear ();
113}
114
115void view::pass (enum mode m)
116{
117 mode = m;
118
119 glDisable (GL_ALPHA_TEST);
120 glDisable (GL_BLEND);
121
122 if (mode == view::DEPTH)
33 { 123 {
34 glEnable (GL_POLYGON_OFFSET_FILL); 124 glEnable (GL_POLYGON_OFFSET_FILL);
35 glPolygonOffset (0, 1); 125 glPolygonOffset (0, 1);
36 glDepthFunc (GL_LESS); 126 glDepthFunc (GL_LESS);
37 glDisable (GL_LIGHTING); 127 glDisable (GL_LIGHTING);
38 glColorMask (0, 0, 0, 0); 128 glColorMask (0, 0, 0, 0);
129 cgGLEnableProfile (vsh_profile);// z-fighting??
130 cgGLDisableProfile (fsh_profile);
39 } 131 }
40 else 132 else
41 { 133 {
134 glEnable (GL_MINMAX);
42 glDisable (GL_POLYGON_OFFSET_FILL); 135 glDisable (GL_POLYGON_OFFSET_FILL);
43 glDrawBuffer (GL_BACK);
44 glDepthFunc (GL_LEQUAL); 136 glDepthFunc (GL_LESS);
45 glEnable (GL_LIGHTING);
46 glDepthMask (0); 137 glDepthMask (0);
138 cgGLEnableProfile (vsh_profile);
139 cgGLEnableProfile (fsh_profile);
47 } 140 }
48 141
49 glViewport (0, 0, w, h); 142 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
143 (*i)->display (*this);
50 144
51 glMatrixMode (GL_PROJECTION); 145 drawn.clear ();
52 glLoadIdentity ();
53 146
54 GLdouble aspect = (GLdouble)w/h; 147 if (mode == view::DEPTH || 1)
55 GLdouble zNear = 0.001; 148 {
56 GLdouble zFar = 100.; 149 glEnable (GL_DEPTH_CLAMP_NV);
150 glDepthFunc (GL_LESS);
151 if (1) glDepthFunc (GL_LEQUAL);
152 glEnable (GL_COLOR_MATERIAL);
153 glDisable (GL_LIGHTING);
154 cgGLDisableProfile (vsh_profile);
155 cgGLDisableProfile (fsh_profile);
156 glShadeModel (GL_FLAT);
57 157
58 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0)); 158#if 0
59 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar); 159 static int count; count++;
160 if (farlist.size ())
161 printf ("%d: size %d\n", count, farlist.size ());
162#endif
60 163
61 vec3 rz = -d; 164 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
62 vec3 rx = cross (u, rz); 165 {
63 vec3 ry = cross (rz, rx); 166 glColor3f (1,0,0);
167 (*i)->draw_bbox (*this);
168 }
64 169
65 gl_matrix &m = ctx.projection; 170 glEnable (GL_DEPTH_TEST);
66 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0; 171 glDisable (GL_DEPTH_CLAMP_NV);
67 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0; 172 glShadeModel (GL_SMOOTH);
68 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0; 173 }
69 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
70
71 glMultMatrixf ((GLfloat *)m.data);
72
73 glMatrixMode (GL_MODELVIEW);
74 glLoadIdentity ();
75 glTranslatef (-p.x, -p.y, -p.z);
76
77 world.draw (ctx);
78
79 ctx.drawn.clear ();
80 174
81 glColorMask (1, 1, 1, 0); 175 glColorMask (1, 1, 1, 0);
82 glDepthMask (1); 176 glDepthMask (1);
177
83} 178}
84 179
180

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines