source: GTP/trunk/Lib/Geom/OgreStuff/include/OgrePatchMesh.h @ 1809

Revision 1809, 5.4 KB checked in by gumbau, 18 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __PatchMesh_H__
26#define __PatchMesh_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreMesh.h"
30#include "OgrePatchSurface.h"
31
32namespace Ogre {
33
34    /** Patch specialisation of Mesh.
35    @remarks
36        Instances of this class should be created by calling MeshManager::createBezierPatch.
37    */
38    class _OgreExport PatchMesh : public Mesh
39    {
40    protected:
41        /// Internal surface definition
42        PatchSurface mSurface;
43        /// Vertex declaration, cloned from the input
44        VertexDeclaration* mDeclaration;
45    public:
46        /// Constructor
47        PatchMesh(ResourceManager* creator, const String& name, ResourceHandle handle,
48            const String& group);
49
50        /// Define the patch, as defined in MeshManager::createBezierPatch
51        void define(void* controlPointBuffer,
52            VertexDeclaration *declaration, size_t width, size_t height,
53            size_t uMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
54            size_t vMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
55            PatchSurface::VisibleSide visibleSide = PatchSurface::VS_FRONT,
56            HardwareBuffer::Usage vbUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
57            HardwareBuffer::Usage ibUsage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
58            bool vbUseShadow = false, bool ibUseShadow = false);
59
60        /* Sets the current subdivision level as a proportion of full detail.
61        @param factor Subdivision factor as a value from 0 (control points only) to 1 (maximum
62            subdivision). */
63        void setSubdivision(Real factor);
64    protected:
65        /// Overridden from Resource
66        void loadImpl(void);
67
68    };
69    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to PatchMeshPtr
70    @note Has to be a subclass since we need operator=.
71    We could templatise this instead of repeating per Resource subclass,
72    except to do so requires a form VC6 does not support i.e.
73    ResourceSubclassPtr<T> : public SharedPtr<T>
74    */
75    class _OgreExport PatchMeshPtr : public SharedPtr<PatchMesh>
76    {
77    public:
78        PatchMeshPtr() : SharedPtr<PatchMesh>() {}
79        explicit PatchMeshPtr(PatchMesh* rep) : SharedPtr<PatchMesh>(rep) {}
80        PatchMeshPtr(const PatchMeshPtr& r) : SharedPtr<PatchMesh>(r) {}
81        PatchMeshPtr(const ResourcePtr& r) : SharedPtr<PatchMesh>()
82        {
83                        // lock & copy other mutex pointer
84            OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
85            {
86                            OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
87                            OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
88                pRep = static_cast<PatchMesh*>(r.getPointer());
89                pUseCount = r.useCountPointer();
90                if (pUseCount)
91                {
92                    ++(*pUseCount);
93                }
94            }
95        }
96
97        /// Operator used to convert a ResourcePtr to a PatchMeshPtr
98        PatchMeshPtr& operator=(const ResourcePtr& r)
99        {
100            if (pRep == static_cast<PatchMesh*>(r.getPointer()))
101                return *this;
102            release();
103
104            OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
105            {
106                            // lock & copy other mutex pointer
107                            OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
108                            OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
109                pRep = static_cast<PatchMesh*>(r.getPointer());
110                pUseCount = r.useCountPointer();
111                if (pUseCount)
112                {
113                    ++(*pUseCount);
114                }
115            }
116            return *this;
117        }
118        /// Operator used to convert a MeshPtr to a PatchMeshPtr
119        PatchMeshPtr& operator=(const MeshPtr& r)
120        {
121            if (pRep == static_cast<PatchMesh*>(r.getPointer()))
122                return *this;
123            release();
124                        // lock & copy other mutex pointer
125            OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
126            {
127                            OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
128                            OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
129                pRep = static_cast<PatchMesh*>(r.getPointer());
130                pUseCount = r.useCountPointer();
131                if (pUseCount)
132                {
133                    ++(*pUseCount);
134                }
135            }
136            return *this;
137        }
138    };
139
140}
141
142#endif
Note: See TracBrowser for help on using the repository browser.