Skip to content

Commit

Permalink
Clean up some internal texture data upload parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Feb 17, 2024
1 parent 81d0c72 commit d880c48
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/modules/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class Texture : public Drawable, public Resource
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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/metal/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Texture final : public love::graphics::Texture

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;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/graphics/metal/Texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static MTLTextureType getMTLTextureType(TextureType type, int msaa)
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())
{
Expand Down Expand Up @@ -219,7 +219,7 @@ static MTLTextureType getMTLTextureType(TextureType type, int msaa)
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
Expand All @@ -237,7 +237,7 @@ static MTLTextureType getMTLTextureType(TextureType type, int msaa)

MTLBlitOption options = MTLBlitOptionNone;

switch (pixelformat)
switch (format)
{
case PIXELFORMAT_PVR1_RGB2_UNORM:
case PIXELFORMAT_PVR1_RGB4_UNORM:
Expand Down
10 changes: 5 additions & 5 deletions src/modules/graphics/opengl/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/opengl/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Texture final : public love::graphics::Texture, public Volatile
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;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/vulkan/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/vulkan/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Texture final
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;

Expand Down

0 comments on commit d880c48

Please sign in to comment.