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

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

added depth pass algorithm + delayed transparent object rendering (so depth ordering is right)

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
29
30namespace Ogre {
31
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        //if (glGenQueriesARB_ptr != 0)
55        if (glGenOcclusionQueriesNV_ptr != 0)
56    {
57                mHasOcclusionSupport = true;
58        }
59        else
60        {
61                mHasOcclusionSupport = false;
62        }
63
64        if(mHasOcclusionSupport)
65        {
66                //glGenQueriesARB_ptr(1, &mQueryID );   
67                glGenOcclusionQueriesNV_ptr(1, &mQueryID);
68        }
69}
70
71/**
72  * Object destructor
73  */
74GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
75{
76        if( mHasOcclusionSupport )
77        {
78                //glDeleteQueriesARB_ptr(1, &mQueryID); 
79                glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); 
80        }       
81}
82
83//------------------------------------------------------------------
84// Occlusion query functions (see base class documentation for this)
85//--
86void GLHardwareOcclusionQuery::beginOcclusionQuery()
87{
88        // Make it fail silently if hardware occlusion isn't supported
89        if(mHasOcclusionSupport)
90        {
91                // Counter starts at 0 again at mSkipInterval
92#ifndef GTP_VISIBILITY_MODIFIED_OGRE
93                if(mSkipCounter == mSkipInterval)
94#else
95                if (mSkipCounter >= mSkipInterval)  // otherwise no query ever issued if mSkipInterval = 0 !
96#endif // GTP_VISIBILITY_MODIFIED_OGRE
97        {
98                        mSkipCounter = 0;
99                }
100
101                if (mSkipCounter == 0)
102                {
103                        //glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID);
104                        glBeginOcclusionQueryNV_ptr(mQueryID);
105                }
106        }
107}
108       
109void GLHardwareOcclusionQuery::endOcclusionQuery()
110{
111        // Make it fail silently if hardware occlusion isn't supported
112        if(mHasOcclusionSupport)
113        {
114                if( mSkipCounter == 0)
115                {
116                        //glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB);
117                        glEndOcclusionQueryNV_ptr();
118                }
119
120                mSkipCounter++;
121        }
122}
123
124//------------------------------------------------------------------
125// OpenGL dosn't use the flag paramter.
126//------------------------------------------------------------------
127bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  )
128{
129        if( mHasOcclusionSupport )      // Make it fail silently if hardware occlusion isn't supported
130        {
131                //glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
132glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
133        }
134        else
135        {
136                *NumOfFragments = 100000;               // Fails quitlly -> every object tested is visable.
137        }
138
139        mPixelCount = *NumOfFragments;
140       
141        return true;
142}
143
144#ifdef GTP_VISIBILITY_MODIFIED_OGRE
145        //------------------------------------------------------------------
146        bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag)
147{
148        unsigned int isAvailable = GL_TRUE;
149
150                if (mHasOcclusionSupport)       
151        {
152                if (!waitForResult)
153                {
154                        // use nv queries rather that arb because they are faster (no flush)
155                                //glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
156                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable);
157                }
158
159                if (isAvailable == GL_TRUE)
160                {
161                                //glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
162                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
163                }
164        }
165        else
166        {
167                // In case hardware occlusion isn't supported, every object is set visible.
168                *NumOfFragments = 100000;               
169        }
170
171                mPixelCount = *NumOfFragments;
172
173        return isAvailable == GL_TRUE; 
174}
175
176#endif // GTP_VIBILITY_MODIFIED_OGRE
177}
Note: See TracBrowser for help on using the repository browser.