1 // Billboard helper class
3 // Written by Harald JOHNSEN, started April 2005.
5 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <simgear/screen/extensions.hxx>
30 #include <simgear/screen/RenderTexture.h>
33 * Billboard helper class.
39 * storage class for impostors state.
43 /// the texture used by this impostor
45 /// the cloud owning this impostor
48 // creation frame number for debug only
50 /// last time this entry was used
52 /// dirty flag for lazy rebuild of impostor
56 void freeTextureMemory(void);
58 * Allocate and initialize the texture pool.
59 * @param count the number of texture to build
60 * @param textureDimension size in pixel of each texture
62 bool allocTextureMemory(int count, int textureDimension);
64 // a list of impostors
70 // for debug only, stats
72 // count of generated BB during the current frame
84 * Call this first to initialize the cache.
85 * @param cacheCount the number of texture to allocate
87 void init(int cacheCount);
90 * Free one cache slot, usualy when the cached object is destroyed.
91 * @param bbId the impostor slot
92 * @param cldId the cloud identifier
94 void free(int bbId, int cldId);
97 * Allocate a new impostor.
98 * @param cldId the cloud identifier
99 * @return an impostor slot
101 int alloc(int cldId);
104 * Query the texture name associated with this cloud.
105 * @param bbId the impostor slot
106 * @param cldId the cloud identifier
107 * @return a texture name
109 GLuint QueryTexID(int cldId, int bbId);
112 * Save the rendered texture from the current context to a new texture.
113 * @param bbId the impostor slot
115 void setTextureData(int bbId);
118 * Start the rendering of a billboard in the RTT context.
120 void beginCapture(void);
123 * Adjust the projection matrix of the RTT context to the size of the object.
124 * @param radius radius in meters of the object to draw
125 * @param dist_center distance between viewer and object
127 void setRadius(float radius, float dist_center);
130 * Forget the RTT and go back to the previous rendering context.
132 void endCapture(void);
135 * For debugging only, give the number of frames since the impostor was built.
136 * @param bbId the impostor slot
138 int queryImpostorAge(int bbId);
141 * Can we still use this impostor ? Check versus view angles and load.
142 * @param bbId the impostor slot
143 * @param cloudId the cloud identifier
144 * @param angleY rotation needed to face the impostor
145 * @param angleX rotation needed to face the impostor
147 bool isBbValid( int cloudId, int bbId, float angleY, float angleX);
150 * Save view angles of this billboard.
151 * @param bbId the impostor slot
152 * @param cloudId the cloud identifier
153 * @param angleY rotation needed to face the impostor
154 * @param angleX rotation needed to face the impostor
156 void setReference( int cloudId, int bbId, float angleY, float angleX);
159 * Prepare the cache for the rendering of a new frame.
160 * Do some garbage collect of unused impostors
162 void startNewFrame(void);
165 * Alloc the impostors texture memory given the size of the memory pool.
166 * If sizeKb == 0 then the memory pool is freed and impostors are disabled
167 * @param sizeKb size of the texture pool in K
169 bool setCacheSize(int sizeKb);
172 * Alloc the impostors texture memory given the count and size of texture.
173 * If count == 0 then the memory pool is freed and impostors are disabled
174 * @param count number of texture to allocate
175 * @param textureDimension size of each texture in pixels
177 bool setCacheSize(int count, int textureDimension);
179 bool isRttAvailable(void) { return rtAvailable; }
182 * Force all impostors to be rebuilt.
184 void invalidateCache(void);
187 * Flag the impostor for a lazy update.
188 * @param bbId the impostor slot
189 * @param cldId the cloud identifier
191 void invalidate(int cldId, int bbId);
194 * Return the size of the memory pool used by texture impostors.
195 * @return size of the memory pool in Kb
197 int queryCacheSize(void);
200 * Maximum number of impostor to regen each frame.
201 * If we can't update all of them we will do that in the next frame
203 int maxImpostorRegenFrame;
206 #endif // _BBCACHE_HXX