OgreManualObject.h
Go to the documentation of this file.

    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-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __OgreManualObject_H__
    00030 #define __OgreManualObject_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreMovableObject.h"
    00034 #include "OgreRenderable.h"
    00035 #include "OgreResourceGroupManager.h"
    00036
    00037
    00038 namespace Ogre
    00039 {
    00106     class _OgreExport ManualObject : public MovableObject
    00107     {
    00108     public:
    00109         ManualObject(const String& name);
    00110         virtual ~ManualObject();
    00111
    00112         //pre-declare ManualObjectSection
    00113         class ManualObjectSection;
    00114
    00124         virtual void clear(void);
    00125
    00133         virtual void estimateVertexCount(size_t vcount);
    00134
    00142         virtual void estimateIndexCount(size_t icount);
    00143
    00153         virtual void begin(const String& materialName,
    00154             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST, const String & groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00155
    00159         virtual void setDynamic(bool dyn) { mDynamic = dyn; }
    00161         virtual bool getDynamic() const { return mDynamic; }
    00162
    00174         virtual void beginUpdate(size_t sectionIndex);
    00182         virtual void position(const Vector3& pos);
    00184         virtual void position(Real x, Real y, Real z);
    00185
    00191         virtual void normal(const Vector3& norm);
    00193         virtual void normal(Real x, Real y, Real z);
    00194
    00202         virtual void tangent(const Vector3& tan);
    00204         virtual void tangent(Real x, Real y, Real z);
    00205
    00214         virtual void textureCoord(Real u);
    00216         virtual void textureCoord(Real u, Real v);
    00218         virtual void textureCoord(Real u, Real v, Real w);
    00220         virtual void textureCoord(Real x, Real y, Real z, Real w);
    00222         virtual void textureCoord(const Vector2& uv);
    00224         virtual void textureCoord(const Vector3& uvw);
    00226         virtual void textureCoord(const Vector4& xyzw);
    00227
    00230         virtual void colour(const ColourValue& col);
    00234         virtual void colour(Real r, Real g, Real b, Real a = 1.0f);
    00235
    00247         virtual void index(uint32 idx);
    00256         virtual void triangle(uint32 i1, uint32 i2, uint32 i3);
    00265         virtual void quad(uint32 i1, uint32 i2, uint32 i3, uint32 i4);
    00266
    00268         virtual size_t getCurrentVertexCount() const;
    00269
    00271         virtual size_t getCurrentIndexCount() const;
    00272
    00277         virtual ManualObjectSection* end(void);
    00278
    00288         virtual void setMaterialName(size_t subindex, const String& name, const String & group = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00289
    00301         virtual MeshPtr convertToMesh(const String& meshName,
    00302             const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00303
    00313         void setUseIdentityProjection(bool useIdentityProjection);
    00314
    00324         bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
    00325
    00335         void setUseIdentityView(bool useIdentityView);
    00336
    00346         bool getUseIdentityView(void) const { return mUseIdentityView; }
    00347
    00355         void setBoundingBox(const AxisAlignedBox& box) { mAABB = box; }
    00356
    00359         ManualObjectSection* getSection(unsigned int index) const;
    00360
    00363         unsigned int getNumSections(void) const;
    00373         void setKeepDeclarationOrder(bool keepOrder) { mKeepDeclarationOrder = keepOrder; }
    00374
    00379         bool getKeepDeclarationOrder() const { return mKeepDeclarationOrder; }
    00380         // MovableObject overrides
    00381
    00383         const String& getMovableType(void) const;
    00385         const AxisAlignedBox& getBoundingBox(void) const;
    00387         Real getBoundingRadius(void) const;
    00389         void _updateRenderQueue(RenderQueue* queue);
    00391         EdgeData* getEdgeList(void);
    00393         bool hasEdgeList(void);
    00395         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
    00396             ShadowTechnique shadowTechnique, const Light* light,
    00397             HardwareIndexBufferSharedPtr* indexBuffer,
    00398             bool extrudeVertices, Real extrusionDist, unsigned long flags = 0);
    00399
    00400
    00402         class _OgreExport ManualObjectSection : public Renderable, public MovableAlloc
    00403         {
    00404         protected:
    00405             ManualObject* mParent;
    00406             String mMaterialName;
    00407             String mGroupName;
    00408             mutable MaterialPtr mMaterial;
    00409             RenderOperation mRenderOperation;
    00410             bool m32BitIndices;
    00411
    00412
    00413         public:
    00414             ManualObjectSection(ManualObject* parent, const String& materialName,
    00415                 RenderOperation::OperationType opType, const String & groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00416             virtual ~ManualObjectSection();
    00417
    00419             RenderOperation* getRenderOperation(void);
    00421             const String& getMaterialName(void) const { return mMaterialName; }
    00423             const String& getMaterialGroup(void) const { return mGroupName; }
    00425             void setMaterialName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
    00427             void set32BitIndices(bool n32) { m32BitIndices = n32; }
    00429             bool get32BitIndices() const { return m32BitIndices; }
    00430
    00431             // Renderable overrides
    00433             const MaterialPtr& getMaterial(void) const;
    00435             void getRenderOperation(RenderOperation& op);
    00437             void getWorldTransforms(Matrix4* xform) const;
    00439             Real getSquaredViewDepth(const Ogre::Camera *) const;
    00441             const LightList &getLights(void) const;
    00442
    00443
    00444
    00445         };
    00447         class _OgreExport ManualObjectSectionShadowRenderable : public ShadowRenderable
    00448         {
    00449         protected:
    00450             ManualObject* mParent;
    00451             // Shared link to position buffer
    00452             HardwareVertexBufferSharedPtr mPositionBuffer;
    00453             // Shared link to w-coord buffer (optional)
    00454             HardwareVertexBufferSharedPtr mWBuffer;
    00455
    00456         public:
    00457             ManualObjectSectionShadowRenderable(ManualObject* parent,
    00458                 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
    00459                 bool createSeparateLightCap, bool isLightCap = false);
    00460             ~ManualObjectSectionShadowRenderable();
    00462             void getWorldTransforms(Matrix4* xform) const;
    00463             HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
    00464             HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
    00466             virtual void rebindIndexBuffer(const HardwareIndexBufferSharedPtr& indexBuffer);
    00467
    00468
    00469
    00470         };
    00471
    00472         typedef vector<ManualObjectSection*>::type SectionList;
    00473
    00475         void visitRenderables(Renderable::Visitor* visitor,
    00476             bool debugRenderables = false);
    00477
    00478
    00479     protected:
    00481         bool mDynamic;
    00483         SectionList mSectionList;
    00485         ManualObjectSection* mCurrentSection;
    00487         bool mCurrentUpdating;
    00489         struct TempVertex
    00490         {
    00491             Vector3 position;
    00492             Vector3 normal;
    00493             Vector3 tangent;
    00494             Vector4 texCoord[OGRE_MAX_TEXTURE_COORD_SETS];
    00495             ushort texCoordDims[OGRE_MAX_TEXTURE_COORD_SETS];
    00496             ColourValue colour;
    00497         };
    00499         TempVertex mTempVertex;
    00501         bool mFirstVertex;
    00503         bool mTempVertexPending;
    00505         char* mTempVertexBuffer;
    00507         size_t mTempVertexSize;
    00509         uint32* mTempIndexBuffer;
    00511         size_t mTempIndexSize;
    00513         size_t mDeclSize;
    00515         size_t mEstVertexCount;
    00517         size_t mEstIndexCount;
    00519         ushort mTexCoordIndex;
    00521         AxisAlignedBox mAABB;
    00523         Real mRadius;
    00525         bool mAnyIndexed;
    00527         EdgeData* mEdgeList;
    00529         ShadowRenderableList mShadowRenderables;
    00531         bool mUseIdentityProjection;
    00533         bool mUseIdentityView;
    00535         bool mKeepDeclarationOrder;
    00536
    00537
    00539         virtual void resetTempAreas(void);
    00541         virtual void resizeTempVertexBufferIfNeeded(size_t numVerts);
    00543         virtual void resizeTempIndexBufferIfNeeded(size_t numInds);
    00544
    00546         virtual void copyTempVertexToBuffer(void);
    00547
    00548     };
    00549
    00550
    00552     class _OgreExport ManualObjectFactory : public MovableObjectFactory
    00553     {
    00554     protected:
    00555         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
    00556     public:
    00557         ManualObjectFactory() {}
    00558         ~ManualObjectFactory() {}
    00559
    00560         static String FACTORY_TYPE_NAME;
    00561
    00562         const String& getType(void) const;
    00563         void destroyInstance( MovableObject* obj);
    00564
    00565     };
    00568 }
    00569
    00570 #endif
    00571
    00572

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22