00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2006 Torus Knot Software Ltd 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 00024 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 00030 #ifndef __OgreManualObject_H__ 00031 #define __OgreManualObject_H__ 00032 00033 #include "OgrePrerequisites.h" 00034 #include "OgreMovableObject.h" 00035 #include "OgreRenderable.h" 00036 #include "OgreResourceGroupManager.h" 00037 00038 00039 namespace Ogre 00040 { 00101 class _OgreExport ManualObject : public MovableObject 00102 { 00103 public: 00104 ManualObject(const String& name); 00105 virtual ~ManualObject(); 00106 00107 //pre-declare ManualObjectSection 00108 class ManualObjectSection; 00109 00119 virtual void clear(void); 00120 00128 virtual void estimateVertexCount(size_t vcount); 00129 00137 virtual void estimateIndexCount(size_t icount); 00138 00148 virtual void begin(const String& materialName, 00149 RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST); 00150 00154 virtual void setDynamic(bool dyn) { mDynamic = dyn; } 00156 virtual bool getDynamic() const { return mDynamic; } 00157 00169 virtual void beginUpdate(size_t sectionIndex); 00177 virtual void position(const Vector3& pos); 00179 virtual void position(Real x, Real y, Real z); 00180 00186 virtual void normal(const Vector3& norm); 00188 virtual void normal(Real x, Real y, Real z); 00189 00198 virtual void textureCoord(Real u); 00200 virtual void textureCoord(Real u, Real v); 00202 virtual void textureCoord(Real u, Real v, Real w); 00204 virtual void textureCoord(Real x, Real y, Real z, Real w); 00206 virtual void textureCoord(const Vector2& uv); 00208 virtual void textureCoord(const Vector3& uvw); 00210 virtual void textureCoord(const Vector4& xyzw); 00211 00214 virtual void colour(const ColourValue& col); 00218 virtual void colour(Real r, Real g, Real b, Real a = 1.0f); 00219 00231 virtual void index(uint32 idx); 00240 virtual void triangle(uint32 i1, uint32 i2, uint32 i3); 00249 virtual void quad(uint32 i1, uint32 i2, uint32 i3, uint32 i4); 00250 00255 virtual ManualObjectSection* end(void); 00256 00266 virtual void setMaterialName(size_t subindex, const String& name); 00267 00279 virtual MeshPtr convertToMesh(const String& meshName, 00280 const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 00281 00291 void setUseIdentityProjection(bool useIdentityProjection); 00292 00302 bool getUseIdentityProjection(void) const { return mUseIdentityProjection; } 00303 00313 void setUseIdentityView(bool useIdentityView); 00314 00324 bool getUseIdentityView(void) const { return mUseIdentityView; } 00325 00333 void setBoundingBox(const AxisAlignedBox& box) { mAABB = box; } 00334 00337 ManualObjectSection* getSection(unsigned int index) const; 00338 00341 unsigned int getNumSections(void) const; 00351 void setKeepDeclarationOrder(bool keepOrder) { mKeepDeclarationOrder = keepOrder; } 00352 00357 bool getKeepDeclarationOrder() const { return mKeepDeclarationOrder; } 00358 // MovableObject overrides 00359 00361 const String& getMovableType(void) const; 00363 const AxisAlignedBox& getBoundingBox(void) const; 00365 Real getBoundingRadius(void) const; 00367 void _updateRenderQueue(RenderQueue* queue); 00369 EdgeData* getEdgeList(void); 00371 bool hasEdgeList(void); 00373 ShadowRenderableListIterator getShadowVolumeRenderableIterator( 00374 ShadowTechnique shadowTechnique, const Light* light, 00375 HardwareIndexBufferSharedPtr* indexBuffer, 00376 bool extrudeVertices, Real extrusionDist, unsigned long flags = 0); 00377 00378 00380 class _OgreExport ManualObjectSection : public Renderable, public MovableAlloc 00381 { 00382 protected: 00383 ManualObject* mParent; 00384 String mMaterialName; 00385 mutable MaterialPtr mMaterial; 00386 RenderOperation mRenderOperation; 00387 bool m32BitIndices; 00388 00389 00390 public: 00391 ManualObjectSection(ManualObject* parent, const String& materialName, 00392 RenderOperation::OperationType opType); 00393 virtual ~ManualObjectSection(); 00394 00396 RenderOperation* getRenderOperation(void); 00398 const String& getMaterialName(void) const { return mMaterialName; } 00400 void setMaterialName(const String& name); 00402 void set32BitIndices(bool n32) { m32BitIndices = n32; } 00404 bool get32BitIndices() const { return m32BitIndices; } 00405 00406 // Renderable overrides 00408 const MaterialPtr& getMaterial(void) const; 00410 void getRenderOperation(RenderOperation& op); 00412 void getWorldTransforms(Matrix4* xform) const; 00414 Real getSquaredViewDepth(const Ogre::Camera *) const; 00416 const LightList &getLights(void) const; 00417 00418 00419 00420 }; 00422 class _OgreExport ManualObjectSectionShadowRenderable : public ShadowRenderable 00423 { 00424 protected: 00425 ManualObject* mParent; 00426 // Shared link to position buffer 00427 HardwareVertexBufferSharedPtr mPositionBuffer; 00428 // Shared link to w-coord buffer (optional) 00429 HardwareVertexBufferSharedPtr mWBuffer; 00430 00431 public: 00432 ManualObjectSectionShadowRenderable(ManualObject* parent, 00433 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData, 00434 bool createSeparateLightCap, bool isLightCap = false); 00435 ~ManualObjectSectionShadowRenderable(); 00437 void getWorldTransforms(Matrix4* xform) const; 00438 HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; } 00439 HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; } 00440 00441 }; 00442 00443 typedef std::vector<ManualObjectSection*> SectionList; 00444 00446 void visitRenderables(Renderable::Visitor* visitor, 00447 bool debugRenderables = false); 00448 00449 00450 protected: 00452 bool mDynamic; 00454 SectionList mSectionList; 00456 ManualObjectSection* mCurrentSection; 00458 bool mCurrentUpdating; 00460 struct TempVertex 00461 { 00462 Vector3 position; 00463 Vector3 normal; 00464 Vector4 texCoord[OGRE_MAX_TEXTURE_COORD_SETS]; 00465 ushort texCoordDims[OGRE_MAX_TEXTURE_COORD_SETS]; 00466 ColourValue colour; 00467 }; 00469 TempVertex mTempVertex; 00471 bool mFirstVertex; 00473 bool mTempVertexPending; 00475 char* mTempVertexBuffer; 00477 size_t mTempVertexSize; 00479 uint32* mTempIndexBuffer; 00481 size_t mTempIndexSize; 00483 size_t mDeclSize; 00485 size_t mEstVertexCount; 00487 size_t mEstIndexCount; 00489 ushort mTexCoordIndex; 00491 AxisAlignedBox mAABB; 00493 Real mRadius; 00495 bool mAnyIndexed; 00497 EdgeData* mEdgeList; 00499 ShadowRenderableList mShadowRenderables; 00501 bool mUseIdentityProjection; 00503 bool mUseIdentityView; 00505 bool mKeepDeclarationOrder; 00506 00507 00509 virtual void resetTempAreas(void); 00511 virtual void resizeTempVertexBufferIfNeeded(size_t numVerts); 00513 virtual void resizeTempIndexBufferIfNeeded(size_t numInds); 00514 00516 virtual void copyTempVertexToBuffer(void); 00517 00518 }; 00519 00520 00522 class _OgreExport ManualObjectFactory : public MovableObjectFactory 00523 { 00524 protected: 00525 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00526 public: 00527 ManualObjectFactory() {} 00528 ~ManualObjectFactory() {} 00529 00530 static String FACTORY_TYPE_NAME; 00531 00532 const String& getType(void) const; 00533 void destroyInstance( MovableObject* obj); 00534 00535 }; 00536 } 00537 00538 #endif 00539
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:23 2009