| 1 | /** |
| 2 | * Copyright (c) 2006-2023 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 | #pragma once |
| 22 | |
| 23 | // LOVE |
| 24 | #include "common/Data.h" |
| 25 | #include "common/StringMap.h" |
| 26 | #include "common/int.h" |
| 27 | #include "common/pixelformat.h" |
| 28 | #include "CompressedSlice.h" |
| 29 | #include "FormatHandler.h" |
| 30 | |
| 31 | // STL |
| 32 | #include <vector> |
| 33 | #include <list> |
| 34 | |
| 35 | namespace love |
| 36 | { |
| 37 | namespace image |
| 38 | { |
| 39 | |
| 40 | /** |
| 41 | * CompressedImageData represents image data which is designed to be uploaded to |
| 42 | * the GPU and rendered in its compressed form, without being decompressed. |
| 43 | * http://renderingpipeline.com/2012/07/texture-compression/ |
| 44 | **/ |
| 45 | class CompressedImageData : public Data |
| 46 | { |
| 47 | public: |
| 48 | |
| 49 | static love::Type type; |
| 50 | |
| 51 | CompressedImageData(const std::list<FormatHandler *> &formats, Data *filedata); |
| 52 | CompressedImageData(const CompressedImageData &c); |
| 53 | virtual ~CompressedImageData(); |
| 54 | |
| 55 | // Implements Data. |
| 56 | CompressedImageData *clone() const override; |
| 57 | void *getData() const override; |
| 58 | size_t getSize() const override; |
| 59 | |
| 60 | /** |
| 61 | * Gets the number of mipmaps in this Compressed Image Data. |
| 62 | * Includes the base image level. |
| 63 | **/ |
| 64 | int getMipmapCount() const; |
| 65 | |
| 66 | /** |
| 67 | * Gets the number of slices (array layers, cube faces, 3D layers, etc.) |
| 68 | **/ |
| 69 | int getSliceCount(int mip = 0) const; |
| 70 | |
| 71 | /** |
| 72 | * Gets the size in bytes of a sub-image at the specified mipmap level. |
| 73 | **/ |
| 74 | size_t getSize(int miplevel) const; |
| 75 | |
| 76 | /** |
| 77 | * Gets the byte data of a sub-image at the specified mipmap level. |
| 78 | **/ |
| 79 | void *getData(int miplevel) const; |
| 80 | |
| 81 | /** |
| 82 | * Gets the width of a sub-image at the specified mipmap level. |
| 83 | **/ |
| 84 | int getWidth(int miplevel = 0) const; |
| 85 | |
| 86 | /** |
| 87 | * Gets the height of a sub-image at the specified mipmap level. |
| 88 | **/ |
| 89 | int getHeight(int miplevel = 0) const; |
| 90 | |
| 91 | /** |
| 92 | * Gets the format of the compressed data. |
| 93 | **/ |
| 94 | PixelFormat getFormat() const; |
| 95 | |
| 96 | bool isSRGB() const; |
| 97 | |
| 98 | CompressedSlice *getSlice(int slice, int miplevel) const; |
| 99 | |
| 100 | protected: |
| 101 | |
| 102 | PixelFormat format; |
| 103 | bool sRGB; |
| 104 | |
| 105 | // Single block of memory containing all of the sub-images. |
| 106 | StrongRef<CompressedMemory> memory; |
| 107 | |
| 108 | // Texture info for each mipmap level. |
| 109 | std::vector<StrongRef<CompressedSlice>> dataImages; |
| 110 | |
| 111 | void checkSliceExists(int slice, int miplevel) const; |
| 112 | |
| 113 | }; // CompressedImageData |
| 114 | |
| 115 | } // image |
| 116 | } // love |
| 117 | |