Skip to content

Commit

Permalink
Remove explicit support for systems that don't support rgba8 canvases.
Browse files Browse the repository at this point in the history
This is just a very small number of really old OpenGL ES 2 drivers.
  • Loading branch information
slime73 committed Oct 14, 2023
1 parent 3865868 commit 983ea6c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 75 deletions.
16 changes: 16 additions & 0 deletions src/modules/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,22 @@ const Graphics::Capabilities &Graphics::getCapabilities() const
return capabilities;
}

PixelFormat Graphics::getSizedFormat(PixelFormat format) const
{
switch (format)
{
case PIXELFORMAT_NORMAL:
if (isGammaCorrect())
return PIXELFORMAT_RGBA8_UNORM_sRGB;
else
return PIXELFORMAT_RGBA8_UNORM;
case PIXELFORMAT_HDR:
return PIXELFORMAT_RGBA16_FLOAT;
default:
return format;
}
}

Graphics::Stats Graphics::getStats() const
{
Stats stats;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class Graphics : public Module
/**
* Converts PIXELFORMAT_NORMAL and PIXELFORMAT_HDR into a real format.
**/
virtual PixelFormat getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const = 0;
PixelFormat getSizedFormat(PixelFormat format) const;

/**
* Gets whether the specified pixel format usage is supported.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Texture::Texture(Graphics *gfx, const Settings &settings, const Slices *slices)
else
readable = !renderTarget || !isPixelFormatDepthStencil(format);

format = gfx->getSizedFormat(format, renderTarget, readable);
format = gfx->getSizedFormat(format);
sRGB = isPixelFormatSRGB(format) || (isCompressed() && isGammaCorrect() && !settings.linear);

if (mipmapsMode == MIPMAPS_AUTO && isCompressed())
Expand Down
1 change: 0 additions & 1 deletion src/modules/graphics/metal/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class Graphics final : public love::graphics::Graphics

void setWireframe(bool enable) override;

PixelFormat getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const override;
bool isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB = false) override;
Renderer getRenderer() const override;
bool usesGLSLES() const override;
Expand Down
23 changes: 2 additions & 21 deletions src/modules/graphics/metal/Graphics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1864,28 +1864,9 @@ static inline void advanceVertexOffsets(const VertexAttributes &attributes, Buff
}
}

PixelFormat Graphics::getSizedFormat(PixelFormat format, bool /*rendertarget*/, bool /*readable*/) const
{
switch (format)
{
case PIXELFORMAT_NORMAL:
if (isGammaCorrect())
return PIXELFORMAT_RGBA8_UNORM_sRGB;
else
return PIXELFORMAT_RGBA8_UNORM;
case PIXELFORMAT_HDR:
return PIXELFORMAT_RGBA16_FLOAT;
default:
return format;
}
}

bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB)
{
bool rendertarget = (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) != 0;
bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0;

format = getSizedFormat(format, rendertarget, readable);
format = getSizedFormat(format);

if (sRGB)
format = getSRGBPixelFormat(format);
Expand All @@ -1902,7 +1883,7 @@ static inline void advanceVertexOffsets(const VertexAttributes &attributes, Buff

uint32 flags = PIXELFORMATUSAGEFLAGS_NONE;

if (isPixelFormatCompressed(format) && rendertarget)
if (isPixelFormatCompressed(format) && (usage & rt) != 0)
return false;

// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
Expand Down
31 changes: 2 additions & 29 deletions src/modules/graphics/opengl/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,31 +1734,6 @@ void Graphics::initCapabilities()
}
}

PixelFormat Graphics::getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const
{
uint32 requiredflags = 0;
if (rendertarget)
requiredflags |= PIXELFORMATUSAGEFLAGS_RENDERTARGET;
if (readable)
requiredflags |= PIXELFORMATUSAGEFLAGS_SAMPLE;

switch (format)
{
case PIXELFORMAT_NORMAL:
if (isGammaCorrect())
return PIXELFORMAT_RGBA8_UNORM_sRGB;
else if ((OpenGL::getPixelFormatUsageFlags(PIXELFORMAT_RGBA8_UNORM) & requiredflags) != requiredflags)
// 32-bit render targets don't have guaranteed support on GLES2.
return PIXELFORMAT_RGBA4_UNORM;
else
return PIXELFORMAT_RGBA8_UNORM;
case PIXELFORMAT_HDR:
return PIXELFORMAT_RGBA16_FLOAT;
default:
return format;
}
}

uint32 Graphics::computePixelFormatUsage(PixelFormat format, bool readable)
{
uint32 usage = OpenGL::getPixelFormatUsageFlags(format);
Expand Down Expand Up @@ -1844,11 +1819,9 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG
if (sRGB)
format = getSRGBPixelFormat(format);

bool rendertarget = (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) != 0;
bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0;

format = getSizedFormat(format, rendertarget, readable);
format = getSizedFormat(format);

bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0;
return (usage & pixelFormatUsage[format][readable ? 1 : 0]) == usage;
}

Expand Down
1 change: 0 additions & 1 deletion src/modules/graphics/opengl/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Graphics final : public love::graphics::Graphics

void setWireframe(bool enable) override;

PixelFormat getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const override;
bool isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB = false) override;
Renderer getRenderer() const override;
bool usesGLSLES() const override;
Expand Down
21 changes: 1 addition & 20 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,28 +1057,9 @@ void Graphics::setWireframe(bool enable)
states.back().wireframe = enable;
}

PixelFormat Graphics::getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const
{
switch (format)
{
case PIXELFORMAT_NORMAL:
if (isGammaCorrect())
return PIXELFORMAT_RGBA8_UNORM_sRGB;
else
return PIXELFORMAT_RGBA8_UNORM;
case PIXELFORMAT_HDR:
return PIXELFORMAT_RGBA16_FLOAT;
default:
return format;
}
}

bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB)
{
bool rendertarget = (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) != 0;
bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0;

format = getSizedFormat(format, rendertarget, readable);
format = getSizedFormat(format);

auto vulkanFormat = Vulkan::getTextureFormat(format, sRGB);

Expand Down
1 change: 0 additions & 1 deletion src/modules/graphics/vulkan/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ class Graphics final : public love::graphics::Graphics
void setBlendState(const BlendState &blend) override;
void setPointSize(float size) override;
void setWireframe(bool enable) override;
PixelFormat getSizedFormat(PixelFormat format, bool rendertarget, bool readable) const override;
bool isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRGB) override;
Renderer getRenderer() const override;
bool usesGLSLES() const override;
Expand Down

0 comments on commit 983ea6c

Please sign in to comment.