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