Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 4.2 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30#include "OgreGLHardwareOcclusionQuery.h"
31#include "OgreException.h"
32
33namespace 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  */
50GLHardwareOcclusionQuery::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  */
73GLHardwareOcclusionQuery::~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//------------------------------------------------------------------
85void 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//------------------------------------------------------------------
97void 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//------------------------------------------------------------------
110bool 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//------------------------------------------------------------------
128bool 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
Note: See TracBrowser for help on using the repository browser.