1 /*
2  * Copyright (C) 1997-2005, R3vis Corporation.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA, or visit http://www.gnu.org/copyleft/lgpl.html.
18  *
19  * Original Contributor:
20  *   Wes Bethel, R3vis Corporation, Marin County, California
21  * Additional Contributor(s):
22  *
23  * The OpenRM project is located at http://openrm.sourceforge.net/.
24  */
25 /*
26  * $Id: rminit.c,v 1.7 2005/03/19 17:17:19 wes Exp $
27  * Version: $Name: OpenRM-1-6-0-2-RC2 $
28  * $Revision: 1.7 $
29  * $Log: rminit.c,v $
30  * Revision 1.7  2005/03/19 17:17:19  wes
31  * Win32 clock init stuff, and deinit upon rmFinish (in response to report
32  * of 8-byte memory leak).
33  *
34  * Revision 1.6  2005/02/19 16:41:34  wes
35  * Distro sync and consolidation.
36  * Support for NO_PTHREADS build.
37  *
38  * Revision 1.5  2005/01/23 17:04:03  wes
39  * Copyright update to 2005.
40  *
41  * Revision 1.4  2004/03/30 14:13:31  wes
42  * Fixed declarations and man page docs for several routines.
43  *
44  * Revision 1.3  2004/01/16 16:45:12  wes
45  * Updated copyright line for 2004.
46  *
47  * Revision 1.2  2003/02/02 02:07:15  wes
48  * Updated copyright to 2003.
49  *
50  * Revision 1.1.1.1  2003/01/28 02:15:23  wes
51  * Manual rebuild of rm150 repository.
52  *
53  * Revision 1.10  2003/01/16 22:21:17  wes
54  * Updated all source files to reflect new organization of header files:
55  * all header files formerly located in include/rmaux, include/rmi, include/rmv
56  * are now located in include/rm.
57  *
58  * Revision 1.9  2002/09/17 14:15:52  wes
59  * Added conditional call to rmComponentManagerPrintStatus() inside rmFinish.
60  * Set the DEBUG_FINAL_MEMCHECK bit on DEBUG_LEVEL to compile this call in
61  * so that applications will see if there are any app-induced memory leaks
62  * at finish time.
63  *
64  * Revision 1.8  2002/08/29 22:20:32  wes
65  *
66  * Massive upgrade to accommodate dynamic object reallocation within
67  * the component manager, and within the context cache. Use the
68  * debug #define DEBUG_LEVEL DEBUG_REALLOC_TRACE to get a printf
69  * whenever a realloc occurs. With this upgrade, there are no
70  * OpenRM limits on the size of the scene graph. There will be external
71  * limits, such as the amount of RAM and the amount of space available
72  * to your OpenGL implementation.
73  *
74  * Revision 1.7  2002/08/19 00:54:27  wes
75  * Added API entries for new experiemental routines to get and set
76  * the size of the OpenRM component manager object pool.
77  *
78  * Revision 1.6  2002/08/17 15:10:11  wes
79  * Added the routine rmInitComponentPoolSize(). This routine can be called
80  * before (and only before) rmInit() to adjust the size of the
81  * component manager's object pool.
82  *
83  * Revision 1.5  2002/04/30 19:31:59  wes
84  * Updated copyright dates.
85  *
86  * Revision 1.4  2001/07/15 17:16:25  wes
87  * Removed dead code.
88  *
89  * Revision 1.3  2001/06/03 20:46:36  wes
90  * Removed unused vars to clean up compile warnings.
91  *
92  * Revision 1.2  2001/03/31 17:12:38  wes
93  * v1.4.0-alpha-2 checkin.
94  *
95  * Revision 1.1  2000/12/03 22:33:06  wes
96  * Initial entry.
97  *
98  */
99 
100 #include <rm/rm.h>
101 #include "rmprivat.h"
102 
103 /*
104  * ----------------------------------------------------
105  * @Name rmInit
106  @pstart
107  void rmInit (void)
108  @pend
109 
110  @astart
111  No arguments.
112  @aend
113 
114  @dstart
115 
116  An initialization routine, rmInit() will perform 4 steps:
117 
118    1) initialize the internal scene graph datastructure
119    2) precompute trigonometric values used for primitive tessellation
120    3) initialize the internal font registry datastructure
121    4) output the OpenRM copyright notice
122 
123  After these steps are performed, RM is not yet fully functional,
124  since a rendering context must be created, bound to an RMpipe, and
125  that context made current in order for rendering to proceed.
126 
127  See rmauxCreateXWindow, rmauxCreateW32Window, rmPipeSetWindow,
128  rmPipeMakeCurrent.
129 
130  @dend
131  * ----------------------------------------------------
132  */
133 void
rmInit(void)134 rmInit (void)
135 {
136     extern RMcompMgrHdr *global_RMimagePool, *global_RMprimitivePool;
137     extern RMcompMgrHdr *global_RMnodePool, *global_RMtexturePool;
138     extern RMcompMgrHdr *global_RMtextPropsPool;
139 
140 #ifdef RM_X
141 
142   /*stat = XInitThreads();   */
143 
144 #ifdef SOLARIS
145     glXInitThreadsSUN();
146 #else
147 
148 #ifndef _NO_PTHREADS
149     pthread_setconcurrency(12);
150 #endif
151 
152 #endif
153 #endif
154 
155 #ifdef RM_WIN
156     private_initTimer();
157 #endif
158 
159     /*
160      * Initialize the component manager, which manages RMimages,
161      * RMprimitives, RMnodes, RMtextures and RMtextProps.
162      */
163     if ((global_RMimagePool = private_rmInitComponentManager(NUM_ITEMS_PER_PAGE,sizeof(RMimage))) == NULL)
164     {
165 	rmError("rmInit() Fatal error: unable to alloc object pool for RMimage objects.");
166 	exit(-1);
167     }
168 
169     if ((global_RMprimitivePool = private_rmInitComponentManager(NUM_ITEMS_PER_PAGE,sizeof(RMprimitive))) == NULL)
170     {
171 	rmError("rmInit() Fatal error: unable to alloc object pool for RMprimitive objects.");
172 	exit(-1);
173     }
174 
175     if ((global_RMnodePool = private_rmInitComponentManager(NUM_ITEMS_PER_PAGE,sizeof(RMnode))) == NULL)
176     {
177 	rmError("rmInit() Fatal error: unable to alloc object pool for RMnode objects.");
178 	exit(-1);
179     }
180 
181     if ((global_RMtexturePool = private_rmInitComponentManager(NUM_ITEMS_PER_PAGE,sizeof(RMtexture))) == NULL)
182     {
183 	rmError("rmInit() Fatal error: unable to alloc object pool for RMtexture objects.");
184 	exit(-1);
185     }
186     if ((global_RMtextPropsPool = private_rmInitComponentManager(NUM_ITEMS_PER_PAGE,sizeof(RMtextProps))) == NULL)
187     {
188 	rmError("rmInit() Fatal error: unable to alloc object pool for RMtextProps objects.");
189 	exit(-1);
190     }
191 
192     private_rmInitCacheKeyMutex();
193 
194     private_initObjectTree();
195     private_initTrigTables();
196 
197     private_rmHello();
198 }
199 
200 
201 /*
202  * ----------------------------------------------------
203  * @Name rmFinish
204  @pstart
205  void rmFinish (void)
206  @pend
207 
208  @astart
209  No arguments.
210  @aend
211 
212  @dstart
213 
214  rmFinish() is used to cleanse the OpenRM component manager, and is
215  typically called as part of an application's shutdown procedure. It
216  will also delete the scene graph rooted at rmRootNode(), but will not
217  delete scene graph nodes that are not part of the directed acyclic
218  graph connected to rmRootNode().
219 
220  @dend
221  * ----------------------------------------------------
222  */
223 void
rmFinish(void)224 rmFinish (void)
225 {
226     extern RMcompMgrHdr *global_RMimagePool, *global_RMprimitivePool;
227     extern RMcompMgrHdr *global_RMnodePool, *global_RMtexturePool;
228     extern RMcompMgrHdr *global_RMtextPropsPool;
229 
230 #ifdef RM_WIN
231     private_deInitTimer();
232 #endif
233 
234     /* grab the root node and do a recursive free */
235     rmSubTreeDelete(rmRootNode());
236 
237 #if (DEBUG_LEVEL & DEBUG_FINAL_MEMCHECK)
238     rmComponentManagerPrintStatus();
239 #endif
240 
241     private_rmDeleteComponentManager(global_RMimagePool);
242     private_rmDeleteComponentManager(global_RMprimitivePool);
243     private_rmDeleteComponentManager(global_RMnodePool);
244     private_rmDeleteComponentManager(global_RMtexturePool);
245     private_rmDeleteComponentManager(global_RMtextPropsPool);
246 
247     private_rmDestroyCacheKeyMutex();
248 }
249 /* EOF */
250 
251