[1001] | 1 | #include "OcclusionQuery.h"
|
---|
| 2 | #include <iostream>
|
---|
| 3 | #include <glInterface.h>
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | using namespace std;
|
---|
| 7 |
|
---|
| 8 | namespace GtpVisibilityPreprocessor {
|
---|
| 9 |
|
---|
[2002] | 10 | bool OcclusionQuery::sUseArbQueries = true;
|
---|
[1001] | 11 |
|
---|
| 12 |
|
---|
| 13 | OcclusionQuery::OcclusionQuery()
|
---|
| 14 | {
|
---|
| 15 | GLuint id;
|
---|
| 16 |
|
---|
| 17 | if (sUseArbQueries)
|
---|
| 18 | {
|
---|
| 19 | glGenQueriesARB(1, &id);
|
---|
| 20 | }
|
---|
| 21 | else
|
---|
| 22 | {
|
---|
| 23 | glGenOcclusionQueriesNV(1, &id);
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | OcclusionQuery::OcclusionQuery(const unsigned int idx):
|
---|
| 28 | mId(idx)
|
---|
| 29 | {}
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | OcclusionQuery::~OcclusionQuery()
|
---|
| 33 | {
|
---|
| 34 | if (sUseArbQueries)
|
---|
| 35 | {
|
---|
| 36 | glDeleteQueriesARB(1, &mId);
|
---|
| 37 | }
|
---|
| 38 | else
|
---|
| 39 | {
|
---|
| 40 | glDeleteOcclusionQueriesNV(1, &mId);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | }
|
---|
| 44 | //-----------------------------------------------------------------------
|
---|
| 45 | void OcclusionQuery::BeginQuery()
|
---|
| 46 | {
|
---|
| 47 | if (sUseArbQueries)
|
---|
| 48 | {
|
---|
| 49 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId);
|
---|
| 50 | }
|
---|
| 51 | else
|
---|
| 52 | {
|
---|
| 53 | glBeginOcclusionQueryNV(mId);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | //-----------------------------------------------------------------------
|
---|
| 57 | void OcclusionQuery::EndQuery()
|
---|
| 58 | {
|
---|
| 59 | if (sUseArbQueries)
|
---|
| 60 | {
|
---|
| 61 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
| 62 | }
|
---|
| 63 | else
|
---|
| 64 | {
|
---|
| 65 | glEndOcclusionQueryNV();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | unsigned int OcclusionQuery::GetQueryId() const
|
---|
| 71 | {
|
---|
| 72 | return mId;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | bool OcclusionQuery::ResultAvailable() const
|
---|
| 76 | {
|
---|
| 77 | GLuint available;
|
---|
| 78 |
|
---|
| 79 | if (sUseArbQueries)
|
---|
| 80 | {
|
---|
| 81 | //GLint available;
|
---|
| 82 | glGetQueryObjectuivARB(mId,
|
---|
| 83 | GL_QUERY_RESULT_AVAILABLE_ARB,
|
---|
| 84 | &available);
|
---|
| 85 | return available == GL_TRUE;
|
---|
| 86 | }
|
---|
| 87 | else
|
---|
| 88 | {
|
---|
| 89 |
|
---|
| 90 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available);
|
---|
| 91 |
|
---|
| 92 | return available == GL_TRUE;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | unsigned int OcclusionQuery::GetQueryResult() const
|
---|
| 99 | {
|
---|
| 100 | GLuint sampleCount;
|
---|
| 101 |
|
---|
| 102 | if (sUseArbQueries)
|
---|
| 103 | {
|
---|
| 104 | glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount);
|
---|
| 105 | return sampleCount;
|
---|
| 106 | }
|
---|
| 107 | else
|
---|
| 108 | {
|
---|
| 109 |
|
---|
| 110 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount);
|
---|
| 111 | return sampleCount;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | void OcclusionQuery::GenQueries(std::vector<OcclusionQuery * > &queries, const int numQueries)
|
---|
| 117 | {
|
---|
| 118 | if ((int)queries.size() < numQueries)
|
---|
| 119 | {
|
---|
| 120 | const int n = numQueries - (int)queries.size();
|
---|
| 121 | unsigned int *newQueries = new unsigned int[n];
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | if (sUseArbQueries)
|
---|
| 125 | {
|
---|
| 126 | glGenQueriesARB(n, (unsigned int *)newQueries);
|
---|
| 127 | }
|
---|
| 128 | else
|
---|
| 129 | {
|
---|
| 130 | glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | for (int i = 0; i < n; ++ i)
|
---|
| 134 | {
|
---|
| 135 | queries.push_back(new OcclusionQuery(newQueries[i]));
|
---|
| 136 | //cout << "q: " << i << " id: " << newQueries[i] << endl;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | delete [] newQueries;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
[1785] | 142 | } // namespace
|
---|