[1944] | 1 | #include "glInterface.h"
|
---|
| 2 | #include "GlobalLinesRenderer.h"
|
---|
| 3 | #include "common.h"
|
---|
| 4 | #include "RenderTexture.h"
|
---|
| 5 | #include "Preprocessor.h"
|
---|
| 6 | #include "GlRenderer.h"
|
---|
[1960] | 7 | #include "Exporter.h"
|
---|
[1963] | 8 | #include "ViewCellsManager.h"
|
---|
[1960] | 9 |
|
---|
[1963] | 10 |
|
---|
[1953] | 11 | // the devil library
|
---|
| 12 | #include <IL/il.h>
|
---|
| 13 | #include <IL/ilu.h>
|
---|
| 14 | #include <IL/ilut.h>
|
---|
[1944] | 15 |
|
---|
| 16 | #include <Cg/cg.h>
|
---|
| 17 | #include <Cg/cgGL.h>
|
---|
| 18 |
|
---|
| 19 | //#include <QtOpenGL>
|
---|
| 20 |
|
---|
| 21 | namespace GtpVisibilityPreprocessor {
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | static CGcontext sCgContext = NULL;
|
---|
| 25 | static CGprogram sCgDepthPeelingProgram = NULL;
|
---|
| 26 | static CGprogram sCgPassThroughProgram = NULL;
|
---|
| 27 |
|
---|
| 28 | static CGprofile sCgFragmentProfile;
|
---|
| 29 | static CGparameter sTextureParam;
|
---|
[1964] | 30 | static CGparameter sTexWidthParam;
|
---|
| 31 | static CGparameter sStepSizeParam;
|
---|
[1944] | 32 |
|
---|
| 33 | GlobalLinesRenderer *globalLinesRenderer = NULL;
|
---|
| 34 |
|
---|
[1960] | 35 | static bool isDepth = true;
|
---|
[1953] | 36 |
|
---|
| 37 | static void InitDevIl()
|
---|
| 38 | {
|
---|
| 39 | ilInit();
|
---|
| 40 | ILuint ImageName;
|
---|
| 41 | ilGenImages(1, &ImageName);
|
---|
| 42 | ilBindImage(ImageName);
|
---|
| 43 | ilEnable(IL_FILE_OVERWRITE);
|
---|
| 44 |
|
---|
| 45 | // ilRegisterFormat(IL_RGBA);
|
---|
| 46 | // ilRegisterType(IL_FLOAT);
|
---|
| 47 |
|
---|
| 48 | // ilEnable(IL_ORIGIN_SET);
|
---|
| 49 | // ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
[1944] | 53 | static void cgErrorCallback()
|
---|
| 54 | {
|
---|
| 55 | CGerror lastError = cgGetError();
|
---|
| 56 |
|
---|
| 57 | if(lastError)
|
---|
| 58 | {
|
---|
| 59 | printf("%s\n\n", cgGetErrorString(lastError));
|
---|
| 60 | printf("%s\n", cgGetLastListing(sCgContext));
|
---|
| 61 | printf("Cg error, exiting...\n");
|
---|
| 62 |
|
---|
| 63 | exit(0);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | static void PrintGLerror(char *msg)
|
---|
| 68 | {
|
---|
| 69 | GLenum errCode;
|
---|
| 70 | const GLubyte *errStr;
|
---|
| 71 |
|
---|
| 72 | if ((errCode = glGetError()) != GL_NO_ERROR)
|
---|
| 73 | {
|
---|
| 74 | errStr = gluErrorString(errCode);
|
---|
| 75 | fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | void Reshape(int w, int h)
|
---|
| 81 | {
|
---|
| 82 | if (h == 0) h = 1;
|
---|
| 83 |
|
---|
| 84 | glViewport(0, 0, w, h);
|
---|
| 85 |
|
---|
| 86 | glMatrixMode(GL_PROJECTION);
|
---|
| 87 | glLoadIdentity();
|
---|
| 88 |
|
---|
[1949] | 89 | //gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 3, 5000.0);
|
---|
[1944] | 90 | //gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.5, 10.0);
|
---|
[1951] | 91 | glOrtho(-1, 1, -1, 1, 0.5, 15);
|
---|
[1944] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
[1960] | 95 | void SetFrustum(const int sizeX, const int sizeY,
|
---|
| 96 | const float nearPlane, const float farPlane)
|
---|
[1953] | 97 | {
|
---|
| 98 | glMatrixMode(GL_PROJECTION);
|
---|
| 99 | glLoadIdentity();
|
---|
| 100 |
|
---|
[1960] | 101 | glOrtho(-sizeX * 0.5, sizeX * 0.5,
|
---|
| 102 | -sizeY * 0.5, sizeY * 0.5,
|
---|
[1953] | 103 | nearPlane, farPlane);
|
---|
| 104 |
|
---|
| 105 | /*glOrtho(0, sizeX,
|
---|
| 106 | 0, sizeY ,
|
---|
| 107 | nearPlane, farPlane);*/
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[1944] | 110 | void Display()
|
---|
| 111 | {
|
---|
| 112 | //globalLinesRenderer->DrawGeometry();
|
---|
[1958] | 113 | //globalLinesRenderer->CastGlobalLines(Beam(), 0);
|
---|
[1960] | 114 | globalLinesRenderer->DisplayBuffer(isDepth);
|
---|
[1944] | 115 | PrintGLerror("display");
|
---|
| 116 |
|
---|
| 117 | glutSwapBuffers();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | void Idle()
|
---|
| 122 | {
|
---|
| 123 | glutPostRedisplay();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | void Keyboard(unsigned char key, int x, int y)
|
---|
| 128 | {
|
---|
| 129 | switch(key)
|
---|
| 130 | {
|
---|
[1949] | 131 | case '2':
|
---|
[1958] | 132 | {
|
---|
| 133 | VssRayContainer rays;
|
---|
| 134 |
|
---|
| 135 | ++ globalLinesRenderer->mMaxDepth;
|
---|
[1964] | 136 | globalLinesRenderer->ApplyDepthPeeling(rays);
|
---|
[1958] | 137 |
|
---|
| 138 | cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl;
|
---|
[1960] | 139 | CLEAR_CONTAINER(rays);
|
---|
[1958] | 140 | return;
|
---|
| 141 | }
|
---|
[1949] | 142 | case '1':
|
---|
[1958] | 143 | {
|
---|
| 144 | VssRayContainer rays;
|
---|
| 145 |
|
---|
| 146 | -- globalLinesRenderer->mMaxDepth;
|
---|
| 147 | cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl;
|
---|
| 148 |
|
---|
[1964] | 149 | globalLinesRenderer->ApplyDepthPeeling(rays);
|
---|
[1960] | 150 | CLEAR_CONTAINER(rays);
|
---|
[1958] | 151 | return;
|
---|
| 152 | }
|
---|
[1953] | 153 | case '3':
|
---|
[1958] | 154 | {
|
---|
| 155 | globalLinesRenderer->ExportDepthBuffer();
|
---|
| 156 | return;
|
---|
| 157 | }
|
---|
| 158 | case '4':
|
---|
| 159 | {
|
---|
[1960] | 160 | globalLinesRenderer->ExportItemBuffer();
|
---|
| 161 | return;
|
---|
| 162 | }
|
---|
| 163 | case '8':
|
---|
| 164 | {
|
---|
| 165 | isDepth = !isDepth;
|
---|
| 166 | return;
|
---|
| 167 | }
|
---|
| 168 | case '9':
|
---|
| 169 | {
|
---|
[1958] | 170 | VssRayContainer rays;
|
---|
[1964] | 171 | globalLinesRenderer->ApplyDepthPeeling(rays);
|
---|
[1960] | 172 | VssRayContainer outRays;
|
---|
| 173 | VssRayContainer::const_iterator vit, vit_end = rays.end();
|
---|
[1958] | 174 |
|
---|
[1960] | 175 | const float p = 8.0f / (float)rays.size();
|
---|
| 176 |
|
---|
| 177 | for (vit = rays.begin(); vit != vit_end; ++ vit)
|
---|
| 178 | {
|
---|
| 179 | if (Random(1.0f) < p)
|
---|
| 180 | {
|
---|
| 181 | outRays.push_back(*vit);
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | globalLinesRenderer->Visualize(rays);
|
---|
| 186 | CLEAR_CONTAINER(rays);
|
---|
| 187 | return;
|
---|
| 188 | }
|
---|
| 189 | case '0':
|
---|
| 190 | {
|
---|
| 191 | VssRayContainer rays;
|
---|
[1964] | 192 | globalLinesRenderer->ApplyDepthPeeling(rays);
|
---|
[1960] | 193 | CLEAR_CONTAINER(rays);
|
---|
[1958] | 194 | return;
|
---|
| 195 | }
|
---|
[1944] | 196 | default:
|
---|
| 197 | return;
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[1953] | 201 |
|
---|
[1944] | 202 | /*GlobalLinesRenderer::GlobalLinesRenderer(RenderTexture *buffer1,
|
---|
| 203 | RenderTexture *buffer2,
|
---|
| 204 | Preprocessor *preprocessor,
|
---|
| 205 | GlRenderer *renderer)
|
---|
[1953] | 206 | : mNewTexture(buffer1), mOldTexture(buffer2), mPreprocessor(preprocessor), mMaxDepth(100),
|
---|
[1944] | 207 | mRenderer(renderer)
|
---|
| 208 | {
|
---|
| 209 | }
|
---|
| 210 | */
|
---|
[1953] | 211 |
|
---|
| 212 |
|
---|
[1949] | 213 | GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,
|
---|
[1964] | 214 | GlRenderer *renderer,
|
---|
| 215 | const float mTexHeight,
|
---|
| 216 | const float mTexWidth,
|
---|
| 217 | const float eps):
|
---|
[1953] | 218 | mNewTexture(NULL),
|
---|
| 219 | mOldTexture(NULL),
|
---|
[1949] | 220 | mMaxDepth(0),
|
---|
[1944] | 221 | mRenderer(renderer),
|
---|
[1964] | 222 | mPreprocessor(preprocessor),
|
---|
| 223 | mTexHeight(mTexHeight),
|
---|
| 224 | mTexWidth(mTexWidth),
|
---|
| 225 | mEpsilon(eps)
|
---|
[1944] | 226 | {
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 |
|
---|
[1964] | 230 | GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor,
|
---|
| 231 | GlRenderer *renderer):
|
---|
| 232 | mNewTexture(NULL),
|
---|
| 233 | mOldTexture(NULL),
|
---|
| 234 | mMaxDepth(0),
|
---|
| 235 | mRenderer(renderer),
|
---|
| 236 | mPreprocessor(preprocessor),
|
---|
| 237 | mTexHeight(128),
|
---|
| 238 | mTexWidth(128),
|
---|
| 239 | mEpsilon(0.0001)
|
---|
| 240 | {}
|
---|
| 241 |
|
---|
| 242 |
|
---|
[1960] | 243 | void GlobalLinesRenderer::DisplayBuffer(const bool isDepth)
|
---|
[1958] | 244 | {
|
---|
[1960] | 245 | if (!isDepth)
|
---|
| 246 | mNewTexture->Bind();
|
---|
| 247 | else
|
---|
| 248 | mNewTexture->BindDepth();
|
---|
[1958] | 249 | mNewTexture->EnableTextureTarget();
|
---|
| 250 |
|
---|
| 251 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 252 |
|
---|
| 253 | if (mNewTexture->IsRectangleTexture())
|
---|
| 254 | {
|
---|
| 255 | glBegin(GL_QUADS);
|
---|
| 256 | glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
|
---|
| 257 | glTexCoord2f(mNewTexture->GetWidth(), 0); glVertex3f( 1, -1, -0.5f);
|
---|
| 258 | glTexCoord2f(mNewTexture->GetWidth(), mNewTexture->GetHeight()); glVertex3f( 1, 1, -0.5f);
|
---|
| 259 | glTexCoord2f(0, mNewTexture->GetHeight()); glVertex3f(-1, 1, -0.5f);
|
---|
| 260 | glEnd();
|
---|
| 261 | }
|
---|
| 262 | else
|
---|
| 263 | {
|
---|
| 264 | glBegin(GL_QUADS);
|
---|
| 265 | glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
|
---|
| 266 | glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
|
---|
| 267 | glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f);
|
---|
| 268 | glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f);
|
---|
| 269 | glEnd();
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | mNewTexture->DisableTextureTarget();
|
---|
| 273 | PrintGLerror("displaytexture");
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 |
|
---|
[1944] | 277 | GlobalLinesRenderer::~GlobalLinesRenderer()
|
---|
| 278 | {
|
---|
| 279 | if (sCgDepthPeelingProgram)
|
---|
| 280 | cgDestroyProgram(sCgDepthPeelingProgram);
|
---|
| 281 | if (sCgContext)
|
---|
| 282 | cgDestroyContext(sCgContext);
|
---|
[1958] | 283 |
|
---|
| 284 | // init the receiving buffers
|
---|
| 285 | delete mNewDepthBuffer;
|
---|
| 286 | delete mOldDepthBuffer;
|
---|
| 287 |
|
---|
| 288 | delete mNewItemBuffer;
|
---|
| 289 | delete mOldItemBuffer;
|
---|
[1944] | 290 | }
|
---|
| 291 |
|
---|
| 292 |
|
---|
[1964] | 293 | void GlobalLinesRenderer::InitScene(const float alpha, const float beta)
|
---|
[1944] | 294 | {
|
---|
[1964] | 295 | AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox();
|
---|
| 296 |
|
---|
| 297 | const float sceneSize = Magnitude(bbox.Diagonal());
|
---|
[1958] | 298 |
|
---|
[1964] | 299 | // compute the center of the scene
|
---|
| 300 | Vector3 midPoint = bbox.Center();
|
---|
| 301 |
|
---|
| 302 | // add a small offset to provide some randomness in the sampling
|
---|
| 303 | Vector3 offset(Random(sceneSize * 1e-3f),
|
---|
| 304 | Random(sceneSize * 1e-3f),
|
---|
| 305 | Random(sceneSize * 1e-3f));
|
---|
| 306 |
|
---|
| 307 | midPoint += offset;
|
---|
| 308 |
|
---|
| 309 | mNear = 1;
|
---|
| 310 | mFar = sceneSize * 2;
|
---|
| 311 | mWidth = sceneSize;
|
---|
| 312 |
|
---|
| 313 | ComputeLookAt(alpha,
|
---|
| 314 | beta,
|
---|
| 315 | mEyeVec,
|
---|
| 316 | mUpVec,
|
---|
| 317 | mLeftVec);
|
---|
| 318 |
|
---|
| 319 | mViewPoint = midPoint - 0.5f * sceneSize * mEyeVec;
|
---|
| 320 |
|
---|
| 321 | cout << "mid point: " << midPoint << endl;
|
---|
| 322 | cout << "view point: " << mViewPoint << endl;
|
---|
| 323 | cout << "scene: " << bbox << endl;
|
---|
| 324 |
|
---|
| 325 | // setup the rendering context for the RenderTexture
|
---|
| 326 | mNewTexture->BeginCapture();
|
---|
| 327 | {
|
---|
| 328 | //Reshape(mTexWidth, mTexHeight);
|
---|
| 329 | glViewport(0, 0, mTexWidth, mTexHeight);
|
---|
| 330 | SetFrustum(mWidth, mWidth, mNear, mFar);
|
---|
| 331 |
|
---|
| 332 | // for item buffer: white means no color
|
---|
| 333 | glClearColor(1, 1, 1, 1);
|
---|
| 334 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 335 |
|
---|
| 336 | glFrontFace(GL_CCW);
|
---|
| 337 | glCullFace(GL_BACK);
|
---|
| 338 |
|
---|
| 339 | glDisable(GL_CULL_FACE);
|
---|
| 340 | //glEnable(GL_CULL_FACE);
|
---|
| 341 |
|
---|
| 342 | glShadeModel(GL_FLAT);
|
---|
| 343 | glEnable(GL_DEPTH_TEST);
|
---|
| 344 |
|
---|
| 345 | glMatrixMode(GL_MODELVIEW);
|
---|
| 346 | glLoadIdentity();
|
---|
| 347 | gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,
|
---|
| 348 | midPoint.x, midPoint.y, midPoint.z,
|
---|
| 349 | mUpVec.x, mUpVec.y, mUpVec.z);
|
---|
| 350 |
|
---|
| 351 | }
|
---|
| 352 | mNewTexture->EndCapture();
|
---|
| 353 |
|
---|
| 354 | // setup the rendering context for the other depth buffer
|
---|
| 355 | mOldTexture->BeginCapture();
|
---|
| 356 | {
|
---|
| 357 | // for item buffer: white means no color
|
---|
| 358 | glClearColor(1, 1, 1, 1);
|
---|
| 359 |
|
---|
| 360 | //Reshape(mTexWidth, mTexHeight);
|
---|
| 361 | glViewport(0, 0, mTexWidth, mTexHeight);
|
---|
| 362 | SetFrustum(mWidth, mWidth, mNear, mFar);
|
---|
| 363 |
|
---|
| 364 | glMatrixMode(GL_MODELVIEW);
|
---|
| 365 | glLoadIdentity();
|
---|
| 366 |
|
---|
| 367 | glFrontFace(GL_CCW);
|
---|
| 368 | glCullFace(GL_BACK);
|
---|
| 369 |
|
---|
| 370 | glDisable(GL_CULL_FACE);
|
---|
| 371 | //glEnable(GL_CULL_FACE);
|
---|
| 372 |
|
---|
| 373 | glShadeModel(GL_FLAT);
|
---|
| 374 | glEnable(GL_DEPTH_TEST);
|
---|
| 375 |
|
---|
| 376 | gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,
|
---|
| 377 | midPoint.x, midPoint.y, midPoint.z,
|
---|
| 378 | mUpVec.x, mUpVec.y, mUpVec.z);
|
---|
| 379 | }
|
---|
| 380 | mOldTexture->EndCapture();
|
---|
| 381 |
|
---|
| 382 | cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 |
|
---|
| 386 | void GlobalLinesRenderer::CastGlobalLines(const float alpha,
|
---|
| 387 | const float beta,
|
---|
| 388 | //const int samples,
|
---|
| 389 | VssRayContainer &rays)
|
---|
| 390 | {
|
---|
| 391 | InitScene(alpha, beta);
|
---|
| 392 |
|
---|
[1944] | 393 | // bind pixel shader implementing the front depth buffer functionality
|
---|
[1964] | 394 | ApplyDepthPeeling(rays);
|
---|
[1944] | 395 | }
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | void GlobalLinesRenderer::RenderObject(Intersectable *obj)
|
---|
| 399 | {
|
---|
| 400 | mRenderer->RenderIntersectable(obj);
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
| 404 | void GlobalLinesRenderer::DrawGeometry()
|
---|
[1945] | 405 | {
|
---|
[1951] | 406 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 407 | glMatrixMode(GL_MODELVIEW);
|
---|
[1944] | 408 |
|
---|
[1951] | 409 | glPushMatrix();
|
---|
| 410 | {
|
---|
[1953] | 411 | //glLoadIdentity();
|
---|
[1951] | 412 | ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end();
|
---|
| 413 |
|
---|
| 414 | Intersectable::NewMail();
|
---|
| 415 |
|
---|
| 416 | for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 417 | {
|
---|
[1962] | 418 | //cout << (*oit)->GetId() << " ";
|
---|
[1951] | 419 | RenderObject(*oit);
|
---|
| 420 | }
|
---|
[1944] | 421 | }
|
---|
[1951] | 422 | glPopMatrix();
|
---|
[1944] | 423 | }
|
---|
| 424 |
|
---|
| 425 |
|
---|
| 426 | void GlobalLinesRenderer::SwitchRenderTextures()
|
---|
| 427 | {
|
---|
[1953] | 428 | RenderTexture *buffer = mOldTexture;
|
---|
| 429 | mOldTexture = mNewTexture;
|
---|
| 430 | mNewTexture = buffer;
|
---|
[1944] | 431 | }
|
---|
| 432 |
|
---|
| 433 |
|
---|
[1958] | 434 | void GlobalLinesRenderer::ComputeLookAt(const float alpha,
|
---|
| 435 | const float beta,
|
---|
| 436 | Vector3 &eye,
|
---|
| 437 | Vector3 &up,
|
---|
[1964] | 438 | Vector3 &left)
|
---|
[1958] | 439 | {
|
---|
| 440 | //float x = cos(alpha);
|
---|
| 441 | //float y = sin(alpha);
|
---|
| 442 | eye.x = sin(alpha) * cos(beta);
|
---|
| 443 | eye.y = sin(alpha) * sin(beta);
|
---|
[1964] | 444 | eye.z = cos(alpha);
|
---|
[1958] | 445 |
|
---|
[1964] | 446 | //eye = Normalize(eye);
|
---|
[1958] | 447 | eye.RightHandedBase(up, left);
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 |
|
---|
[1944] | 451 | void GlobalLinesRenderer::InitGl()
|
---|
| 452 | {
|
---|
[1953] | 453 | InitDevIl();
|
---|
| 454 |
|
---|
[1960] | 455 | glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
---|
[1944] | 456 | glutInitWindowPosition(50, 50);
|
---|
| 457 | glutInitWindowSize(512, 512);
|
---|
| 458 | glutCreateWindow("TestRenderDepthTexture");
|
---|
| 459 |
|
---|
| 460 | int err = glewInit();
|
---|
| 461 | if (GLEW_OK != err)
|
---|
| 462 | {
|
---|
| 463 | // problem: glewInit failed, something is seriously wrong
|
---|
| 464 | fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
|
---|
| 465 | exit(-1);
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | glutKeyboardFunc(Keyboard);
|
---|
| 469 | glutDisplayFunc(Display);
|
---|
| 470 | glutIdleFunc(Idle);
|
---|
| 471 | glutReshapeFunc(Reshape);
|
---|
| 472 |
|
---|
| 473 | Reshape(512, 512);
|
---|
| 474 | glMatrixMode(GL_MODELVIEW);
|
---|
| 475 | glLoadIdentity();
|
---|
| 476 |
|
---|
[1958] | 477 | // initialise the receiving buffers
|
---|
[1964] | 478 | mNewDepthBuffer = new float[mTexWidth * mTexHeight];
|
---|
| 479 | mNewItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4];
|
---|
[1960] | 480 |
|
---|
[1964] | 481 | mOldDepthBuffer = new float[mTexWidth * mTexHeight];
|
---|
| 482 | mOldItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4];
|
---|
[1960] | 483 |
|
---|
[1964] | 484 | for (int i = 0; i < mTexWidth * mTexHeight; ++ i)
|
---|
[1958] | 485 | {
|
---|
| 486 | mNewDepthBuffer[i] = 1;
|
---|
| 487 | mOldDepthBuffer[i] = 1;
|
---|
| 488 |
|
---|
[1960] | 489 | mNewItemBuffer[i * 4] = 255;
|
---|
| 490 | mNewItemBuffer[i * 4 + 1] = 255;
|
---|
| 491 | mNewItemBuffer[i * 4 + 2] = 255;
|
---|
| 492 | mNewItemBuffer[i * 4 + 3] = 255;
|
---|
| 493 |
|
---|
| 494 | mOldItemBuffer[i * 4] = 255;
|
---|
| 495 | mOldItemBuffer[i * 4 + 1] = 255;
|
---|
| 496 | mOldItemBuffer[i * 4 + 2] = 255;
|
---|
| 497 | mOldItemBuffer[i * 4 + 3] = 255;
|
---|
[1958] | 498 | }
|
---|
| 499 |
|
---|
[1960] | 500 | /*gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,
|
---|
[1944] | 501 | midPoint.x, midPoint.y, midPoint.z,
|
---|
| 502 | 0, 1, 0);
|
---|
| 503 | */
|
---|
| 504 | gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
|
---|
| 505 |
|
---|
[1949] | 506 | //glDisable(GL_CULL_FACE);
|
---|
| 507 | glEnable(GL_CULL_FACE);
|
---|
[1944] | 508 | glDisable(GL_LIGHTING);
|
---|
| 509 | glDisable(GL_COLOR_MATERIAL);
|
---|
| 510 | glEnable(GL_DEPTH_TEST);
|
---|
| 511 | glClearColor(0.1, 0.2, 0.3, 1);
|
---|
| 512 |
|
---|
| 513 | // A square, mipmapped, anisotropically filtered 8-bit RGBA texture with
|
---|
| 514 | // depth and stencil.
|
---|
| 515 | // Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware
|
---|
| 516 |
|
---|
[1964] | 517 | mNewTexture = new RenderTexture(mTexWidth, mTexHeight, true, true);
|
---|
| 518 | #ifdef ATI
|
---|
[1953] | 519 | mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
|
---|
[1964] | 520 | #else
|
---|
| 521 | mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
|
---|
| 522 | #endif
|
---|
| 523 |
|
---|
| 524 | mOldTexture = new RenderTexture(mTexWidth, mTexHeight, true, true);
|
---|
| 525 |
|
---|
| 526 | #ifdef ATI
|
---|
[1953] | 527 | mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
|
---|
[1964] | 528 | #else
|
---|
| 529 | mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
|
---|
| 530 | #endif
|
---|
[1944] | 531 |
|
---|
| 532 | // Setup Cg
|
---|
| 533 | cgSetErrorCallback(cgErrorCallback);
|
---|
| 534 |
|
---|
| 535 | // Create cgContext.
|
---|
| 536 | sCgContext = cgCreateContext();
|
---|
| 537 |
|
---|
| 538 | // get the best profile for this hardware
|
---|
| 539 | sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
---|
| 540 |
|
---|
| 541 | //assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN);
|
---|
| 542 | cgGLSetOptimalOptions(sCgFragmentProfile);
|
---|
| 543 |
|
---|
| 544 | sCgDepthPeelingProgram =
|
---|
| 545 | cgCreateProgramFromFile(sCgContext,
|
---|
| 546 | CG_SOURCE,
|
---|
[1953] | 547 | mNewTexture->IsRectangleTexture() ?
|
---|
[1951] | 548 | "../src/depth_peelingRect.cg" : "../src/depth_peeling2d.cg",
|
---|
[1944] | 549 | GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
|
---|
| 550 | NULL,
|
---|
| 551 | NULL);
|
---|
| 552 |
|
---|
| 553 | if(sCgDepthPeelingProgram != NULL)
|
---|
| 554 | {
|
---|
| 555 | cgGLLoadProgram(sCgDepthPeelingProgram);
|
---|
| 556 | sTextureParam = cgGetNamedParameter(sCgDepthPeelingProgram, "depthTex");
|
---|
[1964] | 557 |
|
---|
| 558 | // we need size of texture for scaling
|
---|
| 559 | if (!mNewTexture->IsRectangleTexture())
|
---|
| 560 | {
|
---|
| 561 | sTexWidthParam = cgGetNamedParameter(sCgDepthPeelingProgram, "texWidth");
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | sStepSizeParam = cgGetNamedParameter(sCgDepthPeelingProgram, "stepSize");
|
---|
| 565 |
|
---|
| 566 | cgGLSetParameter1f(sTexWidthParam, (float)mTexWidth);
|
---|
| 567 | cgGLSetParameter1f(sStepSizeParam, mEpsilon);
|
---|
[1944] | 568 | }
|
---|
| 569 |
|
---|
| 570 | sCgPassThroughProgram =
|
---|
| 571 | cgCreateProgramFromFile(sCgContext,
|
---|
| 572 | CG_SOURCE,
|
---|
| 573 | "../src/passthrough.cg",
|
---|
| 574 | GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
|
---|
| 575 | NULL,
|
---|
| 576 | NULL);
|
---|
| 577 |
|
---|
| 578 | if(sCgPassThroughProgram != NULL)
|
---|
| 579 | {
|
---|
| 580 | cgGLLoadProgram(sCgPassThroughProgram);
|
---|
| 581 | }
|
---|
| 582 |
|
---|
[1964] | 583 | const float alpha = 1.1;
|
---|
| 584 | const float beta = 0.9;
|
---|
| 585 | InitScene(alpha, beta);
|
---|
[1953] | 586 |
|
---|
[1944] | 587 | PrintGLerror("init");
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 |
|
---|
[1960] | 591 | Intersectable *GlobalLinesRenderer::ExtractSamplePoint(float *depthBuffer,
|
---|
| 592 | unsigned char *itemBuffer,
|
---|
| 593 | const int x,
|
---|
| 594 | const int y,
|
---|
| 595 | Vector3 &hitPoint,
|
---|
| 596 | const bool isFrontBuffer) const
|
---|
[1944] | 597 | {
|
---|
[1964] | 598 | const int depthIndex = x + mTexWidth * y;
|
---|
[1960] | 599 | const int itemIndex = 4 * depthIndex;
|
---|
| 600 |
|
---|
| 601 | const float depth = depthBuffer[depthIndex];
|
---|
| 602 | const float eyeDist = mNear + (mFar - mNear) * depth;
|
---|
| 603 |
|
---|
[1964] | 604 | const float leftDist = -0.5f * mWidth + mWidth * ((float)x + 0.5f) / mTexWidth;
|
---|
| 605 | //const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / mTexWidth;
|
---|
[1960] | 606 |
|
---|
[1964] | 607 | const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight;
|
---|
| 608 | //const float upDist = 0.5f * mWidth - mWidth * ((float)y + 0.5f) / mTexHeight;
|
---|
| 609 |
|
---|
[1960] | 610 | hitPoint = mViewPoint +
|
---|
| 611 | eyeDist * mEyeVec +
|
---|
[1964] | 612 | upDist * mUpVec +
|
---|
| 613 | leftDist * mLeftVec;
|
---|
[1960] | 614 |
|
---|
| 615 | unsigned char r = itemBuffer[itemIndex];
|
---|
| 616 | unsigned char g = itemBuffer[itemIndex + 1];
|
---|
| 617 | unsigned char b = itemBuffer[itemIndex + 2];
|
---|
| 618 |
|
---|
| 619 | // 3 times 255 means no valid object
|
---|
| 620 | if ((r == 255) && (g == 255) && (b == 255))
|
---|
| 621 | return NULL;
|
---|
| 622 |
|
---|
| 623 | const int id = mRenderer->GetId(r, g, b);
|
---|
| 624 | //cout << "r: " << (int)r << "g: " << (int)g << " b: " << (int)b << " id: " << id << "|";
|
---|
| 625 | Intersectable *intersect = mPreprocessor->GetObjectById(id);
|
---|
| 626 |
|
---|
| 627 | const Vector3 dir = isFrontBuffer ? mEyeVec : -mEyeVec;
|
---|
| 628 | // HACK: assume triangle intersectable
|
---|
| 629 | const Vector3 norm = intersect->GetNormal(0);
|
---|
| 630 |
|
---|
[1961] | 631 | // test for invalid view space
|
---|
| 632 | if (DotProd(dir, norm) >= -Limits::Small)
|
---|
| 633 | return NULL;
|
---|
| 634 |
|
---|
| 635 | return intersect;
|
---|
[1944] | 636 | }
|
---|
| 637 |
|
---|
| 638 |
|
---|
[1960] | 639 | void GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays,
|
---|
[1963] | 640 | const bool oldBufferInitialised,
|
---|
| 641 | const int pass)
|
---|
[1953] | 642 | {
|
---|
| 643 | GrabDepthBuffer(mNewDepthBuffer, mNewTexture);
|
---|
| 644 | GrabItemBuffer(mNewItemBuffer, mNewTexture);
|
---|
| 645 |
|
---|
[1960] | 646 | if (oldBufferInitialised)
|
---|
[1953] | 647 | {
|
---|
[1960] | 648 | GrabDepthBuffer(mOldDepthBuffer, mOldTexture);
|
---|
| 649 | GrabItemBuffer(mOldItemBuffer, mOldTexture);
|
---|
| 650 | }
|
---|
| 651 | else
|
---|
| 652 | {
|
---|
[1964] | 653 | for (int i = 0; i < mTexWidth * mTexHeight; ++ i)
|
---|
[1953] | 654 | {
|
---|
[1960] | 655 | mOldDepthBuffer[i] = 0;
|
---|
[1953] | 656 |
|
---|
[1960] | 657 | mOldItemBuffer[i * 4] = 255;
|
---|
| 658 | mOldItemBuffer[i * 4 + 1] = 255;
|
---|
| 659 | mOldItemBuffer[i * 4 + 2] = 255;
|
---|
| 660 | mOldItemBuffer[i * 4 + 3] = 255;
|
---|
| 661 | }
|
---|
| 662 | }
|
---|
[1953] | 663 |
|
---|
[1964] | 664 | for (int y = 0; y < mTexHeight; ++ y)
|
---|
[1960] | 665 | {
|
---|
[1964] | 666 | for (int x = 0; x < mTexWidth; ++ x)
|
---|
[1960] | 667 | {
|
---|
| 668 | Vector3 newPt, oldPt;
|
---|
[1953] | 669 |
|
---|
[1960] | 670 | Intersectable *termObj1 = ExtractSamplePoint(mNewDepthBuffer,
|
---|
| 671 | mNewItemBuffer,
|
---|
| 672 | x,
|
---|
| 673 | y,
|
---|
| 674 | newPt,
|
---|
| 675 | true);
|
---|
[1953] | 676 |
|
---|
[1960] | 677 | Intersectable *termObj2 = ExtractSamplePoint(mOldDepthBuffer,
|
---|
| 678 | mOldItemBuffer,
|
---|
| 679 | x,
|
---|
| 680 | y,
|
---|
| 681 | oldPt,
|
---|
| 682 | false);
|
---|
[1953] | 683 |
|
---|
[1963] | 684 | if (!termObj1 && !termObj2) // we do not create a ray
|
---|
| 685 | continue;
|
---|
| 686 |
|
---|
| 687 | Vector3 clippedOldPt, clippedNewPt;
|
---|
| 688 |
|
---|
| 689 | ClipToViewSpaceBox(oldPt, newPt, clippedOldPt, clippedNewPt);
|
---|
| 690 | //clippedOldPt = oldPt;
|
---|
| 691 | //clippedNewPt = newPt;
|
---|
| 692 |
|
---|
[1960] | 693 | // create rays in both directions
|
---|
| 694 | if (termObj1)
|
---|
[1958] | 695 | {
|
---|
[1963] | 696 | vssRays.push_back(new VssRay(clippedOldPt, clippedNewPt, NULL, termObj1, pass));
|
---|
[1960] | 697 | //cout << "new pt: " << newPt << endl;
|
---|
[1958] | 698 | }
|
---|
| 699 |
|
---|
[1961] | 700 | if (termObj2)
|
---|
| 701 | {
|
---|
[1963] | 702 | vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass));
|
---|
[1961] | 703 | //cout << "old pt: " << oldPt << endl;
|
---|
| 704 | }
|
---|
[1953] | 705 | }
|
---|
| 706 | }
|
---|
| 707 | }
|
---|
| 708 |
|
---|
| 709 |
|
---|
[1963] | 710 | bool GlobalLinesRenderer::ClipToViewSpaceBox(const Vector3 &origin,
|
---|
| 711 | const Vector3 &termination,
|
---|
| 712 | Vector3 &clippedOrigin,
|
---|
| 713 | Vector3 &clippedTermination)
|
---|
[1944] | 714 | {
|
---|
[1963] | 715 | Ray ray(origin, termination - origin, Ray::LINE_SEGMENT);
|
---|
| 716 | ray.Precompute();
|
---|
| 717 |
|
---|
| 718 | float tmin, tmax;
|
---|
| 719 |
|
---|
| 720 | //const AxisAlignedBox3 bbox = mPreprocessor->mViewCellsManager->GetViewSpaceBox();
|
---|
| 721 | // hack
|
---|
| 722 | const AxisAlignedBox3 bbox = mPreprocessor->mKdTree->GetBox();
|
---|
| 723 |
|
---|
| 724 | if ((!bbox.ComputeMinMaxT(ray, &tmin, &tmax)) ||
|
---|
| 725 | tmin>=tmax)
|
---|
| 726 | {
|
---|
| 727 | return false;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | if (tmin >= 1.0f || tmax <=0.0f)
|
---|
| 731 | return false;
|
---|
| 732 |
|
---|
| 733 | if (tmin > 0.0f)
|
---|
| 734 | clippedOrigin = ray.Extrap(tmin);
|
---|
| 735 | else
|
---|
| 736 | clippedOrigin = origin;
|
---|
| 737 |
|
---|
| 738 | if (tmax < 1.0f)
|
---|
| 739 | clippedTermination = ray.Extrap(tmax);
|
---|
| 740 | else
|
---|
| 741 | clippedTermination = termination;
|
---|
| 742 |
|
---|
| 743 | return true;
|
---|
[1944] | 744 | }
|
---|
| 745 |
|
---|
| 746 |
|
---|
[1963] | 747 | void GlobalLinesRenderer::Run()
|
---|
[1960] | 748 | {
|
---|
[1963] | 749 | glutMainLoop();
|
---|
[1960] | 750 | }
|
---|
| 751 |
|
---|
| 752 |
|
---|
| 753 | void GlobalLinesRenderer::Visualize(const VssRayContainer &vssRays)
|
---|
| 754 | {
|
---|
| 755 | Exporter *exporter = Exporter::GetExporter("globalLines.wrl");
|
---|
| 756 |
|
---|
| 757 | if (!exporter)
|
---|
| 758 | return;
|
---|
| 759 |
|
---|
| 760 | exporter->SetWireframe();
|
---|
| 761 | //exporter->ExportGeometry(preprocessor->mObjects);
|
---|
| 762 | exporter->SetFilled();
|
---|
| 763 |
|
---|
| 764 | VssRayContainer::const_iterator vit, vit_end = vssRays.end();
|
---|
[1963] | 765 | VssRayContainer outRays;
|
---|
[1960] | 766 |
|
---|
[1963] | 767 | Intersectable::NewMail();
|
---|
| 768 |
|
---|
[1960] | 769 | for (vit = vssRays.begin(); vit != vit_end; ++ vit)
|
---|
| 770 | {
|
---|
| 771 | VssRay *ray = *vit;
|
---|
[1963] | 772 | Intersectable *obj = (*vit)->mTerminationObject;
|
---|
| 773 |
|
---|
| 774 | if (!obj->Mailed())
|
---|
| 775 | {
|
---|
| 776 | obj->Mail();
|
---|
| 777 | exporter->ExportIntersectable(obj);
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[1964] | 780 | //if (ray->mPass == 4)
|
---|
[1963] | 781 | outRays.push_back(ray);
|
---|
[1960] | 782 | }
|
---|
| 783 |
|
---|
[1963] | 784 | exporter->ExportRays(outRays);
|
---|
[1960] | 785 |
|
---|
| 786 | delete exporter;
|
---|
| 787 | }
|
---|
| 788 |
|
---|
| 789 |
|
---|
[1953] | 790 | void GlobalLinesRenderer::GrabDepthBuffer(float *data, RenderTexture *rt)
|
---|
| 791 | {
|
---|
| 792 | rt->BindDepth();
|
---|
| 793 | rt->EnableTextureTarget();
|
---|
| 794 |
|
---|
| 795 | const int texFormat = GL_DEPTH_COMPONENT;
|
---|
| 796 | glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data);
|
---|
| 797 |
|
---|
| 798 | mNewTexture->DisableTextureTarget();
|
---|
| 799 | }
|
---|
| 800 |
|
---|
| 801 |
|
---|
[1960] | 802 | void GlobalLinesRenderer::GrabItemBuffer(unsigned char *data, RenderTexture *rt)
|
---|
[1953] | 803 | {
|
---|
[1958] | 804 | rt->Bind();
|
---|
[1953] | 805 | rt->EnableTextureTarget();
|
---|
| 806 |
|
---|
[1958] | 807 | const int texFormat = GL_RGBA;
|
---|
[1960] | 808 | glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_UNSIGNED_BYTE, data);
|
---|
[1953] | 809 |
|
---|
| 810 | mNewTexture->DisableTextureTarget();
|
---|
| 811 | }
|
---|
| 812 |
|
---|
[1958] | 813 |
|
---|
[1953] | 814 | void GlobalLinesRenderer::ExportDepthBuffer()
|
---|
| 815 | {
|
---|
| 816 | mNewTexture->BindDepth();
|
---|
| 817 | mNewTexture->EnableTextureTarget();
|
---|
| 818 | cout << "depth: " << mNewTexture->GetDepthBits() << endl;
|
---|
| 819 |
|
---|
[1960] | 820 | const int components = 1;//mNewTexture->GetDepthBits() / 8;
|
---|
[1953] | 821 |
|
---|
[1964] | 822 | float *data = new float[mTexWidth * mTexHeight * components];
|
---|
[1953] | 823 | //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV;
|
---|
| 824 | const int texFormat = GL_DEPTH_COMPONENT;
|
---|
| 825 | //const int texFormat = GL_RGBA;
|
---|
| 826 | glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data);
|
---|
| 827 |
|
---|
| 828 | string filename("depth.tga");
|
---|
| 829 | ilRegisterType(IL_FLOAT);
|
---|
| 830 |
|
---|
| 831 | const int depth = 1;
|
---|
| 832 | const int bpp = components;
|
---|
| 833 |
|
---|
[1964] | 834 | ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data);
|
---|
[1953] | 835 | ilSaveImage((char *const)filename.c_str());
|
---|
| 836 |
|
---|
| 837 | cout << "finished" << endl;
|
---|
| 838 | delete data;
|
---|
| 839 | cout << "data deleted" << endl;
|
---|
| 840 | mNewTexture->DisableTextureTarget();
|
---|
| 841 | PrintGLerror("grab texture");
|
---|
| 842 | }
|
---|
| 843 |
|
---|
[1958] | 844 |
|
---|
[1960] | 845 | void GlobalLinesRenderer::ExportItemBuffer()
|
---|
| 846 | {
|
---|
| 847 | mNewTexture->Bind();
|
---|
| 848 | mNewTexture->EnableTextureTarget();
|
---|
| 849 | cout << "depth: " << mNewTexture->GetDepthBits() << endl;
|
---|
[1958] | 850 |
|
---|
[1960] | 851 | const int components = 4;//mNewTexture->GetDepthBits() / 8;
|
---|
[1958] | 852 |
|
---|
[1964] | 853 | unsigned char *data = new unsigned char [mTexWidth * mTexHeight * components];
|
---|
[1960] | 854 | //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV;
|
---|
| 855 | const int texFormat = GL_RGBA;
|
---|
| 856 | glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_UNSIGNED_BYTE, data);
|
---|
| 857 |
|
---|
| 858 | string filename("items.jpg");
|
---|
| 859 | ilRegisterType(IL_UNSIGNED_BYTE);
|
---|
| 860 |
|
---|
| 861 | const int depth = 1;
|
---|
| 862 | const int bpp = components;
|
---|
| 863 |
|
---|
[1964] | 864 | ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
---|
[1960] | 865 | ilSaveImage((char *const)filename.c_str());
|
---|
| 866 |
|
---|
| 867 | cout << "finished" << endl;
|
---|
| 868 | delete data;
|
---|
| 869 | cout << "data deleted" << endl;
|
---|
| 870 | mNewTexture->DisableTextureTarget();
|
---|
| 871 | PrintGLerror("grab texture");
|
---|
| 872 | }
|
---|
| 873 |
|
---|
| 874 |
|
---|
[1964] | 875 | void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays)
|
---|
[1958] | 876 | {
|
---|
[1953] | 877 | mNewTexture->BeginCapture();
|
---|
[1944] | 878 | {
|
---|
| 879 | //cgGLBindProgram(sCgPassThroughProgram);
|
---|
| 880 | //cgGLEnableProfile(sCgFragmentProfile);
|
---|
[1951] | 881 | DrawGeometry();
|
---|
[1944] | 882 | }
|
---|
[1953] | 883 | mNewTexture->EndCapture();
|
---|
[1944] | 884 |
|
---|
[1951] | 885 | PrintGLerror("firstpass");
|
---|
[1953] | 886 | if (mNewTexture->IsRectangleTexture()) cout << "rect" << endl;
|
---|
[1944] | 887 |
|
---|
[1958] | 888 | // process the buffers for the first layer
|
---|
[1963] | 889 | ProcessDepthBuffer(rays, false, 0);
|
---|
[1958] | 890 |
|
---|
[1963] | 891 | for(int i = 1; i < mMaxDepth; ++ i)
|
---|
[1944] | 892 | {
|
---|
| 893 | // Peel another layer
|
---|
[1962] | 894 | // switch pointer between rendertextures
|
---|
| 895 | SwitchRenderTextures();
|
---|
[1944] | 896 |
|
---|
[1953] | 897 | mNewTexture->BeginCapture();
|
---|
[1944] | 898 | {
|
---|
| 899 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 900 |
|
---|
| 901 | cgGLBindProgram(sCgDepthPeelingProgram);
|
---|
| 902 | cgGLEnableProfile(sCgFragmentProfile);
|
---|
[1953] | 903 | cgGLSetTextureParameter(sTextureParam, mOldTexture->GetDepthTextureID());
|
---|
[1944] | 904 | cgGLEnableTextureParameter(sTextureParam);
|
---|
| 905 |
|
---|
[1951] | 906 | DrawGeometry();
|
---|
| 907 |
|
---|
[1944] | 908 | cgGLDisableTextureParameter(sTextureParam);
|
---|
[1949] | 909 | cgGLDisableProfile(sCgFragmentProfile);
|
---|
[1944] | 910 | }
|
---|
[1953] | 911 | mNewTexture->EndCapture();
|
---|
[1960] | 912 |
|
---|
| 913 | // process the buffers for following layer
|
---|
[1963] | 914 | ProcessDepthBuffer(rays, true, i);
|
---|
[1944] | 915 | }
|
---|
| 916 |
|
---|
[1951] | 917 | PrintGLerror("endpeeling");
|
---|
[1944] | 918 | }
|
---|
| 919 |
|
---|
| 920 |
|
---|
| 921 | }
|
---|