[1001] | 1 | #include "OcclusionQuery.h"
|
---|
| 2 | #include <iostream>
|
---|
[2575] | 3 |
|
---|
| 4 |
|
---|
| 5 | #ifdef _WIN32
|
---|
[1001] | 6 | #include <glInterface.h>
|
---|
[2575] | 7 | #else
|
---|
| 8 | #include <GL/gl.h>
|
---|
| 9 | #include <GL/glu.h>
|
---|
| 10 | //#include <GL/glxext.h>
|
---|
| 11 | #include <SDL/SDL_opengl.h>
|
---|
| 12 | #endif
|
---|
[1001] | 13 |
|
---|
[2663] | 14 | //#ifdef _WIN32
|
---|
[2629] | 15 | // This Macro does not compile under LINUX
|
---|
[2663] | 16 | //#define _ARBGL
|
---|
| 17 | //#endif
|
---|
[2612] | 18 |
|
---|
[2663] | 19 |
|
---|
[1001] | 20 | using namespace std;
|
---|
| 21 |
|
---|
[2663] | 22 | namespace GtpVisibilityPreprocessor
|
---|
| 23 | {
|
---|
[1001] | 24 |
|
---|
[2663] | 25 | const static bool sUseArbQueries = true;
|
---|
[1001] | 26 |
|
---|
| 27 |
|
---|
| 28 | OcclusionQuery::OcclusionQuery()
|
---|
| 29 | {
|
---|
| 30 | GLuint id;
|
---|
[2663] | 31 |
|
---|
[1001] | 32 | if (sUseArbQueries)
|
---|
| 33 | {
|
---|
[2663] | 34 | #ifdef _WIN32
|
---|
| 35 | // VH
|
---|
| 36 | glGenQueriesARB(1, &id);
|
---|
[2575] | 37 | #endif
|
---|
[1001] | 38 | }
|
---|
| 39 | else
|
---|
| 40 | {
|
---|
[2663] | 41 | #ifdef _WIN32
|
---|
| 42 | // VH
|
---|
[1001] | 43 | glGenOcclusionQueriesNV(1, &id);
|
---|
[2575] | 44 | #endif
|
---|
[1001] | 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[2663] | 48 |
|
---|
[1001] | 49 | OcclusionQuery::OcclusionQuery(const unsigned int idx):
|
---|
| 50 | mId(idx)
|
---|
[2663] | 51 | {
|
---|
| 52 | }
|
---|
[1001] | 53 |
|
---|
| 54 |
|
---|
| 55 | OcclusionQuery::~OcclusionQuery()
|
---|
| 56 | {
|
---|
| 57 | if (sUseArbQueries)
|
---|
| 58 | {
|
---|
[2663] | 59 | #ifdef _WIN32
|
---|
| 60 | // VH
|
---|
[1001] | 61 | glDeleteQueriesARB(1, &mId);
|
---|
[2575] | 62 | #endif
|
---|
[1001] | 63 | }
|
---|
| 64 | else
|
---|
| 65 | {
|
---|
[2663] | 66 | #ifdef _WIN32
|
---|
| 67 | // VH
|
---|
[1001] | 68 | glDeleteOcclusionQueriesNV(1, &mId);
|
---|
[2575] | 69 | #endif
|
---|
[1001] | 70 | }
|
---|
| 71 |
|
---|
| 72 | }
|
---|
[2663] | 73 |
|
---|
| 74 |
|
---|
[1001] | 75 | void OcclusionQuery::BeginQuery()
|
---|
| 76 | {
|
---|
| 77 | if (sUseArbQueries)
|
---|
| 78 | {
|
---|
[2663] | 79 | #ifdef _WIN32
|
---|
| 80 | // VH
|
---|
[2669] | 81 | //cout << "issuing arb query" << endl;
|
---|
[1001] | 82 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId);
|
---|
[2575] | 83 | #endif
|
---|
[1001] | 84 | }
|
---|
| 85 | else
|
---|
| 86 | {
|
---|
[2663] | 87 | #ifdef _WIN32
|
---|
| 88 | // VH
|
---|
| 89 | cout << "issuing nv query" << endl;
|
---|
[1001] | 90 | glBeginOcclusionQueryNV(mId);
|
---|
[2575] | 91 | #endif
|
---|
[1001] | 92 | }
|
---|
| 93 | }
|
---|
[2663] | 94 |
|
---|
| 95 |
|
---|
[1001] | 96 | void OcclusionQuery::EndQuery()
|
---|
| 97 | {
|
---|
| 98 | if (sUseArbQueries)
|
---|
| 99 | {
|
---|
[2663] | 100 | #ifdef _WIN32
|
---|
| 101 | // VH
|
---|
[2669] | 102 | //cout << "ending query" << endl;
|
---|
[1001] | 103 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
[2575] | 104 | #endif
|
---|
[1001] | 105 | }
|
---|
| 106 | else
|
---|
| 107 | {
|
---|
[2663] | 108 | #ifdef _WIN32
|
---|
| 109 | // VH
|
---|
[1001] | 110 | glEndOcclusionQueryNV();
|
---|
[2575] | 111 | #endif
|
---|
[1001] | 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | unsigned int OcclusionQuery::GetQueryId() const
|
---|
| 117 | {
|
---|
| 118 | return mId;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[2663] | 121 |
|
---|
[1001] | 122 | bool OcclusionQuery::ResultAvailable() const
|
---|
| 123 | {
|
---|
[2663] | 124 | GLuint available = GL_TRUE;
|
---|
[1001] | 125 |
|
---|
| 126 | if (sUseArbQueries)
|
---|
| 127 | {
|
---|
[2663] | 128 | #ifdef _WIN32
|
---|
| 129 | // VH
|
---|
| 130 | glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_AVAILABLE_ARB, &available);
|
---|
[2575] | 131 | #endif
|
---|
[1001] | 132 | }
|
---|
| 133 | else
|
---|
| 134 | {
|
---|
[2663] | 135 | #ifdef _WIN32
|
---|
[2669] | 136 | // VH
|
---|
| 137 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available);
|
---|
[2575] | 138 | #endif
|
---|
[1001] | 139 | }
|
---|
| 140 |
|
---|
[2663] | 141 | return available == GL_TRUE;
|
---|
[1001] | 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | unsigned int OcclusionQuery::GetQueryResult() const
|
---|
| 146 | {
|
---|
[2663] | 147 | GLuint sampleCount = 1;
|
---|
[1001] | 148 |
|
---|
| 149 | if (sUseArbQueries)
|
---|
| 150 | {
|
---|
[2663] | 151 | #ifdef _WIN32
|
---|
| 152 | // VH
|
---|
[1001] | 153 | glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount);
|
---|
[2575] | 154 | #endif
|
---|
[1001] | 155 | }
|
---|
| 156 | else
|
---|
| 157 | {
|
---|
[2663] | 158 | #ifdef _WIN32
|
---|
| 159 | // VH
|
---|
[1001] | 160 | glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount);
|
---|
[2575] | 161 | #endif
|
---|
[1001] | 162 | }
|
---|
[2663] | 163 |
|
---|
| 164 | return sampleCount;
|
---|
[1001] | 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
[2663] | 168 | void OcclusionQuery::GenQueries(std::vector<OcclusionQuery * > &queries,
|
---|
| 169 | int numQueries)
|
---|
[1001] | 170 | {
|
---|
| 171 | if ((int)queries.size() < numQueries)
|
---|
| 172 | {
|
---|
| 173 | const int n = numQueries - (int)queries.size();
|
---|
| 174 | unsigned int *newQueries = new unsigned int[n];
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 | if (sUseArbQueries)
|
---|
| 178 | {
|
---|
[2663] | 179 | #ifdef _WIN32
|
---|
| 180 | // VH
|
---|
[1001] | 181 | glGenQueriesARB(n, (unsigned int *)newQueries);
|
---|
[2669] | 182 | //cout << "creating " << n << " arb queries" << endl;
|
---|
[2575] | 183 | #endif
|
---|
[1001] | 184 | }
|
---|
| 185 | else
|
---|
| 186 | {
|
---|
[2663] | 187 | #ifdef _WIN32
|
---|
| 188 | // VH
|
---|
| 189 | glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
|
---|
[2669] | 190 | //cout << "creating " << n << " nv queries" << endl;
|
---|
[2575] | 191 | #endif
|
---|
[1001] | 192 | }
|
---|
| 193 |
|
---|
| 194 | for (int i = 0; i < n; ++ i)
|
---|
| 195 | {
|
---|
| 196 | queries.push_back(new OcclusionQuery(newQueries[i]));
|
---|
| 197 | //cout << "q: " << i << " id: " << newQueries[i] << endl;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | delete [] newQueries;
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
[2663] | 203 |
|
---|
| 204 |
|
---|
[1785] | 205 | } // namespace
|
---|