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