mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +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) const = 0;
|
||||||
virtual bool isCanvasFormatSupported(PixelFormat format, bool readable) 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.
|
* 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)
|
if (validatedata && data.validate() == MIPMAPS_DATA)
|
||||||
mipmapsType = MIPMAPS_DATA;
|
mipmapsType = MIPMAPS_DATA;
|
||||||
|
|
||||||
++imageCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings)
|
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)
|
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;
|
pixelWidth = w;
|
||||||
pixelHeight = h;
|
pixelHeight = h;
|
||||||
|
|
||||||
@@ -97,6 +108,8 @@ void Image::init(PixelFormat fmt, int w, int h, const Settings &settings)
|
|||||||
filter.mipmap = defaultMipmapFilter;
|
filter.mipmap = defaultMipmapFilter;
|
||||||
|
|
||||||
initQuad();
|
initQuad();
|
||||||
|
|
||||||
|
++imageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y)
|
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);
|
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
|
Shader::Language Graphics::getShaderLanguageTarget() const
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public:
|
|||||||
|
|
||||||
bool isCanvasFormatSupported(PixelFormat format) const override;
|
bool isCanvasFormatSupported(PixelFormat format) const override;
|
||||||
bool isCanvasFormatSupported(PixelFormat format, bool readable) 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;
|
Renderer getRenderer() const override;
|
||||||
RendererInfo getRendererInfo() const override;
|
RendererInfo getRendererInfo() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -185,22 +185,8 @@ bool Image::loadVolatile()
|
|||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Image load");
|
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.
|
// 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)
|
if (sRGB && (GLAD_ES_VERSION_2_0 && GLAD_EXT_sRGB && !GLAD_ES_VERSION_3_0)
|
||||||
&& mipmapsType != MIPMAPS_DATA)
|
&& mipmapsType != MIPMAPS_DATA)
|
||||||
@@ -365,14 +351,9 @@ bool Image::setMipmapSharpness(float sharpness)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Image::isFormatSupported(PixelFormat pixelformat)
|
bool Image::isFormatSupported(PixelFormat pixelformat, bool sRGB)
|
||||||
{
|
{
|
||||||
return OpenGL::isPixelFormatSupported(pixelformat, false, true, false);
|
return OpenGL::isPixelFormatSupported(pixelformat, false, true, sRGB);
|
||||||
}
|
|
||||||
|
|
||||||
bool Image::hasSRGBSupport()
|
|
||||||
{
|
|
||||||
return GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB || GLAD_VERSION_2_1 || GLAD_EXT_texture_sRGB;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ public:
|
|||||||
|
|
||||||
bool setMipmapSharpness(float sharpness) override;
|
bool setMipmapSharpness(float sharpness) override;
|
||||||
|
|
||||||
static bool isFormatSupported(PixelFormat pixelformat);
|
static bool isFormatSupported(PixelFormat pixelformat, bool sRGB);
|
||||||
static bool hasSRGBSupport();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user