OgrePatchSurface.h
Go to the documentation of this file.
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-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 
39 namespace Ogre {
40 
54  {
55  public:
58 
60  {
62  PST_BEZIER
63  };
64 
66  enum
67  {
68  AUTO_LEVEL = -1
69  };
70 
71  enum VisibleSide {
77  VS_BOTH
78  };
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 
117  size_t getRequiredVertexCount(void) const;
123  size_t getRequiredIndexCount(void) const;
124 
126  size_t getCurrentIndexCount(void) const;
128  size_t getIndexOffset(void) const { return mIndexOffset; }
130  size_t getVertexOffset(void) const { return mVertexOffset; }
131 
132 
134  const AxisAlignedBox& getBounds(void) const;
153  void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart,
154  HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart);
155 
165 
168 
169  void* getControlPointBuffer(void) const
170  {
171  return mControlPointBuffer;
172  }
176  mControlPointBuffer = 0;
177  }
178  protected:
186  size_t mCtlWidth;
188  size_t mCtlHeight;
190  size_t mCtlCount;
192  size_t mULevel;
194  size_t mVLevel;
196  size_t mMaxULevel;
197  size_t mMaxVLevel;
199  size_t mMeshWidth;
201  size_t mMeshHeight;
204 
206 
208 
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 
224  size_t mIndexOffset;
228 
231 
232 
233 
234  };
235 
239 } // namespace
240 
241 #include "OgreHeaderSuffix.h"
242 
243 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
A 3D box aligned with the x/y/z axes.
Shared pointer implementation used to share index buffers.
Shared pointer implementation used to share vertex buffers.
A surface which is defined by curves of some kind to form a patch, e.g.
size_t mULevel
U-direction subdivision level.
size_t getAutoULevel(bool forMax=false)
size_t mCtlWidth
Width in control points.
size_t getRequiredVertexCount(void) const
Based on a previous call to defineSurface, establishes the number of vertices required to hold this p...
AxisAlignedBox mAABB
void setSubdivisionFactor(Real factor)
Alters the level of subdivision for this surface.
@ VS_BACK
The side from which u goes right and v goes down (reverse of texture coords)
@ VS_FRONT
The side from which u goes right and v goes up (as in texture coords)
size_t mMeshWidth
Width of the subdivided mesh (big enough for max level)
void notifyControlPointBufferDeallocated(void)
Convenience method for telling the patch that the control points have been deleted,...
VertexDeclaration * mDeclaration
Vertex declaration describing the control point buffer.
size_t mCtlCount
TotalNumber of control points.
size_t mMeshHeight
Height of the subdivided mesh (big enough for max level)
void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart, HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart)
Tells the system to build the mesh relating to the surface into externally created buffers.
size_t mMaxULevel
Max subdivision level.
const AxisAlignedBox & getBounds(void) const
Gets the bounds of this patch, only valid after calling defineSurface.
void * getControlPointBuffer(void) const
void interpolateVertexData(void *lockedBuffer, size_t leftIndex, size_t rightIndex, size_t destIndex)
Real getSubdivisionFactor(void) const
Gets the current level of subdivision.
void distributeControlPoints(void *lockedBuffer)
vector< Vector3 >::type mVecCtlPoints
size_t getCurrentIndexCount(void) const
Gets the current index count based on the current subdivision level.
PatchSurfaceType mType
Type of surface.
Real getBoundingSphereRadius(void) const
Gets the radius of the bounding sphere for this patch, only valid after defineSurface has been called...
void makeTriangles(void)
size_t findLevel(Vector3 &a, Vector3 &b, Vector3 &c)
Internal method for finding the subdivision level given 3 control points.
HardwareVertexBufferSharedPtr mVertexBuffer
void * mControlPointBuffer
Buffer containing the system-memory control points.
size_t getIndexOffset(void) const
Returns the index offset used by this buffer to write data into the buffer.
void defineSurface(void *controlPointBuffer, VertexDeclaration *declaration, size_t width, size_t height, PatchSurfaceType pType=PST_BEZIER, size_t uMaxSubdivisionLevel=AUTO_LEVEL, size_t vMaxSubdivisionLevel=AUTO_LEVEL, VisibleSide visibleSide=VS_FRONT)
Sets up the surface by defining it's control points, type and initial subdivision level.
size_t getRequiredIndexCount(void) const
Based on a previous call to defineSurface, establishes the number of indexes required to hold this pa...
size_t mCtlHeight
Height in control points.
HardwareIndexBufferSharedPtr mIndexBuffer
size_t mVLevel
V-direction subdivision level.
size_t getVertexOffset(void) const
Returns the vertex offset used by this buffer to write data into the buffer.
void subdivideCurve(void *lockedBuffer, size_t startIdx, size_t stepSize, size_t numSteps, size_t iterations)
VisibleSide mVSide
Which side is visible.
size_t getAutoVLevel(bool forMax=false)
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
float Real
Software floating point type.

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.