1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #include "OgreGLHardwareOcclusionQuery.h" |
---|
31 | #include "OgreException.h" |
---|
32 | |
---|
33 | namespace Ogre { |
---|
34 | |
---|
35 | /** |
---|
36 | * This is a class that is the base class of the query class for |
---|
37 | * hardware occlusion testing. |
---|
38 | * |
---|
39 | * @author Lee Sandberg email: lee@abcmedia.se |
---|
40 | * |
---|
41 | * Updated on 12/7/2004 by Chris McGuirk |
---|
42 | * - Implemented ARB_occlusion_query |
---|
43 | * Updated on 13/9/2005 by Tuan Kuranes email: tuan.kuranes@free.fr |
---|
44 | */ |
---|
45 | //------------------------------------------------------------------ |
---|
46 | /** |
---|
47 | * Default object constructor |
---|
48 | * |
---|
49 | */ |
---|
50 | GLHardwareOcclusionQuery::GLHardwareOcclusionQuery() |
---|
51 | { |
---|
52 | // Check for hardware occlusion support |
---|
53 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
54 | { |
---|
55 | glGenQueriesARB(1, &mQueryID ); |
---|
56 | } |
---|
57 | else if (GLEW_NV_occlusion_query) |
---|
58 | { |
---|
59 | glGenOcclusionQueriesNV(1, &mQueryID); |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | OGRE_EXCEPT( Exception::ERR_INTERNAL_ERROR, |
---|
64 | "Cannot allocate a Hardware query. This video card doesn't supports it, sorry.", |
---|
65 | "GLHardwareOcclusionQuery::GLHardwareOcclusionQuery" ); |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|
69 | //------------------------------------------------------------------ |
---|
70 | /** |
---|
71 | * Object destructor |
---|
72 | */ |
---|
73 | GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() |
---|
74 | { |
---|
75 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
76 | { |
---|
77 | glDeleteQueriesARB(1, &mQueryID); |
---|
78 | } |
---|
79 | else if (GLEW_NV_occlusion_query) |
---|
80 | { |
---|
81 | glDeleteOcclusionQueriesNV(1, &mQueryID); |
---|
82 | } |
---|
83 | } |
---|
84 | //------------------------------------------------------------------ |
---|
85 | void GLHardwareOcclusionQuery::beginOcclusionQuery() |
---|
86 | { |
---|
87 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
88 | { |
---|
89 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mQueryID); |
---|
90 | } |
---|
91 | else if (GLEW_NV_occlusion_query) |
---|
92 | { |
---|
93 | glBeginOcclusionQueryNV(mQueryID); |
---|
94 | } |
---|
95 | } |
---|
96 | //------------------------------------------------------------------ |
---|
97 | void GLHardwareOcclusionQuery::endOcclusionQuery() |
---|
98 | { |
---|
99 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
100 | { |
---|
101 | glEndQueryARB(GL_SAMPLES_PASSED_ARB); |
---|
102 | } |
---|
103 | else if (GLEW_NV_occlusion_query) |
---|
104 | { |
---|
105 | glEndOcclusionQueryNV(); |
---|
106 | } |
---|
107 | |
---|
108 | } |
---|
109 | //------------------------------------------------------------------ |
---|
110 | bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments ) |
---|
111 | { |
---|
112 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
113 | { |
---|
114 | glGetQueryObjectuivARB(mQueryID, GL_QUERY_RESULT_ARB, (GLuint*)NumOfFragments); |
---|
115 | mPixelCount = *NumOfFragments; |
---|
116 | return true; |
---|
117 | } |
---|
118 | else if (GLEW_NV_occlusion_query) |
---|
119 | { |
---|
120 | glGetOcclusionQueryuivNV(mQueryID, GL_PIXEL_COUNT_NV, (GLuint*)NumOfFragments); |
---|
121 | mPixelCount = *NumOfFragments; |
---|
122 | return true; |
---|
123 | } |
---|
124 | |
---|
125 | return false; |
---|
126 | } |
---|
127 | //------------------------------------------------------------------ |
---|
128 | bool GLHardwareOcclusionQuery::isStillOutstanding(void) |
---|
129 | { |
---|
130 | GLuint available; |
---|
131 | |
---|
132 | if(GLEW_VERSION_1_5 || GLEW_ARB_occlusion_query) |
---|
133 | { |
---|
134 | glGetQueryObjectuivARB(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &available); |
---|
135 | } |
---|
136 | else if (GLEW_NV_occlusion_query) |
---|
137 | { |
---|
138 | glGetOcclusionQueryuivNV(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &available); |
---|
139 | } |
---|
140 | |
---|
141 | // GL_TRUE means a wait would occur |
---|
142 | return !(available == GL_TRUE); |
---|
143 | } |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | |
---|