00001 #ifndef GSGL_SG_TEXTURE_H
00002 #define GSGL_SG_TEXTURE_H
00003
00004
00005
00006
00007
00008
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 #include "platform/platform.hpp"
00038 #include "platform/color.hpp"
00039 #include "data/string.hpp"
00040
00041 struct SDL_Surface;
00042
00043 namespace gsgl
00044 {
00045
00046 class string;
00047
00048 namespace platform
00049 {
00050
00051 class mapped_file;
00052
00053
00054
00055 class PLATFORM_API rgba_buffer
00056 {
00057 int width, height;
00058 unsigned char *buffer;
00059
00060 mapped_file *mf;
00061
00062 public:
00063 rgba_buffer(const gsgl::string & fname);
00064 rgba_buffer(SDL_Surface *surface);
00065 rgba_buffer(int width, int height, const color & c = color::WHITE);
00066 ~rgba_buffer();
00067
00068 int get_width() const { return width; }
00069 int get_height() const { return height; }
00070 unsigned char *get_pointer() { return buffer; }
00071
00072 void save(const gsgl::string & fname);
00073
00074 void clear(const color & c);
00075
00076 private:
00077 void flip_vertical();
00078 };
00079
00080
00081
00082
00083 enum texture_format
00084 {
00085 TEXTURE_COLORMAP = 1,
00086 TEXTURE_HEIGHTMAP = 2
00087 };
00088
00089
00090 enum texture_flags
00091 {
00092 TEXTURE_NO_FLAGS = 0,
00093 TEXTURE_LOAD_UNCOMPRESSED = 1 << 0,
00094 TEXTURE_LOAD_NO_PARAMS = 1 << 1,
00095 TEXTURE_RENDER_ANISOTROPIC = 1 << 2,
00096 TEXTURE_ENV_REPLACE = 1 << 3,
00097 TEXTURE_ENV_MODULATE = 1 << 4,
00098 TEXTURE_ENV_MAX = 1 << 5,
00099 TEXTURE_WRAP_REPEAT = 1 << 6,
00100 TEXTURE_WRAP_CLAMP = 1 << 7,
00101 TEXTURE_WRAP_MAX = 1 << 8,
00102 TEXTURE_FILTER_LINEAR = 1 << 9,
00103 TEXTURE_FILTER_MAX = 1 << 10
00104 };
00105
00106
00107
00108
00109 class texture_impl;
00110
00111
00112
00113 class PLATFORM_API texture
00114 {
00115 texture_impl *impl;
00116
00117 gsgl::flags_t flags;
00118 int gl_env, gl_wrap, gl_filter;
00119
00120 public:
00121 explicit texture(const texture & tex);
00122 explicit texture(const gsgl::string & fname,
00123 const gsgl::flags_t flags = TEXTURE_NO_FLAGS,
00124 const texture_format & format = TEXTURE_COLORMAP,
00125 const int & texture_unit = 0);
00126 explicit texture(SDL_Surface *surface,
00127 const gsgl::flags_t flags = TEXTURE_NO_FLAGS,
00128 const texture_format & format = TEXTURE_COLORMAP,
00129 const gsgl::string & identifier = gsgl::string::EMPTY_STRING,
00130 const int & texture_unit = 0);
00131
00132 ~texture();
00133
00134 const int get_texture_unit() const;
00135
00136
00137 void bind(gsgl::flags_t render_flags = TEXTURE_NO_FLAGS);
00138 void unbind();
00139 void update();
00140 void unload();
00141
00142 static gsgl::data_object *create_global_texture_cache();
00143
00144 private:
00145 void assign_gl_modes();
00146 };
00147
00148 }
00149
00150 }
00151
00152 #endif