mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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 --HG-- branch : image-CompressedData
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2013 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_IMAGE_COMPRESSED_DATA_H
|
||||
#define LOVE_IMAGE_COMPRESSED_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include "common/Data.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "thread/threads.h"
|
||||
|
||||
using love::thread::Mutex;
|
||||
|
||||
// STL
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
|
||||
//
|
||||
class CompressedData : public Data
|
||||
{
|
||||
public:
|
||||
|
||||
//
|
||||
enum TextureType
|
||||
{
|
||||
TYPE_DXT1,
|
||||
TYPE_DXT3,
|
||||
TYPE_DXT5,
|
||||
TYPE_BC5s,
|
||||
TYPE_BC5u,
|
||||
TYPE_BC7,
|
||||
TYPE_BC7srgb,
|
||||
TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
CompressedData();
|
||||
|
||||
virtual ~CompressedData();
|
||||
|
||||
// Implements Data.
|
||||
virtual void *getData() const;
|
||||
virtual int getSize() const;
|
||||
|
||||
/**
|
||||
* Gets the number of mipmaps in this CompressedData.
|
||||
* Includes the base image level.
|
||||
**/
|
||||
int getNumMipmaps() const;
|
||||
|
||||
/**
|
||||
* Gets the size in bytes of the sub-image at the specified mipmap level.
|
||||
**/
|
||||
int getSize(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the byte data of the sub-image at the specified mipmap level.
|
||||
**/
|
||||
void *getData(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the width of the sub-image at the specified mipmap level.
|
||||
**/
|
||||
int getWidth(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the height of the sub-image at the specified mipmap level.
|
||||
**/
|
||||
int getHeight(int miplevel) const;
|
||||
|
||||
/**
|
||||
* Gets the type of the compressed data.
|
||||
**/
|
||||
TextureType getType() const;
|
||||
|
||||
static bool getConstant(const char *in, TextureType &out);
|
||||
static bool getConstant(TextureType in, const char *&out);
|
||||
|
||||
protected:
|
||||
|
||||
struct MipmapInfo
|
||||
{
|
||||
size_t size;
|
||||
int width, height;
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
TextureType type;
|
||||
|
||||
// Texture info for each mipmap level.
|
||||
std::vector<MipmapInfo> dataMipmapInfo;
|
||||
|
||||
void checkMipmapLevelExists(int miplevel) const;
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM>::Entry typeEntries[];
|
||||
static StringMap<TextureType, TYPE_MAX_ENUM> types;
|
||||
|
||||
}; // CompressedData
|
||||
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_IMAGE_COMPRESSED_DATA_H
|
||||
Reference in New Issue
Block a user