/*! * \file include/TextureManager.h * \brief Texture registry * * \author Mongoose * \author xythobuz */ #ifndef _TEXTURE_MANAGER_H #define _TEXTURE_MANAGER_H #include #include #include "math/Vec3.h" // These are loaded into TextureStorage::SYSTEM by initialize()! #define TEXTURE_WHITE 0 #define TEXTURE_SPLASH 1 class TextureTileVertex { public: TextureTileVertex(uint8_t xc, uint8_t xp, uint8_t yc, uint8_t yp); uint8_t xCoordinate, xPixel; uint8_t yCoordinate, yPixel; }; class TextureTile { public: TextureTile(uint16_t a, uint16_t t) : attribute(a), texture(t) { } ~TextureTile(); void add(TextureTileVertex* t); bool isTriangle(); void display(float x, float y, float w, float h, float z); void displayTriangle(Vec3 a, Vec3 b, Vec3 c); void displayRectangle(Vec3 a, Vec3 b, Vec3 c, Vec3 d); private: void displayTriangle(float x, float y, float w, float h, float z); void displayRectangle(float x, float y, float w, float h, float z); uint16_t attribute; uint16_t texture; std::vector vertices; }; /*! * \brief Texture registry */ class TextureManager { public: enum class TextureStorage { GAME, SYSTEM }; ~TextureManager(); int initialize(); void clear(); int numTextures(TextureStorage s = TextureStorage::GAME); /*! * \brief Binds the texture for use in GL * \param n valid texture index * \param s Which TextureStorage should be accessed */ void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME); /*! * \brief Loads Buffer as texture * \param image pixmap matching other params * \param width width of image * \param height height of image * \param mode mode of image * \param bpp bits per pixel of image * \param s Which TextureStorage should be accessed * \param slot slot (ID) of image * \param filter if the texture should be mipmap filtered * \returns texture ID or < 0 on error */ int loadBufferSlot(unsigned char* image, unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp, TextureStorage s = TextureStorage::GAME, int slot = -1, bool filter = true); int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1); void addTile(TextureTile* t); int numTiles(); TextureTile& getTile(int index); void addAnimatedTile(int index, int tile); int numAnimatedTiles(); int getFirstTileAnimation(int index); int getNextTileAnimation(int tile); private: std::vector& getIds(TextureStorage s); int loadTGA(const char* filename, TextureStorage s, int slot); int loadPCX(const char* filename, TextureStorage s, int slot); int loadPNG(const char* filename, TextureStorage s, int slot); std::vector mTextureIdsGame; std::vector mTextureIdsSystem; std::vector tiles; std::vector> animations; }; TextureManager& getTextureManager(); #endif