[svn] / trunk / src / examples / eqPly / channel.cpp Repository:
ViewVC logotype

Annotation of /trunk/src/examples/eqPly/channel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1157 - (view) (download) (as text)

1 : eile 194
2 : eile 774 /* Copyright (c) 2006-2007, Stefan Eilemann <eile@equalizergraphics.com>
3 : eile 194 All rights reserved. */
4 :    
5 :     #include "channel.h"
6 : eile 231
7 : eile 194 #include "frameData.h"
8 : eile 203 #include "initData.h"
9 : eile 231 #include "node.h"
10 : eile 566 #include "pipe.h"
11 : eile 1044 #include "window.h"
12 : eile 194
13 : eile 1044 using namespace eqBase;
14 : eile 194 using namespace std;
15 :    
16 : eile 774 static float lightpos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
17 : eile 240
18 : eile 673 //#define DYNAMIC_NEAR_FAR
19 : eile 583 #ifndef M_SQRT3
20 :     # define M_SQRT3 1.7321f /* sqrt(3) */
21 :     #endif
22 :     #ifndef M_SQRT3_2
23 :     # define M_SQRT3_2 0.86603f /* sqrt(3)/2 */
24 :     #endif
25 :    
26 : eile 1044 namespace eqPly
27 :     {
28 : eile 836 bool Channel::configInit( const uint32_t initID )
29 : eile 194 {
30 : eile 205 EQINFO << "Init channel initID " << initID << " ptr " << this << endl;
31 : eile 203
32 : eile 673 #ifndef DYNAMIC_NEAR_FAR
33 :     setNearFar( 0.0001f, 10.0f );
34 :     #endif
35 : eile 194 return true;
36 :     }
37 :    
38 : eile 839 void Channel::frameDraw( const uint32_t frameID )
39 : eile 194 {
40 : eile 804 vmml::FrustumCullerf culler;
41 :     _initFrustum( culler );
42 : eile 609
43 : eile 194 applyBuffer();
44 :     applyViewport();
45 :    
46 :     glMatrixMode( GL_PROJECTION );
47 :     glLoadIdentity();
48 : eile 582
49 : eile 584 applyFrustum();
50 :    
51 : eile 194 glMatrixMode( GL_MODELVIEW );
52 :     glLoadIdentity();
53 :     applyHeadTransform();
54 : dustin82 396
55 : eile 240 glLightfv( GL_LIGHT0, GL_POSITION, lightpos );
56 :    
57 : eile 776 const Pipe* pipe = static_cast<Pipe*>( getPipe( ));
58 :     const FrameData& frameData = pipe->getFrameData();
59 : eile 231
60 : eile 783 glTranslatef( frameData.data.translation.x,
61 :     frameData.data.translation.y,
62 :     frameData.data.translation.z );
63 :     glMultMatrixf( frameData.data.rotation.ml );
64 : eile 776
65 : eile 636 Node* node = (Node*)getNode();
66 :     const Model* model = node->getModel();
67 :     const eq::Range& range = getRange();
68 : eile 231
69 : eile 783 if( !frameData.data.color )
70 : eile 636 {
71 : eile 783 glColor3f( 1.0f, 1.0f, 1.0f );
72 :     }
73 :     else if( !range.isFull( )) // Color DB-patches
74 :     {
75 : eile 1093 const vmml::Vector3ub color = getUniqueColor();
76 :     glColor3ub( color.r, color.g, color.b );
77 : eile 636 }
78 : eile 635
79 : eile 231 if( model )
80 :     {
81 : eile 636 vector<const Model::BBox*> candidates;
82 : eile 641 candidates.push_back( model->getBBox( ));
83 : eile 608
84 : eile 636 while( !candidates.empty( ) )
85 : eile 490 {
86 : eile 636 const Model::BBox *bbox = candidates.back();
87 :     candidates.pop_back();
88 : eile 490
89 : eile 586 // cull against 'completely out of range'
90 :     if( bbox->range[0] >= range.end || bbox->range[1] < range.start )
91 :     continue;
92 :    
93 : eile 804 const vmml::Visibility visibility = culler.testSphere(
94 :     bbox->cullSphere );
95 : eile 608
96 : eile 490 switch( visibility )
97 :     {
98 : eile 804 case vmml::VISIBILITY_FULL:
99 : eile 586 {
100 :     const bool fullyInRange = (bbox->range[0] >= range.start &&
101 :     bbox->range[1] < range.end );
102 :     if( fullyInRange )
103 :     {
104 : eile 608 model->traverseBBox( bbox, 0, _drawBBoxCB, 0, this );
105 : eile 586 break;
106 :     }
107 :     // partial range, fall through
108 :     }
109 : eile 804 case vmml::VISIBILITY_PARTIAL:
110 : eile 586 if( !bbox->children )
111 : eile 635 {
112 :     if( bbox->range[0] >= range.start )
113 :     model->traverseBBox( bbox, 0, _drawBBoxCB, 0, this);
114 : eile 669 // else drop, to be drawn by 'previous' channel
115 : eile 635 }
116 : eile 490 else
117 :     for( int i=0; i<8; i++ )
118 : eile 636 candidates.push_back( &bbox->children[i] );
119 : eile 490 break;
120 : eile 804 case vmml::VISIBILITY_NONE:
121 : eile 490 break;
122 :     }
123 :     }
124 : eile 231 }
125 :     else
126 :     {
127 : eile 532 glColor3f( 1.f, 1.f, 0.f );
128 :     glNormal3f( 0.f, -1.f, 0.f );
129 : eile 231 glBegin( GL_TRIANGLE_STRIP );
130 : eile 532 glVertex3f( .25f, 0.f, .25f );
131 :     glVertex3f( .25f, 0.f, -.25f );
132 :     glVertex3f( -.25f, 0.f, .25f );
133 :     glVertex3f( -.25f, 0.f, -.25f );
134 : eile 231 glEnd();
135 :     }
136 : eile 1134 _drawLogo();
137 : eile 231 }
138 :    
139 : eile 608 void Channel::_drawBBoxCB( Model::BBox *bbox, void *userData )
140 :     {
141 :     Channel* channel = static_cast<Channel*>( userData );
142 :     channel->_drawBBox( bbox );
143 :     }
144 :    
145 : eile 231 void Channel::_drawBBox( const Model::BBox *bbox )
146 :     {
147 : eile 1141 Window* window = static_cast<Window*>( getWindow( ));
148 :     GLuint displayList = window->getDisplayList( bbox );
149 : eile 566
150 : eile 1044 if( displayList )
151 : eile 566 {
152 :     glCallList( displayList );
153 :     return;
154 :     }
155 :    
156 : eile 1044 displayList = window->newDisplayList( bbox );
157 : eile 566 EQASSERT( displayList );
158 :    
159 : eile 1044 Pipe* pipe = static_cast<Pipe*>( getPipe( ));
160 :     const FrameData& frameData = pipe->getFrameData();
161 :     const size_t nFaces = bbox->nFaces;
162 :     const eq::Range& range = getRange();
163 :     const bool color = frameData.data.color && range.isFull();
164 : eile 636
165 : eile 566 glNewList( displayList, GL_COMPILE );
166 : eile 637 glBegin( GL_TRIANGLES );
167 :    
168 :     if( color )
169 :     for( size_t i=0; i<nFaces; ++i )
170 :     {
171 :     const NormalFace<ColorVertex> &face = bbox->faces[i];
172 :    
173 : eile 636 glColor3fv( face.vertices[0].color );
174 : eile 637 glNormal3fv( face.normal );
175 :     glVertex3fv( face.vertices[0].pos );
176 :    
177 : eile 636 glColor3fv( face.vertices[1].color );
178 : eile 637 glNormal3fv( face.normal );
179 :     glVertex3fv( face.vertices[1].pos );
180 :    
181 : eile 636 glColor3fv( face.vertices[2].color );
182 : eile 637 glNormal3fv( face.normal );
183 :     glVertex3fv( face.vertices[2].pos );
184 :     }
185 :     else
186 :     for( size_t i=0; i<nFaces; ++i )
187 :     {
188 :     const NormalFace<ColorVertex> &face = bbox->faces[i];
189 :    
190 :     glNormal3fv( face.normal );
191 :     glVertex3fv( face.vertices[0].pos );
192 :    
193 :     glNormal3fv( face.normal );
194 :     glVertex3fv( face.vertices[1].pos );
195 :    
196 :     glNormal3fv( face.normal );
197 :     glVertex3fv( face.vertices[2].pos );
198 :     }
199 :    
200 : eile 194 glEnd();
201 : eile 566
202 : eile 1141 glEndList();
203 : eile 566 glCallList( displayList );
204 : eile 194 }
205 :    
206 : eile 1134 void Channel::_drawLogo()
207 :     {
208 : eile 1141 const Window* window = static_cast<Window*>( getWindow( ));
209 : eile 1134 GLuint texture;
210 :     vmml::Vector2i size;
211 :    
212 :     window->getLogoTexture( texture, size );
213 :     if( !texture )
214 :     return;
215 :    
216 : eile 1141 const eq::PixelViewport pvp = getPixelViewport();
217 :     const vmml::Vector2i offset = getPixelOffset();
218 :    
219 : eile 1134 glMatrixMode( GL_PROJECTION );
220 :     glLoadIdentity();
221 : eile 1141 glOrtho( offset.x, offset.x + pvp.w, offset.y, offset.y + pvp.h, 0., 1. );
222 : eile 1134
223 :     glMatrixMode( GL_MODELVIEW );
224 :     glLoadIdentity();
225 :    
226 :     glDisable( GL_DEPTH_TEST );
227 :     glDisable( GL_LIGHTING );
228 :     glEnable( GL_BLEND );
229 :     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
230 :    
231 : eile 1157 glEnable( GL_TEXTURE_RECTANGLE_ARB );
232 :     glBindTexture( GL_TEXTURE_RECTANGLE_ARB, texture );
233 :     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
234 :     GL_LINEAR );
235 :     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
236 :     GL_LINEAR );
237 : eile 1134
238 :     glColor3f( 1.0f, 1.0f, 1.0f );
239 :     glBegin( GL_TRIANGLE_STRIP ); {
240 :     glTexCoord2f( 0.0f, 0.0f );
241 :     glVertex3f( 0.0f, 0.0f, 0.0f );
242 :    
243 :     glTexCoord2f( size.x, 0.0f );
244 :     glVertex3f( size.x, 0.0f, 0.0f );
245 :    
246 :     glTexCoord2f( 0.0f, size.y );
247 :     glVertex3f( 0.0f, size.y, 0.0f );
248 :    
249 :     glTexCoord2f( size.x, size.y );
250 :     glVertex3f( size.x, size.y, 0.0f );
251 :     } glEnd();
252 :    
253 : eile 1157 glDisable( GL_TEXTURE_RECTANGLE_ARB );
254 : eile 1134 glDisable( GL_BLEND );
255 :     glEnable( GL_LIGHTING );
256 :     glEnable( GL_DEPTH_TEST );
257 :     }
258 :    
259 : eile 804 void Channel::_initFrustum( vmml::FrustumCullerf& culler )
260 : eile 490 {
261 : eile 776 const Pipe* pipe = static_cast<Pipe*>( getPipe( ));
262 :     const FrameData& frameData = pipe->getFrameData();
263 : eile 609
264 : eile 783 vmml::Matrix4f view( frameData.data.rotation );
265 :     view.setTranslation( frameData.data.translation );
266 : eile 776
267 : eile 804 const vmml::Frustumf& frustum = getFrustum();
268 : eile 673 const vmml::Matrix4f& headTransform = getHeadTransform();
269 :     const vmml::Matrix4f modelView = headTransform * view;
270 : eile 609
271 : eile 673 #ifdef DYNAMIC_NEAR_FAR
272 :     vmml::Matrix4f modelInv;
273 :     headTransform.getInverse( modelInv );
274 : eile 669
275 : eile 673 const vmml::Vector3f zero = modelInv * vmml::Vector3f( 0.0f, 0.0f, 0.0f );
276 :     vmml::Vector3f front = modelInv * vmml::Vector3f( 0.0f, 0.0f, -1.0f );
277 :     front -= zero;
278 :     front.normalise();
279 :     EQINFO << getName() << " front " << front << endl;
280 :     front.scale( M_SQRT3_2 ); // bounding sphere size of unit-sized cube
281 :    
282 : eile 783 const vmml::Vector3f center( frameData.data.translation );
283 : eile 673 const vmml::Vector3f near = headTransform * ( center - front );
284 :     const vmml::Vector3f far = headTransform * ( center + front );
285 :     const float zNear = MAX( 0.0001f, -near.z );
286 :     const float zFar = MAX( 0.0002f, -far.z );
287 :    
288 :     EQINFO << getName() << " center: " << headTransform * center << endl;
289 :     EQINFO << getName() << " near, far: " << near << " " << far << endl;
290 :     EQINFO << getName() << " near, far: " << zNear << " " << zFar << endl;
291 :     setNearFar( zNear, zFar );
292 : eile 609 #endif
293 :    
294 : eile 804 const vmml::Matrix4f projection = frustum.computeMatrix();
295 :     //const eq::PixelViewport& pvp = getPixelViewport();
296 : eile 490
297 : eile 804 culler.setup( projection * modelView );
298 : eile 490 }
299 : eile 1044 }

Back to Equalizer website
ViewVC Help
Powered by ViewVC 1.0.3