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

Revision 1983, 35.0 KB checked in by bittner, 17 years ago (diff)

merge

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