# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/RenderQueue.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef RenderQueue_INCLUDE_ONCE
    00033 #define RenderQueue_INCLUDE_ONCE
    00034
    00035 #include <vlGraphics/RenderQueueSorter.hpp>
    00036
    00037 namespace vl
    00038 {
    00039   //------------------------------------------------------------------------------
    00040   // RenderQueue
    00041   //------------------------------------------------------------------------------
    00045   class RenderQueue: public Object
    00046   {
    00047   public:
    00048     virtual const char* className() { return "vl::RenderQueue"; }
    00049
    00050     RenderQueue(): mSize(0), mSizeMP(0)
    00051     {
    00052       VL_DEBUG_SET_OBJECT_NAME()
    00053       mList.reserve(100);
    00054       mListMP.reserve(100);
    00055     }
    00056
    00057     RenderToken* at(int i) const { return mList[i].get(); }
    00058
    00059     RenderToken* newToken(bool multipass)
    00060     {
    00061       if (multipass)
    00062       {
    00063         ++mSizeMP;
    00064         if ( mSizeMP > (int)mListMP.size() )
    00065           mListMP.push_back( new RenderToken );
    00066         return mListMP[mSizeMP-1].get();
    00067       }
    00068       else
    00069       {
    00070         ++mSize;
    00071         if ( mSize > (int)mList.size() )
    00072           mList.push_back( new RenderToken );
    00073         return mList[mSize-1].get();
    00074       }
    00075     }
    00076
    00077     void clear()
    00078     {
    00079       mSize   = 0;
    00080       mSizeMP = 0;
    00081     }
    00082
    00083     bool empty()
    00084     {
    00085       return mSize == 0;
    00086     }
    00087
    00088     int size() const
    00089     {
    00090       return mSize;
    00091     }
    00092
    00093     void sort(RenderQueueSorter* sorter, Camera* camera)
    00094     {
    00095       if (sorter->mightNeedZCameraDistance())
    00096       {
    00097         for(int i=0; i<size(); ++i)
    00098         {
    00099           RenderToken* tok = at(i);
    00100           vec3 center = tok->mRenderable->boundingBox().isNull() ? vec3(0,0,0) : tok->mRenderable->boundingBox().center();
    00101           if ( sorter->confirmZCameraDistanceNeed(tok) )
    00102           {
    00103             if (tok->mActor->transform())
    00104               // tok->mCameraDistance = ( camera->viewMatrix() * (tok->mActor->transform()->worldMatrix() * center) ).lengthSquared();
    00105               tok->mCameraDistance = -( camera->viewMatrix() * (tok->mActor->transform()->worldMatrix() * center) ).z();
    00106             else
    00107               // tok->mCameraDistance = ( camera->viewMatrix() * /* I* */ center ).lengthSquared();
    00108               tok->mCameraDistance = -( camera->viewMatrix() * /* I* */ center ).z();
    00109           }
    00110           else
    00111             tok->mCameraDistance = 0;
    00112         }
    00113       }
    00114
    00115       VL_CHECK( sorter )
    00116       std::sort( mList.begin(), mList.begin() + size(), Sorter( sorter ) );
    00117     }
    00118
    00119   private:
    00120     class Sorter
    00121     {
    00122     public:
    00123       Sorter(const RenderQueueSorter* sorter): mRenderQueueSorter(sorter) {}
    00124       bool operator()(const ref<RenderToken>& a, const ref<RenderToken>& b) const
    00125       {
    00126         VL_CHECK(a && b);
    00127         return mRenderQueueSorter->operator()(a.get(), b.get());
    00128       }
    00129     protected:
    00130       const RenderQueueSorter* mRenderQueueSorter;
    00131     };
    00132
    00133   protected:
    00134     std::vector< ref<RenderToken> > mList;
    00135     std::vector< ref<RenderToken> > mListMP;
    00136     int mSize;
    00137     int mSizeMP;
    00138   };
    00139   //------------------------------------------------------------------------------
    00140   typedef std::map< float, ref<RenderQueue> > TRenderQueueMap;
    00141   //------------------------------------------------------------------------------
    00142 }
    00143
    00144 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:25.
Permission is granted to use this page to write and publish articles regarding Visualization Library.