mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Cleaned up love.graphics Image code for determining whether the image's pixel format is supported.
This commit is contained in:
@@ -829,7 +829,7 @@ public:
|
||||
**/
|
||||
virtual bool isCanvasFormatSupported(PixelFormat format) const = 0;
|
||||
virtual bool isCanvasFormatSupported(PixelFormat format, bool readable) const = 0;
|
||||
virtual bool isImageFormatSupported(PixelFormat format) const = 0;
|
||||
virtual bool isImageFormatSupported(PixelFormat format, bool sRGB = false) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the renderer used by love.graphics.
|
||||
|
||||
@@ -43,8 +43,6 @@ Image::Image(const Slices &data, const Settings &settings, bool validatedata)
|
||||
{
|
||||
if (validatedata && data.validate() == MIPMAPS_DATA)
|
||||
mipmapsType = MIPMAPS_DATA;
|
||||
|
||||
++imageCount;
|
||||
}
|
||||
|
||||
Image::Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings)
|
||||
@@ -80,6 +78,19 @@ Image::~Image()
|
||||
|
||||
void Image::init(PixelFormat fmt, int w, int h, const Settings &settings)
|
||||
{
|
||||
Graphics *gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx != nullptr && !gfx->isImageFormatSupported(fmt, sRGB))
|
||||
{
|
||||
const char *str;
|
||||
if (love::getConstant(fmt, str))
|
||||
{
|
||||
throw love::Exception("Cannot create image: "
|
||||
"%s%s images are not supported on this system.", sRGB ? "sRGB " : "", str);
|
||||
}
|
||||
else
|
||||
throw love::Exception("cannot create image: format is not supported on this system.");
|
||||
}
|
||||
|
||||
pixelWidth = w;
|
||||
pixelHeight = h;
|
||||
|
||||
@@ -97,6 +108,8 @@ void Image::init(PixelFormat fmt, int w, int h, const Settings &settings)
|
||||
filter.mipmap = defaultMipmapFilter;
|
||||
|
||||
initQuad();
|
||||
|
||||
++imageCount;
|
||||
}
|
||||
|
||||
void Image::uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y)
|
||||
|
||||
@@ -1398,9 +1398,9 @@ bool Graphics::isCanvasFormatSupported(PixelFormat format, bool readable) const
|
||||
return Canvas::isFormatSupported(format, readable);
|
||||
}
|
||||
|
||||
bool Graphics::isImageFormatSupported(PixelFormat format) const
|
||||
bool Graphics::isImageFormatSupported(PixelFormat format, bool sRGB) const
|
||||
{
|
||||
return Image::isFormatSupported(format);
|
||||
return Image::isFormatSupported(format, sRGB);
|
||||
}
|
||||
|
||||
Shader::Language Graphics::getShaderLanguageTarget() const
|
||||
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
|
||||
bool isCanvasFormatSupported(PixelFormat format) const override;
|
||||
bool isCanvasFormatSupported(PixelFormat format, bool readable) const override;
|
||||
bool isImageFormatSupported(PixelFormat format) const override;
|
||||
bool isImageFormatSupported(PixelFormat format, bool sRGB) const override;
|
||||
Renderer getRenderer() const override;
|
||||
RendererInfo getRendererInfo() const override;
|
||||
|
||||
|
||||
@@ -185,22 +185,8 @@ bool Image::loadVolatile()
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Image load");
|
||||
|
||||
if (!OpenGL::isPixelFormatSupported(format, false, true, sRGB))
|
||||
if (!isCompressed())
|
||||
{
|
||||
const char *str;
|
||||
if (love::getConstant(format, str))
|
||||
{
|
||||
throw love::Exception("Cannot create image: "
|
||||
"%s%s images are not supported on this system.", sRGB ? "sRGB " : "", str);
|
||||
}
|
||||
else
|
||||
throw love::Exception("cannot create image: format is not supported on this system.");
|
||||
}
|
||||
else if (!isCompressed())
|
||||
{
|
||||
if (sRGB && !hasSRGBSupport())
|
||||
throw love::Exception("sRGB images are not supported on this system.");
|
||||
|
||||
// GL_EXT_sRGB doesn't support glGenerateMipmap for sRGB textures.
|
||||
if (sRGB && (GLAD_ES_VERSION_2_0 && GLAD_EXT_sRGB && !GLAD_ES_VERSION_3_0)
|
||||
&& mipmapsType != MIPMAPS_DATA)
|
||||
@@ -365,14 +351,9 @@ bool Image::setMipmapSharpness(float sharpness)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Image::isFormatSupported(PixelFormat pixelformat)
|
||||
bool Image::isFormatSupported(PixelFormat pixelformat, bool sRGB)
|
||||
{
|
||||
return OpenGL::isPixelFormatSupported(pixelformat, false, true, false);
|
||||
}
|
||||
|
||||
bool Image::hasSRGBSupport()
|
||||
{
|
||||
return GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB || GLAD_VERSION_2_1 || GLAD_EXT_texture_sRGB;
|
||||
return OpenGL::isPixelFormatSupported(pixelformat, false, true, sRGB);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -54,8 +54,7 @@ public:
|
||||
|
||||
bool setMipmapSharpness(float sharpness) override;
|
||||
|
||||
static bool isFormatSupported(PixelFormat pixelformat);
|
||||
static bool hasSRGBSupport();
|
||||
static bool isFormatSupported(PixelFormat pixelformat, bool sRGB);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user