00001
00002
00003
00004
00005
00006
00007
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef __TEX_MGMT_HEADER__
00048 #define __TEX_MGMT_HEADER__
00049
00050 #include "defs.h"
00051 #include "utils.h"
00052
00053
00054 #ifdef __APPLE__
00055 #include <OpenGL/gl.h>
00056 #include <OpenGL/glu.h>
00057 #else
00058 #include <GL/gl.h>
00059 #include <GL/glu.h>
00060 #endif
00061
00062 namespace hoa_video
00063 {
00064
00065 namespace private_video
00066 {
00067
00068
00069
00071 enum TexSheetType
00072 {
00073 VIDEO_TEXSHEET_INVALID = -1,
00074
00075 VIDEO_TEXSHEET_32x32 = 0,
00076 VIDEO_TEXSHEET_32x64 = 1,
00077 VIDEO_TEXSHEET_64x64 = 2,
00078 VIDEO_TEXSHEET_ANY = 3,
00079
00080 VIDEO_TEXSHEET_TOTAL = 4
00081 };
00082
00083
00084
00085
00087
00090 class TexMemMgr
00091 {
00092 public:
00093
00094 virtual ~TexMemMgr() {}
00095
00097
00100 virtual bool Insert (Image *img)=0;
00101
00103
00106 virtual bool Remove (Image *img)=0;
00107
00109
00112 virtual bool Free (Image *img)=0;
00113
00115
00118 virtual bool Restore (Image *img)=0;
00119 };
00120
00121
00122
00123
00125
00131 class TexSheet
00132 {
00133 public:
00134
00135 TexSheet(int32 w, int32 h, GLuint texID_, TexSheetType type_, bool is_static_);
00136 ~TexSheet();
00137
00139
00143 bool AddImage
00144 (
00145 Image *img,
00146 ImageLoadInfo & load_info
00147 );
00148
00150
00155 bool CopyRect(int32 x, int32 y, private_video::ImageLoadInfo & load_info);
00156
00158
00163 bool CopyScreenRect(int32 x, int32 y, const ScreenRect &screen_rect);
00164
00166
00169 bool RemoveImage (Image *img);
00170
00172
00175 bool FreeImage (Image *img);
00176
00178
00181 bool RestoreImage (Image *img);
00182
00184
00186 bool Unload();
00187
00189
00191 bool Reload();
00192
00194 int32 width;
00195
00197 int32 height;
00198
00200 bool is_static;
00201
00203 TexSheetType type;
00204
00206 TexMemMgr *tex_mem_manager;
00207
00209 GLuint tex_ID;
00210
00212 bool loaded;
00213 };
00214
00215
00216
00217
00219
00222 class FixedImageNode
00223 {
00224 public:
00225
00227 Image *image;
00228
00230 FixedImageNode *next;
00231
00233 FixedImageNode *prev;
00234
00236 int32 block_index;
00237 };
00238
00239
00240
00241
00243
00249 class FixedTexMemMgr : public TexMemMgr
00250 {
00251 public:
00252 FixedTexMemMgr(TexSheet *texSheet, int32 imgW, int32 imgH);
00253 ~FixedTexMemMgr();
00254
00256
00259 bool Insert (Image *img);
00260
00262
00265 bool Remove (Image *img);
00266
00268
00271 bool Free (Image *img);
00272
00274
00277 bool Restore (Image *img);
00278
00279 private:
00280
00282
00285 int32 _CalculateBlockIndex(Image *img);
00286
00288
00290 void _DeleteNode(int32 block_index);
00291
00293 int32 _sheet_width;
00294
00296 int32 _sheet_height;
00297
00299 int32 _image_width;
00300
00302 int32 _image_height;
00303
00304 TexSheet *_tex_sheet;
00305
00307
00313 FixedImageNode *_open_list_head;
00314
00316
00323 FixedImageNode *_open_list_tail;
00324
00326
00329 FixedImageNode *_blocks;
00330 };
00331
00332
00333
00334
00336 class VariableImageNode
00337 {
00338 public:
00339 VariableImageNode()
00340 {
00341 image = NULL;
00342 free = true;
00343 }
00344
00346 Image *image;
00347
00349 bool free;
00350 };
00351
00352
00353
00354
00356
00362 class VariableTexMemMgr : public TexMemMgr
00363 {
00364 public:
00365
00366 VariableTexMemMgr(TexSheet *sheet);
00367 ~VariableTexMemMgr();
00368
00370
00373 bool Insert (Image *img);
00374
00376
00379 bool Remove (Image *img);
00380
00382
00385 bool Free (Image *img);
00386
00388
00391 bool Restore (Image *img);
00392
00393 private:
00394
00396
00403 bool SetBlockProperties
00404 (
00405 Image *img,
00406 bool change_free,
00407 bool change_image,
00408 bool free,
00409 Image *new_image
00410 );
00411
00413 TexSheet *_tex_sheet;
00414
00416 VariableImageNode *_blocks;
00417
00419 int32 _sheet_width;
00420
00422 int32 _sheet_height;
00423 };
00424
00425
00426
00427 }
00428
00429 }
00430
00431
00432
00433 #endif // !__TEX_MGMT_HEADER__