#include "OcclusionQuery.h" #include #ifdef _WIN32 #include #else #include #include //#include #include #endif //#ifdef _WIN32 // This Macro does not compile under LINUX //#define _ARBGL //#endif using namespace std; namespace GtpVisibilityPreprocessor { const static bool sUseArbQueries = true; OcclusionQuery::OcclusionQuery() { GLuint id; if (sUseArbQueries) { #ifdef _WIN32 // VH glGenQueriesARB(1, &id); #endif } else { #ifdef _WIN32 // VH glGenOcclusionQueriesNV(1, &id); #endif } } OcclusionQuery::OcclusionQuery(const unsigned int idx): mId(idx) { } OcclusionQuery::~OcclusionQuery() { if (sUseArbQueries) { #ifdef _WIN32 // VH glDeleteQueriesARB(1, &mId); #endif } else { #ifdef _WIN32 // VH glDeleteOcclusionQueriesNV(1, &mId); #endif } } void OcclusionQuery::BeginQuery() { if (sUseArbQueries) { #ifdef _WIN32 // VH //cout << "issuing arb query" << endl; glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId); #endif } else { #ifdef _WIN32 // VH cout << "issuing nv query" << endl; glBeginOcclusionQueryNV(mId); #endif } } void OcclusionQuery::EndQuery() { if (sUseArbQueries) { #ifdef _WIN32 // VH //cout << "ending query" << endl; glEndQueryARB(GL_SAMPLES_PASSED_ARB); #endif } else { #ifdef _WIN32 // VH glEndOcclusionQueryNV(); #endif } } unsigned int OcclusionQuery::GetQueryId() const { return mId; } bool OcclusionQuery::ResultAvailable() const { GLuint available = GL_TRUE; if (sUseArbQueries) { #ifdef _WIN32 // VH glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_AVAILABLE_ARB, &available); #endif } else { #ifdef _WIN32 // VH glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); #endif } return available == GL_TRUE; } unsigned int OcclusionQuery::GetQueryResult() const { GLuint sampleCount = 1; if (sUseArbQueries) { #ifdef _WIN32 // VH glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount); #endif } else { #ifdef _WIN32 // VH glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount); #endif } return sampleCount; } void OcclusionQuery::GenQueries(std::vector &queries, int numQueries) { if ((int)queries.size() < numQueries) { const int n = numQueries - (int)queries.size(); unsigned int *newQueries = new unsigned int[n]; if (sUseArbQueries) { #ifdef _WIN32 // VH glGenQueriesARB(n, (unsigned int *)newQueries); //cout << "creating " << n << " arb queries" << endl; #endif } else { #ifdef _WIN32 // VH glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); //cout << "creating " << n << " nv queries" << endl; #endif } for (int i = 0; i < n; ++ i) { queries.push_back(new OcclusionQuery(newQueries[i])); //cout << "q: " << i << " id: " << newQueries[i] << endl; } delete [] newQueries; } } } // namespace