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 | SetupCameraProjection(width(), height());
|
---|
694 | SetupCamera();
|
---|
695 |
|
---|
696 | if (mRenderErrors) {
|
---|
697 | RenderErrors();
|
---|
698 | } else {
|
---|
699 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
700 | RenderPvs();
|
---|
701 | }
|
---|
702 | }
|
---|
703 |
|
---|
704 | RenderInfo();
|
---|
705 |
|
---|
706 | mFrame ++;
|
---|
707 |
|
---|
708 | }
|
---|
709 |
|
---|
710 |
|
---|
711 | void
|
---|
712 | QtGlRendererWidget::SetupCamera()
|
---|
713 | {
|
---|
714 | if (!mTopView)
|
---|
715 | GlRenderer::SetupCamera();
|
---|
716 | else {
|
---|
717 | if (0) {
|
---|
718 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
719 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
720 | -1,
|
---|
721 | mViewDirection.y);
|
---|
722 |
|
---|
723 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
724 | Vector3 up(0,1,0);
|
---|
725 |
|
---|
726 | glLoadIdentity();
|
---|
727 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
728 | target.x, target.y, target.z,
|
---|
729 | up.x, up.y, up.z);
|
---|
730 | } else {
|
---|
731 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance;
|
---|
732 | Vector3 pos = mViewPoint + dist*Vector3(0,
|
---|
733 | 1,
|
---|
734 | 0);
|
---|
735 |
|
---|
736 | Vector3 target = mViewPoint;
|
---|
737 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
738 |
|
---|
739 | glLoadIdentity();
|
---|
740 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
741 | target.x, target.y, target.z,
|
---|
742 | up.x, up.y, up.z);
|
---|
743 |
|
---|
744 | }
|
---|
745 | }
|
---|
746 |
|
---|
747 | }
|
---|
748 |
|
---|
749 |
|
---|
750 | void
|
---|
751 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
752 | {
|
---|
753 | switch (e->key()) {
|
---|
754 | case Qt::Key_T:
|
---|
755 | mTopView = !mTopView;
|
---|
756 | SetupCameraProjection(width(), height());
|
---|
757 | updateGL();
|
---|
758 | break;
|
---|
759 | case Qt::Key_V:
|
---|
760 | mRenderViewCells = !mRenderViewCells;
|
---|
761 | updateGL();
|
---|
762 | break;
|
---|
763 | case Qt::Key_P:
|
---|
764 | // set random viewpoint
|
---|
765 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
766 | updateGL();
|
---|
767 | break;
|
---|
768 | case Qt::Key_S: {
|
---|
769 | // set view poitn and direction
|
---|
770 | QString text;
|
---|
771 | bool ok;
|
---|
772 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
773 | text = QInputDialog::getText(this,
|
---|
774 | "Enter a view point",
|
---|
775 | "",
|
---|
776 | QLineEdit::Normal,
|
---|
777 | text,
|
---|
778 | &ok);
|
---|
779 | if (!ok)
|
---|
780 | break;
|
---|
781 |
|
---|
782 | if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
783 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
784 | text = QInputDialog::getText(this,
|
---|
785 | "Enter a direction",
|
---|
786 | "",
|
---|
787 | QLineEdit::Normal,
|
---|
788 | text,
|
---|
789 | &ok);
|
---|
790 | if (!ok)
|
---|
791 | break;
|
---|
792 | if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
793 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
794 | updateGL();
|
---|
795 | }
|
---|
796 | break;
|
---|
797 | }
|
---|
798 | }
|
---|
799 | default:
|
---|
800 | e->ignore();
|
---|
801 | break;
|
---|
802 | }
|
---|
803 | }
|
---|
804 |
|
---|
805 |
|
---|
806 |
|
---|
807 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
808 | SceneGraph *sceneGraph,
|
---|
809 | ViewCellsManager *viewcells,
|
---|
810 | KdTree *tree,
|
---|
811 | QWidget * parent,
|
---|
812 | const QGLWidget * shareWidget,
|
---|
813 | Qt::WFlags f
|
---|
814 | )
|
---|
815 | :
|
---|
816 | GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
817 | {
|
---|
818 | mPreprocessorThread = NULL;
|
---|
819 | mTopView = false;
|
---|
820 | mRenderViewCells = false;
|
---|
821 | mTopDistance = 1.0f;
|
---|
822 | mCutViewCells = false;
|
---|
823 | mCutScene = false;
|
---|
824 | mRenderErrors = false;
|
---|
825 | mRenderBoxes = false;
|
---|
826 | mRenderFilter = true;
|
---|
827 | mRenderVisibilityEstimates = false;
|
---|
828 | mTransferFunction = 0.2f;
|
---|
829 | mIndexBufferSize = 0;
|
---|
830 |
|
---|
831 | //mCurrentFrame = 0;
|
---|
832 |
|
---|
833 | const int delay = 500; // half a second
|
---|
834 | timerId = startTimer(delay);
|
---|
835 |
|
---|
836 | bool tmp;
|
---|
837 |
|
---|
838 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
839 | mUseFilter = tmp;
|
---|
840 |
|
---|
841 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
842 | tmp );
|
---|
843 | mUseSpatialFilter = tmp;
|
---|
844 |
|
---|
845 | mShowRenderCost = false;
|
---|
846 | mShowPvsSizes = false;
|
---|
847 | mSpatialFilterSize = 0.01;
|
---|
848 | mPvsSize = 0;
|
---|
849 | mRenderError = 0.0f;
|
---|
850 | mShowRays = false;
|
---|
851 |
|
---|
852 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
853 |
|
---|
854 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
855 | connect(mControlWidget,
|
---|
856 | SIGNAL(SetTransferFunction(int)),
|
---|
857 | this,
|
---|
858 | SLOT(SetTransferFunction(int)));
|
---|
859 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
860 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
861 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
862 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
|
---|
863 | SLOT(SetRandomViewPoint()));
|
---|
864 |
|
---|
865 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
866 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
867 |
|
---|
868 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
869 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
870 |
|
---|
871 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
872 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
873 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
874 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
875 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
876 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
877 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
878 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
879 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
880 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)),
|
---|
881 | this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
882 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
883 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
|
---|
884 | this, SLOT(SetUseSpatialFilter(bool)));
|
---|
885 |
|
---|
886 | connect(mControlWidget,
|
---|
887 | SIGNAL(SetShowRays(bool)),
|
---|
888 | this,
|
---|
889 | SLOT(SetShowRays(bool)));
|
---|
890 |
|
---|
891 | resize(1000, 500);
|
---|
892 | mControlWidget->show();
|
---|
893 | }
|
---|
894 |
|
---|
895 | void
|
---|
896 | QtGlRendererWidget::UpdateAllPvs()
|
---|
897 | {
|
---|
898 | // $$ does not work so far:(
|
---|
899 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
900 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
901 | }
|
---|
902 |
|
---|
903 | void
|
---|
904 | QtGlRendererWidget::ComputeVisibility()
|
---|
905 | {
|
---|
906 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
907 | if (!mPreprocessorThread->isRunning())
|
---|
908 | mPreprocessorThread->RunThread();
|
---|
909 | }
|
---|
910 |
|
---|
911 | void
|
---|
912 | QtGlRendererWidget::StopComputation()
|
---|
913 | {
|
---|
914 | cerr<<"stop computation called!\n"<<endl;
|
---|
915 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
916 | }
|
---|
917 |
|
---|
918 | void
|
---|
919 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
920 | {
|
---|
921 | cerr<<"stop computation called!\n"<<endl;
|
---|
922 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
923 | updateGL();
|
---|
924 | }
|
---|
925 |
|
---|
926 | void
|
---|
927 | QtGlRendererWidget::RenderRenderCost()
|
---|
928 | {
|
---|
929 | static vector<float> costFunction;
|
---|
930 | static float maxCost = -1;
|
---|
931 | if (costFunction.size()==0) {
|
---|
932 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
933 | if (tree) {
|
---|
934 | tree->GetCostFunction(costFunction);
|
---|
935 | maxCost = -1;
|
---|
936 | for (int i=0; i < costFunction.size(); i++) {
|
---|
937 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
938 | // update cost function to an absolute value based on the total geometry count
|
---|
939 | costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
|
---|
940 | if (costFunction[i] > maxCost)
|
---|
941 | maxCost = costFunction[i];
|
---|
942 | }
|
---|
943 | }
|
---|
944 | }
|
---|
945 |
|
---|
946 |
|
---|
947 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
948 | float currentCost= -1;
|
---|
949 |
|
---|
950 | if (currentPos < costFunction.size())
|
---|
951 | currentCost = costFunction[currentPos];
|
---|
952 | #if 1
|
---|
953 | cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
|
---|
954 | cout<<"CP="<<currentPos<<endl;
|
---|
955 | cout<<"MC="<<maxCost<<endl;
|
---|
956 | cout<<"CC="<<currentCost<<endl;
|
---|
957 | #endif
|
---|
958 | if (costFunction.size()) {
|
---|
959 | float scaley = 1.0f/log10(maxCost);
|
---|
960 | float scalex = 1.0f/(float)costFunction.size();
|
---|
961 |
|
---|
962 | glDisable(GL_DEPTH_TEST);
|
---|
963 | // init ortographic projection
|
---|
964 | glMatrixMode(GL_PROJECTION);
|
---|
965 |
|
---|
966 | glPushMatrix();
|
---|
967 |
|
---|
968 | glLoadIdentity();
|
---|
969 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
970 |
|
---|
971 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
972 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
973 | glMatrixMode(GL_MODELVIEW);
|
---|
974 | glLoadIdentity();
|
---|
975 |
|
---|
976 | glColor3f(1.0f,0,0);
|
---|
977 | glBegin(GL_LINE_STRIP);
|
---|
978 | // glVertex3f(0,0,0);
|
---|
979 |
|
---|
980 | for (int i=0; i < costFunction.size(); i++) {
|
---|
981 | float x = i*scalex;
|
---|
982 | float y = log10(costFunction[i])*scaley;
|
---|
983 | glVertex3f(x,y,0.0f);
|
---|
984 | }
|
---|
985 | glEnd();
|
---|
986 |
|
---|
987 | glColor3f(1.0f,0,0);
|
---|
988 | glBegin(GL_LINES);
|
---|
989 | float x = currentPos*scalex;
|
---|
990 | glVertex3f(x,0.0,0.0f);
|
---|
991 | glVertex3f(x,1.0f,0.0f);
|
---|
992 | glEnd();
|
---|
993 |
|
---|
994 | glColor3f(0.0f,0,0);
|
---|
995 | // show a grid
|
---|
996 | glBegin(GL_LINE_LOOP);
|
---|
997 | glVertex3f(0,0,0.0f);
|
---|
998 | glVertex3f(1,0,0.0f);
|
---|
999 | glVertex3f(1,1,0.0f);
|
---|
1000 | glVertex3f(0,1,0.0f);
|
---|
1001 | glEnd();
|
---|
1002 |
|
---|
1003 | glBegin(GL_LINES);
|
---|
1004 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
1005 | float x = i*scalex;
|
---|
1006 | glVertex3f(x,0.0,0.0f);
|
---|
1007 | glVertex3f(x,1.0f,0.0f);
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
1011 | float y = i*scaley;
|
---|
1012 | // QString s;
|
---|
1013 | // s.sprintf("%d", (int)pow(10,i));
|
---|
1014 | // renderText(width()/2+5, y*height(), s);
|
---|
1015 | glVertex3f(0.0f, y, 0.0f);
|
---|
1016 | glVertex3f(1.0f, y, 0.0f);
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | glEnd();
|
---|
1020 |
|
---|
1021 |
|
---|
1022 | // restore the projection matrix
|
---|
1023 | glMatrixMode(GL_PROJECTION);
|
---|
1024 | glPopMatrix();
|
---|
1025 | glMatrixMode(GL_MODELVIEW);
|
---|
1026 | glEnable(GL_DEPTH_TEST);
|
---|
1027 |
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | void
|
---|
1035 | QtGlRendererWidget::RenderInfo()
|
---|
1036 | {
|
---|
1037 |
|
---|
1038 | QString s;
|
---|
1039 | int vc = 0;
|
---|
1040 | if (mViewCellsManager)
|
---|
1041 | vc = (int)mViewCellsManager->GetViewCells().size();
|
---|
1042 |
|
---|
1043 | int filter = 0;
|
---|
1044 | if (mViewCellsManager)
|
---|
1045 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
1046 |
|
---|
1047 | glColor3f(1.0f,1.0f,1.0f);
|
---|
1048 |
|
---|
1049 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
1050 | mFrame,
|
---|
1051 | mViewPoint.x,
|
---|
1052 | mViewPoint.y,
|
---|
1053 | mViewPoint.z,
|
---|
1054 | mViewDirection.x,
|
---|
1055 | mViewDirection.y,
|
---|
1056 | mViewDirection.z
|
---|
1057 | );
|
---|
1058 |
|
---|
1059 | renderText(20,20,s);
|
---|
1060 |
|
---|
1061 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
|
---|
1062 | vc,
|
---|
1063 | filter,
|
---|
1064 | mPvsSize,
|
---|
1065 | mRenderError*100.0f);
|
---|
1066 |
|
---|
1067 |
|
---|
1068 | renderText(20,40,s);
|
---|
1069 |
|
---|
1070 |
|
---|
1071 |
|
---|
1072 |
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 |
|
---|
1076 | void
|
---|
1077 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
1078 | {
|
---|
1079 | if (mViewCellsManager) {
|
---|
1080 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
1081 |
|
---|
1082 | // $$ tmp off
|
---|
1083 | mViewCellsManager->CollectViewCells(number);
|
---|
1084 |
|
---|
1085 | // $$ does not work so far:(
|
---|
1086 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1087 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1088 | }
|
---|
1089 | updateGL();
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | void
|
---|
1093 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
1094 | {
|
---|
1095 | if (mViewCellsManager)
|
---|
1096 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
1097 | mPvsCache.Reset();
|
---|
1098 | updateGL();
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | void
|
---|
1102 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
1103 | {
|
---|
1104 | mSpatialFilterSize = 1e-3*number;
|
---|
1105 | mPvsCache.Reset();
|
---|
1106 | updateGL();
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | void
|
---|
1110 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
1111 | {
|
---|
1112 | // assume the cut plane can only be aligned with xz plane
|
---|
1113 | // shift it along y according to number, which is percentage of the bounding
|
---|
1114 | // box position
|
---|
1115 | if (mViewCellsManager) {
|
---|
1116 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1117 | Vector3 p = box.Min() + (number/1000.0f)*box.Max();
|
---|
1118 | mSceneCutPlane.mNormal = Vector3(0,-1,0);
|
---|
1119 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
1120 | updateGL();
|
---|
1121 | }
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | void
|
---|
1125 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1126 | {
|
---|
1127 | mTopDistance = number/1000.0f;
|
---|
1128 | updateGL();
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 | void
|
---|
1132 | QtGlRendererWidget::RenderViewCells()
|
---|
1133 | {
|
---|
1134 | mUseFalseColors = true;
|
---|
1135 |
|
---|
1136 | glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1137 |
|
---|
1138 | glEnable(GL_CULL_FACE);
|
---|
1139 | glCullFace(GL_FRONT);
|
---|
1140 |
|
---|
1141 | glDisable(GL_CULL_FACE);
|
---|
1142 | double eq[4];
|
---|
1143 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1144 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1145 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1146 | eq[3] = mSceneCutPlane.mD;
|
---|
1147 |
|
---|
1148 | if (mCutViewCells) {
|
---|
1149 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1150 | glEnable(GL_CLIP_PLANE0);
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | int i;
|
---|
1154 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1155 | int maxPvs = -1;
|
---|
1156 | for (i=0; i < viewcells.size(); i++)
|
---|
1157 | {
|
---|
1158 | ViewCell *vc = viewcells[i];
|
---|
1159 |
|
---|
1160 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1161 | const int p = vc->GetPvs().GetSize();
|
---|
1162 | if (p > maxPvs)
|
---|
1163 | maxPvs = p;
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 |
|
---|
1167 | for (i=0; i < viewcells.size(); i++) {
|
---|
1168 | ViewCell *vc = viewcells[i];
|
---|
1169 | // Mesh *m = vc->GetMesh();
|
---|
1170 |
|
---|
1171 | RgbColor c;
|
---|
1172 |
|
---|
1173 | if (!mShowPvsSizes) {
|
---|
1174 | mWireFrame = true;
|
---|
1175 | c = vc->GetColor();
|
---|
1176 | } else {
|
---|
1177 | // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
|
---|
1178 | const float importance = 5.0f*mTransferFunction *
|
---|
1179 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1180 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1181 | c = RainbowColorMapping(importance);
|
---|
1182 |
|
---|
1183 | }
|
---|
1184 | glColor3f(c.r, c.g, c.b);
|
---|
1185 |
|
---|
1186 | RenderViewCell(vc);
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | mUseFalseColors = false;
|
---|
1190 | mWireFrame = false;
|
---|
1191 |
|
---|
1192 | glPopAttrib();
|
---|
1193 |
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 |
|
---|
1197 |
|
---|
1198 | /*********************************************************************/
|
---|
1199 | /* QtGlDebuggerWidget implementation */
|
---|
1200 | /*********************************************************************/
|
---|
1201 |
|
---|
1202 |
|
---|
1203 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
1204 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
1205 | {
|
---|
1206 | // create the pbuffer
|
---|
1207 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
1208 | timerId = startTimer(20);
|
---|
1209 | setWindowTitle(("OpenGL pbuffers"));
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 |
|
---|
1213 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
1214 | {
|
---|
1215 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
1216 | glDeleteTextures(1, &dynamicTexture);
|
---|
1217 |
|
---|
1218 | DEL_PTR(mRenderBuffer);
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 |
|
---|
1222 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
1223 | QWidget(parent, f)
|
---|
1224 | {
|
---|
1225 |
|
---|
1226 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
1227 | setLayout(vl);
|
---|
1228 |
|
---|
1229 | QWidget *vbox = new QGroupBox("ViewCells", this);
|
---|
1230 | layout()->addWidget(vbox);
|
---|
1231 |
|
---|
1232 | vl = new QVBoxLayout;
|
---|
1233 | vbox->setLayout(vl);
|
---|
1234 |
|
---|
1235 | QLabel *label = new QLabel("Granularity");
|
---|
1236 | vbox->layout()->addWidget(label);
|
---|
1237 |
|
---|
1238 | QSlider *slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1239 | vl->addWidget(slider);
|
---|
1240 | slider->show();
|
---|
1241 | slider->setRange(1, 10000);
|
---|
1242 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1243 | slider->setValue(200);
|
---|
1244 |
|
---|
1245 |
|
---|
1246 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
1247 |
|
---|
1248 | label = new QLabel("Transfer function");
|
---|
1249 | vbox->layout()->addWidget(label);
|
---|
1250 |
|
---|
1251 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1252 | vl->addWidget(slider);
|
---|
1253 | slider->show();
|
---|
1254 | slider->setRange(1, 10000);
|
---|
1255 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1256 | slider->setValue(100);
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
1260 |
|
---|
1261 | {
|
---|
1262 | QPushButton *button = new QPushButton("Update all PVSs", vbox);
|
---|
1263 | vbox->layout()->addWidget(button);
|
---|
1264 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 |
|
---|
1268 | label = new QLabel("Filter size");
|
---|
1269 | vbox->layout()->addWidget(label);
|
---|
1270 |
|
---|
1271 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1272 | vbox->layout()->addWidget(slider);
|
---|
1273 | slider->show();
|
---|
1274 | slider->setRange(1, 100);
|
---|
1275 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1276 | slider->setValue(3);
|
---|
1277 |
|
---|
1278 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | label = new QLabel("Spatial Filter size");
|
---|
1282 | vbox->layout()->addWidget(label);
|
---|
1283 |
|
---|
1284 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1285 | vbox->layout()->addWidget(slider);
|
---|
1286 | slider->show();
|
---|
1287 | slider->setRange(1, 100);
|
---|
1288 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1289 | slider->setValue(10);
|
---|
1290 |
|
---|
1291 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
1292 |
|
---|
1293 |
|
---|
1294 |
|
---|
1295 | QWidget *hbox = new QWidget(vbox);
|
---|
1296 | vl->addWidget(hbox);
|
---|
1297 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
1298 | hbox->setLayout(hlayout);
|
---|
1299 |
|
---|
1300 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
1301 | hlayout->addWidget(cb);
|
---|
1302 | cb->setChecked(false);
|
---|
1303 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
1304 |
|
---|
1305 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
1306 | hlayout->addWidget(cb);
|
---|
1307 | cb->setChecked(false);
|
---|
1308 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
1309 |
|
---|
1310 | cb = new QCheckBox("Show render cost", hbox);
|
---|
1311 | hlayout->addWidget(cb);
|
---|
1312 | cb->setChecked(false);
|
---|
1313 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1314 |
|
---|
1315 | cb = new QCheckBox("Show rays", hbox);
|
---|
1316 | hlayout->addWidget(cb);
|
---|
1317 | cb->setChecked(false);
|
---|
1318 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
1319 |
|
---|
1320 | vbox->resize(800,100);
|
---|
1321 |
|
---|
1322 |
|
---|
1323 | vbox = new QGroupBox("Rendering", this);
|
---|
1324 | layout()->addWidget(vbox);
|
---|
1325 |
|
---|
1326 | vl = new QVBoxLayout;
|
---|
1327 | vbox->setLayout(vl);
|
---|
1328 |
|
---|
1329 |
|
---|
1330 |
|
---|
1331 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
1332 | vbox->layout()->addWidget(cb);
|
---|
1333 | cb->setChecked(false);
|
---|
1334 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
1335 |
|
---|
1336 |
|
---|
1337 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1338 | vbox->layout()->addWidget(slider);
|
---|
1339 | slider->show();
|
---|
1340 | slider->setRange(0, 1000);
|
---|
1341 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1342 | slider->setValue(1000);
|
---|
1343 |
|
---|
1344 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
1345 |
|
---|
1346 |
|
---|
1347 | cb = new QCheckBox("Cut scene", vbox);
|
---|
1348 | vbox->layout()->addWidget(cb);
|
---|
1349 | cb->setChecked(false);
|
---|
1350 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
1351 |
|
---|
1352 | cb = new QCheckBox("Render boxes", vbox);
|
---|
1353 | vbox->layout()->addWidget(cb);
|
---|
1354 | cb->setChecked(false);
|
---|
1355 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
1356 |
|
---|
1357 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
1358 | vbox->layout()->addWidget(cb);
|
---|
1359 | cb->setChecked(false);
|
---|
1360 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
1361 |
|
---|
1362 |
|
---|
1363 | cb = new QCheckBox("Render errors", vbox);
|
---|
1364 | vbox->layout()->addWidget(cb);
|
---|
1365 | cb->setChecked(false);
|
---|
1366 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
1367 |
|
---|
1368 |
|
---|
1369 | bool tmp;
|
---|
1370 |
|
---|
1371 | cb = new QCheckBox("Use filter", vbox);
|
---|
1372 | vbox->layout()->addWidget(cb);
|
---|
1373 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
1374 | cb->setChecked(tmp);
|
---|
1375 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
1376 |
|
---|
1377 |
|
---|
1378 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
1379 | vbox->layout()->addWidget(cb);
|
---|
1380 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
1381 | tmp );
|
---|
1382 | cb->setChecked(tmp);
|
---|
1383 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
1384 |
|
---|
1385 | cb = new QCheckBox("Render filter", vbox);
|
---|
1386 | vbox->layout()->addWidget(cb);
|
---|
1387 | cb->setChecked(true);
|
---|
1388 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
1389 |
|
---|
1390 |
|
---|
1391 |
|
---|
1392 |
|
---|
1393 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1394 | vbox->layout()->addWidget(slider);
|
---|
1395 | slider->show();
|
---|
1396 | slider->setRange(1, 1000);
|
---|
1397 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1398 | slider->setValue(500);
|
---|
1399 |
|
---|
1400 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
1401 |
|
---|
1402 | cb = new QCheckBox("Top View", vbox);
|
---|
1403 | vbox->layout()->addWidget(cb);
|
---|
1404 | cb->setChecked(false);
|
---|
1405 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1406 |
|
---|
1407 |
|
---|
1408 |
|
---|
1409 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1410 | layout()->addWidget(vbox);
|
---|
1411 |
|
---|
1412 | vl = new QVBoxLayout;
|
---|
1413 | vbox->setLayout(vl);
|
---|
1414 |
|
---|
1415 | QPushButton *button = new QPushButton("Compute Visibility", vbox);
|
---|
1416 | vbox->layout()->addWidget(button);
|
---|
1417 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
1418 |
|
---|
1419 | button = new QPushButton("Stop Computation", vbox);
|
---|
1420 | vbox->layout()->addWidget(button);
|
---|
1421 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
1422 |
|
---|
1423 | button = new QPushButton("Set Random View Point", vbox);
|
---|
1424 | vbox->layout()->addWidget(button);
|
---|
1425 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
|
---|
1426 |
|
---|
1427 |
|
---|
1428 | if (0) {
|
---|
1429 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1430 | layout()->addWidget(vbox);
|
---|
1431 |
|
---|
1432 | vl = new QVBoxLayout;
|
---|
1433 | vbox->setLayout(vl);
|
---|
1434 |
|
---|
1435 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
1436 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
1437 |
|
---|
1438 | connect(mPvsErrorWidget,
|
---|
1439 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
1440 | this,
|
---|
1441 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
1442 |
|
---|
1443 | QPushButton *button = new QPushButton("Next Error Frame", vbox);
|
---|
1444 | vbox->layout()->addWidget(button);
|
---|
1445 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
1446 | }
|
---|
1447 |
|
---|
1448 | setWindowTitle("Preprocessor Control Widget");
|
---|
1449 | adjustSize();
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 |
|
---|
1453 |
|
---|
1454 |
|
---|
1455 | void
|
---|
1456 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
1457 | {
|
---|
1458 |
|
---|
1459 |
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | void
|
---|
1463 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
1464 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
1465 | {
|
---|
1466 |
|
---|
1467 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
1468 | QString s;
|
---|
1469 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
1470 | if (i) {
|
---|
1471 | i->setText(s);
|
---|
1472 | } else {
|
---|
1473 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
1474 | }
|
---|
1475 | mPvsErrorWidget->update();
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 |
|
---|
1479 | void QtGlDebuggerWidget::initializeGL()
|
---|
1480 | {
|
---|
1481 | glMatrixMode(GL_PROJECTION);
|
---|
1482 | glLoadIdentity();
|
---|
1483 |
|
---|
1484 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
1485 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
1486 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
1487 | glMatrixMode(GL_MODELVIEW);
|
---|
1488 |
|
---|
1489 | glEnable(GL_CULL_FACE);
|
---|
1490 | initCommon();
|
---|
1491 | initPbuffer();
|
---|
1492 |
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 |
|
---|
1496 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
1497 | {
|
---|
1498 | glViewport(0, 0, w, h);
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 |
|
---|
1502 | void QtGlDebuggerWidget::paintGL()
|
---|
1503 | {
|
---|
1504 | // draw a spinning cube into the pbuffer..
|
---|
1505 | mRenderBuffer->makeCurrent();
|
---|
1506 |
|
---|
1507 | BeamSampleStatistics stats;
|
---|
1508 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
1509 |
|
---|
1510 | glFlush();
|
---|
1511 |
|
---|
1512 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
1513 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
1514 |
|
---|
1515 | // and use the pbuffer contents as a texture when rendering the
|
---|
1516 | // background and the bouncing cubes
|
---|
1517 | makeCurrent();
|
---|
1518 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
1519 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
1520 |
|
---|
1521 | // draw the background
|
---|
1522 | glMatrixMode(GL_MODELVIEW);
|
---|
1523 | glPushMatrix();
|
---|
1524 | glLoadIdentity();
|
---|
1525 | glMatrixMode(GL_PROJECTION);
|
---|
1526 | glPushMatrix();
|
---|
1527 | glLoadIdentity();
|
---|
1528 |
|
---|
1529 | glPopMatrix();
|
---|
1530 | glMatrixMode(GL_MODELVIEW);
|
---|
1531 | glPopMatrix();
|
---|
1532 | }
|
---|
1533 |
|
---|
1534 |
|
---|
1535 | void QtGlDebuggerWidget::initPbuffer()
|
---|
1536 | {
|
---|
1537 | // set up the pbuffer context
|
---|
1538 | mRenderBuffer->makeCurrent();
|
---|
1539 | /*mRenderBuffer->InitGL();
|
---|
1540 |
|
---|
1541 | glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
|
---|
1542 | glMatrixMode(GL_PROJECTION);
|
---|
1543 | glLoadIdentity();
|
---|
1544 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
1545 | glTranslatef(-0.5f, -0.5f, 0.0f);
|
---|
1546 | glMatrixMode(GL_MODELVIEW);
|
---|
1547 | glLoadIdentity();
|
---|
1548 |
|
---|
1549 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
|
---|
1550 |
|
---|
1551 | // generate a texture that has the same size/format as the pbuffer
|
---|
1552 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
1553 |
|
---|
1554 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
1555 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
1556 | makeCurrent();
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | void QtGlDebuggerWidget::initCommon()
|
---|
1560 | {
|
---|
1561 | glEnable(GL_TEXTURE_2D);
|
---|
1562 | glEnable(GL_DEPTH_TEST);
|
---|
1563 |
|
---|
1564 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
1565 | }
|
---|
1566 |
|
---|
1567 |
|
---|
1568 |
|
---|
1569 | }
|
---|