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