| 1 | // SPDX-FileCopyrightText: 2000 David Megginson |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #ifndef FGCROPPEDTEXTURE_HXX |
| 5 | #define FGCROPPEDTEXTURE_HXX |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
| 10 | #include <simgear/structure/SGSharedPtr.hxx> |
| 11 | |
| 12 | #include "FGDummyTextureLoader.hxx" |
| 13 | |
| 14 | using std::map; |
| 15 | using std::string; |
| 16 | |
| 17 | /** |
| 18 | * Cropped texture (should migrate out into FGFS). |
| 19 | * |
| 20 | * This structure wraps an SSG texture with cropping information. |
| 21 | */ |
| 22 | class FGCroppedTexture : public SGReferenced { |
| 23 | public: |
| 24 | FGCroppedTexture (const string &path, |
| 25 | const float minX = 0.0, const float minY = 0.0, |
| 26 | const float maxX = 1.0, const float maxY = 1.0); |
| 27 | |
| 28 | virtual ~FGCroppedTexture (); |
| 29 | |
| 30 | virtual void setPath (const string &path); |
| 31 | |
| 32 | virtual const string &getPath () const; |
| 33 | |
| 34 | virtual void setCrop (const float minX, const float minY, const float maxX, const float maxY); |
| 35 | |
| 36 | static void registerTextureLoader (const string &extension, |
| 37 | FGTextureLoaderInterface * const loader); |
| 38 | |
| 39 | virtual float getMinX () const; |
| 40 | virtual float getMinY () const; |
| 41 | virtual float getMaxX () const; |
| 42 | virtual float getMaxY () const; |
| 43 | GLuint getTexture () const; |
| 44 | |
| 45 | virtual void bind (const GLint Textured_Layer_Sampler_Loc); |
| 46 | |
| 47 | private: |
| 48 | string m_path; |
| 49 | float m_minX, m_minY, m_maxX, m_maxY; |
| 50 | |
| 51 | GLuint m_texture; |
| 52 | static GLuint s_current_bound_texture; |
| 53 | static map <string, GLuint> s_cache; |
| 54 | static map <string, FGTextureLoaderInterface*> s_TextureLoader; |
| 55 | static FGDummyTextureLoader s_DummyTextureLoader; |
| 56 | }; |
| 57 | |
| 58 | typedef SGSharedPtr <FGCroppedTexture> FGCroppedTexture_ptr; |
| 59 | |
| 60 | #endif |