]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/bbcache.hxx
Harald Johnson:
[simgear.git] / simgear / scene / sky / bbcache.hxx
1 // Billboard helper class
2 //
3 // Written by Harald JOHNSEN, started April 2005.
4 //
5 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
6 //
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.
11 //
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.
16 //
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, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20 //
21 //
22
23 #ifndef _BBCACHE_HXX
24 #define _BBCACHE_HXX
25
26
27 #include <plib/sg.h>
28 #include <plib/ssg.h>
29 #include <simgear/screen/extensions.hxx>
30 #include <simgear/screen/RenderTexture.h>
31
32 class SGBbCache {
33 private:
34
35         typedef struct {
36                 GLuint  texID;
37                 int             cldID;
38                 float   angleX, angleY;
39                 // creation frame number for debug only
40                 int             frame;
41                 // last time this entry was used
42                 int             frameUsed;
43         } bbInfo;
44
45         void freeTextureMemory(void);
46         bool allocTextureMemory(int count, int textureDimension);
47
48         // a list of impostors
49         bbInfo  *bbList;
50         int             bbListCount;
51         int             textureWH;
52         int             cacheSizeKb;
53
54         // for debug only, stats
55         int             builtBBCount;
56         // count of generated BB during the current frame
57         int             builtBBframe;
58
59         long    frameNumber;
60         RenderTexture *rt;
61         bool    rtAvailable;
62
63 public:
64         SGBbCache(void);
65         ~SGBbCache(void);
66
67         // call this first to initialize everything, cacheCount is the number of texture to allocate
68         void init(int cacheCount);
69
70         // free one cache slot, usualy when the cached object is destroyed
71         void free(int bbId, int cldId);
72
73         // allocate a new texture, return an index in the cache
74         int alloc(int cldId);
75
76         // give the texture name to use
77         GLuint QueryTexID(int cldId, int bbId);
78
79         // save the rendered texture from the current context to a new texture
80         void setTextureData(int bbId);
81
82         // start the rendering of a billboard in the RTT context
83         void beginCapture(void);
84
85         // adjust the projection matrix of the RTT context to the size of the object
86         void setRadius(float radius, float dist_center);
87
88         // forget the RTT and go back to the previous rendering context
89         void endCapture(void);
90
91         // for debugging only, give the number of frames since the inpostor was built
92         int queryImpostorAge(int bbId);
93
94         // can we still use this impostor ?
95         bool isBbValid( int cloudId, int bbId, float angleY, float angleX);
96
97         // save view angles of this billboard
98         void setReference( int cloudId, int bbId, float angleY, float angleX);
99
100         // prepare the cache for the rendering of a new frame
101         void startNewFrame(void);
102
103         // alloc the impostors texture memory given the size of the memory pool
104         // if sizeKb == 0 then the memory pool is freed and impostors are disabled
105         bool setCacheSize(int sizeKb);
106
107         // alloc the impostors texture memory given the count and size of texture
108         // if count == 0 then the memory pool is freed and impostors are disabled
109         bool setCacheSize(int count, int textureDimension);
110
111         // return the size of the memory pool used by texture impostors
112         int queryCacheSize(void);
113
114         int maxImpostorRegenFrame;
115 };
116
117 #endif // _BBCACHE_HXX