doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Surface_Patch.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __SURFACE_PATCH_H__
30 #define __SURFACE_PATCH_H__
31 
32 /*
33 ===============================================================================
34 
35  Bezier patch surface.
36 
37 ===============================================================================
38 */
39 
40 class idSurface_Patch : public idSurface {
41 
42 public:
43  idSurface_Patch( void );
44  idSurface_Patch( int maxPatchWidth, int maxPatchHeight );
45  idSurface_Patch( const idSurface_Patch &patch );
46  ~idSurface_Patch( void );
47 
48  void SetSize( int patchWidth, int patchHeight );
49  int GetWidth( void ) const;
50  int GetHeight( void ) const;
51 
52  // subdivide the patch mesh based on error
53  void Subdivide( float maxHorizontalError, float maxVerticalError, float maxLength, bool genNormals = false );
54  // subdivide the patch up to an explicit number of horizontal and vertical subdivisions
55  void SubdivideExplicit( int horzSubdivisions, int vertSubdivisions, bool genNormals, bool removeLinear = false );
56 
57 protected:
58  int width; // width of patch
59  int height; // height of patch
60  int maxWidth; // maximum width allocated for
61  int maxHeight; // maximum height allocated for
62  bool expanded; // true if vertices are spaced out
63 
64 private:
65  // put the approximation points on the curve
66  void PutOnCurve( void );
67  // remove columns and rows with all points on one line
68  void RemoveLinearColumnsRows( void );
69  // resize verts buffer
70  void ResizeExpanded( int height, int width );
71  // space points out over maxWidth * maxHeight buffer
72  void Expand( void );
73  // move all points to the start of the verts buffer
74  void Collapse( void );
75  // project a point onto a vector to calculate maximum curve error
76  void ProjectPointOntoVector( const idVec3 &point, const idVec3 &vStart, const idVec3 &vEnd, idVec3 &vProj );
77  // generate normals
78  void GenerateNormals( void );
79  // generate triangle indexes
80  void GenerateIndexes( void );
81  // lerp point from two patch point
82  void LerpVert( const idDrawVert &a, const idDrawVert &b, idDrawVert &out ) const;
83  // sample a single 3x3 patch
84  void SampleSinglePatchPoint( const idDrawVert ctrl[3][3], float u, float v, idDrawVert *out ) const;
85  void SampleSinglePatch( const idDrawVert ctrl[3][3], int baseCol, int baseRow, int width, int horzSub, int vertSub, idDrawVert *outVerts ) const;
86 };
87 
88 /*
89 =================
90 idSurface_Patch::idSurface_Patch
91 =================
92 */
94  height = width = maxHeight = maxWidth = 0;
95  expanded = false;
96 }
97 
98 /*
99 =================
100 idSurface_Patch::idSurface_Patch
101 =================
102 */
103 ID_INLINE idSurface_Patch::idSurface_Patch( int maxPatchWidth, int maxPatchHeight ) {
104  width = height = 0;
105  maxWidth = maxPatchWidth;
106  maxHeight = maxPatchHeight;
108  expanded = false;
109 }
110 
111 /*
112 =================
113 idSurface_Patch::idSurface_Patch
114 =================
115 */
117  (*this) = patch;
118 }
119 
120 /*
121 =================
122 idSurface_Patch::~idSurface_Patch
123 =================
124 */
126 }
127 
128 /*
129 =================
130 idSurface_Patch::GetWidth
131 =================
132 */
133 ID_INLINE int idSurface_Patch::GetWidth( void ) const {
134  return width;
135 }
136 
137 /*
138 =================
139 idSurface_Patch::GetHeight
140 =================
141 */
142 ID_INLINE int idSurface_Patch::GetHeight( void ) const {
143  return height;
144 }
145 
146 #endif /* !__SURFACE_PATCH_H__ */
void Collapse(void)
idList< idDrawVert > verts
Definition: Surface.h:96
void ResizeExpanded(int height, int width)
const GLdouble * v
Definition: glext.h:2936
void SetNum(int newnum, bool resize=true)
Definition: List.h:289
Definition: Vector.h:316
void LerpVert(const idDrawVert &a, const idDrawVert &b, idDrawVert &out) const
void SubdivideExplicit(int horzSubdivisions, int vertSubdivisions, bool genNormals, bool removeLinear=false)
int GetHeight(void) const
void PutOnCurve(void)
void Subdivide(float maxHorizontalError, float maxVerticalError, float maxLength, bool genNormals=false)
void GenerateIndexes(void)
void GenerateNormals(void)
void RemoveLinearColumnsRows(void)
GLenum GLsizei width
Definition: glext.h:2846
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
GLenum GLsizei GLsizei height
Definition: glext.h:2856
GLubyte GLubyte b
Definition: glext.h:4662
GLsizei maxLength
Definition: glext.h:3627
void ProjectPointOntoVector(const idVec3 &point, const idVec3 &vStart, const idVec3 &vEnd, idVec3 &vProj)
void SampleSinglePatchPoint(const idDrawVert ctrl[3][3], float u, float v, idDrawVert *out) const
void SetSize(int patchWidth, int patchHeight)
void SampleSinglePatch(const idDrawVert ctrl[3][3], int baseCol, int baseRow, int width, int horzSub, int vertSub, idDrawVert *outVerts) const
int GetWidth(void) const