source: trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp @ 343

Revision 343, 5.0 KB checked in by mattausch, 19 years ago (diff)

added switch between NV and ARB queries in the render system and in the demos.
Fixed render queue bug: when clearing queue, we traversed through all priority groups
to clear the passmaps. This became very slow because had to traverse many elements (over 1000
for city demo). Now all we destroy the priority groups for each rendering (per hierarchy node).

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25
26#include "OgreGLHardwareOcclusionQuery.h"
27#include "OgreException.h"
28
29namespace Ogre {
30
31bool GLHardwareOcclusionQuery::sUseArbQueries = false;
32/**
33  * This is a class that is the base class of the query class for
34  * hardware occlusion testing.
35  *
36  * @author Lee Sandberg email: lee@abcmedia.se
37  *
38  * Updated on 12/7/2004 by Chris McGuirk
39  * - Implemented ARB_occlusion_query
40  */
41
42/**
43  * Default object constructor
44  *
45  */
46GLHardwareOcclusionQuery::GLHardwareOcclusionQuery()
47{
48        mPixelCount = 0;
49        mSkipCounter = 0;
50        mSkipInterval = 0;
51
52        // Check for hardware occlusion support
53        // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
54        mHasOcclusionSupportARB = (glGenQueriesARB_ptr != 0);
55        mHasOcclusionSupportNV = (glGenOcclusionQueriesNV_ptr != 0);
56
57        if (sUseArbQueries && mHasOcclusionSupportARB)
58                glGenQueriesARB_ptr(1, &mQueryID );     
59        else if (!sUseArbQueries && mHasOcclusionSupportNV)
60                glGenOcclusionQueriesNV_ptr(1, &mQueryID);
61}
62
63/**
64  * Object destructor
65  */
66GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
67{
68        if (sUseArbQueries && mHasOcclusionSupportARB)
69                glDeleteQueriesARB_ptr(1, &mQueryID);
70        else if (!sUseArbQueries && mHasOcclusionSupportNV)
71                glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); 
72}
73
74//------------------------------------------------------------------
75// Occlusion query functions (see base class documentation for this)
76//--
77void GLHardwareOcclusionQuery::beginOcclusionQuery()
78{
79        //if (mSkipCounter >= mSkipInterval)  // otherwise no query ever issued if mSkipInterval = 0 !
80        //      mSkipCounter = 0; if (mSkipCounter != 0) return;
81
82        if (sUseArbQueries && mHasOcclusionSupportARB)
83                        glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID);
84        else if (!sUseArbQueries && mHasOcclusionSupportNV)
85                        glBeginOcclusionQueryNV_ptr(mQueryID);
86}
87       
88void GLHardwareOcclusionQuery::endOcclusionQuery()
89{
90        //if( mSkipCounter != 0) return;
91        if (sUseArbQueries && mHasOcclusionSupportARB)
92                        glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB);
93        else if (!sUseArbQueries && mHasOcclusionSupportNV)
94                        glEndOcclusionQueryNV_ptr();
95//      mSkipCounter++;
96                }
97
98bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  )
99{
100        if (sUseArbQueries && mHasOcclusionSupportARB)
101                glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
102        else if (!sUseArbQueries && mHasOcclusionSupportNV)
103glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
104        else
105                *NumOfFragments = 100000;               // Fails quietly
106
107        mPixelCount = *NumOfFragments;
108       
109        return true;
110}
111
112#ifdef GTP_VISIBILITY_MODIFIED_OGRE
113        //------------------------------------------------------------------
114bool GLHardwareOcclusionQuery::pullOcclusionQuery(unsigned int * NumOfFragments,
115                                                                                                  const bool waitForResult,
116                                                                                                  const HW_OCCLUSIONQUERY flag)
117{
118        if (sUseArbQueries && mHasOcclusionSupportARB) 
119        {
120                int isAvailable = GL_TRUE;
121
122                if (!waitForResult)
123                        glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
124               
125                if (isAvailable == GL_TRUE)
126                        glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
127
128                mPixelCount = *NumOfFragments;
129
130                return isAvailable == GL_TRUE;
131        }
132        else if (!sUseArbQueries && mHasOcclusionSupportNV)
133                {
134                unsigned int isAvailable = GL_TRUE;
135
136                if (!waitForResult)
137                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable);
138
139                if (isAvailable == GL_TRUE)
140                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
141
142                mPixelCount = *NumOfFragments;
143
144                return isAvailable == GL_TRUE;
145                }
146       
147                // In case hardware occlusion isn't supported, every object is set visible.
148                *NumOfFragments = 100000;               
149                mPixelCount = *NumOfFragments;
150
151        return GL_TRUE;
152}
153
154#endif // GTP_VIBILITY_MODIFIED_OGRE
155}
Note: See TracBrowser for help on using the repository browser.