[Feat] (MG_State, MG_Util, MG_Impl/GLImpl, MG_Backend/DirectGLES): desktop-GL single-channel client formats GL_GREEN/GL_BLUE/GL_ALPHA and _INTEGER variants - validate and readback via wide-RGBA channel extraction (GL CTS packed_pixels rgba8_format_green/blue read with them), unpack GREEN/BLUE(_INTEGER) TexImage uploads into the named channel with 0/1 defaults per table 3.3; GL_ALPHA keeps the legacy Red upload mapping (R8 storage + 000R swizzle), its readback corrected at the backend to source channel 3

This commit is contained in:
2026-07-16 06:47:33 -04:00
parent a1a8a18575
commit 6ca48e40fe
12 changed files with 220 additions and 2 deletions
@@ -58,9 +58,17 @@ namespace MobileGL {
TextureInputFormat ConvertGLEnumToTextureInputFormat(GLenum format) {
switch (format) {
// Legacy carve-out: GL_ALPHA stays mapped to Red so alpha-texture uploads keep landing in
// the R channel of the R8-backed storage (TexImage*_State pairs this with a 0,0,0,R
// swizzle). Readback of GL_ALPHA is corrected at the backend, which maps the raw enum to
// source channel 3 (DirectGLES GetReadbackChannelMapping).
case GL_ALPHA:
case GL_RED:
return TextureInputFormat::Red;
case GL_GREEN:
return TextureInputFormat::Green;
case GL_BLUE:
return TextureInputFormat::Blue;
case GL_RG:
return TextureInputFormat::RG;
case GL_RGB:
@@ -73,6 +81,12 @@ namespace MobileGL {
return TextureInputFormat::BGRA;
case GL_RED_INTEGER:
return TextureInputFormat::RInteger;
case GL_GREEN_INTEGER:
return TextureInputFormat::GreenInteger;
case GL_BLUE_INTEGER:
return TextureInputFormat::BlueInteger;
case GL_ALPHA_INTEGER:
return TextureInputFormat::AlphaInteger;
case GL_RG_INTEGER:
return TextureInputFormat::RGInteger;
case GL_RGB_INTEGER:
@@ -535,6 +535,7 @@ namespace MobileGL {
CASE(GL_RED_INTEGER)
CASE(GL_GREEN_INTEGER)
CASE(GL_BLUE_INTEGER)
CASE(GL_ALPHA_INTEGER)
CASE(GL_RGB_INTEGER)
CASE(GL_RGBA_INTEGER)
CASE(GL_BGR_INTEGER)
@@ -67,6 +67,18 @@ namespace MobileGL {
return GL_RGBA_INTEGER;
case TextureInputFormat::BGRAInteger:
return GL_BGRA_INTEGER;
case TextureInputFormat::Green:
return GL_GREEN;
case TextureInputFormat::Blue:
return GL_BLUE;
case TextureInputFormat::Alpha:
return GL_ALPHA;
case TextureInputFormat::GreenInteger:
return GL_GREEN_INTEGER;
case TextureInputFormat::BlueInteger:
return GL_BLUE_INTEGER;
case TextureInputFormat::AlphaInteger:
return GL_ALPHA_INTEGER;
case TextureInputFormat::StencilIndex:
return GL_STENCIL_INDEX;
case TextureInputFormat::DepthComponent:
@@ -67,6 +67,18 @@ namespace MobileGL {
return "RGBAInteger";
case TextureInputFormat::BGRAInteger:
return "BGRAInteger";
case TextureInputFormat::Green:
return "Green";
case TextureInputFormat::Blue:
return "Blue";
case TextureInputFormat::Alpha:
return "Alpha";
case TextureInputFormat::GreenInteger:
return "GreenInteger";
case TextureInputFormat::BlueInteger:
return "BlueInteger";
case TextureInputFormat::AlphaInteger:
return "AlphaInteger";
case TextureInputFormat::StencilIndex:
return "StencilIndex";
case TextureInputFormat::DepthComponent:
@@ -65,6 +65,16 @@ namespace MobileGL {
return VK_FORMAT_R8G8B8A8_UINT;
case TextureInputFormat::BGRAInteger:
return VK_FORMAT_B8G8R8A8_UINT;
// Single-channel desktop client formats: the client memory holds one component per pixel,
// matching the R8 layouts (the channel it feeds is a pixel-transfer concern, not a layout one).
case TextureInputFormat::Green:
case TextureInputFormat::Blue:
case TextureInputFormat::Alpha:
return VK_FORMAT_R8_UNORM;
case TextureInputFormat::GreenInteger:
case TextureInputFormat::BlueInteger:
case TextureInputFormat::AlphaInteger:
return VK_FORMAT_R8_UINT;
case TextureInputFormat::StencilIndex:
return VK_FORMAT_S8_UINT;
case TextureInputFormat::DepthComponent:
@@ -113,6 +113,12 @@ namespace MobileGL {
switch (format) {
case TextureInputFormat::Red:
case TextureInputFormat::RInteger:
case TextureInputFormat::Green:
case TextureInputFormat::GreenInteger:
case TextureInputFormat::Blue:
case TextureInputFormat::BlueInteger:
case TextureInputFormat::Alpha:
case TextureInputFormat::AlphaInteger:
return 1;
case TextureInputFormat::RG:
case TextureInputFormat::RGInteger:
@@ -201,6 +201,12 @@ namespace MobileGL::MG_Util::PixelStoreProcessor {
switch (format) {
case TextureInputFormat::Red: out = {{0, -1, -1, -1}, 1, false}; return true;
case TextureInputFormat::RInteger: out = {{0, -1, -1, -1}, 1, true}; return true;
case TextureInputFormat::Green: out = {{-1, 0, -1, -1}, 1, false}; return true;
case TextureInputFormat::GreenInteger: out = {{-1, 0, -1, -1}, 1, true}; return true;
case TextureInputFormat::Blue: out = {{-1, -1, 0, -1}, 1, false}; return true;
case TextureInputFormat::BlueInteger: out = {{-1, -1, 0, -1}, 1, true}; return true;
case TextureInputFormat::Alpha: out = {{-1, -1, -1, 0}, 1, false}; return true;
case TextureInputFormat::AlphaInteger: out = {{-1, -1, -1, 0}, 1, true}; return true;
case TextureInputFormat::RG: out = {{0, 1, -1, -1}, 2, false}; return true;
case TextureInputFormat::RGInteger: out = {{0, 1, -1, -1}, 2, true}; return true;
case TextureInputFormat::RGB: out = {{0, 1, 2, -1}, 3, false}; return true;