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

Revision 2577, 50.2 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include "glInterface.h"
2#include "QtGlRenderer.h"
3#include "Mesh.h"
4#include "OcclusionQuery.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#include "Material.h"
17#include "IntersectableWrapper.h"
18
19
20#define USE_CG 1
21
22
23#if USE_CG
24#include <Cg/cg.h>
25#include <Cg/cgGL.h>
26#endif
27
28#include <QVBoxLayout>
29
30namespace GtpVisibilityPreprocessor {
31
32
33 
34class ViewCellsManager;
35
36static CGcontext sCgContext = NULL;
37static CGprogram sCgFragmentProgram = NULL;
38static CGprofile sCgFragmentProfile;
39
40
41//static vector<OcclusionQuery *> sQueries;
42
43QtGlRendererWidget *rendererWidget = NULL;
44QtGlDebuggerWidget *debuggerWidget = NULL;
45
46
47static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
48{
49        return obj1->mId < obj2->mId;
50}
51
52
53inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2)
54{
55        return vc1->GetDistance() > vc2->GetDistance();
56}
57
58
59#if USE_CG
60static void handleCgError()
61{
62    Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
63    exit(1);
64}
65#endif
66
67void
68QtGlRendererBuffer::MakeCurrent()
69{
70  makeCurrent();
71}
72
73void
74QtGlRendererBuffer::DoneCurrent()
75{
76  doneCurrent();
77}
78 
79
80QtGlRendererBuffer::QtGlRendererBuffer(const int w,
81                                                                           const int h,
82                                                                           SceneGraph *sceneGraph,
83                                                                           ViewCellsManager *viewcells,
84                                                                           KdTree *tree):
85  QGLPixelBuffer(QSize(w, h)),
86  //QGLWidget(NULL, w, h),
87  GlRendererBuffer(sceneGraph, viewcells, tree)
88{
89  MakeCurrent();
90  InitGL();
91  DoneCurrent();
92}
93
94
95// reimplemented here so that we can snap the error windows
96float
97QtGlRendererBuffer::GetPixelError(int &pvsSize)
98{
99        float pErrorPixels = -1.0f;
100
101
102        mUseFalseColors = false;
103        unsigned int pixelCount;
104
105
106        ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
107        //  cout<<"View cell"<<viewcell<<endl;
108        if (viewcell == NULL)
109                return 0.0f;
110
111
112        ObjectPvs pvs;
113
114        if (1)
115                pvs = viewcell->GetPvs();
116        else
117                mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs);
118
119        SetupCamera();
120        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
121        glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
122
123
124        glStencilFunc(GL_EQUAL, 0x0, 0x1);
125        glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
126
127        // Render PVS
128        ObjectPvsIterator it = pvs.GetIterator();
129
130        pvsSize = pvs.GetSize();
131
132        Intersectable::NewMail();
133        while (it.HasMoreEntries())
134        {
135                RenderIntersectable(it.Next());
136        }
137
138
139        //glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
140        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
141        glEnable(GL_STENCIL_TEST);
142
143        mUseFalseColors = true;
144
145        OcclusionQuery *query = mOcclusionQueries[0];
146
147
148        query->BeginQuery();
149
150        SetupCamera();
151
152        RenderScene();
153
154        query->EndQuery();
155        glDisable(GL_STENCIL_TEST);
156        // reenable other state
157        //  int wait=0;
158        //  while (!query.ResultAvailable()) {
159        //      wait++;
160        //  }
161
162
163        pixelCount = query->GetQueryResult();
164
165        pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
166
167
168        if (mSnapErrorFrames && pErrorPixels >= 0.01f) {
169                glReadBuffer(GL_BACK);
170
171                char filename[256];
172                sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
173                QImage im = toImage();
174                string str = mSnapPrefix + filename;
175                QString qstr(str.c_str());
176
177                im.save(qstr, "PNG");
178                if (1) { //0 && mFrame == 1543) {
179                        int x,y;
180                        int lastIndex = -1;
181                        for (y=0; y < im.height(); y++)
182                                for (x=0; x < im.width(); x++) {
183                                        QRgb p = im.pixel(x,y);
184                                        int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16);
185                                        if (qGreen(p) != 255 && index!=0) {
186                                                if (index != lastIndex) {
187                                                        //                              Debug<<"ei="<<index<<" ";
188                                                        lastIndex = index;
189                                                }
190                                        }
191                                }
192                }
193
194
195                mUseFalseColors = false;
196                glPushAttrib(GL_CURRENT_BIT);
197                glColor3f(0,1,0);
198                glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
199                SetupCamera();
200                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
201
202                // Render PVS
203                Intersectable::NewMail();
204
205                ObjectPvsIterator it = pvs.GetIterator();
206                for (; it.HasMoreEntries(); )
207                {
208                        RenderIntersectable(it.Next());
209                }
210
211                im = toImage();
212                sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels);
213                str = mSnapPrefix + filename;
214                qstr = str.c_str();
215                im.save(qstr, "PNG");
216                glPopAttrib();
217        }
218
219        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
220
221        return pErrorPixels;
222}
223
224int
225QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
226                                                           ObjectContainer &pvs) const
227{
228        int pvsSize = 0;
229        QImage image = toImage();
230        Intersectable::NewMail();
231
232        std::stable_sort(objects.begin(), objects.end(), ilt);
233
234        MeshInstance dummy(NULL);
235
236        Intersectable *obj = NULL;
237
238        for (int x = 0; x < image.width(); ++ x)
239        {
240                for (int y = 0; y < image.height(); ++ y)
241                {
242                        QRgb pix = image.pixel(x, y);
243                        const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
244
245                        dummy.SetId(id);
246
247                        ObjectContainer::iterator oit =
248                                lower_bound(objects.begin(), objects.end(), &dummy, ilt);
249
250
251                        if (//(oit != oit.end()) &&
252                                ((*oit)->GetId() == id) &&
253                                !obj->Mailed())
254                        {
255                                obj = *oit;
256                                obj->Mail();
257                                ++ pvsSize;
258                                pvs.push_back(obj);
259                        }
260                }
261        }
262
263        return pvsSize;
264}
265
266
267void QtGlRendererWidget::InitGL()
268{
269        GlRenderer::InitGL();
270
271        GLfloat mat_ambient[]   = {  0.5, 0.5, 0.5, 1.0  };
272        /*  mat_specular and mat_shininess are NOT default values       */
273        GLfloat mat_diffuse[]   = {  1.0, 1.0, 1.0, 1.0  };
274        GLfloat mat_specular[]  = {  0.3, 0.3, 0.3, 1.0  };
275        GLfloat mat_shininess[] = {  1.0  };
276
277        GLfloat light_ambient[]  = {  0.2, 0.2, 0.2, 1.0  };
278        GLfloat light_diffuse[]  = {  0.4, 0.4, 0.4, 1.0  };
279        GLfloat light_specular[] = {  0.3, 0.3, 0.3, 1.0  };
280
281        GLfloat lmodel_ambient[] = {  0.3, 0.3, 0.3, 1.0  };
282
283
284        // default Material
285        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
286        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
287        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
288        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
289
290        // a light
291        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
292        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
293        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
294
295        glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
296        glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
297        glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
298
299        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
300
301        glEnable(GL_LIGHTING);
302        glEnable(GL_LIGHT0);
303        glEnable(GL_LIGHT1);
304
305        // set position of the light
306        GLfloat infinite_light[] = {  1.0, 0.8, 1.0, 0.0  };
307        glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
308
309        // set position of the light2
310        GLfloat infinite_light2[] = {  -0.3, 1.5, 1.0, 0.0  };
311        glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
312
313        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
314        // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
315        glEnable(GL_COLOR_MATERIAL);
316
317        glShadeModel(GL_FLAT);
318}
319
320
321void
322QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
323{
324        if (!mTopView) {
325                int ww = w;
326                int hh = h;
327                glViewport(0, 0, ww, hh);
328                glMatrixMode(GL_PROJECTION);
329                glLoadIdentity();
330                gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
331                glMatrixMode(GL_MODELVIEW);
332        } else {
333                int ww = w;
334                int hh = h;
335                glViewport(0, 0, ww, hh);
336                glMatrixMode(GL_PROJECTION);
337                glLoadIdentity();
338                gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
339                glMatrixMode(GL_MODELVIEW);
340        }
341}
342
343
344bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
345{
346        if (viewCell != mPvsCache.mViewCell)
347                return true;
348
349        if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
350                return true;
351
352        return false;
353}
354
355
356void QtGlRendererWidget::_RenderPvs()
357{
358        mUseFalseColors = false;
359
360        int offset = (int)mObjects.size() * 3;
361        char *arrayPtr = mUseVbos ? NULL : (char *)mData;
362
363        glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
364        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
365        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
366}
367
368
369void QtGlRendererWidget::_UpdatePvsIndices()
370{
371        int indexBufferSize = 0;
372       
373        KdNode::NewMail();
374        //Intersectable::NewMail();
375
376        mPvsSize = mPvsCache.mPvs.GetSize();
377
378        ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
379
380        while (it.HasMoreEntries())
381        {
382                Intersectable *obj = it.Next();
383                KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
384
385                _UpdatePvsIndices(node, indexBufferSize);
386        }
387
388        mIndexBufferSize = indexBufferSize;
389}
390
391
392void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node, int &indexBufferSize)
393{
394        if (node->Mailed())
395                return;
396
397        node->Mail();
398
399        // if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl;
400        if (!node->IsLeaf())
401        {
402                KdInterior *kdInterior = static_cast<KdInterior *>(node);
403
404                _UpdatePvsIndices(kdInterior->mBack, indexBufferSize);
405                _UpdatePvsIndices(kdInterior->mFront, indexBufferSize);
406        }
407        else
408        {
409                KdLeaf *leaf = static_cast<KdLeaf *>(node);
410
411                leaf->mIndexBufferStart = indexBufferSize;
412
413                for (size_t i = 0; i < leaf->mObjects.size(); ++ i)
414                {
415                        TriangleIntersectable *obj =
416                                static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
417
418                        // check if already rendered
419                        /*if (!obj->Mailed())
420                        {
421                                obj->Mail();
422
423                                mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
424                                mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
425                                mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
426
427                                indexBufferSize += 3;
428                        }*/
429                        if (obj->mRenderedFrame != mCurrentFrame)
430                        {
431                                obj->mRenderedFrame = mCurrentFrame;
432
433                                mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
434                                mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
435                                mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
436
437                                indexBufferSize += 3;
438                        }
439                }
440
441                leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart;
442        }
443
444        //cout << "id: " << indexBufferSize << endl;
445}
446
447
448void QtGlRendererWidget::RenderPvs()
449{
450        if (mUseVbos)
451                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
452
453        ++ mCurrentFrame;
454
455        EnableDrawArrays();
456
457        //Intersectable::NewMail();
458       
459        if (mDetectEmptyViewSpace)
460                glEnable(GL_CULL_FACE);
461        else
462                glDisable(GL_CULL_FACE);
463
464        ViewCell *viewcell = NULL;
465        viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
466
467        if (viewcell)
468        {
469                // copy the pvs so that it can be filtered ...
470                if (PvsChanged(viewcell))
471                {
472                        mPvsCache.Reset();
473                        mPvsCache.mViewCell = viewcell;
474                        mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
475
476                        if (mUseSpatialFilter)
477                        {
478                                //ObjectPvs pvs;
479
480                                //mMutex.lock();
481                                // mSpatialFilter size is in range 0.001 - 0.1
482                                mViewCellsManager->ApplyFilter2(viewcell,
483                                                                    mUseFilter,
484                                                                    100.0f * mSpatialFilterSize,
485                                                                    //pvs,
486                                                                                                mPvsCache.mPvs,         
487                                                                    &mPvsCache.filteredBoxes);
488                                //mPvsCache.mPvs = pvs;
489                                //mMutex.unlock();
490                        }
491                        else
492                        {
493                                mPvsCache.mPvs = viewcell->GetPvs();
494                        }
495
496                        /// update the indices for rendering
497                        _UpdatePvsIndices();
498
499                        emit PvsUpdated();
500                }
501
502                //Intersectable::NewMail();
503                PvsData pvsData;
504
505                // Render PVS
506                if (mUseSpatialFilter && mRenderBoxes)
507                {
508                        for (int i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
509                        {
510                                RenderBox(mPvsCache.filteredBoxes[i]);
511                        }
512                }
513                else
514                {
515                        if (!mRenderVisibilityEstimates)
516                        {
517                                _RenderPvs();
518                        }
519                        else
520                        {
521                                mPvsSize = mPvsCache.mPvs.GetSize();
522
523                                ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
524
525                                while (it.HasMoreEntries())
526                                {
527                                        Intersectable *object = it.Next(pvsData);
528
529                                        //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
530                                        // glColor3f(visibility, 0.0f, 0.0f);
531                                        //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
532                                        RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1));
533                                        glColor3f(color.r, color.g, color.b);
534
535                                        mUseForcedColors = true;
536                                        RenderIntersectable(object);
537                                        mUseForcedColors = false;
538                                }
539                        }
540                }
541
542                if (mRenderFilter)
543                {
544                        mWireFrame = true;
545                        RenderIntersectable(viewcell);
546                       
547                        /*glPushMatrix();
548                        glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
549                        glScalef(5.0f,5.0f,5.0f);
550                        glPushAttrib(GL_CURRENT_BIT);
551                        glColor3f(1.0f, 0.0f, 0.0f);
552                        //        gluSphere((::GLUquadric *)mSphere,
553                        //                              1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
554                        glPopAttrib();
555                        glPopMatrix();
556                        */
557                        mWireFrame = false;
558                }
559        }
560        else
561        {
562                /*ObjectContainer::const_iterator oi = mObjects.begin();
563                for (; oi != mObjects.end(); oi++)
564                RenderIntersectable(*oi);*/
565                RenderScene();
566        }
567
568        //DisableDrawArrays();
569        //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
570}
571
572float
573QtGlRendererWidget::RenderErrors()
574{
575        float pErrorPixels = -1.0f;
576
577        SetupCamera();
578        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
579
580        glPushAttrib(GL_ENABLE_BIT);
581
582        glStencilFunc(GL_EQUAL, 0x0, 0x1);
583        glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
584
585        mUseForcedColors = true;
586
587        glColor3f(0.0f, 0.8f, 0.2f);
588
589        // Render PVS
590        RenderPvs();
591
592        glEnable(GL_STENCIL_TEST);
593
594        //mUseFalseColors = true;
595
596        glDisable(GL_LIGHTING);
597
598        OcclusionQuery *query = mOcclusionQueries[0];
599        query->BeginQuery();
600
601        SetupCamera();
602
603        glColor3f(1.0f, 0.0f, 0.0f);
604
605        RenderScene();
606
607        mUseForcedColors = false;
608
609        query->EndQuery();
610
611        glDisable(GL_STENCIL_TEST);
612        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
613
614        glPopAttrib();
615
616        // reenable other state
617        //  int wait=0;
618        //  while (!query.ResultAvailable()) {
619        //      wait++;
620        //  }
621
622        int pixelCount = query->GetQueryResult();
623        pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
624        if (0) cout<<"error pixels="<<pixelCount<<endl;
625
626        mRenderError = pErrorPixels;
627
628        return pErrorPixels;
629}
630
631
632void QtGlRendererWidget::timerEvent(QTimerEvent *event)
633{
634        //std::cout << "Timer ID:" << event->timerId();
635        update();
636}
637
638
639void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
640{
641        int x = e->pos().x();
642        int y = e->pos().y();
643
644        mousePoint.x = x;
645        mousePoint.y = y;
646
647}
648
649void
650QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
651{
652        float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
653        float TURN_SENSITIVITY=0.1f;
654        float TILT_SENSITIVITY=32.0 ;
655        float TURN_ANGLE= M_PI/36.0 ;
656
657        int x = e->pos().x();
658        int y = e->pos().y();
659
660        int diffx = -(mousePoint.x - x);
661        int diffy = -(mousePoint.y - y);
662
663        if (e->modifiers() & Qt::ControlModifier)
664        {
665                mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
666                mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
667        }
668        else
669        {
670                mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
671                float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
672                float angle = atan2(mViewDirection.x, mViewDirection.z);
673                mViewDirection.x = sin(angle + adiff);
674                mViewDirection.z = cos(angle + adiff);
675        }
676
677        mousePoint.x = x;
678        mousePoint.y = y;
679
680        updateGL();
681}
682
683void
684QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
685{
686}
687
688void
689QtGlRendererWidget::resizeGL(int w, int h)
690{
691        SetupCameraProjection(w, h);
692        updateGL();
693}
694
695void
696QtGlRendererWidget::paintGL()
697{
698        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
699
700        if (1)
701        {
702                SetupCameraProjection(width(), height());
703                SetupCamera();
704
705                if (mRenderErrors)
706                {
707                        RenderErrors();
708                }
709                else
710                {
711                        glColor3f(0.6f, 0.6f, 0.6f);
712                        RenderPvs();
713                }
714
715                if (1 && mShowRays)
716                {
717                        RenderRays(mViewCellsManager->mVizBuffer.GetRays());
718                }
719        }
720
721        RenderInfo();
722        mFrame ++;
723}
724
725
726void
727QtGlRendererWidget::SetupCamera()
728{
729        if (!mTopView)
730                GlRenderer::SetupCamera();
731        else {
732                if (0) {
733                        float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
734                        Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
735                                -1,
736                                mViewDirection.y);
737
738                        Vector3 target = mViewPoint + dist*mViewDirection;
739                        Vector3 up(0,1,0);
740
741                        glLoadIdentity();
742                        gluLookAt(pos.x, pos.y, pos.z,
743                                target.x, target.y, target.z,
744                                up.x, up.y, up.z);
745                }
746                else
747                {
748                        float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance;
749                        Vector3 pos = mViewPoint  + dist*Vector3(0,
750                                1,
751                                0);
752
753                        Vector3 target = mViewPoint;
754                        Vector3 up(mViewDirection.x, 0, mViewDirection.z);
755
756                        glLoadIdentity();
757                        gluLookAt(pos.x, pos.y, pos.z,
758                                target.x, target.y, target.z,
759                                up.x, up.y, up.z);
760
761                }
762        }
763
764}
765
766
767void
768QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
769{
770        switch (e->key()) {
771case Qt::Key_T:
772        mTopView = !mTopView;
773        SetupCameraProjection(width(), height());
774        updateGL();
775        break;
776case Qt::Key_V:
777        mRenderViewCells = !mRenderViewCells;
778        updateGL();
779        break;
780case Qt::Key_P:
781        // set random viewpoint
782        mViewCellsManager->GetViewPoint(mViewPoint);
783        updateGL();
784        break;
785case Qt::Key_S: {
786        // set view poitn and direction
787        QString text;
788        bool ok;
789        text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
790        text = QInputDialog::getText(this,
791                "Enter a view point",
792                "",
793                QLineEdit::Normal,
794                text,
795                &ok);
796        if (!ok)
797                break;
798
799        if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
800                text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
801                text = QInputDialog::getText(this,
802                        "Enter a direction",
803                        "",
804                        QLineEdit::Normal,
805                        text,
806                        &ok);
807                if (!ok)
808                        break;
809                if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
810                        &mViewDirection.y, &mViewDirection.z) == 3) {
811                                updateGL();
812                        }
813                        break;
814        }
815                                }
816default:
817        e->ignore();
818        break;
819        }
820}
821
822
823
824QtGlRendererWidget::QtGlRendererWidget(
825                                                                           SceneGraph *sceneGraph,
826                                                                           ViewCellsManager *viewcells,
827                                                                           KdTree *tree,
828                                                                           QWidget * parent,
829                                                                           const QGLWidget * shareWidget,
830                                                                           Qt::WFlags f
831                                                                           )
832                                                                           :
833GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
834{
835        mPreprocessorThread = NULL;
836        mTopView = false;
837        mRenderViewCells = false;
838        mTopDistance = 1.0f;
839        mCutViewCells = false;
840        mCutScene = false;
841        mRenderErrors = false;
842        mRenderBoxes = false;
843        mRenderFilter = true;
844        mRenderVisibilityEstimates = false;
845
846        mHideByCost = false;
847        mUseTransparency = false;
848
849        mTransferFunction = 1.0f;
850        mIndexBufferSize = 0;
851
852        //mCurrentFrame = 0;
853
854        const int delay = 250; // in milliseconds
855        timerId = startTimer(delay);
856
857        bool tmp;
858
859        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
860        mUseFilter = tmp;
861
862        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
863                tmp );
864        mUseSpatialFilter = tmp;
865
866        mShowRenderCost = false;
867        mShowPvsSizes = false;
868        mShowPiercingRays = false;
869        mShowWeightedRays = false;
870        mShowWeightedCost = false;
871
872        mShowDistanceWeightedPvs = true;
873        mShowDistanceWeightedTriangles = false;
874        mShowWeightedTriangles = false;
875
876        mSpatialFilterSize = 0.01;
877        mPvsSize = 0;
878        mRenderError = 0.0f;
879        mShowRays = false;
880
881        mControlWidget = new QtRendererControlWidget(NULL);
882
883        connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
884        connect(mControlWidget,
885                SIGNAL(SetTransferFunction(int)),
886                this,
887                SLOT(SetTransferFunction(int)));
888        connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
889        connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
890        connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
891        connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
892                SLOT(SetRandomViewPoint()));
893
894        connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
895        connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
896        connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int)));
897
898        connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
899        connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
900        connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int)));
901
902        connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
903        connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
904        connect(mControlWidget, SIGNAL(SetUseTransparency(bool)), this, SLOT(SetUseTransparency(bool)));
905        connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
906        connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
907        connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
908        connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool)));
909        connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
910        connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
911        connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
912        connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
913        connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), this, SLOT(SetRenderVisibilityEstimates(bool)));
914        connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
915        connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), this, SLOT(SetUseSpatialFilter(bool)));
916        connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
917        connect(mControlWidget, SIGNAL(SetShowWeightedRays(bool)), this, SLOT(SetShowWeightedRays(bool)));
918        connect(mControlWidget, SIGNAL(SetShowWeightedCost(bool)), this, SLOT(SetShowWeightedCost(bool)));
919
920        connect(mControlWidget, SIGNAL(SetShowDistanceWeightedTriangles(bool)), this, SLOT(SetShowDistanceWeightedTriangles(bool)));
921        connect(mControlWidget, SIGNAL(SetShowDistanceWeightedPvs(bool)), this, SLOT(SetShowDistanceWeightedPvs(bool)));
922        connect(mControlWidget, SIGNAL(SetShowWeightedTriangles(bool)), this, SLOT(SetShowWeightedTriangles(bool)));
923
924        connect(mControlWidget,
925                SIGNAL(SetShowRays(bool)),
926                this,
927                SLOT(SetShowRays(bool)));
928
929        resize(1000, 500);
930        mControlWidget->show();
931}
932
933void
934QtGlRendererWidget::UpdateAllPvs()
935{
936        // $$ does not work so far:(
937        mViewCellsManager->UpdatePvsForEvaluation();
938        //      mViewCellsManager->FinalizeViewCells(false);
939}
940
941void
942QtGlRendererWidget::ComputeVisibility()
943{
944        cerr<<"Compute Visibility called!\n"<<endl;
945        if (!mPreprocessorThread->isRunning())
946                mPreprocessorThread->RunThread();
947}
948
949void
950QtGlRendererWidget::StopComputation()
951{
952        cerr<<"stop computation called!\n"<<endl;
953        mViewCellsManager->GetPreprocessor()->mStopComputation = true;
954}
955
956void
957QtGlRendererWidget::SetRandomViewPoint()
958{
959        cerr<<"stop computation called!\n"<<endl;
960        mViewCellsManager->GetViewPoint(mViewPoint);
961        updateGL();
962}
963
964void
965QtGlRendererWidget::RenderRenderCost()
966{
967        static vector<float> costFunction;
968        static float maxCost = -1;
969        if (costFunction.size()==0) {
970                ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
971                if (tree) {
972                        tree->GetCostFunction(costFunction);
973                        maxCost = -1;
974                        for (int i=0;  i < costFunction.size(); i++) {
975                                //                cout<<i<<":"<<costFunction[i]<<" ";
976                                // update cost function to an absolute value based on the total geometry count
977                                costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
978                                if (costFunction[i] > maxCost)
979                                        maxCost = costFunction[i];
980                        }
981                }
982        }
983
984
985        int currentPos = (int)mViewCellsManager->GetViewCells().size();
986        float currentCost= -1;
987
988        if (currentPos < costFunction.size())
989                currentCost = costFunction[currentPos];
990#if 1   
991        cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
992        cout<<"CP="<<currentPos<<endl;
993        cout<<"MC="<<maxCost<<endl;
994        cout<<"CC="<<currentCost<<endl;
995#endif
996        if (costFunction.size()) {
997                float scaley = 1.0f/log10(maxCost);
998                float scalex = 1.0f/(float)costFunction.size();
999
1000                glDisable(GL_DEPTH_TEST);
1001                // init ortographic projection
1002                glMatrixMode(GL_PROJECTION);
1003
1004                glPushMatrix();
1005
1006                glLoadIdentity();
1007                gluOrtho2D(0, 1.0f, 0, 1.0f);
1008
1009                glTranslatef(0.1f, 0.1f, 0.0f);
1010                glScalef(0.8f, 0.8f, 1.0f);
1011                glMatrixMode(GL_MODELVIEW);
1012                glLoadIdentity();
1013
1014                glColor3f(1.0f,0,0);
1015                glBegin(GL_LINE_STRIP);
1016                //        glVertex3f(0,0,0);
1017
1018                for (int i=0;  i < costFunction.size(); i++) {
1019                        float x =  i*scalex;
1020                        float y = log10(costFunction[i])*scaley;
1021                        glVertex3f(x,y,0.0f);
1022                }
1023                glEnd();
1024
1025                glColor3f(1.0f,0,0);
1026                glBegin(GL_LINES);
1027                float x =  currentPos*scalex;
1028                glVertex3f(x,0.0,0.0f);
1029                glVertex3f(x,1.0f,0.0f);
1030                glEnd();
1031
1032                glColor3f(0.0f,0,0);
1033                // show a grid
1034                glBegin(GL_LINE_LOOP);
1035                glVertex3f(0,0,0.0f);
1036                glVertex3f(1,0,0.0f);
1037                glVertex3f(1,1,0.0f);
1038                glVertex3f(0,1,0.0f);
1039                glEnd();
1040
1041                glBegin(GL_LINES);
1042                for (int i=0;  i < costFunction.size(); i += 1000) {
1043                        float x =  i*scalex;
1044                        glVertex3f(x,0.0,0.0f);
1045                        glVertex3f(x,1.0f,0.0f);
1046                }
1047
1048                for (int i=0;  pow(10.0f, i) < maxCost; i+=1) {
1049                        float y = i*scaley;
1050                        //              QString s;
1051                        //              s.sprintf("%d", (int)pow(10,i));
1052                        //              renderText(width()/2+5, y*height(), s);
1053                        glVertex3f(0.0f, y, 0.0f);
1054                        glVertex3f(1.0f, y, 0.0f);
1055                }
1056
1057                glEnd();
1058
1059
1060                // restore the projection matrix
1061                glMatrixMode(GL_PROJECTION);
1062                glPopMatrix();
1063                glMatrixMode(GL_MODELVIEW);
1064                glEnable(GL_DEPTH_TEST);
1065
1066        }
1067
1068
1069
1070}
1071
1072void
1073QtGlRendererWidget::RenderInfo()
1074{
1075
1076        QString s;
1077        int vc = 0;
1078        if (mViewCellsManager)
1079                vc = (int)mViewCellsManager->GetViewCells().size();
1080
1081        int filter = 0;
1082        if (mViewCellsManager)
1083                filter = mViewCellsManager->GetMaxFilterSize();
1084
1085        glColor3f(1.0f,1.0f,1.0f);
1086
1087        s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
1088                mFrame,
1089                mViewPoint.x,
1090                mViewPoint.y,
1091                mViewPoint.z,
1092                mViewDirection.x,
1093                mViewDirection.y,
1094                mViewDirection.z
1095                );
1096
1097        renderText(20,20,s);
1098
1099        s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
1100                vc,
1101                filter,
1102                mPvsSize,
1103                mRenderError*100.0f);
1104
1105
1106        renderText(20,40,s);
1107
1108
1109
1110
1111}
1112
1113
1114void
1115QtGlRendererWidget::SetViewCellGranularity(int number)
1116{
1117        if (mViewCellsManager) {
1118                //      mViewCellsManager->SetMaxFilterSize(number);
1119
1120                // $$ tmp off
1121                mViewCellsManager->CollectViewCells(number);
1122
1123                // $$ does not work so far:(
1124                //      mViewCellsManager->UpdatePvsForEvaluation();
1125                //      mViewCellsManager->FinalizeViewCells(false);
1126        }
1127        updateGL();
1128}
1129
1130void
1131QtGlRendererWidget::SetVisibilityFilterSize(int number)
1132{
1133        if (mViewCellsManager)
1134                mViewCellsManager->SetMaxFilterSize(number);
1135        mPvsCache.Reset();
1136        updateGL();
1137}
1138
1139void
1140QtGlRendererWidget::SetSpatialFilterSize(int number)
1141{
1142        mSpatialFilterSize = 1e-3*number;
1143        mPvsCache.Reset();
1144        updateGL();
1145}
1146
1147void
1148QtGlRendererWidget::SetSceneCut(int number)
1149{
1150        // assume the cut plane can only be aligned with xz plane
1151        // shift it along y according to number, which is percentage of the bounding
1152        // box position
1153        if (mViewCellsManager)
1154        {
1155                const float f = number / 1000.0f;
1156                AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
1157                Vector3 p = (1.0f - f) * box.Min() + f * box.Max();
1158                mSceneCutPlane.mNormal = Vector3(0,-1,0);
1159                mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
1160
1161                updateGL();
1162        }
1163}
1164
1165void
1166QtGlRendererWidget::SetHidingCost(int number)
1167{
1168        mHidingCost = (float)number / 1000.0f;
1169}
1170
1171
1172void
1173QtGlRendererWidget::SetTopDistance(int number)
1174{
1175        mTopDistance = number / 1000.0f;
1176        updateGL();
1177}
1178
1179void QtGlRendererWidget::SetTransparency(int number)
1180{
1181        mTransparency = number / 1000.0f;
1182        updateGL();
1183}
1184
1185#if 0
1186float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
1187{
1188        ObjectPvs basePvs;
1189       
1190        basePvs = vc->CopyPvs();
1191        ObjectPvsIterator pit = basePvs.GetIterator();
1192
1193        float renderCost = 0;
1194
1195        //cout << "cost vis: " << mShowDistanceWeightedPvs << " " << " " << mShowDistanceWeightedTriangles << " " << mShowWeightedTriangles << endl;
1196       
1197        // first mark all objects from this pvs
1198        while (pit.HasMoreEntries())   
1199        {
1200                if (mShowDistanceWeightedPvs)
1201                {
1202                        KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
1203                        const AxisAlignedBox3 box = kdObj->GetBox();
1204
1205                        const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
1206                        renderCost += 1.0f / dist;
1207                }
1208                else if (mShowDistanceWeightedTriangles)
1209                {
1210                        KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
1211                        const AxisAlignedBox3 box = kdObj->GetBox();
1212
1213                        const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
1214                        renderCost += kdObj->ComputeNumTriangles() / dist;
1215                }
1216                else //if (mShowWeightedTriangles)
1217                {
1218                        KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
1219                        renderCost += kdObj->ComputeNumTriangles();
1220                }
1221                //if (pit.Next()->Mail();
1222        }
1223
1224        return renderCost;
1225}
1226#else
1227
1228float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
1229{
1230        float renderCost = 0;
1231
1232        if (mShowDistanceWeightedPvs)
1233        {
1234                return vc->GetPvs().mStats.mDistanceWeightedPvs;
1235        }
1236        else if (mShowDistanceWeightedTriangles)
1237        {
1238                return vc->GetPvs().mStats.mDistanceWeightedTriangles;
1239        }
1240        else //if (mShowWeightedTriangles)
1241        {
1242                return vc->GetPvs().mStats.mWeightedTriangles;
1243        }
1244}
1245#endif
1246
1247
1248
1249void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells,
1250                                                                                  int &maxPvs,
1251                                                                                  int &maxPiercingRays,
1252                                                                                  float &maxRelativeRays,
1253                                                                                  float &maxRcCost)
1254{
1255        maxPvs = -1;
1256        maxPiercingRays = 1; // not zero for savety
1257        maxRelativeRays = Limits::Small; // not zero for savety
1258        maxRcCost = Limits::Small;
1259
1260        for (size_t i = 0; i < viewCells.size(); ++ i)
1261        {
1262                ViewCell *vc = viewCells[i];
1263
1264                if (mShowPvsSizes) // pvs size
1265                {
1266                        //const int p = vc->GetPvs().CountObjectsInPvs();
1267                        const int p = vc->GetPvs().GetSize();
1268                        if (p > maxPvs)
1269                                maxPvs = p;
1270                }
1271                else if (mShowPiercingRays) // relative number of rays
1272                {
1273                        const int piercingRays = vc->GetNumPiercingRays();
1274
1275                        if (piercingRays > maxPiercingRays)
1276                                maxPiercingRays = piercingRays;
1277                }
1278                else if (mShowWeightedRays)
1279                {
1280                        const int piercingRays = vc->GetNumPiercingRays();
1281
1282                        const float relativeArea =
1283                                vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
1284
1285                        if ((float)piercingRays / relativeArea > maxRelativeRays)
1286                                maxRelativeRays = (float)piercingRays / relativeArea;
1287                }
1288                else if (mShowWeightedCost)
1289                {
1290                        const float rcCost = ComputeRenderCost(vc);
1291                        mViewCellsManager->UpdateScalarPvsCost(vc, rcCost);
1292
1293                        if (rcCost > maxRcCost)
1294                                maxRcCost = rcCost;
1295                }
1296        }
1297}
1298
1299
1300
1301void QtGlRendererWidget::FillNewContainer(const ViewCellContainer &viewCells, ViewCellInfoContainer &infos)
1302{
1303        ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
1304
1305        for (vit = viewCells.begin(); vit != vit_end; ++ vit)
1306        {
1307        ViewCell *vc = *vit;
1308                ViewCellInfo info;
1309
1310                info.mPiercingRays = vc->GetNumPiercingRays();
1311
1312                infos.push_back(info);
1313                //myfile << "vc: " << vc->GetPvs().GetSize() << " " << vc->GetNumPiercingRays();
1314        }
1315}
1316
1317
1318
1319void QtGlRendererWidget::RenderViewCells()
1320{
1321        mUseFalseColors = true;
1322
1323        //glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
1324
1325        glEnable(GL_CULL_FACE);
1326        glCullFace(GL_FRONT);
1327        //glDisable(GL_CULL_FACE);
1328
1329        double eq[4];
1330        eq[0] = mSceneCutPlane.mNormal.x;
1331        eq[1] = mSceneCutPlane.mNormal.y;
1332        eq[2] = mSceneCutPlane.mNormal.z;
1333        eq[3] = mSceneCutPlane.mD;
1334
1335        if (mCutViewCells)
1336        {
1337                glClipPlane(GL_CLIP_PLANE0, eq);
1338                glEnable(GL_CLIP_PLANE0);
1339        }
1340
1341        int i;
1342
1343        mRecordHist = false;
1344        //mRecordHist = true;
1345
1346        ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
1347       
1348        if (mRecordHist && (mSamples > mNextSamples))
1349        {
1350                mNextSamples += 2000000;
1351
1352                ViewCellInfoContainer *newContainer = new ViewCellInfoContainer();
1353
1354                FillNewContainer(viewcells, *newContainer);
1355                mCurrentHist[mNextSamples] = newContainer;
1356        }
1357
1358        int maxPvs, maxPiercingRays;
1359        float maxRelativeRays, maxRcCost;
1360
1361        ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
1362
1363
1364        if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost)
1365        {
1366                for (i = 0; i < viewcells.size(); ++ i)
1367                {
1368                        ViewCell *vc = viewcells[i];
1369                        RgbColor c;
1370
1371                        if (!mShowPvsSizes && !mShowPiercingRays)
1372                        {
1373                                mWireFrame = true;
1374                                c = vc->GetColor();
1375                        }
1376
1377                        glColor3f(c.r, c.g, c.b);
1378
1379                        if (!mHideByCost || (mHidingCost < (vc->GetNumPiercingRays() / (float)maxPiercingRays)))
1380                        {
1381                RenderViewCell(vc);
1382                        }
1383                }
1384        }
1385        else
1386        {
1387                // transparency
1388                if (!mUseTransparency)
1389                {
1390                        glEnable(GL_DEPTH_TEST);
1391                        glDisable(GL_BLEND);
1392                }
1393                else
1394                {
1395                        glDisable(GL_DEPTH_TEST);
1396                        glEnable(GL_BLEND);
1397
1398                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1399                        //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
1400
1401                        for (i = 0; i < viewcells.size(); ++ i)
1402                        {
1403                                ViewCell *vc = viewcells[i];
1404
1405                                const float dist = SqrDistance(mDummyViewPoint, vc->GetBox().Center());
1406                                vc->SetDistance(dist);
1407                        }
1408
1409                        sort(viewcells.begin(), viewcells.end(), nearerThan);
1410                }
1411
1412                if (mAssignImportanceByRelativeValue)
1413                        AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
1414                else
1415                {
1416                        ViewCellInfoContainer *infos1 = mCurrentHist[mCurrentSamples];
1417                        ViewCellInfoContainer *infos2 = mCompareHist[mCurrentSamples];
1418                        AssignColorByComparison(viewcells, *infos1, *infos2);
1419                }
1420
1421
1422                glEnable(GL_DEPTH_TEST);       
1423        }
1424       
1425        glEnable(GL_CULL_FACE);
1426        glDisable(GL_CULL_FACE);
1427
1428        glDisable(GL_CLIP_PLANE0);
1429
1430        mUseFalseColors = false;
1431        mWireFrame = false;
1432
1433        glPopAttrib();
1434}
1435
1436
1437void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
1438                                                                                                                 int &maxPvs,
1439                                                                                                                 int &maxPiercingRays,
1440                                                                                                                 float &maxRelativeRays,
1441                                                                                                                 float &maxRcCost)
1442{
1443        for (size_t i = 0; i < viewCells.size(); ++ i)
1444        {
1445                RgbColor c;
1446                ViewCell *vc = viewCells[i];
1447
1448                float importance;
1449
1450                if (mShowPiercingRays)
1451                {
1452                        importance = mTransferFunction *
1453                                ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
1454                }
1455                else if (mShowWeightedRays) // relative number of rays
1456                {
1457                        float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
1458
1459                        if (relativeArea < Limits::Small)
1460                                relativeArea = Limits::Small;
1461
1462                        importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
1463                }
1464                else if (mShowPvsSizes) // pvs size
1465                {
1466                        importance = mTransferFunction *
1467                                ((float)vc->GetPvs().GetSize() / (float)maxPvs);
1468                } // weighted render cost
1469                else if (mShowWeightedCost)
1470                {
1471                        const float rcCost = mTransferFunction * ComputeRenderCost(vc);
1472                        importance = rcCost / maxRcCost;
1473                }
1474
1475                // c = RgbColor(importance, 1.0f - importance, 0.0f);
1476                c = RainbowColorMapping(importance);
1477
1478                glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
1479
1480                if (!mHideByCost || (mHidingCost < importance))
1481                {
1482                        RenderViewCell(vc);
1483                }
1484        }
1485}
1486
1487
1488void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells,
1489                                                                                                 const ViewCellInfoContainer &infos1,
1490                                                                                                 const ViewCellInfoContainer &infos2)
1491{
1492
1493        const float maxRatio = 2;
1494        const float minRatio = 0.5;
1495
1496        const float scale = 1.0f / (maxRatio - minRatio);
1497
1498        for (size_t i = 0; i < viewcells.size(); ++ i)
1499        {
1500                RgbColor c;
1501                ViewCell *vc = viewcells[i];
1502
1503                ViewCellInfo vc1Info = infos1[i];
1504                ViewCellInfo vc2Info = infos2[i];
1505
1506                const float vcRatio = vc1Info.mPiercingRays / vc2Info.mPiercingRays + Limits::Small;
1507
1508                const float importance = (vcRatio - minRatio) * scale;
1509
1510                // c = RgbColor(importance, 1.0f - importance, 0.0f);
1511                c = RainbowColorMapping(importance);
1512
1513                glColor4f(c.r, c.g, c.b, 1.0f);
1514
1515                if (1)//!mHideByCost || (mHidingCost < importance))
1516                {
1517                        RenderViewCell(vc);
1518                }
1519        }
1520}
1521
1522
1523
1524/**********************************************************************/
1525/*              QtRendererControlWidget implementation                */
1526/**********************************************************************/
1527
1528#if 1
1529QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent)
1530{
1531        QRadioButton *rb1, *rb2, *rb3, *rb4, *rb5;
1532       
1533        // Create a check box to be in the group box
1534        rb1 = new QRadioButton("piercing rays", parent);
1535        rb1->setText("piercing rays");
1536        //vl->addWidget(rb1);
1537        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
1538
1539        rb2 = new QRadioButton("pvs size", parent);
1540        rb2->setText("pvs size");
1541        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
1542
1543        rb3 = new QRadioButton("wireframe", parent);
1544        rb3->setText("wireframe");
1545       
1546        rb4 = new QRadioButton("weighted rays", parent);
1547        rb4->setText("weighted rays");
1548        connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedRays(bool)));
1549       
1550        rb5 = new QRadioButton("pvs cost", parent);
1551        rb5->setText("pvs cost");
1552        connect(rb5, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedCost(bool)));
1553
1554        QGroupBox *groupBox = new QGroupBox("Visualization options");
1555
1556        QVBoxLayout *vbox2 = new QVBoxLayout;
1557   
1558        vbox2->addWidget(rb3);
1559        vbox2->addWidget(rb1);
1560        vbox2->addWidget(rb2);
1561        vbox2->addWidget(rb4);
1562        vbox2->addWidget(rb5);
1563       
1564        rb3->setChecked(true);
1565
1566        vbox2->addStretch(1);
1567        groupBox->setLayout(vbox2);
1568
1569        return groupBox;
1570}
1571
1572
1573
1574QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent)
1575{
1576        QRadioButton *rb1, *rb2, *rb3;
1577       
1578        // Create a check box to be in the group box
1579        rb1 = new QRadioButton("triangles", parent);
1580        rb1->setText("triangles");
1581        //vl->addWidget(rb1);
1582        connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedTriangles(bool)));
1583
1584        rb2 = new QRadioButton("distance weighted pvs", parent);
1585        rb2->setText("distance weighted");
1586        connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedPvs(bool)));
1587
1588        rb3 = new QRadioButton("distance weighted triangles", parent);
1589        rb3->setText("distance weighted triangles");
1590        connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedTriangles(bool)));
1591
1592        QGroupBox *groupBox = new QGroupBox("Render cost options");
1593
1594        QVBoxLayout *vbox2 = new QVBoxLayout;
1595   
1596        vbox2->addWidget(rb1);
1597        vbox2->addWidget(rb2);
1598        vbox2->addWidget(rb3);
1599       
1600        rb2->setChecked(true);
1601
1602        vbox2->addStretch(1);
1603        groupBox->setLayout(vbox2);
1604
1605        return groupBox;
1606}
1607
1608
1609QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
1610QWidget(parent, f)
1611{
1612
1613        QVBoxLayout *vl = new QVBoxLayout;
1614        setLayout(vl);
1615
1616        QWidget *vbox = new QGroupBox("ViewCells", this);
1617        layout()->addWidget(vbox);
1618
1619        vl = new QVBoxLayout;
1620        vbox->setLayout(vl);
1621
1622        QLabel *label = new QLabel("Granularity");
1623        vbox->layout()->addWidget(label);
1624
1625        QSlider *slider = new QSlider(Qt::Horizontal, vbox);
1626        vl->addWidget(slider);
1627        slider->show();
1628        slider->setRange(1, 10000);
1629        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1630        slider->setValue(200);
1631
1632        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
1633
1634        ///////////////////////////
1635
1636        label = new QLabel("Transfer function");
1637        vbox->layout()->addWidget(label);
1638
1639        slider = new QSlider(Qt::Horizontal, vbox);
1640        vl->addWidget(slider);
1641        slider->show();
1642        slider->setRange(1, 10000);
1643        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1644        slider->setValue(100);
1645
1646
1647        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
1648
1649        ////////////////////////////////////////7
1650
1651
1652        QPushButton *button = new QPushButton("Update all PVSs", vbox);
1653        vbox->layout()->addWidget(button);
1654        connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
1655
1656
1657        ////////////////////////////////////////77777
1658
1659        label = new QLabel("Filter size");
1660        vbox->layout()->addWidget(label);
1661
1662        slider = new QSlider(Qt::Horizontal, vbox);
1663        vbox->layout()->addWidget(slider);
1664        slider->show();
1665        slider->setRange(1, 100);
1666        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1667        slider->setValue(3);
1668
1669        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
1670
1671
1672        //////////////////////////////////////////
1673
1674        label = new QLabel("Spatial Filter size");
1675        vbox->layout()->addWidget(label);
1676
1677        slider = new QSlider(Qt::Horizontal, vbox);
1678        vbox->layout()->addWidget(slider);
1679        slider->show();
1680        slider->setRange(1, 100);
1681        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1682        slider->setValue(10);
1683
1684        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
1685
1686
1687        ///////////////////////////////////
1688
1689
1690        QWidget *hbox = new QWidget(vbox);
1691        vl->addWidget(hbox);
1692        QHBoxLayout *hlayout = new QHBoxLayout;
1693        hbox->setLayout(hlayout);
1694
1695        QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
1696        hlayout->addWidget(cb);
1697        cb->setChecked(false);
1698        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
1699
1700        cb = new QCheckBox("Render cost curve", hbox);
1701        hlayout->addWidget(cb);
1702        cb->setChecked(false);
1703        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
1704
1705        cb = new QCheckBox("Show rays", hbox);
1706        hlayout->addWidget(cb);
1707        cb->setChecked(false);
1708        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
1709
1710
1711        //////////////////
1712
1713        QHBoxLayout *vh = new QHBoxLayout;
1714
1715        QGroupBox *myBox = new QGroupBox("Visualization");
1716
1717        myBox->setLayout(vh);
1718
1719        vl->addWidget(myBox, 0, 0);
1720
1721        QGroupBox *groupBox = CreateVisualizationPanel(hbox);
1722
1723        vh->addWidget(groupBox, 0, 0);
1724
1725        QGroupBox *groupBox2 = CreateRenderCostPanel(hbox);
1726
1727        vh->addWidget(groupBox2, 0, 0);
1728
1729        //////////////////////////////////
1730
1731
1732        /*cb = new QRadiobox("Top View", vbox);
1733        vbox->layout()->addWidget(cb);
1734        cb->setChecked(false);
1735        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
1736*/
1737
1738        vbox->resize(800,150);
1739
1740
1741        vbox = new QGroupBox("Rendering", this);
1742        layout()->addWidget(vbox);
1743
1744        vl = new QVBoxLayout;
1745        vbox->setLayout(vl);
1746
1747
1748
1749        cb = new QCheckBox("Cut view cells", vbox);
1750        vbox->layout()->addWidget(cb);
1751        cb->setChecked(false);
1752        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
1753
1754
1755        slider = new QSlider(Qt::Horizontal, vbox);
1756        vbox->layout()->addWidget(slider);
1757        slider->show();
1758        slider->setRange(0, 1000);
1759        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1760        slider->setValue(1000);
1761
1762        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
1763
1764       
1765        cb = new QCheckBox("Hide view cells by render cost ", vbox);
1766        vbox->layout()->addWidget(cb);
1767        cb->setChecked(false);
1768        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool)));
1769
1770        ////////////////////////////
1771
1772        const int range = 1000;
1773
1774        label = new QLabel("Hide by cost");
1775        vbox->layout()->addWidget(label);
1776
1777        // the render cost visualization
1778        slider = new QSlider(Qt::Horizontal, vbox);
1779        vbox->layout()->addWidget(slider);
1780        slider->show();
1781        slider->setRange(0, range);
1782        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1783        slider->setValue(0);
1784        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int)));
1785
1786        ///////////////////////////////////////////
1787
1788        cb = new QCheckBox("Top View", vbox);
1789        vbox->layout()->addWidget(cb);
1790        cb->setChecked(false);
1791        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
1792
1793
1794        label = new QLabel("Top distance");
1795        vbox->layout()->addWidget(label);
1796       
1797        slider = new QSlider(Qt::Horizontal, vbox);
1798        vbox->layout()->addWidget(slider);
1799        slider->show();
1800        slider->setRange(1, 1000);
1801        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1802        slider->setValue(500);
1803
1804        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
1805       
1806
1807        ///////////////////////////////////////////
1808
1809        cb = new QCheckBox("Transparency", vbox);
1810        vbox->layout()->addWidget(cb);
1811        cb->setChecked(false);
1812        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseTransparency(bool)));
1813
1814        label = new QLabel("Use transparency");
1815        vbox->layout()->addWidget(label);
1816
1817        // the render cost visualization
1818        slider = new QSlider(Qt::Horizontal, vbox);
1819        vbox->layout()->addWidget(slider);
1820        slider->show();
1821        slider->setRange(0, range);
1822        slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1823        slider->setValue(0);
1824
1825        connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int)));
1826
1827        //////////////////////////////
1828
1829
1830        cb = new QCheckBox("Cut scene", vbox);
1831        vbox->layout()->addWidget(cb);
1832        cb->setChecked(false);
1833        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
1834
1835        cb = new QCheckBox("Render boxes", vbox);
1836        vbox->layout()->addWidget(cb);
1837        cb->setChecked(false);
1838        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
1839
1840        cb = new QCheckBox("Render visibility estimates", vbox);
1841        vbox->layout()->addWidget(cb);
1842        cb->setChecked(false);
1843        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
1844
1845
1846        cb = new QCheckBox("Render errors", vbox);
1847        vbox->layout()->addWidget(cb);
1848        cb->setChecked(false);
1849        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
1850
1851
1852        bool tmp;
1853
1854        cb = new QCheckBox("Use filter", vbox);
1855        vbox->layout()->addWidget(cb);
1856        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
1857        cb->setChecked(tmp);
1858        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
1859
1860
1861        cb = new QCheckBox("Use spatial filter", vbox);
1862        vbox->layout()->addWidget(cb);
1863        Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
1864                tmp );
1865        cb->setChecked(tmp);
1866        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
1867
1868        cb = new QCheckBox("Render filter", vbox);
1869        vbox->layout()->addWidget(cb);
1870        cb->setChecked(true);
1871        connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
1872
1873
1874        vbox = new QGroupBox("PVS Errors", this);
1875        layout()->addWidget(vbox);
1876
1877        vl = new QVBoxLayout;
1878        vbox->setLayout(vl);
1879
1880        button = new QPushButton("Compute Visibility", vbox);
1881        vbox->layout()->addWidget(button);
1882        connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
1883
1884        button = new QPushButton("Stop Computation", vbox);
1885        vbox->layout()->addWidget(button);
1886        connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
1887
1888        button = new QPushButton("Set Random View Point", vbox);
1889        vbox->layout()->addWidget(button);
1890        connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
1891
1892
1893        if (0)
1894        {
1895                vbox = new QGroupBox("PVS Errors", this);
1896                layout()->addWidget(vbox);
1897
1898                vl = new QVBoxLayout;
1899                vbox->setLayout(vl);
1900
1901                mPvsErrorWidget = new QListWidget(vbox);
1902                vbox->layout()->addWidget(mPvsErrorWidget);
1903
1904                connect(mPvsErrorWidget,
1905                        SIGNAL(doubleClicked(const QModelIndex &)),
1906                        this,
1907                        SLOT(PvsErrorClicked(const QModelIndex &)));
1908
1909                button = new QPushButton("Next Error Frame", vbox);
1910                vbox->layout()->addWidget(button);
1911                connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
1912        }
1913       
1914        //mHidingCost = 0.1f;
1915
1916        setWindowTitle("Preprocessor Control Widget");
1917        adjustSize();
1918}
1919
1920
1921
1922
1923void
1924QtRendererControlWidget::FocusNextPvsErrorFrame(void)
1925{}
1926
1927void
1928QtRendererControlWidget::UpdatePvsErrorItem(int row,
1929                                                                                        GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
1930{
1931
1932        QListWidgetItem *i = mPvsErrorWidget->item(row);
1933        QString s;
1934        s.sprintf("%5.5f", pvsErrorEntry.mError);
1935        if (i) {
1936                i->setText(s);
1937        } else {
1938                new QListWidgetItem(s, mPvsErrorWidget);
1939        }
1940        mPvsErrorWidget->update();
1941}
1942
1943
1944
1945#endif
1946
1947
1948/*********************************************************************/
1949/*                   QtGlDebuggerWidget implementation               */
1950/*********************************************************************/
1951
1952
1953QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
1954: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
1955{
1956        // create the pbuffer
1957        //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
1958        timerId = startTimer(20);
1959        setWindowTitle(("OpenGL pbuffers"));
1960}
1961
1962
1963QtGlDebuggerWidget::~QtGlDebuggerWidget()
1964{
1965        mRenderBuffer->releaseFromDynamicTexture();
1966        glDeleteTextures(1, &dynamicTexture);
1967
1968        DEL_PTR(mRenderBuffer);
1969}
1970
1971
1972void QtGlDebuggerWidget::initializeGL()
1973{
1974        glMatrixMode(GL_PROJECTION);
1975        glLoadIdentity();
1976
1977        glFrustum(-1, 1, -1, 1, 10, 100);
1978        glTranslatef(-0.5f, -0.5f, -0.5f);
1979        glTranslatef(0.0f, 0.0f, -15.0f);
1980        glMatrixMode(GL_MODELVIEW);
1981
1982        glEnable(GL_CULL_FACE);
1983        initCommon();
1984        initPbuffer();
1985
1986}
1987
1988
1989void QtGlDebuggerWidget::resizeGL(int w, int h)
1990{
1991        glViewport(0, 0, w, h);
1992}
1993
1994
1995void QtGlDebuggerWidget::paintGL()
1996{
1997        // draw a spinning cube into the pbuffer..
1998        mRenderBuffer->makeCurrent();
1999
2000        BeamSampleStatistics stats;
2001        mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
2002
2003        glFlush();
2004
2005        // rendering directly to a texture is not supported on X11, unfortunately
2006        mRenderBuffer->updateDynamicTexture(dynamicTexture);
2007
2008        // and use the pbuffer contents as a texture when rendering the
2009        // background and the bouncing cubes
2010        makeCurrent();
2011        glBindTexture(GL_TEXTURE_2D, dynamicTexture);
2012        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2013
2014        // draw the background
2015        glMatrixMode(GL_MODELVIEW);
2016        glPushMatrix();
2017        glLoadIdentity();
2018        glMatrixMode(GL_PROJECTION);
2019        glPushMatrix();
2020        glLoadIdentity();
2021
2022        glPopMatrix();
2023        glMatrixMode(GL_MODELVIEW);
2024        glPopMatrix();
2025}
2026
2027
2028void QtGlDebuggerWidget::initPbuffer()
2029{
2030        // set up the pbuffer context
2031        mRenderBuffer->makeCurrent();
2032        /*mRenderBuffer->InitGL();
2033
2034        glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
2035        glMatrixMode(GL_PROJECTION);
2036        glLoadIdentity();
2037        glOrtho(-1, 1, -1, 1, -99, 99);
2038        glTranslatef(-0.5f, -0.5f, 0.0f);
2039        glMatrixMode(GL_MODELVIEW);
2040        glLoadIdentity();
2041
2042        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
2043
2044        // generate a texture that has the same size/format as the pbuffer
2045        dynamicTexture = mRenderBuffer->generateDynamicTexture();
2046
2047        // bind the dynamic texture to the pbuffer - this is a no-op under X11
2048        mRenderBuffer->bindToDynamicTexture(dynamicTexture);
2049        makeCurrent();
2050}
2051
2052
2053void QtGlDebuggerWidget::initCommon()
2054{
2055        glEnable(GL_TEXTURE_2D);
2056        glEnable(GL_DEPTH_TEST);
2057
2058        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
2059}
2060
2061
2062}
Note: See TracBrowser for help on using the repository browser.