mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Clean up some internal texture data upload parameters.
This commit is contained in:
@@ -458,7 +458,7 @@ void Texture::uploadImageData(love::image::ImageDataBase *d, int level, int slic
|
|||||||
lock.setLock(id->getMutex());
|
lock.setLock(id->getMutex());
|
||||||
|
|
||||||
Rect rect = {x, y, d->getWidth(), d->getHeight()};
|
Rect rect = {x, y, d->getWidth(), d->getHeight()};
|
||||||
uploadByteData(format, d->getData(), d->getSize(), level, slice, rect);
|
uploadByteData(d->getData(), d->getSize(), level, slice, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::replacePixels(love::image::ImageDataBase *d, int slice, int mipmap, int x, int y, bool reloadmipmaps)
|
void Texture::replacePixels(love::image::ImageDataBase *d, int slice, int mipmap, int x, int y, bool reloadmipmaps)
|
||||||
@@ -477,7 +477,9 @@ void Texture::replacePixels(love::image::ImageDataBase *d, int slice, int mipmap
|
|||||||
if (getHandle() == 0)
|
if (getHandle() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (d->getFormat() != getPixelFormat())
|
// ImageData format might be linear but intended to be used as sRGB, so we
|
||||||
|
// don't error if only the sRGBness is different.
|
||||||
|
if (getLinearPixelFormat(d->getFormat()) != getLinearPixelFormat(getPixelFormat()))
|
||||||
throw love::Exception("Pixel formats must match.");
|
throw love::Exception("Pixel formats must match.");
|
||||||
|
|
||||||
if (mipmap < 0 || mipmap >= getMipmapCount())
|
if (mipmap < 0 || mipmap >= getMipmapCount())
|
||||||
@@ -533,7 +535,7 @@ void Texture::replacePixels(const void *data, size_t size, int slice, int mipmap
|
|||||||
|
|
||||||
Graphics::flushBatchedDrawsGlobal();
|
Graphics::flushBatchedDrawsGlobal();
|
||||||
|
|
||||||
uploadByteData(format, data, size, mipmap, slice, rect);
|
uploadByteData(data, size, mipmap, slice, rect);
|
||||||
|
|
||||||
if (reloadmipmaps && mipmap == 0 && getMipmapCount() > 1)
|
if (reloadmipmaps && mipmap == 0 && getMipmapCount() > 1)
|
||||||
generateMipmaps();
|
generateMipmaps();
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ protected:
|
|||||||
void setGraphicsMemorySize(int64 size);
|
void setGraphicsMemorySize(int64 size);
|
||||||
|
|
||||||
void uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y);
|
void uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y);
|
||||||
virtual void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r) = 0;
|
virtual void uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r) = 0;
|
||||||
|
|
||||||
bool supportsGenerateMipmaps(const char *&outReason) const;
|
bool supportsGenerateMipmaps(const char *&outReason) const;
|
||||||
virtual void generateMipmapsInternal() = 0;
|
virtual void generateMipmapsInternal() = 0;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r) override;
|
void uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r) override;
|
||||||
void generateMipmapsInternal() override;
|
void generateMipmapsInternal() override;
|
||||||
|
|
||||||
id<MTLTexture> texture;
|
id<MTLTexture> texture;
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id<MTLDevice> device, const
|
|||||||
emptydata.resize(getPixelFormatSliceSize(format, w, h));
|
emptydata.resize(getPixelFormatSliceSize(format, w, h));
|
||||||
|
|
||||||
Rect r = {0, 0, getPixelWidth(mip), getPixelHeight(mip)};
|
Rect r = {0, 0, getPixelWidth(mip), getPixelHeight(mip)};
|
||||||
uploadByteData(format, emptydata.data(), emptydata.size(), mip, slice, r);
|
uploadByteData(emptydata.data(), emptydata.size(), mip, slice, r);
|
||||||
}
|
}
|
||||||
else if (isRenderTarget())
|
else if (isRenderTarget())
|
||||||
{
|
{
|
||||||
@@ -219,7 +219,7 @@ Texture::~Texture()
|
|||||||
sampler = nil;
|
sampler = nil;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r)
|
void Texture::uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r)
|
||||||
{ @autoreleasepool {
|
{ @autoreleasepool {
|
||||||
auto gfx = Graphics::getInstance();
|
auto gfx = Graphics::getInstance();
|
||||||
id<MTLBuffer> buffer = [gfx->device newBufferWithBytes:data
|
id<MTLBuffer> buffer = [gfx->device newBufferWithBytes:data
|
||||||
@@ -237,7 +237,7 @@ void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t s
|
|||||||
|
|
||||||
MTLBlitOption options = MTLBlitOptionNone;
|
MTLBlitOption options = MTLBlitOptionNone;
|
||||||
|
|
||||||
switch (pixelformat)
|
switch (format)
|
||||||
{
|
{
|
||||||
case PIXELFORMAT_PVR1_RGB2_UNORM:
|
case PIXELFORMAT_PVR1_RGB2_UNORM:
|
||||||
case PIXELFORMAT_PVR1_RGB4_UNORM:
|
case PIXELFORMAT_PVR1_RGB4_UNORM:
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ void Texture::createTexture()
|
|||||||
int slices = texType == TEXTURE_VOLUME ? getDepth(mip) : layers;
|
int slices = texType == TEXTURE_VOLUME ? getDepth(mip) : layers;
|
||||||
slices = texType == TEXTURE_CUBE ? 6 : slices;
|
slices = texType == TEXTURE_CUBE ? 6 : slices;
|
||||||
for (int i = 0; i < slices; i++)
|
for (int i = 0; i < slices; i++)
|
||||||
uploadByteData(format, emptydata.data(), emptydata.size(), mip, i, r);
|
uploadByteData(emptydata.data(), emptydata.size(), mip, i, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,19 +466,19 @@ void Texture::unloadVolatile()
|
|||||||
setGraphicsMemorySize(0);
|
setGraphicsMemorySize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r)
|
void Texture::uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r)
|
||||||
{
|
{
|
||||||
OpenGL::TempDebugGroup debuggroup("Texture data upload");
|
OpenGL::TempDebugGroup debuggroup("Texture data upload");
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
|
|
||||||
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false);
|
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, false);
|
||||||
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
GLenum gltarget = OpenGL::getGLTextureType(texType);
|
||||||
|
|
||||||
if (texType == TEXTURE_CUBE)
|
if (texType == TEXTURE_CUBE)
|
||||||
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
||||||
|
|
||||||
if (isPixelFormatCompressed(pixelformat))
|
if (isPixelFormatCompressed(format))
|
||||||
{
|
{
|
||||||
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
|
||||||
{
|
{
|
||||||
@@ -566,7 +566,7 @@ void Texture::copyFromBuffer(love::graphics::Buffer *source, size_t sourceoffset
|
|||||||
// glTexSubImage and friends copy from the active pixel_unpack_buffer by
|
// glTexSubImage and friends copy from the active pixel_unpack_buffer by
|
||||||
// treating the pointer as a byte offset.
|
// treating the pointer as a byte offset.
|
||||||
const uint8 *byteoffset = (const uint8 *)(ptrdiff_t)sourceoffset;
|
const uint8 *byteoffset = (const uint8 *)(ptrdiff_t)sourceoffset;
|
||||||
uploadByteData(format, byteoffset, size, mipmap, slice, rect);
|
uploadByteData(byteoffset, size, mipmap, slice, rect);
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void createTexture();
|
void createTexture();
|
||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r) override;
|
void uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r) override;
|
||||||
|
|
||||||
void generateMipmapsInternal() override;
|
void generateMipmapsInternal() override;
|
||||||
|
|
||||||
|
|||||||
@@ -472,7 +472,7 @@ void Texture::generateMipmapsInternal()
|
|||||||
1, &barrier);
|
1, &barrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r)
|
void Texture::uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r)
|
||||||
{
|
{
|
||||||
VkBuffer stagingBuffer;
|
VkBuffer stagingBuffer;
|
||||||
VmaAllocation vmaAllocation;
|
VmaAllocation vmaAllocation;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
VkImageView getRenderTargetView(int mip, int layer);
|
VkImageView getRenderTargetView(int mip, int layer);
|
||||||
VkSampleCountFlagBits getMsaaSamples() const;
|
VkSampleCountFlagBits getMsaaSamples() const;
|
||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r) override;
|
void uploadByteData(const void *data, size_t size, int level, int slice, const Rect &r) override;
|
||||||
|
|
||||||
void generateMipmapsInternal() override;
|
void generateMipmapsInternal() override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user