Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
textureset.hpp
1 //////////////////////////////
2 //
3 // File: lxs/coregraphics/textureset.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Nov 27 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_TEXTURESET_
15 #define __LXS_TEXTURESET_
16 #include <map>
17 #include <string>
18 #include "helper/opengl.h"
19 #include "lxs/system/servicethread.hpp"
20 #include "lxs/system/assetloader.hpp"
21 namespace LxS
22 {
23  namespace System
24  {
25  class MyMutex;
26  }
27  namespace CoreGraphics
28  {
29  class TextureInfo;
30  //! class works as a frontend to global texture manager
31  class TextureSet
32  {
33  //! if texture is set up and can be used
34  bool is_initialized;
35  //! \brief count of textures in set;
36  //! this object is typically used to represent whole set of textures
37  //! in particular shader - so if you have color tex, alpha tex and the
38  //! bump map, you get three.
39  int count;
40  //! texels count in whole texture set. Width*height*count
41  unsigned long texels;
42  //! magnification filter - for OpenGL scaling settings
43  GLint mag_filter;
44  //! minificaton filter - for OpenGL scaling settings
45  GLint min_filter;
46  typedef std::map<std::string,TextureInfo> TextureManager;
47 
48  static TextureManager GlobalTextureManager;
49  static System::MyMutex GlobalTextureManagerMutex;
50  //! pi stands for pointer to iterator
51  typedef TextureManager::iterator * pi_TextureInfo;
52  //! pointer to an iterator to object representing whole texture opengl handle
53  pi_TextureInfo opengl_Handle;
54  //! Texture loader - opengl part. (this function uploads set of pixel to GPU
55  //!but is not responsible for decompressing, disk access etc. - bare minimum
56  //! that HAS to be executed in opengl context
57  static void LoadTextureGL(TextureInfo * h);
58  //! free texture from opengl memory
59  static void FreeTexturesGL(GLuint handle);
60  public:
61  //! used to implement android run states and moving between OpenGL contexts
62  static void ReloadAllTextures();
63  //! after losing context, graphics glitches etc
64  static void MarkNecessityToReload();
65  //! prints infodump on all textures to a console
66  static void PrintGlobalStatus();
67  TextureSet();
68  //! only before init; correct values:
69  //! GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR
70  void SetTexMagFilter(GLint mf) {mag_filter=mf;}
71  //! only before init; correct values:
72  //! GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR
73  void SetTexMinFilter(GLint mf) { min_filter=mf;}
74  //! load set of textures immediately
75  void LoadTextures(const char** FileName, int count);
76  //! return opengl handle of ith texture
77  GLuint GetHandle(int i);
78  //! count of textures held by objects
79  int GetCount() { return count;}
80  //! free up GPU resources
81  void FreeTextures();
82  //! how many texels are there within this texture set (all textures added together)
83  unsigned long GetTexelsCount() {return texels;}
84  ~TextureSet() {FreeTextures();}
85  };
86  //end of class TextureSet
87 
88  }
89 }
90 
91 #endif