source: OGRE/trunk/ogre_changes/obsolete/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp @ 657

Revision 657, 5.1 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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  * Updated on 4/8/2005 by Tuan Kuranes email: tuan.kuranes@free.fr
41  */
42
43/**
44  * Default object constructor
45  *
46  */
47GLHardwareOcclusionQuery::GLHardwareOcclusionQuery()
48{
49        mPixelCount = 0;
50        mSkipCounter = 0;
51        mSkipInterval = 0;
52
53        // Check for hardware occlusion support
54        // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
55        mHasOcclusionSupportARB = (glGenQueriesARB_ptr != 0);
56        mHasOcclusionSupportNV = (glGenOcclusionQueriesNV_ptr != 0);
57
58        if (sUseArbQueries && mHasOcclusionSupportARB)
59                glGenQueriesARB_ptr(1, &mQueryID );     
60        else if (!sUseArbQueries && mHasOcclusionSupportNV)
61                glGenOcclusionQueriesNV_ptr(1, &mQueryID);
62}
63
64/**
65  * Object destructor
66  */
67GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
68{
69        if (sUseArbQueries && mHasOcclusionSupportARB)
70                glDeleteQueriesARB_ptr(1, &mQueryID);
71        else if (!sUseArbQueries && mHasOcclusionSupportNV)
72                glDeleteOcclusionQueriesNV_ptr(1, &mQueryID); 
73}
74
75//------------------------------------------------------------------
76// Occlusion query functions (see base class documentation for this)
77//--
78void GLHardwareOcclusionQuery::beginOcclusionQuery()
79{
80        //if (mSkipCounter >= mSkipInterval)  // otherwise no query ever issued if mSkipInterval = 0 !
81        //      mSkipCounter = 0; if (mSkipCounter != 0) return;
82
83        if (sUseArbQueries && mHasOcclusionSupportARB)
84                        glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID);
85        else if (!sUseArbQueries && mHasOcclusionSupportNV)
86                        glBeginOcclusionQueryNV_ptr(mQueryID);
87}
88       
89void GLHardwareOcclusionQuery::endOcclusionQuery()
90{
91        //if( mSkipCounter != 0) return;
92        if (sUseArbQueries && mHasOcclusionSupportARB)
93                        glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB);
94        else if (!sUseArbQueries && mHasOcclusionSupportNV)
95                        glEndOcclusionQueryNV_ptr();
96//      mSkipCounter++;
97                }
98
99bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  )
100{
101        if (sUseArbQueries && mHasOcclusionSupportARB)
102                glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
103        else if (!sUseArbQueries && mHasOcclusionSupportNV)
104glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
105        else
106                *NumOfFragments = 100000;               // Fails quietly
107
108        mPixelCount = *NumOfFragments;
109       
110        return true;
111}
112
113#ifdef GTP_VISIBILITY_MODIFIED_OGRE
114        //------------------------------------------------------------------
115bool GLHardwareOcclusionQuery::pullOcclusionQuery(unsigned int * NumOfFragments,
116                                                                                                  const bool waitForResult,
117                                                                                                  const HW_OCCLUSIONQUERY flag)
118{
119        if (sUseArbQueries && mHasOcclusionSupportARB) 
120        {
121                int isAvailable = GL_TRUE;
122
123                if (!waitForResult)
124                        glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
125               
126                if (isAvailable == GL_TRUE)
127                        glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
128
129                mPixelCount = *NumOfFragments;
130
131                return isAvailable == GL_TRUE;
132        }
133        else if (!sUseArbQueries && mHasOcclusionSupportNV)
134                {
135                unsigned int isAvailable = GL_TRUE;
136
137                if (!waitForResult)
138                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable);
139
140                if (isAvailable == GL_TRUE)
141                                glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
142
143                mPixelCount = *NumOfFragments;
144
145                return isAvailable == GL_TRUE;
146                }
147       
148                // In case hardware occlusion isn't supported, every object is set visible.
149                *NumOfFragments = 100000;               
150                mPixelCount = *NumOfFragments;
151
152        return GL_TRUE;
153}
154
155#endif // GTP_VIBILITY_MODIFIED_OGRE
156}
157
158
Note: See TracBrowser for help on using the repository browser.