/src/ogre/OgreMain/include/OgreSubEntity.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 __SubEntity_H__ |
29 | | #define __SubEntity_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | |
33 | | #include "OgreEntity.h" |
34 | | #include "OgreRenderable.h" |
35 | | #include "OgreResourceGroupManager.h" |
36 | | #include "OgreHeaderPrefix.h" |
37 | | |
38 | | namespace Ogre { |
39 | | |
40 | | /** \addtogroup Core |
41 | | * @{ |
42 | | */ |
43 | | /** \addtogroup Scene |
44 | | * @{ |
45 | | */ |
46 | | /** Utility class which defines the sub-parts of an Entity. |
47 | | |
48 | | Just as meshes are split into submeshes, an Entity is made up of |
49 | | potentially multiple SubMeshes. These are mainly here to provide the |
50 | | link between the Material which the SubEntity uses (which may be the |
51 | | default Material for the SubMesh or may have been changed for this |
52 | | object) and the SubMesh data. |
53 | | @par |
54 | | The SubEntity also allows the application some flexibility in the |
55 | | material properties for this section of a particular instance of this |
56 | | Mesh, e.g. tinting the windows on a car model. |
57 | | @par |
58 | | SubEntity instances are never created manually. They are created at |
59 | | the same time as their parent Entity by the SceneManager method |
60 | | createEntity. |
61 | | */ |
62 | | class _OgreExport SubEntity: public Renderable, public SubEntityAlloc |
63 | | { |
64 | | // Note no virtual functions for efficiency |
65 | | friend class Entity; |
66 | | friend class SceneManager; |
67 | | private: |
68 | | /** Private constructor - don't allow creation by anybody else. |
69 | | */ |
70 | | SubEntity(Entity* parent, SubMesh* subMeshBasis); |
71 | | ~SubEntity(); |
72 | | |
73 | | /// Pointer to parent. |
74 | | Entity* mParentEntity; |
75 | | |
76 | | /// Cached pointer to material. |
77 | | MaterialPtr mMaterialPtr; |
78 | | |
79 | | /// Pointer to the SubMesh defining geometry. |
80 | | SubMesh* mSubMesh; |
81 | | |
82 | | /// override the start index for the RenderOperation |
83 | | uint32 mIndexStart; |
84 | | /// override the end index for the RenderOperation |
85 | | uint32 mIndexEnd; |
86 | | |
87 | | /// Is this SubEntity visible? |
88 | | bool mVisible; |
89 | | |
90 | | /// The render queue to use when rendering this renderable |
91 | | uint8 mRenderQueueID; |
92 | | /// Flags whether the RenderQueue's default should be used. |
93 | | bool mRenderQueueIDSet; |
94 | | /// Flags whether the RenderQueue's default should be used. |
95 | | bool mRenderQueuePrioritySet; |
96 | | /// The render queue priority to use when rendering this renderable |
97 | | ushort mRenderQueuePriority; |
98 | | /// Blend buffer details for dedicated geometry |
99 | | std::unique_ptr<VertexData> mSkelAnimVertexData; |
100 | | /// Quick lookup of buffers |
101 | | Entity::TempBlendedBufferInfo mTempSkelAnimInfo; |
102 | | /// Temp buffer details for software Vertex anim geometry |
103 | | Entity::TempBlendedBufferInfo mTempVertexAnimInfo; |
104 | | /// Vertex data details for software Vertex anim of shared geometry |
105 | | std::unique_ptr<VertexData> mSoftwareVertexAnimVertexData; |
106 | | /// Vertex data details for hardware Vertex anim of shared geometry |
107 | | /// - separate since we need to s/w anim for shadows whilst still altering |
108 | | /// the vertex data for hardware morphing (pos2 binding) |
109 | | std::unique_ptr<VertexData> mHardwareVertexAnimVertexData; |
110 | | /// Cached distance to last camera for getSquaredViewDepth |
111 | | mutable Real mCachedCameraDist; |
112 | | /// Number of hardware blended poses supported by material |
113 | | ushort mHardwarePoseCount; |
114 | | /// Have we applied any vertex animation to geometry? |
115 | | bool mVertexAnimationAppliedThisFrame; |
116 | | /// The camera for which the cached distance is valid |
117 | | mutable const Camera *mCachedCamera; |
118 | | |
119 | | /** Internal method for preparing this Entity for use in animation. */ |
120 | | void prepareTempBlendBuffers(void); |
121 | | |
122 | | public: |
123 | | /** Gets the name of the Material in use by this instance. |
124 | | */ |
125 | | const String& getMaterialName() const; |
126 | | |
127 | | /** Sets the name of the Material to be used. |
128 | | |
129 | | By default a SubEntity uses the default Material that the SubMesh |
130 | | uses. This call can alter that so that the Material is different |
131 | | for this instance. |
132 | | */ |
133 | | void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ); |
134 | | |
135 | | /// @copydoc setMaterialName |
136 | | void setMaterial( const MaterialPtr& material ); |
137 | | |
138 | | /** Tells this SubEntity whether to be visible or not. */ |
139 | | void setVisible(bool visible); |
140 | | |
141 | | /** Returns whether or not this SubEntity is supposed to be visible. */ |
142 | 0 | bool isVisible(void) const { return mVisible; } |
143 | | |
144 | | /** Sets the render queue group this SubEntity will be rendered through. |
145 | | |
146 | | Render queues are grouped to allow you to more tightly control the ordering |
147 | | of rendered objects. If you do not call this method, the SubEntity will use |
148 | | either the Entity's queue or it will use the default |
149 | | (RenderQueue::getDefaultQueueGroup). |
150 | | @par |
151 | | See Entity::setRenderQueueGroup for more details. |
152 | | @param queueID Enumerated value of the queue group to use. See the |
153 | | enum RenderQueueGroupID for what kind of values can be used here. |
154 | | */ |
155 | | void setRenderQueueGroup(uint8 queueID); |
156 | | |
157 | | /** Sets the render queue group and group priority this SubEntity will be rendered through. |
158 | | |
159 | | Render queues are grouped to allow you to more tightly control the ordering |
160 | | of rendered objects. Within a single render group there another type of grouping |
161 | | called priority which allows further control. If you do not call this method, |
162 | | all Entity objects default to the default queue and priority |
163 | | (RenderQueue::getDefaultQueueGroup, RenderQueue::getDefaultRenderablePriority). |
164 | | @par |
165 | | See Entity::setRenderQueueGroupAndPriority for more details. |
166 | | @param queueID Enumerated value of the queue group to use. See the |
167 | | enum RenderQueueGroupID for what kind of values can be used here. |
168 | | @param priority The priority within a group to use. |
169 | | */ |
170 | | void setRenderQueueGroupAndPriority(uint8 queueID, ushort priority); |
171 | | |
172 | | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ |
173 | 0 | uint8 getRenderQueueGroup(void) const { return mRenderQueueID; } |
174 | | |
175 | | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ |
176 | 0 | ushort getRenderQueuePriority(void) const { return mRenderQueuePriority; } |
177 | | |
178 | | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ |
179 | 0 | bool isRenderQueueGroupSet(void) const { return mRenderQueueIDSet; } |
180 | | |
181 | | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */ |
182 | 0 | bool isRenderQueuePrioritySet(void) const { return mRenderQueuePrioritySet; } |
183 | | |
184 | | /** Accessor method to read mesh data. |
185 | | */ |
186 | 0 | SubMesh* getSubMesh(void) const { return mSubMesh; } |
187 | | |
188 | | /** Accessor to get parent Entity */ |
189 | 0 | Entity* getParent(void) const { return mParentEntity; } |
190 | | |
191 | | |
192 | 0 | const MaterialPtr& getMaterial(void) const override { return mMaterialPtr; } |
193 | | void getRenderOperation(RenderOperation& op) override; |
194 | | |
195 | | /// @deprecated api about to be removed |
196 | | OGRE_DEPRECATED void setIndexDataStartIndex(uint32 start_index); |
197 | | |
198 | | /// @deprecated api about to be removed |
199 | 0 | OGRE_DEPRECATED uint32 getIndexDataStartIndex() const { return mIndexStart; } |
200 | | |
201 | | /// @deprecated api about to be removed |
202 | | OGRE_DEPRECATED void setIndexDataEndIndex(uint32 end_index); |
203 | | |
204 | | /// @deprecated api about to be removed |
205 | 0 | OGRE_DEPRECATED uint32 getIndexDataEndIndex() const { return mIndexEnd; } |
206 | | |
207 | | /** Reset the custom start/end index to the default values. |
208 | | */ |
209 | | void resetIndexDataStartEndIndex(); |
210 | | |
211 | | void getWorldTransforms(Matrix4* xform) const override; |
212 | | unsigned short getNumWorldTransforms(void) const override; |
213 | | Real getSquaredViewDepth(const Camera* cam) const override; |
214 | | const LightList& getLights(void) const override; |
215 | | bool getCastsShadows(void) const override; |
216 | | /** Advanced method to get the temporarily blended vertex information |
217 | | for entities which are software skinned. |
218 | | |
219 | | Internal engine will eliminate software animation if possible, this |
220 | | information is unreliable unless added request for software animation |
221 | | via Entity::addSoftwareAnimationRequest. |
222 | | @note |
223 | | The positions/normals of the returned vertex data is in object space. |
224 | | */ |
225 | | VertexData* _getSkelAnimVertexData(void); |
226 | | /** Advanced method to get the temporarily blended software morph vertex information |
227 | | |
228 | | Internal engine will eliminate software animation if possible, this |
229 | | information is unreliable unless added request for software animation |
230 | | via Entity::addSoftwareAnimationRequest. |
231 | | @note |
232 | | The positions/normals of the returned vertex data is in object space. |
233 | | */ |
234 | | VertexData* _getSoftwareVertexAnimVertexData(void); |
235 | | /** Advanced method to get the hardware morph vertex information |
236 | | @note |
237 | | The positions/normals of the returned vertex data is in object space. |
238 | | */ |
239 | | VertexData* _getHardwareVertexAnimVertexData(void); |
240 | | /// Retrieve the VertexData which should be used for GPU binding |
241 | | VertexData* getVertexDataForBinding(void); |
242 | | |
243 | | /** Mark all vertex data as so far unanimated. |
244 | | */ |
245 | | void _markBuffersUnusedForAnimation(void); |
246 | | /** Mark all vertex data as animated. |
247 | | */ |
248 | | void _markBuffersUsedForAnimation(void); |
249 | | /** Are buffers already marked as vertex animated? */ |
250 | 0 | bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } |
251 | | /** Internal method to copy original vertex data to the morph structures |
252 | | should there be no active animation in use. |
253 | | */ |
254 | | void _restoreBuffersForUnusedAnimation(bool hardwareAnimation); |
255 | | |
256 | | /** Overridden from Renderable to provide some custom behaviour. */ |
257 | | void _updateCustomGpuParameter( |
258 | | const GpuProgramParameters::AutoConstantEntry& constantEntry, |
259 | | GpuProgramParameters* params) const override; |
260 | | |
261 | | /** Invalidate the camera distance cache */ |
262 | | void _invalidateCameraCache () |
263 | 0 | { mCachedCamera = 0; } |
264 | | }; |
265 | | /** @} */ |
266 | | /** @} */ |
267 | | |
268 | | } |
269 | | |
270 | | #include "OgreHeaderSuffix.h" |
271 | | |
272 | | #endif |