#include "OcclusionQuery.h" #include #ifdef _WIN32 #include #else #include #include //#include #include #endif #define _ARBGL using namespace std; namespace GtpVisibilityPreprocessor { bool OcclusionQuery::sUseArbQueries = true; OcclusionQuery::OcclusionQuery() { GLuint id; if (sUseArbQueries) { #ifdef _ARBGL // VH glGenQueriesARB(1, &id); #endif } else { #ifdef _ARBGL // VH glGenOcclusionQueriesNV(1, &id); #endif } } OcclusionQuery::OcclusionQuery(const unsigned int idx): mId(idx) {} OcclusionQuery::~OcclusionQuery() { if (sUseArbQueries) { #ifdef _ARBGL // VH glDeleteQueriesARB(1, &mId); #endif } else { #ifdef _ARBGL // VH glDeleteOcclusionQueriesNV(1, &mId); #endif } } //----------------------------------------------------------------------- void OcclusionQuery::BeginQuery() { if (sUseArbQueries) { #ifdef _ARBGL // VH glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId); #endif } else { #ifdef _ARBGL // VH glBeginOcclusionQueryNV(mId); #endif } } //----------------------------------------------------------------------- void OcclusionQuery::EndQuery() { if (sUseArbQueries) { #ifdef _ARBGL // VH glEndQueryARB(GL_SAMPLES_PASSED_ARB); #endif } else { #ifdef _ARBGL // VH glEndOcclusionQueryNV(); #endif } } unsigned int OcclusionQuery::GetQueryId() const { return mId; } bool OcclusionQuery::ResultAvailable() const { GLuint available; if (sUseArbQueries) { #ifdef _ARBGL // VH //GLint available; glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_AVAILABLE_ARB, &available); #endif return available == GL_TRUE; } else { #ifdef _ARBGL // VH glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available); #endif return available == GL_TRUE; } } unsigned int OcclusionQuery::GetQueryResult() const { GLuint sampleCount; if (sUseArbQueries) { #ifdef _ARBGL // VH glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount); #endif return sampleCount; } else { #ifdef _ARBGL // VH glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount); #endif return sampleCount; } } void OcclusionQuery::GenQueries(std::vector &queries, const int numQueries) { if ((int)queries.size() < numQueries) { const int n = numQueries - (int)queries.size(); unsigned int *newQueries = new unsigned int[n]; if (sUseArbQueries) { #ifdef _ARBGL // VH glGenQueriesARB(n, (unsigned int *)newQueries); #endif } else { #ifdef _ARBGL // VH glGenOcclusionQueriesNV(n, (unsigned int *)newQueries); #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