1 | #include "Mesh.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "OcclusionQuery.h"
|
---|
4 | #include "QtGlRenderer.h"
|
---|
5 | #include "ViewCellsManager.h"
|
---|
6 | #include "SceneGraph.h"
|
---|
7 | #include "Pvs.h"
|
---|
8 | #include "Viewcell.h"
|
---|
9 | #include "Beam.h"
|
---|
10 | #include "KdTree.h"
|
---|
11 | #include "Environment.h"
|
---|
12 | #include "RssPreprocessor.h"
|
---|
13 | #include "RssTree.h"
|
---|
14 | #include "Trackball.h"
|
---|
15 | #include "QtPreprocessorThread.h"
|
---|
16 | #include "Material.h"
|
---|
17 | #include "IntersectableWrapper.h"
|
---|
18 |
|
---|
19 |
|
---|
20 | #define USE_CG 1
|
---|
21 |
|
---|
22 |
|
---|
23 | #if USE_CG
|
---|
24 | #include <Cg/cg.h>
|
---|
25 | #include <Cg/cgGL.h>
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | #include <QVBoxLayout>
|
---|
29 |
|
---|
30 | namespace GtpVisibilityPreprocessor {
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | class ViewCellsManager;
|
---|
35 |
|
---|
36 | static CGcontext sCgContext = NULL;
|
---|
37 | static CGprogram sCgFragmentProgram = NULL;
|
---|
38 | static CGprofile sCgFragmentProfile;
|
---|
39 |
|
---|
40 |
|
---|
41 | //static vector<OcclusionQuery *> sQueries;
|
---|
42 |
|
---|
43 | QtGlRendererWidget *rendererWidget = NULL;
|
---|
44 | QtGlDebuggerWidget *debuggerWidget = NULL;
|
---|
45 |
|
---|
46 |
|
---|
47 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
48 | {
|
---|
49 | return obj1->mId < obj2->mId;
|
---|
50 | }
|
---|
51 |
|
---|
52 | #if USE_CG
|
---|
53 | static void handleCgError()
|
---|
54 | {
|
---|
55 | Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
56 | exit(1);
|
---|
57 | }
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | void
|
---|
61 | QtGlRendererBuffer::MakeCurrent()
|
---|
62 | {
|
---|
63 | makeCurrent();
|
---|
64 | }
|
---|
65 |
|
---|
66 | void
|
---|
67 | QtGlRendererBuffer::DoneCurrent()
|
---|
68 | {
|
---|
69 | doneCurrent();
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | QtGlRendererBuffer::QtGlRendererBuffer(const int w,
|
---|
74 | const int h,
|
---|
75 | SceneGraph *sceneGraph,
|
---|
76 | ViewCellsManager *viewcells,
|
---|
77 | KdTree *tree):
|
---|
78 | QGLPixelBuffer(QSize(w, h)),
|
---|
79 | //QGLWidget(NULL, w, h),
|
---|
80 | GlRendererBuffer(sceneGraph, viewcells, tree)
|
---|
81 | {
|
---|
82 | MakeCurrent();
|
---|
83 | InitGL();
|
---|
84 | DoneCurrent();
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | // reimplemented here so that we can snap the error windows
|
---|
89 | float
|
---|
90 | QtGlRendererBuffer::GetPixelError(int &pvsSize)
|
---|
91 | {
|
---|
92 | float pErrorPixels = -1.0f;
|
---|
93 |
|
---|
94 |
|
---|
95 | mUseFalseColors = false;
|
---|
96 | unsigned int pixelCount;
|
---|
97 |
|
---|
98 |
|
---|
99 | ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
100 | // cout<<"View cell"<<viewcell<<endl;
|
---|
101 | if (viewcell == NULL)
|
---|
102 | return 0.0f;
|
---|
103 |
|
---|
104 | // ViewCell *viewcell = NULL;
|
---|
105 |
|
---|
106 | // PrVs prvs;
|
---|
107 |
|
---|
108 | // mViewCellsManager->SetMaxFilterSize(0);
|
---|
109 | // mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth());
|
---|
110 | // viewcell = prvs.mViewCell;
|
---|
111 |
|
---|
112 | ObjectPvs pvs;
|
---|
113 |
|
---|
114 | if (1)
|
---|
115 | pvs = viewcell->GetPvs();
|
---|
116 | else
|
---|
117 | mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs);
|
---|
118 |
|
---|
119 | // cout<<"pvs size"<<pvs.GetSize()<<endl<<flush;
|
---|
120 |
|
---|
121 | SetupCamera();
|
---|
122 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
123 | glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
|
---|
124 |
|
---|
125 |
|
---|
126 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
127 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
128 |
|
---|
129 | // Render PVS
|
---|
130 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
131 |
|
---|
132 | pvsSize = pvs.GetSize();
|
---|
133 | Intersectable::NewMail();
|
---|
134 | for (; it.HasMoreEntries(); ) {
|
---|
135 | RenderIntersectable(it.Next());
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
140 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
141 | glEnable(GL_STENCIL_TEST);
|
---|
142 |
|
---|
143 | mUseFalseColors = true;
|
---|
144 |
|
---|
145 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
146 |
|
---|
147 |
|
---|
148 | query->BeginQuery();
|
---|
149 |
|
---|
150 | SetupCamera();
|
---|
151 |
|
---|
152 | RenderScene();
|
---|
153 |
|
---|
154 | query->EndQuery();
|
---|
155 | glDisable(GL_STENCIL_TEST);
|
---|
156 | // reenable other state
|
---|
157 | // int wait=0;
|
---|
158 | // while (!query.ResultAvailable()) {
|
---|
159 | // wait++;
|
---|
160 | // }
|
---|
161 |
|
---|
162 |
|
---|
163 | pixelCount = query->GetQueryResult();
|
---|
164 |
|
---|
165 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
166 |
|
---|
167 |
|
---|
168 | if (mSnapErrorFrames && pErrorPixels >= 0.01f) {
|
---|
169 | glReadBuffer(GL_BACK);
|
---|
170 |
|
---|
171 | char filename[256];
|
---|
172 | sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
|
---|
173 | QImage im = toImage();
|
---|
174 | string str = mSnapPrefix + filename;
|
---|
175 | QString qstr(str.c_str());
|
---|
176 |
|
---|
177 | im.save(qstr, "PNG");
|
---|
178 | if (1) { //0 && mFrame == 1543) {
|
---|
179 | int x,y;
|
---|
180 | int lastIndex = -1;
|
---|
181 | for (y=0; y < im.height(); y++)
|
---|
182 | for (x=0; x < im.width(); x++) {
|
---|
183 | QRgb p = im.pixel(x,y);
|
---|
184 | int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16);
|
---|
185 | if (qGreen(p) != 255 && index!=0) {
|
---|
186 | if (index != lastIndex) {
|
---|
187 | // Debug<<"ei="<<index<<" ";
|
---|
188 | lastIndex = index;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | mUseFalseColors = false;
|
---|
196 | glPushAttrib(GL_CURRENT_BIT);
|
---|
197 | glColor3f(0,1,0);
|
---|
198 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
199 | SetupCamera();
|
---|
200 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
201 |
|
---|
202 | // Render PVS
|
---|
203 | Intersectable::NewMail();
|
---|
204 |
|
---|
205 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
206 | for (; it.HasMoreEntries(); ) {
|
---|
207 | RenderIntersectable(it.Next());
|
---|
208 | }
|
---|
209 |
|
---|
210 | im = toImage();
|
---|
211 | sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels);
|
---|
212 | str = mSnapPrefix + filename;
|
---|
213 | qstr = str.c_str();
|
---|
214 | im.save(qstr, "PNG");
|
---|
215 | glPopAttrib();
|
---|
216 | }
|
---|
217 |
|
---|
218 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
219 |
|
---|
220 | return pErrorPixels;
|
---|
221 | }
|
---|
222 |
|
---|
223 | int
|
---|
224 | QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
|
---|
225 | ObjectContainer &pvs) const
|
---|
226 | {
|
---|
227 | int pvsSize = 0;
|
---|
228 | QImage image = toImage();
|
---|
229 | Intersectable::NewMail();
|
---|
230 |
|
---|
231 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
232 |
|
---|
233 | MeshInstance dummy(NULL);
|
---|
234 |
|
---|
235 | Intersectable *obj = NULL;
|
---|
236 |
|
---|
237 | for (int x = 0; x < image.width(); ++ x)
|
---|
238 | {
|
---|
239 | for (int y = 0; y < image.height(); ++ y)
|
---|
240 | {
|
---|
241 | QRgb pix = image.pixel(x, y);
|
---|
242 | const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
|
---|
243 |
|
---|
244 | dummy.SetId(id);
|
---|
245 |
|
---|
246 | ObjectContainer::iterator oit =
|
---|
247 | lower_bound(objects.begin(), objects.end(), &dummy, ilt);
|
---|
248 |
|
---|
249 |
|
---|
250 | if (//(oit != oit.end()) &&
|
---|
251 | ((*oit)->GetId() == id) &&
|
---|
252 | !obj->Mailed())
|
---|
253 | {
|
---|
254 | obj = *oit;
|
---|
255 | obj->Mail();
|
---|
256 | ++ pvsSize;
|
---|
257 | pvs.push_back(obj);
|
---|
258 | }
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | return pvsSize;
|
---|
263 | }
|
---|
264 |
|
---|
265 | ///////////////////////////////////////////////////////////////
|
---|
266 | ///////////////////////////////////////////////////////////////
|
---|
267 | ///////////////////////////////////////////////////////////////
|
---|
268 | ///////////////////////////////////////////////////////////////
|
---|
269 |
|
---|
270 |
|
---|
271 | void
|
---|
272 | QtGlRendererWidget::InitGL()
|
---|
273 | {
|
---|
274 | GlRenderer::InitGL();
|
---|
275 |
|
---|
276 | GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
|
---|
277 | /* mat_specular and mat_shininess are NOT default values */
|
---|
278 | GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
279 | GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
280 | GLfloat mat_shininess[] = { 1.0 };
|
---|
281 |
|
---|
282 | GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
---|
283 | GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 };
|
---|
284 | GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
285 |
|
---|
286 | GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
287 |
|
---|
288 |
|
---|
289 | // default Material
|
---|
290 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
291 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
292 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
293 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
294 |
|
---|
295 | // a light
|
---|
296 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
297 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
298 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
299 |
|
---|
300 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
301 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
302 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
303 |
|
---|
304 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
305 |
|
---|
306 | glEnable(GL_LIGHTING);
|
---|
307 | glEnable(GL_LIGHT0);
|
---|
308 | glEnable(GL_LIGHT1);
|
---|
309 |
|
---|
310 |
|
---|
311 | // set position of the light
|
---|
312 | GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 };
|
---|
313 | glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
|
---|
314 |
|
---|
315 | // set position of the light2
|
---|
316 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
317 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
318 |
|
---|
319 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
320 | // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
321 | glEnable(GL_COLOR_MATERIAL);
|
---|
322 |
|
---|
323 | glShadeModel( GL_FLAT );
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 | void
|
---|
328 | QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
|
---|
329 | {
|
---|
330 | if (!mTopView) {
|
---|
331 | int ww = w;
|
---|
332 | int hh = h;
|
---|
333 | glViewport(0, 0, ww, hh);
|
---|
334 | glMatrixMode(GL_PROJECTION);
|
---|
335 | glLoadIdentity();
|
---|
336 | gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
337 | glMatrixMode(GL_MODELVIEW);
|
---|
338 | } else {
|
---|
339 | int ww = w;
|
---|
340 | int hh = h;
|
---|
341 | glViewport(0, 0, ww, hh);
|
---|
342 | glMatrixMode(GL_PROJECTION);
|
---|
343 | glLoadIdentity();
|
---|
344 | gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
345 | glMatrixMode(GL_MODELVIEW);
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
|
---|
351 | {
|
---|
352 | if (viewCell != mPvsCache.mViewCell)
|
---|
353 | return true;
|
---|
354 |
|
---|
355 | if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
|
---|
356 | return true;
|
---|
357 |
|
---|
358 | return false;
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | void QtGlRendererWidget::_RenderPvs()
|
---|
363 | {
|
---|
364 | mUseFalseColors = false;
|
---|
365 |
|
---|
366 | int offset = mObjects.size() * 3;
|
---|
367 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
368 |
|
---|
369 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
370 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
371 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | void QtGlRendererWidget::_UpdatePvsIndices()
|
---|
376 | {
|
---|
377 | mIndexBufferSize = 0;
|
---|
378 | KdNode::NewMail();
|
---|
379 |
|
---|
380 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
381 |
|
---|
382 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
383 |
|
---|
384 | for (; it.HasMoreEntries(); )
|
---|
385 | {
|
---|
386 | Intersectable *obj = it.Next();
|
---|
387 | KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
|
---|
388 | _UpdatePvsIndices(node);
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node)
|
---|
394 | {
|
---|
395 | if (node->Mailed())
|
---|
396 | return;
|
---|
397 |
|
---|
398 | node->Mail();
|
---|
399 |
|
---|
400 | if (!node->IsLeaf())
|
---|
401 | {
|
---|
402 | KdInterior *in = static_cast<KdInterior *>(node);
|
---|
403 |
|
---|
404 | _UpdatePvsIndices(in->mBack);
|
---|
405 | _UpdatePvsIndices(in->mFront);
|
---|
406 | }
|
---|
407 | else
|
---|
408 | {
|
---|
409 | KdLeaf *leaf = static_cast<KdLeaf *>(node);
|
---|
410 |
|
---|
411 | leaf->mIndexBufferStart = mIndexBufferSize;
|
---|
412 |
|
---|
413 | for (size_t i = 0; i < leaf->mObjects.size(); ++ i)
|
---|
414 | {
|
---|
415 | TriangleIntersectable *obj =
|
---|
416 | static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
|
---|
417 |
|
---|
418 | // check if already rendered
|
---|
419 | if (!obj->Mailed())
|
---|
420 | {
|
---|
421 | obj->Mail();
|
---|
422 |
|
---|
423 | mIndices[mIndexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
|
---|
424 | mIndices[mIndexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
|
---|
425 | mIndices[mIndexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
|
---|
426 |
|
---|
427 | mIndexBufferSize += 3;
|
---|
428 | }
|
---|
429 | }
|
---|
430 |
|
---|
431 | leaf->mIndexBufferSize = mIndexBufferSize - leaf->mIndexBufferStart;
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 |
|
---|
436 | void QtGlRendererWidget::RenderPvs()
|
---|
437 | {
|
---|
438 | if (mUseVbos)
|
---|
439 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
440 |
|
---|
441 | EnableDrawArrays();
|
---|
442 |
|
---|
443 | Intersectable::NewMail();
|
---|
444 | ViewCell *viewcell = NULL;
|
---|
445 |
|
---|
446 | if (mDetectEmptyViewSpace)
|
---|
447 | glEnable(GL_CULL_FACE);
|
---|
448 | else
|
---|
449 | glDisable(GL_CULL_FACE);
|
---|
450 |
|
---|
451 | viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
|
---|
452 |
|
---|
453 | if (viewcell)
|
---|
454 | {
|
---|
455 | // copy the pvs so that it can be filtered...
|
---|
456 | if (PvsChanged(viewcell))
|
---|
457 | {
|
---|
458 | mPvsCache.Reset();
|
---|
459 | mPvsCache.mViewCell = viewcell;
|
---|
460 | mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
|
---|
461 |
|
---|
462 | if (mUseSpatialFilter)
|
---|
463 | {
|
---|
464 | // 9.11. 2006 -> experiment with new spatial filter
|
---|
465 | #if 0
|
---|
466 | mViewCellsManager->ApplySpatialFilter(mKdTree,
|
---|
467 | mSpatialFilterSize*
|
---|
468 | Magnitude(mViewCellsManager->GetViewSpaceBox().Size()),
|
---|
469 | mPvsCache.mPvs);
|
---|
470 | #else
|
---|
471 | //cout<<"updating filter" << endl;
|
---|
472 | // mSpatialFilter size is in range 0.001 - 0.1
|
---|
473 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
474 | mUseFilter,
|
---|
475 | 100 * mSpatialFilterSize,
|
---|
476 | mPvsCache.mPvs,
|
---|
477 | &mPvsCache.filteredBoxes
|
---|
478 | );
|
---|
479 | #endif
|
---|
480 | }
|
---|
481 | else
|
---|
482 | {
|
---|
483 | mPvsCache.mPvs = viewcell->GetPvs();
|
---|
484 | }
|
---|
485 |
|
---|
486 | /// update the indices for rendering
|
---|
487 | _UpdatePvsIndices();
|
---|
488 |
|
---|
489 | emit PvsUpdated();
|
---|
490 | }
|
---|
491 |
|
---|
492 | Intersectable::NewMail();
|
---|
493 | PvsData pvsData;
|
---|
494 |
|
---|
495 | // Render PVS
|
---|
496 | if (mUseSpatialFilter && mRenderBoxes)
|
---|
497 | {
|
---|
498 | for (int i=0; i < mPvsCache.filteredBoxes.size(); i++)
|
---|
499 | RenderBox(mPvsCache.filteredBoxes[i]);
|
---|
500 | }
|
---|
501 | else
|
---|
502 | {
|
---|
503 | if (!mRenderVisibilityEstimates)
|
---|
504 | {
|
---|
505 | _RenderPvs();
|
---|
506 | }
|
---|
507 | else
|
---|
508 | {
|
---|
509 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
510 |
|
---|
511 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
512 | for (; it.HasMoreEntries(); )
|
---|
513 | {
|
---|
514 | Intersectable *object = it.Next(pvsData);
|
---|
515 |
|
---|
516 | //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
|
---|
517 | // glColor3f(visibility, 0.0f, 0.0f);
|
---|
518 | //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
|
---|
519 | RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1));
|
---|
520 | glColor3f(color.r, color.g, color.b);
|
---|
521 |
|
---|
522 | mUseForcedColors = true;
|
---|
523 | RenderIntersectable(object);
|
---|
524 | mUseForcedColors = false;
|
---|
525 | }
|
---|
526 | }
|
---|
527 | }
|
---|
528 |
|
---|
529 | if (mRenderFilter)
|
---|
530 | {
|
---|
531 | mWireFrame = true;
|
---|
532 | RenderIntersectable(viewcell);
|
---|
533 | glPushMatrix();
|
---|
534 | glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
535 | glScalef(5.0f,5.0f,5.0f);
|
---|
536 | glPushAttrib(GL_CURRENT_BIT);
|
---|
537 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
538 | // gluSphere((::GLUquadric *)mSphere,
|
---|
539 | // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
|
---|
540 | glPopAttrib();
|
---|
541 | glPopMatrix();
|
---|
542 | mWireFrame = false;
|
---|
543 | }
|
---|
544 | }
|
---|
545 | else
|
---|
546 | {
|
---|
547 | /*ObjectContainer::const_iterator oi = mObjects.begin();
|
---|
548 | for (; oi != mObjects.end(); oi++)
|
---|
549 | RenderIntersectable(*oi);*/
|
---|
550 | RenderScene();
|
---|
551 | }
|
---|
552 |
|
---|
553 | //DisableDrawArrays();
|
---|
554 | //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
---|
555 | }
|
---|
556 |
|
---|
557 | float
|
---|
558 | QtGlRendererWidget::RenderErrors()
|
---|
559 | {
|
---|
560 | float pErrorPixels = -1.0f;
|
---|
561 |
|
---|
562 | SetupCamera();
|
---|
563 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
564 |
|
---|
565 | glPushAttrib(GL_ENABLE_BIT);
|
---|
566 |
|
---|
567 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
568 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
569 |
|
---|
570 | mUseForcedColors = true;
|
---|
571 |
|
---|
572 | glColor3f(0.0f, 0.8f, 0.2f);
|
---|
573 |
|
---|
574 | // Render PVS
|
---|
575 | RenderPvs();
|
---|
576 |
|
---|
577 | glEnable(GL_STENCIL_TEST);
|
---|
578 |
|
---|
579 | //mUseFalseColors = true;
|
---|
580 |
|
---|
581 | glDisable(GL_LIGHTING);
|
---|
582 |
|
---|
583 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
584 | query->BeginQuery();
|
---|
585 |
|
---|
586 | SetupCamera();
|
---|
587 |
|
---|
588 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
589 |
|
---|
590 | RenderScene();
|
---|
591 |
|
---|
592 | mUseForcedColors = false;
|
---|
593 |
|
---|
594 | query->EndQuery();
|
---|
595 |
|
---|
596 | glDisable(GL_STENCIL_TEST);
|
---|
597 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
598 |
|
---|
599 | glPopAttrib();
|
---|
600 |
|
---|
601 | // reenable other state
|
---|
602 | // int wait=0;
|
---|
603 | // while (!query.ResultAvailable()) {
|
---|
604 | // wait++;
|
---|
605 | // }
|
---|
606 |
|
---|
607 | int pixelCount = query->GetQueryResult();
|
---|
608 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
609 | if (0) cout<<"error pixels="<<pixelCount<<endl;
|
---|
610 |
|
---|
611 | mRenderError = pErrorPixels;
|
---|
612 |
|
---|
613 | return pErrorPixels;
|
---|
614 | }
|
---|
615 |
|
---|
616 |
|
---|
617 | void QtGlRendererWidget::timerEvent(QTimerEvent *event)
|
---|
618 | {
|
---|
619 | //std::cout << "Timer ID:" << event->timerId();
|
---|
620 | update();
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
|
---|
625 | {
|
---|
626 | int x = e->pos().x();
|
---|
627 | int y = e->pos().y();
|
---|
628 |
|
---|
629 | mousePoint.x = x;
|
---|
630 | mousePoint.y = y;
|
---|
631 |
|
---|
632 | }
|
---|
633 |
|
---|
634 | void
|
---|
635 | QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
|
---|
636 | {
|
---|
637 | float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
|
---|
638 | float TURN_SENSITIVITY=0.1f;
|
---|
639 | float TILT_SENSITIVITY=32.0 ;
|
---|
640 | float TURN_ANGLE= M_PI/36.0 ;
|
---|
641 |
|
---|
642 | int x = e->pos().x();
|
---|
643 | int y = e->pos().y();
|
---|
644 |
|
---|
645 | int diffx = -(mousePoint.x - x);
|
---|
646 | int diffy = -(mousePoint.y - y);
|
---|
647 |
|
---|
648 | if (e->modifiers() & Qt::ControlModifier)
|
---|
649 | {
|
---|
650 | mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
|
---|
651 | mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
|
---|
652 | }
|
---|
653 | else
|
---|
654 | {
|
---|
655 | mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
|
---|
656 | float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
|
---|
657 | float angle = atan2(mViewDirection.x, mViewDirection.z);
|
---|
658 | mViewDirection.x = sin(angle + adiff);
|
---|
659 | mViewDirection.z = cos(angle + adiff);
|
---|
660 | }
|
---|
661 |
|
---|
662 | mousePoint.x = x;
|
---|
663 | mousePoint.y = y;
|
---|
664 |
|
---|
665 | updateGL();
|
---|
666 | }
|
---|
667 |
|
---|
668 | void
|
---|
669 | QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
|
---|
670 | {
|
---|
671 | }
|
---|
672 |
|
---|
673 | void
|
---|
674 | QtGlRendererWidget::resizeGL(int w, int h)
|
---|
675 | {
|
---|
676 | SetupCameraProjection(w, h);
|
---|
677 | updateGL();
|
---|
678 | }
|
---|
679 |
|
---|
680 | void
|
---|
681 | QtGlRendererWidget::paintGL()
|
---|
682 | {
|
---|
683 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
684 |
|
---|
685 | if (1) {
|
---|
686 | SetupCameraProjection(width(), height());
|
---|
687 | SetupCamera();
|
---|
688 |
|
---|
689 | if (mRenderErrors) {
|
---|
690 | RenderErrors();
|
---|
691 | } else {
|
---|
692 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
693 | RenderPvs();
|
---|
694 | }
|
---|
695 | }
|
---|
696 |
|
---|
697 | RenderInfo();
|
---|
698 |
|
---|
699 | mFrame ++;
|
---|
700 |
|
---|
701 | }
|
---|
702 |
|
---|
703 |
|
---|
704 | void
|
---|
705 | QtGlRendererWidget::SetupCamera()
|
---|
706 | {
|
---|
707 | if (!mTopView)
|
---|
708 | GlRenderer::SetupCamera();
|
---|
709 | else {
|
---|
710 | if (0) {
|
---|
711 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
712 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
713 | -1,
|
---|
714 | mViewDirection.y);
|
---|
715 |
|
---|
716 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
717 | Vector3 up(0,1,0);
|
---|
718 |
|
---|
719 | glLoadIdentity();
|
---|
720 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
721 | target.x, target.y, target.z,
|
---|
722 | up.x, up.y, up.z);
|
---|
723 | } else {
|
---|
724 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance;
|
---|
725 | Vector3 pos = mViewPoint + dist*Vector3(0,
|
---|
726 | 1,
|
---|
727 | 0);
|
---|
728 |
|
---|
729 | Vector3 target = mViewPoint;
|
---|
730 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
731 |
|
---|
732 | glLoadIdentity();
|
---|
733 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
734 | target.x, target.y, target.z,
|
---|
735 | up.x, up.y, up.z);
|
---|
736 |
|
---|
737 | }
|
---|
738 | }
|
---|
739 |
|
---|
740 | }
|
---|
741 |
|
---|
742 |
|
---|
743 | void
|
---|
744 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
745 | {
|
---|
746 | switch (e->key()) {
|
---|
747 | case Qt::Key_T:
|
---|
748 | mTopView = !mTopView;
|
---|
749 | SetupCameraProjection(width(), height());
|
---|
750 | updateGL();
|
---|
751 | break;
|
---|
752 | case Qt::Key_V:
|
---|
753 | mRenderViewCells = !mRenderViewCells;
|
---|
754 | updateGL();
|
---|
755 | break;
|
---|
756 | case Qt::Key_P:
|
---|
757 | // set random viewpoint
|
---|
758 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
759 | updateGL();
|
---|
760 | break;
|
---|
761 | case Qt::Key_S: {
|
---|
762 | // set view poitn and direction
|
---|
763 | QString text;
|
---|
764 | bool ok;
|
---|
765 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
766 | text = QInputDialog::getText(this,
|
---|
767 | "Enter a view point",
|
---|
768 | "",
|
---|
769 | QLineEdit::Normal,
|
---|
770 | text,
|
---|
771 | &ok);
|
---|
772 | if (!ok)
|
---|
773 | break;
|
---|
774 |
|
---|
775 | if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
776 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
777 | text = QInputDialog::getText(this,
|
---|
778 | "Enter a direction",
|
---|
779 | "",
|
---|
780 | QLineEdit::Normal,
|
---|
781 | text,
|
---|
782 | &ok);
|
---|
783 | if (!ok)
|
---|
784 | break;
|
---|
785 | if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
786 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
787 | updateGL();
|
---|
788 | }
|
---|
789 | break;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | default:
|
---|
793 | e->ignore();
|
---|
794 | break;
|
---|
795 | }
|
---|
796 | }
|
---|
797 |
|
---|
798 |
|
---|
799 |
|
---|
800 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
801 | SceneGraph *sceneGraph,
|
---|
802 | ViewCellsManager *viewcells,
|
---|
803 | KdTree *tree,
|
---|
804 | QWidget * parent,
|
---|
805 | const QGLWidget * shareWidget,
|
---|
806 | Qt::WFlags f
|
---|
807 | )
|
---|
808 | :
|
---|
809 | GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
810 | {
|
---|
811 | mPreprocessorThread = NULL;
|
---|
812 | mTopView = false;
|
---|
813 | mRenderViewCells = false;
|
---|
814 | mTopDistance = 1.0f;
|
---|
815 | mCutViewCells = false;
|
---|
816 | mCutScene = false;
|
---|
817 | mRenderErrors = false;
|
---|
818 | mRenderBoxes = false;
|
---|
819 | mRenderFilter = true;
|
---|
820 | mRenderVisibilityEstimates = false;
|
---|
821 | mTransferFunction = 0.2f;
|
---|
822 | mIndexBufferSize = 0;
|
---|
823 |
|
---|
824 | const int delay = 500; // half a second
|
---|
825 | timerId = startTimer(delay);
|
---|
826 |
|
---|
827 | bool tmp;
|
---|
828 |
|
---|
829 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
830 | mUseFilter = tmp;
|
---|
831 |
|
---|
832 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
833 | tmp );
|
---|
834 | mUseSpatialFilter = tmp;
|
---|
835 |
|
---|
836 | mShowRenderCost = false;
|
---|
837 | mShowPvsSizes = false;
|
---|
838 | mSpatialFilterSize = 0.01;
|
---|
839 | mPvsSize = 0;
|
---|
840 | mRenderError = 0.0f;
|
---|
841 | mShowRays = false;
|
---|
842 |
|
---|
843 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
844 |
|
---|
845 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
846 | connect(mControlWidget,
|
---|
847 | SIGNAL(SetTransferFunction(int)),
|
---|
848 | this,
|
---|
849 | SLOT(SetTransferFunction(int)));
|
---|
850 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
851 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
852 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
853 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
|
---|
854 | SLOT(SetRandomViewPoint()));
|
---|
855 |
|
---|
856 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
857 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
858 |
|
---|
859 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
860 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
861 |
|
---|
862 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
863 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
864 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
865 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
866 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
867 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
868 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
869 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
870 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
871 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)),
|
---|
872 | this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
873 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
874 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
|
---|
875 | this, SLOT(SetUseSpatialFilter(bool)));
|
---|
876 |
|
---|
877 | connect(mControlWidget,
|
---|
878 | SIGNAL(SetShowRays(bool)),
|
---|
879 | this,
|
---|
880 | SLOT(SetShowRays(bool)));
|
---|
881 |
|
---|
882 | resize(1000, 500);
|
---|
883 | mControlWidget->show();
|
---|
884 | }
|
---|
885 |
|
---|
886 | void
|
---|
887 | QtGlRendererWidget::UpdateAllPvs()
|
---|
888 | {
|
---|
889 | // $$ does not work so far:(
|
---|
890 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
891 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
892 | }
|
---|
893 |
|
---|
894 | void
|
---|
895 | QtGlRendererWidget::ComputeVisibility()
|
---|
896 | {
|
---|
897 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
898 | if (!mPreprocessorThread->isRunning())
|
---|
899 | mPreprocessorThread->RunThread();
|
---|
900 | }
|
---|
901 |
|
---|
902 | void
|
---|
903 | QtGlRendererWidget::StopComputation()
|
---|
904 | {
|
---|
905 | cerr<<"stop computation called!\n"<<endl;
|
---|
906 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
907 | }
|
---|
908 |
|
---|
909 | void
|
---|
910 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
911 | {
|
---|
912 | cerr<<"stop computation called!\n"<<endl;
|
---|
913 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
914 | updateGL();
|
---|
915 | }
|
---|
916 |
|
---|
917 | void
|
---|
918 | QtGlRendererWidget::RenderRenderCost()
|
---|
919 | {
|
---|
920 | static vector<float> costFunction;
|
---|
921 | static float maxCost = -1;
|
---|
922 | if (costFunction.size()==0) {
|
---|
923 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
924 | if (tree) {
|
---|
925 | tree->GetCostFunction(costFunction);
|
---|
926 | maxCost = -1;
|
---|
927 | for (int i=0; i < costFunction.size(); i++) {
|
---|
928 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
929 | // update cost function to an absolute value based on the total geometry count
|
---|
930 | costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
|
---|
931 | if (costFunction[i] > maxCost)
|
---|
932 | maxCost = costFunction[i];
|
---|
933 | }
|
---|
934 | }
|
---|
935 | }
|
---|
936 |
|
---|
937 |
|
---|
938 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
939 | float currentCost= -1;
|
---|
940 |
|
---|
941 | if (currentPos < costFunction.size())
|
---|
942 | currentCost = costFunction[currentPos];
|
---|
943 | #if 1
|
---|
944 | cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
|
---|
945 | cout<<"CP="<<currentPos<<endl;
|
---|
946 | cout<<"MC="<<maxCost<<endl;
|
---|
947 | cout<<"CC="<<currentCost<<endl;
|
---|
948 | #endif
|
---|
949 | if (costFunction.size()) {
|
---|
950 | float scaley = 1.0f/log10(maxCost);
|
---|
951 | float scalex = 1.0f/(float)costFunction.size();
|
---|
952 |
|
---|
953 | glDisable(GL_DEPTH_TEST);
|
---|
954 | // init ortographic projection
|
---|
955 | glMatrixMode(GL_PROJECTION);
|
---|
956 |
|
---|
957 | glPushMatrix();
|
---|
958 |
|
---|
959 | glLoadIdentity();
|
---|
960 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
961 |
|
---|
962 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
963 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
964 | glMatrixMode(GL_MODELVIEW);
|
---|
965 | glLoadIdentity();
|
---|
966 |
|
---|
967 | glColor3f(1.0f,0,0);
|
---|
968 | glBegin(GL_LINE_STRIP);
|
---|
969 | // glVertex3f(0,0,0);
|
---|
970 |
|
---|
971 | for (int i=0; i < costFunction.size(); i++) {
|
---|
972 | float x = i*scalex;
|
---|
973 | float y = log10(costFunction[i])*scaley;
|
---|
974 | glVertex3f(x,y,0.0f);
|
---|
975 | }
|
---|
976 | glEnd();
|
---|
977 |
|
---|
978 | glColor3f(1.0f,0,0);
|
---|
979 | glBegin(GL_LINES);
|
---|
980 | float x = currentPos*scalex;
|
---|
981 | glVertex3f(x,0.0,0.0f);
|
---|
982 | glVertex3f(x,1.0f,0.0f);
|
---|
983 | glEnd();
|
---|
984 |
|
---|
985 | glColor3f(0.0f,0,0);
|
---|
986 | // show a grid
|
---|
987 | glBegin(GL_LINE_LOOP);
|
---|
988 | glVertex3f(0,0,0.0f);
|
---|
989 | glVertex3f(1,0,0.0f);
|
---|
990 | glVertex3f(1,1,0.0f);
|
---|
991 | glVertex3f(0,1,0.0f);
|
---|
992 | glEnd();
|
---|
993 |
|
---|
994 | glBegin(GL_LINES);
|
---|
995 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
996 | float x = i*scalex;
|
---|
997 | glVertex3f(x,0.0,0.0f);
|
---|
998 | glVertex3f(x,1.0f,0.0f);
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
1002 | float y = i*scaley;
|
---|
1003 | // QString s;
|
---|
1004 | // s.sprintf("%d", (int)pow(10,i));
|
---|
1005 | // renderText(width()/2+5, y*height(), s);
|
---|
1006 | glVertex3f(0.0f, y, 0.0f);
|
---|
1007 | glVertex3f(1.0f, y, 0.0f);
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | glEnd();
|
---|
1011 |
|
---|
1012 |
|
---|
1013 | // restore the projection matrix
|
---|
1014 | glMatrixMode(GL_PROJECTION);
|
---|
1015 | glPopMatrix();
|
---|
1016 | glMatrixMode(GL_MODELVIEW);
|
---|
1017 | glEnable(GL_DEPTH_TEST);
|
---|
1018 |
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 |
|
---|
1022 |
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | void
|
---|
1026 | QtGlRendererWidget::RenderInfo()
|
---|
1027 | {
|
---|
1028 |
|
---|
1029 | QString s;
|
---|
1030 | int vc = 0;
|
---|
1031 | if (mViewCellsManager)
|
---|
1032 | vc = (int)mViewCellsManager->GetViewCells().size();
|
---|
1033 |
|
---|
1034 | int filter = 0;
|
---|
1035 | if (mViewCellsManager)
|
---|
1036 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
1037 |
|
---|
1038 | glColor3f(1.0f,1.0f,1.0f);
|
---|
1039 |
|
---|
1040 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
1041 | mFrame,
|
---|
1042 | mViewPoint.x,
|
---|
1043 | mViewPoint.y,
|
---|
1044 | mViewPoint.z,
|
---|
1045 | mViewDirection.x,
|
---|
1046 | mViewDirection.y,
|
---|
1047 | mViewDirection.z
|
---|
1048 | );
|
---|
1049 |
|
---|
1050 | renderText(20,20,s);
|
---|
1051 |
|
---|
1052 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
|
---|
1053 | vc,
|
---|
1054 | filter,
|
---|
1055 | mPvsSize,
|
---|
1056 | mRenderError*100.0f);
|
---|
1057 |
|
---|
1058 |
|
---|
1059 | renderText(20,40,s);
|
---|
1060 |
|
---|
1061 |
|
---|
1062 |
|
---|
1063 |
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 |
|
---|
1067 | void
|
---|
1068 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
1069 | {
|
---|
1070 | if (mViewCellsManager) {
|
---|
1071 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
1072 |
|
---|
1073 | // $$ tmp off
|
---|
1074 | mViewCellsManager->CollectViewCells(number);
|
---|
1075 |
|
---|
1076 | // $$ does not work so far:(
|
---|
1077 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1078 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1079 | }
|
---|
1080 | updateGL();
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | void
|
---|
1084 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
1085 | {
|
---|
1086 | if (mViewCellsManager)
|
---|
1087 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
1088 | mPvsCache.Reset();
|
---|
1089 | updateGL();
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | void
|
---|
1093 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
1094 | {
|
---|
1095 | mSpatialFilterSize = 1e-3*number;
|
---|
1096 | mPvsCache.Reset();
|
---|
1097 | updateGL();
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | void
|
---|
1101 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
1102 | {
|
---|
1103 | // assume the cut plane can only be aligned with xz plane
|
---|
1104 | // shift it along y according to number, which is percentage of the bounding
|
---|
1105 | // box position
|
---|
1106 | if (mViewCellsManager) {
|
---|
1107 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1108 | Vector3 p = box.Min() + (number/1000.0f)*box.Max();
|
---|
1109 | mSceneCutPlane.mNormal = Vector3(0,-1,0);
|
---|
1110 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
1111 | updateGL();
|
---|
1112 | }
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | void
|
---|
1116 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1117 | {
|
---|
1118 | mTopDistance = number/1000.0f;
|
---|
1119 | updateGL();
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | void
|
---|
1123 | QtGlRendererWidget::RenderViewCells()
|
---|
1124 | {
|
---|
1125 | mUseFalseColors = true;
|
---|
1126 |
|
---|
1127 | glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1128 |
|
---|
1129 | glEnable(GL_CULL_FACE);
|
---|
1130 | glCullFace(GL_FRONT);
|
---|
1131 |
|
---|
1132 | glDisable(GL_CULL_FACE);
|
---|
1133 | double eq[4];
|
---|
1134 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1135 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1136 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1137 | eq[3] = mSceneCutPlane.mD;
|
---|
1138 |
|
---|
1139 | if (mCutViewCells) {
|
---|
1140 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1141 | glEnable(GL_CLIP_PLANE0);
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | int i;
|
---|
1145 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1146 | int maxPvs = -1;
|
---|
1147 | for (i=0; i < viewcells.size(); i++)
|
---|
1148 | {
|
---|
1149 | ViewCell *vc = viewcells[i];
|
---|
1150 |
|
---|
1151 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1152 | const int p = vc->GetPvs().GetSize();
|
---|
1153 | if (p > maxPvs)
|
---|
1154 | maxPvs = p;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 |
|
---|
1158 | for (i=0; i < viewcells.size(); i++) {
|
---|
1159 | ViewCell *vc = viewcells[i];
|
---|
1160 | // Mesh *m = vc->GetMesh();
|
---|
1161 |
|
---|
1162 | RgbColor c;
|
---|
1163 |
|
---|
1164 | if (!mShowPvsSizes) {
|
---|
1165 | mWireFrame = true;
|
---|
1166 | c = vc->GetColor();
|
---|
1167 | } else {
|
---|
1168 | // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
|
---|
1169 | const float importance = 5.0f*mTransferFunction *
|
---|
1170 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1171 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1172 | c = RainbowColorMapping(importance);
|
---|
1173 |
|
---|
1174 | }
|
---|
1175 | glColor3f(c.r, c.g, c.b);
|
---|
1176 |
|
---|
1177 | RenderViewCell(vc);
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | mUseFalseColors = false;
|
---|
1181 | mWireFrame = false;
|
---|
1182 |
|
---|
1183 | glPopAttrib();
|
---|
1184 |
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 |
|
---|
1188 |
|
---|
1189 | /*********************************************************************/
|
---|
1190 | /* QtGlDebuggerWidget implementation */
|
---|
1191 | /*********************************************************************/
|
---|
1192 |
|
---|
1193 |
|
---|
1194 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
1195 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
1196 | {
|
---|
1197 | // create the pbuffer
|
---|
1198 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
1199 | timerId = startTimer(20);
|
---|
1200 | setWindowTitle(("OpenGL pbuffers"));
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 |
|
---|
1204 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
1205 | {
|
---|
1206 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
1207 | glDeleteTextures(1, &dynamicTexture);
|
---|
1208 |
|
---|
1209 | DEL_PTR(mRenderBuffer);
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 |
|
---|
1213 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
1214 | QWidget(parent, f)
|
---|
1215 | {
|
---|
1216 |
|
---|
1217 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
1218 | setLayout(vl);
|
---|
1219 |
|
---|
1220 | QWidget *vbox = new QGroupBox("ViewCells", this);
|
---|
1221 | layout()->addWidget(vbox);
|
---|
1222 |
|
---|
1223 | vl = new QVBoxLayout;
|
---|
1224 | vbox->setLayout(vl);
|
---|
1225 |
|
---|
1226 | QLabel *label = new QLabel("Granularity");
|
---|
1227 | vbox->layout()->addWidget(label);
|
---|
1228 |
|
---|
1229 | QSlider *slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1230 | vl->addWidget(slider);
|
---|
1231 | slider->show();
|
---|
1232 | slider->setRange(1, 10000);
|
---|
1233 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1234 | slider->setValue(200);
|
---|
1235 |
|
---|
1236 |
|
---|
1237 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
1238 |
|
---|
1239 | label = new QLabel("Transfer function");
|
---|
1240 | vbox->layout()->addWidget(label);
|
---|
1241 |
|
---|
1242 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1243 | vl->addWidget(slider);
|
---|
1244 | slider->show();
|
---|
1245 | slider->setRange(1, 10000);
|
---|
1246 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1247 | slider->setValue(100);
|
---|
1248 |
|
---|
1249 |
|
---|
1250 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
1251 |
|
---|
1252 | {
|
---|
1253 | QPushButton *button = new QPushButton("Update all PVSs", vbox);
|
---|
1254 | vbox->layout()->addWidget(button);
|
---|
1255 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | label = new QLabel("Filter size");
|
---|
1260 | vbox->layout()->addWidget(label);
|
---|
1261 |
|
---|
1262 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1263 | vbox->layout()->addWidget(slider);
|
---|
1264 | slider->show();
|
---|
1265 | slider->setRange(1, 100);
|
---|
1266 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1267 | slider->setValue(3);
|
---|
1268 |
|
---|
1269 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
1270 |
|
---|
1271 |
|
---|
1272 | label = new QLabel("Spatial Filter size");
|
---|
1273 | vbox->layout()->addWidget(label);
|
---|
1274 |
|
---|
1275 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1276 | vbox->layout()->addWidget(slider);
|
---|
1277 | slider->show();
|
---|
1278 | slider->setRange(1, 100);
|
---|
1279 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1280 | slider->setValue(10);
|
---|
1281 |
|
---|
1282 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
1283 |
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | QWidget *hbox = new QWidget(vbox);
|
---|
1287 | vl->addWidget(hbox);
|
---|
1288 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
1289 | hbox->setLayout(hlayout);
|
---|
1290 |
|
---|
1291 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
1292 | hlayout->addWidget(cb);
|
---|
1293 | cb->setChecked(false);
|
---|
1294 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
1295 |
|
---|
1296 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
1297 | hlayout->addWidget(cb);
|
---|
1298 | cb->setChecked(false);
|
---|
1299 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
1300 |
|
---|
1301 | cb = new QCheckBox("Show render cost", hbox);
|
---|
1302 | hlayout->addWidget(cb);
|
---|
1303 | cb->setChecked(false);
|
---|
1304 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1305 |
|
---|
1306 | cb = new QCheckBox("Show rays", hbox);
|
---|
1307 | hlayout->addWidget(cb);
|
---|
1308 | cb->setChecked(false);
|
---|
1309 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
1310 |
|
---|
1311 | vbox->resize(800,100);
|
---|
1312 |
|
---|
1313 |
|
---|
1314 | vbox = new QGroupBox("Rendering", this);
|
---|
1315 | layout()->addWidget(vbox);
|
---|
1316 |
|
---|
1317 | vl = new QVBoxLayout;
|
---|
1318 | vbox->setLayout(vl);
|
---|
1319 |
|
---|
1320 |
|
---|
1321 |
|
---|
1322 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
1323 | vbox->layout()->addWidget(cb);
|
---|
1324 | cb->setChecked(false);
|
---|
1325 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
1326 |
|
---|
1327 |
|
---|
1328 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1329 | vbox->layout()->addWidget(slider);
|
---|
1330 | slider->show();
|
---|
1331 | slider->setRange(0, 1000);
|
---|
1332 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1333 | slider->setValue(1000);
|
---|
1334 |
|
---|
1335 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
1336 |
|
---|
1337 |
|
---|
1338 | cb = new QCheckBox("Cut scene", vbox);
|
---|
1339 | vbox->layout()->addWidget(cb);
|
---|
1340 | cb->setChecked(false);
|
---|
1341 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
1342 |
|
---|
1343 | cb = new QCheckBox("Render boxes", vbox);
|
---|
1344 | vbox->layout()->addWidget(cb);
|
---|
1345 | cb->setChecked(false);
|
---|
1346 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
1347 |
|
---|
1348 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
1349 | vbox->layout()->addWidget(cb);
|
---|
1350 | cb->setChecked(false);
|
---|
1351 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
1352 |
|
---|
1353 |
|
---|
1354 | cb = new QCheckBox("Render errors", vbox);
|
---|
1355 | vbox->layout()->addWidget(cb);
|
---|
1356 | cb->setChecked(false);
|
---|
1357 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
1358 |
|
---|
1359 |
|
---|
1360 | bool tmp;
|
---|
1361 |
|
---|
1362 | cb = new QCheckBox("Use filter", vbox);
|
---|
1363 | vbox->layout()->addWidget(cb);
|
---|
1364 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
1365 | cb->setChecked(tmp);
|
---|
1366 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
1367 |
|
---|
1368 |
|
---|
1369 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
1370 | vbox->layout()->addWidget(cb);
|
---|
1371 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
1372 | tmp );
|
---|
1373 | cb->setChecked(tmp);
|
---|
1374 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
1375 |
|
---|
1376 | cb = new QCheckBox("Render filter", vbox);
|
---|
1377 | vbox->layout()->addWidget(cb);
|
---|
1378 | cb->setChecked(true);
|
---|
1379 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
1380 |
|
---|
1381 |
|
---|
1382 |
|
---|
1383 |
|
---|
1384 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1385 | vbox->layout()->addWidget(slider);
|
---|
1386 | slider->show();
|
---|
1387 | slider->setRange(1, 1000);
|
---|
1388 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1389 | slider->setValue(500);
|
---|
1390 |
|
---|
1391 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
1392 |
|
---|
1393 | cb = new QCheckBox("Top View", vbox);
|
---|
1394 | vbox->layout()->addWidget(cb);
|
---|
1395 | cb->setChecked(false);
|
---|
1396 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1397 |
|
---|
1398 |
|
---|
1399 |
|
---|
1400 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1401 | layout()->addWidget(vbox);
|
---|
1402 |
|
---|
1403 | vl = new QVBoxLayout;
|
---|
1404 | vbox->setLayout(vl);
|
---|
1405 |
|
---|
1406 | QPushButton *button = new QPushButton("Compute Visibility", vbox);
|
---|
1407 | vbox->layout()->addWidget(button);
|
---|
1408 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
1409 |
|
---|
1410 | button = new QPushButton("Stop Computation", vbox);
|
---|
1411 | vbox->layout()->addWidget(button);
|
---|
1412 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
1413 |
|
---|
1414 | button = new QPushButton("Set Random View Point", vbox);
|
---|
1415 | vbox->layout()->addWidget(button);
|
---|
1416 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
|
---|
1417 |
|
---|
1418 |
|
---|
1419 | if (0) {
|
---|
1420 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1421 | layout()->addWidget(vbox);
|
---|
1422 |
|
---|
1423 | vl = new QVBoxLayout;
|
---|
1424 | vbox->setLayout(vl);
|
---|
1425 |
|
---|
1426 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
1427 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
1428 |
|
---|
1429 | connect(mPvsErrorWidget,
|
---|
1430 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
1431 | this,
|
---|
1432 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
1433 |
|
---|
1434 | QPushButton *button = new QPushButton("Next Error Frame", vbox);
|
---|
1435 | vbox->layout()->addWidget(button);
|
---|
1436 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | setWindowTitle("Preprocessor Control Widget");
|
---|
1440 | adjustSize();
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 |
|
---|
1444 |
|
---|
1445 |
|
---|
1446 | void
|
---|
1447 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
1448 | {
|
---|
1449 |
|
---|
1450 |
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | void
|
---|
1454 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
1455 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
1456 | {
|
---|
1457 |
|
---|
1458 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
1459 | QString s;
|
---|
1460 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
1461 | if (i) {
|
---|
1462 | i->setText(s);
|
---|
1463 | } else {
|
---|
1464 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
1465 | }
|
---|
1466 | mPvsErrorWidget->update();
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 |
|
---|
1470 | void QtGlDebuggerWidget::initializeGL()
|
---|
1471 | {
|
---|
1472 | glMatrixMode(GL_PROJECTION);
|
---|
1473 | glLoadIdentity();
|
---|
1474 |
|
---|
1475 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
1476 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
1477 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
1478 | glMatrixMode(GL_MODELVIEW);
|
---|
1479 |
|
---|
1480 | glEnable(GL_CULL_FACE);
|
---|
1481 | initCommon();
|
---|
1482 | initPbuffer();
|
---|
1483 |
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 |
|
---|
1487 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
1488 | {
|
---|
1489 | glViewport(0, 0, w, h);
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 |
|
---|
1493 | void QtGlDebuggerWidget::paintGL()
|
---|
1494 | {
|
---|
1495 | // draw a spinning cube into the pbuffer..
|
---|
1496 | mRenderBuffer->makeCurrent();
|
---|
1497 |
|
---|
1498 | BeamSampleStatistics stats;
|
---|
1499 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
1500 |
|
---|
1501 | glFlush();
|
---|
1502 |
|
---|
1503 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
1504 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
1505 |
|
---|
1506 | // and use the pbuffer contents as a texture when rendering the
|
---|
1507 | // background and the bouncing cubes
|
---|
1508 | makeCurrent();
|
---|
1509 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
1510 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
1511 |
|
---|
1512 | // draw the background
|
---|
1513 | glMatrixMode(GL_MODELVIEW);
|
---|
1514 | glPushMatrix();
|
---|
1515 | glLoadIdentity();
|
---|
1516 | glMatrixMode(GL_PROJECTION);
|
---|
1517 | glPushMatrix();
|
---|
1518 | glLoadIdentity();
|
---|
1519 |
|
---|
1520 | glPopMatrix();
|
---|
1521 | glMatrixMode(GL_MODELVIEW);
|
---|
1522 | glPopMatrix();
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 |
|
---|
1526 | void QtGlDebuggerWidget::initPbuffer()
|
---|
1527 | {
|
---|
1528 | // set up the pbuffer context
|
---|
1529 | mRenderBuffer->makeCurrent();
|
---|
1530 | /*mRenderBuffer->InitGL();
|
---|
1531 |
|
---|
1532 | glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
|
---|
1533 | glMatrixMode(GL_PROJECTION);
|
---|
1534 | glLoadIdentity();
|
---|
1535 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
1536 | glTranslatef(-0.5f, -0.5f, 0.0f);
|
---|
1537 | glMatrixMode(GL_MODELVIEW);
|
---|
1538 | glLoadIdentity();
|
---|
1539 |
|
---|
1540 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
|
---|
1541 |
|
---|
1542 | // generate a texture that has the same size/format as the pbuffer
|
---|
1543 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
1544 |
|
---|
1545 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
1546 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
1547 | makeCurrent();
|
---|
1548 | }
|
---|
1549 |
|
---|
1550 | void QtGlDebuggerWidget::initCommon()
|
---|
1551 | {
|
---|
1552 | glEnable(GL_TEXTURE_2D);
|
---|
1553 | glEnable(GL_DEPTH_TEST);
|
---|
1554 |
|
---|
1555 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 |
|
---|
1559 |
|
---|
1560 | }
|
---|