csplugincommon/rendermanager/standardtreetraits.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_STANDARDTREETRAITS_H__ 00020 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_STANDARDTREETRAITS_H__ 00021 00026 #include "iengine/mesh.h" 00027 #include "ivaria/view.h" 00028 #include "ivideo/rendermesh.h" 00029 #include "csutil/comparator.h" 00030 #include "csutil/compileassert.h" 00031 #include "csplugincommon/rendermanager/renderview.h" 00032 #include "csplugincommon/rendermanager/svarrayholder.h" 00033 00034 namespace CS 00035 { 00036 00037 00038 namespace RenderManager 00039 { 00049 class RenderTreeStandardTraits 00050 { 00051 public: 00054 00055 struct MeshNodeExtraDataType 00056 { 00057 CS::Graphics::RenderPriority priority; 00058 }; 00059 00061 struct ContextNodeExtraDataType 00062 { 00063 }; 00064 00066 struct MeshExtraDataType 00067 { 00068 }; 00069 00071 struct PersistentDataExtraDataType 00072 { 00073 }; 00074 00079 struct MeshNodeKeyType 00080 { 00081 uint8 priority : 5; 00082 uint8 isPortal : 1; 00083 uint8 meshSorting : 2; 00084 00085 bool operator== (const MeshNodeKeyType& other) const 00086 { 00087 //BIG HACK 00088 return (reinterpret_cast<const int8&> (*this) == reinterpret_cast<const int8&> (other)); 00089 } 00090 bool operator<= (const MeshNodeKeyType& other) const 00091 { 00092 //BIG HACK 00093 return (reinterpret_cast<const int8&> (*this) <= reinterpret_cast<const int8&> (other)); 00094 } 00095 }; 00098 // Enable/disables 00099 00102 00103 static CS_FORCEINLINE 00104 MeshNodeKeyType GetMeshNodeKey (CS::Graphics::RenderPriority defaultPriority, 00105 const csRenderMesh& rendermesh, 00106 const PersistentDataExtraDataType& data) 00107 { 00108 MeshNodeKeyType result = {0}; 00109 00110 if (rendermesh.renderPrio.IsValid()) 00111 result.priority = rendermesh.renderPrio; 00112 else 00113 result.priority = defaultPriority; 00114 result.isPortal = rendermesh.portal != 0; 00115 00116 return result; 00117 } 00118 00120 template<typename T> 00121 static CS_FORCEINLINE_TEMPLATEMETHOD 00122 void SetupMeshNode (T& meshNode, CS::Graphics::RenderPriority defaultPriority, 00123 const csRenderMesh& rendermesh, 00124 const PersistentDataExtraDataType& data) 00125 { 00126 if (rendermesh.renderPrio.IsValid()) 00127 meshNode.priority = rendermesh.renderPrio; 00128 else 00129 meshNode.priority = defaultPriority; 00130 } 00133 private: 00134 }; 00135 00136 00137 00138 } 00139 } 00140 00141 // Make sure the size matches so that we can use the comparison hack below 00142 CS_COMPILE_ASSERT(sizeof(CS::RenderManager::RenderTreeStandardTraits::MeshNodeKeyType) == sizeof(int8)); 00143 00144 template<> 00145 class csComparator<CS::RenderManager::RenderTreeStandardTraits::MeshNodeKeyType> 00146 { 00147 public: 00148 static int Compare (CS::RenderManager::RenderTreeStandardTraits::MeshNodeKeyType const& mk1, 00149 CS::RenderManager::RenderTreeStandardTraits::MeshNodeKeyType const& mk2) 00150 { 00151 //BIG HACK 00152 return (int) (reinterpret_cast<const int8&> (mk1) - reinterpret_cast<const int8&> (mk2)); 00153 } 00154 }; 00155 00156 00157 00158 #endif
Generated for Crystal Space 2.0 by doxygen 1.6.1