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