csplugincommon/rendermanager/viscull.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csplugincommon/rendermanager/viscull.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2007 by Marten Svanfeldt
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSPLUGINCOMMON_RENDERMANAGER_VISCULL_H__
    00020 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_VISCULL_H__
    00021
    00026 #include "csplugincommon/rendermanager/rendertree.h"
    00027 #include "csplugincommon/rendermanager/renderview.h"
    00028 #include "iengine/viscull.h"
    00029
    00030 namespace CS
    00031 {
    00032 namespace RenderManager
    00033 {
    00034   // Forward declare the functions
    00035
    00036   template<typename RenderTree>
    00037   bool Viscull (typename RenderTree::ContextNode& context, RenderView* rw,
    00038     iVisibilityCuller* culler);
    00039
    00040   namespace Implementation
    00041   {
    00046     template<typename RenderTree>
    00047     class ViscullCallback :
    00048       public scfImplementation1<ViscullCallback<RenderTree>, iVisibilityCullerListener>
    00049     {
    00050     public:
    00051       //---- Types
    00052       typedef RenderTree RenderTreeType;
    00053       typedef typename RenderTreeType::ContextNode ContextNodeType;
    00054
    00055       ViscullCallback (ContextNodeType& context, RenderView* currentRenderView,
    00056         const CS::Utility::MeshFilter* filter)
    00057         : scfImplementation1<ViscullCallback, iVisibilityCullerListener> (this),
    00058         context (context), currentRenderView (currentRenderView),
    00059         sector (currentRenderView->GetThisSector()), filter (filter)
    00060       {}
    00061
    00062
    00063       virtual void ObjectVisible (iVisibilityObject *visobject,
    00064         iMeshWrapper *imesh, uint32 frustum_mask)
    00065           {
    00066         if (!(filter && filter->IsMeshFiltered (imesh)))
    00067         {
    00068           // Get the meshes
    00069           int numMeshes;
    00070           csSectorVisibleRenderMeshes* meshList = sector->GetVisibleRenderMeshes (
    00071                     numMeshes,
    00072                     imesh, currentRenderView, frustum_mask);
    00073
    00074           for (int m = 0; m < numMeshes; ++m)
    00075           {
    00076                   // Todo: Handle static lod & draw distance
    00077                   csZBufMode zmode = meshList[m].imesh->GetZBufMode ();
    00078                   CS::Graphics::RenderPriority renderPrio =
    00079                     meshList[m].imesh->GetRenderPriority ();
    00080
    00081         #ifdef CS_DEBUG
    00082                   const char* const db_mesh_name = meshList[m].imesh->QueryObject()->GetName();
    00083         #endif
    00084                   typename RenderTreeType::MeshNode::SingleMesh sm;
    00085                   sm.meshWrapper = meshList[m].imesh;
    00086                   sm.meshObjSVs = meshList[m].imesh->GetSVContext();
    00087                   sm.zmode = zmode;
    00088                   sm.meshFlags = meshList[m].imesh->GetFlags();
    00089
    00090                   // Add it to the appropriate meshnode
    00091                   for (int i = 0; i < meshList[m].num; ++i)
    00092                   {
    00093                     csRenderMesh* rm = meshList[m].rmeshes[i];
    00094
    00095                     if (rm->portal)
    00096                     {
    00097               #ifdef CS_DEBUG
    00098                             typename ContextNodeType::PortalHolder h = {db_mesh_name, rm->portal, imesh};
    00099               #else
    00100                             typename ContextNodeType::PortalHolder h = {rm->portal, imesh};
    00101               #endif
    00102                             context.allPortals.Push (h);
    00103                     }
    00104                     else
    00105                     {
    00106                             context.AddRenderMesh (rm, renderPrio, sm);
    00107                     }
    00108                   }
    00109                 }
    00110               }
    00111       } // end objectvisible
    00112
    00113       virtual int GetVisibleMeshes (iMeshWrapper* mw, uint32 frustum_mask, csSectorVisibleRenderMeshes*& meshList)
    00114       {
    00115         if (filter && filter->IsMeshFiltered (mw))
    00116         {
    00117           // Return 0 visible meshes if filtered.
    00118           return 0;
    00119         }
    00120
    00121         // Get the meshes
    00122         int numMeshes;
    00123         meshList = sector->GetVisibleRenderMeshes (numMeshes, mw, currentRenderView, frustum_mask);
    00124         return numMeshes;
    00125       }
    00126
    00127
    00128       virtual void MarkVisible (iMeshWrapper *mw, int numMeshes, csSectorVisibleRenderMeshes*& meshList)
    00129       {
    00130         for (int m = 0; m < numMeshes; ++m)
    00131         {
    00132           csZBufMode zmode = meshList[m].imesh->GetZBufMode ();
    00133           CS::Graphics::RenderPriority renderPrio =
    00134             meshList[m].imesh->GetRenderPriority ();
    00135
    00136 #ifdef CS_DEBUG
    00137           const char* const db_mesh_name = meshList[m].imesh->QueryObject()->GetName();
    00138 #endif
    00139
    00140           typename RenderTreeType::MeshNode::SingleMesh sm;
    00141           sm.meshWrapper = meshList[m].imesh;
    00142           sm.meshObjSVs = meshList[m].imesh->GetSVContext();
    00143           sm.zmode = zmode;
    00144           sm.meshFlags = meshList[m].imesh->GetFlags();
    00145
    00146           // Add it to the appropriate meshnode
    00147           for (int i = 0; i < meshList[m].num; ++i)
    00148           {
    00149             csRenderMesh* rm = meshList[m].rmeshes[i];
    00150
    00151             if (rm->portal)
    00152             {
    00153
    00154 #ifdef CS_DEBUG
    00155               typename ContextNodeType::PortalHolder h = {db_mesh_name, rm->portal, mw};
    00156 #else
    00157               typename ContextNodeType::PortalHolder h = {rm->portal, mw};
    00158 #endif
    00159
    00160               context.allPortals.Push (h);
    00161             }
    00162             else
    00163             {
    00164               context.AddRenderMesh (rm, renderPrio, sm);
    00165             }
    00166           }
    00167         }
    00168       }
    00169
    00170     private:
    00171       ContextNodeType& context;
    00172       RenderView* currentRenderView;
    00173       iSector* sector;
    00174       const CS::Utility::MeshFilter* filter;
    00175     };
    00176   }
    00177
    00194   template<typename RenderTree>
    00195   bool Viscull (typename RenderTree::ContextNode& context, RenderView* rw,
    00196     iVisibilityCuller* culler)
    00197   {
    00198     const CS::Utility::MeshFilter* filter = &rw->GetMeshFilter();
    00199     CS::RenderManager::Implementation::ViscullCallback<RenderTree> cb (context, rw, filter);
    00200
    00201     int renderW = 0, renderH = 0;
    00202     context.GetTargetDimensions (renderW, renderH);
    00203     culler->VisTest (rw, &cb, renderW, renderH);
    00204
    00205     return true;
    00206   }
    00207
    00208 }
    00209 }
    00210
    00211
    00212
    00213 #endif