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