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

Revision 2629, 3.1 KB checked in by bittner, 16 years ago (diff)

commit after merge with vlastimil

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