home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / shareware / crystalppc / texture.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  5KB  |  212 lines

  1. #ifndef TEXTURE_H
  2. #define TEXTURE_H
  3.  
  4. //vonmir
  5. //extern "C" {
  6.  
  7. //ersatzlos gestrichen
  8. //
  9. #include "gifload.h"
  10. //vonmir
  11. //}
  12.  
  13. //ersatzlos gestrichen
  14. //
  15.  
  16. #define ZDIST_MIPMAP1 15.
  17. #define ZDIST_MIPMAP2 30.
  18. #define ZDIST_MIPMAP3 60.
  19.  
  20. class Filter;
  21. class Textures;
  22. class PolyTexture;
  23.  
  24. struct ColorUsage
  25. {
  26.   int cnt;      // How many times is this color used in a texture
  27.   int idx;      // Original index in texture
  28.   RGBcolor color;
  29. };
  30.  
  31. class Texture
  32. {
  33. private:
  34.   Graphic_file* gf;
  35.   ColorUsage* usage;
  36.   char name[50];
  37.   int transparent;
  38.   int filtered;
  39.   Filter** filters;
  40.   int shf_w, shf_h;
  41.   int and_w, and_h;
  42.  
  43. public:
  44.   Texture (char* name);         // Create a texture directly from a graphic file.
  45.   Texture (int w, int h);       // Create an empty texture with a width and height.
  46.   ~Texture ();
  47.  
  48.   void set_transparent (int col);
  49.   int get_transparent () { return transparent; }
  50.   void set_filter (int col, Filter* filter);
  51.   int get_filtered () { return filtered; }
  52.   Filter** get_filters () { return filters; }
  53.  
  54.   char* get_name () { return name; }
  55.   unsigned char* get_bitmap () { return gf->bitmap; }
  56.   int get_width () { return gf->width; }
  57.   int get_height () { return gf->height; }
  58.   int get_w_shift () { return shf_w; }
  59.   int get_h_shift () { return shf_h; }
  60.   int get_w_mask () { return and_w; }
  61.   int get_h_mask () { return and_h; }
  62.  
  63.   int get_pal_red (int idx) { return gf->palette[idx].red; }
  64.   int get_pal_green (int idx) { return gf->palette[idx].green; }
  65.   int get_pal_blue (int idx) { return gf->palette[idx].blue; }
  66.   int get_num_colors () { return gf->palette_entries; }
  67.   void compute_color_usage ();
  68.   void clear_color_usage ();
  69.   ColorUsage& get_usage (int idx) { return usage[idx]; }
  70.   void remap_palette (Textures* new_palette);
  71.  
  72.   void save (FILE* fp, int indent);
  73.   void load (char** buf);
  74. };
  75.  
  76. typedef unsigned char RGBmap[256];
  77.  
  78. #define TABLE_WHITE 0
  79. #define TABLE_RED 1
  80. #define TABLE_GREEN 2
  81. #define TABLE_BLUE 3
  82.  
  83. #define MIPMAP_UGLY 0
  84. #define MIPMAP_DEFAULT 1
  85. #define MIPMAP_NICE 2
  86.  
  87. class Textures
  88. {
  89. private:
  90.   Texture** textures;
  91.   int num_textures;
  92.   int max_textures;
  93.   int rnum_textures;
  94.   int offs_mipmap1;
  95.   int offs_mipmap2;
  96.   int offs_mipmap3;
  97.   RGBcolor pal[256];
  98.   RGBmap light[256];
  99.   RGBmap red_light[256];
  100.   RGBmap blue_light[256];
  101.   int alloc[256];
  102.   int red_color, yellow_color, green_color, blue_color, white_color, black_color;
  103.   int level1, level2, level3;
  104.  
  105.   // Configuration values.
  106.   int prefered_dist, prefered_col_dist;
  107.   int color_table1;
  108.   int color_table2;
  109.   int color_table3;
  110.   int mipmap_nice;
  111.  
  112.   void read_config ();
  113.  
  114. public:
  115.   int mipmapped;
  116.   int textured;
  117.   int do_lighting;
  118.  
  119. public:
  120.   Textures (int max);
  121.   ~Textures ();
  122.  
  123.   Texture* new_texture (char* name);
  124.   Texture* get_texture (int idx) { return textures[idx]; }
  125.   int get_texture_idx (char* name);
  126.  
  127.   int find_rgb_map (int r, int g, int b, int map_type, int l);
  128.   int find_rgb (int r, int g, int b);
  129.   int find_rgb_slow (int r, int g, int b);
  130.   int alloc_rgb (int r, int g, int b, int dist);
  131.   void compute_palette ();
  132.   void compute_light_tables ();
  133.   void alloc_palette (Graphics* g);
  134.  
  135.   void create_mipmap_textures ();
  136.   int get_mipmap1_nr (int texnr) { return texnr+offs_mipmap1; }
  137.   int get_mipmap2_nr (int texnr) { return texnr+offs_mipmap2; }
  138.   int get_mipmap3_nr (int texnr) { return texnr+offs_mipmap3; }
  139.  
  140.   int get_pal_alloced (int idx) { return alloc[idx]; }
  141.   int get_pal_red (int idx) { return pal[idx].red; }
  142.   int get_pal_green (int idx) { return pal[idx].green; }
  143.   int get_pal_blue (int idx) { return pal[idx].blue; }
  144.  
  145.   unsigned char* get_light_table (int lev) { return (unsigned char*)(light[lev]); }
  146.   unsigned char* get_red_light_table (int lev) { return (unsigned char*)(red_light[lev]); }
  147.   unsigned char* get_blue_light_table (int lev) { return (unsigned char*)(blue_light[lev]); }
  148.   int get_level1 () { return level1; }
  149.   int get_level2 () { return level2; }
  150.   int get_level3 () { return level3; }
  151.  
  152.   void save (FILE* fp, int indent);
  153.   void load (char** buf);
  154.  
  155.   int red () { return red_color; }
  156.   int blue () { return blue_color; }
  157.   int yellow () { return yellow_color; }
  158.   int green () { return green_color; }
  159.   int white () { return white_color; }
  160.   int black () { return black_color; }
  161. };
  162.  
  163. class Filter
  164. {
  165. private:
  166.   unsigned char* trans;
  167.   char name[30];
  168.  
  169. public:
  170.   Filter (char* name);
  171.   ~Filter ();
  172.  
  173.   static void init_filters (Textures* tex);
  174.  
  175.   char* get_name () { return name; }
  176.  
  177.   void mean_with_color (Textures* tex, int rg, int gg, int bg, int weight);
  178.   void add_color (Textures* tex, int rg, int gg, int bg);
  179.  
  180.   void very_light_glass (Textures* tex);
  181.   void light_glass (Textures* tex);
  182.   void dark_glass (Textures* tex);
  183.   void medium_glass (Textures* tex);
  184.   void very_dark_glass (Textures* tex);
  185.   void transparent (Textures* tex);
  186.  
  187.   unsigned char translate (int idx) { return trans[idx]; }
  188. };
  189.  
  190. #define MAX_CACHE_SIZE 5000000
  191.  
  192. class TextureCache
  193. {
  194. private:
  195.   PolyTexture* first, * last;
  196.   long total_size;
  197.   int total_textures;
  198.  
  199. public:
  200.   TextureCache ();
  201.   ~TextureCache ();
  202.  
  203.   void clear ();
  204.   void use_texture (PolyTexture* pt, Textures* textures);
  205.  
  206.   void dump ();
  207. };
  208.  
  209. extern TextureCache cache;
  210.  
  211. #endif /*TEXTURE_H*/
  212.