Clean up some internal texture data upload parameters.

This commit is contained in:
Sasha Szpakowski
2024-02-17 14:10:38 -04:00
parent 81d0c720a2
commit d880c48502
8 changed files with 18 additions and 16 deletions
+5 -3
View File
@@ -458,7 +458,7 @@ void Texture::uploadImageData(love::image::ImageDataBase *d, int level, int slic
lock.setLock(id->getMutex());
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)
@@ -477,7 +477,9 @@ void Texture::replacePixels(love::image::ImageDataBase *d, int slice, int mipmap
if (getHandle() == 0)
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.");
if (mipmap < 0 || mipmap >= getMipmapCount())
@@ -533,7 +535,7 @@ void Texture::replacePixels(const void *data, size_t size, int slice, int mipmap
Graphics::flushBatchedDrawsGlobal();
uploadByteData(format, data, size, mipmap, slice, rect);
uploadByteData(data, size, mipmap, slice, rect);
if (reloadmipmaps && mipmap == 0 && getMipmapCount() > 1)
generateMipmaps();
+1 -1
View File
@@ -313,7 +313,7 @@ protected:
void setGraphicsMemorySize(int64 size);
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;
virtual void generateMipmapsInternal() = 0;
+1 -1
View File
@@ -55,7 +55,7 @@ public:
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;
id<MTLTexture> texture;
+3 -3
View File
@@ -149,7 +149,7 @@ Texture::Texture(love::graphics::Graphics *gfxbase, id<MTLDevice> device, const
emptydata.resize(getPixelFormatSliceSize(format, w, h));
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())
{
@@ -219,7 +219,7 @@ Texture::~Texture()
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 {
auto gfx = Graphics::getInstance();
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;
switch (pixelformat)
switch (format)
{
case PIXELFORMAT_PVR1_RGB2_UNORM:
case PIXELFORMAT_PVR1_RGB4_UNORM:
+5 -5
View File
@@ -356,7 +356,7 @@ void Texture::createTexture()
int slices = texType == TEXTURE_VOLUME ? getDepth(mip) : layers;
slices = texType == TEXTURE_CUBE ? 6 : slices;
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);
}
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");
gl.bindTextureToUnit(this, 0, false);
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false);
OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, false);
GLenum gltarget = OpenGL::getGLTextureType(texType);
if (texType == TEXTURE_CUBE)
gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
if (isPixelFormatCompressed(pixelformat))
if (isPixelFormatCompressed(format))
{
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
// treating the pointer as a byte offset.
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);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+1 -1
View File
@@ -63,7 +63,7 @@ public:
private:
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;
+1 -1
View File
@@ -472,7 +472,7 @@ void Texture::generateMipmapsInternal()
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;
VmaAllocation vmaAllocation;
+1 -1
View File
@@ -59,7 +59,7 @@ public:
VkImageView getRenderTargetView(int mip, int layer);
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;