diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 098c886cc..be2b979e0 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -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; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 456e5d28f..f9a51eab3 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -819,7 +819,7 @@ public: /** * 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. diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index d70bf1d8b..5cda31dae 100644 --- a/src/modules/graphics/Texture.cpp +++ b/src/modules/graphics/Texture.cpp @@ -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()) diff --git a/src/modules/graphics/metal/Graphics.h b/src/modules/graphics/metal/Graphics.h index ab2e8fc2b..ea8894f4c 100644 --- a/src/modules/graphics/metal/Graphics.h +++ b/src/modules/graphics/metal/Graphics.h @@ -110,7 +110,6 @@ public: 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; diff --git a/src/modules/graphics/metal/Graphics.mm b/src/modules/graphics/metal/Graphics.mm index f07433cd6..ca6c76b82 100644 --- a/src/modules/graphics/metal/Graphics.mm +++ b/src/modules/graphics/metal/Graphics.mm @@ -1864,28 +1864,9 @@ void Graphics::setWireframe(bool 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); if (sRGB) format = getSRGBPixelFormat(format); @@ -1902,7 +1883,7 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG 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 diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 50f0a3e79..651978742 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -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); @@ -1844,11 +1819,9 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG if (sRGB) format = getSRGBPixelFormat(format); - bool rendertarget = (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) != 0; + format = getSizedFormat(format); + bool readable = (usage & PIXELFORMATUSAGEFLAGS_SAMPLE) != 0; - - format = getSizedFormat(format, rendertarget, readable); - return (usage & pixelFormatUsage[format][readable ? 1 : 0]) == usage; } diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 997239c15..d27c96791 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -106,7 +106,6 @@ public: 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; diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index b51db2154..39228f335 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -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); diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index 7d90542b8..69ae238b5 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -297,7 +297,6 @@ public: 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;