1 // SuperTuxKart - a fun racing game with go-kart 2 // Copyright (C) 2017 SuperTuxKart-Team 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 3 7 // of the License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 #ifndef HEADER_STK_TEXTURE_HPP 19 #define HEADER_STK_TEXTURE_HPP 20 21 #include "graphics/gl_headers.hpp" 22 #include "utils/no_copy.hpp" 23 24 #include <string> 25 #include <ITexture.h> 26 27 using namespace irr; 28 29 struct TexConfig; 30 31 class STKTexture : public video::ITexture, NoCopy 32 { 33 private: 34 core::dimension2d<u32> m_size, m_orig_size; 35 36 bool m_single_channel; 37 38 TexConfig* m_tex_config; 39 40 GLuint m_texture_name; 41 42 unsigned int m_texture_size; 43 44 video::IImage* m_texture_image; 45 46 // ------------------------------------------------------------------------ 47 video::IImage* resizeImage(video::IImage* orig_img, 48 core::dimension2du* orig_size = NULL, 49 core::dimension2du* final_size = NULL) const; 50 // ------------------------------------------------------------------------ 51 void formatConversion(uint8_t* data, unsigned int* format, unsigned int w, 52 unsigned int h) const; 53 // ------------------------------------------------------------------------ 54 bool isSrgb() const; 55 // ------------------------------------------------------------------------ 56 bool isPremulAlpha() const; 57 // ------------------------------------------------------------------------ 58 void applyMask(video::IImage* orig_img); 59 // ------------------------------------------------------------------------ 60 61 public: 62 // ------------------------------------------------------------------------ 63 STKTexture(const std::string& path, TexConfig* tc, bool no_upload = false); 64 // ------------------------------------------------------------------------ 65 STKTexture(uint8_t* data, const std::string& name, unsigned int size, 66 bool single_channel = false); 67 // ------------------------------------------------------------------------ 68 STKTexture(video::IImage* img, const std::string& name); 69 // ------------------------------------------------------------------------ 70 virtual ~STKTexture(); 71 // ------------------------------------------------------------------------ 72 virtual void* lock(video::E_TEXTURE_LOCK_MODE mode = 73 video::ETLM_READ_WRITE, u32 mipmap_level = 0); 74 // ------------------------------------------------------------------------ unlock()75 virtual void unlock() 76 { 77 if (m_texture_image) 78 m_texture_image->unlock(); 79 } 80 // ------------------------------------------------------------------------ getOriginalSize() const81 virtual const core::dimension2d<u32>& getOriginalSize() const 82 { return m_orig_size; } 83 // ------------------------------------------------------------------------ getSize() const84 virtual const core::dimension2d<u32>& getSize() const { return m_size; } 85 // ------------------------------------------------------------------------ getDriverType() const86 virtual video::E_DRIVER_TYPE getDriverType() const 87 { 88 #if defined(USE_GLES2) 89 return video::EDT_OGLES2; 90 #else 91 return video::EDT_OPENGL; 92 #endif 93 } 94 // ------------------------------------------------------------------------ getColorFormat() const95 virtual video::ECOLOR_FORMAT getColorFormat() const 96 { return video::ECF_A8R8G8B8; } 97 // ------------------------------------------------------------------------ getPitch() const98 virtual u32 getPitch() const { return 0; } 99 // ------------------------------------------------------------------------ 100 virtual bool hasMipMaps() const; 101 // ------------------------------------------------------------------------ regenerateMipMapLevels(void * mipmap_data=NULL)102 virtual void regenerateMipMapLevels(void* mipmap_data = NULL) {} 103 // ------------------------------------------------------------------------ getOpenGLTextureName() const104 virtual u32 getOpenGLTextureName() const { return m_texture_name; } 105 // ------------------------------------------------------------------------ getTextureSize() const106 virtual unsigned int getTextureSize() const { return m_texture_size; } 107 // ------------------------------------------------------------------------ 108 void reload(bool no_upload = false, uint8_t* preload_data = NULL, 109 video::IImage* preload_img = NULL); 110 // ------------------------------------------------------------------------ getTextureImage()111 video::IImage* getTextureImage() { return m_texture_image; } 112 // ------------------------------------------------------------------------ 113 bool isMeshTexture() const; 114 115 }; // STKTexture 116 117 #endif 118