comparison src/modules/image/devil/Image.cpp @ 1420:2a5ef265e040 image-CompressedData

Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy. - added a new CompressedData type to love.image - added love.image.isCompressed(file or data) - love.graphics.newImage automatically tests for compression when loading a file - added love.graphics.isSupported strings for DXT, BC5, and BC7 Compressed textures meant to be used on the GPU offer huge performance gains when - loading the texture from a file - loading the texture from RAM to VRAM - loading mipmaps - rendering
author Alex Szpakowski <slime73@gmail.com>
date Thu, 04 Apr 2013 19:09:18 -0300
parents b7f097053d74
children aa603d1b03bc
comparison
equal deleted inserted replaced
1419:edd946442f86 1420:2a5ef265e040
19 **/ 19 **/
20 20
21 #include "Image.h" 21 #include "Image.h"
22 22
23 #include "ImageData.h" 23 #include "ImageData.h"
24 #include "CompressedData.h"
24 25
25 // DevIL 26 // DevIL
26 #include <IL/il.h> 27 #include <IL/il.h>
27 28
28 namespace love 29 namespace love
29 { 30 {
30 namespace image 31 namespace image
31 { 32 {
32 namespace devil 33 namespace devil
33 { 34 {
35
36 const std::string Image::compressedExts[] =
37 {
38 ".dds", ""
39 };
34 40
35 Image::Image() 41 Image::Image()
36 { 42 {
37 ilInit(); 43 ilInit();
38 ilOriginFunc(IL_ORIGIN_UPPER_LEFT); 44 ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
67 love::image::ImageData *Image::newImageData(int width, int height, void *data) 73 love::image::ImageData *Image::newImageData(int width, int height, void *data)
68 { 74 {
69 return new ImageData(width, height, data); 75 return new ImageData(width, height, data);
70 } 76 }
71 77
78 love::image::CompressedData *Image::newCompressedData(love::filesystem::File *file)
79 {
80 return new CompressedData(file);
81 }
82
83 love::image::CompressedData *Image::newCompressedData(love::Data *data)
84 {
85 return new CompressedData(data);
86 }
87
88 bool Image::isCompressed(love::filesystem::File *file)
89 {
90 bool hasExt = false;
91
92 // Check whether the file has an extension known to contain compressed data.
93 const std::string &ext = file->getExtension();
94 for (int i = 0; !(compressedExts[i].empty()); i++)
95 {
96 if (compressedExts[i].compare(ext))
97 {
98 hasExt = true;
99 break;
100 }
101 }
102
103 if (!hasExt)
104 return false;
105
106 // Check whether the actual data is compressed.
107 Data *data = file->read();
108 bool compressed = CompressedData::isCompressed(data);
109 data->release();
110
111 return compressed;
112 }
113
114 bool Image::isCompressed(love::Data *data)
115 {
116 return CompressedData::isCompressed(data);
117 }
118
72 } // devil 119 } // devil
73 } // image 120 } // image
74 } // love 121 } // love