Repository navigation
Expand file tree
/
Copy pathQueryObject.h
More file actions
86 lines (65 loc) · 2.66 KB
/
Copy pathQueryObject.h
File metadata and controls
86 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
This file is part of the Rendering library.
Copyright (C) 2007-2012 Benjamin Eikel <benjamin@eikel.org>
Copyright (C) 2007-2012 Claudius Jähn <claudius@uni-paderborn.de>
Copyright (C) 2007-2012 Ralf Petring <ralf@petring.net>
This library is subject to the terms of the Mozilla Public License, v. 2.0.
You should have received a copy of the MPL along with this library; see the
file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef RENDERING_QUERY_OBJECT_H_
#define RENDERING_QUERY_OBJECT_H_
#include <cstdint>
namespace Rendering {
/**
* Wrapper class for OpenGL queries.
* @see OcclusionQuery.h
* @author Benjamin Eikel, Claudius Jähn
* @date 2013-03-21
* @ingroup rendering_helper
*/
class QueryObject {
public:
//! Standard constructor
explicit QueryObject(uint32_t _queryType) : queryType(_queryType),id(getFreeId()) {}
QueryObject(const QueryObject & other) = delete;
QueryObject(QueryObject && other) : queryType(other.queryType),id(other.id){ other.id = 0; }
//! Destructor frees the query identifier.
~QueryObject() { freeId(id); }
QueryObject & operator=(const QueryObject &) = delete;
QueryObject & operator=(QueryObject && other) = delete;
/*! Check if the result of the last query is already available.
* @return @c true if the test is finished, false otherwise.
*/
RENDERINGAPI bool isResultAvailable() const;
/*! Return the result of the query.
* @return result value (e.g. sample count )
*/
RENDERINGAPI uint32_t getResult() const;
/*! Returns the result as 64bit value.
* If the used open gl driver does not support 'GL_ARB_timer_query', a warning is shown once
* and getResult() is returned instead. */
RENDERINGAPI uint64_t getResult64()const;
//! Start the query. @a end() has to be called after the rendering was done.
RENDERINGAPI void begin() const;
//! Stop the query.
RENDERINGAPI void end() const;
//! Record the GL time; only used with GL_TIMESTAMP
RENDERINGAPI void queryCounter() const;
bool isValid()const { return id!=0; }
//! Returns the GL constant of the query's type. \note Don't rely on GL constants from outside of Rendering.
uint32_t _getQueryType()const { return queryType; }
private:
uint32_t queryType; //! OpenGL query object type; e.g. GL_SAMPLES_PASSED
uint32_t id; //! OpenGL query object identifier
/*! Request the next free query identifier.
* @return Occlusion query identifier
*/
RENDERINGAPI static uint32_t getFreeId();
/*! Mark the given query identifier as free.
* @param id Occlusion query identifier
*/
RENDERINGAPI static void freeId(uint32_t id);
};
}
#endif /* RENDERING_QUERY_OBJECT_H_ */