| 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 __PatchMesh_H__ |
|---|
| 30 | #define __PatchMesh_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.h" |
|---|
| 33 | #include "OgreMesh.h" |
|---|
| 34 | #include "OgrePatchSurface.h" |
|---|
| 35 | |
|---|
| 36 | namespace Ogre { |
|---|
| 37 | |
|---|
| 38 | /** Patch specialisation of Mesh. |
|---|
| 39 | @remarks |
|---|
| 40 | Instances of this class should be created by calling MeshManager::createBezierPatch. |
|---|
| 41 | */ |
|---|
| 42 | class _OgreExport PatchMesh : public Mesh |
|---|
| 43 | { |
|---|
| 44 | protected: |
|---|
| 45 | /// Internal surface definition |
|---|
| 46 | PatchSurface mSurface; |
|---|
| 47 | /// Vertex declaration, cloned from the input |
|---|
| 48 | VertexDeclaration* mDeclaration; |
|---|
| 49 | public: |
|---|
| 50 | /// Constructor |
|---|
| 51 | PatchMesh(ResourceManager* creator, const String& name, ResourceHandle handle, |
|---|
| 52 | const String& group); |
|---|
| 53 | |
|---|
| 54 | /// Define the patch, as defined in MeshManager::createBezierPatch |
|---|
| 55 | void define(void* controlPointBuffer, |
|---|
| 56 | VertexDeclaration *declaration, size_t width, size_t height, |
|---|
| 57 | size_t uMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL, |
|---|
| 58 | size_t vMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL, |
|---|
| 59 | PatchSurface::VisibleSide visibleSide = PatchSurface::VS_FRONT, |
|---|
| 60 | HardwareBuffer::Usage vbUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY, |
|---|
| 61 | HardwareBuffer::Usage ibUsage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, |
|---|
| 62 | bool vbUseShadow = false, bool ibUseShadow = false); |
|---|
| 63 | |
|---|
| 64 | /* Sets the current subdivision level as a proportion of full detail. |
|---|
| 65 | @param factor Subdivision factor as a value from 0 (control points only) to 1 (maximum |
|---|
| 66 | subdivision). */ |
|---|
| 67 | void setSubdivision(Real factor); |
|---|
| 68 | protected: |
|---|
| 69 | /// Overridden from Resource |
|---|
| 70 | void loadImpl(void); |
|---|
| 71 | |
|---|
| 72 | }; |
|---|
| 73 | /** Specialisation of SharedPtr to allow SharedPtr to be assigned to PatchMeshPtr |
|---|
| 74 | @note Has to be a subclass since we need operator=. |
|---|
| 75 | We could templatise this instead of repeating per Resource subclass, |
|---|
| 76 | except to do so requires a form VC6 does not support i.e. |
|---|
| 77 | ResourceSubclassPtr<T> : public SharedPtr<T> |
|---|
| 78 | */ |
|---|
| 79 | class _OgreExport PatchMeshPtr : public SharedPtr<PatchMesh> |
|---|
| 80 | { |
|---|
| 81 | public: |
|---|
| 82 | PatchMeshPtr() : SharedPtr<PatchMesh>() {} |
|---|
| 83 | explicit PatchMeshPtr(PatchMesh* rep) : SharedPtr<PatchMesh>(rep) {} |
|---|
| 84 | PatchMeshPtr(const PatchMeshPtr& r) : SharedPtr<PatchMesh>(r) {} |
|---|
| 85 | PatchMeshPtr(const ResourcePtr& r) : SharedPtr<PatchMesh>() |
|---|
| 86 | { |
|---|
| 87 | // lock & copy other mutex pointer |
|---|
| 88 | OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 89 | { |
|---|
| 90 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 91 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 92 | pRep = static_cast<PatchMesh*>(r.getPointer()); |
|---|
| 93 | pUseCount = r.useCountPointer(); |
|---|
| 94 | if (pUseCount) |
|---|
| 95 | { |
|---|
| 96 | ++(*pUseCount); |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /// Operator used to convert a ResourcePtr to a PatchMeshPtr |
|---|
| 102 | PatchMeshPtr& operator=(const ResourcePtr& r) |
|---|
| 103 | { |
|---|
| 104 | if (pRep == static_cast<PatchMesh*>(r.getPointer())) |
|---|
| 105 | return *this; |
|---|
| 106 | release(); |
|---|
| 107 | |
|---|
| 108 | OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 109 | { |
|---|
| 110 | // lock & copy other mutex pointer |
|---|
| 111 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 112 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 113 | pRep = static_cast<PatchMesh*>(r.getPointer()); |
|---|
| 114 | pUseCount = r.useCountPointer(); |
|---|
| 115 | if (pUseCount) |
|---|
| 116 | { |
|---|
| 117 | ++(*pUseCount); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | else |
|---|
| 121 | { |
|---|
| 122 | // RHS must be a null pointer |
|---|
| 123 | assert(r.isNull() && "RHS must be null if it has no mutex!"); |
|---|
| 124 | setNull(); |
|---|
| 125 | } |
|---|
| 126 | return *this; |
|---|
| 127 | } |
|---|
| 128 | /// Operator used to convert a MeshPtr to a PatchMeshPtr |
|---|
| 129 | PatchMeshPtr& operator=(const MeshPtr& r) |
|---|
| 130 | { |
|---|
| 131 | if (pRep == static_cast<PatchMesh*>(r.getPointer())) |
|---|
| 132 | return *this; |
|---|
| 133 | release(); |
|---|
| 134 | // lock & copy other mutex pointer |
|---|
| 135 | OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 136 | { |
|---|
| 137 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 138 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) |
|---|
| 139 | pRep = static_cast<PatchMesh*>(r.getPointer()); |
|---|
| 140 | pUseCount = r.useCountPointer(); |
|---|
| 141 | if (pUseCount) |
|---|
| 142 | { |
|---|
| 143 | ++(*pUseCount); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | return *this; |
|---|
| 147 | } |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | #endif |
|---|