1 #include <stdlib.h> 2 #include <GL/gl.h> 3 4 #define MINTOL 1.0e-15 5 #define ABS(x) ( (x)>0 ? (x) : -(x) ) 6 7 extern GLuint xcGenLists( GLsizei i ); 8 9 /* 10 The three routines below (findList1, compareParams1, and 11 makeModelPtr1) are slightly modified versions of libaux findList, 12 compareParams, and makeModelPtr routines (from "OpenGL Programming 13 Guide", file: shapes.c). Below is the corresponding copyright. 14 15 * (c) Copyright 1993, Silicon Graphics, Inc. 16 * ALL RIGHTS RESERVED 17 * Permission to use, copy, modify, and distribute this software for 18 * any purpose and without fee is hereby granted, provided that the above 19 * copyright notice appear in all copies and that both the copyright notice 20 * and this permission notice appear in supporting documentation, and that 21 * the name of Silicon Graphics, Inc. not be used in advertising 22 * or publicity pertaining to distribution of the software without specific, 23 * written prior permission. 24 * 25 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 26 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 27 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 28 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 29 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 30 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 31 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 32 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 33 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 34 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 35 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 36 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 37 * 38 * US Government Users Restricted Rights 39 * Use, duplication, or disclosure by the Government is subject to 40 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 41 * (c)(1)(ii) of the Rights in Technical Data and Computer Software 42 * clause at DFARS 252.227-7013 and/or in similar or successor 43 * clauses in the FAR or the DOD or NASA FAR Supplement. 44 * Unpublished-- rights reserved under the copyright laws of the 45 * United States. Contractor/manufacturer is Silicon Graphics, 46 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 47 * 48 * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 49 50 */ 51 52 GLuint findList1 (int lindex, GLdouble *paramArray, int size); 53 static int compareParams1 (GLdouble *oneArray, GLdouble *twoArray, int size); 54 GLuint makeModelPtr1 (int lindex, GLdouble *sizeArray, int count); 55 56 /*****************************************************************************/ 57 /* THIS IS FOR LISTS */ 58 /* structure for each geometric object */ 59 typedef struct model { 60 GLuint list; /* display list to render object */ 61 struct model *ptr; /* pointer to next object */ 62 int numParam; /* # of parameters */ 63 GLdouble *params; /* array with parameters */ 64 } MODEL, *MODELPTR; 65 66 /* array of linked lists--used to keep track of display lists 67 * for each different type of geometric object. 68 */ 69 static MODELPTR lists[25] = { 70 NULL, NULL, NULL, NULL, NULL, 71 NULL, NULL, NULL, NULL, NULL, 72 NULL, NULL, NULL, NULL, NULL, 73 NULL, NULL, NULL, NULL, NULL, 74 NULL, NULL, NULL, NULL, NULL 75 }; 76 77 78 /****************NEXT THREE FUNCTIONS ARE LISTS MANAGEMENT *******************/ 79 /* linked lists--display lists for each different 80 * type of geometric objects. The linked list is 81 * searched, until an object of the requested 82 * size is found. If no geometric object of that size 83 * has been previously made, a new one is created. 84 */ 85 GLuint 86 findList1 (int lindex, GLdouble *paramArray, int size) 87 { 88 MODELPTR endList; 89 90 endList = lists[lindex]; 91 while (endList != NULL) { 92 if (compareParams1 (endList->params, paramArray, size)) 93 return (endList->list); 94 endList = endList->ptr; 95 } 96 /* if not found, return 0 and calling routine should 97 * make a new list 98 */ 99 return (0); 100 } 101 102 103 static int 104 compareParams1 (GLdouble *oneArray, GLdouble *twoArray, int size) 105 { 106 int i; 107 int matches = 1; 108 GLdouble diff; 109 110 for (i = 0; (i < size) && matches; i++) { 111 diff = *oneArray++ - *twoArray++; 112 if ( ABS(diff) > MINTOL ) 113 matches = 0; 114 } 115 return (matches); 116 } 117 118 119 GLuint 120 makeModelPtr1 (int lindex, GLdouble sizeArray[], int count) 121 { 122 int i; 123 MODELPTR newModel; 124 GLdouble *size; 125 126 size = (GLdouble *) malloc( sizeof(GLdouble) * count ); 127 for (i=0; i<count; i++) 128 size[i] = sizeArray[i]; 129 130 newModel = (MODELPTR) malloc (sizeof (MODEL)); 131 newModel->list = xcGenLists (1); 132 newModel->numParam = count; 133 newModel->params = size; 134 newModel->ptr = lists[lindex]; 135 lists[lindex] = newModel; 136 137 return (newModel->list); 138 } 139