| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* trimvertexpool.c++ - $Revision: 1.1.1.1 $ |
| 39 |
* Derrick Burns - 1991 |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "glimports.h" |
| 43 |
#include "myassert.h" |
| 44 |
#include "mystdio.h" |
| 45 |
#include "mystring.h" |
| 46 |
#include "trimvertex.h" |
| 47 |
#include "trimvertpool.h" |
| 48 |
#include "bufpool.h" |
| 49 |
|
| 50 |
/*---------------------------------------------------------------------------- |
| 51 |
* TrimVertexPool::TrimVertexPool |
| 52 |
*---------------------------------------------------------------------------- |
| 53 |
*/ |
| 54 |
TrimVertexPool::TrimVertexPool( void ) |
| 55 |
: pool( sizeof(TrimVertex)*3, 32, "Threevertspool" ) |
| 56 |
{ |
| 57 |
// initialize array of pointers to vertex lists |
| 58 |
nextvlistslot = 0; |
| 59 |
vlistsize = INIT_VERTLISTSIZE; |
| 60 |
vlist = new TrimVertex_p[vlistsize]; |
| 61 |
} |
| 62 |
|
| 63 |
/*---------------------------------------------------------------------------- |
| 64 |
* TrimVertexPool::~TrimVertexPool |
| 65 |
*---------------------------------------------------------------------------- |
| 66 |
*/ |
| 67 |
TrimVertexPool::~TrimVertexPool( void ) |
| 68 |
{ |
| 69 |
// free all arrays of TrimVertices vertices |
| 70 |
while( nextvlistslot ) { |
| 71 |
delete[] vlist[--nextvlistslot]; |
| 72 |
} |
| 73 |
|
| 74 |
// reallocate space for array of pointers to vertex lists |
| 75 |
if( vlist ) delete[] vlist; |
| 76 |
} |
| 77 |
|
| 78 |
/*---------------------------------------------------------------------------- |
| 79 |
* TrimVertexPool::clear |
| 80 |
*---------------------------------------------------------------------------- |
| 81 |
*/ |
| 82 |
void |
| 83 |
TrimVertexPool::clear( void ) |
| 84 |
{ |
| 85 |
// reinitialize pool of 3 vertex arrays |
| 86 |
pool.clear(); |
| 87 |
|
| 88 |
// free all arrays of TrimVertices vertices |
| 89 |
while( nextvlistslot ) { |
| 90 |
delete[] vlist[--nextvlistslot]; |
| 91 |
vlist[nextvlistslot] = 0; |
| 92 |
} |
| 93 |
|
| 94 |
// reallocate space for array of pointers to vertex lists |
| 95 |
if( vlist ) delete[] vlist; |
| 96 |
vlist = new TrimVertex_p[vlistsize]; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
/*---------------------------------------------------------------------------- |
| 101 |
* TrimVertexPool::get - allocate a vertex list |
| 102 |
*---------------------------------------------------------------------------- |
| 103 |
*/ |
| 104 |
TrimVertex * |
| 105 |
TrimVertexPool::get( int n ) |
| 106 |
{ |
| 107 |
TrimVertex *v; |
| 108 |
if( n == 3 ) { |
| 109 |
v = (TrimVertex *) pool.new_buffer(); |
| 110 |
} else { |
| 111 |
if( nextvlistslot == vlistsize ) { |
| 112 |
vlistsize *= 2; |
| 113 |
TrimVertex_p *nvlist = new TrimVertex_p[vlistsize]; |
| 114 |
memcpy( nvlist, vlist, nextvlistslot * sizeof(TrimVertex_p) ); |
| 115 |
if( vlist ) delete[] vlist; |
| 116 |
vlist = nvlist; |
| 117 |
} |
| 118 |
v = vlist[nextvlistslot++] = new TrimVertex[n]; |
| 119 |
} |
| 120 |
return v; |
| 121 |
} |