1 /***************************************************************************
2 
3     file                 : grssgext.h
4     created              : Wed Aug 30 01:35:45 CEST 2000
5     copyright            : (C) 2000 by Eric Espie
6     email                : torcs@free.fr
7     version              : $Id: grssgext.h,v 1.7 2005/06/03 23:51:20 berniw Exp $
8 
9 ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   (at your option) any later version.                                   *
17  *                                                                         *
18  ***************************************************************************/
19 
20 /** @file
21     		This file contains the divergences from PLIB.
22 		I derived PLIB objects to adapt them to my needs.
23     @author	<a href=mailto:torcs@free.fr>Eric Espie</a>
24     @version	$Id: grssgext.h,v 1.7 2005/06/03 23:51:20 berniw Exp $
25 */
26 
27 #ifndef _GRSSGEXT_H_
28 #define _GRSSGEXT_H_
29 
30 #include "grtexture.h"
31 
32 /*
33  * An ssgBranch with pre and post draw callbacks.
34  * It must be clear that all the children nodes
35  * have to be non-transparent in order to be
36  * drawn immediately.
37  */
38 class ssgBranchCb : public ssgBranch
39 {
40 
41  protected:
42 
43   ssgCallback  preDrawCB;
44   ssgCallback postDrawCB;
45 
46  public:
47 
ssgBranchCb(void)48   ssgBranchCb(void):ssgBranch() {
49     preDrawCB = NULL;
50     postDrawCB = NULL;
51   }
52 
cull(sgFrustum * f,sgMat4 m,int test_needed)53   void cull  ( sgFrustum *f, sgMat4 m, int test_needed )
54     {
55       int cull_result = cull_test ( f, m, test_needed ) ;
56 
57       if ( cull_result == SSG_OUTSIDE )
58 	return ;
59 
60       if ( preDrawCB != NULL && ! (*preDrawCB)(this) )
61 	return ;
62 
63       for ( ssgEntity *e = getKid ( 0 ) ; e != NULL ; e = getNextKid() )
64 	e -> cull ( f, m, cull_result != SSG_INSIDE ) ;
65 
66       if ( postDrawCB != NULL )
67 	(*postDrawCB)(this) ;
68     }
69 
setCallback(int cb_type,ssgCallback cb)70   void setCallback ( int cb_type, ssgCallback cb ) {
71     if ( cb_type == SSG_CALLBACK_PREDRAW )
72       preDrawCB = cb ;
73     else
74       postDrawCB = cb ;
75   }
76 
77 };
78 
79 
80 /* Use the texture name to select options like mipmap */
81 class ssgLoaderOptionsEx : public ssgLoaderOptions {
82 	public:
ssgLoaderOptionsEx()83 		ssgLoaderOptionsEx():ssgLoaderOptions() {}
84 
85 		ssgTexture* createTexture(char* tfname, int wrapu = TRUE, int wrapv = TRUE, int mipmap = TRUE) {
86 			mipmap = doMipMap(tfname, mipmap);
87 			return ssgLoaderOptions::createTexture(tfname, wrapu, wrapv, mipmap) ;
88 		}
89 
makeModelPath(char * path,const char * fname)90 		virtual void makeModelPath ( char* path, const char *fname ) const
91 		{
92 			ulFindFile ( path, model_dir, fname, NULL ) ;
93 		}
94 
makeTexturePath(char * path,const char * fname)95 		virtual void makeTexturePath ( char* path, const char *fname ) const
96 		{
97 			ulFindFile ( path, texture_dir, fname, NULL ) ;
98 		}
99 };
100 
101 
102 
103 #endif /* _GRSSGEXT_H_ */
104 
105 
106 
107