Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

/Users/blackie/Documents/myRepository/phobosengine-vc2005/phobosengine/phobosengine/OcclusionQuery.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef OCCLUSIONQUERY_H
00004 #define OCCLUSIONQUERY_H
00005 
00006 
00007 #include "Renderer.h"
00008 
00009 #include "AABB.h"
00010 #include "Vector3f.h"
00011 
00012 
00013 namespace pge {
00014         namespace occlusionquery  {
00015                 //
00016                 //
00017                 //
00018                 static int occlusionQuery(AABB *boundingBox) {
00019                         int pixelCount;
00020                         unsigned int queryId;
00021 
00022                         // Generate a new query.
00023                         glGenQueries(1, &queryId);
00024 
00025                         // Do not render anything actually to the screen.
00026                         glColorMask(false, false, false, false);
00027                         glDepthMask(false);
00028                         // Disable texturing for faster "rendering".
00029                         glDisable(GL_TEXTURE_2D);
00030 
00031                         // Start the query.
00032                         glBeginQuery(GL_SAMPLES_PASSED_ARB, queryId);
00033 
00034                         // Here render the AABB which should be checked.
00035                         boundingBox->renderSolid(Vector3f(1.0f, 1.0f, 1.0f));
00036 
00037                         // End the query.
00038                         glEndQuery(GL_SAMPLES_PASSED_ARB);
00039 
00040                         // And set render mode back to normal.
00041                         glColorMask(true, true, true, true);
00042                         glDepthMask(true);
00043 
00044                         // With this construct you can wait for the result and do some calculations in between.
00045                         // But since this engine currently does not support any physics calculations or something similar,
00046                         // there is nothing we could wait for.
00047 
00048                         //available = new int[1];
00049                         //do {
00050 
00051                         // Do some calculations here.
00052 
00053                         //gl.glGetQueryObjectivARB(queryId[0], GL.GL_QUERY_RESULT_AVAILABLE_ARB, IntBuffer.wrap(available));
00054 
00055                         //} while (available[0] == 0);
00056 
00057                         // So we just wait normally for the result.
00058                         glGetQueryObjectiv(queryId, GL_QUERY_RESULT_ARB, &pixelCount);
00059 
00060                         // Delete the query.
00061                         glDeleteQueries(1, &queryId);
00062 
00063                         // Return the value.
00064                         return pixelCount;
00065                 }
00066         };
00067 };
00068 
00069 #endif

Generated on Mon Oct 16 12:08:10 2006 for Phobosengine by doxygen 1.3.4