ReactOS  0.4.12-dev-418-g3df31a8
quilt.cc
Go to the documentation of this file.
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 */
34 
35 /*
36  * quilt.c++
37  *
38  */
39 
40 //#include "glimports.h"
41 //#include "mystdio.h"
42 //#include "myassert.h"
43 #include "quilt.h"
44 #include "backend.h"
45 #include "mapdesc.h"
46 #include "flist.h"
47 #include "patchlist.h"
48 #include "simplemath.h" //min()
49 
50 /* local preprocessor definitions */
51 #define DEF_PATCH_STEPSIZE .4
52 #define fsizeof(x) (sizeof(x)/sizeof(REAL))
53 
54 
55 Quilt::Quilt( Mapdesc *_mapdesc )
56 {
57  mapdesc = _mapdesc;
58 }
59 
60 void
62 {
63  for( Quiltspec *q=qspec; q != eqspec; q++ ) {
64 #if 1
65  if( q->breakpoints) delete[] q->breakpoints; q->breakpoints = 0;
66 #else
67  if( q->breakpoints) {
68  delete[] q->breakpoints;
69  q->breakpoints = 0;
70 printf("in here\n");
71  }
72 #endif
73  }
74  if( cpts ) delete[] cpts;
75  cpts = 0;
77 }
78 
79 void
80 Quilt::show( void )
81 {
82 #ifndef NDEBUG
83  int nc = mapdesc->getNcoords();
84  REAL *ps = cpts;
85  ps += qspec[0].offset;
86  ps += qspec[1].offset;
87  for( int i=0; i!= qspec[0].order * qspec[0].width; i++ ) {
88  for( int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) {
89  for( int k=0; k < nc; k++ )
90  _glu_dprintf( "%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] );
91  _glu_dprintf( "\n" );
92  }
93  _glu_dprintf( "\n" );
94  }
95  _glu_dprintf( "\n" );
96 #endif
97 }
98 
99 /*--------------------------------------------------------------------------
100  * Quilt::select - find which map in each quilt contains the points
101  * pta and ptb with pta[i] < ptb[i]
102  *--------------------------------------------------------------------------
103  */
104 
105 void
106 Quilt::select( REAL *pta, REAL *ptb )
107 {
108  int dim = eqspec - qspec;
109  int i, j;
110  for( i=0; i<dim; i++) {
111  for( j=qspec[i].width-1; j>=0; j-- )
112  if( (qspec[i].breakpoints[j] <= pta[i] ) &&
113  (ptb[i] <= qspec[i].breakpoints[j+1] ) )
114  break;
115  assert( j != -1 );
116  qspec[i].index = j;
117  }
118 }
119 
120 void
122 {
123  if( getDimension() == 2 ) {
124  REAL *ps = cpts;
125  ps += qspec[0].offset;
126  ps += qspec[1].offset;
127  ps += qspec[0].index * qspec[0].order * qspec[0].stride;
128  ps += qspec[1].index * qspec[1].order * qspec[1].stride;
129  backend.surfpts( mapdesc->getType(), ps,
130  qspec[0].stride,
131  qspec[1].stride,
132  qspec[0].order,
133  qspec[1].order,
134  qspec[0].breakpoints[qspec[0].index],
135  qspec[0].breakpoints[qspec[0].index+1],
136  qspec[1].breakpoints[qspec[1].index],
137  qspec[1].breakpoints[qspec[1].index+1] );
138  } else {
139  REAL *ps = cpts;
140  ps += qspec[0].offset;
141  ps += qspec[0].index * qspec[0].order * qspec[0].stride;
142  backend.curvpts( mapdesc->getType(), ps,
143  qspec[0].stride,
144  qspec[0].order,
145  qspec[0].breakpoints[qspec[0].index],
146  qspec[0].breakpoints[qspec[0].index+1] );
147  }
148 }
149 
150 /*--------------------------------------------------------------------------
151  * Quilt::downloadAll - download each map that contains the current patch
152  *--------------------------------------------------------------------------
153  */
154 
155 void
156 Quilt::downloadAll( REAL *pta, REAL *ptb, Backend &backend )
157 {
158  for( Quilt *m = this; m; m=m->next ) {
159  m->select( pta, ptb );
160  m->download( backend );
161  }
162 }
163 
164 /*--------------------------------------------------------------------------
165  * Quilt::isCulled - determine if an entire quilt is trivially rejected.
166  *--------------------------------------------------------------------------
167  */
168 
169 int
171 {
172  if( mapdesc->isCulling() )
174  qspec[0].order * qspec[0].width, qspec[0].stride,
175  qspec[1].order * qspec[1].width, qspec[1].stride );
176  else
177  return CULL_ACCEPT;
178 }
179 
180 /*---------------------------------------------------------------------------
181  * Quilt::getRange - retrieve the valid paramater range of a set of quilts
182  *---------------------------------------------------------------------------
183  */
184 void
186 {
187  getRange( from, to, 0, slist );
188  getRange( from, to, 1, tlist );
189 }
190 
191 /*---------------------------------------------------------------------------
192  * Quilt::getRange - retrieve the valid paramater range of a set of quilts
193  *---------------------------------------------------------------------------
194  */
195 void
197 {
198  Quilt *maps = this;
199  from[i] = maps->qspec[i].breakpoints[0];
200  to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width];
201  int maxpts = 0;
202  Quilt_ptr m;
203  for( m=maps; m; m=m->next ) {
204  if( m->qspec[i].breakpoints[0] > from[i] )
205  from[i] = m->qspec[i].breakpoints[0];
206  if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] )
207  to[i] = m->qspec[i].breakpoints[m->qspec[i].width];
208  maxpts += m->qspec[i].width + 1;
209  }
210 
211  list.grow( maxpts );
212 
213  for( m=maps; m; m=m->next )
214  for( int j=0; j<=m->qspec[i].width; j++ ) {
215  list.add( m->qspec[i].breakpoints[j] );
216  }
217 
218  list.filter( );
219  list.taper( from[i], to[i] );
220 }
221 
222 void
224 {
225  getRange( from, to, 0, slist );
226 }
227 
228 void
230 {
231  findSampleRates( slist, tlist );
232  rate[0] = qspec[0].step_size;
233  rate[1] = qspec[1].step_size;
234 
235  for( Quilt *q = next; q; q = q->next ) {
236  q->findSampleRates( slist, tlist );
237  if( q->qspec[0].step_size < rate[0] )
238  rate[0] = q->qspec[0].step_size;
239  if( q->qspec[1].step_size < rate[1] )
240  rate[1] = q->qspec[1].step_size;
241  }
242 }
243 
244 void
246 {
248  (qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]);
250  (qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]);
251 
252  for( int i = slist.start; i < slist.end-1; i++ ) {
253  for( int j = tlist.start; j < tlist.end-1; j++ ) {
254 
255  REAL pta[2], ptb[2];
256  pta[0] = slist.pts[i];
257  ptb[0] = slist.pts[i+1];
258  pta[1] = tlist.pts[j];
259  ptb[1] = tlist.pts[j+1];
260  Patchlist patchlist( this, pta, ptb );
261  patchlist.getstepsize();
262 
263  {
264  float edge_len_s = min(glu_abs(ptb[0]-pta[0]),1.0);
265  float edge_len_t = min(glu_abs(ptb[1]-pta[1]),1.0);
266 
267  if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size )
268  qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s;
269  if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size )
270  qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t;
271  }
272  }
273  }
274 }
void findSampleRates(Flist &slist, Flist &tlist)
Definition: quilt.cc:245
GLint GLint GLsizei width
Definition: gl.h:1546
Definition: quilt.h:64
Mapdesc * mapdesc
Definition: quilt.h:67
Definition: flist.h:42
Quiltspec qspec[MAXDIM]
Definition: quilt.h:69
REAL * pts
Definition: flist.h:44
REAL glu_abs(REAL x)
Definition: simplemath.h:50
Definition: _slist.h:198
void curvpts(long, REAL *, long, int, REAL, REAL)
Definition: backend.cc:541
#define assert(x)
Definition: debug.h:53
void getstepsize(void)
Definition: patchlist.cc:114
int rate
Definition: pcmconverter.c:99
const GLfloat * m
Definition: glext.h:10848
long getType(void)
Definition: mapdesc.h:168
REAL getStepsize(int)
Definition: patchlist.h:70
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int stride
Definition: quilt.h:52
int offset
Definition: quilt.h:54
#define CULL_ACCEPT
Definition: defines.h:42
int getNcoords(void)
Definition: mapdesc.h:198
REAL step_size
Definition: quilt.h:58
#define DEF_PATCH_STEPSIZE
Definition: quilt.cc:51
void deleteMe(Pool &)
Definition: bufpool.h:136
class Quilt * Quilt_ptr
Definition: quilt.h:90
Quiltspec_ptr eqspec
Definition: quilt.h:70
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
GLsizei stride
Definition: glext.h:5848
void findRates(Flist &slist, Flist &tlist, REAL[2])
Definition: quilt.cc:229
Definition: bufpool.h:50
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
int isCulled(void)
Definition: quilt.cc:170
Quilt(Mapdesc *)
Definition: quilt.cc:55
int width
Definition: quilt.h:53
Definition: _list.h:228
void surfpts(long, REAL *, long, long, int, int, REAL, REAL, REAL, REAL)
Definition: backend.cc:105
int index
Definition: quilt.h:56
void deleteMe(Pool &)
Definition: quilt.cc:61
iterator end()
Definition: _slist.h:420
void show()
Definition: quilt.cc:80
void getRange(REAL *, REAL *, Flist &, Flist &)
Definition: quilt.cc:185
int order
Definition: quilt.h:55
#define min(a, b)
Definition: monoChain.cc:55
void downloadAll(REAL *, REAL *, Backend &)
Definition: quilt.cc:156
int start
Definition: flist.h:46
Knot * breakpoints
Definition: quilt.h:59
REAL * cpts
Definition: quilt.h:68
Quilt * next
Definition: quilt.h:71
int getDimension(void)
Definition: quilt.h:78
GLfloat GLfloat p
Definition: glext.h:8902
float REAL
Definition: types.h:41
CardRegion * from
Definition: spigame.cpp:19
int end
Definition: flist.h:47
int xformAndCullCheck(REAL *, int, int, int, int)
Definition: mapdesc.cc:355
int k
Definition: mpi.c:3369
int isCulling(void)
Definition: mapdesc.h:261
#define printf
Definition: config.h:203
void download(Backend &)
Definition: quilt.cc:121
void select(REAL *, REAL *)
Definition: quilt.cc:106