mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Implement Array, Cubemap, and Volume texture types (issue #1111).
- Add love.graphics.newArrayImage, newCubeImage, and newVolumeImage.
- Add love.graphics.newCanvas(w, h, layers) and newCanvas(w, h, layers, settings). Add ‘type’ field to the settings table of newCanvas.
- Add new love.graphics.setCanvas variants: setCanvas(canvas, slice), and setCanvas(canvastable) where canvastable is in the format: {{canvas1, layer=2}, {canvas2, face=5}}
- Add Texture:getTextureType, getDepth, getLayerCount, getMipmapCount, and getFormat.
- Remove Image:getData and Image:refresh.
- Add Image:replacePixels(imagedata [, slice] [, mipmap]).
- Update Canvas:newImageData to accept a slice argument.
- Add love.image.newCubeFaces(imagedata).
--HG--
branch : minor
This commit is contained in:
@@ -27,11 +27,57 @@ namespace image
|
||||
|
||||
love::Type CompressedImageData::type("CompressedImageData", &Data::type);
|
||||
|
||||
CompressedImageData::Memory::Memory(size_t size)
|
||||
: data(nullptr)
|
||||
, size(size)
|
||||
{
|
||||
try
|
||||
{
|
||||
data = new uint8[size];
|
||||
}
|
||||
catch (std::exception &)
|
||||
{
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
}
|
||||
|
||||
CompressedImageData::Memory::~Memory()
|
||||
{
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
CompressedImageData::Slice::Slice(PixelFormat format, int width, int height, Memory *memory, size_t offset, size_t size)
|
||||
: memory(memory)
|
||||
, offset(offset)
|
||||
, dataSize(size)
|
||||
{
|
||||
this->format = format;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
CompressedImageData::Slice::Slice(const Slice &s)
|
||||
: memory(s.memory)
|
||||
, offset(s.offset)
|
||||
, dataSize(s.dataSize)
|
||||
{
|
||||
this->format = s.getFormat();
|
||||
this->width = s.getWidth();
|
||||
this->height = s.getHeight();
|
||||
}
|
||||
|
||||
CompressedImageData::Slice::~Slice()
|
||||
{
|
||||
}
|
||||
|
||||
CompressedImageData::Slice *CompressedImageData::Slice::clone() const
|
||||
{
|
||||
return new Slice(*this);
|
||||
}
|
||||
|
||||
CompressedImageData::CompressedImageData()
|
||||
: format(PIXELFORMAT_UNKNOWN)
|
||||
, sRGB(false)
|
||||
, data(nullptr)
|
||||
, dataSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,45 +87,50 @@ CompressedImageData::~CompressedImageData()
|
||||
|
||||
size_t CompressedImageData::getSize() const
|
||||
{
|
||||
return dataSize;
|
||||
return memory->size;
|
||||
}
|
||||
|
||||
void *CompressedImageData::getData() const
|
||||
{
|
||||
return data;
|
||||
return memory->data;
|
||||
}
|
||||
|
||||
int CompressedImageData::getMipmapCount() const
|
||||
int CompressedImageData::getMipmapCount(int /*slice*/) const
|
||||
{
|
||||
return (int) dataImages.size();
|
||||
}
|
||||
|
||||
int CompressedImageData::getSliceCount(int /*mip*/) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t CompressedImageData::getSize(int miplevel) const
|
||||
{
|
||||
checkMipmapLevelExists(miplevel);
|
||||
checkSliceExists(0, miplevel);
|
||||
|
||||
return dataImages[miplevel].size;
|
||||
return dataImages[miplevel]->getSize();
|
||||
}
|
||||
|
||||
void *CompressedImageData::getData(int miplevel) const
|
||||
{
|
||||
checkMipmapLevelExists(miplevel);
|
||||
checkSliceExists(0, miplevel);
|
||||
|
||||
return &dataImages[miplevel].data[0];
|
||||
return dataImages[miplevel]->getData();
|
||||
}
|
||||
|
||||
int CompressedImageData::getWidth(int miplevel) const
|
||||
{
|
||||
checkMipmapLevelExists(miplevel);
|
||||
checkSliceExists(0, miplevel);
|
||||
|
||||
return dataImages[miplevel].width;
|
||||
return dataImages[miplevel]->getWidth();
|
||||
}
|
||||
|
||||
int CompressedImageData::getHeight(int miplevel) const
|
||||
{
|
||||
checkMipmapLevelExists(miplevel);
|
||||
checkSliceExists(0, miplevel);
|
||||
|
||||
return dataImages[miplevel].height;
|
||||
return dataImages[miplevel]->getHeight();
|
||||
}
|
||||
|
||||
PixelFormat CompressedImageData::getFormat() const
|
||||
@@ -92,8 +143,18 @@ bool CompressedImageData::isSRGB() const
|
||||
return sRGB;
|
||||
}
|
||||
|
||||
void CompressedImageData::checkMipmapLevelExists(int miplevel) const
|
||||
CompressedImageData::Slice *CompressedImageData::getSlice(int slice, int miplevel) const
|
||||
{
|
||||
checkSliceExists(slice, miplevel);
|
||||
|
||||
return dataImages[miplevel].get();
|
||||
}
|
||||
|
||||
void CompressedImageData::checkSliceExists(int slice, int miplevel) const
|
||||
{
|
||||
if (slice != 0)
|
||||
throw love::Exception("Slice index %d does not exists", slice + 1);
|
||||
|
||||
if (miplevel < 0 || miplevel >= (int) dataImages.size())
|
||||
throw love::Exception("Mipmap level %d does not exist", miplevel + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user