source: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp @ 1948

Revision 1948, 34.7 KB checked in by mattausch, 17 years ago (diff)
Line 
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
27namespace GtpVisibilityPreprocessor {
28
29
30 
31class ViewCellsManager;
32
33static CGcontext sCgContext = NULL;
34static CGprogram sCgFragmentProgram = NULL;
35static CGprofile sCgFragmentProfile;
36
37
38//static vector<OcclusionQuery *> sQueries;
39
40QtGlRendererWidget *rendererWidget = NULL;
41QtGlDebuggerWidget *debuggerWidget = NULL;
42
43
44static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
45{
46        return obj1->mId < obj2->mId;
47}
48
49#if USE_CG
50static void handleCgError()
51{
52    Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
53    exit(1);
54}
55#endif
56
57void
58QtGlRendererBuffer::MakeCurrent()
59{
60  makeCurrent();
61}
62
63void
64QtGlRendererBuffer::DoneCurrent()
65{
66  doneCurrent();
67}
68 
69
70QtGlRendererBuffer::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
86float
87QtGlRendererBuffer::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
257int
258QtGlRendererBuffer::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
306
307
308void
309QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
310{
311  if (!mTopView) {
312        int ww = w;
313        int hh = h;
314        glViewport(0, 0, ww, hh);
315        glMatrixMode(GL_PROJECTION);
316        glLoadIdentity();
317        gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
318        glMatrixMode(GL_MODELVIEW);
319  } else {
320        int ww = w;
321        int hh = h;
322        glViewport(0, 0, ww, hh);
323        glMatrixMode(GL_PROJECTION);
324        glLoadIdentity();
325        gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
326        glMatrixMode(GL_MODELVIEW);
327  }
328}
329
330
331
332void
333QtGlRendererWidget::RenderPvs()
334{
335       
336  Intersectable::NewMail();
337
338  ViewCell *viewcell = NULL;
339
340  PrVs prvs;
341 
342  if (1 || !mUseFilter) {
343        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
344  } else {
345        //  mViewCellsManager->SetMaxFilterSize(1);
346        mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth());
347        viewcell = prvs.mViewCell;
348  }
349 
350  if (viewcell) {
351        // copy the pvs so that it can be filtered...
352       
353        //      mPvsCache.mPvs;
354       
355        if (mPvsCache.mViewCell != viewcell) {
356          mPvsCache.Reset();
357          mPvsCache.mViewCell = viewcell;
358         
359          if (mUseSpatialFilter) {
360                // 9.11. 2006 -> experiment with new spatial filter
361#if 0
362                mViewCellsManager->ApplySpatialFilter(mKdTree,
363                                                                                          mSpatialFilterSize*
364                                                                                          Magnitude(mViewCellsManager->GetViewSpaceBox().Size()),
365                                                                                          mPvsCache.mPvs);
366#else
367                // mSpatialFilter size is in range 0.001 - 0.1
368                mViewCellsManager->ApplyFilter2(viewcell,
369                                                                                mUseFilter,
370                                                                                100*mSpatialFilterSize,
371                                                                                mPvsCache.mPvs,
372                                                                                &mPvsCache.filteredBoxes
373                                                                                );
374#endif
375          } else
376                mPvsCache.mPvs = viewcell->GetPvs();
377         
378          emit PvsUpdated();
379        }
380
381        // Render PVS
382        if (mUseSpatialFilter && mRenderBoxes) {
383                for (int i=0; i < mPvsCache.filteredBoxes.size(); i++)
384                        RenderBox(mPvsCache.filteredBoxes[i]);
385        } else {
386                ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
387               
388                mPvsSize = mPvsCache.mPvs.GetSize();
389                for (; it.HasMoreEntries(); ) {
390                        ObjectPvsEntry entry = it.Next();
391                        Intersectable *object = entry.mObject;
392                       
393                        if (mRenderVisibilityEstimates) {
394                               
395                                float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
396                                glColor3f(visibility, 0.0f, 0.0f);
397                                mUseForcedColors = true;
398                                RenderIntersectable(object);
399                                mUseForcedColors = false;
400                        } else {
401                                mUseForcedColors = false;
402                                RenderIntersectable(object);
403                        }
404                }
405        }
406
407        if (mRenderFilter) {
408          mWireFrame = true;
409          RenderIntersectable(viewcell);
410          glPushMatrix();
411          glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
412          glScalef(5.0f,5.0f,5.0f);
413          glPushAttrib(GL_CURRENT_BIT);
414          glColor3f(1.0f, 0.0f, 0.0f);
415          gluSphere((::GLUquadric *)mSphere,
416                                                        1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
417          glPopAttrib();
418          glPopMatrix();
419          mWireFrame = false;
420        }
421       
422        if (0 && mUseFilter)
423          mViewCellsManager->DeleteLocalMergeTree(viewcell);
424
425  } else {
426                ObjectContainer::const_iterator oi = mObjects.begin();
427                for (; oi != mObjects.end(); oi++)
428                        RenderIntersectable(*oi);
429  }
430}
431
432float
433QtGlRendererWidget::RenderErrors()
434{
435  float pErrorPixels = -1.0f;
436
437  glReadBuffer(GL_BACK);
438 
439  mUseFalseColors = true;
440
441  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
442 
443  double eq[4];
444  eq[0] = mSceneCutPlane.mNormal.x;
445  eq[1] = mSceneCutPlane.mNormal.y;
446  eq[2] = mSceneCutPlane.mNormal.z;
447  eq[3] = mSceneCutPlane.mD;
448 
449  if (mCutScene) {
450        glClipPlane(GL_CLIP_PLANE0, eq);
451    glEnable(GL_CLIP_PLANE0);
452  }
453 
454  if (mDetectEmptyViewSpace)
455        glEnable( GL_CULL_FACE );
456  else
457        glDisable( GL_CULL_FACE );
458
459  ObjectContainer::const_iterator oi = mObjects.begin();
460  for (; oi != mObjects.end(); oi++)
461        RenderIntersectable(*oi);
462
463  ViewCell *viewcell = NULL;
464
465  QImage im1, im2;
466  QImage diff;
467 
468  if (viewcell) {
469        // read back the texture
470        im1 = grabFrameBuffer(true);
471       
472        RenderPvs();
473
474        // read back the texture
475        im2 = grabFrameBuffer(true);
476       
477        diff = im1;
478        int x, y;
479        int errorPixels = 0;
480       
481        for (y = 0; y < im1.height(); y++)
482          for (x = 0; x < im1.width(); x++)
483                if (im1.pixel(x, y) == im2.pixel(x, y))
484                  diff.setPixel(x, y, qRgba(0,0,0,0));
485                else {
486                  diff.setPixel(x, y, qRgba(255,128,128,255));
487                  errorPixels++;
488                }
489        pErrorPixels = ((float)errorPixels)/(im1.height()*im1.width());
490  }
491
492  // now render the pvs again
493  SetupCamera();
494  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
495  mUseFalseColors = false;
496 
497  oi = mObjects.begin();
498  for (; oi != mObjects.end(); oi++)
499        RenderIntersectable(*oi);
500
501  // now render im1
502  if (viewcell) {
503        if (0 && mTopView) {
504          mWireFrame = true;
505          RenderIntersectable(viewcell);
506          mWireFrame = false;
507        }
508       
509        // init ortographic projection
510        glMatrixMode(GL_PROJECTION);
511        glPushMatrix();
512       
513        glLoadIdentity();
514        gluOrtho2D(0, 1.0f, 0, 1.0f);
515       
516        glMatrixMode(GL_MODELVIEW);
517        glLoadIdentity();
518       
519        bindTexture(diff);
520       
521        glPushAttrib(GL_ENABLE_BIT);
522        glEnable( GL_ALPHA_TEST );
523        glDisable( GL_CULL_FACE );
524        glAlphaFunc( GL_GREATER, 0.5 );
525       
526        glEnable( GL_TEXTURE_2D );
527        glBegin(GL_QUADS);
528       
529        glTexCoord2f(0,0);
530        glVertex3f(0,0,0);
531       
532        glTexCoord2f(1,0);
533        glVertex3f( 1, 0, 0);
534       
535        glTexCoord2f(1,1);
536        glVertex3f( 1, 1, 0);
537       
538        glTexCoord2f(0,1);
539        glVertex3f(0, 1, 0);
540        glEnd();
541       
542        glPopAttrib();
543       
544        // restore the projection matrix
545        glMatrixMode(GL_PROJECTION);
546        glPopMatrix();
547        glMatrixMode(GL_MODELVIEW);
548  }
549
550  glDisable(GL_CLIP_PLANE0);
551 
552  mRenderError = pErrorPixels;
553  return pErrorPixels;
554}
555
556
557void
558QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
559{
560  int x = e->pos().x();
561  int y = e->pos().y();
562
563  mousePoint.x = x;
564  mousePoint.y = y;
565 
566}
567
568void
569QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
570{
571  float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
572  float TURN_SENSITIVITY=0.1f;
573  float TILT_SENSITIVITY=32.0 ;
574  float TURN_ANGLE= M_PI/36.0 ;
575
576  int x = e->pos().x();
577  int y = e->pos().y();
578
579  int diffx = -(mousePoint.x - x);
580  int diffy = -(mousePoint.y - y);
581 
582  if (e->modifiers() & Qt::ControlModifier) {
583        mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
584        mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
585  } else {
586        mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
587        float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
588        float angle = atan2(mViewDirection.x, mViewDirection.z);
589        mViewDirection.x = sin(angle+adiff);
590        mViewDirection.z = cos(angle+adiff);
591  }
592 
593  mousePoint.x = x;
594  mousePoint.y = y;
595 
596  updateGL();
597}
598
599void
600QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
601{
602
603
604}
605
606void
607QtGlRendererWidget::resizeGL(int w, int h)
608{
609  SetupCameraProjection(w, h);
610  updateGL();
611}
612
613void
614QtGlRendererWidget::paintGL()
615{
616  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
617
618  if (1) {
619        SetupCameraProjection(width(), height());
620        SetupCamera();
621       
622        if (mRenderErrors) {
623          RenderErrors();
624        } else {
625          RenderPvs();
626        }
627       
628  }
629
630  RenderInfo();
631
632  mFrame++;
633 
634}
635
636
637void
638QtGlRendererWidget::SetupCamera()
639{
640  if (!mTopView)
641        GlRenderer::SetupCamera();
642  else {
643        if (0) {
644          float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
645          Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
646                                                                                          -1,
647                                                                                          mViewDirection.y);
648         
649          Vector3 target = mViewPoint + dist*mViewDirection;
650          Vector3 up(0,1,0);
651         
652          glLoadIdentity();
653          gluLookAt(pos.x, pos.y, pos.z,
654                                target.x, target.y, target.z,
655                                up.x, up.y, up.z);
656        } else {
657          float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance;
658          Vector3 pos = mViewPoint  + dist*Vector3(0,
659                                                                                           1,
660                                                                                           0);
661         
662          Vector3 target = mViewPoint;
663          Vector3 up(mViewDirection.x, 0, mViewDirection.z);
664         
665          glLoadIdentity();
666          gluLookAt(pos.x, pos.y, pos.z,
667                                target.x, target.y, target.z,
668                                up.x, up.y, up.z);
669         
670        }
671  }
672
673}
674
675
676void
677QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
678{
679  switch (e->key()) {
680  case Qt::Key_T:
681        mTopView = !mTopView;
682        SetupCameraProjection(width(), height());
683        updateGL();
684        break;
685  case Qt::Key_V:
686        mRenderViewCells = !mRenderViewCells;
687        updateGL();
688        break;
689  case Qt::Key_P:
690        // set random viewpoint
691        mViewCellsManager->GetViewPoint(mViewPoint);
692        updateGL();
693        break;
694
695  default:
696        e->ignore();
697        break;
698  }
699}
700
701 
702
703QtGlRendererWidget::QtGlRendererWidget(
704                                                                           SceneGraph *sceneGraph,
705                                                                           ViewCellsManager *viewcells,
706                                                                           KdTree *tree,
707                                                                           QWidget * parent,
708                                                                           const QGLWidget * shareWidget,
709                                                                           Qt::WFlags f
710                                                                           )
711  :
712  GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
713{
714  mPreprocessorThread = NULL;
715  mTopView = false;
716  mRenderViewCells = false;
717  mTopDistance = 1.0f;
718  mCutViewCells = false;
719  mCutScene = false;
720  mRenderErrors = false;
721  mRenderBoxes = false;
722  mRenderFilter = true;
723  mRenderVisibilityEstimates = false;
724  mTransferFunction = 0.2f;
725
726  bool tmp;
727
728  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
729  mUseFilter = tmp;
730 
731  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
732                                                        tmp );
733  mUseSpatialFilter = tmp;
734
735  mShowRenderCost = false;
736  mShowPvsSizes = false;
737  mSpatialFilterSize = 0.01;
738  mPvsSize = 0;
739  mRenderError = 0.0f;
740  mShowRays = false;
741 
742  mControlWidget = new QtRendererControlWidget(NULL);
743 
744  connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
745  connect(mControlWidget,
746                  SIGNAL(SetTransferFunction(int)),
747                  this,
748                  SLOT(SetTransferFunction(int)));
749  connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
750  connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
751  connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
752  connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
753                  SLOT(SetRandomViewPoint()));
754
755  connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
756  connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
757
758  connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
759  connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
760
761  connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
762  connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
763  connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
764  connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
765  connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
766  connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
767  connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
768  connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
769  connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
770  connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)),
771                  this, SLOT(SetRenderVisibilityEstimates(bool)));
772  connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
773  connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
774                  this, SLOT(SetUseSpatialFilter(bool)));
775
776  connect(mControlWidget,
777                  SIGNAL(SetShowRays(bool)),
778                  this,
779                  SLOT(SetShowRays(bool)));
780
781  resize(1000, 500);
782  mControlWidget->show();
783}
784
785void
786QtGlRendererWidget::UpdateAllPvs()
787{
788  // $$ does not work so far:(
789  mViewCellsManager->UpdatePvsForEvaluation();
790  //    mViewCellsManager->FinalizeViewCells(false);
791}
792
793void
794QtGlRendererWidget::ComputeVisibility()
795{
796  cerr<<"Compute Visibility called!\n"<<endl;
797  if (!mPreprocessorThread->isRunning())
798        mPreprocessorThread->RunThread();
799}
800
801void
802QtGlRendererWidget::StopComputation()
803{
804  cerr<<"stop computation called!\n"<<endl;
805  mViewCellsManager->GetPreprocessor()->mStopComputation = true;
806}
807
808void
809QtGlRendererWidget::SetRandomViewPoint()
810{
811  cerr<<"stop computation called!\n"<<endl;
812  mViewCellsManager->GetViewPoint(mViewPoint);
813  updateGL();
814}
815
816void
817QtGlRendererWidget::RenderRenderCost()
818{
819        static vector<float> costFunction;
820        static float maxCost = -1;
821        if (costFunction.size()==0) {
822          ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
823          if (tree) {
824                tree->GetCostFunction(costFunction);
825                maxCost = -1;
826                for (int i=0;  i < costFunction.size(); i++) {
827                  //              cout<<i<<":"<<costFunction[i]<<" ";
828                  // update cost function to an absolute value based on the total geometry count
829                  costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
830                  if (costFunction[i] > maxCost)
831                        maxCost = costFunction[i];
832                }
833          }
834        }
835
836       
837        int currentPos = (int)mViewCellsManager->GetViewCells().size();
838        float currentCost= -1;
839
840        if (currentPos < costFunction.size())
841          currentCost = costFunction[currentPos];
842#if 1   
843        cout<<"costFunction.size()="<<costFunction.size()<<endl;
844        cout<<"CP="<<currentPos<<endl;
845        cout<<"MC="<<maxCost<<endl;
846        cout<<"CC="<<currentCost<<endl;
847#endif
848        if (costFunction.size()) {
849          float scaley = 1.0f/log10(maxCost);
850          float scalex = 1.0f/(float)costFunction.size();
851
852          glDisable(GL_DEPTH_TEST);
853          // init ortographic projection
854          glMatrixMode(GL_PROJECTION);
855         
856          glPushMatrix();
857         
858          glLoadIdentity();
859          gluOrtho2D(0, 1.0f, 0, 1.0f);
860         
861          glTranslatef(0.1f, 0.1f, 0.0f);
862          glScalef(0.8f, 0.8f, 1.0f);
863          glMatrixMode(GL_MODELVIEW);
864          glLoadIdentity();
865         
866          glColor3f(1.0f,0,0);
867          glBegin(GL_LINE_STRIP);
868          //      glVertex3f(0,0,0);
869         
870          for (int i=0;  i < costFunction.size(); i++) {
871                float x =  i*scalex;
872                float y = log10(costFunction[i])*scaley;
873                glVertex3f(x,y,0.0f);
874          }
875          glEnd();
876         
877          glColor3f(1.0f,0,0);
878          glBegin(GL_LINES);
879          float x =  currentPos*scalex;
880          glVertex3f(x,0.0,0.0f);
881          glVertex3f(x,1.0f,0.0f);
882          glEnd();
883         
884          glColor3f(0.0f,0,0);
885          // show a grid
886          glBegin(GL_LINE_LOOP);
887          glVertex3f(0,0,0.0f);
888          glVertex3f(1,0,0.0f);
889          glVertex3f(1,1,0.0f);
890          glVertex3f(0,1,0.0f);
891          glEnd();
892
893          glBegin(GL_LINES);
894          for (int i=0;  i < costFunction.size(); i += 1000) {
895                float x =  i*scalex;
896                glVertex3f(x,0.0,0.0f);
897                glVertex3f(x,1.0f,0.0f);
898          }
899
900          for (int i=0;  pow(10.0f, i) < maxCost; i+=1) {
901                float y = i*scaley;
902                //              QString s;
903                //              s.sprintf("%d", (int)pow(10,i));
904                //              renderText(width()/2+5, y*height(), s);
905                glVertex3f(0.0f, y, 0.0f);
906                glVertex3f(1.0f, y, 0.0f);
907          }
908
909          glEnd();
910
911         
912          // restore the projection matrix
913          glMatrixMode(GL_PROJECTION);
914          glPopMatrix();
915          glMatrixMode(GL_MODELVIEW);
916          glEnable(GL_DEPTH_TEST);
917
918        }
919 
920
921
922}
923
924void
925QtGlRendererWidget::RenderInfo()
926{
927 
928  QString s;
929  int vc = 0;
930  if (mViewCellsManager)
931        vc = mViewCellsManager->GetViewCells().size();
932  int filter = 0;
933  if (mViewCellsManager)
934        filter = mViewCellsManager->GetMaxFilterSize();
935
936  glColor3f(1.0f,1.0f,1.0f);
937
938  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
939                        mFrame,
940                        mViewPoint.x,
941                        mViewPoint.y,
942                        mViewPoint.z,
943                        mViewDirection.x,
944                        mViewDirection.y,
945                        mViewDirection.z
946                        );
947
948  renderText(20,20,s);
949
950  s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
951                        vc,
952                        filter,
953                        mPvsSize,
954                        mRenderError*100.0f);
955
956
957  renderText(20,40,s);
958
959 
960
961 
962}
963
964
965void
966QtGlRendererWidget::SetViewCellGranularity(int number)
967{
968  if (mViewCellsManager) {
969        //      mViewCellsManager->SetMaxFilterSize(number);
970    mViewCellsManager->CollectViewCells(number);
971
972        // $$ does not work so far:(
973        //      mViewCellsManager->UpdatePvsForEvaluation();
974        //      mViewCellsManager->FinalizeViewCells(false);
975  }
976  updateGL();
977}
978
979void
980QtGlRendererWidget::SetVisibilityFilterSize(int number)
981{
982  if (mViewCellsManager)
983        mViewCellsManager->SetMaxFilterSize(number);
984  mPvsCache.Reset();
985  updateGL();
986}
987
988void
989QtGlRendererWidget::SetSpatialFilterSize(int number)
990{
991  mSpatialFilterSize = 1e-3*number;
992  mPvsCache.Reset();
993  updateGL();
994}
995
996void
997QtGlRendererWidget::SetSceneCut(int number)
998{
999  // assume the cut plane can only be aligned with xz plane
1000  // shift it along y according to number, which is percentage of the bounding
1001  // box position
1002  if (mViewCellsManager) {
1003        AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
1004        Vector3 p = box.Min() + (number/1000.0f)*box.Max();
1005        mSceneCutPlane.mNormal = Vector3(0,-1,0);
1006        mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
1007        updateGL();
1008  }
1009}
1010
1011void
1012QtGlRendererWidget::SetTopDistance(int number)
1013{
1014  mTopDistance = number/1000.0f;
1015  updateGL();
1016}
1017
1018void
1019QtGlRendererWidget::RenderViewCells()
1020{
1021  mUseFalseColors = true;
1022
1023  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
1024 
1025  glEnable(GL_CULL_FACE);
1026  //glDisable(GL_CULL_FACE);
1027  glCullFace(GL_FRONT);
1028  double eq[4];
1029  eq[0] = mSceneCutPlane.mNormal.x;
1030  eq[1] = mSceneCutPlane.mNormal.y;
1031  eq[2] = mSceneCutPlane.mNormal.z;
1032  eq[3] = mSceneCutPlane.mD;
1033
1034  if (mCutViewCells) {
1035        glClipPlane(GL_CLIP_PLANE0, eq);
1036        glEnable(GL_CLIP_PLANE0);
1037  }
1038 
1039  int i;
1040  ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
1041  int maxPvs = -1;
1042  for (i=0; i < viewcells.size(); i++)
1043  {
1044        ViewCell *vc = viewcells[i];
1045
1046        //const int p = vc->GetPvs().CountObjectsInPvs();
1047        const int p = vc->GetPvs().GetSize();
1048        if (p > maxPvs)
1049          maxPvs = p;
1050  }
1051
1052
1053  for (i=0; i < viewcells.size(); i++) {
1054        ViewCell *vc = viewcells[i];
1055        //      Mesh *m = vc->GetMesh();
1056
1057
1058        RgbColor c;
1059
1060        if (!mShowPvsSizes) {
1061          mWireFrame = true;
1062          c = vc->GetColor();
1063        } else {
1064          //      const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
1065          const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().GetSize() / (float)maxPvs);
1066          c = RgbColor(importance, 1.0f - importance, 0.0f);
1067        }
1068        glColor3f(c.r, c.g, c.b);
1069       
1070        RenderViewCell(vc);
1071  }
1072
1073  mUseFalseColors = false;
1074  mWireFrame = false;
1075
1076  glPopAttrib();
1077 
1078}
1079
1080
1081
1082
1083
1084/***********************************************************************/
1085/*                     QtGlDebuggerWidget implementation                                   */
1086/***********************************************************************/
1087
1088
1089QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
1090      : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
1091{
1092        // create the pbuffer
1093    //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
1094    timerId = startTimer(20);
1095    setWindowTitle(("OpenGL pbuffers"));
1096}
1097
1098
1099QtGlDebuggerWidget::~QtGlDebuggerWidget()
1100{
1101 mRenderBuffer->releaseFromDynamicTexture();
1102   glDeleteTextures(1, &dynamicTexture);
1103         
1104         DEL_PTR(mRenderBuffer);
1105}
1106
1107
1108
1109QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
1110  QWidget(parent, f)
1111{
1112
1113  QVBoxLayout *vl = new QVBoxLayout;
1114  setLayout(vl);
1115 
1116  QWidget *vbox = new QGroupBox("ViewCells", this);
1117  layout()->addWidget(vbox);
1118 
1119  vl = new QVBoxLayout;
1120  vbox->setLayout(vl);
1121
1122  QLabel *label = new QLabel("Granularity");
1123  vbox->layout()->addWidget(label);
1124 
1125  QSlider *slider = new QSlider(Qt::Horizontal, vbox);
1126  vl->addWidget(slider);
1127  slider->show();
1128  slider->setRange(1, 10000);
1129  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1130  slider->setValue(200);
1131
1132 
1133  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
1134
1135  label = new QLabel("Transfer function");
1136  vbox->layout()->addWidget(label);
1137 
1138  slider = new QSlider(Qt::Horizontal, vbox);
1139  vl->addWidget(slider);
1140  slider->show();
1141  slider->setRange(1, 1000);
1142  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1143  slider->setValue(100);
1144
1145 
1146  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
1147
1148  {
1149        QPushButton *button = new QPushButton("Update all PVSs", vbox);
1150        vbox->layout()->addWidget(button);
1151        connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
1152  }
1153 
1154 
1155  label = new QLabel("Filter size");
1156  vbox->layout()->addWidget(label);
1157 
1158  slider = new QSlider(Qt::Horizontal, vbox);
1159  vbox->layout()->addWidget(slider);
1160  slider->show();
1161  slider->setRange(1, 100);
1162  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1163  slider->setValue(3);
1164 
1165  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
1166
1167
1168  label = new QLabel("Spatial Filter size");
1169  vbox->layout()->addWidget(label);
1170 
1171  slider = new QSlider(Qt::Horizontal, vbox);
1172  vbox->layout()->addWidget(slider);
1173  slider->show();
1174  slider->setRange(1, 100);
1175  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1176  slider->setValue(10);
1177 
1178  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
1179
1180
1181
1182  QWidget *hbox = new QWidget(vbox);
1183  vl->addWidget(hbox);
1184  QHBoxLayout *hlayout = new QHBoxLayout;
1185  hbox->setLayout(hlayout);
1186 
1187  QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
1188  hlayout->addWidget(cb);
1189  cb->setChecked(false);
1190  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
1191
1192  cb = new QCheckBox("Render cost curve", hbox);
1193  hlayout->addWidget(cb);
1194  cb->setChecked(false);
1195  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
1196
1197  cb = new QCheckBox("Show render cost", hbox);
1198  hlayout->addWidget(cb);
1199  cb->setChecked(false);
1200  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
1201
1202  cb = new QCheckBox("Show rays", hbox);
1203  hlayout->addWidget(cb);
1204  cb->setChecked(false);
1205  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
1206
1207  vbox->resize(800,100);
1208
1209 
1210  vbox = new QGroupBox("Rendering", this);
1211  layout()->addWidget(vbox);
1212 
1213  vl = new QVBoxLayout;
1214  vbox->setLayout(vl);
1215
1216
1217
1218  cb = new QCheckBox("Cut view cells", vbox);
1219  vbox->layout()->addWidget(cb);
1220  cb->setChecked(false);
1221  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
1222
1223
1224  slider = new QSlider(Qt::Horizontal, vbox);
1225  vbox->layout()->addWidget(slider);
1226  slider->show();
1227  slider->setRange(0, 1000);
1228  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1229  slider->setValue(1000);
1230
1231  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
1232
1233
1234  cb = new QCheckBox("Cut scene", vbox);
1235  vbox->layout()->addWidget(cb);
1236  cb->setChecked(false);
1237  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
1238
1239  cb = new QCheckBox("Render boxes", vbox);
1240  vbox->layout()->addWidget(cb);
1241  cb->setChecked(false);
1242  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
1243
1244  cb = new QCheckBox("Render visibility estimates", vbox);
1245  vbox->layout()->addWidget(cb);
1246  cb->setChecked(false);
1247  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
1248
1249 
1250  cb = new QCheckBox("Render errors", vbox);
1251  vbox->layout()->addWidget(cb);
1252  cb->setChecked(false);
1253  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
1254
1255 
1256  bool tmp;
1257
1258  cb = new QCheckBox("Use filter", vbox);
1259  vbox->layout()->addWidget(cb);
1260  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
1261  cb->setChecked(tmp);
1262  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
1263
1264 
1265  cb = new QCheckBox("Use spatial filter", vbox);
1266  vbox->layout()->addWidget(cb);
1267  Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
1268                                                                                        tmp );
1269  cb->setChecked(tmp);
1270  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
1271
1272  cb = new QCheckBox("Render filter", vbox);
1273  vbox->layout()->addWidget(cb);
1274  cb->setChecked(true);
1275  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
1276
1277
1278
1279 
1280  slider = new QSlider(Qt::Horizontal, vbox);
1281  vbox->layout()->addWidget(slider);
1282  slider->show();
1283  slider->setRange(1, 1000);
1284  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1285  slider->setValue(500);
1286 
1287  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
1288 
1289  cb = new QCheckBox("Top View", vbox);
1290  vbox->layout()->addWidget(cb);
1291  cb->setChecked(false);
1292  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
1293
1294
1295
1296  vbox = new QGroupBox("PVS Errors", this);
1297  layout()->addWidget(vbox);
1298 
1299  vl = new QVBoxLayout;
1300  vbox->setLayout(vl);
1301
1302  QPushButton *button = new QPushButton("Compute Visibility", vbox);
1303  vbox->layout()->addWidget(button);
1304  connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
1305
1306  button = new QPushButton("Stop Computation", vbox);
1307  vbox->layout()->addWidget(button);
1308  connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
1309
1310  button = new QPushButton("Set Random View Point", vbox);
1311  vbox->layout()->addWidget(button);
1312  connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
1313
1314
1315  if (0) {
1316        vbox = new QGroupBox("PVS Errors", this);
1317        layout()->addWidget(vbox);
1318       
1319        vl = new QVBoxLayout;
1320        vbox->setLayout(vl);
1321       
1322        mPvsErrorWidget = new QListWidget(vbox);
1323        vbox->layout()->addWidget(mPvsErrorWidget);
1324       
1325        connect(mPvsErrorWidget,
1326                        SIGNAL(doubleClicked(const QModelIndex &)),
1327                        this,
1328                        SLOT(PvsErrorClicked(const QModelIndex &)));
1329       
1330        QPushButton *button = new QPushButton("Next Error Frame", vbox);
1331        vbox->layout()->addWidget(button);
1332        connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
1333  }
1334 
1335  setWindowTitle("Preprocessor Control Widget");
1336  adjustSize();
1337}
1338
1339
1340
1341
1342void
1343QtRendererControlWidget::FocusNextPvsErrorFrame(void)
1344{
1345 
1346 
1347}
1348
1349void
1350QtRendererControlWidget::UpdatePvsErrorItem(int row,
1351                                                                                  GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
1352{
1353
1354  QListWidgetItem *i = mPvsErrorWidget->item(row);
1355  QString s;
1356  s.sprintf("%5.5f", pvsErrorEntry.mError);
1357  if (i) {
1358        i->setText(s);
1359  } else {
1360        new QListWidgetItem(s, mPvsErrorWidget);
1361  }
1362  mPvsErrorWidget->update();
1363}
1364
1365
1366void QtGlDebuggerWidget::initializeGL()
1367{
1368        glMatrixMode(GL_PROJECTION);
1369        glLoadIdentity();
1370
1371        glFrustum(-1, 1, -1, 1, 10, 100);
1372        glTranslatef(-0.5f, -0.5f, -0.5f);
1373        glTranslatef(0.0f, 0.0f, -15.0f);
1374        glMatrixMode(GL_MODELVIEW);
1375
1376        glEnable(GL_CULL_FACE);
1377        initCommon();
1378        initPbuffer();
1379
1380}
1381
1382
1383void QtGlDebuggerWidget::resizeGL(int w, int h)
1384{
1385        glViewport(0, 0, w, h);
1386}
1387
1388
1389void QtGlDebuggerWidget::paintGL()
1390{
1391        // draw a spinning cube into the pbuffer..
1392        mRenderBuffer->makeCurrent();
1393       
1394        BeamSampleStatistics stats;
1395        mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
1396
1397        glFlush();
1398
1399        // rendering directly to a texture is not supported on X11, unfortunately
1400    mRenderBuffer->updateDynamicTexture(dynamicTexture);
1401   
1402    // and use the pbuffer contents as a texture when rendering the
1403    // background and the bouncing cubes
1404    makeCurrent();
1405    glBindTexture(GL_TEXTURE_2D, dynamicTexture);
1406    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1407
1408    // draw the background
1409    glMatrixMode(GL_MODELVIEW);
1410    glPushMatrix();
1411    glLoadIdentity();
1412    glMatrixMode(GL_PROJECTION);
1413    glPushMatrix();
1414    glLoadIdentity();
1415
1416        glPopMatrix();
1417        glMatrixMode(GL_MODELVIEW);
1418        glPopMatrix();
1419}
1420
1421
1422void QtGlDebuggerWidget::initPbuffer()
1423{
1424        // set up the pbuffer context
1425    mRenderBuffer->makeCurrent();
1426        /*mRenderBuffer->InitGL();
1427
1428        glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
1429        glMatrixMode(GL_PROJECTION);
1430        glLoadIdentity();
1431        glOrtho(-1, 1, -1, 1, -99, 99);
1432        glTranslatef(-0.5f, -0.5f, 0.0f);
1433        glMatrixMode(GL_MODELVIEW);
1434        glLoadIdentity();
1435
1436        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
1437       
1438        // generate a texture that has the same size/format as the pbuffer
1439    dynamicTexture = mRenderBuffer->generateDynamicTexture();
1440
1441        // bind the dynamic texture to the pbuffer - this is a no-op under X11
1442        mRenderBuffer->bindToDynamicTexture(dynamicTexture);
1443        makeCurrent();
1444}
1445
1446void QtGlDebuggerWidget::initCommon()
1447{
1448        glEnable(GL_TEXTURE_2D);
1449        glEnable(GL_DEPTH_TEST);
1450
1451        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
1452}
1453
1454
1455
1456}
Note: See TracBrowser for help on using the repository browser.