[Feat] (MG_State, MG_Impl, MG_Backend, MG_Util): make the border colour real sampler state

glGetSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR) raised INVALID_ENUM,
because MobileGL kept the border colour on the texture object and
GetSamplerParam_State had no case for it at all. That is the first thing
direct_state_access.samplers_defaults asks, so the case threw before reaching
any of the defaults it was written to check.

GL 4.6 core table 23.18 lists TEXTURE_BORDER_COLOR as sampler state, so it moves
to SamplerParameters and TextureObjectBase reaches it through the SamplerObject
it already owns - one source of truth, and a sampler object bound over a texture
now supplies its own border colour, which is what GL says should happen. The
texture params version still moves on a write, because the DirectGLES texture
sync memoises on it. glSamplerParameter{fv,Iiv,Iuiv} and their getters read and
write all four components in whichever representation the caller used, and the
three representations are kept in step so any getter has an answer. The bogus
[0,1] and [0,255] range checks are gone: GL clamps a border colour when a
fixed-point format is sampled, it does not reject it.

DirectVulkan's ResolveVkBorderColor now reads the sampler rather than the
texture. DirectGLES gained a glSamplerParameterfv in its sampler sync, and both
that and the pre-existing glTexParameterfv are gated on a new
SupportsTextureBorderClamp capability - ES 3.2 core, or EXT/OES_texture_border_clamp
before it - since without the extension every such call is INVALID_ENUM on the
driver. DriverPost gains the matching row per the POST rule, saying what a user
actually loses when it is missing.

Takes direct_state_access.samplers_defaults from failing to passing on both
backends.
This commit is contained in:
BZLZHH
2026-08-05 04:45:55 -04:00
parent 96ad7ca0cc
commit dd60ff39ce
10 changed files with 167 additions and 26 deletions
@@ -28,6 +28,11 @@ namespace MobileGL::MG_Impl::GLImpl {
case GL_TEXTURE_MAX_LOD:
case GL_TEXTURE_LOD_BIAS:
return true;
// Four components, and GL puts no range on them - a border colour outside [0,1] is
// clamped when a fixed-point format is sampled, not rejected here. The scalar readers
// below would look at one component and invent an error.
case GL_TEXTURE_BORDER_COLOR:
return true;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
if (ReadSamplerScalar(param, isFloat, isUnsignedInteger) >= 1.0f) return true;
MG_State::pGLContext->RecordError(
@@ -99,6 +104,20 @@ namespace MobileGL::MG_Impl::GLImpl {
case GL_TEXTURE_COMPARE_FUNC:
samplerObj->SetSamplerCompareFunc(MG_Util::ConvertGLEnumToSamplerCompareFunc(*(const GLint*)param));
break;
case GL_TEXTURE_BORDER_COLOR:
// The only four-component sampler parameter: the caller's form decides which
// representation is authoritative, and SamplerObject keeps the other two in step.
if (isFloat) {
const auto* values = (const GLfloat*)param;
samplerObj->SetBorderColor(FloatVec4(values[0], values[1], values[2], values[3]));
} else if (isUnsignedInteger) {
const auto* values = (const GLuint*)param;
samplerObj->SetBorderColorUI(UintVec4(values[0], values[1], values[2], values[3]));
} else {
const auto* values = (const GLint*)param;
samplerObj->SetBorderColorI(IntVec4(values[0], values[1], values[2], values[3]));
}
break;
default:
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "SetSamplerParam_State",
@@ -162,6 +181,31 @@ namespace MobileGL::MG_Impl::GLImpl {
case GL_TEXTURE_COMPARE_FUNC:
*(GLuint*)params = MG_Util::ConvertSamplerCompareFuncToGLEnum(samplerObj->GetSamplerCompareFunc());
break;
case GL_TEXTURE_BORDER_COLOR: {
if (isFloat) {
const auto& color = samplerObj->GetBorderColor();
auto* out = (GLfloat*)params;
out[0] = color.x();
out[1] = color.y();
out[2] = color.z();
out[3] = color.w();
} else if (isUnsignedInteger) {
const auto& color = samplerObj->GetBorderColorUI();
auto* out = (GLuint*)params;
out[0] = color.x();
out[1] = color.y();
out[2] = color.z();
out[3] = color.w();
} else {
const auto& color = samplerObj->GetBorderColorI();
auto* out = (GLint*)params;
out[0] = color.x();
out[1] = color.y();
out[2] = color.z();
out[3] = color.w();
}
break;
}
default:
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetSamplerParam_State",