[3] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __VertexIndexData_H__ |
---|
| 30 | #define __VertexIndexData_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | #include "OgreHardwareVertexBuffer.h" |
---|
| 34 | #include "OgreHardwareIndexBuffer.h" |
---|
| 35 | |
---|
| 36 | namespace Ogre { |
---|
| 37 | |
---|
| 38 | /// Define a list of usage flags |
---|
| 39 | typedef std::vector<HardwareBuffer::Usage> BufferUsageList; |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | /** Summary class collecting together vertex source information. */ |
---|
| 43 | class _OgreExport VertexData |
---|
| 44 | { |
---|
| 45 | private: |
---|
| 46 | /// Protected copy constructor, to prevent misuse |
---|
| 47 | VertexData(const VertexData& rhs); /* do nothing, should not use */ |
---|
| 48 | /// Protected operator=, to prevent misuse |
---|
| 49 | VertexData& operator=(const VertexData& rhs); /* do not use */ |
---|
| 50 | public: |
---|
| 51 | VertexData(); |
---|
| 52 | ~VertexData(); |
---|
| 53 | |
---|
| 54 | /** Declaration of the vertex to be used in this operation. |
---|
| 55 | @remarks Note that this is created for you on construction. |
---|
| 56 | */ |
---|
| 57 | VertexDeclaration* vertexDeclaration; |
---|
| 58 | /** The vertex buffer bindings to be used. |
---|
| 59 | @remarks Note that this is created for you on construction. |
---|
| 60 | */ |
---|
| 61 | VertexBufferBinding* vertexBufferBinding; |
---|
| 62 | /// The base vertex index to start from |
---|
| 63 | size_t vertexStart; |
---|
| 64 | /// The number of vertices used in this operation |
---|
| 65 | size_t vertexCount; |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | /// Struct used to hold hardware morph / pose vertex data information |
---|
| 69 | struct HardwareAnimationData |
---|
| 70 | { |
---|
| 71 | const VertexElement* targetVertexElement; |
---|
| 72 | Real parametric; |
---|
| 73 | }; |
---|
| 74 | typedef std::vector<HardwareAnimationData> HardwareAnimationDataList; |
---|
| 75 | /// VertexElements used for hardware morph / pose animation |
---|
| 76 | HardwareAnimationDataList hwAnimationDataList; |
---|
| 77 | /// Number of hardware animation data items used |
---|
| 78 | size_t hwAnimDataItemsUsed; |
---|
| 79 | |
---|
| 80 | /** Clones this vertex data, potentially including replicating any vertex buffers. |
---|
| 81 | @remarks The caller is expected to delete the returned pointer when ready |
---|
| 82 | */ |
---|
| 83 | VertexData* clone(bool copyData = true) const; |
---|
| 84 | |
---|
| 85 | /** Modifies the vertex data to be suitable for use for rendering shadow geometry. |
---|
| 86 | @remarks |
---|
| 87 | Preparing vertex data to generate a shadow volume involves firstly ensuring that the |
---|
| 88 | vertex buffer containing the positions is a standalone vertex buffer, |
---|
| 89 | with no other components in it. This method will therefore break apart any existing |
---|
| 90 | vertex buffers if position is sharing a vertex buffer. |
---|
| 91 | Secondly, it will double the size of this vertex buffer so that there are 2 copies of |
---|
| 92 | the position data for the mesh. The first half is used for the original, and the second |
---|
| 93 | half is used for the 'extruded' version. The vertex count used to render will remain |
---|
| 94 | the same though, so as not to add any overhead to regular rendering of the object. |
---|
| 95 | Both copies of the position are required in one buffer because shadow volumes stretch |
---|
| 96 | from the original mesh to the extruded version. |
---|
| 97 | @par |
---|
| 98 | It's important to appreciate that this method can fundamentally change the structure of your |
---|
| 99 | vertex buffers, although in reality they will be new buffers. As it happens, if other |
---|
| 100 | objects are using the original buffers then they will be unaffected because the reference |
---|
| 101 | counting will keep them intact. However, if you have made any assumptions about the |
---|
| 102 | structure of the vertex data in the buffers of this object, you may have to rethink them. |
---|
| 103 | */ |
---|
| 104 | void prepareForShadowVolume(void); |
---|
| 105 | |
---|
| 106 | /** Additional shadow volume vertex buffer storage. |
---|
| 107 | @remarks |
---|
| 108 | This additional buffer is only used where we have prepared this VertexData for |
---|
| 109 | use in shadow volume contruction, and where the current render system supports |
---|
| 110 | vertex programs. This buffer contains the 'w' vertex position component which will |
---|
| 111 | be used by that program to differentiate between extruded and non-extruded vertices. |
---|
| 112 | This 'w' component cannot be included in the original position buffer because |
---|
| 113 | DirectX does not allow 4-component positions in the fixed-function pipeline, and the original |
---|
| 114 | position buffer must still be usable for fixed-function rendering. |
---|
| 115 | @par |
---|
| 116 | Note that we don't store any vertex declaration or vertex buffer binding here becuase this |
---|
| 117 | can be reused in the shadow algorithm. |
---|
| 118 | */ |
---|
| 119 | HardwareVertexBufferSharedPtr hardwareShadowVolWBuffer; |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | /** Reorganises the data in the vertex buffers according to the |
---|
| 123 | new vertex declaration passed in. Note that new vertex buffers |
---|
| 124 | are created and written to, so if the buffers being referenced |
---|
| 125 | by this vertex data object are also used by others, then the |
---|
| 126 | original buffers will not be damaged by this operation. |
---|
| 127 | Once this operation has completed, the new declaration |
---|
| 128 | passed in will overwrite the current one. |
---|
| 129 | @param newDeclaration The vertex declaration which will be used |
---|
| 130 | for the reorganised buffer state. Note that the new delcaration |
---|
| 131 | must not include any elements which do not already exist in the |
---|
| 132 | current declaration; you can drop elements by |
---|
| 133 | excluding them from the declaration if you wish, however. |
---|
| 134 | @param bufferUsages Vector of usage flags which indicate the usage options |
---|
| 135 | for each new vertex buffer created. The indexes of the entries must correspond |
---|
| 136 | to the buffer binding values referenced in the declaration. |
---|
| 137 | */ |
---|
| 138 | void reorganiseBuffers(VertexDeclaration* newDeclaration, const BufferUsageList& bufferUsage); |
---|
| 139 | |
---|
| 140 | /** Reorganises the data in the vertex buffers according to the |
---|
| 141 | new vertex declaration passed in. Note that new vertex buffers |
---|
| 142 | are created and written to, so if the buffers being referenced |
---|
| 143 | by this vertex data object are also used by others, then the |
---|
| 144 | original buffers will not be damaged by this operation. |
---|
| 145 | Once this operation has completed, the new declaration |
---|
| 146 | passed in will overwrite the current one. |
---|
| 147 | This version of the method derives the buffer usages from the existing |
---|
| 148 | buffers, by using the 'most flexible' usage from the equivalent sources. |
---|
| 149 | @param newDeclaration The vertex declaration which will be used |
---|
| 150 | for the reorganised buffer state. Note that the new delcaration |
---|
| 151 | must not include any elements which do not already exist in the |
---|
| 152 | current declaration; you can drop elements by |
---|
| 153 | excluding them from the declaration if you wish, however. |
---|
| 154 | */ |
---|
| 155 | void reorganiseBuffers(VertexDeclaration* newDeclaration); |
---|
| 156 | |
---|
| 157 | /** Remove any gaps in the vertex buffer bindings. |
---|
| 158 | @remarks |
---|
| 159 | This is useful if you've removed elements and buffers from this vertex |
---|
| 160 | data and want to remove any gaps in the vertex buffer bindings. This |
---|
| 161 | method is mainly useful when reorganising vertex data manually. |
---|
| 162 | @note |
---|
| 163 | This will cause binding index of the elements in the vertex declaration |
---|
| 164 | to be altered to new binding index. |
---|
| 165 | */ |
---|
| 166 | void closeGapsInBindings(void); |
---|
| 167 | |
---|
| 168 | /** Remove all vertex buffers that never used by the vertex declaration. |
---|
| 169 | @remarks |
---|
| 170 | This is useful if you've removed elements from the vertex declaration |
---|
| 171 | and want to unreference buffers that never used any more. This method |
---|
| 172 | is mainly useful when reorganising vertex data manually. |
---|
| 173 | @note |
---|
| 174 | This also remove any gaps in the vertex buffer bindings. |
---|
| 175 | */ |
---|
| 176 | void removeUnusedBuffers(void); |
---|
| 177 | |
---|
| 178 | /** Convert all packed colour values (VET_COLOUR_*) in buffers used to |
---|
| 179 | another type. |
---|
| 180 | @param srcType The source colour type to assume if the ambiguous VET_COLOUR |
---|
| 181 | is encountered. |
---|
| 182 | @param destType The destination colour type, must be VET_COLOUR_ABGR or |
---|
| 183 | VET_COLOUR_ARGB. |
---|
| 184 | */ |
---|
| 185 | void convertPackedColour(VertexElementType srcType, VertexElementType destType); |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | /** Allocate elements to serve a holder of morph / pose target data |
---|
| 189 | for hardware morphing / pose blending. |
---|
| 190 | @remarks |
---|
| 191 | This method will allocate the given number of 3D texture coordinate |
---|
| 192 | sets for use as a morph target or target pose offset (3D position). |
---|
| 193 | These elements will be saved in hwAnimationDataList. |
---|
| 194 | It will also assume that the source of these new elements will be new |
---|
| 195 | buffers which are not bound at this time, so will start the sources to |
---|
| 196 | 1 higher than the current highest binding source. The caller is |
---|
| 197 | expected to bind these new buffers when appropriate. For morph animation |
---|
| 198 | the original position buffer will be the 'from' keyframe data, whilst |
---|
| 199 | for pose animation it will be the original vertex data. |
---|
| 200 | */ |
---|
| 201 | void allocateHardwareAnimationElements(ushort count); |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | }; |
---|
| 206 | |
---|
| 207 | /** Summary class collecting together index data source information. */ |
---|
| 208 | class _OgreExport IndexData |
---|
| 209 | { |
---|
| 210 | protected: |
---|
| 211 | /// Protected copy constructor, to prevent misuse |
---|
| 212 | IndexData(const IndexData& rhs); /* do nothing, should not use */ |
---|
| 213 | /// Protected operator=, to prevent misuse |
---|
| 214 | IndexData& operator=(const IndexData& rhs); /* do not use */ |
---|
| 215 | public: |
---|
| 216 | IndexData(); |
---|
| 217 | ~IndexData(); |
---|
| 218 | /// pointer to the HardwareIndexBuffer to use, must be specified if useIndexes = true |
---|
| 219 | HardwareIndexBufferSharedPtr indexBuffer; |
---|
| 220 | |
---|
| 221 | /// index in the buffer to start from for this operation |
---|
| 222 | size_t indexStart; |
---|
| 223 | |
---|
| 224 | /// The number of indexes to use from the buffer |
---|
| 225 | size_t indexCount; |
---|
| 226 | |
---|
| 227 | /** Clones this index data, potentially including replicating the index buffer. |
---|
| 228 | @remarks The caller is expected to delete the returned pointer when finished |
---|
| 229 | */ |
---|
| 230 | IndexData* clone(bool copyData = true) const; |
---|
| 231 | |
---|
| 232 | /** Re-order the indexes in this index data structure to be more |
---|
| 233 | vertex cache friendly; that is to re-use the same vertices as close |
---|
| 234 | together as possible. |
---|
| 235 | @remarks |
---|
| 236 | Can only be used for index data which consists of triangle lists. |
---|
| 237 | It would in fact be pointless to use it on triangle strips or fans |
---|
| 238 | in any case. |
---|
| 239 | */ |
---|
| 240 | void optimiseVertexCacheTriList(void); |
---|
| 241 | |
---|
| 242 | }; |
---|
| 243 | |
---|
| 244 | /** Vertex cache profiler. |
---|
| 245 | @remarks |
---|
| 246 | Utility class for evaluating the effectiveness of the use of the vertex |
---|
| 247 | cache by a given index buffer. |
---|
| 248 | */ |
---|
| 249 | class _OgreExport VertexCacheProfiler |
---|
| 250 | { |
---|
| 251 | public: |
---|
| 252 | enum CacheType { |
---|
| 253 | FIFO, LRU |
---|
| 254 | }; |
---|
| 255 | |
---|
| 256 | VertexCacheProfiler(unsigned int cachesize = 16, CacheType cachetype = FIFO ) |
---|
| 257 | : size ( cachesize ), type ( cachetype ), tail (0), buffersize (0), hit (0), miss (0) |
---|
| 258 | { |
---|
| 259 | cache = new uint32[size]; |
---|
| 260 | }; |
---|
| 261 | |
---|
| 262 | ~VertexCacheProfiler() |
---|
| 263 | { |
---|
| 264 | delete[] cache; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | void profile(const HardwareIndexBufferSharedPtr& indexBuffer); |
---|
| 268 | void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; }; |
---|
| 269 | void flush() { tail = 0; buffersize = 0; }; |
---|
| 270 | |
---|
| 271 | unsigned int getHits() { return hit; }; |
---|
| 272 | unsigned int getMisses() { return miss; }; |
---|
| 273 | unsigned int getSize() { return size; }; |
---|
| 274 | private: |
---|
| 275 | unsigned int size; |
---|
| 276 | uint32 *cache; |
---|
| 277 | CacheType type; |
---|
| 278 | |
---|
| 279 | unsigned int tail, buffersize; |
---|
| 280 | unsigned int hit, miss; |
---|
| 281 | |
---|
| 282 | bool inCache(unsigned int index); |
---|
| 283 | }; |
---|
| 284 | } |
---|
| 285 | #endif |
---|
| 286 | |
---|