| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org/
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #ifndef __VertexIndexData_H__
- #define __VertexIndexData_H__
- #include "CmPrerequisites.h"
- #include "CmHardwareVertexBuffer.h"
- #include "CmHardwareIndexBuffer.h"
- namespace CamelotEngine {
- /** \addtogroup Core
- * @{
- */
- /** \addtogroup RenderSystem
- * @{
- */
- /// Define a list of usage flags
- typedef vector<HardwareBuffer::Usage>::type BufferUsageList;
- /** Summary class collecting together vertex source information. */
- class CM_EXPORT VertexData
- {
- private:
- /// Protected copy constructor, to prevent misuse
- VertexData(const VertexData& rhs); /* do nothing, should not use */
- /// Protected operator=, to prevent misuse
- VertexData& operator=(const VertexData& rhs); /* do not use */
- HardwareBufferManagerBase* mMgr;
- public:
- /** Constructor.
- @note
- This constructor creates the VertexDeclaration and VertexBufferBinding
- automatically, and arranges for their deletion afterwards.
- @param mgr Optional HardwareBufferManager from which to create resources
- */
- VertexData(HardwareBufferManagerBase* mgr = 0);
- /** Constructor.
- @note
- This constructor receives the VertexDeclaration and VertexBufferBinding
- from the caller, and as such does not arrange for their deletion afterwards,
- the caller remains responsible for that.
- @param dcl The VertexDeclaration to use
- @param bind The VertexBufferBinding to use
- */
- VertexData(VertexDeclarationPtr dcl, VertexBufferBinding* bind);
- ~VertexData();
- /** Declaration of the vertex to be used in this operation.
- @remarks Note that this is created for you on construction.
- */
- VertexDeclarationPtr vertexDeclaration;
- /** The vertex buffer bindings to be used.
- @remarks Note that this is created for you on construction.
- */
- VertexBufferBinding* vertexBufferBinding;
- /// Whether this class should delete the declaration and binding
- bool mDeleteDclBinding;
- /// The base vertex index to start from
- size_t vertexStart;
- /// The number of vertices used in this operation
- size_t vertexCount;
-
- /** Clones this vertex data, potentially including replicating any vertex buffers.
- @param copyData Whether to create new vertex buffers too or just reference the existing ones
- @param mgr If supplied, the buffer manager through which copies should be made
- @remarks The caller is expected to delete the returned pointer when ready
- */
- VertexData* clone(bool copyData = true, HardwareBufferManagerBase* mgr = 0) const;
- /** Modifies the vertex data to be suitable for use for rendering shadow geometry.
- @remarks
- Preparing vertex data to generate a shadow volume involves firstly ensuring that the
- vertex buffer containing the positions is a standalone vertex buffer,
- with no other components in it. This method will therefore break apart any existing
- vertex buffers if position is sharing a vertex buffer.
- Secondly, it will double the size of this vertex buffer so that there are 2 copies of
- the position data for the mesh. The first half is used for the original, and the second
- half is used for the 'extruded' version. The vertex count used to render will remain
- the same though, so as not to add any overhead to regular rendering of the object.
- Both copies of the position are required in one buffer because shadow volumes stretch
- from the original mesh to the extruded version.
- @par
- It's important to appreciate that this method can fundamentally change the structure of your
- vertex buffers, although in reality they will be new buffers. As it happens, if other
- objects are using the original buffers then they will be unaffected because the reference
- counting will keep them intact. However, if you have made any assumptions about the
- structure of the vertex data in the buffers of this object, you may have to rethink them.
- */
- void prepareForShadowVolume(void);
- /** Additional shadow volume vertex buffer storage.
- @remarks
- This additional buffer is only used where we have prepared this VertexData for
- use in shadow volume construction, and where the current render system supports
- vertex programs. This buffer contains the 'w' vertex position component which will
- be used by that program to differentiate between extruded and non-extruded vertices.
- This 'w' component cannot be included in the original position buffer because
- DirectX does not allow 4-component positions in the fixed-function pipeline, and the original
- position buffer must still be usable for fixed-function rendering.
- @par
- Note that we don't store any vertex declaration or vertex buffer binding here because this
- can be reused in the shadow algorithm.
- */
- HardwareVertexBufferPtr hardwareShadowVolWBuffer;
- /** Reorganises the data in the vertex buffers according to the
- new vertex declaration passed in. Note that new vertex buffers
- are created and written to, so if the buffers being referenced
- by this vertex data object are also used by others, then the
- original buffers will not be damaged by this operation.
- Once this operation has completed, the new declaration
- passed in will overwrite the current one.
- @param newDeclaration The vertex declaration which will be used
- for the reorganised buffer state. Note that the new declaration
- must not include any elements which do not already exist in the
- current declaration; you can drop elements by
- excluding them from the declaration if you wish, however.
- @param bufferUsages Vector of usage flags which indicate the usage options
- for each new vertex buffer created. The indexes of the entries must correspond
- to the buffer binding values referenced in the declaration.
- @param mgr Optional pointer to the manager to use to create new declarations
- and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
- */
- void reorganiseBuffers(VertexDeclarationPtr newDeclaration, const BufferUsageList& bufferUsage,
- HardwareBufferManagerBase* mgr = 0);
- /** Reorganises the data in the vertex buffers according to the
- new vertex declaration passed in. Note that new vertex buffers
- are created and written to, so if the buffers being referenced
- by this vertex data object are also used by others, then the
- original buffers will not be damaged by this operation.
- Once this operation has completed, the new declaration
- passed in will overwrite the current one.
- This version of the method derives the buffer usages from the existing
- buffers, by using the 'most flexible' usage from the equivalent sources.
- @param newDeclaration The vertex declaration which will be used
- for the reorganised buffer state. Note that the new delcaration
- must not include any elements which do not already exist in the
- current declaration; you can drop elements by
- excluding them from the declaration if you wish, however.
- @param mgr Optional pointer to the manager to use to create new declarations
- and buffers etc. If not supplied, the HardwareBufferManager singleton will be used
- */
- void reorganiseBuffers(VertexDeclarationPtr newDeclaration, HardwareBufferManagerBase* mgr = 0);
- /** Remove any gaps in the vertex buffer bindings.
- @remarks
- This is useful if you've removed elements and buffers from this vertex
- data and want to remove any gaps in the vertex buffer bindings. This
- method is mainly useful when reorganising vertex data manually.
- @note
- This will cause binding index of the elements in the vertex declaration
- to be altered to new binding index.
- */
- void closeGapsInBindings(void);
- /** Remove all vertex buffers that never used by the vertex declaration.
- @remarks
- This is useful if you've removed elements from the vertex declaration
- and want to unreference buffers that never used any more. This method
- is mainly useful when reorganising vertex data manually.
- @note
- This also remove any gaps in the vertex buffer bindings.
- */
- void removeUnusedBuffers(void);
- /** Convert all packed colour values (VET_COLOUR_*) in buffers used to
- another type.
- @param srcType The source colour type to assume if the ambiguous VET_COLOUR
- is encountered.
- @param destType The destination colour type, must be VET_COLOUR_ABGR or
- VET_COLOUR_ARGB.
- */
- void convertPackedColour(VertexElementType srcType, VertexElementType destType);
- };
- /** Summary class collecting together index data source information. */
- class CM_EXPORT IndexData
- {
- protected:
- /// Protected copy constructor, to prevent misuse
- IndexData(const IndexData& rhs); /* do nothing, should not use */
- /// Protected operator=, to prevent misuse
- IndexData& operator=(const IndexData& rhs); /* do not use */
- public:
- IndexData();
- ~IndexData();
- /// pointer to the HardwareIndexBuffer to use, must be specified if useIndexes = true
- HardwareIndexBufferPtr indexBuffer;
- /// index in the buffer to start from for this operation
- size_t indexStart;
- /// The number of indexes to use from the buffer
- size_t indexCount;
- /** Clones this index data, potentially including replicating the index buffer.
- @param copyData Whether to create new buffers too or just reference the existing ones
- @param mgr If supplied, the buffer manager through which copies should be made
- @remarks The caller is expected to delete the returned pointer when finished
- */
- IndexData* clone(bool copyData = true, HardwareBufferManagerBase* mgr = 0) const;
- /** Re-order the indexes in this index data structure to be more
- vertex cache friendly; that is to re-use the same vertices as close
- together as possible.
- @remarks
- Can only be used for index data which consists of triangle lists.
- It would in fact be pointless to use it on triangle strips or fans
- in any case.
- */
- void optimiseVertexCacheTriList(void);
-
- };
- /** Vertex cache profiler.
- @remarks
- Utility class for evaluating the effectiveness of the use of the vertex
- cache by a given index buffer.
- */
- class CM_EXPORT VertexCacheProfiler
- {
- public:
- enum CacheType {
- FIFO, LRU
- };
- VertexCacheProfiler(unsigned int cachesize = 16, CacheType cachetype = FIFO )
- : size ( cachesize ), type ( cachetype ), tail (0), buffersize (0), hit (0), miss (0)
- {
- cache = (UINT32*)malloc(sizeof(UINT32) * size);
- }
- ~VertexCacheProfiler()
- {
- free(cache);
- }
- void profile(const HardwareIndexBufferPtr& indexBuffer);
- void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; }
- void flush() { tail = 0; buffersize = 0; }
- unsigned int getHits() { return hit; }
- unsigned int getMisses() { return miss; }
- unsigned int getSize() { return size; }
- private:
- unsigned int size;
- UINT32 *cache;
- CacheType type;
- unsigned int tail, buffersize;
- unsigned int hit, miss;
- bool inCache(unsigned int index);
- };
- /** @} */
- /** @} */
- }
- #endif
|