source: GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp @ 2575

Revision 2575, 3.0 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

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