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