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

Revision 1867, 34.2 KB checked in by bittner, 18 years ago (diff)

merge, global lines, rss sampling updates

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