1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3bf215546Sopenharmony_ci * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice including the dates of first publication and
13bf215546Sopenharmony_ci * either this permission notice or a reference to
14bf215546Sopenharmony_ci * http://oss.sgi.com/projects/FreeB/
15bf215546Sopenharmony_ci * shall be included in all copies or substantial portions of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20bf215546Sopenharmony_ci * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21bf215546Sopenharmony_ci * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22bf215546Sopenharmony_ci * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23bf215546Sopenharmony_ci * SOFTWARE.
24bf215546Sopenharmony_ci *
25bf215546Sopenharmony_ci * Except as contained in this notice, the name of Silicon Graphics, Inc.
26bf215546Sopenharmony_ci * shall not be used in advertising or otherwise to promote the sale, use or
27bf215546Sopenharmony_ci * other dealings in this Software without prior written authorization from
28bf215546Sopenharmony_ci * Silicon Graphics, Inc.
29bf215546Sopenharmony_ci */
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "packrender.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/*
34bf215546Sopenharmony_ci** Routines to pack evaluator maps into the transport buffer.  Maps are
35bf215546Sopenharmony_ci** allowed to have extra arbitrary data, so these routines extract just
36bf215546Sopenharmony_ci** the information that the GL needs.
37bf215546Sopenharmony_ci*/
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_civoid
40bf215546Sopenharmony_ci__glFillMap1f(GLint k, GLint order, GLint stride,
41bf215546Sopenharmony_ci              const GLfloat * points, GLubyte * pc)
42bf215546Sopenharmony_ci{
43bf215546Sopenharmony_ci   if (stride == k) {
44bf215546Sopenharmony_ci      /* Just copy the data */
45bf215546Sopenharmony_ci      __GLX_PUT_FLOAT_ARRAY(0, points, order * k);
46bf215546Sopenharmony_ci   }
47bf215546Sopenharmony_ci   else {
48bf215546Sopenharmony_ci      GLint i;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci      for (i = 0; i < order; i++) {
51bf215546Sopenharmony_ci         __GLX_PUT_FLOAT_ARRAY(0, points, k);
52bf215546Sopenharmony_ci         points += stride;
53bf215546Sopenharmony_ci         pc += k * __GLX_SIZE_FLOAT32;
54bf215546Sopenharmony_ci      }
55bf215546Sopenharmony_ci   }
56bf215546Sopenharmony_ci}
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_civoid
59bf215546Sopenharmony_ci__glFillMap1d(GLint k, GLint order, GLint stride,
60bf215546Sopenharmony_ci              const GLdouble * points, GLubyte * pc)
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci   if (stride == k) {
63bf215546Sopenharmony_ci      /* Just copy the data */
64bf215546Sopenharmony_ci      __GLX_PUT_DOUBLE_ARRAY(0, points, order * k);
65bf215546Sopenharmony_ci   }
66bf215546Sopenharmony_ci   else {
67bf215546Sopenharmony_ci      GLint i;
68bf215546Sopenharmony_ci      for (i = 0; i < order; i++) {
69bf215546Sopenharmony_ci         __GLX_PUT_DOUBLE_ARRAY(0, points, k);
70bf215546Sopenharmony_ci         points += stride;
71bf215546Sopenharmony_ci         pc += k * __GLX_SIZE_FLOAT64;
72bf215546Sopenharmony_ci      }
73bf215546Sopenharmony_ci   }
74bf215546Sopenharmony_ci}
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_civoid
77bf215546Sopenharmony_ci__glFillMap2f(GLint k, GLint majorOrder, GLint minorOrder,
78bf215546Sopenharmony_ci              GLint majorStride, GLint minorStride,
79bf215546Sopenharmony_ci              const GLfloat * points, GLfloat * data)
80bf215546Sopenharmony_ci{
81bf215546Sopenharmony_ci   GLint i, j, x;
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   if ((minorStride == k) && (majorStride == minorOrder * k)) {
84bf215546Sopenharmony_ci      /* Just copy the data */
85bf215546Sopenharmony_ci      __GLX_MEM_COPY(data, points, majorOrder * majorStride *
86bf215546Sopenharmony_ci                     __GLX_SIZE_FLOAT32);
87bf215546Sopenharmony_ci      return;
88bf215546Sopenharmony_ci   }
89bf215546Sopenharmony_ci   for (i = 0; i < majorOrder; i++) {
90bf215546Sopenharmony_ci      for (j = 0; j < minorOrder; j++) {
91bf215546Sopenharmony_ci         for (x = 0; x < k; x++) {
92bf215546Sopenharmony_ci            data[x] = points[x];
93bf215546Sopenharmony_ci         }
94bf215546Sopenharmony_ci         points += minorStride;
95bf215546Sopenharmony_ci         data += k;
96bf215546Sopenharmony_ci      }
97bf215546Sopenharmony_ci      points += majorStride - minorStride * minorOrder;
98bf215546Sopenharmony_ci   }
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_civoid
102bf215546Sopenharmony_ci__glFillMap2d(GLint k, GLint majorOrder, GLint minorOrder,
103bf215546Sopenharmony_ci              GLint majorStride, GLint minorStride,
104bf215546Sopenharmony_ci              const GLdouble * points, GLdouble * data)
105bf215546Sopenharmony_ci{
106bf215546Sopenharmony_ci   int i, j, x;
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   if ((minorStride == k) && (majorStride == minorOrder * k)) {
109bf215546Sopenharmony_ci      /* Just copy the data */
110bf215546Sopenharmony_ci      __GLX_MEM_COPY(data, points, majorOrder * majorStride *
111bf215546Sopenharmony_ci                     __GLX_SIZE_FLOAT64);
112bf215546Sopenharmony_ci      return;
113bf215546Sopenharmony_ci   }
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci#ifdef __GLX_ALIGN64
116bf215546Sopenharmony_ci   x = k * __GLX_SIZE_FLOAT64;
117bf215546Sopenharmony_ci#endif
118bf215546Sopenharmony_ci   for (i = 0; i < majorOrder; i++) {
119bf215546Sopenharmony_ci      for (j = 0; j < minorOrder; j++) {
120bf215546Sopenharmony_ci#ifdef __GLX_ALIGN64
121bf215546Sopenharmony_ci         __GLX_MEM_COPY(data, points, x);
122bf215546Sopenharmony_ci#else
123bf215546Sopenharmony_ci         for (x = 0; x < k; x++) {
124bf215546Sopenharmony_ci            data[x] = points[x];
125bf215546Sopenharmony_ci         }
126bf215546Sopenharmony_ci#endif
127bf215546Sopenharmony_ci         points += minorStride;
128bf215546Sopenharmony_ci         data += k;
129bf215546Sopenharmony_ci      }
130bf215546Sopenharmony_ci      points += majorStride - minorStride * minorOrder;
131bf215546Sopenharmony_ci   }
132bf215546Sopenharmony_ci}
133