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

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
[2629]14#ifdef _WIN32
15// This Macro does not compile under LINUX
[2612]16#define _ARBGL
[2629]17#endif
[2612]18
[1001]19using namespace std;
20
21namespace GtpVisibilityPreprocessor {
22
[2002]23bool OcclusionQuery::sUseArbQueries = true;
[1001]24
25
26OcclusionQuery::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
46OcclusionQuery::OcclusionQuery(const unsigned int idx):
47mId(idx)
48{}
49
50
51OcclusionQuery::~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//-----------------------------------------------------------------------
70void 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//-----------------------------------------------------------------------
88void 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
107unsigned int OcclusionQuery::GetQueryId() const
108{
109        return mId;
110}
111
112bool 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
139unsigned 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
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                {
[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
Note: See TracBrowser for help on using the repository browser.