[1] | 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-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __SubEntity_H__ |
---|
| 30 | #define __SubEntity_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | |
---|
| 34 | #include "OgreString.h" |
---|
| 35 | #include "OgreRenderable.h" |
---|
| 36 | #include "OgreHardwareBufferManager.h" |
---|
| 37 | |
---|
| 38 | namespace Ogre { |
---|
| 39 | |
---|
| 40 | /** Utility class which defines the sub-parts of an Entity. |
---|
| 41 | @remarks |
---|
| 42 | Just as meshes are split into submeshes, an Entity is made up of |
---|
| 43 | potentially multiple SubMeshes. These are mainly here to provide the |
---|
| 44 | link between the Material which the SubEntity uses (which may be the |
---|
| 45 | default Material for the SubMesh or may have been changed for this |
---|
| 46 | object) and the SubMesh data. |
---|
| 47 | @par |
---|
| 48 | The SubEntity also allows the application some flexibility in the |
---|
| 49 | material properties for this section of a particular instance of this |
---|
| 50 | Mesh, e.g. tinting the windows on a car model. |
---|
| 51 | @par |
---|
| 52 | SubEntity instances are never created manually. They are created at |
---|
| 53 | the same time as their parent Entity by the SceneManager method |
---|
| 54 | createEntity. |
---|
| 55 | */ |
---|
| 56 | class _OgreExport SubEntity: public Renderable |
---|
| 57 | { |
---|
| 58 | // Note no virtual functions for efficiency |
---|
| 59 | friend class Entity; |
---|
| 60 | friend class SceneManager; |
---|
| 61 | protected: |
---|
| 62 | /** Private constructor - don't allow creation by anybody else. |
---|
| 63 | */ |
---|
| 64 | SubEntity(Entity* parent, SubMesh* subMeshBasis); |
---|
| 65 | |
---|
| 66 | /** Private destructor. |
---|
| 67 | */ |
---|
| 68 | virtual ~SubEntity(); |
---|
| 69 | |
---|
| 70 | /// Pointer to parent. |
---|
| 71 | Entity* mParentEntity; |
---|
| 72 | |
---|
| 73 | /// Name of Material in use by this SubEntity. |
---|
| 74 | String mMaterialName; |
---|
| 75 | |
---|
| 76 | /// Cached pointer to material. |
---|
| 77 | MaterialPtr mpMaterial; |
---|
| 78 | |
---|
| 79 | // Pointer to the SubMesh defining geometry. |
---|
| 80 | SubMesh* mSubMesh; |
---|
| 81 | |
---|
| 82 | /// Is this SubEntity visible? |
---|
| 83 | bool mVisible; |
---|
| 84 | |
---|
| 85 | /// The LOD number of the material to use, calculated by Entity::_notifyCurrentCamera |
---|
| 86 | unsigned short mMaterialLodIndex; |
---|
| 87 | |
---|
| 88 | /// blend buffer details for dedicated geometry |
---|
| 89 | VertexData* mSkelAnimVertexData; |
---|
| 90 | /// Quick lookup of buffers |
---|
| 91 | TempBlendedBufferInfo mTempSkelAnimInfo; |
---|
| 92 | /// Temp buffer details for software Vertex anim geometry |
---|
| 93 | TempBlendedBufferInfo mTempVertexAnimInfo; |
---|
| 94 | /// Vertex data details for software Vertex anim of shared geometry |
---|
| 95 | VertexData* mSoftwareVertexAnimVertexData; |
---|
| 96 | /// Vertex data details for hardware Vertex anim of shared geometry |
---|
| 97 | /// - separate since we need to s/w anim for shadows whilst still altering |
---|
| 98 | /// the vertex data for hardware morphing (pos2 binding) |
---|
| 99 | VertexData* mHardwareVertexAnimVertexData; |
---|
| 100 | /// Have we applied any vertex animation to geometry? |
---|
| 101 | bool mVertexAnimationAppliedThisFrame; |
---|
| 102 | /// Number of hardware blended poses supported by material |
---|
| 103 | ushort mHardwarePoseCount; |
---|
| 104 | /// Cached distance to last camera for getSquaredViewDepth |
---|
| 105 | mutable Real mCachedCameraDist; |
---|
| 106 | /// The camera for which the cached distance is valid |
---|
| 107 | mutable const Camera *mCachedCamera; |
---|
| 108 | |
---|
| 109 | /** Internal method for preparing this Entity for use in animation. */ |
---|
| 110 | void prepareTempBlendBuffers(void); |
---|
| 111 | |
---|
| 112 | public: |
---|
| 113 | /** Gets the name of the Material in use by this instance. |
---|
| 114 | */ |
---|
| 115 | const String& getMaterialName() const; |
---|
| 116 | |
---|
| 117 | /** Sets the name of the Material to be used. |
---|
| 118 | @remarks |
---|
| 119 | By default a SubEntity uses the default Material that the SubMesh |
---|
| 120 | uses. This call can alter that so that the Material is different |
---|
| 121 | for this instance. |
---|
| 122 | */ |
---|
| 123 | void setMaterialName( const String& name ); |
---|
| 124 | |
---|
| 125 | /** Tells this SubEntity whether to be visible or not. */ |
---|
| 126 | virtual void setVisible(bool visible); |
---|
| 127 | |
---|
| 128 | /** Returns whether or not this SubEntity is supposed to be visible. */ |
---|
| 129 | virtual bool isVisible(void) const; |
---|
| 130 | |
---|
| 131 | /** Accessor method to read mesh data. |
---|
| 132 | */ |
---|
| 133 | SubMesh* getSubMesh(void); |
---|
| 134 | |
---|
| 135 | /** Accessor to get parent Entity */ |
---|
| 136 | Entity* getParent(void) const { return mParentEntity; } |
---|
| 137 | |
---|
| 138 | /** Overridden - see Renderable. |
---|
| 139 | */ |
---|
| 140 | const MaterialPtr& getMaterial(void) const; |
---|
| 141 | |
---|
| 142 | /** Overridden - see Renderable. |
---|
| 143 | */ |
---|
| 144 | Technique* getTechnique(void) const; |
---|
| 145 | |
---|
| 146 | /** Overridden - see Renderable. |
---|
| 147 | */ |
---|
| 148 | void getRenderOperation(RenderOperation& op); |
---|
| 149 | |
---|
| 150 | /** Overridden - see Renderable. |
---|
| 151 | */ |
---|
| 152 | void getWorldTransforms(Matrix4* xform) const; |
---|
| 153 | /** @copydoc Renderable::getWorldOrientation */ |
---|
| 154 | const Quaternion& getWorldOrientation(void) const; |
---|
| 155 | /** @copydoc Renderable::getWorldPosition */ |
---|
| 156 | const Vector3& getWorldPosition(void) const; |
---|
| 157 | /** Overridden - see Renderable. |
---|
| 158 | */ |
---|
| 159 | bool getNormaliseNormals(void) const; |
---|
| 160 | /** Overridden - see Renderable. |
---|
| 161 | */ |
---|
| 162 | unsigned short getNumWorldTransforms(void) const; |
---|
| 163 | /** Overridden, see Renderable */ |
---|
| 164 | Real getSquaredViewDepth(const Camera* cam) const; |
---|
| 165 | /** @copydoc Renderable::getLights */ |
---|
| 166 | const LightList& getLights(void) const; |
---|
| 167 | /** @copydoc Renderable::getCastsShadows */ |
---|
| 168 | bool getCastsShadows(void) const; |
---|
| 169 | /** Advanced method to get the temporarily blended vertex information |
---|
| 170 | for entities which are software skinned. |
---|
| 171 | @remarks |
---|
| 172 | Internal engine will eliminate software animation if possible, this |
---|
| 173 | information is unreliable unless added request for software animation |
---|
| 174 | via Entity::addSoftwareAnimationRequest. |
---|
| 175 | @note |
---|
| 176 | The positions/normals of the returned vertex data is in object space. |
---|
| 177 | */ |
---|
| 178 | VertexData* _getSkelAnimVertexData(void); |
---|
| 179 | /** Advanced method to get the temporarily blended software morph vertex information |
---|
| 180 | @remarks |
---|
| 181 | Internal engine will eliminate software animation if possible, this |
---|
| 182 | information is unreliable unless added request for software animation |
---|
| 183 | via Entity::addSoftwareAnimationRequest. |
---|
| 184 | @note |
---|
| 185 | The positions/normals of the returned vertex data is in object space. |
---|
| 186 | */ |
---|
| 187 | VertexData* _getSoftwareVertexAnimVertexData(void); |
---|
| 188 | /** Advanced method to get the hardware morph vertex information |
---|
| 189 | @note |
---|
| 190 | The positions/normals of the returned vertex data is in object space. |
---|
| 191 | */ |
---|
| 192 | VertexData* _getHardwareVertexAnimVertexData(void); |
---|
| 193 | /** Advanced method to get the temp buffer information for software |
---|
| 194 | skeletal animation. |
---|
| 195 | */ |
---|
| 196 | TempBlendedBufferInfo* _getSkelAnimTempBufferInfo(void); |
---|
| 197 | /** Advanced method to get the temp buffer information for software |
---|
| 198 | morph animation. |
---|
| 199 | */ |
---|
| 200 | TempBlendedBufferInfo* _getVertexAnimTempBufferInfo(void); |
---|
| 201 | /// Retrieve the VertexData which should be used for GPU binding |
---|
| 202 | VertexData* getVertexDataForBinding(void); |
---|
| 203 | |
---|
| 204 | /** Mark all vertex data as so far unanimated. |
---|
| 205 | */ |
---|
| 206 | void _markBuffersUnusedForAnimation(void); |
---|
| 207 | /** Mark all vertex data as animated. |
---|
| 208 | */ |
---|
| 209 | void _markBuffersUsedForAnimation(void); |
---|
| 210 | /** Are buffers already marked as vertex animated? */ |
---|
| 211 | bool _getBuffersMarkedForAnimation(void) const { return mVertexAnimationAppliedThisFrame; } |
---|
| 212 | /** Internal method to copy original vertex data to the morph structures |
---|
| 213 | should there be no active animation in use. |
---|
| 214 | */ |
---|
| 215 | void _restoreBuffersForUnusedAnimation(bool hardwareAnimation); |
---|
| 216 | |
---|
| 217 | /** Overridden from Renderble to provide some custom behaviour. */ |
---|
| 218 | void _updateCustomGpuParameter( |
---|
| 219 | const GpuProgramParameters::AutoConstantEntry& constantEntry, |
---|
| 220 | GpuProgramParameters* params) const; |
---|
| 221 | |
---|
| 222 | /** Invalidate the camera distance cache */ |
---|
| 223 | void _invalidateCameraCache () |
---|
| 224 | { mCachedCamera = 0; } |
---|
| 225 | }; |
---|
| 226 | |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | |
---|
| 230 | #endif |
---|