PixelLightAPI  .
OcclusionQuery.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: OcclusionQuery.h                               *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLRENDERER_OCCLUSION_QUERY_H__
00024 #define __PLRENDERER_OCCLUSION_QUERY_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLRenderer/Renderer/Resource.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLRenderer {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Abstract renderer occlusion query
00046 *
00047 *  @verbatim
00048 *    Usage example:
00049 *    Create one or more OcclusionQuery object one per outstanding
00050 *    query or one per tested object.
00051 *
00052 *    OcclusionQuery *pOcclusionQuery = cRenderer.CreateOcclusionQuery();
00053 *    // In the rendering loop:
00054 *    // Draw all occludes
00055 *    pOcclusionQuery->BeginOcclusionQuery();
00056 *    // Draw the polygons to be tested
00057 *    pOcclusionQuery->EndOcclusionQuery();
00058 *    // Do something useful to give the GPU some time to process the stuff
00059 *    // Results must be pulled using:
00060 *    PLCore::uint32 nNumberOfVisibleFragments;
00061 *    if (!pOcclusionQuery->PullOcclusionQuery(&nNumberOfVisibleFragments)) {
00062 *      if (nNumberOfVisibleFragments >= pOcclusionQuery->GetMinFragments()) {
00063 *        // Our object is visible (or visible enough ;-)
00064 *      }
00065 *    } else {
00066 *       // The result isn't available yet! We still have to wait for it...
00067 *    }
00068 *  @endverbatim
00069 */
00070 class OcclusionQuery : public Resource {
00071 
00072 
00073     //[-------------------------------------------------------]
00074     //[ Public functions                                      ]
00075     //[-------------------------------------------------------]
00076     public:
00077         /**
00078         *  @brief
00079         *    Destructor
00080         */
00081         PLRENDERER_API virtual ~OcclusionQuery();
00082 
00083 
00084     //[-------------------------------------------------------]
00085     //[ Public virtual OcclusionQuery functions               ]
00086     //[-------------------------------------------------------]
00087     public:
00088         /**
00089         *  @brief
00090         *    Starts the hardware occlusion query
00091         *
00092         *  @return
00093         *    'true' if all went fine and the occlusion query was started, else
00094         *    'false' (maybe occlusion query is not supported or skip rate is active)
00095         */
00096         virtual bool BeginOcclusionQuery() = 0;
00097 
00098         /**
00099         *  @brief
00100         *    Ends the hardware occlusion query
00101         */
00102         virtual void EndOcclusionQuery() = 0;
00103 
00104         /**
00105         *  @brief
00106         *    Pulls the hardware occlusion query too see if there is a result
00107         *
00108         *  @param[out] pnNumOfFragments
00109         *    If not a null pointer it will receive the number of visible fragments
00110         *
00111         *  @return
00112         *    'true' if all went fine, else 'false' (the queried data isn't available yet)
00113         *
00114         *  @note
00115         *    - Hardware occlusion is an asynchronous process the result may take a frame or so.
00116         *      one idea is to test pass 1 and if not visible skip pass 2. Also note that objects which are
00117         *      not visible must be tested every frame. Visible objects don't need testing every frame.
00118         *      Testing non visible objects can be don unlit, no texture with low LOD object - this
00119         *      is also the case when using for instance only a bounding box for a complex mesh.
00120         *    - After BeginOcclusionQuery()/EndOcclusionQuery() you should do some other stuff before
00121         *      asking for the result using this function to give the GPU some time to process the
00122         *      the stuff. If this function returns 'true' then you still have to wait for the result!
00123         *
00124         *  @see
00125         *    - GetMinFragments()
00126         */
00127         virtual bool PullOcclusionQuery(PLCore::uint32 *pnNumOfFragments = nullptr) = 0;
00128 
00129         /**
00130         *  @brief
00131         *    Returns the number of the last occlusion query visible fragments
00132         *
00133         *  @return
00134         *    The fragment count from the last test
00135         */
00136         virtual PLCore::uint32 GetLastQuerysPixelCount() const = 0;
00137 
00138         /**
00139         *  @brief
00140         *    Returns the skip rate
00141         *
00142         *  @return
00143         *    Current skip rate
00144         *
00145         *  @remarks
00146         *    This function allows you to set how often the hardware occlusion really are sent to the driver
00147         *    if you set it to 0 every hw occlusion test is actually made. If you set it to 1 only the half
00148         *    of your queries are sent for all visible objects. 2 will result in 25% of all queries to actually be sent
00149         *    which will result in a better performance. New and none visible objects will be tested all the time.
00150         *    This class can keep track on visible and none visible objects for you.
00151         */
00152         virtual PLCore::uint32 GetSkipRate() const = 0;
00153 
00154         /**
00155         *  @brief
00156         *    Sets the skip rate
00157         *
00158         *  @param[in] nRate
00159         *    New skip rate
00160         *
00161         *  @see
00162         *    - GetSkipRate()
00163         */
00164         virtual void SetSkipRate(PLCore::uint32 nRate = 0) = 0;
00165 
00166         /**
00167         *  @brief
00168         *    Gets the minimum number of visible fragments
00169         *
00170         *  @return
00171         *    Minimum number of visible fragments
00172         *
00173         *  @remarks
00174         *    This setting indicates when something can be seen as invisible.
00175         *    For instance often you can see something as invisible if less then
00176         *    e.g. 10 fragments are visible without a visual quality impact.
00177         */
00178         virtual PLCore::uint32 GetMinFragments() const = 0;
00179 
00180         /**
00181         *  @brief
00182         *    Sets the minimum number of visible fragments
00183         *
00184         *  @param[in] nMinFragments
00185         *    Minimum number of visible fragments
00186         *
00187         *  @see
00188         *    - GetMinFragments()
00189         */
00190         virtual void SetMinFragments(PLCore::uint32 nMinFragments = 0) = 0;
00191 
00192 
00193     //[-------------------------------------------------------]
00194     //[ Protected functions                                   ]
00195     //[-------------------------------------------------------]
00196     protected:
00197         /**
00198         *  @brief
00199         *    Constructor
00200         *
00201         *  @param[in] cRenderer
00202         *    The owner renderer
00203         */
00204         PLRENDERER_API OcclusionQuery(Renderer &cRenderer);
00205 
00206 
00207     //[-------------------------------------------------------]
00208     //[ Private functions                                     ]
00209     //[-------------------------------------------------------]
00210     private:
00211         /**
00212         *  @brief
00213         *    Copy constructor
00214         *
00215         *  @param[in] cSource
00216         *    Source to copy from
00217         */
00218         OcclusionQuery(const OcclusionQuery &cSource);
00219 
00220         /**
00221         *  @brief
00222         *    Copy operator
00223         *
00224         *  @param[in] cSource
00225         *    Source to copy from
00226         *
00227         *  @return
00228         *    Reference to this instance
00229         */
00230         OcclusionQuery &operator =(const OcclusionQuery &cSource);
00231 
00232 
00233 };
00234 
00235 
00236 //[-------------------------------------------------------]
00237 //[ Namespace                                             ]
00238 //[-------------------------------------------------------]
00239 } // PLRenderer
00240 
00241 
00242 #endif // __PLRENDERER_OCCLUSION_QUERY_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:57
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported