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.
28 #include <simgear/screen/extensions.hxx>
29 #include <simgear/screen/RenderTexture.h>
32 * Billboard helper class.
38 * storage class for impostors state.
42 /// the texture used by this impostor
44 /// the cloud owning this impostor
47 // creation frame number for debug only
49 /// last time this entry was used
51 /// dirty flag for lazy rebuild of impostor
55 void freeTextureMemory(void);
57 * Allocate and initialize the texture pool.
58 * @param count the number of texture to build
59 * @param textureDimension size in pixel of each texture
61 bool allocTextureMemory(int count, int textureDimension);
63 // a list of impostors
69 // for debug only, stats
71 // count of generated BB during the current frame
83 * Call this first to initialize the cache.
84 * @param cacheCount the number of texture to allocate
86 void init(int cacheCount);
89 * Free one cache slot, usualy when the cached object is destroyed.
90 * @param bbId the impostor slot
91 * @param cldId the cloud identifier
93 void free(int bbId, int cldId);
96 * Allocate a new impostor.
97 * @param cldId the cloud identifier
98 * @return an impostor slot
100 int alloc(int cldId);
103 * Query the texture name associated with this cloud.
104 * @param bbId the impostor slot
105 * @param cldId the cloud identifier
106 * @return a texture name
108 GLuint QueryTexID(int cldId, int bbId);
111 * Save the rendered texture from the current context to a new texture.
112 * @param bbId the impostor slot
114 void setTextureData(int bbId);
117 * Start the rendering of a billboard in the RTT context.
119 void beginCapture(void);
122 * Adjust the projection matrix of the RTT context to the size of the object.
123 * @param radius radius in meters of the object to draw
124 * @param dist_center distance between viewer and object
126 void setRadius(float radius, float dist_center);
129 * Forget the RTT and go back to the previous rendering context.
131 void endCapture(void);
134 * For debugging only, give the number of frames since the impostor was built.
135 * @param bbId the impostor slot
137 int queryImpostorAge(int bbId);
140 * Can we still use this impostor ? Check versus view angles and load.
141 * @param bbId the impostor slot
142 * @param cloudId the cloud identifier
143 * @param angleY rotation needed to face the impostor
144 * @param angleX rotation needed to face the impostor
146 bool isBbValid( int cloudId, int bbId, float angleY, float angleX);
149 * Save view angles of this billboard.
150 * @param bbId the impostor slot
151 * @param cloudId the cloud identifier
152 * @param angleY rotation needed to face the impostor
153 * @param angleX rotation needed to face the impostor
155 void setReference( int cloudId, int bbId, float angleY, float angleX);
158 * Prepare the cache for the rendering of a new frame.
159 * Do some garbage collect of unused impostors
161 void startNewFrame(void);
164 * Alloc the impostors texture memory given the size of the memory pool.
165 * If sizeKb == 0 then the memory pool is freed and impostors are disabled
166 * @param sizeKb size of the texture pool in K
168 bool setCacheSize(int sizeKb);
171 * Alloc the impostors texture memory given the count and size of texture.
172 * If count == 0 then the memory pool is freed and impostors are disabled
173 * @param count number of texture to allocate
174 * @param textureDimension size of each texture in pixels
176 bool setCacheSize(int count, int textureDimension);
178 bool isRttAvailable(void) { return rtAvailable; }
181 * Force all impostors to be rebuilt.
183 void invalidateCache(void);
186 * Flag the impostor for a lazy update.
187 * @param bbId the impostor slot
188 * @param cldId the cloud identifier
190 void invalidate(int cldId, int bbId);
193 * Return the size of the memory pool used by texture impostors.
194 * @return size of the memory pool in Kb
196 int queryCacheSize(void);
199 * Maximum number of impostor to regen each frame.
200 * If we can't update all of them we will do that in the next frame
202 int maxImpostorRegenFrame;
205 #endif // _BBCACHE_HXX