2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
23
#include "GLResource.h"
24
#include "GLDeviceFactory.h"
26
#include "GLDeviceObjects.h"
27
#include "IOpenGLQuery.h"
31
IMPLEMENT_OBJECT_TYPE(IOpenGLQuery);
33
int IOpenGLQuery::_CurrentlyActiveQuery = 0;
34
IOpenGLQuery::IOpenGLQuery(QUERY_TYPE Type)
36
, _QueryStarted(false)
37
, IOpenGLResource(RTQUERY)
39
CHECKGL( glGenQueriesARB(1, &_OpenGLID)) ;
42
// The return type identifies the query state (see Queries).
43
// The method returns 1 (S_OK) if the query data is available and 0 (S_FALSE) if it is not.
44
// These are considered successful return values.
45
int IOpenGLQuery::GetData(
51
unsigned int ResultReady = 0;
52
glGetQueryObjectuivARB(_OpenGLID, GL_QUERY_RESULT_AVAILABLE_ARB, &ResultReady);
53
CHECKGL_MSG( glGetQueryObjectuivARB );
57
glGetQueryObjectuivARB(_OpenGLID, GL_QUERY_RESULT_ARB, (GLuint*)pData);
58
CHECKGL_MSG( glGetQueryObjectuivARB );
67
DWORD IOpenGLQuery::GetDataSize()
72
void IOpenGLQuery::GetDevice(GLDeviceFactory **ppDevice)
74
// Do not call this function.
78
QUERY_TYPE IOpenGLQuery::GetType()
83
void IOpenGLQuery::Issue(
87
if(IssueFlags == ISSUE_BEGIN)
89
nuxAssert(_CurrentlyActiveQuery == 0);
90
if(_QueryStarted == true)
92
nuxError(TEXT("The Query as already been activated"));
97
CHECKGL( glBeginQueryARB(GL_SAMPLES_PASSED_ARB, _OpenGLID) );
98
_CurrentlyActiveQuery = _OpenGLID;
101
else if(IssueFlags == ISSUE_END)
103
nuxAssert(_CurrentlyActiveQuery == _OpenGLID);
104
if(_QueryStarted == false)
106
nuxError(TEXT("The Query as already been stoped"));
110
_QueryStarted = false;
111
CHECKGL( glEndQueryARB(GL_SAMPLES_PASSED_ARB) );
112
_CurrentlyActiveQuery = 0;
117
// Return True is the result is available. That is glGetQueryObjectuivARB won't block
118
// if called with GL_QUERY_RESULT_ARB.
119
bool IOpenGLQuery::IsResultAvailable()
121
unsigned int ResultReady = 0;
122
glGetQueryObjectuivARB(_OpenGLID, GL_QUERY_RESULT_AVAILABLE_ARB, &ResultReady);
123
CHECKGL_MSG( glGetQueryObjectuivARB );
125
return ResultReady != 0;
127
// Return the result of the query. Make sure IsResultAvailable returned TRUE before calling this function.
128
// If you fail to do that, GetResult will block before returning.
129
unsigned int IOpenGLQuery::GetResult()
131
unsigned int SamplesPassed = 0;
132
glGetQueryObjectuivARB(_OpenGLID, GL_QUERY_RESULT_ARB, &SamplesPassed);
133
CHECKGL_MSG( glGetQueryObjectuivARB );
135
return SamplesPassed;