]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/sky/bbcache.hxx
Merge branch 'ehofman/sound'
[simgear.git] / simgear / scene / sky / bbcache.hxx
index f2ba56419d30315629f54509ab1b5e79b0c6c3b4..021e5487b5ddd419fdb36ca01db6a05267db4033 100644 (file)
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 //
 
 
 
 #include <plib/sg.h>
-#include <plib/ssg.h>
 #include <simgear/screen/extensions.hxx>
 #include <simgear/screen/RenderTexture.h>
 
+/**
+ * Billboard helper class.
+ */
 class SGBbCache {
 private:
 
-       typedef struct {
+       /**
+       * storage class for impostors state.
+       */
+       class bbInfo {
+       public:
+               /// the texture used by this impostor
                GLuint  texID;
+               /// the cloud owning this impostor
                int             cldID;
                float   angleX, angleY;
                // creation frame number for debug only
                int             frame;
-               // last time this entry was used
+               /// last time this entry was used
                int             frameUsed;
-       } bbInfo;
+               /// dirty flag for lazy rebuild of impostor
+               bool    needRedraw;
+       };
 
        void freeTextureMemory(void);
+    /**
+     * Allocate and initialize the texture pool.
+     * @param count the number of texture to build
+     * @param textureDimension size in pixel of each texture
+     */
        bool allocTextureMemory(int count, int textureDimension);
 
        // a list of impostors
@@ -64,53 +79,126 @@ public:
        SGBbCache(void);
        ~SGBbCache(void);
 
-       // call this first to initialize everything, cacheCount is the number of texture to allocate
+    /**
+     * Call this first to initialize the cache.
+     * @param cacheCount the number of texture to allocate
+     */
        void init(int cacheCount);
 
-       // free one cache slot, usualy when the cached object is destroyed
+    /**
+     * Free one cache slot, usualy when the cached object is destroyed.
+     * @param bbId the impostor slot
+     * @param cldId the cloud identifier
+     */
        void free(int bbId, int cldId);
 
-       // allocate a new texture, return an index in the cache
+    /**
+     * Allocate a new impostor.
+     * @param cldId the cloud identifier
+     * @return an impostor slot
+     */
        int alloc(int cldId);
 
-       // give the texture name to use
+    /**
+     * Query the texture name associated with this cloud.
+     * @param bbId the impostor slot
+     * @param cldId the cloud identifier
+     * @return a texture name
+     */
        GLuint QueryTexID(int cldId, int bbId);
 
-       // save the rendered texture from the current context to a new texture
+    /**
+     * Save the rendered texture from the current context to a new texture.
+     * @param bbId the impostor slot
+     */
        void setTextureData(int bbId);
 
-       // start the rendering of a billboard in the RTT context
+    /**
+     * Start the rendering of a billboard in the RTT context.
+     */
        void beginCapture(void);
 
-       // adjust the projection matrix of the RTT context to the size of the object
+    /**
+     * Adjust the projection matrix of the RTT context to the size of the object.
+     * @param radius radius in meters of the object to draw
+     * @param dist_center distance between viewer and object
+     */
        void setRadius(float radius, float dist_center);
 
-       // forget the RTT and go back to the previous rendering context
+    /**
+     * Forget the RTT and go back to the previous rendering context.
+     */
        void endCapture(void);
 
-       // for debugging only, give the number of frames since the inpostor was built
+    /**
+     * For debugging only, give the number of frames since the impostor was built.
+     * @param bbId the impostor slot
+     */
        int queryImpostorAge(int bbId);
 
-       // can we still use this impostor ?
+    /**
+     * Can we still use this impostor ? Check versus view angles and load.
+     * @param bbId the impostor slot
+     * @param cloudId the cloud identifier
+     * @param angleY rotation needed to face the impostor
+     * @param angleX rotation needed to face the impostor
+     */
        bool isBbValid( int cloudId, int bbId, float angleY, float angleX);
 
-       // save view angles of this billboard
+    /**
+     * Save view angles of this billboard.
+     * @param bbId the impostor slot
+     * @param cloudId the cloud identifier
+     * @param angleY rotation needed to face the impostor
+     * @param angleX rotation needed to face the impostor
+     */
        void setReference( int cloudId, int bbId, float angleY, float angleX);
 
-       // prepare the cache for the rendering of a new frame
+    /**
+     * Prepare the cache for the rendering of a new frame.
+     * Do some garbage collect of unused impostors
+     */
        void startNewFrame(void);
 
-       // alloc the impostors texture memory given the size of the memory pool
-       // if sizeKb == 0 then the memory pool is freed and impostors are disabled
+    /**
+     * Alloc the impostors texture memory given the size of the memory pool.
+        * If sizeKb == 0 then the memory pool is freed and impostors are disabled
+     * @param sizeKb size of the texture pool in K
+     */
        bool setCacheSize(int sizeKb);
 
-       // alloc the impostors texture memory given the count and size of texture
-       // if count == 0 then the memory pool is freed and impostors are disabled
+    /**
+     * Alloc the impostors texture memory given the count and size of texture.
+        * If count == 0 then the memory pool is freed and impostors are disabled
+     * @param count number of texture to allocate
+     * @param textureDimension size of each texture in pixels
+     */
        bool setCacheSize(int count, int textureDimension);
 
-       // return the size of the memory pool used by texture impostors
+       bool isRttAvailable(void) { return rtAvailable; }
+
+    /**
+     * Force all impostors to be rebuilt.
+     */
+       void invalidateCache(void);
+
+    /**
+     * Flag the impostor for a lazy update.
+     * @param bbId the impostor slot
+     * @param cldId the cloud identifier
+     */
+       void invalidate(int cldId, int bbId);
+
+    /**
+     * Return the size of the memory pool used by texture impostors.
+     * @return size of the memory pool in Kb
+     */
        int queryCacheSize(void);
 
+    /**
+     * Maximum number of impostor to regen each frame.
+     * If we can't update all of them we will do that in the next frame
+     */
        int maxImpostorRegenFrame;
 };