1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 #ifndef _TEXTURE_MANAGER_H 13 #define _TEXTURE_MANAGER_H 14 15 #include <string> 16 #include <map> 17 18 #include "OpenGLTexture.h" 19 #include "Singleton.h" 20 21 22 struct FileTextureInit 23 { 24 std::string name; 25 OpenGLTexture::Filter filter; 26 }; 27 28 29 typedef struct 30 { 31 int id; 32 int x; 33 int y; 34 bool alpha; 35 OpenGLTexture *texture; 36 std::string name; 37 } ImageInfo; 38 39 class TextureManager; 40 41 struct ProcTextureInit 42 { 43 std::string name; 44 TextureManager *manager; 45 OpenGLTexture::Filter filter; 46 int (*proc)(ProcTextureInit &init); 47 }; 48 49 50 class TextureManager : public Singleton<TextureManager> 51 { 52 public: 53 int getTextureID( const char* name, bool reportFail = true ); 54 55 bool isLoaded(const std::string& name); 56 bool removeTexture(const std::string& name); 57 bool reloadTextures(); 58 bool reloadTextureImage(const std::string& name); 59 60 void updateTextureFilters(); 61 void setTextureFilter(int texId, OpenGLTexture::Filter filter); 62 OpenGLTexture::Filter getTextureFilter(int texId); 63 64 bool bind ( int id ); 65 bool bind ( const char* name ); 66 67 const ImageInfo& getInfo ( int id ); 68 const ImageInfo& getInfo ( const char* name ); 69 70 OpenGLTexture::Filter getMaxFilter ( void ); 71 std::string getMaxFilterName ( void ); 72 void setMaxFilter ( OpenGLTexture::Filter filter ); 73 void setMaxFilter ( std::string filter ); 74 75 float GetAspectRatio ( int id ); 76 77 int newTexture (const char* name, int x, int y, unsigned char* data, 78 OpenGLTexture::Filter filter, bool repeat = true); 79 protected: 80 friend class Singleton<TextureManager>; 81 82 private: 83 TextureManager(); 84 TextureManager(const TextureManager &tm); 85 TextureManager& operator=(const TextureManager &tm); 86 ~TextureManager(); 87 88 int addTexture( const char*, OpenGLTexture *texture ); 89 OpenGLTexture* loadTexture( FileTextureInit &init, bool reportFail = true ); 90 91 typedef std::map<std::string, ImageInfo> TextureNameMap; 92 typedef std::map<int, ImageInfo*> TextureIDMap; 93 94 int lastImageID; 95 int lastBoundID; 96 TextureIDMap textureIDs; 97 TextureNameMap textureNames; 98 }; 99 100 101 #endif //_TEXTURE_MANAGER_H 102 103 // Local Variables: *** 104 // mode: C++ *** 105 // tab-width: 4 *** 106 // c-basic-offset: 4 *** 107 // indent-tabs-mode: nil *** 108 // End: *** 109 // ex: shiftwidth=4 tabstop=4 110