00001 #ifndef GUI_GL_MATERIAL_HPP
00002 #define GUI_GL_MATERIAL_HPP
00003
00004 #include <utils.hpp>
00005 #include <gui_material.hpp>
00006 #include <gui_color.hpp>
00007
00008 #include <vector>
00009
00010 namespace gui {
00011 namespace gl
00012 {
00013 struct ub32color
00014 {
00015 typedef unsigned char chanel;
00016
00017 chanel r, g, b, a;
00018 };
00019
00021
00025 class material : public gui::material
00026 {
00027 public :
00028
00029 enum wrap
00030 {
00031 REPEAT,
00032 CLAMP
00033 };
00034
00035 enum filter
00036 {
00037 NONE,
00038 LINEAR
00039 };
00040
00041 enum type
00042 {
00043 TYPE_TEXTURE,
00044 TYPE_COLOR
00045 };
00046
00048
00055 material(uint uiWidth, uint uiHeight, wrap mWrap = REPEAT, filter mFilter = NONE, bool bGPUOnly = false);
00056
00058
00060 material(const color& mColor);
00061
00063 ~material();
00064
00066
00068 type get_type() const;
00069
00071
00073 float get_width() const;
00074
00076
00078 float get_height() const;
00079
00081
00088 float get_real_width() const;
00089
00091
00098 float get_real_height() const;
00099
00101
00105 bool set_dimensions(uint uiWidth, uint uiHeight);
00106
00108
00110 color get_color() const;
00111
00113
00116 void premultiply_alpha();
00117
00119
00121 void set_wrap(wrap mWrap);
00122
00124
00128 void set_filter(filter mFilter);
00129
00131 void bind() const;
00132
00134
00136 const std::vector<ub32color>& get_data() const;
00137
00139
00144 std::vector<ub32color>& get_data();
00145
00147
00154 void set_pixel(uint x, uint y, const ub32color& mColor);
00155
00157
00161 const ub32color& get_pixel(uint x, uint y) const;
00162
00164
00171 ub32color& get_pixel(uint x, uint y);
00172
00174
00178 void update_texture();
00179
00181
00183 void clear_cache_data_();
00184
00186
00188 uint get_handle_();
00189
00191
00195 static void check_availability();
00196
00197 private:
00198
00199 material(const material& tex);
00200 material& operator = (const material& tex);
00201
00202 struct texture_data
00203 {
00204 uint uiWidth_, uiHeight_;
00205 uint uiRealWidth_, uiRealHeight_;
00206 wrap mWrap_;
00207 filter mFilter_;
00208 uint uiTextureHandle_;
00209
00210 std::vector<ub32color> pData_;
00211 };
00212
00213 struct color_data
00214 {
00215 color mColor_;
00216 };
00217
00218 type mType_;
00219
00220 utils::refptr<texture_data> pTexData_;
00221 utils::refptr<color_data> pColData_;
00222
00223 static bool ONLY_POWER_OF_TWO;
00224 static uint MAXIMUM_SIZE;
00225 };
00226 }
00227 }
00228
00229 #endif