rag
graphic 2d engine
Image.h
1 #ifndef _IMAGE_H_
2 #define _IMAGE_H_
3 
4 #include <rag/Platform.h>
5 #include <rag/ResourceMgr.h>
6 #include <rag/Color.h>
7 #include <string>
8 #include <vector>
9 
10 namespace rag
11 {
12  class ImageLoaderJPG;
13  class ImageLoader;
14 
16 
19  class Image: public Resource
20  {
21  public:
22 
24 
26  static Image* loadImage(const std::string& path = "", int textureWrapMode = GL_CLAMP_TO_EDGE, bool deleteImageData = true, bool downloaded = false);
27 
29 
31  Image(const std::string& path = "", int textureWrapMode = GL_CLAMP_TO_EDGE, bool deleteImageData = true, bool downloaded = false);
32 
34  virtual ~Image();
35 
37  virtual void loadInBackground() override;
38 
40  virtual void loadSync() override;
41 
43  void reload();
44 
46 
49  static void setCompressedFolder(std::string folder);
50 
52  static void clearCompressedFolders();
53 
54  int width, height;
55  int pixelFormat;
56  GLuint name;
57  GLubyte *bytes;
58 
59  static int s_memorySize;
60 
61  private:
62 
63  friend class ImageLoaderJPG; // TODO Refactor downloaded stuff.
64 
65  void init();
66 
67  int nextpot(unsigned int n);
68  void* rgba8888_to_rgba4444(void* src);
69 
70  int textureWrapMode;
71 
72  bool deleteImageData;
73  bool isDownloaded;
74 
75  static std::vector<std::string> compressedFolders;
76 
77  ImageLoader* imageLoader;
78  };
79 }
80 
81 #endif
virtual ~Image()
Default destructor.
Definition: Image.cpp:71
static void setCompressedFolder(std::string folder)
Adds a compressed folder.
Definition: Image.cpp:342
Image(const std::string &path="", int textureWrapMode=GL_CLAMP_TO_EDGE, bool deleteImageData=true, bool downloaded=false)
Returns a functional image with size, the image is loaded in background.
Definition: Image.cpp:25
virtual void loadInBackground() override
CPU intensive load goes here.
Definition: Image.cpp:84
Interface to load images.
Definition: ImageLoader.h:8
Definition: Bitmap.h:8
virtual void loadSync() override
The part of the loading that must be done in main thread.
Definition: Image.cpp:90
Loader for .jpg format.
Definition: ImageLoaderJPG.h:14
void reload()
on context lost, images can be reloaded.
Definition: Image.cpp:183
static void clearCompressedFolders()
Clears all compressed folders.
Definition: Image.cpp:351
Abstract class the represent a game Resource, typically something costly to loaded.
Definition: ResourceMgr.h:18
static Image * loadImage(const std::string &path="", int textureWrapMode=GL_CLAMP_TO_EDGE, bool deleteImageData=true, bool downloaded=false)
Returns a functional image with size, the image is loaded in background.
Definition: Image.cpp:14
Image object.
Definition: Image.h:19