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