]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a swizzle mode for presenting an RGBA texture as RGB
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2021 16:23:21 +0000 (18:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Nov 2021 16:34:00 +0000 (18:34 +0200)
Not many Vulkan implementations support RGB textures

source/backends/opengl/pixelformat_backend.cpp
source/core/pixelformat.cpp
source/core/pixelformat.h

index 79669ba999a75a4c9adb172153d3c10e35b0e74a..9cf796479c37d6ac7077aef33abe1255da16b4ac 100644 (file)
@@ -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
 };
 
 }
index 2ee5af7de6cf7f2d073fdeaa065a6218b4ac6c51..6e7621882fef8eae4e595cd07e004a34b8e567bf 100644 (file)
@@ -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");
 }
index b2d1b9cd7948d069233e71cb4722043df6120f83..13bc03a8c059325d7272120f5a486b58e7e5d01e 100644 (file)
@@ -45,7 +45,8 @@ enum ComponentSwizzle
        NO_SWIZZLE,
        R_TO_LUMINANCE,
        RG_TO_LUMINANCE_ALPHA,
-       RGB_TO_BGR
+       RGB_TO_BGR,
+       RGBA_TO_RGB
 };
 
 /**