00001 #ifndef MERCURYTEXTURE_H
00002 #define MERCURYTEXTURE_H
00003
00004 #include <map>
00005 #include "PStack.h"
00006 #include "global.h"
00007
00008 #include "MercuryObject.h"
00009
00010 using namespace std;
00011
00012 enum ColorBytes
00013 {
00014
00015 BLANK = 0,
00016 BLANK1,
00017 LUMINANCE_ALPHA,
00018 RGB,
00019 DEPTH_COMPONENT24,
00020 RGBA,
00021 RGBA_FLOAT,
00022 };
00023
00024 int ColorBytesToSize(ColorBytes cb);
00025
00026
00027 enum MAPPING
00028 {
00029 STANDARD = 0,
00030 SPHERE,
00031 CUBE,
00032 DOT3
00033 };
00034
00035 enum BLENDMODE
00036 {
00037 BLEND = 0,
00038 MODULATE,
00039 DECAL,
00040 REPLACE,
00041 ADD,
00042 COMBINE
00043 };
00044
00045 enum FILTER
00046 {
00047 LINEAR,
00048 NEAREST,
00049 };
00050
00051 enum MAPMODE
00052 {
00053 CLAMP_UV = 0,
00054 REPEAT_V = 1,
00055 REPEAT_U = 2,
00056 REPEAT_UV = 3
00057 };
00058
00059 struct ImageAttrs
00060 {
00061 ImageAttrs()
00062 {
00063 m_height = 0;
00064 m_width = 0;
00065 m_ID = 0;
00066 m_dpi_x = m_dpi_y = 72.0;
00067
00068 m_height_original = 0;
00069 m_width_original = 0;
00070 m_ColorByteType = RGB;
00071 m_cube = false;
00072 m_resizeFactor = MercuryPoint(1,1,1);
00073 }
00074
00075 int m_height;
00076 int m_width;
00077 int m_height_original;
00078 int m_width_original;
00079 float m_dpi_x, m_dpi_y;
00080 ColorBytes m_ColorByteType;
00081 unsigned int m_ID;
00082 bool m_cube;
00083 MercuryPoint m_resizeFactor;
00084 };
00085
00086 struct TextureAttrs
00087 {
00088 TextureAttrs()
00089 {
00090 m_mapping = STANDARD;
00091 m_mapMode = CLAMP_UV;
00092 m_magFilter = LINEAR;
00093 m_blendMode = MODULATE;
00094
00095 m_isDynamic = false;
00096 m_isDynamicShadow = false;
00097
00098 m_isMipmap = true;
00099
00100 m_MakeThisVBO = 0;
00101 }
00102 bool m_isDynamic;
00103 bool m_isDynamicShadow;
00104 bool m_isMipmap;
00105 int m_MakeThisVBO;
00106
00107 MAPPING m_mapping;
00108
00113 int m_mapMode;
00114
00115 FILTER m_magFilter;
00116
00117 BLENDMODE m_blendMode;
00118
00119
00120
00121
00122 PStack m_extraData;
00123 };
00124
00125 struct RawImageData
00126 {
00127 RawImageData() :data(NULL) {};
00128 ~RawImageData() { SAFE_DELETE(data); }
00129
00130 void CorrectSize();
00131 void ToRGBA();
00132
00133 ImageAttrs attrs;
00134 unsigned char* data;
00135 };
00136
00137
00138
00140 class MercuryTexture : public MercuryObject
00141 {
00142 public:
00143 MercuryTexture();
00144 MercuryTexture(const MercuryTexture& texture);
00145 virtual ~MercuryTexture();
00146
00147 virtual void Message( int Message, PStack & data, const MString & name );
00148 virtual void CalculateMatrices();
00149
00150
00151 inline void SetIsDynamic(bool isDynamic) {m_attrs.m_isDynamic = isDynamic; }
00152 inline bool IsDynamic () const {return m_attrs.m_isDynamic; }
00153
00154 inline void SetIsDynamicShadow(bool isDynamicShadow) {m_attrs.m_isDynamicShadow = isDynamicShadow; }
00155 inline bool IsDynamicShadow() const {return m_attrs.m_isDynamicShadow; }
00156
00157
00158 virtual void Prerender();
00159 virtual void Render() {};
00160 virtual void Draw() {};
00161
00163 void AutoDestroy();
00164
00165 void SetPath(MString path) { m_path = path; }
00166
00167 inline void SetIsMipmap(bool value) { m_attrs.m_isMipmap = value; }
00168 inline bool IsMipmap() const { return m_attrs.m_isMipmap; }
00169
00170 inline MAPPING GetMapping() const { return m_attrs.m_mapping; }
00171 inline void SetMapping(MAPPING mapping) { m_attrs.m_mapping = mapping; }
00172
00173 inline FILTER GetMagFilter() const { return m_attrs.m_magFilter; }
00174 inline void SetMagFilter(FILTER filter) { m_attrs.m_magFilter = filter; }
00175
00180 inline void SetMapMode(int mapMode) { m_attrs.m_mapMode = mapMode; }
00181 inline int GetMapMode() const { return m_attrs.m_mapMode; }
00182
00184 inline int GetWidth() const { return m_imageAttrs.m_width; }
00185 inline int GetHeight() const { return m_imageAttrs.m_height; }
00186 inline void SetWidth(unsigned int w) { m_imageAttrs.m_width = w; }
00187 inline void SetHeight(unsigned int h) { m_imageAttrs.m_height = h; }
00188
00190 inline int GetOriginalWidth() const { return m_imageAttrs.m_width_original; }
00191 inline int GetOriginalHeight() const { return m_imageAttrs.m_height_original; }
00192 inline void SetOriginalWidth( int width ) { m_imageAttrs.m_width_original = width; }
00193 inline void SetOriginalHeight( int height ) { m_imageAttrs.m_height_original = height; }
00194
00195 inline float GetDpiX() const { return m_imageAttrs.m_dpi_x; }
00196 inline float GetDpiY() const { return m_imageAttrs.m_dpi_y; }
00197 inline void SetDpiX(const float dpi_x) { m_imageAttrs.m_dpi_x = dpi_x; }
00198 inline void SetDpiY(const float dpi_y) { m_imageAttrs.m_dpi_y = dpi_y; }
00199 inline const MString& GetPath() const { return m_path; }
00200 inline ColorBytes GetColorByteType() const { return m_imageAttrs.m_ColorByteType; }
00201 inline void SetColorByteType(ColorBytes type) { m_imageAttrs.m_ColorByteType = type; }
00202 inline unsigned int GetID() const { return m_imageAttrs.m_ID; }
00203 inline void SetID(unsigned int id) { m_imageAttrs.m_ID = id; }
00204 inline void SetAttributes(TextureAttrs& attrs) { m_attrs = attrs; SetMatrixTainted(true);}
00205 inline const TextureAttrs& GetAttributes() const { return m_attrs; }
00206 inline const ImageAttrs& GetImageAttributes() const { return m_imageAttrs; }
00207
00208 void operator=(const MercuryTexture& texture);
00209 CLASS_RTTI( MercuryTexture, MercuryObject );
00210
00211 inline void MakeAttachToVBO( int iVBO ) { m_attrs.m_MakeThisVBO = iVBO; }
00212
00213 void SendLoadMessage();
00214 void SendLoadFromRaw(RawImageData* data);
00215 private:
00216 void SendRemoveMessage();
00217 void CorrectSize();
00218 MString m_path;
00219 TextureAttrs m_attrs;
00220 ImageAttrs m_imageAttrs;
00221 };
00222
00223 void CaclulateDiv2Texture( const RawImageData & riIn, RawImageData & riOut );
00224
00225 #endif
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250