/src/ogre/OgreMain/include/OgreInstanceBatchHW_VTF.h
Line | Count | Source (jump to first uncovered line) |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __InstanceBatchHW_VTF_H__ |
29 | | #define __InstanceBatchHW_VTF_H__ |
30 | | |
31 | | #include "OgreInstanceBatchVTF.h" |
32 | | |
33 | | namespace Ogre |
34 | | { |
35 | | /** \addtogroup Core |
36 | | * @{ |
37 | | */ |
38 | | /** \addtogroup Scene |
39 | | * @{ |
40 | | */ |
41 | | |
42 | | /** Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) and |
43 | | hardware instancing. |
44 | | @see BaseInstanceBatchVTF and @see InstanceBatchHW |
45 | | |
46 | | The advantage over TextureVTF technique, is that this implements a basic culling algorithm |
47 | | to avoid useless processing in vertex shader and uses a lot less VRAM and memory bandwidth |
48 | | |
49 | | Basically it has the benefits of both TextureVTF (skeleton animations) and HWInstancingBasic |
50 | | (lower memory consumption and basic culling) techniques |
51 | | |
52 | | |
53 | | Design discussion webpage: http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59902 |
54 | | @author |
55 | | Matias N. Goldberg ("dark_sylinc") |
56 | | */ |
57 | | class _OgreExport InstanceBatchHW_VTF : public BaseInstanceBatchVTF |
58 | | { |
59 | | protected: |
60 | | bool mKeepStatic; |
61 | | |
62 | | //Pointer to the buffer containing the per instance vertex data |
63 | | HardwareVertexBufferSharedPtr mInstanceVertexBuffer; |
64 | | |
65 | | void setupVertices( const SubMesh* baseSubMesh ) override; |
66 | | void setupIndices( const SubMesh* baseSubMesh ) override; |
67 | | |
68 | | /** Creates 2 TEXCOORD semantics that will be used to sample the vertex texture */ |
69 | | void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData, |
70 | | const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec& hwBoneWgt ) override; |
71 | | |
72 | | /** updates the vertex buffer containing the per instance data |
73 | | @param[in] isFirstTime Tells if this is the first time the buffer is being updated |
74 | | @param[in] currentCamera The camera being used for render (valid when using bone matrix lookup) |
75 | | @return The number of instances to be rendered |
76 | | */ |
77 | | virtual size_t updateInstanceDataBuffer(bool isFirstTime, Camera* currentCamera); |
78 | | |
79 | | |
80 | | bool checkSubMeshCompatibility( const SubMesh* baseSubMesh ) override; |
81 | | |
82 | | /** Keeps filling the VTF with world matrix data. Overloaded to avoid culled objects |
83 | | and update visible instances' animation |
84 | | */ |
85 | | size_t updateVertexTexture( Camera *currentCamera ); |
86 | | |
87 | 0 | bool matricesTogetherPerRow() const override { return true; } |
88 | | public: |
89 | | InstanceBatchHW_VTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material, |
90 | | size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap, |
91 | | const String &batchName ); |
92 | | virtual ~InstanceBatchHW_VTF(); |
93 | | /** @see InstanceBatch::calculateMaxNumInstances */ |
94 | | size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const override; |
95 | | |
96 | | /** @copydoc InstanceBatchHW::_boundsDirty */ |
97 | | void _boundsDirty(void) override; |
98 | | |
99 | | /** @copydoc InstanceBatchHW::setStaticAndUpdate */ |
100 | | void setStaticAndUpdate( bool bStatic ) override; |
101 | | |
102 | 0 | bool isStatic() const override { return mKeepStatic; } |
103 | | |
104 | | /** Overloaded to visibility on a per unit basis and finally updated the vertex texture */ |
105 | | void _updateRenderQueue( RenderQueue* queue ) override; |
106 | | }; |
107 | | |
108 | | } |
109 | | |
110 | | #endif |