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

RevLine 
[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
14using namespace std;
15
16namespace GtpVisibilityPreprocessor {
17
[2002]18bool OcclusionQuery::sUseArbQueries = true;
[1001]19
20
21OcclusionQuery::OcclusionQuery()
22{
23        GLuint id;
24
25        if (sUseArbQueries)
26        {
[2575]27#ifdef _ARBGL
28          // VH
29          glGenQueriesARB(1, &id);
30#endif
[1001]31        }
32        else
33        {               
[2575]34#ifdef _ARBGL
35          // VH
[1001]36                glGenOcclusionQueriesNV(1, &id);
[2575]37#endif
[1001]38        }
39}
40
41OcclusionQuery::OcclusionQuery(const unsigned int idx):
42mId(idx)
43{}
44
45
46OcclusionQuery::~OcclusionQuery()
47{
48        if (sUseArbQueries)
49        {
[2575]50#ifdef _ARBGL
51          // VH
[1001]52                glDeleteQueriesARB(1, &mId);
[2575]53#endif
[1001]54        }
55        else
56        {
[2575]57#ifdef _ARBGL
58          // VH
[1001]59                glDeleteOcclusionQueriesNV(1, &mId);
[2575]60#endif
[1001]61        }
62       
63}
64//-----------------------------------------------------------------------
65void OcclusionQuery::BeginQuery()
66{
67        if (sUseArbQueries)
68        {
[2575]69#ifdef _ARBGL
70          // VH
[1001]71                glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId);
[2575]72#endif
[1001]73        }
74        else
75        {
[2575]76#ifdef _ARBGL
77          // VH
[1001]78                glBeginOcclusionQueryNV(mId);
[2575]79#endif
[1001]80        }
81}
82//-----------------------------------------------------------------------
83void OcclusionQuery::EndQuery()
84{
85        if (sUseArbQueries)
86        {
[2575]87#ifdef _ARBGL
88          // VH
[1001]89                glEndQueryARB(GL_SAMPLES_PASSED_ARB);
[2575]90#endif
[1001]91        }
92        else
93        {
[2575]94#ifdef _ARBGL
95          // VH
[1001]96                glEndOcclusionQueryNV();       
[2575]97#endif
[1001]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        {
[2575]113#ifdef _ARBGL
114          // VH
[1001]115                //GLint available;
116                glGetQueryObjectuivARB(mId,
117                                                           GL_QUERY_RESULT_AVAILABLE_ARB,
[2575]118                                       &available);
119#endif         
[1001]120                return available == GL_TRUE;
121        }
122        else
123        {
[2575]124#ifdef _ARBGL
125          // VH
126          glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available);
127#endif
[1001]128                return available == GL_TRUE;
129        }
130
131}
132
133
134unsigned int OcclusionQuery::GetQueryResult() const
135{
136        GLuint sampleCount;
137
138        if (sUseArbQueries)
139        {
[2575]140#ifdef _ARBGL
141          // VH
[1001]142                glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount);
[2575]143#endif
[1001]144                return sampleCount;
145        }
146        else
147        {       
[2575]148#ifdef _ARBGL
149          // VH
[1001]150                glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount);
[2575]151#endif         
[1001]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                {
[2575]167#ifdef _ARBGL
168          // VH
[1001]169                        glGenQueriesARB(n, (unsigned int *)newQueries);
[2575]170#endif
[1001]171                }
172                else
173                {
[2575]174#ifdef _ARBGL
175          // VH           
176                  glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
177#endif           
[1001]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}
[1785]189} // namespace
Note: See TracBrowser for help on using the repository browser.