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

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

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