[589] | 1 | #include "Mesh.h"
|
---|
[1001] | 2 | #include "glInterface.h"
|
---|
| 3 | #include "OcclusionQuery.h"
|
---|
[589] | 4 | #include "GlRenderer.h"
|
---|
| 5 | #include "ViewCellsManager.h"
|
---|
| 6 | #include "SceneGraph.h"
|
---|
| 7 | #include "Pvs.h"
|
---|
| 8 | #include "Viewcell.h"
|
---|
| 9 | #include "Beam.h"
|
---|
[532] | 10 | #include "KdTree.h"
|
---|
[589] | 11 | #include "Environment.h"
|
---|
[513] | 12 |
|
---|
[1146] | 13 | //#include <Cg/cg.h>
|
---|
| 14 | //#include <Cg/cgGL.h>
|
---|
[1001] | 15 |
|
---|
| 16 |
|
---|
[863] | 17 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 18 |
|
---|
[516] | 19 |
|
---|
[1112] | 20 | static bool arbQuerySupport = false;
|
---|
| 21 | static bool nvQuerySupport = false;
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | static void InitExtensions()
|
---|
| 25 | {
|
---|
| 26 | GLenum err = glewInit();
|
---|
| 27 |
|
---|
| 28 | if (GLEW_OK != err)
|
---|
| 29 | {
|
---|
| 30 | // problem: glewInit failed, something is seriously wrong
|
---|
| 31 | cerr << "Error: " << glewGetErrorString(err) << endl;
|
---|
| 32 | exit(1);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | if (GLEW_ARB_occlusion_query)
|
---|
| 36 | arbQuerySupport = true;
|
---|
| 37 |
|
---|
| 38 | if (GLEW_NV_occlusion_query)
|
---|
| 39 | nvQuerySupport = true;
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | if (!arbQuerySupport && !nvQuerySupport)
|
---|
| 43 | {
|
---|
| 44 | cout << "I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n";
|
---|
| 45 | exit(1);
|
---|
| 46 | }
|
---|
[1001] | 47 | }
|
---|
[589] | 48 |
|
---|
[811] | 49 |
|
---|
[589] | 50 | GlRenderer::GlRenderer(SceneGraph *sceneGraph,
|
---|
| 51 | ViewCellsManager *viewCellsManager,
|
---|
| 52 | KdTree *tree):
|
---|
| 53 | Renderer(sceneGraph, viewCellsManager),
|
---|
| 54 | mKdTree(tree)
|
---|
| 55 | {
|
---|
| 56 | mSceneGraph->CollectObjects(&mObjects);
|
---|
[1112] | 57 |
|
---|
| 58 | // mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
| 59 |
|
---|
[589] | 60 | mViewPoint = mSceneGraph->GetBox().Center();
|
---|
| 61 | mViewDirection = Vector3(0,0,1);
|
---|
[608] | 62 |
|
---|
[1112] | 63 | // mViewPoint = Vector3(991.7, 187.8, -271);
|
---|
| 64 | // mViewDirection = Vector3(0.9, 0, -0.4);
|
---|
[878] | 65 |
|
---|
[589] | 66 | // timerId = startTimer(10);
|
---|
| 67 | // debug coords for atlanta
|
---|
[608] | 68 | // mViewPoint = Vector3(3473, 6.778, -1699);
|
---|
| 69 | // mViewDirection = Vector3(-0.2432, 0, 0.97);
|
---|
[589] | 70 |
|
---|
| 71 | mFrame = 0;
|
---|
| 72 | mWireFrame = false;
|
---|
[1004] | 73 | Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
|
---|
[746] | 74 | mSnapErrorFrames = true;
|
---|
| 75 | mSnapPrefix = "snap/";
|
---|
| 76 | mUseForcedColors = false;
|
---|
[811] | 77 |
|
---|
| 78 | mUseGlLists = true;
|
---|
[1001] | 79 | //mUseGlLists = false;
|
---|
[589] | 80 | }
|
---|
| 81 |
|
---|
| 82 | GlRenderer::~GlRenderer()
|
---|
| 83 | {
|
---|
| 84 | cerr<<"gl renderer destructor..\n";
|
---|
[1145] | 85 |
|
---|
| 86 | //CLEAR_CONTAINER(sQueries);
|
---|
[1001] | 87 | CLEAR_CONTAINER(mOcclusionQueries);
|
---|
[589] | 88 |
|
---|
[1145] | 89 | cerr<<"done."<<endl;
|
---|
[589] | 90 | }
|
---|
| 91 |
|
---|
[1145] | 92 |
|
---|
[589] | 93 | void
|
---|
| 94 | GlRenderer::RenderIntersectable(Intersectable *object)
|
---|
| 95 | {
|
---|
| 96 |
|
---|
| 97 | glPushAttrib(GL_CURRENT_BIT);
|
---|
| 98 | if (mUseFalseColors)
|
---|
| 99 | SetupFalseColor(object->mId);
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | switch (object->Type()) {
|
---|
| 103 | case Intersectable::MESH_INSTANCE:
|
---|
| 104 | RenderMeshInstance((MeshInstance *)object);
|
---|
| 105 | break;
|
---|
| 106 | case Intersectable::VIEW_CELL:
|
---|
| 107 | RenderViewCell(dynamic_cast<ViewCell *>(object));
|
---|
| 108 | break;
|
---|
[1001] | 109 | case Intersectable::TRANSFORMED_MESH_INSTANCE:
|
---|
| 110 | RenderTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
|
---|
| 111 | break;
|
---|
[589] | 112 | default:
|
---|
| 113 | cerr<<"Rendering this object not yet implemented\n";
|
---|
| 114 | break;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | glPopAttrib();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | void
|
---|
| 122 | GlRenderer::RenderViewCell(ViewCell *vc)
|
---|
| 123 | {
|
---|
| 124 | if (vc->GetMesh()) {
|
---|
| 125 |
|
---|
[599] | 126 | if (!mUseFalseColors) {
|
---|
| 127 | if (vc->GetValid())
|
---|
| 128 | glColor3f(0,1,0);
|
---|
| 129 | else
|
---|
| 130 | glColor3f(0,0,1);
|
---|
| 131 | }
|
---|
[589] | 132 |
|
---|
| 133 | RenderMesh(vc->GetMesh());
|
---|
[599] | 134 | } else {
|
---|
| 135 | // render viewcells in the subtree
|
---|
| 136 | if (!vc->IsLeaf()) {
|
---|
| 137 | ViewCellInterior *vci = (ViewCellInterior *) vc;
|
---|
| 138 |
|
---|
| 139 | ViewCellContainer::iterator it = vci->mChildren.begin();
|
---|
| 140 | for (; it != vci->mChildren.end(); ++it) {
|
---|
| 141 | RenderViewCell(*it);
|
---|
| 142 | }
|
---|
[685] | 143 | } else {
|
---|
| 144 | // cerr<<"Empty viewcell mesh\n";
|
---|
[599] | 145 | }
|
---|
[589] | 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[599] | 149 |
|
---|
[589] | 150 | void
|
---|
| 151 | GlRenderer::RenderMeshInstance(MeshInstance *mi)
|
---|
| 152 | {
|
---|
| 153 | RenderMesh(mi->GetMesh());
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[1001] | 156 |
|
---|
[589] | 157 | void
|
---|
[1001] | 158 | GlRenderer::RenderTransformedMeshInstance(TransformedMeshInstance *mi)
|
---|
| 159 | {
|
---|
| 160 | // apply world transform before rendering
|
---|
| 161 | Matrix4x4 m;
|
---|
| 162 | mi->GetWorldTransform(m);
|
---|
| 163 |
|
---|
| 164 | glPushMatrix();
|
---|
[1002] | 165 | /* cout << "\n";
|
---|
[1001] | 166 | for (int i = 0; i < 4; ++ i)
|
---|
| 167 | for (int j = 0; j < 4; ++ j)
|
---|
[1002] | 168 | cout << m.x[i][j] << " "; cout << "\n"*/
|
---|
[1001] | 169 |
|
---|
| 170 | glMultMatrixf((float *)m.x);
|
---|
| 171 |
|
---|
[1002] | 172 | /*GLfloat dummy[16];
|
---|
| 173 | glGetFloatv(GL_MODELVIEW_MATRIX, dummy);
|
---|
[1001] | 174 | for (int i = 0; i < 16; ++ i)
|
---|
| 175 | cout << dummy[i] << " ";
|
---|
| 176 | cout << endl;*/
|
---|
| 177 | RenderMesh(mi->GetMesh());
|
---|
| 178 |
|
---|
| 179 | glPopMatrix();
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 |
|
---|
| 183 | void
|
---|
[589] | 184 | GlRenderer::SetupFalseColor(const int id)
|
---|
| 185 | {
|
---|
| 186 | // swap bits of the color
|
---|
| 187 | glColor3ub(id&255, (id>>8)&255, (id>>16)&255);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | int GlRenderer::GetId(int r, int g, int b) const
|
---|
| 192 | {
|
---|
| 193 | return r + (g << 8) + (b << 16);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | void
|
---|
| 197 | GlRenderer::SetupMaterial(Material *m)
|
---|
| 198 | {
|
---|
| 199 | if (m)
|
---|
| 200 | glColor3fv(&(m->mDiffuseColor.r));
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void
|
---|
| 204 | GlRenderer::RenderMesh(Mesh *mesh)
|
---|
| 205 | {
|
---|
| 206 | int i = 0;
|
---|
| 207 |
|
---|
[746] | 208 | if (!mUseFalseColors && !mUseForcedColors)
|
---|
[589] | 209 | SetupMaterial(mesh->mMaterial);
|
---|
| 210 |
|
---|
| 211 | for (i=0; i < mesh->mFaces.size(); i++) {
|
---|
| 212 | if (mWireFrame)
|
---|
| 213 | glBegin(GL_LINE_LOOP);
|
---|
| 214 | else
|
---|
| 215 | glBegin(GL_POLYGON);
|
---|
| 216 |
|
---|
| 217 | Face *face = mesh->mFaces[i];
|
---|
| 218 | for (int j = 0; j < face->mVertexIndices.size(); j++) {
|
---|
| 219 | glVertex3fv(&mesh->mVertices[face->mVertexIndices[j]].x);
|
---|
| 220 | }
|
---|
| 221 | glEnd();
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | void
|
---|
| 226 | GlRenderer::InitGL()
|
---|
| 227 | {
|
---|
| 228 | glMatrixMode(GL_PROJECTION);
|
---|
| 229 | glLoadIdentity();
|
---|
| 230 |
|
---|
| 231 | glMatrixMode(GL_MODELVIEW);
|
---|
| 232 | glLoadIdentity();
|
---|
| 233 |
|
---|
| 234 | glEnable(GL_CULL_FACE);
|
---|
| 235 | glShadeModel(GL_FLAT);
|
---|
| 236 | glEnable(GL_DEPTH_TEST);
|
---|
| 237 | glEnable(GL_CULL_FACE);
|
---|
| 238 |
|
---|
[1001] | 239 | InitExtensions();
|
---|
[811] | 240 |
|
---|
[746] | 241 | #if 0
|
---|
| 242 | GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
|
---|
| 243 | /* mat_specular and mat_shininess are NOT default values */
|
---|
| 244 | GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
| 245 | GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
| 246 | GLfloat mat_shininess[] = { 1.0 };
|
---|
| 247 |
|
---|
| 248 | GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
---|
| 249 | GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 };
|
---|
| 250 | GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
| 251 |
|
---|
| 252 | GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
| 253 |
|
---|
| 254 |
|
---|
| 255 | // default Material
|
---|
| 256 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
| 257 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
| 258 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
| 259 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
| 260 |
|
---|
| 261 | // a light
|
---|
| 262 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
| 263 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
| 264 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
| 265 |
|
---|
| 266 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
| 267 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
| 268 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
| 269 |
|
---|
| 270 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
| 271 |
|
---|
| 272 | glEnable(GL_LIGHTING);
|
---|
| 273 | glEnable(GL_LIGHT0);
|
---|
| 274 | glEnable(GL_LIGHT1);
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | // set position of the light
|
---|
| 278 | GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 };
|
---|
| 279 | glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
|
---|
| 280 |
|
---|
| 281 | // set position of the light2
|
---|
| 282 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
| 283 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
| 284 |
|
---|
| 285 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
| 286 | // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
| 287 | glEnable(GL_COLOR_MATERIAL);
|
---|
| 288 |
|
---|
| 289 | glShadeModel( GL_FLAT );
|
---|
| 290 |
|
---|
| 291 | glDepthFunc( GL_LESS );
|
---|
| 292 | glEnable( GL_DEPTH_TEST );
|
---|
| 293 | #endif
|
---|
| 294 |
|
---|
| 295 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
|
---|
| 296 |
|
---|
| 297 | glEnable( GL_NORMALIZE );
|
---|
| 298 |
|
---|
| 299 | glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
|
---|
[589] | 300 | }
|
---|
| 301 |
|
---|
[746] | 302 |
|
---|
[589] | 303 | void
|
---|
[811] | 304 | GlRenderer::SetupProjection(const int w, const int h, const float angle)
|
---|
[589] | 305 | {
|
---|
| 306 | glViewport(0, 0, w, h);
|
---|
| 307 | glMatrixMode(GL_PROJECTION);
|
---|
| 308 | glLoadIdentity();
|
---|
[811] | 309 | gluPerspective(angle, 1.0, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
[589] | 310 | glMatrixMode(GL_MODELVIEW);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | void
|
---|
| 314 | GlRenderer::SetupCamera()
|
---|
| 315 | {
|
---|
| 316 | Vector3 target = mViewPoint + mViewDirection;
|
---|
[811] | 317 |
|
---|
[589] | 318 | Vector3 up(0,1,0);
|
---|
| 319 |
|
---|
[811] | 320 | if (abs(DotProd(mViewDirection, up)) > 0.99f)
|
---|
| 321 | up = Vector3(1, 0, 0);
|
---|
| 322 |
|
---|
[589] | 323 | glLoadIdentity();
|
---|
| 324 | gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,
|
---|
| 325 | target.x, target.y, target.z,
|
---|
| 326 | up.x, up.y, up.z);
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[1145] | 329 | void
|
---|
| 330 | GlRenderer::_RenderScene()
|
---|
| 331 | {
|
---|
| 332 | ObjectContainer::const_iterator oi = mObjects.begin();
|
---|
[811] | 333 |
|
---|
[1145] | 334 | for (; oi != mObjects.end(); oi++)
|
---|
| 335 | RenderIntersectable(*oi);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | bool
|
---|
| 339 | GlRenderer::RenderScene()
|
---|
| 340 | {
|
---|
| 341 | static int glList = -1;
|
---|
| 342 | if (mUseGlLists) {
|
---|
| 343 | if (glList == -1) {
|
---|
| 344 | glList = glGenLists(1);
|
---|
| 345 | glNewList(glList, GL_COMPILE);
|
---|
| 346 | _RenderScene();
|
---|
| 347 | glEndList();
|
---|
| 348 | }
|
---|
| 349 | glCallList(glList);
|
---|
| 350 | } else
|
---|
| 351 | _RenderScene();
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 | return true;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 |
|
---|
[589] | 358 | void
|
---|
[997] | 359 | GlRendererBuffer::EvalQueryWithItemBuffer(
|
---|
[1001] | 360 | //RenderCostSample &sample
|
---|
[997] | 361 | )
|
---|
| 362 | {
|
---|
| 363 | // read back the texture
|
---|
| 364 | glReadPixels(0, 0,
|
---|
| 365 | GetWidth(), GetHeight(),
|
---|
| 366 | GL_RGBA,
|
---|
| 367 | GL_UNSIGNED_BYTE,
|
---|
| 368 | mPixelBuffer);
|
---|
| 369 |
|
---|
| 370 |
|
---|
| 371 | unsigned int *p = mPixelBuffer;
|
---|
| 372 |
|
---|
| 373 | for (int y = 0; y < GetHeight(); y++)
|
---|
| 374 | {
|
---|
| 375 | for (int x = 0; x < GetWidth(); x++, p++)
|
---|
| 376 | {
|
---|
| 377 | unsigned int id = (*p) & 0xFFFFFF;
|
---|
| 378 |
|
---|
| 379 | if (id != 0xFFFFFF)
|
---|
| 380 | ++ mObjects[id]->mCounter;
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[1145] | 385 |
|
---|
| 386 |
|
---|
| 387 | /****************************************************************/
|
---|
| 388 | /* GlRendererBuffer implementation */
|
---|
| 389 | /****************************************************************/
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 |
|
---|
| 393 | GlRendererBuffer::GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
| 394 | ViewCellsManager *viewcells,
|
---|
| 395 | KdTree *tree):
|
---|
| 396 | GlRenderer(sceneGraph, viewcells, tree)
|
---|
| 397 | {
|
---|
| 398 | mPixelBuffer = NULL;
|
---|
| 399 |
|
---|
| 400 | // implement width and height in subclasses
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
[997] | 404 | void
|
---|
| 405 | GlRendererBuffer::EvalQueryWithOcclusionQueries(
|
---|
| 406 | //RenderCostSample &sample
|
---|
| 407 | )
|
---|
| 408 | {
|
---|
| 409 | glDepthFunc(GL_LEQUAL);
|
---|
| 410 |
|
---|
| 411 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
| 412 | glDepthMask(GL_FALSE);
|
---|
[1000] | 413 |
|
---|
| 414 |
|
---|
| 415 | // simulate detectemptyviewspace using backface culling
|
---|
[1001] | 416 | if (mDetectEmptyViewSpace)
|
---|
[997] | 417 | {
|
---|
[1000] | 418 | glEnable(GL_CULL_FACE);
|
---|
[1001] | 419 | //cout << "culling" << endl;
|
---|
[1000] | 420 | }
|
---|
| 421 | else
|
---|
| 422 | {
|
---|
[1001] | 423 | //cout << "not culling" << endl;
|
---|
[1000] | 424 | glDisable(GL_CULL_FACE);
|
---|
[1001] | 425 | }
|
---|
[1000] | 426 |
|
---|
| 427 |
|
---|
[1001] | 428 | //const int numQ = 1;
|
---|
| 429 | const int numQ = (int)mOcclusionQueries.size();
|
---|
[1000] | 430 |
|
---|
[1001] | 431 | //glFinish();
|
---|
| 432 | #if 0
|
---|
[1000] | 433 | //-- now issue queries for all objects
|
---|
| 434 | for (int j = 0; j < (int)mObjects.size(); ++ j)
|
---|
[1001] | 435 | {
|
---|
| 436 | mOcclusionQueries[j]->BeginQuery();
|
---|
| 437 | RenderIntersectable(mObjects[j]);
|
---|
| 438 | mOcclusionQueries[j]->EndQuery();
|
---|
| 439 |
|
---|
| 440 | unsigned int pixelCount;
|
---|
| 441 |
|
---|
| 442 | pixelCount = mOcclusionQueries[j]->GetQueryResult();
|
---|
| 443 | mObjects[j]->mCounter += pixelCount;
|
---|
| 444 | }
|
---|
| 445 | #else
|
---|
| 446 |
|
---|
| 447 | int q = 0;
|
---|
| 448 |
|
---|
| 449 | //-- now issue queries for all objects
|
---|
| 450 | for (int j = 0; j < (int)mObjects.size(); j += q)
|
---|
[1000] | 451 | {
|
---|
[1001] | 452 | for (q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q)
|
---|
[997] | 453 | {
|
---|
[1000] | 454 | //glFinish();
|
---|
[1001] | 455 | mOcclusionQueries[q]->BeginQuery();
|
---|
[1000] | 456 |
|
---|
[997] | 457 | RenderIntersectable(mObjects[j + q]);
|
---|
[1000] | 458 |
|
---|
[1001] | 459 | mOcclusionQueries[q]->EndQuery();
|
---|
[1000] | 460 | //glFinish();
|
---|
[997] | 461 | }
|
---|
[1001] | 462 | //cout << "q: " << q << endl;
|
---|
[997] | 463 | // collect results of the queries
|
---|
[1001] | 464 | for (int t = 0; t < q; ++ t)
|
---|
[997] | 465 | {
|
---|
| 466 | unsigned int pixelCount;
|
---|
[1001] | 467 |
|
---|
[997] | 468 | //-- reenable other state
|
---|
[1001] | 469 | #if 0
|
---|
| 470 | bool available;
|
---|
| 471 |
|
---|
[997] | 472 | do
|
---|
| 473 | {
|
---|
[1001] | 474 | available = mOcclusionQueries[t]->ResultAvailable();
|
---|
| 475 |
|
---|
| 476 | if (!available) cout << "W";
|
---|
[997] | 477 | }
|
---|
[1001] | 478 | while (!available);
|
---|
[997] | 479 | #endif
|
---|
| 480 |
|
---|
[1001] | 481 | pixelCount = mOcclusionQueries[t]->GetQueryResult();
|
---|
[997] | 482 |
|
---|
[1001] | 483 | //if (pixelCount > 0)
|
---|
| 484 | // cout <<"o="<<j+q<<" q="<<mOcclusionQueries[q]->GetQueryId()<<" pc="<<pixelCount<<" ";
|
---|
| 485 | mObjects[j + t]->mCounter += pixelCount;
|
---|
[997] | 486 | }
|
---|
| 487 |
|
---|
[1001] | 488 | //j += q;
|
---|
[997] | 489 | }
|
---|
[1001] | 490 | #endif
|
---|
| 491 | //glFinish();
|
---|
[997] | 492 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
| 493 | glDepthMask(GL_TRUE);
|
---|
[1000] | 494 |
|
---|
| 495 | glEnable(GL_CULL_FACE);
|
---|
[997] | 496 | }
|
---|
| 497 |
|
---|
| 498 |
|
---|
| 499 | void
|
---|
[589] | 500 | GlRendererBuffer::RandomViewPoint()
|
---|
[1001] | 501 | {
|
---|
[589] | 502 | // do not use this function since it could return different viewpoints for
|
---|
| 503 | // different executions of the algorithm
|
---|
| 504 |
|
---|
[1112] | 505 | // mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
[589] | 506 |
|
---|
| 507 | while (1) {
|
---|
| 508 | Vector3 pVector = Vector3(halton.GetNumber(1),
|
---|
| 509 | halton.GetNumber(2),
|
---|
| 510 | halton.GetNumber(3));
|
---|
| 511 |
|
---|
[1112] | 512 | mViewPoint = mViewCellsManager->GetViewSpaceBox().GetPoint(pVector);
|
---|
[589] | 513 | ViewCell *v = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
| 514 | if (v && v->GetValid())
|
---|
| 515 | break;
|
---|
| 516 | // generate a new vector
|
---|
| 517 | halton.GenerateNext();
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | Vector3 dVector = Vector3(2*M_PI*halton.GetNumber(4),
|
---|
| 521 | M_PI*halton.GetNumber(5),
|
---|
| 522 | 0.0f);
|
---|
| 523 |
|
---|
| 524 | mViewDirection = Normalize(Vector3(sin(dVector.x),
|
---|
| 525 | // cos(dVector.y),
|
---|
| 526 | 0.0f,
|
---|
| 527 | cos(dVector.x)));
|
---|
| 528 | halton.GenerateNext();
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 |
|
---|
[811] | 532 | }
|
---|