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