Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgrePatchSurface.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 10.5 KB
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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __PatchSurface_H__
29#define __PatchSurface_H__
30
31#include "OgrePrerequisites.h"
32
33#include "OgreVector3.h"
34#include "OgreString.h"
35#include "OgreRenderOperation.h"
36#include "OgreAxisAlignedBox.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre {
40
41        /** \addtogroup Core
42        *  @{
43        */
44        /** \addtogroup LOD
45        *  @{
46        */
47        /** A surface which is defined by curves of some kind to form a patch, e.g. a Bezier patch.
48        @remarks
49            This object will take a list of control points with various assorted data, and will
50            subdivide it into a patch mesh. Currently only Bezier curves are supported for defining
51            the surface, but other techniques such as NURBS would follow the same basic approach.
52    */
53        class _OgreExport PatchSurface : public PatchAlloc
54    {
55    public:
56        PatchSurface();
57        ~PatchSurface();
58
59        enum PatchSurfaceType
60        {
61            /// A patch defined by a set of bezier curves
62            PST_BEZIER
63        };
64
65        /// Constant for indicating automatic determination of subdivision level for patches
66        enum
67        {
68            AUTO_LEVEL = -1
69        };
70
71        enum VisibleSide {
72            /// The side from which u goes right and v goes up (as in texture coords)
73            VS_FRONT,
74            /// The side from which u goes right and v goes down (reverse of texture coords)
75            VS_BACK,
76            /// Both sides are visible - warning this creates 2x the number of triangles and adds extra overhead for calculating normals
77            VS_BOTH
78        };
79        /** Sets up the surface by defining it's control points, type and initial subdivision level.
80            @remarks
81                This method initialises the surface by passing it a set of control points. The type of curves to be used
82                are also defined here, although the only supported option currently is a bezier patch. You can also
83                specify a global subdivision level here if you like, although it is recommended that the parameter
84                is left as AUTO_LEVEL, which means the system decides how much subdivision is required (based on the
85                curvature of the surface)
86            @param
87                controlPointBuffer A pointer to a buffer containing the vertex data which defines control points
88                of the curves rather than actual vertices. Note that you are expected to provide not
89                just position information, but potentially normals and texture coordinates too. The
90                format of the buffer is defined in the VertexDeclaration parameter
91            @param
92                declaration VertexDeclaration describing the contents of the buffer.
93                Note this declaration must _only_ draw on buffer source 0!
94            @param
95                width Specifies the width of the patch in control points.
96            @param
97                height Specifies the height of the patch in control points.
98            @param
99                pType The type of surface - currently only PST_BEZIER is supported
100            @param
101                uMaxSubdivisionLevel,vMaxSubdivisionLevel If you want to manually set the top level of subdivision,
102                do it here, otherwise let the system decide.
103            @param
104                visibleSide Determines which side of the patch (or both) triangles are generated for.
105        */
106        void defineSurface(void* controlPointBuffer, 
107            VertexDeclaration *declaration, size_t width, size_t height,
108            PatchSurfaceType pType = PST_BEZIER, 
109            size_t uMaxSubdivisionLevel = AUTO_LEVEL, size_t vMaxSubdivisionLevel = AUTO_LEVEL,
110            VisibleSide visibleSide = VS_FRONT);
111
112        /** Based on a previous call to defineSurface, establishes the number of vertices required
113            to hold this patch at the maximum detail level.
114            @remarks This is useful when you wish to build the patch into external vertex / index buffers.
115
116        */
117        size_t getRequiredVertexCount(void) const;
118        /** Based on a previous call to defineSurface, establishes the number of indexes required
119            to hold this patch at the maximum detail level.
120            @remarks This is useful when you wish to build the patch into external vertex / index buffers.
121
122        */
123        size_t getRequiredIndexCount(void) const;
124
125        /** Gets the current index count based on the current subdivision level. */
126        size_t getCurrentIndexCount(void) const;
127        /// Returns the index offset used by this buffer to write data into the buffer
128        size_t getIndexOffset(void) const { return mIndexOffset; }
129        /// Returns the vertex offset used by this buffer to write data into the buffer
130        size_t getVertexOffset(void) const { return mVertexOffset; }
131
132
133        /** Gets the bounds of this patch, only valid after calling defineSurface. */
134        const AxisAlignedBox& getBounds(void) const;
135        /** Gets the radius of the bounding sphere for this patch, only valid after defineSurface
136        has been called. */
137        Real getBoundingSphereRadius(void) const;
138        /** Tells the system to build the mesh relating to the surface into externally created
139            buffers.
140            @remarks
141                The VertexDeclaration of the vertex buffer must be identical to the one passed into
142                defineSurface.  In addition, there must be enough space in the buffer to
143                accommodate the patch at full detail level; you should call getRequiredVertexCount
144                and getRequiredIndexCount to determine this. This method does not create an internal
145                mesh for this patch and so getMesh will return null if you call it after building the
146                patch this way.
147            @param destVertexBuffer The destination vertex buffer in which to build the patch.
148            @param vertexStart The offset at which to start writing vertices for this patch
149            @param destIndexBuffer The destination index buffer in which to build the patch.
150            @param indexStart The offset at which to start writing indexes for this patch
151
152        */
153        void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart,
154            HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart);
155
156        /** Alters the level of subdivision for this surface.
157            @remarks
158                This method changes the proportionate detail level of the patch; since
159                the U and V directions can have different subdivision levels, this method
160                takes a single Real value where 0 is the minimum detail (the control points)
161                and 1 is the maximum detail level as supplied to the original call to
162                defineSurface.
163        */
164        void setSubdivisionFactor(Real factor);
165
166        /** Gets the current level of subdivision. */
167        Real getSubdivisionFactor(void) const;
168
169        void* getControlPointBuffer(void) const
170        {
171            return mControlPointBuffer;
172        }
173        /** Convenience method for telling the patch that the control points have been
174            deleted, since once the patch has been built they are not required. */
175        void notifyControlPointBufferDeallocated(void) { 
176            mControlPointBuffer = 0;
177        }
178    protected:
179        /// Vertex declaration describing the control point buffer
180        VertexDeclaration* mDeclaration;
181        /// Buffer containing the system-memory control points
182        void* mControlPointBuffer;
183        /// Type of surface
184        PatchSurfaceType mType;
185        /// Width in control points
186        size_t mCtlWidth;
187        /// Height in control points
188        size_t mCtlHeight;
189        /// TotalNumber of control points
190        size_t mCtlCount;
191        /// U-direction subdivision level
192        size_t mULevel;
193        /// V-direction subdivision level
194        size_t mVLevel;
195        /// Max subdivision level
196        size_t mMaxULevel;
197        size_t mMaxVLevel;
198        /// Width of the subdivided mesh (big enough for max level)
199        size_t mMeshWidth;
200        /// Height of the subdivided mesh (big enough for max level)
201        size_t mMeshHeight;
202        /// Which side is visible
203        VisibleSide mVSide;
204
205        Real mSubdivisionFactor;
206
207        vector<Vector3>::type mVecCtlPoints;
208
209        /** Internal method for finding the subdivision level given 3 control points.
210        */
211        size_t findLevel( Vector3& a, Vector3& b, Vector3& c);
212
213        void distributeControlPoints(void* lockedBuffer);
214        void subdivideCurve(void* lockedBuffer, size_t startIdx, size_t stepSize, size_t numSteps, size_t iterations);
215        void interpolateVertexData(void* lockedBuffer, size_t leftIndex, size_t rightIndex, size_t destIndex);
216        void makeTriangles(void);
217
218        size_t getAutoULevel(bool forMax = false);
219        size_t getAutoVLevel(bool forMax = false);
220
221        HardwareVertexBufferSharedPtr mVertexBuffer;
222        HardwareIndexBufferSharedPtr mIndexBuffer;
223        size_t mVertexOffset;
224        size_t mIndexOffset;
225        size_t mRequiredVertexCount;
226        size_t mRequiredIndexCount;
227        size_t mCurrIndexCount;
228
229        AxisAlignedBox mAABB;
230        Real mBoundingSphere;
231
232
233
234    };
235
236        /** @} */
237        /** @} */
238
239} // namespace
240
241#include "OgreHeaderSuffix.h"
242
243#endif
Note: See TracBrowser for help on using the repository browser.