mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Move Texture:generateMipmaps error handling out of backend code
This commit is contained in:
@@ -487,6 +487,17 @@ void Texture::replacePixels(const void *data, size_t size, int slice, int mipmap
|
|||||||
generateMipmaps();
|
generateMipmaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::generateMipmaps()
|
||||||
|
{
|
||||||
|
if (getMipmapCount() == 1 || getMipmapsMode() == MIPMAPS_NONE)
|
||||||
|
throw love::Exception("generateMipmaps can only be called on a Texture which was created with mipmaps enabled.");
|
||||||
|
|
||||||
|
if (isPixelFormatCompressed(format))
|
||||||
|
throw love::Exception("generateMipmaps cannot be called on a compressed Texture.");
|
||||||
|
|
||||||
|
generateMipmapsInternal();
|
||||||
|
}
|
||||||
|
|
||||||
love::image::ImageData *Texture::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
love::image::ImageData *Texture::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
||||||
{
|
{
|
||||||
if (!isReadable())
|
if (!isReadable())
|
||||||
@@ -521,7 +532,11 @@ love::image::ImageData *Texture::newImageData(love::image::Image *module, int sl
|
|||||||
throw love::Exception("ImageData with the '%s' pixel format is not supported.", formatname);
|
throw love::Exception("ImageData with the '%s' pixel format is not supported.", formatname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return module->newImageData(r.w, r.h, dataformat);
|
auto imagedata = module->newImageData(r.w, r.h, dataformat);
|
||||||
|
|
||||||
|
readbackImageData(imagedata, slice, mipmap, r);
|
||||||
|
|
||||||
|
return imagedata;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureType Texture::getTextureType() const
|
TextureType Texture::getTextureType() const
|
||||||
|
|||||||
@@ -218,9 +218,9 @@ public:
|
|||||||
void replacePixels(love::image::ImageDataBase *d, int slice, int mipmap, int x, int y, bool reloadmipmaps);
|
void replacePixels(love::image::ImageDataBase *d, int slice, int mipmap, int x, int y, bool reloadmipmaps);
|
||||||
void replacePixels(const void *data, size_t size, int slice, int mipmap, const Rect &rect, bool reloadmipmaps);
|
void replacePixels(const void *data, size_t size, int slice, int mipmap, const Rect &rect, bool reloadmipmaps);
|
||||||
|
|
||||||
virtual void generateMipmaps() = 0;
|
void generateMipmaps();
|
||||||
|
|
||||||
virtual love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect);
|
love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect);
|
||||||
|
|
||||||
virtual ptrdiff_t getRenderTargetHandle() const = 0;
|
virtual ptrdiff_t getRenderTargetHandle() const = 0;
|
||||||
|
|
||||||
@@ -278,6 +278,9 @@ protected:
|
|||||||
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, love::image::ImageDataBase *imgd = nullptr) = 0;
|
virtual void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) = 0;
|
||||||
|
|
||||||
|
virtual void generateMipmapsInternal() = 0;
|
||||||
|
virtual void readbackImageData(love::image::ImageData *imagedata, int slice, int mipmap, const Rect &rect) = 0;
|
||||||
|
|
||||||
bool validateDimensions(bool throwException) const;
|
bool validateDimensions(bool throwException) const;
|
||||||
|
|
||||||
TextureType texType;
|
TextureType texType;
|
||||||
|
|||||||
@@ -480,14 +480,8 @@ void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::generateMipmaps()
|
void Texture::generateMipmapsInternal()
|
||||||
{
|
{
|
||||||
if (getMipmapCount() == 1 || getMipmapsMode() == MIPMAPS_NONE)
|
|
||||||
throw love::Exception("generateMipmaps can only be called on a Texture which was created with mipmaps enabled.");
|
|
||||||
|
|
||||||
if (isPixelFormatCompressed(format))
|
|
||||||
throw love::Exception("generateMipmaps cannot be called on a compressed Texture.");
|
|
||||||
|
|
||||||
gl.bindTextureToUnit(this, 0, false);
|
gl.bindTextureToUnit(this, 0, false);
|
||||||
|
|
||||||
GLenum gltextype = OpenGL::getGLTextureType(texType);
|
GLenum gltextype = OpenGL::getGLTextureType(texType);
|
||||||
@@ -498,13 +492,10 @@ void Texture::generateMipmaps()
|
|||||||
glGenerateMipmap(gltextype);
|
glGenerateMipmap(gltextype);
|
||||||
}
|
}
|
||||||
|
|
||||||
love::image::ImageData *Texture::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
|
void Texture::readbackImageData(love::image::ImageData *data, int slice, int mipmap, const Rect &r)
|
||||||
{
|
{
|
||||||
// Base class does validation (only RTs allowed, etc) and creates ImageData.
|
|
||||||
love::image::ImageData *data = love::graphics::Texture::newImageData(module, slice, mipmap, r);
|
|
||||||
|
|
||||||
if (fbo == 0) // Should never be reached.
|
if (fbo == 0) // Should never be reached.
|
||||||
return data;
|
return;
|
||||||
|
|
||||||
bool isSRGB = false;
|
bool isSRGB = false;
|
||||||
OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
|
OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
|
||||||
@@ -525,8 +516,6 @@ love::image::ImageData *Texture::newImageData(love::image::Image *module, int sl
|
|||||||
gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, 0, 0, 0);
|
gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, 0, 0, 0);
|
||||||
|
|
||||||
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
|
gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::setSamplerState(const SamplerState &s)
|
void Texture::setSamplerState(const SamplerState &s)
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public:
|
|||||||
bool loadVolatile() override;
|
bool loadVolatile() override;
|
||||||
void unloadVolatile() override;
|
void unloadVolatile() override;
|
||||||
|
|
||||||
void generateMipmaps() override;
|
|
||||||
love::image::ImageData *newImageData(love::image::Image *module, int slice, int mipmap, const Rect &rect) override;
|
|
||||||
void setSamplerState(const SamplerState &s) override;
|
void setSamplerState(const SamplerState &s) override;
|
||||||
|
|
||||||
ptrdiff_t getHandle() const override;
|
ptrdiff_t getHandle() const override;
|
||||||
@@ -62,6 +60,10 @@ private:
|
|||||||
|
|
||||||
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override;
|
void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override;
|
||||||
|
|
||||||
|
void generateMipmapsInternal() override;
|
||||||
|
|
||||||
|
void readbackImageData(love::image::ImageData *imagedata, int slice, int mipmap, const Rect &rect) override;
|
||||||
|
|
||||||
Slices slices;
|
Slices slices;
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
|
|||||||
Reference in New Issue
Block a user