From: Mikko Rasa Date: Fri, 12 Nov 2021 16:23:21 +0000 (+0200) Subject: Add a swizzle mode for presenting an RGBA texture as RGB X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f06597a014938746c9018e1dfc463932c8dde5ec;p=libs%2Fgl.git Add a swizzle mode for presenting an RGBA texture as RGB Not many Vulkan implementations support RGB textures --- diff --git a/source/backends/opengl/pixelformat_backend.cpp b/source/backends/opengl/pixelformat_backend.cpp index 79669ba9..9cf79647 100644 --- a/source/backends/opengl/pixelformat_backend.cpp +++ b/source/backends/opengl/pixelformat_backend.cpp @@ -18,7 +18,8 @@ int swizzle_orders[] = GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED, GL_RED, GL_RED, GL_ONE, GL_RED, GL_RED, GL_RED, GL_GREEN, - GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA + GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA, + GL_RED, GL_GREEN, GL_BLUE, GL_ONE }; } diff --git a/source/core/pixelformat.cpp b/source/core/pixelformat.cpp index 2ee5af7d..6e762188 100644 --- a/source/core/pixelformat.cpp +++ b/source/core/pixelformat.cpp @@ -110,6 +110,10 @@ PixelComponents swizzle_components(PixelComponents comp, ComponentSwizzle swiz) return BGR; else if(comp==RGBA && swiz==RGB_TO_BGR) return BGRA; + else if(comp==RGBA && swiz==RGBA_TO_RGB) + return RGB; + else if(comp==BGRA && swiz==RGBA_TO_RGB) + return BGR; else throw invalid_argument("swizzle_components"); } @@ -126,6 +130,10 @@ PixelComponents unswizzle_components(PixelComponents comp, ComponentSwizzle swiz return RGB; else if(comp==BGRA && swiz==RGB_TO_BGR) return RGBA; + else if(comp==RGB && swiz==RGBA_TO_RGB) + return RGBA; + else if(comp==BGR && swiz==RGBA_TO_RGB) + return BGRA; else throw invalid_argument("swizzle_components"); } diff --git a/source/core/pixelformat.h b/source/core/pixelformat.h index b2d1b9cd..13bc03a8 100644 --- a/source/core/pixelformat.h +++ b/source/core/pixelformat.h @@ -45,7 +45,8 @@ enum ComponentSwizzle NO_SWIZZLE, R_TO_LUMINANCE, RG_TO_LUMINANCE_ALPHA, - RGB_TO_BGR + RGB_TO_BGR, + RGBA_TO_RGB }; /**