source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreVertexIndexData.h @ 1812

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