Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
txtmgr.h
00001 /* 00002 Copyright (C) 1998 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_TXTMGR_H__ 00020 #define __CS_TXTMGR_H__ 00021 00022 #include "csextern.h" 00023 #include "csutil/parray.h" 00024 #include "ivideo/txtmgr.h" 00025 #include "ivideo/material.h" 00026 #include "iengine/material.h" 00027 #include "ivideo/texture.h" 00028 #include "ivideo/shader/shader.h" 00029 #include "iengine/texture.h" 00030 //#include "ivideo/graph3d.h" 00031 #include "ivideo/graph2d.h" 00032 #include "csgfx/rgbpixel.h" 00033 #include "csutil/weakrefarr.h" 00034 00035 class csTexture; 00036 class csTextureManager; 00037 struct iImage; 00038 struct iConfigFile; 00039 struct iGraphics2D; 00040 struct iObjectRegistry; 00041 00056 class CS_CSPLUGINCOMMON_EXPORT csTextureHandle : public iTextureHandle 00057 { 00058 protected: 00060 csRef<iImage> image; 00062 csRef<csTextureManager> texman; 00063 00065 int flags; 00066 00068 csTexture *tex [4]; 00069 00071 void *cachedata; 00072 00074 bool transp; 00076 csRGBpixel transp_color; 00078 csRGBpixel mean_color; 00079 00080 csStringID texClass; 00081 public: 00083 csTextureHandle (csTextureManager* texman, iImage *Image, int Flags); 00085 virtual ~csTextureHandle (); 00086 00088 int GetFlags () const { return flags; } 00089 00091 void FreeImage (); 00092 00094 virtual void CreateMipmaps (); 00095 00099 virtual void PrepareInt () { } 00100 00102 csTexture *get_texture (int mipmap) 00103 { 00104 PrepareInt (); 00105 return (mipmap >= 0) && (mipmap < 4) ? tex [mipmap] : 0; 00106 } 00107 00112 void AdjustSizePo2 (); 00113 00115 csRGBpixel *get_transparent () 00116 { return &transp_color; } 00117 00119 virtual csTexture* NewTexture (iImage *Image, bool ismipmap = false) = 0; 00120 00122 virtual void ComputeMeanColor () = 0; 00123 00124 virtual void Blit (int x, int y, int width, int height, 00125 unsigned char const* data) { } 00126 00128 SCF_DECLARE_IBASE; 00129 00131 virtual void SetKeyColor (bool Enable); 00132 00134 virtual void SetKeyColor (uint8 red, uint8 green, uint8 blue); 00135 00140 virtual bool GetKeyColor () const; 00141 00143 virtual void GetKeyColor (uint8 &r, uint8 &g, uint8 &b) const; 00144 00150 virtual bool GetRendererDimensions (int &mw, int &mh); 00151 virtual void GetOriginalDimensions (int& w, int& h) 00152 { 00153 GetRendererDimensions (w, h); 00154 } 00155 00157 virtual void GetMeanColor (uint8 &r, uint8 &g, uint8 &b) const; 00158 00160 virtual void *GetCacheData () 00161 { return cachedata; } 00163 virtual void SetCacheData (void *d) 00164 { cachedata = d; } 00165 00167 virtual void *GetPrivateObject () 00168 { return (csTextureHandle *)this; } 00169 00175 virtual bool GetAlphaMap () 00176 { return false; } 00177 00184 static void CalculateNextBestPo2Size (const int orgDim, int& newDim); 00185 00186 virtual csAlphaMode::AlphaType GetAlphaType () const 00187 { return csAlphaMode::alphaNone; } 00188 virtual void SetAlphaType (csAlphaMode::AlphaType alphaType) 00189 { } 00190 00191 virtual void Precache () {} 00192 00193 virtual void SetTextureClass (const char* className); 00194 virtual const char* GetTextureClass (); 00195 }; 00196 00212 class CS_CSPLUGINCOMMON_EXPORT csTexture 00213 { 00214 protected: 00216 csTextureHandle *parent; 00218 int w, h; 00220 int shf_w, shf_h; 00222 int and_w, and_h; 00223 00225 void compute_masks (); 00226 00227 public: 00229 csTexture (csTextureHandle *Parent); 00231 virtual ~csTexture (); 00232 00234 int get_width () { return w; } 00236 int get_height () { return h; } 00238 int get_w_shift () { return shf_w; } 00240 int get_h_shift () { return shf_h; } 00242 int get_w_mask () { return and_w; } 00244 int get_h_mask () { return and_h; } 00246 int get_size () { return w * h; } 00248 csTextureHandle *get_parent () { return parent; } 00249 }; 00250 00254 class CS_CSPLUGINCOMMON_EXPORT csMaterialHandle : public iMaterialHandle 00255 { 00256 protected: 00258 csRef<iMaterial> material; 00260 csRef<csTextureManager> texman; 00261 00262 public: 00264 csMaterialHandle (iMaterial* material, csTextureManager *parent); 00266 csMaterialHandle (iTextureHandle* texture, csTextureManager *parent); 00268 virtual ~csMaterialHandle (); 00269 00271 void FreeMaterial (); 00272 00274 iMaterial* GetMaterial () { return material; } 00275 00276 //--------------------- iMaterialHandle implementation ---------------------- 00277 SCF_DECLARE_IBASE; 00278 00282 virtual iShader *GetShader (csStringID type) 00283 { return material->GetShader(type); } 00284 00288 virtual iTextureHandle *GetTexture (); 00289 00294 virtual void GetFlatColor (csRGBpixel &oColor) 00295 { 00296 material->GetFlatColor (oColor); 00297 } 00298 00302 virtual void GetReflection (float &oDiffuse, float &oAmbient, 00303 float &oReflection) 00304 { 00305 material->GetReflection (oDiffuse, oAmbient, oReflection); 00306 } 00307 }; 00308 00314 class CS_CSPLUGINCOMMON_EXPORT csTextureManager : public iTextureManager 00315 { 00316 protected: 00317 00318 //typedef csArray<csTextureHandle*> csTexVector; 00319 typedef csWeakRefArray<csTextureHandle> csTexVector; 00320 00322 csTexVector textures; 00323 00324 // Private class used to keep a list of objects derived from csMaterialHandle 00325 //typedef csArray<csMaterialHandle*> csMatVector; 00326 typedef csWeakRefArray<csMaterialHandle> csMatVector; 00327 00329 csMatVector materials; 00330 00332 iObjectRegistry *object_reg; 00333 00335 virtual void read_config (iConfigFile *config); 00336 public: 00338 csPixelFormat pfmt; 00339 00340 csStringID nameDiffuseTexture; 00341 00342 csStringSet texClassIDs; 00343 00344 SCF_DECLARE_IBASE; 00345 00347 csTextureManager (iObjectRegistry* object_reg, iGraphics2D *iG2D); 00349 virtual ~csTextureManager (); 00350 00355 void UnregisterMaterial (csMaterialHandle* handle); 00356 00358 virtual void Clear () 00359 { 00360 textures.DeleteAll (); 00361 materials.DeleteAll (); 00362 } 00363 00371 virtual int GetTextureFormat (); 00372 00379 virtual csPtr<iMaterialHandle> RegisterMaterial (iMaterial* material); 00380 00385 virtual csPtr<iMaterialHandle> RegisterMaterial (iTextureHandle* txthandle); 00386 00391 virtual void FreeMaterials (); 00392 }; 00393 00394 #endif // __CS_TXTMGR_H__
Generated for Crystal Space by doxygen 1.3.9.1