source: trunk/VUT/work/ogre_changes/RenderSystem/GL/src/OgreGLHardwareOcclusionQuery.cpp @ 88

Revision 88, 4.2 KB checked in by mattausch, 19 years ago (diff)
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
31int GLHardwareOcclusionQuery::m_Skip = 0;
32
33/**
34  * This is a class that is the base class of the query class for
35  * hardware occlusion testing.
36  *
37  * @author Lee Sandberg email: lee@abcmedia.se
38  */
39
40/* Functions used;
41
42glGenOcclusionQueriesNV_ptr( 1, m_uintQuery );
43glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] );
44glBeginOcclusionQueryNV_ptr( m_uintQuery[0] );
45glEndOcclusionQueryNV_ptr();
46glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );
47
48  TO DO: change this to the new ARB functions...
49
50*/
51
52
53/**
54  * Default object constructor
55  *
56  */
57GLHardwareOcclusionQuery::GLHardwareOcclusionQuery()
58{
59        m_uintPixelCount = 0;
60        m_SkipCounter = 0;
61
62        // Check for hardware occlusion support
63    if( glDeleteOcclusionQueriesNV_ptr != 0 )   // This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
64    {
65                m_bHWOcclusionSupport = true;
66        }
67        else
68        {
69                m_bHWOcclusionSupport = false;
70        }
71
72        if( m_bHWOcclusionSupport )
73        {
74                glGenOcclusionQueriesNV_ptr( 1, m_uintQuery ); 
75        }
76}
77
78
79/**
80  * Object destructor
81  */
82GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery()
83{
84        if( m_bHWOcclusionSupport )
85        {
86                glDeleteOcclusionQueriesNV_ptr( 1, &m_uintQuery[0] ); 
87        }       
88}
89
90//------------------------------------------------------------------
91// Occlusion query functions (see base class documentation for this)
92//--
93void GLHardwareOcclusionQuery::beginOcclusionQuery()
94{
95        if( m_bHWOcclusionSupport )     // Make it fail silently if hardware occlusion isn't supported
96        {
97                glBeginOcclusionQueryNV_ptr( m_uintQuery[0] );
98        }
99}
100       
101void GLHardwareOcclusionQuery::endOcclusionQuery()
102{
103        if( m_bHWOcclusionSupport )     // Make it fail silently if hardware occlusion isn't supported
104        {
105                glEndOcclusionQueryNV_ptr();
106        }
107}
108
109bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments, const bool waitForResult)
110{
111        unsigned int isAvailable = GL_TRUE;
112
113        if( m_bHWOcclusionSupport )     
114        {
115                if(!waitForResult)
116                {
117                        glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable );
118                }
119
120                if(isAvailable == GL_TRUE)
121                {
122                        glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, NumOfFragments );
123                }
124        }
125        else
126        {
127                // In case hardware occlusion isn't supported, every object is set visible.
128                *NumOfFragments = 100000;               
129        }
130
131        m_uintPixelCount = *NumOfFragments;
132
133        return isAvailable == GL_TRUE; 
134}
135
136//------------------------------------------------------------------
137// OpenGL doesn't use the flag, but to implement the abstract interface we need to include this function.
138// Using this function in OpenGL mode simple works the same way as calling the other function without the flag parameter,
139// but in DX9 it works differentlly, see notes in the DX9 implementation.
140//--
141bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag  )
142{
143        return pullOcclusionQuery(NumOfFragments, waitForResult);
144}
145
146}
147
148
Note: See TracBrowser for help on using the repository browser.