Mercurial > love-experiments
comparison src/modules/image/CompressedData.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 | |
| children | aa603d1b03bc |
comparison
equal
deleted
inserted
replaced
| 1419:edd946442f86 | 1420:2a5ef265e040 |
|---|---|
| 1 /** | |
| 2 * Copyright (c) 2006-2013 LOVE Development Team | |
| 3 * | |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "CompressedData.h" | |
| 22 | |
| 23 namespace love | |
| 24 { | |
| 25 namespace image | |
| 26 { | |
| 27 | |
| 28 CompressedData::CompressedData() | |
| 29 : type(TYPE_MAX_ENUM) | |
| 30 { | |
| 31 | |
| 32 } | |
| 33 | |
| 34 CompressedData::~CompressedData() | |
| 35 { | |
| 36 | |
| 37 } | |
| 38 | |
| 39 int CompressedData::getSize() const | |
| 40 { | |
| 41 size_t totalsize = sizeof(MipmapInfo) * dataMipmapInfo.size(); | |
| 42 | |
| 43 for (size_t i = 0; i < dataMipmapInfo.size(); i++) | |
| 44 totalsize += dataMipmapInfo[i].size; | |
| 45 | |
| 46 return totalsize; | |
| 47 } | |
| 48 | |
| 49 void *CompressedData::getData() const | |
| 50 { | |
| 51 // ? | |
| 52 return (void *) &dataMipmapInfo[0].data[0]; | |
| 53 } | |
| 54 | |
| 55 int CompressedData::getNumMipmaps() const | |
| 56 { | |
| 57 return dataMipmapInfo.size(); | |
| 58 } | |
| 59 | |
| 60 int CompressedData::getSize(int miplevel) const | |
| 61 { | |
| 62 checkMipmapLevelExists(miplevel); | |
| 63 | |
| 64 return dataMipmapInfo[miplevel].size; | |
| 65 } | |
| 66 | |
| 67 void *CompressedData::getData(int miplevel) const | |
| 68 { | |
| 69 checkMipmapLevelExists(miplevel); | |
| 70 | |
| 71 return (void *) &dataMipmapInfo[miplevel].data[0]; | |
| 72 } | |
| 73 | |
| 74 int CompressedData::getWidth(int miplevel) const | |
| 75 { | |
| 76 checkMipmapLevelExists(miplevel); | |
| 77 | |
| 78 return dataMipmapInfo[miplevel].width; | |
| 79 } | |
| 80 | |
| 81 int CompressedData::getHeight(int miplevel) const | |
| 82 { | |
| 83 checkMipmapLevelExists(miplevel); | |
| 84 | |
| 85 return dataMipmapInfo[miplevel].height; | |
| 86 } | |
| 87 | |
| 88 CompressedData::TextureType CompressedData::getType() const | |
| 89 { | |
| 90 return type; | |
| 91 } | |
| 92 | |
| 93 void CompressedData::checkMipmapLevelExists(int miplevel) const | |
| 94 { | |
| 95 if (miplevel < 0 || miplevel >= dataMipmapInfo.size()) | |
| 96 throw love::Exception("Mipmap level %d does not exist", miplevel); | |
| 97 } | |
| 98 | |
| 99 bool CompressedData::getConstant(const char *in, CompressedData::TextureType &out) | |
| 100 { | |
| 101 return types.find(in, out); | |
| 102 } | |
| 103 | |
| 104 bool CompressedData::getConstant(CompressedData::TextureType in, const char *&out) | |
| 105 { | |
| 106 return types.find(in, out); | |
| 107 } | |
| 108 | |
| 109 StringMap<CompressedData::TextureType, CompressedData::TYPE_MAX_ENUM>::Entry CompressedData::typeEntries[] = | |
| 110 { | |
| 111 {"dxt1", CompressedData::TYPE_DXT1}, | |
| 112 {"dxt3", CompressedData::TYPE_DXT3}, | |
| 113 {"dxt5", CompressedData::TYPE_DXT5}, | |
| 114 {"bc5s", CompressedData::TYPE_BC5s}, | |
| 115 {"bc5u", CompressedData::TYPE_BC5u}, | |
| 116 {"bc7", CompressedData::TYPE_BC7}, | |
| 117 {"bc7srgb", CompressedData::TYPE_BC7srgb}, | |
| 118 }; | |
| 119 | |
| 120 StringMap<CompressedData::TextureType, CompressedData::TYPE_MAX_ENUM> CompressedData::types(CompressedData::typeEntries, sizeof(CompressedData::typeEntries)); | |
| 121 | |
| 122 } // image | |
| 123 } // love |
