[Fix] (MG_Impl, MG_State): answer the texture parameters the getters were missing

glGetTexParameter and its by-name form rejected several parameters GL 4.6 core table 8.20
lists, with INVALID_ENUM as if the application had made them up. GL_DEPTH_STENCIL_TEXTURE_MODE
was the worst of them: the float setter accepted it, validated it and then threw the value
away, the integer setter did not accept it at all, and neither getter could report it - so
the mode could be set and never read back, and setting it through glTextureParameteri was an
error.

It is real state now, defaulting to DEPTH_COMPONENT, set by both setters and readable from
both getters. GL_TEXTURE_LOD_BIAS was in the same position: settable, not gettable.

The by-name getters reach the target-based ones through a temporary binding rather than the
per-object path, so both had to learn these; the per-object path gained the swizzle
components, the target, the image format compatibility type and the texture-view parameters
at the same time, since they were missing there for the same reason.

direct_state_access.textures_get_set_parameter passes on both backends, and textures_defaults
stops raising an internal error and reports an ordinary failure it can be diagnosed from.
This commit is contained in:
BZLZHH
2026-08-05 00:49:12 -04:00
parent 18c1a4d586
commit efeb24ff9b
2 changed files with 74 additions and 2 deletions
+67 -2
View File
@@ -911,6 +911,16 @@ namespace MobileGL::MG_Impl::GLImpl {
case GL_GENERATE_MIPMAP:
g_autoGenerateMipmapByTextureId[textureObject->GetExternalIndex()] = (param != GL_FALSE);
break;
case GL_DEPTH_STENCIL_TEXTURE_MODE:
if (param != GL_DEPTH_COMPONENT && param != GL_STENCIL_INDEX) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", caller,
"Invalid GL_DEPTH_STENCIL_TEXTURE_MODE value."));
return;
}
textureObject->SetDepthStencilTextureMode(static_cast<GLenum>(param));
break;
default:
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
@@ -985,7 +995,9 @@ namespace MobileGL::MG_Impl::GLImpl {
ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", caller,
"Invalid GL_DEPTH_STENCIL_TEXTURE_MODE value."));
return;
}
textureObject->SetDepthStencilTextureMode(static_cast<GLenum>(param));
break;
default:
MG_State::pGLContext->RecordError(
@@ -1048,11 +1060,44 @@ namespace MobileGL::MG_Impl::GLImpl {
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
*params = static_cast<GLint>(textureObject->GetSamplerObject()->GetMaxAnisotropy());
break;
case GL_DEPTH_STENCIL_TEXTURE_MODE:
*params = static_cast<GLint>(textureObject->GetDepthStencilTextureMode());
break;
case GL_TEXTURE_LOD_BIAS:
*params = static_cast<GLint>(textureObject->GetSamplerObject()->GetLodBias());
break;
case GL_TEXTURE_SWIZZLE_R:
case GL_TEXTURE_SWIZZLE_G:
case GL_TEXTURE_SWIZZLE_B:
case GL_TEXTURE_SWIZZLE_A: {
const auto component = static_cast<SizeT>(pname - GL_TEXTURE_SWIZZLE_R);
*params = static_cast<GLint>(
MG_Util::ConvertTextureSwizzleParamToGLEnum(textureObject->GetAllSwizzleParams()[component]));
break;
}
case GL_TEXTURE_TARGET:
*params = static_cast<GLint>(MG_Util::ConvertTextureTargetToGLEnum(textureObject->GetTarget()));
break;
case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
*params = GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE;
break;
// Texture views are not implemented; a texture that is not a view reports the defaults
// GL 4.6 core table 23.17 gives (0 layers/levels of offset, and its own extent).
case GL_TEXTURE_VIEW_MIN_LEVEL:
case GL_TEXTURE_VIEW_MIN_LAYER:
*params = 0;
break;
case GL_TEXTURE_VIEW_NUM_LEVELS:
case GL_TEXTURE_VIEW_NUM_LAYERS:
*params = 0;
break;
default:
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", caller,
"pname is not a valid texture parameter."));
MakeUnique<GenericErrorInfo>(
"MG_Impl/GLImpl", caller,
std::format("pname {} is not a valid texture parameter.",
MG_Util::ConvertGLEnumToString(pname))));
return;
}
}
@@ -2441,6 +2486,16 @@ namespace MobileGL::MG_Impl::GLImpl {
*params = GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE;
}
break;
case GL_DEPTH_STENCIL_TEXTURE_MODE:
if (params) {
*params = static_cast<GLint>(textureObject->GetDepthStencilTextureMode());
}
break;
case GL_TEXTURE_LOD_BIAS:
if (params) {
*params = static_cast<GLint>(textureObject->GetSamplerObject()->GetLodBias());
}
break;
default:
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetTexParameteriv_State",
@@ -2587,6 +2642,16 @@ namespace MobileGL::MG_Impl::GLImpl {
*params = textureObject->GetSamplerObject()->GetMaxAnisotropy();
}
break;
case GL_DEPTH_STENCIL_TEXTURE_MODE:
if (params) {
*params = static_cast<GLfloat>(textureObject->GetDepthStencilTextureMode());
}
break;
case GL_TEXTURE_LOD_BIAS:
if (params) {
*params = static_cast<GLfloat>(textureObject->GetSamplerObject()->GetLodBias());
}
break;
default:
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetTexParameterfv_State",
@@ -60,6 +60,10 @@ namespace MobileGL::MG_State::GLState {
virtual Bool HasFixedSampleLocations() const = 0;
virtual void SetFixedSampleLocations(Bool fixedSampleLocations) = 0;
virtual Uint64 GetLifetimeId() const = 0;
// Which aspect of a packed depth/stencil texture a sampler reads (GL 4.6 core 8.10).
// DEPTH_COMPONENT until set, and meaningless for every other format.
virtual GLenum GetDepthStencilTextureMode() const = 0;
virtual void SetDepthStencilTextureMode(GLenum mode) = 0;
protected:
virtual Uint GetIndexOfTextureUploadTarget(TextureUploadTarget target) const = 0;
@@ -104,6 +108,8 @@ namespace MobileGL::MG_State::GLState {
Bool HasFixedSampleLocations() const override;
void SetFixedSampleLocations(Bool fixedSampleLocations) override;
Uint64 GetLifetimeId() const override;
GLenum GetDepthStencilTextureMode() const override { return m_depthStencilTextureMode; }
void SetDepthStencilTextureMode(GLenum mode) override { m_depthStencilTextureMode = mode; }
protected:
static Uint64 AllocateLifetimeId();
@@ -124,6 +130,7 @@ namespace MobileGL::MG_State::GLState {
// Starts at 1 so a freshly-created backend resource (snapshot 0) never spuriously
// matches before its first sync. Bumped only on dirty=true in MarkStorageDirty.
Uint64 m_contentVersion = 1;
GLenum m_depthStencilTextureMode = GL_DEPTH_COMPONENT;
Int m_samples = 0;
Bool m_fixedSampleLocations = true;
};