1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #include "glue/cg.h"
34 #include "coindefs.h"
35 
36 #include <cassert>
37 #include <cstdlib>
38 #include <cstring>
39 #include <cstdio>
40 
41 #include <Inventor/C/basic.h>
42 #include <Inventor/C/errors/debugerror.h>
43 #include <Inventor/C/tidbits.h>
44 #include <Inventor/C/glue/dl.h>
45 
46 #include "threads/threadsutilp.h"
47 #include "tidbitsp.h"
48 
49 /* ********************************************************************** */
50 
51 typedef CGcontext (*glue_cgCreateContext_t)(void);
52 typedef void (*glue_cgDestroyContext_t)(CGcontext);
53 typedef CGbool (*glue_cgIsContext_t)(CGcontext);
54 typedef const char * (*glue_cgGetLastListing_t)(CGcontext);
55 typedef CGprogram (*glue_cgCreateProgram_t)(CGcontext, CGenum, const char *, CGprofile, const char *, const char **);
56 typedef void (*glue_cgDestroyProgram_t)(CGprogram);
57 typedef CGbool (*glue_cgIsProgram_t)(CGprogram);
58 typedef const char * (*glue_cgGetProfileString_t)(CGprofile);
59 typedef CGerror (*glue_cgGetError_t)(void);
60 typedef const char * (*glue_cgGetErrorString_t)(CGerror);
61 typedef void (*glue_cgSetErrorCallback_t)(CGerrorCallbackFunc);
62 typedef CGbool (*glue_cgIsParameter_t)(CGparameter);
63 typedef CGtype (*glue_cgGetParameterType_t)(CGparameter);
64 typedef CGparameter (*glue_cgGetNamedParameter_t)(CGprogram, const char *);
65 typedef const char * (*glue_cgGetTypeString_t)(CGtype);
66 typedef CGbool (*glue_cgGLIsProfileSupported_t)(CGprofile);
67 typedef void (*glue_cgGLEnableProfile_t)(CGprofile);
68 typedef void (*glue_cgGLDisableProfile_t)(CGprofile);
69 typedef CGprofile (*glue_cgGLGetLatestProfile_t)(CGGLenum);
70 typedef void (*glue_cgGLLoadProgram_t)(CGprogram);
71 typedef void (*glue_cgGLBindProgram_t)(CGprogram);
72 typedef void (*glue_cgGLSetParameter1f_t)(CGparameter, float);
73 typedef void (*glue_cgGLSetParameter2f_t)(CGparameter, float, float);
74 typedef void (*glue_cgGLSetParameter3f_t)(CGparameter, float, float, float);
75 typedef void (*glue_cgGLSetParameter4f_t)(CGparameter, float, float, float, float);
76 typedef void (*glue_cgGLSetStateMatrixParameter_t)(CGparameter, CGGLenum, CGGLenum);
77 typedef void (*glue_cgGLSetParameterArray1f_t)(CGparameter, long, long, const float *);
78 typedef void (*glue_cgGLSetParameterArray2f_t)(CGparameter, long, long, const float *);
79 typedef void (*glue_cgGLSetParameterArray3f_t)(CGparameter, long, long, const float *);
80 typedef void (*glue_cgGLSetParameterArray4f_t)(CGparameter, long, long, const float *);
81 typedef void (*glue_cgGLSetMatrixParameterfc_t)(CGparameter, const float *);
82 typedef void (*glue_cgGLSetMatrixParameterArrayfc_t)(CGparameter, long, long, const float *);
83 typedef int (*glue_cgGetArrayDimension_t)(CGparameter);
84 typedef int (*glue_cgGetArraySize_t)(CGparameter, int);
85 
86 /* texture parameters */
87 typedef void (*glue_cgGLSetManageTextureParameters_t)(CGcontext, CGbool flag);
88 
89 /* CgFX */
90 typedef CGeffect (*glue_cgCreateEffect_t)(CGcontext, const char *, const char **);
91 typedef CGprogram (*glue_cgCreateProgramFromEffect_t)(CGeffect, CGprofile, const char * entry, const char ** args);
92 typedef void (*glue_cgDestroyEffect_t)(CGeffect);
93 typedef CGbool (*glue_cgIsEffect_t)(CGeffect);
94 typedef void (*glue_cgGLRegisterStates_t)(CGcontext);
95 
96 typedef CGtechnique (*glue_cgGetFirstTechnique_t)(CGeffect);
97 typedef CGtechnique (*glue_cgGetNextTechnique_t)(CGtechnique);
98 typedef CGbool (*glue_cgValidateTechnique_t)(CGtechnique);
99 
100 typedef CGpass (*glue_cgGetFirstPass_t)(CGtechnique);
101 typedef CGpass (*glue_cgGetNextPass_t)(CGpass);
102 typedef void (*glue_cgSetPassState_t)(CGpass);
103 typedef void (*glue_cgResetPassState_t)(CGpass);
104 
105 
106 
107 typedef struct {
108   int available;
109   int cgfx_available;
110 
111   glue_cgCreateContext_t cgCreateContext;
112   glue_cgDestroyContext_t cgDestroyContext;
113   glue_cgIsContext_t cgIsContext;
114   glue_cgGetLastListing_t cgGetLastListing;
115   glue_cgCreateProgram_t cgCreateProgram;
116   glue_cgDestroyProgram_t cgDestroyProgram;
117   glue_cgIsProgram_t cgIsProgram;
118   glue_cgGetProfileString_t cgGetProfileString;
119   glue_cgGetError_t cgGetError;
120   glue_cgGetErrorString_t cgGetErrorString;
121   glue_cgSetErrorCallback_t cgSetErrorCallback;
122   glue_cgIsParameter_t cgIsParameter;
123   glue_cgGetParameterType_t cgGetParameterType;
124   glue_cgGetNamedParameter_t cgGetNamedParameter;
125   glue_cgGetTypeString_t cgGetTypeString;
126   glue_cgGLIsProfileSupported_t cgGLIsProfileSupported;
127   glue_cgGLEnableProfile_t cgGLEnableProfile;
128   glue_cgGLDisableProfile_t cgGLDisableProfile;
129   glue_cgGLGetLatestProfile_t cgGLGetLatestProfile;
130   glue_cgGLLoadProgram_t cgGLLoadProgram;
131   glue_cgGLBindProgram_t cgGLBindProgram;
132   glue_cgGLSetParameter1f_t cgGLSetParameter1f;
133   glue_cgGLSetParameter2f_t cgGLSetParameter2f;
134   glue_cgGLSetParameter3f_t cgGLSetParameter3f;
135   glue_cgGLSetParameter4f_t cgGLSetParameter4f;
136   glue_cgGLSetStateMatrixParameter_t cgGLSetStateMatrixParameter;
137   glue_cgGLSetParameterArray1f_t cgGLSetParameterArray1f;
138   glue_cgGLSetParameterArray2f_t cgGLSetParameterArray2f;
139   glue_cgGLSetParameterArray3f_t cgGLSetParameterArray3f;
140   glue_cgGLSetParameterArray4f_t cgGLSetParameterArray4f;
141   glue_cgGLSetMatrixParameterfc_t cgGLSetMatrixParameterfc;
142   glue_cgGLSetMatrixParameterArrayfc_t cgGLSetMatrixParameterArrayfc;
143   glue_cgGetArrayDimension_t cgGetArrayDimension;
144   glue_cgGetArraySize_t cgGetArraySize;
145 
146   /* texture parameters */
147   glue_cgGLSetManageTextureParameters_t cgGLSetManageTextureParameters;
148 
149   /* CgFX */
150   glue_cgCreateEffect_t cgCreateEffect;
151   glue_cgCreateProgramFromEffect_t cgCreateProgramFromEffect;
152   glue_cgDestroyEffect_t cgDestroyEffect;
153   glue_cgIsEffect_t cgIsEffect;
154   glue_cgGLRegisterStates_t cgGLRegisterStates;
155 
156   glue_cgGetFirstTechnique_t cgGetFirstTechnique;
157   glue_cgGetNextTechnique_t cgGetNextTechnique;
158   glue_cgValidateTechnique_t cgValidateTechnique;
159 
160   glue_cgGetFirstPass_t cgGetFirstPass;
161   glue_cgGetNextPass_t cgGetNextPass;
162   glue_cgSetPassState_t cgSetPassState;
163   glue_cgResetPassState_t cgResetPassState;
164 
165 } cc_cgglue_t;
166 
167 /* ********************************************************************** */
168 
169 static cc_cgglue_t * cg_instance = NULL;
170 /* Cg is split into two dll's under Windows. Need two libhandles */
171 static cc_libhandle cg_libhandle = NULL;
172 static cc_libhandle cg_libhandle2 = NULL;
173 static int cg_failed_to_load = 0;
174 
175 /* ********************************************************************** */
176 
177 /* Cleans up at exit. */
178 static void
cgglue_cleanup(void)179 cgglue_cleanup(void)
180 {
181 #ifdef CGLIB_RUNTIME_LINKING
182   if (cg_libhandle) { cc_dl_close(cg_libhandle); }
183   if (cg_libhandle2) { cc_dl_close(cg_libhandle2); }
184 #endif /* CGLIB_RUNTIME_LINKING */
185   assert(cg_instance);
186   free(cg_instance);
187 
188   /* restore variables to initial value */
189   cg_instance = NULL;
190   cg_libhandle = NULL;
191   cg_libhandle2 = NULL;
192   cg_failed_to_load = 0;
193 }
194 
195 /* ********************************************************************** */
196 
197 static const cc_cgglue_t *
cgglue_init(void)198 cgglue_init(void)
199 {
200   CC_SYNC_BEGIN(cgglue_init);
201 
202   if (!cg_instance && !cg_failed_to_load) {
203     /* First invocation, do initializations. */
204     cc_cgglue_t * zi = (cc_cgglue_t *)malloc(sizeof(cc_cgglue_t));
205     (void)coin_atexit((coin_atexit_f *)cgglue_cleanup, CC_ATEXIT_DYNLIBS);
206 
207     /* The common case is that the library is either available from
208        the linking process or we're successfully going to link it
209        in. */
210     zi->available = 1;
211     zi->cgfx_available = 1;
212 
213 #ifdef CGLIB_RUNTIME_LINKING
214     {
215       int idx;
216       /* FIXME: should we get the system shared library name from an
217          Autoconf check? 20000930 mortene. */
218       const char * possiblelibnames[] = {
219         NULL, /* is set below */
220         "CgGL", "libCgGL", "libCgGL.so",
221 
222         /* FIXME: not yet tested on Mac OS X. 20050125 mortene. */
223         "libCgGL.dylib",
224         NULL
225       };
226 
227       possiblelibnames[0] = coin_getenv("COIN_CG_LIBNAME");
228       idx = possiblelibnames[0] ? 0 : 1;
229 
230       while (!cg_libhandle && possiblelibnames[idx]) {
231         cg_libhandle = cc_dl_open(possiblelibnames[idx]);
232         idx++;
233       }
234 
235       if (!cg_libhandle) {
236         zi->available = 0;
237         zi->cgfx_available = 0;
238         cg_failed_to_load = 1;
239       }
240       /* Cg is split into two dll's under Windows */
241       if (cg_libhandle) {
242         /* FIXME: do a proper possiblenames while loop? pederb, 2005-11-28 */
243         cg_libhandle2 = cc_dl_open("Cg");
244       }
245     }
246     /* Define CGGLUE_REGISTER_FUNC macro. Casting the type is
247        necessary for this file to be compatible with C++ compilers. */
248 #define CGGLUE_REGISTER_FUNC(_funcsig_, _funcname_) \
249     do { \
250       zi->_funcname_ = (_funcsig_)cc_dl_sym(cg_libhandle, SO__QUOTE(_funcname_)); \
251       if (!zi->_funcname_ && cg_libhandle2) { \
252         zi->_funcname_ = (_funcsig_)cc_dl_sym(cg_libhandle2, SO__QUOTE(_funcname_)); \
253       } \
254       if (zi->_funcname_ == NULL) { \
255         zi->available = 0; \
256         zi->cgfx_available = 0; \
257       } \
258     } while (0)
259 #define CGGLUE_REGISTER_FXFUNC(_funcsig_, _funcname_) \
260     do { \
261       zi->_funcname_ = (_funcsig_)cc_dl_sym(cg_libhandle, SO__QUOTE(_funcname_)); \
262       if (!zi->_funcname_ && cg_libhandle2) { \
263         zi->_funcname_ = (_funcsig_)cc_dl_sym(cg_libhandle2, SO__QUOTE(_funcname_)); \
264       } \
265       if (zi->_funcname_ == NULL) { \
266         zi->cgfx_available = 0; \
267       } \
268     } while (0)
269 
270 #elif defined(HAVE_CGLIB) /* no dynamic linking, but static linking possible */
271 
272     /* Define CGGLUE_REGISTER_FUNC macro. */
273 #define CGGLUE_REGISTER_FUNC(_funcsig_, _funcname_) \
274     zi->_funcname_ = (_funcsig_)_funcname_
275 
276 #define CGGLUE_REGISTER_FXFUNC(_funcsig_, _funcname_) \
277     zi->_funcname_ = (_funcsig_)_funcname_
278 
279 #else /* no dynamic linking, and Cg-lib not available for static linking */
280     zi->available = 0;
281     zi->cgfx_available = 0;
282     /* Define CGGLUE_REGISTER_FUNC macro. */
283 #define CGGLUE_REGISTER_FUNC(_funcsig_, _funcname_) \
284     zi->_funcname_ = NULL
285 #define CGGLUE_REGISTER_FXFUNC(_funcsig_, _funcname_) \
286     zi->_funcname_ = NULL
287 
288 #endif /* no linking */
289 
290     if (zi->available) {
291       CGGLUE_REGISTER_FUNC(glue_cgCreateContext_t, cgCreateContext);
292       CGGLUE_REGISTER_FUNC(glue_cgDestroyContext_t, cgDestroyContext);
293       CGGLUE_REGISTER_FUNC(glue_cgIsContext_t, cgIsContext);
294       CGGLUE_REGISTER_FUNC(glue_cgGetLastListing_t, cgGetLastListing);
295       CGGLUE_REGISTER_FUNC(glue_cgCreateProgram_t, cgCreateProgram);
296       CGGLUE_REGISTER_FUNC(glue_cgDestroyProgram_t, cgDestroyProgram);
297       CGGLUE_REGISTER_FUNC(glue_cgIsProgram_t, cgIsProgram);
298       CGGLUE_REGISTER_FUNC(glue_cgGetProfileString_t, cgGetProfileString);
299       CGGLUE_REGISTER_FUNC(glue_cgGetError_t, cgGetError);
300       CGGLUE_REGISTER_FUNC(glue_cgGetErrorString_t, cgGetErrorString);
301       CGGLUE_REGISTER_FUNC(glue_cgSetErrorCallback_t, cgSetErrorCallback);
302       CGGLUE_REGISTER_FUNC(glue_cgIsParameter_t, cgIsParameter);
303       CGGLUE_REGISTER_FUNC(glue_cgGetParameterType_t, cgGetParameterType);
304       CGGLUE_REGISTER_FUNC(glue_cgGetNamedParameter_t, cgGetNamedParameter);
305       CGGLUE_REGISTER_FUNC(glue_cgGetTypeString_t, cgGetTypeString);
306       CGGLUE_REGISTER_FUNC(glue_cgGLIsProfileSupported_t, cgGLIsProfileSupported);
307       CGGLUE_REGISTER_FUNC(glue_cgGLEnableProfile_t, cgGLEnableProfile);
308       CGGLUE_REGISTER_FUNC(glue_cgGLDisableProfile_t, cgGLDisableProfile);
309       CGGLUE_REGISTER_FUNC(glue_cgGLGetLatestProfile_t, cgGLGetLatestProfile);
310       CGGLUE_REGISTER_FUNC(glue_cgGLLoadProgram_t, cgGLLoadProgram);
311       CGGLUE_REGISTER_FUNC(glue_cgGLBindProgram_t, cgGLBindProgram);
312       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameter1f_t, cgGLSetParameter1f);
313       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameter2f_t, cgGLSetParameter2f);
314       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameter3f_t, cgGLSetParameter3f);
315       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameter4f_t, cgGLSetParameter4f);
316       CGGLUE_REGISTER_FUNC(glue_cgGLSetStateMatrixParameter_t, cgGLSetStateMatrixParameter);
317       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameterArray1f_t, cgGLSetParameterArray1f);
318       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameterArray2f_t, cgGLSetParameterArray2f);
319       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameterArray3f_t, cgGLSetParameterArray3f);
320       CGGLUE_REGISTER_FUNC(glue_cgGLSetParameterArray4f_t, cgGLSetParameterArray4f);
321       CGGLUE_REGISTER_FUNC(glue_cgGLSetMatrixParameterfc_t, cgGLSetMatrixParameterfc);
322       CGGLUE_REGISTER_FUNC(glue_cgGLSetMatrixParameterArrayfc_t, cgGLSetMatrixParameterArrayfc);
323       CGGLUE_REGISTER_FUNC(glue_cgGetArrayDimension_t, cgGetArrayDimension);
324       CGGLUE_REGISTER_FUNC(glue_cgGetArraySize_t, cgGetArraySize);
325 
326       CGGLUE_REGISTER_FUNC(glue_cgGLSetManageTextureParameters_t, cgGLSetManageTextureParameters);
327 
328       /* CgFX */
329       CGGLUE_REGISTER_FXFUNC(glue_cgCreateEffect_t, cgCreateEffect);
330       CGGLUE_REGISTER_FXFUNC(glue_cgCreateProgramFromEffect_t, cgCreateProgramFromEffect);
331       CGGLUE_REGISTER_FXFUNC(glue_cgDestroyEffect_t, cgDestroyEffect);
332       CGGLUE_REGISTER_FXFUNC(glue_cgIsEffect_t, cgIsEffect);
333       CGGLUE_REGISTER_FXFUNC(glue_cgGLRegisterStates_t, cgGLRegisterStates);
334       CGGLUE_REGISTER_FXFUNC(glue_cgGetFirstTechnique_t, cgGetFirstTechnique);
335       CGGLUE_REGISTER_FXFUNC(glue_cgGetNextTechnique_t, cgGetNextTechnique);
336       CGGLUE_REGISTER_FXFUNC(glue_cgValidateTechnique_t, cgValidateTechnique);
337       CGGLUE_REGISTER_FXFUNC(glue_cgGetFirstPass_t, cgGetFirstPass);
338       CGGLUE_REGISTER_FXFUNC(glue_cgGetNextPass_t, cgGetNextPass);
339       CGGLUE_REGISTER_FXFUNC(glue_cgSetPassState_t, cgSetPassState);
340       CGGLUE_REGISTER_FXFUNC(glue_cgResetPassState_t, cgResetPassState);
341     }
342     /* Do this late, so we can detect recursive calls to this function. */
343     cg_instance = zi;
344   }
345   CC_SYNC_END(cgglue_init);
346   return cg_instance;
347 }
348 
349 /* ********************************************************************** */
350 
351 int
cc_cgglue_available(void)352 cc_cgglue_available(void)
353 {
354   if (cg_instance && cg_instance->available) { return 1; }
355   else { cgglue_init(); }
356   return (cg_instance && cg_instance->available);
357 }
358 
359 int
glue_cgglue_cgfx_available()360 glue_cgglue_cgfx_available()
361 {
362   if (cg_instance && cg_instance->available && cg_instance->cgfx_available) { return 1; }
363   else { cgglue_init(); }
364   return (cg_instance && cg_instance->available && cg_instance->cgfx_available);
365 }
366 
367 /* ********************************************************************** */
368 
369 CGcontext
glue_cgCreateContext(void)370 glue_cgCreateContext(void)
371 {
372   return cg_instance->cgCreateContext();
373 }
374 
375 void
glue_cgDestroyContext(CGcontext c)376 glue_cgDestroyContext(CGcontext c)
377 {
378   cg_instance->cgDestroyContext(c);
379 }
380 
381 CGbool
glue_cgIsContext(CGcontext c)382 glue_cgIsContext(CGcontext c)
383 {
384   return cg_instance->cgIsContext(c);
385 }
386 
387 const char *
glue_cgGetLastListing(CGcontext c)388 glue_cgGetLastListing(CGcontext c)
389 {
390   return cg_instance->cgGetLastListing(c);
391 }
392 
393 CGprogram
glue_cgCreateProgram(CGcontext c,CGenum e,const char * cp0,CGprofile p,const char * cp1,const char ** cpp)394 glue_cgCreateProgram(CGcontext c, CGenum e, const char * cp0, CGprofile p,
395                      const char * cp1, const char ** cpp)
396 {
397   return cg_instance->cgCreateProgram(c, e, cp0, p, cp1, cpp);
398 }
399 
400 void
glue_cgDestroyProgram(CGprogram p)401 glue_cgDestroyProgram(CGprogram p)
402 {
403   cg_instance->cgDestroyProgram(p);
404 }
405 
406 CGbool
glue_cgIsProgram(CGprogram p)407 glue_cgIsProgram(CGprogram p)
408 {
409   return cg_instance->cgIsProgram(p);
410 }
411 
412 const char *
glue_cgGetProfileString(CGprofile p)413 glue_cgGetProfileString(CGprofile p)
414 {
415   return cg_instance->cgGetProfileString(p);
416 }
417 
418 CGerror
glue_cgGetError(void)419 glue_cgGetError(void)
420 {
421   return cg_instance->cgGetError();
422 }
423 
424 const char *
glue_cgGetErrorString(CGerror e)425 glue_cgGetErrorString(CGerror e)
426 {
427   return cg_instance->cgGetErrorString(e);
428 }
429 
430 void
glue_cgSetErrorCallback(CGerrorCallbackFunc f)431 glue_cgSetErrorCallback(CGerrorCallbackFunc f)
432 {
433   cg_instance->cgSetErrorCallback(f);
434 }
435 
436 CGbool
glue_cgIsParameter(CGparameter p)437 glue_cgIsParameter(CGparameter p)
438 {
439   return cg_instance->cgIsParameter(p);
440 }
441 
442 CGtype
glue_cgGetParameterType(CGparameter p)443 glue_cgGetParameterType(CGparameter p)
444 {
445   return cg_instance->cgGetParameterType(p);
446 }
447 
448 CGparameter
glue_cgGetNamedParameter(CGprogram p,const char * c)449 glue_cgGetNamedParameter(CGprogram p, const char * c)
450 {
451   return cg_instance->cgGetNamedParameter(p, c);
452 }
453 
454 const char *
glue_cgGetTypeString(CGtype t)455 glue_cgGetTypeString(CGtype t)
456 {
457   return cg_instance->cgGetTypeString(t);
458 }
459 
460 CGbool
glue_cgGLIsProfileSupported(CGprofile p)461 glue_cgGLIsProfileSupported(CGprofile p)
462 {
463   return cg_instance->cgGLIsProfileSupported(p);
464 }
465 
466 void
glue_cgGLEnableProfile(CGprofile p)467 glue_cgGLEnableProfile(CGprofile p)
468 {
469   cg_instance->cgGLEnableProfile(p);
470 }
471 
472 void
glue_cgGLDisableProfile(CGprofile p)473 glue_cgGLDisableProfile(CGprofile p)
474 {
475   cg_instance->cgGLDisableProfile(p);
476 }
477 
478 CGprofile
glue_cgGLGetLatestProfile(CGGLenum e)479 glue_cgGLGetLatestProfile(CGGLenum e)
480 {
481   return cg_instance->cgGLGetLatestProfile(e);
482 }
483 
484 void
glue_cgGLLoadProgram(CGprogram p)485 glue_cgGLLoadProgram(CGprogram p)
486 {
487   cg_instance->cgGLLoadProgram(p);
488 }
489 
490 void
glue_cgGLBindProgram(CGprogram p)491 glue_cgGLBindProgram(CGprogram p)
492 {
493   cg_instance->cgGLBindProgram(p);
494 }
495 
496 void
glue_cgGLSetParameter1f(CGparameter p,float f)497 glue_cgGLSetParameter1f(CGparameter p, float f)
498 {
499   cg_instance->cgGLSetParameter1f(p, f);
500 }
501 
502 void
glue_cgGLSetParameter2f(CGparameter p,float f0,float f1)503 glue_cgGLSetParameter2f(CGparameter p, float f0, float f1)
504 {
505   cg_instance->cgGLSetParameter2f(p, f0, f1);
506 }
507 
508 void
glue_cgGLSetParameter3f(CGparameter p,float f0,float f1,float f2)509 glue_cgGLSetParameter3f(CGparameter p, float f0, float f1, float f2)
510 {
511   cg_instance->cgGLSetParameter3f(p, f0, f1, f2);
512 }
513 
514 void
glue_cgGLSetParameter4f(CGparameter p,float f0,float f1,float f2,float f3)515 glue_cgGLSetParameter4f(CGparameter p, float f0, float f1, float f2, float f3)
516 {
517   cg_instance->cgGLSetParameter4f(p, f0, f1, f2, f3);
518 }
519 
520 void
glue_cgGLSetStateMatrixParameter(CGparameter p,CGGLenum e0,CGGLenum e1)521 glue_cgGLSetStateMatrixParameter(CGparameter p, CGGLenum e0, CGGLenum e1)
522 {
523   cg_instance->cgGLSetStateMatrixParameter(p, e0, e1);
524 }
525 
526 void
glue_cgGLSetParameterArray1f(CGparameter p,long o,long n,const float * v)527 glue_cgGLSetParameterArray1f(CGparameter p, long o, long n, const float *v)
528 {
529   cg_instance->cgGLSetParameterArray1f(p, o, n, v);
530 }
531 
532 void
glue_cgGLSetParameterArray2f(CGparameter p,long o,long n,const float * v)533 glue_cgGLSetParameterArray2f(CGparameter p, long o, long n, const float *v)
534 {
535   cg_instance->cgGLSetParameterArray2f(p, o, n, v);
536 }
537 
538 void
glue_cgGLSetParameterArray3f(CGparameter p,long o,long n,const float * v)539 glue_cgGLSetParameterArray3f(CGparameter p, long o, long n, const float *v)
540 {
541   cg_instance->cgGLSetParameterArray3f(p, o, n, v);
542 }
543 
544 void
glue_cgGLSetParameterArray4f(CGparameter p,long o,long n,const float * v)545 glue_cgGLSetParameterArray4f(CGparameter p, long o, long n, const float *v)
546 {
547   cg_instance->cgGLSetParameterArray4f(p, o, n, v);
548 }
549 
550 void
glue_cgGLSetMatrixParameterfc(CGparameter p,const float * v)551 glue_cgGLSetMatrixParameterfc(CGparameter p, const float *v)
552 {
553   cg_instance->cgGLSetMatrixParameterfc(p, v);
554 }
555 
556 void
glue_cgGLSetMatrixParameterArrayfc(CGparameter p,long o,long n,const float * v)557 glue_cgGLSetMatrixParameterArrayfc(CGparameter p, long o, long n, const float *v)
558 {
559   cg_instance->cgGLSetMatrixParameterArrayfc(p, o, n, v);
560 }
561 
562 int
glue_cgGetArrayDimension(CGparameter p)563 glue_cgGetArrayDimension(CGparameter p)
564 {
565   return cg_instance->cgGetArrayDimension(p);
566 }
567 
568 int
glue_cgGetArraySize(CGparameter p,int dim)569 glue_cgGetArraySize(CGparameter p, int dim)
570 {
571   return cg_instance->cgGetArraySize(p, dim);
572 }
573 
574 /* texture parameters */
575 void
glue_cgGLSetManageTextureParameters(CGcontext context,CGbool flag)576 glue_cgGLSetManageTextureParameters(CGcontext context, CGbool flag)
577 {
578   cg_instance->cgGLSetManageTextureParameters(context, flag);
579 }
580 
581 /* CgFX */
582 CGeffect
glue_cgCreateEffect(CGcontext context,const char * program,const char ** args)583 glue_cgCreateEffect(CGcontext context, const char * program, const char ** args)
584 {
585   assert(cg_instance);
586   return cg_instance->cgCreateEffect(context, program, args);
587 }
588 
589 CGprogram
glue_cgCreateProgramFromEffect(CGeffect effect,CGprofile profile,const char * entry,const char ** args)590 glue_cgCreateProgramFromEffect(CGeffect effect, CGprofile profile, const char * entry, const char ** args)
591 {
592   assert(cg_instance);
593   return cg_instance->cgCreateProgramFromEffect(effect, profile, entry, args);
594 }
595 
596 void
glue_cgDestroyEffect(CGeffect COIN_UNUSED_ARG (effect))597 glue_cgDestroyEffect(CGeffect COIN_UNUSED_ARG(effect))
598 {
599 }
600 
601 CGbool
glue_cgIsEffect(CGeffect COIN_UNUSED_ARG (effect))602 glue_cgIsEffect(CGeffect COIN_UNUSED_ARG(effect))
603 {
604   return FALSE;
605 }
606 
607 void
glue_cgGLRegisterStates(CGcontext c)608 glue_cgGLRegisterStates(CGcontext c)
609 {
610   assert(cg_instance);
611   cg_instance->cgGLRegisterStates(c);
612 }
613 
614 /* ********************************************************************** */
615